pci: Add PCIe driver for Samsung Exynos
Subsystems (4)
PATCH v5 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.
.../devicetree/bindings/pci/exynos-pcie.txt | 71 ++ drivers/pci/host/Kconfig | 5 + drivers/pci/host/Makefile | 1 + drivers/pci/host/pci-exynos.c | 1078 ++++++++++++++++++++ 4 files changed, 1155 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 290000 { + 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 0x00001000 /* configuration space */ + 0x81000000 0 0 0x40001000 0 0x00010000 /* downstream I/O */ + 0x82000000 0 0x40011000 0x40011000 0 0x1ffef000>; /* 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 0x00001000 /* configuration space */ + 0x81000000 0 0 0x60001000 0 0x00010000 /* downstream I/O */ + 0x82000000 0 0x60011000 0x60011000 0 0x1ffef000>; /* 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 290000 { + reset-gpio = <&pin_ctrl 5 0>; + }; + + pcie1 at 2a0000 { + reset-gpio = <&pin_ctrl 22 0>; + };
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 +1078 -0
1,078 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Quoted 23 lines · On Thursday 13 June 2013 22:22:31 Jingoo Han wrote:
drivers/pci/host/pci-exynos.c new file +23
-0+struct pcie_port_info { +u32 cfg0_size; +u32 cfg1_size; +u32 io_size; +u32 mem_size; +phys_addr_t io_bus_addr; +phys_addr_t mem_bus_addr; +}; + +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 65
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; +};
You mentioned that you'd use u64 for the resources here but did not.
Quoted 28 lines
drivers/pci/host/pci-exynos.c new file +28
-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, (u64 )pp->cfg0_base, dbi_base +PCIE_ATU_LOWER_BASE ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_UPPER_BASE ); +writel_rc (pp, (u64 )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 ); +} + +static void exynos_pcie_prog_viewport_cfg1 (struct pcie_port *pp,u32 busdev) +{ +u32 val; +void __iomem *dbi_base = pp->dbi_base; + +/* Program viewport 1 : OUTBOUND : CFG1 */ + 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 297
Quoted 10 lines
drivers/pci/host/pci-exynos.c new file +10
-0+writel_rc (pp,PCIE_ATU_TYPE_CFG1 , dbi_base +PCIE_ATU_CR1 ); + val =PCIE_ATU_ENABLE ; +writel_rc (pp, val, dbi_base +PCIE_ATU_CR2 ); +writel_rc (pp, (u64 )pp->cfg1_base, dbi_base +PCIE_ATU_LOWER_BASE ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_UPPER_BASE ); +writel_rc (pp, (u64 )pp->cfg1_base + pp->config.cfg1_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 ); +}
And you still don't set up the UPPER halves, which was really the point of my comment. Same thing for all the other ones.
Quoted 9 lines
drivers/pci/host/pci-exynos.c new file +9
-0+static void exynos_pcie_prog_viewport_mem_inbound (struct pcie_port *pp) +{ +u32 val; +void __iomem *dbi_base = pp->dbi_base; + +/* Program viewport 0 : INBOUND : MEM */ + 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 );
drivers/pci/host/pci-exynos.c line 357
Quoted 10 lines
drivers/pci/host/pci-exynos.c new file +10
-0+ val =PCIE_ATU_ENABLE |PCIE_ATU_BAR_MODE_ENABLE ; +writel_rc (pp, val, dbi_base +PCIE_ATU_CR2 ); +writel_rc (pp, (u64 )pp->config.mem_bus_addr, + dbi_base +PCIE_ATU_LOWER_BASE ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_UPPER_BASE ); +writel_rc (pp, (u64 )pp->config.mem_bus_addr + pp->config.mem_size -1 , + dbi_base +PCIE_ATU_LIMIT ); +writel_rc (pp, (u64 )pp->mem_base, dbi_base +PCIE_ATU_LOWER_TARGET ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_UPPER_TARGET ); +}
This makes even less sense than before, it seems like now you only allow DMA between PCI devices but not to main memory.
Quoted 9 lines
drivers/pci/host/pci-exynos.c new file +9
-0+static void exynos_pcie_prog_viewport_io_inbound (struct pcie_port *pp) +{ +u32 val; +void __iomem *dbi_base = pp->dbi_base; + +/* 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 );
drivers/pci/host/pci-exynos.c line 377
Quoted 10 lines
drivers/pci/host/pci-exynos.c new file +10
-0+ val =PCIE_ATU_ENABLE |PCIE_ATU_BAR_MODE_ENABLE ; +writel_rc (pp, val, dbi_base +PCIE_ATU_CR2 ); +writel_rc (pp, (u64 )pp->config.io_bus_addr, + dbi_base +PCIE_ATU_LOWER_BASE ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_UPPER_BASE ); +writel_rc (pp, (u64 )pp->config.io_bus_addr + pp->config.io_size -1 , + dbi_base +PCIE_ATU_LIMIT ); +writel_rc (pp, (u64 )pp->io_base, dbi_base +PCIE_ATU_LOWER_TARGET ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_UPPER_TARGET ); +}
Can you please explain what the inbound window is as I asked you? I still don't see why you would need to set it up like this.
drivers/pci/host/pci-exynos.c line 435
Quoted 11 lines
drivers/pci/host/pci-exynos.c new file +11
-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 ; + +pci_add_resource (&sys->resources, &pp->io); +pci_add_resource (&sys->resources, &pp->mem);
Now you are missing the offsets. You have to at least pass an offset for one of the I/O spaces, since they are using the same bus address. The offset must match the value you pass to pci_ioremap_io.
For the memory space, you should pass the difference between the physical base address and the bus address. That address happens to be zero with you DT setup, but I would advise to also try out some other values in DT, just to ensure it still works.
drivers/pci/host/pci-exynos.c line 952
Quoted 1 line
drivers/pci/host/pci-exynos.c new file +1
-0+ pp->reset_gpio =of_get_named_gpio (np,"reset-gpio" ,0 );
Ok.
drivers/pci/host/pci-exynos.c line 1005
Quoted 10 lines
drivers/pci/host/pci-exynos.c new file +10
-0+ +static int __exit exynos_pcie_remove(struct platform_device *pdev) +{ +struct pcie_port *pp =platform_get_drvdata (pdev); + +clk_disable_unprepare (pp->bus_clk); +clk_disable_unprepare (pp->clk); + +return 0 ; +}
You also don't remove the PCI devices here, as mentioned in an earlier review.
Arnd
Quoted 29 lines · Arnd Bergmann
Quoted 27 lines · On Thursday 13 June 2013 22:22:31 Jingoo Han wrote:
drivers/pci/host/pci-exynos.c new file +27
-0+struct pcie_port_info { +u32 cfg0_size; +u32 cfg1_size; +u32 io_size; +u32 mem_size; +phys_addr_t io_bus_addr; +phys_addr_t mem_bus_addr; +}; + +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; +spinlock_t conf_lock; +struct resource cfg; +struct resource io; +struct resource mem;
Quoted 8 lines
drivers/pci/host/pci-exynos.c line 65
Quoted 6 lines
drivers/pci/host/pci-exynos.c new file +6
-0+struct pcie_port_info config; +struct clk *clk; +struct clk *bus_clk; +int irq; +int reset_gpio; +};You mentioned that you'd use u64 for the resources here but did not.
Do you mean the following?
+ u64 cfg0_base;
+ u64 cfg1_base;
+ u64 io_base;
+ u64 mem_base;
Quoted 34 lines
Quoted 34 lines
drivers/pci/host/pci-exynos.c new file +33
-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, (u64 )pp->cfg0_base, dbi_base +PCIE_ATU_LOWER_BASE ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_UPPER_BASE ); +writel_rc (pp, (u64 )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 ); +} + +static void exynos_pcie_prog_viewport_cfg1 (struct pcie_port *pp,u32 busdev) +{ +u32 val; +void __iomem *dbi_base = pp->dbi_base; + +/* Program viewport 1 : OUTBOUND : CFG1 */ + val =PCIE_ATU_REGION_OUTBOUND |PCIE_ATU_REGION_INDEX1 ; +writel_rc (pp, val, dbi_base +PCIE_ATU_VIEWPORT ); +writel_rc (pp,PCIE_ATU_TYPE_CFG1 , dbi_base +PCIE_ATU_CR1 ); + val =PCIE_ATU_ENABLE ; +writel_rc (pp, val, dbi_base +PCIE_ATU_CR2 ); +writel_rc (pp, (u64 )pp->cfg1_base, 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 297
Quoted 5 lines
drivers/pci/host/pci-exynos.c new file +5
-0+writel_rc (pp, (u64 )pp->cfg1_base + pp->config.cfg1_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 ); +}And you still don't set up the UPPER halves, which was really the point of my comment. Same thing for all the other ones.
Do you mean the following?
+ writel_rc(pp, pp->cfg1_base, dbi_base + PCIE_ATU_LOWER_BASE);
+ writel_rc(pp, (pp->cfg1_base >> 32), dbi_base + PCIE_ATU_UPPER_BASE);
Quoted 15 lines
Quoted 15 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; + +/* Program viewport 0 : INBOUND : MEM */ + 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, (u64 )pp->config.mem_bus_addr, + 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 357
Quoted 5 lines
drivers/pci/host/pci-exynos.c new file +5
-0+writel_rc (pp, (u64 )pp->config.mem_bus_addr + pp->config.mem_size -1 , + dbi_base +PCIE_ATU_LIMIT ); +writel_rc (pp, (u64 )pp->mem_base, dbi_base +PCIE_ATU_LOWER_TARGET ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_UPPER_TARGET ); +}This makes even less sense than before, it seems like now you only allow DMA between PCI devices but not to main memory.
Sorry, I cannot understand it.
Could you give me more details?
Also, pseudo-code will be very helpful.
Quoted 15 lines
Quoted 15 lines
drivers/pci/host/pci-exynos.c new file +14
-0+static void exynos_pcie_prog_viewport_io_inbound (struct pcie_port *pp) +{ +u32 val; +void __iomem *dbi_base = pp->dbi_base; + +/* 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, (u64 )pp->config.io_bus_addr, + 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 377
Quoted 5 lines
drivers/pci/host/pci-exynos.c new file +5
-0+writel_rc (pp, (u64 )pp->config.io_bus_addr + pp->config.io_size -1 , + dbi_base +PCIE_ATU_LIMIT ); +writel_rc (pp, (u64 )pp->io_base, dbi_base +PCIE_ATU_LOWER_TARGET ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_UPPER_TARGET ); +}Can you please explain what the inbound window is as I asked you? I still don't see why you would need to set it up like this.
Sorry, I was guided to use this inbound from hardware engineer. without this inbound, Exynos5440 PCIe cannot work at booting.
Surendranath Gurivireddy Balla, Siva Reddy,
Would you explain what the inbound window is?
Quoted 17 lines
drivers/pci/host/pci-exynos.c line 435
Quoted 12 lines
drivers/pci/host/pci-exynos.c new file +11
-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 ; + +pci_add_resource (&sys->resources, &pp->io); +pci_add_resource (&sys->resources, &pp->mem);Now you are missing the offsets. You have to at least pass an offset for one of the I/O spaces, since they are using the same bus address. The offset must match the value you pass to
pci_ioremap_io.
Quoted 4 lines
For the memory space, you should pass the difference between the physical base address and the bus address. That address happens to be zero with you DT setup, but I would advise to also try out some other values in DT, just to ensure it still works.
Um, I cannot understand it, too.
Could you give me Psuedo-code?
Or, let me know which pcie driver can be the good reference.
Quoted 5 lines
drivers/pci/host/pci-exynos.c line 952
Quoted 2 lines
drivers/pci/host/pci-exynos.c new file +1
-0+ pp->reset_gpio =of_get_named_gpio (np,"reset-gpio" ,0 );Ok.
Quoted 13 lines
drivers/pci/host/pci-exynos.c line 1005
Quoted 10 lines
drivers/pci/host/pci-exynos.c new file +10
-0+ +static int __exit exynos_pcie_remove(struct platform_device *pdev) +{ +struct pcie_port *pp =platform_get_drvdata (pdev); + +clk_disable_unprepare (pp->bus_clk); +clk_disable_unprepare (pp->clk); + +return 0 ; +}You also don't remove the PCI devices here, as mentioned in an earlier review.
I reviewed Marvell PCIe driver and Tegra PCIe driver; however, I cannot know what you mean.
Could let me know which additional functions are needed?
Quoted 2 lines
Arnd
Quoted 2 lines · Jingoo Han
Quoted 1 line · Arnd Bergmann
On Thursday 13 June 2013 22:22:31 Jingoo Han wrote:
[...]
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
drivers/pci/host/pci-exynos.c new file +4
-0+static int __exit exynos_pcie_remove(struct platform_device *pdev) +{ +struct pcie_port *pp =platform_get_drvdata (pdev); +Quoted 8 lines
drivers/pci/host/pci-exynos.c line 1005
Quoted 5 lines
drivers/pci/host/pci-exynos.c new file +5
-0+clk_disable_unprepare (pp->bus_clk); +clk_disable_unprepare (pp->clk); + +return 0 ; +}You also don't remove the PCI devices here, as mentioned in an earlier review.
Quoted 4 lines
I reviewed Marvell PCIe driver and Tegra PCIe driver; however, I cannot know what you mean.
Could let me know which additional functions are needed?
We don't currently do that on Tegra either. pci-mvebu doesn't do that either, but they don't implement the driver's .remove() in the first place.
I think the biggest missing piece is pci_common_exit(), the counterpart of pci_common_init(), to cleanup a host bridge on ARM. I haven't looked in detail at the other architectures, but I suspect there must be some code to call when a host bridge is removed.
Looking at drivers/pci/remove.c, it seems like pci_remove_root_bus() might be what we're looking at. It isn't exported so it can't be used by modules, but that can be changed. Is that how a host bridge is typically removed from the system?
Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130614/87654f11/attachment-0001.sig>
Quoted 10 lines · On Friday 14 June 2013 12:53:11 Thierry Reding wrote:
I think the biggest missing piece is
pci_common_exit(), the counterpart ofpci_common_init(), to cleanup a host bridge on ARM. I haven't looked in detail at the other architectures, but I suspect there must be some code to call when a host bridge is removed.Looking at
drivers/pci/remove.c, it seems likepci_remove_root_bus()might be what we're looking at. It isn't exported so it can't be used by modules, but that can be changed. Is that how a host bridge is typically removed from the system?
It's fairly new to have host bridges in loadable modules, so I'm pretty sure it's not supported by the core yet, but it also doesn't seem hard to do. I think you are right with regard to pci_remove_root_bus, and Bjorn might be able to provide more information.
Ideally we should be able to load and unload the pci host driver in a loop indefinitely without crashing or exposing any races or leaks, but I would not bet on that working without bugs in the core, since that goes beyond the normal pci (device) hotplug case.
Arnd
Quoted 17 lines · Arnd Bergmann
Quoted 10 lines · On Friday 14 June 2013 12:53:11 Thierry Reding wrote:
I think the biggest missing piece is
pci_common_exit(), the counterpart ofpci_common_init(), to cleanup a host bridge on ARM. I haven't looked in detail at the other architectures, but I suspect there must be some code to call when a host bridge is removed.Looking at
drivers/pci/remove.c, it seems likepci_remove_root_bus()might be what we're looking at. It isn't exported so it can't be used by modules, but that can be changed. Is that how a host bridge is typically removed from the system?It's fairly new to have host bridges in loadable modules, so I'm pretty sure it's not supported by the core yet, but it also doesn't seem hard to do. I think you are right with regard to
pci_remove_root_bus, and Bjorn might be able to provide more information.
Quoted 4 lines
Ideally we should be able to load and unload the pci host driver in a loop indefinitely without crashing or exposing any races or leaks, but I would not bet on that working without bugs in the core, since that goes beyond the normal pci (device) hotplug case.
I've done some preliminary testing on Tegra using sysfs to unbind and rebind the device from and to the driver. Some code needs to be added for this to work, but it doesn't crash and PCI even continues to work after unbinding and rebinding (tested using gigabit ethernet).
However I haven't looked for leaks yet, and I'm pretty sure some more code is required to undo some of what pci_common_init() does on ARM. Looking more closely, I think most (if not all) remaining leaks could be fixed by keeping the list of pci_sys_data structures around and cleaning them up properly.
Given the experimental nature of this I don't want to make that part of the driver for 3.12 and I've opted to just disable any means of removing the driver for now. But I do want to get back to this after the driver has been merged.
Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130717/f8bfe607/attachment.sig>
Quoted 32 lines · On Friday 14 June 2013 17:18:46 Jingoo Han wrote:
Quoted 20 lines · Arnd Bergmann
Quoted 18 lines · On Thursday 13 June 2013 22:22:31 Jingoo Han wrote:
drivers/pci/host/pci-exynos.c new file +18
-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; +spinlock_t conf_lock; +struct resource cfg; +struct resource io; +struct resource mem;Quoted 8 lines
drivers/pci/host/pci-exynos.c line 65
Quoted 6 lines
drivers/pci/host/pci-exynos.c new file +6
-0+struct pcie_port_info config; +struct clk *clk; +struct clk *bus_clk; +int irq; +int reset_gpio; +};You mentioned that you'd use u64 for the resources here but did not.
Do you mean the following?
Review
Quoted 4 lines
(quoted diff) +4
-0+ u64 cfg0_base; + u64 cfg1_base; + u64 io_base; + u64 mem_base;
Yes, anything you need to program into a 64 bit hardware register.
Quoted 24 lines
Quoted 13 lines
Quoted 13 lines
drivers/pci/host/pci-exynos.c new file +13
-0+static void exynos_pcie_prog_viewport_cfg1 (struct pcie_port *pp,u32 busdev) +{ +u32 val; +void __iomem *dbi_base = pp->dbi_base; + +/* Program viewport 1 : OUTBOUND : CFG1 */ + val =PCIE_ATU_REGION_OUTBOUND |PCIE_ATU_REGION_INDEX1 ; +writel_rc (pp, val, dbi_base +PCIE_ATU_VIEWPORT ); +writel_rc (pp,PCIE_ATU_TYPE_CFG1 , dbi_base +PCIE_ATU_CR1 ); + val =PCIE_ATU_ENABLE ; +writel_rc (pp, val, dbi_base +PCIE_ATU_CR2 ); +writel_rc (pp, (u64 )pp->cfg1_base, 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 297
Quoted 5 lines
drivers/pci/host/pci-exynos.c new file +5
-0+writel_rc (pp, (u64 )pp->cfg1_base + pp->config.cfg1_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 ); +}And you still don't set up the UPPER halves, which was really the point of my comment. Same thing for all the other ones.
Do you mean the following?
Review
Quoted 2 lines
(quoted diff) +2
-0+ writel_rc(pp, pp->cfg1_base, dbi_base + PCIE_ATU_LOWER_BASE); + writel_rc(pp, (pp->cfg1_base >> 32), dbi_base + PCIE_ATU_UPPER_BASE);
Right. Note that you could achieve the same using phys_addr_t instead of u64, but it's more complicated to get that to work for both 32 and 64 bit phys_addr_t types, since you cannot shift a 32 bit value by 32 bits in C.
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_mem_inbound (struct pcie_port *pp) +{ +u32 val; +void __iomem *dbi_base = pp->dbi_base; + +/* Program viewport 0 : INBOUND : MEM */ + 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, (u64 )pp->config.mem_bus_addr, + 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 357
Quoted 5 lines
drivers/pci/host/pci-exynos.c new file +5
-0+writel_rc (pp, (u64 )pp->config.mem_bus_addr + pp->config.mem_size -1 , + dbi_base +PCIE_ATU_LIMIT ); +writel_rc (pp, (u64 )pp->mem_base, dbi_base +PCIE_ATU_LOWER_TARGET ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_UPPER_TARGET ); +}This makes even less sense than before, it seems like now you only allow DMA between PCI devices but not to main memory.
Quoted 3 lines
Sorry, I cannot understand it.
Could you give me more details?
Also, pseudo-code will be very helpful.
Please look up the documentation about inbound viewport and describe in a code comment what it does. I /assume/ that this is how DMA accesses from the bus get translated into AXI bus transactions. If so, you have to let the window translate addresses from RAM. If it's something else, then you should document what it is and how it needs to be set up.
Quoted 16 lines
Quoted 16 lines
drivers/pci/host/pci-exynos.c line 435
Quoted 11 lines
drivers/pci/host/pci-exynos.c new file +11
-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 ; + +pci_add_resource (&sys->resources, &pp->io); +pci_add_resource (&sys->resources, &pp->mem);Now you are missing the offsets. You have to at least pass an offset for one of the I/O spaces, since they are using the same bus address. The offset must match the value you pass to
pci_ioremap_io.
Quoted 8 lines
Quoted 4 lines
For the memory space, you should pass the difference between the physical base address and the bus address. That address happens to be zero with you DT setup, but I would advise to also try out some other values in DT, just to ensure it still works.
Um, I cannot understand it, too.
Could you give me Psuedo-code?
Or, let me know which pcie driver can be the good reference.
I think most hardware is not as flexible as yours, so they can just hardcode a lot of this.
What you need here is
static unsigned long global_io_offset = 0;
if (global_io_offset < SZ_1M && pp->config.io_size > 0) {
sys->io_offset = global_io_offset - pp->config.io_bus_addr; /* normally 0 */
pci_ioremap_io(sys->io_offset, pp->io.start);
global_io_offset += SZ_64K;
}sys->mem_offset = pp->mem.start - pp->config.mem_bus_addr; /* normally 0 */
sys->io_offset normally increases by 64K for each bus but should always be between 0 and 1MB, it is the index into the registers mapped at (void __iomem*)PCI_IO_VIRT_BASE.
It is best practice to map 64KB of I/O space at bus address 0 for each domain into PCI_IO_VIRT_BASE, and set up a 1:1 translation between memory space bus addresses and CPU physical addresses, as you do in your 'ranges' property.
However, you should be able to use any other bus addresses with the code above, except for broken device drivers.
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
drivers/pci/host/pci-exynos.c new file +4
-0+static int __exit exynos_pcie_remove(struct platform_device *pdev) +{ +struct pcie_port *pp =platform_get_drvdata (pdev); +Quoted 8 lines
drivers/pci/host/pci-exynos.c line 1005
Quoted 5 lines
drivers/pci/host/pci-exynos.c new file +5
-0+clk_disable_unprepare (pp->bus_clk); +clk_disable_unprepare (pp->clk); + +return 0 ; +}You also don't remove the PCI devices here, as mentioned in an earlier review.
Quoted 4 lines
I reviewed Marvell PCIe driver and Tegra PCIe driver; however, I cannot know what you mean.
Could let me know which additional functions are needed?
The mvebu driver does not allow module unload. I haven't looked at the tegra driver. If you allow unloading the driver and provide a 'remove' callback, that callback needs to clean up the entire bus and remove all child devices that were added as well as undo everything the probe function did. I think it would be great if you can do that, although it might not be easy. The simplest solution would be to not support unloading though.
Arnd
Quoted 31 lines · Arnd Bergmann
Quoted 30 lines · On Friday 14 June 2013 17:18:46 Jingoo Han wrote:
Quoted 28 lines · Arnd Bergmann
Quoted 14 lines · On Thursday 13 June 2013 22:22:31 Jingoo Han wrote:
drivers/pci/host/pci-exynos.c new file +14
-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 65
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; +};You mentioned that you'd use u64 for the resources here but did not.
Quoted 8 lines
Review
Quoted 6 lines
Do you mean the following?
(quoted diff) +4
-0+ u64 cfg0_base; + u64 cfg1_base; + u64 io_base; + u64 mem_base;Yes, anything you need to program into a 64 bit hardware register.
OK,
Quoted 23 lines
Quoted 23 lines
Quoted 22 lines
Quoted 9 lines
drivers/pci/host/pci-exynos.c new file +8
-0+static void exynos_pcie_prog_viewport_cfg1 (struct pcie_port *pp,u32 busdev) +{ +u32 val; +void __iomem *dbi_base = pp->dbi_base; + +/* Program viewport 1 : OUTBOUND : CFG1 */ + 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 297
Quoted 10 lines
drivers/pci/host/pci-exynos.c new file +10
-0+writel_rc (pp,PCIE_ATU_TYPE_CFG1 , dbi_base +PCIE_ATU_CR1 ); + val =PCIE_ATU_ENABLE ; +writel_rc (pp, val, dbi_base +PCIE_ATU_CR2 ); +writel_rc (pp, (u64 )pp->cfg1_base, dbi_base +PCIE_ATU_LOWER_BASE ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_UPPER_BASE ); +writel_rc (pp, (u64 )pp->cfg1_base + pp->config.cfg1_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 ); +}And you still don't set up the UPPER halves, which was really the point of my comment. Same thing for all the other ones.
Quoted 8 lines
Review
Quoted 4 lines
Do you mean the following?
(quoted diff) +2
-0+ writel_rc(pp, pp->cfg1_base, dbi_base + PCIE_ATU_LOWER_BASE); + writel_rc(pp, (pp->cfg1_base >> 32), dbi_base + PCIE_ATU_UPPER_BASE);Right. Note that you could achieve the same using
phys_addr_tinstead of u64, but it's more complicated to get that to work for both 32 and 64 bitphys_addr_ttypes, since you cannot shift a 32 bit value by 32 bits in C.
OK,
Quoted 28 lines
Quoted 24 lines
Quoted 15 lines
Quoted 15 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; + +/* Program viewport 0 : INBOUND : MEM */ + 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, (u64 )pp->config.mem_bus_addr, + 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 357
Quoted 5 lines
drivers/pci/host/pci-exynos.c new file +5
-0+writel_rc (pp, (u64 )pp->config.mem_bus_addr + pp->config.mem_size -1 , + dbi_base +PCIE_ATU_LIMIT ); +writel_rc (pp, (u64 )pp->mem_base, dbi_base +PCIE_ATU_LOWER_TARGET ); +writel_rc (pp,0 , dbi_base +PCIE_ATU_UPPER_TARGET ); +}This makes even less sense than before, it seems like now you only allow DMA between PCI devices but not to main memory.
Quoted 3 lines
Sorry, I cannot understand it.
Could you give me more details?
Also, pseudo-code will be very helpful.
Quoted 5 lines
Please look up the documentation about inbound viewport and describe in a code comment what it does. I /assume/ that this is how DMA accesses from the bus get translated into AXI bus transactions. If so, you have to let the window translate addresses from RAM. If it's something else, then you should document what it is and how it needs to be set up.
One of our hardware engineer confirmed it.
He said that these inbound functions are unnecessary. Also, I checked that PCIe works properly without these functions. So, I will remove these inbound functions.
Quoted 43 lines
Quoted 17 lines
Quoted 17 lines
drivers/pci/host/pci-exynos.c line 435
Quoted 12 lines
drivers/pci/host/pci-exynos.c new file +11
-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 ; + +pci_add_resource (&sys->resources, &pp->io); +pci_add_resource (&sys->resources, &pp->mem);Now you are missing the offsets. You have to at least pass an offset for one of the I/O spaces, since they are using the same bus address. The offset must match the value you pass to
pci_ioremap_io.Quoted 8 lines
Quoted 4 lines
For the memory space, you should pass the difference between the physical base address and the bus address. That address happens to be zero with you DT setup, but I would advise to also try out some other values in DT, just to ensure it still works.
Um, I cannot understand it, too.
Could you give me Psuedo-code?
Or, let me know which pcie driver can be the good reference.I think most hardware is not as flexible as yours, so they can just hardcode a lot of this.
What you need here is
static unsigned long
global_io_offset= 0;if (global_io_offset < SZ_1M && pp->config.io_size > 0) { sys->io_offset = global_io_offset - pp->config.io_bus_addr; /* normally 0 */ pci_ioremap_io(sys->io_offset, pp->io.start); global_io_offset += SZ_64K; }
sys->mem_offset=pp->mem.start-pp->config.mem_bus_addr; /* normally 0 */
sys->io_offsetnormally increases by 64K for each bus but should always be between 0 and 1MB, it is the index into the registers mapped at (void __iomem*)PCI_IO_VIRT_BASE.
Quoted 7 lines
It is best practice to map 64KB of I/O space at bus address 0 for each domain into
PCI_IO_VIRT_BASE, and set up a 1:1 translation between memory space bus addresses and CPU physical addresses, as you do in your 'ranges' property.However, you should be able to use any other bus addresses with the code above, except for broken device drivers.
Then, do you mean the following?
static unsigned long global_io_offset = 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;
if (global_io_offset < SZ_1M && pp->config.io_size > 0) {
sys->io_offset = global_io_offset - pp->config.io_bus_addr; /* normally 0 */
pci_ioremap_io(sys->io_offset, pp->io.start);
global_io_offset += SZ_64K;
}
sys->mem_offset = pp->mem.start - pp->config.mem_bus_addr; /* normally 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;
}In this case, boot message is as below:
PCI host bridge to bus 0000:00pci_bus 0000:00: root bus resource [io 0x40001000-0x40010fff]pci_bus 0000:00: root bus resource [mem 0x40011000-0x5fffffff]pci_bus 0000:00: No busn resource found for root bus, will use [bus 00-ff]
pci 0000:00:00.0: [144d:a549] type 01 class 0x060400
[.....]
PCI host bridge to bus 0001:00pci_bus 0001:00: root bus resource [io 0x60001000-0x60010fff] (bus address [0x5fff1000-0x6000 0fff])pci_bus 0001:00: root bus resource [mem 0x60011000-0x7fffffff]pci_bus 0001:00: No busn resource found for root bus, will use [bus 00-ff]
pci 0001:00:00.0: [144d:a549] type 01 class 0x060400
Quoted 19 lines
Quoted 14 lines
Quoted 13 lines
drivers/pci/host/pci-exynos.c line 1005
Quoted 10 lines
drivers/pci/host/pci-exynos.c new file +9
-0+static int __exit exynos_pcie_remove(struct platform_device *pdev) +{ +struct pcie_port *pp =platform_get_drvdata (pdev); + +clk_disable_unprepare (pp->bus_clk); +clk_disable_unprepare (pp->clk); + +return 0 ; +}You also don't remove the PCI devices here, as mentioned in an earlier review.
Quoted 4 lines
I reviewed Marvell PCIe driver and Tegra PCIe driver; however, I cannot know what you mean.
Could let me know which additional functions are needed?
Quoted 7 lines
The mvebu driver does not allow module unload. I haven't looked at the tegra driver. If you allow unloading the driver and provide a 'remove' callback, that callback needs to clean up the entire bus and remove all child devices that were added as well as undo everything the probe function did. I think it would be great if you can do that, although it might not be easy. The simplest solution would be to not support unloading though.
As the mvebu driver uses platform_driver_probe(), the Exynos driver uses platform_driver_probe(). Thus, I will not provide a 'remove' callback.
Thank you.
Best regards,
Jingoo Han
Quoted 2 lines
Arnd
Quoted 8 lines · On Monday 17 June 2013 18:45:52 Jingoo Han wrote:
Quoted 6 lines · Arnd Bergmann
Please look up the documentation about inbound viewport and describe in a code comment what it does. I /assume/ that this is how DMA accesses from the bus get translated into AXI bus transactions. If so, you have to let the window translate addresses from RAM. If it's something else, then you should document what it is and how it needs to be set up.
Quoted 4 lines
One of our hardware engineer confirmed it.
He said that these inbound functions are unnecessary. Also, I checked that PCIe works properly without these functions. So, I will remove these inbound functions.
Ok, good. So DMA just gets translated 1:1 independent of the inbound viewport? Have you tested this with PCI device using DMA?
Quoted 15 lines
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; if (global_io_offset < SZ_1M && pp->config.io_size > 0) { sys->io_offset = global_io_offset - pp->config.io_bus_addr; /* normally 0 */ pci_ioremap_io(sys->io_offset, pp->io.start); global_io_offset += SZ_64K; }
Quoted 7 lines
sys->mem_offset = pp->mem.start - pp->config.mem_bus_addr; /* normally 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;
}This is what I meant, yes.
Quoted 14 lines
In this case, boot message is as below:
PCI host bridge to bus 0000:00
pci_bus0000:00: root bus resource [io 0x40001000-0x40010fff]pci_bus0000:00: root bus resource [mem 0x40011000-0x5fffffff]pci_bus0000:00: No busn resource found for root bus, will use [bus 00-ff]
pci 0000:00:00.0: [144d:a549] type 01 class0x060400
[.....]
PCI host bridge to bus 0001:00pci_bus0001:00: root bus resource [io 0x60001000-0x60010fff] (bus address [0x5fff1000-0x6000 0fff])pci_bus0001:00: root bus resource [mem 0x60011000-0x7fffffff]pci_bus0001:00: No busn resource found for root bus, will use [bus 00-ff]
pci 0001:00:00.0: [144d:a549] type 01 class0x060400
The io resources here look wrong. I would have expected
pci_bus 0000:00: root bus resource [io 0x001000-0x00ffff]pci_bus 0001:00: root bus resource [io 0x010000-0x01ffff] (bus address [0x000000-0x00ffff])
Please have a look at the pci-mvebu driver and how it calculates its 'realio' resource.
Quoted 26 lines
Quoted 18 lines
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
drivers/pci/host/pci-exynos.c new file +4
-0+static int __exit exynos_pcie_remove(struct platform_device *pdev) +{ +struct pcie_port *pp =platform_get_drvdata (pdev); +Quoted 8 lines
drivers/pci/host/pci-exynos.c line 1005
Quoted 5 lines
drivers/pci/host/pci-exynos.c new file +5
-0+clk_disable_unprepare (pp->bus_clk); +clk_disable_unprepare (pp->clk); + +return 0 ; +}You also don't remove the PCI devices here, as mentioned in an earlier review.
Quoted 4 lines
I reviewed Marvell PCIe driver and Tegra PCIe driver; however, I cannot know what you mean.
Could let me know which additional functions are needed?
Quoted 7 lines
The mvebu driver does not allow module unload. I haven't looked at the tegra driver. If you allow unloading the driver and provide a 'remove' callback, that callback needs to clean up the entire bus and remove all child devices that were added as well as undo everything the probe function did. I think it would be great if you can do that, although it might not be easy. The simplest solution would be to not support unloading though.
Quoted 2 lines
As the mvebu driver uses
platform_driver_probe(), the Exynos driver usesplatform_driver_probe(). Thus, I will not provide a 'remove' callback.
Well, the important part is not to provide a module_exit() function, which will ensure the driver cannot be unloaded.
Arnd
Quoted 9 lines · Arnd Bergmann
Quoted 8 lines · On Monday 17 June 2013 18:45:52 Jingoo Han wrote:
Quoted 6 lines · Arnd Bergmann
Please look up the documentation about inbound viewport and describe in a code comment what it does. I /assume/ that this is how DMA accesses from the bus get translated into AXI bus transactions. If so, you have to let the window translate addresses from RAM. If it's something else, then you should document what it is and how it needs to be set up.
Quoted 8 lines
Quoted 4 lines
One of our hardware engineer confirmed it.
He said that these inbound functions are unnecessary. Also, I checked that PCIe works properly without these functions. So, I will remove these inbound functions.Ok, good. So DMA just gets translated 1:1 independent of the inbound viewport? Have you tested this with PCI device using DMA?
According to our hardware engineer,
He said that
"That's correct. We tested it by doing a memory write from the device. A device DMA is a series of memory r/w so I expect it to work same way."
Also, he thought that I already tested too, since it works after removing the functions.
Quoted 41 lines
Quoted 16 lines
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; if (global_io_offset < SZ_1M && pp->config.io_size > 0) { sys->io_offset = global_io_offset - pp->config.io_bus_addr; /* normally 0 */ pci_ioremap_io(sys->io_offset, pp->io.start); global_io_offset += SZ_64K; }Quoted 7 lines
sys->mem_offset = pp->mem.start - pp->config.mem_bus_addr; /* normally 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; }This is what I meant, yes.
Quoted 14 lines
In this case, boot message is as below:
PCI host bridge to bus 0000:00
pci_bus0000:00: root bus resource [io 0x40001000-0x40010fff]pci_bus0000:00: root bus resource [mem 0x40011000-0x5fffffff]pci_bus0000:00: No busn resource found for root bus, will use [bus 00-ff]
pci 0000:00:00.0: [144d:a549] type 01 class0x060400
[.....]
PCI host bridge to bus 0001:00pci_bus0001:00: root bus resource [io 0x60001000-0x60010fff] (bus address [0x5fff1000-0x6000 0fff])pci_bus0001:00: root bus resource [mem 0x60011000-0x7fffffff]pci_bus0001:00: No busn resource found for root bus, will use [bus 00-ff]
pci 0001:00:00.0: [144d:a549] type 01 class0x060400
Quoted 7 lines
The io resources here look wrong. I would have expected
pci_bus0000:00: root bus resource [io 0x001000-0x00ffff]pci_bus0001:00: root bus resource [io 0x010000-0x01ffff] (bus address [0x000000-0x00ffff])Please have a look at the pci-mvebu driver and how it calculates its 'realio' resource.
I looked at the pci-mvebu driver,
Then I fixed it as the pci-mvebu driver did.
Also, I added 'global_io_offset'.
@@ -909,6 +909,12 @@ static int __init exynos_pcie_probe(struct platform_device *pdev)
if (restype == IORESOURCE_IO) {
of_pci_range_to_resource(&range, np, &pp->io);
pp->io.name = "I/O";+ pp->io.start = max_t(resource_size_t,
+ PCIBIOS_MIN_IO,
+ range.pci_addr + global_io_offset);
+ pp->io.end = min_t(resource_size_t,
+ IO_SPACE_LIMIT,
+ range.pci_addr + range.size + global_io_offset);
pp->config.io_size = resource_size(&pp->io);
pp->config.io_bus_addr = range.pci_addr;In this case, boot message is as below:
PCI host bridge to bus 0000:00pci_bus 0000:00: root bus resource [io 0x1000-0x10000]pci_bus 0000:00: root bus resource [mem 0x40011000-0x5fffffff]
[.....]
PCI host bridge to bus 0001:00pci_bus 0001:00: root bus resource [io 0x10000-0x20000] (bus address [0x0000-0x10000]) pci_bus 0001:00: root bus resource [mem 0x60011000-0x7fffffff]
Quoted 27 lines
Quoted 27 lines
Quoted 26 lines
Quoted 14 lines
Quoted 13 lines
drivers/pci/host/pci-exynos.c line 1005
Quoted 10 lines
drivers/pci/host/pci-exynos.c new file +9
-0+static int __exit exynos_pcie_remove(struct platform_device *pdev) +{ +struct pcie_port *pp =platform_get_drvdata (pdev); + +clk_disable_unprepare (pp->bus_clk); +clk_disable_unprepare (pp->clk); + +return 0 ; +}You also don't remove the PCI devices here, as mentioned in an earlier review.
Quoted 4 lines
I reviewed Marvell PCIe driver and Tegra PCIe driver; however, I cannot know what you mean.
Could let me know which additional functions are needed?
The mvebu driver does not allow module unload. I haven't looked at the tegra driver. If you allow unloading the driver and provide a 'remove' callback, that callback needs to clean up the entire bus and remove all child devices that were added as well as undo everything the probe function did. I think it would be great if you can do that, although it might not be easy. The simplest solution would be to not support unloading though.
Quoted 5 lines
Quoted 2 lines
As the mvebu driver uses
platform_driver_probe(), the Exynos driver usesplatform_driver_probe(). Thus, I will not provide a 'remove' callback.Well, the important part is not to provide a
module_exit()function, which will ensure the driver cannot be unloaded.
I will remove a 'remove' callback. Is it OK?
Or what should I do?
Thank you for your comment. :)
Best regards,
Jingoo Han
Quoted 2 lines
Arnd
Quoted 19 lines · Jingoo Han
Quoted 9 lines · Arnd Bergmann
Quoted 8 lines · On Monday 17 June 2013 18:45:52 Jingoo Han wrote:
Quoted 6 lines · Arnd Bergmann
Please look up the documentation about inbound viewport and describe in a code comment what it does. I /assume/ that this is how DMA accesses from the bus get translated into AXI bus transactions. If so, you have to let the window translate addresses from RAM. If it's something else, then you should document what it is and how it needs to be set up.
Quoted 8 lines
Quoted 4 lines
One of our hardware engineer confirmed it.
He said that these inbound functions are unnecessary. Also, I checked that PCIe works properly without these functions. So, I will remove these inbound functions.Ok, good. So DMA just gets translated 1:1 independent of the inbound viewport? Have you tested this with PCI device using DMA?
Quoted 7 lines
According to our hardware engineer,
He said that
"That's correct. We tested it by doing a memory write from the device. A device DMA is a series of memory r/w so I expect it to work same way."Also, he thought that I already tested too, since it works after removing the functions.
It could be that the default setting just creates a 1:1 map so that would work, but if you tested it, that should be good enough.
Quoted 19 lines
I looked at the pci-mvebu driver,
Then I fixed it as the pci-mvebu driver did.
Also, I added 'global_io_offset'.(quoted diff) +6
-0@@ -909,6 +909,12 @@ static int __init exynos_pcie_probe(struct platform_device *pdev) if (restype == IORESOURCE_IO) { of_pci_range_to_resource(&range, np, &pp->io); pp->io.name = "I/O"; + pp->io.start = max_t(resource_size_t, + PCIBIOS_MIN_IO, + range.pci_addr + global_io_offset); + pp->io.end = min_t(resource_size_t, + IO_SPACE_LIMIT, + range.pci_addr + range.size + global_io_offset); pp->config.io_size = resource_size(&pp->io); pp->config.io_bus_addr = range.pci_addr;In this case, boot message is as below:
Quoted 7 lines
PCI host bridge to bus 0000:00
pci_bus0000:00: root bus resource [io 0x1000-0x10000]pci_bus0000:00: root bus resource [mem 0x40011000-0x5fffffff]
[.....]
PCI host bridge to bus 0001:00pci_bus0001:00: root bus resource [io 0x10000-0x20000] (bus address [0x0000-0x10000])pci_bus0001:00: root bus resource [mem 0x60011000-0x7fffffff]
Ok, very good.
Quoted 3 lines
I will remove a 'remove' callback. Is it OK?
Or what should I do?
I think you should keep the remove function, but add a comment explaining that you don't allow module unload and that in order to allow it, the remove function will have to remove all pci buses and devices under the host bridge.
Arnd
Quoted 5 lines · Arnd Bergmann
Quoted 4 lines · Jingoo Han
Quoted 3 lines · Arnd Bergmann
Quoted 2 lines · On Monday 17 June 2013 18:45:52 Jingoo Han wrote:
Quoted 1 line · Arnd Bergmann
[.....]
Quoted 7 lines
Quoted 3 lines
I will remove a 'remove' callback. Is it OK?
Or what should I do?I think you should keep the remove function, but add a comment explaining that you don't allow module unload and that in order to allow it, the remove function will have to remove all pci buses and devices under the host bridge.
Then, do you mean the following?
static int __exit exynos_pcie_remove(struct platform_device *pdev)
{
struct pcie_port *pp = platform_get_drvdata(pdev);
clk_disable_unprepare(pp->bus_clk);
clk_disable_unprepare(pp->clk);
return 0;
}static struct platform_driver exynos_pcie_driver = {
.remove = __exit_p(exynos_pcie_remove),[.....]
/* Exynos PCIe driver does not allow module unload */
static int __init pcie_init(void)
{
hook_fault_code(16 + 6, exynos_pcie_abort, SIGBUS, 0,
"imprecise external abort");
platform_driver_probe(&exynos_pcie_driver, exynos_pcie_probe);
return 0;
}subsys_initcall(pcie_init);
MODULE_AUTHOR("Jingoo Han <[email protected]>"); MODULE_DESCRIPTION("Samsung PCIe host controller driver"); MODULE_LICENSE("GPLv2");
Quoted 6 lines
Arnd
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 28 lines · Jingoo Han
Then, do you mean the following?
static int
__exitexynos_pcie_remove(struct platform_device *pdev){ struct pcie_port *pp = platform_get_drvdata(pdev); clk_disable_unprepare(pp->bus_clk); clk_disable_unprepare(pp->clk); return 0; }static struct platform_driver exynos_pcie_driver = { .remove = __exit_p(exynos_pcie_remove),[.....]
/* Exynos PCIe driver does not allow module unload */
static int
__initpcie_init(void){ hook_fault_code(16 + 6, exynos_pcie_abort, SIGBUS, 0, "imprecise external abort"); platform_driver_probe(&exynos_pcie_driver, exynos_pcie_probe); return 0; }
Quoted 6 lines
subsys_initcall(pcie_init);
MODULE_AUTHOR("Jingoo Han <[email protected]>");MODULE_DESCRIPTION("Samsung PCIe host controller driver");MODULE_LICENSE("GPLv2");
Yes, this looks good. I would probably use platform_driver_register rather than platform_driver_probe, but that is your choice. using platform_driver_probe() mean you cannot deal with deferred probing.
Arnd
Quoted 31 lines · Arnd Bergmann
Quoted 30 lines · Jingoo Han
Then, do you mean the following?
static int
__exitexynos_pcie_remove(struct platform_device *pdev){ struct pcie_port *pp = platform_get_drvdata(pdev); clk_disable_unprepare(pp->bus_clk); clk_disable_unprepare(pp->clk); return 0; }static struct platform_driver exynos_pcie_driver = { .remove = __exit_p(exynos_pcie_remove),[.....]
/* Exynos PCIe driver does not allow module unload */
static int
__initpcie_init(void){ hook_fault_code(16 + 6, exynos_pcie_abort, SIGBUS, 0, "imprecise external abort"); platform_driver_probe(&exynos_pcie_driver, exynos_pcie_probe); return 0; }
subsys_initcall(pcie_init);
Quoted 8 lines
Quoted 4 lines
MODULE_AUTHOR("Jingoo Han <[email protected]>");MODULE_DESCRIPTION("Samsung PCIe host controller driver");MODULE_LICENSE("GPLv2");Yes, this looks good. I would probably use
platform_driver_registerrather thanplatform_driver_probe, but that is your choice. usingplatform_driver_probe()mean you cannot deal with deferred probing.
Hi Arnd,
Thank you for your reply. :) I will send PATCH v6, soon.
I really appreciate your comments.
Hi Thomas Abraham, Kukjin Kim, Thank you for your support. It is very helpful.
Best regards,
Jingoo Han
Quoted 3 lines · Arnd Bergmann
Quoted 2 lines · On Monday 17 June 2013 18:45:52 Jingoo Han wrote:
Quoted 1 line · Arnd Bergmann
[.....]
Quoted 26 lines
Quoted 26 lines
Quoted 25 lines
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
drivers/pci/host/pci-exynos.c new file +4
-0+static int __exit exynos_pcie_remove(struct platform_device *pdev) +{ +struct pcie_port *pp =platform_get_drvdata (pdev); +Quoted 8 lines
drivers/pci/host/pci-exynos.c line 1005
Quoted 5 lines
drivers/pci/host/pci-exynos.c new file +5
-0+clk_disable_unprepare (pp->bus_clk); +clk_disable_unprepare (pp->clk); + +return 0 ; +}You also don't remove the PCI devices here, as mentioned in an earlier review.
Quoted 4 lines
I reviewed Marvell PCIe driver and Tegra PCIe driver; however, I cannot know what you mean.
Could let me know which additional functions are needed?
The mvebu driver does not allow module unload. I haven't looked at the tegra driver. If you allow unloading the driver and provide a 'remove' callback, that callback needs to clean up the entire bus and remove all child devices that were added as well as undo everything the probe function did. I think it would be great if you can do that, although it might not be easy. The simplest solution would be to not support unloading though.
Quoted 5 lines
Quoted 2 lines
As the mvebu driver uses
platform_driver_probe(), the Exynos driver usesplatform_driver_probe(). Thus, I will not provide a 'remove' callback.Well, the important part is not to provide a
module_exit()function, which will ensure the driver cannot be unloaded.
Aha, I see.
I will not provide a module_exit() function), as the mvebu driver does.
Best regards,
Jingoo Han
Quoted 2 lines
Arnd