powerpc/pci: Add a platform hook after probe and before resource survey
PATCH 1/5 powerpc/pci: Add a platform hook after probe and before resource survey
Some platforms need to perform resource allocation using a custom algorithm due to HW constraints, or may want to tweak things globally below a host bridge. For example OPAL support for IODA will need to perform a resource allocation pass that applies IODA specific segmentation constraints to MMIO which cannot be done simply using the kernel generic resource management code.
--- arch/powerpc/include/asm/machdep.h | 3 +++ arch/powerpc/kernel/pci-common.c | 6 ++++++ 2 files changed, 9 insertions(+), 0 deletions(-)
arch/powerpc/include/asm/machdep.h +3 -0
@@ -212,6 +212,9 @@ struct machdep_calls {* allow assignment/enabling of the device. */ int (*pcibios_enable_device_hook)(struct pci_dev *); +/* Called after scan and before resource survey */ +void (*pcibios_fixup_phb)(struct pci_controller *hose); +/* Called to shutdown machine specific hardware not already controlled * by other drivers. */
arch/powerpc/kernel/pci-common.c +6 -0
@@ -1731,6 +1731,12 @@ void __devinit pcibios_scan_phb(struct pci_controller *hose)if (mode ==PCI_PROBE_NORMAL ) hose->last_busno = bus->subordinate =pci_scan_child_bus (bus); +/* Platform gets a chance to do some global fixups before +* we proceed to resource allocation +*/ +if (ppc_md.pcibios_fixup_phb) + ppc_md.pcibios_fixup_phb (hose); +/* Configure PCI Express settings */ if (bus && !pci_has_flag (PCI_PROBE_ONLY )) {struct pci_bus *child;
Signature · 1 line
1.7.7.1
PATCH 2/5 powerpc/pci: Change how re-assigning resouces work
When PCI_REASSIGN_ALL_RSRC is set, we used to clear all bus resources at the beginning of survey and re-allocate them later.
This changes it so instead, during early fixup, we mark all resources as IORESOURCE_UNSET and move them down to be 0-based.
Later, if bus resources are still unset at the beginning of the survey, then we clear them.
This shouldn't impact the re-assignment case on 4xx, but will enable us to have the platform do some custom resource assignment before the survey, by clearing individual resources IORESOURCE_UNSET bit.
Also limits the clutter in the kernel log from fixup when re-assigning since we don't care about the offset applied to the BAR values in this case.
--- arch/powerpc/kernel/pci-common.c | 66 ++++++++++++++++++++----------------- 1 files changed, 36 insertions(+), 30 deletions(-)
arch/powerpc/kernel/pci-common.c +36 -30
@@ -920,18 +920,22 @@ static void __devinit pcibios_fixup_resources(struct pci_dev *dev)struct resource *res = dev->resource + i;if (!res->flags)continue ; -/* On platforms that have PCI_PROBE_ONLY set, we don't -* consider 0 as an unassigned BAR value. It's technically -* a valid value, but linux doesn't like it... so when we can -* re-assign things, we do so, but if we can't, we keep it -* around and hope for the best... + +/* If we're going to re-assign everything, we mark all resources +* as unset (and 0-base them). In addition, we mark BARs starting +* at 0 as unset as well, except if PCI_PROBE_ONLY is also set +* since in that case, we don't want to re-assign anything */ -if (res->start ==0 && !pci_has_flag (PCI_PROBE_ONLY )) { -pr_debug ("PCI:%s Resource %d %016llx-%016llx [%x] is unassigned\n" , -pci_name (dev), i, - (unsigned long long )res->start, - (unsigned long long )res->end, - (unsigned int )res->flags); +if (pci_has_flag (PCI_REASSIGN_ALL_RSRC ) || + (res->start ==0 && !pci_has_flag (PCI_PROBE_ONLY ))) { +/* Only print message if not re-assigning */ +if (!pci_has_flag (PCI_REASSIGN_ALL_RSRC )) +pr_debug ("PCI:%s Resource %d %016llx-%016llx [%x] " +"is unassigned\n" , +pci_name (dev), i, + (unsigned long long )res->start, + (unsigned long long )res->end, + (unsigned int )res->flags); res->end -= res->start; res->start =0 ; res->flags |=IORESOURCE_UNSET ;
@@ -1041,6 +1045,16 @@ static void __devinit pcibios_fixup_bridge(struct pci_bus *bus)if (i >=3 && bus->self->transparent)continue ; +/* If we are going to re-assign everything, mark the resource +* as unset and move it down to 0 +*/ +if (pci_has_flag (PCI_REASSIGN_ALL_RSRC )) { + res->flags |=IORESOURCE_UNSET ; + res->end -= res->start; + res->start =0 ; +continue ; + } + pr_debug("PCI:%s Bus rsrc %d %016llx-%016llx [%x] fixup...\n", pci_name(dev), i, (unsigned long long)res->start,\
@@ -1261,18 +1275,15 @@ void pcibios_allocate_bus_resources(struct pci_bus *bus)pci_bus_for_each_resource (bus, res, i) {if (!res || !res->flags || res->start > res->end || res->parent)continue ; + +/* If the resource was left unset at this point, we clear it */ +if (res->flags &IORESOURCE_UNSET ) + goto clear_resource; +if (bus->parent ==NULL ) pr = (res->flags &IORESOURCE_IO ) ? &ioport_resource : &iomem_resource;else { -/* Don't bother with non-root busses when -* re-assigning all resources. We clear the -* resource flags as if they were colliding -* and as such ensure proper re-allocation -* later. -*/ -if (pci_has_flag (PCI_REASSIGN_ALL_RSRC )) - goto clear_resource; pr =pci_find_parent_resource (bus->self, res);if (pr == res) {/* this happens when the generic PCI
@@ -1303,9 +1314,9 @@ void pcibios_allocate_bus_resources(struct pci_bus *bus)if (reparent_resources (pr, res) ==0 )continue ; } -printk (KERN_WARNING "PCI: Cannot allocate resource region " -"%d of PCI bridge %d, will remap\n" , i, bus->number); -clear_resource: +pr_warning ("PCI: Cannot allocate resource region " +"%d of PCI bridge %d, will remap\n" , i, bus->number); + clear_resource: res->start = res->end =0 ; res->flags =0 ; }
@@ -1450,16 +1461,11 @@ void __init pcibios_resource_survey(void) {struct pci_bus *b; -/* Allocate and assign resources. If we re-assign everything, then -* we skip the allocate phase -*/ +/* Allocate and assign resources */ list_for_each_entry (b, &pci_root_buses, node)pcibios_allocate_bus_resources (b); - -if (!pci_has_flag (PCI_REASSIGN_ALL_RSRC )) { -pcibios_allocate_resources (0 ); -pcibios_allocate_resources (1 ); - } +pcibios_allocate_resources (0 ); +pcibios_allocate_resources (1 );/* Before we start assigning unassigned resource, we try to reserve * the low IO area and the VGA memory area if they intersect the
Signature · 1 line
1.7.7.1
Re: [PATCH 2/5] powerpc/pci: Change how re-assigning resouces work
Quoted 9 lines · Benjamin Herrenschmidt
When
PCI_REASSIGN_ALL_RSRCis set, we used to clear all bus resources at the beginning of survey and re-allocate them later.This changes it so instead, during early fixup, we mark all resources as
IORESOURCE_UNSETand move them down to be 0-based.Later, if bus resources are still unset at the beginning of the survey, then we clear them.
Quoted 7 lines
This shouldn't impact the re-assignment case on 4xx, but will enable us to have the platform do some custom resource assignment before the survey, by clearing individual resources
IORESOURCE_UNSETbit.Also limits the clutter in the kernel log from fixup when re-assigning since we don't care about the offset applied to the BAR values in this case.
Hi guys !
This one could be invasive to FSL and 4xx if you use PCI_REASSIGN_ALL_RSRC. I very much want to merge it for 3.3, so any chance you can give it a beating and see if everything is still allright ?
Cheers,
Ben.
Quoted 117 lines
Signed-off-by Benjamin Herrenschmidt <[email protected]>--- arch/powerpc/kernel/pci-common.c | 66 ++++++++++++++++++++----------------- 1 files changed, 36 insertions(+), 30 deletions(-)arch/powerpc/kernel/pci-common.c +36
-30@@ -920,18 +920,22 @@ static void __devinit pcibios_fixup_resources(struct pci_dev *dev)struct resource *res = dev->resource + i;if (!res->flags)continue ; -/* On platforms that have PCI_PROBE_ONLY set, we don't -* consider 0 as an unassigned BAR value. It's technically -* a valid value, but linux doesn't like it... so when we can -* re-assign things, we do so, but if we can't, we keep it -* around and hope for the best... + +/* If we're going to re-assign everything, we mark all resources +* as unset (and 0-base them). In addition, we mark BARs starting +* at 0 as unset as well, except if PCI_PROBE_ONLY is also set +* since in that case, we don't want to re-assign anything */ -if (res->start ==0 && !pci_has_flag (PCI_PROBE_ONLY )) { -pr_debug ("PCI:%s Resource %d %016llx-%016llx [%x] is unassigned\n" , -pci_name (dev), i, - (unsigned long long )res->start, - (unsigned long long )res->end, - (unsigned int )res->flags); +if (pci_has_flag (PCI_REASSIGN_ALL_RSRC ) || + (res->start ==0 && !pci_has_flag (PCI_PROBE_ONLY ))) { +/* Only print message if not re-assigning */ +if (!pci_has_flag (PCI_REASSIGN_ALL_RSRC )) +pr_debug ("PCI:%s Resource %d %016llx-%016llx [%x] " +"is unassigned\n" , +pci_name (dev), i, + (unsigned long long )res->start, + (unsigned long long )res->end, + (unsigned int )res->flags); res->end -= res->start; res->start =0 ; res->flags |=IORESOURCE_UNSET ;@@ -1041,6 +1045,16 @@ static void __devinit pcibios_fixup_bridge(struct pci_bus *bus)if (i >=3 && bus->self->transparent)continue ; +/* If we are going to re-assign everything, mark the resource +* as unset and move it down to 0 +*/ +if (pci_has_flag (PCI_REASSIGN_ALL_RSRC )) { + res->flags |=IORESOURCE_UNSET ; + res->end -= res->start; + res->start =0 ; +continue ; + } + pr_debug("PCI:%s Bus rsrc %d %016llx-%016llx [%x] fixup...\n", pci_name(dev), i, (unsigned long long)res->start,\@@ -1261,18 +1275,15 @@ void pcibios_allocate_bus_resources(struct pci_bus *bus)pci_bus_for_each_resource (bus, res, i) {if (!res || !res->flags || res->start > res->end || res->parent)continue ; + +/* If the resource was left unset at this point, we clear it */ +if (res->flags &IORESOURCE_UNSET ) + goto clear_resource; +if (bus->parent ==NULL ) pr = (res->flags &IORESOURCE_IO ) ? &ioport_resource : &iomem_resource;else { -/* Don't bother with non-root busses when -* re-assigning all resources. We clear the -* resource flags as if they were colliding -* and as such ensure proper re-allocation -* later. -*/ -if (pci_has_flag (PCI_REASSIGN_ALL_RSRC )) - goto clear_resource; pr =pci_find_parent_resource (bus->self, res);if (pr == res) {/* this happens when the generic PCI @@ -1303,9 +1314,9 @@ void pcibios_allocate_bus_resources(struct pci_bus *bus)if (reparent_resources (pr, res) ==0 )continue ; } -printk (KERN_WARNING "PCI: Cannot allocate resource region " -"%d of PCI bridge %d, will remap\n" , i, bus->number); -clear_resource: +pr_warning ("PCI: Cannot allocate resource region " +"%d of PCI bridge %d, will remap\n" , i, bus->number); + clear_resource: res->start = res->end =0 ; res->flags =0 ; }@@ -1450,16 +1461,11 @@ void __init pcibios_resource_survey(void) {struct pci_bus *b; -/* Allocate and assign resources. If we re-assign everything, then -* we skip the allocate phase -*/ +/* Allocate and assign resources */ list_for_each_entry (b, &pci_root_buses, node)pcibios_allocate_bus_resources (b); - -if (!pci_has_flag (PCI_REASSIGN_ALL_RSRC )) { -pcibios_allocate_resources (0 ); -pcibios_allocate_resources (1 ); - } +pcibios_allocate_resources (0 ); +pcibios_allocate_resources (1 );/* Before we start assigning unassigned resource, we try to reserve * the low IO area and the VGA memory area if they intersect the
PATCH 3/5 powerpc/powernv: Add TCE SW invalidation support
In reply to Benjamin HerrenschmidtThis is used for newer IO Hubs such as p7IOC.
--- arch/powerpc/include/asm/tce.h | 10 +++- arch/powerpc/platforms/powernv/pci.c | 84 +++++++++++++++++++++++++++++----- 2 files changed, 79 insertions(+), 15 deletions(-)
arch/powerpc/include/asm/tce.h +7 -3
@@ -26,10 +26,14 @@/* * Tces come in two formats, one for the virtual bus and a different -* format for PCI +* format for PCI. We also use a separate value for SW invalidated +* PCI */ -#define TCE_VB 0 -#define TCE_PCI 1 +#define TCE_VB 0 +#define TCE_PCI 1 +#define TCE_PCI_SWINV_CREATE 2 +#define TCE_PCI_SWINV_FREE 4 +#define TCE_PCI_SWINV_PAIR 8/* TCE page size is 4096 bytes (1 << 12) */
arch/powerpc/platforms/powernv/pci.c +72 -12
128 lines not on this page · raw message
Signature · 1 line
1.7.7.1
PATCH 4/5 powerpc/powernv: Fixup p7ioc PCIe root complex class code
In reply to Benjamin HerrenschmidtIt advertises "host bridge" instead of "PCI to PCI bridge" which confuses the Linux probe code.
--- arch/powerpc/platforms/powernv/pci.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)
arch/powerpc/platforms/powernv/pci.c +7 -0
@@ -416,6 +416,13 @@ static void __devinit pnv_pci_dma_dev_setup(struct pci_dev *pdev)pnv_pci_dma_fallback_setup (hose, pdev); } +/* Fixup wrong class code in p7ioc root complex */ +static void __devinit pnv_p7ioc_rc_quirk (struct pci_dev *dev) +{ + dev->class =PCI_CLASS_BRIDGE_PCI <<8 ; +} +DECLARE_PCI_FIXUP_EARLY (PCI_VENDOR_ID_IBM ,0x3b9 , pnv_p7ioc_rc_quirk); +static int pnv_pci_probe_mode (struct pci_bus *bus) {struct pci_controller *hose =pci_bus_to_host (bus);
Signature · 1 line
1.7.7.1
PATCH 5/5 powerpc/powernv: PCI support for p7IOC under OPAL v2
In reply to Benjamin HerrenschmidtThis adds support for p7IOC (and possibly other IODA v1 IO Hubs) using OPAL v2 interfaces.
We completely take over resource assignment and assign them using an algorithm that hands out device BARs in a way that makes them fit in individual segments of the M32 window of the bridge, which enables us to assign individual PEs to devices and functions.
The current implementation gives out a PE per functions on PCIe, and a PE for the entire bridge for PCIe to PCI-X bridges.
This can be adjusted / fine tuned later.
We also setup DMA resources (32-bit only for now) and MSIs (both 32-bit and 64-bit MSI are supported).
The DMA allocation tries to divide the available 256M segments of the 32-bit DMA address space "fairly" among PEs. This is done using a "weight" heuristic which assigns less value to things like OHCI USB controllers than, for example SCSI RAID controllers. This algorithm will probably want some fine tuning for specific devices or device types.
--- arch/powerpc/include/asm/pci-bridge.h | 6 +- arch/powerpc/kernel/pci_dn.c | 3 + arch/powerpc/platforms/powernv/Makefile | 2 +- arch/powerpc/platforms/powernv/pci-ioda.c | 1319 +++++++++++++++++++++++++++++ arch/powerpc/platforms/powernv/pci.c | 20 +- arch/powerpc/platforms/powernv/pci.h | 84 ++ 6 files changed, 1428 insertions(+), 6 deletions(-) create mode 100644 arch/powerpc/platforms/powernv/pci-ioda.c
arch/powerpc/include/asm/pci-bridge.h +5 -1
@@ -153,8 +153,8 @@ struct pci_dn {int pci_ext_config_space;/* for pci devices */ -#ifdef CONFIG_EEH struct pci_dev *pcidev;/* back-pointer to the pci device */ +#ifdef CONFIG_EEH int class_code;/* pci device class */ int eeh_mode;/* See eeh.h for possible EEH_MODEs */ int eeh_config_addr;
@@ -164,6 +164,10 @@ struct pci_dn {int eeh_false_positives;/* # times this device reported #ff's */ u32 config_space[16 ];/* saved PCI config space */ #endif +#define IODA_INVALID_PE (-1) +#ifdef CONFIG_PPC_POWERNV +int pe_number; +#endif };/* Get the pointer to a device_node's pci_dn */
arch/powerpc/kernel/pci_dn.c +3 -0
@@ -49,6 +49,9 @@ void * __devinit update_dn_pci_info(struct device_node *dn, void *data) dn->data = pdn; pdn->node = dn; pdn->phb = phb; +#ifdef CONFIG_PPC_POWERNV + pdn->pe_number =IODA_INVALID_PE ; +#endif regs =of_get_property (dn,"reg" ,NULL );if (regs) {/* First register entry is addr (00BBSS00) */
arch/powerpc/platforms/powernv/Makefile +1 -1
@@ -2,4 +2,4 @@ obj-y += setup.o opal-takeover.o opal-wrappers.o opal.o obj-y += opal-rtc.o opal-nvram.o obj-$(CONFIG_SMP) += smp.o -obj-$(CONFIG_PCI) += pci.o pci-p5ioc2.o +obj-$(CONFIG_PCI) += pci.o pci-p5ioc2.o pci-ioda.o
arch/powerpc/platforms/powernv/pci-ioda.c new file +1319 -0
1,319 lines not on this page · raw message
arch/powerpc/platforms/powernv/pci.c +16 -4
@@ -467,12 +467,24 @@ void __init pnv_pci_init(void)init_pci_config_tokens ();find_and_init_phbs ();#endif /* CONFIG_PPC_POWERNV_RTAS */ - }else { -/* OPAL is here, do our normal stuff */ + } +/* OPAL is here, do our normal stuff */ +else { +int found_ioda =0 ; + +/* Look for IODA IO-Hubs. We don't support mixing IODA +* and p5ioc2 due to the need to change some global +* probing flags +*/ +for_each_compatible_node (np,NULL ,"ibm,ioda-hub" ) { +pnv_pci_init_ioda_hub (np); + found_ioda =1 ; + }/* Look for p5ioc2 IO-Hubs */ -for_each_compatible_node (np,NULL ,"ibm,p5ioc2" ) -pnv_pci_init_p5ioc2_hub (np); +if (!found_ioda) +for_each_compatible_node (np,NULL ,"ibm,p5ioc2" ) +pnv_pci_init_p5ioc2_hub (np); }/* Setup the linkage between OF nodes and PHBs */
arch/powerpc/platforms/powernv/pci.h +84 -0
102 lines not on this page · raw message
Signature · 1 line
1.7.7.1