2014-02-13 03:01:52

by Magnus Damm

[permalink] [raw]
Subject: [PATCH 00/08] PCI: rcar: Recent driver patches from Ben Dooks and me

PCI: rcar: Recent driver patches from Ben Dooks and me

[PATCH 01/08] PCI: rcar: check platform_get_irq() return code
[PATCH v2 02/08] PCI: rcar: add error interrupt handling
[PATCH 03/08] PCI: rcar: fix bridge logic configuration accesses
[PATCH v2 04/08] PCI: rcar: Register each instance independently
[PATCH v2 05/08] PCI: rcar: Break out window size handling
[PATCH v2 06/08] PCI: rcar: Add DMABOUNCE support
[PATCH 07/08] PCI: rcar: Enable BOUNCE in case of HIGHMEM
[PATCH 08/08] PCI: rcar: Make the Kconfig dependencies more generic

These patches update the pci-rcar-gen2.c driver with patches from
Ben Dooks and me. The first 3 are written by Ben (thanks!) and are
included here to show what I would like to have merged and what I
rebased my patches on. The following 4 are updated versions of

[PATCH 00/04] PCI: rcar: Driver model and physical address space update

The final patch is a new one that fixes up the Kconfig dependencies.

Patch 1-3:
Signed-off-by: Ben Dooks <[email protected]>

Patch 4-8:
Signed-off-by: Magnus Damm <[email protected]>
---

Written against renesas.git tag renesas-devel-v3.14-rc1-20140207

drivers/pci/host/Kconfig | 5
drivers/pci/host/pci-rcar-gen2.c | 445 ++++++++++++++++++++++++++++++++------
2 files changed, 385 insertions(+), 65 deletions(-)


2014-02-13 03:02:04

by Magnus Damm

[permalink] [raw]
Subject: [PATCH 01/08] PCI: rcar: check platform_get_irq() return code

From: Ben Dooks <[email protected]>

The current code does not check the return from platform_get_irq()
so add an error check and return if this call does fail.

Signed-off-by: Ben Dooks <[email protected]>
Signed-off-by: Magnus Damm <[email protected]>
---

drivers/pci/host/pci-rcar-gen2.c | 5 +++++
1 file changed, 5 insertions(+)

--- 0001/drivers/pci/host/pci-rcar-gen2.c
+++ work/drivers/pci/host/pci-rcar-gen2.c 2014-02-13 09:41:55.000000000 +0900
@@ -308,6 +308,11 @@ static int __init rcar_pci_probe(struct
priv->reg = reg;
priv->dev = &pdev->dev;

+ if (priv->irq < 0) {
+ dev_err(&pdev->dev, "no valid irq found\n");
+ return priv->irq;
+ }
+
return rcar_pci_add_controller(priv);
}

2014-02-13 03:02:13

by Magnus Damm

[permalink] [raw]
Subject: [PATCH v2 02/08] PCI: rcar: add error interrupt handling

From: Ben Dooks <[email protected]>

Add option to enable interrupts to report any errors from
the AHB-PCI bridge to help find any issues with the bridge
when in use.

Signed-off-by: Ben Dooks <[email protected]>
Signed-off-by: Magnus Damm <[email protected]>
---

v2:
- removed kconfig entry and use CONFIG_PCI_DEBUG
- check for irq > 0 before trying to attach irq

drivers/pci/host/pci-rcar-gen2.c | 60 ++++++++++++++++++++++++++++++++++++++
1 file changed, 60 insertions(+)

--- 0004/drivers/pci/host/pci-rcar-gen2.c
+++ work/drivers/pci/host/pci-rcar-gen2.c 2014-02-13 09:42:56.000000000 +0900
@@ -39,9 +39,26 @@

#define RCAR_PCI_INT_ENABLE_REG (RCAR_AHBPCI_PCICOM_OFFSET + 0x20)
#define RCAR_PCI_INT_STATUS_REG (RCAR_AHBPCI_PCICOM_OFFSET + 0x24)
+#define RCAR_PCI_INT_SIGTABORT (1 << 0)
+#define RCAR_PCI_INT_SIGRETABORT (1 << 1)
+#define RCAR_PCI_INT_REMABORT (1 << 2)
+#define RCAR_PCI_INT_PERR (1 << 3)
+#define RCAR_PCI_INT_SIGSERR (1 << 4)
+#define RCAR_PCI_INT_RESERR (1 << 5)
+#define RCAR_PCI_INT_WIN1ERR (1 << 12)
+#define RCAR_PCI_INT_WIN2ERR (1 << 13)
#define RCAR_PCI_INT_A (1 << 16)
#define RCAR_PCI_INT_B (1 << 17)
#define RCAR_PCI_INT_PME (1 << 19)
+#define RCAR_PCI_INT_ALLERRORS (RCAR_PCI_INT_SIGTABORT | \
+ RCAR_PCI_INT_SIGRETABORT | \
+ RCAR_PCI_INT_SIGRETABORT | \
+ RCAR_PCI_INT_REMABORT | \
+ RCAR_PCI_INT_PERR | \
+ RCAR_PCI_INT_SIGSERR | \
+ RCAR_PCI_INT_RESERR | \
+ RCAR_PCI_INT_WIN1ERR | \
+ RCAR_PCI_INT_WIN2ERR)

#define RCAR_AHB_BUS_CTR_REG (RCAR_AHBPCI_PCICOM_OFFSET + 0x30)
#define RCAR_AHB_BUS_MMODE_HTRANS (1 << 0)
@@ -164,6 +181,46 @@ static int __init rcar_pci_map_irq(const
return priv->irq;
}

+#ifdef CONFIG_PCI_DEBUG
+/* if debug enabled, then attach an error handler irq to the bridge */
+
+static irqreturn_t rcar_pci_err_irq(int irq, void *pw)
+{
+ struct rcar_pci_priv *priv = pw;
+ u32 status = ioread32(priv->reg + RCAR_PCI_INT_STATUS_REG);
+
+ if (status & RCAR_PCI_INT_ALLERRORS) {
+ dev_err(priv->dev, "error irq: status %08x\n", status);
+
+ /* clear the error(s) */
+ iowrite32(status & RCAR_PCI_INT_ALLERRORS,
+ priv->reg + RCAR_PCI_INT_STATUS_REG);
+ return IRQ_HANDLED;
+ }
+
+ return IRQ_NONE;
+}
+
+static void rcar_pci_setup_errirq(struct rcar_pci_priv *priv)
+{
+ int ret;
+ u32 val;
+
+ ret = devm_request_irq(priv->dev, priv->irq, rcar_pci_err_irq,
+ IRQF_SHARED, "error irq", priv);
+ if (ret) {
+ dev_err(priv->dev, "cannot claim IRQ for error handling\n");
+ return;
+ }
+
+ val = ioread32(priv->reg + RCAR_PCI_INT_ENABLE_REG);
+ val |= RCAR_PCI_INT_ALLERRORS;
+ iowrite32(val, priv->reg + RCAR_PCI_INT_ENABLE_REG);
+}
+#else
+static inline void rcar_pci_setup_errirq(struct rcar_pci_priv *priv) { }
+#endif
+
/* PCI host controller setup */
static int __init rcar_pci_setup(int nr, struct pci_sys_data *sys)
{
@@ -224,6 +281,9 @@ static int __init rcar_pci_setup(int nr,
iowrite32(RCAR_PCI_INT_A | RCAR_PCI_INT_B | RCAR_PCI_INT_PME,
reg + RCAR_PCI_INT_ENABLE_REG);

+ if (priv->irq > 0)
+ rcar_pci_setup_errirq(priv);
+
/* Add PCI resources */
pci_add_resource(&sys->resources, &priv->io_res);
pci_add_resource(&sys->resources, &priv->mem_res);

2014-02-13 03:02:24

by Magnus Damm

[permalink] [raw]
Subject: [PATCH 03/08] PCI: rcar: fix bridge logic configuration accesses

From: Ben Dooks <[email protected]>

The bridge logic at slot 0 only supports reads up to 0x40 and the
rest of the PCI configuration space for this slot is marked as
reserved in the manual.

Trying a read from offset 0x100 is producing an error from the
bridge. With error interrupts enabled, the following is printed:

pci-rcar-gen2 ee0d0000.pci: error irq: status 00000014

Signed-off-by: Ben Dooks <[email protected]>
Signed-off-by: Magnus Damm <[email protected]>
---

drivers/pci/host/pci-rcar-gen2.c | 4 ++++
1 file changed, 4 insertions(+)

--- 0005/drivers/pci/host/pci-rcar-gen2.c
+++ work/drivers/pci/host/pci-rcar-gen2.c 2014-02-13 09:45:45.000000000 +0900
@@ -119,6 +119,10 @@ static void __iomem *rcar_pci_cfg_base(s
if (slot > 2)
return NULL;

+ /* bridge logic only has registers to 0x40 */
+ if (slot == 0x0 && where >= 0x40)
+ return NULL;
+
val = slot ? RCAR_AHBPCI_WIN1_DEVICE | RCAR_AHBPCI_WIN_CTR_CFG :
RCAR_AHBPCI_WIN1_HOST | RCAR_AHBPCI_WIN_CTR_CFG;

2014-02-13 03:02:44

by Magnus Damm

[permalink] [raw]
Subject: [PATCH v2 05/08] PCI: rcar: Break out window size handling

From: Magnus Damm <[email protected]>

Break out the hard coded window size code to allow
dynamic setup. The window size is still left at 1GiB
but with this patch changing window size is easy for
testing.

Signed-off-by: Magnus Damm <[email protected]>
---

Changes since V1:
- Updated to fit on top of patches from Ben Dooks

drivers/pci/host/pci-rcar-gen2.c | 31 ++++++++++++++++++++++++++++---
1 file changed, 28 insertions(+), 3 deletions(-)

--- 0007/drivers/pci/host/pci-rcar-gen2.c
+++ work/drivers/pci/host/pci-rcar-gen2.c 2014-02-13 10:16:48.000000000 +0900
@@ -18,6 +18,7 @@
#include <linux/pci.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
+#include <linux/sizes.h>
#include <linux/slab.h>

/* AHB-PCI Bridge PCI communication registers */
@@ -98,6 +99,7 @@ struct rcar_pci_priv {
struct resource mem_res;
struct resource *cfg_res;
int irq;
+ unsigned long window_size;
};

/* PCI configuration space operations */
@@ -241,10 +243,31 @@ static int __init rcar_pci_setup(int nr,
iowrite32(val, reg + RCAR_USBCTR_REG);
udelay(4);

- /* De-assert reset and set PCIAHB window1 size to 1GB */
+ /* De-assert reset and reset PCIAHB window1 size */
val &= ~(RCAR_USBCTR_PCIAHB_WIN1_MASK | RCAR_USBCTR_PCICLK_MASK |
RCAR_USBCTR_USBH_RST | RCAR_USBCTR_PLL_RST);
- iowrite32(val | RCAR_USBCTR_PCIAHB_WIN1_1G, reg + RCAR_USBCTR_REG);
+
+ /* Setup PCIAHB window1 size */
+ switch (priv->window_size) {
+ case SZ_2G:
+ val |= RCAR_USBCTR_PCIAHB_WIN1_2G;
+ break;
+ case SZ_1G:
+ val |= RCAR_USBCTR_PCIAHB_WIN1_1G;
+ break;
+ case SZ_512M:
+ val |= RCAR_USBCTR_PCIAHB_WIN1_512M;
+ break;
+ default:
+ pr_warn("unknown window size %ld - defaulting to 256M\n",
+ priv->window_size);
+ priv->window_size = SZ_256M;
+ /* fall-through */
+ case SZ_256M:
+ val |= RCAR_USBCTR_PCIAHB_WIN1_256M;
+ break;
+ }
+ iowrite32(val, reg + RCAR_USBCTR_REG);

/* Configure AHB master and slave modes */
iowrite32(RCAR_AHB_BUS_MODE, reg + RCAR_AHB_BUS_CTR_REG);
@@ -255,7 +278,7 @@ static int __init rcar_pci_setup(int nr,
RCAR_PCI_ARBITER_PCIBP_MODE;
iowrite32(val, reg + RCAR_PCI_ARBITER_CTR_REG);

- /* PCI-AHB mapping: 0x40000000-0x80000000 */
+ /* PCI-AHB mapping: 0x40000000 base */
iowrite32(0x40000000 | RCAR_PCIAHB_PREFETCH16,
reg + RCAR_PCIAHB_WIN1_CTR_REG);

@@ -341,6 +364,8 @@ static int rcar_pci_probe(struct platfor
return priv->irq;
}

+ priv->window_size = SZ_1G;
+
hw_private[0] = priv;
memset(&hw, 0, sizeof(hw));
hw.nr_controllers = ARRAY_SIZE(hw_private);

2014-02-13 03:02:54

by Magnus Damm

[permalink] [raw]
Subject: [PATCH v2 06/08] PCI: rcar: Add DMABOUNCE support

From: Magnus Damm <[email protected]>

Add DMABOUNCE support together with a local memory area for
all PCI devices hanging off this bridge. 4MiB of memory is
set aside for coherent allocations which is shared between
the on-chip OHCI and EHCI devices that are hanging off the
PCI bridge. With this patch the driver will work for all
CONFIG_VMSPLIT settings.

Signed-off-by: Magnus Damm <[email protected]>
---

Changes since V1:
- Updated to fit on top of patches by Ben Dooks.
- Break out code into rcar_pci_init_bounce()

drivers/pci/host/Kconfig | 2
drivers/pci/host/pci-rcar-gen2.c | 269 +++++++++++++++++++++++++++++++++++++-
2 files changed, 268 insertions(+), 3 deletions(-)

--- 0001/drivers/pci/host/Kconfig
+++ work/drivers/pci/host/Kconfig 2014-02-13 10:52:48.000000000 +0900
@@ -28,6 +28,8 @@ config PCI_TEGRA
config PCI_RCAR_GEN2
bool "Renesas R-Car Gen2 Internal PCI controller"
depends on ARM && (ARCH_R8A7790 || ARCH_R8A7791 || COMPILE_TEST)
+ select GENERIC_ALLOCATOR
+ select DMABOUNCE
help
Say Y here if you want internal PCI support on R-Car Gen2 SoC.
There are 3 internal PCI controllers available with a single
--- 0008/drivers/pci/host/pci-rcar-gen2.c
+++ work/drivers/pci/host/pci-rcar-gen2.c 2014-02-13 11:12:38.000000000 +0900
@@ -15,11 +15,14 @@
#include <linux/io.h>
#include <linux/kernel.h>
#include <linux/module.h>
+#include <linux/notifier.h>
#include <linux/pci.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
#include <linux/sizes.h>
#include <linux/slab.h>
+#include <linux/spinlock.h>
+#include <linux/genalloc.h>

/* AHB-PCI Bridge PCI communication registers */
#define RCAR_AHBPCI_PCICOM_OFFSET 0x800
@@ -100,6 +103,11 @@ struct rcar_pci_priv {
struct resource *cfg_res;
int irq;
unsigned long window_size;
+ u32 window_base;
+ struct notifier_block bus_notifier;
+ struct gen_pool *dma_pool;
+ unsigned long dma_size;
+ dma_addr_t dma_phys;
};

/* PCI configuration space operations */
@@ -278,8 +286,8 @@ static int __init rcar_pci_setup(int nr,
RCAR_PCI_ARBITER_PCIBP_MODE;
iowrite32(val, reg + RCAR_PCI_ARBITER_CTR_REG);

- /* PCI-AHB mapping: 0x40000000 base */
- iowrite32(0x40000000 | RCAR_PCIAHB_PREFETCH16,
+ /* PCI-AHB mapping: dynamic base */
+ iowrite32(priv->window_base | RCAR_PCIAHB_PREFETCH16,
reg + RCAR_PCIAHB_WIN1_CTR_REG);

/* AHB-PCI mapping: OHCI/EHCI registers */
@@ -290,7 +298,7 @@ static int __init rcar_pci_setup(int nr,
iowrite32(RCAR_AHBPCI_WIN1_HOST | RCAR_AHBPCI_WIN_CTR_CFG,
reg + RCAR_AHBPCI_WIN1_CTR_REG);
/* Set PCI-AHB Window1 address */
- iowrite32(0x40000000 | PCI_BASE_ADDRESS_MEM_PREFETCH,
+ iowrite32(priv->window_base | PCI_BASE_ADDRESS_MEM_PREFETCH,
reg + PCI_BASE_ADDRESS_1);
/* Set AHB-PCI bridge PCI communication area address */
val = priv->cfg_res->start + RCAR_AHBPCI_PCICOM_OFFSET;
@@ -322,6 +330,235 @@ static struct pci_ops rcar_pci_ops = {
.write = rcar_pci_write_config,
};

+static struct rcar_pci_priv *rcar_pci_dev_to_priv(struct device *dev)
+{
+ struct pci_sys_data *sys = to_pci_dev(dev)->sysdata;
+
+ return sys->private_data;
+}
+
+static void *rcar_pci_dma_alloc(struct device *dev, size_t size,
+ dma_addr_t *handle, gfp_t gfp,
+ struct dma_attrs *attrs)
+{
+ struct rcar_pci_priv *p = rcar_pci_dev_to_priv(dev);
+
+ return (void *)gen_pool_dma_alloc(p->dma_pool, size, handle);
+}
+
+static void rcar_pci_dma_free(struct device *dev, size_t size, void *cpu_addr,
+ dma_addr_t handle, struct dma_attrs *attrs)
+{
+ struct rcar_pci_priv *p = rcar_pci_dev_to_priv(dev);
+
+ gen_pool_free(p->dma_pool, (unsigned long)cpu_addr, size);
+}
+
+static struct dma_map_ops rcar_pci_dma_ops_init = {
+ .alloc = rcar_pci_dma_alloc,
+ .free = rcar_pci_dma_free,
+};
+
+static int rcar_pci_dma_mmap(struct device *dev, struct vm_area_struct *vma,
+ void *cpu_addr, dma_addr_t dma_addr, size_t size,
+ struct dma_attrs *attrs)
+{
+ struct rcar_pci_priv *p = rcar_pci_dev_to_priv(dev);
+
+ return get_dma_ops(p->dev)->mmap(p->dev, vma, cpu_addr,
+ dma_addr, size, attrs);
+}
+
+static int rcar_pci_dma_get_sgtable(struct device *dev, struct sg_table *sgt,
+ void *cpu_addr, dma_addr_t handle,
+ size_t size, struct dma_attrs *attrs)
+{
+ struct rcar_pci_priv *p = rcar_pci_dev_to_priv(dev);
+
+ return get_dma_ops(p->dev)->get_sgtable(p->dev, sgt, cpu_addr,
+ handle, size, attrs);
+}
+
+static dma_addr_t rcar_pci_dma_map_page(struct device *dev, struct page *page,
+ unsigned long offset, size_t size,
+ enum dma_data_direction dir,
+ struct dma_attrs *attrs)
+{
+ struct rcar_pci_priv *p = rcar_pci_dev_to_priv(dev);
+
+ return get_dma_ops(p->dev)->map_page(p->dev, page, offset,
+ size, dir, attrs);
+}
+
+static void rcar_pci_dma_unmap_page(struct device *dev, dma_addr_t dma_handle,
+ size_t size, enum dma_data_direction dir,
+ struct dma_attrs *attrs)
+{
+ struct rcar_pci_priv *p = rcar_pci_dev_to_priv(dev);
+
+ get_dma_ops(p->dev)->unmap_page(p->dev, dma_handle, size, dir, attrs);
+}
+
+static int rcar_pci_dma_map_sg(struct device *dev, struct scatterlist *sg,
+ int nents, enum dma_data_direction dir,
+ struct dma_attrs *attrs)
+{
+ struct rcar_pci_priv *p = rcar_pci_dev_to_priv(dev);
+
+ return get_dma_ops(p->dev)->map_sg(p->dev, sg, nents, dir, attrs);
+}
+
+static void rcar_pci_dma_unmap_sg(struct device *dev, struct scatterlist *sg,
+ int nents, enum dma_data_direction dir,
+ struct dma_attrs *attrs)
+{
+ struct rcar_pci_priv *p = rcar_pci_dev_to_priv(dev);
+
+ get_dma_ops(p->dev)->unmap_sg(p->dev, sg, nents, dir, attrs);
+}
+
+static void rcar_pci_dma_sync_single_for_cpu(struct device *dev,
+ dma_addr_t dma_handle,
+ size_t size,
+ enum dma_data_direction dir)
+{
+ struct rcar_pci_priv *p = rcar_pci_dev_to_priv(dev);
+
+ get_dma_ops(p->dev)->sync_single_for_cpu(p->dev, dma_handle,
+ size, dir);
+}
+
+static void rcar_pci_dma_sync_single_for_device(struct device *dev,
+ dma_addr_t dma_handle,
+ size_t size,
+ enum dma_data_direction dir)
+{
+ struct rcar_pci_priv *p = rcar_pci_dev_to_priv(dev);
+
+ get_dma_ops(p->dev)->sync_single_for_device(p->dev, dma_handle,
+ size, dir);
+}
+
+static void rcar_pci_dma_sync_sg_for_cpu(struct device *dev,
+ struct scatterlist *sg,
+ int nents,
+ enum dma_data_direction dir)
+{
+ struct rcar_pci_priv *p = rcar_pci_dev_to_priv(dev);
+
+ get_dma_ops(p->dev)->sync_sg_for_cpu(p->dev, sg, nents, dir);
+}
+
+static void rcar_pci_dma_sync_sg_for_device(struct device *dev,
+ struct scatterlist *sg,
+ int nents,
+ enum dma_data_direction dir)
+{
+ struct rcar_pci_priv *p = rcar_pci_dev_to_priv(dev);
+
+ get_dma_ops(p->dev)->sync_sg_for_device(p->dev, sg, nents, dir);
+}
+
+static int rcar_pci_dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
+{
+ struct rcar_pci_priv *p = rcar_pci_dev_to_priv(dev);
+
+ return get_dma_ops(p->dev)->mapping_error(p->dev, dma_addr);
+}
+
+static int rcar_pci_dma_supported(struct device *dev, u64 mask)
+{
+ struct rcar_pci_priv *p = rcar_pci_dev_to_priv(dev);
+
+ return get_dma_ops(p->dev)->dma_supported(p->dev, mask);
+}
+
+static int rcar_pci_dma_set_dma_mask(struct device *dev, u64 mask)
+{
+ struct rcar_pci_priv *p = rcar_pci_dev_to_priv(dev);
+
+ return get_dma_ops(p->dev)->set_dma_mask(p->dev, mask);
+}
+
+static struct dma_map_ops rcar_pci_dma_ops = {
+ .alloc = rcar_pci_dma_alloc,
+ .free = rcar_pci_dma_free,
+ .mmap = rcar_pci_dma_mmap,
+ .get_sgtable = rcar_pci_dma_get_sgtable,
+ .map_page = rcar_pci_dma_map_page,
+ .unmap_page = rcar_pci_dma_unmap_page,
+ .map_sg = rcar_pci_dma_map_sg,
+ .unmap_sg = rcar_pci_dma_unmap_sg,
+ .sync_single_for_cpu = rcar_pci_dma_sync_single_for_cpu,
+ .sync_single_for_device = rcar_pci_dma_sync_single_for_device,
+ .sync_sg_for_cpu = rcar_pci_dma_sync_sg_for_cpu,
+ .sync_sg_for_device = rcar_pci_dma_sync_sg_for_device,
+ .mapping_error = rcar_pci_dma_mapping_error,
+ .dma_supported = rcar_pci_dma_supported,
+ .set_dma_mask = rcar_pci_dma_set_dma_mask,
+};
+
+static int rcar_pci_bus_notify(struct notifier_block *nb,
+ unsigned long action, void *data)
+{
+ struct rcar_pci_priv *priv;
+ struct device *dev = data;
+ struct pci_dev *pci_dev = to_pci_dev(dev);
+ struct pci_sys_data *sys = pci_dev->sysdata;
+
+ priv = container_of(nb, struct rcar_pci_priv, bus_notifier);
+ if (priv != sys->private_data)
+ return 0;
+
+ if (action == BUS_NOTIFY_BIND_DRIVER)
+ set_dma_ops(dev, &rcar_pci_dma_ops);
+
+ return 0;
+}
+
+static void rcar_pci_add_bus(struct pci_bus *bus)
+{
+ struct pci_sys_data *sys = bus->sysdata;
+ struct rcar_pci_priv *priv = sys->private_data;
+
+ bus_register_notifier(&pci_bus_type, &priv->bus_notifier);
+}
+
+static void rcar_pci_remove_bus(struct pci_bus *bus)
+{
+ struct pci_sys_data *sys = bus->sysdata;
+ struct rcar_pci_priv *priv = sys->private_data;
+
+ bus_unregister_notifier(&pci_bus_type, &priv->bus_notifier);
+}
+
+static int rcar_pci_needs_bounce(struct device *dev,
+ dma_addr_t dma_addr, size_t size)
+{
+ struct platform_device *pdev = to_platform_device(dev);
+ struct rcar_pci_priv *priv = platform_get_drvdata(pdev);
+
+ if (dma_addr < priv->window_base)
+ return 1;
+
+ if (dma_addr >= (priv->window_base + priv->window_size))
+ return 1;
+
+ return 0;
+}
+
+static void rcar_pci_init_bounce(struct rcar_pci_priv *priv)
+{
+ /* use notifier to hook pool allocator */
+ priv->bus_notifier.notifier_call = rcar_pci_bus_notify;
+
+ /* setup alloc()/free() to let dmabounce allocate from our pool */
+ set_dma_ops(priv->dev, &rcar_pci_dma_ops_init);
+
+ /* shared dmabounce for the PCI bridge */
+ dmabounce_register_dev(priv->dev, 2048, 4096, rcar_pci_needs_bounce);
+}
+
static int rcar_pci_probe(struct platform_device *pdev)
{
struct resource *cfg_res, *mem_res;
@@ -329,6 +566,8 @@ static int rcar_pci_probe(struct platfor
void __iomem *reg;
struct hw_pci hw;
void *hw_private[1];
+ void *dma_virt;
+ int ret;

cfg_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
reg = devm_ioremap_resource(&pdev->dev, cfg_res);
@@ -358,6 +597,7 @@ static int rcar_pci_probe(struct platfor
priv->irq = platform_get_irq(pdev, 0);
priv->reg = reg;
priv->dev = &pdev->dev;
+ platform_set_drvdata(pdev, priv);

if (priv->irq < 0) {
dev_err(&pdev->dev, "no valid irq found\n");
@@ -365,6 +605,27 @@ static int rcar_pci_probe(struct platfor
}

priv->window_size = SZ_1G;
+ priv->dma_size = SZ_4M;
+
+ /* allocate pool of memory guaranteed to be inside window */
+ priv->dma_pool = devm_gen_pool_create(&pdev->dev, 7, -1);
+ if (!priv->dma_pool)
+ return -ENOMEM;
+
+ dma_virt = dmam_alloc_coherent(&pdev->dev, priv->dma_size,
+ &priv->dma_phys, GFP_KERNEL);
+ if (!dma_virt)
+ return -ENOMEM;
+
+ ret = gen_pool_add_virt(priv->dma_pool, (unsigned long)dma_virt,
+ priv->dma_phys, priv->dma_size, -1);
+ if (ret)
+ return ret;
+
+ /* select window base address based on physical address for memory */
+ priv->window_base = priv->dma_phys & ~(priv->window_size - 1);
+
+ rcar_pci_init_bounce(priv);

hw_private[0] = priv;
memset(&hw, 0, sizeof(hw));
@@ -373,6 +634,8 @@ static int rcar_pci_probe(struct platfor
hw.map_irq = rcar_pci_map_irq;
hw.ops = &rcar_pci_ops;
hw.setup = rcar_pci_setup;
+ hw.add_bus = rcar_pci_add_bus;
+ hw.remove_bus = rcar_pci_remove_bus;
pci_common_init_dev(&pdev->dev, &hw);
return 0;
}

2014-02-13 03:03:06

by Magnus Damm

[permalink] [raw]
Subject: [PATCH 07/08] PCI: rcar: Enable BOUNCE in case of HIGHMEM

From: Magnus Damm <[email protected]>

Select BOUNCE in case of HIGHMEM to enable bounce buffers in
the block layer. Without this patch the DMABOUNCE code will
error out due to lack of HIGHMEM support, and without DMABOUNCE
there will be silent errors.

Signed-off-by: Magnus Damm <[email protected]>
---

drivers/pci/host/Kconfig | 1 +
1 file changed, 1 insertion(+)

--- 0009/drivers/pci/host/Kconfig
+++ work/drivers/pci/host/Kconfig 2014-02-04 16:11:27.000000000 +0900
@@ -30,6 +30,7 @@ config PCI_RCAR_GEN2
depends on ARM && (ARCH_R8A7790 || ARCH_R8A7791 || COMPILE_TEST)
select GENERIC_ALLOCATOR
select DMABOUNCE
+ select BOUNCE if HIGHMEM
help
Say Y here if you want internal PCI support on R-Car Gen2 SoC.
There are 3 internal PCI controllers available with a single

2014-02-13 03:03:15

by Magnus Damm

[permalink] [raw]
Subject: [PATCH 08/08] PCI: rcar: Make the Kconfig dependencies more generic

From: Magnus Damm <[email protected]>

Update the R-Car Generation 2 PCI driver Kconfig dependencies
to follow same style as other drivers - no SoC dependencies.

Also, update the COMPILE_TEST bits to depend on ARM. This since
the DMA bounce buffer and dma_ops handling code is ARM specific.

Signed-off-by: Magnus Damm <[email protected]>
---

drivers/pci/host/Kconfig | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

--- 0010/drivers/pci/host/Kconfig
+++ work/drivers/pci/host/Kconfig 2014-02-13 11:19:19.000000000 +0900
@@ -27,7 +27,7 @@ config PCI_TEGRA

config PCI_RCAR_GEN2
bool "Renesas R-Car Gen2 Internal PCI controller"
- depends on ARM && (ARCH_R8A7790 || ARCH_R8A7791 || COMPILE_TEST)
+ depends on ARCH_SHMOBILE || (ARM && COMPILE_TEST)
select GENERIC_ALLOCATOR
select DMABOUNCE
select BOUNCE if HIGHMEM

2014-02-13 03:03:59

by Magnus Damm

[permalink] [raw]
Subject: [PATCH v2 04/08] PCI: rcar: Register each instance independently

From: Magnus Damm <[email protected]>

Convert the code to allow per-device probe() like other device
drivers. This also delays driver registration due to change from
subsys_initcall() to regular module_platform_driver().

Signed-off-by: Magnus Damm <[email protected]>
---

Changes since V1:
- Updated to fit on top of patches from Ben Dooks
- Use hw_private[1] for hw.private_data, thanks Geert!
- Use ARRAY_SIZE with hw_private for hw.nr_controllers

drivers/pci/host/pci-rcar-gen2.c | 76 +++++++++-----------------------------
1 file changed, 18 insertions(+), 58 deletions(-)

--- 0006/drivers/pci/host/pci-rcar-gen2.c
+++ work/drivers/pci/host/pci-rcar-gen2.c 2014-02-13 10:10:25.000000000 +0900
@@ -91,9 +91,6 @@

#define RCAR_PCI_UNIT_REV_REG (RCAR_AHBPCI_PCICOM_OFFSET + 0x48)

-/* Number of internal PCI controllers */
-#define RCAR_PCI_NR_CONTROLLERS 3
-
struct rcar_pci_priv {
struct device *dev;
void __iomem *reg;
@@ -292,6 +289,8 @@ static int __init rcar_pci_setup(int nr,
pci_add_resource(&sys->resources, &priv->io_res);
pci_add_resource(&sys->resources, &priv->mem_res);

+ /* Setup bus number based on platform device id */
+ sys->busnr = to_platform_device(priv->dev)->id;
return 1;
}

@@ -300,48 +299,13 @@ static struct pci_ops rcar_pci_ops = {
.write = rcar_pci_write_config,
};

-static struct hw_pci rcar_hw_pci __initdata = {
- .map_irq = rcar_pci_map_irq,
- .ops = &rcar_pci_ops,
- .setup = rcar_pci_setup,
-};
-
-static int rcar_pci_count __initdata;
-
-static int __init rcar_pci_add_controller(struct rcar_pci_priv *priv)
-{
- void **private_data;
- int count;
-
- if (rcar_hw_pci.nr_controllers < rcar_pci_count)
- goto add_priv;
-
- /* (Re)allocate private data pointer array if needed */
- count = rcar_pci_count + RCAR_PCI_NR_CONTROLLERS;
- private_data = kzalloc(count * sizeof(void *), GFP_KERNEL);
- if (!private_data)
- return -ENOMEM;
-
- rcar_pci_count = count;
- if (rcar_hw_pci.private_data) {
- memcpy(private_data, rcar_hw_pci.private_data,
- rcar_hw_pci.nr_controllers * sizeof(void *));
- kfree(rcar_hw_pci.private_data);
- }
-
- rcar_hw_pci.private_data = private_data;
-
-add_priv:
- /* Add private data pointer to the array */
- rcar_hw_pci.private_data[rcar_hw_pci.nr_controllers++] = priv;
- return 0;
-}
-
-static int __init rcar_pci_probe(struct platform_device *pdev)
+static int rcar_pci_probe(struct platform_device *pdev)
{
struct resource *cfg_res, *mem_res;
struct rcar_pci_priv *priv;
void __iomem *reg;
+ struct hw_pci hw;
+ void *hw_private[1];

cfg_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
reg = devm_ioremap_resource(&pdev->dev, cfg_res);
@@ -377,31 +341,27 @@ static int __init rcar_pci_probe(struct
return priv->irq;
}

- return rcar_pci_add_controller(priv);
+ hw_private[0] = priv;
+ memset(&hw, 0, sizeof(hw));
+ hw.nr_controllers = ARRAY_SIZE(hw_private);
+ hw.private_data = hw_private;
+ hw.map_irq = rcar_pci_map_irq;
+ hw.ops = &rcar_pci_ops;
+ hw.setup = rcar_pci_setup;
+ pci_common_init_dev(&pdev->dev, &hw);
+ return 0;
}

static struct platform_driver rcar_pci_driver = {
.driver = {
.name = "pci-rcar-gen2",
+ .owner = THIS_MODULE,
+ .suppress_bind_attrs = true,
},
+ .probe = rcar_pci_probe,
};

-static int __init rcar_pci_init(void)
-{
- int retval;
-
- retval = platform_driver_probe(&rcar_pci_driver, rcar_pci_probe);
- if (!retval)
- pci_common_init(&rcar_hw_pci);
-
- /* Private data pointer array is not needed any more */
- kfree(rcar_hw_pci.private_data);
- rcar_hw_pci.private_data = NULL;
-
- return retval;
-}
-
-subsys_initcall(rcar_pci_init);
+module_platform_driver(rcar_pci_driver);

MODULE_LICENSE("GPL v2");
MODULE_DESCRIPTION("Renesas R-Car Gen2 internal PCI");

2014-02-13 04:39:59

by Simon Horman

[permalink] [raw]
Subject: Re: [PATCH 00/08] PCI: rcar: Recent driver patches from Ben Dooks and me

On Thu, Feb 13, 2014 at 12:03:02PM +0900, Magnus Damm wrote:
> PCI: rcar: Recent driver patches from Ben Dooks and me
>
> [PATCH 01/08] PCI: rcar: check platform_get_irq() return code
> [PATCH v2 02/08] PCI: rcar: add error interrupt handling
> [PATCH 03/08] PCI: rcar: fix bridge logic configuration accesses
> [PATCH v2 04/08] PCI: rcar: Register each instance independently
> [PATCH v2 05/08] PCI: rcar: Break out window size handling
> [PATCH v2 06/08] PCI: rcar: Add DMABOUNCE support
> [PATCH 07/08] PCI: rcar: Enable BOUNCE in case of HIGHMEM
> [PATCH 08/08] PCI: rcar: Make the Kconfig dependencies more generic
>
> These patches update the pci-rcar-gen2.c driver with patches from
> Ben Dooks and me. The first 3 are written by Ben (thanks!) and are
> included here to show what I would like to have merged and what I
> rebased my patches on. The following 4 are updated versions of
>
> [PATCH 00/04] PCI: rcar: Driver model and physical address space update
>
> The final patch is a new one that fixes up the Kconfig dependencies.
>
> Patch 1-3:
> Signed-off-by: Ben Dooks <[email protected]>
>
> Patch 4-8:
> Signed-off-by: Magnus Damm <[email protected]>
> ---
>
> Written against renesas.git tag renesas-devel-v3.14-rc1-20140207
>
> drivers/pci/host/Kconfig | 5
> drivers/pci/host/pci-rcar-gen2.c | 445 ++++++++++++++++++++++++++++++++------
> 2 files changed, 385 insertions(+), 65 deletions(-)

Bjorn,

I am happy with these.
Could you consider merging this series?

Acked-by: Simon Horman <[email protected]>

2014-02-13 12:34:57

by Ben Dooks

[permalink] [raw]
Subject: Re: [PATCH 00/08] PCI: rcar: Recent driver patches from Ben Dooks and me

On 13/02/14 03:03, Magnus Damm wrote:
> PCI: rcar: Recent driver patches from Ben Dooks and me
>
> [PATCH 01/08] PCI: rcar: check platform_get_irq() return code
> [PATCH v2 02/08] PCI: rcar: add error interrupt handling
> [PATCH 03/08] PCI: rcar: fix bridge logic configuration accesses
> [PATCH v2 04/08] PCI: rcar: Register each instance independently
> [PATCH v2 05/08] PCI: rcar: Break out window size handling
> [PATCH v2 06/08] PCI: rcar: Add DMABOUNCE support
> [PATCH 07/08] PCI: rcar: Enable BOUNCE in case of HIGHMEM
> [PATCH 08/08] PCI: rcar: Make the Kconfig dependencies more generic
>
> These patches update the pci-rcar-gen2.c driver with patches from
> Ben Dooks and me. The first 3 are written by Ben (thanks!) and are
> included here to show what I would like to have merged and what I
> rebased my patches on. The following 4 are updated versions of
>
> [PATCH 00/04] PCI: rcar: Driver model and physical address space update
>
> The final patch is a new one that fixes up the Kconfig dependencies.

Thanks. Is there any chance of getting this driver device-tree
enabled too?

--
Ben Dooks http://www.codethink.co.uk/
Senior Engineer Codethink - Providing Genius

2014-02-14 05:40:42

by Magnus Damm

[permalink] [raw]
Subject: Re: [PATCH 00/08] PCI: rcar: Recent driver patches from Ben Dooks and me

On Thu, Feb 13, 2014 at 9:34 PM, Ben Dooks <[email protected]> wrote:
> On 13/02/14 03:03, Magnus Damm wrote:
>>
>> PCI: rcar: Recent driver patches from Ben Dooks and me
>>
>> [PATCH 01/08] PCI: rcar: check platform_get_irq() return code
>> [PATCH v2 02/08] PCI: rcar: add error interrupt handling
>> [PATCH 03/08] PCI: rcar: fix bridge logic configuration accesses
>> [PATCH v2 04/08] PCI: rcar: Register each instance independently
>> [PATCH v2 05/08] PCI: rcar: Break out window size handling
>> [PATCH v2 06/08] PCI: rcar: Add DMABOUNCE support
>> [PATCH 07/08] PCI: rcar: Enable BOUNCE in case of HIGHMEM
>> [PATCH 08/08] PCI: rcar: Make the Kconfig dependencies more generic
>>
>> These patches update the pci-rcar-gen2.c driver with patches from
>> Ben Dooks and me. The first 3 are written by Ben (thanks!) and are
>> included here to show what I would like to have merged and what I
>> rebased my patches on. The following 4 are updated versions of
>>
>> [PATCH 00/04] PCI: rcar: Driver model and physical address space update
>>
>> The final patch is a new one that fixes up the Kconfig dependencies.
>
>
> Thanks. Is there any chance of getting this driver device-tree
> enabled too?

I think so! The DT bindings proposed by you looked good for this device.

The only question is how to handle the PHY hardware in a sane way. The
PHY is the central problematic point so to say, since it ties these
PCI USB2.0 devices together with USBHS and for some SoCs USB 3.0 as
well.

I'm thinking of something along these lines:

1) To use DT to describe the full hardware topology
2) Enable all or some device drivers in the kernel configuration
3) Have a sane default but use the bind interface to reassign
driver-to-port configuration.

What is your intended use case?

Thanks,

/ magnus

2014-02-14 10:52:30

by Ben Dooks

[permalink] [raw]
Subject: Re: [PATCH 00/08] PCI: rcar: Recent driver patches from Ben Dooks and me

On 14/02/14 05:40, Magnus Damm wrote:
> On Thu, Feb 13, 2014 at 9:34 PM, Ben Dooks <[email protected]> wrote:
>> On 13/02/14 03:03, Magnus Damm wrote:
>>>
>>> PCI: rcar: Recent driver patches from Ben Dooks and me
>>>
>>> [PATCH 01/08] PCI: rcar: check platform_get_irq() return code
>>> [PATCH v2 02/08] PCI: rcar: add error interrupt handling
>>> [PATCH 03/08] PCI: rcar: fix bridge logic configuration accesses
>>> [PATCH v2 04/08] PCI: rcar: Register each instance independently
>>> [PATCH v2 05/08] PCI: rcar: Break out window size handling
>>> [PATCH v2 06/08] PCI: rcar: Add DMABOUNCE support
>>> [PATCH 07/08] PCI: rcar: Enable BOUNCE in case of HIGHMEM
>>> [PATCH 08/08] PCI: rcar: Make the Kconfig dependencies more generic
>>>
>>> These patches update the pci-rcar-gen2.c driver with patches from
>>> Ben Dooks and me. The first 3 are written by Ben (thanks!) and are
>>> included here to show what I would like to have merged and what I
>>> rebased my patches on. The following 4 are updated versions of
>>>
>>> [PATCH 00/04] PCI: rcar: Driver model and physical address space update
>>>
>>> The final patch is a new one that fixes up the Kconfig dependencies.
>>
>>
>> Thanks. Is there any chance of getting this driver device-tree
>> enabled too?
>
> I think so! The DT bindings proposed by you looked good for this device.
>
> The only question is how to handle the PHY hardware in a sane way. The
> PHY is the central problematic point so to say, since it ties these
> PCI USB2.0 devices together with USBHS and for some SoCs USB 3.0 as
> well.
>
> I'm thinking of something along these lines:
>
> 1) To use DT to describe the full hardware topology
> 2) Enable all or some device drivers in the kernel configuration
> 3) Have a sane default but use the bind interface to reassign
> driver-to-port configuration.
>
> What is your intended use case?

I think we can describe this all from the PHY node or links to
the PHY node. I was going to look at sorting out the bindings
next week, due to this week being mostly consumed by chasing
bugs.

--
Ben Dooks http://www.codethink.co.uk/
Senior Engineer Codethink - Providing Genius

2014-02-14 18:34:37

by Bjorn Helgaas

[permalink] [raw]
Subject: Re: [PATCH 00/08] PCI: rcar: Recent driver patches from Ben Dooks and me

On Thu, Feb 13, 2014 at 01:39:54PM +0900, Simon Horman wrote:
> On Thu, Feb 13, 2014 at 12:03:02PM +0900, Magnus Damm wrote:
> > PCI: rcar: Recent driver patches from Ben Dooks and me
> >
> > [PATCH 01/08] PCI: rcar: check platform_get_irq() return code
> > [PATCH v2 02/08] PCI: rcar: add error interrupt handling
> > [PATCH 03/08] PCI: rcar: fix bridge logic configuration accesses
> > [PATCH v2 04/08] PCI: rcar: Register each instance independently
> > [PATCH v2 05/08] PCI: rcar: Break out window size handling
> > [PATCH v2 06/08] PCI: rcar: Add DMABOUNCE support
> > [PATCH 07/08] PCI: rcar: Enable BOUNCE in case of HIGHMEM
> > [PATCH 08/08] PCI: rcar: Make the Kconfig dependencies more generic
> >
> > These patches update the pci-rcar-gen2.c driver with patches from
> > Ben Dooks and me. The first 3 are written by Ben (thanks!) and are
> > included here to show what I would like to have merged and what I
> > rebased my patches on. The following 4 are updated versions of
> >
> > [PATCH 00/04] PCI: rcar: Driver model and physical address space update
> >
> > The final patch is a new one that fixes up the Kconfig dependencies.
> >
> > Patch 1-3:
> > Signed-off-by: Ben Dooks <[email protected]>
> >
> > Patch 4-8:
> > Signed-off-by: Magnus Damm <[email protected]>
> > ---
> >
> > Written against renesas.git tag renesas-devel-v3.14-rc1-20140207
> >
> > drivers/pci/host/Kconfig | 5
> > drivers/pci/host/pci-rcar-gen2.c | 445 ++++++++++++++++++++++++++++++++------
> > 2 files changed, 385 insertions(+), 65 deletions(-)
>
> Bjorn,
>
> I am happy with these.
> Could you consider merging this series?
>
> Acked-by: Simon Horman <[email protected]>

Applied to pci/host-rcar for v3.15, thanks!

Bjorn

2014-02-17 01:12:15

by Simon Horman

[permalink] [raw]
Subject: Re: [PATCH 00/08] PCI: rcar: Recent driver patches from Ben Dooks and me

On Fri, Feb 14, 2014 at 11:34:30AM -0700, Bjorn Helgaas wrote:
> On Thu, Feb 13, 2014 at 01:39:54PM +0900, Simon Horman wrote:
> > On Thu, Feb 13, 2014 at 12:03:02PM +0900, Magnus Damm wrote:
> > > PCI: rcar: Recent driver patches from Ben Dooks and me
> > >
> > > [PATCH 01/08] PCI: rcar: check platform_get_irq() return code
> > > [PATCH v2 02/08] PCI: rcar: add error interrupt handling
> > > [PATCH 03/08] PCI: rcar: fix bridge logic configuration accesses
> > > [PATCH v2 04/08] PCI: rcar: Register each instance independently
> > > [PATCH v2 05/08] PCI: rcar: Break out window size handling
> > > [PATCH v2 06/08] PCI: rcar: Add DMABOUNCE support
> > > [PATCH 07/08] PCI: rcar: Enable BOUNCE in case of HIGHMEM
> > > [PATCH 08/08] PCI: rcar: Make the Kconfig dependencies more generic
> > >
> > > These patches update the pci-rcar-gen2.c driver with patches from
> > > Ben Dooks and me. The first 3 are written by Ben (thanks!) and are
> > > included here to show what I would like to have merged and what I
> > > rebased my patches on. The following 4 are updated versions of
> > >
> > > [PATCH 00/04] PCI: rcar: Driver model and physical address space update
> > >
> > > The final patch is a new one that fixes up the Kconfig dependencies.
> > >
> > > Patch 1-3:
> > > Signed-off-by: Ben Dooks <[email protected]>
> > >
> > > Patch 4-8:
> > > Signed-off-by: Magnus Damm <[email protected]>
> > > ---
> > >
> > > Written against renesas.git tag renesas-devel-v3.14-rc1-20140207
> > >
> > > drivers/pci/host/Kconfig | 5
> > > drivers/pci/host/pci-rcar-gen2.c | 445 ++++++++++++++++++++++++++++++++------
> > > 2 files changed, 385 insertions(+), 65 deletions(-)
> >
> > Bjorn,
> >
> > I am happy with these.
> > Could you consider merging this series?
> >
> > Acked-by: Simon Horman <[email protected]>
>
> Applied to pci/host-rcar for v3.15, thanks!
>
> Bjorn

Thanks!