Lines Matching +full:device +full:- +full:handle

1 // SPDX-License-Identifier: GPL-2.0-only
3 * scan.c - support for transforming the ACPI namespace into individual objects
19 #include <linux/dma-map-ops.h>
23 #include <linux/dma-direct.h>
34 static const char *dummy_hid = "device";
46 * The UART device described by the SPCR table is the only object which needs
47 * special-casing. Everything else is covered by ACPI namespace paths in STAO
79 hp->notify = notify; in acpi_initialize_hp_context()
80 hp->uevent = uevent; in acpi_initialize_hp_context()
89 return -EINVAL; in acpi_scan_add_handler()
91 list_add_tail(&handler->list_node, &acpi_scan_handlers_list); in acpi_scan_add_handler()
104 acpi_sysfs_add_hotplug_profile(&handler->hotplug, hotplug_profile_name); in acpi_scan_add_handler_with_hotplug()
118 mutex_lock_nested(&adev->physical_node_lock, SINGLE_DEPTH_NESTING); in acpi_scan_is_offline()
120 list_for_each_entry(pn, &adev->physical_node_list, node) in acpi_scan_is_offline()
121 if (device_supports_offline(pn->dev) && !pn->dev->offline) { in acpi_scan_is_offline()
123 kobject_uevent_env(&pn->dev->kobj, KOBJ_CHANGE, envp); in acpi_scan_is_offline()
129 mutex_unlock(&adev->physical_node_lock); in acpi_scan_is_offline()
133 static acpi_status acpi_bus_offline(acpi_handle handle, u32 lvl, void *data, in acpi_bus_offline() argument
136 struct acpi_device *device = acpi_fetch_acpi_dev(handle); in acpi_bus_offline() local
141 if (!device) in acpi_bus_offline()
144 if (device->handler && !device->handler->hotplug.enabled) { in acpi_bus_offline()
145 *ret_p = &device->dev; in acpi_bus_offline()
149 mutex_lock(&device->physical_node_lock); in acpi_bus_offline()
151 list_for_each_entry(pn, &device->physical_node_list, node) { in acpi_bus_offline()
156 if (pn->put_online) in acpi_bus_offline()
159 pn->put_online = false; in acpi_bus_offline()
161 ret = device_offline(pn->dev); in acpi_bus_offline()
163 pn->put_online = !ret; in acpi_bus_offline()
165 *ret_p = pn->dev; in acpi_bus_offline()
173 mutex_unlock(&device->physical_node_lock); in acpi_bus_offline()
178 static acpi_status acpi_bus_online(acpi_handle handle, u32 lvl, void *data, in acpi_bus_online() argument
181 struct acpi_device *device = acpi_fetch_acpi_dev(handle); in acpi_bus_online() local
184 if (!device) in acpi_bus_online()
187 mutex_lock(&device->physical_node_lock); in acpi_bus_online()
189 list_for_each_entry(pn, &device->physical_node_list, node) in acpi_bus_online()
190 if (pn->put_online) { in acpi_bus_online()
191 device_online(pn->dev); in acpi_bus_online()
192 pn->put_online = false; in acpi_bus_online()
195 mutex_unlock(&device->physical_node_lock); in acpi_bus_online()
200 static int acpi_scan_try_to_offline(struct acpi_device *device) in acpi_scan_try_to_offline() argument
202 acpi_handle handle = device->handle; in acpi_scan_try_to_offline() local
203 struct device *errdev = NULL; in acpi_scan_try_to_offline()
215 status = acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX, in acpi_scan_try_to_offline()
220 acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX, in acpi_scan_try_to_offline()
222 return -EPERM; in acpi_scan_try_to_offline()
224 acpi_bus_offline(handle, 0, (void *)false, (void **)&errdev); in acpi_scan_try_to_offline()
227 acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX, in acpi_scan_try_to_offline()
231 acpi_bus_offline(handle, 0, (void *)true, in acpi_scan_try_to_offline()
236 acpi_bus_online(handle, 0, NULL, NULL); in acpi_scan_try_to_offline()
237 acpi_walk_namespace(ACPI_TYPE_ANY, handle, in acpi_scan_try_to_offline()
240 return -EBUSY; in acpi_scan_try_to_offline()
251 struct acpi_scan_handler *handler = adev->handler; in acpi_scan_check_and_detach()
265 /* Skip device that have not been enumerated. */ in acpi_scan_check_and_detach()
267 dev_dbg(&adev->dev, "Still not enumerated\n"); in acpi_scan_check_and_detach()
272 adev->flags.match_driver = false; in acpi_scan_check_and_detach()
274 if (handler->detach) in acpi_scan_check_and_detach()
275 handler->detach(adev); in acpi_scan_check_and_detach()
277 device_release_driver(&adev->dev); in acpi_scan_check_and_detach()
280 * Most likely, the device is going away, so put it into D3cold before in acpi_scan_check_and_detach()
284 adev->flags.initialized = false; in acpi_scan_check_and_detach()
288 adev->handler = NULL; in acpi_scan_check_and_detach()
296 struct acpi_scan_handler *handler = adev->handler; in acpi_bus_post_eject()
301 if (handler->post_eject) in acpi_bus_post_eject()
302 handler->post_eject(adev); in acpi_bus_post_eject()
304 adev->handler = NULL; in acpi_bus_post_eject()
319 static int acpi_scan_hot_remove(struct acpi_device *device) in acpi_scan_hot_remove() argument
321 acpi_handle handle = device->handle; in acpi_scan_hot_remove() local
326 if (device->handler && device->handler->hotplug.demand_offline) { in acpi_scan_hot_remove()
327 if (!acpi_scan_is_offline(device, true)) in acpi_scan_hot_remove()
328 return -EBUSY; in acpi_scan_hot_remove()
330 int error = acpi_scan_try_to_offline(device); in acpi_scan_hot_remove()
335 acpi_handle_debug(handle, "Ejecting\n"); in acpi_scan_hot_remove()
337 acpi_scan_check_and_detach(device, (void *)flags); in acpi_scan_hot_remove()
339 acpi_evaluate_lck(handle, 0); in acpi_scan_hot_remove()
343 status = acpi_evaluate_ej0(handle); in acpi_scan_hot_remove()
345 return -ENODEV; in acpi_scan_hot_remove()
347 return -EIO; in acpi_scan_hot_remove()
353 status = acpi_evaluate_integer(handle, "_STA", NULL, &sta); in acpi_scan_hot_remove()
355 acpi_handle_warn(handle, in acpi_scan_hot_remove()
358 acpi_handle_warn(handle, in acpi_scan_hot_remove()
359 "Eject incomplete - status 0x%llx\n", sta); in acpi_scan_hot_remove()
361 acpi_bus_post_eject(device, NULL); in acpi_scan_hot_remove()
369 struct acpi_scan_handler *handler = adev->handler; in acpi_scan_rescan_bus()
372 if (handler && handler->hotplug.scan_dependent) in acpi_scan_rescan_bus()
373 ret = handler->hotplug.scan_dependent(adev); in acpi_scan_rescan_bus()
375 ret = acpi_bus_scan(adev->handle); in acpi_scan_rescan_bus()
378 dev_info(&adev->dev, "Namespace scan failure\n"); in acpi_scan_rescan_bus()
393 * This function is only called for device objects for which matching in acpi_scan_device_check()
395 * is not attached to this device object yet is when the device has in acpi_scan_device_check()
399 if (adev->handler) { in acpi_scan_device_check()
400 dev_dbg(&adev->dev, "Already enumerated\n"); in acpi_scan_device_check()
427 if (adev->handler && !adev->handler->hotplug.enabled) { in acpi_generic_hotplug_event()
428 dev_info(&adev->dev, "Eject disabled\n"); in acpi_generic_hotplug_event()
429 return -EPERM; in acpi_generic_hotplug_event()
431 acpi_evaluate_ost(adev->handle, ACPI_NOTIFY_EJECT_REQUEST, in acpi_generic_hotplug_event()
435 return -EINVAL; in acpi_generic_hotplug_event()
441 int error = -ENODEV; in acpi_device_hotplug()
447 * The device object's ACPI handle cannot become invalid as long as we in acpi_device_hotplug()
451 if (adev->handle == INVALID_ACPI_HANDLE) in acpi_device_hotplug()
454 if (adev->flags.is_dock_station) { in acpi_device_hotplug()
456 } else if (adev->flags.hotplug_notify) { in acpi_device_hotplug()
462 notify = adev->hp ? adev->hp->notify : NULL; in acpi_device_hotplug()
465 * There may be additional notify handlers for device objects in acpi_device_hotplug()
477 case -EPERM: in acpi_device_hotplug()
480 case -EBUSY: in acpi_device_hotplug()
489 acpi_evaluate_ost(adev->handle, src, ost_code, NULL); in acpi_device_hotplug()
497 static void acpi_free_power_resources_lists(struct acpi_device *device) in acpi_free_power_resources_lists() argument
501 if (device->wakeup.flags.valid) in acpi_free_power_resources_lists()
502 acpi_power_resources_list_free(&device->wakeup.resources); in acpi_free_power_resources_lists()
504 if (!device->power.flags.power_resources) in acpi_free_power_resources_lists()
508 struct acpi_device_power_state *ps = &device->power.states[i]; in acpi_free_power_resources_lists()
509 acpi_power_resources_list_free(&ps->resources); in acpi_free_power_resources_lists()
513 static void acpi_device_release(struct device *dev) in acpi_device_release()
518 acpi_free_pnp_ids(&acpi_dev->pnp); in acpi_device_release()
523 static void acpi_device_del(struct acpi_device *device) in acpi_device_del() argument
530 if (!strcmp(acpi_device_bus_id->bus_id, in acpi_device_del()
531 acpi_device_hid(device))) { in acpi_device_del()
532 ida_free(&acpi_device_bus_id->instance_ida, in acpi_device_del()
533 device->pnp.instance_no); in acpi_device_del()
534 if (ida_is_empty(&acpi_device_bus_id->instance_ida)) { in acpi_device_del()
535 list_del(&acpi_device_bus_id->node); in acpi_device_del()
536 kfree_const(acpi_device_bus_id->bus_id); in acpi_device_del()
542 list_del(&device->wakeup_list); in acpi_device_del()
546 acpi_power_add_remove_device(device, false); in acpi_device_del()
547 acpi_device_remove_files(device); in acpi_device_del()
548 if (device->remove) in acpi_device_del()
549 device->remove(device); in acpi_device_del()
551 device_del(&device->dev); in acpi_device_del()
572 list_del(&adev->del_list); in acpi_device_del_work_fn()
582 * used by the device. in acpi_device_del_work_fn()
590 * acpi_scan_drop_device - Drop an ACPI device object.
591 * @handle: Handle of an ACPI namespace node, not used.
592 * @context: Address of the ACPI device object to drop.
595 * namespace node the device object pointed to by @context is attached to.
599 * ensure the correct ordering (the device objects must be unregistered in the
602 static void acpi_scan_drop_device(acpi_handle handle, void *context) in acpi_scan_drop_device() argument
612 * prevents attempts to register device objects identical to those being in acpi_scan_drop_device()
616 * those work items to ensure that they are not accessing stale device in acpi_scan_drop_device()
622 list_add_tail(&adev->del_list, &acpi_device_del_list); in acpi_scan_drop_device()
623 /* Make acpi_ns_validate_handle() return NULL for this handle. */ in acpi_scan_drop_device()
624 adev->handle = INVALID_ACPI_HANDLE; in acpi_scan_drop_device()
629 static struct acpi_device *handle_to_device(acpi_handle handle, in handle_to_device() argument
635 status = acpi_get_data_full(handle, acpi_scan_drop_device, in handle_to_device()
638 acpi_handle_debug(handle, "No context!\n"); in handle_to_device()
645 * acpi_fetch_acpi_dev - Retrieve ACPI device object.
646 * @handle: ACPI handle associated with the requested ACPI device object.
648 * Return a pointer to the ACPI device object associated with @handle, if
651 struct acpi_device *acpi_fetch_acpi_dev(acpi_handle handle) in acpi_fetch_acpi_dev() argument
653 return handle_to_device(handle, NULL); in acpi_fetch_acpi_dev()
663 * acpi_get_acpi_dev - Retrieve ACPI device object and reference count it.
664 * @handle: ACPI handle associated with the requested ACPI device object.
666 * Return a pointer to the ACPI device object associated with @handle and bump
670 * The ACPI device object reference acquired by this function needs to be
673 struct acpi_device *acpi_get_acpi_dev(acpi_handle handle) in acpi_get_acpi_dev() argument
675 return handle_to_device(handle, get_acpi_device); in acpi_get_acpi_dev()
685 if (!strcmp(acpi_device_bus_id->bus_id, dev_id)) in acpi_device_bus_id_match()
691 static int acpi_device_set_name(struct acpi_device *device, in acpi_device_set_name() argument
694 struct ida *instance_ida = &acpi_device_bus_id->instance_ida; in acpi_device_set_name()
701 device->pnp.instance_no = result; in acpi_device_set_name()
702 dev_set_name(&device->dev, "%s:%02x", acpi_device_bus_id->bus_id, result); in acpi_device_set_name()
708 acpi_handle handle = adev->handle; in acpi_tie_acpi_dev() local
711 if (!handle) in acpi_tie_acpi_dev()
714 status = acpi_attach_data(handle, acpi_scan_drop_device, adev); in acpi_tie_acpi_dev()
716 acpi_handle_err(handle, "Unable to attach device data\n"); in acpi_tie_acpi_dev()
717 return -ENODEV; in acpi_tie_acpi_dev()
728 status = acpi_get_physical_device_location(adev->handle, &pld); in acpi_store_pld_crc()
732 adev->pld_crc = crc32(~0, pld, sizeof(*pld)); in acpi_store_pld_crc()
736 int acpi_device_add(struct acpi_device *device) in acpi_device_add() argument
743 * ------- in acpi_device_add()
744 * Link this device to its parent and siblings. in acpi_device_add()
746 INIT_LIST_HEAD(&device->wakeup_list); in acpi_device_add()
747 INIT_LIST_HEAD(&device->physical_node_list); in acpi_device_add()
748 INIT_LIST_HEAD(&device->del_list); in acpi_device_add()
749 mutex_init(&device->physical_node_lock); in acpi_device_add()
753 acpi_device_bus_id = acpi_device_bus_id_match(acpi_device_hid(device)); in acpi_device_add()
755 result = acpi_device_set_name(device, acpi_device_bus_id); in acpi_device_add()
762 result = -ENOMEM; in acpi_device_add()
765 acpi_device_bus_id->bus_id = in acpi_device_add()
766 kstrdup_const(acpi_device_hid(device), GFP_KERNEL); in acpi_device_add()
767 if (!acpi_device_bus_id->bus_id) { in acpi_device_add()
769 result = -ENOMEM; in acpi_device_add()
773 ida_init(&acpi_device_bus_id->instance_ida); in acpi_device_add()
775 result = acpi_device_set_name(device, acpi_device_bus_id); in acpi_device_add()
777 kfree_const(acpi_device_bus_id->bus_id); in acpi_device_add()
782 list_add_tail(&acpi_device_bus_id->node, &acpi_bus_id_list); in acpi_device_add()
785 if (device->wakeup.flags.valid) in acpi_device_add()
786 list_add_tail(&device->wakeup_list, &acpi_wakeup_device_list); in acpi_device_add()
788 acpi_store_pld_crc(device); in acpi_device_add()
792 result = device_add(&device->dev); in acpi_device_add()
794 dev_err(&device->dev, "Error registering device\n"); in acpi_device_add()
798 acpi_device_setup_files(device); in acpi_device_add()
805 list_del(&device->wakeup_list); in acpi_device_add()
810 acpi_detach_data(device->handle, acpi_scan_drop_device); in acpi_device_add()
815 /* --------------------------------------------------------------------------
816 Device Enumeration
817 -------------------------------------------------------------------------- */
824 if (!(info->valid & ACPI_VALID_HID)) in acpi_info_matches_ids()
827 index = match_string(ids, -1, info->hardware_id.string); in acpi_info_matches_ids()
831 if (info->valid & ACPI_VALID_CID) in acpi_info_matches_ids()
832 cid_list = &info->compatible_id_list; in acpi_info_matches_ids()
837 for (i = 0; i < cid_list->count; i++) { in acpi_info_matches_ids()
838 index = match_string(ids, -1, cid_list->ids[i].string); in acpi_info_matches_ids()
848 "PNP0D80", /* Windows-compatible System Power Management Controller */
849 "INT33BD", /* Intel Baytrail Mailbox Device */
861 "RSCV0001", /* RISC-V PLIC */
862 "RSCV0002", /* RISC-V APLIC */
863 "PNP0C0F", /* PCI Link Device */
867 static struct acpi_device *acpi_find_parent_acpi_dev(acpi_handle handle) in acpi_find_parent_acpi_dev() argument
876 if (!handle) in acpi_find_parent_acpi_dev()
882 status = acpi_get_parent(handle, &handle); in acpi_find_parent_acpi_dev()
889 adev = acpi_fetch_acpi_dev(handle); in acpi_find_parent_acpi_dev()
895 acpi_bus_get_ejd(acpi_handle handle, acpi_handle *ejd) in acpi_bus_get_ejd() argument
902 status = acpi_get_handle(handle, "_EJD", &tmp); in acpi_bus_get_ejd()
906 status = acpi_evaluate_object(handle, "_EJD", NULL, &buffer); in acpi_bus_get_ejd()
909 status = acpi_get_handle(ACPI_ROOT_OBJECT, obj->string.pointer, in acpi_bus_get_ejd()
919 acpi_handle handle = dev->handle; in acpi_bus_extract_wakeup_device_power_package() local
920 struct acpi_device_wakeup *wakeup = &dev->wakeup; in acpi_bus_extract_wakeup_device_power_package()
925 int err = -ENODATA; in acpi_bus_extract_wakeup_device_power_package()
927 INIT_LIST_HEAD(&wakeup->resources); in acpi_bus_extract_wakeup_device_power_package()
930 status = acpi_evaluate_object(handle, "_PRW", NULL, &buffer); in acpi_bus_extract_wakeup_device_power_package()
932 acpi_handle_info(handle, "_PRW evaluation failed: %s\n", in acpi_bus_extract_wakeup_device_power_package()
939 if (!package || package->package.count < 2) in acpi_bus_extract_wakeup_device_power_package()
942 element = &(package->package.elements[0]); in acpi_bus_extract_wakeup_device_power_package()
946 if (element->type == ACPI_TYPE_PACKAGE) { in acpi_bus_extract_wakeup_device_power_package()
947 if ((element->package.count < 2) || in acpi_bus_extract_wakeup_device_power_package()
948 (element->package.elements[0].type != in acpi_bus_extract_wakeup_device_power_package()
950 || (element->package.elements[1].type != ACPI_TYPE_INTEGER)) in acpi_bus_extract_wakeup_device_power_package()
953 wakeup->gpe_device = in acpi_bus_extract_wakeup_device_power_package()
954 element->package.elements[0].reference.handle; in acpi_bus_extract_wakeup_device_power_package()
955 wakeup->gpe_number = in acpi_bus_extract_wakeup_device_power_package()
956 (u32) element->package.elements[1].integer.value; in acpi_bus_extract_wakeup_device_power_package()
957 } else if (element->type == ACPI_TYPE_INTEGER) { in acpi_bus_extract_wakeup_device_power_package()
958 wakeup->gpe_device = NULL; in acpi_bus_extract_wakeup_device_power_package()
959 wakeup->gpe_number = element->integer.value; in acpi_bus_extract_wakeup_device_power_package()
964 element = &(package->package.elements[1]); in acpi_bus_extract_wakeup_device_power_package()
965 if (element->type != ACPI_TYPE_INTEGER) in acpi_bus_extract_wakeup_device_power_package()
968 wakeup->sleep_state = element->integer.value; in acpi_bus_extract_wakeup_device_power_package()
970 err = acpi_extract_power_resources(package, 2, &wakeup->resources); in acpi_bus_extract_wakeup_device_power_package()
974 if (!list_empty(&wakeup->resources)) { in acpi_bus_extract_wakeup_device_power_package()
977 err = acpi_power_wakeup_list_init(&wakeup->resources, in acpi_bus_extract_wakeup_device_power_package()
980 acpi_handle_warn(handle, "Retrieving current states " in acpi_bus_extract_wakeup_device_power_package()
982 acpi_power_resources_list_free(&wakeup->resources); in acpi_bus_extract_wakeup_device_power_package()
985 if (sleep_state < wakeup->sleep_state) { in acpi_bus_extract_wakeup_device_power_package()
986 acpi_handle_warn(handle, "Overriding _PRW sleep state " in acpi_bus_extract_wakeup_device_power_package()
988 (int)wakeup->sleep_state, sleep_state); in acpi_bus_extract_wakeup_device_power_package()
989 wakeup->sleep_state = sleep_state; in acpi_bus_extract_wakeup_device_power_package()
1001 static bool acpi_wakeup_gpe_init(struct acpi_device *device) in acpi_wakeup_gpe_init() argument
1009 struct acpi_device_wakeup *wakeup = &device->wakeup; in acpi_wakeup_gpe_init()
1013 wakeup->flags.notifier_present = 0; in acpi_wakeup_gpe_init()
1016 match = acpi_match_acpi_device(button_device_ids, device); in acpi_wakeup_gpe_init()
1018 if ((match->driver_data & ACPI_AVOID_WAKE_FROM_S5) && in acpi_wakeup_gpe_init()
1019 wakeup->sleep_state == ACPI_STATE_S5) in acpi_wakeup_gpe_init()
1020 wakeup->sleep_state = ACPI_STATE_S4; in acpi_wakeup_gpe_init()
1021 acpi_mark_gpe_for_wake(wakeup->gpe_device, wakeup->gpe_number); in acpi_wakeup_gpe_init()
1022 device_set_wakeup_capable(&device->dev, true); in acpi_wakeup_gpe_init()
1026 status = acpi_setup_gpe_for_wake(device->handle, wakeup->gpe_device, in acpi_wakeup_gpe_init()
1027 wakeup->gpe_number); in acpi_wakeup_gpe_init()
1031 static void acpi_bus_get_wakeup_device_flags(struct acpi_device *device) in acpi_bus_get_wakeup_device_flags() argument
1036 if (!acpi_has_method(device->handle, "_PRW")) in acpi_bus_get_wakeup_device_flags()
1039 err = acpi_bus_extract_wakeup_device_power_package(device); in acpi_bus_get_wakeup_device_flags()
1041 dev_err(&device->dev, "Unable to extract wakeup power resources"); in acpi_bus_get_wakeup_device_flags()
1045 device->wakeup.flags.valid = acpi_wakeup_gpe_init(device); in acpi_bus_get_wakeup_device_flags()
1046 device->wakeup.prepare_count = 0; in acpi_bus_get_wakeup_device_flags()
1049 * system for the ACPI device with the _PRW object. in acpi_bus_get_wakeup_device_flags()
1054 err = acpi_device_sleep_wake(device, 0, 0, 0); in acpi_bus_get_wakeup_device_flags()
1059 static void acpi_bus_init_power_state(struct acpi_device *device, int state) in acpi_bus_init_power_state() argument
1061 struct acpi_device_power_state *ps = &device->power.states[state]; in acpi_bus_init_power_state()
1066 INIT_LIST_HEAD(&ps->resources); in acpi_bus_init_power_state()
1069 status = acpi_evaluate_object(device->handle, pathname, NULL, &buffer); in acpi_bus_init_power_state()
1074 && package->type == ACPI_TYPE_PACKAGE in acpi_bus_init_power_state()
1075 && package->package.count) in acpi_bus_init_power_state()
1076 acpi_extract_power_resources(package, 0, &ps->resources); in acpi_bus_init_power_state()
1083 if (acpi_has_method(device->handle, pathname)) in acpi_bus_init_power_state()
1084 ps->flags.explicit_set = 1; in acpi_bus_init_power_state()
1086 /* State is valid if there are means to put the device into it. */ in acpi_bus_init_power_state()
1087 if (!list_empty(&ps->resources) || ps->flags.explicit_set) in acpi_bus_init_power_state()
1088 ps->flags.valid = 1; in acpi_bus_init_power_state()
1090 ps->power = -1; /* Unknown - driver assigned */ in acpi_bus_init_power_state()
1091 ps->latency = -1; /* Unknown - driver assigned */ in acpi_bus_init_power_state()
1094 static void acpi_bus_get_power_flags(struct acpi_device *device) in acpi_bus_get_power_flags() argument
1100 if (!acpi_has_method(device->handle, "_PS0") && in acpi_bus_get_power_flags()
1101 !acpi_has_method(device->handle, "_PR0")) in acpi_bus_get_power_flags()
1104 device->flags.power_manageable = 1; in acpi_bus_get_power_flags()
1109 if (acpi_has_method(device->handle, "_PSC")) in acpi_bus_get_power_flags()
1110 device->power.flags.explicit_get = 1; in acpi_bus_get_power_flags()
1112 if (acpi_has_method(device->handle, "_IRC")) in acpi_bus_get_power_flags()
1113 device->power.flags.inrush_current = 1; in acpi_bus_get_power_flags()
1115 if (acpi_has_method(device->handle, "_DSW")) in acpi_bus_get_power_flags()
1116 device->power.flags.dsw_present = 1; in acpi_bus_get_power_flags()
1118 acpi_evaluate_integer(device->handle, "_DSC", NULL, &dsc); in acpi_bus_get_power_flags()
1119 device->power.state_for_enumeration = dsc; in acpi_bus_get_power_flags()
1125 acpi_bus_init_power_state(device, i); in acpi_bus_get_power_flags()
1127 INIT_LIST_HEAD(&device->power.states[ACPI_STATE_D3_COLD].resources); in acpi_bus_get_power_flags()
1130 device->power.states[ACPI_STATE_D0].flags.valid = 1; in acpi_bus_get_power_flags()
1131 device->power.states[ACPI_STATE_D0].power = 100; in acpi_bus_get_power_flags()
1132 device->power.states[ACPI_STATE_D3_HOT].flags.valid = 1; in acpi_bus_get_power_flags()
1139 if (!list_empty(&device->power.states[ACPI_STATE_D0].resources)) { in acpi_bus_get_power_flags()
1140 device->power.flags.power_resources = 1; in acpi_bus_get_power_flags()
1145 if (!list_empty(&device->power.states[ACPI_STATE_D3_HOT].resources)) in acpi_bus_get_power_flags()
1146 device->power.states[ACPI_STATE_D3_COLD].flags.valid = 1; in acpi_bus_get_power_flags()
1149 if (acpi_bus_init_power(device)) in acpi_bus_get_power_flags()
1150 device->flags.power_manageable = 0; in acpi_bus_get_power_flags()
1153 static void acpi_bus_get_flags(struct acpi_device *device) in acpi_bus_get_flags() argument
1156 if (acpi_has_method(device->handle, "_STA")) in acpi_bus_get_flags()
1157 device->flags.dynamic_status = 1; in acpi_bus_get_flags()
1160 if (acpi_has_method(device->handle, "_RMV")) in acpi_bus_get_flags()
1161 device->flags.removable = 1; in acpi_bus_get_flags()
1164 if (acpi_has_method(device->handle, "_EJD") || in acpi_bus_get_flags()
1165 acpi_has_method(device->handle, "_EJ0")) in acpi_bus_get_flags()
1166 device->flags.ejectable = 1; in acpi_bus_get_flags()
1169 static void acpi_device_get_busid(struct acpi_device *device) in acpi_device_get_busid() argument
1177 * ------ in acpi_device_get_busid()
1178 * The device's Bus ID is simply the object name. in acpi_device_get_busid()
1181 if (!acpi_dev_parent(device)) { in acpi_device_get_busid()
1182 strcpy(device->pnp.bus_id, "ACPI"); in acpi_device_get_busid()
1186 switch (device->device_type) { in acpi_device_get_busid()
1188 strcpy(device->pnp.bus_id, "PWRF"); in acpi_device_get_busid()
1191 strcpy(device->pnp.bus_id, "SLPF"); in acpi_device_get_busid()
1194 strcpy(device->pnp.bus_id, "ECDT"); in acpi_device_get_busid()
1197 acpi_get_name(device->handle, ACPI_SINGLE_NAME, &buffer); in acpi_device_get_busid()
1199 for (i = 3; i > 1; i--) { in acpi_device_get_busid()
1205 strcpy(device->pnp.bus_id, bus_id); in acpi_device_get_busid()
1211 * acpi_ata_match - see if an acpi object is an ATA device
1214 * then we can safely call it an ATA device.
1216 bool acpi_ata_match(acpi_handle handle) in acpi_ata_match() argument
1218 return acpi_has_method(handle, "_GTF") || in acpi_ata_match()
1219 acpi_has_method(handle, "_GTM") || in acpi_ata_match()
1220 acpi_has_method(handle, "_STM") || in acpi_ata_match()
1221 acpi_has_method(handle, "_SDD"); in acpi_ata_match()
1225 * acpi_bay_match - see if an acpi object is an ejectable driver bay
1230 bool acpi_bay_match(acpi_handle handle) in acpi_bay_match() argument
1234 if (!acpi_has_method(handle, "_EJ0")) in acpi_bay_match()
1236 if (acpi_ata_match(handle)) in acpi_bay_match()
1238 if (ACPI_FAILURE(acpi_get_parent(handle, &phandle))) in acpi_bay_match()
1248 list_for_each_entry(hwid, &adev->pnp.ids, list) in acpi_device_is_battery()
1249 if (!strcmp("PNP0C0A", hwid->id)) in acpi_device_is_battery()
1257 acpi_handle handle = adev->handle; in is_ejectable_bay() local
1259 if (acpi_has_method(handle, "_EJ0") && acpi_device_is_battery(adev)) in is_ejectable_bay()
1262 return acpi_bay_match(handle); in is_ejectable_bay()
1266 * acpi_dock_match - see if an acpi object has a _DCK method
1268 bool acpi_dock_match(acpi_handle handle) in acpi_dock_match() argument
1270 return acpi_has_method(handle, "_DCK"); in acpi_dock_match()
1274 acpi_backlight_cap_match(acpi_handle handle, u32 level, void *context, in acpi_backlight_cap_match() argument
1279 if (acpi_has_method(handle, "_BCM") && in acpi_backlight_cap_match()
1280 acpi_has_method(handle, "_BCL")) { in acpi_backlight_cap_match()
1281 acpi_handle_debug(handle, "Found generic backlight support\n"); in acpi_backlight_cap_match()
1289 /* Returns true if the ACPI object is a video device which can be
1291 * The device will get a Linux specific CID added in scan.c to
1292 * identify the device as an ACPI graphics device
1293 * Be aware that the graphics device may not be physically present
1297 long acpi_is_video_device(acpi_handle handle) in acpi_is_video_device() argument
1301 /* Is this device able to support video switching ? */ in acpi_is_video_device()
1302 if (acpi_has_method(handle, "_DOD") || acpi_has_method(handle, "_DOS")) in acpi_is_video_device()
1305 /* Is this device able to retrieve a video ROM ? */ in acpi_is_video_device()
1306 if (acpi_has_method(handle, "_ROM")) in acpi_is_video_device()
1309 /* Is this device able to configure which video head to be POSTed ? */ in acpi_is_video_device()
1310 if (acpi_has_method(handle, "_VPO") && in acpi_is_video_device()
1311 acpi_has_method(handle, "_GPD") && in acpi_is_video_device()
1312 acpi_has_method(handle, "_SPD")) in acpi_is_video_device()
1317 acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, in acpi_is_video_device()
1325 const char *acpi_device_hid(struct acpi_device *device) in acpi_device_hid() argument
1329 hid = list_first_entry_or_null(&device->pnp.ids, struct acpi_hardware_id, list); in acpi_device_hid()
1333 return hid->id; in acpi_device_hid()
1345 id->id = kstrdup_const(dev_id, GFP_KERNEL); in acpi_add_id()
1346 if (!id->id) { in acpi_add_id()
1351 list_add_tail(&id->list, &pnp->ids); in acpi_add_id()
1352 pnp->type.hardware_id = 1; in acpi_add_id()
1360 static bool acpi_ibm_smbus_match(acpi_handle handle) in acpi_ibm_smbus_match() argument
1369 if (ACPI_FAILURE(acpi_get_name(handle, ACPI_SINGLE_NAME, &path)) || in acpi_ibm_smbus_match()
1374 if (acpi_has_method(handle, "SBI") && in acpi_ibm_smbus_match()
1375 acpi_has_method(handle, "SBR") && in acpi_ibm_smbus_match()
1376 acpi_has_method(handle, "SBW")) in acpi_ibm_smbus_match()
1382 static bool acpi_object_is_system_bus(acpi_handle handle) in acpi_object_is_system_bus() argument
1387 tmp == handle) in acpi_object_is_system_bus()
1390 tmp == handle) in acpi_object_is_system_bus()
1396 static void acpi_set_pnp_ids(acpi_handle handle, struct acpi_device_pnp *pnp, in acpi_set_pnp_ids() argument
1405 if (handle == ACPI_ROOT_OBJECT) { in acpi_set_pnp_ids()
1410 acpi_get_object_info(handle, &info); in acpi_set_pnp_ids()
1412 pr_err("%s: Error reading device info\n", __func__); in acpi_set_pnp_ids()
1416 if (info->valid & ACPI_VALID_HID) { in acpi_set_pnp_ids()
1417 acpi_add_id(pnp, info->hardware_id.string); in acpi_set_pnp_ids()
1418 pnp->type.platform_id = 1; in acpi_set_pnp_ids()
1420 if (info->valid & ACPI_VALID_CID) { in acpi_set_pnp_ids()
1421 cid_list = &info->compatible_id_list; in acpi_set_pnp_ids()
1422 for (i = 0; i < cid_list->count; i++) in acpi_set_pnp_ids()
1423 acpi_add_id(pnp, cid_list->ids[i].string); in acpi_set_pnp_ids()
1425 if (info->valid & ACPI_VALID_ADR) { in acpi_set_pnp_ids()
1426 pnp->bus_address = info->address; in acpi_set_pnp_ids()
1427 pnp->type.bus_address = 1; in acpi_set_pnp_ids()
1429 if (info->valid & ACPI_VALID_UID) in acpi_set_pnp_ids()
1430 pnp->unique_id = kstrdup(info->unique_id.string, in acpi_set_pnp_ids()
1432 if (info->valid & ACPI_VALID_CLS) in acpi_set_pnp_ids()
1433 acpi_add_id(pnp, info->class_code.string); in acpi_set_pnp_ids()
1441 if (acpi_is_video_device(handle)) { in acpi_set_pnp_ids()
1443 pnp->type.backlight = 1; in acpi_set_pnp_ids()
1446 if (acpi_bay_match(handle)) in acpi_set_pnp_ids()
1448 else if (acpi_dock_match(handle)) in acpi_set_pnp_ids()
1450 else if (acpi_ibm_smbus_match(handle)) in acpi_set_pnp_ids()
1452 else if (list_empty(&pnp->ids) && in acpi_set_pnp_ids()
1453 acpi_object_is_system_bus(handle)) { in acpi_set_pnp_ids()
1456 strcpy(pnp->device_name, ACPI_BUS_DEVICE_NAME); in acpi_set_pnp_ids()
1457 strcpy(pnp->device_class, ACPI_BUS_CLASS); in acpi_set_pnp_ids()
1486 list_for_each_entry_safe(id, tmp, &pnp->ids, list) { in acpi_free_pnp_ids()
1487 kfree_const(id->id); in acpi_free_pnp_ids()
1490 kfree(pnp->unique_id); in acpi_free_pnp_ids()
1494 * acpi_dma_supported - Check DMA support for the specified device.
1495 * @adev: The pointer to acpi device
1504 if (adev->flags.cca_seen) in acpi_dma_supported()
1508 * Per ACPI 6.0 sec 6.2.17, assume devices can do cache-coherent in acpi_dma_supported()
1519 * acpi_get_dma_attr - Check the supported DMA attr for the specified device.
1520 * @adev: The pointer to acpi device
1529 if (adev->flags.coherent_dma) in acpi_get_dma_attr()
1536 * acpi_dma_get_range() - Get device DMA parameters.
1538 * @dev: device to configure
1546 int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map) in acpi_dma_get_range()
1552 struct device *dma_dev = dev; in acpi_dma_get_range()
1556 * Walk the device tree chasing an ACPI companion with a _DMA in acpi_dma_get_range()
1557 * object while we go. Stop if we find a device with an ACPI in acpi_dma_get_range()
1562 if (adev && acpi_has_method(adev->handle, METHOD_NAME__DMA)) in acpi_dma_get_range()
1565 dma_dev = dma_dev->parent; in acpi_dma_get_range()
1569 return -ENODEV; in acpi_dma_get_range()
1571 if (!acpi_has_method(adev->handle, METHOD_NAME__CRS)) { in acpi_dma_get_range()
1572 acpi_handle_warn(adev->handle, "_DMA is valid only if _CRS is present\n"); in acpi_dma_get_range()
1573 return -EINVAL; in acpi_dma_get_range()
1580 ret = -ENOMEM; in acpi_dma_get_range()
1587 if (rentry->res->start >= rentry->res->end) { in acpi_dma_get_range()
1590 ret = -EINVAL; in acpi_dma_get_range()
1595 r->cpu_start = rentry->res->start; in acpi_dma_get_range()
1596 r->dma_start = rentry->res->start - rentry->offset; in acpi_dma_get_range()
1597 r->size = resource_size(rentry->res); in acpi_dma_get_range()
1608 int acpi_iommu_fwspec_init(struct device *dev, u32 id, in acpi_iommu_fwspec_init()
1620 static int acpi_iommu_configure_id(struct device *dev, const u32 *id_in) in acpi_iommu_configure_id()
1624 /* Serialise to make dev->iommu stable under our potential fwspec */ in acpi_iommu_configure_id()
1633 if (err && err != -EPROBE_DEFER) in acpi_iommu_configure_id()
1641 if (!err && dev->bus) in acpi_iommu_configure_id()
1649 int acpi_iommu_fwspec_init(struct device *dev, u32 id, in acpi_iommu_fwspec_init()
1652 return -ENODEV; in acpi_iommu_fwspec_init()
1655 static int acpi_iommu_configure_id(struct device *dev, const u32 *id_in) in acpi_iommu_configure_id()
1657 return -ENODEV; in acpi_iommu_configure_id()
1663 * acpi_dma_configure_id - Set-up DMA configuration for the device.
1664 * @dev: The pointer to the device
1665 * @attr: device dma attributes
1666 * @input_id: input device id const value pointer
1668 int acpi_dma_configure_id(struct device *dev, enum dev_dma_attr attr, in acpi_dma_configure_id()
1682 if (ret == -EPROBE_DEFER) in acpi_dma_configure_id()
1683 return -EPROBE_DEFER; in acpi_dma_configure_id()
1699 if (parent && parent->flags.cca_seen) { in acpi_init_coherency()
1704 adev->flags.cca_seen = 1; in acpi_init_coherency()
1705 cca = parent->flags.coherent_dma; in acpi_init_coherency()
1707 status = acpi_evaluate_integer(adev->handle, "_CCA", in acpi_init_coherency()
1710 adev->flags.cca_seen = 1; in acpi_init_coherency()
1714 * required for DMA-able devices (e.g. x86), in acpi_init_coherency()
1719 acpi_handle_debug(adev->handle, in acpi_init_coherency()
1720 "ACPI device is missing _CCA.\n"); in acpi_init_coherency()
1723 adev->flags.coherent_dma = cca; in acpi_init_coherency()
1730 if (ares->type != ACPI_RESOURCE_TYPE_SERIAL_BUS) in acpi_check_serial_bus_slave()
1736 return -1; in acpi_check_serial_bus_slave()
1739 static bool acpi_is_indirect_io_slave(struct acpi_device *device) in acpi_is_indirect_io_slave() argument
1741 struct acpi_device *parent = acpi_dev_parent(device); in acpi_is_indirect_io_slave()
1750 static bool acpi_device_enumeration_by_parent(struct acpi_device *device) in acpi_device_enumeration_by_parent() argument
1757 * device must be instantiated for each of them, each with in acpi_device_enumeration_by_parent()
1758 * its own device id. in acpi_device_enumeration_by_parent()
1759 * Normally we only instantiate one client device for the first in acpi_device_enumeration_by_parent()
1761 * by the drivers/platform/x86/serial-multi-instantiate.c driver, which in acpi_device_enumeration_by_parent()
1762 * knows which client device id to use for each resource. in acpi_device_enumeration_by_parent()
1772 /* Non-conforming _HID for Cirrus Logic already released */ in acpi_device_enumeration_by_parent()
1782 * HIDs of device with an UartSerialBusV2 resource for which userspace in acpi_device_enumeration_by_parent()
1785 * such as the rfkill-gpio driver. in acpi_device_enumeration_by_parent()
1792 if (acpi_is_indirect_io_slave(device)) in acpi_device_enumeration_by_parent()
1795 /* Macs use device properties in lieu of _CRS resources */ in acpi_device_enumeration_by_parent()
1797 (fwnode_property_present(&device->fwnode, "spiSclkPeriod") || in acpi_device_enumeration_by_parent()
1798 fwnode_property_present(&device->fwnode, "i2cAddress") || in acpi_device_enumeration_by_parent()
1799 fwnode_property_present(&device->fwnode, "baud"))) in acpi_device_enumeration_by_parent()
1802 if (!acpi_match_device_ids(device, ignore_serial_bus_ids)) in acpi_device_enumeration_by_parent()
1806 acpi_dev_get_resources(device, &resource_list, in acpi_device_enumeration_by_parent()
1814 void acpi_init_device_object(struct acpi_device *device, acpi_handle handle, in acpi_init_device_object() argument
1815 int type, void (*release)(struct device *)) in acpi_init_device_object() argument
1817 struct acpi_device *parent = acpi_find_parent_acpi_dev(handle); in acpi_init_device_object()
1819 INIT_LIST_HEAD(&device->pnp.ids); in acpi_init_device_object()
1820 device->device_type = type; in acpi_init_device_object()
1821 device->handle = handle; in acpi_init_device_object()
1822 device->dev.parent = parent ? &parent->dev : NULL; in acpi_init_device_object()
1823 device->dev.release = release; in acpi_init_device_object()
1824 device->dev.bus = &acpi_bus_type; in acpi_init_device_object()
1825 device->dev.groups = acpi_groups; in acpi_init_device_object()
1826 fwnode_init(&device->fwnode, &acpi_device_fwnode_ops); in acpi_init_device_object()
1827 acpi_set_device_status(device, ACPI_STA_DEFAULT); in acpi_init_device_object()
1828 acpi_device_get_busid(device); in acpi_init_device_object()
1829 acpi_set_pnp_ids(handle, &device->pnp, type); in acpi_init_device_object()
1830 acpi_init_properties(device); in acpi_init_device_object()
1831 acpi_bus_get_flags(device); in acpi_init_device_object()
1832 device->flags.match_driver = false; in acpi_init_device_object()
1833 device->flags.initialized = true; in acpi_init_device_object()
1834 device->flags.enumeration_by_parent = in acpi_init_device_object()
1835 acpi_device_enumeration_by_parent(device); in acpi_init_device_object()
1836 acpi_device_clear_enumerated(device); in acpi_init_device_object()
1837 device_initialize(&device->dev); in acpi_init_device_object()
1838 dev_set_uevent_suppress(&device->dev, true); in acpi_init_device_object()
1839 acpi_init_coherency(device); in acpi_init_device_object()
1847 if (dep->consumer == adev->handle) { in acpi_scan_dep_init()
1848 if (dep->honor_dep) in acpi_scan_dep_init()
1849 adev->flags.honor_deps = 1; in acpi_scan_dep_init()
1851 if (!dep->met) in acpi_scan_dep_init()
1852 adev->dep_unmet++; in acpi_scan_dep_init()
1857 void acpi_device_add_finalize(struct acpi_device *device) in acpi_device_add_finalize() argument
1859 dev_set_uevent_suppress(&device->dev, false); in acpi_device_add_finalize()
1860 kobject_uevent(&device->dev.kobj, KOBJ_ADD); in acpi_device_add_finalize()
1870 acpi_handle handle, int type, bool dep_init) in acpi_add_single_object() argument
1872 struct acpi_device *device; in acpi_add_single_object() local
1876 device = kzalloc(sizeof(struct acpi_device), GFP_KERNEL); in acpi_add_single_object()
1877 if (!device) in acpi_add_single_object()
1878 return -ENOMEM; in acpi_add_single_object()
1880 acpi_init_device_object(device, handle, type, acpi_device_release); in acpi_add_single_object()
1884 * this must be done before the get power-/wakeup_dev-flags calls. in acpi_add_single_object()
1893 * updating dep_unmet for the device. in acpi_add_single_object()
1896 acpi_scan_dep_init(device); in acpi_add_single_object()
1898 acpi_scan_init_status(device); in acpi_add_single_object()
1901 acpi_bus_get_power_flags(device); in acpi_add_single_object()
1902 acpi_bus_get_wakeup_device_flags(device); in acpi_add_single_object()
1904 result = acpi_tie_acpi_dev(device); in acpi_add_single_object()
1910 result = acpi_device_add(device); in acpi_add_single_object()
1913 acpi_device_release(&device->dev); in acpi_add_single_object()
1917 acpi_power_add_remove_device(device, true); in acpi_add_single_object()
1918 acpi_device_add_finalize(device); in acpi_add_single_object()
1920 acpi_handle_debug(handle, "Added as %s, parent %s\n", in acpi_add_single_object()
1921 dev_name(&device->dev), device->dev.parent ? in acpi_add_single_object()
1922 dev_name(device->dev.parent) : "(null)"); in acpi_add_single_object()
1924 *child = device; in acpi_add_single_object()
1939 static bool acpi_device_should_be_hidden(acpi_handle handle) in acpi_device_should_be_hidden() argument
1944 /* Check if it should ignore the UART device */ in acpi_device_should_be_hidden()
1945 if (!(spcr_uart_addr && acpi_has_method(handle, METHOD_NAME__CRS))) in acpi_device_should_be_hidden()
1949 * The UART device described in SPCR table is assumed to have only one in acpi_device_should_be_hidden()
1952 status = acpi_walk_resources(handle, METHOD_NAME__CRS, in acpi_device_should_be_hidden()
1957 acpi_handle_info(handle, "The UART device @%pa in SPCR table will be hidden\n", in acpi_device_should_be_hidden()
1965 return adev->status.present || adev->status.functional; in acpi_device_is_present()
1970 return adev->status.enabled; in acpi_device_is_enabled()
1979 if (handler->match) in acpi_scan_handler_matching()
1980 return handler->match(idstr, matchid); in acpi_scan_handler_matching()
1982 for (devid = handler->ids; devid->id[0]; devid++) in acpi_scan_handler_matching()
1983 if (!strcmp((char *)devid->id, idstr)) { in acpi_scan_handler_matching()
2007 if (!!hotplug->enabled == !!val) in acpi_scan_hotplug_enabled()
2012 hotplug->enabled = val; in acpi_scan_hotplug_enabled()
2017 int acpi_scan_add_dep(acpi_handle handle, struct acpi_handle_list *dep_devices) in acpi_scan_add_dep() argument
2022 for (count = 0, i = 0; i < dep_devices->count; i++) { in acpi_scan_add_dep()
2028 status = acpi_get_object_info(dep_devices->handles[i], &info); in acpi_scan_add_dep()
2030 acpi_handle_debug(handle, "Error reading _DEP device info\n"); in acpi_scan_add_dep()
2047 dep->supplier = dep_devices->handles[i]; in acpi_scan_add_dep()
2048 dep->consumer = handle; in acpi_scan_add_dep()
2049 dep->honor_dep = honor_dep; in acpi_scan_add_dep()
2052 list_add_tail(&dep->node, &acpi_dep_list); in acpi_scan_add_dep()
2064 if (acpi_dock_match(adev->handle) || is_ejectable_bay(adev)) { in acpi_scan_init_hotplug()
2068 list_for_each_entry(hwid, &adev->pnp.ids, list) { in acpi_scan_init_hotplug()
2071 handler = acpi_scan_match_handler(hwid->id, NULL); in acpi_scan_init_hotplug()
2073 adev->flags.hotplug_notify = true; in acpi_scan_init_hotplug()
2079 u32 __weak arch_acpi_add_auto_dep(acpi_handle handle) { return 0; } in arch_acpi_add_auto_dep() argument
2081 static u32 acpi_scan_check_dep(acpi_handle handle) in acpi_scan_check_dep() argument
2087 * Some architectures like RISC-V need to add dependencies for in acpi_scan_check_dep()
2093 count += arch_acpi_add_auto_dep(handle); in acpi_scan_check_dep()
2101 if (!acpi_has_method(handle, "_DEP") || !acpi_has_method(handle, "_HID")) in acpi_scan_check_dep()
2104 if (!acpi_evaluate_reference(handle, "_DEP", NULL, &dep_devices)) { in acpi_scan_check_dep()
2105 acpi_handle_debug(handle, "Failed to evaluate _DEP.\n"); in acpi_scan_check_dep()
2109 count += acpi_scan_add_dep(handle, &dep_devices); in acpi_scan_check_dep()
2113 static acpi_status acpi_scan_check_crs_csi2_cb(acpi_handle handle, u32 a, void *b, void **c) in acpi_scan_check_crs_csi2_cb() argument
2115 acpi_mipi_check_crs_csi2(handle); in acpi_scan_check_crs_csi2_cb()
2119 static acpi_status acpi_bus_check_add(acpi_handle handle, bool first_pass, in acpi_bus_check_add() argument
2122 struct acpi_device *device = acpi_fetch_acpi_dev(handle); in acpi_bus_check_add() local
2126 if (device) in acpi_bus_check_add()
2129 if (ACPI_FAILURE(acpi_get_type(handle, &acpi_type))) in acpi_bus_check_add()
2134 if (acpi_device_should_be_hidden(handle)) in acpi_bus_check_add()
2138 acpi_mipi_check_crs_csi2(handle); in acpi_bus_check_add()
2141 if (acpi_scan_check_dep(handle) > 0) { in acpi_bus_check_add()
2143 * The entire CSI-2 connection graph needs to be in acpi_bus_check_add()
2145 * are bound to struct device objects, so scan in acpi_bus_check_add()
2146 * _CRS CSI-2 resource descriptors for all in acpi_bus_check_add()
2147 * devices below the current handle. in acpi_bus_check_add()
2149 acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, in acpi_bus_check_add()
2171 acpi_add_power_resource(handle); in acpi_bus_check_add()
2178 * If first_pass is true at this point, the device has no dependencies, in acpi_bus_check_add()
2179 * or the creation of the device object would have been postponed above. in acpi_bus_check_add()
2181 acpi_add_single_object(&device, handle, type, !first_pass); in acpi_bus_check_add()
2182 if (!device) in acpi_bus_check_add()
2185 acpi_scan_init_hotplug(device); in acpi_bus_check_add()
2189 *adev_p = device; in acpi_bus_check_add()
2194 static acpi_status acpi_bus_check_add_1(acpi_handle handle, u32 lvl_not_used, in acpi_bus_check_add_1() argument
2197 return acpi_bus_check_add(handle, true, (struct acpi_device **)ret_p); in acpi_bus_check_add_1()
2200 static acpi_status acpi_bus_check_add_2(acpi_handle handle, u32 lvl_not_used, in acpi_bus_check_add_2() argument
2203 return acpi_bus_check_add(handle, false, (struct acpi_device **)ret_p); in acpi_bus_check_add_2()
2206 static void acpi_default_enumeration(struct acpi_device *device) in acpi_default_enumeration() argument
2212 if (!device->flags.enumeration_by_parent) { in acpi_default_enumeration()
2213 acpi_create_platform_device(device, NULL); in acpi_default_enumeration()
2214 acpi_device_set_enumerated(device); in acpi_default_enumeration()
2217 ACPI_RECONFIG_DEVICE_ADD, device); in acpi_default_enumeration()
2233 if (adev->data.of_compatible) in acpi_generic_device_attach()
2244 static int acpi_scan_attach_handler(struct acpi_device *device) in acpi_scan_attach_handler() argument
2249 list_for_each_entry(hwid, &device->pnp.ids, list) { in acpi_scan_attach_handler()
2253 handler = acpi_scan_match_handler(hwid->id, &devid); in acpi_scan_attach_handler()
2255 if (!handler->attach) { in acpi_scan_attach_handler()
2256 device->pnp.type.platform_id = 0; in acpi_scan_attach_handler()
2259 device->handler = handler; in acpi_scan_attach_handler()
2260 ret = handler->attach(device, devid); in acpi_scan_attach_handler()
2264 device->handler = NULL; in acpi_scan_attach_handler()
2273 static int acpi_bus_attach(struct acpi_device *device, void *first_pass) in acpi_bus_attach() argument
2275 bool skip = !first_pass && device->flags.visited; in acpi_bus_attach()
2282 if (ACPI_SUCCESS(acpi_bus_get_ejd(device->handle, &ejd))) in acpi_bus_attach()
2283 register_dock_dependent_device(device, ejd); in acpi_bus_attach()
2285 acpi_bus_get_status(device); in acpi_bus_attach()
2287 if (!acpi_dev_ready_for_enumeration(device)) { in acpi_bus_attach()
2288 device->flags.initialized = false; in acpi_bus_attach()
2289 acpi_device_clear_enumerated(device); in acpi_bus_attach()
2290 device->flags.power_manageable = 0; in acpi_bus_attach()
2293 if (device->handler) in acpi_bus_attach()
2296 acpi_ec_register_opregions(device); in acpi_bus_attach()
2298 if (!device->flags.initialized) { in acpi_bus_attach()
2299 device->flags.power_manageable = in acpi_bus_attach()
2300 device->power.states[ACPI_STATE_D0].flags.valid; in acpi_bus_attach()
2301 if (acpi_bus_init_power(device)) in acpi_bus_attach()
2302 device->flags.power_manageable = 0; in acpi_bus_attach()
2304 device->flags.initialized = true; in acpi_bus_attach()
2305 } else if (device->flags.visited) { in acpi_bus_attach()
2309 ret = acpi_scan_attach_handler(device); in acpi_bus_attach()
2313 device->flags.match_driver = true; in acpi_bus_attach()
2314 if (ret > 0 && !device->flags.enumeration_by_parent) { in acpi_bus_attach()
2315 acpi_device_set_enumerated(device); in acpi_bus_attach()
2319 ret = device_attach(&device->dev); in acpi_bus_attach()
2323 if (device->pnp.type.platform_id || device->flags.enumeration_by_parent) in acpi_bus_attach()
2324 acpi_default_enumeration(device); in acpi_bus_attach()
2326 acpi_device_set_enumerated(device); in acpi_bus_attach()
2329 acpi_dev_for_each_child(device, acpi_bus_attach, first_pass); in acpi_bus_attach()
2331 if (!skip && device->handler && device->handler->hotplug.notify_online) in acpi_bus_attach()
2332 device->handler->hotplug.notify_online(device); in acpi_bus_attach()
2343 * If we're passed a 'previous' consumer device then we need to skip in acpi_dev_get_next_consumer_dev_cb()
2348 if (dep->consumer == adev->handle) in acpi_dev_get_next_consumer_dev_cb()
2354 adev = acpi_get_acpi_dev(dep->consumer); in acpi_dev_get_next_consumer_dev_cb()
2359 /* Continue parsing if the device object is not present. */ in acpi_dev_get_next_consumer_dev_cb()
2375 acpi_bus_attach(cdw->adev, (void *)true); in acpi_scan_clear_dep_fn()
2378 acpi_dev_put(cdw->adev); in acpi_scan_clear_dep_fn()
2386 if (adev->dep_unmet) in acpi_scan_clear_dep_queue()
2393 cdw->adev = adev; in acpi_scan_clear_dep_queue()
2394 INIT_WORK(&cdw->work, acpi_scan_clear_dep_fn); in acpi_scan_clear_dep_queue()
2400 queue_work(system_unbound_wq, &cdw->work); in acpi_scan_clear_dep_queue()
2407 list_del(&dep->node); in acpi_scan_delete_dep_data()
2413 struct acpi_device *adev = acpi_get_acpi_dev(dep->consumer); in acpi_scan_clear_dep()
2416 adev->dep_unmet--; in acpi_scan_clear_dep()
2421 if (dep->free_when_met) in acpi_scan_clear_dep()
2424 dep->met = true; in acpi_scan_clear_dep()
2430 * acpi_walk_dep_device_list - Apply a callback to every entry in acpi_dep_list
2431 * @handle: The ACPI handle of the supplier device
2441 static int acpi_walk_dep_device_list(acpi_handle handle, in acpi_walk_dep_device_list() argument
2450 if (dep->supplier == handle) { in acpi_walk_dep_device_list()
2462 * acpi_dev_clear_dependencies - Inform consumers that the device is now active
2465 * Clear dependencies on the given device.
2469 acpi_walk_dep_device_list(supplier->handle, acpi_scan_clear_dep, NULL); in acpi_dev_clear_dependencies()
2474 * acpi_dev_ready_for_enumeration - Check if the ACPI device is ready for enumeration
2475 * @device: Pointer to the &struct acpi_device to check
2477 * Check if the device is present and has no unmet dependencies.
2479 * Return true if the device is ready for enumeratino. Otherwise, return false.
2481 bool acpi_dev_ready_for_enumeration(const struct acpi_device *device) in acpi_dev_ready_for_enumeration() argument
2483 if (device->flags.honor_deps && device->dep_unmet) in acpi_dev_ready_for_enumeration()
2486 return acpi_device_is_present(device); in acpi_dev_ready_for_enumeration()
2491 * acpi_dev_get_next_consumer_dev - Return the next adev dependent on @supplier
2492 * @supplier: Pointer to the dependee device
2493 * @start: Pointer to the current dependent device
2506 acpi_walk_dep_device_list(supplier->handle, in acpi_dev_get_next_consumer_dev()
2518 static void acpi_scan_postponed_branch(acpi_handle handle) in acpi_scan_postponed_branch() argument
2522 if (ACPI_FAILURE(acpi_bus_check_add(handle, false, &adev))) in acpi_scan_postponed_branch()
2525 acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX, in acpi_scan_postponed_branch()
2529 * Populate the ACPI _CRS CSI-2 software nodes for the ACPI devices that in acpi_scan_postponed_branch()
2544 acpi_handle handle = dep->consumer; in acpi_scan_postponed() local
2548 * same consumer, skip the current entry if the consumer device in acpi_scan_postponed()
2551 if (!acpi_fetch_acpi_dev(handle)) { in acpi_scan_postponed()
2560 acpi_scan_postponed_branch(handle); in acpi_scan_postponed()
2565 if (dep->met) in acpi_scan_postponed()
2568 dep->free_when_met = true; in acpi_scan_postponed()
2575 * acpi_bus_scan - Add ACPI device node objects in a given namespace scope.
2576 * @handle: Root of the namespace scope to scan.
2578 * Scan a given ACPI tree (probably recently hot-plugged) and create and add
2581 * If no devices were found, -ENODEV is returned, but it does not mean that
2583 * in the table trunk from which the kernel could create a device and add an
2588 int acpi_bus_scan(acpi_handle handle) in acpi_bus_scan() argument
2590 struct acpi_device *device = NULL; in acpi_bus_scan() local
2594 if (ACPI_SUCCESS(acpi_bus_check_add(handle, true, &device))) in acpi_bus_scan()
2595 acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX, in acpi_bus_scan()
2597 (void **)&device); in acpi_bus_scan()
2599 if (!device) in acpi_bus_scan()
2600 return -ENODEV; in acpi_bus_scan()
2603 * Set up ACPI _CRS CSI-2 software nodes using information extracted in acpi_bus_scan()
2604 * from the _CRS CSI-2 resource descriptors during the ACPI namespace in acpi_bus_scan()
2605 * walk above and MIPI DisCo for Imaging device properties. in acpi_bus_scan()
2610 acpi_bus_attach(device, (void *)true); in acpi_bus_scan()
2623 * acpi_bus_trim - Detach scan handlers and drivers from ACPI device objects.
2638 struct acpi_device *device = NULL; in acpi_bus_register_early_device() local
2641 result = acpi_add_single_object(&device, NULL, type, false); in acpi_bus_register_early_device()
2645 device->flags.match_driver = true; in acpi_bus_register_early_device()
2646 return device_attach(&device->dev); in acpi_bus_register_early_device()
2658 adev->flags.match_driver = true; in acpi_bus_scan_fixed()
2659 if (device_attach(&adev->dev) >= 0) in acpi_bus_scan_fixed()
2660 device_init_wakeup(&adev->dev, true); in acpi_bus_scan_fixed()
2662 dev_dbg(&adev->dev, "No driver\n"); in acpi_bus_scan_fixed()
2672 adev->flags.match_driver = true; in acpi_bus_scan_fixed()
2673 if (device_attach(&adev->dev) < 0) in acpi_bus_scan_fixed()
2674 dev_dbg(&adev->dev, "No driver\n"); in acpi_bus_scan_fixed()
2691 spcr_uart_addr = spcr_ptr->serial_port.address; in acpi_get_spcr_uart_addr()
2720 * device in SPCR table. in acpi_scan_init()
2725 if (stao_ptr->header.length > sizeof(struct acpi_table_stao)) in acpi_scan_init()
2728 if (stao_ptr->ignore_uart) in acpi_scan_init()
2754 /* Fixed feature devices do not exist on HW-reduced platform */ in acpi_scan_init()
2773 if (!ape->subtable_valid || ape->subtable_valid(&header->common, ape)) in acpi_match_madt()
2774 if (!ape->probe_subtbl(header, end)) in acpi_match_madt()
2791 for (ape = ap_head; nr; ape++, nr--) { in __acpi_probe_device_table()
2792 if (ACPI_COMPARE_NAMESEG(ACPI_SIG_MADT, ape->id)) { in __acpi_probe_device_table()
2794 acpi_table_parse_madt(ape->type, acpi_match_madt, 0); in __acpi_probe_device_table()
2798 res = acpi_table_parse(ape->id, ape->probe_table); in __acpi_probe_device_table()