Re: [RESEND: RFC PATCH 3/3] pcie: keystone: add pcie driver based on designware core driver
On 2 April 2014 16:43, Murali Karicheri m-kariche...@ti.com wrote: Keystone pcie driver is developed based on other dw based pcie drivers such as pci-exynos that uses subsys_initcall(). I am new to this list, probably Jingoo (copied) has some history on why we can't use module. For now I will keep it as is and can be re-visited in the next revisions. Also I will experiment with PCIE port driver as well. BTW, PCIE driver currently uses Legacy or MSI IRQ. Keystone PCI has a platform IRQ. Is DT based irq configuration is the appropriate way to add this capability? As far as I am aware - the PCI standards define a particular way for devices to describe which interrupt will be used for things like hotplug, AER and PME. These interrupts are always PCI interrupts (i.e. MSI/MSI-X/legacy). Thus the port services code in the kernel uses standard configuration space accesses to determine the interrupt to use. Also note that it's not just the host bridge that can provide these services but any PCIE device, I guess in this sense a host bridge is treated like any other device. If my understanding is correct I don't believe the current port services code allows exceptions to this, i.e. to say this host bridge actually uses a platform IRQ for AER rather than an MSI. Though this may be quite useful as I suspect many host bridges provide interrupts for things like PME through platform IRQs rather that PCI interrupts. Does the Keystone have platform IRQs for things like AER? Is that because the IP makes these events available through platform IRQs in addition to the standard PCI means? Andrew Murray -- To unsubscribe from this list: send the line unsubscribe linux-samsung-soc in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RESEND: RFC PATCH 3/3] pcie: keystone: add pcie driver based on designware core driver
On 25 March 2014 10:35, Thierry Reding thierry.red...@gmail.com wrote: On Tue, Mar 25, 2014 at 08:44:36AM +0100, Arnd Bergmann wrote: On Monday 24 March 2014 20:35:26 Murali Karicheri wrote: [...] +/* Keystone PCIe driver does not allow module unload */ +static int __init ks_pcie_init(void) +{ + return platform_driver_probe(ks_pcie_driver, ks_pcie_probe); +} +subsys_initcall(ks_pcie_init); Why subsys_initcall? We should probably try to fix unloading soon. I did some work on this a few months ago but never got around to cleaning up the patches. Let me see if I can resurrect that work. I think there may be merit in these drivers using subsys_init. I've not had time to investigate, but as far as I can remember this causes issues with piceport. For ARM32 host drivers, pci_fixup_irqs (arch/arm/kernel/bios32.c) must be called before init_service_irqs (portdrv_core.c) otherwise pcieport acts on invalid information in dev-irq and breaks. It seems that its possible for the portbus driver to pick up new devices before bios32 has been able to fixup the irqs. Making the host bridge drivers subsys will overcome this. I guess this hasn't been an issue in the past as host bridge drivers were always in the arch/ directories. In any case it may be worth testing this driver with PCIEPORTBUS enabled. Andrew Murray -- To unsubscribe from this list: send the line unsubscribe linux-samsung-soc in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v9 2/3] of/pci: mips: convert to common of_pci_range_parser
This patch converts the pci_load_of_ranges function to use the new common of_pci_range_parser. Signed-off-by: Andrew Murray andrew.mur...@arm.com Signed-off-by: Liviu Dudau liviu.du...@arm.com Signed-off-by: Gabor Juhos juh...@openwrt.org Reviewed-by: Rob Herring rob.herr...@calxeda.com Reviewed-by: Grant Likely grant.lik...@secretlab.ca Tested-by: Linus Walleij linus.wall...@linaro.org --- arch/mips/pci/pci.c | 50 ++ 1 files changed, 18 insertions(+), 32 deletions(-) diff --git a/arch/mips/pci/pci.c b/arch/mips/pci/pci.c index 0872f12..0d291e9 100644 --- a/arch/mips/pci/pci.c +++ b/arch/mips/pci/pci.c @@ -122,51 +122,37 @@ static void pcibios_scanbus(struct pci_controller *hose) #ifdef CONFIG_OF void pci_load_of_ranges(struct pci_controller *hose, struct device_node *node) { - const __be32 *ranges; - int rlen; - int pna = of_n_addr_cells(node); - int np = pna + 5; + struct of_pci_range range; + struct of_pci_range_parser parser; pr_info(PCI host bridge %s ranges:\n, node-full_name); - ranges = of_get_property(node, ranges, rlen); - if (ranges == NULL) - return; hose-of_node = node; - while ((rlen -= np * 4) = 0) { - u32 pci_space; + if (of_pci_range_parser_init(parser, node)) + return; + + for_each_of_pci_range(parser, range) { struct resource *res = NULL; - u64 addr, size; - - pci_space = be32_to_cpup(ranges[0]); - addr = of_translate_address(node, ranges + 3); - size = of_read_number(ranges + pna + 3, 2); - ranges += np; - switch ((pci_space 24) 0x3) { - case 1: /* PCI IO space */ + + switch (range.flags IORESOURCE_TYPE_BITS) { + case IORESOURCE_IO: pr_info( IO 0x%016llx..0x%016llx\n, - addr, addr + size - 1); + range.cpu_addr, + range.cpu_addr + range.size - 1); hose-io_map_base = - (unsigned long)ioremap(addr, size); + (unsigned long)ioremap(range.cpu_addr, + range.size); res = hose-io_resource; - res-flags = IORESOURCE_IO; break; - case 2: /* PCI Memory space */ - case 3: /* PCI 64 bits Memory space */ + case IORESOURCE_MEM: pr_info( MEM 0x%016llx..0x%016llx\n, - addr, addr + size - 1); + range.cpu_addr, + range.cpu_addr + range.size - 1); res = hose-mem_resource; - res-flags = IORESOURCE_MEM; break; } - if (res != NULL) { - res-start = addr; - res-name = node-full_name; - res-end = res-start + size - 1; - res-parent = NULL; - res-sibling = NULL; - res-child = NULL; - } + if (res != NULL) + of_pci_range_to_resource(range, node, res); } } #endif -- 1.7.0.4 -- To unsubscribe from this list: send the line unsubscribe linux-samsung-soc in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v9 3/3] of/pci: microblaze: convert to common of_pci_range_parser
This patch converts the pci_load_of_ranges function to use the new common of_pci_range_parser. Signed-off-by: Andrew Murray andrew.mur...@arm.com Signed-off-by: Liviu Dudau liviu.du...@arm.com --- arch/microblaze/pci/pci-common.c | 106 ++ 1 files changed, 38 insertions(+), 68 deletions(-) diff --git a/arch/microblaze/pci/pci-common.c b/arch/microblaze/pci/pci-common.c index 9ea521e..ba9e4a1 100644 --- a/arch/microblaze/pci/pci-common.c +++ b/arch/microblaze/pci/pci-common.c @@ -658,67 +658,42 @@ void pci_resource_to_user(const struct pci_dev *dev, int bar, void pci_process_bridge_OF_ranges(struct pci_controller *hose, struct device_node *dev, int primary) { - const u32 *ranges; - int rlen; - int pna = of_n_addr_cells(dev); - int np = pna + 5; int memno = 0, isa_hole = -1; - u32 pci_space; - unsigned long long pci_addr, cpu_addr, pci_next, cpu_next, size; unsigned long long isa_mb = 0; struct resource *res; + struct of_pci_range range; + struct of_pci_range_parser parser; pr_info(PCI host bridge %s %s ranges:\n, dev-full_name, primary ? (primary) : ); - /* Get ranges property */ - ranges = of_get_property(dev, ranges, rlen); - if (ranges == NULL) + /* Check for ranges property */ + if (of_pci_range_parser_init(parser, dev)) return; - /* Parse it */ pr_debug(Parsing ranges property...\n); - while ((rlen -= np * 4) = 0) { + for_each_of_pci_range(parser, range) { /* Read next ranges element */ - pci_space = ranges[0]; - pci_addr = of_read_number(ranges + 1, 2); - cpu_addr = of_translate_address(dev, ranges + 3); - size = of_read_number(ranges + pna + 3, 2); - pr_debug(pci_space: 0x%08x pci_addr:0x%016llx , - pci_space, pci_addr); + range.pci_space, range.pci_addr); pr_debug(cpu_addr:0x%016llx size:0x%016llx\n, - cpu_addr, size); - - ranges += np; + range.cpu_addr, range.size); /* If we failed translation or got a zero-sized region * (some FW try to feed us with non sensical zero sized regions * such as power3 which look like some kind of attempt * at exposing the VGA memory hole) */ - if (cpu_addr == OF_BAD_ADDR || size == 0) + if (range.cpu_addr == OF_BAD_ADDR || range.size == 0) continue; - /* Now consume following elements while they are contiguous */ - for (; rlen = np * sizeof(u32); -ranges += np, rlen -= np * 4) { - if (ranges[0] != pci_space) - break; - pci_next = of_read_number(ranges + 1, 2); - cpu_next = of_translate_address(dev, ranges + 3); - if (pci_next != pci_addr + size || - cpu_next != cpu_addr + size) - break; - size += of_read_number(ranges + pna + 3, 2); - } - /* Act based on address space type */ res = NULL; - switch ((pci_space 24) 0x3) { - case 1: /* PCI IO space */ + switch (range.flags IORESOURCE_TYPE_BITS) { + case IORESOURCE_IO: pr_info( IO 0x%016llx..0x%016llx - 0x%016llx\n, - cpu_addr, cpu_addr + size - 1, pci_addr); + range.cpu_addr, range.cpu_addr + range.size - 1, + range.pci_addr); /* We support only one IO range */ if (hose-pci_io_size) { @@ -726,11 +701,12 @@ void pci_process_bridge_OF_ranges(struct pci_controller *hose, continue; } /* On 32 bits, limit I/O space to 16MB */ - if (size 0x0100) - size = 0x0100; + if (range.size 0x0100) + range.size = 0x0100; /* 32 bits needs to map IOs here */ - hose-io_base_virt = ioremap(cpu_addr, size); + hose-io_base_virt = ioremap(range.cpu_addr, + range.size); /* Expect trouble if pci_addr is not 0 */ if (primary) @@ -739,19 +715,20 @@ void pci_process_bridge_OF_ranges(struct pci_controller *hose
[PATCH v9 0/3] of/pci: Provide common support for PCI DT parsing
This patchset factors out duplicated code associated with parsing PCI DT ranges properties across the architectures and introduces a ranges parser. This parser of_pci_range_parser can be used directly by ARM host bridge drivers enabling them to obtain ranges from device trees. I've included the Reviewed-by, Tested-by and Acked-by's received from v5/v6/v7/v8 in this patchset, earlier versions of this patchset (v3) have been tested-by: Thierry Reding thierry.red...@avionic-design.de Jingoo Han jg1@samsung.com I've tested that this patchset builds and runs on ARM and that it builds on PowerPC, x86_64, MIPS and Microblaze. Compared to the v8 sent by Andrew Murray, the following changes have been made (please note that the MIPS patch is unchanged from v8): * Remove the unification of pci_process_bridge_OF_ranges between PowerPC and Microblaze. Feedback from Bjorn and Benjamin (along with a NAK) suggested that this goes against their future direction (using more of struct pci_host_bridge and less of arch specific struct pci_controller). Compared to the v7 sent by Andrew Murray, the following changes have been made (please note that the first patch is unchanged from v7): * Rename of_pci_range_parser to of_pci_range_parser_init and of_pci_process_ranges to of_pci_range_parser_one as suggested by Grant Likely. * Reverted back to using a switch statement instead of if/else in pci_process_bridge_OF_ranges. Grant Likely highlighted this change from the original code which was unnecessary. * Squashed in a patch provided by Gabor Juhos which fixes build errors on MIPS found in the last patchset. Compared to the v6 sent by Andrew Murray, the following changes have been made in response to build errors/warnings: * Inclusion of linux/of_address.h in of_pci.c as suggested by Michal Simek to prevent compilation failures on Microblaze (and others) and his ack. * Use of externs, static inlines and a typo in linux/of_address.h in response to linker errors (multiple defination) on x86_64 as spotted by a kbuild test robot on (jcooper/linux.git mvebu/drivers) * Add EXPORT_SYMBOL_GPL to of_pci_range_parser function to be consistent with of_pci_process_ranges function Compared to the v5 sent by Andrew Murray, the following changes have been made: * Use of CONFIG_64BIT instead of CONFIG_[a32bitarch] as suggested by Rob Herring in drivers/of/of_pci.c * Added forward declaration of struct pci_controller in linux/of_pci.h to prevent compiler warning as suggested by Thomas Petazzoni * Improved error checking (!range check), removal of unnecessary be32_to_cpup call, improved formatting of struct of_pci_range_parser layout and replacement of macro with a static inline. All suggested by Rob Herring. Compared to the v4 (incorrectly labelled v3) sent by Andrew Murray, the following changes have been made: * Split the patch as suggested by Rob Herring Compared to the v3 sent by Andrew Murray, the following changes have been made: * Unify and move duplicate pci_process_bridge_OF_ranges functions to drivers/of/of_pci.c as suggested by Rob Herring * Fix potential build errors with Microblaze/MIPS Compared to [PATCH v5 01/17] of/pci: Provide support for parsing PCI DT ranges property, the following changes have been made: * Correct use of IORESOURCE_* as suggested by Russell King * Improved interface and naming as suggested by Thierry Reding Compared to the v2 sent by Andrew Murray, Thomas Petazzoni did: * Add a memset() on the struct of_pci_range_iter when starting the for loop in for_each_pci_range(). Otherwise, with an uninitialized of_pci_range_iter, of_pci_process_ranges() may crash. * Add parenthesis around 'res', 'np' and 'iter' in the for_each_of_pci_range macro definitions. Otherwise, passing something like foobar as 'res' didn't work. * Rebased on top of 3.9-rc2, which required fixing a few conflicts in the Microblaze code. v2: This follows on from suggestions made by Grant Likely (marc.info/?l=linux-kernelm=136079602806328) Andrew Murray (3): of/pci: Provide support for parsing PCI DT ranges property of/pci: mips: convert to common of_pci_range_parser of/pci: microblaze: convert to common of_pci_range_parser arch/microblaze/pci/pci-common.c | 106 ++ arch/mips/pci/pci.c | 50 ++--- drivers/of/address.c | 67 include/linux/of_address.h | 48 + 4 files changed, 171 insertions(+), 100 deletions(-) -- To unsubscribe from this list: send the line unsubscribe linux-samsung-soc in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v9 1/3] of/pci: Provide support for parsing PCI DT ranges property
This patch factors out common implementation patterns to reduce overall kernel code and provide a means for host bridge drivers to directly obtain struct resources from the DT's ranges property without relying on architecture specific DT handling. This will make it easier to write archiecture independent host bridge drivers and mitigate against further duplication of DT parsing code. This patch can be used in the following way: struct of_pci_range_parser parser; struct of_pci_range range; if (of_pci_range_parser_init(parser, np)) ; //no ranges property for_each_of_pci_range(parser, range) { /* directly access properties of the address range, e.g.: range.pci_space, range.pci_addr, range.cpu_addr, range.size, range.flags alternatively obtain a struct resource, e.g.: struct resource res; of_pci_range_to_resource(range, np, res); */ } Additionally the implementation takes care of adjacent ranges and merges them into a single range (as was the case with powerpc and microblaze). Signed-off-by: Andrew Murray andrew.mur...@arm.com Signed-off-by: Liviu Dudau liviu.du...@arm.com Signed-off-by: Thomas Petazzoni thomas.petazz...@free-electrons.com Reviewed-by: Rob Herring rob.herr...@calxeda.com Tested-by: Thomas Petazzoni thomas.petazz...@free-electrons.com Tested-by: Linus Walleij linus.wall...@linaro.org Tested-by: Jingoo Han jg1@samsung.com Acked-by: Grant Likely grant.lik...@secretlab.ca --- drivers/of/address.c | 67 include/linux/of_address.h | 48 +++ 2 files changed, 115 insertions(+), 0 deletions(-) diff --git a/drivers/of/address.c b/drivers/of/address.c index 04da786..fdd0636 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -227,6 +227,73 @@ int of_pci_address_to_resource(struct device_node *dev, int bar, return __of_address_to_resource(dev, addrp, size, flags, NULL, r); } EXPORT_SYMBOL_GPL(of_pci_address_to_resource); + +int of_pci_range_parser_init(struct of_pci_range_parser *parser, + struct device_node *node) +{ + const int na = 3, ns = 2; + int rlen; + + parser-node = node; + parser-pna = of_n_addr_cells(node); + parser-np = parser-pna + na + ns; + + parser-range = of_get_property(node, ranges, rlen); + if (parser-range == NULL) + return -ENOENT; + + parser-end = parser-range + rlen / sizeof(__be32); + + return 0; +} +EXPORT_SYMBOL_GPL(of_pci_range_parser_init); + +struct of_pci_range *of_pci_range_parser_one(struct of_pci_range_parser *parser, + struct of_pci_range *range) +{ + const int na = 3, ns = 2; + + if (!range) + return NULL; + + if (!parser-range || parser-range + parser-np parser-end) + return NULL; + + range-pci_space = parser-range[0]; + range-flags = of_bus_pci_get_flags(parser-range); + range-pci_addr = of_read_number(parser-range + 1, ns); + range-cpu_addr = of_translate_address(parser-node, + parser-range + na); + range-size = of_read_number(parser-range + parser-pna + na, ns); + + parser-range += parser-np; + + /* Now consume following elements while they are contiguous */ + while (parser-range + parser-np = parser-end) { + u32 flags, pci_space; + u64 pci_addr, cpu_addr, size; + + pci_space = be32_to_cpup(parser-range); + flags = of_bus_pci_get_flags(parser-range); + pci_addr = of_read_number(parser-range + 1, ns); + cpu_addr = of_translate_address(parser-node, + parser-range + na); + size = of_read_number(parser-range + parser-pna + na, ns); + + if (flags != range-flags) + break; + if (pci_addr != range-pci_addr + range-size || + cpu_addr != range-cpu_addr + range-size) + break; + + range-size += size; + parser-range += parser-np; + } + + return range; +} +EXPORT_SYMBOL_GPL(of_pci_range_parser_one); + #endif /* CONFIG_PCI */ /* diff --git a/include/linux/of_address.h b/include/linux/of_address.h index 0506eb5..4c2e6f2 100644 --- a/include/linux/of_address.h +++ b/include/linux/of_address.h @@ -4,6 +4,36 @@ #include linux/errno.h #include linux/of.h +struct of_pci_range_parser { + struct device_node *node; + const __be32 *range; + const __be32 *end; + int np; + int pna; +}; + +struct of_pci_range { + u32 pci_space; + u64 pci_addr; + u64 cpu_addr; + u64
[PATCH v8 1/3] of/pci: Unify pci_process_bridge_OF_ranges from Microblaze and PowerPC
The pci_process_bridge_OF_ranges function, used to parse the ranges property of a PCI host device, is found in both Microblaze and PowerPC architectures. These implementations are nearly identical. This patch moves this common code to a common place. Signed-off-by: Andrew Murray andrew.mur...@arm.com Signed-off-by: Liviu Dudau liviu.du...@arm.com Reviewed-by: Rob Herring rob.herr...@calxeda.com Tested-by: Thomas Petazzoni thomas.petazz...@free-electrons.com Tested-by: Linus Walleij linus.wall...@linaro.org Acked-by: Michal Simek mon...@monstr.eu Acked-by: Grant Likely grant.lik...@linaro.org --- arch/microblaze/include/asm/pci-bridge.h |5 +- arch/microblaze/pci/pci-common.c | 192 arch/powerpc/include/asm/pci-bridge.h|5 +- arch/powerpc/kernel/pci-common.c | 192 drivers/of/of_pci.c | 200 ++ include/linux/of_pci.h |4 + 6 files changed, 206 insertions(+), 392 deletions(-) diff --git a/arch/microblaze/include/asm/pci-bridge.h b/arch/microblaze/include/asm/pci-bridge.h index cb5d397..5783cd6 100644 --- a/arch/microblaze/include/asm/pci-bridge.h +++ b/arch/microblaze/include/asm/pci-bridge.h @@ -10,6 +10,7 @@ #include linux/pci.h #include linux/list.h #include linux/ioport.h +#include linux/of_pci.h struct device_node; @@ -132,10 +133,6 @@ extern void setup_indirect_pci(struct pci_controller *hose, extern struct pci_controller *pci_find_hose_for_OF_device( struct device_node *node); -/* Fill up host controller resources from the OF node */ -extern void pci_process_bridge_OF_ranges(struct pci_controller *hose, - struct device_node *dev, int primary); - /* Allocate free a PCI host bridge structure */ extern struct pci_controller *pcibios_alloc_controller(struct device_node *dev); extern void pcibios_free_controller(struct pci_controller *phb); diff --git a/arch/microblaze/pci/pci-common.c b/arch/microblaze/pci/pci-common.c index 9ea521e..2735ad9 100644 --- a/arch/microblaze/pci/pci-common.c +++ b/arch/microblaze/pci/pci-common.c @@ -622,198 +622,6 @@ void pci_resource_to_user(const struct pci_dev *dev, int bar, *end = rsrc-end - offset; } -/** - * pci_process_bridge_OF_ranges - Parse PCI bridge resources from device tree - * @hose: newly allocated pci_controller to be setup - * @dev: device node of the host bridge - * @primary: set if primary bus (32 bits only, soon to be deprecated) - * - * This function will parse the ranges property of a PCI host bridge device - * node and setup the resource mapping of a pci controller based on its - * content. - * - * Life would be boring if it wasn't for a few issues that we have to deal - * with here: - * - * - We can only cope with one IO space range and up to 3 Memory space - * ranges. However, some machines (thanks Apple !) tend to split their - * space into lots of small contiguous ranges. So we have to coalesce. - * - * - We can only cope with all memory ranges having the same offset - * between CPU addresses and PCI addresses. Unfortunately, some bridges - * are setup for a large 1:1 mapping along with a small window which - * maps PCI address 0 to some arbitrary high address of the CPU space in - * order to give access to the ISA memory hole. - * The way out of here that I've chosen for now is to always set the - * offset based on the first resource found, then override it if we - * have a different offset and the previous was set by an ISA hole. - * - * - Some busses have IO space not starting at 0, which causes trouble with - * the way we do our IO resource renumbering. The code somewhat deals with - * it for 64 bits but I would expect problems on 32 bits. - * - * - Some 32 bits platforms such as 4xx can have physical space larger than - * 32 bits so we need to use 64 bits values for the parsing - */ -void pci_process_bridge_OF_ranges(struct pci_controller *hose, - struct device_node *dev, int primary) -{ - const u32 *ranges; - int rlen; - int pna = of_n_addr_cells(dev); - int np = pna + 5; - int memno = 0, isa_hole = -1; - u32 pci_space; - unsigned long long pci_addr, cpu_addr, pci_next, cpu_next, size; - unsigned long long isa_mb = 0; - struct resource *res; - - pr_info(PCI host bridge %s %s ranges:\n, - dev-full_name, primary ? (primary) : ); - - /* Get ranges property */ - ranges = of_get_property(dev, ranges, rlen); - if (ranges == NULL) - return; - - /* Parse it */ - pr_debug(Parsing ranges property...\n); - while ((rlen -= np * 4) = 0) { - /* Read next ranges element */ - pci_space = ranges[0]; - pci_addr = of_read_number(ranges + 1, 2); - cpu_addr
[PATCH v8 3/3] of/pci: mips: convert to common of_pci_range_parser
This patch converts the pci_load_of_ranges function to use the new common of_pci_range_parser. Signed-off-by: Andrew Murray andrew.mur...@arm.com Signed-off-by: Liviu Dudau liviu.du...@arm.com Signed-off-by: Gabor Juhos juh...@openwrt.org Reviewed-by: Rob Herring rob.herr...@calxeda.com Reviewed-by: Grant Likely grant.lik...@secretlab.ca Tested-by: Linus Walleij linus.wall...@linaro.org --- arch/mips/pci/pci.c | 51 +++ 1 files changed, 19 insertions(+), 32 deletions(-) diff --git a/arch/mips/pci/pci.c b/arch/mips/pci/pci.c index 0872f12..4b09ca8 100644 --- a/arch/mips/pci/pci.c +++ b/arch/mips/pci/pci.c @@ -122,51 +122,38 @@ static void pcibios_scanbus(struct pci_controller *hose) #ifdef CONFIG_OF void pci_load_of_ranges(struct pci_controller *hose, struct device_node *node) { - const __be32 *ranges; - int rlen; - int pna = of_n_addr_cells(node); - int np = pna + 5; + struct of_pci_range range; + struct of_pci_range_parser parser; + u32 res_type; pr_info(PCI host bridge %s ranges:\n, node-full_name); - ranges = of_get_property(node, ranges, rlen); - if (ranges == NULL) - return; hose-of_node = node; - while ((rlen -= np * 4) = 0) { - u32 pci_space; + if (of_pci_range_parser_init(parser, node)) + return; + + for_each_of_pci_range(parser, range) { struct resource *res = NULL; - u64 addr, size; - - pci_space = be32_to_cpup(ranges[0]); - addr = of_translate_address(node, ranges + 3); - size = of_read_number(ranges + pna + 3, 2); - ranges += np; - switch ((pci_space 24) 0x3) { - case 1: /* PCI IO space */ + + switch (range.flags IORESOURCE_TYPE_BITS) { + case IORESOURCE_IO: pr_info( IO 0x%016llx..0x%016llx\n, - addr, addr + size - 1); + range.cpu_addr, + range.cpu_addr + range.size - 1); hose-io_map_base = - (unsigned long)ioremap(addr, size); + (unsigned long)ioremap(range.cpu_addr, + range.size); res = hose-io_resource; - res-flags = IORESOURCE_IO; break; - case 2: /* PCI Memory space */ - case 3: /* PCI 64 bits Memory space */ + case IORESOURCE_MEM: pr_info( MEM 0x%016llx..0x%016llx\n, - addr, addr + size - 1); + range.cpu_addr, + range.cpu_addr + range.size - 1); res = hose-mem_resource; - res-flags = IORESOURCE_MEM; break; } - if (res != NULL) { - res-start = addr; - res-name = node-full_name; - res-end = res-start + size - 1; - res-parent = NULL; - res-sibling = NULL; - res-child = NULL; - } + if (res != NULL) + of_pci_range_to_resource(range, node, res); } } #endif -- 1.7.0.4 -- To unsubscribe from this list: send the line unsubscribe linux-samsung-soc in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v8 0/3] of/pci: Provide common support for PCI DT parsing
This patchset factors out duplicated code associated with parsing PCI DT ranges properties across the architectures and introduces a ranges parser. This parser of_pci_range_parser can be used directly by ARM host bridge drivers enabling them to obtain ranges from device trees. I've included the Reviewed-by, Tested-by and Acked-by's received from v5/v6/v7 in this patchset, earlier versions of this patchset (v3) have been tested-by: Thierry Reding thierry.red...@avionic-design.de Jingoo Han jg1@samsung.com I've tested that this patchset builds and runs on ARM and that it builds on PowerPC, x86_64 and MIPS. Compared to the v7 sent by Andrew Murray, the following changes have been made (please note that the first patch is unchanged from v7): * Rename of_pci_range_parser to of_pci_range_parser_init and of_pci_process_ranges to of_pci_range_parser_one as suggested by Grant Likely. * Reverted back to using a switch statement instead of if/else in pci_process_bridge_OF_ranges. Grant Likely highlighted this change from the original code which was unnecessary. * Squashed in a patch provided by Gabor Juhos which fixes build errors on MIPS found in the last patchset. Compared to the v6 sent by Andrew Murray, the following changes have been made in response to build errors/warnings: * Inclusion of linux/of_address.h in of_pci.c as suggested by Michal Simek to prevent compilation failures on Microblaze (and others) and his ack. * Use of externs, static inlines and a typo in linux/of_address.h in response to linker errors (multiple defination) on x86_64 as spotted by a kbuild test robot on (jcooper/linux.git mvebu/drivers) * Add EXPORT_SYMBOL_GPL to of_pci_range_parser function to be consistent with of_pci_process_ranges function Compared to the v5 sent by Andrew Murray, the following changes have been made: * Use of CONFIG_64BIT instead of CONFIG_[a32bitarch] as suggested by Rob Herring in drivers/of/of_pci.c * Added forward declaration of struct pci_controller in linux/of_pci.h to prevent compiler warning as suggested by Thomas Petazzoni * Improved error checking (!range check), removal of unnecessary be32_to_cpup call, improved formatting of struct of_pci_range_parser layout and replacement of macro with a static inline. All suggested by Rob Herring. Compared to the v4 (incorrectly labelled v3) sent by Andrew Murray, the following changes have been made: * Split the patch as suggested by Rob Herring Compared to the v3 sent by Andrew Murray, the following changes have been made: * Unify and move duplicate pci_process_bridge_OF_ranges functions to drivers/of/of_pci.c as suggested by Rob Herring * Fix potential build errors with Microblaze/MIPS Compared to [PATCH v5 01/17] of/pci: Provide support for parsing PCI DT ranges property, the following changes have been made: * Correct use of IORESOURCE_* as suggested by Russell King * Improved interface and naming as suggested by Thierry Reding Compared to the v2 sent by Andrew Murray, Thomas Petazzoni did: * Add a memset() on the struct of_pci_range_iter when starting the for loop in for_each_pci_range(). Otherwise, with an uninitialized of_pci_range_iter, of_pci_process_ranges() may crash. * Add parenthesis around 'res', 'np' and 'iter' in the for_each_of_pci_range macro definitions. Otherwise, passing something like foobar as 'res' didn't work. * Rebased on top of 3.9-rc2, which required fixing a few conflicts in the Microblaze code. v2: This follows on from suggestions made by Grant Likely (marc.info/?l=linux-kernelm=136079602806328) Andrew Murray (3): of/pci: Unify pci_process_bridge_OF_ranges from Microblaze and PowerPC of/pci: Provide support for parsing PCI DT ranges property of/pci: mips: convert to common of_pci_range_parser arch/microblaze/include/asm/pci-bridge.h |5 +- arch/microblaze/pci/pci-common.c | 192 -- arch/mips/pci/pci.c | 51 +++- arch/powerpc/include/asm/pci-bridge.h|5 +- arch/powerpc/kernel/pci-common.c | 192 -- drivers/of/address.c | 67 +++ drivers/of/of_pci.c | 173 +++ include/linux/of_address.h | 48 include/linux/of_pci.h |4 + 9 files changed, 313 insertions(+), 424 deletions(-) -- To unsubscribe from this list: send the line unsubscribe linux-samsung-soc in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v8 2/3] of/pci: Provide support for parsing PCI DT ranges property
This patch factors out common implementation patterns to reduce overall kernel code and provide a means for host bridge drivers to directly obtain struct resources from the DT's ranges property without relying on architecture specific DT handling. This will make it easier to write archiecture independent host bridge drivers and mitigate against further duplication of DT parsing code. This patch can be used in the following way: struct of_pci_range_parser parser; struct of_pci_range range; if (of_pci_range_parser_init(parser, np)) ; //no ranges property for_each_of_pci_range(parser, range) { /* directly access properties of the address range, e.g.: range.pci_space, range.pci_addr, range.cpu_addr, range.size, range.flags alternatively obtain a struct resource, e.g.: struct resource res; of_pci_range_to_resource(range, np, res); */ } Additionally the implementation takes care of adjacent ranges and merges them into a single range (as was the case with powerpc and microblaze). Signed-off-by: Andrew Murray andrew.mur...@arm.com Signed-off-by: Liviu Dudau liviu.du...@arm.com Signed-off-by: Thomas Petazzoni thomas.petazz...@free-electrons.com Reviewed-by: Rob Herring rob.herr...@calxeda.com Tested-by: Thomas Petazzoni thomas.petazz...@free-electrons.com Tested-by: Linus Walleij linus.wall...@linaro.org Acked-by: Grant Likely grant.lik...@secretlab.ca --- drivers/of/address.c | 67 ++ drivers/of/of_pci.c| 113 +--- include/linux/of_address.h | 48 +++ 3 files changed, 158 insertions(+), 70 deletions(-) diff --git a/drivers/of/address.c b/drivers/of/address.c index 04da786..fdd0636 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -227,6 +227,73 @@ int of_pci_address_to_resource(struct device_node *dev, int bar, return __of_address_to_resource(dev, addrp, size, flags, NULL, r); } EXPORT_SYMBOL_GPL(of_pci_address_to_resource); + +int of_pci_range_parser_init(struct of_pci_range_parser *parser, + struct device_node *node) +{ + const int na = 3, ns = 2; + int rlen; + + parser-node = node; + parser-pna = of_n_addr_cells(node); + parser-np = parser-pna + na + ns; + + parser-range = of_get_property(node, ranges, rlen); + if (parser-range == NULL) + return -ENOENT; + + parser-end = parser-range + rlen / sizeof(__be32); + + return 0; +} +EXPORT_SYMBOL_GPL(of_pci_range_parser_init); + +struct of_pci_range *of_pci_range_parser_one(struct of_pci_range_parser *parser, + struct of_pci_range *range) +{ + const int na = 3, ns = 2; + + if (!range) + return NULL; + + if (!parser-range || parser-range + parser-np parser-end) + return NULL; + + range-pci_space = parser-range[0]; + range-flags = of_bus_pci_get_flags(parser-range); + range-pci_addr = of_read_number(parser-range + 1, ns); + range-cpu_addr = of_translate_address(parser-node, + parser-range + na); + range-size = of_read_number(parser-range + parser-pna + na, ns); + + parser-range += parser-np; + + /* Now consume following elements while they are contiguous */ + while (parser-range + parser-np = parser-end) { + u32 flags, pci_space; + u64 pci_addr, cpu_addr, size; + + pci_space = be32_to_cpup(parser-range); + flags = of_bus_pci_get_flags(parser-range); + pci_addr = of_read_number(parser-range + 1, ns); + cpu_addr = of_translate_address(parser-node, + parser-range + na); + size = of_read_number(parser-range + parser-pna + na, ns); + + if (flags != range-flags) + break; + if (pci_addr != range-pci_addr + range-size || + cpu_addr != range-cpu_addr + range-size) + break; + + range-size += size; + parser-range += parser-np; + } + + return range; +} +EXPORT_SYMBOL_GPL(of_pci_range_parser_one); + #endif /* CONFIG_PCI */ /* diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c index 1626172..3c49ab2 100644 --- a/drivers/of/of_pci.c +++ b/drivers/of/of_pci.c @@ -2,6 +2,7 @@ #include linux/export.h #include linux/of.h #include linux/of_pci.h +#include linux/of_address.h #include asm/prom.h #if defined(CONFIG_PPC32) || defined(CONFIG_PPC64) || defined(CONFIG_MICROBLAZE) @@ -82,67 +83,42 @@ EXPORT_SYMBOL_GPL(of_pci_find_child_device); void pci_process_bridge_OF_ranges(struct pci_controller
[PATCH v7 0/3] of/pci: Provide common support for PCI DT parsing
This patchset factors out duplicated code associated with parsing PCI DT ranges properties across the architectures and introduces a ranges parser. This parser of_pci_range_parser can be used directly by ARM host bridge drivers enabling them to obtain ranges from device trees. I've included the Reviewed-by and Tested-by's received from v5/v6 in this patchset, earlier versions of this patchset (v3) have been tested-by: Thierry Reding thierry.red...@avionic-design.de Jingoo Han jg1@samsung.com I've tested that this patchset builds and runs on ARM and that it builds on PowerPC and x86_64. Compared to the v6 sent by Andrew Murray, the following changes have been made in response to build errors/warnings: * Inclusion of linux/of_address.h in of_pci.c as suggested by Michal Simek to prevent compilation failures on Microblaze (and others) and his ack. * Use of externs, static inlines and a typo in linux/of_address.h in response to linker errors (multiple defination) on x86_64 as spotted by a kbuild test robot on (jcooper/linux.git mvebu/drivers) * Add EXPORT_SYMBOL_GPL to of_pci_range_parser function to be consistent with of_pci_process_ranges function Compared to the v5 sent by Andrew Murray, the following changes have been made: * Use of CONFIG_64BIT instead of CONFIG_[a32bitarch] as suggested by Rob Herring in drivers/of/of_pci.c * Added forward declaration of struct pci_controller in linux/of_pci.h to prevent compiler warning as suggested by Thomas Petazzoni * Improved error checking (!range check), removal of unnecessary be32_to_cpup call, improved formatting of struct of_pci_range_parser layout and replacement of macro with a static inline. All suggested by Rob Herring. Compared to the v4 (incorrectly labelled v3) sent by Andrew Murray, the following changes have been made: * Split the patch as suggested by Rob Herring Compared to the v3 sent by Andrew Murray, the following changes have been made: * Unify and move duplicate pci_process_bridge_OF_ranges functions to drivers/of/of_pci.c as suggested by Rob Herring * Fix potential build errors with Microblaze/MIPS Compared to [PATCH v5 01/17] of/pci: Provide support for parsing PCI DT ranges property, the following changes have been made: * Correct use of IORESOURCE_* as suggested by Russell King * Improved interface and naming as suggested by Thierry Reding Compared to the v2 sent by Andrew Murray, Thomas Petazzoni did: * Add a memset() on the struct of_pci_range_iter when starting the for loop in for_each_pci_range(). Otherwise, with an uninitialized of_pci_range_iter, of_pci_process_ranges() may crash. * Add parenthesis around 'res', 'np' and 'iter' in the for_each_of_pci_range macro definitions. Otherwise, passing something like foobar as 'res' didn't work. * Rebased on top of 3.9-rc2, which required fixing a few conflicts in the Microblaze code. v2: This follows on from suggestions made by Grant Likely (marc.info/?l=linux-kernelm=136079602806328) Andrew Murray (3): of/pci: Unify pci_process_bridge_OF_ranges from Microblaze and PowerPC of/pci: Provide support for parsing PCI DT ranges property of/pci: mips: convert to common of_pci_range_parser arch/microblaze/include/asm/pci-bridge.h |5 +- arch/microblaze/pci/pci-common.c | 192 -- arch/mips/pci/pci.c | 50 +++-- arch/powerpc/include/asm/pci-bridge.h|5 +- arch/powerpc/kernel/pci-common.c | 192 -- drivers/of/address.c | 67 +++ drivers/of/of_pci.c | 169 ++ include/linux/of_address.h | 46 +++ include/linux/of_pci.h |4 + 9 files changed, 304 insertions(+), 426 deletions(-) -- To unsubscribe from this list: send the line unsubscribe linux-samsung-soc in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v7 3/3] of/pci: mips: convert to common of_pci_range_parser
This patch converts the pci_load_of_ranges function to use the new common of_pci_range_parser. Signed-off-by: Andrew Murray andrew.mur...@arm.com Signed-off-by: Liviu Dudau liviu.du...@arm.com Reviewed-by: Rob Herring rob.herr...@calxeda.com --- arch/mips/pci/pci.c | 50 -- 1 files changed, 16 insertions(+), 34 deletions(-) diff --git a/arch/mips/pci/pci.c b/arch/mips/pci/pci.c index 0872f12..bee49a4 100644 --- a/arch/mips/pci/pci.c +++ b/arch/mips/pci/pci.c @@ -122,51 +122,33 @@ static void pcibios_scanbus(struct pci_controller *hose) #ifdef CONFIG_OF void pci_load_of_ranges(struct pci_controller *hose, struct device_node *node) { - const __be32 *ranges; - int rlen; - int pna = of_n_addr_cells(node); - int np = pna + 5; + struct of_pci_range_range range; + struct of_pci_range_parser parser; + u32 res_type; pr_info(PCI host bridge %s ranges:\n, node-full_name); - ranges = of_get_property(node, ranges, rlen); - if (ranges == NULL) - return; hose-of_node = node; - while ((rlen -= np * 4) = 0) { - u32 pci_space; + if (of_pci_range_parser(parser, node)) + return; + + for_each_of_pci_range(parser, range) { struct resource *res = NULL; - u64 addr, size; - - pci_space = be32_to_cpup(ranges[0]); - addr = of_translate_address(node, ranges + 3); - size = of_read_number(ranges + pna + 3, 2); - ranges += np; - switch ((pci_space 24) 0x3) { - case 1: /* PCI IO space */ + + res_type = range.flags IORESOURCE_TYPE_BITS; + if (res_type == IORESOURCE_IO) { pr_info( IO 0x%016llx..0x%016llx\n, - addr, addr + size - 1); + range.addr, range.addr + range.size - 1); hose-io_map_base = - (unsigned long)ioremap(addr, size); + (unsigned long)ioremap(range.addr, range.size); res = hose-io_resource; - res-flags = IORESOURCE_IO; - break; - case 2: /* PCI Memory space */ - case 3: /* PCI 64 bits Memory space */ + } else if (res_type == IORESOURCE_MEM) { pr_info( MEM 0x%016llx..0x%016llx\n, - addr, addr + size - 1); + range.addr, range.addr + range.size - 1); res = hose-mem_resource; - res-flags = IORESOURCE_MEM; - break; - } - if (res != NULL) { - res-start = addr; - res-name = node-full_name; - res-end = res-start + size - 1; - res-parent = NULL; - res-sibling = NULL; - res-child = NULL; } + if (res != NULL) + of_pci_range_to_resource(range, node, res); } } #endif -- 1.7.0.4 -- To unsubscribe from this list: send the line unsubscribe linux-samsung-soc in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v7 2/3] of/pci: Provide support for parsing PCI DT ranges property
This patch factors out common implementation patterns to reduce overall kernel code and provide a means for host bridge drivers to directly obtain struct resources from the DT's ranges property without relying on architecture specific DT handling. This will make it easier to write archiecture independent host bridge drivers and mitigate against further duplication of DT parsing code. This patch can be used in the following way: struct of_pci_range_parser parser; struct of_pci_range range; if (of_pci_range_parser(parser, np)) ; //no ranges property for_each_of_pci_range(parser, range) { /* directly access properties of the address range, e.g.: range.pci_space, range.pci_addr, range.cpu_addr, range.size, range.flags alternatively obtain a struct resource, e.g.: struct resource res; of_pci_range_to_resource(range, np, res); */ } Additionally the implementation takes care of adjacent ranges and merges them into a single range (as was the case with powerpc and microblaze). Signed-off-by: Andrew Murray andrew.mur...@arm.com Signed-off-by: Liviu Dudau liviu.du...@arm.com Signed-off-by: Thomas Petazzoni thomas.petazz...@free-electrons.com Reviewed-by: Rob Herring rob.herr...@calxeda.com Tested-by: Thomas Petazzoni thomas.petazz...@free-electrons.com Tested-by: Linus Walleij linus.wall...@linaro.org --- drivers/of/address.c | 67 ++ drivers/of/of_pci.c| 113 include/linux/of_address.h | 46 ++ 3 files changed, 154 insertions(+), 72 deletions(-) diff --git a/drivers/of/address.c b/drivers/of/address.c index 04da786..6eec70c 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -227,6 +227,73 @@ int of_pci_address_to_resource(struct device_node *dev, int bar, return __of_address_to_resource(dev, addrp, size, flags, NULL, r); } EXPORT_SYMBOL_GPL(of_pci_address_to_resource); + +int of_pci_range_parser(struct of_pci_range_parser *parser, + struct device_node *node) +{ + const int na = 3, ns = 2; + int rlen; + + parser-node = node; + parser-pna = of_n_addr_cells(node); + parser-np = parser-pna + na + ns; + + parser-range = of_get_property(node, ranges, rlen); + if (parser-range == NULL) + return -ENOENT; + + parser-end = parser-range + rlen / sizeof(__be32); + + return 0; +} +EXPORT_SYMBOL_GPL(of_pci_range_parser); + +struct of_pci_range *of_pci_process_ranges(struct of_pci_range_parser *parser, + struct of_pci_range *range) +{ + const int na = 3, ns = 2; + + if (!range) + return NULL; + + if (!parser-range || parser-range + parser-np parser-end) + return NULL; + + range-pci_space = parser-range[0]; + range-flags = of_bus_pci_get_flags(parser-range); + range-pci_addr = of_read_number(parser-range + 1, ns); + range-cpu_addr = of_translate_address(parser-node, + parser-range + na); + range-size = of_read_number(parser-range + parser-pna + na, ns); + + parser-range += parser-np; + + /* Now consume following elements while they are contiguous */ + while (parser-range + parser-np = parser-end) { + u32 flags, pci_space; + u64 pci_addr, cpu_addr, size; + + pci_space = be32_to_cpup(parser-range); + flags = of_bus_pci_get_flags(parser-range); + pci_addr = of_read_number(parser-range + 1, ns); + cpu_addr = of_translate_address(parser-node, + parser-range + na); + size = of_read_number(parser-range + parser-pna + na, ns); + + if (flags != range-flags) + break; + if (pci_addr != range-pci_addr + range-size || + cpu_addr != range-cpu_addr + range-size) + break; + + range-size += size; + parser-range += parser-np; + } + + return range; +} +EXPORT_SYMBOL_GPL(of_pci_process_ranges); + #endif /* CONFIG_PCI */ /* diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c index 1626172..e5ab604 100644 --- a/drivers/of/of_pci.c +++ b/drivers/of/of_pci.c @@ -2,6 +2,7 @@ #include linux/export.h #include linux/of.h #include linux/of_pci.h +#include linux/of_address.h #include asm/prom.h #if defined(CONFIG_PPC32) || defined(CONFIG_PPC64) || defined(CONFIG_MICROBLAZE) @@ -82,67 +83,43 @@ EXPORT_SYMBOL_GPL(of_pci_find_child_device); void pci_process_bridge_OF_ranges(struct pci_controller *hose, struct device_node *dev, int primary
[PATCH v7 1/3] of/pci: Unify pci_process_bridge_OF_ranges from Microblaze and PowerPC
The pci_process_bridge_OF_ranges function, used to parse the ranges property of a PCI host device, is found in both Microblaze and PowerPC architectures. These implementations are nearly identical. This patch moves this common code to a common place. Signed-off-by: Andrew Murray andrew.mur...@arm.com Signed-off-by: Liviu Dudau liviu.du...@arm.com Reviewed-by: Rob Herring rob.herr...@calxeda.com Tested-by: Thomas Petazzoni thomas.petazz...@free-electrons.com Tested-by: Linus Walleij linus.wall...@linaro.org Acked-by: Michal Simek mon...@monstr.eu --- arch/microblaze/include/asm/pci-bridge.h |5 +- arch/microblaze/pci/pci-common.c | 192 arch/powerpc/include/asm/pci-bridge.h|5 +- arch/powerpc/kernel/pci-common.c | 192 drivers/of/of_pci.c | 200 ++ include/linux/of_pci.h |4 + 6 files changed, 206 insertions(+), 392 deletions(-) diff --git a/arch/microblaze/include/asm/pci-bridge.h b/arch/microblaze/include/asm/pci-bridge.h index cb5d397..5783cd6 100644 --- a/arch/microblaze/include/asm/pci-bridge.h +++ b/arch/microblaze/include/asm/pci-bridge.h @@ -10,6 +10,7 @@ #include linux/pci.h #include linux/list.h #include linux/ioport.h +#include linux/of_pci.h struct device_node; @@ -132,10 +133,6 @@ extern void setup_indirect_pci(struct pci_controller *hose, extern struct pci_controller *pci_find_hose_for_OF_device( struct device_node *node); -/* Fill up host controller resources from the OF node */ -extern void pci_process_bridge_OF_ranges(struct pci_controller *hose, - struct device_node *dev, int primary); - /* Allocate free a PCI host bridge structure */ extern struct pci_controller *pcibios_alloc_controller(struct device_node *dev); extern void pcibios_free_controller(struct pci_controller *phb); diff --git a/arch/microblaze/pci/pci-common.c b/arch/microblaze/pci/pci-common.c index 9ea521e..2735ad9 100644 --- a/arch/microblaze/pci/pci-common.c +++ b/arch/microblaze/pci/pci-common.c @@ -622,198 +622,6 @@ void pci_resource_to_user(const struct pci_dev *dev, int bar, *end = rsrc-end - offset; } -/** - * pci_process_bridge_OF_ranges - Parse PCI bridge resources from device tree - * @hose: newly allocated pci_controller to be setup - * @dev: device node of the host bridge - * @primary: set if primary bus (32 bits only, soon to be deprecated) - * - * This function will parse the ranges property of a PCI host bridge device - * node and setup the resource mapping of a pci controller based on its - * content. - * - * Life would be boring if it wasn't for a few issues that we have to deal - * with here: - * - * - We can only cope with one IO space range and up to 3 Memory space - * ranges. However, some machines (thanks Apple !) tend to split their - * space into lots of small contiguous ranges. So we have to coalesce. - * - * - We can only cope with all memory ranges having the same offset - * between CPU addresses and PCI addresses. Unfortunately, some bridges - * are setup for a large 1:1 mapping along with a small window which - * maps PCI address 0 to some arbitrary high address of the CPU space in - * order to give access to the ISA memory hole. - * The way out of here that I've chosen for now is to always set the - * offset based on the first resource found, then override it if we - * have a different offset and the previous was set by an ISA hole. - * - * - Some busses have IO space not starting at 0, which causes trouble with - * the way we do our IO resource renumbering. The code somewhat deals with - * it for 64 bits but I would expect problems on 32 bits. - * - * - Some 32 bits platforms such as 4xx can have physical space larger than - * 32 bits so we need to use 64 bits values for the parsing - */ -void pci_process_bridge_OF_ranges(struct pci_controller *hose, - struct device_node *dev, int primary) -{ - const u32 *ranges; - int rlen; - int pna = of_n_addr_cells(dev); - int np = pna + 5; - int memno = 0, isa_hole = -1; - u32 pci_space; - unsigned long long pci_addr, cpu_addr, pci_next, cpu_next, size; - unsigned long long isa_mb = 0; - struct resource *res; - - pr_info(PCI host bridge %s %s ranges:\n, - dev-full_name, primary ? (primary) : ); - - /* Get ranges property */ - ranges = of_get_property(dev, ranges, rlen); - if (ranges == NULL) - return; - - /* Parse it */ - pr_debug(Parsing ranges property...\n); - while ((rlen -= np * 4) = 0) { - /* Read next ranges element */ - pci_space = ranges[0]; - pci_addr = of_read_number(ranges + 1, 2); - cpu_addr = of_translate_address(dev, ranges + 3
Re: [PATCH v5 1/3] of/pci: Unify pci_process_bridge_OF_ranges from Microblaze and PowerPC
On Wed, Apr 10, 2013 at 02:13:54PM +0100, Rob Herring wrote: Adding Ben H and Michal... On 04/10/2013 02:29 AM, Andrew Murray wrote: The pci_process_bridge_OF_ranges function, used to parse the ranges property of a PCI host device, is found in both Microblaze and PowerPC architectures. These implementations are nearly identical. This patch moves this common code to a common place. Signed-off-by: Andrew Murray andrew.mur...@arm.com Signed-off-by: Liviu Dudau liviu.du...@arm.com One comment below. Otherwise, Reviewed-by: Rob Herring rob.herr...@calxeda.com You need also need acks from Ben and Michal. [...] + /* Act based on address space type */ + res = NULL; + switch ((pci_space 24) 0x3) { + case 1: /* PCI IO space */ + pr_info( IO 0x%016llx..0x%016llx - 0x%016llx\n, + cpu_addr, cpu_addr + size - 1, pci_addr); + + /* We support only one IO range */ + if (hose-pci_io_size) { + pr_info( \\-- Skipped (too many) !\n); + continue; + } +#if defined(CONFIG_PPC32) || defined(CONFIG_MICROBLAZE) How about if (!IS_ENABLED(CONFIG_64BIT)) instead. OK I'll add in my next re-spin. Would #ifndef CONFIG_64BIT suffice? + /* On 32 bits, limit I/O space to 16MB */ + if (size 0x0100) + size = 0x0100; + + /* 32 bits needs to map IOs here */ + hose-io_base_virt = ioremap(cpu_addr, size); + + /* Expect trouble if pci_addr is not 0 */ + if (primary) + isa_io_base = + (unsigned long)hose-io_base_virt; +#endif /* CONFIG_PPC32 || CONFIG_MICROBLAZE */ + /* pci_io_size and io_base_phys always represent IO +* space starting at 0 so we factor in pci_addr +*/ + hose-pci_io_size = pci_addr + size; + hose-io_base_phys = cpu_addr - pci_addr; -- To unsubscribe from this list: send the line unsubscribe linux-samsung-soc in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v5 2/3] of/pci: Provide support for parsing PCI DT ranges property
On Wed, Apr 10, 2013 at 07:26:02PM +0100, Rob Herring wrote: On 04/10/2013 02:29 AM, Andrew Murray wrote: This patch factors out common implementation patterns to reduce overall kernel code and provide a means for host bridge drivers to directly obtain struct resources from the DT's ranges property without relying on architecture specific DT handling. This will make it easier to write archiecture independent host bridge drivers and mitigate against further duplication of DT parsing code. This patch can be used in the following way: struct of_pci_range_parser parser; struct of_pci_range range; if (of_pci_range_parser(parser, np)) ; //no ranges property for_each_of_pci_range(parser, range) { /* directly access properties of the address range, e.g.: range.pci_space, range.pci_addr, range.cpu_addr, range.size, range.flags alternatively obtain a struct resource, e.g.: struct resource res; of_pci_range_to_resource(range, np, res); */ } Additionally the implementation takes care of adjacent ranges and merges them into a single range (as was the case with powerpc and microblaze). Signed-off-by: Andrew Murray andrew.mur...@arm.com Signed-off-by: Liviu Dudau liviu.du...@arm.com Signed-off-by: Thomas Petazzoni thomas.petazz...@free-electrons.com --- A few minor things below, otherwise: Reviewed-by: Rob Herring rob.herr...@calxeda.com Thanks for the feedback, I've included this in my next spin. Andrew Murray -- To unsubscribe from this list: send the line unsubscribe linux-samsung-soc in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v6 0/3] of/pci: Provide common support for PCI DT parsing
This patchset factors out duplicated code associated with parsing PCI DT ranges properties across the architectures and introduces a ranges parser. This parser of_pci_range_parser can be used directly by ARM host bridge drivers enabling them to obtain ranges from device trees. I've included the Reviewed-by and Tested-by's received from v5 in this patchset, earlier versions of this patchset (v3) have been tested-by: Thierry Reding thierry.red...@avionic-design.de Jingoo Han jg1@samsung.com I believe a version of this patchset has also been tested through its inclusion in Thomas Petazzoni's Armada 370 and Armada XP SoCs PCIe support by: Linus Walleij linus.wall...@linaro.org I've tested that this patchset builds and runs on ARM and that it builds on PowerPC. Compared to the v5 sent by Andrew Murray, the following changes have been made: * Use of CONFIG_64BIT instead of CONFIG_[a32bitarch] as suggested by Rob Herring in drivers/of/of_pci.c * Added forward declaration of struct pci_controller in linux/of_pci.h to prevent compiler warning as suggested by Thomas Petazzoni * Improved error checking (!range check), removal of unnecessary be32_to_cpup call, improved formatting of struct of_pci_range_parser layout and replacement of macro with a static inline. All suggested by Rob Herring. Compared to the v4 (incorrectly labelled v3) sent by Andrew Murray, the following changes have been made: * Split the patch as suggested by Rob Herring Compared to the v3 sent by Andrew Murray, the following changes have been made: * Unify and move duplicate pci_process_bridge_OF_ranges functions to drivers/of/of_pci.c as suggested by Rob Herring * Fix potential build errors with Microblaze/MIPS Compared to [PATCH v5 01/17] of/pci: Provide support for parsing PCI DT ranges property, the following changes have been made: * Correct use of IORESOURCE_* as suggested by Russell King * Improved interface and naming as suggested by Thierry Reding Compared to the v2 sent by Andrew Murray, Thomas Petazzoni did: * Add a memset() on the struct of_pci_range_iter when starting the for loop in for_each_pci_range(). Otherwise, with an uninitialized of_pci_range_iter, of_pci_process_ranges() may crash. * Add parenthesis around 'res', 'np' and 'iter' in the for_each_of_pci_range macro definitions. Otherwise, passing something like foobar as 'res' didn't work. * Rebased on top of 3.9-rc2, which required fixing a few conflicts in the Microblaze code. v2: This follows on from suggestions made by Grant Likely (marc.info/?l=linux-kernelm=136079602806328) Andrew Murray (3): of/pci: Unify pci_process_bridge_OF_ranges from Microblaze and PowerPC of/pci: Provide support for parsing PCI DT ranges property of/pci: mips: convert to common of_pci_range_parser arch/microblaze/include/asm/pci-bridge.h |5 +- arch/microblaze/pci/pci-common.c | 192 -- arch/mips/pci/pci.c | 50 +++-- arch/powerpc/include/asm/pci-bridge.h|5 +- arch/powerpc/kernel/pci-common.c | 192 -- drivers/of/address.c | 66 ++ drivers/of/of_pci.c | 168 ++ include/linux/of_address.h | 46 +++ include/linux/of_pci.h |4 + 9 files changed, 302 insertions(+), 426 deletions(-) -- To unsubscribe from this list: send the line unsubscribe linux-samsung-soc in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v6 1/3] of/pci: Unify pci_process_bridge_OF_ranges from Microblaze and PowerPC
The pci_process_bridge_OF_ranges function, used to parse the ranges property of a PCI host device, is found in both Microblaze and PowerPC architectures. These implementations are nearly identical. This patch moves this common code to a common place. Signed-off-by: Andrew Murray andrew.mur...@arm.com Signed-off-by: Liviu Dudau liviu.du...@arm.com Reviewed-by: Rob Herring rob.herr...@calxeda.com Tested-by: Thomas Petazzoni thomas.petazz...@free-electrons.com --- arch/microblaze/include/asm/pci-bridge.h |5 +- arch/microblaze/pci/pci-common.c | 192 arch/powerpc/include/asm/pci-bridge.h|5 +- arch/powerpc/kernel/pci-common.c | 192 drivers/of/of_pci.c | 200 ++ include/linux/of_pci.h |4 + 6 files changed, 206 insertions(+), 392 deletions(-) diff --git a/arch/microblaze/include/asm/pci-bridge.h b/arch/microblaze/include/asm/pci-bridge.h index cb5d397..5783cd6 100644 --- a/arch/microblaze/include/asm/pci-bridge.h +++ b/arch/microblaze/include/asm/pci-bridge.h @@ -10,6 +10,7 @@ #include linux/pci.h #include linux/list.h #include linux/ioport.h +#include linux/of_pci.h struct device_node; @@ -132,10 +133,6 @@ extern void setup_indirect_pci(struct pci_controller *hose, extern struct pci_controller *pci_find_hose_for_OF_device( struct device_node *node); -/* Fill up host controller resources from the OF node */ -extern void pci_process_bridge_OF_ranges(struct pci_controller *hose, - struct device_node *dev, int primary); - /* Allocate free a PCI host bridge structure */ extern struct pci_controller *pcibios_alloc_controller(struct device_node *dev); extern void pcibios_free_controller(struct pci_controller *phb); diff --git a/arch/microblaze/pci/pci-common.c b/arch/microblaze/pci/pci-common.c index 9ea521e..2735ad9 100644 --- a/arch/microblaze/pci/pci-common.c +++ b/arch/microblaze/pci/pci-common.c @@ -622,198 +622,6 @@ void pci_resource_to_user(const struct pci_dev *dev, int bar, *end = rsrc-end - offset; } -/** - * pci_process_bridge_OF_ranges - Parse PCI bridge resources from device tree - * @hose: newly allocated pci_controller to be setup - * @dev: device node of the host bridge - * @primary: set if primary bus (32 bits only, soon to be deprecated) - * - * This function will parse the ranges property of a PCI host bridge device - * node and setup the resource mapping of a pci controller based on its - * content. - * - * Life would be boring if it wasn't for a few issues that we have to deal - * with here: - * - * - We can only cope with one IO space range and up to 3 Memory space - * ranges. However, some machines (thanks Apple !) tend to split their - * space into lots of small contiguous ranges. So we have to coalesce. - * - * - We can only cope with all memory ranges having the same offset - * between CPU addresses and PCI addresses. Unfortunately, some bridges - * are setup for a large 1:1 mapping along with a small window which - * maps PCI address 0 to some arbitrary high address of the CPU space in - * order to give access to the ISA memory hole. - * The way out of here that I've chosen for now is to always set the - * offset based on the first resource found, then override it if we - * have a different offset and the previous was set by an ISA hole. - * - * - Some busses have IO space not starting at 0, which causes trouble with - * the way we do our IO resource renumbering. The code somewhat deals with - * it for 64 bits but I would expect problems on 32 bits. - * - * - Some 32 bits platforms such as 4xx can have physical space larger than - * 32 bits so we need to use 64 bits values for the parsing - */ -void pci_process_bridge_OF_ranges(struct pci_controller *hose, - struct device_node *dev, int primary) -{ - const u32 *ranges; - int rlen; - int pna = of_n_addr_cells(dev); - int np = pna + 5; - int memno = 0, isa_hole = -1; - u32 pci_space; - unsigned long long pci_addr, cpu_addr, pci_next, cpu_next, size; - unsigned long long isa_mb = 0; - struct resource *res; - - pr_info(PCI host bridge %s %s ranges:\n, - dev-full_name, primary ? (primary) : ); - - /* Get ranges property */ - ranges = of_get_property(dev, ranges, rlen); - if (ranges == NULL) - return; - - /* Parse it */ - pr_debug(Parsing ranges property...\n); - while ((rlen -= np * 4) = 0) { - /* Read next ranges element */ - pci_space = ranges[0]; - pci_addr = of_read_number(ranges + 1, 2); - cpu_addr = of_translate_address(dev, ranges + 3); - size = of_read_number(ranges + pna + 3, 2); - - pr_debug(pci_space: 0x%08x
[PATCH v6 3/3] of/pci: mips: convert to common of_pci_range_parser
This patch converts the pci_load_of_ranges function to use the new common of_pci_range_parser. Signed-off-by: Andrew Murray andrew.mur...@arm.com Signed-off-by: Liviu Dudau liviu.du...@arm.com Reviewed-by: Rob Herring rob.herr...@calxeda.com --- arch/mips/pci/pci.c | 50 -- 1 files changed, 16 insertions(+), 34 deletions(-) diff --git a/arch/mips/pci/pci.c b/arch/mips/pci/pci.c index 0872f12..bee49a4 100644 --- a/arch/mips/pci/pci.c +++ b/arch/mips/pci/pci.c @@ -122,51 +122,33 @@ static void pcibios_scanbus(struct pci_controller *hose) #ifdef CONFIG_OF void pci_load_of_ranges(struct pci_controller *hose, struct device_node *node) { - const __be32 *ranges; - int rlen; - int pna = of_n_addr_cells(node); - int np = pna + 5; + struct of_pci_range_range range; + struct of_pci_range_parser parser; + u32 res_type; pr_info(PCI host bridge %s ranges:\n, node-full_name); - ranges = of_get_property(node, ranges, rlen); - if (ranges == NULL) - return; hose-of_node = node; - while ((rlen -= np * 4) = 0) { - u32 pci_space; + if (of_pci_range_parser(parser, node)) + return; + + for_each_of_pci_range(parser, range) { struct resource *res = NULL; - u64 addr, size; - - pci_space = be32_to_cpup(ranges[0]); - addr = of_translate_address(node, ranges + 3); - size = of_read_number(ranges + pna + 3, 2); - ranges += np; - switch ((pci_space 24) 0x3) { - case 1: /* PCI IO space */ + + res_type = range.flags IORESOURCE_TYPE_BITS; + if (res_type == IORESOURCE_IO) { pr_info( IO 0x%016llx..0x%016llx\n, - addr, addr + size - 1); + range.addr, range.addr + range.size - 1); hose-io_map_base = - (unsigned long)ioremap(addr, size); + (unsigned long)ioremap(range.addr, range.size); res = hose-io_resource; - res-flags = IORESOURCE_IO; - break; - case 2: /* PCI Memory space */ - case 3: /* PCI 64 bits Memory space */ + } else if (res_type == IORESOURCE_MEM) { pr_info( MEM 0x%016llx..0x%016llx\n, - addr, addr + size - 1); + range.addr, range.addr + range.size - 1); res = hose-mem_resource; - res-flags = IORESOURCE_MEM; - break; - } - if (res != NULL) { - res-start = addr; - res-name = node-full_name; - res-end = res-start + size - 1; - res-parent = NULL; - res-sibling = NULL; - res-child = NULL; } + if (res != NULL) + of_pci_range_to_resource(range, node, res); } } #endif -- 1.7.0.4 -- To unsubscribe from this list: send the line unsubscribe linux-samsung-soc in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v6 2/3] of/pci: Provide support for parsing PCI DT ranges property
This patch factors out common implementation patterns to reduce overall kernel code and provide a means for host bridge drivers to directly obtain struct resources from the DT's ranges property without relying on architecture specific DT handling. This will make it easier to write archiecture independent host bridge drivers and mitigate against further duplication of DT parsing code. This patch can be used in the following way: struct of_pci_range_parser parser; struct of_pci_range range; if (of_pci_range_parser(parser, np)) ; //no ranges property for_each_of_pci_range(parser, range) { /* directly access properties of the address range, e.g.: range.pci_space, range.pci_addr, range.cpu_addr, range.size, range.flags alternatively obtain a struct resource, e.g.: struct resource res; of_pci_range_to_resource(range, np, res); */ } Additionally the implementation takes care of adjacent ranges and merges them into a single range (as was the case with powerpc and microblaze). Signed-off-by: Andrew Murray andrew.mur...@arm.com Signed-off-by: Liviu Dudau liviu.du...@arm.com Signed-off-by: Thomas Petazzoni thomas.petazz...@free-electrons.com Reviewed-by: Rob Herring rob.herr...@calxeda.com Tested-by: Thomas Petazzoni thomas.petazz...@free-electrons.com --- drivers/of/address.c | 66 ++ drivers/of/of_pci.c| 112 include/linux/of_address.h | 46 ++ 3 files changed, 152 insertions(+), 72 deletions(-) diff --git a/drivers/of/address.c b/drivers/of/address.c index 04da786..d3c4f2f 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -227,6 +227,72 @@ int of_pci_address_to_resource(struct device_node *dev, int bar, return __of_address_to_resource(dev, addrp, size, flags, NULL, r); } EXPORT_SYMBOL_GPL(of_pci_address_to_resource); + +int of_pci_range_parser(struct of_pci_range_parser *parser, + struct device_node *node) +{ + const int na = 3, ns = 2; + int rlen; + + parser-node = node; + parser-pna = of_n_addr_cells(node); + parser-np = parser-pna + na + ns; + + parser-range = of_get_property(node, ranges, rlen); + if (parser-range == NULL) + return -ENOENT; + + parser-end = parser-range + rlen / sizeof(__be32); + + return 0; +} + +struct of_pci_range *of_pci_process_ranges(struct of_pci_range_parser *parser, + struct of_pci_range *range) +{ + const int na = 3, ns = 2; + + if (!range) + return NULL; + + if (!parser-range || parser-range + parser-np parser-end) + return NULL; + + range-pci_space = parser-range[0]; + range-flags = of_bus_pci_get_flags(parser-range); + range-pci_addr = of_read_number(parser-range + 1, ns); + range-cpu_addr = of_translate_address(parser-node, + parser-range + na); + range-size = of_read_number(parser-range + parser-pna + na, ns); + + parser-range += parser-np; + + /* Now consume following elements while they are contiguous */ + while (parser-range + parser-np = parser-end) { + u32 flags, pci_space; + u64 pci_addr, cpu_addr, size; + + pci_space = be32_to_cpup(parser-range); + flags = of_bus_pci_get_flags(parser-range); + pci_addr = of_read_number(parser-range + 1, ns); + cpu_addr = of_translate_address(parser-node, + parser-range + na); + size = of_read_number(parser-range + parser-pna + na, ns); + + if (flags != range-flags) + break; + if (pci_addr != range-pci_addr + range-size || + cpu_addr != range-cpu_addr + range-size) + break; + + range-size += size; + parser-range += parser-np; + } + + return range; +} +EXPORT_SYMBOL_GPL(of_pci_process_ranges); + #endif /* CONFIG_PCI */ /* diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c index 1626172..3e428a1 100644 --- a/drivers/of/of_pci.c +++ b/drivers/of/of_pci.c @@ -82,67 +82,43 @@ EXPORT_SYMBOL_GPL(of_pci_find_child_device); void pci_process_bridge_OF_ranges(struct pci_controller *hose, struct device_node *dev, int primary) { - const u32 *ranges; - int rlen; - int pna = of_n_addr_cells(dev); - int np = pna + 5; int memno = 0, isa_hole = -1; - u32 pci_space; - unsigned long long pci_addr, cpu_addr, pci_next, cpu_next, size; unsigned long long isa_mb = 0; struct resource
[PATCH v5 3/3] of/pci: mips: convert to common of_pci_range_parser
This patch converts the pci_load_of_ranges function to use the new common of_pci_range_parser. Signed-off-by: Andrew Murray andrew.mur...@arm.com Signed-off-by: Liviu Dudau liviu.du...@arm.com --- arch/mips/pci/pci.c | 50 -- 1 files changed, 16 insertions(+), 34 deletions(-) diff --git a/arch/mips/pci/pci.c b/arch/mips/pci/pci.c index 0872f12..bee49a4 100644 --- a/arch/mips/pci/pci.c +++ b/arch/mips/pci/pci.c @@ -122,51 +122,33 @@ static void pcibios_scanbus(struct pci_controller *hose) #ifdef CONFIG_OF void pci_load_of_ranges(struct pci_controller *hose, struct device_node *node) { - const __be32 *ranges; - int rlen; - int pna = of_n_addr_cells(node); - int np = pna + 5; + struct of_pci_range_range range; + struct of_pci_range_parser parser; + u32 res_type; pr_info(PCI host bridge %s ranges:\n, node-full_name); - ranges = of_get_property(node, ranges, rlen); - if (ranges == NULL) - return; hose-of_node = node; - while ((rlen -= np * 4) = 0) { - u32 pci_space; + if (of_pci_range_parser(parser, node)) + return; + + for_each_of_pci_range(parser, range) { struct resource *res = NULL; - u64 addr, size; - - pci_space = be32_to_cpup(ranges[0]); - addr = of_translate_address(node, ranges + 3); - size = of_read_number(ranges + pna + 3, 2); - ranges += np; - switch ((pci_space 24) 0x3) { - case 1: /* PCI IO space */ + + res_type = range.flags IORESOURCE_TYPE_BITS; + if (res_type == IORESOURCE_IO) { pr_info( IO 0x%016llx..0x%016llx\n, - addr, addr + size - 1); + range.addr, range.addr + range.size - 1); hose-io_map_base = - (unsigned long)ioremap(addr, size); + (unsigned long)ioremap(range.addr, range.size); res = hose-io_resource; - res-flags = IORESOURCE_IO; - break; - case 2: /* PCI Memory space */ - case 3: /* PCI 64 bits Memory space */ + } else if (res_type == IORESOURCE_MEM) { pr_info( MEM 0x%016llx..0x%016llx\n, - addr, addr + size - 1); + range.addr, range.addr + range.size - 1); res = hose-mem_resource; - res-flags = IORESOURCE_MEM; - break; - } - if (res != NULL) { - res-start = addr; - res-name = node-full_name; - res-end = res-start + size - 1; - res-parent = NULL; - res-sibling = NULL; - res-child = NULL; } + if (res != NULL) + of_pci_range_to_resource(range, node, res); } } #endif -- 1.7.0.4 -- To unsubscribe from this list: send the line unsubscribe linux-samsung-soc in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v5 0/3] of/pci: Provide common support for PCI DT parsing
This patchset factors out duplicated code associated with parsing PCI DT ranges properties across the architectures and introduces a ranges parser. This parser of_pci_range_parser can be used directly by ARM host bridge drivers enabling them to obtain ranges from device trees. Compared to the v4 (incorrectly labelled v3) sent by Andrew Murray, the following changes have been made: * Split the patch as suggested by Rob Herring Compared to the v3 sent by Andrew Murray, the following changes have been made: * Unify and move duplicate pci_process_bridge_OF_ranges functions to drivers/of/of_pci.c as suggested by Rob Herring * Fix potential build errors with Microblaze/MIPS Compared to [PATCH v5 01/17] of/pci: Provide support for parsing PCI DT ranges property, the following changes have been made: * Correct use of IORESOURCE_* as suggested by Russell King * Improved interface and naming as suggested by Thierry Reding Compared to the v2 sent by Andrew Murray, Thomas Petazzoni did: * Add a memset() on the struct of_pci_range_iter when starting the for loop in for_each_pci_range(). Otherwise, with an uninitialized of_pci_range_iter, of_pci_process_ranges() may crash. * Add parenthesis around 'res', 'np' and 'iter' in the for_each_of_pci_range macro definitions. Otherwise, passing something like foobar as 'res' didn't work. * Rebased on top of 3.9-rc2, which required fixing a few conflicts in the Microblaze code. v2: This follows on from suggestions made by Grant Likely (marc.info/?l=linux-kernelm=136079602806328) Andrew Murray (3): of/pci: Unify pci_process_bridge_OF_ranges from Microblaze and PowerPC of/pci: Provide support for parsing PCI DT ranges property of/pci: mips: convert to common of_pci_range_parser arch/microblaze/include/asm/pci-bridge.h |5 +- arch/microblaze/pci/pci-common.c | 192 -- arch/mips/pci/pci.c | 50 +++-- arch/powerpc/include/asm/pci-bridge.h|5 +- arch/powerpc/kernel/pci-common.c | 192 -- drivers/of/address.c | 63 ++ drivers/of/of_pci.c | 168 ++ include/linux/of_address.h | 42 +++ include/linux/of_pci.h |3 + 9 files changed, 294 insertions(+), 426 deletions(-) -- To unsubscribe from this list: send the line unsubscribe linux-samsung-soc in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v5 2/3] of/pci: Provide support for parsing PCI DT ranges property
This patch factors out common implementation patterns to reduce overall kernel code and provide a means for host bridge drivers to directly obtain struct resources from the DT's ranges property without relying on architecture specific DT handling. This will make it easier to write archiecture independent host bridge drivers and mitigate against further duplication of DT parsing code. This patch can be used in the following way: struct of_pci_range_parser parser; struct of_pci_range range; if (of_pci_range_parser(parser, np)) ; //no ranges property for_each_of_pci_range(parser, range) { /* directly access properties of the address range, e.g.: range.pci_space, range.pci_addr, range.cpu_addr, range.size, range.flags alternatively obtain a struct resource, e.g.: struct resource res; of_pci_range_to_resource(range, np, res); */ } Additionally the implementation takes care of adjacent ranges and merges them into a single range (as was the case with powerpc and microblaze). Signed-off-by: Andrew Murray andrew.mur...@arm.com Signed-off-by: Liviu Dudau liviu.du...@arm.com Signed-off-by: Thomas Petazzoni thomas.petazz...@free-electrons.com --- drivers/of/address.c | 63 + drivers/of/of_pci.c| 112 include/linux/of_address.h | 42 3 files changed, 145 insertions(+), 72 deletions(-) diff --git a/drivers/of/address.c b/drivers/of/address.c index 04da786..e87f45e 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -227,6 +227,69 @@ int of_pci_address_to_resource(struct device_node *dev, int bar, return __of_address_to_resource(dev, addrp, size, flags, NULL, r); } EXPORT_SYMBOL_GPL(of_pci_address_to_resource); + +int of_pci_range_parser(struct of_pci_range_parser *parser, + struct device_node *node) +{ + const int na = 3, ns = 2; + int rlen; + + parser-node = node; + parser-pna = of_n_addr_cells(node); + parser-np = parser-pna + na + ns; + + parser-range = of_get_property(node, ranges, rlen); + if (parser-range == NULL) + return -ENOENT; + + parser-end = parser-range + rlen / sizeof(__be32); + + return 0; +} + +struct of_pci_range *of_pci_process_ranges(struct of_pci_range_parser *parser, + struct of_pci_range *range) +{ + const int na = 3, ns = 2; + + if (!parser-range || parser-range + parser-np parser-end) + return NULL; + + range-pci_space = be32_to_cpup(parser-range); + range-flags = of_bus_pci_get_flags(parser-range); + range-pci_addr = of_read_number(parser-range + 1, ns); + range-cpu_addr = of_translate_address(parser-node, + parser-range + na); + range-size = of_read_number(parser-range + parser-pna + na, ns); + + parser-range += parser-np; + + /* Now consume following elements while they are contiguous */ + while (parser-range + parser-np = parser-end) { + u32 flags, pci_space; + u64 pci_addr, cpu_addr, size; + + pci_space = be32_to_cpup(parser-range); + flags = of_bus_pci_get_flags(parser-range); + pci_addr = of_read_number(parser-range + 1, ns); + cpu_addr = of_translate_address(parser-node, + parser-range + na); + size = of_read_number(parser-range + parser-pna + na, ns); + + if (flags != range-flags) + break; + if (pci_addr != range-pci_addr + range-size || + cpu_addr != range-cpu_addr + range-size) + break; + + range-size += size; + parser-range += parser-np; + } + + return range; +} +EXPORT_SYMBOL_GPL(of_pci_process_ranges); + #endif /* CONFIG_PCI */ /* diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c index 0611248..9680dc6 100644 --- a/drivers/of/of_pci.c +++ b/drivers/of/of_pci.c @@ -82,67 +82,43 @@ EXPORT_SYMBOL_GPL(of_pci_find_child_device); void pci_process_bridge_OF_ranges(struct pci_controller *hose, struct device_node *dev, int primary) { - const u32 *ranges; - int rlen; - int pna = of_n_addr_cells(dev); - int np = pna + 5; int memno = 0, isa_hole = -1; - u32 pci_space; - unsigned long long pci_addr, cpu_addr, pci_next, cpu_next, size; unsigned long long isa_mb = 0; struct resource *res; + struct of_pci_range range; + struct of_pci_range_parser parser; + u32 res_type; pr_info(PCI host bridge %s %s ranges:\n
[PATCH v5 1/3] of/pci: Unify pci_process_bridge_OF_ranges from Microblaze and PowerPC
The pci_process_bridge_OF_ranges function, used to parse the ranges property of a PCI host device, is found in both Microblaze and PowerPC architectures. These implementations are nearly identical. This patch moves this common code to a common place. Signed-off-by: Andrew Murray andrew.mur...@arm.com Signed-off-by: Liviu Dudau liviu.du...@arm.com --- arch/microblaze/include/asm/pci-bridge.h |5 +- arch/microblaze/pci/pci-common.c | 192 arch/powerpc/include/asm/pci-bridge.h|5 +- arch/powerpc/kernel/pci-common.c | 192 drivers/of/of_pci.c | 200 ++ include/linux/of_pci.h |3 + 6 files changed, 205 insertions(+), 392 deletions(-) diff --git a/arch/microblaze/include/asm/pci-bridge.h b/arch/microblaze/include/asm/pci-bridge.h index cb5d397..5783cd6 100644 --- a/arch/microblaze/include/asm/pci-bridge.h +++ b/arch/microblaze/include/asm/pci-bridge.h @@ -10,6 +10,7 @@ #include linux/pci.h #include linux/list.h #include linux/ioport.h +#include linux/of_pci.h struct device_node; @@ -132,10 +133,6 @@ extern void setup_indirect_pci(struct pci_controller *hose, extern struct pci_controller *pci_find_hose_for_OF_device( struct device_node *node); -/* Fill up host controller resources from the OF node */ -extern void pci_process_bridge_OF_ranges(struct pci_controller *hose, - struct device_node *dev, int primary); - /* Allocate free a PCI host bridge structure */ extern struct pci_controller *pcibios_alloc_controller(struct device_node *dev); extern void pcibios_free_controller(struct pci_controller *phb); diff --git a/arch/microblaze/pci/pci-common.c b/arch/microblaze/pci/pci-common.c index 9ea521e..2735ad9 100644 --- a/arch/microblaze/pci/pci-common.c +++ b/arch/microblaze/pci/pci-common.c @@ -622,198 +622,6 @@ void pci_resource_to_user(const struct pci_dev *dev, int bar, *end = rsrc-end - offset; } -/** - * pci_process_bridge_OF_ranges - Parse PCI bridge resources from device tree - * @hose: newly allocated pci_controller to be setup - * @dev: device node of the host bridge - * @primary: set if primary bus (32 bits only, soon to be deprecated) - * - * This function will parse the ranges property of a PCI host bridge device - * node and setup the resource mapping of a pci controller based on its - * content. - * - * Life would be boring if it wasn't for a few issues that we have to deal - * with here: - * - * - We can only cope with one IO space range and up to 3 Memory space - * ranges. However, some machines (thanks Apple !) tend to split their - * space into lots of small contiguous ranges. So we have to coalesce. - * - * - We can only cope with all memory ranges having the same offset - * between CPU addresses and PCI addresses. Unfortunately, some bridges - * are setup for a large 1:1 mapping along with a small window which - * maps PCI address 0 to some arbitrary high address of the CPU space in - * order to give access to the ISA memory hole. - * The way out of here that I've chosen for now is to always set the - * offset based on the first resource found, then override it if we - * have a different offset and the previous was set by an ISA hole. - * - * - Some busses have IO space not starting at 0, which causes trouble with - * the way we do our IO resource renumbering. The code somewhat deals with - * it for 64 bits but I would expect problems on 32 bits. - * - * - Some 32 bits platforms such as 4xx can have physical space larger than - * 32 bits so we need to use 64 bits values for the parsing - */ -void pci_process_bridge_OF_ranges(struct pci_controller *hose, - struct device_node *dev, int primary) -{ - const u32 *ranges; - int rlen; - int pna = of_n_addr_cells(dev); - int np = pna + 5; - int memno = 0, isa_hole = -1; - u32 pci_space; - unsigned long long pci_addr, cpu_addr, pci_next, cpu_next, size; - unsigned long long isa_mb = 0; - struct resource *res; - - pr_info(PCI host bridge %s %s ranges:\n, - dev-full_name, primary ? (primary) : ); - - /* Get ranges property */ - ranges = of_get_property(dev, ranges, rlen); - if (ranges == NULL) - return; - - /* Parse it */ - pr_debug(Parsing ranges property...\n); - while ((rlen -= np * 4) = 0) { - /* Read next ranges element */ - pci_space = ranges[0]; - pci_addr = of_read_number(ranges + 1, 2); - cpu_addr = of_translate_address(dev, ranges + 3); - size = of_read_number(ranges + pna + 3, 2); - - pr_debug(pci_space: 0x%08x pci_addr:0x%016llx , - pci_space, pci_addr); - pr_debug(cpu_addr:0x
[PATCH v3] of/pci: Provide support for parsing PCI DT ranges property
This patch factors out common implementation patterns to reduce overall kernel code and provide a means for host bridge drivers to directly obtain struct resources from the DT's ranges property without relying on architecture specific DT handling. This will make it easier to write archiecture independent host bridge drivers and mitigate against further duplication of DT parsing code. This patch can be used in the following way: struct of_pci_range_parser parser; struct of_pci_range range; if (of_pci_range_parser(parser, np)) ; //no ranges property for_each_of_pci_range(parser, range) { /* directly access properties of the address range, e.g.: range.pci_space, range.pci_addr, range.cpu_addr, range.size, range.flags alternatively obtain a struct resource, e.g.: struct resource res; of_pci_range_to_resource(range, np, res); */ } Additionally the implementation takes care of adjacent ranges and merges them into a single range (as was the case with powerpc and microblaze). The modifications to microblaze, mips and powerpc have not been tested. Signed-off-by: Andrew Murray andrew.mur...@arm.com Signed-off-by: Liviu Dudau liviu.du...@arm.com Signed-off-by: Thomas Petazzoni thomas.petazz...@free-electrons.com --- Compared to the v3 sent by Andrew Murray, the following changes have been made: * Unify and move duplicate pci_process_bridge_OF_ranges functions to drivers/of/of_pci.c as suggested by Rob Herring * Fix potential build errors with Microblaze/MIPS Compared to [PATCH v5 01/17] of/pci: Provide support for parsing PCI DT ranges property, the following changes have been made: * Correct use of IORESOURCE_* as suggested by Russell King * Improved interface and naming as suggested by Thierry Reding Compared to the v2 sent by Andrew Murray, Thomas Petazzoni did: * Add a memset() on the struct of_pci_range_iter when starting the for loop in for_each_pci_range(). Otherwise, with an uninitialized of_pci_range_iter, of_pci_process_ranges() may crash. * Add parenthesis around 'res', 'np' and 'iter' in the for_each_of_pci_range macro definitions. Otherwise, passing something like foobar as 'res' didn't work. * Rebased on top of 3.9-rc2, which required fixing a few conflicts in the Microblaze code. v2: This follows on from suggestions made by Grant Likely (marc.info/?l=linux-kernelm=136079602806328) --- arch/microblaze/include/asm/pci-bridge.h |5 +- arch/microblaze/pci/pci-common.c | 192 -- arch/mips/pci/pci.c | 50 +++-- arch/powerpc/include/asm/pci-bridge.h|5 +- arch/powerpc/kernel/pci-common.c | 192 -- drivers/of/address.c | 63 ++ drivers/of/of_pci.c | 168 ++ include/linux/of_address.h | 42 +++ include/linux/of_pci.h |3 + 9 files changed, 294 insertions(+), 426 deletions(-) diff --git a/arch/microblaze/include/asm/pci-bridge.h b/arch/microblaze/include/asm/pci-bridge.h index cb5d397..5783cd6 100644 --- a/arch/microblaze/include/asm/pci-bridge.h +++ b/arch/microblaze/include/asm/pci-bridge.h @@ -10,6 +10,7 @@ #include linux/pci.h #include linux/list.h #include linux/ioport.h +#include linux/of_pci.h struct device_node; @@ -132,10 +133,6 @@ extern void setup_indirect_pci(struct pci_controller *hose, extern struct pci_controller *pci_find_hose_for_OF_device( struct device_node *node); -/* Fill up host controller resources from the OF node */ -extern void pci_process_bridge_OF_ranges(struct pci_controller *hose, - struct device_node *dev, int primary); - /* Allocate free a PCI host bridge structure */ extern struct pci_controller *pcibios_alloc_controller(struct device_node *dev); extern void pcibios_free_controller(struct pci_controller *phb); diff --git a/arch/microblaze/pci/pci-common.c b/arch/microblaze/pci/pci-common.c index 9ea521e..2735ad9 100644 --- a/arch/microblaze/pci/pci-common.c +++ b/arch/microblaze/pci/pci-common.c @@ -622,198 +622,6 @@ void pci_resource_to_user(const struct pci_dev *dev, int bar, *end = rsrc-end - offset; } -/** - * pci_process_bridge_OF_ranges - Parse PCI bridge resources from device tree - * @hose: newly allocated pci_controller to be setup - * @dev: device node of the host bridge - * @primary: set if primary bus (32 bits only, soon to be deprecated) - * - * This function will parse the ranges property of a PCI host bridge device - * node and setup the resource mapping of a pci controller based on its - * content. - * - * Life would be boring if it wasn't for a few issues that we have to deal
[PATCH v3] of/pci: Provide support for parsing PCI DT ranges property
This patch factors out common implementation patterns to reduce overall kernel code and provide a means for host bridge drivers to directly obtain struct resources from the DT's ranges property without relying on architecture specific DT handling. This will make it easier to write archiecture independent host bridge drivers and mitigate against further duplication of DT parsing code. This patch can be used in the following way: struct of_pci_range_parser parser; struct of_pci_range range; if (of_pci_range_parser(parser, np)) ; //no ranges property for_each_of_pci_range(parser, range) { /* directly access properties of the address range, e.g.: range.pci_space, range.pci_addr, range.cpu_addr, range.size, range.flags alternatively obtain a struct resource, e.g.: struct resource res; of_pci_range_to_resource(range, np, res); */ } Additionally the implementation takes care of adjacent ranges and merges them into a single range (as was the case with powerpc and microblaze). The modifications to microblaze, mips and powerpc have not been tested. Signed-off-by: Andrew Murray andrew.mur...@arm.com Signed-off-by: Liviu Dudau liviu.du...@arm.com Signed-off-by: Thomas Petazzoni thomas.petazz...@free-electrons.com --- Compared to [PATCH v5 01/17] of/pci: Provide support for parsing PCI DT ranges property, the following changes have been made: * Correct use of IORESOURCE_* as suggested by Russell King * Improved interface and naming as suggested by Thierry Reding Compared to the v2 sent by Andrew Murray, Thomas Petazzoni did: * Add a memset() on the struct of_pci_range_iter when starting the for loop in for_each_pci_range(). Otherwise, with an uninitialized of_pci_range_iter, of_pci_process_ranges() may crash. * Add parenthesis around 'res', 'np' and 'iter' in the for_each_of_pci_range macro definitions. Otherwise, passing something like foobar as 'res' didn't work. * Rebased on top of 3.9-rc2, which required fixing a few conflicts in the Microblaze code. v2: This follows on from suggestions made by Grant Likely (marc.info/?l=linux-kernelm=136079602806328) --- arch/microblaze/pci/pci-common.c | 110 + arch/mips/pci/pci.c | 50 ++ arch/powerpc/kernel/pci-common.c | 99 -- drivers/of/address.c | 63 ++ include/linux/of_address.h | 42 ++ 5 files changed, 194 insertions(+), 170 deletions(-) diff --git a/arch/microblaze/pci/pci-common.c b/arch/microblaze/pci/pci-common.c index 9ea521e..17a7ad1 100644 --- a/arch/microblaze/pci/pci-common.c +++ b/arch/microblaze/pci/pci-common.c @@ -658,67 +658,43 @@ void pci_resource_to_user(const struct pci_dev *dev, int bar, void pci_process_bridge_OF_ranges(struct pci_controller *hose, struct device_node *dev, int primary) { - const u32 *ranges; - int rlen; - int pna = of_n_addr_cells(dev); - int np = pna + 5; int memno = 0, isa_hole = -1; - u32 pci_space; - unsigned long long pci_addr, cpu_addr, pci_next, cpu_next, size; unsigned long long isa_mb = 0; struct resource *res; + struct of_pci_range range; + struct of_pci_range_parser parser; + u32 res_type; pr_info(PCI host bridge %s %s ranges:\n, dev-full_name, primary ? (primary) : ); - /* Get ranges property */ - ranges = of_get_property(dev, ranges, rlen); - if (ranges == NULL) + /* Check for ranges property */ + if (of_pci_range_parser(parser, dev)) return; - /* Parse it */ pr_debug(Parsing ranges property...\n); - while ((rlen -= np * 4) = 0) { + for_each_of_pci_range(parser, range) { /* Read next ranges element */ - pci_space = ranges[0]; - pci_addr = of_read_number(ranges + 1, 2); - cpu_addr = of_translate_address(dev, ranges + 3); - size = of_read_number(ranges + pna + 3, 2); - - pr_debug(pci_space: 0x%08x pci_addr:0x%016llx , - pci_space, pci_addr); - pr_debug(cpu_addr:0x%016llx size:0x%016llx\n, - cpu_addr, size); - - ranges += np; + pr_debug(pci_space: 0x%08x pci_addr: 0x%016llx , + range.pci_space, range.pci_addr); + pr_debug(cpu_addr: 0x%016llx size: 0x%016llx\n, + range.cpu_addr, range.size); /* If we failed translation or got a zero-sized region * (some FW try to feed us with non sensical
Re: [PATCH 1/6] of/pci: Provide support for parsing PCI DT ranges property
On Sat, Mar 23, 2013 at 01:37:04PM +, Thomas Petazzoni wrote: On Sat, 23 Mar 2013 10:41:56 +, Russell King - ARM Linux wrote: Please look at how IORESOURCE_* stuff is defined: #define IORESOURCE_TYPE_BITS0x1f00 /* Resource type */ #define IORESOURCE_IO 0x0100 /* PCI/ISA I/O ports */ #define IORESOURCE_MEM 0x0200 #define IORESOURCE_REG 0x0300 /* Register offsets */ #define IORESOURCE_IRQ 0x0400 #define IORESOURCE_DMA 0x0800 #define IORESOURCE_BUS 0x1000 Notice that it's not an array of bits. So this should be: if ((iter.flags IORESOURCE_TYPE_BITS) == IORESOURCE_IO) { What I've done for the Marvell PCIe driver is: + for_each_of_pci_range(iter, np) { + unsigned long restype = iter.flags IORESOURCE_TYPE_BITS; + if (restype == IORESOURCE_IO) { [...] + if (restype == IORESOURCE_MEM) { [...] OK I'll update this patch and also include Thierry's suggestions. Andrew Murray -- To unsubscribe from this list: send the line unsubscribe linux-samsung-soc in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 1/2] ARM: EXYNOS: Add PCIe driver support
On Mon, Mar 04, 2013 at 10:22:28AM +, Jingoo Han wrote: Exynos5440 has two PCIe controllers which can be used as Root Complex. This driver supports the PCIe controllers as Root Complex mode. Signed-off-by: Surendranath Gurivireddy Balla suren.re...@samsung.com Signed-off-by: Siva Reddy Kallam siva.kal...@samsung.com Signed-off-by: Jingoo Han jg1@samsung.com --- .../devicetree/bindings/pci/exynos-pcie.txt| 58 ++ arch/arm/Kconfig |2 + arch/arm/mach-exynos/Kconfig |8 + arch/arm/mach-exynos/Makefile |2 + arch/arm/mach-exynos/include/mach/pcie.h | 146 +++ arch/arm/mach-exynos/pcie.c| 1009 6 files changed, 1225 insertions(+), 0 deletions(-) create mode 100644 Documentation/devicetree/bindings/pci/exynos-pcie.txt create mode 100644 arch/arm/mach-exynos/include/mach/pcie.h create mode 100644 arch/arm/mach-exynos/pcie.c diff --git a/Documentation/devicetree/bindings/pci/exynos-pcie.txt b/Documentation/devicetree/bindings/pci/exynos-pcie.txt new file mode 100644 index 000..4fe05b5 --- /dev/null +++ b/Documentation/devicetree/bindings/pci/exynos-pcie.txt @@ -0,0 +1,58 @@ +* Samsung Exynos PCIe interface + +Required properties: +-compatible: should be samsung,pcie-host +-reg: base addresses and lengths of the pcie conteroller, + additional register for the pcie controller, + the phy controller, + additional register for the phy controller. +- interrupts: interrupt values for level interrupt, + pulse interrupt, special interrupt. +- pcie-host,io_size: memory size for IO +- pcie-host,cfg0_size: memory size for CFG0 +- pcie-host,cfg1_size: memory size for CFG1 +- pcie-host,mem_size: memory size for MEM +- pcie-host,in_mem_size: memory size for Inbound MEM +- reset-gpio: gpio pin number of power good signal + +Example: + +SoC specific DT Entry: + + pcie0@4000 { + compatible = samsung,pcie-host; + reg = 0x4000 0x4000 + 0x29 0x1000 + 0x27 0x1000 + 0x271000 0x40; + interrupts = 0 20 0, 0 21 0, 0 22 0; + pcie-host,io_size = 0x4000; + pcie-host,cfg0_size = 0x10; + pcie-host,cfg1_size = 0x10; + pcie-host,mem_size = 0x1000; + pcie-host,in_mem_size = 0x800; + }; + It's quite common for information such as mem_size and io_size to be represented with the defacto binding ranges - see http://devicetree.org/Device_Tree_Usage#PCI_Address_Translation. Thomas Petazzoni and Thierry Reding have recent patch sets that use this representation. The ranges property is used across many architectures of the kernel, however each architecture has its own way of parsing this binding. There isn't an accepted version for ARM yet but efforts are underway to add one that doesn't duplicate code. It would probably make sense for all these new PCIe host drivers to be consistent where possible. Andrew Murray -- To unsubscribe from this list: send the line unsubscribe linux-samsung-soc in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html