···157157acpi_memory_get_device(acpi_handle handle,158158 struct acpi_memory_device **mem_device)159159{160160- acpi_status status;161161- acpi_handle phandle;162160 struct acpi_device *device = NULL;163163- struct acpi_device *pdevice = NULL;164161 int result;165165-166162167163 if (!acpi_bus_get_device(handle, &device) && device)168164 goto end;169169-170170- status = acpi_get_parent(handle, &phandle);171171- if (ACPI_FAILURE(status)) {172172- ACPI_EXCEPTION((AE_INFO, status, "Cannot find acpi parent"));173173- return -EINVAL;174174- }175175-176176- /* Get the parent device */177177- result = acpi_bus_get_device(phandle, &pdevice);178178- if (result) {179179- acpi_handle_warn(phandle, "Cannot get acpi bus device\n");180180- return -EINVAL;181181- }182165183166 /*184167 * Now add the notified device. This creates the acpi_device185168 * and invokes .add function186169 */187187- result = acpi_bus_add(&device, pdevice, handle, ACPI_BUS_TYPE_DEVICE);170170+ result = acpi_bus_scan(handle);188171 if (result) {189172 acpi_handle_warn(handle, "Cannot add acpi bus\n");173173+ return -EINVAL;174174+ }175175+ result = acpi_bus_get_device(handle, &device);176176+ if (result) {177177+ acpi_handle_warn(handle, "Missing device object\n");190178 return -EINVAL;191179 }192180···343355 break;344356 }345357346346- ej_event->handle = handle;358358+ ej_event->device = device;347359 ej_event->event = ACPI_NOTIFY_EJECT_REQUEST;348360 acpi_os_hotplug_execute(acpi_bus_hot_remove_device,349361 (void *)ej_event);
+6-25
drivers/acpi/container.c
···135135 return status;136136}137137138138-static int container_device_add(struct acpi_device **device, acpi_handle handle)139139-{140140- acpi_handle phandle;141141- struct acpi_device *pdev;142142- int result;143143-144144-145145- if (acpi_get_parent(handle, &phandle)) {146146- return -ENODEV;147147- }148148-149149- if (acpi_bus_get_device(phandle, &pdev)) {150150- return -ENODEV;151151- }152152-153153- if (acpi_bus_add(device, pdev, handle, ACPI_BUS_TYPE_DEVICE)) {154154- return -ENODEV;155155- }156156-157157- result = acpi_bus_start(*device);158158-159159- return result;160160-}161161-162138static void container_notify_cb(acpi_handle handle, u32 type, void *context)163139{164140 struct acpi_device *device = NULL;···166190 if (!ACPI_FAILURE(status) || device)167191 break;168192169169- result = container_device_add(&device, handle);193193+ result = acpi_bus_scan(handle);170194 if (result) {171195 acpi_handle_warn(handle, "Failed to add container\n");196196+ break;197197+ }198198+ result = acpi_bus_get_device(handle, &device);199199+ if (result) {200200+ acpi_handle_warn(handle, "Missing device object\n");172201 break;173202 }174203
+1-1
drivers/acpi/device_pm.c
···353353 * acpi_dev_pm_get_node - Get ACPI device node for the given physical device.354354 * @dev: Device to get the ACPI node for.355355 */356356-static struct acpi_device *acpi_dev_pm_get_node(struct device *dev)356356+struct acpi_device *acpi_dev_pm_get_node(struct device *dev)357357{358358 acpi_handle handle = DEVICE_ACPI_HANDLE(dev);359359 struct acpi_device *adev;
+5-12
drivers/acpi/dock.c
···310310static struct acpi_device * dock_create_acpi_device(acpi_handle handle)311311{312312 struct acpi_device *device;313313- struct acpi_device *parent_device;314314- acpi_handle parent;315313 int ret;316314317315 if (acpi_bus_get_device(handle, &device)) {···317319 * no device created for this object,318320 * so we should create one.319321 */320320- acpi_get_parent(handle, &parent);321321- if (acpi_bus_get_device(parent, &parent_device))322322- parent_device = NULL;323323-324324- ret = acpi_bus_add(&device, parent_device, handle,325325- ACPI_BUS_TYPE_DEVICE);326326- if (ret) {322322+ ret = acpi_bus_scan(handle);323323+ if (ret)327324 pr_debug("error adding bus, %x\n", -ret);328328- return NULL;329329- }325325+326326+ acpi_bus_get_device(handle, &device);330327 }331328 return device;332329}···339346 int ret;340347341348 if (!acpi_bus_get_device(handle, &device)) {342342- ret = acpi_bus_trim(device, 1);349349+ ret = acpi_bus_trim(device);343350 if (ret)344351 pr_debug("error removing bus, %x\n", -ret);345352 }
+35-15
drivers/acpi/glue.c
···6868{6969 struct acpi_bus_type *tmp, *ret = NULL;70707171+ if (!type)7272+ return NULL;7373+7174 down_read(&bus_type_sem);7275 list_for_each_entry(tmp, &bus_type_list, list) {7376 if (tmp->bus == type) {···272269{273270 struct acpi_bus_type *type;274271 acpi_handle handle;275275- int ret = -EINVAL;272272+ int ret;276273277274 ret = acpi_bind_one(dev, NULL);278278- if (!ret)279279- goto out;280280-281281- if (!dev->bus || !dev->parent) {275275+ if (ret && (!dev->bus || !dev->parent)) {282276 /* bridge devices genernally haven't bus or parent */283277 ret = acpi_find_bridge_device(dev, &handle);284284- goto end;278278+ if (!ret) {279279+ ret = acpi_bind_one(dev, handle);280280+ if (ret)281281+ goto out;282282+ }285283 }284284+286285 type = acpi_get_bus_type(dev->bus);287287- if (!type) {288288- DBG("No ACPI bus support for %s\n", dev_name(dev));289289- ret = -EINVAL;290290- goto end;286286+ if (ret) {287287+ if (!type || !type->find_device) {288288+ DBG("No ACPI bus support for %s\n", dev_name(dev));289289+ ret = -EINVAL;290290+ goto out;291291+ }292292+293293+ ret = type->find_device(dev, &handle);294294+ if (ret) {295295+ DBG("Unable to get handle for %s\n", dev_name(dev));296296+ goto out;297297+ }298298+ ret = acpi_bind_one(dev, handle);299299+ if (ret)300300+ goto out;291301 }292292- if ((ret = type->find_device(dev, &handle)) != 0)293293- DBG("Can't get handler for %s\n", dev_name(dev));294294- end:295295- if (!ret)296296- acpi_bind_one(dev, handle);302302+303303+ if (type && type->setup)304304+ type->setup(dev);297305298306 out:299307#if ACPI_GLUE_DEBUG···323309324310static int acpi_platform_notify_remove(struct device *dev)325311{312312+ struct acpi_bus_type *type;313313+314314+ type = acpi_get_bus_type(dev->bus);315315+ if (type && type->cleanup)316316+ type->cleanup(dev);317317+326318 acpi_unbind_one(dev);327319 return 0;328320}
···11-/*22- * pci_bind.c - ACPI PCI Device Binding ($Revision: 2 $)33- *44- * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>55- * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>66- *77- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~88- *99- * This program is free software; you can redistribute it and/or modify1010- * it under the terms of the GNU General Public License as published by1111- * the Free Software Foundation; either version 2 of the License, or (at1212- * your option) any later version.1313- *1414- * This program is distributed in the hope that it will be useful, but1515- * WITHOUT ANY WARRANTY; without even the implied warranty of1616- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU1717- * General Public License for more details.1818- *1919- * You should have received a copy of the GNU General Public License along2020- * with this program; if not, write to the Free Software Foundation, Inc.,2121- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.2222- *2323- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~2424- */2525-2626-#include <linux/kernel.h>2727-#include <linux/types.h>2828-#include <linux/pci.h>2929-#include <linux/pci-acpi.h>3030-#include <linux/acpi.h>3131-#include <linux/pm_runtime.h>3232-#include <acpi/acpi_bus.h>3333-#include <acpi/acpi_drivers.h>3434-3535-#define _COMPONENT ACPI_PCI_COMPONENT3636-ACPI_MODULE_NAME("pci_bind");3737-3838-static int acpi_pci_unbind(struct acpi_device *device)3939-{4040- struct pci_dev *dev;4141-4242- dev = acpi_get_pci_dev(device->handle);4343- if (!dev)4444- goto out;4545-4646- device_set_run_wake(&dev->dev, false);4747- pci_acpi_remove_pm_notifier(device);4848- acpi_power_resource_unregister_device(&dev->dev, device->handle);4949-5050- if (!dev->subordinate)5151- goto out;5252-5353- acpi_pci_irq_del_prt(pci_domain_nr(dev->bus), dev->subordinate->number);5454-5555- device->ops.bind = NULL;5656- device->ops.unbind = NULL;5757-5858-out:5959- pci_dev_put(dev);6060- return 0;6161-}6262-6363-static int acpi_pci_bind(struct acpi_device *device)6464-{6565- acpi_status status;6666- acpi_handle handle;6767- unsigned char bus;6868- struct pci_dev *dev;6969-7070- dev = acpi_get_pci_dev(device->handle);7171- if (!dev)7272- return 0;7373-7474- pci_acpi_add_pm_notifier(device, dev);7575- acpi_power_resource_register_device(&dev->dev, device->handle);7676- if (device->wakeup.flags.run_wake)7777- device_set_run_wake(&dev->dev, true);7878-7979- /*8080- * Install the 'bind' function to facilitate callbacks for8181- * children of the P2P bridge.8282- */8383- if (dev->subordinate) {8484- ACPI_DEBUG_PRINT((ACPI_DB_INFO,8585- "Device %04x:%02x:%02x.%d is a PCI bridge\n",8686- pci_domain_nr(dev->bus), dev->bus->number,8787- PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn)));8888- device->ops.bind = acpi_pci_bind;8989- device->ops.unbind = acpi_pci_unbind;9090- }9191-9292- /*9393- * Evaluate and parse _PRT, if exists. This code allows parsing of9494- * _PRT objects within the scope of non-bridge devices. Note that9595- * _PRTs within the scope of a PCI bridge assume the bridge's9696- * subordinate bus number.9797- *9898- * TBD: Can _PRTs exist within the scope of non-bridge PCI devices?9999- */100100- status = acpi_get_handle(device->handle, METHOD_NAME__PRT, &handle);101101- if (ACPI_FAILURE(status))102102- goto out;103103-104104- if (dev->subordinate)105105- bus = dev->subordinate->number;106106- else107107- bus = dev->bus->number;108108-109109- acpi_pci_irq_add_prt(device->handle, pci_domain_nr(dev->bus), bus);110110-111111-out:112112- pci_dev_put(dev);113113- return 0;114114-}115115-116116-int acpi_pci_bind_root(struct acpi_device *device)117117-{118118- device->ops.bind = acpi_pci_bind;119119- device->ops.unbind = acpi_pci_unbind;120120-121121- return 0;122122-}
+12-55
drivers/acpi/pci_root.c
···4747#define ACPI_PCI_ROOT_DEVICE_NAME "PCI Root Bridge"4848static int acpi_pci_root_add(struct acpi_device *device);4949static int acpi_pci_root_remove(struct acpi_device *device, int type);5050-static int acpi_pci_root_start(struct acpi_device *device);51505251#define ACPI_PCIE_REQ_SUPPORT (OSC_EXT_PCI_CONFIG_SUPPORT \5352 | OSC_ACTIVE_STATE_PWR_SUPPORT \···6667 .ops = {6768 .add = acpi_pci_root_add,6869 .remove = acpi_pci_root_remove,6969- .start = acpi_pci_root_start,7070 },7171};7272···184186 if (res->start == -1)185187 return AE_ERROR;186188 return AE_OK;187187-}188188-189189-static void acpi_pci_bridge_scan(struct acpi_device *device)190190-{191191- int status;192192- struct acpi_device *child = NULL;193193-194194- if (device->flags.bus_address)195195- if (device->parent && device->parent->ops.bind) {196196- status = device->parent->ops.bind(device);197197- if (!status) {198198- list_for_each_entry(child, &device->children, node)199199- acpi_pci_bridge_scan(child);200200- }201201- }202189}203190204191static u8 pci_osc_uuid_str[] = "33DB4D5B-1FF7-401C-9657-7441C03DD766";···435452 int result;436453 struct acpi_pci_root *root;437454 acpi_handle handle;438438- struct acpi_device *child;455455+ struct acpi_pci_driver *driver;439456 u32 flags, base_flags;440457 bool is_osc_granted = false;441458···586603 goto out_del_root;587604 }588605589589- /*590590- * Attach ACPI-PCI Context591591- * -----------------------592592- * Thus binding the ACPI and PCI devices.593593- */594594- result = acpi_pci_bind_root(device);595595- if (result)596596- goto out_del_root;597597-598598- /*599599- * Scan and bind all _ADR-Based Devices600600- */601601- list_for_each_entry(child, &device->children, node)602602- acpi_pci_bridge_scan(child);603603-604606 /* ASPM setting */605607 if (is_osc_granted) {606608 if (acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_ASPM)···599631 pci_acpi_add_bus_pm_notifier(device, root->bus);600632 if (device->wakeup.flags.run_wake)601633 device_set_run_wake(root->bus->bridge, true);602602-603603- return 0;604604-605605-out_del_root:606606- mutex_lock(&acpi_pci_root_lock);607607- list_del(&root->node);608608- mutex_unlock(&acpi_pci_root_lock);609609-610610- acpi_pci_irq_del_prt(root->segment, root->secondary.start);611611-end:612612- kfree(root);613613- return result;614614-}615615-616616-static int acpi_pci_root_start(struct acpi_device *device)617617-{618618- struct acpi_pci_root *root = acpi_driver_data(device);619619- struct acpi_pci_driver *driver;620634621635 if (system_state != SYSTEM_BOOTING)622636 pci_assign_unassigned_bus_resources(root->bus);···614664 pci_enable_bridges(root->bus);615665616666 pci_bus_add_devices(root->bus);617617-618667 return 0;668668+669669+out_del_root:670670+ mutex_lock(&acpi_pci_root_lock);671671+ list_del(&root->node);672672+ mutex_unlock(&acpi_pci_root_lock);673673+674674+ acpi_pci_irq_del_prt(root->segment, root->secondary.start);675675+end:676676+ kfree(root);677677+ return result;619678}620679621680static int acpi_pci_root_remove(struct acpi_device *device, int type)···658699 return 0;659700}660701661661-static int __init acpi_pci_root_init(void)702702+int __init acpi_pci_root_init(void)662703{663704 acpi_hest_init();664705···671712672713 return 0;673714}674674-675675-subsys_initcall(acpi_pci_root_init);
+7-25
drivers/acpi/processor_driver.c
···677677 return 0;678678}679679680680-static681681-int acpi_processor_device_add(acpi_handle handle, struct acpi_device **device)682682-{683683- acpi_handle phandle;684684- struct acpi_device *pdev;685685-686686-687687- if (acpi_get_parent(handle, &phandle)) {688688- return -ENODEV;689689- }690690-691691- if (acpi_bus_get_device(phandle, &pdev)) {692692- return -ENODEV;693693- }694694-695695- if (acpi_bus_add(device, pdev, handle, ACPI_BUS_TYPE_PROCESSOR)) {696696- return -ENODEV;697697- }698698-699699- return 0;700700-}701701-702680static void acpi_processor_hotplug_notify(acpi_handle handle,703681 u32 event, void *data)704682{···699721 if (!acpi_bus_get_device(handle, &device))700722 break;701723702702- result = acpi_processor_device_add(handle, &device);724724+ result = acpi_bus_scan(handle);703725 if (result) {704726 acpi_handle_err(handle, "Unable to add the device\n");705727 break;706728 }707707-729729+ result = acpi_bus_get_device(handle, &device);730730+ if (result) {731731+ acpi_handle_err(handle, "Missing device object\n");732732+ break;733733+ }708734 ost_code = ACPI_OST_SC_SUCCESS;709735 break;710736···733751 break;734752 }735753736736- ej_event->handle = handle;754754+ ej_event->device = device;737755 ej_event->event = ACPI_NOTIFY_EJECT_REQUEST;738756 acpi_os_hotplug_execute(acpi_bus_hot_remove_device,739757 (void *)ej_event);
+125-223
drivers/acpi/scan.c
···116116void acpi_bus_hot_remove_device(void *context)117117{118118 struct acpi_eject_event *ej_event = (struct acpi_eject_event *) context;119119- struct acpi_device *device;120120- acpi_handle handle = ej_event->handle;119119+ struct acpi_device *device = ej_event->device;120120+ acpi_handle handle = device->handle;121121 acpi_handle temp;122122 struct acpi_object_list arg_list;123123 union acpi_object arg;124124 acpi_status status = AE_OK;125125 u32 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE; /* default */126126127127- if (acpi_bus_get_device(handle, &device))128128- goto err_out;129129-130130- if (!device)131131- goto err_out;132132-133127 ACPI_DEBUG_PRINT((ACPI_DB_INFO,134128 "Hot-removing device %s...\n", dev_name(&device->dev)));135129136136- if (acpi_bus_trim(device, 1)) {130130+ if (acpi_bus_trim(device)) {137131 printk(KERN_ERR PREFIX138132 "Removing device failed\n");139133 goto err_out;···209215 goto err;210216 }211217212212- ej_event->handle = acpi_device->handle;218218+ ej_event->device = acpi_device;213219 if (acpi_device->flags.eject_pending) {214220 /* event originated from ACPI eject notification */215221 ej_event->event = ACPI_NOTIFY_EJECT_REQUEST;···217223 } else {218224 /* event originated from user */219225 ej_event->event = ACPI_OST_EC_OSPM_EJECT;220220- (void) acpi_evaluate_hotplug_ost(ej_event->handle,226226+ (void) acpi_evaluate_hotplug_ost(acpi_device->handle,221227 ej_event->event, ACPI_OST_SC_EJECT_IN_PROGRESS, NULL);222228 }223229···488494 struct acpi_device *acpi_dev = to_acpi_device(dev);489495 struct acpi_driver *acpi_drv = to_acpi_driver(drv);490496491491- return !acpi_match_device_ids(acpi_dev, acpi_drv->ids);497497+ return acpi_dev->flags.match_driver498498+ && !acpi_match_device_ids(acpi_dev, acpi_drv->ids);492499}493500494501static int acpi_device_uevent(struct device *dev, struct kobj_uevent_env *env)···565570}566571567572static int acpi_bus_driver_init(struct acpi_device *, struct acpi_driver *);568568-static int acpi_start_single_object(struct acpi_device *);569573static int acpi_device_probe(struct device * dev)570574{571575 struct acpi_device *acpi_dev = to_acpi_device(dev);···573579574580 ret = acpi_bus_driver_init(acpi_dev, acpi_drv);575581 if (!ret) {576576- if (acpi_dev->bus_ops.acpi_op_start)577577- acpi_start_single_object(acpi_dev);578578-579582 if (acpi_drv->ops.notify) {580583 ret = acpi_device_install_notify_handler(acpi_dev);581584 if (ret) {···695704 return result;696705}697706698698-static void acpi_device_unregister(struct acpi_device *device, int type)707707+static void acpi_device_unregister(struct acpi_device *device)699708{700709 mutex_lock(&acpi_device_lock);701710 if (device->parent)···749758 ACPI_DEBUG_PRINT((ACPI_DB_INFO,750759 "Driver successfully bound to device\n"));751760 return 0;752752-}753753-754754-static int acpi_start_single_object(struct acpi_device *device)755755-{756756- int result = 0;757757- struct acpi_driver *driver;758758-759759-760760- if (!(driver = device->driver))761761- return 0;762762-763763- if (driver->ops.start) {764764- result = driver->ops.start(device);765765- if (result && driver->ops.remove)766766- driver->ops.remove(device, ACPI_BUS_REMOVAL_NORMAL);767767- }768768-769769- return result;770761}771762772763/**···13681395 return -ENODEV;13691396}1370139713711371-static int acpi_bus_remove(struct acpi_device *dev, int rmdevice)13721372-{13731373- if (!dev)13741374- return -EINVAL;13751375-13761376- dev->removal_type = ACPI_BUS_REMOVAL_EJECT;13771377- device_release_driver(&dev->dev);13781378-13791379- if (!rmdevice)13801380- return 0;13811381-13821382- /*13831383- * unbind _ADR-Based Devices when hot removal13841384- */13851385- if (dev->flags.bus_address) {13861386- if ((dev->parent) && (dev->parent->ops.unbind))13871387- dev->parent->ops.unbind(dev);13881388- }13891389- acpi_device_unregister(dev, ACPI_BUS_REMOVAL_EJECT);13901390-13911391- return 0;13921392-}13931393-13941398static int acpi_add_single_object(struct acpi_device **child,13951399 acpi_handle handle, int type,13961396- unsigned long long sta,13971397- struct acpi_bus_ops *ops)14001400+ unsigned long long sta, bool match_driver)13981401{13991402 int result;14001403 struct acpi_device *device;···13861437 device->device_type = type;13871438 device->handle = handle;13881439 device->parent = acpi_bus_get_parent(handle);13891389- device->bus_ops = *ops; /* workround for not call .start */13901440 STRUCT_TO_INT(device->status) = sta;1391144113921442 acpi_device_get_busid(device);···14361488 if ((result = acpi_device_set_context(device)))14371489 goto end;1438149014911491+ device->flags.match_driver = match_driver;14391492 result = acpi_device_register(device);14401440-14411441- /*14421442- * Bind _ADR-Based Devices when hot add14431443- */14441444- if (device->flags.bus_address) {14451445- if (device->parent && device->parent->ops.bind)14461446- device->parent->ops.bind(device);14471447- }1448149314491494end:14501495 if (!result) {···1460151914611520static void acpi_bus_add_power_resource(acpi_handle handle)14621521{14631463- struct acpi_bus_ops ops = {14641464- .acpi_op_add = 1,14651465- .acpi_op_start = 1,14661466- };14671522 struct acpi_device *device = NULL;1468152314691524 acpi_bus_get_device(handle, &device);14701525 if (!device)14711526 acpi_add_single_object(&device, handle, ACPI_BUS_TYPE_POWER,14721472- ACPI_STA_DEFAULT, &ops);15271527+ ACPI_STA_DEFAULT, true);14731528}1474152914751530static int acpi_bus_type_and_status(acpi_handle handle, int *type,···15071570 return 0;15081571}1509157215101510-static acpi_status acpi_bus_check_add(acpi_handle handle, u32 lvl,15111511- void *context, void **return_value)15731573+static acpi_status acpi_bus_check_add(acpi_handle handle, u32 lvl_not_used,15741574+ void *not_used, void **return_value)15121575{15131513- struct acpi_bus_ops *ops = context;15761576+ struct acpi_device *device = NULL;15141577 int type;15151578 unsigned long long sta;15161516- struct acpi_device *device;15171579 acpi_status status;15181580 int result;15811581+15821582+ acpi_bus_get_device(handle, &device);15831583+ if (device)15841584+ goto out;1519158515201586 result = acpi_bus_type_and_status(handle, &type, &sta);15211587 if (result)···15361596 return AE_CTRL_DEPTH;15371597 }1538159815391539- /*15401540- * We may already have an acpi_device from a previous enumeration. If15411541- * so, we needn't add it again, but we may still have to start it.15421542- */15431543- device = NULL;15441544- acpi_bus_get_device(handle, &device);15451545- if (ops->acpi_op_add && !device) {15461546- acpi_add_single_object(&device, handle, type, sta, ops);15471547- /* Is the device a known good platform device? */15481548- if (device15491549- && !acpi_match_device_ids(device, acpi_platform_device_ids))15501550- acpi_create_platform_device(device);15511551- }15521552-15991599+ acpi_add_single_object(&device, handle, type, sta,16001600+ type == ACPI_BUS_TYPE_POWER);15531601 if (!device)15541602 return AE_CTRL_DEPTH;1555160315561556- if (ops->acpi_op_start && !(ops->acpi_op_add)) {15571557- status = acpi_start_single_object(device);15581558- if (ACPI_FAILURE(status))15591559- return AE_CTRL_DEPTH;15601560- }16041604+ device->flags.match_driver = true;1561160516061606+ out:15621607 if (!*return_value)15631608 *return_value = device;16091609+15641610 return AE_OK;15651611}1566161215671567-static int acpi_bus_scan(acpi_handle handle, struct acpi_bus_ops *ops,15681568- struct acpi_device **child)16131613+static acpi_status acpi_bus_device_attach(acpi_handle handle, u32 lvl_not_used,16141614+ void *not_used, void **ret_not_used)15691615{15701570- acpi_status status;16161616+ acpi_status status = AE_OK;16171617+ struct acpi_device *device;16181618+ unsigned long long sta_not_used;16191619+ int type_not_used;16201620+16211621+ /*16221622+ * Ignore errors ignored by acpi_bus_check_add() to avoid terminating16231623+ * namespace walks prematurely.16241624+ */16251625+ if (acpi_bus_type_and_status(handle, &type_not_used, &sta_not_used))16261626+ return AE_OK;16271627+16281628+ if (acpi_bus_get_device(handle, &device))16291629+ return AE_CTRL_DEPTH;16301630+16311631+ if (!acpi_match_device_ids(device, acpi_platform_device_ids)) {16321632+ /* This is a known good platform device. */16331633+ acpi_create_platform_device(device);16341634+ } else if (device_attach(&device->dev) < 0) {16351635+ status = AE_CTRL_DEPTH;16361636+ }16371637+ return status;16381638+}16391639+16401640+/**16411641+ * acpi_bus_scan - Add ACPI device node objects in a given namespace scope.16421642+ * @handle: Root of the namespace scope to scan.16431643+ *16441644+ * Scan a given ACPI tree (probably recently hot-plugged) and create and add16451645+ * found devices.16461646+ *16471647+ * If no devices were found, -ENODEV is returned, but it does not mean that16481648+ * there has been a real error. There just have been no suitable ACPI objects16491649+ * in the table trunk from which the kernel could create a device and add an16501650+ * appropriate driver.16511651+ */16521652+int acpi_bus_scan(acpi_handle handle)16531653+{15711654 void *device = NULL;1572165515731573- status = acpi_bus_check_add(handle, 0, ops, &device);15741574- if (ACPI_SUCCESS(status))16561656+ if (ACPI_SUCCESS(acpi_bus_check_add(handle, 0, NULL, &device)))15751657 acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,15761576- acpi_bus_check_add, NULL, ops, &device);15771577-15781578- if (child)15791579- *child = device;15801580-15811581- if (device)15821582- return 0;15831583- else15841584- return -ENODEV;15851585-}15861586-15871587-/*15881588- * acpi_bus_add and acpi_bus_start15891589- *15901590- * scan a given ACPI tree and (probably recently hot-plugged)15911591- * create and add or starts found devices.15921592- *15931593- * If no devices were found -ENODEV is returned which does not15941594- * mean that this is a real error, there just have been no suitable15951595- * ACPI objects in the table trunk from which the kernel could create15961596- * a device and add/start an appropriate driver.15971597- */15981598-15991599-int16001600-acpi_bus_add(struct acpi_device **child,16011601- struct acpi_device *parent, acpi_handle handle, int type)16021602-{16031603- struct acpi_bus_ops ops;16041604-16051605- memset(&ops, 0, sizeof(ops));16061606- ops.acpi_op_add = 1;16071607-16081608- return acpi_bus_scan(handle, &ops, child);16091609-}16101610-EXPORT_SYMBOL(acpi_bus_add);16111611-16121612-int acpi_bus_start(struct acpi_device *device)16131613-{16141614- struct acpi_bus_ops ops;16151615- int result;16581658+ acpi_bus_check_add, NULL, NULL, &device);1616165916171660 if (!device)16181618- return -EINVAL;16611661+ return -ENODEV;1619166216201620- memset(&ops, 0, sizeof(ops));16211621- ops.acpi_op_start = 1;16631663+ if (ACPI_SUCCESS(acpi_bus_device_attach(handle, 0, NULL, NULL)))16641664+ acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,16651665+ acpi_bus_device_attach, NULL, NULL, NULL);1622166616231623- result = acpi_bus_scan(device->handle, &ops, NULL);16241624-16251625- acpi_update_all_gpes();16261626-16271627- return result;16671667+ return 0;16281668}16291629-EXPORT_SYMBOL(acpi_bus_start);16691669+EXPORT_SYMBOL(acpi_bus_scan);1630167016311631-int acpi_bus_trim(struct acpi_device *start, int rmdevice)16711671+static acpi_status acpi_bus_device_detach(acpi_handle handle, u32 lvl_not_used,16721672+ void *not_used, void **ret_not_used)16321673{16331633- acpi_status status;16341634- struct acpi_device *parent, *child;16351635- acpi_handle phandle, chandle;16361636- acpi_object_type type;16371637- u32 level = 1;16381638- int err = 0;16741674+ struct acpi_device *device = NULL;1639167516401640- parent = start;16411641- phandle = start->handle;16421642- child = chandle = NULL;16431643-16441644- while ((level > 0) && parent && (!err)) {16451645- status = acpi_get_next_object(ACPI_TYPE_ANY, phandle,16461646- chandle, &chandle);16471647-16481648- /*16491649- * If this scope is exhausted then move our way back up.16501650- */16511651- if (ACPI_FAILURE(status)) {16521652- level--;16531653- chandle = phandle;16541654- acpi_get_parent(phandle, &phandle);16551655- child = parent;16561656- parent = parent->parent;16571657-16581658- if (level == 0)16591659- err = acpi_bus_remove(child, rmdevice);16601660- else16611661- err = acpi_bus_remove(child, 1);16621662-16631663- continue;16641664- }16651665-16661666- status = acpi_get_type(chandle, &type);16671667- if (ACPI_FAILURE(status)) {16681668- continue;16691669- }16701670- /*16711671- * If there is a device corresponding to chandle then16721672- * parse it (depth-first).16731673- */16741674- if (acpi_bus_get_device(chandle, &child) == 0) {16751675- level++;16761676- phandle = chandle;16771677- chandle = NULL;16781678- parent = child;16791679- }16801680- continue;16761676+ if (!acpi_bus_get_device(handle, &device)) {16771677+ device->removal_type = ACPI_BUS_REMOVAL_EJECT;16781678+ device_release_driver(&device->dev);16811679 }16821682- return err;16801680+ return AE_OK;16811681+}16821682+16831683+static acpi_status acpi_bus_remove(acpi_handle handle, u32 lvl_not_used,16841684+ void *not_used, void **ret_not_used)16851685+{16861686+ struct acpi_device *device = NULL;16871687+16881688+ if (!acpi_bus_get_device(handle, &device))16891689+ acpi_device_unregister(device);16901690+16911691+ return AE_OK;16921692+}16931693+16941694+int acpi_bus_trim(struct acpi_device *start)16951695+{16961696+ /*16971697+ * Execute acpi_bus_device_detach() as a post-order callback to detach16981698+ * all ACPI drivers from the device nodes being removed.16991699+ */17001700+ acpi_walk_namespace(ACPI_TYPE_ANY, start->handle, ACPI_UINT32_MAX, NULL,17011701+ acpi_bus_device_detach, NULL, NULL);17021702+ acpi_bus_device_detach(start->handle, 0, NULL, NULL);17031703+ /*17041704+ * Execute acpi_bus_remove() as a post-order callback to remove device17051705+ * nodes in the given namespace scope.17061706+ */17071707+ acpi_walk_namespace(ACPI_TYPE_ANY, start->handle, ACPI_UINT32_MAX, NULL,17081708+ acpi_bus_remove, NULL, NULL);17091709+ acpi_bus_remove(start->handle, 0, NULL, NULL);17101710+ return 0;16831711}16841712EXPORT_SYMBOL_GPL(acpi_bus_trim);16851713···16551747{16561748 int result = 0;16571749 struct acpi_device *device = NULL;16581658- struct acpi_bus_ops ops;16591659-16601660- memset(&ops, 0, sizeof(ops));16611661- ops.acpi_op_add = 1;16621662- ops.acpi_op_start = 1;1663175016641751 /*16651752 * Enumerate all fixed-feature devices.···16621759 if ((acpi_gbl_FADT.flags & ACPI_FADT_POWER_BUTTON) == 0) {16631760 result = acpi_add_single_object(&device, NULL,16641761 ACPI_BUS_TYPE_POWER_BUTTON,16651665- ACPI_STA_DEFAULT,16661666- &ops);17621762+ ACPI_STA_DEFAULT, true);16671763 device_init_wakeup(&device->dev, true);16681764 }1669176516701766 if ((acpi_gbl_FADT.flags & ACPI_FADT_SLEEP_BUTTON) == 0) {16711767 result = acpi_add_single_object(&device, NULL,16721768 ACPI_BUS_TYPE_SLEEP_BUTTON,16731673- ACPI_STA_DEFAULT,16741674- &ops);17691769+ ACPI_STA_DEFAULT, true);16751770 }1676177116771772 return result;···16781777int __init acpi_scan_init(void)16791778{16801779 int result;16811681- struct acpi_bus_ops ops;16821682-16831683- memset(&ops, 0, sizeof(ops));16841684- ops.acpi_op_add = 1;16851685- ops.acpi_op_start = 1;1686178016871781 result = bus_register(&acpi_bus_type);16881782 if (result) {···16861790 }1687179116881792 acpi_power_init();17931793+ acpi_pci_root_init();1689179416901795 /*16911796 * Enumerate devices in the ACPI namespace.16921797 */16931693- result = acpi_bus_scan(ACPI_ROOT_OBJECT, &ops, &acpi_root);16941694-16951695- if (!result)16961696- result = acpi_bus_scan_fixed();16971697-17981798+ result = acpi_bus_scan(ACPI_ROOT_OBJECT);16981799 if (result)16991699- acpi_device_unregister(acpi_root, ACPI_BUS_REMOVAL_NORMAL);17001700- else17011701- acpi_update_all_gpes();18001800+ return result;1702180117031703- return result;18021802+ result = acpi_bus_get_device(ACPI_ROOT_OBJECT, &acpi_root);18031803+ if (result)18041804+ return result;18051805+18061806+ result = acpi_bus_scan_fixed();18071807+ if (result) {18081808+ acpi_device_unregister(acpi_root);18091809+ return result;18101810+ }18111811+18121812+ acpi_update_all_gpes();18131813+ return 0;17041814}
+16-28
drivers/pci/hotplug/acpiphp_glue.c
···734734 */735735static int acpiphp_bus_add(struct acpiphp_func *func)736736{737737- acpi_handle phandle;738738- struct acpi_device *device, *pdevice;737737+ struct acpi_device *device;739738 int ret_val;740739741741- acpi_get_parent(func->handle, &phandle);742742- if (acpi_bus_get_device(phandle, &pdevice)) {743743- dbg("no parent device, assuming NULL\n");744744- pdevice = NULL;745745- }746740 if (!acpi_bus_get_device(func->handle, &device)) {747741 dbg("bus exists... trim\n");748742 /* this shouldn't be in here, so remove749743 * the bus then re-add it...750744 */751751- ret_val = acpi_bus_trim(device, 1);745745+ ret_val = acpi_bus_trim(device);752746 dbg("acpi_bus_trim return %x\n", ret_val);753747 }754748755755- ret_val = acpi_bus_add(&device, pdevice, func->handle,756756- ACPI_BUS_TYPE_DEVICE);757757- if (ret_val) {758758- dbg("error adding bus, %x\n",759759- -ret_val);760760- goto acpiphp_bus_add_out;761761- }762762- ret_val = acpi_bus_start(device);749749+ ret_val = acpi_bus_scan(func->handle);750750+ if (!ret_val)751751+ ret_val = acpi_bus_get_device(func->handle, &device);763752764764-acpiphp_bus_add_out:753753+ if (ret_val)754754+ dbg("error adding bus, %x\n", -ret_val);755755+765756 return ret_val;766757}767758···772781 return retval;773782 }774783775775- retval = acpi_bus_trim(device, 1);784784+ retval = acpi_bus_trim(device);776785 if (retval)777786 err("cannot remove from acpi list\n");778787···1121113011221131static void handle_bridge_insertion(acpi_handle handle, u32 type)11231132{11241124- struct acpi_device *device, *pdevice;11251125- acpi_handle phandle;11331133+ struct acpi_device *device;1126113411271135 if ((type != ACPI_NOTIFY_BUS_CHECK) &&11281136 (type != ACPI_NOTIFY_DEVICE_CHECK)) {···11291139 return;11301140 }1131114111321132- acpi_get_parent(handle, &phandle);11331133- if (acpi_bus_get_device(phandle, &pdevice)) {11341134- dbg("no parent device, assuming NULL\n");11351135- pdevice = NULL;11361136- }11371137- if (acpi_bus_add(&device, pdevice, handle, ACPI_BUS_TYPE_DEVICE)) {11421142+ if (acpi_bus_scan(handle)) {11381143 err("cannot add bridge to acpi list\n");11391144 return;11401145 }11411141- if (!acpiphp_configure_bridge(handle) &&11421142- !acpi_bus_start(device))11461146+ if (acpi_bus_get_device(handle, &device)) {11471147+ err("ACPI device object missing\n");11481148+ return;11491149+ }11501150+ if (!acpiphp_configure_bridge(handle))11431151 add_bridge(handle);11441152 else11451153 err("cannot configure and start bridge\n");
+3-7
drivers/pci/hotplug/sgi_hotplug.c
···412412 if (SN_ACPI_BASE_SUPPORT() && ssdt) {413413 unsigned long long adr;414414 struct acpi_device *pdevice;415415- struct acpi_device *device;416415 acpi_handle phandle;417416 acpi_handle chandle = NULL;418417 acpi_handle rethandle;···447448 if (ACPI_SUCCESS(ret) &&448449 (adr>>16) == (slot->device_num + 1)) {449450450450- ret = acpi_bus_add(&device, pdevice, chandle,451451- ACPI_BUS_TYPE_DEVICE);451451+ ret = acpi_bus_scan(chandle);452452 if (ACPI_FAILURE(ret)) {453453- printk(KERN_ERR "%s: acpi_bus_add "453453+ printk(KERN_ERR "%s: acpi_bus_scan "454454 "failed (0x%x) for slot %d "455455 "func %d\n", __func__,456456 ret, (int)(adr>>16),457457 (int)(adr&0xffff));458458 /* try to continue on */459459- } else {460460- acpi_bus_start(device);461459 }462460 }463461 }···535539 ret = acpi_bus_get_device(chandle,536540 &device);537541 if (ACPI_SUCCESS(ret))538538- acpi_bus_trim(device, 1);542542+ acpi_bus_trim(device);539543 }540544 }541545
+57-1
drivers/pci/pci-acpi.c
···283283 .is_manageable = acpi_pci_power_manageable,284284 .set_state = acpi_pci_set_power_state,285285 .choose_state = acpi_pci_choose_state,286286- .can_wakeup = acpi_pci_can_wakeup,287286 .sleep_wake = acpi_pci_sleep_wake,288287 .run_wake = acpi_pci_run_wake,289288};···320321 return 0;321322}322323324324+static void pci_acpi_setup(struct device *dev)325325+{326326+ struct pci_dev *pci_dev = to_pci_dev(dev);327327+ acpi_handle handle = ACPI_HANDLE(dev);328328+ struct acpi_device *adev;329329+ acpi_status status;330330+ acpi_handle dummy;331331+332332+ /*333333+ * Evaluate and parse _PRT, if exists. This code allows parsing of334334+ * _PRT objects within the scope of non-bridge devices. Note that335335+ * _PRTs within the scope of a PCI bridge assume the bridge's336336+ * subordinate bus number.337337+ *338338+ * TBD: Can _PRTs exist within the scope of non-bridge PCI devices?339339+ */340340+ status = acpi_get_handle(handle, METHOD_NAME__PRT, &dummy);341341+ if (ACPI_SUCCESS(status)) {342342+ unsigned char bus;343343+344344+ bus = pci_dev->subordinate ?345345+ pci_dev->subordinate->number : pci_dev->bus->number;346346+ acpi_pci_irq_add_prt(handle, pci_domain_nr(pci_dev->bus), bus);347347+ }348348+349349+ acpi_power_resource_register_device(dev, handle);350350+ if (acpi_bus_get_device(handle, &adev) || !adev->wakeup.flags.valid)351351+ return;352352+353353+ device_set_wakeup_capable(dev, true);354354+ acpi_pci_sleep_wake(pci_dev, false);355355+356356+ pci_acpi_add_pm_notifier(adev, pci_dev);357357+ if (adev->wakeup.flags.run_wake)358358+ device_set_run_wake(dev, true);359359+}360360+361361+static void pci_acpi_cleanup(struct device *dev)362362+{363363+ struct pci_dev *pci_dev = to_pci_dev(dev);364364+ acpi_handle handle = ACPI_HANDLE(dev);365365+ struct acpi_device *adev;366366+367367+ if (!acpi_bus_get_device(handle, &adev) && adev->wakeup.flags.valid) {368368+ device_set_wakeup_capable(dev, false);369369+ device_set_run_wake(dev, false);370370+ pci_acpi_remove_pm_notifier(adev);371371+ }372372+ acpi_power_resource_unregister_device(dev, handle);373373+374374+ if (pci_dev->subordinate)375375+ acpi_pci_irq_del_prt(pci_domain_nr(pci_dev->bus),376376+ pci_dev->subordinate->number);377377+}378378+323379static struct acpi_bus_type acpi_pci_bus = {324380 .bus = &pci_bus_type,325381 .find_device = acpi_pci_find_device,326382 .find_bridge = acpi_pci_find_root_bridge,383383+ .setup = pci_acpi_setup,384384+ .cleanup = pci_acpi_cleanup,327385};328386329387static int __init acpi_pci_init(void)
+1-25
drivers/pci/pci.c
···450450int pci_set_platform_pm(struct pci_platform_pm_ops *ops)451451{452452 if (!ops->is_manageable || !ops->set_state || !ops->choose_state453453- || !ops->sleep_wake || !ops->can_wakeup)453453+ || !ops->sleep_wake)454454 return -EINVAL;455455 pci_platform_pm = ops;456456 return 0;···471471{472472 return pci_platform_pm ?473473 pci_platform_pm->choose_state(dev) : PCI_POWER_ERROR;474474-}475475-476476-static inline bool platform_pci_can_wakeup(struct pci_dev *dev)477477-{478478- return pci_platform_pm ? pci_platform_pm->can_wakeup(dev) : false;479474}480475481476static inline int platform_pci_sleep_wake(struct pci_dev *dev, bool enable)···19781983 } else {19791984 dev->pme_support = 0;19801985 }19811981-}19821982-19831983-/**19841984- * platform_pci_wakeup_init - init platform wakeup if present19851985- * @dev: PCI device19861986- *19871987- * Some devices don't have PCI PM caps but can still generate wakeup19881988- * events through platform methods (like ACPI events). If @dev supports19891989- * platform wakeup events, set the device flag to indicate as much. This19901990- * may be redundant if the device also supports PCI PM caps, but double19911991- * initialization should be safe in that case.19921992- */19931993-void platform_pci_wakeup_init(struct pci_dev *dev)19941994-{19951995- if (!platform_pci_can_wakeup(dev))19961996- return;19971997-19981998- device_set_wakeup_capable(&dev->dev, true);19991999- platform_pci_sleep_wake(dev, false);20001986}2001198720021988static void pci_add_saved_cap(struct pci_dev *pci_dev,
-5
drivers/pci/pci.h
···4343 * platform; to be used during system-wide transitions from a4444 * sleeping state to the working state and vice versa4545 *4646- * @can_wakeup: returns 'true' if given device is capable of waking up the4747- * system from a sleeping state4848- *4946 * @sleep_wake: enables/disables the system wake up capability of given device5047 *5148 * @run_wake: enables/disables the platform to generate run-time wake-up events···5659 bool (*is_manageable)(struct pci_dev *dev);5760 int (*set_state)(struct pci_dev *dev, pci_power_t state);5861 pci_power_t (*choose_state)(struct pci_dev *dev);5959- bool (*can_wakeup)(struct pci_dev *dev);6062 int (*sleep_wake)(struct pci_dev *dev, bool enable);6163 int (*run_wake)(struct pci_dev *dev, bool enable);6264};···7074extern void pci_config_pm_runtime_get(struct pci_dev *dev);7175extern void pci_config_pm_runtime_put(struct pci_dev *dev);7276extern void pci_pm_init(struct pci_dev *dev);7373-extern void platform_pci_wakeup_init(struct pci_dev *dev);7477extern void pci_allocate_cap_save_buffers(struct pci_dev *dev);7578void pci_free_cap_save_buffers(struct pci_dev *dev);7679