ACPI pci hotplug patch series
A series of 5 patches coming up that make acpiphp work on an rx8620. Unfortunately, they'll cause i386 to not work, so don't apply these for now.
01-pci-bus-address.diff
Adds a way to convert from a global system address to a local pci bus address.
02-ia64-fixups.diff
Fix some bugs. Nothing earth-shattering.
03-acpiphp-domains.diff
Make acpiphp handle domains properly
04-acpiphp-pcidev.diff
Prevent acpiphp from crashing the system in nasty untracable ways
05-acpiphp-misc.diff
Some minor cleanups
Signature · 6 lines
"Next the statesmen will invent cheap lies, putting the blame upon the nation that is attacked, and every man will be glad of those conscience-soothing falsities, and will diligently study them, and refuse to examine any refutations of them; and thus he will by and by convince himself that the war is just, and will thank God for the better sleep he enjoys after this process of grotesque self-deception." -- Mark Twain
PATCH 1/1 pci_bus_address [1/5]
pci_bus_address() allows one to convert a global system address to a local PCI bus address. In Documentation/IO-mapping.txt terms, this is a phys_to_bus() call, except that we pass the PCI bus or PCI device so we know which bus is being referred to.
arch/ia64/pci/pci.c +20 -0
@@ -370,6 +371,27 @@ pcibios_fixup_bus (struct pci_bus *b)return ; } +unsigned long pcibios_bus_address (struct pci_controller *controller, +unsigned long addr,int flags) +{ +int i; +for (i =0 ; i < controller->windows; i++) { +struct pci_window *window = &controller->window[i]; +unsigned long offset = window->offset; +unsigned long bus_addr = addr - offset; + if ((flags & (IORESOURCE_IO | IORESOURCE_MEM)) !+ window->resource.flags) +continue ; +if (bus_addr < window->resource.start) +continue ; +if (window->resource.end < bus_addr) +continue ; +return bus_addr; + } + +return addr; +} +void __devinit pcibios_update_irq (struct pci_dev *dev,int irq) {
include/asm-ia64/pci.h +6 -0
@@ -119,6 +119,12 @@ static inline void pcibios_add_platform_ { } +extern unsigned long pcibios_bus_address (struct pci_controller *, +unsigned long ,int ); + +#define pci_bus_address (busdev, addr, flags) \ + pcibios_bus_address(PCI_CONTROLLER(busdev), (addr), (flags)) +/* generic pci stuff */ #include <asm-generic/pci.h>
include/linux/pci.h +8 -0
@@ -951,6 +951,14 @@ static inline int pci_name_bus(char *nam#endif /* !CONFIG_PCI */ +/* +* Convert from a global physical address to a bus-local address. You can +* override this in asm/pci.h +*/ +#ifndef pci_bus_address +#define pci_bus_address (busdev, addr, flags) (addr) +#endif +/* these helpers provide future and backwards compatibility * for accessing popular PCI BAR info */ #define pci_resource_start (dev,bar) ((dev)->resource[(bar)].start)
Signature · 6 lines
"Next the statesmen will invent cheap lies, putting the blame upon the nation that is attacked, and every man will be glad of those conscience-soothing falsities, and will diligently study them, and refuse to examine any refutations of them; and thus he will by and by convince himself that the war is just, and will thank God for the better sleep he enjoys after this process of grotesque self-deception." -- Mark Twain
PATCH 1/1 ia64 misc fixes [2/5]
In reply to Matthew WilcoxSome miscellaneous fixes:
- flags can be a simple assignment since the resource is newly created
- Zero the allocated memory for the PCI windows
- pcibios_fixup_device_resources is called from pcibios_fixup_bus which is __devinit, so it cannot be __init.
- pci_claim_resource is called from pcibios_fixup_device_resources so must also be __devinit.
arch/ia64/pci/pci.c +3 -2
@@ -272,7 +272,7 @@ add_window (struct acpi_resource *res, vreturn AE_OK ; window = &info->controller->window[info->controller->windows++]; - window->resource.flags |= flags; + window->resource.flags = flags; window->resource.start = addr.min_address_range; window->resource.end = addr.max_address_range; window->offset = offset;
@@ -305,6 +305,7 @@ pci_acpi_scan_root (struct acpi_device * controller->window =kmalloc (sizeof (*controller->window) * windows,GFP_KERNEL );if (!controller->window) goto out2; +memset (controller->window,0 ,sizeof (*controller->window) * windows); name =kmalloc (16 ,GFP_KERNEL );if (!name)
@@ -325,7 +326,7 @@ out1:return NULL ; } -void __init +void __devinit pcibios_fixup_device_resources (struct pci_dev *dev,struct pci_bus *bus) {struct pci_controller *controller =PCI_CONTROLLER (dev);
drivers/pci/setup-res.c +1 -1
@@ -90,7 +90,7 @@ pci_update_resource(struct pci_dev *dev, new & ~PCI_REGION_FLAG_MASK)); } -int __init +int __devinit pci_claim_resource (struct pci_dev *dev,int resource) {struct resource *res = &dev->resource[resource];
Signature · 6 lines
"Next the statesmen will invent cheap lies, putting the blame upon the nation that is attacked, and every man will be glad of those conscience-soothing falsities, and will diligently study them, and refuse to examine any refutations of them; and thus he will by and by convince himself that the war is just, and will thank God for the better sleep he enjoys after this process of grotesque self-deception." -- Mark Twain
PATCH 1/1 acpiphp domain support [3/5]
In reply to Matthew Wilcoxacpiphp doesn't work very well on a machine with multiple PCI domains. This patch improves the situation by using pci_get_slot() instead of pci_find_slot(). The new reference couting rules are documented at the top of acpiphp_glue.c. This necessitated some cleanup of error handling paths and change of calling conventions.
The seg/bus/sub entries are removed from struct acpiphp_bridge and retrieved from the pci_bus when necessary. The per-bridge removal code is moved from acpiphp_glue_exit() to the remove_bridge() method where it should have been all along.
I've added my copyright and bumped the version number.
drivers/pci/hotplug/acpiphp.h +0 -4
@@ -101,10 +101,6 @@ struct acpiphp_bridge {int type;int nr_slots; -u8 seg; -u8 bus; -u8 sub; -u32 flags;/* This bus (host bridge) or Secondary bus (PCI-to-PCI bridge) */
drivers/pci/hotplug/acpiphp_core.c +4 -2
@@ -7,6 +7,8 @@* Copyright (C) 2002 Hiroshi Aono ([email protected]) * Copyright (C) 2002,2003 Takayoshi Kochi ([email protected]) * Copyright (C) 2002,2003 NEC Corporation +* Copyright (C) 2003,2004 Matthew Wilcox ([email protected]) +* Copyright (C) 2003,2004 Hewlett Packard * * All rights reserved. *
@@ -52,8 +54,8 @@ static LIST_HEAD(slot_list);/* local variables */ static int num_slots; -#define DRIVER_VERSION "0.4" -#define DRIVER_AUTHOR "Greg Kroah-Hartman <[email protected]>, Takayoshi Kochi <[email protected]>" +#define DRIVER_VERSION "0.5" +#define DRIVER_AUTHOR "Greg Kroah-Hartman <[email protected]>, Takayoshi Kochi <[email protected]>, Matthew Wilcox <[email protected]>"#define DRIVER_DESC "ACPI Hot Plug PCI Controller Driver"MODULE_AUTHOR (DRIVER_AUTHOR );
drivers/pci/hotplug/acpiphp_glue.c +175 -140
554 lines not on this page · raw message
Signature · 6 lines
"Next the statesmen will invent cheap lies, putting the blame upon the nation that is attacked, and every man will be glad of those conscience-soothing falsities, and will diligently study them, and refuse to examine any refutations of them; and thus he will by and by convince himself that the war is just, and will thank God for the better sleep he enjoys after this process of grotesque self-deception." -- Mark Twain
PATCH 1/1 acpiphp resource usage [4/5]
In reply to Matthew WilcoxReading the config size from a PCI BAR can only be done when the device is quiesced. With the current code, loading the acpiphp driver at runtime can cause all kinds of interesting errors.
This patch makes acpiphp use the resources embedded in the pci_dev instead where possible. It uses the new pci_bus_address() function introduced in patch 01 of this series. By using the pci_dev resources instead of reading the BARs directly, this also cures some of the problems found with plugin cards that contain PCI-to-PCI bridges.
drivers/pci/hotplug/acpiphp_pci.c +70 -171
@@ -45,44 +45,29 @@/* allocate mem/pmem/io resource to a new function */ static int init_config_space (struct acpiphp_func *func) { -u32 bar, len; -u32 address[] = { -PCI_BASE_ADDRESS_0 , -PCI_BASE_ADDRESS_1 , -PCI_BASE_ADDRESS_2 , -PCI_BASE_ADDRESS_3 , -PCI_BASE_ADDRESS_4 , -PCI_BASE_ADDRESS_5 , -0 - };int count; -struct acpiphp_bridge *bridge; -struct pci_resource *res; -struct pci_bus *pbus; -int bus, device, function; -unsigned int devfn;u16 tmp; - bridge = func->slot->bridge; - pbus = bridge->pci_bus; - bus = bridge->bus; - device = func->slot->device; - function = func->function; - devfn =PCI_DEVFN (device, function); - -for (count =0 ; address[count]; count++) {/* for 6 BARs */ -pci_bus_write_config_dword (pbus, devfn, - address[count],0xFFFFFFFF ); -pci_bus_read_config_dword (pbus, devfn, address[count], &bar); +struct acpiphp_bridge *bridge = func->slot->bridge; +struct pci_bus *pbus = bridge->pci_bus; +int bus = pbus->number; +int device = func->slot->device; +int function = func->function; +int devfn =PCI_DEVFN (device, function); + +for (count =0 ; count <6 ; count++) { +struct pci_resource *res; +u32 bar, len; +unsigned int address =PCI_BASE_ADDRESS_0 + (count <<2 ); +pci_bus_write_config_dword (pbus, devfn, address,0xFFFFFFFF ); +pci_bus_read_config_dword (pbus, devfn, address, &bar); -if (!bar)/* This BAR is not implemented */ +if (!bar || bar =0xffffffff )continue ;dbg ("Device %02x.%02x BAR %d wants %x\n" , device, function, count, bar); -if (bar &PCI_BASE_ADDRESS_SPACE_IO ) { -/* This is IO */ - +if ((bar &PCI_BASE_ADDRESS_SPACE ) =PCI_BASE_ADDRESS_SPACE_IO ) { len = bar & (PCI_BASE_ADDRESS_IO_MASK &0xFFFF ); len = len & ~(len -1 );
@@ -97,82 +82,52 @@ static int init_config_space (struct acp bus, device, function, len);return -1 ; } -pci_bus_write_config_dword (pbus, devfn, - address[count], +pci_bus_write_config_dword (pbus, devfn, address, (u32 )res->base); res->next = func->io_head; func->io_head = res; - }else { -/* This is Memory */ -if (bar &PCI_BASE_ADDRESS_MEM_PREFETCH ) { -/* pfmem */ - - len = bar &0xFFFFFFF0 ; - len = ~len +1 ; - -dbg ("len in PFMEM %x, BAR %d\n" , len, count); - -spin_lock (&bridge->res_lock); - res =acpiphp_get_resource (&bridge->p_mem_head, len); -spin_unlock (&bridge->res_lock); - -if (!res) { -err ("cannot allocate requested pfmem for %02x:%02x.%d len %x\n" , - bus, device, function, len); -return -1 ; - } - -pci_bus_write_config_dword (pbus, devfn, - address[count], - (u32 )res->base); - -if (bar &PCI_BASE_ADDRESS_MEM_TYPE_64 ) {/* takes up another dword */ -dbg ("inside the pfmem 64 case, count %d\n" , count); - count +=1 ; -pci_bus_write_config_dword (pbus, devfn, - address[count], - (u32)(res->base >>32 )); - } +struct pci_resource **bridge_mem_head; +struct pci_resource **func_mem_head; - res->next = func->p_mem_head; - func->p_mem_head = res; + len = bar &PCI_BASE_ADDRESS_MEM_MASK ; + len = ~len +1 ; +dbg ("len in MEM %x, BAR %d\n" , len, count); +if (bar &PCI_BASE_ADDRESS_MEM_PREFETCH ) { + bridge_mem_head = &bridge->p_mem_head; + func_mem_head = &func->p_mem_head; }else { -/* regular memory */ + bridge_mem_head = &bridge->mem_head; + func_mem_head = &func->mem_head; + } - len = bar &0xFFFFFFF0 ; - len = ~len +1 ; +spin_lock (&bridge->res_lock); + res =acpiphp_get_resource (bridge_mem_head, len); +spin_unlock (&bridge->res_lock); -dbg ("len in MEM %x, BAR %d\n" , len, count); +if (!res) { +err ("cannot allocate requested mem for " +"%02x:%02x.%d len %x\n" , + bus, device, function, len); +return -1 ; + } +dbg ("received address 0x%lx\n" , res->base); -spin_lock (&bridge->res_lock); - res =acpiphp_get_resource (&bridge->mem_head, len); -spin_unlock (&bridge->res_lock); - -if (!res) { -err ("cannot allocate requested pfmem for %02x:%02x.%d len %x\n" , - bus, device, function, len); -return -1 ; - } +pci_bus_write_config_dword (pbus, devfn, address, + (u32 )res->base); +if (bar &PCI_BASE_ADDRESS_MEM_TYPE_64 ) { +/* takes up another dword */ +dbg ("inside the mem 64 case, count %d\n" , count); + count++;pci_bus_write_config_dword (pbus, devfn, - address[count], - (u32 )res->base); - -if (bar &PCI_BASE_ADDRESS_MEM_TYPE_64 ) { -/* takes up another dword */ -dbg ("inside mem 64 case, reg. mem, count %d\n" , count); - count +=1 ; -pci_bus_write_config_dword (pbus, devfn, - address[count], - (u32)(res->base >>32 )); - } - - res->next = func->mem_head; - func->mem_head = res; - + address +4 , + (u32)(res->base >>32 )); } + + res->next = *func_mem_head; + *func_mem_head = res; } }
@@ -214,6 +169,7 @@ static int detect_used_resource (structdbg ("BAR[%d] 0x%lx - 0x%lx (0x%lx)\n" , count, base, base + len -1 , flags); + base =pci_bus_address (dev, base, flags);if (flags &IORESOURCE_IO ) { head = &bridge->io_head;
@@ -255,100 +211,43 @@ int acpiphp_detect_pci_resource (struct/** -* acpiphp_init_slot_resource - gather resource usage information of a slot +* acpiphp_init_func_resource - gather resource usage information of a slot * @slot: ACPI slot object to be checked, should have valid pci_dev member -* -* TBD: PCI-to-PCI bridge case -* use pci_dev->resource[] */ int acpiphp_init_func_resource (struct acpiphp_func *func) { -u64 base; -u32 bar, len; -u32 address[] = { -PCI_BASE_ADDRESS_0 , -PCI_BASE_ADDRESS_1 , -PCI_BASE_ADDRESS_2 , -PCI_BASE_ADDRESS_3 , -PCI_BASE_ADDRESS_4 , -PCI_BASE_ADDRESS_5 , -0 - };int count; -struct pci_resource *res; -struct pci_dev *dev; - - dev = func->pci_dev; +struct pci_dev *dev = func->pci_dev;dbg ("Hot-pluggable device %s\n" ,pci_name (dev)); -for (count =0 ; address[count]; count++) {/* for 6 BARs */ -pci_read_config_dword (dev, address[count], &bar); - -if (!bar)/* This BAR is not implemented */ -continue ; +for (count =0 ; count <DEVICE_COUNT_RESOURCE ; count++) { +struct pci_resource *res; -pci_write_config_dword (dev, address[count],0xFFFFFFFF ); -pci_read_config_dword (dev, address[count], &len); +unsigned long base = dev->resource[count].start; +unsigned long len = dev->resource[count].end - base +1 ; +unsigned long flags = dev->resource[count].flags; -if (len &PCI_BASE_ADDRESS_SPACE_IO ) { -/* This is IO */ - base = bar &0xFFFFFFFC ; - len = len & (PCI_BASE_ADDRESS_IO_MASK &0xFFFF ); - len = len & ~(len -1 ); +if (!flags) +continue ; -dbg ("BAR[%d] %08x - %08x (IO)\n" , count, (u32 )base, (u32 )base + len -1 ); +dbg ("BAR[%d] 0x%lx - 0x%lx (0x%lx)\n" , count, base, + base + len -1 , flags); + base =pci_bus_address (dev, base, flags); - res =acpiphp_make_resource (base, len); -if (!res) - goto no_memory; + res =acpiphp_make_resource (base, len); +if (!res) + goto no_memory; +if (flags &IORESOURCE_IO ) { res->next = func->io_head; func->io_head = res; - + }else if (flags &IORESOURCE_PREFETCH ) { + res->next = func->p_mem_head; + func->p_mem_head = res; }else { -/* This is Memory */ - base = bar &0xFFFFFFF0 ; -if (len &PCI_BASE_ADDRESS_MEM_PREFETCH ) { -/* pfmem */ - - len &=0xFFFFFFF0 ; - len = ~len +1 ; - -if (len &PCI_BASE_ADDRESS_MEM_TYPE_64 ) {/* takes up another dword */ -dbg ("prefetch mem 64\n" ); - count +=1 ; - } -dbg ("BAR[%d] %08x - %08x (PMEM)\n" , count, (u32 )base, (u32 )base + len -1 ); - res =acpiphp_make_resource (base, len); -if (!res) - goto no_memory; - - res->next = func->p_mem_head; - func->p_mem_head = res; - - }else { -/* regular memory */ - - len &=0xFFFFFFF0 ; - len = ~len +1 ; - -if (len &PCI_BASE_ADDRESS_MEM_TYPE_64 ) { -/* takes up another dword */ -dbg ("mem 64\n" ); - count +=1 ; - } -dbg ("BAR[%d] %08x - %08x (MEM)\n" , count, (u32 )base, (u32 )base + len -1 ); - res =acpiphp_make_resource (base, len); -if (!res) - goto no_memory; - - res->next = func->mem_head; - func->mem_head = res; - - } + res->next = func->mem_head; + func->mem_head = res; } - -pci_write_config_dword (dev, address[count], bar); }#if 1 acpiphp_dump_func_resource (func);
Signature · 6 lines
"Next the statesmen will invent cheap lies, putting the blame upon the nation that is attacked, and every man will be glad of those conscience-soothing falsities, and will diligently study them, and refuse to examine any refutations of them; and thus he will by and by convince himself that the war is just, and will thank God for the better sleep he enjoys after this process of grotesque self-deception." -- Mark Twain
PATCH 1/1 acpiphp misc fixes [5/5]
In reply to Matthew WilcoxTwo minor fixes:
- Correct the docbook (parameter renamed to value)
- If a resource is 64-bit, the debug code was previously truncating its value.
drivers/pci/hotplug/acpiphp_core.c +1 -2
@@ -210,8 +212,7 @@ static int get_adapter_status(struct hot/** * get_address - get pci address of a slot * @hotplug_slot: slot to get status -* @busdev: pointer to struct pci_busdev (seg, bus, dev) -* +* @value: pointer to struct pci_busdev (seg, bus, dev) */ static int get_address (struct hotplug_slot *hotplug_slot,u32 *value) {
drivers/pci/hotplug/acpiphp_res.c +2 -2
@@ -669,8 +669,8 @@ static void dump_resource(struct pci_res cnt =0 ;while (p) { -dbg ("[%02d] %08x - %08x\n" , - cnt++, (u32 )p->base, (u32 )p->base + p->length -1 ); +dbg ("[%02d] 0x%llx - 0x%llx\n" , cnt++, (long long )p->base, + (long long )(p->base + p->length -1 )); p = p->next; } }
Signature · 6 lines
"Next the statesmen will invent cheap lies, putting the blame upon the nation that is attacked, and every man will be glad of those conscience-soothing falsities, and will diligently study them, and refuse to examine any refutations of them; and thus he will by and by convince himself that the war is just, and will thank God for the better sleep he enjoys after this process of grotesque self-deception." -- Mark Twain
PATCH 1/1 build acpiphp modular and on i386/x86_64 [6/5]
In reply to Matthew WilcoxAfter the first five patches I sent, in order to build acpiphp on i386/x86_64 or as a module on ia64, we need these exports and defines currently. I have a much better scheme in mind but it's not ready yet. I promise I'll replace this with something much more portable.
arch/ia64/pci/pci.c +1 -0
@@ -354,6 +354,7 @@ pcibios_fixup_device_resources (struct ppci_claim_resource (dev, i); } } +EXPORT_SYMBOL (pcibios_fixup_device_resources);/* * Called after each bus is probed, but before its children are examined.
include/asm-i386/pci.h +3 -0
@@ -99,6 +99,9 @@ static inline void pcibios_add_platform_ { } +/* XXX: temporary hack for acpiphp */ +#define pcibios_fixup_device_resources () do { } while (0) +#endif /* __KERNEL__ */ /* implement the pci_ DMA API in terms of the generic device dma_ one */
include/asm-ia64/pci.h +3 -0
@@ -125,6 +125,9 @@ extern unsigned long pcibios_bus_address#define pci_bus_address (busdev, addr, flags) \ pcibios_bus_address(PCI_CONTROLLER(busdev), (addr), (flags)) +/* XXX: temporary hack for acpiphp */ +extern void pcibios_fixup_device_resources (struct pci_dev *,struct pci_bus *); +/* generic pci stuff */ #include <asm-generic/pci.h>
include/asm-x86_64/pci.h +3 -0
@@ -132,6 +132,9 @@ static inline void pcibios_add_platform_ { } +/* XXX: temporary hack for acpiphp */ +#define pcibios_fixup_device_resources () do { } while (0) +#endif /* __KERNEL__ */ /* generic pci stuff */
Signature · 6 lines
"Next the statesmen will invent cheap lies, putting the blame upon the nation that is attacked, and every man will be glad of those conscience-soothing falsities, and will diligently study them, and refuse to examine any refutations of them; and thus he will by and by convince himself that the war is just, and will thank God for the better sleep he enjoys after this process of grotesque self-deception." -- Mark Twain