pci: Add PCIe driver for Samsung Exynos
Subsystems (4)
PATCH v4 1/3 pci: Add PCIe driver for Samsung Exynos
Exynos5440 has a PCIe controller which can be used as Root Complex. This driver supports a PCIe controller as Root Complex mode.
---
Tested on Exynos5440.
Changes since v3:
- Supported multi domains
- Removed 'bus-range' property from DT
- Added 'interrupt-map-mask', 'interrupt-map' properties to DT
- Fixed the start address of MEM space in DT
- Increased the size of I/O space to 64kB in DT
- Added 'clocks', 'clock-names' properties to DT
- Removed redundant physical addresses from struct pcie_port
- Added clock enable/disable
- Used devm_ioremap_resource()
.../devicetree/bindings/pci/exynos-pcie.txt | 71 ++ drivers/pci/host/Kconfig | 5 + drivers/pci/host/Makefile | 1 + drivers/pci/host/pci-exynos.c | 1074 ++++++++++++++++++++ 4 files changed, 1151 insertions(+) create mode 100644 Documentation/devicetree/bindings/pci/exynos-pcie.txt create mode 100644 drivers/pci/host/pci-exynos.c
Documentation/devicetree/bindings/pci/exynos-pcie.txt new file +71 -0
@@ -0,0 +1,71 @@ +* Samsung Exynos PCIe interface + +Required properties: +-compatible: should be "samsung,exynos5440-pcie" +-reg: base addresses and lengths of the pcie conteroller, + the phy controller, additional register for the phy controller. +- interrupts: interrupt values for level interrupt, + pulse interrupt, special interrupt. +- clocks: from common clock binding: handle to pci clock. +- clock-names: from common clock binding: Shall be "pcie", "pcie_bus". +- #address-cells, set to <3> +- #size-cells, set to <2> +- device_type, set to "pci" +- ranges: ranges for the PCI memory and I/O regions +- #interrupt-cells, set to <1> +- interrupt-map-mask and interrupt-map: standard PCI properties + to define the mapping of the PCIe interface to interrupt + numbers. +- reset-gpio: gpio pin number of power good signal + +Example: + +SoC specific DT Entry: + + pcie0 at 0x290000 { + compatible = "samsung,exynos5440-pcie"; + reg = <0x290000 0x1000 + 0x270000 0x1000 + 0x271000 0x40>; + interrupts = <0 20 0>, <0 21 0>, <0 22 0>; + clocks = <&clock 28>, <&clock 27>; + clock-names = "pcie", "pcie_bus"; + #address-cells = <3>; + #size-cells = <2>; + device_type = "pci"; + ranges = <0x00000800 0 0x40000000 0x40000000 0 0x00200000 /* configuration space */ + 0x81000000 0 0 0x40200000 0 0x00010000 /* downstream I/O */ + 0x82000000 0 0x40210000 0x40210000 0 0x10000000>; /* non-prefetchable memory */ + #interrupt-cells = <1>; + interrupt-map-mask = <0 0 0 0>; + interrupt-map = <0x0 0 &gic 53>; + }; + + pcie1 at 2a0000 { + compatible = "samsung,exynos5440-pcie"; + reg = <0x2a0000 0x1000 + 0x272000 0x1000 + 0x271040 0x40>; + interrupts = <0 23 0>, <0 24 0>, <0 25 0>; + clocks = <&clock 29>, <&clock 27>; + clock-names = "pcie", "pcie_bus"; + #address-cells = <3>; + #size-cells = <2>; + device_type = "pci"; + ranges = <0x00000800 0 0x60000000 0x60000000 0 0x00200000 /* configuration space */ + 0x81000000 0 0 0x60200000 0 0x00010000 /* downstream I/O */ + 0x82000000 0 0x60210000 0x60210000 0 0x10000000>; /* non-prefetchable memory */ + #interrupt-cells = <1>; + interrupt-map-mask = <0 0 0 0>; + interrupt-map = <0x0 0 &gic 56>; + }; + +Board specific DT Entry: + + pcie0 at 40000000 { + reset-gpio = <5>; + }; + + pcie1 at 60000000 { + reset-gpio = <22>; + };
drivers/pci/host/Kconfig +5 -0
@@ -5,4 +5,9 @@ config PCI_MVEBU bool "Marvell EBU PCIe controller" depends on ARCH_MVEBU || ARCH_KIRKWOOD +config PCI_EXYNOS + bool "Samsung Exynos PCIe controller" + depends on SOC_EXYNOS5440 + select PCIEPORTBUS + endmenu
drivers/pci/host/Makefile +1 -0
@@ -1 +1,2 @@ obj-$(CONFIG_PCI_MVEBU) += pci-mvebu.o +obj-$(CONFIG_PCI_EXYNOS) += pci-exynos.o
drivers/pci/host/pci-exynos.c new file +1074 -0
1,074 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Quoted 15 lines · On Wednesday 12 June 2013 19:19:05 Jingoo Han wrote:
drivers/pci/host/pci-exynos.c new file +15
-0+ +struct pcie_port { +struct device *dev; +u8 controller; +u8 root_bus_nr; +void __iomem *dbi_base; +void __iomem *elbi_base; +void __iomem *phy_base; +void __iomem *purple_base; +phys_addr_t cfg0_base; +void __iomem *va_cfg0_base; +phys_addr_t cfg1_base; +void __iomem *va_cfg1_base; +phys_addr_t io_base; +phys_addr_t mem_base;
drivers/pci/host/pci-exynos.c line 63
Quoted 10 lines
drivers/pci/host/pci-exynos.c new file +10
-0+spinlock_t conf_lock; +struct resource cfg; +struct resource io; +struct resource mem; +struct pcie_port_info config; +struct clk *clk; +struct clk *bus_clk; +int irq; +int reset_gpio; +};
This looks much better now.
drivers/pci/host/pci-exynos.c line 68
Quoted 5 lines
drivers/pci/host/pci-exynos.c new file +5
-0+ +/* synopsis specific PCIE configuration registers*/ +#define PCIE_PORT_LINK_CONTROL 0x710 +#define PORT_LINK_MODE_MASK (0x3f << 16) +#define PORT_LINK_MODE_4_LANES (0x7 << 16)
Do you mean this is a "Synopsys" designware part? In that case it should really not be called "exynos-pcie" but "designware-pcie" and you should make sure that the driver makes no assumptions about the platform. A lot of other platforms also use designware parts and should be able to reuse this driver.
Quoted 8 lines
drivers/pci/host/pci-exynos.c new file +8
-0+static void exynos_pcie_prog_viewport_cfg0 (struct pcie_port *pp,u32 busdev) +{ +u32 val; +void __iomem *dbi_base = pp->dbi_base; + +/* Program viewport 0 : OUTBOUND : CFG0 */ + val =PCIE_ATU_REGION_OUTBOUND |PCIE_ATU_REGION_INDEX0 ; +writel_rc (pp, val, dbi_base +PCIE_ATU_VIEWPORT );
drivers/pci/host/pci-exynos.c line 276
Quoted 10 lines
drivers/pci/host/pci-exynos.c new file +10
-0+writel_rc (pp, (u32 )pp->cfg0_base, dbi_base +PCIE_ATU_LOWER_BASE ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_UPPER_BASE ); +writel_rc (pp, (u32 )pp->cfg0_base + pp->config.cfg0_size -1 , + dbi_base +PCIE_ATU_LIMIT ); +writel_rc (pp, busdev, dbi_base +PCIE_ATU_LOWER_TARGET ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_UPPER_TARGET ); +writel_rc (pp,PCIE_ATU_TYPE_CFG0 , dbi_base +PCIE_ATU_CR1 ); + val =PCIE_ATU_ENABLE ; +writel_rc (pp, val, dbi_base +PCIE_ATU_CR2 ); +}
I think you should not assume that the physical base address is a 32 bit value. The hardware clearly supports "lower" and "upper" halves for the address window, so when resource_size_t is 64 bit, you should set the upper half accordingly. Since the hardware is always 64 bit, you can use a "u64" type rather than resource_size_t to simplify the code here.
Quoted 8 lines
drivers/pci/host/pci-exynos.c new file +8
-0+static void exynos_pcie_prog_viewport_mem_outbound (struct pcie_port *pp) +{ +u32 val; +void __iomem *dbi_base = pp->dbi_base; + +/* Program viewport 0 : OUTBOUND : MEM */ + val =PCIE_ATU_REGION_OUTBOUND |PCIE_ATU_REGION_INDEX0 ; +writel_rc (pp, val, dbi_base +PCIE_ATU_VIEWPORT );
drivers/pci/host/pci-exynos.c line 314
Quoted 10 lines
drivers/pci/host/pci-exynos.c new file +10
-0+writel_rc (pp,PCIE_ATU_TYPE_MEM , dbi_base +PCIE_ATU_CR1 ); + val =PCIE_ATU_ENABLE ; +writel_rc (pp, val, dbi_base +PCIE_ATU_CR2 ); +writel_rc (pp, (u32 )pp->mem_base, dbi_base +PCIE_ATU_LOWER_BASE ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_UPPER_BASE ); +writel_rc (pp, (u32)(pp->mem_base + pp->config.mem_size -1 ), + dbi_base +PCIE_ATU_LIMIT ); +writel_rc (pp, (u32 )pp->mem_base, dbi_base +PCIE_ATU_LOWER_TARGET ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_UPPER_TARGET ); +}
You probably should not assume that there is a 1:1 mapping between bus addresses and host physical addresses, but rather read both values from the DT individually. With the ranges defined as
0x82000000 0 0x40210000 0x40210000 0 0x10000000>; /* non-prefetchable memory */
the second and third cell should go into PCIE_ATU_UPPER_TARGET/PCIE_ATU_LOWER_TARGET, while the translated address (from the third cell) should go into PCIE_ATU_LOWER_BASE/PCIE_ATU_UPPER_BASE
The PCIE_ATU_LIMIT seems to correctly get translated from the last cell.
Quoted 8 lines
drivers/pci/host/pci-exynos.c new file +8
-0+static void exynos_pcie_prog_viewport_io_outbound (struct pcie_port *pp) +{ +u32 val; +void __iomem *dbi_base = pp->dbi_base; + +/* Program viewport 1 : OUTBOUND : IO */ + val =PCIE_ATU_REGION_OUTBOUND |PCIE_ATU_REGION_INDEX1 ; +writel_rc (pp, val, dbi_base +PCIE_ATU_VIEWPORT );
drivers/pci/host/pci-exynos.c line 333
Quoted 10 lines
drivers/pci/host/pci-exynos.c new file +10
-0+writel_rc (pp,PCIE_ATU_TYPE_IO , dbi_base +PCIE_ATU_CR1 ); + val =PCIE_ATU_ENABLE ; +writel_rc (pp, val, dbi_base +PCIE_ATU_CR2 ); +writel_rc (pp, (u32 )pp->io_base, dbi_base +PCIE_ATU_LOWER_BASE ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_UPPER_BASE ); +writel_rc (pp, (u32)(pp->io_base + pp->config.io_size -1 ), + dbi_base +PCIE_ATU_LIMIT ); +writel_rc (pp, (u32 )pp->io_base, dbi_base +PCIE_ATU_LOWER_TARGET ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_UPPER_TARGET ); +}
You don't actually map the I/O space anywhere into virtual memory. I think you need to call pci_ioremap_io with the pp->io_base at boot time.
I think you mixed up the PCIE_ATU_LOWER_TARGET, it should really be 0, since all I/O port numbers have to be smaller than IO_SPACE_LIMIT.
The first argument to pci_ioremap_io needs to be unique for each domain and you need to use it to calculate the io_offset you set in pci_sys_data->io_offset.
Quoted 8 lines
drivers/pci/host/pci-exynos.c new file +8
-0+static void exynos_pcie_prog_viewport_mem_inbound (struct pcie_port *pp) +{ +u32 val; +void __iomem *dbi_base = pp->dbi_base; +struct pcie_port_info *config = &pp->config; + +/* Program viewport 0 : INBOUND : MEMORY */ + val =PCIE_ATU_REGION_INBOUND |PCIE_ATU_REGION_INDEX0 ;
drivers/pci/host/pci-exynos.c line 352
Quoted 10 lines
drivers/pci/host/pci-exynos.c new file +10
-0+writel_rc (pp, val, dbi_base +PCIE_ATU_VIEWPORT ); +writel_rc (pp,PCIE_ATU_TYPE_MEM , dbi_base +PCIE_ATU_CR1 ); + val =PCIE_ATU_ENABLE |PCIE_ATU_BAR_MODE_ENABLE ; +writel_rc (pp, val, dbi_base +PCIE_ATU_CR2 ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_LOWER_BASE ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_UPPER_BASE ); +writel_rc (pp, config->in_mem_size -1 , dbi_base +PCIE_ATU_LIMIT ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_LOWER_TARGET ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_UPPER_TARGET ); +}
You hardcode the in_mem_size to 256 MB. Does that mean you only allow PCI bus master DMA on the first part of RAM? Shouldn't it get computed from the actual location and size of RAM?
Quoted 8 lines
drivers/pci/host/pci-exynos.c new file +8
-0+static void exynos_pcie_prog_viewport_io_inbound (struct pcie_port *pp) +{ +u32 val; +void __iomem *dbi_base = pp->dbi_base; +struct pcie_port_info *config = &pp->config; + +/* Program viewport 1 : INBOUND : IO */ + val =PCIE_ATU_REGION_INBOUND |PCIE_ATU_REGION_INDEX1 ;
drivers/pci/host/pci-exynos.c line 371
Quoted 10 lines
drivers/pci/host/pci-exynos.c new file +10
-0+writel_rc (pp, val, dbi_base +PCIE_ATU_VIEWPORT ); +writel_rc (pp,PCIE_ATU_TYPE_IO , dbi_base +PCIE_ATU_CR1 ); + val =PCIE_ATU_ENABLE |PCIE_ATU_BAR_MODE_ENABLE ; +writel_rc (pp, val, dbi_base +PCIE_ATU_CR2 ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_LOWER_BASE ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_UPPER_BASE ); +writel_rc (pp, config->in_mem_size -1 , dbi_base +PCIE_ATU_LIMIT ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_LOWER_TARGET ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_UPPER_TARGET ); +}
I don't understand what in inbound I/O access actually means. What does this do, is it for PCI target emulation?
Quoted 5 lines
drivers/pci/host/pci-exynos.c new file +5
-0+ +static int exynos_pcie_setup (int nr,struct pci_sys_data *sys) +{ +struct pcie_port *pp; +
drivers/pci/host/pci-exynos.c line 432
Quoted 10 lines
drivers/pci/host/pci-exynos.c new file +10
-0+ pp =sys_to_pcie (sys); + +if (!pp) +return 0 ; + +pci_add_resource_offset (&sys->resources, &pp->io, sys->io_offset); +pci_add_resource_offset (&sys->resources, &pp->mem, sys->mem_offset); + +return 1 ; +}
You don't actually set up io_offset and mem_offset, right?
Arnd
Quoted 30 lines · Arnd Bergmann
Quoted 15 lines · On Wednesday 12 June 2013 19:19:05 Jingoo Han wrote:
drivers/pci/host/pci-exynos.c new file +15
-0+ +struct pcie_port { +struct device *dev; +u8 controller; +u8 root_bus_nr; +void __iomem *dbi_base; +void __iomem *elbi_base; +void __iomem *phy_base; +void __iomem *purple_base; +phys_addr_t cfg0_base; +void __iomem *va_cfg0_base; +phys_addr_t cfg1_base; +void __iomem *va_cfg1_base; +phys_addr_t io_base; +phys_addr_t mem_base;drivers/pci/host/pci-exynos.c line 63
Quoted 10 lines
drivers/pci/host/pci-exynos.c new file +10
-0+spinlock_t conf_lock; +struct resource cfg; +struct resource io; +struct resource mem; +struct pcie_port_info config; +struct clk *clk; +struct clk *bus_clk; +int irq; +int reset_gpio; +};This looks much better now.
Quoted 11 lines
drivers/pci/host/pci-exynos.c line 68
Quoted 5 lines
drivers/pci/host/pci-exynos.c new file +5
-0+ +/* synopsis specific PCIE configuration registers*/ +#define PCIE_PORT_LINK_CONTROL 0x710 +#define PORT_LINK_MODE_MASK (0x3f << 16) +#define PORT_LINK_MODE_4_LANES (0x7 << 16)Do you mean this is a "Synopsys" designware part? In that case it should really not be called "exynos-pcie" but "designware-pcie" and you should make sure that the driver makes no assumptions about the platform. A lot of other platforms also use designware parts and should be able to reuse this driver.
Sorry, I don't think so.
Only core block is a "Synopsys" designware part IP block, other parts are Exynos-specific.
So, it is hard to share with other PCIe IPs using synopsis core.
Quoted 18 lines
Quoted 18 lines
drivers/pci/host/pci-exynos.c new file +17
-0+static void exynos_pcie_prog_viewport_cfg0 (struct pcie_port *pp,u32 busdev) +{ +u32 val; +void __iomem *dbi_base = pp->dbi_base; + +/* Program viewport 0 : OUTBOUND : CFG0 */ + val =PCIE_ATU_REGION_OUTBOUND |PCIE_ATU_REGION_INDEX0 ; +writel_rc (pp, val, dbi_base +PCIE_ATU_VIEWPORT ); +writel_rc (pp, (u32 )pp->cfg0_base, dbi_base +PCIE_ATU_LOWER_BASE ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_UPPER_BASE ); +writel_rc (pp, (u32 )pp->cfg0_base + pp->config.cfg0_size -1 , + dbi_base +PCIE_ATU_LIMIT ); +writel_rc (pp, busdev, dbi_base +PCIE_ATU_LOWER_TARGET ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_UPPER_TARGET ); +writel_rc (pp,PCIE_ATU_TYPE_CFG0 , dbi_base +PCIE_ATU_CR1 ); + val =PCIE_ATU_ENABLE ; +writel_rc (pp, val, dbi_base +PCIE_ATU_CR2 );
Quoted 8 lines
Quoted 1 line
+}
I think you should not assume that the physical base address is a 32 bit value. The hardware clearly supports "lower" and "upper" halves for the address window, so when
resource_size_tis 64 bit, you should set the upper half accordingly. Since the hardware is always 64 bit, you can use a "u64" type rather thanresource_size_tto simplify the code here.
OK, I will replace "u32" with "u64".
Quoted 24 lines
Quoted 9 lines
drivers/pci/host/pci-exynos.c new file +8
-0+static void exynos_pcie_prog_viewport_mem_outbound (struct pcie_port *pp) +{ +u32 val; +void __iomem *dbi_base = pp->dbi_base; + +/* Program viewport 0 : OUTBOUND : MEM */ + val =PCIE_ATU_REGION_OUTBOUND |PCIE_ATU_REGION_INDEX0 ; +writel_rc (pp, val, dbi_base +PCIE_ATU_VIEWPORT );drivers/pci/host/pci-exynos.c line 314
Quoted 10 lines
drivers/pci/host/pci-exynos.c new file +10
-0+writel_rc (pp,PCIE_ATU_TYPE_MEM , dbi_base +PCIE_ATU_CR1 ); + val =PCIE_ATU_ENABLE ; +writel_rc (pp, val, dbi_base +PCIE_ATU_CR2 ); +writel_rc (pp, (u32 )pp->mem_base, dbi_base +PCIE_ATU_LOWER_BASE ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_UPPER_BASE ); +writel_rc (pp, (u32)(pp->mem_base + pp->config.mem_size -1 ), + dbi_base +PCIE_ATU_LIMIT ); +writel_rc (pp, (u32 )pp->mem_base, dbi_base +PCIE_ATU_LOWER_TARGET ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_UPPER_TARGET ); +}You probably should not assume that there is a 1:1 mapping between bus addresses and host physical addresses, but rather read both values from the DT individually. With the ranges defined as
Quoted 8 lines
0x82000000 0 0x40210000 0x40210000 0 0x10000000>; /* non-prefetchable memory */the second and third cell should go into PCIE_ATU_UPPER_TARGET/PCIE_ATU_LOWER_TARGET, while the translated address (from the third cell) should go into PCIE_ATU_LOWER_BASE/PCIE_ATU_UPPER_BASE
The
PCIE_ATU_LIMITseems to correctly get translated from the last cell.
OK, I will change it.
Quoted 15 lines
Quoted 15 lines
drivers/pci/host/pci-exynos.c new file +14
-0+static void exynos_pcie_prog_viewport_io_outbound (struct pcie_port *pp) +{ +u32 val; +void __iomem *dbi_base = pp->dbi_base; + +/* Program viewport 1 : OUTBOUND : IO */ + val =PCIE_ATU_REGION_OUTBOUND |PCIE_ATU_REGION_INDEX1 ; +writel_rc (pp, val, dbi_base +PCIE_ATU_VIEWPORT ); +writel_rc (pp,PCIE_ATU_TYPE_IO , dbi_base +PCIE_ATU_CR1 ); + val =PCIE_ATU_ENABLE ; +writel_rc (pp, val, dbi_base +PCIE_ATU_CR2 ); +writel_rc (pp, (u32 )pp->io_base, dbi_base +PCIE_ATU_LOWER_BASE ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_UPPER_BASE ); + writel_rc(pp, (u32)(pp->io_base + pp->config.io_size - 1),
Quoted 8 lines
drivers/pci/host/pci-exynos.c line 333
Quoted 4 lines
drivers/pci/host/pci-exynos.c new file +4
-0+ dbi_base + PCIE_ATU_LIMIT); +writel_rc (pp, (u32 )pp->io_base, dbi_base +PCIE_ATU_LOWER_TARGET ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_UPPER_TARGET ); +}You don't actually map the I/O space anywhere into virtual memory. I think you need to call
pci_ioremap_iowith thepp->io_baseat boot time.
Sorry, when pci_ioremap_io() is used, Exynos5440 hangs. I don't know how to deal this.
Quoted 22 lines
I think you mixed up the
PCIE_ATU_LOWER_TARGET, it should really be 0, since all I/O port numbers have to be smaller thanIO_SPACE_LIMIT.The first argument to
pci_ioremap_ioneeds to be unique for each domain and you need to use it to calculate theio_offsetyou set inpci_sys_data->io_offset.Quoted 14 lines
drivers/pci/host/pci-exynos.c new file +14
-0+static void exynos_pcie_prog_viewport_mem_inbound (struct pcie_port *pp) +{ +u32 val; +void __iomem *dbi_base = pp->dbi_base; +struct pcie_port_info *config = &pp->config; + +/* Program viewport 0 : INBOUND : MEMORY */ + val =PCIE_ATU_REGION_INBOUND |PCIE_ATU_REGION_INDEX0 ; +writel_rc (pp, val, dbi_base +PCIE_ATU_VIEWPORT ); +writel_rc (pp,PCIE_ATU_TYPE_MEM , dbi_base +PCIE_ATU_CR1 ); + val =PCIE_ATU_ENABLE |PCIE_ATU_BAR_MODE_ENABLE ; +writel_rc (pp, val, dbi_base +PCIE_ATU_CR2 ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_LOWER_BASE ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_UPPER_BASE );
Quoted 8 lines
drivers/pci/host/pci-exynos.c line 352
Quoted 4 lines
drivers/pci/host/pci-exynos.c new file +4
-0+writel_rc (pp, config->in_mem_size -1 , dbi_base +PCIE_ATU_LIMIT ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_LOWER_TARGET ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_UPPER_TARGET ); +}You hardcode the
in_mem_sizeto 256 MB. Does that mean you only allow PCI bus master DMA on the first part of RAM? Shouldn't it get computed from the actual location and size of RAM?
I will remove the hard-coded in_mem_size, instead use the size of MEM region.
Quoted 14 lines
Quoted 14 lines
drivers/pci/host/pci-exynos.c new file +13
-0+static void exynos_pcie_prog_viewport_io_inbound (struct pcie_port *pp) +{ +u32 val; +void __iomem *dbi_base = pp->dbi_base; +struct pcie_port_info *config = &pp->config; + +/* Program viewport 1 : INBOUND : IO */ + val =PCIE_ATU_REGION_INBOUND |PCIE_ATU_REGION_INDEX1 ; +writel_rc (pp, val, dbi_base +PCIE_ATU_VIEWPORT ); +writel_rc (pp,PCIE_ATU_TYPE_IO , dbi_base +PCIE_ATU_CR1 ); + val =PCIE_ATU_ENABLE |PCIE_ATU_BAR_MODE_ENABLE ; +writel_rc (pp, val, dbi_base +PCIE_ATU_CR2 ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_LOWER_BASE );
Quoted 8 lines
drivers/pci/host/pci-exynos.c line 352
Quoted 5 lines
drivers/pci/host/pci-exynos.c new file +5
-0+writel_rc (pp,0 , dbi_base +PCIE_ATU_UPPER_BASE ); +writel_rc (pp, config->in_mem_size -1 , dbi_base +PCIE_ATU_LIMIT ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_LOWER_TARGET ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_UPPER_TARGET ); +}I don't understand what in inbound I/O access actually means. What does this do, is it for PCI target emulation?
I reviewed the manual, and I will fix it.
I will add bus addresses and host physical addresses to PCIE_ATU_LOWER_BASE/ PCIE_ATU_LOWER_TARGET.
Quoted 10 lines
Quoted 10 lines
drivers/pci/host/pci-exynos.c new file +9
-0+ +static int exynos_pcie_setup (int nr,struct pci_sys_data *sys) +{ +struct pcie_port *pp; + + pp =sys_to_pcie (sys); + +if (!pp) +return 0 ;
Quoted 8 lines
drivers/pci/host/pci-exynos.c line 432
Quoted 6 lines
drivers/pci/host/pci-exynos.c new file +6
-0+ +pci_add_resource_offset (&sys->resources, &pp->io, sys->io_offset); +pci_add_resource_offset (&sys->resources, &pp->mem, sys->mem_offset); + +return 1 ; +}You don't actually set up
io_offsetandmem_offset, right?
OK, I will replace pci_add_resource_offset() with pci_add_resource().
Best regards,
Jingoo Han
Quoted 2 lines
Arnd
Quoted 15 lines · On Thursday 13 June 2013 22:18:50 Jingoo Han wrote:
Quoted 13 lines · Arnd Bergmann
drivers/pci/host/pci-exynos.c line 68
Quoted 5 lines · On Wednesday 12 June 2013 19:19:05 Jingoo Han wrote:
drivers/pci/host/pci-exynos.c new file +5
-0+ +/* synopsis specific PCIE configuration registers*/ +#define PCIE_PORT_LINK_CONTROL 0x710 +#define PORT_LINK_MODE_MASK (0x3f << 16) +#define PORT_LINK_MODE_4_LANES (0x7 << 16)Do you mean this is a "Synopsys" designware part? In that case it should really not be called "exynos-pcie" but "designware-pcie" and you should make sure that the driver makes no assumptions about the platform. A lot of other platforms also use designware parts and should be able to reuse this driver.
Quoted 4 lines
Sorry, I don't think so.
Only core block is a "Synopsys" designware part IP block, other parts are Exynos-specific.
So, it is hard to share with other PCIe IPs using synopsis core.
Just call it synopsys anyway and put a comment in to explain this. That should be enough for the next person with a synopsys PCI core to reuse your code and split out the exynos specific parts into a separate file.
Quoted 8 lines
Quoted 6 lines
I think you should not assume that the physical base address is a 32 bit value. The hardware clearly supports "lower" and "upper" halves for the address window, so when
resource_size_tis 64 bit, you should set the upper half accordingly. Since the hardware is always 64 bit, you can use a "u64" type rather thanresource_size_tto simplify the code here.OK, I will replace "u32" with "u64".
Not what I meant, please read it again.
Quoted 23 lines
Quoted 14 lines
Quoted 14 lines
drivers/pci/host/pci-exynos.c new file +14
-0+static void exynos_pcie_prog_viewport_io_outbound (struct pcie_port *pp) +{ +u32 val; +void __iomem *dbi_base = pp->dbi_base; + +/* Program viewport 1 : OUTBOUND : IO */ + val =PCIE_ATU_REGION_OUTBOUND |PCIE_ATU_REGION_INDEX1 ; +writel_rc (pp, val, dbi_base +PCIE_ATU_VIEWPORT ); +writel_rc (pp,PCIE_ATU_TYPE_IO , dbi_base +PCIE_ATU_CR1 ); + val =PCIE_ATU_ENABLE ; +writel_rc (pp, val, dbi_base +PCIE_ATU_CR2 ); +writel_rc (pp, (u32 )pp->io_base, dbi_base +PCIE_ATU_LOWER_BASE ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_UPPER_BASE ); + writel_rc(pp, (u32)(pp->io_base + pp->config.io_size - 1),Quoted 8 lines
drivers/pci/host/pci-exynos.c line 333
Quoted 4 lines
drivers/pci/host/pci-exynos.c new file +4
-0+ dbi_base + PCIE_ATU_LIMIT); +writel_rc (pp, (u32 )pp->io_base, dbi_base +PCIE_ATU_LOWER_TARGET ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_UPPER_TARGET ); +}You don't actually map the I/O space anywhere into virtual memory. I think you need to call
pci_ioremap_iowith thepp->io_baseat boot time.
Quoted 2 lines
Sorry, when
pci_ioremap_io()is used, Exynos5440 hangs. I don't know how to deal this.
You have to call it, there is no way around that. You will have to debug this yourself, I'm sure there is an easy solution.
Quoted 6 lines
Quoted 4 lines
You hardcode the
in_mem_sizeto 256 MB. Does that mean you only allow PCI bus master DMA on the first part of RAM? Shouldn't it get computed from the actual location and size of RAM?I will remove the hard-coded
in_mem_size, instead use the size of MEM region.
This should be system RAM, not the PCI memory space. What good would it be to have an inbound window that only redirects back to the bus?
Quoted 22 lines
Quoted 13 lines
Quoted 13 lines
drivers/pci/host/pci-exynos.c new file +13
-0+static void exynos_pcie_prog_viewport_io_inbound (struct pcie_port *pp) +{ +u32 val; +void __iomem *dbi_base = pp->dbi_base; +struct pcie_port_info *config = &pp->config; + +/* Program viewport 1 : INBOUND : IO */ + val =PCIE_ATU_REGION_INBOUND |PCIE_ATU_REGION_INDEX1 ; +writel_rc (pp, val, dbi_base +PCIE_ATU_VIEWPORT ); +writel_rc (pp,PCIE_ATU_TYPE_IO , dbi_base +PCIE_ATU_CR1 ); + val =PCIE_ATU_ENABLE |PCIE_ATU_BAR_MODE_ENABLE ; +writel_rc (pp, val, dbi_base +PCIE_ATU_CR2 ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_LOWER_BASE );Quoted 8 lines
drivers/pci/host/pci-exynos.c line 352
Quoted 5 lines
drivers/pci/host/pci-exynos.c new file +5
-0+writel_rc (pp,0 , dbi_base +PCIE_ATU_UPPER_BASE ); +writel_rc (pp, config->in_mem_size -1 , dbi_base +PCIE_ATU_LIMIT ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_LOWER_TARGET ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_UPPER_TARGET ); +}I don't understand what in inbound I/O access actually means. What does this do, is it for PCI target emulation?
Quoted 3 lines
I reviewed the manual, and I will fix it.
I will add bus addresses and host physical addresses to PCIE_ATU_LOWER_BASE/PCIE_ATU_LOWER_TARGET.
You have not answered my question.
Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
drivers/pci/host/pci-exynos.c new file +8
-0+static int exynos_pcie_setup (int nr,struct pci_sys_data *sys) +{ +struct pcie_port *pp; + + pp =sys_to_pcie (sys); + +if (!pp) +return 0 ;Quoted 8 lines
drivers/pci/host/pci-exynos.c line 432
Quoted 6 lines
drivers/pci/host/pci-exynos.c new file +6
-0+ +pci_add_resource_offset (&sys->resources, &pp->io, sys->io_offset); +pci_add_resource_offset (&sys->resources, &pp->mem, sys->mem_offset); + +return 1 ; +}You don't actually set up
io_offsetandmem_offset, right?
Quoted 1 line
OK, I will replace
pci_add_resource_offset()withpci_add_resource().
No, you have to set up the offsets.
Please don't post another version until you actually understand what you need to do. If you don't understand the comments, ask back rather than picking a random interpretation.
Arnd
Quoted 15 lines · Arnd Bergmann
Quoted 14 lines · On Thursday 13 June 2013 22:18:50 Jingoo Han wrote:
Quoted 14 lines · Arnd Bergmann
Quoted 12 lines
Quoted 12 lines · On Wednesday 12 June 2013 19:19:05 Jingoo Han wrote:
Quoted 5 lines
drivers/pci/host/pci-exynos.c line 68
Quoted 5 lines
drivers/pci/host/pci-exynos.c new file +5
-0+ +/* synopsis specific PCIE configuration registers*/ +#define PCIE_PORT_LINK_CONTROL 0x710 +#define PORT_LINK_MODE_MASK (0x3f << 16) +#define PORT_LINK_MODE_4_LANES (0x7 << 16)Do you mean this is a "Synopsys" designware part? In that case it should really not be called "exynos-pcie" but "designware-pcie" and you should make sure that the driver makes no assumptions about the platform. A lot of other platforms also use designware parts and should be able to reuse this driver.
Quoted 9 lines
Quoted 4 lines
Quoted 4 lines
Sorry, I don't think so.
Only core block is a "Synopsys" designware part IP block, other parts are Exynos-specific.
So, it is hard to share with other PCIe IPs using synopsis core.Just call it synopsys anyway and put a comment in to explain this. That should be enough for the next person with a synopsys PCI core to reuse your code and split out the exynos specific parts into a separate file.
I agree to Arnd that this patch should be split. I had worked in past with SPEAr PCIe which also had designware PCIe IP. I see some code which will fit both in SPEAr as well as in exynos. Unfortunately, I was not able to get SPEAr driver pushed to mainline, as I moved to some other project and got heavily occupied.
Last patch is here:
https://patchwork.kernel.org/patch/1661441/
Infact, these functions should be common to all arm platforms.
sys_to_pciecfg_readcfg_write
Following functions should be common to all designware based driver (at least they are same in SPEAr)
exynos_pcie_prog_viewport_cfg0exynos_pcie_prog_viewport_cfg1exynos_pcie_rd_other_confexynos_pcie_wr_other_confexynos_pcie_setupexynos_pcie_valid_configexynos_pcie_rd_confexynos_pcie_wd_confexynos_pcie_scan_busexynos_pcie_map_irqadd_pcie_port (after a bit of generalization)exynos_pcie_probeexynos_pcie_remove
Following should be specific to exynos:
exynos_pcie_rd_own_confexynos_pcie_wr_own_confexynos_pcie_link_upexynos_pcie_setup_rcexynos_pcie_assert_core_resetexynos_pcie_deassert_core_resetexynos_pcie_assert_phy_resetexynos_pcie_deassert_phy_resetexynos_pcie_init_phyexynos_pcie_assert_resetexynos_pcie_establish_linkexynos_pcie_host_init
struct pcie_port_info and struct pcie_port can also be standardized.
Regards
Pratyush
Quoted 26 lines · Pratyush Anand
Quoted 15 lines · Arnd Bergmann
Quoted 14 lines · On Thursday 13 June 2013 22:18:50 Jingoo Han wrote:
Quoted 14 lines · Arnd Bergmann
Quoted 12 lines
Quoted 12 lines · On Wednesday 12 June 2013 19:19:05 Jingoo Han wrote:
Quoted 5 lines
drivers/pci/host/pci-exynos.c line 68
Quoted 5 lines
drivers/pci/host/pci-exynos.c new file +5
-0+ +/* synopsis specific PCIE configuration registers*/ +#define PCIE_PORT_LINK_CONTROL 0x710 +#define PORT_LINK_MODE_MASK (0x3f << 16) +#define PORT_LINK_MODE_4_LANES (0x7 << 16)Do you mean this is a "Synopsys" designware part? In that case it should really not be called "exynos-pcie" but "designware-pcie" and you should make sure that the driver makes no assumptions about the platform. A lot of other platforms also use designware parts and should be able to reuse this driver.
Quoted 9 lines
Quoted 4 lines
Quoted 4 lines
Sorry, I don't think so.
Only core block is a "Synopsys" designware part IP block, other parts are Exynos-specific.
So, it is hard to share with other PCIe IPs using synopsis core.Just call it synopsys anyway and put a comment in to explain this. That should be enough for the next person with a synopsys PCI core to reuse your code and split out the exynos specific parts into a separate file.
Quoted 5 lines
I agree to Arnd that this patch should be split. I had worked in past with SPEAr PCIe which also had designware PCIe IP. I see some code which will fit both in SPEAr as well as in exynos. Unfortunately, I was not able to get SPEAr driver pushed to mainline, as I moved to some other project and got heavily occupied.
Oh, I see.
How about this?
At the next PATCH v7, I will change the file name from 'pci-exynos.c' to 'pci-designware.c', as Arnd mentioned.
Then, when Spear or other platform using designware is submitted, this 'pci-designware.c' will be split to two separate files such as 'pci-designware.c' and 'pci-exynos.c'.
Best regards,
Jingoo Han
Quoted 51 lines
Last patch is here:
https://patchwork.kernel.org/patch/1661441/
Infact, these functions should be common to all arm platforms.
sys_to_pciecfg_readcfg_writeFollowing functions should be common to all designware based driver (at least they are same in SPEAr)
exynos_pcie_prog_viewport_cfg0exynos_pcie_prog_viewport_cfg1exynos_pcie_rd_other_confexynos_pcie_wr_other_confexynos_pcie_setupexynos_pcie_valid_configexynos_pcie_rd_confexynos_pcie_wd_confexynos_pcie_scan_busexynos_pcie_map_irqadd_pcie_port(after a bit of generalization)exynos_pcie_probeexynos_pcie_removeFollowing should be specific to exynos:
exynos_pcie_rd_own_confexynos_pcie_wr_own_confexynos_pcie_link_upexynos_pcie_setup_rcexynos_pcie_assert_core_resetexynos_pcie_deassert_core_resetexynos_pcie_assert_phy_resetexynos_pcie_deassert_phy_resetexynos_pcie_init_phyexynos_pcie_assert_resetexynos_pcie_establish_linkexynos_pcie_host_initstruct
pcie_port_infoand structpcie_portcan also be standardized.Regards
Pratyush
Hi,
Quoted 35 lines · Jingoo Han
Quoted 26 lines · Pratyush Anand
Quoted 15 lines · Arnd Bergmann
Quoted 14 lines · On Thursday 13 June 2013 22:18:50 Jingoo Han wrote:
Quoted 14 lines · Arnd Bergmann
Quoted 12 lines
Quoted 12 lines · On Wednesday 12 June 2013 19:19:05 Jingoo Han wrote:
Quoted 5 lines
drivers/pci/host/pci-exynos.c line 68
Quoted 5 lines
drivers/pci/host/pci-exynos.c new file +5
-0+ +/* synopsis specific PCIE configuration registers*/ +#define PCIE_PORT_LINK_CONTROL 0x710 +#define PORT_LINK_MODE_MASK (0x3f << 16) +#define PORT_LINK_MODE_4_LANES (0x7 << 16)Do you mean this is a "Synopsys" designware part? In that case it should really not be called "exynos-pcie" but "designware-pcie" and you should make sure that the driver makes no assumptions about the platform. A lot of other platforms also use designware parts and should be able to reuse this driver.
Quoted 9 lines
Quoted 4 lines
Quoted 4 lines
Sorry, I don't think so.
Only core block is a "Synopsys" designware part IP block, other parts are Exynos-specific.
So, it is hard to share with other PCIe IPs using synopsis core.Just call it synopsys anyway and put a comment in to explain this. That should be enough for the next person with a synopsys PCI core to reuse your code and split out the exynos specific parts into a separate file.
Quoted 5 lines
I agree to Arnd that this patch should be split. I had worked in past with SPEAr PCIe which also had designware PCIe IP. I see some code which will fit both in SPEAr as well as in exynos. Unfortunately, I was not able to get SPEAr driver pushed to mainline, as I moved to some other project and got heavily occupied.
Oh, I see.
Quoted 8 lines
How about this?
At the next PATCH v7, I will change the file name from 'pci-exynos.c' to 'pci-designware.c', as Arnd mentioned.Then, when Spear or other platform using designware is submitted, this '
pci-designware.c' will be split to two separate files such as 'pci-designware.c' and 'pci-exynos.c'.
For me it's OK. Let it go to mainline as Arnd mentioned. Please keep Mohit in mail chain, who might have some bandwidth to further add and follow up for SPEAr on top of your patches.
Regards
Pratyush
Quoted 58 lines
Best regards,
Jingoo HanQuoted 47 lines
Last patch is here:
https://patchwork.kernel.org/patch/1661441/
Infact, these functions should be common to all arm platforms.
sys_to_pciecfg_readcfg_writeFollowing functions should be common to all designware based driver (at least they are same in SPEAr)
exynos_pcie_prog_viewport_cfg0exynos_pcie_prog_viewport_cfg1exynos_pcie_rd_other_confexynos_pcie_wr_other_confexynos_pcie_setupexynos_pcie_valid_configexynos_pcie_rd_confexynos_pcie_wd_confexynos_pcie_scan_busexynos_pcie_map_irqadd_pcie_port(after a bit of generalization)exynos_pcie_probeexynos_pcie_removeFollowing should be specific to exynos:
exynos_pcie_rd_own_confexynos_pcie_wr_own_confexynos_pcie_link_upexynos_pcie_setup_rcexynos_pcie_assert_core_resetexynos_pcie_deassert_core_resetexynos_pcie_assert_phy_resetexynos_pcie_deassert_phy_resetexynos_pcie_init_phyexynos_pcie_assert_resetexynos_pcie_establish_linkexynos_pcie_host_initQuoted 4 lines
struct
pcie_port_infoand structpcie_portcan also be standardized.Regards
Pratyush.
Quoted 40 lines · Pratyush Anand
Quoted 39 lines · Jingoo Han
Quoted 26 lines · Pratyush Anand
Quoted 15 lines · Arnd Bergmann
Quoted 14 lines · On Thursday 13 June 2013 22:18:50 Jingoo Han wrote:
Quoted 14 lines · Arnd Bergmann
Quoted 12 lines
Quoted 12 lines · On Wednesday 12 June 2013 19:19:05 Jingoo Han wrote:
Quoted 5 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ +/* synopsis specific PCIE configuration registers*/ +#define PCIE_PORT_LINK_CONTROL 0x710 +#define PORT_LINK_MODE_MASK (0x3f << 16) +#define PORT_LINK_MODE_4_LANES (0x7 << 16)Do you mean this is a "Synopsys" designware part? In that case it should really not be called "exynos-pcie" but "designware-pcie" and you should make sure that the driver makes no assumptions about the platform. A lot of other platforms also use designware parts and should be able to reuse this driver.
Quoted 9 lines
Quoted 4 lines
Quoted 4 lines
Sorry, I don't think so.
Only core block is a "Synopsys" designware part IP block, other parts are Exynos-specific.
So, it is hard to share with other PCIe IPs using synopsis core.Just call it synopsys anyway and put a comment in to explain this. That should be enough for the next person with a synopsys PCI core to reuse your code and split out the exynos specific parts into a separate file.
Quoted 5 lines
I agree to Arnd that this patch should be split. I had worked in past with SPEAr PCIe which also had designware PCIe IP. I see some code which will fit both in SPEAr as well as in exynos. Unfortunately, I was not able to get SPEAr driver pushed to mainline, as I moved to some other project and got heavily occupied.
Oh, I see.
How about this?
At the next PATCH v7, I will change the file name from 'pci-exynos.c' to 'pci-designware.c', as Arnd mentioned.
Quoted 8 lines
Quoted 4 lines
Then, when Spear or other platform using designware is submitted, this '
pci-designware.c' will be split to two separate files such as 'pci-designware.c' and 'pci-exynos.c'.For me it's OK. Let it go to mainline as Arnd mentioned. Please keep Mohit in mail chain, who might have some bandwidth to further add and follow up for SPEAr on top of your patches.
Dear Pratyush Anand,
Thank you for accepting the suggestion. :)
OK, I will keep Mohit in main chain.
Best regards,
Jingoo Han
Quoted 62 lines
Regards
PratyushQuoted 58 lines
Best regards,
Jingoo HanQuoted 47 lines
Last patch is here:
https://patchwork.kernel.org/patch/1661441/
Infact, these functions should be common to all arm platforms.
sys_to_pciecfg_readcfg_writeFollowing functions should be common to all designware based driver (at least they are same in SPEAr)
exynos_pcie_prog_viewport_cfg0exynos_pcie_prog_viewport_cfg1exynos_pcie_rd_other_confexynos_pcie_wr_other_confexynos_pcie_setupexynos_pcie_valid_configexynos_pcie_rd_confexynos_pcie_wd_confexynos_pcie_scan_busexynos_pcie_map_irqadd_pcie_port(after a bit of generalization)exynos_pcie_probeexynos_pcie_removeFollowing should be specific to exynos:
exynos_pcie_rd_own_confexynos_pcie_wr_own_confexynos_pcie_link_upexynos_pcie_setup_rcexynos_pcie_assert_core_resetexynos_pcie_deassert_core_resetexynos_pcie_assert_phy_resetexynos_pcie_deassert_phy_resetexynos_pcie_init_phyexynos_pcie_assert_resetexynos_pcie_establish_linkexynos_pcie_host_initQuoted 4 lines
struct
pcie_port_infoand structpcie_portcan also be standardized.Regards
Pratyush.