Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'linux-next' of git://git.kernel.org/pub/scm/linux/kernel/git/jbarnes/pci-2.6

* 'linux-next' of git://git.kernel.org/pub/scm/linux/kernel/git/jbarnes/pci-2.6: (72 commits)
Revert "x86/PCI: ACPI based PCI gap calculation"
PCI: remove unnecessary volatile in PCIe hotplug struct controller
x86/PCI: ACPI based PCI gap calculation
PCI: include linux/pm_wakeup.h for device_set_wakeup_capable
PCI PM: Fix pci_prepare_to_sleep
x86/PCI: Fix PCI config space for domains > 0
Fix acpi_pm_device_sleep_wake() by providing a stub for CONFIG_PM_SLEEP=n
PCI: Simplify PCI device PM code
PCI PM: Introduce pci_prepare_to_sleep and pci_back_from_sleep
PCI ACPI: Rework PCI handling of wake-up
ACPI: Introduce new device wakeup flag 'prepared'
ACPI: Introduce acpi_device_sleep_wake function
PCI: rework pci_set_power_state function to call platform first
PCI: Introduce platform_pci_power_manageable function
ACPI: Introduce acpi_bus_power_manageable function
PCI: make pci_name use dev_name
PCI: handle pci_name() being const
PCI: add stub for pci_set_consistent_dma_mask()
PCI: remove unused arch pcibios_update_resource() functions
PCI: fix pci_setup_device()'s sprinting into a const buffer
...

Fixed up conflicts in various files (arch/x86/kernel/setup_64.c,
arch/x86/pci/irq.c, arch/x86/pci/pci.h, drivers/acpi/sleep/main.c,
drivers/pci/pci.c, drivers/pci/pci.h, include/acpi/acpi_bus.h) from x86
and ACPI updates manually.

+4005 -1758
+8 -1
Documentation/kernel-parameters.txt
··· 147 147 default: 0 148 148 149 149 acpi_sleep= [HW,ACPI] Sleep options 150 - Format: { s3_bios, s3_mode, s3_beep } 150 + Format: { s3_bios, s3_mode, s3_beep, old_ordering } 151 151 See Documentation/power/video.txt for s3_bios and s3_mode. 152 152 s3_beep is for debugging; it makes the PC's speaker beep 153 153 as soon as the kernel's real-mode entry point is called. 154 + old_ordering causes the ACPI 1.0 ordering of the _PTS 155 + control method, wrt putting devices into low power 156 + states, to be enforced (the ACPI 2.0 ordering of _PTS is 157 + used by default). 154 158 155 159 acpi_sci= [HW,ACPI] ACPI System Control Interrupt trigger mode 156 160 Format: { level | edge | high | low } ··· 1541 1537 Use with caution as certain devices share 1542 1538 address decoders between ROMs and other 1543 1539 resources. 1540 + norom [X86-32,X86_64] Do not assign address space to 1541 + expansion ROMs that do not already have 1542 + BIOS assigned address ranges. 1544 1543 irqmask=0xMMMM [X86-32] Set a bit mask of IRQs allowed to be 1545 1544 assigned automatically to PCI devices. You can 1546 1545 make the kernel exclude IRQs of your ISA cards
+6 -6
MAINTAINERS
··· 248 248 ACPI PCI HOTPLUG DRIVER 249 249 P: Kristen Carlson Accardi 250 250 M: kristen.c.accardi@intel.com 251 - L: pcihpd-discuss@lists.sourceforge.net 251 + L: linux-pci@vger.kernel.org 252 252 S: Supported 253 253 254 254 ACPI THERMAL DRIVER ··· 1145 1145 P: Scott Murray 1146 1146 M: scottm@somanetworks.com 1147 1147 M: scott@spiteful.org 1148 - L: pcihpd-discuss@lists.sourceforge.net 1148 + L: linux-pci@vger.kernel.org 1149 1149 S: Supported 1150 1150 1151 1151 COMPACTPCI HOTPLUG ZIATECH ZT5550 DRIVER 1152 1152 P: Scott Murray 1153 1153 M: scottm@somanetworks.com 1154 1154 M: scott@spiteful.org 1155 - L: pcihpd-discuss@lists.sourceforge.net 1155 + L: linux-pci@vger.kernel.org 1156 1156 S: Supported 1157 1157 1158 1158 COMPACTPCI HOTPLUG GENERIC DRIVER 1159 1159 P: Scott Murray 1160 1160 M: scottm@somanetworks.com 1161 1161 M: scott@spiteful.org 1162 - L: pcihpd-discuss@lists.sourceforge.net 1162 + L: linux-pci@vger.kernel.org 1163 1163 S: Supported 1164 1164 1165 1165 COMPAL LAPTOP SUPPORT ··· 3219 3219 PCIE HOTPLUG DRIVER 3220 3220 P: Kristen Carlson Accardi 3221 3221 M: kristen.c.accardi@intel.com 3222 - L: pcihpd-discuss@lists.sourceforge.net 3222 + L: linux-pci@vger.kernel.org 3223 3223 S: Supported 3224 3224 3225 3225 PCMCIA SUBSYSTEM ··· 3865 3865 SHPC HOTPLUG DRIVER 3866 3866 P: Kristen Carlson Accardi 3867 3867 M: kristen.c.accardi@intel.com 3868 - L: pcihpd-discuss@lists.sourceforge.net 3868 + L: linux-pci@vger.kernel.org 3869 3869 S: Supported 3870 3870 3871 3871 SECURE DIGITAL HOST CONTROLLER INTERFACE DRIVER
-30
arch/frv/mb93090-mb00/pci-frv.c
··· 19 19 20 20 #include "pci-frv.h" 21 21 22 - #if 0 23 - void 24 - pcibios_update_resource(struct pci_dev *dev, struct resource *root, 25 - struct resource *res, int resource) 26 - { 27 - u32 new, check; 28 - int reg; 29 - 30 - new = res->start | (res->flags & PCI_REGION_FLAG_MASK); 31 - if (resource < 6) { 32 - reg = PCI_BASE_ADDRESS_0 + 4*resource; 33 - } else if (resource == PCI_ROM_RESOURCE) { 34 - res->flags |= IORESOURCE_ROM_ENABLE; 35 - new |= PCI_ROM_ADDRESS_ENABLE; 36 - reg = dev->rom_base_reg; 37 - } else { 38 - /* Somebody might have asked allocation of a non-standard resource */ 39 - return; 40 - } 41 - 42 - pci_write_config_dword(dev, reg, new); 43 - pci_read_config_dword(dev, reg, &check); 44 - if ((new ^ check) & ((new & PCI_BASE_ADDRESS_SPACE_IO) ? PCI_BASE_ADDRESS_IO_MASK : PCI_BASE_ADDRESS_MEM_MASK)) { 45 - printk(KERN_ERR "PCI: Error while updating region " 46 - "%s/%d (%08x != %08x)\n", pci_name(dev), resource, 47 - new, check); 48 - } 49 - } 50 - #endif 51 - 52 22 /* 53 23 * We need to avoid collisions with `mirrored' VGA ports 54 24 * and other strange ISA hardware, so we always want the
-9
arch/m68knommu/kernel/comempci.c
··· 375 375 376 376 /*****************************************************************************/ 377 377 378 - void pcibios_update_resource(struct pci_dev *dev, struct resource *root, struct resource *r, int resource) 379 - { 380 - printk(KERN_WARNING "%s(%d): no support for changing PCI resources...\n", 381 - __FILE__, __LINE__); 382 - } 383 - 384 - 385 - /*****************************************************************************/ 386 - 387 378 /* 388 379 * Local routines to interrcept the standard I/O and vector handling 389 380 * code. Don't include this 'till now - initialization code above needs
-36
arch/mips/pmc-sierra/yosemite/ht.c
··· 345 345 return pcibios_enable_resources(dev); 346 346 } 347 347 348 - 349 - 350 - void pcibios_update_resource(struct pci_dev *dev, struct resource *root, 351 - struct resource *res, int resource) 352 - { 353 - u32 new, check; 354 - int reg; 355 - 356 - return; 357 - 358 - new = res->start | (res->flags & PCI_REGION_FLAG_MASK); 359 - if (resource < 6) { 360 - reg = PCI_BASE_ADDRESS_0 + 4 * resource; 361 - } else if (resource == PCI_ROM_RESOURCE) { 362 - res->flags |= IORESOURCE_ROM_ENABLE; 363 - reg = dev->rom_base_reg; 364 - } else { 365 - /* 366 - * Somebody might have asked allocation of a non-standard 367 - * resource 368 - */ 369 - return; 370 - } 371 - 372 - pci_write_config_dword(dev, reg, new); 373 - pci_read_config_dword(dev, reg, &check); 374 - if ((new ^ check) & 375 - ((new & PCI_BASE_ADDRESS_SPACE_IO) ? PCI_BASE_ADDRESS_IO_MASK : 376 - PCI_BASE_ADDRESS_MEM_MASK)) { 377 - printk(KERN_ERR "PCI: Error while updating region " 378 - "%s/%d (%08x != %08x)\n", pci_name(dev), resource, 379 - new, check); 380 - } 381 - } 382 - 383 - 384 348 void pcibios_align_resource(void *data, struct resource *res, 385 349 resource_size_t size, resource_size_t align) 386 350 {
-32
arch/sh/drivers/pci/pci.c
··· 76 76 pci_read_bridge_bases(bus); 77 77 } 78 78 79 - void 80 - pcibios_update_resource(struct pci_dev *dev, struct resource *root, 81 - struct resource *res, int resource) 82 - { 83 - u32 new, check; 84 - int reg; 85 - 86 - new = res->start | (res->flags & PCI_REGION_FLAG_MASK); 87 - if (resource < 6) { 88 - reg = PCI_BASE_ADDRESS_0 + 4*resource; 89 - } else if (resource == PCI_ROM_RESOURCE) { 90 - res->flags |= IORESOURCE_ROM_ENABLE; 91 - new |= PCI_ROM_ADDRESS_ENABLE; 92 - reg = dev->rom_base_reg; 93 - } else { 94 - /* 95 - * Somebody might have asked allocation of a non-standard 96 - * resource 97 - */ 98 - return; 99 - } 100 - 101 - pci_write_config_dword(dev, reg, new); 102 - pci_read_config_dword(dev, reg, &check); 103 - if ((new ^ check) & ((new & PCI_BASE_ADDRESS_SPACE_IO) ? 104 - PCI_BASE_ADDRESS_IO_MASK : PCI_BASE_ADDRESS_MEM_MASK)) { 105 - printk(KERN_ERR "PCI: Error while updating region " 106 - "%s/%d (%08x != %08x)\n", pci_name(dev), resource, 107 - new, check); 108 - } 109 - } 110 - 111 79 void pcibios_align_resource(void *data, struct resource *res, 112 80 resource_size_t size, resource_size_t align) 113 81 __attribute__ ((weak));
+1 -1
arch/sparc64/kernel/pci.c
··· 408 408 dev->class = class >> 8; 409 409 dev->revision = class & 0xff; 410 410 411 - sprintf(pci_name(dev), "%04x:%02x:%02x.%d", pci_domain_nr(bus), 411 + sprintf(dev->dev.bus_id, "%04x:%02x:%02x.%d", pci_domain_nr(bus), 412 412 dev->bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn)); 413 413 414 414 if (ofpci_verbose)
+2
arch/x86/kernel/acpi/sleep.c
··· 158 158 acpi_realmode_flags |= 2; 159 159 if (strncmp(str, "s3_beep", 7) == 0) 160 160 acpi_realmode_flags |= 4; 161 + if (strncmp(str, "old_ordering", 12) == 0) 162 + acpi_old_suspend_ordering(); 161 163 str = strchr(str, ','); 162 164 if (str != NULL) 163 165 str += strspn(str, ", \t");
+4 -4
arch/x86/kernel/apm_32.c
··· 1213 1213 if (err != APM_SUCCESS) 1214 1214 apm_error("suspend", err); 1215 1215 err = (err == APM_SUCCESS) ? 0 : -EIO; 1216 - device_power_up(); 1216 + device_power_up(PMSG_RESUME); 1217 1217 local_irq_enable(); 1218 - device_resume(); 1218 + device_resume(PMSG_RESUME); 1219 1219 queue_event(APM_NORMAL_RESUME, NULL); 1220 1220 spin_lock(&user_list_lock); 1221 1221 for (as = user_list; as != NULL; as = as->next) { ··· 1240 1240 apm_error("standby", err); 1241 1241 1242 1242 local_irq_disable(); 1243 - device_power_up(); 1243 + device_power_up(PMSG_RESUME); 1244 1244 local_irq_enable(); 1245 1245 } 1246 1246 ··· 1326 1326 ignore_bounce = 1; 1327 1327 if ((event != APM_NORMAL_RESUME) 1328 1328 || (ignore_normal_resume == 0)) { 1329 - device_resume(); 1329 + device_resume(PMSG_RESUME); 1330 1330 queue_event(event, NULL); 1331 1331 } 1332 1332 ignore_normal_resume = 0;
+21 -5
arch/x86/kernel/early-quirks.c
··· 120 120 {} 121 121 }; 122 122 123 - static void __init check_dev_quirk(int num, int slot, int func) 123 + /** 124 + * check_dev_quirk - apply early quirks to a given PCI device 125 + * @num: bus number 126 + * @slot: slot number 127 + * @func: PCI function 128 + * 129 + * Check the vendor & device ID against the early quirks table. 130 + * 131 + * If the device is single function, let early_quirks() know so we don't 132 + * poke at this device again. 133 + */ 134 + static int __init check_dev_quirk(int num, int slot, int func) 124 135 { 125 136 u16 class; 126 137 u16 vendor; ··· 142 131 class = read_pci_config_16(num, slot, func, PCI_CLASS_DEVICE); 143 132 144 133 if (class == 0xffff) 145 - return; 134 + return -1; /* no class, treat as single function */ 146 135 147 136 vendor = read_pci_config_16(num, slot, func, PCI_VENDOR_ID); 148 137 ··· 165 154 type = read_pci_config_byte(num, slot, func, 166 155 PCI_HEADER_TYPE); 167 156 if (!(type & 0x80)) 168 - return; 157 + return -1; 158 + 159 + return 0; 169 160 } 170 161 171 162 void __init early_quirks(void) ··· 180 167 /* Poor man's PCI discovery */ 181 168 for (num = 0; num < 32; num++) 182 169 for (slot = 0; slot < 32; slot++) 183 - for (func = 0; func < 8; func++) 184 - check_dev_quirk(num, slot, func); 170 + for (func = 0; func < 8; func++) { 171 + /* Only probe function 0 on single fn devices */ 172 + if (check_dev_quirk(num, slot, func)) 173 + break; 174 + } 185 175 }
+5
arch/x86/kernel/setup.c
··· 684 684 clear_cpu_cap(&boot_cpu_data, X86_FEATURE_APIC); 685 685 } 686 686 687 + #ifdef CONFIG_PCI 688 + if (pci_early_dump_regs) 689 + early_dump_pci_devices(); 690 + #endif 691 + 687 692 finish_e820_parsing(); 688 693 689 694 #ifdef CONFIG_X86_32
+28 -2
arch/x86/pci/common.c
··· 20 20 unsigned int pci_probe = PCI_PROBE_BIOS | PCI_PROBE_CONF1 | PCI_PROBE_CONF2 | 21 21 PCI_PROBE_MMCONF; 22 22 23 + unsigned int pci_early_dump_regs; 23 24 static int pci_bf_sort; 24 25 int pci_routeirq; 25 26 int pcibios_last_bus = -1; ··· 32 31 int raw_pci_read(unsigned int domain, unsigned int bus, unsigned int devfn, 33 32 int reg, int len, u32 *val) 34 33 { 35 - if (reg < 256 && raw_pci_ops) 34 + if (domain == 0 && reg < 256 && raw_pci_ops) 36 35 return raw_pci_ops->read(domain, bus, devfn, reg, len, val); 37 36 if (raw_pci_ext_ops) 38 37 return raw_pci_ext_ops->read(domain, bus, devfn, reg, len, val); ··· 42 41 int raw_pci_write(unsigned int domain, unsigned int bus, unsigned int devfn, 43 42 int reg, int len, u32 val) 44 43 { 45 - if (reg < 256 && raw_pci_ops) 44 + if (domain == 0 && reg < 256 && raw_pci_ops) 46 45 return raw_pci_ops->write(domain, bus, devfn, reg, len, val); 47 46 if (raw_pci_ext_ops) 48 47 return raw_pci_ext_ops->write(domain, bus, devfn, reg, len, val); ··· 122 121 dmi_check_system(can_skip_pciprobe_dmi_table); 123 122 } 124 123 124 + static void __devinit pcibios_fixup_device_resources(struct pci_dev *dev) 125 + { 126 + struct resource *rom_r = &dev->resource[PCI_ROM_RESOURCE]; 127 + 128 + if (pci_probe & PCI_NOASSIGN_ROMS) { 129 + if (rom_r->parent) 130 + return; 131 + if (rom_r->start) { 132 + /* we deal with BIOS assigned ROM later */ 133 + return; 134 + } 135 + rom_r->start = rom_r->end = rom_r->flags = 0; 136 + } 137 + } 138 + 125 139 /* 126 140 * Called after each bus is probed, but before its children 127 141 * are examined. ··· 144 128 145 129 void __devinit pcibios_fixup_bus(struct pci_bus *b) 146 130 { 131 + struct pci_dev *dev; 132 + 147 133 pci_read_bridge_bases(b); 134 + list_for_each_entry(dev, &b->devices, bus_list) 135 + pcibios_fixup_device_resources(dev); 148 136 } 149 137 150 138 /* ··· 501 481 else if (!strcmp(str, "rom")) { 502 482 pci_probe |= PCI_ASSIGN_ROMS; 503 483 return NULL; 484 + } else if (!strcmp(str, "norom")) { 485 + pci_probe |= PCI_NOASSIGN_ROMS; 486 + return NULL; 504 487 } else if (!strcmp(str, "assign-busses")) { 505 488 pci_probe |= PCI_ASSIGN_ALL_BUSSES; 506 489 return NULL; 507 490 } else if (!strcmp(str, "use_crs")) { 508 491 pci_probe |= PCI_USE__CRS; 492 + return NULL; 493 + } else if (!strcmp(str, "earlydump")) { 494 + pci_early_dump_regs = 1; 509 495 return NULL; 510 496 } else if (!strcmp(str, "routeirq")) { 511 497 pci_routeirq = 1;
+59 -1
arch/x86/pci/early.c
··· 49 49 { 50 50 PDprintk("%x writing to %x: %x\n", slot, offset, val); 51 51 outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8); 52 - outb(val, 0xcfc); 52 + outb(val, 0xcfc + (offset&3)); 53 + } 54 + 55 + void write_pci_config_16(u8 bus, u8 slot, u8 func, u8 offset, u16 val) 56 + { 57 + PDprintk("%x writing to %x: %x\n", slot, offset, val); 58 + outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8); 59 + outw(val, 0xcfc + (offset&2)); 53 60 } 54 61 55 62 int early_pci_allowed(void) ··· 64 57 return (pci_probe & (PCI_PROBE_CONF1|PCI_PROBE_NOEARLY)) == 65 58 PCI_PROBE_CONF1; 66 59 } 60 + 61 + void early_dump_pci_device(u8 bus, u8 slot, u8 func) 62 + { 63 + int i; 64 + int j; 65 + u32 val; 66 + 67 + printk("PCI: %02x:%02x:%02x", bus, slot, func); 68 + 69 + for (i = 0; i < 256; i += 4) { 70 + if (!(i & 0x0f)) 71 + printk("\n%04x:",i); 72 + 73 + val = read_pci_config(bus, slot, func, i); 74 + for (j = 0; j < 4; j++) { 75 + printk(" %02x", val & 0xff); 76 + val >>= 8; 77 + } 78 + } 79 + printk("\n"); 80 + } 81 + 82 + void early_dump_pci_devices(void) 83 + { 84 + unsigned bus, slot, func; 85 + 86 + if (!early_pci_allowed()) 87 + return; 88 + 89 + for (bus = 0; bus < 256; bus++) { 90 + for (slot = 0; slot < 32; slot++) { 91 + for (func = 0; func < 8; func++) { 92 + u32 class; 93 + u8 type; 94 + class = read_pci_config(bus, slot, func, 95 + PCI_CLASS_REVISION); 96 + if (class == 0xffffffff) 97 + break; 98 + 99 + early_dump_pci_device(bus, slot, func); 100 + 101 + /* No multi-function device? */ 102 + type = read_pci_config_byte(bus, slot, func, 103 + PCI_HEADER_TYPE); 104 + if (!(type & 0x80)) 105 + break; 106 + } 107 + } 108 + } 109 + } 110 +
+82 -38
arch/x86/pci/irq.c
··· 45 45 char *name; 46 46 u16 vendor, device; 47 47 int (*get)(struct pci_dev *router, struct pci_dev *dev, int pirq); 48 - int (*set)(struct pci_dev *router, struct pci_dev *dev, int pirq, int new); 48 + int (*set)(struct pci_dev *router, struct pci_dev *dev, int pirq, 49 + int new); 49 50 }; 50 51 51 52 struct irq_router_handler { ··· 78 77 for (i = 0; i < rt->size; i++) 79 78 sum += addr[i]; 80 79 if (!sum) { 81 - DBG(KERN_DEBUG "PCI: Interrupt Routing Table found at 0x%p\n", rt); 80 + DBG(KERN_DEBUG "PCI: Interrupt Routing Table found at 0x%p\n", 81 + rt); 82 82 return rt; 83 83 } 84 84 return NULL; ··· 185 183 return (nr & 1) ? (x >> 4) : (x & 0xf); 186 184 } 187 185 188 - static void write_config_nybble(struct pci_dev *router, unsigned offset, unsigned nr, unsigned int val) 186 + static void write_config_nybble(struct pci_dev *router, unsigned offset, 187 + unsigned nr, unsigned int val) 189 188 { 190 189 u8 x; 191 190 unsigned reg = offset + (nr >> 1); ··· 470 467 return inb(0xc01) & 0xf; 471 468 } 472 469 473 - static int pirq_serverworks_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq) 470 + static int pirq_serverworks_set(struct pci_dev *router, struct pci_dev *dev, 471 + int pirq, int irq) 474 472 { 475 473 outb(pirq, 0xc00); 476 474 outb(irq, 0xc01); ··· 664 660 } 665 661 666 662 667 - static __init int serverworks_router_probe(struct irq_router *r, struct pci_dev *router, u16 device) 663 + static __init int serverworks_router_probe(struct irq_router *r, 664 + struct pci_dev *router, u16 device) 668 665 { 669 666 switch (device) { 670 667 case PCI_DEVICE_ID_SERVERWORKS_OSB4: ··· 832 827 833 828 for (h = pirq_routers; h->vendor; h++) { 834 829 /* First look for a router match */ 835 - if (rt->rtr_vendor == h->vendor && h->probe(r, pirq_router_dev, rt->rtr_device)) 830 + if (rt->rtr_vendor == h->vendor && 831 + h->probe(r, pirq_router_dev, rt->rtr_device)) 836 832 break; 837 833 /* Fall back to a device match */ 838 - if (pirq_router_dev->vendor == h->vendor && h->probe(r, pirq_router_dev, pirq_router_dev->device)) 834 + if (pirq_router_dev->vendor == h->vendor && 835 + h->probe(r, pirq_router_dev, pirq_router_dev->device)) 839 836 break; 840 837 } 841 838 printk(KERN_INFO "PCI: Using IRQ router %s [%04x/%04x] at %s\n", ··· 852 845 static struct irq_info *pirq_get_info(struct pci_dev *dev) 853 846 { 854 847 struct irq_routing_table *rt = pirq_table; 855 - int entries = (rt->size - sizeof(struct irq_routing_table)) / sizeof(struct irq_info); 848 + int entries = (rt->size - sizeof(struct irq_routing_table)) / 849 + sizeof(struct irq_info); 856 850 struct irq_info *info; 857 851 858 852 for (info = rt->slots; entries--; info++) 859 - if (info->bus == dev->bus->number && PCI_SLOT(info->devfn) == PCI_SLOT(dev->devfn)) 853 + if (info->bus == dev->bus->number && 854 + PCI_SLOT(info->devfn) == PCI_SLOT(dev->devfn)) 860 855 return info; 861 856 return NULL; 862 857 } ··· 899 890 DBG(" -> not routed\n" KERN_DEBUG); 900 891 return 0; 901 892 } 902 - DBG(" -> PIRQ %02x, mask %04x, excl %04x", pirq, mask, pirq_table->exclusive_irqs); 893 + DBG(" -> PIRQ %02x, mask %04x, excl %04x", pirq, mask, 894 + pirq_table->exclusive_irqs); 903 895 mask &= pcibios_irq_mask; 904 896 905 897 /* Work around broken HP Pavilion Notebooks which assign USB to ··· 913 903 } 914 904 915 905 /* same for Acer Travelmate 360, but with CB and irq 11 -> 10 */ 916 - if (acer_tm360_irqrouting && dev->irq == 11 && dev->vendor == PCI_VENDOR_ID_O2) { 906 + if (acer_tm360_irqrouting && dev->irq == 11 && 907 + dev->vendor == PCI_VENDOR_ID_O2) { 917 908 pirq = 0x68; 918 909 mask = 0x400; 919 910 dev->irq = r->get(pirq_router_dev, dev, pirq); ··· 931 920 newirq = 0; 932 921 else 933 922 printk("\n" KERN_WARNING 934 - "PCI: IRQ %i for device %s doesn't match PIRQ mask " 935 - "- try pci=usepirqmask\n" KERN_DEBUG, newirq, 936 - pci_name(dev)); 923 + "PCI: IRQ %i for device %s doesn't match PIRQ mask - try pci=usepirqmask\n" 924 + KERN_DEBUG, newirq, 925 + pci_name(dev)); 937 926 } 938 927 if (!newirq && assign) { 939 928 for (i = 0; i < 16; i++) { 940 929 if (!(mask & (1 << i))) 941 930 continue; 942 - if (pirq_penalty[i] < pirq_penalty[newirq] && can_request_irq(i, IRQF_SHARED)) 931 + if (pirq_penalty[i] < pirq_penalty[newirq] && 932 + can_request_irq(i, IRQF_SHARED)) 943 933 newirq = i; 944 934 } 945 935 } ··· 956 944 DBG(" -> got IRQ %d\n", irq); 957 945 msg = "Found"; 958 946 eisa_set_level_irq(irq); 959 - } else if (newirq && r->set && (dev->class >> 8) != PCI_CLASS_DISPLAY_VGA) { 947 + } else if (newirq && r->set && 948 + (dev->class >> 8) != PCI_CLASS_DISPLAY_VGA) { 960 949 DBG(" -> assigning IRQ %d", newirq); 961 950 if (r->set(pirq_router_dev, dev, pirq, newirq)) { 962 951 eisa_set_level_irq(newirq); ··· 975 962 } else 976 963 return 0; 977 964 } 978 - printk(KERN_INFO "PCI: %s IRQ %d for device %s\n", msg, irq, pci_name(dev)); 965 + printk(KERN_INFO "PCI: %s IRQ %d for device %s\n", msg, irq, 966 + pci_name(dev)); 979 967 980 968 /* Update IRQ for all devices with the same pirq value */ 981 969 while ((dev2 = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev2)) != NULL) { ··· 988 974 if (!info) 989 975 continue; 990 976 if (info->irq[pin].link == pirq) { 991 - /* We refuse to override the dev->irq information. Give a warning! */ 977 + /* 978 + * We refuse to override the dev->irq 979 + * information. Give a warning! 980 + */ 992 981 if (dev2->irq && dev2->irq != irq && \ 993 982 (!(pci_probe & PCI_USE_PIRQ_MASK) || \ 994 983 ((1 << dev2->irq) & mask))) { ··· 1004 987 dev2->irq = irq; 1005 988 pirq_penalty[irq]++; 1006 989 if (dev != dev2) 1007 - printk(KERN_INFO "PCI: Sharing IRQ %d with %s\n", irq, pci_name(dev2)); 990 + printk(KERN_INFO 991 + "PCI: Sharing IRQ %d with %s\n", 992 + irq, pci_name(dev2)); 1008 993 } 1009 994 } 1010 995 return 1; ··· 1020 1001 DBG(KERN_DEBUG "PCI: IRQ fixup\n"); 1021 1002 while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) { 1022 1003 /* 1023 - * If the BIOS has set an out of range IRQ number, just ignore it. 1024 - * Also keep track of which IRQ's are already in use. 1004 + * If the BIOS has set an out of range IRQ number, just 1005 + * ignore it. Also keep track of which IRQ's are 1006 + * already in use. 1025 1007 */ 1026 1008 if (dev->irq >= 16) { 1027 - DBG(KERN_DEBUG "%s: ignoring bogus IRQ %d\n", pci_name(dev), dev->irq); 1009 + DBG(KERN_DEBUG "%s: ignoring bogus IRQ %d\n", 1010 + pci_name(dev), dev->irq); 1028 1011 dev->irq = 0; 1029 1012 } 1030 - /* If the IRQ is already assigned to a PCI device, ignore its ISA use penalty */ 1031 - if (pirq_penalty[dev->irq] >= 100 && pirq_penalty[dev->irq] < 100000) 1013 + /* 1014 + * If the IRQ is already assigned to a PCI device, 1015 + * ignore its ISA use penalty 1016 + */ 1017 + if (pirq_penalty[dev->irq] >= 100 && 1018 + pirq_penalty[dev->irq] < 100000) 1032 1019 pirq_penalty[dev->irq] = 0; 1033 1020 pirq_penalty[dev->irq]++; 1034 1021 } ··· 1050 1025 int irq; 1051 1026 1052 1027 if (pin) { 1053 - pin--; /* interrupt pins are numbered starting from 1 */ 1054 - irq = IO_APIC_get_PCI_irq_vector(dev->bus->number, PCI_SLOT(dev->devfn), pin); 1028 + /* 1029 + * interrupt pins are numbered starting 1030 + * from 1 1031 + */ 1032 + pin--; 1033 + irq = IO_APIC_get_PCI_irq_vector(dev->bus->number, 1034 + PCI_SLOT(dev->devfn), pin); 1055 1035 /* 1056 1036 * Busses behind bridges are typically not listed in the MP-table. 1057 1037 * In this case we have to look up the IRQ based on the parent bus, ··· 1097 1067 { 1098 1068 if (!broken_hp_bios_irq9) { 1099 1069 broken_hp_bios_irq9 = 1; 1100 - printk(KERN_INFO "%s detected - fixing broken IRQ routing\n", d->ident); 1070 + printk(KERN_INFO "%s detected - fixing broken IRQ routing\n", 1071 + d->ident); 1101 1072 } 1102 1073 return 0; 1103 1074 } ··· 1111 1080 { 1112 1081 if (!acer_tm360_irqrouting) { 1113 1082 acer_tm360_irqrouting = 1; 1114 - printk(KERN_INFO "%s detected - fixing broken IRQ routing\n", d->ident); 1083 + printk(KERN_INFO "%s detected - fixing broken IRQ routing\n", 1084 + d->ident); 1115 1085 } 1116 1086 return 0; 1117 1087 } ··· 1124 1092 .matches = { 1125 1093 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"), 1126 1094 DMI_MATCH(DMI_BIOS_VERSION, "GE.M1.03"), 1127 - DMI_MATCH(DMI_PRODUCT_VERSION, "HP Pavilion Notebook Model GE"), 1095 + DMI_MATCH(DMI_PRODUCT_VERSION, 1096 + "HP Pavilion Notebook Model GE"), 1128 1097 DMI_MATCH(DMI_BOARD_VERSION, "OmniBook N32N-736"), 1129 1098 }, 1130 1099 }, ··· 1164 1131 if (!(pirq_table->exclusive_irqs & (1 << i))) 1165 1132 pirq_penalty[i] += 100; 1166 1133 } 1167 - /* If we're using the I/O APIC, avoid using the PCI IRQ routing table */ 1134 + /* 1135 + * If we're using the I/O APIC, avoid using the PCI IRQ 1136 + * routing table 1137 + */ 1168 1138 if (io_apic_assign_pci_irqs) 1169 1139 pirq_table = NULL; 1170 1140 } ··· 1211 1175 if (pin && !pcibios_lookup_irq(dev, 1) && !dev->irq) { 1212 1176 char *msg = ""; 1213 1177 1214 - pin--; /* interrupt pins are numbered starting from 1 */ 1178 + pin--; /* interrupt pins are numbered starting from 1 */ 1215 1179 1216 1180 if (io_apic_assign_pci_irqs) { 1217 1181 int irq; ··· 1231 1195 irq = IO_APIC_get_PCI_irq_vector(bridge->bus->number, 1232 1196 PCI_SLOT(bridge->devfn), pin); 1233 1197 if (irq >= 0) 1234 - printk(KERN_WARNING "PCI: using PPB %s[%c] to get irq %d\n", 1235 - pci_name(bridge), 'A' + pin, irq); 1198 + printk(KERN_WARNING 1199 + "PCI: using PPB %s[%c] to get irq %d\n", 1200 + pci_name(bridge), 1201 + 'A' + pin, irq); 1236 1202 dev = bridge; 1237 1203 } 1238 1204 dev = temp_dev; 1239 1205 if (irq >= 0) { 1240 - printk(KERN_INFO "PCI->APIC IRQ transform: %s[%c] -> IRQ %d\n", 1206 + printk(KERN_INFO 1207 + "PCI->APIC IRQ transform: %s[%c] -> IRQ %d\n", 1241 1208 pci_name(dev), 'A' + pin, irq); 1242 1209 dev->irq = irq; 1243 1210 return 0; ··· 1251 1212 else 1252 1213 msg = " Please try using pci=biosirq."; 1253 1214 1254 - /* With IDE legacy devices the IRQ lookup failure is not a problem.. */ 1255 - if (dev->class >> 8 == PCI_CLASS_STORAGE_IDE && !(dev->class & 0x5)) 1215 + /* 1216 + * With IDE legacy devices the IRQ lookup failure is not 1217 + * a problem.. 1218 + */ 1219 + if (dev->class >> 8 == PCI_CLASS_STORAGE_IDE && 1220 + !(dev->class & 0x5)) 1256 1221 return 0; 1257 1222 1258 - printk(KERN_WARNING "PCI: No IRQ known for interrupt pin %c of device %s.%s\n", 1259 - 'A' + pin, pci_name(dev), msg); 1223 + printk(KERN_WARNING 1224 + "PCI: No IRQ known for interrupt pin %c of device %s.%s\n", 1225 + 'A' + pin, pci_name(dev), msg); 1260 1226 } 1261 1227 return 0; 1262 1228 }
+1
arch/x86/pci/pci.h
··· 28 28 #define PCI_USE__CRS 0x10000 29 29 #define PCI_CHECK_ENABLE_AMD_MMCONF 0x20000 30 30 #define PCI_HAS_IO_ECS 0x40000 31 + #define PCI_NOASSIGN_ROMS 0x80000 31 32 32 33 extern unsigned int pci_probe; 33 34 extern unsigned long pirq_table_addr;
+9
drivers/acpi/Kconfig
··· 336 336 the battery and thermal drivers. If you are compiling for a 337 337 mobile system, say Y. 338 338 339 + config ACPI_PCI_SLOT 340 + tristate "PCI slot detection driver" 341 + default n 342 + help 343 + This driver will attempt to discover all PCI slots in your system, 344 + and creates entries in /sys/bus/pci/slots/. This feature can 345 + help you correlate PCI bus addresses with the physical geography 346 + of your slots. If you are unsure, say N. 347 + 339 348 config ACPI_POWER 340 349 bool 341 350 default y
+1
drivers/acpi/Makefile
··· 48 48 obj-$(CONFIG_ACPI_BAY) += bay.o 49 49 obj-$(CONFIG_ACPI_VIDEO) += video.o 50 50 obj-y += pci_root.o pci_link.o pci_irq.o pci_bind.o 51 + obj-$(CONFIG_ACPI_PCI_SLOT) += pci_slot.o 51 52 obj-$(CONFIG_ACPI_POWER) += power.o 52 53 obj-$(CONFIG_ACPI_PROCESSOR) += processor.o 53 54 obj-$(CONFIG_ACPI_CONTAINER) += container.o
+22
drivers/acpi/bus.c
··· 295 295 296 296 EXPORT_SYMBOL(acpi_bus_set_power); 297 297 298 + bool acpi_bus_power_manageable(acpi_handle handle) 299 + { 300 + struct acpi_device *device; 301 + int result; 302 + 303 + result = acpi_bus_get_device(handle, &device); 304 + return result ? false : device->flags.power_manageable; 305 + } 306 + 307 + EXPORT_SYMBOL(acpi_bus_power_manageable); 308 + 309 + bool acpi_bus_can_wakeup(acpi_handle handle) 310 + { 311 + struct acpi_device *device; 312 + int result; 313 + 314 + result = acpi_bus_get_device(handle, &device); 315 + return result ? false : device->wakeup.flags.valid; 316 + } 317 + 318 + EXPORT_SYMBOL(acpi_bus_can_wakeup); 319 + 298 320 /* -------------------------------------------------------------------------- 299 321 Event Management 300 322 -------------------------------------------------------------------------- */
+2
drivers/acpi/glue.c
··· 166 166 "firmware_node"); 167 167 ret = sysfs_create_link(&acpi_dev->dev.kobj, &dev->kobj, 168 168 "physical_node"); 169 + if (acpi_dev->wakeup.flags.valid) 170 + device_set_wakeup_capable(dev, true); 169 171 } 170 172 171 173 return 0;
+368
drivers/acpi/pci_slot.c
··· 1 + /* 2 + * pci_slot.c - ACPI PCI Slot Driver 3 + * 4 + * The code here is heavily leveraged from the acpiphp module. 5 + * Thanks to Matthew Wilcox <matthew@wil.cx> for much guidance. 6 + * Thanks to Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com> for code 7 + * review and fixes. 8 + * 9 + * Copyright (C) 2007 Alex Chiang <achiang@hp.com> 10 + * Copyright (C) 2007 Hewlett-Packard Development Company, L.P. 11 + * 12 + * This program is free software; you can redistribute it and/or modify it 13 + * under the terms and conditions of the GNU General Public License, 14 + * version 2, as published by the Free Software Foundation. 15 + * 16 + * This program is distributed in the hope that it will be useful, but 17 + * WITHOUT ANY WARRANTY; without even the implied warranty of 18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 + * General Public License for more details. 20 + * 21 + * You should have received a copy of the GNU General Public License along 22 + * with this program; if not, write to the Free Software Foundation, Inc., 23 + * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. 24 + */ 25 + 26 + #include <linux/kernel.h> 27 + #include <linux/module.h> 28 + #include <linux/init.h> 29 + #include <linux/types.h> 30 + #include <linux/pci.h> 31 + #include <linux/acpi.h> 32 + #include <acpi/acpi_bus.h> 33 + #include <acpi/acpi_drivers.h> 34 + 35 + static int debug; 36 + static int check_sta_before_sun; 37 + 38 + #define DRIVER_VERSION "0.1" 39 + #define DRIVER_AUTHOR "Alex Chiang <achiang@hp.com>" 40 + #define DRIVER_DESC "ACPI PCI Slot Detection Driver" 41 + MODULE_AUTHOR(DRIVER_AUTHOR); 42 + MODULE_DESCRIPTION(DRIVER_DESC); 43 + MODULE_LICENSE("GPL"); 44 + MODULE_PARM_DESC(debug, "Debugging mode enabled or not"); 45 + module_param(debug, bool, 0644); 46 + 47 + #define _COMPONENT ACPI_PCI_COMPONENT 48 + ACPI_MODULE_NAME("pci_slot"); 49 + 50 + #define MY_NAME "pci_slot" 51 + #define err(format, arg...) printk(KERN_ERR "%s: " format , MY_NAME , ## arg) 52 + #define info(format, arg...) printk(KERN_INFO "%s: " format , MY_NAME , ## arg) 53 + #define dbg(format, arg...) \ 54 + do { \ 55 + if (debug) \ 56 + printk(KERN_DEBUG "%s: " format, \ 57 + MY_NAME , ## arg); \ 58 + } while (0) 59 + 60 + #define SLOT_NAME_SIZE 20 /* Inspired by #define in acpiphp.h */ 61 + 62 + struct acpi_pci_slot { 63 + acpi_handle root_handle; /* handle of the root bridge */ 64 + struct pci_slot *pci_slot; /* corresponding pci_slot */ 65 + struct list_head list; /* node in the list of slots */ 66 + }; 67 + 68 + static int acpi_pci_slot_add(acpi_handle handle); 69 + static void acpi_pci_slot_remove(acpi_handle handle); 70 + 71 + static LIST_HEAD(slot_list); 72 + static DEFINE_MUTEX(slot_list_lock); 73 + static struct acpi_pci_driver acpi_pci_slot_driver = { 74 + .add = acpi_pci_slot_add, 75 + .remove = acpi_pci_slot_remove, 76 + }; 77 + 78 + static int 79 + check_slot(acpi_handle handle, int *device, unsigned long *sun) 80 + { 81 + int retval = 0; 82 + unsigned long adr, sta; 83 + acpi_status status; 84 + struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 85 + 86 + acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer); 87 + dbg("Checking slot on path: %s\n", (char *)buffer.pointer); 88 + 89 + if (check_sta_before_sun) { 90 + /* If SxFy doesn't have _STA, we just assume it's there */ 91 + status = acpi_evaluate_integer(handle, "_STA", NULL, &sta); 92 + if (ACPI_SUCCESS(status) && !(sta & ACPI_STA_DEVICE_PRESENT)) { 93 + retval = -1; 94 + goto out; 95 + } 96 + } 97 + 98 + status = acpi_evaluate_integer(handle, "_ADR", NULL, &adr); 99 + if (ACPI_FAILURE(status)) { 100 + dbg("_ADR returned %d on %s\n", status, (char *)buffer.pointer); 101 + retval = -1; 102 + goto out; 103 + } 104 + 105 + *device = (adr >> 16) & 0xffff; 106 + 107 + /* No _SUN == not a slot == bail */ 108 + status = acpi_evaluate_integer(handle, "_SUN", NULL, sun); 109 + if (ACPI_FAILURE(status)) { 110 + dbg("_SUN returned %d on %s\n", status, (char *)buffer.pointer); 111 + retval = -1; 112 + goto out; 113 + } 114 + 115 + out: 116 + kfree(buffer.pointer); 117 + return retval; 118 + } 119 + 120 + struct callback_args { 121 + acpi_walk_callback user_function; /* only for walk_p2p_bridge */ 122 + struct pci_bus *pci_bus; 123 + acpi_handle root_handle; 124 + }; 125 + 126 + /* 127 + * register_slot 128 + * 129 + * Called once for each SxFy object in the namespace. Don't worry about 130 + * calling pci_create_slot multiple times for the same pci_bus:device, 131 + * since each subsequent call simply bumps the refcount on the pci_slot. 132 + * 133 + * The number of calls to pci_destroy_slot from unregister_slot is 134 + * symmetrical. 135 + */ 136 + static acpi_status 137 + register_slot(acpi_handle handle, u32 lvl, void *context, void **rv) 138 + { 139 + int device; 140 + unsigned long sun; 141 + char name[SLOT_NAME_SIZE]; 142 + struct acpi_pci_slot *slot; 143 + struct pci_slot *pci_slot; 144 + struct callback_args *parent_context = context; 145 + struct pci_bus *pci_bus = parent_context->pci_bus; 146 + 147 + if (check_slot(handle, &device, &sun)) 148 + return AE_OK; 149 + 150 + slot = kmalloc(sizeof(*slot), GFP_KERNEL); 151 + if (!slot) { 152 + err("%s: cannot allocate memory\n", __func__); 153 + return AE_OK; 154 + } 155 + 156 + snprintf(name, sizeof(name), "%u", (u32)sun); 157 + pci_slot = pci_create_slot(pci_bus, device, name); 158 + if (IS_ERR(pci_slot)) { 159 + err("pci_create_slot returned %ld\n", PTR_ERR(pci_slot)); 160 + kfree(slot); 161 + } 162 + 163 + slot->root_handle = parent_context->root_handle; 164 + slot->pci_slot = pci_slot; 165 + INIT_LIST_HEAD(&slot->list); 166 + mutex_lock(&slot_list_lock); 167 + list_add(&slot->list, &slot_list); 168 + mutex_unlock(&slot_list_lock); 169 + 170 + dbg("pci_slot: %p, pci_bus: %x, device: %d, name: %s\n", 171 + pci_slot, pci_bus->number, device, name); 172 + 173 + return AE_OK; 174 + } 175 + 176 + /* 177 + * walk_p2p_bridge - discover and walk p2p bridges 178 + * @handle: points to an acpi_pci_root 179 + * @context: p2p_bridge_context pointer 180 + * 181 + * Note that when we call ourselves recursively, we pass a different 182 + * value of pci_bus in the child_context. 183 + */ 184 + static acpi_status 185 + walk_p2p_bridge(acpi_handle handle, u32 lvl, void *context, void **rv) 186 + { 187 + int device, function; 188 + unsigned long adr; 189 + acpi_status status; 190 + acpi_handle dummy_handle; 191 + acpi_walk_callback user_function; 192 + 193 + struct pci_dev *dev; 194 + struct pci_bus *pci_bus; 195 + struct callback_args child_context; 196 + struct callback_args *parent_context = context; 197 + 198 + pci_bus = parent_context->pci_bus; 199 + user_function = parent_context->user_function; 200 + 201 + status = acpi_get_handle(handle, "_ADR", &dummy_handle); 202 + if (ACPI_FAILURE(status)) 203 + return AE_OK; 204 + 205 + status = acpi_evaluate_integer(handle, "_ADR", NULL, &adr); 206 + if (ACPI_FAILURE(status)) 207 + return AE_OK; 208 + 209 + device = (adr >> 16) & 0xffff; 210 + function = adr & 0xffff; 211 + 212 + dev = pci_get_slot(pci_bus, PCI_DEVFN(device, function)); 213 + if (!dev || !dev->subordinate) 214 + goto out; 215 + 216 + child_context.pci_bus = dev->subordinate; 217 + child_context.user_function = user_function; 218 + child_context.root_handle = parent_context->root_handle; 219 + 220 + dbg("p2p bridge walk, pci_bus = %x\n", dev->subordinate->number); 221 + status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, (u32)1, 222 + user_function, &child_context, NULL); 223 + if (ACPI_FAILURE(status)) 224 + goto out; 225 + 226 + status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, (u32)1, 227 + walk_p2p_bridge, &child_context, NULL); 228 + out: 229 + pci_dev_put(dev); 230 + return AE_OK; 231 + } 232 + 233 + /* 234 + * walk_root_bridge - generic root bridge walker 235 + * @handle: points to an acpi_pci_root 236 + * @user_function: user callback for slot objects 237 + * 238 + * Call user_function for all objects underneath this root bridge. 239 + * Walk p2p bridges underneath us and call user_function on those too. 240 + */ 241 + static int 242 + walk_root_bridge(acpi_handle handle, acpi_walk_callback user_function) 243 + { 244 + int seg, bus; 245 + unsigned long tmp; 246 + acpi_status status; 247 + acpi_handle dummy_handle; 248 + struct pci_bus *pci_bus; 249 + struct callback_args context; 250 + 251 + /* If the bridge doesn't have _STA, we assume it is always there */ 252 + status = acpi_get_handle(handle, "_STA", &dummy_handle); 253 + if (ACPI_SUCCESS(status)) { 254 + status = acpi_evaluate_integer(handle, "_STA", NULL, &tmp); 255 + if (ACPI_FAILURE(status)) { 256 + info("%s: _STA evaluation failure\n", __func__); 257 + return 0; 258 + } 259 + if ((tmp & ACPI_STA_DEVICE_FUNCTIONING) == 0) 260 + /* don't register this object */ 261 + return 0; 262 + } 263 + 264 + status = acpi_evaluate_integer(handle, "_SEG", NULL, &tmp); 265 + seg = ACPI_SUCCESS(status) ? tmp : 0; 266 + 267 + status = acpi_evaluate_integer(handle, "_BBN", NULL, &tmp); 268 + bus = ACPI_SUCCESS(status) ? tmp : 0; 269 + 270 + pci_bus = pci_find_bus(seg, bus); 271 + if (!pci_bus) 272 + return 0; 273 + 274 + context.pci_bus = pci_bus; 275 + context.user_function = user_function; 276 + context.root_handle = handle; 277 + 278 + dbg("root bridge walk, pci_bus = %x\n", pci_bus->number); 279 + status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, (u32)1, 280 + user_function, &context, NULL); 281 + if (ACPI_FAILURE(status)) 282 + return status; 283 + 284 + status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, (u32)1, 285 + walk_p2p_bridge, &context, NULL); 286 + if (ACPI_FAILURE(status)) 287 + err("%s: walk_p2p_bridge failure - %d\n", __func__, status); 288 + 289 + return status; 290 + } 291 + 292 + /* 293 + * acpi_pci_slot_add 294 + * @handle: points to an acpi_pci_root 295 + */ 296 + static int 297 + acpi_pci_slot_add(acpi_handle handle) 298 + { 299 + acpi_status status; 300 + 301 + status = walk_root_bridge(handle, register_slot); 302 + if (ACPI_FAILURE(status)) 303 + err("%s: register_slot failure - %d\n", __func__, status); 304 + 305 + return status; 306 + } 307 + 308 + /* 309 + * acpi_pci_slot_remove 310 + * @handle: points to an acpi_pci_root 311 + */ 312 + static void 313 + acpi_pci_slot_remove(acpi_handle handle) 314 + { 315 + struct acpi_pci_slot *slot, *tmp; 316 + 317 + mutex_lock(&slot_list_lock); 318 + list_for_each_entry_safe(slot, tmp, &slot_list, list) { 319 + if (slot->root_handle == handle) { 320 + list_del(&slot->list); 321 + pci_destroy_slot(slot->pci_slot); 322 + kfree(slot); 323 + } 324 + } 325 + mutex_unlock(&slot_list_lock); 326 + } 327 + 328 + static int do_sta_before_sun(const struct dmi_system_id *d) 329 + { 330 + info("%s detected: will evaluate _STA before calling _SUN\n", d->ident); 331 + check_sta_before_sun = 1; 332 + return 0; 333 + } 334 + 335 + static struct dmi_system_id acpi_pci_slot_dmi_table[] __initdata = { 336 + /* 337 + * Fujitsu Primequest machines will return 1023 to indicate an 338 + * error if the _SUN method is evaluated on SxFy objects that 339 + * are not present (as indicated by _STA), so for those machines, 340 + * we want to check _STA before evaluating _SUN. 341 + */ 342 + { 343 + .callback = do_sta_before_sun, 344 + .ident = "Fujitsu PRIMEQUEST", 345 + .matches = { 346 + DMI_MATCH(DMI_BIOS_VENDOR, "FUJITSU LIMITED"), 347 + DMI_MATCH(DMI_BIOS_VERSION, "PRIMEQUEST"), 348 + }, 349 + }, 350 + {} 351 + }; 352 + 353 + static int __init 354 + acpi_pci_slot_init(void) 355 + { 356 + dmi_check_system(acpi_pci_slot_dmi_table); 357 + acpi_pci_register_driver(&acpi_pci_slot_driver); 358 + return 0; 359 + } 360 + 361 + static void __exit 362 + acpi_pci_slot_exit(void) 363 + { 364 + acpi_pci_unregister_driver(&acpi_pci_slot_driver); 365 + } 366 + 367 + module_init(acpi_pci_slot_init); 368 + module_exit(acpi_pci_slot_exit);
+102 -36
drivers/acpi/power.c
··· 292 292 return 0; 293 293 } 294 294 295 + /** 296 + * acpi_device_sleep_wake - execute _DSW (Device Sleep Wake) or (deprecated in 297 + * ACPI 3.0) _PSW (Power State Wake) 298 + * @dev: Device to handle. 299 + * @enable: 0 - disable, 1 - enable the wake capabilities of the device. 300 + * @sleep_state: Target sleep state of the system. 301 + * @dev_state: Target power state of the device. 302 + * 303 + * Execute _DSW (Device Sleep Wake) or (deprecated in ACPI 3.0) _PSW (Power 304 + * State Wake) for the device, if present. On failure reset the device's 305 + * wakeup.flags.valid flag. 306 + * 307 + * RETURN VALUE: 308 + * 0 if either _DSW or _PSW has been successfully executed 309 + * 0 if neither _DSW nor _PSW has been found 310 + * -ENODEV if the execution of either _DSW or _PSW has failed 311 + */ 312 + int acpi_device_sleep_wake(struct acpi_device *dev, 313 + int enable, int sleep_state, int dev_state) 314 + { 315 + union acpi_object in_arg[3]; 316 + struct acpi_object_list arg_list = { 3, in_arg }; 317 + acpi_status status = AE_OK; 318 + 319 + /* 320 + * Try to execute _DSW first. 321 + * 322 + * Three agruments are needed for the _DSW object: 323 + * Argument 0: enable/disable the wake capabilities 324 + * Argument 1: target system state 325 + * Argument 2: target device state 326 + * When _DSW object is called to disable the wake capabilities, maybe 327 + * the first argument is filled. The values of the other two agruments 328 + * are meaningless. 329 + */ 330 + in_arg[0].type = ACPI_TYPE_INTEGER; 331 + in_arg[0].integer.value = enable; 332 + in_arg[1].type = ACPI_TYPE_INTEGER; 333 + in_arg[1].integer.value = sleep_state; 334 + in_arg[2].type = ACPI_TYPE_INTEGER; 335 + in_arg[2].integer.value = dev_state; 336 + status = acpi_evaluate_object(dev->handle, "_DSW", &arg_list, NULL); 337 + if (ACPI_SUCCESS(status)) { 338 + return 0; 339 + } else if (status != AE_NOT_FOUND) { 340 + printk(KERN_ERR PREFIX "_DSW execution failed\n"); 341 + dev->wakeup.flags.valid = 0; 342 + return -ENODEV; 343 + } 344 + 345 + /* Execute _PSW */ 346 + arg_list.count = 1; 347 + in_arg[0].integer.value = enable; 348 + status = acpi_evaluate_object(dev->handle, "_PSW", &arg_list, NULL); 349 + if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) { 350 + printk(KERN_ERR PREFIX "_PSW execution failed\n"); 351 + dev->wakeup.flags.valid = 0; 352 + return -ENODEV; 353 + } 354 + 355 + return 0; 356 + } 357 + 295 358 /* 296 359 * Prepare a wakeup device, two steps (Ref ACPI 2.0:P229): 297 360 * 1. Power on the power resources required for the wakeup device 298 - * 2. Enable _PSW (power state wake) for the device if present 361 + * 2. Execute _DSW (Device Sleep Wake) or (deprecated in ACPI 3.0) _PSW (Power 362 + * State Wake) for the device, if present 299 363 */ 300 - int acpi_enable_wakeup_device_power(struct acpi_device *dev) 364 + int acpi_enable_wakeup_device_power(struct acpi_device *dev, int sleep_state) 301 365 { 302 - union acpi_object arg = { ACPI_TYPE_INTEGER }; 303 - struct acpi_object_list arg_list = { 1, &arg }; 304 - acpi_status status = AE_OK; 305 - int i; 306 - int ret = 0; 366 + int i, err; 307 367 308 368 if (!dev || !dev->wakeup.flags.valid) 309 - return -1; 369 + return -EINVAL; 310 370 311 - arg.integer.value = 1; 371 + /* 372 + * Do not execute the code below twice in a row without calling 373 + * acpi_disable_wakeup_device_power() in between for the same device 374 + */ 375 + if (dev->wakeup.flags.prepared) 376 + return 0; 377 + 312 378 /* Open power resource */ 313 379 for (i = 0; i < dev->wakeup.resources.count; i++) { 314 - ret = acpi_power_on(dev->wakeup.resources.handles[i], dev); 380 + int ret = acpi_power_on(dev->wakeup.resources.handles[i], dev); 315 381 if (ret) { 316 382 printk(KERN_ERR PREFIX "Transition power state\n"); 317 383 dev->wakeup.flags.valid = 0; 318 - return -1; 384 + return -ENODEV; 319 385 } 320 386 } 321 387 322 - /* Execute PSW */ 323 - status = acpi_evaluate_object(dev->handle, "_PSW", &arg_list, NULL); 324 - if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) { 325 - printk(KERN_ERR PREFIX "Evaluate _PSW\n"); 326 - dev->wakeup.flags.valid = 0; 327 - ret = -1; 328 - } 388 + /* 389 + * Passing 3 as the third argument below means the device may be placed 390 + * in arbitrary power state afterwards. 391 + */ 392 + err = acpi_device_sleep_wake(dev, 1, sleep_state, 3); 393 + if (!err) 394 + dev->wakeup.flags.prepared = 1; 329 395 330 - return ret; 396 + return err; 331 397 } 332 398 333 399 /* 334 400 * Shutdown a wakeup device, counterpart of above method 335 - * 1. Disable _PSW (power state wake) 401 + * 1. Execute _DSW (Device Sleep Wake) or (deprecated in ACPI 3.0) _PSW (Power 402 + * State Wake) for the device, if present 336 403 * 2. Shutdown down the power resources 337 404 */ 338 405 int acpi_disable_wakeup_device_power(struct acpi_device *dev) 339 406 { 340 - union acpi_object arg = { ACPI_TYPE_INTEGER }; 341 - struct acpi_object_list arg_list = { 1, &arg }; 342 - acpi_status status = AE_OK; 343 - int i; 344 - int ret = 0; 345 - 407 + int i, ret; 346 408 347 409 if (!dev || !dev->wakeup.flags.valid) 348 - return -1; 410 + return -EINVAL; 349 411 350 - arg.integer.value = 0; 351 - /* Execute PSW */ 352 - status = acpi_evaluate_object(dev->handle, "_PSW", &arg_list, NULL); 353 - if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) { 354 - printk(KERN_ERR PREFIX "Evaluate _PSW\n"); 355 - dev->wakeup.flags.valid = 0; 356 - return -1; 357 - } 412 + /* 413 + * Do not execute the code below twice in a row without calling 414 + * acpi_enable_wakeup_device_power() in between for the same device 415 + */ 416 + if (!dev->wakeup.flags.prepared) 417 + return 0; 418 + 419 + dev->wakeup.flags.prepared = 0; 420 + 421 + ret = acpi_device_sleep_wake(dev, 0, 0, 0); 422 + if (ret) 423 + return ret; 358 424 359 425 /* Close power resource */ 360 426 for (i = 0; i < dev->wakeup.resources.count; i++) { ··· 428 362 if (ret) { 429 363 printk(KERN_ERR PREFIX "Transition power state\n"); 430 364 dev->wakeup.flags.valid = 0; 431 - return -1; 365 + return -ENODEV; 432 366 } 433 367 } 434 368
+6 -36
drivers/acpi/scan.c
··· 703 703 acpi_status status = 0; 704 704 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 705 705 union acpi_object *package = NULL; 706 - union acpi_object in_arg[3]; 707 - struct acpi_object_list arg_list = { 3, in_arg }; 708 - acpi_status psw_status = AE_OK; 706 + int psw_error; 709 707 710 708 struct acpi_device_id button_device_ids[] = { 711 709 {"PNP0C0D", 0}, ··· 735 737 * So it is necessary to call _DSW object first. Only when it is not 736 738 * present will the _PSW object used. 737 739 */ 738 - /* 739 - * Three agruments are needed for the _DSW object. 740 - * Argument 0: enable/disable the wake capabilities 741 - * When _DSW object is called to disable the wake capabilities, maybe 742 - * the first argument is filled. The value of the other two agruments 743 - * is meaningless. 744 - */ 745 - in_arg[0].type = ACPI_TYPE_INTEGER; 746 - in_arg[0].integer.value = 0; 747 - in_arg[1].type = ACPI_TYPE_INTEGER; 748 - in_arg[1].integer.value = 0; 749 - in_arg[2].type = ACPI_TYPE_INTEGER; 750 - in_arg[2].integer.value = 0; 751 - psw_status = acpi_evaluate_object(device->handle, "_DSW", 752 - &arg_list, NULL); 753 - if (ACPI_FAILURE(psw_status) && (psw_status != AE_NOT_FOUND)) 754 - ACPI_DEBUG_PRINT((ACPI_DB_INFO, "error in evaluate _DSW\n")); 755 - /* 756 - * When the _DSW object is not present, OSPM will call _PSW object. 757 - */ 758 - if (psw_status == AE_NOT_FOUND) { 759 - /* 760 - * Only one agruments is required for the _PSW object. 761 - * agrument 0: enable/disable the wake capabilities 762 - */ 763 - arg_list.count = 1; 764 - in_arg[0].integer.value = 0; 765 - psw_status = acpi_evaluate_object(device->handle, "_PSW", 766 - &arg_list, NULL); 767 - if (ACPI_FAILURE(psw_status) && (psw_status != AE_NOT_FOUND)) 768 - ACPI_DEBUG_PRINT((ACPI_DB_INFO, "error in " 769 - "evaluate _PSW\n")); 770 - } 740 + psw_error = acpi_device_sleep_wake(device, 0, 0, 0); 741 + if (psw_error) 742 + ACPI_DEBUG_PRINT((ACPI_DB_INFO, 743 + "error in _DSW or _PSW evaluation\n")); 744 + 771 745 /* Power button, Lid switch always enable wakeup */ 772 746 if (!acpi_match_device_ids(device, button_device_ids)) 773 747 device->wakeup.flags.run_wake = 1;
+190 -115
drivers/acpi/sleep/main.c
··· 24 24 25 25 u8 sleep_states[ACPI_S_STATE_COUNT]; 26 26 27 - #ifdef CONFIG_PM_SLEEP 28 - static u32 acpi_target_sleep_state = ACPI_STATE_S0; 29 - #endif 30 - 31 27 static int acpi_sleep_prepare(u32 acpi_state) 32 28 { 33 29 #ifdef CONFIG_ACPI_SLEEP ··· 45 49 return 0; 46 50 } 47 51 48 - #ifdef CONFIG_SUSPEND 49 - static struct platform_suspend_ops acpi_suspend_ops; 52 + #ifdef CONFIG_PM_SLEEP 53 + static u32 acpi_target_sleep_state = ACPI_STATE_S0; 50 54 55 + /* 56 + * ACPI 1.0 wants us to execute _PTS before suspending devices, so we allow the 57 + * user to request that behavior by using the 'acpi_old_suspend_ordering' 58 + * kernel command line option that causes the following variable to be set. 59 + */ 60 + static bool old_suspend_ordering; 61 + 62 + void __init acpi_old_suspend_ordering(void) 63 + { 64 + old_suspend_ordering = true; 65 + } 66 + 67 + /** 68 + * acpi_pm_disable_gpes - Disable the GPEs. 69 + */ 70 + static int acpi_pm_disable_gpes(void) 71 + { 72 + acpi_hw_disable_all_gpes(); 73 + return 0; 74 + } 75 + 76 + /** 77 + * __acpi_pm_prepare - Prepare the platform to enter the target state. 78 + * 79 + * If necessary, set the firmware waking vector and do arch-specific 80 + * nastiness to get the wakeup code to the waking vector. 81 + */ 82 + static int __acpi_pm_prepare(void) 83 + { 84 + int error = acpi_sleep_prepare(acpi_target_sleep_state); 85 + 86 + if (error) 87 + acpi_target_sleep_state = ACPI_STATE_S0; 88 + return error; 89 + } 90 + 91 + /** 92 + * acpi_pm_prepare - Prepare the platform to enter the target sleep 93 + * state and disable the GPEs. 94 + */ 95 + static int acpi_pm_prepare(void) 96 + { 97 + int error = __acpi_pm_prepare(); 98 + 99 + if (!error) 100 + acpi_hw_disable_all_gpes(); 101 + return error; 102 + } 103 + 104 + /** 105 + * acpi_pm_finish - Instruct the platform to leave a sleep state. 106 + * 107 + * This is called after we wake back up (or if entering the sleep state 108 + * failed). 109 + */ 110 + static void acpi_pm_finish(void) 111 + { 112 + u32 acpi_state = acpi_target_sleep_state; 113 + 114 + if (acpi_state == ACPI_STATE_S0) 115 + return; 116 + 117 + printk(KERN_INFO PREFIX "Waking up from system sleep state S%d\n", 118 + acpi_state); 119 + acpi_disable_wakeup_device(acpi_state); 120 + acpi_leave_sleep_state(acpi_state); 121 + 122 + /* reset firmware waking vector */ 123 + acpi_set_firmware_waking_vector((acpi_physical_address) 0); 124 + 125 + acpi_target_sleep_state = ACPI_STATE_S0; 126 + } 127 + 128 + /** 129 + * acpi_pm_end - Finish up suspend sequence. 130 + */ 131 + static void acpi_pm_end(void) 132 + { 133 + /* 134 + * This is necessary in case acpi_pm_finish() is not called during a 135 + * failing transition to a sleep state. 136 + */ 137 + acpi_target_sleep_state = ACPI_STATE_S0; 138 + } 139 + #endif /* CONFIG_PM_SLEEP */ 140 + 141 + #ifdef CONFIG_SUSPEND 51 142 extern void do_suspend_lowlevel(void); 52 143 53 144 static u32 acpi_suspend_states[] = { ··· 148 65 * acpi_suspend_begin - Set the target system sleep state to the state 149 66 * associated with given @pm_state, if supported. 150 67 */ 151 - 152 68 static int acpi_suspend_begin(suspend_state_t pm_state) 153 69 { 154 70 u32 acpi_state = acpi_suspend_states[pm_state]; ··· 164 82 } 165 83 166 84 /** 167 - * acpi_suspend_prepare - Do preliminary suspend work. 168 - * 169 - * If necessary, set the firmware waking vector and do arch-specific 170 - * nastiness to get the wakeup code to the waking vector. 171 - */ 172 - 173 - static int acpi_suspend_prepare(void) 174 - { 175 - int error = acpi_sleep_prepare(acpi_target_sleep_state); 176 - 177 - if (error) { 178 - acpi_target_sleep_state = ACPI_STATE_S0; 179 - return error; 180 - } 181 - 182 - return ACPI_SUCCESS(acpi_hw_disable_all_gpes()) ? 0 : -EFAULT; 183 - } 184 - 185 - /** 186 85 * acpi_suspend_enter - Actually enter a sleep state. 187 86 * @pm_state: ignored 188 87 * ··· 171 108 * assembly, which in turn call acpi_enter_sleep_state(). 172 109 * It's unfortunate, but it works. Please fix if you're feeling frisky. 173 110 */ 174 - 175 111 static int acpi_suspend_enter(suspend_state_t pm_state) 176 112 { 177 113 acpi_status status = AE_OK; ··· 227 165 return ACPI_SUCCESS(status) ? 0 : -EFAULT; 228 166 } 229 167 230 - /** 231 - * acpi_suspend_finish - Instruct the platform to leave a sleep state. 232 - * 233 - * This is called after we wake back up (or if entering the sleep state 234 - * failed). 235 - */ 236 - 237 - static void acpi_suspend_finish(void) 238 - { 239 - u32 acpi_state = acpi_target_sleep_state; 240 - 241 - acpi_disable_wakeup_device(acpi_state); 242 - acpi_leave_sleep_state(acpi_state); 243 - 244 - /* reset firmware waking vector */ 245 - acpi_set_firmware_waking_vector((acpi_physical_address) 0); 246 - 247 - acpi_target_sleep_state = ACPI_STATE_S0; 248 - } 249 - 250 - /** 251 - * acpi_suspend_end - Finish up suspend sequence. 252 - */ 253 - 254 - static void acpi_suspend_end(void) 255 - { 256 - /* 257 - * This is necessary in case acpi_suspend_finish() is not called during a 258 - * failing transition to a sleep state. 259 - */ 260 - acpi_target_sleep_state = ACPI_STATE_S0; 261 - } 262 - 263 168 static int acpi_suspend_state_valid(suspend_state_t pm_state) 264 169 { 265 170 u32 acpi_state; ··· 246 217 static struct platform_suspend_ops acpi_suspend_ops = { 247 218 .valid = acpi_suspend_state_valid, 248 219 .begin = acpi_suspend_begin, 249 - .prepare = acpi_suspend_prepare, 220 + .prepare = acpi_pm_prepare, 250 221 .enter = acpi_suspend_enter, 251 - .finish = acpi_suspend_finish, 252 - .end = acpi_suspend_end, 222 + .finish = acpi_pm_finish, 223 + .end = acpi_pm_end, 224 + }; 225 + 226 + /** 227 + * acpi_suspend_begin_old - Set the target system sleep state to the 228 + * state associated with given @pm_state, if supported, and 229 + * execute the _PTS control method. This function is used if the 230 + * pre-ACPI 2.0 suspend ordering has been requested. 231 + */ 232 + static int acpi_suspend_begin_old(suspend_state_t pm_state) 233 + { 234 + int error = acpi_suspend_begin(pm_state); 235 + 236 + if (!error) 237 + error = __acpi_pm_prepare(); 238 + return error; 239 + } 240 + 241 + /* 242 + * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has 243 + * been requested. 244 + */ 245 + static struct platform_suspend_ops acpi_suspend_ops_old = { 246 + .valid = acpi_suspend_state_valid, 247 + .begin = acpi_suspend_begin_old, 248 + .prepare = acpi_pm_disable_gpes, 249 + .enter = acpi_suspend_enter, 250 + .finish = acpi_pm_finish, 251 + .end = acpi_pm_end, 252 + .recover = acpi_pm_finish, 253 253 }; 254 254 #endif /* CONFIG_SUSPEND */ 255 255 ··· 286 228 static int acpi_hibernation_begin(void) 287 229 { 288 230 acpi_target_sleep_state = ACPI_STATE_S4; 289 - 290 231 return 0; 291 - } 292 - 293 - static int acpi_hibernation_prepare(void) 294 - { 295 - int error = acpi_sleep_prepare(ACPI_STATE_S4); 296 - 297 - if (error) { 298 - acpi_target_sleep_state = ACPI_STATE_S0; 299 - return error; 300 - } 301 - 302 - return ACPI_SUCCESS(acpi_hw_disable_all_gpes()) ? 0 : -EFAULT; 303 232 } 304 233 305 234 static int acpi_hibernation_enter(void) ··· 318 273 acpi_leave_sleep_state_prep(ACPI_STATE_S4); 319 274 } 320 275 321 - static void acpi_hibernation_finish(void) 322 - { 323 - acpi_disable_wakeup_device(ACPI_STATE_S4); 324 - acpi_leave_sleep_state(ACPI_STATE_S4); 325 - 326 - /* reset firmware waking vector */ 327 - acpi_set_firmware_waking_vector((acpi_physical_address) 0); 328 - 329 - acpi_target_sleep_state = ACPI_STATE_S0; 330 - } 331 - 332 - static void acpi_hibernation_end(void) 333 - { 334 - /* 335 - * This is necessary in case acpi_hibernation_finish() is not called 336 - * during a failing transition to the sleep state. 337 - */ 338 - acpi_target_sleep_state = ACPI_STATE_S0; 339 - } 340 - 341 - static int acpi_hibernation_pre_restore(void) 342 - { 343 - acpi_status status; 344 - 345 - status = acpi_hw_disable_all_gpes(); 346 - 347 - return ACPI_SUCCESS(status) ? 0 : -EFAULT; 348 - } 349 - 350 - static void acpi_hibernation_restore_cleanup(void) 276 + static void acpi_pm_enable_gpes(void) 351 277 { 352 278 acpi_hw_enable_all_runtime_gpes(); 353 279 } 354 280 355 281 static struct platform_hibernation_ops acpi_hibernation_ops = { 356 282 .begin = acpi_hibernation_begin, 357 - .end = acpi_hibernation_end, 358 - .pre_snapshot = acpi_hibernation_prepare, 359 - .finish = acpi_hibernation_finish, 360 - .prepare = acpi_hibernation_prepare, 283 + .end = acpi_pm_end, 284 + .pre_snapshot = acpi_pm_prepare, 285 + .finish = acpi_pm_finish, 286 + .prepare = acpi_pm_prepare, 361 287 .enter = acpi_hibernation_enter, 362 288 .leave = acpi_hibernation_leave, 363 - .pre_restore = acpi_hibernation_pre_restore, 364 - .restore_cleanup = acpi_hibernation_restore_cleanup, 289 + .pre_restore = acpi_pm_disable_gpes, 290 + .restore_cleanup = acpi_pm_enable_gpes, 365 291 }; 366 - #endif /* CONFIG_HIBERNATION */ 292 + 293 + /** 294 + * acpi_hibernation_begin_old - Set the target system sleep state to 295 + * ACPI_STATE_S4 and execute the _PTS control method. This 296 + * function is used if the pre-ACPI 2.0 suspend ordering has been 297 + * requested. 298 + */ 299 + static int acpi_hibernation_begin_old(void) 300 + { 301 + int error = acpi_sleep_prepare(ACPI_STATE_S4); 302 + 303 + if (!error) 304 + acpi_target_sleep_state = ACPI_STATE_S4; 305 + return error; 306 + } 307 + 308 + /* 309 + * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has 310 + * been requested. 311 + */ 312 + static struct platform_hibernation_ops acpi_hibernation_ops_old = { 313 + .begin = acpi_hibernation_begin_old, 314 + .end = acpi_pm_end, 315 + .pre_snapshot = acpi_pm_disable_gpes, 316 + .finish = acpi_pm_finish, 317 + .prepare = acpi_pm_disable_gpes, 318 + .enter = acpi_hibernation_enter, 319 + .leave = acpi_hibernation_leave, 320 + .pre_restore = acpi_pm_disable_gpes, 321 + .restore_cleanup = acpi_pm_enable_gpes, 322 + .recover = acpi_pm_finish, 323 + }; 324 + #endif /* CONFIG_HIBERNATION */ 367 325 368 326 int acpi_suspend(u32 acpi_state) 369 327 { ··· 467 419 *d_min_p = d_min; 468 420 return d_max; 469 421 } 422 + 423 + /** 424 + * acpi_pm_device_sleep_wake - enable or disable the system wake-up 425 + * capability of given device 426 + * @dev: device to handle 427 + * @enable: 'true' - enable, 'false' - disable the wake-up capability 428 + */ 429 + int acpi_pm_device_sleep_wake(struct device *dev, bool enable) 430 + { 431 + acpi_handle handle; 432 + struct acpi_device *adev; 433 + 434 + if (!device_may_wakeup(dev)) 435 + return -EINVAL; 436 + 437 + handle = DEVICE_ACPI_HANDLE(dev); 438 + if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) { 439 + printk(KERN_DEBUG "ACPI handle has no context!\n"); 440 + return -ENODEV; 441 + } 442 + 443 + return enable ? 444 + acpi_enable_wakeup_device_power(adev, acpi_target_sleep_state) : 445 + acpi_disable_wakeup_device_power(adev); 446 + } 470 447 #endif 471 448 472 449 static void acpi_power_off_prepare(void) ··· 533 460 } 534 461 } 535 462 536 - suspend_set_ops(&acpi_suspend_ops); 463 + suspend_set_ops(old_suspend_ordering ? 464 + &acpi_suspend_ops_old : &acpi_suspend_ops); 537 465 #endif 538 466 539 467 #ifdef CONFIG_HIBERNATION 540 468 status = acpi_get_sleep_type_data(ACPI_STATE_S4, &type_a, &type_b); 541 469 if (ACPI_SUCCESS(status)) { 542 - hibernation_set_ops(&acpi_hibernation_ops); 470 + hibernation_set_ops(old_suspend_ordering ? 471 + &acpi_hibernation_ops_old : &acpi_hibernation_ops); 543 472 sleep_states[ACPI_STATE_S4] = 1; 544 473 printk(" S4"); 545 474 }
+8 -5
drivers/acpi/sleep/wakeup.c
··· 42 42 continue; 43 43 44 44 spin_unlock(&acpi_device_lock); 45 - acpi_enable_wakeup_device_power(dev); 45 + acpi_enable_wakeup_device_power(dev, sleep_state); 46 46 spin_lock(&acpi_device_lock); 47 47 } 48 48 spin_unlock(&acpi_device_lock); ··· 66 66 list_for_each_safe(node, next, &acpi_wakeup_device_list) { 67 67 struct acpi_device *dev = 68 68 container_of(node, struct acpi_device, wakeup_list); 69 + 69 70 if (!dev->wakeup.flags.valid) 70 71 continue; 72 + 71 73 /* If users want to disable run-wake GPE, 72 74 * we only disable it for wake and leave it for runtime 73 75 */ 74 - if (!dev->wakeup.state.enabled || 75 - sleep_state > (u32) dev->wakeup.sleep_state) { 76 + if ((!dev->wakeup.state.enabled && !dev->wakeup.flags.prepared) 77 + || sleep_state > (u32) dev->wakeup.sleep_state) { 76 78 if (dev->wakeup.flags.run_wake) { 77 79 spin_unlock(&acpi_device_lock); 78 80 /* set_gpe_type will disable GPE, leave it like that */ ··· 112 110 113 111 if (!dev->wakeup.flags.valid) 114 112 continue; 115 - if (!dev->wakeup.state.enabled || 116 - sleep_state > (u32) dev->wakeup.sleep_state) { 113 + 114 + if ((!dev->wakeup.state.enabled && !dev->wakeup.flags.prepared) 115 + || sleep_state > (u32) dev->wakeup.sleep_state) { 117 116 if (dev->wakeup.flags.run_wake) { 118 117 spin_unlock(&acpi_device_lock); 119 118 acpi_set_gpe_type(dev->wakeup.gpe_device,
+288 -8
drivers/base/platform.c
··· 453 453 drv->driver.suspend = platform_drv_suspend; 454 454 if (drv->resume) 455 455 drv->driver.resume = platform_drv_resume; 456 + if (drv->pm) 457 + drv->driver.pm = &drv->pm->base; 456 458 return driver_register(&drv->driver); 457 459 } 458 460 EXPORT_SYMBOL_GPL(platform_driver_register); ··· 562 560 return (strncmp(pdev->name, drv->name, BUS_ID_SIZE) == 0); 563 561 } 564 562 565 - static int platform_suspend(struct device *dev, pm_message_t mesg) 563 + #ifdef CONFIG_PM_SLEEP 564 + 565 + static int platform_legacy_suspend(struct device *dev, pm_message_t mesg) 566 566 { 567 567 int ret = 0; 568 568 ··· 574 570 return ret; 575 571 } 576 572 577 - static int platform_suspend_late(struct device *dev, pm_message_t mesg) 573 + static int platform_legacy_suspend_late(struct device *dev, pm_message_t mesg) 578 574 { 579 575 struct platform_driver *drv = to_platform_driver(dev->driver); 580 576 struct platform_device *pdev; ··· 587 583 return ret; 588 584 } 589 585 590 - static int platform_resume_early(struct device *dev) 586 + static int platform_legacy_resume_early(struct device *dev) 591 587 { 592 588 struct platform_driver *drv = to_platform_driver(dev->driver); 593 589 struct platform_device *pdev; ··· 600 596 return ret; 601 597 } 602 598 603 - static int platform_resume(struct device *dev) 599 + static int platform_legacy_resume(struct device *dev) 604 600 { 605 601 int ret = 0; 606 602 ··· 610 606 return ret; 611 607 } 612 608 609 + static int platform_pm_prepare(struct device *dev) 610 + { 611 + struct device_driver *drv = dev->driver; 612 + int ret = 0; 613 + 614 + if (drv && drv->pm && drv->pm->prepare) 615 + ret = drv->pm->prepare(dev); 616 + 617 + return ret; 618 + } 619 + 620 + static void platform_pm_complete(struct device *dev) 621 + { 622 + struct device_driver *drv = dev->driver; 623 + 624 + if (drv && drv->pm && drv->pm->complete) 625 + drv->pm->complete(dev); 626 + } 627 + 628 + #ifdef CONFIG_SUSPEND 629 + 630 + static int platform_pm_suspend(struct device *dev) 631 + { 632 + struct device_driver *drv = dev->driver; 633 + int ret = 0; 634 + 635 + if (drv && drv->pm) { 636 + if (drv->pm->suspend) 637 + ret = drv->pm->suspend(dev); 638 + } else { 639 + ret = platform_legacy_suspend(dev, PMSG_SUSPEND); 640 + } 641 + 642 + return ret; 643 + } 644 + 645 + static int platform_pm_suspend_noirq(struct device *dev) 646 + { 647 + struct platform_driver *pdrv; 648 + int ret = 0; 649 + 650 + if (!dev->driver) 651 + return 0; 652 + 653 + pdrv = to_platform_driver(dev->driver); 654 + if (pdrv->pm) { 655 + if (pdrv->pm->suspend_noirq) 656 + ret = pdrv->pm->suspend_noirq(dev); 657 + } else { 658 + ret = platform_legacy_suspend_late(dev, PMSG_SUSPEND); 659 + } 660 + 661 + return ret; 662 + } 663 + 664 + static int platform_pm_resume(struct device *dev) 665 + { 666 + struct device_driver *drv = dev->driver; 667 + int ret = 0; 668 + 669 + if (drv && drv->pm) { 670 + if (drv->pm->resume) 671 + ret = drv->pm->resume(dev); 672 + } else { 673 + ret = platform_legacy_resume(dev); 674 + } 675 + 676 + return ret; 677 + } 678 + 679 + static int platform_pm_resume_noirq(struct device *dev) 680 + { 681 + struct platform_driver *pdrv; 682 + int ret = 0; 683 + 684 + if (!dev->driver) 685 + return 0; 686 + 687 + pdrv = to_platform_driver(dev->driver); 688 + if (pdrv->pm) { 689 + if (pdrv->pm->resume_noirq) 690 + ret = pdrv->pm->resume_noirq(dev); 691 + } else { 692 + ret = platform_legacy_resume_early(dev); 693 + } 694 + 695 + return ret; 696 + } 697 + 698 + #else /* !CONFIG_SUSPEND */ 699 + 700 + #define platform_pm_suspend NULL 701 + #define platform_pm_resume NULL 702 + #define platform_pm_suspend_noirq NULL 703 + #define platform_pm_resume_noirq NULL 704 + 705 + #endif /* !CONFIG_SUSPEND */ 706 + 707 + #ifdef CONFIG_HIBERNATION 708 + 709 + static int platform_pm_freeze(struct device *dev) 710 + { 711 + struct device_driver *drv = dev->driver; 712 + int ret = 0; 713 + 714 + if (!drv) 715 + return 0; 716 + 717 + if (drv->pm) { 718 + if (drv->pm->freeze) 719 + ret = drv->pm->freeze(dev); 720 + } else { 721 + ret = platform_legacy_suspend(dev, PMSG_FREEZE); 722 + } 723 + 724 + return ret; 725 + } 726 + 727 + static int platform_pm_freeze_noirq(struct device *dev) 728 + { 729 + struct platform_driver *pdrv; 730 + int ret = 0; 731 + 732 + if (!dev->driver) 733 + return 0; 734 + 735 + pdrv = to_platform_driver(dev->driver); 736 + if (pdrv->pm) { 737 + if (pdrv->pm->freeze_noirq) 738 + ret = pdrv->pm->freeze_noirq(dev); 739 + } else { 740 + ret = platform_legacy_suspend_late(dev, PMSG_FREEZE); 741 + } 742 + 743 + return ret; 744 + } 745 + 746 + static int platform_pm_thaw(struct device *dev) 747 + { 748 + struct device_driver *drv = dev->driver; 749 + int ret = 0; 750 + 751 + if (drv && drv->pm) { 752 + if (drv->pm->thaw) 753 + ret = drv->pm->thaw(dev); 754 + } else { 755 + ret = platform_legacy_resume(dev); 756 + } 757 + 758 + return ret; 759 + } 760 + 761 + static int platform_pm_thaw_noirq(struct device *dev) 762 + { 763 + struct platform_driver *pdrv; 764 + int ret = 0; 765 + 766 + if (!dev->driver) 767 + return 0; 768 + 769 + pdrv = to_platform_driver(dev->driver); 770 + if (pdrv->pm) { 771 + if (pdrv->pm->thaw_noirq) 772 + ret = pdrv->pm->thaw_noirq(dev); 773 + } else { 774 + ret = platform_legacy_resume_early(dev); 775 + } 776 + 777 + return ret; 778 + } 779 + 780 + static int platform_pm_poweroff(struct device *dev) 781 + { 782 + struct device_driver *drv = dev->driver; 783 + int ret = 0; 784 + 785 + if (drv && drv->pm) { 786 + if (drv->pm->poweroff) 787 + ret = drv->pm->poweroff(dev); 788 + } else { 789 + ret = platform_legacy_suspend(dev, PMSG_HIBERNATE); 790 + } 791 + 792 + return ret; 793 + } 794 + 795 + static int platform_pm_poweroff_noirq(struct device *dev) 796 + { 797 + struct platform_driver *pdrv; 798 + int ret = 0; 799 + 800 + if (!dev->driver) 801 + return 0; 802 + 803 + pdrv = to_platform_driver(dev->driver); 804 + if (pdrv->pm) { 805 + if (pdrv->pm->poweroff_noirq) 806 + ret = pdrv->pm->poweroff_noirq(dev); 807 + } else { 808 + ret = platform_legacy_suspend_late(dev, PMSG_HIBERNATE); 809 + } 810 + 811 + return ret; 812 + } 813 + 814 + static int platform_pm_restore(struct device *dev) 815 + { 816 + struct device_driver *drv = dev->driver; 817 + int ret = 0; 818 + 819 + if (drv && drv->pm) { 820 + if (drv->pm->restore) 821 + ret = drv->pm->restore(dev); 822 + } else { 823 + ret = platform_legacy_resume(dev); 824 + } 825 + 826 + return ret; 827 + } 828 + 829 + static int platform_pm_restore_noirq(struct device *dev) 830 + { 831 + struct platform_driver *pdrv; 832 + int ret = 0; 833 + 834 + if (!dev->driver) 835 + return 0; 836 + 837 + pdrv = to_platform_driver(dev->driver); 838 + if (pdrv->pm) { 839 + if (pdrv->pm->restore_noirq) 840 + ret = pdrv->pm->restore_noirq(dev); 841 + } else { 842 + ret = platform_legacy_resume_early(dev); 843 + } 844 + 845 + return ret; 846 + } 847 + 848 + #else /* !CONFIG_HIBERNATION */ 849 + 850 + #define platform_pm_freeze NULL 851 + #define platform_pm_thaw NULL 852 + #define platform_pm_poweroff NULL 853 + #define platform_pm_restore NULL 854 + #define platform_pm_freeze_noirq NULL 855 + #define platform_pm_thaw_noirq NULL 856 + #define platform_pm_poweroff_noirq NULL 857 + #define platform_pm_restore_noirq NULL 858 + 859 + #endif /* !CONFIG_HIBERNATION */ 860 + 861 + struct pm_ext_ops platform_pm_ops = { 862 + .base = { 863 + .prepare = platform_pm_prepare, 864 + .complete = platform_pm_complete, 865 + .suspend = platform_pm_suspend, 866 + .resume = platform_pm_resume, 867 + .freeze = platform_pm_freeze, 868 + .thaw = platform_pm_thaw, 869 + .poweroff = platform_pm_poweroff, 870 + .restore = platform_pm_restore, 871 + }, 872 + .suspend_noirq = platform_pm_suspend_noirq, 873 + .resume_noirq = platform_pm_resume_noirq, 874 + .freeze_noirq = platform_pm_freeze_noirq, 875 + .thaw_noirq = platform_pm_thaw_noirq, 876 + .poweroff_noirq = platform_pm_poweroff_noirq, 877 + .restore_noirq = platform_pm_restore_noirq, 878 + }; 879 + 880 + #define PLATFORM_PM_OPS_PTR &platform_pm_ops 881 + 882 + #else /* !CONFIG_PM_SLEEP */ 883 + 884 + #define PLATFORM_PM_OPS_PTR NULL 885 + 886 + #endif /* !CONFIG_PM_SLEEP */ 887 + 613 888 struct bus_type platform_bus_type = { 614 889 .name = "platform", 615 890 .dev_attrs = platform_dev_attrs, 616 891 .match = platform_match, 617 892 .uevent = platform_uevent, 618 - .suspend = platform_suspend, 619 - .suspend_late = platform_suspend_late, 620 - .resume_early = platform_resume_early, 621 - .resume = platform_resume, 893 + .pm = PLATFORM_PM_OPS_PTR, 622 894 }; 623 895 EXPORT_SYMBOL_GPL(platform_bus_type); 624 896
+526 -155
drivers/base/power/main.c
··· 12 12 * and add it to the list of power-controlled devices. sysfs entries for 13 13 * controlling device power management will also be added. 14 14 * 15 - * A different set of lists than the global subsystem list are used to 16 - * keep track of power info because we use different lists to hold 17 - * devices based on what stage of the power management process they 18 - * are in. The power domain dependencies may also differ from the 19 - * ancestral dependencies that the subsystem list maintains. 15 + * A separate list is used for keeping track of power info, because the power 16 + * domain dependencies may differ from the ancestral dependencies that the 17 + * subsystem list maintains. 20 18 */ 21 19 22 20 #include <linux/device.h> ··· 28 30 #include "power.h" 29 31 30 32 /* 31 - * The entries in the dpm_active list are in a depth first order, simply 33 + * The entries in the dpm_list list are in a depth first order, simply 32 34 * because children are guaranteed to be discovered after parents, and 33 35 * are inserted at the back of the list on discovery. 34 - * 35 - * All the other lists are kept in the same order, for consistency. 36 - * However the lists aren't always traversed in the same order. 37 - * Semaphores must be acquired from the top (i.e., front) down 38 - * and released in the opposite order. Devices must be suspended 39 - * from the bottom (i.e., end) up and resumed in the opposite order. 40 - * That way no parent will be suspended while it still has an active 41 - * child. 42 36 * 43 37 * Since device_pm_add() may be called with a device semaphore held, 44 38 * we must never try to acquire a device semaphore while holding 45 39 * dpm_list_mutex. 46 40 */ 47 41 48 - LIST_HEAD(dpm_active); 49 - static LIST_HEAD(dpm_off); 50 - static LIST_HEAD(dpm_off_irq); 42 + LIST_HEAD(dpm_list); 51 43 52 44 static DEFINE_MUTEX(dpm_list_mtx); 53 45 54 - /* 'true' if all devices have been suspended, protected by dpm_list_mtx */ 55 - static bool all_sleeping; 46 + /* 47 + * Set once the preparation of devices for a PM transition has started, reset 48 + * before starting to resume devices. Protected by dpm_list_mtx. 49 + */ 50 + static bool transition_started; 51 + 52 + /** 53 + * device_pm_lock - lock the list of active devices used by the PM core 54 + */ 55 + void device_pm_lock(void) 56 + { 57 + mutex_lock(&dpm_list_mtx); 58 + } 59 + 60 + /** 61 + * device_pm_unlock - unlock the list of active devices used by the PM core 62 + */ 63 + void device_pm_unlock(void) 64 + { 65 + mutex_unlock(&dpm_list_mtx); 66 + } 56 67 57 68 /** 58 69 * device_pm_add - add a device to the list of active devices ··· 75 68 dev->bus ? dev->bus->name : "No Bus", 76 69 kobject_name(&dev->kobj)); 77 70 mutex_lock(&dpm_list_mtx); 78 - if ((dev->parent && dev->parent->power.sleeping) || all_sleeping) { 79 - if (dev->parent->power.sleeping) 80 - dev_warn(dev, "parent %s is sleeping\n", 71 + if (dev->parent) { 72 + if (dev->parent->power.status >= DPM_SUSPENDING) { 73 + dev_warn(dev, "parent %s is sleeping, will not add\n", 81 74 dev->parent->bus_id); 82 - else 83 - dev_warn(dev, "all devices are sleeping\n"); 75 + WARN_ON(true); 76 + } 77 + } else if (transition_started) { 78 + /* 79 + * We refuse to register parentless devices while a PM 80 + * transition is in progress in order to avoid leaving them 81 + * unhandled down the road 82 + */ 84 83 WARN_ON(true); 85 84 } 86 85 error = dpm_sysfs_add(dev); 87 - if (!error) 88 - list_add_tail(&dev->power.entry, &dpm_active); 86 + if (!error) { 87 + dev->power.status = DPM_ON; 88 + list_add_tail(&dev->power.entry, &dpm_list); 89 + } 89 90 mutex_unlock(&dpm_list_mtx); 90 91 return error; 91 92 } ··· 115 100 mutex_unlock(&dpm_list_mtx); 116 101 } 117 102 103 + /** 104 + * pm_op - execute the PM operation appropiate for given PM event 105 + * @dev: Device. 106 + * @ops: PM operations to choose from. 107 + * @state: PM transition of the system being carried out. 108 + */ 109 + static int pm_op(struct device *dev, struct pm_ops *ops, pm_message_t state) 110 + { 111 + int error = 0; 112 + 113 + switch (state.event) { 114 + #ifdef CONFIG_SUSPEND 115 + case PM_EVENT_SUSPEND: 116 + if (ops->suspend) { 117 + error = ops->suspend(dev); 118 + suspend_report_result(ops->suspend, error); 119 + } 120 + break; 121 + case PM_EVENT_RESUME: 122 + if (ops->resume) { 123 + error = ops->resume(dev); 124 + suspend_report_result(ops->resume, error); 125 + } 126 + break; 127 + #endif /* CONFIG_SUSPEND */ 128 + #ifdef CONFIG_HIBERNATION 129 + case PM_EVENT_FREEZE: 130 + case PM_EVENT_QUIESCE: 131 + if (ops->freeze) { 132 + error = ops->freeze(dev); 133 + suspend_report_result(ops->freeze, error); 134 + } 135 + break; 136 + case PM_EVENT_HIBERNATE: 137 + if (ops->poweroff) { 138 + error = ops->poweroff(dev); 139 + suspend_report_result(ops->poweroff, error); 140 + } 141 + break; 142 + case PM_EVENT_THAW: 143 + case PM_EVENT_RECOVER: 144 + if (ops->thaw) { 145 + error = ops->thaw(dev); 146 + suspend_report_result(ops->thaw, error); 147 + } 148 + break; 149 + case PM_EVENT_RESTORE: 150 + if (ops->restore) { 151 + error = ops->restore(dev); 152 + suspend_report_result(ops->restore, error); 153 + } 154 + break; 155 + #endif /* CONFIG_HIBERNATION */ 156 + default: 157 + error = -EINVAL; 158 + } 159 + return error; 160 + } 161 + 162 + /** 163 + * pm_noirq_op - execute the PM operation appropiate for given PM event 164 + * @dev: Device. 165 + * @ops: PM operations to choose from. 166 + * @state: PM transition of the system being carried out. 167 + * 168 + * The operation is executed with interrupts disabled by the only remaining 169 + * functional CPU in the system. 170 + */ 171 + static int pm_noirq_op(struct device *dev, struct pm_ext_ops *ops, 172 + pm_message_t state) 173 + { 174 + int error = 0; 175 + 176 + switch (state.event) { 177 + #ifdef CONFIG_SUSPEND 178 + case PM_EVENT_SUSPEND: 179 + if (ops->suspend_noirq) { 180 + error = ops->suspend_noirq(dev); 181 + suspend_report_result(ops->suspend_noirq, error); 182 + } 183 + break; 184 + case PM_EVENT_RESUME: 185 + if (ops->resume_noirq) { 186 + error = ops->resume_noirq(dev); 187 + suspend_report_result(ops->resume_noirq, error); 188 + } 189 + break; 190 + #endif /* CONFIG_SUSPEND */ 191 + #ifdef CONFIG_HIBERNATION 192 + case PM_EVENT_FREEZE: 193 + case PM_EVENT_QUIESCE: 194 + if (ops->freeze_noirq) { 195 + error = ops->freeze_noirq(dev); 196 + suspend_report_result(ops->freeze_noirq, error); 197 + } 198 + break; 199 + case PM_EVENT_HIBERNATE: 200 + if (ops->poweroff_noirq) { 201 + error = ops->poweroff_noirq(dev); 202 + suspend_report_result(ops->poweroff_noirq, error); 203 + } 204 + break; 205 + case PM_EVENT_THAW: 206 + case PM_EVENT_RECOVER: 207 + if (ops->thaw_noirq) { 208 + error = ops->thaw_noirq(dev); 209 + suspend_report_result(ops->thaw_noirq, error); 210 + } 211 + break; 212 + case PM_EVENT_RESTORE: 213 + if (ops->restore_noirq) { 214 + error = ops->restore_noirq(dev); 215 + suspend_report_result(ops->restore_noirq, error); 216 + } 217 + break; 218 + #endif /* CONFIG_HIBERNATION */ 219 + default: 220 + error = -EINVAL; 221 + } 222 + return error; 223 + } 224 + 225 + static char *pm_verb(int event) 226 + { 227 + switch (event) { 228 + case PM_EVENT_SUSPEND: 229 + return "suspend"; 230 + case PM_EVENT_RESUME: 231 + return "resume"; 232 + case PM_EVENT_FREEZE: 233 + return "freeze"; 234 + case PM_EVENT_QUIESCE: 235 + return "quiesce"; 236 + case PM_EVENT_HIBERNATE: 237 + return "hibernate"; 238 + case PM_EVENT_THAW: 239 + return "thaw"; 240 + case PM_EVENT_RESTORE: 241 + return "restore"; 242 + case PM_EVENT_RECOVER: 243 + return "recover"; 244 + default: 245 + return "(unknown PM event)"; 246 + } 247 + } 248 + 249 + static void pm_dev_dbg(struct device *dev, pm_message_t state, char *info) 250 + { 251 + dev_dbg(dev, "%s%s%s\n", info, pm_verb(state.event), 252 + ((state.event & PM_EVENT_SLEEP) && device_may_wakeup(dev)) ? 253 + ", may wakeup" : ""); 254 + } 255 + 256 + static void pm_dev_err(struct device *dev, pm_message_t state, char *info, 257 + int error) 258 + { 259 + printk(KERN_ERR "PM: Device %s failed to %s%s: error %d\n", 260 + kobject_name(&dev->kobj), pm_verb(state.event), info, error); 261 + } 262 + 118 263 /*------------------------- Resume routines -------------------------*/ 119 264 120 265 /** 121 - * resume_device_early - Power on one device (early resume). 266 + * resume_device_noirq - Power on one device (early resume). 122 267 * @dev: Device. 268 + * @state: PM transition of the system being carried out. 123 269 * 124 270 * Must be called with interrupts disabled. 125 271 */ 126 - static int resume_device_early(struct device *dev) 272 + static int resume_device_noirq(struct device *dev, pm_message_t state) 127 273 { 128 274 int error = 0; 129 275 130 276 TRACE_DEVICE(dev); 131 277 TRACE_RESUME(0); 132 278 133 - if (dev->bus && dev->bus->resume_early) { 134 - dev_dbg(dev, "EARLY resume\n"); 279 + if (!dev->bus) 280 + goto End; 281 + 282 + if (dev->bus->pm) { 283 + pm_dev_dbg(dev, state, "EARLY "); 284 + error = pm_noirq_op(dev, dev->bus->pm, state); 285 + } else if (dev->bus->resume_early) { 286 + pm_dev_dbg(dev, state, "legacy EARLY "); 135 287 error = dev->bus->resume_early(dev); 136 288 } 137 - 289 + End: 138 290 TRACE_RESUME(error); 139 291 return error; 140 292 } 141 293 142 294 /** 143 295 * dpm_power_up - Power on all regular (non-sysdev) devices. 296 + * @state: PM transition of the system being carried out. 144 297 * 145 - * Walk the dpm_off_irq list and power each device up. This 146 - * is used for devices that required they be powered down with 147 - * interrupts disabled. As devices are powered on, they are moved 148 - * to the dpm_off list. 298 + * Execute the appropriate "noirq resume" callback for all devices marked 299 + * as DPM_OFF_IRQ. 149 300 * 150 301 * Must be called with interrupts disabled and only one CPU running. 151 302 */ 152 - static void dpm_power_up(void) 303 + static void dpm_power_up(pm_message_t state) 153 304 { 305 + struct device *dev; 154 306 155 - while (!list_empty(&dpm_off_irq)) { 156 - struct list_head *entry = dpm_off_irq.next; 157 - struct device *dev = to_device(entry); 307 + list_for_each_entry(dev, &dpm_list, power.entry) 308 + if (dev->power.status > DPM_OFF) { 309 + int error; 158 310 159 - list_move_tail(entry, &dpm_off); 160 - resume_device_early(dev); 161 - } 311 + dev->power.status = DPM_OFF; 312 + error = resume_device_noirq(dev, state); 313 + if (error) 314 + pm_dev_err(dev, state, " early", error); 315 + } 162 316 } 163 317 164 318 /** 165 319 * device_power_up - Turn on all devices that need special attention. 320 + * @state: PM transition of the system being carried out. 166 321 * 167 322 * Power on system devices, then devices that required we shut them down 168 323 * with interrupts disabled. 169 324 * 170 325 * Must be called with interrupts disabled. 171 326 */ 172 - void device_power_up(void) 327 + void device_power_up(pm_message_t state) 173 328 { 174 329 sysdev_resume(); 175 - dpm_power_up(); 330 + dpm_power_up(state); 176 331 } 177 332 EXPORT_SYMBOL_GPL(device_power_up); 178 333 179 334 /** 180 335 * resume_device - Restore state for one device. 181 336 * @dev: Device. 182 - * 337 + * @state: PM transition of the system being carried out. 183 338 */ 184 - static int resume_device(struct device *dev) 339 + static int resume_device(struct device *dev, pm_message_t state) 185 340 { 186 341 int error = 0; 187 342 ··· 360 175 361 176 down(&dev->sem); 362 177 363 - if (dev->bus && dev->bus->resume) { 364 - dev_dbg(dev,"resuming\n"); 365 - error = dev->bus->resume(dev); 178 + if (dev->bus) { 179 + if (dev->bus->pm) { 180 + pm_dev_dbg(dev, state, ""); 181 + error = pm_op(dev, &dev->bus->pm->base, state); 182 + } else if (dev->bus->resume) { 183 + pm_dev_dbg(dev, state, "legacy "); 184 + error = dev->bus->resume(dev); 185 + } 186 + if (error) 187 + goto End; 366 188 } 367 189 368 - if (!error && dev->type && dev->type->resume) { 369 - dev_dbg(dev,"resuming\n"); 370 - error = dev->type->resume(dev); 190 + if (dev->type) { 191 + if (dev->type->pm) { 192 + pm_dev_dbg(dev, state, "type "); 193 + error = pm_op(dev, dev->type->pm, state); 194 + } else if (dev->type->resume) { 195 + pm_dev_dbg(dev, state, "legacy type "); 196 + error = dev->type->resume(dev); 197 + } 198 + if (error) 199 + goto End; 371 200 } 372 201 373 - if (!error && dev->class && dev->class->resume) { 374 - dev_dbg(dev,"class resume\n"); 375 - error = dev->class->resume(dev); 202 + if (dev->class) { 203 + if (dev->class->pm) { 204 + pm_dev_dbg(dev, state, "class "); 205 + error = pm_op(dev, dev->class->pm, state); 206 + } else if (dev->class->resume) { 207 + pm_dev_dbg(dev, state, "legacy class "); 208 + error = dev->class->resume(dev); 209 + } 376 210 } 377 - 211 + End: 378 212 up(&dev->sem); 379 213 380 214 TRACE_RESUME(error); ··· 402 198 403 199 /** 404 200 * dpm_resume - Resume every device. 201 + * @state: PM transition of the system being carried out. 405 202 * 406 - * Resume the devices that have either not gone through 407 - * the late suspend, or that did go through it but also 408 - * went through the early resume. 409 - * 410 - * Take devices from the dpm_off_list, resume them, 411 - * and put them on the dpm_locked list. 203 + * Execute the appropriate "resume" callback for all devices the status of 204 + * which indicates that they are inactive. 412 205 */ 413 - static void dpm_resume(void) 206 + static void dpm_resume(pm_message_t state) 414 207 { 415 - mutex_lock(&dpm_list_mtx); 416 - all_sleeping = false; 417 - while(!list_empty(&dpm_off)) { 418 - struct list_head *entry = dpm_off.next; 419 - struct device *dev = to_device(entry); 208 + struct list_head list; 420 209 421 - list_move_tail(entry, &dpm_active); 422 - dev->power.sleeping = false; 423 - mutex_unlock(&dpm_list_mtx); 424 - resume_device(dev); 425 - mutex_lock(&dpm_list_mtx); 210 + INIT_LIST_HEAD(&list); 211 + mutex_lock(&dpm_list_mtx); 212 + transition_started = false; 213 + while (!list_empty(&dpm_list)) { 214 + struct device *dev = to_device(dpm_list.next); 215 + 216 + get_device(dev); 217 + if (dev->power.status >= DPM_OFF) { 218 + int error; 219 + 220 + dev->power.status = DPM_RESUMING; 221 + mutex_unlock(&dpm_list_mtx); 222 + 223 + error = resume_device(dev, state); 224 + 225 + mutex_lock(&dpm_list_mtx); 226 + if (error) 227 + pm_dev_err(dev, state, "", error); 228 + } else if (dev->power.status == DPM_SUSPENDING) { 229 + /* Allow new children of the device to be registered */ 230 + dev->power.status = DPM_RESUMING; 231 + } 232 + if (!list_empty(&dev->power.entry)) 233 + list_move_tail(&dev->power.entry, &list); 234 + put_device(dev); 426 235 } 236 + list_splice(&list, &dpm_list); 237 + mutex_unlock(&dpm_list_mtx); 238 + } 239 + 240 + /** 241 + * complete_device - Complete a PM transition for given device 242 + * @dev: Device. 243 + * @state: PM transition of the system being carried out. 244 + */ 245 + static void complete_device(struct device *dev, pm_message_t state) 246 + { 247 + down(&dev->sem); 248 + 249 + if (dev->class && dev->class->pm && dev->class->pm->complete) { 250 + pm_dev_dbg(dev, state, "completing class "); 251 + dev->class->pm->complete(dev); 252 + } 253 + 254 + if (dev->type && dev->type->pm && dev->type->pm->complete) { 255 + pm_dev_dbg(dev, state, "completing type "); 256 + dev->type->pm->complete(dev); 257 + } 258 + 259 + if (dev->bus && dev->bus->pm && dev->bus->pm->base.complete) { 260 + pm_dev_dbg(dev, state, "completing "); 261 + dev->bus->pm->base.complete(dev); 262 + } 263 + 264 + up(&dev->sem); 265 + } 266 + 267 + /** 268 + * dpm_complete - Complete a PM transition for all devices. 269 + * @state: PM transition of the system being carried out. 270 + * 271 + * Execute the ->complete() callbacks for all devices that are not marked 272 + * as DPM_ON. 273 + */ 274 + static void dpm_complete(pm_message_t state) 275 + { 276 + struct list_head list; 277 + 278 + INIT_LIST_HEAD(&list); 279 + mutex_lock(&dpm_list_mtx); 280 + while (!list_empty(&dpm_list)) { 281 + struct device *dev = to_device(dpm_list.prev); 282 + 283 + get_device(dev); 284 + if (dev->power.status > DPM_ON) { 285 + dev->power.status = DPM_ON; 286 + mutex_unlock(&dpm_list_mtx); 287 + 288 + complete_device(dev, state); 289 + 290 + mutex_lock(&dpm_list_mtx); 291 + } 292 + if (!list_empty(&dev->power.entry)) 293 + list_move(&dev->power.entry, &list); 294 + put_device(dev); 295 + } 296 + list_splice(&list, &dpm_list); 427 297 mutex_unlock(&dpm_list_mtx); 428 298 } 429 299 430 300 /** 431 301 * device_resume - Restore state of each device in system. 302 + * @state: PM transition of the system being carried out. 432 303 * 433 304 * Resume all the devices, unlock them all, and allow new 434 305 * devices to be registered once again. 435 306 */ 436 - void device_resume(void) 307 + void device_resume(pm_message_t state) 437 308 { 438 309 might_sleep(); 439 - dpm_resume(); 310 + dpm_resume(state); 311 + dpm_complete(state); 440 312 } 441 313 EXPORT_SYMBOL_GPL(device_resume); 442 314 443 315 444 316 /*------------------------- Suspend routines -------------------------*/ 445 317 446 - static inline char *suspend_verb(u32 event) 318 + /** 319 + * resume_event - return a PM message representing the resume event 320 + * corresponding to given sleep state. 321 + * @sleep_state: PM message representing a sleep state. 322 + */ 323 + static pm_message_t resume_event(pm_message_t sleep_state) 447 324 { 448 - switch (event) { 449 - case PM_EVENT_SUSPEND: return "suspend"; 450 - case PM_EVENT_FREEZE: return "freeze"; 451 - case PM_EVENT_PRETHAW: return "prethaw"; 452 - default: return "(unknown suspend event)"; 325 + switch (sleep_state.event) { 326 + case PM_EVENT_SUSPEND: 327 + return PMSG_RESUME; 328 + case PM_EVENT_FREEZE: 329 + case PM_EVENT_QUIESCE: 330 + return PMSG_RECOVER; 331 + case PM_EVENT_HIBERNATE: 332 + return PMSG_RESTORE; 453 333 } 454 - } 455 - 456 - static void 457 - suspend_device_dbg(struct device *dev, pm_message_t state, char *info) 458 - { 459 - dev_dbg(dev, "%s%s%s\n", info, suspend_verb(state.event), 460 - ((state.event == PM_EVENT_SUSPEND) && device_may_wakeup(dev)) ? 461 - ", may wakeup" : ""); 334 + return PMSG_ON; 462 335 } 463 336 464 337 /** 465 - * suspend_device_late - Shut down one device (late suspend). 338 + * suspend_device_noirq - Shut down one device (late suspend). 466 339 * @dev: Device. 467 - * @state: Power state device is entering. 340 + * @state: PM transition of the system being carried out. 468 341 * 469 342 * This is called with interrupts off and only a single CPU running. 470 343 */ 471 - static int suspend_device_late(struct device *dev, pm_message_t state) 344 + static int suspend_device_noirq(struct device *dev, pm_message_t state) 472 345 { 473 346 int error = 0; 474 347 475 - if (dev->bus && dev->bus->suspend_late) { 476 - suspend_device_dbg(dev, state, "LATE "); 348 + if (!dev->bus) 349 + return 0; 350 + 351 + if (dev->bus->pm) { 352 + pm_dev_dbg(dev, state, "LATE "); 353 + error = pm_noirq_op(dev, dev->bus->pm, state); 354 + } else if (dev->bus->suspend_late) { 355 + pm_dev_dbg(dev, state, "legacy LATE "); 477 356 error = dev->bus->suspend_late(dev, state); 478 357 suspend_report_result(dev->bus->suspend_late, error); 479 358 } ··· 565 278 566 279 /** 567 280 * device_power_down - Shut down special devices. 568 - * @state: Power state to enter. 281 + * @state: PM transition of the system being carried out. 569 282 * 570 - * Power down devices that require interrupts to be disabled 571 - * and move them from the dpm_off list to the dpm_off_irq list. 283 + * Power down devices that require interrupts to be disabled. 572 284 * Then power down system devices. 573 285 * 574 286 * Must be called with interrupts disabled and only one CPU running. 575 287 */ 576 288 int device_power_down(pm_message_t state) 577 289 { 290 + struct device *dev; 578 291 int error = 0; 579 292 580 - while (!list_empty(&dpm_off)) { 581 - struct list_head *entry = dpm_off.prev; 582 - struct device *dev = to_device(entry); 583 - 584 - error = suspend_device_late(dev, state); 293 + list_for_each_entry_reverse(dev, &dpm_list, power.entry) { 294 + error = suspend_device_noirq(dev, state); 585 295 if (error) { 586 - printk(KERN_ERR "Could not power down device %s: " 587 - "error %d\n", 588 - kobject_name(&dev->kobj), error); 296 + pm_dev_err(dev, state, " late", error); 589 297 break; 590 298 } 591 - if (!list_empty(&dev->power.entry)) 592 - list_move(&dev->power.entry, &dpm_off_irq); 299 + dev->power.status = DPM_OFF_IRQ; 593 300 } 594 - 595 301 if (!error) 596 302 error = sysdev_suspend(state); 597 303 if (error) 598 - dpm_power_up(); 304 + dpm_power_up(resume_event(state)); 599 305 return error; 600 306 } 601 307 EXPORT_SYMBOL_GPL(device_power_down); ··· 596 316 /** 597 317 * suspend_device - Save state of one device. 598 318 * @dev: Device. 599 - * @state: Power state device is entering. 319 + * @state: PM transition of the system being carried out. 600 320 */ 601 321 static int suspend_device(struct device *dev, pm_message_t state) 602 322 { ··· 604 324 605 325 down(&dev->sem); 606 326 607 - if (dev->class && dev->class->suspend) { 608 - suspend_device_dbg(dev, state, "class "); 609 - error = dev->class->suspend(dev, state); 610 - suspend_report_result(dev->class->suspend, error); 327 + if (dev->class) { 328 + if (dev->class->pm) { 329 + pm_dev_dbg(dev, state, "class "); 330 + error = pm_op(dev, dev->class->pm, state); 331 + } else if (dev->class->suspend) { 332 + pm_dev_dbg(dev, state, "legacy class "); 333 + error = dev->class->suspend(dev, state); 334 + suspend_report_result(dev->class->suspend, error); 335 + } 336 + if (error) 337 + goto End; 611 338 } 612 339 613 - if (!error && dev->type && dev->type->suspend) { 614 - suspend_device_dbg(dev, state, "type "); 615 - error = dev->type->suspend(dev, state); 616 - suspend_report_result(dev->type->suspend, error); 340 + if (dev->type) { 341 + if (dev->type->pm) { 342 + pm_dev_dbg(dev, state, "type "); 343 + error = pm_op(dev, dev->type->pm, state); 344 + } else if (dev->type->suspend) { 345 + pm_dev_dbg(dev, state, "legacy type "); 346 + error = dev->type->suspend(dev, state); 347 + suspend_report_result(dev->type->suspend, error); 348 + } 349 + if (error) 350 + goto End; 617 351 } 618 352 619 - if (!error && dev->bus && dev->bus->suspend) { 620 - suspend_device_dbg(dev, state, ""); 621 - error = dev->bus->suspend(dev, state); 622 - suspend_report_result(dev->bus->suspend, error); 353 + if (dev->bus) { 354 + if (dev->bus->pm) { 355 + pm_dev_dbg(dev, state, ""); 356 + error = pm_op(dev, &dev->bus->pm->base, state); 357 + } else if (dev->bus->suspend) { 358 + pm_dev_dbg(dev, state, "legacy "); 359 + error = dev->bus->suspend(dev, state); 360 + suspend_report_result(dev->bus->suspend, error); 361 + } 623 362 } 624 - 363 + End: 625 364 up(&dev->sem); 626 365 627 366 return error; ··· 648 349 649 350 /** 650 351 * dpm_suspend - Suspend every device. 651 - * @state: Power state to put each device in. 352 + * @state: PM transition of the system being carried out. 652 353 * 653 - * Walk the dpm_locked list. Suspend each device and move it 654 - * to the dpm_off list. 655 - * 656 - * (For historical reasons, if it returns -EAGAIN, that used to mean 657 - * that the device would be called again with interrupts disabled. 658 - * These days, we use the "suspend_late()" callback for that, so we 659 - * print a warning and consider it an error). 354 + * Execute the appropriate "suspend" callbacks for all devices. 660 355 */ 661 356 static int dpm_suspend(pm_message_t state) 662 357 { 358 + struct list_head list; 663 359 int error = 0; 664 360 361 + INIT_LIST_HEAD(&list); 665 362 mutex_lock(&dpm_list_mtx); 666 - while (!list_empty(&dpm_active)) { 667 - struct list_head *entry = dpm_active.prev; 668 - struct device *dev = to_device(entry); 363 + while (!list_empty(&dpm_list)) { 364 + struct device *dev = to_device(dpm_list.prev); 669 365 670 - WARN_ON(dev->parent && dev->parent->power.sleeping); 671 - 672 - dev->power.sleeping = true; 366 + get_device(dev); 673 367 mutex_unlock(&dpm_list_mtx); 368 + 674 369 error = suspend_device(dev, state); 370 + 675 371 mutex_lock(&dpm_list_mtx); 676 372 if (error) { 677 - printk(KERN_ERR "Could not suspend device %s: " 678 - "error %d%s\n", 679 - kobject_name(&dev->kobj), 680 - error, 681 - (error == -EAGAIN ? 682 - " (please convert to suspend_late)" : 683 - "")); 684 - dev->power.sleeping = false; 373 + pm_dev_err(dev, state, "", error); 374 + put_device(dev); 685 375 break; 686 376 } 377 + dev->power.status = DPM_OFF; 687 378 if (!list_empty(&dev->power.entry)) 688 - list_move(&dev->power.entry, &dpm_off); 379 + list_move(&dev->power.entry, &list); 380 + put_device(dev); 689 381 } 690 - if (!error) 691 - all_sleeping = true; 382 + list_splice(&list, dpm_list.prev); 692 383 mutex_unlock(&dpm_list_mtx); 384 + return error; 385 + } 386 + 387 + /** 388 + * prepare_device - Execute the ->prepare() callback(s) for given device. 389 + * @dev: Device. 390 + * @state: PM transition of the system being carried out. 391 + */ 392 + static int prepare_device(struct device *dev, pm_message_t state) 393 + { 394 + int error = 0; 395 + 396 + down(&dev->sem); 397 + 398 + if (dev->bus && dev->bus->pm && dev->bus->pm->base.prepare) { 399 + pm_dev_dbg(dev, state, "preparing "); 400 + error = dev->bus->pm->base.prepare(dev); 401 + suspend_report_result(dev->bus->pm->base.prepare, error); 402 + if (error) 403 + goto End; 404 + } 405 + 406 + if (dev->type && dev->type->pm && dev->type->pm->prepare) { 407 + pm_dev_dbg(dev, state, "preparing type "); 408 + error = dev->type->pm->prepare(dev); 409 + suspend_report_result(dev->type->pm->prepare, error); 410 + if (error) 411 + goto End; 412 + } 413 + 414 + if (dev->class && dev->class->pm && dev->class->pm->prepare) { 415 + pm_dev_dbg(dev, state, "preparing class "); 416 + error = dev->class->pm->prepare(dev); 417 + suspend_report_result(dev->class->pm->prepare, error); 418 + } 419 + End: 420 + up(&dev->sem); 693 421 694 422 return error; 695 423 } 696 424 697 425 /** 698 - * device_suspend - Save state and stop all devices in system. 699 - * @state: new power management state 426 + * dpm_prepare - Prepare all devices for a PM transition. 427 + * @state: PM transition of the system being carried out. 700 428 * 701 - * Prevent new devices from being registered, then lock all devices 702 - * and suspend them. 429 + * Execute the ->prepare() callback for all devices. 430 + */ 431 + static int dpm_prepare(pm_message_t state) 432 + { 433 + struct list_head list; 434 + int error = 0; 435 + 436 + INIT_LIST_HEAD(&list); 437 + mutex_lock(&dpm_list_mtx); 438 + transition_started = true; 439 + while (!list_empty(&dpm_list)) { 440 + struct device *dev = to_device(dpm_list.next); 441 + 442 + get_device(dev); 443 + dev->power.status = DPM_PREPARING; 444 + mutex_unlock(&dpm_list_mtx); 445 + 446 + error = prepare_device(dev, state); 447 + 448 + mutex_lock(&dpm_list_mtx); 449 + if (error) { 450 + dev->power.status = DPM_ON; 451 + if (error == -EAGAIN) { 452 + put_device(dev); 453 + continue; 454 + } 455 + printk(KERN_ERR "PM: Failed to prepare device %s " 456 + "for power transition: error %d\n", 457 + kobject_name(&dev->kobj), error); 458 + put_device(dev); 459 + break; 460 + } 461 + dev->power.status = DPM_SUSPENDING; 462 + if (!list_empty(&dev->power.entry)) 463 + list_move_tail(&dev->power.entry, &list); 464 + put_device(dev); 465 + } 466 + list_splice(&list, &dpm_list); 467 + mutex_unlock(&dpm_list_mtx); 468 + return error; 469 + } 470 + 471 + /** 472 + * device_suspend - Save state and stop all devices in system. 473 + * @state: PM transition of the system being carried out. 474 + * 475 + * Prepare and suspend all devices. 703 476 */ 704 477 int device_suspend(pm_message_t state) 705 478 { 706 479 int error; 707 480 708 481 might_sleep(); 709 - error = dpm_suspend(state); 710 - if (error) 711 - device_resume(); 482 + error = dpm_prepare(state); 483 + if (!error) 484 + error = dpm_suspend(state); 712 485 return error; 713 486 } 714 487 EXPORT_SYMBOL_GPL(device_suspend);
+1 -1
drivers/base/power/power.h
··· 4 4 * main.c 5 5 */ 6 6 7 - extern struct list_head dpm_active; /* The active device list */ 7 + extern struct list_head dpm_list; /* The active device list */ 8 8 9 9 static inline struct device *to_device(struct list_head *entry) 10 10 {
-3
drivers/base/power/sysfs.c
··· 6 6 #include <linux/string.h> 7 7 #include "power.h" 8 8 9 - int (*platform_enable_wakeup)(struct device *dev, int is_on); 10 - 11 - 12 9 /* 13 10 * wakeup - Report/change current wakeup option for device 14 11 *
+2 -2
drivers/base/power/trace.c
··· 188 188 static int show_dev_hash(unsigned int value) 189 189 { 190 190 int match = 0; 191 - struct list_head * entry = dpm_active.prev; 191 + struct list_head *entry = dpm_list.prev; 192 192 193 - while (entry != &dpm_active) { 193 + while (entry != &dpm_list) { 194 194 struct device * dev = to_device(entry); 195 195 unsigned int hash = hash_string(DEVSEED, dev->bus_id, DEVHASH); 196 196 if (hash == value) {
+1 -1
drivers/pci/Makefile
··· 2 2 # Makefile for the PCI bus specific drivers. 3 3 # 4 4 5 - obj-y += access.o bus.o probe.o remove.o pci.o quirks.o \ 5 + obj-y += access.o bus.o probe.o remove.o pci.o quirks.o slot.o \ 6 6 pci-driver.o search.o pci-sysfs.o rom.o setup-res.o 7 7 obj-$(CONFIG_PROC_FS) += proc.o 8 8
+81 -4
drivers/pci/hotplug/acpi_pcihp.c
··· 30 30 #include <linux/types.h> 31 31 #include <linux/pci.h> 32 32 #include <linux/pci_hotplug.h> 33 + #include <linux/pci-acpi.h> 33 34 #include <acpi/acpi.h> 34 35 #include <acpi/acpi_bus.h> 35 36 #include <acpi/actypes.h> ··· 300 299 * 301 300 * @handle - the handle of the hotplug controller. 302 301 */ 303 - acpi_status acpi_run_oshp(acpi_handle handle) 302 + static acpi_status acpi_run_oshp(acpi_handle handle) 304 303 { 305 304 acpi_status status; 306 305 struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL }; ··· 323 322 kfree(string.pointer); 324 323 return status; 325 324 } 326 - EXPORT_SYMBOL_GPL(acpi_run_oshp); 327 - 328 - 329 325 330 326 /* acpi_get_hp_params_from_firmware 331 327 * ··· 372 374 } 373 375 EXPORT_SYMBOL_GPL(acpi_get_hp_params_from_firmware); 374 376 377 + /** 378 + * acpi_get_hp_hw_control_from_firmware 379 + * @dev: the pci_dev of the bridge that has a hotplug controller 380 + * @flags: requested control bits for _OSC 381 + * 382 + * Attempt to take hotplug control from firmware. 383 + */ 384 + int acpi_get_hp_hw_control_from_firmware(struct pci_dev *dev, u32 flags) 385 + { 386 + acpi_status status; 387 + acpi_handle chandle, handle = DEVICE_ACPI_HANDLE(&(dev->dev)); 388 + struct pci_dev *pdev = dev; 389 + struct pci_bus *parent; 390 + struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL }; 391 + 392 + flags &= (OSC_PCI_EXPRESS_NATIVE_HP_CONTROL | 393 + OSC_SHPC_NATIVE_HP_CONTROL | 394 + OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL); 395 + if (!flags) { 396 + err("Invalid flags %u specified!\n", flags); 397 + return -EINVAL; 398 + } 399 + 400 + /* 401 + * Per PCI firmware specification, we should run the ACPI _OSC 402 + * method to get control of hotplug hardware before using it. If 403 + * an _OSC is missing, we look for an OSHP to do the same thing. 404 + * To handle different BIOS behavior, we look for _OSC and OSHP 405 + * within the scope of the hotplug controller and its parents, 406 + * upto the host bridge under which this controller exists. 407 + */ 408 + while (!handle) { 409 + /* 410 + * This hotplug controller was not listed in the ACPI name 411 + * space at all. Try to get acpi handle of parent pci bus. 412 + */ 413 + if (!pdev || !pdev->bus->parent) 414 + break; 415 + parent = pdev->bus->parent; 416 + dbg("Could not find %s in acpi namespace, trying parent\n", 417 + pci_name(pdev)); 418 + if (!parent->self) 419 + /* Parent must be a host bridge */ 420 + handle = acpi_get_pci_rootbridge_handle( 421 + pci_domain_nr(parent), 422 + parent->number); 423 + else 424 + handle = DEVICE_ACPI_HANDLE(&(parent->self->dev)); 425 + pdev = parent->self; 426 + } 427 + 428 + while (handle) { 429 + acpi_get_name(handle, ACPI_FULL_PATHNAME, &string); 430 + dbg("Trying to get hotplug control for %s \n", 431 + (char *)string.pointer); 432 + status = pci_osc_control_set(handle, flags); 433 + if (status == AE_NOT_FOUND) 434 + status = acpi_run_oshp(handle); 435 + if (ACPI_SUCCESS(status)) { 436 + dbg("Gained control for hotplug HW for pci %s (%s)\n", 437 + pci_name(dev), (char *)string.pointer); 438 + kfree(string.pointer); 439 + return 0; 440 + } 441 + if (acpi_root_bridge(handle)) 442 + break; 443 + chandle = handle; 444 + status = acpi_get_parent(chandle, &handle); 445 + if (ACPI_FAILURE(status)) 446 + break; 447 + } 448 + 449 + dbg("Cannot get control of hotplug hardware for pci %s\n", 450 + pci_name(dev)); 451 + 452 + kfree(string.pointer); 453 + return -ENODEV; 454 + } 455 + EXPORT_SYMBOL(acpi_get_hp_hw_control_from_firmware); 375 456 376 457 /* acpi_root_bridge - check to see if this acpi object is a root bridge 377 458 *
-1
drivers/pci/hotplug/acpiphp.h
··· 215 215 extern u8 acpiphp_get_attention_status (struct acpiphp_slot *slot); 216 216 extern u8 acpiphp_get_latch_status (struct acpiphp_slot *slot); 217 217 extern u8 acpiphp_get_adapter_status (struct acpiphp_slot *slot); 218 - extern u32 acpiphp_get_address (struct acpiphp_slot *slot); 219 218 220 219 /* variables */ 221 220 extern int acpiphp_debug;
+5 -20
drivers/pci/hotplug/acpiphp_core.c
··· 70 70 static int set_attention_status (struct hotplug_slot *slot, u8 value); 71 71 static int get_power_status (struct hotplug_slot *slot, u8 *value); 72 72 static int get_attention_status (struct hotplug_slot *slot, u8 *value); 73 - static int get_address (struct hotplug_slot *slot, u32 *value); 74 73 static int get_latch_status (struct hotplug_slot *slot, u8 *value); 75 74 static int get_adapter_status (struct hotplug_slot *slot, u8 *value); 76 75 ··· 82 83 .get_attention_status = get_attention_status, 83 84 .get_latch_status = get_latch_status, 84 85 .get_adapter_status = get_adapter_status, 85 - .get_address = get_address, 86 86 }; 87 87 88 88 ··· 272 274 return 0; 273 275 } 274 276 275 - 276 - /** 277 - * get_address - get pci address of a slot 278 - * @hotplug_slot: slot to get status 279 - * @value: pointer to struct pci_busdev (seg, bus, dev) 280 - */ 281 - static int get_address(struct hotplug_slot *hotplug_slot, u32 *value) 282 - { 283 - struct slot *slot = hotplug_slot->private; 284 - 285 - dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name); 286 - 287 - *value = acpiphp_get_address(slot->acpi_slot); 288 - 289 - return 0; 290 - } 291 - 292 277 static int __init init_acpi(void) 293 278 { 294 279 int retval; ··· 338 357 acpiphp_slot->slot = slot; 339 358 snprintf(slot->name, sizeof(slot->name), "%u", slot->acpi_slot->sun); 340 359 341 - retval = pci_hp_register(slot->hotplug_slot); 360 + retval = pci_hp_register(slot->hotplug_slot, 361 + acpiphp_slot->bridge->pci_bus, 362 + acpiphp_slot->device); 363 + if (retval == -EBUSY) 364 + goto error_hpslot; 342 365 if (retval) { 343 366 err("pci_hp_register failed with error %d\n", retval); 344 367 goto error_hpslot;
+6 -17
drivers/pci/hotplug/acpiphp_glue.c
··· 258 258 bridge->pci_bus->number, slot->device); 259 259 retval = acpiphp_register_hotplug_slot(slot); 260 260 if (retval) { 261 - warn("acpiphp_register_hotplug_slot failed(err code = 0x%x)\n", retval); 261 + if (retval == -EBUSY) 262 + warn("Slot %d already registered by another " 263 + "hotplug driver\n", slot->sun); 264 + else 265 + warn("acpiphp_register_hotplug_slot failed " 266 + "(err code = 0x%x)\n", retval); 262 267 goto err_exit; 263 268 } 264 269 } ··· 1882 1877 sta = get_slot_status(slot); 1883 1878 1884 1879 return (sta == 0) ? 0 : 1; 1885 - } 1886 - 1887 - 1888 - /* 1889 - * pci address (seg/bus/dev) 1890 - */ 1891 - u32 acpiphp_get_address(struct acpiphp_slot *slot) 1892 - { 1893 - u32 address; 1894 - struct pci_bus *pci_bus = slot->bridge->pci_bus; 1895 - 1896 - address = (pci_domain_nr(pci_bus) << 16) | 1897 - (pci_bus->number << 8) | 1898 - slot->device; 1899 - 1900 - return address; 1901 1880 }
+4 -2
drivers/pci/hotplug/acpiphp_ibm.c
··· 33 33 #include <linux/kobject.h> 34 34 #include <asm/uaccess.h> 35 35 #include <linux/moduleparam.h> 36 + #include <linux/pci.h> 36 37 37 38 #include "acpiphp.h" 39 + #include "../pci.h" 38 40 39 41 #define DRIVER_VERSION "1.0.1" 40 42 #define DRIVER_AUTHOR "Irene Zubarev <zubarev@us.ibm.com>, Vernon Mauery <vernux@us.ibm.com>" ··· 432 430 int retval = 0; 433 431 acpi_status status; 434 432 struct acpi_device *device; 435 - struct kobject *sysdir = &pci_hotplug_slots_kset->kobj; 433 + struct kobject *sysdir = &pci_slots_kset->kobj; 436 434 437 435 dbg("%s\n", __func__); 438 436 ··· 479 477 static void __exit ibm_acpiphp_exit(void) 480 478 { 481 479 acpi_status status; 482 - struct kobject *sysdir = &pci_hotplug_slots_kset->kobj; 480 + struct kobject *sysdir = &pci_slots_kset->kobj; 483 481 484 482 dbg("%s\n", __func__); 485 483
+1 -1
drivers/pci/hotplug/cpci_hotplug_core.c
··· 285 285 info->attention_status = cpci_get_attention_status(slot); 286 286 287 287 dbg("registering slot %s", slot->hotplug_slot->name); 288 - status = pci_hp_register(slot->hotplug_slot); 288 + status = pci_hp_register(slot->hotplug_slot, bus, i); 289 289 if (status) { 290 290 err("pci_hp_register failed with error %d", status); 291 291 goto error_name;
+3 -1
drivers/pci/hotplug/cpqphp_core.c
··· 434 434 slot->bus, slot->device, 435 435 slot->number, ctrl->slot_device_offset, 436 436 slot_number); 437 - result = pci_hp_register(hotplug_slot); 437 + result = pci_hp_register(hotplug_slot, 438 + ctrl->pci_dev->subordinate, 439 + slot->device); 438 440 if (result) { 439 441 err("pci_hp_register failed with error %d\n", result); 440 442 goto error_name;
+32 -58
drivers/pci/hotplug/fakephp.c
··· 66 66 struct pci_dev *dev; 67 67 struct work_struct remove_work; 68 68 unsigned long removed; 69 + char name[8]; 69 70 }; 70 71 71 72 static int debug; ··· 101 100 struct dummy_slot *dslot; 102 101 struct hotplug_slot *slot; 103 102 int retval = -ENOMEM; 103 + static int count = 1; 104 104 105 105 slot = kzalloc(sizeof(struct hotplug_slot), GFP_KERNEL); 106 106 if (!slot) ··· 115 113 slot->info->max_bus_speed = PCI_SPEED_UNKNOWN; 116 114 slot->info->cur_bus_speed = PCI_SPEED_UNKNOWN; 117 115 118 - slot->name = &dev->dev.bus_id[0]; 119 - dbg("slot->name = %s\n", slot->name); 120 - 121 116 dslot = kzalloc(sizeof(struct dummy_slot), GFP_KERNEL); 122 117 if (!dslot) 123 118 goto error_info; 124 119 120 + slot->name = dslot->name; 121 + snprintf(slot->name, sizeof(dslot->name), "fake%d", count++); 122 + dbg("slot->name = %s\n", slot->name); 125 123 slot->ops = &dummy_hotplug_slot_ops; 126 124 slot->release = &dummy_release; 127 125 slot->private = dslot; 128 126 129 - retval = pci_hp_register(slot); 127 + retval = pci_hp_register(slot, dev->bus, PCI_SLOT(dev->devfn)); 130 128 if (retval) { 131 129 err("pci_hp_register failed with error %d\n", retval); 132 130 goto error_dslot; ··· 150 148 static int __init pci_scan_buses(void) 151 149 { 152 150 struct pci_dev *dev = NULL; 153 - int retval = 0; 151 + int lastslot = 0; 154 152 155 153 while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) { 156 - retval = add_slot(dev); 157 - if (retval) { 158 - pci_dev_put(dev); 159 - break; 160 - } 154 + if (PCI_FUNC(dev->devfn) > 0 && 155 + lastslot == PCI_SLOT(dev->devfn)) 156 + continue; 157 + lastslot = PCI_SLOT(dev->devfn); 158 + add_slot(dev); 161 159 } 162 160 163 - return retval; 161 + return 0; 164 162 } 165 163 166 164 static void remove_slot(struct dummy_slot *dslot) ··· 298 296 return 0; 299 297 } 300 298 301 - /* find the hotplug_slot for the pci_dev */ 302 - static struct hotplug_slot *get_slot_from_dev(struct pci_dev *dev) 303 - { 304 - struct dummy_slot *dslot; 305 - 306 - list_for_each_entry(dslot, &slot_list, node) { 307 - if (dslot->dev == dev) 308 - return dslot->slot; 309 - } 310 - return NULL; 311 - } 312 - 313 - 314 299 static int disable_slot(struct hotplug_slot *slot) 315 300 { 316 301 struct dummy_slot *dslot; 317 - struct hotplug_slot *hslot; 318 302 struct pci_dev *dev; 319 303 int func; 320 304 ··· 310 322 311 323 dbg("%s - physical_slot = %s\n", __func__, slot->name); 312 324 313 - /* don't disable bridged devices just yet, we can't handle them easily... */ 314 - if (dslot->dev->subordinate) { 315 - err("Can't remove PCI devices with other PCI devices behind it yet.\n"); 316 - return -ENODEV; 317 - } 318 - if (test_and_set_bit(0, &dslot->removed)) { 319 - dbg("Slot already scheduled for removal\n"); 320 - return -ENODEV; 321 - } 322 - /* search for subfunctions and disable them first */ 323 - if (!(dslot->dev->devfn & 7)) { 324 - for (func = 1; func < 8; func++) { 325 - dev = pci_get_slot(dslot->dev->bus, 326 - dslot->dev->devfn + func); 327 - if (dev) { 328 - hslot = get_slot_from_dev(dev); 329 - if (hslot) 330 - disable_slot(hslot); 331 - else { 332 - err("Hotplug slot not found for subfunction of PCI device\n"); 333 - return -ENODEV; 334 - } 335 - pci_dev_put(dev); 336 - } else 337 - dbg("No device in slot found\n"); 325 + for (func = 7; func >= 0; func--) { 326 + dev = pci_get_slot(dslot->dev->bus, dslot->dev->devfn + func); 327 + if (!dev) 328 + continue; 329 + 330 + if (test_and_set_bit(0, &dslot->removed)) { 331 + dbg("Slot already scheduled for removal\n"); 332 + return -ENODEV; 338 333 } 334 + 335 + /* queue work item to blow away this sysfs entry and other 336 + * parts. 337 + */ 338 + INIT_WORK(&dslot->remove_work, remove_slot_worker); 339 + queue_work(dummyphp_wq, &dslot->remove_work); 340 + 341 + /* blow away this sysfs entry and other parts. */ 342 + remove_slot(dslot); 343 + 344 + pci_dev_put(dev); 339 345 } 340 - 341 - /* remove the device from the pci core */ 342 - pci_remove_bus_device(dslot->dev); 343 - 344 - /* queue work item to blow away this sysfs entry and other parts. */ 345 - INIT_WORK(&dslot->remove_work, remove_slot_worker); 346 - queue_work(dummyphp_wq, &dslot->remove_work); 347 - 348 346 return 0; 349 347 } 350 348
+2 -1
drivers/pci/hotplug/ibmphp_ebda.c
··· 1001 1001 tmp_slot = list_entry (list, struct slot, ibm_slot_list); 1002 1002 1003 1003 snprintf (tmp_slot->hotplug_slot->name, 30, "%s", create_file_name (tmp_slot)); 1004 - pci_hp_register (tmp_slot->hotplug_slot); 1004 + pci_hp_register(tmp_slot->hotplug_slot, 1005 + pci_find_bus(0, tmp_slot->bus), tmp_slot->device); 1005 1006 } 1006 1007 1007 1008 print_ebda_hpc ();
+120 -164
drivers/pci/hotplug/pci_hotplug_core.c
··· 40 40 #include <linux/pci.h> 41 41 #include <linux/pci_hotplug.h> 42 42 #include <asm/uaccess.h> 43 + #include "../pci.h" 43 44 44 45 #define MY_NAME "pci_hotplug" 45 46 ··· 61 60 ////////////////////////////////////////////////////////////////// 62 61 63 62 static LIST_HEAD(pci_hotplug_slot_list); 64 - 65 - struct kset *pci_hotplug_slots_kset; 66 - 67 - static ssize_t hotplug_slot_attr_show(struct kobject *kobj, 68 - struct attribute *attr, char *buf) 69 - { 70 - struct hotplug_slot *slot = to_hotplug_slot(kobj); 71 - struct hotplug_slot_attribute *attribute = to_hotplug_attr(attr); 72 - return attribute->show ? attribute->show(slot, buf) : -EIO; 73 - } 74 - 75 - static ssize_t hotplug_slot_attr_store(struct kobject *kobj, 76 - struct attribute *attr, const char *buf, size_t len) 77 - { 78 - struct hotplug_slot *slot = to_hotplug_slot(kobj); 79 - struct hotplug_slot_attribute *attribute = to_hotplug_attr(attr); 80 - return attribute->store ? attribute->store(slot, buf, len) : -EIO; 81 - } 82 - 83 - static struct sysfs_ops hotplug_slot_sysfs_ops = { 84 - .show = hotplug_slot_attr_show, 85 - .store = hotplug_slot_attr_store, 86 - }; 87 - 88 - static void hotplug_slot_release(struct kobject *kobj) 89 - { 90 - struct hotplug_slot *slot = to_hotplug_slot(kobj); 91 - if (slot->release) 92 - slot->release(slot); 93 - } 94 - 95 - static struct kobj_type hotplug_slot_ktype = { 96 - .sysfs_ops = &hotplug_slot_sysfs_ops, 97 - .release = &hotplug_slot_release, 98 - }; 63 + static DEFINE_SPINLOCK(pci_hotplug_slot_list_lock); 99 64 100 65 /* these strings match up with the values in pci_bus_speed */ 101 66 static char *pci_bus_speed_strings[] = { ··· 116 149 GET_STATUS(attention_status, u8) 117 150 GET_STATUS(latch_status, u8) 118 151 GET_STATUS(adapter_status, u8) 119 - GET_STATUS(address, u32) 120 152 GET_STATUS(max_bus_speed, enum pci_bus_speed) 121 153 GET_STATUS(cur_bus_speed, enum pci_bus_speed) 122 154 123 - static ssize_t power_read_file (struct hotplug_slot *slot, char *buf) 155 + static ssize_t power_read_file(struct pci_slot *slot, char *buf) 124 156 { 125 157 int retval; 126 158 u8 value; 127 159 128 - retval = get_power_status (slot, &value); 160 + retval = get_power_status(slot->hotplug, &value); 129 161 if (retval) 130 162 goto exit; 131 163 retval = sprintf (buf, "%d\n", value); ··· 132 166 return retval; 133 167 } 134 168 135 - static ssize_t power_write_file (struct hotplug_slot *slot, const char *buf, 169 + static ssize_t power_write_file(struct pci_slot *pci_slot, const char *buf, 136 170 size_t count) 137 171 { 172 + struct hotplug_slot *slot = pci_slot->hotplug; 138 173 unsigned long lpower; 139 174 u8 power; 140 175 int retval = 0; ··· 171 204 return count; 172 205 } 173 206 174 - static struct hotplug_slot_attribute hotplug_slot_attr_power = { 207 + static struct pci_slot_attribute hotplug_slot_attr_power = { 175 208 .attr = {.name = "power", .mode = S_IFREG | S_IRUGO | S_IWUSR}, 176 209 .show = power_read_file, 177 210 .store = power_write_file 178 211 }; 179 212 180 - static ssize_t attention_read_file (struct hotplug_slot *slot, char *buf) 213 + static ssize_t attention_read_file(struct pci_slot *slot, char *buf) 181 214 { 182 215 int retval; 183 216 u8 value; 184 217 185 - retval = get_attention_status (slot, &value); 218 + retval = get_attention_status(slot->hotplug, &value); 186 219 if (retval) 187 220 goto exit; 188 - retval = sprintf (buf, "%d\n", value); 221 + retval = sprintf(buf, "%d\n", value); 189 222 190 223 exit: 191 224 return retval; 192 225 } 193 226 194 - static ssize_t attention_write_file (struct hotplug_slot *slot, const char *buf, 227 + static ssize_t attention_write_file(struct pci_slot *slot, const char *buf, 195 228 size_t count) 196 229 { 230 + struct hotplug_slot_ops *ops = slot->hotplug->ops; 197 231 unsigned long lattention; 198 232 u8 attention; 199 233 int retval = 0; ··· 203 235 attention = (u8)(lattention & 0xff); 204 236 dbg (" - attention = %d\n", attention); 205 237 206 - if (!try_module_get(slot->ops->owner)) { 238 + if (!try_module_get(ops->owner)) { 207 239 retval = -ENODEV; 208 240 goto exit; 209 241 } 210 - if (slot->ops->set_attention_status) 211 - retval = slot->ops->set_attention_status(slot, attention); 212 - module_put(slot->ops->owner); 242 + if (ops->set_attention_status) 243 + retval = ops->set_attention_status(slot->hotplug, attention); 244 + module_put(ops->owner); 213 245 214 246 exit: 215 247 if (retval) ··· 217 249 return count; 218 250 } 219 251 220 - static struct hotplug_slot_attribute hotplug_slot_attr_attention = { 252 + static struct pci_slot_attribute hotplug_slot_attr_attention = { 221 253 .attr = {.name = "attention", .mode = S_IFREG | S_IRUGO | S_IWUSR}, 222 254 .show = attention_read_file, 223 255 .store = attention_write_file 224 256 }; 225 257 226 - static ssize_t latch_read_file (struct hotplug_slot *slot, char *buf) 258 + static ssize_t latch_read_file(struct pci_slot *slot, char *buf) 227 259 { 228 260 int retval; 229 261 u8 value; 230 262 231 - retval = get_latch_status (slot, &value); 263 + retval = get_latch_status(slot->hotplug, &value); 232 264 if (retval) 233 265 goto exit; 234 266 retval = sprintf (buf, "%d\n", value); ··· 237 269 return retval; 238 270 } 239 271 240 - static struct hotplug_slot_attribute hotplug_slot_attr_latch = { 272 + static struct pci_slot_attribute hotplug_slot_attr_latch = { 241 273 .attr = {.name = "latch", .mode = S_IFREG | S_IRUGO}, 242 274 .show = latch_read_file, 243 275 }; 244 276 245 - static ssize_t presence_read_file (struct hotplug_slot *slot, char *buf) 277 + static ssize_t presence_read_file(struct pci_slot *slot, char *buf) 246 278 { 247 279 int retval; 248 280 u8 value; 249 281 250 - retval = get_adapter_status (slot, &value); 282 + retval = get_adapter_status(slot->hotplug, &value); 251 283 if (retval) 252 284 goto exit; 253 285 retval = sprintf (buf, "%d\n", value); ··· 256 288 return retval; 257 289 } 258 290 259 - static struct hotplug_slot_attribute hotplug_slot_attr_presence = { 291 + static struct pci_slot_attribute hotplug_slot_attr_presence = { 260 292 .attr = {.name = "adapter", .mode = S_IFREG | S_IRUGO}, 261 293 .show = presence_read_file, 262 294 }; 263 295 264 - static ssize_t address_read_file (struct hotplug_slot *slot, char *buf) 265 - { 266 - int retval; 267 - u32 address; 268 - 269 - retval = get_address (slot, &address); 270 - if (retval) 271 - goto exit; 272 - retval = sprintf (buf, "%04x:%02x:%02x\n", 273 - (address >> 16) & 0xffff, 274 - (address >> 8) & 0xff, 275 - address & 0xff); 276 - 277 - exit: 278 - return retval; 279 - } 280 - 281 - static struct hotplug_slot_attribute hotplug_slot_attr_address = { 282 - .attr = {.name = "address", .mode = S_IFREG | S_IRUGO}, 283 - .show = address_read_file, 284 - }; 285 - 286 296 static char *unknown_speed = "Unknown bus speed"; 287 297 288 - static ssize_t max_bus_speed_read_file (struct hotplug_slot *slot, char *buf) 298 + static ssize_t max_bus_speed_read_file(struct pci_slot *slot, char *buf) 289 299 { 290 300 char *speed_string; 291 301 int retval; 292 302 enum pci_bus_speed value; 293 303 294 - retval = get_max_bus_speed (slot, &value); 304 + retval = get_max_bus_speed(slot->hotplug, &value); 295 305 if (retval) 296 306 goto exit; 297 307 ··· 284 338 return retval; 285 339 } 286 340 287 - static struct hotplug_slot_attribute hotplug_slot_attr_max_bus_speed = { 341 + static struct pci_slot_attribute hotplug_slot_attr_max_bus_speed = { 288 342 .attr = {.name = "max_bus_speed", .mode = S_IFREG | S_IRUGO}, 289 343 .show = max_bus_speed_read_file, 290 344 }; 291 345 292 - static ssize_t cur_bus_speed_read_file (struct hotplug_slot *slot, char *buf) 346 + static ssize_t cur_bus_speed_read_file(struct pci_slot *slot, char *buf) 293 347 { 294 348 char *speed_string; 295 349 int retval; 296 350 enum pci_bus_speed value; 297 351 298 - retval = get_cur_bus_speed (slot, &value); 352 + retval = get_cur_bus_speed(slot->hotplug, &value); 299 353 if (retval) 300 354 goto exit; 301 355 ··· 310 364 return retval; 311 365 } 312 366 313 - static struct hotplug_slot_attribute hotplug_slot_attr_cur_bus_speed = { 367 + static struct pci_slot_attribute hotplug_slot_attr_cur_bus_speed = { 314 368 .attr = {.name = "cur_bus_speed", .mode = S_IFREG | S_IRUGO}, 315 369 .show = cur_bus_speed_read_file, 316 370 }; 317 371 318 - static ssize_t test_write_file (struct hotplug_slot *slot, const char *buf, 372 + static ssize_t test_write_file(struct pci_slot *pci_slot, const char *buf, 319 373 size_t count) 320 374 { 375 + struct hotplug_slot *slot = pci_slot->hotplug; 321 376 unsigned long ltest; 322 377 u32 test; 323 378 int retval = 0; ··· 341 394 return count; 342 395 } 343 396 344 - static struct hotplug_slot_attribute hotplug_slot_attr_test = { 397 + static struct pci_slot_attribute hotplug_slot_attr_test = { 345 398 .attr = {.name = "test", .mode = S_IFREG | S_IRUGO | S_IWUSR}, 346 399 .store = test_write_file 347 400 }; 348 401 349 - static int has_power_file (struct hotplug_slot *slot) 402 + static int has_power_file(struct pci_slot *pci_slot) 350 403 { 404 + struct hotplug_slot *slot = pci_slot->hotplug; 351 405 if ((!slot) || (!slot->ops)) 352 406 return -ENODEV; 353 407 if ((slot->ops->enable_slot) || ··· 358 410 return -ENOENT; 359 411 } 360 412 361 - static int has_attention_file (struct hotplug_slot *slot) 413 + static int has_attention_file(struct pci_slot *pci_slot) 362 414 { 415 + struct hotplug_slot *slot = pci_slot->hotplug; 363 416 if ((!slot) || (!slot->ops)) 364 417 return -ENODEV; 365 418 if ((slot->ops->set_attention_status) || ··· 369 420 return -ENOENT; 370 421 } 371 422 372 - static int has_latch_file (struct hotplug_slot *slot) 423 + static int has_latch_file(struct pci_slot *pci_slot) 373 424 { 425 + struct hotplug_slot *slot = pci_slot->hotplug; 374 426 if ((!slot) || (!slot->ops)) 375 427 return -ENODEV; 376 428 if (slot->ops->get_latch_status) ··· 379 429 return -ENOENT; 380 430 } 381 431 382 - static int has_adapter_file (struct hotplug_slot *slot) 432 + static int has_adapter_file(struct pci_slot *pci_slot) 383 433 { 434 + struct hotplug_slot *slot = pci_slot->hotplug; 384 435 if ((!slot) || (!slot->ops)) 385 436 return -ENODEV; 386 437 if (slot->ops->get_adapter_status) ··· 389 438 return -ENOENT; 390 439 } 391 440 392 - static int has_address_file (struct hotplug_slot *slot) 441 + static int has_max_bus_speed_file(struct pci_slot *pci_slot) 393 442 { 394 - if ((!slot) || (!slot->ops)) 395 - return -ENODEV; 396 - if (slot->ops->get_address) 397 - return 0; 398 - return -ENOENT; 399 - } 400 - 401 - static int has_max_bus_speed_file (struct hotplug_slot *slot) 402 - { 443 + struct hotplug_slot *slot = pci_slot->hotplug; 403 444 if ((!slot) || (!slot->ops)) 404 445 return -ENODEV; 405 446 if (slot->ops->get_max_bus_speed) ··· 399 456 return -ENOENT; 400 457 } 401 458 402 - static int has_cur_bus_speed_file (struct hotplug_slot *slot) 459 + static int has_cur_bus_speed_file(struct pci_slot *pci_slot) 403 460 { 461 + struct hotplug_slot *slot = pci_slot->hotplug; 404 462 if ((!slot) || (!slot->ops)) 405 463 return -ENODEV; 406 464 if (slot->ops->get_cur_bus_speed) ··· 409 465 return -ENOENT; 410 466 } 411 467 412 - static int has_test_file (struct hotplug_slot *slot) 468 + static int has_test_file(struct pci_slot *pci_slot) 413 469 { 470 + struct hotplug_slot *slot = pci_slot->hotplug; 414 471 if ((!slot) || (!slot->ops)) 415 472 return -ENODEV; 416 473 if (slot->ops->hardware_test) ··· 419 474 return -ENOENT; 420 475 } 421 476 422 - static int fs_add_slot (struct hotplug_slot *slot) 477 + static int fs_add_slot(struct pci_slot *slot) 423 478 { 424 479 int retval = 0; 425 480 ··· 448 503 &hotplug_slot_attr_presence.attr); 449 504 if (retval) 450 505 goto exit_adapter; 451 - } 452 - 453 - if (has_address_file(slot) == 0) { 454 - retval = sysfs_create_file(&slot->kobj, 455 - &hotplug_slot_attr_address.attr); 456 - if (retval) 457 - goto exit_address; 458 506 } 459 507 460 508 if (has_max_bus_speed_file(slot) == 0) { ··· 482 544 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_max_bus_speed.attr); 483 545 484 546 exit_max_speed: 485 - if (has_address_file(slot) == 0) 486 - sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_address.attr); 487 - 488 - exit_address: 489 547 if (has_adapter_file(slot) == 0) 490 548 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_presence.attr); 491 549 ··· 501 567 return retval; 502 568 } 503 569 504 - static void fs_remove_slot (struct hotplug_slot *slot) 570 + static void fs_remove_slot(struct pci_slot *slot) 505 571 { 506 572 if (has_power_file(slot) == 0) 507 573 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_power.attr); ··· 514 580 515 581 if (has_adapter_file(slot) == 0) 516 582 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_presence.attr); 517 - 518 - if (has_address_file(slot) == 0) 519 - sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_address.attr); 520 583 521 584 if (has_max_bus_speed_file(slot) == 0) 522 585 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_max_bus_speed.attr); ··· 530 599 struct hotplug_slot *slot; 531 600 struct list_head *tmp; 532 601 602 + spin_lock(&pci_hotplug_slot_list_lock); 533 603 list_for_each (tmp, &pci_hotplug_slot_list) { 534 604 slot = list_entry (tmp, struct hotplug_slot, slot_list); 535 605 if (strcmp(slot->name, name) == 0) 536 - return slot; 606 + goto out; 537 607 } 538 - return NULL; 608 + slot = NULL; 609 + out: 610 + spin_unlock(&pci_hotplug_slot_list_lock); 611 + return slot; 539 612 } 540 613 541 614 /** 542 615 * pci_hp_register - register a hotplug_slot with the PCI hotplug subsystem 616 + * @bus: bus this slot is on 543 617 * @slot: pointer to the &struct hotplug_slot to register 618 + * @slot_nr: slot number 544 619 * 545 620 * Registers a hotplug slot with the pci hotplug subsystem, which will allow 546 621 * userspace interaction to the slot. 547 622 * 548 623 * Returns 0 if successful, anything else for an error. 549 624 */ 550 - int pci_hp_register (struct hotplug_slot *slot) 625 + int pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus, int slot_nr) 551 626 { 552 627 int result; 553 - struct hotplug_slot *tmp; 628 + struct pci_slot *pci_slot; 554 629 555 630 if (slot == NULL) 556 631 return -ENODEV; ··· 569 632 } 570 633 571 634 /* Check if we have already registered a slot with the same name. */ 572 - tmp = get_slot_from_name(slot->name); 573 - if (tmp) 635 + if (get_slot_from_name(slot->name)) 574 636 return -EEXIST; 575 637 576 - slot->kobj.kset = pci_hotplug_slots_kset; 577 - result = kobject_init_and_add(&slot->kobj, &hotplug_slot_ktype, NULL, 578 - "%s", slot->name); 579 - if (result) { 580 - err("Unable to register kobject '%s'", slot->name); 581 - return -EINVAL; 638 + /* 639 + * No problems if we call this interface from both ACPI_PCI_SLOT 640 + * driver and call it here again. If we've already created the 641 + * pci_slot, the interface will simply bump the refcount. 642 + */ 643 + pci_slot = pci_create_slot(bus, slot_nr, slot->name); 644 + if (IS_ERR(pci_slot)) 645 + return PTR_ERR(pci_slot); 646 + 647 + if (pci_slot->hotplug) { 648 + dbg("%s: already claimed\n", __func__); 649 + pci_destroy_slot(pci_slot); 650 + return -EBUSY; 582 651 } 583 652 584 - list_add (&slot->slot_list, &pci_hotplug_slot_list); 653 + slot->pci_slot = pci_slot; 654 + pci_slot->hotplug = slot; 585 655 586 - result = fs_add_slot (slot); 587 - kobject_uevent(&slot->kobj, KOBJ_ADD); 588 - dbg ("Added slot %s to the list\n", slot->name); 656 + /* 657 + * Allow pcihp drivers to override the ACPI_PCI_SLOT name. 658 + */ 659 + if (strcmp(kobject_name(&pci_slot->kobj), slot->name)) { 660 + result = kobject_rename(&pci_slot->kobj, slot->name); 661 + if (result) { 662 + pci_destroy_slot(pci_slot); 663 + return result; 664 + } 665 + } 666 + 667 + spin_lock(&pci_hotplug_slot_list_lock); 668 + list_add(&slot->slot_list, &pci_hotplug_slot_list); 669 + spin_unlock(&pci_hotplug_slot_list_lock); 670 + 671 + result = fs_add_slot(pci_slot); 672 + kobject_uevent(&pci_slot->kobj, KOBJ_ADD); 673 + dbg("Added slot %s to the list\n", slot->name); 674 + 675 + 589 676 return result; 590 677 } 591 678 592 679 /** 593 680 * pci_hp_deregister - deregister a hotplug_slot with the PCI hotplug subsystem 594 - * @slot: pointer to the &struct hotplug_slot to deregister 681 + * @hotplug: pointer to the &struct hotplug_slot to deregister 595 682 * 596 683 * The @slot must have been registered with the pci hotplug subsystem 597 684 * previously with a call to pci_hp_register(). 598 685 * 599 686 * Returns 0 if successful, anything else for an error. 600 687 */ 601 - int pci_hp_deregister (struct hotplug_slot *slot) 688 + int pci_hp_deregister(struct hotplug_slot *hotplug) 602 689 { 603 690 struct hotplug_slot *temp; 691 + struct pci_slot *slot; 604 692 605 - if (slot == NULL) 693 + if (!hotplug) 606 694 return -ENODEV; 607 695 608 - temp = get_slot_from_name (slot->name); 609 - if (temp != slot) { 696 + temp = get_slot_from_name(hotplug->name); 697 + if (temp != hotplug) 610 698 return -ENODEV; 611 - } 612 - list_del (&slot->slot_list); 613 699 614 - fs_remove_slot (slot); 615 - dbg ("Removed slot %s from the list\n", slot->name); 616 - kobject_put(&slot->kobj); 700 + spin_lock(&pci_hotplug_slot_list_lock); 701 + list_del(&hotplug->slot_list); 702 + spin_unlock(&pci_hotplug_slot_list_lock); 703 + 704 + slot = hotplug->pci_slot; 705 + fs_remove_slot(slot); 706 + dbg("Removed slot %s from the list\n", hotplug->name); 707 + 708 + hotplug->release(hotplug); 709 + slot->hotplug = NULL; 710 + pci_destroy_slot(slot); 711 + 617 712 return 0; 618 713 } 619 714 620 715 /** 621 716 * pci_hp_change_slot_info - changes the slot's information structure in the core 622 - * @slot: pointer to the slot whose info has changed 717 + * @hotplug: pointer to the slot whose info has changed 623 718 * @info: pointer to the info copy into the slot's info structure 624 719 * 625 720 * @slot must have been registered with the pci ··· 659 690 * 660 691 * Returns 0 if successful, anything else for an error. 661 692 */ 662 - int __must_check pci_hp_change_slot_info(struct hotplug_slot *slot, 693 + int __must_check pci_hp_change_slot_info(struct hotplug_slot *hotplug, 663 694 struct hotplug_slot_info *info) 664 695 { 665 - if ((slot == NULL) || (info == NULL)) 696 + struct pci_slot *slot; 697 + if (!hotplug || !info) 666 698 return -ENODEV; 699 + slot = hotplug->pci_slot; 667 700 668 - memcpy (slot->info, info, sizeof (struct hotplug_slot_info)); 701 + memcpy(hotplug->info, info, sizeof(struct hotplug_slot_info)); 669 702 670 703 return 0; 671 704 } ··· 675 704 static int __init pci_hotplug_init (void) 676 705 { 677 706 int result; 678 - struct kset *pci_bus_kset; 679 707 680 - pci_bus_kset = bus_get_kset(&pci_bus_type); 681 - 682 - pci_hotplug_slots_kset = kset_create_and_add("slots", NULL, 683 - &pci_bus_kset->kobj); 684 - if (!pci_hotplug_slots_kset) { 685 - result = -ENOMEM; 686 - err("Register subsys error\n"); 687 - goto exit; 688 - } 689 708 result = cpci_hotplug_init(debug); 690 709 if (result) { 691 710 err ("cpci_hotplug_init with error %d\n", result); 692 - goto err_subsys; 711 + goto err_cpci; 693 712 } 694 713 695 714 info (DRIVER_DESC " version: " DRIVER_VERSION "\n"); 696 - goto exit; 697 715 698 - err_subsys: 699 - kset_unregister(pci_hotplug_slots_kset); 700 - exit: 716 + err_cpci: 701 717 return result; 702 718 } 703 719 704 720 static void __exit pci_hotplug_exit (void) 705 721 { 706 722 cpci_hotplug_exit(); 707 - kset_unregister(pci_hotplug_slots_kset); 708 723 } 709 724 710 725 module_init(pci_hotplug_init); ··· 702 745 module_param(debug, bool, 0644); 703 746 MODULE_PARM_DESC(debug, "Debugging mode enabled or not"); 704 747 705 - EXPORT_SYMBOL_GPL(pci_hotplug_slots_kset); 706 748 EXPORT_SYMBOL_GPL(pci_hp_register); 707 749 EXPORT_SYMBOL_GPL(pci_hp_deregister); 708 750 EXPORT_SYMBOL_GPL(pci_hp_change_slot_info);
+11 -5
drivers/pci/hotplug/pciehp.h
··· 43 43 extern int pciehp_poll_time; 44 44 extern int pciehp_debug; 45 45 extern int pciehp_force; 46 + extern int pciehp_slot_with_bus; 46 47 extern struct workqueue_struct *pciehp_wq; 47 48 48 49 #define dbg(format, arg...) \ ··· 97 96 u32 slot_cap; 98 97 u8 cap_base; 99 98 struct timer_list poll_timer; 100 - volatile int cmd_busy; 99 + int cmd_busy; 101 100 unsigned int no_cmd_complete:1; 102 101 }; 103 102 ··· 157 156 extern int pciehp_configure_device(struct slot *p_slot); 158 157 extern int pciehp_unconfigure_device(struct slot *p_slot); 159 158 extern void pciehp_queue_pushbutton_work(struct work_struct *work); 160 - int pcie_init(struct controller *ctrl, struct pcie_device *dev); 159 + struct controller *pcie_init(struct pcie_device *dev); 161 160 int pciehp_enable_slot(struct slot *p_slot); 162 161 int pciehp_disable_slot(struct slot *p_slot); 163 - int pcie_init_hardware_part2(struct controller *ctrl, struct pcie_device *dev); 162 + int pcie_enable_notification(struct controller *ctrl); 164 163 165 164 static inline struct slot *pciehp_find_slot(struct controller *ctrl, u8 device) 166 165 { ··· 203 202 #include <acpi/actypes.h> 204 203 #include <linux/pci-acpi.h> 205 204 206 - #define pciehp_get_hp_hw_control_from_firmware(dev) \ 207 - pciehp_acpi_get_hp_hw_control_from_firmware(dev) 205 + static inline int pciehp_get_hp_hw_control_from_firmware(struct pci_dev *dev) 206 + { 207 + u32 flags = (OSC_PCI_EXPRESS_NATIVE_HP_CONTROL | 208 + OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL); 209 + return acpi_get_hp_hw_control_from_firmware(dev, flags); 210 + } 211 + 208 212 static inline int pciehp_get_hp_params_from_firmware(struct pci_dev *dev, 209 213 struct hotplug_params *hpp) 210 214 {
+34 -95
drivers/pci/hotplug/pciehp_core.c
··· 72 72 static int get_attention_status (struct hotplug_slot *slot, u8 *value); 73 73 static int get_latch_status (struct hotplug_slot *slot, u8 *value); 74 74 static int get_adapter_status (struct hotplug_slot *slot, u8 *value); 75 - static int get_address (struct hotplug_slot *slot, u32 *value); 76 75 static int get_max_bus_speed (struct hotplug_slot *slot, enum pci_bus_speed *value); 77 76 static int get_cur_bus_speed (struct hotplug_slot *slot, enum pci_bus_speed *value); 78 77 ··· 84 85 .get_attention_status = get_attention_status, 85 86 .get_latch_status = get_latch_status, 86 87 .get_adapter_status = get_adapter_status, 87 - .get_address = get_address, 88 88 .get_max_bus_speed = get_max_bus_speed, 89 89 .get_cur_bus_speed = get_cur_bus_speed, 90 90 }; ··· 183 185 */ 184 186 static void release_slot(struct hotplug_slot *hotplug_slot) 185 187 { 186 - struct slot *slot = hotplug_slot->private; 187 - 188 188 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name); 189 189 190 - kfree(slot->hotplug_slot->info); 191 - kfree(slot->hotplug_slot); 192 - kfree(slot); 193 - } 194 - 195 - static void make_slot_name(struct slot *slot) 196 - { 197 - if (pciehp_slot_with_bus) 198 - snprintf(slot->hotplug_slot->name, SLOT_NAME_SIZE, "%04d_%04d", 199 - slot->bus, slot->number); 200 - else 201 - snprintf(slot->hotplug_slot->name, SLOT_NAME_SIZE, "%d", 202 - slot->number); 190 + kfree(hotplug_slot->info); 191 + kfree(hotplug_slot); 203 192 } 204 193 205 194 static int init_slots(struct controller *ctrl) ··· 195 210 struct hotplug_slot *hotplug_slot; 196 211 struct hotplug_slot_info *info; 197 212 int retval = -ENOMEM; 198 - int i; 199 213 200 - for (i = 0; i < ctrl->num_slots; i++) { 201 - slot = kzalloc(sizeof(*slot), GFP_KERNEL); 202 - if (!slot) 203 - goto error; 204 - 214 + list_for_each_entry(slot, &ctrl->slot_list, slot_list) { 205 215 hotplug_slot = kzalloc(sizeof(*hotplug_slot), GFP_KERNEL); 206 216 if (!hotplug_slot) 207 - goto error_slot; 208 - slot->hotplug_slot = hotplug_slot; 217 + goto error; 209 218 210 219 info = kzalloc(sizeof(*info), GFP_KERNEL); 211 220 if (!info) 212 221 goto error_hpslot; 213 - hotplug_slot->info = info; 214 - 215 - hotplug_slot->name = slot->name; 216 - 217 - slot->hp_slot = i; 218 - slot->ctrl = ctrl; 219 - slot->bus = ctrl->pci_dev->subordinate->number; 220 - slot->device = ctrl->slot_device_offset + i; 221 - slot->hpc_ops = ctrl->hpc_ops; 222 - slot->number = ctrl->first_slot; 223 - mutex_init(&slot->lock); 224 - INIT_DELAYED_WORK(&slot->work, pciehp_queue_pushbutton_work); 225 222 226 223 /* register this slot with the hotplug pci core */ 224 + hotplug_slot->info = info; 225 + hotplug_slot->name = slot->name; 227 226 hotplug_slot->private = slot; 228 227 hotplug_slot->release = &release_slot; 229 - make_slot_name(slot); 230 228 hotplug_slot->ops = &pciehp_hotplug_slot_ops; 231 - 232 229 get_power_status(hotplug_slot, &info->power_status); 233 230 get_attention_status(hotplug_slot, &info->attention_status); 234 231 get_latch_status(hotplug_slot, &info->latch_status); 235 232 get_adapter_status(hotplug_slot, &info->adapter_status); 233 + slot->hotplug_slot = hotplug_slot; 236 234 237 235 dbg("Registering bus=%x dev=%x hp_slot=%x sun=%x " 238 236 "slot_device_offset=%x\n", slot->bus, slot->device, 239 237 slot->hp_slot, slot->number, ctrl->slot_device_offset); 240 - retval = pci_hp_register(hotplug_slot); 238 + retval = pci_hp_register(hotplug_slot, 239 + ctrl->pci_dev->subordinate, 240 + slot->device); 241 241 if (retval) { 242 242 err("pci_hp_register failed with error %d\n", retval); 243 243 if (retval == -EEXIST) ··· 233 263 } 234 264 /* create additional sysfs entries */ 235 265 if (EMI(ctrl)) { 236 - retval = sysfs_create_file(&hotplug_slot->kobj, 266 + retval = sysfs_create_file(&hotplug_slot->pci_slot->kobj, 237 267 &hotplug_slot_attr_lock.attr); 238 268 if (retval) { 239 269 pci_hp_deregister(hotplug_slot); ··· 241 271 goto error_info; 242 272 } 243 273 } 244 - 245 - list_add(&slot->slot_list, &ctrl->slot_list); 246 274 } 247 275 248 276 return 0; ··· 248 280 kfree(info); 249 281 error_hpslot: 250 282 kfree(hotplug_slot); 251 - error_slot: 252 - kfree(slot); 253 283 error: 254 284 return retval; 255 285 } 256 286 257 287 static void cleanup_slots(struct controller *ctrl) 258 288 { 259 - struct list_head *tmp; 260 - struct list_head *next; 261 289 struct slot *slot; 262 290 263 - list_for_each_safe(tmp, next, &ctrl->slot_list) { 264 - slot = list_entry(tmp, struct slot, slot_list); 265 - list_del(&slot->slot_list); 291 + list_for_each_entry(slot, &ctrl->slot_list, slot_list) { 266 292 if (EMI(ctrl)) 267 - sysfs_remove_file(&slot->hotplug_slot->kobj, 293 + sysfs_remove_file(&slot->hotplug_slot->pci_slot->kobj, 268 294 &hotplug_slot_attr_lock.attr); 269 - cancel_delayed_work(&slot->work); 270 - flush_scheduled_work(); 271 - flush_workqueue(pciehp_wq); 272 295 pci_hp_deregister(slot->hotplug_slot); 273 296 } 274 297 } ··· 357 398 return 0; 358 399 } 359 400 360 - static int get_address(struct hotplug_slot *hotplug_slot, u32 *value) 361 - { 362 - struct slot *slot = hotplug_slot->private; 363 - struct pci_bus *bus = slot->ctrl->pci_dev->subordinate; 364 - 365 - dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name); 366 - 367 - *value = (pci_domain_nr(bus) << 16) | (slot->bus << 8) | slot->device; 368 - 369 - return 0; 370 - } 371 - 372 - static int get_max_bus_speed(struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value) 401 + static int get_max_bus_speed(struct hotplug_slot *hotplug_slot, 402 + enum pci_bus_speed *value) 373 403 { 374 404 struct slot *slot = hotplug_slot->private; 375 405 int retval; ··· 392 444 struct controller *ctrl; 393 445 struct slot *t_slot; 394 446 u8 value; 395 - struct pci_dev *pdev; 447 + struct pci_dev *pdev = dev->port; 396 448 397 - ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL); 449 + if (pciehp_force) 450 + dbg("Bypassing BIOS check for pciehp use on %s\n", 451 + pci_name(pdev)); 452 + else if (pciehp_get_hp_hw_control_from_firmware(pdev)) 453 + goto err_out_none; 454 + 455 + ctrl = pcie_init(dev); 398 456 if (!ctrl) { 399 - err("%s : out of memory\n", __func__); 457 + dbg("%s: controller initialization failed\n", PCIE_MODULE_NAME); 400 458 goto err_out_none; 401 459 } 402 - INIT_LIST_HEAD(&ctrl->slot_list); 403 - 404 - pdev = dev->port; 405 - ctrl->pci_dev = pdev; 406 - 407 - rc = pcie_init(ctrl, dev); 408 - if (rc) { 409 - dbg("%s: controller initialization failed\n", PCIE_MODULE_NAME); 410 - goto err_out_free_ctrl; 411 - } 412 - 413 - pci_set_drvdata(pdev, ctrl); 414 - 415 - dbg("%s: ctrl bus=0x%x, device=%x, function=%x, irq=%x\n", 416 - __func__, pdev->bus->number, PCI_SLOT(pdev->devfn), 417 - PCI_FUNC(pdev->devfn), pdev->irq); 460 + set_service_data(dev, ctrl); 418 461 419 462 /* Setup the slot information structures */ 420 463 rc = init_slots(ctrl); 421 464 if (rc) { 422 - err("%s: slot initialization failed\n", PCIE_MODULE_NAME); 465 + if (rc == -EBUSY) 466 + warn("%s: slot already registered by another " 467 + "hotplug driver\n", PCIE_MODULE_NAME); 468 + else 469 + err("%s: slot initialization failed\n", 470 + PCIE_MODULE_NAME); 423 471 goto err_out_release_ctlr; 424 472 } 425 473 ··· 439 495 cleanup_slots(ctrl); 440 496 err_out_release_ctlr: 441 497 ctrl->hpc_ops->release_ctlr(ctrl); 442 - err_out_free_ctrl: 443 - kfree(ctrl); 444 498 err_out_none: 445 499 return -ENODEV; 446 500 } 447 501 448 502 static void pciehp_remove (struct pcie_device *dev) 449 503 { 450 - struct pci_dev *pdev = dev->port; 451 - struct controller *ctrl = pci_get_drvdata(pdev); 504 + struct controller *ctrl = get_service_data(dev); 452 505 453 506 cleanup_slots(ctrl); 454 507 ctrl->hpc_ops->release_ctlr(ctrl); 455 - kfree(ctrl); 456 508 } 457 509 458 510 #ifdef CONFIG_PM ··· 462 522 { 463 523 printk("%s ENTRY\n", __func__); 464 524 if (pciehp_force) { 465 - struct pci_dev *pdev = dev->port; 466 - struct controller *ctrl = pci_get_drvdata(pdev); 525 + struct controller *ctrl = get_service_data(dev); 467 526 struct slot *t_slot; 468 527 u8 status; 469 528 470 529 /* reinitialize the chipset's event detection logic */ 471 - pcie_init_hardware_part2(ctrl, dev); 530 + pcie_enable_notification(ctrl); 472 531 473 532 t_slot = pciehp_find_slot(ctrl, ctrl->slot_device_offset); 474 533
+139 -183
drivers/pci/hotplug/pciehp_hpc.c
··· 247 247 free_irq(ctrl->pci_dev->irq, ctrl); 248 248 } 249 249 250 - static inline int pcie_poll_cmd(struct controller *ctrl) 250 + static int pcie_poll_cmd(struct controller *ctrl) 251 251 { 252 252 u16 slot_status; 253 253 int timeout = 1000; 254 254 255 - if (!pciehp_readw(ctrl, SLOTSTATUS, &slot_status)) 256 - if (slot_status & CMD_COMPLETED) 257 - goto completed; 258 - for (timeout = 1000; timeout > 0; timeout -= 100) { 259 - msleep(100); 260 - if (!pciehp_readw(ctrl, SLOTSTATUS, &slot_status)) 261 - if (slot_status & CMD_COMPLETED) 262 - goto completed; 255 + if (!pciehp_readw(ctrl, SLOTSTATUS, &slot_status)) { 256 + if (slot_status & CMD_COMPLETED) { 257 + pciehp_writew(ctrl, SLOTSTATUS, CMD_COMPLETED); 258 + return 1; 259 + } 260 + } 261 + while (timeout > 1000) { 262 + msleep(10); 263 + timeout -= 10; 264 + if (!pciehp_readw(ctrl, SLOTSTATUS, &slot_status)) { 265 + if (slot_status & CMD_COMPLETED) { 266 + pciehp_writew(ctrl, SLOTSTATUS, CMD_COMPLETED); 267 + return 1; 268 + } 269 + } 263 270 } 264 271 return 0; /* timeout */ 265 - 266 - completed: 267 - pciehp_writew(ctrl, SLOTSTATUS, CMD_COMPLETED); 268 - return timeout; 269 272 } 270 273 271 - static inline int pcie_wait_cmd(struct controller *ctrl, int poll) 274 + static void pcie_wait_cmd(struct controller *ctrl, int poll) 272 275 { 273 - int retval = 0; 274 276 unsigned int msecs = pciehp_poll_mode ? 2500 : 1000; 275 277 unsigned long timeout = msecs_to_jiffies(msecs); 276 278 int rc; ··· 280 278 if (poll) 281 279 rc = pcie_poll_cmd(ctrl); 282 280 else 283 - rc = wait_event_interruptible_timeout(ctrl->queue, 284 - !ctrl->cmd_busy, timeout); 281 + rc = wait_event_timeout(ctrl->queue, !ctrl->cmd_busy, timeout); 285 282 if (!rc) 286 283 dbg("Command not completed in 1000 msec\n"); 287 - else if (rc < 0) { 288 - retval = -EINTR; 289 - info("Command was interrupted by a signal\n"); 290 - } 291 - 292 - return retval; 293 284 } 294 285 295 286 /** ··· 337 342 338 343 slot_ctrl &= ~mask; 339 344 slot_ctrl |= (cmd & mask); 340 - /* Don't enable command completed if caller is changing it. */ 341 - if (!(mask & CMD_CMPL_INTR_ENABLE)) 342 - slot_ctrl |= CMD_CMPL_INTR_ENABLE; 343 - 344 345 ctrl->cmd_busy = 1; 345 346 smp_mb(); 346 347 retval = pciehp_writew(ctrl, SLOTCTRL, slot_ctrl); ··· 356 365 if (!(slot_ctrl & HP_INTR_ENABLE) || 357 366 !(slot_ctrl & CMD_CMPL_INTR_ENABLE)) 358 367 poll = 1; 359 - retval = pcie_wait_cmd(ctrl, poll); 368 + pcie_wait_cmd(ctrl, poll); 360 369 } 361 370 out: 362 371 mutex_unlock(&ctrl->ctrl_lock); ··· 605 614 __func__, ctrl->cap_base + SLOTCTRL, slot_cmd); 606 615 } 607 616 608 - static void hpc_release_ctlr(struct controller *ctrl) 609 - { 610 - /* Mask Hot-plug Interrupt Enable */ 611 - if (pcie_write_cmd(ctrl, 0, HP_INTR_ENABLE | CMD_CMPL_INTR_ENABLE)) 612 - err("%s: Cannot mask hotplut interrupt enable\n", __func__); 613 - 614 - /* Free interrupt handler or interrupt polling timer */ 615 - pciehp_free_irq(ctrl); 616 - 617 - /* 618 - * If this is the last controller to be released, destroy the 619 - * pciehp work queue 620 - */ 621 - if (atomic_dec_and_test(&pciehp_num_controllers)) 622 - destroy_workqueue(pciehp_wq); 623 - } 624 - 625 617 static int hpc_power_on_slot(struct slot * slot) 626 618 { 627 619 struct controller *ctrl = slot->ctrl; ··· 759 785 intr_loc |= detected; 760 786 if (!intr_loc) 761 787 return IRQ_NONE; 762 - if (pciehp_writew(ctrl, SLOTSTATUS, detected)) { 788 + if (detected && pciehp_writew(ctrl, SLOTSTATUS, detected)) { 763 789 err("%s: Cannot write to SLOTSTATUS\n", __func__); 764 790 return IRQ_NONE; 765 791 } ··· 771 797 if (intr_loc & CMD_COMPLETED) { 772 798 ctrl->cmd_busy = 0; 773 799 smp_mb(); 774 - wake_up_interruptible(&ctrl->queue); 800 + wake_up(&ctrl->queue); 775 801 } 776 802 777 803 if (!(intr_loc & ~CMD_COMPLETED)) 778 804 return IRQ_HANDLED; 779 805 780 - /* 781 - * Return without handling events if this handler routine is 782 - * called before controller initialization is done. This may 783 - * happen if hotplug event or another interrupt that shares 784 - * the IRQ with pciehp arrives before slot initialization is 785 - * done after interrupt handler is registered. 786 - * 787 - * FIXME - Need more structural fixes. We need to be ready to 788 - * handle the event before installing interrupt handler. 789 - */ 790 806 p_slot = pciehp_find_slot(ctrl, ctrl->slot_device_offset); 791 - if (!p_slot || !p_slot->hpc_ops) 792 - return IRQ_HANDLED; 793 807 794 808 /* Check MRL Sensor Changed */ 795 809 if (intr_loc & MRL_SENS_CHANGED) ··· 954 992 return retval; 955 993 } 956 994 995 + static void pcie_release_ctrl(struct controller *ctrl); 957 996 static struct hpc_ops pciehp_hpc_ops = { 958 997 .power_on_slot = hpc_power_on_slot, 959 998 .power_off_slot = hpc_power_off_slot, ··· 976 1013 .green_led_off = hpc_set_green_led_off, 977 1014 .green_led_blink = hpc_set_green_led_blink, 978 1015 979 - .release_ctlr = hpc_release_ctlr, 1016 + .release_ctlr = pcie_release_ctrl, 980 1017 .check_lnk_status = hpc_check_lnk_status, 981 1018 }; 982 1019 983 - #ifdef CONFIG_ACPI 984 - static int pciehp_acpi_get_hp_hw_control_from_firmware(struct pci_dev *dev) 985 - { 986 - acpi_status status; 987 - acpi_handle chandle, handle = DEVICE_ACPI_HANDLE(&(dev->dev)); 988 - struct pci_dev *pdev = dev; 989 - struct pci_bus *parent; 990 - struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL }; 991 - 992 - /* 993 - * Per PCI firmware specification, we should run the ACPI _OSC 994 - * method to get control of hotplug hardware before using it. 995 - * If an _OSC is missing, we look for an OSHP to do the same thing. 996 - * To handle different BIOS behavior, we look for _OSC and OSHP 997 - * within the scope of the hotplug controller and its parents, upto 998 - * the host bridge under which this controller exists. 999 - */ 1000 - while (!handle) { 1001 - /* 1002 - * This hotplug controller was not listed in the ACPI name 1003 - * space at all. Try to get acpi handle of parent pci bus. 1004 - */ 1005 - if (!pdev || !pdev->bus->parent) 1006 - break; 1007 - parent = pdev->bus->parent; 1008 - dbg("Could not find %s in acpi namespace, trying parent\n", 1009 - pci_name(pdev)); 1010 - if (!parent->self) 1011 - /* Parent must be a host bridge */ 1012 - handle = acpi_get_pci_rootbridge_handle( 1013 - pci_domain_nr(parent), 1014 - parent->number); 1015 - else 1016 - handle = DEVICE_ACPI_HANDLE( 1017 - &(parent->self->dev)); 1018 - pdev = parent->self; 1019 - } 1020 - 1021 - while (handle) { 1022 - acpi_get_name(handle, ACPI_FULL_PATHNAME, &string); 1023 - dbg("Trying to get hotplug control for %s \n", 1024 - (char *)string.pointer); 1025 - status = pci_osc_control_set(handle, 1026 - OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL | 1027 - OSC_PCI_EXPRESS_NATIVE_HP_CONTROL); 1028 - if (status == AE_NOT_FOUND) 1029 - status = acpi_run_oshp(handle); 1030 - if (ACPI_SUCCESS(status)) { 1031 - dbg("Gained control for hotplug HW for pci %s (%s)\n", 1032 - pci_name(dev), (char *)string.pointer); 1033 - kfree(string.pointer); 1034 - return 0; 1035 - } 1036 - if (acpi_root_bridge(handle)) 1037 - break; 1038 - chandle = handle; 1039 - status = acpi_get_parent(chandle, &handle); 1040 - if (ACPI_FAILURE(status)) 1041 - break; 1042 - } 1043 - 1044 - dbg("Cannot get control of hotplug hardware for pci %s\n", 1045 - pci_name(dev)); 1046 - 1047 - kfree(string.pointer); 1048 - return -1; 1049 - } 1050 - #endif 1051 - 1052 - static int pcie_init_hardware_part1(struct controller *ctrl, 1053 - struct pcie_device *dev) 1054 - { 1055 - /* Clear all remaining event bits in Slot Status register */ 1056 - if (pciehp_writew(ctrl, SLOTSTATUS, 0x1f)) { 1057 - err("%s: Cannot write to SLOTSTATUS register\n", __func__); 1058 - return -1; 1059 - } 1060 - 1061 - /* Mask Hot-plug Interrupt Enable */ 1062 - if (pcie_write_cmd(ctrl, 0, HP_INTR_ENABLE | CMD_CMPL_INTR_ENABLE)) { 1063 - err("%s: Cannot mask hotplug interrupt enable\n", __func__); 1064 - return -1; 1065 - } 1066 - return 0; 1067 - } 1068 - 1069 - int pcie_init_hardware_part2(struct controller *ctrl, struct pcie_device *dev) 1020 + int pcie_enable_notification(struct controller *ctrl) 1070 1021 { 1071 1022 u16 cmd, mask; 1072 1023 ··· 992 1115 if (MRL_SENS(ctrl)) 993 1116 cmd |= MRL_DETECT_ENABLE; 994 1117 if (!pciehp_poll_mode) 995 - cmd |= HP_INTR_ENABLE; 1118 + cmd |= HP_INTR_ENABLE | CMD_CMPL_INTR_ENABLE; 996 1119 997 - mask = PRSN_DETECT_ENABLE | ATTN_BUTTN_ENABLE | 998 - PWR_FAULT_DETECT_ENABLE | MRL_DETECT_ENABLE | HP_INTR_ENABLE; 1120 + mask = PRSN_DETECT_ENABLE | ATTN_BUTTN_ENABLE | MRL_DETECT_ENABLE | 1121 + PWR_FAULT_DETECT_ENABLE | HP_INTR_ENABLE | CMD_CMPL_INTR_ENABLE; 999 1122 1000 1123 if (pcie_write_cmd(ctrl, cmd, mask)) { 1001 1124 err("%s: Cannot enable software notification\n", __func__); 1002 - goto abort; 1125 + return -1; 1003 1126 } 1004 - 1005 - if (pciehp_force) 1006 - dbg("Bypassing BIOS check for pciehp use on %s\n", 1007 - pci_name(ctrl->pci_dev)); 1008 - else if (pciehp_get_hp_hw_control_from_firmware(ctrl->pci_dev)) 1009 - goto abort_disable_intr; 1010 - 1011 1127 return 0; 1128 + } 1012 1129 1013 - /* We end up here for the many possible ways to fail this API. */ 1014 - abort_disable_intr: 1015 - if (pcie_write_cmd(ctrl, 0, HP_INTR_ENABLE)) 1016 - err("%s : disabling interrupts failed\n", __func__); 1017 - abort: 1018 - return -1; 1130 + static void pcie_disable_notification(struct controller *ctrl) 1131 + { 1132 + u16 mask; 1133 + mask = PRSN_DETECT_ENABLE | ATTN_BUTTN_ENABLE | MRL_DETECT_ENABLE | 1134 + PWR_FAULT_DETECT_ENABLE | HP_INTR_ENABLE | CMD_CMPL_INTR_ENABLE; 1135 + if (pcie_write_cmd(ctrl, 0, mask)) 1136 + warn("%s: Cannot disable software notification\n", __func__); 1137 + } 1138 + 1139 + static int pcie_init_notification(struct controller *ctrl) 1140 + { 1141 + if (pciehp_request_irq(ctrl)) 1142 + return -1; 1143 + if (pcie_enable_notification(ctrl)) { 1144 + pciehp_free_irq(ctrl); 1145 + return -1; 1146 + } 1147 + return 0; 1148 + } 1149 + 1150 + static void pcie_shutdown_notification(struct controller *ctrl) 1151 + { 1152 + pcie_disable_notification(ctrl); 1153 + pciehp_free_irq(ctrl); 1154 + } 1155 + 1156 + static void make_slot_name(struct slot *slot) 1157 + { 1158 + if (pciehp_slot_with_bus) 1159 + snprintf(slot->name, SLOT_NAME_SIZE, "%04d_%04d", 1160 + slot->bus, slot->number); 1161 + else 1162 + snprintf(slot->name, SLOT_NAME_SIZE, "%d", slot->number); 1163 + } 1164 + 1165 + static int pcie_init_slot(struct controller *ctrl) 1166 + { 1167 + struct slot *slot; 1168 + 1169 + slot = kzalloc(sizeof(*slot), GFP_KERNEL); 1170 + if (!slot) 1171 + return -ENOMEM; 1172 + 1173 + slot->hp_slot = 0; 1174 + slot->ctrl = ctrl; 1175 + slot->bus = ctrl->pci_dev->subordinate->number; 1176 + slot->device = ctrl->slot_device_offset + slot->hp_slot; 1177 + slot->hpc_ops = ctrl->hpc_ops; 1178 + slot->number = ctrl->first_slot; 1179 + make_slot_name(slot); 1180 + mutex_init(&slot->lock); 1181 + INIT_DELAYED_WORK(&slot->work, pciehp_queue_pushbutton_work); 1182 + list_add(&slot->slot_list, &ctrl->slot_list); 1183 + return 0; 1184 + } 1185 + 1186 + static void pcie_cleanup_slot(struct controller *ctrl) 1187 + { 1188 + struct slot *slot; 1189 + slot = list_first_entry(&ctrl->slot_list, struct slot, slot_list); 1190 + list_del(&slot->slot_list); 1191 + cancel_delayed_work(&slot->work); 1192 + flush_scheduled_work(); 1193 + flush_workqueue(pciehp_wq); 1194 + kfree(slot); 1019 1195 } 1020 1196 1021 1197 static inline void dbg_ctrl(struct controller *ctrl) ··· 1106 1176 dbg(" Comamnd Completed : %3s\n", NO_CMD_CMPL(ctrl)? "no" : "yes"); 1107 1177 pciehp_readw(ctrl, SLOTSTATUS, &reg16); 1108 1178 dbg("Slot Status : 0x%04x\n", reg16); 1109 - pciehp_readw(ctrl, SLOTSTATUS, &reg16); 1179 + pciehp_readw(ctrl, SLOTCTRL, &reg16); 1110 1180 dbg("Slot Control : 0x%04x\n", reg16); 1111 1181 } 1112 1182 1113 - int pcie_init(struct controller *ctrl, struct pcie_device *dev) 1183 + struct controller *pcie_init(struct pcie_device *dev) 1114 1184 { 1185 + struct controller *ctrl; 1115 1186 u32 slot_cap; 1116 1187 struct pci_dev *pdev = dev->port; 1188 + 1189 + ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL); 1190 + if (!ctrl) { 1191 + err("%s : out of memory\n", __func__); 1192 + goto abort; 1193 + } 1194 + INIT_LIST_HEAD(&ctrl->slot_list); 1117 1195 1118 1196 ctrl->pci_dev = pdev; 1119 1197 ctrl->cap_base = pci_find_capability(pdev, PCI_CAP_ID_EXP); ··· 1153 1215 !(POWER_CTRL(ctrl) | ATTN_LED(ctrl) | PWR_LED(ctrl) | EMI(ctrl))) 1154 1216 ctrl->no_cmd_complete = 1; 1155 1217 1156 - info("HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n", 1157 - pdev->vendor, pdev->device, 1158 - pdev->subsystem_vendor, pdev->subsystem_device); 1218 + /* Clear all remaining event bits in Slot Status register */ 1219 + if (pciehp_writew(ctrl, SLOTSTATUS, 0x1f)) 1220 + goto abort_ctrl; 1159 1221 1160 - if (pcie_init_hardware_part1(ctrl, dev)) 1161 - goto abort; 1162 - 1163 - if (pciehp_request_irq(ctrl)) 1164 - goto abort; 1222 + /* Disable sotfware notification */ 1223 + pcie_disable_notification(ctrl); 1165 1224 1166 1225 /* 1167 1226 * If this is the first controller to be initialized, ··· 1166 1231 */ 1167 1232 if (atomic_add_return(1, &pciehp_num_controllers) == 1) { 1168 1233 pciehp_wq = create_singlethread_workqueue("pciehpd"); 1169 - if (!pciehp_wq) { 1170 - goto abort_free_irq; 1171 - } 1234 + if (!pciehp_wq) 1235 + goto abort_ctrl; 1172 1236 } 1173 1237 1174 - if (pcie_init_hardware_part2(ctrl, dev)) 1175 - goto abort_free_irq; 1238 + info("HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n", 1239 + pdev->vendor, pdev->device, 1240 + pdev->subsystem_vendor, pdev->subsystem_device); 1176 1241 1177 - return 0; 1242 + if (pcie_init_slot(ctrl)) 1243 + goto abort_ctrl; 1178 1244 1179 - abort_free_irq: 1180 - pciehp_free_irq(ctrl); 1245 + if (pcie_init_notification(ctrl)) 1246 + goto abort_slot; 1247 + 1248 + return ctrl; 1249 + 1250 + abort_slot: 1251 + pcie_cleanup_slot(ctrl); 1252 + abort_ctrl: 1253 + kfree(ctrl); 1181 1254 abort: 1182 - return -1; 1255 + return NULL; 1256 + } 1257 + 1258 + void pcie_release_ctrl(struct controller *ctrl) 1259 + { 1260 + pcie_shutdown_notification(ctrl); 1261 + pcie_cleanup_slot(ctrl); 1262 + /* 1263 + * If this is the last controller to be released, destroy the 1264 + * pciehp work queue 1265 + */ 1266 + if (atomic_dec_and_test(&pciehp_num_controllers)) 1267 + destroy_workqueue(pciehp_wq); 1268 + kfree(ctrl); 1183 1269 }
+3 -2
drivers/pci/hotplug/rpadlpar_sysfs.c
··· 14 14 */ 15 15 #include <linux/kobject.h> 16 16 #include <linux/string.h> 17 + #include <linux/pci.h> 17 18 #include <linux/pci_hotplug.h> 18 19 #include "rpadlpar.h" 20 + #include "../pci.h" 19 21 20 22 #define DLPAR_KOBJ_NAME "control" 21 23 ··· 28 26 #define REMOVE_SLOT_ATTR_NAME remove_slot 29 27 30 28 #define MAX_DRC_NAME_LEN 64 31 - 32 29 33 30 static ssize_t add_slot_store(struct kobject *kobj, struct kobj_attribute *attr, 34 31 const char *buf, size_t nbytes) ··· 113 112 int error; 114 113 115 114 dlpar_kobj = kobject_create_and_add(DLPAR_KOBJ_NAME, 116 - &pci_hotplug_slots_kset->kobj); 115 + &pci_slots_kset->kobj); 117 116 if (!dlpar_kobj) 118 117 return -EINVAL; 119 118
+6 -38
drivers/pci/hotplug/rpaphp_slot.c
··· 33 33 #include <asm/rtas.h> 34 34 #include "rpaphp.h" 35 35 36 - static ssize_t address_read_file (struct hotplug_slot *php_slot, char *buf) 37 - { 38 - int retval; 39 - struct slot *slot = (struct slot *)php_slot->private; 40 - struct pci_bus *bus; 41 - 42 - if (!slot) 43 - return -ENOENT; 44 - 45 - bus = slot->bus; 46 - if (!bus) 47 - return -ENOENT; 48 - 49 - if (bus->self) 50 - retval = sprintf(buf, pci_name(bus->self)); 51 - else 52 - retval = sprintf(buf, "%04x:%02x:00.0", 53 - pci_domain_nr(bus), bus->number); 54 - 55 - return retval; 56 - } 57 - 58 - static struct hotplug_slot_attribute php_attr_address = { 59 - .attr = {.name = "address", .mode = S_IFREG | S_IRUGO}, 60 - .show = address_read_file, 61 - }; 62 - 63 36 /* free up the memory used by a slot */ 64 37 static void rpaphp_release_slot(struct hotplug_slot *hotplug_slot) 65 38 { ··· 108 135 109 136 list_del(&slot->rpaphp_slot_list); 110 137 111 - /* remove "address" file */ 112 - sysfs_remove_file(&php_slot->kobj, &php_attr_address.attr); 113 - 114 138 retval = pci_hp_deregister(php_slot); 115 139 if (retval) 116 140 err("Problem unregistering a slot %s\n", slot->name); ··· 121 151 { 122 152 struct hotplug_slot *php_slot = slot->hotplug_slot; 123 153 int retval; 154 + int slotno; 124 155 125 156 dbg("%s registering slot:path[%s] index[%x], name[%s] pdomain[%x] type[%d]\n", 126 157 __func__, slot->dn->full_name, slot->index, slot->name, ··· 133 162 return -EAGAIN; 134 163 } 135 164 136 - retval = pci_hp_register(php_slot); 165 + if (slot->dn->child) 166 + slotno = PCI_SLOT(PCI_DN(slot->dn->child)->devfn); 167 + else 168 + slotno = -1; 169 + retval = pci_hp_register(php_slot, slot->bus, slotno); 137 170 if (retval) { 138 171 err("pci_hp_register failed with error %d\n", retval); 139 172 return retval; 140 - } 141 - 142 - /* create "address" file */ 143 - retval = sysfs_create_file(&php_slot->kobj, &php_attr_address.attr); 144 - if (retval) { 145 - err("sysfs_create_file failed with error %d\n", retval); 146 - goto sysfs_fail; 147 173 } 148 174 149 175 /* add slot to our internal list */
+8 -4
drivers/pci/hotplug/sgi_hotplug.c
··· 197 197 static struct hotplug_slot * sn_hp_destroy(void) 198 198 { 199 199 struct slot *slot; 200 + struct pci_slot *pci_slot; 200 201 struct hotplug_slot *bss_hotplug_slot = NULL; 201 202 202 203 list_for_each_entry(slot, &sn_hp_list, hp_list) { 203 204 bss_hotplug_slot = slot->hotplug_slot; 205 + pci_slot = bss_hotplug_slot->pci_slot; 204 206 list_del(&((struct slot *)bss_hotplug_slot->private)-> 205 207 hp_list); 206 - sysfs_remove_file(&bss_hotplug_slot->kobj, 208 + sysfs_remove_file(&pci_slot->kobj, 207 209 &sn_slot_path_attr.attr); 208 210 break; 209 211 } ··· 616 614 static int sn_hotplug_slot_register(struct pci_bus *pci_bus) 617 615 { 618 616 int device; 617 + struct pci_slot *pci_slot; 619 618 struct hotplug_slot *bss_hotplug_slot; 620 619 int rc = 0; 621 620 ··· 653 650 bss_hotplug_slot->ops = &sn_hotplug_slot_ops; 654 651 bss_hotplug_slot->release = &sn_release_slot; 655 652 656 - rc = pci_hp_register(bss_hotplug_slot); 653 + rc = pci_hp_register(bss_hotplug_slot, pci_bus, device); 657 654 if (rc) 658 655 goto register_err; 659 656 660 - rc = sysfs_create_file(&bss_hotplug_slot->kobj, 657 + pci_slot = bss_hotplug_slot->pci_slot; 658 + rc = sysfs_create_file(&pci_slot->kobj, 661 659 &sn_slot_path_attr.attr); 662 660 if (rc) 663 661 goto register_err; ··· 668 664 669 665 register_err: 670 666 dev_dbg(&pci_bus->self->dev, "bus failed to register with err = %d\n", 671 - rc); 667 + rc); 672 668 673 669 alloc_err: 674 670 if (rc == -ENOMEM)
+8 -6
drivers/pci/hotplug/shpchp.h
··· 170 170 extern int shpc_init( struct controller *ctrl, struct pci_dev *pdev); 171 171 172 172 #ifdef CONFIG_ACPI 173 + #include <linux/pci-acpi.h> 173 174 static inline int get_hp_params_from_firmware(struct pci_dev *dev, 174 175 struct hotplug_params *hpp) 175 176 { ··· 178 177 return -ENODEV; 179 178 return 0; 180 179 } 181 - #define get_hp_hw_control_from_firmware(pdev) \ 182 - do { \ 183 - if (DEVICE_ACPI_HANDLE(&(pdev->dev))) \ 184 - acpi_run_oshp(DEVICE_ACPI_HANDLE(&(pdev->dev)));\ 185 - } while (0) 180 + 181 + static inline int get_hp_hw_control_from_firmware(struct pci_dev *dev) 182 + { 183 + u32 flags = OSC_SHPC_NATIVE_HP_CONTROL; 184 + return acpi_get_hp_hw_control_from_firmware(dev, flags); 185 + } 186 186 #else 187 187 #define get_hp_params_from_firmware(dev, hpp) (-ENODEV) 188 - #define get_hp_hw_control_from_firmware(dev) do { } while (0) 188 + #define get_hp_hw_control_from_firmware(dev) (0) 189 189 #endif 190 190 191 191 struct ctrl_reg {
+13 -24
drivers/pci/hotplug/shpchp_core.c
··· 39 39 int shpchp_debug; 40 40 int shpchp_poll_mode; 41 41 int shpchp_poll_time; 42 - int shpchp_slot_with_bus; 42 + static int shpchp_slot_with_bus; 43 43 struct workqueue_struct *shpchp_wq; 44 44 45 45 #define DRIVER_VERSION "0.4" ··· 68 68 static int get_attention_status (struct hotplug_slot *slot, u8 *value); 69 69 static int get_latch_status (struct hotplug_slot *slot, u8 *value); 70 70 static int get_adapter_status (struct hotplug_slot *slot, u8 *value); 71 - static int get_address (struct hotplug_slot *slot, u32 *value); 72 71 static int get_max_bus_speed (struct hotplug_slot *slot, enum pci_bus_speed *value); 73 72 static int get_cur_bus_speed (struct hotplug_slot *slot, enum pci_bus_speed *value); 74 73 ··· 80 81 .get_attention_status = get_attention_status, 81 82 .get_latch_status = get_latch_status, 82 83 .get_adapter_status = get_adapter_status, 83 - .get_address = get_address, 84 84 .get_max_bus_speed = get_max_bus_speed, 85 85 .get_cur_bus_speed = get_cur_bus_speed, 86 86 }; ··· 157 159 dbg("Registering bus=%x dev=%x hp_slot=%x sun=%x " 158 160 "slot_device_offset=%x\n", slot->bus, slot->device, 159 161 slot->hp_slot, slot->number, ctrl->slot_device_offset); 160 - retval = pci_hp_register(slot->hotplug_slot); 162 + retval = pci_hp_register(slot->hotplug_slot, 163 + ctrl->pci_dev->subordinate, slot->device); 161 164 if (retval) { 162 165 err("pci_hp_register failed with error %d\n", retval); 163 166 if (retval == -EEXIST) ··· 287 288 return 0; 288 289 } 289 290 290 - static int get_address (struct hotplug_slot *hotplug_slot, u32 *value) 291 - { 292 - struct slot *slot = get_slot(hotplug_slot); 293 - struct pci_bus *bus = slot->ctrl->pci_dev->subordinate; 294 - 295 - dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name); 296 - 297 - *value = (pci_domain_nr(bus) << 16) | (slot->bus << 8) | slot->device; 298 - 299 - return 0; 300 - } 301 - 302 - static int get_max_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value) 291 + static int get_max_bus_speed(struct hotplug_slot *hotplug_slot, 292 + enum pci_bus_speed *value) 303 293 { 304 294 struct slot *slot = get_slot(hotplug_slot); 305 295 int retval; ··· 318 330 319 331 static int is_shpc_capable(struct pci_dev *dev) 320 332 { 321 - if ((dev->vendor == PCI_VENDOR_ID_AMD) || (dev->device == 322 - PCI_DEVICE_ID_AMD_GOLAM_7450)) 323 - return 1; 324 - if (pci_find_capability(dev, PCI_CAP_ID_SHPC)) 325 - return 1; 326 - 327 - return 0; 333 + if ((dev->vendor == PCI_VENDOR_ID_AMD) || (dev->device == 334 + PCI_DEVICE_ID_AMD_GOLAM_7450)) 335 + return 1; 336 + if (!pci_find_capability(dev, PCI_CAP_ID_SHPC)) 337 + return 0; 338 + if (get_hp_hw_control_from_firmware(dev)) 339 + return 0; 340 + return 1; 328 341 } 329 342 330 343 static int shpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
-1
drivers/pci/hotplug/shpchp_hpc.c
··· 1084 1084 dbg("%s: HPC at b:d:f:irq=0x%x:%x:%x:%x\n", __func__, 1085 1085 pdev->bus->number, PCI_SLOT(pdev->devfn), 1086 1086 PCI_FUNC(pdev->devfn), pdev->irq); 1087 - get_hp_hw_control_from_firmware(pdev); 1088 1087 1089 1088 /* 1090 1089 * If this is the first controller to be initialized,
-1
drivers/pci/intel-iommu.c
··· 1748 1748 deferred_flush = kzalloc(g_num_of_iommus * 1749 1749 sizeof(struct deferred_flush_tables), GFP_KERNEL); 1750 1750 if (!deferred_flush) { 1751 - kfree(g_iommus); 1752 1751 ret = -ENOMEM; 1753 1752 goto error; 1754 1753 }
+12 -10
drivers/pci/msi.c
··· 70 70 } 71 71 } 72 72 73 - static void msi_set_enable(struct pci_dev *dev, int enable) 73 + static void __msi_set_enable(struct pci_dev *dev, int pos, int enable) 74 74 { 75 - int pos; 76 75 u16 control; 77 76 78 - pos = pci_find_capability(dev, PCI_CAP_ID_MSI); 79 77 if (pos) { 80 78 pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &control); 81 79 control &= ~PCI_MSI_FLAGS_ENABLE; ··· 81 83 control |= PCI_MSI_FLAGS_ENABLE; 82 84 pci_write_config_word(dev, pos + PCI_MSI_FLAGS, control); 83 85 } 86 + } 87 + 88 + static void msi_set_enable(struct pci_dev *dev, int enable) 89 + { 90 + __msi_set_enable(dev, pci_find_capability(dev, PCI_CAP_ID_MSI), enable); 84 91 } 85 92 86 93 static void msix_set_enable(struct pci_dev *dev, int enable) ··· 144 141 mask_bits |= flag & mask; 145 142 pci_write_config_dword(entry->dev, pos, mask_bits); 146 143 } else { 147 - msi_set_enable(entry->dev, !flag); 144 + __msi_set_enable(entry->dev, entry->msi_attrib.pos, 145 + !flag); 148 146 } 149 147 break; 150 148 case PCI_CAP_ID_MSIX: ··· 565 561 566 562 /* Check whether driver already requested for MSI-X irqs */ 567 563 if (dev->msix_enabled) { 568 - printk(KERN_INFO "PCI: %s: Can't enable MSI. " 569 - "Device already has MSI-X enabled\n", 570 - pci_name(dev)); 564 + dev_info(&dev->dev, "can't enable MSI " 565 + "(MSI-X already enabled)\n"); 571 566 return -EINVAL; 572 567 } 573 568 status = msi_capability_init(dev); ··· 689 686 690 687 /* Check whether driver already requested for MSI irq */ 691 688 if (dev->msi_enabled) { 692 - printk(KERN_INFO "PCI: %s: Can't enable MSI-X. " 693 - "Device already has an MSI irq assigned\n", 694 - pci_name(dev)); 689 + dev_info(&dev->dev, "can't enable MSI-X " 690 + "(MSI IRQ already assigned)\n"); 695 691 return -EINVAL; 696 692 } 697 693 status = msix_capability_init(dev, entries, nvec);
+151 -174
drivers/pci/pci-acpi.c
··· 21 21 22 22 struct acpi_osc_data { 23 23 acpi_handle handle; 24 - u32 ctrlset_buf[3]; 25 - u32 global_ctrlsets; 24 + u32 support_set; 25 + u32 control_set; 26 + int is_queried; 27 + u32 query_result; 26 28 struct list_head sibiling; 27 29 }; 28 30 static LIST_HEAD(acpi_osc_data_list); 31 + 32 + struct acpi_osc_args { 33 + u32 capbuf[3]; 34 + u32 query_result; 35 + }; 29 36 30 37 static struct acpi_osc_data *acpi_get_osc_data(acpi_handle handle) 31 38 { ··· 51 44 return data; 52 45 } 53 46 54 - static u8 OSC_UUID[16] = {0x5B, 0x4D, 0xDB, 0x33, 0xF7, 0x1F, 0x1C, 0x40, 0x96, 0x57, 0x74, 0x41, 0xC0, 0x3D, 0xD7, 0x66}; 47 + static u8 OSC_UUID[16] = {0x5B, 0x4D, 0xDB, 0x33, 0xF7, 0x1F, 0x1C, 0x40, 48 + 0x96, 0x57, 0x74, 0x41, 0xC0, 0x3D, 0xD7, 0x66}; 55 49 56 - static acpi_status 57 - acpi_query_osc ( 58 - acpi_handle handle, 59 - u32 level, 60 - void *context, 61 - void **retval ) 50 + static acpi_status acpi_run_osc(acpi_handle handle, 51 + struct acpi_osc_args *osc_args) 62 52 { 63 - acpi_status status; 64 - struct acpi_object_list input; 65 - union acpi_object in_params[4]; 66 - struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL}; 67 - union acpi_object *out_obj; 68 - u32 osc_dw0; 69 - acpi_status *ret_status = (acpi_status *)retval; 53 + acpi_status status; 54 + struct acpi_object_list input; 55 + union acpi_object in_params[4]; 56 + struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL}; 57 + union acpi_object *out_obj; 58 + u32 osc_dw0, flags = osc_args->capbuf[OSC_QUERY_TYPE]; 59 + 60 + /* Setting up input parameters */ 61 + input.count = 4; 62 + input.pointer = in_params; 63 + in_params[0].type = ACPI_TYPE_BUFFER; 64 + in_params[0].buffer.length = 16; 65 + in_params[0].buffer.pointer = OSC_UUID; 66 + in_params[1].type = ACPI_TYPE_INTEGER; 67 + in_params[1].integer.value = 1; 68 + in_params[2].type = ACPI_TYPE_INTEGER; 69 + in_params[2].integer.value = 3; 70 + in_params[3].type = ACPI_TYPE_BUFFER; 71 + in_params[3].buffer.length = 12; 72 + in_params[3].buffer.pointer = (u8 *)osc_args->capbuf; 73 + 74 + status = acpi_evaluate_object(handle, "_OSC", &input, &output); 75 + if (ACPI_FAILURE(status)) 76 + return status; 77 + 78 + out_obj = output.pointer; 79 + if (out_obj->type != ACPI_TYPE_BUFFER) { 80 + printk(KERN_DEBUG "Evaluate _OSC returns wrong type\n"); 81 + status = AE_TYPE; 82 + goto out_kfree; 83 + } 84 + osc_dw0 = *((u32 *)out_obj->buffer.pointer); 85 + if (osc_dw0) { 86 + if (osc_dw0 & OSC_REQUEST_ERROR) 87 + printk(KERN_DEBUG "_OSC request fails\n"); 88 + if (osc_dw0 & OSC_INVALID_UUID_ERROR) 89 + printk(KERN_DEBUG "_OSC invalid UUID\n"); 90 + if (osc_dw0 & OSC_INVALID_REVISION_ERROR) 91 + printk(KERN_DEBUG "_OSC invalid revision\n"); 92 + if (osc_dw0 & OSC_CAPABILITIES_MASK_ERROR) { 93 + if (flags & OSC_QUERY_ENABLE) 94 + goto out_success; 95 + printk(KERN_DEBUG "_OSC FW not grant req. control\n"); 96 + status = AE_SUPPORT; 97 + goto out_kfree; 98 + } 99 + status = AE_ERROR; 100 + goto out_kfree; 101 + } 102 + out_success: 103 + if (flags & OSC_QUERY_ENABLE) 104 + osc_args->query_result = 105 + *((u32 *)(out_obj->buffer.pointer + 8)); 106 + status = AE_OK; 107 + 108 + out_kfree: 109 + kfree(output.pointer); 110 + return status; 111 + } 112 + 113 + static acpi_status acpi_query_osc(acpi_handle handle, 114 + u32 level, void *context, void **retval) 115 + { 116 + acpi_status status; 70 117 struct acpi_osc_data *osc_data; 71 - u32 flags = (unsigned long)context, temp; 118 + u32 flags = (unsigned long)context, support_set; 72 119 acpi_handle tmp; 120 + struct acpi_osc_args osc_args; 73 121 74 122 status = acpi_get_handle(handle, "_OSC", &tmp); 75 123 if (ACPI_FAILURE(status)) ··· 136 74 return AE_ERROR; 137 75 } 138 76 139 - osc_data->ctrlset_buf[OSC_SUPPORT_TYPE] |= (flags & OSC_SUPPORT_MASKS); 140 - 141 77 /* do _OSC query for all possible controls */ 142 - temp = osc_data->ctrlset_buf[OSC_CONTROL_TYPE]; 143 - osc_data->ctrlset_buf[OSC_QUERY_TYPE] = OSC_QUERY_ENABLE; 144 - osc_data->ctrlset_buf[OSC_CONTROL_TYPE] = OSC_CONTROL_MASKS; 78 + support_set = osc_data->support_set | (flags & OSC_SUPPORT_MASKS); 79 + osc_args.capbuf[OSC_QUERY_TYPE] = OSC_QUERY_ENABLE; 80 + osc_args.capbuf[OSC_SUPPORT_TYPE] = support_set; 81 + osc_args.capbuf[OSC_CONTROL_TYPE] = OSC_CONTROL_MASKS; 145 82 146 - /* Setting up input parameters */ 147 - input.count = 4; 148 - input.pointer = in_params; 149 - in_params[0].type = ACPI_TYPE_BUFFER; 150 - in_params[0].buffer.length = 16; 151 - in_params[0].buffer.pointer = OSC_UUID; 152 - in_params[1].type = ACPI_TYPE_INTEGER; 153 - in_params[1].integer.value = 1; 154 - in_params[2].type = ACPI_TYPE_INTEGER; 155 - in_params[2].integer.value = 3; 156 - in_params[3].type = ACPI_TYPE_BUFFER; 157 - in_params[3].buffer.length = 12; 158 - in_params[3].buffer.pointer = (u8 *)osc_data->ctrlset_buf; 159 - 160 - status = acpi_evaluate_object(handle, "_OSC", &input, &output); 161 - if (ACPI_FAILURE(status)) 162 - goto out_nofree; 163 - out_obj = output.pointer; 164 - 165 - if (out_obj->type != ACPI_TYPE_BUFFER) { 166 - printk(KERN_DEBUG 167 - "Evaluate _OSC returns wrong type\n"); 168 - status = AE_TYPE; 169 - goto query_osc_out; 170 - } 171 - osc_dw0 = *((u32 *) out_obj->buffer.pointer); 172 - if (osc_dw0) { 173 - if (osc_dw0 & OSC_REQUEST_ERROR) 174 - printk(KERN_DEBUG "_OSC request fails\n"); 175 - if (osc_dw0 & OSC_INVALID_UUID_ERROR) 176 - printk(KERN_DEBUG "_OSC invalid UUID\n"); 177 - if (osc_dw0 & OSC_INVALID_REVISION_ERROR) 178 - printk(KERN_DEBUG "_OSC invalid revision\n"); 179 - if (osc_dw0 & OSC_CAPABILITIES_MASK_ERROR) { 180 - /* Update Global Control Set */ 181 - osc_data->global_ctrlsets = 182 - *((u32 *)(out_obj->buffer.pointer + 8)); 183 - status = AE_OK; 184 - goto query_osc_out; 185 - } 186 - status = AE_ERROR; 187 - goto query_osc_out; 83 + status = acpi_run_osc(handle, &osc_args); 84 + if (ACPI_SUCCESS(status)) { 85 + osc_data->support_set = support_set; 86 + osc_data->query_result = osc_args.query_result; 87 + osc_data->is_queried = 1; 188 88 } 189 89 190 - /* Update Global Control Set */ 191 - osc_data->global_ctrlsets = *((u32 *)(out_obj->buffer.pointer + 8)); 192 - status = AE_OK; 193 - 194 - query_osc_out: 195 - kfree(output.pointer); 196 - out_nofree: 197 - *ret_status = status; 198 - 199 - osc_data->ctrlset_buf[OSC_QUERY_TYPE] = !OSC_QUERY_ENABLE; 200 - osc_data->ctrlset_buf[OSC_CONTROL_TYPE] = temp; 201 - if (ACPI_FAILURE(status)) { 202 - /* no osc support at all */ 203 - osc_data->ctrlset_buf[OSC_SUPPORT_TYPE] = 0; 204 - } 205 - 206 - return status; 207 - } 208 - 209 - 210 - static acpi_status 211 - acpi_run_osc ( 212 - acpi_handle handle, 213 - void *context) 214 - { 215 - acpi_status status; 216 - struct acpi_object_list input; 217 - union acpi_object in_params[4]; 218 - struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL}; 219 - union acpi_object *out_obj; 220 - u32 osc_dw0; 221 - 222 - /* Setting up input parameters */ 223 - input.count = 4; 224 - input.pointer = in_params; 225 - in_params[0].type = ACPI_TYPE_BUFFER; 226 - in_params[0].buffer.length = 16; 227 - in_params[0].buffer.pointer = OSC_UUID; 228 - in_params[1].type = ACPI_TYPE_INTEGER; 229 - in_params[1].integer.value = 1; 230 - in_params[2].type = ACPI_TYPE_INTEGER; 231 - in_params[2].integer.value = 3; 232 - in_params[3].type = ACPI_TYPE_BUFFER; 233 - in_params[3].buffer.length = 12; 234 - in_params[3].buffer.pointer = (u8 *)context; 235 - 236 - status = acpi_evaluate_object(handle, "_OSC", &input, &output); 237 - if (ACPI_FAILURE (status)) 238 - return status; 239 - 240 - out_obj = output.pointer; 241 - if (out_obj->type != ACPI_TYPE_BUFFER) { 242 - printk(KERN_DEBUG 243 - "Evaluate _OSC returns wrong type\n"); 244 - status = AE_TYPE; 245 - goto run_osc_out; 246 - } 247 - osc_dw0 = *((u32 *) out_obj->buffer.pointer); 248 - if (osc_dw0) { 249 - if (osc_dw0 & OSC_REQUEST_ERROR) 250 - printk(KERN_DEBUG "_OSC request fails\n"); 251 - if (osc_dw0 & OSC_INVALID_UUID_ERROR) 252 - printk(KERN_DEBUG "_OSC invalid UUID\n"); 253 - if (osc_dw0 & OSC_INVALID_REVISION_ERROR) 254 - printk(KERN_DEBUG "_OSC invalid revision\n"); 255 - if (osc_dw0 & OSC_CAPABILITIES_MASK_ERROR) { 256 - printk(KERN_DEBUG "_OSC FW not grant req. control\n"); 257 - status = AE_SUPPORT; 258 - goto run_osc_out; 259 - } 260 - status = AE_ERROR; 261 - goto run_osc_out; 262 - } 263 - status = AE_OK; 264 - 265 - run_osc_out: 266 - kfree(output.pointer); 267 90 return status; 268 91 } 269 92 ··· 162 215 **/ 163 216 acpi_status __pci_osc_support_set(u32 flags, const char *hid) 164 217 { 165 - acpi_status retval = AE_NOT_FOUND; 166 - 167 - if (!(flags & OSC_SUPPORT_MASKS)) { 218 + if (!(flags & OSC_SUPPORT_MASKS)) 168 219 return AE_TYPE; 169 - } 170 - acpi_get_devices(hid, 171 - acpi_query_osc, 172 - (void *)(unsigned long)flags, 173 - (void **) &retval ); 220 + 221 + acpi_get_devices(hid, acpi_query_osc, 222 + (void *)(unsigned long)flags, NULL); 174 223 return AE_OK; 175 224 } 176 225 ··· 179 236 **/ 180 237 acpi_status pci_osc_control_set(acpi_handle handle, u32 flags) 181 238 { 182 - acpi_status status; 183 - u32 ctrlset; 239 + acpi_status status; 240 + u32 ctrlset, control_set; 184 241 acpi_handle tmp; 185 242 struct acpi_osc_data *osc_data; 243 + struct acpi_osc_args osc_args; 186 244 187 245 status = acpi_get_handle(handle, "_OSC", &tmp); 188 246 if (ACPI_FAILURE(status)) ··· 196 252 } 197 253 198 254 ctrlset = (flags & OSC_CONTROL_MASKS); 199 - if (!ctrlset) { 255 + if (!ctrlset) 200 256 return AE_TYPE; 201 - } 202 - if (osc_data->ctrlset_buf[OSC_SUPPORT_TYPE] && 203 - ((osc_data->global_ctrlsets & ctrlset) != ctrlset)) { 257 + 258 + if (osc_data->is_queried && 259 + ((osc_data->query_result & ctrlset) != ctrlset)) 204 260 return AE_SUPPORT; 205 - } 206 - osc_data->ctrlset_buf[OSC_CONTROL_TYPE] |= ctrlset; 207 - status = acpi_run_osc(handle, osc_data->ctrlset_buf); 208 - if (ACPI_FAILURE (status)) { 209 - osc_data->ctrlset_buf[OSC_CONTROL_TYPE] &= ~ctrlset; 210 - } 211 - 261 + 262 + control_set = osc_data->control_set | ctrlset; 263 + osc_args.capbuf[OSC_QUERY_TYPE] = 0; 264 + osc_args.capbuf[OSC_SUPPORT_TYPE] = osc_data->support_set; 265 + osc_args.capbuf[OSC_CONTROL_TYPE] = control_set; 266 + status = acpi_run_osc(handle, &osc_args); 267 + if (ACPI_SUCCESS(status)) 268 + osc_data->control_set = control_set; 269 + 212 270 return status; 213 271 } 214 272 EXPORT_SYMBOL(pci_osc_control_set); 215 273 216 - #ifdef CONFIG_ACPI_SLEEP 217 274 /* 218 275 * _SxD returns the D-state with the highest power 219 276 * (lowest D-state number) supported in the S-state "x". ··· 258 313 } 259 314 return PCI_POWER_ERROR; 260 315 } 261 - #endif 316 + 317 + static bool acpi_pci_power_manageable(struct pci_dev *dev) 318 + { 319 + acpi_handle handle = DEVICE_ACPI_HANDLE(&dev->dev); 320 + 321 + return handle ? acpi_bus_power_manageable(handle) : false; 322 + } 262 323 263 324 static int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state) 264 325 { ··· 277 326 [PCI_D3hot] = ACPI_STATE_D3, 278 327 [PCI_D3cold] = ACPI_STATE_D3 279 328 }; 329 + int error = -EINVAL; 280 330 281 - if (!handle) 282 - return -ENODEV; 283 331 /* If the ACPI device has _EJ0, ignore the device */ 284 - if (ACPI_SUCCESS(acpi_get_handle(handle, "_EJ0", &tmp))) 285 - return 0; 332 + if (!handle || ACPI_SUCCESS(acpi_get_handle(handle, "_EJ0", &tmp))) 333 + return -ENODEV; 286 334 287 335 switch (state) { 288 336 case PCI_D0: ··· 289 339 case PCI_D2: 290 340 case PCI_D3hot: 291 341 case PCI_D3cold: 292 - return acpi_bus_set_power(handle, state_conv[state]); 342 + error = acpi_bus_set_power(handle, state_conv[state]); 293 343 } 294 - return -EINVAL; 344 + 345 + if (!error) 346 + dev_printk(KERN_INFO, &dev->dev, 347 + "power state changed by ACPI to D%d\n", state); 348 + 349 + return error; 295 350 } 296 351 352 + static bool acpi_pci_can_wakeup(struct pci_dev *dev) 353 + { 354 + acpi_handle handle = DEVICE_ACPI_HANDLE(&dev->dev); 355 + 356 + return handle ? acpi_bus_can_wakeup(handle) : false; 357 + } 358 + 359 + static int acpi_pci_sleep_wake(struct pci_dev *dev, bool enable) 360 + { 361 + int error = acpi_pm_device_sleep_wake(&dev->dev, enable); 362 + 363 + if (!error) 364 + dev_printk(KERN_INFO, &dev->dev, 365 + "wake-up capability %s by ACPI\n", 366 + enable ? "enabled" : "disabled"); 367 + return error; 368 + } 369 + 370 + static struct pci_platform_pm_ops acpi_pci_platform_pm = { 371 + .is_manageable = acpi_pci_power_manageable, 372 + .set_state = acpi_pci_set_power_state, 373 + .choose_state = acpi_pci_choose_state, 374 + .can_wakeup = acpi_pci_can_wakeup, 375 + .sleep_wake = acpi_pci_sleep_wake, 376 + }; 297 377 298 378 /* ACPI bus type */ 299 379 static int acpi_pci_find_device(struct device *dev, acpi_handle *handle) ··· 375 395 ret = register_acpi_bus_type(&acpi_pci_bus); 376 396 if (ret) 377 397 return 0; 378 - #ifdef CONFIG_ACPI_SLEEP 379 - platform_pci_choose_state = acpi_pci_choose_state; 380 - #endif 381 - platform_pci_set_power_state = acpi_pci_set_power_state; 398 + pci_set_platform_pm(&acpi_pci_platform_pm); 382 399 return 0; 383 400 } 384 401 arch_initcall(acpi_pci_init);
+346 -42
drivers/pci/pci-driver.c
··· 274 274 return 0; 275 275 } 276 276 277 - static int pci_device_suspend(struct device * dev, pm_message_t state) 277 + static void pci_device_shutdown(struct device *dev) 278 + { 279 + struct pci_dev *pci_dev = to_pci_dev(dev); 280 + struct pci_driver *drv = pci_dev->driver; 281 + 282 + if (drv && drv->shutdown) 283 + drv->shutdown(pci_dev); 284 + pci_msi_shutdown(pci_dev); 285 + pci_msix_shutdown(pci_dev); 286 + } 287 + 288 + #ifdef CONFIG_PM_SLEEP 289 + 290 + /* 291 + * Default "suspend" method for devices that have no driver provided suspend, 292 + * or not even a driver at all. 293 + */ 294 + static void pci_default_pm_suspend(struct pci_dev *pci_dev) 295 + { 296 + pci_save_state(pci_dev); 297 + /* 298 + * mark its power state as "unknown", since we don't know if 299 + * e.g. the BIOS will change its device state when we suspend. 300 + */ 301 + if (pci_dev->current_state == PCI_D0) 302 + pci_dev->current_state = PCI_UNKNOWN; 303 + } 304 + 305 + /* 306 + * Default "resume" method for devices that have no driver provided resume, 307 + * or not even a driver at all. 308 + */ 309 + static int pci_default_pm_resume(struct pci_dev *pci_dev) 310 + { 311 + int retval = 0; 312 + 313 + /* restore the PCI config space */ 314 + pci_restore_state(pci_dev); 315 + /* if the device was enabled before suspend, reenable */ 316 + retval = pci_reenable_device(pci_dev); 317 + /* 318 + * if the device was busmaster before the suspend, make it busmaster 319 + * again 320 + */ 321 + if (pci_dev->is_busmaster) 322 + pci_set_master(pci_dev); 323 + 324 + return retval; 325 + } 326 + 327 + static int pci_legacy_suspend(struct device *dev, pm_message_t state) 278 328 { 279 329 struct pci_dev * pci_dev = to_pci_dev(dev); 280 330 struct pci_driver * drv = pci_dev->driver; ··· 334 284 i = drv->suspend(pci_dev, state); 335 285 suspend_report_result(drv->suspend, i); 336 286 } else { 337 - pci_save_state(pci_dev); 338 - /* 339 - * mark its power state as "unknown", since we don't know if 340 - * e.g. the BIOS will change its device state when we suspend. 341 - */ 342 - if (pci_dev->current_state == PCI_D0) 343 - pci_dev->current_state = PCI_UNKNOWN; 287 + pci_default_pm_suspend(pci_dev); 344 288 } 345 289 return i; 346 290 } 347 291 348 - static int pci_device_suspend_late(struct device * dev, pm_message_t state) 292 + static int pci_legacy_suspend_late(struct device *dev, pm_message_t state) 349 293 { 350 294 struct pci_dev * pci_dev = to_pci_dev(dev); 351 295 struct pci_driver * drv = pci_dev->driver; ··· 352 308 return i; 353 309 } 354 310 355 - /* 356 - * Default resume method for devices that have no driver provided resume, 357 - * or not even a driver at all. 358 - */ 359 - static int pci_default_resume(struct pci_dev *pci_dev) 360 - { 361 - int retval = 0; 362 - 363 - /* restore the PCI config space */ 364 - pci_restore_state(pci_dev); 365 - /* if the device was enabled before suspend, reenable */ 366 - retval = pci_reenable_device(pci_dev); 367 - /* if the device was busmaster before the suspend, make it busmaster again */ 368 - if (pci_dev->is_busmaster) 369 - pci_set_master(pci_dev); 370 - 371 - return retval; 372 - } 373 - 374 - static int pci_device_resume(struct device * dev) 311 + static int pci_legacy_resume(struct device *dev) 375 312 { 376 313 int error; 377 314 struct pci_dev * pci_dev = to_pci_dev(dev); ··· 361 336 if (drv && drv->resume) 362 337 error = drv->resume(pci_dev); 363 338 else 364 - error = pci_default_resume(pci_dev); 339 + error = pci_default_pm_resume(pci_dev); 365 340 return error; 366 341 } 367 342 368 - static int pci_device_resume_early(struct device * dev) 343 + static int pci_legacy_resume_early(struct device *dev) 369 344 { 370 345 int error = 0; 371 346 struct pci_dev * pci_dev = to_pci_dev(dev); 372 347 struct pci_driver * drv = pci_dev->driver; 373 - 374 - pci_fixup_device(pci_fixup_resume, pci_dev); 375 348 376 349 if (drv && drv->resume_early) 377 350 error = drv->resume_early(pci_dev); 378 351 return error; 379 352 } 380 353 381 - static void pci_device_shutdown(struct device *dev) 354 + static int pci_pm_prepare(struct device *dev) 355 + { 356 + struct device_driver *drv = dev->driver; 357 + int error = 0; 358 + 359 + if (drv && drv->pm && drv->pm->prepare) 360 + error = drv->pm->prepare(dev); 361 + 362 + return error; 363 + } 364 + 365 + static void pci_pm_complete(struct device *dev) 366 + { 367 + struct device_driver *drv = dev->driver; 368 + 369 + if (drv && drv->pm && drv->pm->complete) 370 + drv->pm->complete(dev); 371 + } 372 + 373 + #ifdef CONFIG_SUSPEND 374 + 375 + static int pci_pm_suspend(struct device *dev) 376 + { 377 + struct pci_dev *pci_dev = to_pci_dev(dev); 378 + struct device_driver *drv = dev->driver; 379 + int error = 0; 380 + 381 + if (drv && drv->pm) { 382 + if (drv->pm->suspend) { 383 + error = drv->pm->suspend(dev); 384 + suspend_report_result(drv->pm->suspend, error); 385 + } else { 386 + pci_default_pm_suspend(pci_dev); 387 + } 388 + } else { 389 + error = pci_legacy_suspend(dev, PMSG_SUSPEND); 390 + } 391 + pci_fixup_device(pci_fixup_suspend, pci_dev); 392 + 393 + return error; 394 + } 395 + 396 + static int pci_pm_suspend_noirq(struct device *dev) 382 397 { 383 398 struct pci_dev *pci_dev = to_pci_dev(dev); 384 399 struct pci_driver *drv = pci_dev->driver; 400 + int error = 0; 385 401 386 - if (drv && drv->shutdown) 387 - drv->shutdown(pci_dev); 388 - pci_msi_shutdown(pci_dev); 389 - pci_msix_shutdown(pci_dev); 402 + if (drv && drv->pm) { 403 + if (drv->pm->suspend_noirq) { 404 + error = drv->pm->suspend_noirq(dev); 405 + suspend_report_result(drv->pm->suspend_noirq, error); 406 + } 407 + } else { 408 + error = pci_legacy_suspend_late(dev, PMSG_SUSPEND); 409 + } 410 + 411 + return error; 390 412 } 413 + 414 + static int pci_pm_resume(struct device *dev) 415 + { 416 + struct pci_dev *pci_dev = to_pci_dev(dev); 417 + struct device_driver *drv = dev->driver; 418 + int error; 419 + 420 + pci_fixup_device(pci_fixup_resume, pci_dev); 421 + 422 + if (drv && drv->pm) { 423 + error = drv->pm->resume ? drv->pm->resume(dev) : 424 + pci_default_pm_resume(pci_dev); 425 + } else { 426 + error = pci_legacy_resume(dev); 427 + } 428 + 429 + return error; 430 + } 431 + 432 + static int pci_pm_resume_noirq(struct device *dev) 433 + { 434 + struct pci_dev *pci_dev = to_pci_dev(dev); 435 + struct pci_driver *drv = pci_dev->driver; 436 + int error = 0; 437 + 438 + pci_fixup_device(pci_fixup_resume_early, pci_dev); 439 + 440 + if (drv && drv->pm) { 441 + if (drv->pm->resume_noirq) 442 + error = drv->pm->resume_noirq(dev); 443 + } else { 444 + error = pci_legacy_resume_early(dev); 445 + } 446 + 447 + return error; 448 + } 449 + 450 + #else /* !CONFIG_SUSPEND */ 451 + 452 + #define pci_pm_suspend NULL 453 + #define pci_pm_suspend_noirq NULL 454 + #define pci_pm_resume NULL 455 + #define pci_pm_resume_noirq NULL 456 + 457 + #endif /* !CONFIG_SUSPEND */ 458 + 459 + #ifdef CONFIG_HIBERNATION 460 + 461 + static int pci_pm_freeze(struct device *dev) 462 + { 463 + struct pci_dev *pci_dev = to_pci_dev(dev); 464 + struct device_driver *drv = dev->driver; 465 + int error = 0; 466 + 467 + if (drv && drv->pm) { 468 + if (drv->pm->freeze) { 469 + error = drv->pm->freeze(dev); 470 + suspend_report_result(drv->pm->freeze, error); 471 + } else { 472 + pci_default_pm_suspend(pci_dev); 473 + } 474 + } else { 475 + error = pci_legacy_suspend(dev, PMSG_FREEZE); 476 + pci_fixup_device(pci_fixup_suspend, pci_dev); 477 + } 478 + 479 + return error; 480 + } 481 + 482 + static int pci_pm_freeze_noirq(struct device *dev) 483 + { 484 + struct pci_dev *pci_dev = to_pci_dev(dev); 485 + struct pci_driver *drv = pci_dev->driver; 486 + int error = 0; 487 + 488 + if (drv && drv->pm) { 489 + if (drv->pm->freeze_noirq) { 490 + error = drv->pm->freeze_noirq(dev); 491 + suspend_report_result(drv->pm->freeze_noirq, error); 492 + } 493 + } else { 494 + error = pci_legacy_suspend_late(dev, PMSG_FREEZE); 495 + } 496 + 497 + return error; 498 + } 499 + 500 + static int pci_pm_thaw(struct device *dev) 501 + { 502 + struct device_driver *drv = dev->driver; 503 + int error = 0; 504 + 505 + if (drv && drv->pm) { 506 + if (drv->pm->thaw) 507 + error = drv->pm->thaw(dev); 508 + } else { 509 + pci_fixup_device(pci_fixup_resume, to_pci_dev(dev)); 510 + error = pci_legacy_resume(dev); 511 + } 512 + 513 + return error; 514 + } 515 + 516 + static int pci_pm_thaw_noirq(struct device *dev) 517 + { 518 + struct pci_dev *pci_dev = to_pci_dev(dev); 519 + struct pci_driver *drv = pci_dev->driver; 520 + int error = 0; 521 + 522 + if (drv && drv->pm) { 523 + if (drv->pm->thaw_noirq) 524 + error = drv->pm->thaw_noirq(dev); 525 + } else { 526 + pci_fixup_device(pci_fixup_resume_early, pci_dev); 527 + error = pci_legacy_resume_early(dev); 528 + } 529 + 530 + return error; 531 + } 532 + 533 + static int pci_pm_poweroff(struct device *dev) 534 + { 535 + struct device_driver *drv = dev->driver; 536 + int error = 0; 537 + 538 + pci_fixup_device(pci_fixup_suspend, to_pci_dev(dev)); 539 + 540 + if (drv && drv->pm) { 541 + if (drv->pm->poweroff) { 542 + error = drv->pm->poweroff(dev); 543 + suspend_report_result(drv->pm->poweroff, error); 544 + } 545 + } else { 546 + error = pci_legacy_suspend(dev, PMSG_HIBERNATE); 547 + } 548 + 549 + return error; 550 + } 551 + 552 + static int pci_pm_poweroff_noirq(struct device *dev) 553 + { 554 + struct pci_dev *pci_dev = to_pci_dev(dev); 555 + struct pci_driver *drv = pci_dev->driver; 556 + int error = 0; 557 + 558 + if (drv && drv->pm) { 559 + if (drv->pm->poweroff_noirq) { 560 + error = drv->pm->poweroff_noirq(dev); 561 + suspend_report_result(drv->pm->poweroff_noirq, error); 562 + } 563 + } else { 564 + error = pci_legacy_suspend_late(dev, PMSG_HIBERNATE); 565 + } 566 + 567 + return error; 568 + } 569 + 570 + static int pci_pm_restore(struct device *dev) 571 + { 572 + struct pci_dev *pci_dev = to_pci_dev(dev); 573 + struct device_driver *drv = dev->driver; 574 + int error; 575 + 576 + if (drv && drv->pm) { 577 + error = drv->pm->restore ? drv->pm->restore(dev) : 578 + pci_default_pm_resume(pci_dev); 579 + } else { 580 + error = pci_legacy_resume(dev); 581 + } 582 + pci_fixup_device(pci_fixup_resume, pci_dev); 583 + 584 + return error; 585 + } 586 + 587 + static int pci_pm_restore_noirq(struct device *dev) 588 + { 589 + struct pci_dev *pci_dev = to_pci_dev(dev); 590 + struct pci_driver *drv = pci_dev->driver; 591 + int error = 0; 592 + 593 + pci_fixup_device(pci_fixup_resume, pci_dev); 594 + 595 + if (drv && drv->pm) { 596 + if (drv->pm->restore_noirq) 597 + error = drv->pm->restore_noirq(dev); 598 + } else { 599 + error = pci_legacy_resume_early(dev); 600 + } 601 + pci_fixup_device(pci_fixup_resume_early, pci_dev); 602 + 603 + return error; 604 + } 605 + 606 + #else /* !CONFIG_HIBERNATION */ 607 + 608 + #define pci_pm_freeze NULL 609 + #define pci_pm_freeze_noirq NULL 610 + #define pci_pm_thaw NULL 611 + #define pci_pm_thaw_noirq NULL 612 + #define pci_pm_poweroff NULL 613 + #define pci_pm_poweroff_noirq NULL 614 + #define pci_pm_restore NULL 615 + #define pci_pm_restore_noirq NULL 616 + 617 + #endif /* !CONFIG_HIBERNATION */ 618 + 619 + struct pm_ext_ops pci_pm_ops = { 620 + .base = { 621 + .prepare = pci_pm_prepare, 622 + .complete = pci_pm_complete, 623 + .suspend = pci_pm_suspend, 624 + .resume = pci_pm_resume, 625 + .freeze = pci_pm_freeze, 626 + .thaw = pci_pm_thaw, 627 + .poweroff = pci_pm_poweroff, 628 + .restore = pci_pm_restore, 629 + }, 630 + .suspend_noirq = pci_pm_suspend_noirq, 631 + .resume_noirq = pci_pm_resume_noirq, 632 + .freeze_noirq = pci_pm_freeze_noirq, 633 + .thaw_noirq = pci_pm_thaw_noirq, 634 + .poweroff_noirq = pci_pm_poweroff_noirq, 635 + .restore_noirq = pci_pm_restore_noirq, 636 + }; 637 + 638 + #define PCI_PM_OPS_PTR &pci_pm_ops 639 + 640 + #else /* !CONFIG_PM_SLEEP */ 641 + 642 + #define PCI_PM_OPS_PTR NULL 643 + 644 + #endif /* !CONFIG_PM_SLEEP */ 391 645 392 646 /** 393 647 * __pci_register_driver - register a new pci driver ··· 689 385 drv->driver.bus = &pci_bus_type; 690 386 drv->driver.owner = owner; 691 387 drv->driver.mod_name = mod_name; 388 + 389 + if (drv->pm) 390 + drv->driver.pm = &drv->pm->base; 692 391 693 392 spin_lock_init(&drv->dynids.lock); 694 393 INIT_LIST_HEAD(&drv->dynids.list); ··· 818 511 .uevent = pci_uevent, 819 512 .probe = pci_device_probe, 820 513 .remove = pci_device_remove, 821 - .suspend = pci_device_suspend, 822 - .suspend_late = pci_device_suspend_late, 823 - .resume_early = pci_device_resume_early, 824 - .resume = pci_device_resume, 825 514 .shutdown = pci_device_shutdown, 826 515 .dev_attrs = pci_dev_attrs, 516 + .pm = PCI_PM_OPS_PTR, 827 517 }; 828 518 829 519 static int __init pci_driver_init(void)
+351 -130
drivers/pci/pci.c
··· 1 1 /* 2 - * $Id: pci.c,v 1.91 1999/01/21 13:34:01 davem Exp $ 3 - * 4 2 * PCI Bus Services, see include/linux/pci.h for further explanation. 5 3 * 6 4 * Copyright 1993 -- 1997 Drew Eckhardt, Frederic Potter, ··· 17 19 #include <linux/string.h> 18 20 #include <linux/log2.h> 19 21 #include <linux/pci-aspm.h> 22 + #include <linux/pm_wakeup.h> 20 23 #include <asm/dma.h> /* isa_dma_bridge_buggy */ 21 24 #include "pci.h" 22 25 ··· 377 378 pci_update_resource(dev, &dev->resource[i], i); 378 379 } 379 380 380 - int (*platform_pci_set_power_state)(struct pci_dev *dev, pci_power_t t); 381 + static struct pci_platform_pm_ops *pci_platform_pm; 382 + 383 + int pci_set_platform_pm(struct pci_platform_pm_ops *ops) 384 + { 385 + if (!ops->is_manageable || !ops->set_state || !ops->choose_state 386 + || !ops->sleep_wake || !ops->can_wakeup) 387 + return -EINVAL; 388 + pci_platform_pm = ops; 389 + return 0; 390 + } 391 + 392 + static inline bool platform_pci_power_manageable(struct pci_dev *dev) 393 + { 394 + return pci_platform_pm ? pci_platform_pm->is_manageable(dev) : false; 395 + } 396 + 397 + static inline int platform_pci_set_power_state(struct pci_dev *dev, 398 + pci_power_t t) 399 + { 400 + return pci_platform_pm ? pci_platform_pm->set_state(dev, t) : -ENOSYS; 401 + } 402 + 403 + static inline pci_power_t platform_pci_choose_state(struct pci_dev *dev) 404 + { 405 + return pci_platform_pm ? 406 + pci_platform_pm->choose_state(dev) : PCI_POWER_ERROR; 407 + } 408 + 409 + static inline bool platform_pci_can_wakeup(struct pci_dev *dev) 410 + { 411 + return pci_platform_pm ? pci_platform_pm->can_wakeup(dev) : false; 412 + } 413 + 414 + static inline int platform_pci_sleep_wake(struct pci_dev *dev, bool enable) 415 + { 416 + return pci_platform_pm ? 417 + pci_platform_pm->sleep_wake(dev, enable) : -ENODEV; 418 + } 381 419 382 420 /** 383 - * pci_set_power_state - Set the power state of a PCI device 384 - * @dev: PCI device to be suspended 385 - * @state: PCI power state (D0, D1, D2, D3hot, D3cold) we're entering 421 + * pci_raw_set_power_state - Use PCI PM registers to set the power state of 422 + * given PCI device 423 + * @dev: PCI device to handle. 424 + * @state: PCI power state (D0, D1, D2, D3hot) to put the device into. 386 425 * 387 - * Transition a device to a new power state, using the Power Management 388 - * Capabilities in the device's config space. 389 - * 390 - * RETURN VALUE: 391 - * -EINVAL if trying to enter a lower state than we're already in. 392 - * 0 if we're already in the requested state. 393 - * -EIO if device does not support PCI PM. 394 - * 0 if we can successfully change the power state. 426 + * RETURN VALUE: 427 + * -EINVAL if the requested state is invalid. 428 + * -EIO if device does not support PCI PM or its PM capabilities register has a 429 + * wrong version, or device doesn't support the requested state. 430 + * 0 if device already is in the requested state. 431 + * 0 if device's power state has been successfully changed. 395 432 */ 396 - int 397 - pci_set_power_state(struct pci_dev *dev, pci_power_t state) 433 + static int 434 + pci_raw_set_power_state(struct pci_dev *dev, pci_power_t state) 398 435 { 399 - int pm, need_restore = 0; 400 - u16 pmcsr, pmc; 436 + u16 pmcsr; 437 + bool need_restore = false; 401 438 402 - /* bound the state we're entering */ 403 - if (state > PCI_D3hot) 404 - state = PCI_D3hot; 405 - 406 - /* 407 - * If the device or the parent bridge can't support PCI PM, ignore 408 - * the request if we're doing anything besides putting it into D0 409 - * (which would only happen on boot). 410 - */ 411 - if ((state == PCI_D1 || state == PCI_D2) && pci_no_d1d2(dev)) 412 - return 0; 413 - 414 - /* find PCI PM capability in list */ 415 - pm = pci_find_capability(dev, PCI_CAP_ID_PM); 416 - 417 - /* abort if the device doesn't support PM capabilities */ 418 - if (!pm) 439 + if (!dev->pm_cap) 419 440 return -EIO; 441 + 442 + if (state < PCI_D0 || state > PCI_D3hot) 443 + return -EINVAL; 420 444 421 445 /* Validate current state: 422 446 * Can enter D0 from any state, but if we can only go deeper 423 447 * to sleep if we're already in a low power state 424 448 */ 425 - if (state != PCI_D0 && dev->current_state > state) { 426 - printk(KERN_ERR "%s(): %s: state=%d, current state=%d\n", 427 - __func__, pci_name(dev), state, dev->current_state); 449 + if (dev->current_state == state) { 450 + /* we're already there */ 451 + return 0; 452 + } else if (state != PCI_D0 && dev->current_state <= PCI_D3cold 453 + && dev->current_state > state) { 454 + dev_err(&dev->dev, "invalid power transition " 455 + "(from state %d to %d)\n", dev->current_state, state); 428 456 return -EINVAL; 429 - } else if (dev->current_state == state) 430 - return 0; /* we're already there */ 431 - 432 - 433 - pci_read_config_word(dev,pm + PCI_PM_PMC,&pmc); 434 - if ((pmc & PCI_PM_CAP_VER_MASK) > 3) { 435 - printk(KERN_DEBUG 436 - "PCI: %s has unsupported PM cap regs version (%u)\n", 437 - pci_name(dev), pmc & PCI_PM_CAP_VER_MASK); 438 - return -EIO; 439 457 } 440 458 441 459 /* check if this device supports the desired state */ 442 - if (state == PCI_D1 && !(pmc & PCI_PM_CAP_D1)) 443 - return -EIO; 444 - else if (state == PCI_D2 && !(pmc & PCI_PM_CAP_D2)) 460 + if ((state == PCI_D1 && !dev->d1_support) 461 + || (state == PCI_D2 && !dev->d2_support)) 445 462 return -EIO; 446 463 447 - pci_read_config_word(dev, pm + PCI_PM_CTRL, &pmcsr); 464 + pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr); 448 465 449 466 /* If we're (effectively) in D3, force entire word to 0. 450 467 * This doesn't affect PME_Status, disables PME_En, and ··· 476 461 case PCI_UNKNOWN: /* Boot-up */ 477 462 if ((pmcsr & PCI_PM_CTRL_STATE_MASK) == PCI_D3hot 478 463 && !(pmcsr & PCI_PM_CTRL_NO_SOFT_RESET)) 479 - need_restore = 1; 464 + need_restore = true; 480 465 /* Fall-through: force to D0 */ 481 466 default: 482 467 pmcsr = 0; ··· 484 469 } 485 470 486 471 /* enter specified state */ 487 - pci_write_config_word(dev, pm + PCI_PM_CTRL, pmcsr); 472 + pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, pmcsr); 488 473 489 474 /* Mandatory power management transition delays */ 490 475 /* see PCI PM 1.1 5.6.1 table 18 */ ··· 492 477 msleep(pci_pm_d3_delay); 493 478 else if (state == PCI_D2 || dev->current_state == PCI_D2) 494 479 udelay(200); 495 - 496 - /* 497 - * Give firmware a chance to be called, such as ACPI _PRx, _PSx 498 - * Firmware method after native method ? 499 - */ 500 - if (platform_pci_set_power_state) 501 - platform_pci_set_power_state(dev, state); 502 480 503 481 dev->current_state = state; 504 482 ··· 516 508 return 0; 517 509 } 518 510 519 - pci_power_t (*platform_pci_choose_state)(struct pci_dev *dev); 520 - 511 + /** 512 + * pci_update_current_state - Read PCI power state of given device from its 513 + * PCI PM registers and cache it 514 + * @dev: PCI device to handle. 515 + */ 516 + static void pci_update_current_state(struct pci_dev *dev) 517 + { 518 + if (dev->pm_cap) { 519 + u16 pmcsr; 520 + 521 + pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr); 522 + dev->current_state = (pmcsr & PCI_PM_CTRL_STATE_MASK); 523 + } 524 + } 525 + 526 + /** 527 + * pci_set_power_state - Set the power state of a PCI device 528 + * @dev: PCI device to handle. 529 + * @state: PCI power state (D0, D1, D2, D3hot) to put the device into. 530 + * 531 + * Transition a device to a new power state, using the platform formware and/or 532 + * the device's PCI PM registers. 533 + * 534 + * RETURN VALUE: 535 + * -EINVAL if the requested state is invalid. 536 + * -EIO if device does not support PCI PM or its PM capabilities register has a 537 + * wrong version, or device doesn't support the requested state. 538 + * 0 if device already is in the requested state. 539 + * 0 if device's power state has been successfully changed. 540 + */ 541 + int pci_set_power_state(struct pci_dev *dev, pci_power_t state) 542 + { 543 + int error; 544 + 545 + /* bound the state we're entering */ 546 + if (state > PCI_D3hot) 547 + state = PCI_D3hot; 548 + else if (state < PCI_D0) 549 + state = PCI_D0; 550 + else if ((state == PCI_D1 || state == PCI_D2) && pci_no_d1d2(dev)) 551 + /* 552 + * If the device or the parent bridge do not support PCI PM, 553 + * ignore the request if we're doing anything other than putting 554 + * it into D0 (which would only happen on boot). 555 + */ 556 + return 0; 557 + 558 + if (state == PCI_D0 && platform_pci_power_manageable(dev)) { 559 + /* 560 + * Allow the platform to change the state, for example via ACPI 561 + * _PR0, _PS0 and some such, but do not trust it. 562 + */ 563 + int ret = platform_pci_set_power_state(dev, PCI_D0); 564 + if (!ret) 565 + pci_update_current_state(dev); 566 + } 567 + 568 + error = pci_raw_set_power_state(dev, state); 569 + 570 + if (state > PCI_D0 && platform_pci_power_manageable(dev)) { 571 + /* Allow the platform to finalize the transition */ 572 + int ret = platform_pci_set_power_state(dev, state); 573 + if (!ret) { 574 + pci_update_current_state(dev); 575 + error = 0; 576 + } 577 + } 578 + 579 + return error; 580 + } 581 + 521 582 /** 522 583 * pci_choose_state - Choose the power state of a PCI device 523 584 * @dev: PCI device to be suspended ··· 604 527 if (!pci_find_capability(dev, PCI_CAP_ID_PM)) 605 528 return PCI_D0; 606 529 607 - if (platform_pci_choose_state) { 608 - ret = platform_pci_choose_state(dev); 609 - if (ret != PCI_POWER_ERROR) 610 - return ret; 611 - } 530 + ret = platform_pci_choose_state(dev); 531 + if (ret != PCI_POWER_ERROR) 532 + return ret; 612 533 613 534 switch (state.event) { 614 535 case PM_EVENT_ON: ··· 618 543 case PM_EVENT_HIBERNATE: 619 544 return PCI_D3hot; 620 545 default: 621 - printk("Unrecognized suspend event %d\n", state.event); 546 + dev_info(&dev->dev, "unrecognized suspend event %d\n", 547 + state.event); 622 548 BUG(); 623 549 } 624 550 return PCI_D0; ··· 644 568 else 645 569 found = 1; 646 570 if (!save_state) { 647 - dev_err(&dev->dev, "Out of memory in pci_save_pcie_state\n"); 571 + dev_err(&dev->dev, "out of memory in pci_save_pcie_state\n"); 648 572 return -ENOMEM; 649 573 } 650 574 cap = (u16 *)&save_state->data[0]; ··· 695 619 else 696 620 found = 1; 697 621 if (!save_state) { 698 - dev_err(&dev->dev, "Out of memory in pci_save_pcie_state\n"); 622 + dev_err(&dev->dev, "out of memory in pci_save_pcie_state\n"); 699 623 return -ENOMEM; 700 624 } 701 625 cap = (u16 *)&save_state->data[0]; ··· 761 685 for (i = 15; i >= 0; i--) { 762 686 pci_read_config_dword(dev, i * 4, &val); 763 687 if (val != dev->saved_config_space[i]) { 764 - printk(KERN_DEBUG "PM: Writing back config space on " 765 - "device %s at offset %x (was %x, writing %x)\n", 766 - pci_name(dev), i, 767 - val, (int)dev->saved_config_space[i]); 688 + dev_printk(KERN_DEBUG, &dev->dev, "restoring config " 689 + "space at offset %#x (was %#x, writing %#x)\n", 690 + i, val, (int)dev->saved_config_space[i]); 768 691 pci_write_config_dword(dev,i * 4, 769 692 dev->saved_config_space[i]); 770 693 } ··· 1036 961 } 1037 962 1038 963 /** 964 + * pci_pme_capable - check the capability of PCI device to generate PME# 965 + * @dev: PCI device to handle. 966 + * @state: PCI state from which device will issue PME#. 967 + */ 968 + static bool pci_pme_capable(struct pci_dev *dev, pci_power_t state) 969 + { 970 + if (!dev->pm_cap) 971 + return false; 972 + 973 + return !!(dev->pme_support & (1 << state)); 974 + } 975 + 976 + /** 977 + * pci_pme_active - enable or disable PCI device's PME# function 978 + * @dev: PCI device to handle. 979 + * @enable: 'true' to enable PME# generation; 'false' to disable it. 980 + * 981 + * The caller must verify that the device is capable of generating PME# before 982 + * calling this function with @enable equal to 'true'. 983 + */ 984 + static void pci_pme_active(struct pci_dev *dev, bool enable) 985 + { 986 + u16 pmcsr; 987 + 988 + if (!dev->pm_cap) 989 + return; 990 + 991 + pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr); 992 + /* Clear PME_Status by writing 1 to it and enable PME# */ 993 + pmcsr |= PCI_PM_CTRL_PME_STATUS | PCI_PM_CTRL_PME_ENABLE; 994 + if (!enable) 995 + pmcsr &= ~PCI_PM_CTRL_PME_ENABLE; 996 + 997 + pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, pmcsr); 998 + 999 + dev_printk(KERN_INFO, &dev->dev, "PME# %s\n", 1000 + enable ? "enabled" : "disabled"); 1001 + } 1002 + 1003 + /** 1039 1004 * pci_enable_wake - enable PCI device as wakeup event source 1040 1005 * @dev: PCI device affected 1041 1006 * @state: PCI state from which device will issue wakeup events ··· 1086 971 * called automatically by this routine. 1087 972 * 1088 973 * Devices with legacy power management (no standard PCI PM capabilities) 1089 - * always require such platform hooks. Depending on the platform, devices 1090 - * supporting the standard PCI PME# signal may require such platform hooks; 1091 - * they always update bits in config space to allow PME# generation. 974 + * always require such platform hooks. 1092 975 * 1093 - * -EIO is returned if the device can't ever be a wakeup event source. 1094 - * -EINVAL is returned if the device can't generate wakeup events from 1095 - * the specified PCI state. Returns zero if the operation is successful. 976 + * RETURN VALUE: 977 + * 0 is returned on success 978 + * -EINVAL is returned if device is not supposed to wake up the system 979 + * Error code depending on the platform is returned if both the platform and 980 + * the native mechanism fail to enable the generation of wake-up events 1096 981 */ 1097 982 int pci_enable_wake(struct pci_dev *dev, pci_power_t state, int enable) 1098 983 { 1099 - int pm; 1100 - int status; 1101 - u16 value; 984 + int error = 0; 985 + bool pme_done = false; 1102 986 1103 - /* Note that drivers should verify device_may_wakeup(&dev->dev) 1104 - * before calling this function. Platform code should report 1105 - * errors when drivers try to enable wakeup on devices that 1106 - * can't issue wakeups, or on which wakeups were disabled by 1107 - * userspace updating the /sys/devices.../power/wakeup file. 987 + if (!device_may_wakeup(&dev->dev)) 988 + return -EINVAL; 989 + 990 + /* 991 + * According to "PCI System Architecture" 4th ed. by Tom Shanley & Don 992 + * Anderson we should be doing PME# wake enable followed by ACPI wake 993 + * enable. To disable wake-up we call the platform first, for symmetry. 1108 994 */ 1109 995 1110 - status = call_platform_enable_wakeup(&dev->dev, enable); 996 + if (!enable && platform_pci_can_wakeup(dev)) 997 + error = platform_pci_sleep_wake(dev, false); 998 + 999 + if (!enable || pci_pme_capable(dev, state)) { 1000 + pci_pme_active(dev, enable); 1001 + pme_done = true; 1002 + } 1003 + 1004 + if (enable && platform_pci_can_wakeup(dev)) 1005 + error = platform_pci_sleep_wake(dev, true); 1006 + 1007 + return pme_done ? 0 : error; 1008 + } 1009 + 1010 + /** 1011 + * pci_prepare_to_sleep - prepare PCI device for system-wide transition into 1012 + * a sleep state 1013 + * @dev: Device to handle. 1014 + * 1015 + * Choose the power state appropriate for the device depending on whether 1016 + * it can wake up the system and/or is power manageable by the platform 1017 + * (PCI_D3hot is the default) and put the device into that state. 1018 + */ 1019 + int pci_prepare_to_sleep(struct pci_dev *dev) 1020 + { 1021 + pci_power_t target_state = PCI_D3hot; 1022 + int error; 1023 + 1024 + if (platform_pci_power_manageable(dev)) { 1025 + /* 1026 + * Call the platform to choose the target state of the device 1027 + * and enable wake-up from this state if supported. 1028 + */ 1029 + pci_power_t state = platform_pci_choose_state(dev); 1030 + 1031 + switch (state) { 1032 + case PCI_POWER_ERROR: 1033 + case PCI_UNKNOWN: 1034 + break; 1035 + case PCI_D1: 1036 + case PCI_D2: 1037 + if (pci_no_d1d2(dev)) 1038 + break; 1039 + default: 1040 + target_state = state; 1041 + } 1042 + } else if (device_may_wakeup(&dev->dev)) { 1043 + /* 1044 + * Find the deepest state from which the device can generate 1045 + * wake-up events, make it the target state and enable device 1046 + * to generate PME#. 1047 + */ 1048 + if (!dev->pm_cap) 1049 + return -EIO; 1050 + 1051 + if (dev->pme_support) { 1052 + while (target_state 1053 + && !(dev->pme_support & (1 << target_state))) 1054 + target_state--; 1055 + } 1056 + } 1057 + 1058 + pci_enable_wake(dev, target_state, true); 1059 + 1060 + error = pci_set_power_state(dev, target_state); 1061 + 1062 + if (error) 1063 + pci_enable_wake(dev, target_state, false); 1064 + 1065 + return error; 1066 + } 1067 + 1068 + /** 1069 + * pci_back_from_sleep - turn PCI device on during system-wide transition into 1070 + * the working state a sleep state 1071 + * @dev: Device to handle. 1072 + * 1073 + * Disable device's sytem wake-up capability and put it into D0. 1074 + */ 1075 + int pci_back_from_sleep(struct pci_dev *dev) 1076 + { 1077 + pci_enable_wake(dev, PCI_D0, false); 1078 + return pci_set_power_state(dev, PCI_D0); 1079 + } 1080 + 1081 + /** 1082 + * pci_pm_init - Initialize PM functions of given PCI device 1083 + * @dev: PCI device to handle. 1084 + */ 1085 + void pci_pm_init(struct pci_dev *dev) 1086 + { 1087 + int pm; 1088 + u16 pmc; 1089 + 1090 + dev->pm_cap = 0; 1111 1091 1112 1092 /* find PCI PM capability in list */ 1113 1093 pm = pci_find_capability(dev, PCI_CAP_ID_PM); 1114 - 1115 - /* If device doesn't support PM Capabilities, but caller wants to 1116 - * disable wake events, it's a NOP. Otherwise fail unless the 1117 - * platform hooks handled this legacy device already. 1118 - */ 1119 1094 if (!pm) 1120 - return enable ? status : 0; 1121 - 1095 + return; 1122 1096 /* Check device's ability to generate PME# */ 1123 - pci_read_config_word(dev,pm+PCI_PM_PMC,&value); 1097 + pci_read_config_word(dev, pm + PCI_PM_PMC, &pmc); 1124 1098 1125 - value &= PCI_PM_CAP_PME_MASK; 1126 - value >>= ffs(PCI_PM_CAP_PME_MASK) - 1; /* First bit of mask */ 1127 - 1128 - /* Check if it can generate PME# from requested state. */ 1129 - if (!value || !(value & (1 << state))) { 1130 - /* if it can't, revert what the platform hook changed, 1131 - * always reporting the base "EINVAL, can't PME#" error 1132 - */ 1133 - if (enable) 1134 - call_platform_enable_wakeup(&dev->dev, 0); 1135 - return enable ? -EINVAL : 0; 1099 + if ((pmc & PCI_PM_CAP_VER_MASK) > 3) { 1100 + dev_err(&dev->dev, "unsupported PM cap regs version (%u)\n", 1101 + pmc & PCI_PM_CAP_VER_MASK); 1102 + return; 1136 1103 } 1137 1104 1138 - pci_read_config_word(dev, pm + PCI_PM_CTRL, &value); 1105 + dev->pm_cap = pm; 1139 1106 1140 - /* Clear PME_Status by writing 1 to it and enable PME# */ 1141 - value |= PCI_PM_CTRL_PME_STATUS | PCI_PM_CTRL_PME_ENABLE; 1107 + dev->d1_support = false; 1108 + dev->d2_support = false; 1109 + if (!pci_no_d1d2(dev)) { 1110 + if (pmc & PCI_PM_CAP_D1) { 1111 + dev_printk(KERN_DEBUG, &dev->dev, "supports D1\n"); 1112 + dev->d1_support = true; 1113 + } 1114 + if (pmc & PCI_PM_CAP_D2) { 1115 + dev_printk(KERN_DEBUG, &dev->dev, "supports D2\n"); 1116 + dev->d2_support = true; 1117 + } 1118 + } 1142 1119 1143 - if (!enable) 1144 - value &= ~PCI_PM_CTRL_PME_ENABLE; 1145 - 1146 - pci_write_config_word(dev, pm + PCI_PM_CTRL, value); 1147 - 1148 - return 0; 1120 + pmc &= PCI_PM_CAP_PME_MASK; 1121 + if (pmc) { 1122 + dev_printk(KERN_INFO, &dev->dev, 1123 + "PME# supported from%s%s%s%s%s\n", 1124 + (pmc & PCI_PM_CAP_PME_D0) ? " D0" : "", 1125 + (pmc & PCI_PM_CAP_PME_D1) ? " D1" : "", 1126 + (pmc & PCI_PM_CAP_PME_D2) ? " D2" : "", 1127 + (pmc & PCI_PM_CAP_PME_D3) ? " D3hot" : "", 1128 + (pmc & PCI_PM_CAP_PME_D3cold) ? " D3cold" : ""); 1129 + dev->pme_support = pmc >> PCI_PM_CAP_PME_SHIFT; 1130 + /* 1131 + * Make device's PM flags reflect the wake-up capability, but 1132 + * let the user space enable it to wake up the system as needed. 1133 + */ 1134 + device_set_wakeup_capable(&dev->dev, true); 1135 + device_set_wakeup_enable(&dev->dev, false); 1136 + /* Disable the PME# generation functionality */ 1137 + pci_pme_active(dev, false); 1138 + } else { 1139 + dev->pme_support = 0; 1140 + } 1149 1141 } 1150 1142 1151 1143 int ··· 1338 1116 return 0; 1339 1117 1340 1118 err_out: 1341 - printk (KERN_WARNING "PCI: Unable to reserve %s region #%d:%llx@%llx " 1342 - "for device %s\n", 1343 - pci_resource_flags(pdev, bar) & IORESOURCE_IO ? "I/O" : "mem", 1344 - bar + 1, /* PCI BAR # */ 1345 - (unsigned long long)pci_resource_len(pdev, bar), 1346 - (unsigned long long)pci_resource_start(pdev, bar), 1347 - pci_name(pdev)); 1119 + dev_warn(&pdev->dev, "BAR %d: can't reserve %s region [%#llx-%#llx]\n", 1120 + bar, 1121 + pci_resource_flags(pdev, bar) & IORESOURCE_IO ? "I/O" : "mem", 1122 + (unsigned long long)pci_resource_start(pdev, bar), 1123 + (unsigned long long)pci_resource_end(pdev, bar)); 1348 1124 return -EBUSY; 1349 1125 } 1350 1126 ··· 1434 1214 1435 1215 pci_read_config_word(dev, PCI_COMMAND, &cmd); 1436 1216 if (! (cmd & PCI_COMMAND_MASTER)) { 1437 - pr_debug("PCI: Enabling bus mastering for device %s\n", pci_name(dev)); 1217 + dev_dbg(&dev->dev, "enabling bus mastering\n"); 1438 1218 cmd |= PCI_COMMAND_MASTER; 1439 1219 pci_write_config_word(dev, PCI_COMMAND, cmd); 1440 1220 } ··· 1499 1279 if (cacheline_size == pci_cache_line_size) 1500 1280 return 0; 1501 1281 1502 - printk(KERN_DEBUG "PCI: cache line size of %d is not supported " 1503 - "by device %s\n", pci_cache_line_size << 2, pci_name(dev)); 1282 + dev_printk(KERN_DEBUG, &dev->dev, "cache line size of %d is not " 1283 + "supported\n", pci_cache_line_size << 2); 1504 1284 1505 1285 return -EINVAL; 1506 1286 } ··· 1525 1305 1526 1306 pci_read_config_word(dev, PCI_COMMAND, &cmd); 1527 1307 if (! (cmd & PCI_COMMAND_INVALIDATE)) { 1528 - pr_debug("PCI: Enabling Mem-Wr-Inval for device %s\n", 1529 - pci_name(dev)); 1308 + dev_dbg(&dev->dev, "enabling Mem-Wr-Inval\n"); 1530 1309 cmd |= PCI_COMMAND_INVALIDATE; 1531 1310 pci_write_config_word(dev, PCI_COMMAND, cmd); 1532 1311 } ··· 1921 1702 EXPORT_SYMBOL(pci_save_state); 1922 1703 EXPORT_SYMBOL(pci_restore_state); 1923 1704 EXPORT_SYMBOL(pci_enable_wake); 1705 + EXPORT_SYMBOL(pci_prepare_to_sleep); 1706 + EXPORT_SYMBOL(pci_back_from_sleep); 1924 1707 EXPORT_SYMBOL_GPL(pci_set_pcie_reset_state); 1925 1708
+43 -4
drivers/pci/pci.h
··· 5 5 extern void pci_remove_sysfs_dev_files(struct pci_dev *pdev); 6 6 extern void pci_cleanup_rom(struct pci_dev *dev); 7 7 8 - /* Firmware callbacks */ 9 - extern pci_power_t (*platform_pci_choose_state)(struct pci_dev *dev); 10 - extern int (*platform_pci_set_power_state)(struct pci_dev *dev, 11 - pci_power_t state); 8 + /** 9 + * Firmware PM callbacks 10 + * 11 + * @is_manageable - returns 'true' if given device is power manageable by the 12 + * platform firmware 13 + * 14 + * @set_state - invokes the platform firmware to set the device's power state 15 + * 16 + * @choose_state - returns PCI power state of given device preferred by the 17 + * platform; to be used during system-wide transitions from a 18 + * sleeping state to the working state and vice versa 19 + * 20 + * @can_wakeup - returns 'true' if given device is capable of waking up the 21 + * system from a sleeping state 22 + * 23 + * @sleep_wake - enables/disables the system wake up capability of given device 24 + * 25 + * If given platform is generally capable of power managing PCI devices, all of 26 + * these callbacks are mandatory. 27 + */ 28 + struct pci_platform_pm_ops { 29 + bool (*is_manageable)(struct pci_dev *dev); 30 + int (*set_state)(struct pci_dev *dev, pci_power_t state); 31 + pci_power_t (*choose_state)(struct pci_dev *dev); 32 + bool (*can_wakeup)(struct pci_dev *dev); 33 + int (*sleep_wake)(struct pci_dev *dev, bool enable); 34 + }; 35 + 36 + extern int pci_set_platform_pm(struct pci_platform_pm_ops *ops); 37 + extern void pci_pm_init(struct pci_dev *dev); 12 38 13 39 extern int pci_user_read_config_byte(struct pci_dev *dev, int where, u8 *val); 14 40 extern int pci_user_read_config_word(struct pci_dev *dev, int where, u16 *val); ··· 131 105 } 132 106 133 107 struct pci_dev *pci_find_upstream_pcie_bridge(struct pci_dev *pdev); 108 + 109 + /* PCI slot sysfs helper code */ 110 + #define to_pci_slot(s) container_of(s, struct pci_slot, kobj) 111 + 112 + extern struct kset *pci_slots_kset; 113 + 114 + struct pci_slot_attribute { 115 + struct attribute attr; 116 + ssize_t (*show)(struct pci_slot *, char *); 117 + ssize_t (*store)(struct pci_slot *, const char *, size_t); 118 + }; 119 + #define to_pci_slot_attr(s) container_of(s, struct pci_slot_attribute, attr) 120 +
+4 -5
drivers/pci/pcie/aer/aerdrv.c
··· 26 26 #include <linux/pcieport_if.h> 27 27 28 28 #include "aerdrv.h" 29 + #include "../../pci.h" 29 30 30 31 /* 31 32 * Version Information ··· 220 219 221 220 /* Alloc rpc data structure */ 222 221 if (!(rpc = aer_alloc_rpc(dev))) { 223 - printk(KERN_DEBUG "%s: Alloc rpc fails on PCIE device[%s]\n", 224 - __func__, device->bus_id); 222 + dev_printk(KERN_DEBUG, device, "alloc rpc failed\n"); 225 223 aer_remove(dev); 226 224 return -ENOMEM; 227 225 } ··· 228 228 /* Request IRQ ISR */ 229 229 if ((status = request_irq(dev->irq, aer_irq, IRQF_SHARED, "aerdrv", 230 230 dev))) { 231 - printk(KERN_DEBUG "%s: Request ISR fails on PCIE device[%s]\n", 232 - __func__, device->bus_id); 231 + dev_printk(KERN_DEBUG, device, "request IRQ failed\n"); 233 232 aer_remove(dev); 234 233 return status; 235 234 } ··· 272 273 * to issue Configuration Requests to those devices. 273 274 */ 274 275 msleep(200); 275 - printk(KERN_DEBUG "Complete link reset at Root[%s]\n", dev->dev.bus_id); 276 + dev_printk(KERN_DEBUG, &dev->dev, "Root Port link has been reset\n"); 276 277 277 278 /* Enable Root Port's interrupt in response to error messages */ 278 279 pci_read_config_dword(dev, pos + PCI_ERR_ROOT_STATUS, &status);
+4 -4
drivers/pci/pcie/aer/aerdrv_acpi.c
··· 50 50 } 51 51 52 52 if (ACPI_FAILURE(status)) { 53 - printk(KERN_DEBUG "AER service couldn't init device %s - %s\n", 54 - pciedev->device.bus_id, 55 - (status == AE_SUPPORT || status == AE_NOT_FOUND) ? 56 - "no _OSC support" : "Run ACPI _OSC fails"); 53 + dev_printk(KERN_DEBUG, &pciedev->device, "AER service couldn't " 54 + "init device: %s\n", 55 + (status == AE_SUPPORT || status == AE_NOT_FOUND) ? 56 + "no _OSC support" : "_OSC failed"); 57 57 return -1; 58 58 } 59 59
+12 -12
drivers/pci/pcie/aer/aerdrv_core.c
··· 221 221 * of a driver for this device is unaware of 222 222 * its hw state. 223 223 */ 224 - printk(KERN_DEBUG "Device ID[%s] has %s\n", 225 - dev->dev.bus_id, (dev->driver) ? 226 - "no AER-aware driver" : "no driver"); 224 + dev_printk(KERN_DEBUG, &dev->dev, "device has %s\n", 225 + dev->driver ? 226 + "no AER-aware driver" : "no driver"); 227 227 } 228 228 return; 229 229 } ··· 304 304 { 305 305 struct aer_broadcast_data result_data; 306 306 307 - printk(KERN_DEBUG "Broadcast %s message\n", error_mesg); 307 + dev_printk(KERN_DEBUG, &dev->dev, "broadcast %s message\n", error_mesg); 308 308 result_data.state = state; 309 309 if (cb == report_error_detected) 310 310 result_data.result = PCI_ERS_RESULT_CAN_RECOVER; ··· 404 404 data.aer_driver = 405 405 to_service_driver(aerdev->device.driver); 406 406 } else { 407 - printk(KERN_DEBUG "No link-reset support to Device ID" 408 - "[%s]\n", 409 - dev->dev.bus_id); 407 + dev_printk(KERN_DEBUG, &dev->dev, "no link-reset " 408 + "support\n"); 410 409 return PCI_ERS_RESULT_DISCONNECT; 411 410 } 412 411 } 413 412 414 413 status = data.aer_driver->reset_link(udev); 415 414 if (status != PCI_ERS_RESULT_RECOVERED) { 416 - printk(KERN_DEBUG "Link reset at upstream Device ID" 417 - "[%s] failed\n", 418 - udev->dev.bus_id); 415 + dev_printk(KERN_DEBUG, &dev->dev, "link reset at upstream " 416 + "device %s failed\n", pci_name(udev)); 419 417 return PCI_ERS_RESULT_DISCONNECT; 420 418 } 421 419 ··· 509 511 } else { 510 512 status = do_recovery(aerdev, dev, info.severity); 511 513 if (status == PCI_ERS_RESULT_RECOVERED) { 512 - printk(KERN_DEBUG "AER driver successfully recovered\n"); 514 + dev_printk(KERN_DEBUG, &dev->dev, "AER driver " 515 + "successfully recovered\n"); 513 516 } else { 514 517 /* TODO: Should kernel panic here? */ 515 - printk(KERN_DEBUG "AER driver didn't recover\n"); 518 + dev_printk(KERN_DEBUG, &dev->dev, "AER driver didn't " 519 + "recover\n"); 516 520 } 517 521 } 518 522 }
+1
drivers/pci/pcie/portdrv_bus.c
··· 13 13 #include <linux/pm.h> 14 14 15 15 #include <linux/pcieport_if.h> 16 + #include "portdrv.h" 16 17 17 18 static int pcie_port_bus_match(struct device *dev, struct device_driver *drv); 18 19 static int pcie_port_bus_suspend(struct device *dev, pm_message_t state);
+11 -11
drivers/pci/pcie/portdrv_core.c
··· 23 23 { 24 24 struct pcie_device *pciedev; 25 25 struct pcie_port_service_driver *driver; 26 - int status = -ENODEV; 26 + int status; 27 27 28 28 if (!dev || !dev->driver) 29 - return status; 29 + return -ENODEV; 30 30 31 31 driver = to_service_driver(dev->driver); 32 32 if (!driver || !driver->probe) 33 - return status; 33 + return -ENODEV; 34 34 35 35 pciedev = to_pcie_device(dev); 36 36 status = driver->probe(pciedev, driver->id_table); 37 37 if (!status) { 38 - printk(KERN_DEBUG "Load service driver %s on pcie device %s\n", 39 - driver->name, dev->bus_id); 38 + dev_printk(KERN_DEBUG, dev, "service driver %s loaded\n", 39 + driver->name); 40 40 get_device(dev); 41 41 } 42 42 return status; ··· 53 53 pciedev = to_pcie_device(dev); 54 54 driver = to_service_driver(dev->driver); 55 55 if (driver && driver->remove) { 56 - printk(KERN_DEBUG "Unload service driver %s on pcie device %s\n", 57 - driver->name, dev->bus_id); 56 + dev_printk(KERN_DEBUG, dev, "unloading service driver %s\n", 57 + driver->name); 58 58 driver->remove(pciedev); 59 59 put_device(dev); 60 60 } ··· 103 103 */ 104 104 static void release_pcie_device(struct device *dev) 105 105 { 106 - printk(KERN_DEBUG "Free Port Service[%s]\n", dev->bus_id); 106 + dev_printk(KERN_DEBUG, dev, "free port service\n"); 107 107 kfree(to_pcie_device(dev)); 108 108 } 109 109 ··· 150 150 if (pos) { 151 151 struct msix_entry msix_entries[PCIE_PORT_DEVICE_MAXSERVICES] = 152 152 {{0, 0}, {0, 1}, {0, 2}, {0, 3}}; 153 - printk("%s Found MSIX capability\n", __func__); 153 + dev_info(&dev->dev, "found MSI-X capability\n"); 154 154 status = pci_enable_msix(dev, msix_entries, nvec); 155 155 if (!status) { 156 156 int j = 0; ··· 165 165 if (status) { 166 166 pos = pci_find_capability(dev, PCI_CAP_ID_MSI); 167 167 if (pos) { 168 - printk("%s Found MSI capability\n", __func__); 168 + dev_info(&dev->dev, "found MSI capability\n"); 169 169 status = pci_enable_msi(dev); 170 170 if (!status) { 171 171 interrupt_mode = PCIE_PORT_MSI_MODE; ··· 252 252 return NULL; 253 253 254 254 pcie_device_init(parent, device, port_type, service_type, irq,irq_mode); 255 - printk(KERN_DEBUG "Allocate Port Service[%s]\n", device->device.bus_id); 255 + dev_printk(KERN_DEBUG, &device->device, "allocate port service\n"); 256 256 return device; 257 257 } 258 258
+2 -3
drivers/pci/pcie/portdrv_pci.c
··· 91 91 92 92 pci_set_master(dev); 93 93 if (!dev->irq && dev->pin) { 94 - printk(KERN_WARNING 95 - "%s->Dev[%04x:%04x] has invalid IRQ. Check vendor BIOS\n", 96 - __func__, dev->vendor, dev->device); 94 + dev_warn(&dev->dev, "device [%04x/%04x] has invalid IRQ; " 95 + "check vendor BIOS\n", dev->vendor, dev->device); 97 96 } 98 97 if (pcie_port_device_register(dev)) { 99 98 pci_disable_device(dev);
+22 -16
drivers/pci/probe.c
··· 277 277 res->end = res->start + sz64; 278 278 #else 279 279 if (sz64 > 0x100000000ULL) { 280 - printk(KERN_ERR "PCI: Unable to handle 64-bit " 281 - "BAR for device %s\n", pci_name(dev)); 280 + dev_err(&dev->dev, "BAR %d: can't handle 64-bit" 281 + " BAR\n", pos); 282 282 res->start = 0; 283 283 res->flags = 0; 284 284 } else if (lhi) { ··· 329 329 return; 330 330 331 331 if (dev->transparent) { 332 - printk(KERN_INFO "PCI: Transparent bridge - %s\n", pci_name(dev)); 332 + dev_info(&dev->dev, "transparent bridge\n"); 333 333 for(i = 3; i < PCI_BUS_NUM_RESOURCES; i++) 334 334 child->resource[i] = child->parent->resource[i - 3]; 335 335 } ··· 392 392 limit |= ((long) mem_limit_hi) << 32; 393 393 #else 394 394 if (mem_base_hi || mem_limit_hi) { 395 - printk(KERN_ERR "PCI: Unable to handle 64-bit address space for bridge %s\n", pci_name(dev)); 395 + dev_err(&dev->dev, "can't handle 64-bit " 396 + "address space for bridge\n"); 396 397 return; 397 398 } 398 399 #endif ··· 415 414 INIT_LIST_HEAD(&b->node); 416 415 INIT_LIST_HEAD(&b->children); 417 416 INIT_LIST_HEAD(&b->devices); 417 + INIT_LIST_HEAD(&b->slots); 418 418 } 419 419 return b; 420 420 } ··· 513 511 514 512 pci_read_config_dword(dev, PCI_PRIMARY_BUS, &buses); 515 513 516 - pr_debug("PCI: Scanning behind PCI bridge %s, config %06x, pass %d\n", 517 - pci_name(dev), buses & 0xffffff, pass); 514 + dev_dbg(&dev->dev, "scanning behind bridge, config %06x, pass %d\n", 515 + buses & 0xffffff, pass); 518 516 519 517 /* Disable MasterAbortMode during probing to avoid reporting 520 518 of bus errors (in some architectures) */ ··· 537 535 * ignore it. This can happen with the i450NX chipset. 538 536 */ 539 537 if (pci_find_bus(pci_domain_nr(bus), busnr)) { 540 - printk(KERN_INFO "PCI: Bus %04x:%02x already known\n", 541 - pci_domain_nr(bus), busnr); 538 + dev_info(&dev->dev, "bus %04x:%02x already known\n", 539 + pci_domain_nr(bus), busnr); 542 540 goto out; 543 541 } 544 542 ··· 713 711 { 714 712 u32 class; 715 713 716 - sprintf(pci_name(dev), "%04x:%02x:%02x.%d", pci_domain_nr(dev->bus), 717 - dev->bus->number, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn)); 714 + dev_set_name(&dev->dev, "%04x:%02x:%02x.%d", pci_domain_nr(dev->bus), 715 + dev->bus->number, PCI_SLOT(dev->devfn), 716 + PCI_FUNC(dev->devfn)); 718 717 719 718 pci_read_config_dword(dev, PCI_CLASS_REVISION, &class); 720 719 dev->revision = class & 0xff; ··· 723 720 dev->class = class; 724 721 class >>= 8; 725 722 726 - pr_debug("PCI: Found %s [%04x/%04x] %06x %02x\n", pci_name(dev), 723 + dev_dbg(&dev->dev, "found [%04x/%04x] class %06x header type %02x\n", 727 724 dev->vendor, dev->device, class, dev->hdr_type); 728 725 729 726 /* "Unknown power state" */ ··· 791 788 break; 792 789 793 790 default: /* unknown header */ 794 - printk(KERN_ERR "PCI: device %s has unknown header type %02x, ignoring.\n", 795 - pci_name(dev), dev->hdr_type); 791 + dev_err(&dev->dev, "unknown header type %02x, " 792 + "ignoring device\n", dev->hdr_type); 796 793 return -1; 797 794 798 795 bad: 799 - printk(KERN_ERR "PCI: %s: class %x doesn't match header type %02x. Ignoring class.\n", 800 - pci_name(dev), class, dev->hdr_type); 796 + dev_err(&dev->dev, "ignoring class %02x (doesn't match header " 797 + "type %02x)\n", class, dev->hdr_type); 801 798 dev->class = PCI_CLASS_NOT_DEFINED; 802 799 } 803 800 ··· 930 927 return NULL; 931 928 /* Card hasn't responded in 60 seconds? Must be stuck. */ 932 929 if (delay > 60 * 1000) { 933 - printk(KERN_WARNING "Device %04x:%02x:%02x.%d not " 930 + printk(KERN_WARNING "pci %04x:%02x:%02x.%d: not " 934 931 "responding\n", pci_domain_nr(bus), 935 932 bus->number, PCI_SLOT(devfn), 936 933 PCI_FUNC(devfn)); ··· 986 983 987 984 /* Fix up broken headers */ 988 985 pci_fixup_device(pci_fixup_header, dev); 986 + 987 + /* Initialize power management of the device */ 988 + pci_pm_init(dev); 989 989 990 990 /* 991 991 * Add the device to our list of discovered devices
+1 -3
drivers/pci/proc.c
··· 1 1 /* 2 - * $Id: proc.c,v 1.13 1998/05/12 07:36:07 mj Exp $ 3 - * 4 2 * Procfs interface for the PCI bus. 5 3 * 6 4 * Copyright (c) 1997--1999 Martin Mares <mj@ucw.cz> ··· 480 482 return 0; 481 483 } 482 484 483 - __initcall(pci_proc_init); 485 + device_initcall(pci_proc_init); 484 486
+97 -37
drivers/pci/quirks.c
··· 556 556 pci_write_config_byte (dev, 0x58, tmp); 557 557 } 558 558 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686, quirk_via_ioapic); 559 - DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686, quirk_via_ioapic); 559 + DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686, quirk_via_ioapic); 560 560 561 561 /* 562 562 * VIA 8237: Some BIOSs don't set the 'Bypass APIC De-Assert Message' Bit. ··· 576 576 } 577 577 } 578 578 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, quirk_via_vt8237_bypass_apic_deassert); 579 - DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, quirk_via_vt8237_bypass_apic_deassert); 579 + DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, quirk_via_vt8237_bypass_apic_deassert); 580 580 581 581 /* 582 582 * The AMD io apic can hang the box when an apic irq is masked. ··· 622 622 } 623 623 } 624 624 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE, quirk_amd_8131_ioapic); 625 - DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE, quirk_amd_8131_ioapic); 625 + DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE, quirk_amd_8131_ioapic); 626 626 #endif /* CONFIG_X86_IO_APIC */ 627 627 628 628 /* ··· 774 774 pci_write_config_dword(dev, PCI_CB_LEGACY_MODE_BASE, 0); 775 775 } 776 776 DECLARE_PCI_FIXUP_FINAL(PCI_ANY_ID, PCI_ANY_ID, quirk_cardbus_legacy); 777 - DECLARE_PCI_FIXUP_RESUME(PCI_ANY_ID, PCI_ANY_ID, quirk_cardbus_legacy); 777 + DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_ANY_ID, PCI_ANY_ID, quirk_cardbus_legacy); 778 778 779 779 /* 780 780 * Following the PCI ordering rules is optional on the AMD762. I'm not ··· 797 797 } 798 798 } 799 799 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_FE_GATE_700C, quirk_amd_ordering); 800 - DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_FE_GATE_700C, quirk_amd_ordering); 800 + DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_FE_GATE_700C, quirk_amd_ordering); 801 801 802 802 /* 803 803 * DreamWorks provided workaround for Dunord I-3000 problem ··· 865 865 } 866 866 } 867 867 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82454NX, quirk_disable_pxb); 868 - DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82454NX, quirk_disable_pxb); 868 + DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82454NX, quirk_disable_pxb); 869 869 870 870 static void __devinit quirk_amd_ide_mode(struct pci_dev *pdev) 871 871 { ··· 885 885 } 886 886 } 887 887 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP600_SATA, quirk_amd_ide_mode); 888 - DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP600_SATA, quirk_amd_ide_mode); 888 + DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP600_SATA, quirk_amd_ide_mode); 889 889 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP700_SATA, quirk_amd_ide_mode); 890 - DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP700_SATA, quirk_amd_ide_mode); 890 + DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP700_SATA, quirk_amd_ide_mode); 891 891 892 892 /* 893 893 * Serverworks CSB5 IDE does not fully support native mode ··· 1054 1054 * its on-board VGA controller */ 1055 1055 asus_hides_smbus = 1; 1056 1056 } 1057 + else if (dev->device == PCI_DEVICE_ID_INTEL_82845G_IG) 1058 + switch(dev->subsystem_device) { 1059 + case 0x00b8: /* Compaq Evo D510 CMT */ 1060 + case 0x00b9: /* Compaq Evo D510 SFF */ 1061 + asus_hides_smbus = 1; 1062 + } 1063 + else if (dev->device == PCI_DEVICE_ID_INTEL_82815_CGC) 1064 + switch (dev->subsystem_device) { 1065 + case 0x001A: /* Compaq Deskpro EN SSF P667 815E */ 1066 + /* Motherboard doesn't have host bridge 1067 + * subvendor/subdevice IDs, therefore checking 1068 + * its on-board VGA controller */ 1069 + asus_hides_smbus = 1; 1070 + } 1057 1071 } 1058 1072 } 1059 1073 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82845_HB, asus_hides_smbus_hostbridge); ··· 1082 1068 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82915GM_HB, asus_hides_smbus_hostbridge); 1083 1069 1084 1070 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82810_IG3, asus_hides_smbus_hostbridge); 1071 + DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82845G_IG, asus_hides_smbus_hostbridge); 1072 + DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82815_CGC, asus_hides_smbus_hostbridge); 1085 1073 1086 1074 static void asus_hides_smbus_lpc(struct pci_dev *dev) 1087 1075 { ··· 1109 1093 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12, asus_hides_smbus_lpc); 1110 1094 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12, asus_hides_smbus_lpc); 1111 1095 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0, asus_hides_smbus_lpc); 1112 - DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_0, asus_hides_smbus_lpc); 1113 - DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0, asus_hides_smbus_lpc); 1114 - DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0, asus_hides_smbus_lpc); 1115 - DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0, asus_hides_smbus_lpc); 1116 - DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12, asus_hides_smbus_lpc); 1117 - DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12, asus_hides_smbus_lpc); 1118 - DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0, asus_hides_smbus_lpc); 1096 + DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_0, asus_hides_smbus_lpc); 1097 + DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0, asus_hides_smbus_lpc); 1098 + DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0, asus_hides_smbus_lpc); 1099 + DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0, asus_hides_smbus_lpc); 1100 + DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12, asus_hides_smbus_lpc); 1101 + DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12, asus_hides_smbus_lpc); 1102 + DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0, asus_hides_smbus_lpc); 1119 1103 1120 - static void asus_hides_smbus_lpc_ich6(struct pci_dev *dev) 1104 + /* It appears we just have one such device. If not, we have a warning */ 1105 + static void __iomem *asus_rcba_base; 1106 + static void asus_hides_smbus_lpc_ich6_suspend(struct pci_dev *dev) 1121 1107 { 1122 - u32 val, rcba; 1123 - void __iomem *base; 1108 + u32 rcba; 1124 1109 1125 1110 if (likely(!asus_hides_smbus)) 1126 1111 return; 1112 + WARN_ON(asus_rcba_base); 1113 + 1127 1114 pci_read_config_dword(dev, 0xF0, &rcba); 1128 - base = ioremap_nocache(rcba & 0xFFFFC000, 0x4000); /* use bits 31:14, 16 kB aligned */ 1129 - if (base == NULL) return; 1130 - val=readl(base + 0x3418); /* read the Function Disable register, dword mode only */ 1131 - writel(val & 0xFFFFFFF7, base + 0x3418); /* enable the SMBus device */ 1132 - iounmap(base); 1115 + /* use bits 31:14, 16 kB aligned */ 1116 + asus_rcba_base = ioremap_nocache(rcba & 0xFFFFC000, 0x4000); 1117 + if (asus_rcba_base == NULL) 1118 + return; 1119 + } 1120 + 1121 + static void asus_hides_smbus_lpc_ich6_resume_early(struct pci_dev *dev) 1122 + { 1123 + u32 val; 1124 + 1125 + if (likely(!asus_hides_smbus || !asus_rcba_base)) 1126 + return; 1127 + /* read the Function Disable register, dword mode only */ 1128 + val = readl(asus_rcba_base + 0x3418); 1129 + writel(val & 0xFFFFFFF7, asus_rcba_base + 0x3418); /* enable the SMBus device */ 1130 + } 1131 + 1132 + static void asus_hides_smbus_lpc_ich6_resume(struct pci_dev *dev) 1133 + { 1134 + if (likely(!asus_hides_smbus || !asus_rcba_base)) 1135 + return; 1136 + iounmap(asus_rcba_base); 1137 + asus_rcba_base = NULL; 1133 1138 dev_info(&dev->dev, "Enabled ICH6/i801 SMBus device\n"); 1134 1139 } 1140 + 1141 + static void asus_hides_smbus_lpc_ich6(struct pci_dev *dev) 1142 + { 1143 + asus_hides_smbus_lpc_ich6_suspend(dev); 1144 + asus_hides_smbus_lpc_ich6_resume_early(dev); 1145 + asus_hides_smbus_lpc_ich6_resume(dev); 1146 + } 1135 1147 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, asus_hides_smbus_lpc_ich6); 1136 - DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, asus_hides_smbus_lpc_ich6); 1148 + DECLARE_PCI_FIXUP_SUSPEND(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, asus_hides_smbus_lpc_ich6_suspend); 1149 + DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, asus_hides_smbus_lpc_ich6_resume); 1150 + DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, asus_hides_smbus_lpc_ich6_resume_early); 1137 1151 1138 1152 /* 1139 1153 * SiS 96x south bridge: BIOS typically hides SMBus device... ··· 1181 1135 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_962, quirk_sis_96x_smbus); 1182 1136 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_963, quirk_sis_96x_smbus); 1183 1137 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC, quirk_sis_96x_smbus); 1184 - DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_961, quirk_sis_96x_smbus); 1185 - DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_962, quirk_sis_96x_smbus); 1186 - DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_963, quirk_sis_96x_smbus); 1187 - DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC, quirk_sis_96x_smbus); 1138 + DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_961, quirk_sis_96x_smbus); 1139 + DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_962, quirk_sis_96x_smbus); 1140 + DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_963, quirk_sis_96x_smbus); 1141 + DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC, quirk_sis_96x_smbus); 1188 1142 1189 1143 /* 1190 1144 * ... This is further complicated by the fact that some SiS96x south ··· 1218 1172 quirk_sis_96x_smbus(dev); 1219 1173 } 1220 1174 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503, quirk_sis_503); 1221 - DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503, quirk_sis_503); 1175 + DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503, quirk_sis_503); 1222 1176 1223 1177 1224 1178 /* ··· 1251 1205 } 1252 1206 } 1253 1207 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, asus_hides_ac97_lpc); 1254 - DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, asus_hides_ac97_lpc); 1208 + DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, asus_hides_ac97_lpc); 1255 1209 1256 1210 #if defined(CONFIG_ATA) || defined(CONFIG_ATA_MODULE) 1257 1211 ··· 1316 1270 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB365, quirk_jmicron_ata); 1317 1271 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB366, quirk_jmicron_ata); 1318 1272 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB368, quirk_jmicron_ata); 1319 - DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB360, quirk_jmicron_ata); 1320 - DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB361, quirk_jmicron_ata); 1321 - DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB363, quirk_jmicron_ata); 1322 - DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB365, quirk_jmicron_ata); 1323 - DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB366, quirk_jmicron_ata); 1324 - DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB368, quirk_jmicron_ata); 1273 + DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB360, quirk_jmicron_ata); 1274 + DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB361, quirk_jmicron_ata); 1275 + DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB363, quirk_jmicron_ata); 1276 + DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB365, quirk_jmicron_ata); 1277 + DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB366, quirk_jmicron_ata); 1278 + DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB368, quirk_jmicron_ata); 1325 1279 1326 1280 #endif 1327 1281 ··· 1567 1521 extern struct pci_fixup __end_pci_fixups_enable[]; 1568 1522 extern struct pci_fixup __start_pci_fixups_resume[]; 1569 1523 extern struct pci_fixup __end_pci_fixups_resume[]; 1524 + extern struct pci_fixup __start_pci_fixups_resume_early[]; 1525 + extern struct pci_fixup __end_pci_fixups_resume_early[]; 1526 + extern struct pci_fixup __start_pci_fixups_suspend[]; 1527 + extern struct pci_fixup __end_pci_fixups_suspend[]; 1570 1528 1571 1529 1572 1530 void pci_fixup_device(enum pci_fixup_pass pass, struct pci_dev *dev) ··· 1601 1551 case pci_fixup_resume: 1602 1552 start = __start_pci_fixups_resume; 1603 1553 end = __end_pci_fixups_resume; 1554 + break; 1555 + 1556 + case pci_fixup_resume_early: 1557 + start = __start_pci_fixups_resume_early; 1558 + end = __end_pci_fixups_resume_early; 1559 + break; 1560 + 1561 + case pci_fixup_suspend: 1562 + start = __start_pci_fixups_suspend; 1563 + end = __end_pci_fixups_suspend; 1604 1564 break; 1605 1565 1606 1566 default: ··· 1689 1629 } 1690 1630 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_CK804_PCIE, 1691 1631 quirk_nvidia_ck804_pcie_aer_ext_cap); 1692 - DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_CK804_PCIE, 1632 + DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_CK804_PCIE, 1693 1633 quirk_nvidia_ck804_pcie_aer_ext_cap); 1694 1634 1695 1635 static void __devinit quirk_via_cx700_pci_parking_caching(struct pci_dev *dev)
+18 -25
drivers/pci/setup-bus.c
··· 27 27 #include <linux/slab.h> 28 28 29 29 30 - #define DEBUG_CONFIG 1 31 - #if DEBUG_CONFIG 32 - #define DBG(x...) printk(x) 33 - #else 34 - #define DBG(x...) 35 - #endif 36 - 37 30 static void pbus_assign_resources_sorted(struct pci_bus *bus) 38 31 { 39 32 struct pci_dev *dev; ··· 74 81 struct pci_dev *bridge = bus->self; 75 82 struct pci_bus_region region; 76 83 77 - printk("PCI: Bus %d, cardbus bridge: %s\n", 78 - bus->number, pci_name(bridge)); 84 + dev_info(&bridge->dev, "CardBus bridge, secondary bus %04x:%02x\n", 85 + pci_domain_nr(bus), bus->number); 79 86 80 87 pcibios_resource_to_bus(bridge, &region, bus->resource[0]); 81 88 if (bus->resource[0]->flags & IORESOURCE_IO) { ··· 83 90 * The IO resource is allocated a range twice as large as it 84 91 * would normally need. This allows us to set both IO regs. 85 92 */ 86 - printk(KERN_INFO " IO window: 0x%08lx-0x%08lx\n", 93 + dev_info(&bridge->dev, " IO window: %#08lx-%#08lx\n", 87 94 (unsigned long)region.start, 88 95 (unsigned long)region.end); 89 96 pci_write_config_dword(bridge, PCI_CB_IO_BASE_0, ··· 94 101 95 102 pcibios_resource_to_bus(bridge, &region, bus->resource[1]); 96 103 if (bus->resource[1]->flags & IORESOURCE_IO) { 97 - printk(KERN_INFO " IO window: 0x%08lx-0x%08lx\n", 104 + dev_info(&bridge->dev, " IO window: %#08lx-%#08lx\n", 98 105 (unsigned long)region.start, 99 106 (unsigned long)region.end); 100 107 pci_write_config_dword(bridge, PCI_CB_IO_BASE_1, ··· 105 112 106 113 pcibios_resource_to_bus(bridge, &region, bus->resource[2]); 107 114 if (bus->resource[2]->flags & IORESOURCE_MEM) { 108 - printk(KERN_INFO " PREFETCH window: 0x%08lx-0x%08lx\n", 115 + dev_info(&bridge->dev, " PREFETCH window: %#08lx-%#08lx\n", 109 116 (unsigned long)region.start, 110 117 (unsigned long)region.end); 111 118 pci_write_config_dword(bridge, PCI_CB_MEMORY_BASE_0, ··· 116 123 117 124 pcibios_resource_to_bus(bridge, &region, bus->resource[3]); 118 125 if (bus->resource[3]->flags & IORESOURCE_MEM) { 119 - printk(KERN_INFO " MEM window: 0x%08lx-0x%08lx\n", 126 + dev_info(&bridge->dev, " MEM window: %#08lx-%#08lx\n", 120 127 (unsigned long)region.start, 121 128 (unsigned long)region.end); 122 129 pci_write_config_dword(bridge, PCI_CB_MEMORY_BASE_1, ··· 144 151 struct pci_bus_region region; 145 152 u32 l, bu, lu, io_upper16; 146 153 147 - DBG(KERN_INFO "PCI: Bridge: %s\n", pci_name(bridge)); 154 + dev_info(&bridge->dev, "PCI bridge, secondary bus %04x:%02x\n", 155 + pci_domain_nr(bus), bus->number); 148 156 149 157 /* Set up the top and bottom of the PCI I/O segment for this bus. */ 150 158 pcibios_resource_to_bus(bridge, &region, bus->resource[0]); ··· 156 162 l |= region.end & 0xf000; 157 163 /* Set up upper 16 bits of I/O base/limit. */ 158 164 io_upper16 = (region.end & 0xffff0000) | (region.start >> 16); 159 - DBG(KERN_INFO " IO window: %04lx-%04lx\n", 165 + dev_info(&bridge->dev, " IO window: %#04lx-%#04lx\n", 160 166 (unsigned long)region.start, 161 167 (unsigned long)region.end); 162 168 } ··· 164 170 /* Clear upper 16 bits of I/O base/limit. */ 165 171 io_upper16 = 0; 166 172 l = 0x00f0; 167 - DBG(KERN_INFO " IO window: disabled.\n"); 173 + dev_info(&bridge->dev, " IO window: disabled\n"); 168 174 } 169 175 /* Temporarily disable the I/O range before updating PCI_IO_BASE. */ 170 176 pci_write_config_dword(bridge, PCI_IO_BASE_UPPER16, 0x0000ffff); ··· 179 185 if (bus->resource[1]->flags & IORESOURCE_MEM) { 180 186 l = (region.start >> 16) & 0xfff0; 181 187 l |= region.end & 0xfff00000; 182 - DBG(KERN_INFO " MEM window: 0x%08lx-0x%08lx\n", 188 + dev_info(&bridge->dev, " MEM window: %#08lx-%#08lx\n", 183 189 (unsigned long)region.start, 184 190 (unsigned long)region.end); 185 191 } 186 192 else { 187 193 l = 0x0000fff0; 188 - DBG(KERN_INFO " MEM window: disabled.\n"); 194 + dev_info(&bridge->dev, " MEM window: disabled\n"); 189 195 } 190 196 pci_write_config_dword(bridge, PCI_MEMORY_BASE, l); 191 197 ··· 202 208 l |= region.end & 0xfff00000; 203 209 bu = upper_32_bits(region.start); 204 210 lu = upper_32_bits(region.end); 205 - DBG(KERN_INFO " PREFETCH window: 0x%016llx-0x%016llx\n", 211 + dev_info(&bridge->dev, " PREFETCH window: %#016llx-%#016llx\n", 206 212 (unsigned long long)region.start, 207 213 (unsigned long long)region.end); 208 214 } 209 215 else { 210 216 l = 0x0000fff0; 211 - DBG(KERN_INFO " PREFETCH window: disabled.\n"); 217 + dev_info(&bridge->dev, " PREFETCH window: disabled\n"); 212 218 } 213 219 pci_write_config_dword(bridge, PCI_PREF_MEMORY_BASE, l); 214 220 ··· 355 361 align = (i < PCI_BRIDGE_RESOURCES) ? r_size : r->start; 356 362 order = __ffs(align) - 20; 357 363 if (order > 11) { 358 - printk(KERN_WARNING "PCI: region %s/%d " 359 - "too large: 0x%016llx-0x%016llx\n", 360 - pci_name(dev), i, 364 + dev_warn(&dev->dev, "BAR %d too large: " 365 + "%#016llx-%#016llx\n", i, 361 366 (unsigned long long)r->start, 362 367 (unsigned long long)r->end); 363 368 r->flags = 0; ··· 522 529 break; 523 530 524 531 default: 525 - printk(KERN_INFO "PCI: not setting up bridge %s " 526 - "for bus %d\n", pci_name(dev), b->number); 532 + dev_info(&dev->dev, "not setting up bridge for bus " 533 + "%04x:%02x\n", pci_domain_nr(b), b->number); 527 534 break; 528 535 } 529 536 }
+1 -2
drivers/pci/setup-irq.c
··· 47 47 } 48 48 dev->irq = irq; 49 49 50 - pr_debug("PCI: fixup irq: (%s) got %d\n", 51 - kobject_name(&dev->dev.kobj), dev->irq); 50 + dev_dbg(&dev->dev, "fixup irq: got %d\n", dev->irq); 52 51 53 52 /* Always tell the device, so the driver knows what is 54 53 the real IRQ to use; the device does not use it. */
+33 -37
drivers/pci/setup-res.c
··· 26 26 #include "pci.h" 27 27 28 28 29 - void 30 - pci_update_resource(struct pci_dev *dev, struct resource *res, int resno) 29 + void pci_update_resource(struct pci_dev *dev, struct resource *res, int resno) 31 30 { 32 31 struct pci_bus_region region; 33 32 u32 new, check, mask; ··· 42 43 /* 43 44 * Ignore non-moveable resources. This might be legacy resources for 44 45 * which no functional BAR register exists or another important 45 - * system resource we should better not move around in system address 46 - * space. 46 + * system resource we shouldn't move around. 47 47 */ 48 48 if (res->flags & IORESOURCE_PCI_FIXED) 49 49 return; 50 50 51 51 pcibios_resource_to_bus(dev, &region, res); 52 52 53 - pr_debug(" got res [%llx:%llx] bus [%llx:%llx] flags %lx for " 54 - "BAR %d of %s\n", (unsigned long long)res->start, 53 + dev_dbg(&dev->dev, "BAR %d: got res [%#llx-%#llx] bus [%#llx-%#llx] " 54 + "flags %#lx\n", resno, 55 + (unsigned long long)res->start, 55 56 (unsigned long long)res->end, 56 57 (unsigned long long)region.start, 57 58 (unsigned long long)region.end, 58 - (unsigned long)res->flags, resno, pci_name(dev)); 59 + (unsigned long)res->flags); 59 60 60 61 new = region.start | (res->flags & PCI_REGION_FLAG_MASK); 61 62 if (res->flags & IORESOURCE_IO) ··· 80 81 pci_read_config_dword(dev, reg, &check); 81 82 82 83 if ((new ^ check) & mask) { 83 - printk(KERN_ERR "PCI: Error while updating region " 84 - "%s/%d (%08x != %08x)\n", pci_name(dev), resno, 85 - new, check); 84 + dev_err(&dev->dev, "BAR %d: error updating (%#08x != %#08x)\n", 85 + resno, new, check); 86 86 } 87 87 88 88 if ((new & (PCI_BASE_ADDRESS_SPACE|PCI_BASE_ADDRESS_MEM_TYPE_MASK)) == ··· 90 92 pci_write_config_dword(dev, reg + 4, new); 91 93 pci_read_config_dword(dev, reg + 4, &check); 92 94 if (check != new) { 93 - printk(KERN_ERR "PCI: Error updating region " 94 - "%s/%d (high %08x != %08x)\n", 95 - pci_name(dev), resno, new, check); 95 + dev_err(&dev->dev, "BAR %d: error updating " 96 + "(high %#08x != %#08x)\n", resno, new, check); 96 97 } 97 98 } 98 99 res->flags &= ~IORESOURCE_UNSET; 99 - pr_debug("PCI: moved device %s resource %d (%lx) to %x\n", 100 - pci_name(dev), resno, res->flags, 101 - new & ~PCI_REGION_FLAG_MASK); 100 + dev_dbg(&dev->dev, "BAR %d: moved to bus [%#llx-%#llx] flags %#lx\n", 101 + resno, (unsigned long long)region.start, 102 + (unsigned long long)region.end, res->flags); 102 103 } 103 104 104 105 int pci_claim_resource(struct pci_dev *dev, int resource) ··· 114 117 err = insert_resource(root, res); 115 118 116 119 if (err) { 117 - printk(KERN_ERR "PCI: %s region %d of %s %s [%llx:%llx]\n", 118 - root ? "Address space collision on" : 119 - "No parent found for", 120 - resource, dtype, pci_name(dev), 120 + dev_err(&dev->dev, "BAR %d: %s of %s [%#llx-%#llx]\n", 121 + resource, 122 + root ? "address space collision on" : 123 + "no parent found for", 124 + dtype, 121 125 (unsigned long long)res->start, 122 126 (unsigned long long)res->end); 123 127 } ··· 138 140 139 141 align = resource_alignment(res); 140 142 if (!align) { 141 - printk(KERN_ERR "PCI: Cannot allocate resource (bogus " 142 - "alignment) %d [%llx:%llx] (flags %lx) of %s\n", 143 + dev_err(&dev->dev, "BAR %d: can't allocate resource (bogus " 144 + "alignment) [%#llx-%#llx] flags %#lx\n", 143 145 resno, (unsigned long long)res->start, 144 - (unsigned long long)res->end, res->flags, 145 - pci_name(dev)); 146 + (unsigned long long)res->end, res->flags); 146 147 return -EINVAL; 147 148 } 148 149 ··· 162 165 } 163 166 164 167 if (ret) { 165 - printk(KERN_ERR "PCI: Failed to allocate %s resource " 166 - "#%d:%llx@%llx for %s\n", 168 + dev_err(&dev->dev, "BAR %d: can't allocate %s resource " 169 + "[%#llx-%#llx]\n", resno, 167 170 res->flags & IORESOURCE_IO ? "I/O" : "mem", 168 - resno, (unsigned long long)size, 169 - (unsigned long long)res->start, pci_name(dev)); 171 + (unsigned long long)res->start, 172 + (unsigned long long)res->end); 170 173 } else { 171 174 res->flags &= ~IORESOURCE_STARTALIGN; 172 175 if (resno < PCI_BRIDGE_RESOURCES) ··· 202 205 } 203 206 204 207 if (ret) { 205 - printk(KERN_ERR "PCI: Failed to allocate %s resource " 206 - "#%d:%llx@%llx for %s\n", 208 + dev_err(&dev->dev, "BAR %d: can't allocate %s resource " 209 + "[%#llx-%#llx\n]", resno, 207 210 res->flags & IORESOURCE_IO ? "I/O" : "mem", 208 - resno, (unsigned long long)(res->end - res->start + 1), 209 - (unsigned long long)res->start, pci_name(dev)); 211 + (unsigned long long)res->start, 212 + (unsigned long long)res->end); 210 213 } else if (resno < PCI_BRIDGE_RESOURCES) { 211 214 pci_update_resource(dev, res, resno); 212 215 } ··· 236 239 237 240 r_align = resource_alignment(r); 238 241 if (!r_align) { 239 - printk(KERN_WARNING "PCI: bogus alignment of resource " 240 - "%d [%llx:%llx] (flags %lx) of %s\n", 242 + dev_warn(&dev->dev, "BAR %d: bogus alignment " 243 + "[%#llx-%#llx] flags %#lx\n", 241 244 i, (unsigned long long)r->start, 242 - (unsigned long long)r->end, r->flags, 243 - pci_name(dev)); 245 + (unsigned long long)r->end, r->flags); 244 246 continue; 245 247 } 246 248 for (list = head; ; list = list->next) { ··· 287 291 288 292 if (!r->parent) { 289 293 dev_err(&dev->dev, "device not available because of " 290 - "BAR %d [%llx:%llx] collisions\n", i, 294 + "BAR %d [%#llx-%#llx] collisions\n", i, 291 295 (unsigned long long) r->start, 292 296 (unsigned long long) r->end); 293 297 return -EINVAL;
+233
drivers/pci/slot.c
··· 1 + /* 2 + * drivers/pci/slot.c 3 + * Copyright (C) 2006 Matthew Wilcox <matthew@wil.cx> 4 + * Copyright (C) 2006-2008 Hewlett-Packard Development Company, L.P. 5 + * Alex Chiang <achiang@hp.com> 6 + */ 7 + 8 + #include <linux/kobject.h> 9 + #include <linux/pci.h> 10 + #include <linux/err.h> 11 + #include "pci.h" 12 + 13 + struct kset *pci_slots_kset; 14 + EXPORT_SYMBOL_GPL(pci_slots_kset); 15 + 16 + static ssize_t pci_slot_attr_show(struct kobject *kobj, 17 + struct attribute *attr, char *buf) 18 + { 19 + struct pci_slot *slot = to_pci_slot(kobj); 20 + struct pci_slot_attribute *attribute = to_pci_slot_attr(attr); 21 + return attribute->show ? attribute->show(slot, buf) : -EIO; 22 + } 23 + 24 + static ssize_t pci_slot_attr_store(struct kobject *kobj, 25 + struct attribute *attr, const char *buf, size_t len) 26 + { 27 + struct pci_slot *slot = to_pci_slot(kobj); 28 + struct pci_slot_attribute *attribute = to_pci_slot_attr(attr); 29 + return attribute->store ? attribute->store(slot, buf, len) : -EIO; 30 + } 31 + 32 + static struct sysfs_ops pci_slot_sysfs_ops = { 33 + .show = pci_slot_attr_show, 34 + .store = pci_slot_attr_store, 35 + }; 36 + 37 + static ssize_t address_read_file(struct pci_slot *slot, char *buf) 38 + { 39 + if (slot->number == 0xff) 40 + return sprintf(buf, "%04x:%02x\n", 41 + pci_domain_nr(slot->bus), 42 + slot->bus->number); 43 + else 44 + return sprintf(buf, "%04x:%02x:%02x\n", 45 + pci_domain_nr(slot->bus), 46 + slot->bus->number, 47 + slot->number); 48 + } 49 + 50 + static void pci_slot_release(struct kobject *kobj) 51 + { 52 + struct pci_slot *slot = to_pci_slot(kobj); 53 + 54 + pr_debug("%s: releasing pci_slot on %x:%d\n", __func__, 55 + slot->bus->number, slot->number); 56 + 57 + list_del(&slot->list); 58 + 59 + kfree(slot); 60 + } 61 + 62 + static struct pci_slot_attribute pci_slot_attr_address = 63 + __ATTR(address, (S_IFREG | S_IRUGO), address_read_file, NULL); 64 + 65 + static struct attribute *pci_slot_default_attrs[] = { 66 + &pci_slot_attr_address.attr, 67 + NULL, 68 + }; 69 + 70 + static struct kobj_type pci_slot_ktype = { 71 + .sysfs_ops = &pci_slot_sysfs_ops, 72 + .release = &pci_slot_release, 73 + .default_attrs = pci_slot_default_attrs, 74 + }; 75 + 76 + /** 77 + * pci_create_slot - create or increment refcount for physical PCI slot 78 + * @parent: struct pci_bus of parent bridge 79 + * @slot_nr: PCI_SLOT(pci_dev->devfn) or -1 for placeholder 80 + * @name: user visible string presented in /sys/bus/pci/slots/<name> 81 + * 82 + * PCI slots have first class attributes such as address, speed, width, 83 + * and a &struct pci_slot is used to manage them. This interface will 84 + * either return a new &struct pci_slot to the caller, or if the pci_slot 85 + * already exists, its refcount will be incremented. 86 + * 87 + * Slots are uniquely identified by a @pci_bus, @slot_nr, @name tuple. 88 + * 89 + * Placeholder slots: 90 + * In most cases, @pci_bus, @slot_nr will be sufficient to uniquely identify 91 + * a slot. There is one notable exception - pSeries (rpaphp), where the 92 + * @slot_nr cannot be determined until a device is actually inserted into 93 + * the slot. In this scenario, the caller may pass -1 for @slot_nr. 94 + * 95 + * The following semantics are imposed when the caller passes @slot_nr == 96 + * -1. First, the check for existing %struct pci_slot is skipped, as the 97 + * caller may know about several unpopulated slots on a given %struct 98 + * pci_bus, and each slot would have a @slot_nr of -1. Uniqueness for 99 + * these slots is then determined by the @name parameter. We expect 100 + * kobject_init_and_add() to warn us if the caller attempts to create 101 + * multiple slots with the same name. The other change in semantics is 102 + * user-visible, which is the 'address' parameter presented in sysfs will 103 + * consist solely of a dddd:bb tuple, where dddd is the PCI domain of the 104 + * %struct pci_bus and bb is the bus number. In other words, the devfn of 105 + * the 'placeholder' slot will not be displayed. 106 + */ 107 + 108 + struct pci_slot *pci_create_slot(struct pci_bus *parent, int slot_nr, 109 + const char *name) 110 + { 111 + struct pci_slot *slot; 112 + int err; 113 + 114 + down_write(&pci_bus_sem); 115 + 116 + if (slot_nr == -1) 117 + goto placeholder; 118 + 119 + /* If we've already created this slot, bump refcount and return. */ 120 + list_for_each_entry(slot, &parent->slots, list) { 121 + if (slot->number == slot_nr) { 122 + kobject_get(&slot->kobj); 123 + pr_debug("%s: inc refcount to %d on %04x:%02x:%02x\n", 124 + __func__, 125 + atomic_read(&slot->kobj.kref.refcount), 126 + pci_domain_nr(parent), parent->number, 127 + slot_nr); 128 + goto out; 129 + } 130 + } 131 + 132 + placeholder: 133 + slot = kzalloc(sizeof(*slot), GFP_KERNEL); 134 + if (!slot) { 135 + slot = ERR_PTR(-ENOMEM); 136 + goto out; 137 + } 138 + 139 + slot->bus = parent; 140 + slot->number = slot_nr; 141 + 142 + slot->kobj.kset = pci_slots_kset; 143 + err = kobject_init_and_add(&slot->kobj, &pci_slot_ktype, NULL, 144 + "%s", name); 145 + if (err) { 146 + printk(KERN_ERR "Unable to register kobject %s\n", name); 147 + goto err; 148 + } 149 + 150 + INIT_LIST_HEAD(&slot->list); 151 + list_add(&slot->list, &parent->slots); 152 + 153 + /* Don't care if debug printk has a -1 for slot_nr */ 154 + pr_debug("%s: created pci_slot on %04x:%02x:%02x\n", 155 + __func__, pci_domain_nr(parent), parent->number, slot_nr); 156 + 157 + out: 158 + up_write(&pci_bus_sem); 159 + return slot; 160 + err: 161 + kfree(slot); 162 + slot = ERR_PTR(err); 163 + goto out; 164 + } 165 + EXPORT_SYMBOL_GPL(pci_create_slot); 166 + 167 + /** 168 + * pci_update_slot_number - update %struct pci_slot -> number 169 + * @slot - %struct pci_slot to update 170 + * @slot_nr - new number for slot 171 + * 172 + * The primary purpose of this interface is to allow callers who earlier 173 + * created a placeholder slot in pci_create_slot() by passing a -1 as 174 + * slot_nr, to update their %struct pci_slot with the correct @slot_nr. 175 + */ 176 + 177 + void pci_update_slot_number(struct pci_slot *slot, int slot_nr) 178 + { 179 + int name_count = 0; 180 + struct pci_slot *tmp; 181 + 182 + down_write(&pci_bus_sem); 183 + 184 + list_for_each_entry(tmp, &slot->bus->slots, list) { 185 + WARN_ON(tmp->number == slot_nr); 186 + if (!strcmp(kobject_name(&tmp->kobj), kobject_name(&slot->kobj))) 187 + name_count++; 188 + } 189 + 190 + if (name_count > 1) 191 + printk(KERN_WARNING "pci_update_slot_number found %d slots with the same name: %s\n", name_count, kobject_name(&slot->kobj)); 192 + 193 + slot->number = slot_nr; 194 + up_write(&pci_bus_sem); 195 + } 196 + EXPORT_SYMBOL_GPL(pci_update_slot_number); 197 + 198 + /** 199 + * pci_destroy_slot - decrement refcount for physical PCI slot 200 + * @slot: struct pci_slot to decrement 201 + * 202 + * %struct pci_slot is refcounted, so destroying them is really easy; we 203 + * just call kobject_put on its kobj and let our release methods do the 204 + * rest. 205 + */ 206 + 207 + void pci_destroy_slot(struct pci_slot *slot) 208 + { 209 + pr_debug("%s: dec refcount to %d on %04x:%02x:%02x\n", __func__, 210 + atomic_read(&slot->kobj.kref.refcount) - 1, 211 + pci_domain_nr(slot->bus), slot->bus->number, slot->number); 212 + 213 + down_write(&pci_bus_sem); 214 + kobject_put(&slot->kobj); 215 + up_write(&pci_bus_sem); 216 + } 217 + EXPORT_SYMBOL_GPL(pci_destroy_slot); 218 + 219 + static int pci_slot_init(void) 220 + { 221 + struct kset *pci_bus_kset; 222 + 223 + pci_bus_kset = bus_get_kset(&pci_bus_type); 224 + pci_slots_kset = kset_create_and_add("slots", NULL, 225 + &pci_bus_kset->kobj); 226 + if (!pci_slots_kset) { 227 + printk(KERN_ERR "PCI: Slot initialization failure\n"); 228 + return -ENOMEM; 229 + } 230 + return 0; 231 + } 232 + 233 + subsys_initcall(pci_slot_init);
+8
include/acpi/acpi_bus.h
··· 259 259 /* Wakeup Management */ 260 260 struct acpi_device_wakeup_flags { 261 261 u8 valid:1; /* Can successfully enable wakeup? */ 262 + u8 prepared:1; /* Has the wake-up capability been enabled? */ 262 263 u8 run_wake:1; /* Run-Wake GPE devices */ 263 264 }; 264 265 ··· 336 335 int acpi_bus_get_status(struct acpi_device *device); 337 336 int acpi_bus_get_power(acpi_handle handle, int *state); 338 337 int acpi_bus_set_power(acpi_handle handle, int state); 338 + bool acpi_bus_power_manageable(acpi_handle handle); 339 + bool acpi_bus_can_wakeup(acpi_handle handle); 339 340 #ifdef CONFIG_ACPI_PROC_EVENT 340 341 int acpi_bus_generate_proc_event(struct acpi_device *device, u8 type, int data); 341 342 int acpi_bus_generate_proc_event4(const char *class, const char *bid, u8 type, int data); ··· 380 377 381 378 #ifdef CONFIG_PM_SLEEP 382 379 int acpi_pm_device_sleep_state(struct device *, int *); 380 + int acpi_pm_device_sleep_wake(struct device *, bool); 383 381 #else /* !CONFIG_PM_SLEEP */ 384 382 static inline int acpi_pm_device_sleep_state(struct device *d, int *p) 385 383 { 386 384 if (p) 387 385 *p = ACPI_STATE_D0; 388 386 return ACPI_STATE_D3; 387 + } 388 + static inline int acpi_pm_device_sleep_wake(struct device *dev, bool enable) 389 + { 390 + return -ENODEV; 389 391 } 390 392 #endif /* !CONFIG_PM_SLEEP */ 391 393
+3 -1
include/acpi/acpi_drivers.h
··· 87 87 -------------------------------------------------------------------------- */ 88 88 89 89 #ifdef CONFIG_ACPI_POWER 90 - int acpi_enable_wakeup_device_power(struct acpi_device *dev); 90 + int acpi_device_sleep_wake(struct acpi_device *dev, 91 + int enable, int sleep_state, int dev_state); 92 + int acpi_enable_wakeup_device_power(struct acpi_device *dev, int sleep_state); 91 93 int acpi_disable_wakeup_device_power(struct acpi_device *dev); 92 94 int acpi_power_get_inferred_state(struct acpi_device *device); 93 95 int acpi_power_transition(struct acpi_device *device, int state);
+6
include/asm-generic/vmlinux.lds.h
··· 86 86 VMLINUX_SYMBOL(__start_pci_fixups_resume) = .; \ 87 87 *(.pci_fixup_resume) \ 88 88 VMLINUX_SYMBOL(__end_pci_fixups_resume) = .; \ 89 + VMLINUX_SYMBOL(__start_pci_fixups_resume_early) = .; \ 90 + *(.pci_fixup_resume_early) \ 91 + VMLINUX_SYMBOL(__end_pci_fixups_resume_early) = .; \ 92 + VMLINUX_SYMBOL(__start_pci_fixups_suspend) = .; \ 93 + *(.pci_fixup_suspend) \ 94 + VMLINUX_SYMBOL(__end_pci_fixups_suspend) = .; \ 89 95 } \ 90 96 \ 91 97 /* Built-in firmware blobs */ \
+4
include/asm-x86/pci-direct.h
··· 11 11 extern u16 read_pci_config_16(u8 bus, u8 slot, u8 func, u8 offset); 12 12 extern void write_pci_config(u8 bus, u8 slot, u8 func, u8 offset, u32 val); 13 13 extern void write_pci_config_byte(u8 bus, u8 slot, u8 func, u8 offset, u8 val); 14 + extern void write_pci_config_16(u8 bus, u8 slot, u8 func, u8 offset, u16 val); 14 15 15 16 extern int early_pci_allowed(void); 16 17 18 + extern unsigned int pci_early_dump_regs; 19 + extern void early_dump_pci_device(u8 bus, u8 slot, u8 func); 20 + extern void early_dump_pci_devices(void); 17 21 #endif
+3
include/linux/acpi.h
··· 235 235 int acpi_check_mem_region(resource_size_t start, resource_size_t n, 236 236 const char *name); 237 237 238 + #ifdef CONFIG_PM_SLEEP 239 + void __init acpi_old_suspend_ordering(void); 240 + #endif /* CONFIG_PM_SLEEP */ 238 241 #else /* CONFIG_ACPI */ 239 242 240 243 static inline int early_acpi_boot_init(void)
+9
include/linux/device.h
··· 68 68 int (*resume_early)(struct device *dev); 69 69 int (*resume)(struct device *dev); 70 70 71 + struct pm_ext_ops *pm; 72 + 71 73 struct bus_type_private *p; 72 74 }; 73 75 ··· 132 130 int (*suspend) (struct device *dev, pm_message_t state); 133 131 int (*resume) (struct device *dev); 134 132 struct attribute_group **groups; 133 + 134 + struct pm_ops *pm; 135 135 136 136 struct driver_private *p; 137 137 }; ··· 201 197 202 198 int (*suspend)(struct device *dev, pm_message_t state); 203 199 int (*resume)(struct device *dev); 200 + 201 + struct pm_ops *pm; 204 202 }; 205 203 206 204 extern int __must_check class_register(struct class *class); ··· 254 248 struct attribute_group **groups; 255 249 int (*uevent)(struct device *dev, struct kobj_uevent_env *env); 256 250 void (*release)(struct device *dev); 251 + 257 252 int (*suspend)(struct device *dev, pm_message_t state); 258 253 int (*resume)(struct device *dev); 254 + 255 + struct pm_ops *pm; 259 256 }; 260 257 261 258 /* interface for exporting device attributes */
+48 -9
include/linux/pci.h
··· 17 17 #ifndef LINUX_PCI_H 18 18 #define LINUX_PCI_H 19 19 20 - /* Include the pci register defines */ 21 - #include <linux/pci_regs.h> 20 + #include <linux/pci_regs.h> /* The pci register defines */ 22 21 23 22 /* 24 23 * The PCI interface treats multi-function devices as independent ··· 48 49 #include <linux/list.h> 49 50 #include <linux/compiler.h> 50 51 #include <linux/errno.h> 52 + #include <linux/kobject.h> 51 53 #include <asm/atomic.h> 52 54 #include <linux/device.h> 53 55 54 56 /* Include the ID list */ 55 57 #include <linux/pci_ids.h> 58 + 59 + /* pci_slot represents a physical slot */ 60 + struct pci_slot { 61 + struct pci_bus *bus; /* The bus this slot is on */ 62 + struct list_head list; /* node in list of slots on this bus */ 63 + struct hotplug_slot *hotplug; /* Hotplug info (migrate over time) */ 64 + unsigned char number; /* PCI_SLOT(pci_dev->devfn) */ 65 + struct kobject kobj; 66 + }; 56 67 57 68 /* File state for mmap()s on /proc/bus/pci/X/Y */ 58 69 enum pci_mmap_state { ··· 151 142 152 143 void *sysdata; /* hook for sys-specific extension */ 153 144 struct proc_dir_entry *procent; /* device entry in /proc/bus/pci */ 145 + struct pci_slot *slot; /* Physical slot this device is in */ 154 146 155 147 unsigned int devfn; /* encoded device & function index */ 156 148 unsigned short vendor; ··· 177 167 pci_power_t current_state; /* Current operating state. In ACPI-speak, 178 168 this is D0-D3, D0 being fully functional, 179 169 and D3 being off. */ 170 + int pm_cap; /* PM capability offset in the 171 + configuration space */ 172 + unsigned int pme_support:5; /* Bitmask of states from which PME# 173 + can be generated */ 174 + unsigned int d1_support:1; /* Low power state D1 is supported */ 175 + unsigned int d2_support:1; /* Low power state D2 is supported */ 176 + unsigned int no_d1d2:1; /* Only allow D0 and D3 */ 180 177 181 178 #ifdef CONFIG_PCIEASPM 182 179 struct pcie_link_state *link_state; /* ASPM link state. */ ··· 208 191 unsigned int is_added:1; 209 192 unsigned int is_busmaster:1; /* device is busmaster */ 210 193 unsigned int no_msi:1; /* device may not use msi */ 211 - unsigned int no_d1d2:1; /* only allow d0 or d3 */ 212 194 unsigned int block_ucfg_access:1; /* userspace config space access is blocked */ 213 195 unsigned int broken_parity_status:1; /* Device generates false positive parity */ 214 196 unsigned int msi_enabled:1; ··· 283 267 struct list_head children; /* list of child buses */ 284 268 struct list_head devices; /* list of devices on this bus */ 285 269 struct pci_dev *self; /* bridge device as seen by parent */ 270 + struct list_head slots; /* list of slots on this bus */ 286 271 struct resource *resource[PCI_BUS_NUM_RESOURCES]; 287 272 /* address space routed to this bus */ 288 273 ··· 345 328 struct pci_dynids { 346 329 spinlock_t lock; /* protects list, index */ 347 330 struct list_head list; /* for IDs added at runtime */ 348 - unsigned int use_driver_data:1; /* pci_driver->driver_data is used */ 331 + unsigned int use_driver_data:1; /* pci_device_id->driver_data is used */ 349 332 }; 350 333 351 334 /* ---------------------------------------------------------------- */ ··· 407 390 int (*resume_early) (struct pci_dev *dev); 408 391 int (*resume) (struct pci_dev *dev); /* Device woken up */ 409 392 void (*shutdown) (struct pci_dev *dev); 410 - 393 + struct pm_ext_ops *pm; 411 394 struct pci_error_handlers *err_handler; 412 395 struct device_driver driver; 413 396 struct pci_dynids dynids; ··· 506 489 struct pci_ops *ops, void *sysdata); 507 490 struct pci_bus *pci_add_new_bus(struct pci_bus *parent, struct pci_dev *dev, 508 491 int busnr); 492 + struct pci_slot *pci_create_slot(struct pci_bus *parent, int slot_nr, 493 + const char *name); 494 + void pci_destroy_slot(struct pci_slot *slot); 495 + void pci_update_slot_number(struct pci_slot *slot, int slot_nr); 509 496 int pci_scan_slot(struct pci_bus *bus, int devfn); 510 497 struct pci_dev *pci_scan_single_device(struct pci_bus *bus, int devfn); 511 498 void pci_device_add(struct pci_dev *dev, struct pci_bus *bus); ··· 639 618 int pci_set_power_state(struct pci_dev *dev, pci_power_t state); 640 619 pci_power_t pci_choose_state(struct pci_dev *dev, pm_message_t state); 641 620 int pci_enable_wake(struct pci_dev *dev, pci_power_t state, int enable); 621 + int pci_prepare_to_sleep(struct pci_dev *dev); 622 + int pci_back_from_sleep(struct pci_dev *dev); 642 623 643 624 /* Functions for PCI Hotplug drivers to use */ 644 625 int pci_bus_find_capability(struct pci_bus *bus, unsigned int devfn, int cap); ··· 862 839 return -EIO; 863 840 } 864 841 842 + static inline int pci_set_consistent_dma_mask(struct pci_dev *dev, u64 mask) 843 + { 844 + return -EIO; 845 + } 846 + 865 847 static inline int pci_set_dma_max_seg_size(struct pci_dev *dev, 866 848 unsigned int size) 867 849 { ··· 1005 977 /* If you want to know what to call your pci_dev, ask this function. 1006 978 * Again, it's a wrapper around the generic device. 1007 979 */ 1008 - static inline char *pci_name(struct pci_dev *pdev) 980 + static inline const char *pci_name(struct pci_dev *pdev) 1009 981 { 1010 - return pdev->dev.bus_id; 982 + return dev_name(&pdev->dev); 1011 983 } 1012 984 1013 985 ··· 1042 1014 pci_fixup_header, /* After reading configuration header */ 1043 1015 pci_fixup_final, /* Final phase of device fixups */ 1044 1016 pci_fixup_enable, /* pci_enable_device() time */ 1045 - pci_fixup_resume, /* pci_enable_device() time */ 1017 + pci_fixup_resume, /* pci_device_resume() */ 1018 + pci_fixup_suspend, /* pci_device_suspend */ 1019 + pci_fixup_resume_early, /* pci_device_resume_early() */ 1046 1020 }; 1047 1021 1048 1022 /* Anonymous variables would be nice... */ ··· 1066 1036 #define DECLARE_PCI_FIXUP_RESUME(vendor, device, hook) \ 1067 1037 DECLARE_PCI_FIXUP_SECTION(.pci_fixup_resume, \ 1068 1038 resume##vendor##device##hook, vendor, device, hook) 1039 + #define DECLARE_PCI_FIXUP_RESUME_EARLY(vendor, device, hook) \ 1040 + DECLARE_PCI_FIXUP_SECTION(.pci_fixup_resume_early, \ 1041 + resume_early##vendor##device##hook, vendor, device, hook) 1042 + #define DECLARE_PCI_FIXUP_SUSPEND(vendor, device, hook) \ 1043 + DECLARE_PCI_FIXUP_SECTION(.pci_fixup_suspend, \ 1044 + suspend##vendor##device##hook, vendor, device, hook) 1069 1045 1070 1046 1071 1047 void pci_fixup_device(enum pci_fixup_pass pass, struct pci_dev *dev); ··· 1096 1060 extern unsigned long pci_cardbus_io_size; 1097 1061 extern unsigned long pci_cardbus_mem_size; 1098 1062 1099 - extern int pcibios_add_platform_entries(struct pci_dev *dev); 1063 + int pcibios_add_platform_entries(struct pci_dev *dev); 1064 + void pcibios_disable_device(struct pci_dev *dev); 1065 + int pcibios_set_pcie_reset_state(struct pci_dev *dev, 1066 + enum pcie_reset_state state); 1100 1067 1101 1068 #ifdef CONFIG_PCI_MMCONFIG 1102 1069 extern void __init pci_mmcfg_early_init(void);
+4 -10
include/linux/pci_hotplug.h
··· 95 95 * @get_adapter_status: Called to get see if an adapter is present in the slot or not. 96 96 * If this field is NULL, the value passed in the struct hotplug_slot_info 97 97 * will be used when this value is requested by a user. 98 - * @get_address: Called to get pci address of a slot. 99 - * If this field is NULL, the value passed in the struct hotplug_slot_info 100 - * will be used when this value is requested by a user. 101 98 * @get_max_bus_speed: Called to get the max bus speed for a slot. 102 99 * If this field is NULL, the value passed in the struct hotplug_slot_info 103 100 * will be used when this value is requested by a user. ··· 117 120 int (*get_attention_status) (struct hotplug_slot *slot, u8 *value); 118 121 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value); 119 122 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value); 120 - int (*get_address) (struct hotplug_slot *slot, u32 *value); 121 123 int (*get_max_bus_speed) (struct hotplug_slot *slot, enum pci_bus_speed *value); 122 124 int (*get_cur_bus_speed) (struct hotplug_slot *slot, enum pci_bus_speed *value); 123 125 }; ··· 136 140 u8 attention_status; 137 141 u8 latch_status; 138 142 u8 adapter_status; 139 - u32 address; 140 143 enum pci_bus_speed max_bus_speed; 141 144 enum pci_bus_speed cur_bus_speed; 142 145 }; ··· 161 166 162 167 /* Variables below this are for use only by the hotplug pci core. */ 163 168 struct list_head slot_list; 164 - struct kobject kobj; 169 + struct pci_slot *pci_slot; 165 170 }; 166 171 #define to_hotplug_slot(n) container_of(n, struct hotplug_slot, kobj) 167 172 168 - extern int pci_hp_register (struct hotplug_slot *slot); 169 - extern int pci_hp_deregister (struct hotplug_slot *slot); 173 + extern int pci_hp_register(struct hotplug_slot *, struct pci_bus *, int nr); 174 + extern int pci_hp_deregister(struct hotplug_slot *slot); 170 175 extern int __must_check pci_hp_change_slot_info (struct hotplug_slot *slot, 171 176 struct hotplug_slot_info *info); 172 - extern struct kset *pci_hotplug_slots_kset; 173 177 174 178 /* PCI Setting Record (Type 0) */ 175 179 struct hpp_type0 { ··· 221 227 #include <acpi/acpi.h> 222 228 #include <acpi/acpi_bus.h> 223 229 #include <acpi/actypes.h> 224 - extern acpi_status acpi_run_oshp(acpi_handle handle); 225 230 extern acpi_status acpi_get_hp_params_from_firmware(struct pci_bus *bus, 226 231 struct hotplug_params *hpp); 232 + int acpi_get_hp_hw_control_from_firmware(struct pci_dev *dev, u32 flags); 227 233 int acpi_root_bridge(acpi_handle handle); 228 234 #endif 229 235 #endif
+1
include/linux/pci_regs.h
··· 231 231 #define PCI_PM_CAP_PME_D2 0x2000 /* PME# from D2 */ 232 232 #define PCI_PM_CAP_PME_D3 0x4000 /* PME# from D3 (hot) */ 233 233 #define PCI_PM_CAP_PME_D3cold 0x8000 /* PME# from D3 (cold) */ 234 + #define PCI_PM_CAP_PME_SHIFT 11 /* Start of the PME Mask in PMC */ 234 235 #define PCI_PM_CTRL 4 /* PM control and status register */ 235 236 #define PCI_PM_CTRL_STATE_MASK 0x0003 /* Current power state (D0 to D3) */ 236 237 #define PCI_PM_CTRL_NO_SOFT_RESET 0x0004 /* No reset for D3hot->D0 */
+1
include/linux/platform_device.h
··· 53 53 int (*suspend_late)(struct platform_device *, pm_message_t state); 54 54 int (*resume_early)(struct platform_device *); 55 55 int (*resume)(struct platform_device *); 56 + struct pm_ext_ops *pm; 56 57 struct device_driver driver; 57 58 }; 58 59
+287 -29
include/linux/pm.h
··· 112 112 int event; 113 113 } pm_message_t; 114 114 115 - /* 115 + /** 116 + * struct pm_ops - device PM callbacks 117 + * 116 118 * Several driver power state transitions are externally visible, affecting 117 119 * the state of pending I/O queues and (for drivers that touch hardware) 118 120 * interrupts, wakeups, DMA, and other hardware state. There may also be ··· 122 120 * to the rest of the driver stack (such as a driver that's ON gating off 123 121 * clocks which are not in active use). 124 122 * 123 + * The externally visible transitions are handled with the help of the following 124 + * callbacks included in this structure: 125 + * 126 + * @prepare: Prepare the device for the upcoming transition, but do NOT change 127 + * its hardware state. Prevent new children of the device from being 128 + * registered after @prepare() returns (the driver's subsystem and 129 + * generally the rest of the kernel is supposed to prevent new calls to the 130 + * probe method from being made too once @prepare() has succeeded). If 131 + * @prepare() detects a situation it cannot handle (e.g. registration of a 132 + * child already in progress), it may return -EAGAIN, so that the PM core 133 + * can execute it once again (e.g. after the new child has been registered) 134 + * to recover from the race condition. This method is executed for all 135 + * kinds of suspend transitions and is followed by one of the suspend 136 + * callbacks: @suspend(), @freeze(), or @poweroff(). 137 + * The PM core executes @prepare() for all devices before starting to 138 + * execute suspend callbacks for any of them, so drivers may assume all of 139 + * the other devices to be present and functional while @prepare() is being 140 + * executed. In particular, it is safe to make GFP_KERNEL memory 141 + * allocations from within @prepare(). However, drivers may NOT assume 142 + * anything about the availability of the user space at that time and it 143 + * is not correct to request firmware from within @prepare() (it's too 144 + * late to do that). [To work around this limitation, drivers may 145 + * register suspend and hibernation notifiers that are executed before the 146 + * freezing of tasks.] 147 + * 148 + * @complete: Undo the changes made by @prepare(). This method is executed for 149 + * all kinds of resume transitions, following one of the resume callbacks: 150 + * @resume(), @thaw(), @restore(). Also called if the state transition 151 + * fails before the driver's suspend callback (@suspend(), @freeze(), 152 + * @poweroff()) can be executed (e.g. if the suspend callback fails for one 153 + * of the other devices that the PM core has unsuccessfully attempted to 154 + * suspend earlier). 155 + * The PM core executes @complete() after it has executed the appropriate 156 + * resume callback for all devices. 157 + * 158 + * @suspend: Executed before putting the system into a sleep state in which the 159 + * contents of main memory are preserved. Quiesce the device, put it into 160 + * a low power state appropriate for the upcoming system state (such as 161 + * PCI_D3hot), and enable wakeup events as appropriate. 162 + * 163 + * @resume: Executed after waking the system up from a sleep state in which the 164 + * contents of main memory were preserved. Put the device into the 165 + * appropriate state, according to the information saved in memory by the 166 + * preceding @suspend(). The driver starts working again, responding to 167 + * hardware events and software requests. The hardware may have gone 168 + * through a power-off reset, or it may have maintained state from the 169 + * previous suspend() which the driver may rely on while resuming. On most 170 + * platforms, there are no restrictions on availability of resources like 171 + * clocks during @resume(). 172 + * 173 + * @freeze: Hibernation-specific, executed before creating a hibernation image. 174 + * Quiesce operations so that a consistent image can be created, but do NOT 175 + * otherwise put the device into a low power device state and do NOT emit 176 + * system wakeup events. Save in main memory the device settings to be 177 + * used by @restore() during the subsequent resume from hibernation or by 178 + * the subsequent @thaw(), if the creation of the image or the restoration 179 + * of main memory contents from it fails. 180 + * 181 + * @thaw: Hibernation-specific, executed after creating a hibernation image OR 182 + * if the creation of the image fails. Also executed after a failing 183 + * attempt to restore the contents of main memory from such an image. 184 + * Undo the changes made by the preceding @freeze(), so the device can be 185 + * operated in the same way as immediately before the call to @freeze(). 186 + * 187 + * @poweroff: Hibernation-specific, executed after saving a hibernation image. 188 + * Quiesce the device, put it into a low power state appropriate for the 189 + * upcoming system state (such as PCI_D3hot), and enable wakeup events as 190 + * appropriate. 191 + * 192 + * @restore: Hibernation-specific, executed after restoring the contents of main 193 + * memory from a hibernation image. Driver starts working again, 194 + * responding to hardware events and software requests. Drivers may NOT 195 + * make ANY assumptions about the hardware state right prior to @restore(). 196 + * On most platforms, there are no restrictions on availability of 197 + * resources like clocks during @restore(). 198 + * 199 + * All of the above callbacks, except for @complete(), return error codes. 200 + * However, the error codes returned by the resume operations, @resume(), 201 + * @thaw(), and @restore(), do not cause the PM core to abort the resume 202 + * transition during which they are returned. The error codes returned in 203 + * that cases are only printed by the PM core to the system logs for debugging 204 + * purposes. Still, it is recommended that drivers only return error codes 205 + * from their resume methods in case of an unrecoverable failure (i.e. when the 206 + * device being handled refuses to resume and becomes unusable) to allow us to 207 + * modify the PM core in the future, so that it can avoid attempting to handle 208 + * devices that failed to resume and their children. 209 + * 210 + * It is allowed to unregister devices while the above callbacks are being 211 + * executed. However, it is not allowed to unregister a device from within any 212 + * of its own callbacks. 213 + */ 214 + 215 + struct pm_ops { 216 + int (*prepare)(struct device *dev); 217 + void (*complete)(struct device *dev); 218 + int (*suspend)(struct device *dev); 219 + int (*resume)(struct device *dev); 220 + int (*freeze)(struct device *dev); 221 + int (*thaw)(struct device *dev); 222 + int (*poweroff)(struct device *dev); 223 + int (*restore)(struct device *dev); 224 + }; 225 + 226 + /** 227 + * struct pm_ext_ops - extended device PM callbacks 228 + * 229 + * Some devices require certain operations related to suspend and hibernation 230 + * to be carried out with interrupts disabled. Thus, 'struct pm_ext_ops' below 231 + * is defined, adding callbacks to be executed with interrupts disabled to 232 + * 'struct pm_ops'. 233 + * 234 + * The following callbacks included in 'struct pm_ext_ops' are executed with 235 + * the nonboot CPUs switched off and with interrupts disabled on the only 236 + * functional CPU. They also are executed with the PM core list of devices 237 + * locked, so they must NOT unregister any devices. 238 + * 239 + * @suspend_noirq: Complete the operations of ->suspend() by carrying out any 240 + * actions required for suspending the device that need interrupts to be 241 + * disabled 242 + * 243 + * @resume_noirq: Prepare for the execution of ->resume() by carrying out any 244 + * actions required for resuming the device that need interrupts to be 245 + * disabled 246 + * 247 + * @freeze_noirq: Complete the operations of ->freeze() by carrying out any 248 + * actions required for freezing the device that need interrupts to be 249 + * disabled 250 + * 251 + * @thaw_noirq: Prepare for the execution of ->thaw() by carrying out any 252 + * actions required for thawing the device that need interrupts to be 253 + * disabled 254 + * 255 + * @poweroff_noirq: Complete the operations of ->poweroff() by carrying out any 256 + * actions required for handling the device that need interrupts to be 257 + * disabled 258 + * 259 + * @restore_noirq: Prepare for the execution of ->restore() by carrying out any 260 + * actions required for restoring the operations of the device that need 261 + * interrupts to be disabled 262 + * 263 + * All of the above callbacks return error codes, but the error codes returned 264 + * by the resume operations, @resume_noirq(), @thaw_noirq(), and 265 + * @restore_noirq(), do not cause the PM core to abort the resume transition 266 + * during which they are returned. The error codes returned in that cases are 267 + * only printed by the PM core to the system logs for debugging purposes. 268 + * Still, as stated above, it is recommended that drivers only return error 269 + * codes from their resume methods if the device being handled fails to resume 270 + * and is not usable any more. 271 + */ 272 + 273 + struct pm_ext_ops { 274 + struct pm_ops base; 275 + int (*suspend_noirq)(struct device *dev); 276 + int (*resume_noirq)(struct device *dev); 277 + int (*freeze_noirq)(struct device *dev); 278 + int (*thaw_noirq)(struct device *dev); 279 + int (*poweroff_noirq)(struct device *dev); 280 + int (*restore_noirq)(struct device *dev); 281 + }; 282 + 283 + /** 284 + * PM_EVENT_ messages 285 + * 286 + * The following PM_EVENT_ messages are defined for the internal use of the PM 287 + * core, in order to provide a mechanism allowing the high level suspend and 288 + * hibernation code to convey the necessary information to the device PM core 289 + * code: 290 + * 291 + * ON No transition. 292 + * 293 + * FREEZE System is going to hibernate, call ->prepare() and ->freeze() 294 + * for all devices. 295 + * 296 + * SUSPEND System is going to suspend, call ->prepare() and ->suspend() 297 + * for all devices. 298 + * 299 + * HIBERNATE Hibernation image has been saved, call ->prepare() and 300 + * ->poweroff() for all devices. 301 + * 302 + * QUIESCE Contents of main memory are going to be restored from a (loaded) 303 + * hibernation image, call ->prepare() and ->freeze() for all 304 + * devices. 305 + * 306 + * RESUME System is resuming, call ->resume() and ->complete() for all 307 + * devices. 308 + * 309 + * THAW Hibernation image has been created, call ->thaw() and 310 + * ->complete() for all devices. 311 + * 312 + * RESTORE Contents of main memory have been restored from a hibernation 313 + * image, call ->restore() and ->complete() for all devices. 314 + * 315 + * RECOVER Creation of a hibernation image or restoration of the main 316 + * memory contents from a hibernation image has failed, call 317 + * ->thaw() and ->complete() for all devices. 318 + */ 319 + 320 + #define PM_EVENT_ON 0x0000 321 + #define PM_EVENT_FREEZE 0x0001 322 + #define PM_EVENT_SUSPEND 0x0002 323 + #define PM_EVENT_HIBERNATE 0x0004 324 + #define PM_EVENT_QUIESCE 0x0008 325 + #define PM_EVENT_RESUME 0x0010 326 + #define PM_EVENT_THAW 0x0020 327 + #define PM_EVENT_RESTORE 0x0040 328 + #define PM_EVENT_RECOVER 0x0080 329 + 330 + #define PM_EVENT_SLEEP (PM_EVENT_SUSPEND | PM_EVENT_HIBERNATE) 331 + 332 + #define PMSG_FREEZE ((struct pm_message){ .event = PM_EVENT_FREEZE, }) 333 + #define PMSG_QUIESCE ((struct pm_message){ .event = PM_EVENT_QUIESCE, }) 334 + #define PMSG_SUSPEND ((struct pm_message){ .event = PM_EVENT_SUSPEND, }) 335 + #define PMSG_HIBERNATE ((struct pm_message){ .event = PM_EVENT_HIBERNATE, }) 336 + #define PMSG_RESUME ((struct pm_message){ .event = PM_EVENT_RESUME, }) 337 + #define PMSG_THAW ((struct pm_message){ .event = PM_EVENT_THAW, }) 338 + #define PMSG_RESTORE ((struct pm_message){ .event = PM_EVENT_RESTORE, }) 339 + #define PMSG_RECOVER ((struct pm_message){ .event = PM_EVENT_RECOVER, }) 340 + #define PMSG_ON ((struct pm_message){ .event = PM_EVENT_ON, }) 341 + 342 + /** 343 + * Device power management states 344 + * 345 + * These state labels are used internally by the PM core to indicate the current 346 + * status of a device with respect to the PM core operations. 347 + * 348 + * DPM_ON Device is regarded as operational. Set this way 349 + * initially and when ->complete() is about to be called. 350 + * Also set when ->prepare() fails. 351 + * 352 + * DPM_PREPARING Device is going to be prepared for a PM transition. Set 353 + * when ->prepare() is about to be called. 354 + * 355 + * DPM_RESUMING Device is going to be resumed. Set when ->resume(), 356 + * ->thaw(), or ->restore() is about to be called. 357 + * 358 + * DPM_SUSPENDING Device has been prepared for a power transition. Set 359 + * when ->prepare() has just succeeded. 360 + * 361 + * DPM_OFF Device is regarded as inactive. Set immediately after 362 + * ->suspend(), ->freeze(), or ->poweroff() has succeeded. 363 + * Also set when ->resume()_noirq, ->thaw_noirq(), or 364 + * ->restore_noirq() is about to be called. 365 + * 366 + * DPM_OFF_IRQ Device is in a "deep sleep". Set immediately after 367 + * ->suspend_noirq(), ->freeze_noirq(), or 368 + * ->poweroff_noirq() has just succeeded. 369 + */ 370 + 371 + enum dpm_state { 372 + DPM_INVALID, 373 + DPM_ON, 374 + DPM_PREPARING, 375 + DPM_RESUMING, 376 + DPM_SUSPENDING, 377 + DPM_OFF, 378 + DPM_OFF_IRQ, 379 + }; 380 + 381 + struct dev_pm_info { 382 + pm_message_t power_state; 383 + unsigned can_wakeup:1; 384 + unsigned should_wakeup:1; 385 + enum dpm_state status; /* Owned by the PM core */ 386 + #ifdef CONFIG_PM_SLEEP 387 + struct list_head entry; 388 + #endif 389 + }; 390 + 391 + /* 392 + * The PM_EVENT_ messages are also used by drivers implementing the legacy 393 + * suspend framework, based on the ->suspend() and ->resume() callbacks common 394 + * for suspend and hibernation transitions, according to the rules below. 395 + */ 396 + 397 + /* Necessary, because several drivers use PM_EVENT_PRETHAW */ 398 + #define PM_EVENT_PRETHAW PM_EVENT_QUIESCE 399 + 400 + /* 125 401 * One transition is triggered by resume(), after a suspend() call; the 126 402 * message is implicit: 127 403 * ··· 444 164 * or from system low-power states such as standby or suspend-to-RAM. 445 165 */ 446 166 447 - #define PM_EVENT_ON 0 448 - #define PM_EVENT_FREEZE 1 449 - #define PM_EVENT_SUSPEND 2 450 - #define PM_EVENT_HIBERNATE 4 451 - #define PM_EVENT_PRETHAW 8 452 - 453 - #define PM_EVENT_SLEEP (PM_EVENT_SUSPEND | PM_EVENT_HIBERNATE) 454 - 455 - #define PMSG_FREEZE ((struct pm_message){ .event = PM_EVENT_FREEZE, }) 456 - #define PMSG_PRETHAW ((struct pm_message){ .event = PM_EVENT_PRETHAW, }) 457 - #define PMSG_SUSPEND ((struct pm_message){ .event = PM_EVENT_SUSPEND, }) 458 - #define PMSG_HIBERNATE ((struct pm_message){ .event = PM_EVENT_HIBERNATE, }) 459 - #define PMSG_ON ((struct pm_message){ .event = PM_EVENT_ON, }) 460 - 461 - struct dev_pm_info { 462 - pm_message_t power_state; 463 - unsigned can_wakeup:1; 464 - unsigned should_wakeup:1; 465 - bool sleeping:1; /* Owned by the PM core */ 466 - #ifdef CONFIG_PM_SLEEP 467 - struct list_head entry; 468 - #endif 469 - }; 470 - 471 - extern int device_power_down(pm_message_t state); 472 - extern void device_power_up(void); 473 - extern void device_resume(void); 474 - 475 167 #ifdef CONFIG_PM_SLEEP 168 + extern void device_pm_lock(void); 169 + extern void device_power_up(pm_message_t state); 170 + extern void device_resume(pm_message_t state); 171 + 172 + extern void device_pm_unlock(void); 173 + extern int device_power_down(pm_message_t state); 476 174 extern int device_suspend(pm_message_t state); 477 175 extern int device_prepare_suspend(pm_message_t state); 478 176
+8 -20
include/linux/pm_wakeup.h
··· 35 35 dev->power.can_wakeup = dev->power.should_wakeup = !!val; 36 36 } 37 37 38 + static inline void device_set_wakeup_capable(struct device *dev, int val) 39 + { 40 + dev->power.can_wakeup = !!val; 41 + } 42 + 38 43 static inline int device_can_wakeup(struct device *dev) 39 44 { 40 45 return dev->power.can_wakeup; ··· 52 47 53 48 static inline int device_may_wakeup(struct device *dev) 54 49 { 55 - return dev->power.can_wakeup & dev->power.should_wakeup; 56 - } 57 - 58 - /* 59 - * Platform hook to activate device wakeup capability, if that's not already 60 - * handled by enable_irq_wake() etc. 61 - * Returns zero on success, else negative errno 62 - */ 63 - extern int (*platform_enable_wakeup)(struct device *dev, int is_on); 64 - 65 - static inline int call_platform_enable_wakeup(struct device *dev, int is_on) 66 - { 67 - if (platform_enable_wakeup) 68 - return (*platform_enable_wakeup)(dev, is_on); 69 - return 0; 50 + return dev->power.can_wakeup && dev->power.should_wakeup; 70 51 } 71 52 72 53 #else /* !CONFIG_PM */ ··· 63 72 dev->power.can_wakeup = !!val; 64 73 } 65 74 75 + static inline void device_set_wakeup_capable(struct device *dev, int val) { } 76 + 66 77 static inline int device_can_wakeup(struct device *dev) 67 78 { 68 79 return dev->power.can_wakeup; ··· 72 79 73 80 #define device_set_wakeup_enable(dev, val) do {} while (0) 74 81 #define device_may_wakeup(dev) 0 75 - 76 - static inline int call_platform_enable_wakeup(struct device *dev, int is_on) 77 - { 78 - return 0; 79 - } 80 82 81 83 #endif /* !CONFIG_PM */ 82 84
+13 -1
include/linux/suspend.h
··· 86 86 * that implement @begin(), but platforms implementing @begin() should 87 87 * also provide a @end() which cleans up transitions aborted before 88 88 * @enter(). 89 + * 90 + * @recover: Recover the platform from a suspend failure. 91 + * Called by the PM core if the suspending of devices fails. 92 + * This callback is optional and should only be implemented by platforms 93 + * which require special recovery actions in that situation. 89 94 */ 90 95 struct platform_suspend_ops { 91 96 int (*valid)(suspend_state_t state); ··· 99 94 int (*enter)(suspend_state_t state); 100 95 void (*finish)(void); 101 96 void (*end)(void); 97 + void (*recover)(void); 102 98 }; 103 99 104 100 #ifdef CONFIG_SUSPEND ··· 155 149 * The methods in this structure allow a platform to carry out special 156 150 * operations required by it during a hibernation transition. 157 151 * 158 - * All the methods below must be implemented. 152 + * All the methods below, except for @recover(), must be implemented. 159 153 * 160 154 * @begin: Tell the platform driver that we're starting hibernation. 161 155 * Called right after shrinking memory and before freezing devices. ··· 195 189 * @restore_cleanup: Clean up after a failing image restoration. 196 190 * Called right after the nonboot CPUs have been enabled and before 197 191 * thawing devices (runs with IRQs on). 192 + * 193 + * @recover: Recover the platform from a failure to suspend devices. 194 + * Called by the PM core if the suspending of devices during hibernation 195 + * fails. This callback is optional and should only be implemented by 196 + * platforms which require special recovery actions in that situation. 198 197 */ 199 198 struct platform_hibernation_ops { 200 199 int (*begin)(void); ··· 211 200 void (*leave)(void); 212 201 int (*pre_restore)(void); 213 202 void (*restore_cleanup)(void); 203 + void (*recover)(void); 214 204 }; 215 205 216 206 #ifdef CONFIG_HIBERNATION
+37 -13
kernel/power/disk.c
··· 180 180 } 181 181 182 182 /** 183 + * platform_recover - recover the platform from a failure to suspend 184 + * devices. 185 + */ 186 + 187 + static void platform_recover(int platform_mode) 188 + { 189 + if (platform_mode && hibernation_ops && hibernation_ops->recover) 190 + hibernation_ops->recover(); 191 + } 192 + 193 + /** 183 194 * create_image - freeze devices that need to be frozen with interrupts 184 195 * off, create the hibernation image and thaw those devices. Control 185 196 * reappears in this routine after a restore. ··· 204 193 if (error) 205 194 return error; 206 195 196 + device_pm_lock(); 207 197 local_irq_disable(); 208 198 /* At this point, device_suspend() has been called, but *not* 209 199 * device_power_down(). We *must* call device_power_down() now. ··· 236 224 /* NOTE: device_power_up() is just a resume() for devices 237 225 * that suspended with irqs off ... no overall powerup. 238 226 */ 239 - device_power_up(); 227 + device_power_up(in_suspend ? 228 + (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE); 240 229 Enable_irqs: 241 230 local_irq_enable(); 231 + device_pm_unlock(); 242 232 return error; 243 233 } 244 234 ··· 269 255 suspend_console(); 270 256 error = device_suspend(PMSG_FREEZE); 271 257 if (error) 272 - goto Resume_console; 258 + goto Recover_platform; 273 259 274 260 if (hibernation_test(TEST_DEVICES)) 275 - goto Resume_devices; 261 + goto Recover_platform; 276 262 277 263 error = platform_pre_snapshot(platform_mode); 278 264 if (error || hibernation_test(TEST_PLATFORM)) ··· 294 280 Finish: 295 281 platform_finish(platform_mode); 296 282 Resume_devices: 297 - device_resume(); 298 - Resume_console: 283 + device_resume(in_suspend ? 284 + (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE); 299 285 resume_console(); 300 286 Close: 301 287 platform_end(platform_mode); 302 288 return error; 289 + 290 + Recover_platform: 291 + platform_recover(platform_mode); 292 + goto Resume_devices; 303 293 } 304 294 305 295 /** ··· 318 300 { 319 301 int error; 320 302 303 + device_pm_lock(); 321 304 local_irq_disable(); 322 - error = device_power_down(PMSG_PRETHAW); 305 + error = device_power_down(PMSG_QUIESCE); 323 306 if (error) { 324 307 printk(KERN_ERR "PM: Some devices failed to power down, " 325 308 "aborting resume\n"); ··· 348 329 swsusp_free(); 349 330 restore_processor_state(); 350 331 touch_softlockup_watchdog(); 351 - device_power_up(); 332 + device_power_up(PMSG_RECOVER); 352 333 Enable_irqs: 353 334 local_irq_enable(); 335 + device_pm_unlock(); 354 336 return error; 355 337 } 356 338 ··· 370 350 371 351 pm_prepare_console(); 372 352 suspend_console(); 373 - error = device_suspend(PMSG_PRETHAW); 353 + error = device_suspend(PMSG_QUIESCE); 374 354 if (error) 375 355 goto Finish; 376 356 ··· 382 362 enable_nonboot_cpus(); 383 363 } 384 364 platform_restore_cleanup(platform_mode); 385 - device_resume(); 365 + device_resume(PMSG_RECOVER); 386 366 Finish: 387 367 resume_console(); 388 368 pm_restore_console(); ··· 412 392 413 393 suspend_console(); 414 394 error = device_suspend(PMSG_HIBERNATE); 415 - if (error) 416 - goto Resume_console; 395 + if (error) { 396 + if (hibernation_ops->recover) 397 + hibernation_ops->recover(); 398 + goto Resume_devices; 399 + } 417 400 418 401 error = hibernation_ops->prepare(); 419 402 if (error) ··· 426 403 if (error) 427 404 goto Finish; 428 405 406 + device_pm_lock(); 429 407 local_irq_disable(); 430 408 error = device_power_down(PMSG_HIBERNATE); 431 409 if (!error) { ··· 435 411 while (1); 436 412 } 437 413 local_irq_enable(); 414 + device_pm_unlock(); 438 415 439 416 /* 440 417 * We don't need to reenable the nonboot CPUs or resume consoles, since ··· 444 419 Finish: 445 420 hibernation_ops->finish(); 446 421 Resume_devices: 447 - device_resume(); 448 - Resume_console: 422 + device_resume(PMSG_RESTORE); 449 423 resume_console(); 450 424 Close: 451 425 hibernation_ops->end();
+11 -5
kernel/power/main.c
··· 228 228 { 229 229 int error = 0; 230 230 231 + device_pm_lock(); 231 232 arch_suspend_disable_irqs(); 232 233 BUG_ON(!irqs_disabled()); 233 234 ··· 240 239 if (!suspend_test(TEST_CORE)) 241 240 error = suspend_ops->enter(state); 242 241 243 - device_power_up(); 242 + device_power_up(PMSG_RESUME); 244 243 Done: 245 244 arch_suspend_enable_irqs(); 246 245 BUG_ON(irqs_disabled()); 246 + device_pm_unlock(); 247 247 return error; 248 248 } 249 249 ··· 269 267 error = device_suspend(PMSG_SUSPEND); 270 268 if (error) { 271 269 printk(KERN_ERR "PM: Some devices failed to suspend\n"); 272 - goto Resume_console; 270 + goto Recover_platform; 273 271 } 274 272 275 273 if (suspend_test(TEST_DEVICES)) 276 - goto Resume_devices; 274 + goto Recover_platform; 277 275 278 276 if (suspend_ops->prepare) { 279 277 error = suspend_ops->prepare(); ··· 293 291 if (suspend_ops->finish) 294 292 suspend_ops->finish(); 295 293 Resume_devices: 296 - device_resume(); 297 - Resume_console: 294 + device_resume(PMSG_RESUME); 298 295 resume_console(); 299 296 Close: 300 297 if (suspend_ops->end) 301 298 suspend_ops->end(); 302 299 return error; 300 + 301 + Recover_platform: 302 + if (suspend_ops->recover) 303 + suspend_ops->recover(); 304 + goto Resume_devices; 303 305 } 304 306 305 307 /**
+1
lib/kobject.c
··· 439 439 440 440 return error; 441 441 } 442 + EXPORT_SYMBOL_GPL(kobject_rename); 442 443 443 444 /** 444 445 * kobject_move - move object to another parent