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

Merge branch 'pci/yinghai-survey-resources+acpi-scan' into next

* pci/yinghai-survey-resources+acpi-scan:
ACPI / scan: Treat power resources in a special way
ACPI: Remove unused struct acpi_pci_root.id member
ACPI: Drop ACPI device .bind() and .unbind() callbacks
ACPI / PCI: Move the _PRT setup and cleanup code to pci-acpi.c
ACPI / PCI: Rework the setup and cleanup of device wakeup
ACPI: Add .setup() and .cleanup() callbacks to struct acpi_bus_type
ACPI: Make acpi_bus_scan() and acpi_bus_add() take only one argument
ACPI: Replace ACPI device add_type field with a match_driver flag
ACPI: Drop the second argument of acpi_bus_scan()
ACPI: Remove the arguments of acpi_bus_add() that are not used
ACPI: Remove acpi_start_single_object() and acpi_bus_start()
ACPI / PCI: Fold acpi_pci_root_start() into acpi_pci_root_add()
ACPI: Change the ordering of acpi_bus_check_add()
ACPI: Replace struct acpi_bus_ops with enum type
ACPI: Reduce the usage of struct acpi_bus_ops
ACPI: Make acpi_bus_add() and acpi_bus_start() visibly different
ACPI: Change the ordering of PCI root bridge driver registrarion
ACPI: Separate adding ACPI device objects from probing ACPI drivers

+237 -484
+1 -1
drivers/acpi/Makefile
··· 37 37 acpi-y += processor_core.o 38 38 acpi-y += ec.o 39 39 acpi-$(CONFIG_ACPI_DOCK) += dock.o 40 - acpi-y += pci_root.o pci_link.o pci_irq.o pci_bind.o 40 + acpi-y += pci_root.o pci_link.o pci_irq.o 41 41 acpi-y += acpi_platform.o 42 42 acpi-y += power.o 43 43 acpi-y += event.o
+6 -18
drivers/acpi/acpi_memhotplug.c
··· 157 157 acpi_memory_get_device(acpi_handle handle, 158 158 struct acpi_memory_device **mem_device) 159 159 { 160 - acpi_status status; 161 - acpi_handle phandle; 162 160 struct acpi_device *device = NULL; 163 - struct acpi_device *pdevice = NULL; 164 161 int result; 165 - 166 162 167 163 if (!acpi_bus_get_device(handle, &device) && device) 168 164 goto end; 169 - 170 - status = acpi_get_parent(handle, &phandle); 171 - if (ACPI_FAILURE(status)) { 172 - ACPI_EXCEPTION((AE_INFO, status, "Cannot find acpi parent")); 173 - return -EINVAL; 174 - } 175 - 176 - /* Get the parent device */ 177 - result = acpi_bus_get_device(phandle, &pdevice); 178 - if (result) { 179 - acpi_handle_warn(phandle, "Cannot get acpi bus device\n"); 180 - return -EINVAL; 181 - } 182 165 183 166 /* 184 167 * Now add the notified device. This creates the acpi_device 185 168 * and invokes .add function 186 169 */ 187 - result = acpi_bus_add(&device, pdevice, handle, ACPI_BUS_TYPE_DEVICE); 170 + result = acpi_bus_add(handle); 188 171 if (result) { 189 172 acpi_handle_warn(handle, "Cannot add acpi bus\n"); 173 + return -EINVAL; 174 + } 175 + result = acpi_bus_get_device(handle, &device); 176 + if (result) { 177 + acpi_handle_warn(handle, "Missing device object\n"); 190 178 return -EINVAL; 191 179 } 192 180
+6 -25
drivers/acpi/container.c
··· 135 135 return status; 136 136 } 137 137 138 - static int container_device_add(struct acpi_device **device, acpi_handle handle) 139 - { 140 - acpi_handle phandle; 141 - struct acpi_device *pdev; 142 - int result; 143 - 144 - 145 - if (acpi_get_parent(handle, &phandle)) { 146 - return -ENODEV; 147 - } 148 - 149 - if (acpi_bus_get_device(phandle, &pdev)) { 150 - return -ENODEV; 151 - } 152 - 153 - if (acpi_bus_add(device, pdev, handle, ACPI_BUS_TYPE_DEVICE)) { 154 - return -ENODEV; 155 - } 156 - 157 - result = acpi_bus_start(*device); 158 - 159 - return result; 160 - } 161 - 162 138 static void container_notify_cb(acpi_handle handle, u32 type, void *context) 163 139 { 164 140 struct acpi_device *device = NULL; ··· 166 190 if (!ACPI_FAILURE(status) || device) 167 191 break; 168 192 169 - result = container_device_add(&device, handle); 193 + result = acpi_bus_add(handle); 170 194 if (result) { 171 195 acpi_handle_warn(handle, "Failed to add container\n"); 196 + break; 197 + } 198 + result = acpi_bus_get_device(handle, &device); 199 + if (result) { 200 + acpi_handle_warn(handle, "Missing device object\n"); 172 201 break; 173 202 } 174 203
+1 -1
drivers/acpi/device_pm.c
··· 353 353 * acpi_dev_pm_get_node - Get ACPI device node for the given physical device. 354 354 * @dev: Device to get the ACPI node for. 355 355 */ 356 - static struct acpi_device *acpi_dev_pm_get_node(struct device *dev) 356 + struct acpi_device *acpi_dev_pm_get_node(struct device *dev) 357 357 { 358 358 acpi_handle handle = DEVICE_ACPI_HANDLE(dev); 359 359 struct acpi_device *adev;
+4 -11
drivers/acpi/dock.c
··· 310 310 static struct acpi_device * dock_create_acpi_device(acpi_handle handle) 311 311 { 312 312 struct acpi_device *device; 313 - struct acpi_device *parent_device; 314 - acpi_handle parent; 315 313 int ret; 316 314 317 315 if (acpi_bus_get_device(handle, &device)) { ··· 317 319 * no device created for this object, 318 320 * so we should create one. 319 321 */ 320 - acpi_get_parent(handle, &parent); 321 - if (acpi_bus_get_device(parent, &parent_device)) 322 - parent_device = NULL; 323 - 324 - ret = acpi_bus_add(&device, parent_device, handle, 325 - ACPI_BUS_TYPE_DEVICE); 326 - if (ret) { 322 + ret = acpi_bus_add(handle); 323 + if (ret) 327 324 pr_debug("error adding bus, %x\n", -ret); 328 - return NULL; 329 - } 325 + 326 + acpi_bus_get_device(handle, &device); 330 327 } 331 328 return device; 332 329 }
+35 -15
drivers/acpi/glue.c
··· 63 63 { 64 64 struct acpi_bus_type *tmp, *ret = NULL; 65 65 66 + if (!type) 67 + return NULL; 68 + 66 69 down_read(&bus_type_sem); 67 70 list_for_each_entry(tmp, &bus_type_list, list) { 68 71 if (tmp->bus == type) { ··· 267 264 { 268 265 struct acpi_bus_type *type; 269 266 acpi_handle handle; 270 - int ret = -EINVAL; 267 + int ret; 271 268 272 269 ret = acpi_bind_one(dev, NULL); 273 - if (!ret) 274 - goto out; 275 - 276 - if (!dev->bus || !dev->parent) { 270 + if (ret && (!dev->bus || !dev->parent)) { 277 271 /* bridge devices genernally haven't bus or parent */ 278 272 ret = acpi_find_bridge_device(dev, &handle); 279 - goto end; 273 + if (!ret) { 274 + ret = acpi_bind_one(dev, handle); 275 + if (ret) 276 + goto out; 277 + } 280 278 } 279 + 281 280 type = acpi_get_bus_type(dev->bus); 282 - if (!type) { 283 - DBG("No ACPI bus support for %s\n", dev_name(dev)); 284 - ret = -EINVAL; 285 - goto end; 281 + if (ret) { 282 + if (!type || !type->find_device) { 283 + DBG("No ACPI bus support for %s\n", dev_name(dev)); 284 + ret = -EINVAL; 285 + goto out; 286 + } 287 + 288 + ret = type->find_device(dev, &handle); 289 + if (ret) { 290 + DBG("Unable to get handle for %s\n", dev_name(dev)); 291 + goto out; 292 + } 293 + ret = acpi_bind_one(dev, handle); 294 + if (ret) 295 + goto out; 286 296 } 287 - if ((ret = type->find_device(dev, &handle)) != 0) 288 - DBG("Can't get handler for %s\n", dev_name(dev)); 289 - end: 290 - if (!ret) 291 - acpi_bind_one(dev, handle); 297 + 298 + if (type && type->setup) 299 + type->setup(dev); 292 300 293 301 out: 294 302 #if ACPI_GLUE_DEBUG ··· 318 304 319 305 static int acpi_platform_notify_remove(struct device *dev) 320 306 { 307 + struct acpi_bus_type *type; 308 + 309 + type = acpi_get_bus_type(dev->bus); 310 + if (type && type->cleanup) 311 + type->cleanup(dev); 312 + 321 313 acpi_unbind_one(dev); 322 314 return 0; 323 315 }
+1
drivers/acpi/internal.h
··· 67 67 68 68 extern struct acpi_ec *first_ec; 69 69 70 + int acpi_pci_root_init(void); 70 71 int acpi_ec_init(void); 71 72 int acpi_ec_ecdt_probe(void); 72 73 int acpi_boot_ec_enable(void);
-122
drivers/acpi/pci_bind.c
··· 1 - /* 2 - * pci_bind.c - ACPI PCI Device Binding ($Revision: 2 $) 3 - * 4 - * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com> 5 - * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> 6 - * 7 - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 8 - * 9 - * This program is free software; you can redistribute it and/or modify 10 - * it under the terms of the GNU General Public License as published by 11 - * the Free Software Foundation; either version 2 of the License, or (at 12 - * your option) any later version. 13 - * 14 - * This program is distributed in the hope that it will be useful, but 15 - * WITHOUT ANY WARRANTY; without even the implied warranty of 16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 - * General Public License for more details. 18 - * 19 - * You should have received a copy of the GNU General Public License along 20 - * with this program; if not, write to the Free Software Foundation, Inc., 21 - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 22 - * 23 - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 24 - */ 25 - 26 - #include <linux/kernel.h> 27 - #include <linux/types.h> 28 - #include <linux/pci.h> 29 - #include <linux/pci-acpi.h> 30 - #include <linux/acpi.h> 31 - #include <linux/pm_runtime.h> 32 - #include <acpi/acpi_bus.h> 33 - #include <acpi/acpi_drivers.h> 34 - 35 - #define _COMPONENT ACPI_PCI_COMPONENT 36 - ACPI_MODULE_NAME("pci_bind"); 37 - 38 - static int acpi_pci_unbind(struct acpi_device *device) 39 - { 40 - struct pci_dev *dev; 41 - 42 - dev = acpi_get_pci_dev(device->handle); 43 - if (!dev) 44 - goto out; 45 - 46 - device_set_run_wake(&dev->dev, false); 47 - pci_acpi_remove_pm_notifier(device); 48 - acpi_power_resource_unregister_device(&dev->dev, device->handle); 49 - 50 - if (!dev->subordinate) 51 - goto out; 52 - 53 - acpi_pci_irq_del_prt(pci_domain_nr(dev->bus), dev->subordinate->number); 54 - 55 - device->ops.bind = NULL; 56 - device->ops.unbind = NULL; 57 - 58 - out: 59 - pci_dev_put(dev); 60 - return 0; 61 - } 62 - 63 - static int acpi_pci_bind(struct acpi_device *device) 64 - { 65 - acpi_status status; 66 - acpi_handle handle; 67 - unsigned char bus; 68 - struct pci_dev *dev; 69 - 70 - dev = acpi_get_pci_dev(device->handle); 71 - if (!dev) 72 - return 0; 73 - 74 - pci_acpi_add_pm_notifier(device, dev); 75 - acpi_power_resource_register_device(&dev->dev, device->handle); 76 - if (device->wakeup.flags.run_wake) 77 - device_set_run_wake(&dev->dev, true); 78 - 79 - /* 80 - * Install the 'bind' function to facilitate callbacks for 81 - * children of the P2P bridge. 82 - */ 83 - if (dev->subordinate) { 84 - ACPI_DEBUG_PRINT((ACPI_DB_INFO, 85 - "Device %04x:%02x:%02x.%d is a PCI bridge\n", 86 - pci_domain_nr(dev->bus), dev->bus->number, 87 - PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn))); 88 - device->ops.bind = acpi_pci_bind; 89 - device->ops.unbind = acpi_pci_unbind; 90 - } 91 - 92 - /* 93 - * Evaluate and parse _PRT, if exists. This code allows parsing of 94 - * _PRT objects within the scope of non-bridge devices. Note that 95 - * _PRTs within the scope of a PCI bridge assume the bridge's 96 - * subordinate bus number. 97 - * 98 - * TBD: Can _PRTs exist within the scope of non-bridge PCI devices? 99 - */ 100 - status = acpi_get_handle(device->handle, METHOD_NAME__PRT, &handle); 101 - if (ACPI_FAILURE(status)) 102 - goto out; 103 - 104 - if (dev->subordinate) 105 - bus = dev->subordinate->number; 106 - else 107 - bus = dev->bus->number; 108 - 109 - acpi_pci_irq_add_prt(device->handle, pci_domain_nr(dev->bus), bus); 110 - 111 - out: 112 - pci_dev_put(dev); 113 - return 0; 114 - } 115 - 116 - int acpi_pci_bind_root(struct acpi_device *device) 117 - { 118 - device->ops.bind = acpi_pci_bind; 119 - device->ops.unbind = acpi_pci_unbind; 120 - 121 - return 0; 122 - }
+12 -55
drivers/acpi/pci_root.c
··· 47 47 #define ACPI_PCI_ROOT_DEVICE_NAME "PCI Root Bridge" 48 48 static int acpi_pci_root_add(struct acpi_device *device); 49 49 static int acpi_pci_root_remove(struct acpi_device *device, int type); 50 - static int acpi_pci_root_start(struct acpi_device *device); 51 50 52 51 #define ACPI_PCIE_REQ_SUPPORT (OSC_EXT_PCI_CONFIG_SUPPORT \ 53 52 | OSC_ACTIVE_STATE_PWR_SUPPORT \ ··· 66 67 .ops = { 67 68 .add = acpi_pci_root_add, 68 69 .remove = acpi_pci_root_remove, 69 - .start = acpi_pci_root_start, 70 70 }, 71 71 }; 72 72 ··· 184 186 if (res->start == -1) 185 187 return AE_ERROR; 186 188 return AE_OK; 187 - } 188 - 189 - static void acpi_pci_bridge_scan(struct acpi_device *device) 190 - { 191 - int status; 192 - struct acpi_device *child = NULL; 193 - 194 - if (device->flags.bus_address) 195 - if (device->parent && device->parent->ops.bind) { 196 - status = device->parent->ops.bind(device); 197 - if (!status) { 198 - list_for_each_entry(child, &device->children, node) 199 - acpi_pci_bridge_scan(child); 200 - } 201 - } 202 189 } 203 190 204 191 static u8 pci_osc_uuid_str[] = "33DB4D5B-1FF7-401C-9657-7441C03DD766"; ··· 435 452 int result; 436 453 struct acpi_pci_root *root; 437 454 acpi_handle handle; 438 - struct acpi_device *child; 455 + struct acpi_pci_driver *driver; 439 456 u32 flags, base_flags; 440 457 bool is_osc_granted = false; 441 458 ··· 586 603 goto out_del_root; 587 604 } 588 605 589 - /* 590 - * Attach ACPI-PCI Context 591 - * ----------------------- 592 - * Thus binding the ACPI and PCI devices. 593 - */ 594 - result = acpi_pci_bind_root(device); 595 - if (result) 596 - goto out_del_root; 597 - 598 - /* 599 - * Scan and bind all _ADR-Based Devices 600 - */ 601 - list_for_each_entry(child, &device->children, node) 602 - acpi_pci_bridge_scan(child); 603 - 604 606 /* ASPM setting */ 605 607 if (is_osc_granted) { 606 608 if (acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_ASPM) ··· 599 631 pci_acpi_add_bus_pm_notifier(device, root->bus); 600 632 if (device->wakeup.flags.run_wake) 601 633 device_set_run_wake(root->bus->bridge, true); 602 - 603 - return 0; 604 - 605 - out_del_root: 606 - mutex_lock(&acpi_pci_root_lock); 607 - list_del(&root->node); 608 - mutex_unlock(&acpi_pci_root_lock); 609 - 610 - acpi_pci_irq_del_prt(root->segment, root->secondary.start); 611 - end: 612 - kfree(root); 613 - return result; 614 - } 615 - 616 - static int acpi_pci_root_start(struct acpi_device *device) 617 - { 618 - struct acpi_pci_root *root = acpi_driver_data(device); 619 - struct acpi_pci_driver *driver; 620 634 621 635 if (system_state != SYSTEM_BOOTING) { 622 636 pcibios_resource_survey_bus(root->bus); ··· 616 666 pci_enable_bridges(root->bus); 617 667 618 668 pci_bus_add_devices(root->bus); 619 - 620 669 return 0; 670 + 671 + out_del_root: 672 + mutex_lock(&acpi_pci_root_lock); 673 + list_del(&root->node); 674 + mutex_unlock(&acpi_pci_root_lock); 675 + 676 + acpi_pci_irq_del_prt(root->segment, root->secondary.start); 677 + end: 678 + kfree(root); 679 + return result; 621 680 } 622 681 623 682 static int acpi_pci_root_remove(struct acpi_device *device, int type) ··· 660 701 return 0; 661 702 } 662 703 663 - static int __init acpi_pci_root_init(void) 704 + int __init acpi_pci_root_init(void) 664 705 { 665 706 acpi_hest_init(); 666 707 ··· 673 714 674 715 return 0; 675 716 } 676 - 677 - subsys_initcall(acpi_pci_root_init);
+6 -24
drivers/acpi/processor_driver.c
··· 677 677 return 0; 678 678 } 679 679 680 - static 681 - int acpi_processor_device_add(acpi_handle handle, struct acpi_device **device) 682 - { 683 - acpi_handle phandle; 684 - struct acpi_device *pdev; 685 - 686 - 687 - if (acpi_get_parent(handle, &phandle)) { 688 - return -ENODEV; 689 - } 690 - 691 - if (acpi_bus_get_device(phandle, &pdev)) { 692 - return -ENODEV; 693 - } 694 - 695 - if (acpi_bus_add(device, pdev, handle, ACPI_BUS_TYPE_PROCESSOR)) { 696 - return -ENODEV; 697 - } 698 - 699 - return 0; 700 - } 701 - 702 680 static void acpi_processor_hotplug_notify(acpi_handle handle, 703 681 u32 event, void *data) 704 682 { ··· 699 721 if (!acpi_bus_get_device(handle, &device)) 700 722 break; 701 723 702 - result = acpi_processor_device_add(handle, &device); 724 + result = acpi_bus_add(handle); 703 725 if (result) { 704 726 acpi_handle_err(handle, "Unable to add the device\n"); 705 727 break; 706 728 } 707 - 729 + result = acpi_bus_get_device(handle, &device); 730 + if (result) { 731 + acpi_handle_err(handle, "Missing device object\n"); 732 + break; 733 + } 708 734 ost_code = ACPI_OST_SC_SUCCESS; 709 735 break; 710 736
+82 -136
drivers/acpi/scan.c
··· 494 494 struct acpi_device *acpi_dev = to_acpi_device(dev); 495 495 struct acpi_driver *acpi_drv = to_acpi_driver(drv); 496 496 497 - return !acpi_match_device_ids(acpi_dev, acpi_drv->ids); 497 + return acpi_dev->flags.match_driver 498 + && !acpi_match_device_ids(acpi_dev, acpi_drv->ids); 498 499 } 499 500 500 501 static int acpi_device_uevent(struct device *dev, struct kobj_uevent_env *env) ··· 571 570 } 572 571 573 572 static int acpi_bus_driver_init(struct acpi_device *, struct acpi_driver *); 574 - static int acpi_start_single_object(struct acpi_device *); 575 573 static int acpi_device_probe(struct device * dev) 576 574 { 577 575 struct acpi_device *acpi_dev = to_acpi_device(dev); ··· 579 579 580 580 ret = acpi_bus_driver_init(acpi_dev, acpi_drv); 581 581 if (!ret) { 582 - if (acpi_dev->bus_ops.acpi_op_start) 583 - acpi_start_single_object(acpi_dev); 584 - 585 582 if (acpi_drv->ops.notify) { 586 583 ret = acpi_device_install_notify_handler(acpi_dev); 587 584 if (ret) { ··· 755 758 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 756 759 "Driver successfully bound to device\n")); 757 760 return 0; 758 - } 759 - 760 - static int acpi_start_single_object(struct acpi_device *device) 761 - { 762 - int result = 0; 763 - struct acpi_driver *driver; 764 - 765 - 766 - if (!(driver = device->driver)) 767 - return 0; 768 - 769 - if (driver->ops.start) { 770 - result = driver->ops.start(device); 771 - if (result && driver->ops.remove) 772 - driver->ops.remove(device, ACPI_BUS_REMOVAL_NORMAL); 773 - } 774 - 775 - return result; 776 761 } 777 762 778 763 /** ··· 1385 1406 if (!rmdevice) 1386 1407 return 0; 1387 1408 1388 - /* 1389 - * unbind _ADR-Based Devices when hot removal 1390 - */ 1391 - if (dev->flags.bus_address) { 1392 - if ((dev->parent) && (dev->parent->ops.unbind)) 1393 - dev->parent->ops.unbind(dev); 1394 - } 1395 1409 acpi_device_unregister(dev, ACPI_BUS_REMOVAL_EJECT); 1396 1410 1397 1411 return 0; ··· 1392 1420 1393 1421 static int acpi_add_single_object(struct acpi_device **child, 1394 1422 acpi_handle handle, int type, 1395 - unsigned long long sta, 1396 - struct acpi_bus_ops *ops) 1423 + unsigned long long sta, bool match_driver) 1397 1424 { 1398 1425 int result; 1399 1426 struct acpi_device *device; ··· 1408 1437 device->device_type = type; 1409 1438 device->handle = handle; 1410 1439 device->parent = acpi_bus_get_parent(handle); 1411 - device->bus_ops = *ops; /* workround for not call .start */ 1412 1440 STRUCT_TO_INT(device->status) = sta; 1413 1441 1414 1442 acpi_device_get_busid(device); ··· 1458 1488 if ((result = acpi_device_set_context(device))) 1459 1489 goto end; 1460 1490 1491 + device->flags.match_driver = match_driver; 1461 1492 result = acpi_device_register(device); 1462 - 1463 - /* 1464 - * Bind _ADR-Based Devices when hot add 1465 - */ 1466 - if (device->flags.bus_address) { 1467 - if (device->parent && device->parent->ops.bind) 1468 - device->parent->ops.bind(device); 1469 - } 1470 1493 1471 1494 end: 1472 1495 if (!result) { ··· 1482 1519 1483 1520 static void acpi_bus_add_power_resource(acpi_handle handle) 1484 1521 { 1485 - struct acpi_bus_ops ops = { 1486 - .acpi_op_add = 1, 1487 - .acpi_op_start = 1, 1488 - }; 1489 1522 struct acpi_device *device = NULL; 1490 1523 1491 1524 acpi_bus_get_device(handle, &device); 1492 1525 if (!device) 1493 1526 acpi_add_single_object(&device, handle, ACPI_BUS_TYPE_POWER, 1494 - ACPI_STA_DEFAULT, &ops); 1527 + ACPI_STA_DEFAULT, true); 1495 1528 } 1496 1529 1497 1530 static int acpi_bus_type_and_status(acpi_handle handle, int *type, ··· 1529 1570 return 0; 1530 1571 } 1531 1572 1532 - static acpi_status acpi_bus_check_add(acpi_handle handle, u32 lvl, 1533 - void *context, void **return_value) 1573 + static acpi_status acpi_bus_check_add(acpi_handle handle, u32 lvl_not_used, 1574 + void *not_used, void **return_value) 1534 1575 { 1535 - struct acpi_bus_ops *ops = context; 1576 + struct acpi_device *device = NULL; 1536 1577 int type; 1537 1578 unsigned long long sta; 1538 - struct acpi_device *device; 1539 1579 acpi_status status; 1540 1580 int result; 1581 + 1582 + acpi_bus_get_device(handle, &device); 1583 + if (device) 1584 + goto out; 1541 1585 1542 1586 result = acpi_bus_type_and_status(handle, &type, &sta); 1543 1587 if (result) ··· 1558 1596 return AE_CTRL_DEPTH; 1559 1597 } 1560 1598 1561 - /* 1562 - * We may already have an acpi_device from a previous enumeration. If 1563 - * so, we needn't add it again, but we may still have to start it. 1564 - */ 1565 - device = NULL; 1566 - acpi_bus_get_device(handle, &device); 1567 - if (ops->acpi_op_add && !device) { 1568 - acpi_add_single_object(&device, handle, type, sta, ops); 1569 - /* Is the device a known good platform device? */ 1570 - if (device 1571 - && !acpi_match_device_ids(device, acpi_platform_device_ids)) 1572 - acpi_create_platform_device(device); 1573 - } 1574 - 1599 + acpi_add_single_object(&device, handle, type, sta, 1600 + type == ACPI_BUS_TYPE_POWER); 1575 1601 if (!device) 1576 1602 return AE_CTRL_DEPTH; 1577 1603 1578 - if (ops->acpi_op_start && !(ops->acpi_op_add)) { 1579 - status = acpi_start_single_object(device); 1580 - if (ACPI_FAILURE(status)) 1581 - return AE_CTRL_DEPTH; 1582 - } 1604 + device->flags.match_driver = true; 1583 1605 1606 + out: 1584 1607 if (!*return_value) 1585 1608 *return_value = device; 1609 + 1586 1610 return AE_OK; 1587 1611 } 1588 1612 1589 - static int acpi_bus_scan(acpi_handle handle, struct acpi_bus_ops *ops, 1590 - struct acpi_device **child) 1613 + static acpi_status acpi_bus_device_attach(acpi_handle handle, u32 lvl_not_used, 1614 + void *not_used, void **ret_not_used) 1591 1615 { 1592 - acpi_status status; 1616 + acpi_status status = AE_OK; 1617 + struct acpi_device *device; 1618 + unsigned long long sta_not_used; 1619 + int type_not_used; 1620 + 1621 + /* 1622 + * Ignore errors ignored by acpi_bus_check_add() to avoid terminating 1623 + * namespace walks prematurely. 1624 + */ 1625 + if (acpi_bus_type_and_status(handle, &type_not_used, &sta_not_used)) 1626 + return AE_OK; 1627 + 1628 + if (acpi_bus_get_device(handle, &device)) 1629 + return AE_CTRL_DEPTH; 1630 + 1631 + if (!acpi_match_device_ids(device, acpi_platform_device_ids)) { 1632 + /* This is a known good platform device. */ 1633 + acpi_create_platform_device(device); 1634 + } else if (device_attach(&device->dev)) { 1635 + status = AE_CTRL_DEPTH; 1636 + } 1637 + return status; 1638 + } 1639 + 1640 + static int acpi_bus_scan(acpi_handle handle) 1641 + { 1593 1642 void *device = NULL; 1594 1643 1595 - status = acpi_bus_check_add(handle, 0, ops, &device); 1596 - if (ACPI_SUCCESS(status)) 1644 + if (ACPI_SUCCESS(acpi_bus_check_add(handle, 0, NULL, &device))) 1597 1645 acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX, 1598 - acpi_bus_check_add, NULL, ops, &device); 1599 - 1600 - if (child) 1601 - *child = device; 1602 - 1603 - if (device) 1604 - return 0; 1605 - else 1606 - return -ENODEV; 1607 - } 1608 - 1609 - /* 1610 - * acpi_bus_add and acpi_bus_start 1611 - * 1612 - * scan a given ACPI tree and (probably recently hot-plugged) 1613 - * create and add or starts found devices. 1614 - * 1615 - * If no devices were found -ENODEV is returned which does not 1616 - * mean that this is a real error, there just have been no suitable 1617 - * ACPI objects in the table trunk from which the kernel could create 1618 - * a device and add/start an appropriate driver. 1619 - */ 1620 - 1621 - int 1622 - acpi_bus_add(struct acpi_device **child, 1623 - struct acpi_device *parent, acpi_handle handle, int type) 1624 - { 1625 - struct acpi_bus_ops ops; 1626 - 1627 - memset(&ops, 0, sizeof(ops)); 1628 - ops.acpi_op_add = 1; 1629 - 1630 - return acpi_bus_scan(handle, &ops, child); 1631 - } 1632 - EXPORT_SYMBOL(acpi_bus_add); 1633 - 1634 - int acpi_bus_start(struct acpi_device *device) 1635 - { 1636 - struct acpi_bus_ops ops; 1637 - int result; 1646 + acpi_bus_check_add, NULL, NULL, &device); 1638 1647 1639 1648 if (!device) 1640 - return -EINVAL; 1649 + return -ENODEV; 1641 1650 1642 - memset(&ops, 0, sizeof(ops)); 1643 - ops.acpi_op_start = 1; 1651 + if (ACPI_SUCCESS(acpi_bus_device_attach(handle, 0, NULL, NULL))) 1652 + acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX, 1653 + acpi_bus_device_attach, NULL, NULL, NULL); 1644 1654 1645 - result = acpi_bus_scan(device->handle, &ops, NULL); 1655 + return 0; 1656 + } 1657 + 1658 + /** 1659 + * acpi_bus_add - Add ACPI device node objects in a given namespace scope. 1660 + * @handle: Root of the namespace scope to scan. 1661 + * 1662 + * Scan a given ACPI tree (probably recently hot-plugged) and create and add 1663 + * found devices. 1664 + * 1665 + * If no devices were found, -ENODEV is returned, but it does not mean that 1666 + * there has been a real error. There just have been no suitable ACPI objects 1667 + * in the table trunk from which the kernel could create a device and add an 1668 + * appropriate driver. 1669 + */ 1670 + int acpi_bus_add(acpi_handle handle) 1671 + { 1672 + int err; 1673 + 1674 + err = acpi_bus_scan(handle); 1675 + if (err) 1676 + return err; 1646 1677 1647 1678 acpi_update_all_gpes(); 1648 - 1649 - return result; 1679 + return 0; 1650 1680 } 1651 - EXPORT_SYMBOL(acpi_bus_start); 1681 + EXPORT_SYMBOL(acpi_bus_add); 1652 1682 1653 1683 int acpi_bus_trim(struct acpi_device *start, int rmdevice) 1654 1684 { ··· 1701 1747 { 1702 1748 int result = 0; 1703 1749 struct acpi_device *device = NULL; 1704 - struct acpi_bus_ops ops; 1705 - 1706 - memset(&ops, 0, sizeof(ops)); 1707 - ops.acpi_op_add = 1; 1708 - ops.acpi_op_start = 1; 1709 1750 1710 1751 /* 1711 1752 * Enumerate all fixed-feature devices. ··· 1708 1759 if ((acpi_gbl_FADT.flags & ACPI_FADT_POWER_BUTTON) == 0) { 1709 1760 result = acpi_add_single_object(&device, NULL, 1710 1761 ACPI_BUS_TYPE_POWER_BUTTON, 1711 - ACPI_STA_DEFAULT, 1712 - &ops); 1762 + ACPI_STA_DEFAULT, true); 1713 1763 device_init_wakeup(&device->dev, true); 1714 1764 } 1715 1765 1716 1766 if ((acpi_gbl_FADT.flags & ACPI_FADT_SLEEP_BUTTON) == 0) { 1717 1767 result = acpi_add_single_object(&device, NULL, 1718 1768 ACPI_BUS_TYPE_SLEEP_BUTTON, 1719 - ACPI_STA_DEFAULT, 1720 - &ops); 1769 + ACPI_STA_DEFAULT, true); 1721 1770 } 1722 1771 1723 1772 return result; ··· 1724 1777 int __init acpi_scan_init(void) 1725 1778 { 1726 1779 int result; 1727 - struct acpi_bus_ops ops; 1728 - 1729 - memset(&ops, 0, sizeof(ops)); 1730 - ops.acpi_op_add = 1; 1731 - ops.acpi_op_start = 1; 1732 1780 1733 1781 result = bus_register(&acpi_bus_type); 1734 1782 if (result) { ··· 1732 1790 } 1733 1791 1734 1792 acpi_power_init(); 1793 + acpi_pci_root_init(); 1735 1794 1736 1795 /* 1737 1796 * Enumerate devices in the ACPI namespace. 1738 1797 */ 1739 - result = acpi_bus_scan(ACPI_ROOT_OBJECT, &ops, &acpi_root); 1798 + result = acpi_bus_scan(ACPI_ROOT_OBJECT); 1799 + if (result) 1800 + return result; 1740 1801 1802 + result = acpi_bus_get_device(ACPI_ROOT_OBJECT, &acpi_root); 1741 1803 if (!result) 1742 1804 result = acpi_bus_scan_fixed(); 1743 1805
+14 -26
drivers/pci/hotplug/acpiphp_glue.c
··· 734 734 */ 735 735 static int acpiphp_bus_add(struct acpiphp_func *func) 736 736 { 737 - acpi_handle phandle; 738 - struct acpi_device *device, *pdevice; 737 + struct acpi_device *device; 739 738 int ret_val; 740 739 741 - acpi_get_parent(func->handle, &phandle); 742 - if (acpi_bus_get_device(phandle, &pdevice)) { 743 - dbg("no parent device, assuming NULL\n"); 744 - pdevice = NULL; 745 - } 746 740 if (!acpi_bus_get_device(func->handle, &device)) { 747 741 dbg("bus exists... trim\n"); 748 742 /* this shouldn't be in here, so remove ··· 746 752 dbg("acpi_bus_trim return %x\n", ret_val); 747 753 } 748 754 749 - ret_val = acpi_bus_add(&device, pdevice, func->handle, 750 - ACPI_BUS_TYPE_DEVICE); 751 - if (ret_val) { 752 - dbg("error adding bus, %x\n", 753 - -ret_val); 754 - goto acpiphp_bus_add_out; 755 - } 756 - ret_val = acpi_bus_start(device); 755 + ret_val = acpi_bus_add(func->handle); 756 + if (!ret_val) 757 + ret_val = acpi_bus_get_device(func->handle, &device); 757 758 758 - acpiphp_bus_add_out: 759 + if (ret_val) 760 + dbg("error adding bus, %x\n", -ret_val); 761 + 759 762 return ret_val; 760 763 } 761 764 ··· 1121 1130 1122 1131 static void handle_bridge_insertion(acpi_handle handle, u32 type) 1123 1132 { 1124 - struct acpi_device *device, *pdevice; 1125 - acpi_handle phandle; 1133 + struct acpi_device *device; 1126 1134 1127 1135 if ((type != ACPI_NOTIFY_BUS_CHECK) && 1128 1136 (type != ACPI_NOTIFY_DEVICE_CHECK)) { ··· 1129 1139 return; 1130 1140 } 1131 1141 1132 - acpi_get_parent(handle, &phandle); 1133 - if (acpi_bus_get_device(phandle, &pdevice)) { 1134 - dbg("no parent device, assuming NULL\n"); 1135 - pdevice = NULL; 1136 - } 1137 - if (acpi_bus_add(&device, pdevice, handle, ACPI_BUS_TYPE_DEVICE)) { 1142 + if (acpi_bus_add(handle)) { 1138 1143 err("cannot add bridge to acpi list\n"); 1139 1144 return; 1140 1145 } 1141 - if (!acpiphp_configure_bridge(handle) && 1142 - !acpi_bus_start(device)) 1146 + if (acpi_bus_get_device(handle, &device)) { 1147 + err("ACPI device object missing\n"); 1148 + return; 1149 + } 1150 + if (!acpiphp_configure_bridge(handle)) 1143 1151 add_bridge(handle); 1144 1152 else 1145 1153 err("cannot configure and start bridge\n");
+1 -5
drivers/pci/hotplug/sgi_hotplug.c
··· 412 412 if (SN_ACPI_BASE_SUPPORT() && ssdt) { 413 413 unsigned long long adr; 414 414 struct acpi_device *pdevice; 415 - struct acpi_device *device; 416 415 acpi_handle phandle; 417 416 acpi_handle chandle = NULL; 418 417 acpi_handle rethandle; ··· 447 448 if (ACPI_SUCCESS(ret) && 448 449 (adr>>16) == (slot->device_num + 1)) { 449 450 450 - ret = acpi_bus_add(&device, pdevice, chandle, 451 - ACPI_BUS_TYPE_DEVICE); 451 + ret = acpi_bus_add(chandle); 452 452 if (ACPI_FAILURE(ret)) { 453 453 printk(KERN_ERR "%s: acpi_bus_add " 454 454 "failed (0x%x) for slot %d " ··· 455 457 ret, (int)(adr>>16), 456 458 (int)(adr&0xffff)); 457 459 /* try to continue on */ 458 - } else { 459 - acpi_bus_start(device); 460 460 } 461 461 } 462 462 }
+57 -1
drivers/pci/pci-acpi.c
··· 283 283 .is_manageable = acpi_pci_power_manageable, 284 284 .set_state = acpi_pci_set_power_state, 285 285 .choose_state = acpi_pci_choose_state, 286 - .can_wakeup = acpi_pci_can_wakeup, 287 286 .sleep_wake = acpi_pci_sleep_wake, 288 287 .run_wake = acpi_pci_run_wake, 289 288 }; ··· 320 321 return 0; 321 322 } 322 323 324 + static void pci_acpi_setup(struct device *dev) 325 + { 326 + struct pci_dev *pci_dev = to_pci_dev(dev); 327 + acpi_handle handle = ACPI_HANDLE(dev); 328 + struct acpi_device *adev; 329 + acpi_status status; 330 + acpi_handle dummy; 331 + 332 + /* 333 + * Evaluate and parse _PRT, if exists. This code allows parsing of 334 + * _PRT objects within the scope of non-bridge devices. Note that 335 + * _PRTs within the scope of a PCI bridge assume the bridge's 336 + * subordinate bus number. 337 + * 338 + * TBD: Can _PRTs exist within the scope of non-bridge PCI devices? 339 + */ 340 + status = acpi_get_handle(handle, METHOD_NAME__PRT, &dummy); 341 + if (ACPI_SUCCESS(status)) { 342 + unsigned char bus; 343 + 344 + bus = pci_dev->subordinate ? 345 + pci_dev->subordinate->number : pci_dev->bus->number; 346 + acpi_pci_irq_add_prt(handle, pci_domain_nr(pci_dev->bus), bus); 347 + } 348 + 349 + acpi_power_resource_register_device(dev, handle); 350 + if (acpi_bus_get_device(handle, &adev) || !adev->wakeup.flags.valid) 351 + return; 352 + 353 + device_set_wakeup_capable(dev, true); 354 + acpi_pci_sleep_wake(pci_dev, false); 355 + 356 + pci_acpi_add_pm_notifier(adev, pci_dev); 357 + if (adev->wakeup.flags.run_wake) 358 + device_set_run_wake(dev, true); 359 + } 360 + 361 + static void pci_acpi_cleanup(struct device *dev) 362 + { 363 + struct pci_dev *pci_dev = to_pci_dev(dev); 364 + acpi_handle handle = ACPI_HANDLE(dev); 365 + struct acpi_device *adev; 366 + 367 + if (!acpi_bus_get_device(handle, &adev) && adev->wakeup.flags.valid) { 368 + device_set_wakeup_capable(dev, false); 369 + device_set_run_wake(dev, false); 370 + pci_acpi_remove_pm_notifier(adev); 371 + } 372 + acpi_power_resource_unregister_device(dev, handle); 373 + 374 + if (pci_dev->subordinate) 375 + acpi_pci_irq_del_prt(pci_domain_nr(pci_dev->bus), 376 + pci_dev->subordinate->number); 377 + } 378 + 323 379 static struct acpi_bus_type acpi_pci_bus = { 324 380 .bus = &pci_bus_type, 325 381 .find_device = acpi_pci_find_device, 326 382 .find_bridge = acpi_pci_find_root_bridge, 383 + .setup = pci_acpi_setup, 384 + .cleanup = pci_acpi_cleanup, 327 385 }; 328 386 329 387 static int __init acpi_pci_init(void)
+1 -25
drivers/pci/pci.c
··· 450 450 int pci_set_platform_pm(struct pci_platform_pm_ops *ops) 451 451 { 452 452 if (!ops->is_manageable || !ops->set_state || !ops->choose_state 453 - || !ops->sleep_wake || !ops->can_wakeup) 453 + || !ops->sleep_wake) 454 454 return -EINVAL; 455 455 pci_platform_pm = ops; 456 456 return 0; ··· 471 471 { 472 472 return pci_platform_pm ? 473 473 pci_platform_pm->choose_state(dev) : PCI_POWER_ERROR; 474 - } 475 - 476 - static inline bool platform_pci_can_wakeup(struct pci_dev *dev) 477 - { 478 - return pci_platform_pm ? pci_platform_pm->can_wakeup(dev) : false; 479 474 } 480 475 481 476 static inline int platform_pci_sleep_wake(struct pci_dev *dev, bool enable) ··· 1977 1982 } else { 1978 1983 dev->pme_support = 0; 1979 1984 } 1980 - } 1981 - 1982 - /** 1983 - * platform_pci_wakeup_init - init platform wakeup if present 1984 - * @dev: PCI device 1985 - * 1986 - * Some devices don't have PCI PM caps but can still generate wakeup 1987 - * events through platform methods (like ACPI events). If @dev supports 1988 - * platform wakeup events, set the device flag to indicate as much. This 1989 - * may be redundant if the device also supports PCI PM caps, but double 1990 - * initialization should be safe in that case. 1991 - */ 1992 - void platform_pci_wakeup_init(struct pci_dev *dev) 1993 - { 1994 - if (!platform_pci_can_wakeup(dev)) 1995 - return; 1996 - 1997 - device_set_wakeup_capable(&dev->dev, true); 1998 - platform_pci_sleep_wake(dev, false); 1999 1985 } 2000 1986 2001 1987 static void pci_add_saved_cap(struct pci_dev *pci_dev,
-5
drivers/pci/pci.h
··· 43 43 * platform; to be used during system-wide transitions from a 44 44 * sleeping state to the working state and vice versa 45 45 * 46 - * @can_wakeup: returns 'true' if given device is capable of waking up the 47 - * system from a sleeping state 48 - * 49 46 * @sleep_wake: enables/disables the system wake up capability of given device 50 47 * 51 48 * @run_wake: enables/disables the platform to generate run-time wake-up events ··· 56 59 bool (*is_manageable)(struct pci_dev *dev); 57 60 int (*set_state)(struct pci_dev *dev, pci_power_t state); 58 61 pci_power_t (*choose_state)(struct pci_dev *dev); 59 - bool (*can_wakeup)(struct pci_dev *dev); 60 62 int (*sleep_wake)(struct pci_dev *dev, bool enable); 61 63 int (*run_wake)(struct pci_dev *dev, bool enable); 62 64 }; ··· 70 74 extern void pci_config_pm_runtime_get(struct pci_dev *dev); 71 75 extern void pci_config_pm_runtime_put(struct pci_dev *dev); 72 76 extern void pci_pm_init(struct pci_dev *dev); 73 - extern void platform_pci_wakeup_init(struct pci_dev *dev); 74 77 extern void pci_allocate_cap_save_buffers(struct pci_dev *dev); 75 78 void pci_free_cap_save_buffers(struct pci_dev *dev); 76 79
-1
drivers/pci/probe.c
··· 1280 1280 1281 1281 /* Power Management */ 1282 1282 pci_pm_init(dev); 1283 - platform_pci_wakeup_init(dev); 1284 1283 1285 1284 /* Vital Product Data */ 1286 1285 pci_vpd_pci22_init(dev);
+5 -13
include/acpi/acpi_bus.h
··· 95 95 typedef int (*acpi_op_unbind) (struct acpi_device * device); 96 96 typedef void (*acpi_op_notify) (struct acpi_device * device, u32 event); 97 97 98 - struct acpi_bus_ops { 99 - u32 acpi_op_add:1; 100 - u32 acpi_op_start:1; 101 - }; 102 - 103 98 struct acpi_device_ops { 104 99 acpi_op_add add; 105 100 acpi_op_remove remove; 106 101 acpi_op_start start; 107 - acpi_op_bind bind; 108 - acpi_op_unbind unbind; 109 102 acpi_op_notify notify; 110 103 }; 111 104 ··· 141 148 u32 power_manageable:1; 142 149 u32 performance_manageable:1; 143 150 u32 eject_pending:1; 144 - u32 reserved:24; 151 + u32 match_driver:1; 152 + u32 reserved:23; 145 153 }; 146 154 147 155 /* File System */ ··· 277 283 struct acpi_driver *driver; 278 284 void *driver_data; 279 285 struct device dev; 280 - struct acpi_bus_ops bus_ops; /* workaround for different code path for hotplug */ 281 286 enum acpi_bus_removal_type removal_type; /* indicate for different removal type */ 282 287 u8 physical_node_count; 283 288 struct list_head physical_node_list; ··· 349 356 #endif 350 357 int acpi_bus_register_driver(struct acpi_driver *driver); 351 358 void acpi_bus_unregister_driver(struct acpi_driver *driver); 352 - int acpi_bus_add(struct acpi_device **child, struct acpi_device *parent, 353 - acpi_handle handle, int type); 359 + int acpi_bus_add(acpi_handle handle); 354 360 void acpi_bus_hot_remove_device(void *context); 355 361 int acpi_bus_trim(struct acpi_device *start, int rmdevice); 356 - int acpi_bus_start(struct acpi_device *device); 357 362 acpi_status acpi_bus_get_ejd(acpi_handle handle, acpi_handle * ejd); 358 363 int acpi_match_device_ids(struct acpi_device *device, 359 364 const struct acpi_device_id *ids); ··· 381 390 int (*find_device) (struct device *, acpi_handle *); 382 391 /* For bridges, such as PCI root bridge, IDE controller */ 383 392 int (*find_bridge) (struct device *, acpi_handle *); 393 + void (*setup)(struct device *); 394 + void (*cleanup)(struct device *); 384 395 }; 385 396 int register_acpi_bus_type(struct acpi_bus_type *); 386 397 int unregister_acpi_bus_type(struct acpi_bus_type *); ··· 390 397 struct acpi_pci_root { 391 398 struct list_head node; 392 399 struct acpi_device * device; 393 - struct acpi_pci_id id; 394 400 struct pci_bus *bus; 395 401 u16 segment; 396 402 struct resource secondary; /* downstream bus range */
+5
include/linux/acpi.h
··· 526 526 #endif 527 527 528 528 #if defined(CONFIG_ACPI) && defined(CONFIG_PM) 529 + struct acpi_device *acpi_dev_pm_get_node(struct device *dev); 529 530 int acpi_dev_pm_attach(struct device *dev, bool power_on); 530 531 void acpi_dev_pm_detach(struct device *dev, bool power_off); 531 532 #else 533 + static inline struct acpi_device *acpi_dev_pm_get_node(struct device *dev) 534 + { 535 + return NULL; 536 + } 532 537 static inline int acpi_dev_pm_attach(struct device *dev, bool power_on) 533 538 { 534 539 return -ENODEV;