Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  * scan.c - support for transforming the ACPI namespace into individual objects
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11) #include <linux/acpi_iort.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) #include <linux/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) #include <linux/kthread.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #include <linux/dmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #include <linux/nls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include <linux/dma-map-ops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include <linux/platform_data/x86/apple.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include <linux/pgtable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include "internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #define _COMPONENT		ACPI_BUS_COMPONENT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) ACPI_MODULE_NAME("scan");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) extern struct acpi_device *acpi_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) #define ACPI_BUS_CLASS			"system_bus"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) #define ACPI_BUS_HID			"LNXSYBUS"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) #define ACPI_BUS_DEVICE_NAME		"System Bus"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) #define ACPI_IS_ROOT_DEVICE(device)    (!(device)->parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #define INVALID_ACPI_HANDLE	((acpi_handle)empty_zero_page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) static const char *dummy_hid = "device";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) static LIST_HEAD(acpi_dep_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) static DEFINE_MUTEX(acpi_dep_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) LIST_HEAD(acpi_bus_id_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) static DEFINE_MUTEX(acpi_scan_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) static LIST_HEAD(acpi_scan_handlers_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) DEFINE_MUTEX(acpi_device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) LIST_HEAD(acpi_wakeup_device_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) static DEFINE_MUTEX(acpi_hp_context_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46)  * The UART device described by the SPCR table is the only object which needs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47)  * special-casing. Everything else is covered by ACPI namespace paths in STAO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48)  * table.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) static u64 spcr_uart_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) struct acpi_dep_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) 	struct list_head node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) 	acpi_handle master;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 	acpi_handle slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) void acpi_scan_lock_acquire(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) 	mutex_lock(&acpi_scan_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) EXPORT_SYMBOL_GPL(acpi_scan_lock_acquire);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) void acpi_scan_lock_release(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) 	mutex_unlock(&acpi_scan_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) EXPORT_SYMBOL_GPL(acpi_scan_lock_release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) void acpi_lock_hp_context(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 	mutex_lock(&acpi_hp_context_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) void acpi_unlock_hp_context(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 	mutex_unlock(&acpi_hp_context_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) void acpi_initialize_hp_context(struct acpi_device *adev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 				struct acpi_hotplug_context *hp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 				int (*notify)(struct acpi_device *, u32),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 				void (*uevent)(struct acpi_device *, u32))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 	acpi_lock_hp_context();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 	hp->notify = notify;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 	hp->uevent = uevent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 	acpi_set_hp_context(adev, hp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 	acpi_unlock_hp_context();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) EXPORT_SYMBOL_GPL(acpi_initialize_hp_context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) int acpi_scan_add_handler(struct acpi_scan_handler *handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 	if (!handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 	list_add_tail(&handler->list_node, &acpi_scan_handlers_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) int acpi_scan_add_handler_with_hotplug(struct acpi_scan_handler *handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 				       const char *hotplug_profile_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 	error = acpi_scan_add_handler(handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 	acpi_sysfs_add_hotplug_profile(&handler->hotplug, hotplug_profile_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) bool acpi_scan_is_offline(struct acpi_device *adev, bool uevent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 	struct acpi_device_physical_node *pn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 	bool offline = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 	char *envp[] = { "EVENT=offline", NULL };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 	 * acpi_container_offline() calls this for all of the container's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 	 * children under the container's physical_node_lock lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 	mutex_lock_nested(&adev->physical_node_lock, SINGLE_DEPTH_NESTING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 	list_for_each_entry(pn, &adev->physical_node_list, node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 		if (device_supports_offline(pn->dev) && !pn->dev->offline) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 			if (uevent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 				kobject_uevent_env(&pn->dev->kobj, KOBJ_CHANGE, envp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 			offline = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 	mutex_unlock(&adev->physical_node_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 	return offline;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) static acpi_status acpi_bus_offline(acpi_handle handle, u32 lvl, void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 				    void **ret_p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 	struct acpi_device *device = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 	struct acpi_device_physical_node *pn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 	bool second_pass = (bool)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 	acpi_status status = AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 	if (acpi_bus_get_device(handle, &device))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 		return AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 	if (device->handler && !device->handler->hotplug.enabled) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 		*ret_p = &device->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 		return AE_SUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 	mutex_lock(&device->physical_node_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 	list_for_each_entry(pn, &device->physical_node_list, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 		int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 		if (second_pass) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 			/* Skip devices offlined by the first pass. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 			if (pn->put_online)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 			pn->put_online = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 		ret = device_offline(pn->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 		if (ret >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 			pn->put_online = !ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 			*ret_p = pn->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 			if (second_pass) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 				status = AE_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 	mutex_unlock(&device->physical_node_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) static acpi_status acpi_bus_online(acpi_handle handle, u32 lvl, void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 				   void **ret_p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 	struct acpi_device *device = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 	struct acpi_device_physical_node *pn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 	if (acpi_bus_get_device(handle, &device))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 		return AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 	mutex_lock(&device->physical_node_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	list_for_each_entry(pn, &device->physical_node_list, node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 		if (pn->put_online) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 			device_online(pn->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 			pn->put_online = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 	mutex_unlock(&device->physical_node_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 	return AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) static int acpi_scan_try_to_offline(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 	acpi_handle handle = device->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 	struct device *errdev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 	 * Carry out two passes here and ignore errors in the first pass,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	 * because if the devices in question are memory blocks and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 	 * CONFIG_MEMCG is set, one of the blocks may hold data structures
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 	 * that the other blocks depend on, but it is not known in advance which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 	 * block holds them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 	 * If the first pass is successful, the second one isn't needed, though.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 	status = acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 				     NULL, acpi_bus_offline, (void *)false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 				     (void **)&errdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	if (status == AE_SUPPORT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 		dev_warn(errdev, "Offline disabled.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 		acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 				    acpi_bus_online, NULL, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 		return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 	acpi_bus_offline(handle, 0, (void *)false, (void **)&errdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 	if (errdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 		errdev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 		acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 				    NULL, acpi_bus_offline, (void *)true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 				    (void **)&errdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 		if (!errdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 			acpi_bus_offline(handle, 0, (void *)true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 					 (void **)&errdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 		if (errdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 			dev_warn(errdev, "Offline failed.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 			acpi_bus_online(handle, 0, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 			acpi_walk_namespace(ACPI_TYPE_ANY, handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 					    ACPI_UINT32_MAX, acpi_bus_online,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 					    NULL, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 			return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) static int acpi_scan_hot_remove(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 	acpi_handle handle = device->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 	unsigned long long sta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 	if (device->handler && device->handler->hotplug.demand_offline) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 		if (!acpi_scan_is_offline(device, true))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 			return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 		int error = acpi_scan_try_to_offline(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 			return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 	ACPI_DEBUG_PRINT((ACPI_DB_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 		"Hot-removing device %s...\n", dev_name(&device->dev)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 	acpi_bus_trim(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 	acpi_evaluate_lck(handle, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 	 * TBD: _EJD support.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 	status = acpi_evaluate_ej0(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 	if (status == AE_NOT_FOUND)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 	else if (ACPI_FAILURE(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 	 * Verify if eject was indeed successful.  If not, log an error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 	 * message.  No need to call _OST since _EJ0 call was made OK.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 	status = acpi_evaluate_integer(handle, "_STA", NULL, &sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 	if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 		acpi_handle_warn(handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 			"Status check after eject failed (0x%x)\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 	} else if (sta & ACPI_STA_DEVICE_ENABLED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 		acpi_handle_warn(handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 			"Eject incomplete - status 0x%llx\n", sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) static int acpi_scan_device_not_present(struct acpi_device *adev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 	if (!acpi_device_enumerated(adev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 		dev_warn(&adev->dev, "Still not present\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 		return -EALREADY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 	acpi_bus_trim(adev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) static int acpi_scan_device_check(struct acpi_device *adev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 	acpi_bus_get_status(adev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 	if (adev->status.present || adev->status.functional) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 		 * This function is only called for device objects for which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 		 * matching scan handlers exist.  The only situation in which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 		 * the scan handler is not attached to this device object yet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 		 * is when the device has just appeared (either it wasn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 		 * present at all before or it was removed and then added
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 		 * again).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 		if (adev->handler) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 			dev_warn(&adev->dev, "Already enumerated\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 			return -EALREADY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 		error = acpi_bus_scan(adev->handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 		if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 			dev_warn(&adev->dev, "Namespace scan failure\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 			return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 		if (!adev->handler) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 			dev_warn(&adev->dev, "Enumeration failure\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 			error = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 		error = acpi_scan_device_not_present(adev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) static int acpi_scan_bus_check(struct acpi_device *adev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 	struct acpi_scan_handler *handler = adev->handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 	struct acpi_device *child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 	acpi_bus_get_status(adev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 	if (!(adev->status.present || adev->status.functional)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 		acpi_scan_device_not_present(adev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 	if (handler && handler->hotplug.scan_dependent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 		return handler->hotplug.scan_dependent(adev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 	error = acpi_bus_scan(adev->handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 		dev_warn(&adev->dev, "Namespace scan failure\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 	list_for_each_entry(child, &adev->children, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 		error = acpi_scan_bus_check(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 			return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) static int acpi_generic_hotplug_event(struct acpi_device *adev, u32 type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 	switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 	case ACPI_NOTIFY_BUS_CHECK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 		return acpi_scan_bus_check(adev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 	case ACPI_NOTIFY_DEVICE_CHECK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 		return acpi_scan_device_check(adev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 	case ACPI_NOTIFY_EJECT_REQUEST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 	case ACPI_OST_EC_OSPM_EJECT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 		if (adev->handler && !adev->handler->hotplug.enabled) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 			dev_info(&adev->dev, "Eject disabled\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 			return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 		acpi_evaluate_ost(adev->handle, ACPI_NOTIFY_EJECT_REQUEST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 				  ACPI_OST_SC_EJECT_IN_PROGRESS, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 		return acpi_scan_hot_remove(adev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 	return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) void acpi_device_hotplug(struct acpi_device *adev, u32 src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 	u32 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 	int error = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 	lock_device_hotplug();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 	mutex_lock(&acpi_scan_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 	 * The device object's ACPI handle cannot become invalid as long as we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 	 * are holding acpi_scan_lock, but it might have become invalid before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 	 * that lock was acquired.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 	if (adev->handle == INVALID_ACPI_HANDLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 		goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 	if (adev->flags.is_dock_station) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 		error = dock_notify(adev, src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 	} else if (adev->flags.hotplug_notify) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 		error = acpi_generic_hotplug_event(adev, src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 		int (*notify)(struct acpi_device *, u32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 		acpi_lock_hp_context();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 		notify = adev->hp ? adev->hp->notify : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 		acpi_unlock_hp_context();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 		 * There may be additional notify handlers for device objects
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 		 * without the .event() callback, so ignore them here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 		if (notify)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 			error = notify(adev, src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 	switch (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 		ost_code = ACPI_OST_SC_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 	case -EPERM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 		ost_code = ACPI_OST_SC_EJECT_NOT_SUPPORTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 	case -EBUSY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 		ost_code = ACPI_OST_SC_DEVICE_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 		ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439)  err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	acpi_evaluate_ost(adev->handle, src, ost_code, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442)  out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 	acpi_bus_put_acpi_device(adev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 	mutex_unlock(&acpi_scan_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 	unlock_device_hotplug();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) static void acpi_free_power_resources_lists(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 	if (device->wakeup.flags.valid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 		acpi_power_resources_list_free(&device->wakeup.resources);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 	if (!device->power.flags.power_resources)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 	for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3_HOT; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 		struct acpi_device_power_state *ps = &device->power.states[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 		acpi_power_resources_list_free(&ps->resources);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) static void acpi_device_release(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 	struct acpi_device *acpi_dev = to_acpi_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 	acpi_free_properties(acpi_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 	acpi_free_pnp_ids(&acpi_dev->pnp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 	acpi_free_power_resources_lists(acpi_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	kfree(acpi_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) static void acpi_device_del(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 	struct acpi_device_bus_id *acpi_device_bus_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 	mutex_lock(&acpi_device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 	if (device->parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 		list_del(&device->node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 	list_for_each_entry(acpi_device_bus_id, &acpi_bus_id_list, node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 		if (!strcmp(acpi_device_bus_id->bus_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 			    acpi_device_hid(device))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 			ida_simple_remove(&acpi_device_bus_id->instance_ida, device->pnp.instance_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 			if (ida_is_empty(&acpi_device_bus_id->instance_ida)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 				list_del(&acpi_device_bus_id->node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 				kfree_const(acpi_device_bus_id->bus_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 				kfree(acpi_device_bus_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 	list_del(&device->wakeup_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 	mutex_unlock(&acpi_device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 	acpi_power_add_remove_device(device, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 	acpi_device_remove_files(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 	if (device->remove)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 		device->remove(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 	device_del(&device->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) static BLOCKING_NOTIFIER_HEAD(acpi_reconfig_chain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) static LIST_HEAD(acpi_device_del_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) static DEFINE_MUTEX(acpi_device_del_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) static void acpi_device_del_work_fn(struct work_struct *work_not_used)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 	for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 		struct acpi_device *adev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 		mutex_lock(&acpi_device_del_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 		if (list_empty(&acpi_device_del_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 			mutex_unlock(&acpi_device_del_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 		adev = list_first_entry(&acpi_device_del_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 					struct acpi_device, del_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 		list_del(&adev->del_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 		mutex_unlock(&acpi_device_del_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 		blocking_notifier_call_chain(&acpi_reconfig_chain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 					     ACPI_RECONFIG_DEVICE_REMOVE, adev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 		acpi_device_del(adev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 		 * Drop references to all power resources that might have been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 		 * used by the device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 		acpi_power_transition(adev, ACPI_STATE_D3_COLD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 		put_device(&adev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541)  * acpi_scan_drop_device - Drop an ACPI device object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542)  * @handle: Handle of an ACPI namespace node, not used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543)  * @context: Address of the ACPI device object to drop.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545)  * This is invoked by acpi_ns_delete_node() during the removal of the ACPI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546)  * namespace node the device object pointed to by @context is attached to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548)  * The unregistration is carried out asynchronously to avoid running
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549)  * acpi_device_del() under the ACPICA's namespace mutex and the list is used to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550)  * ensure the correct ordering (the device objects must be unregistered in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551)  * same order in which the corresponding namespace nodes are deleted).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) static void acpi_scan_drop_device(acpi_handle handle, void *context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 	static DECLARE_WORK(work, acpi_device_del_work_fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 	struct acpi_device *adev = context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 	mutex_lock(&acpi_device_del_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 	 * Use the ACPI hotplug workqueue which is ordered, so this work item
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 	 * won't run after any hotplug work items submitted subsequently.  That
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	 * prevents attempts to register device objects identical to those being
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 	 * deleted from happening concurrently (such attempts result from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 	 * hotplug events handled via the ACPI hotplug workqueue).  It also will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 	 * run after all of the work items submitted previosuly, which helps
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 	 * those work items to ensure that they are not accessing stale device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 	 * objects.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 	if (list_empty(&acpi_device_del_list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 		acpi_queue_hotplug_work(&work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 	list_add_tail(&adev->del_list, &acpi_device_del_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 	/* Make acpi_ns_validate_handle() return NULL for this handle. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 	adev->handle = INVALID_ACPI_HANDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	mutex_unlock(&acpi_device_del_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) static int acpi_get_device_data(acpi_handle handle, struct acpi_device **device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 				void (*callback)(void *))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 	if (!device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 	*device = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 	status = acpi_get_data_full(handle, acpi_scan_drop_device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 				    (void **)device, callback);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 	if (ACPI_FAILURE(status) || !*device) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 		ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 				  handle));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) int acpi_bus_get_device(acpi_handle handle, struct acpi_device **device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 	return acpi_get_device_data(handle, device, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) EXPORT_SYMBOL(acpi_bus_get_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) static void get_acpi_device(void *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 	if (dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 		get_device(&((struct acpi_device *)dev)->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) struct acpi_device *acpi_bus_get_acpi_device(acpi_handle handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 	struct acpi_device *adev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 	acpi_get_device_data(handle, &adev, get_acpi_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 	return adev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) void acpi_bus_put_acpi_device(struct acpi_device *adev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 	put_device(&adev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) static struct acpi_device_bus_id *acpi_device_bus_id_match(const char *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 	struct acpi_device_bus_id *acpi_device_bus_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 	/* Find suitable bus_id and instance number in acpi_bus_id_list. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 	list_for_each_entry(acpi_device_bus_id, &acpi_bus_id_list, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 		if (!strcmp(acpi_device_bus_id->bus_id, dev_id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 			return acpi_device_bus_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) static int acpi_device_set_name(struct acpi_device *device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 				struct acpi_device_bus_id *acpi_device_bus_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 	struct ida *instance_ida = &acpi_device_bus_id->instance_ida;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 	result = ida_simple_get(instance_ida, 0, ACPI_MAX_DEVICE_INSTANCES, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 	if (result < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 		return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 	device->pnp.instance_no = result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 	dev_set_name(&device->dev, "%s:%02x", acpi_device_bus_id->bus_id, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) int acpi_device_add(struct acpi_device *device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 		    void (*release)(struct device *))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 	struct acpi_device_bus_id *acpi_device_bus_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 	if (device->handle) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 		acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 		status = acpi_attach_data(device->handle, acpi_scan_drop_device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 					  device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 		if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 			acpi_handle_err(device->handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 					"Unable to attach device data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 			return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 	 * Linkage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 	 * -------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 	 * Link this device to its parent and siblings.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 	INIT_LIST_HEAD(&device->children);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 	INIT_LIST_HEAD(&device->node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 	INIT_LIST_HEAD(&device->wakeup_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 	INIT_LIST_HEAD(&device->physical_node_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 	INIT_LIST_HEAD(&device->del_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 	mutex_init(&device->physical_node_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 	mutex_lock(&acpi_device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 	acpi_device_bus_id = acpi_device_bus_id_match(acpi_device_hid(device));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 	if (acpi_device_bus_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 		result = acpi_device_set_name(device, acpi_device_bus_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 		if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 			goto err_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 		acpi_device_bus_id = kzalloc(sizeof(*acpi_device_bus_id),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 					     GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 		if (!acpi_device_bus_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 			result = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 			goto err_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 		acpi_device_bus_id->bus_id =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 			kstrdup_const(acpi_device_hid(device), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 		if (!acpi_device_bus_id->bus_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 			kfree(acpi_device_bus_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 			result = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 			goto err_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 		ida_init(&acpi_device_bus_id->instance_ida);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 		result = acpi_device_set_name(device, acpi_device_bus_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 		if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 			kfree_const(acpi_device_bus_id->bus_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 			kfree(acpi_device_bus_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 			goto err_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 		list_add_tail(&acpi_device_bus_id->node, &acpi_bus_id_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 	if (device->parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 		list_add_tail(&device->node, &device->parent->children);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 	if (device->wakeup.flags.valid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 		list_add_tail(&device->wakeup_list, &acpi_wakeup_device_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 	mutex_unlock(&acpi_device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	if (device->parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 		device->dev.parent = &device->parent->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 	device->dev.bus = &acpi_bus_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 	device->dev.release = release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	result = device_add(&device->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 	if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 		dev_err(&device->dev, "Error registering device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 	result = acpi_device_setup_files(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 	if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 		printk(KERN_ERR PREFIX "Error creating sysfs interface for device %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 		       dev_name(&device->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740)  err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 	mutex_lock(&acpi_device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 	if (device->parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 		list_del(&device->node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 	list_del(&device->wakeup_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746)  err_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 	mutex_unlock(&acpi_device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 	acpi_detach_data(device->handle, acpi_scan_drop_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) /* --------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754)                                  Device Enumeration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755)    -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) static struct acpi_device *acpi_bus_get_parent(acpi_handle handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 	struct acpi_device *device = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 	 * Fixed hardware devices do not appear in the namespace and do not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 	 * have handles, but we fabricate acpi_devices for them, so we have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 	 * to deal with them specially.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 	if (!handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 		return acpi_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 		status = acpi_get_parent(handle, &handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 		if (ACPI_FAILURE(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 			return status == AE_NULL_ENTRY ? NULL : acpi_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 	} while (acpi_bus_get_device(handle, &device));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 	return device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) acpi_bus_get_ejd(acpi_handle handle, acpi_handle *ejd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 	acpi_handle tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 	struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 	union acpi_object *obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 	status = acpi_get_handle(handle, "_EJD", &tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 	if (ACPI_FAILURE(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 		return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 	status = acpi_evaluate_object(handle, "_EJD", NULL, &buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 	if (ACPI_SUCCESS(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 		obj = buffer.pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 		status = acpi_get_handle(ACPI_ROOT_OBJECT, obj->string.pointer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 					 ejd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 		kfree(buffer.pointer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) EXPORT_SYMBOL_GPL(acpi_bus_get_ejd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) static int acpi_bus_extract_wakeup_device_power_package(struct acpi_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 	acpi_handle handle = dev->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 	struct acpi_device_wakeup *wakeup = &dev->wakeup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 	union acpi_object *package = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 	union acpi_object *element = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 	int err = -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 	INIT_LIST_HEAD(&wakeup->resources);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 	/* _PRW */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 	status = acpi_evaluate_object(handle, "_PRW", NULL, &buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 	if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 		ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRW"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 	package = (union acpi_object *)buffer.pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 	if (!package || package->package.count < 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 	element = &(package->package.elements[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 	if (!element)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 	if (element->type == ACPI_TYPE_PACKAGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 		if ((element->package.count < 2) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 		    (element->package.elements[0].type !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 		     ACPI_TYPE_LOCAL_REFERENCE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 		    || (element->package.elements[1].type != ACPI_TYPE_INTEGER))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 		wakeup->gpe_device =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 		    element->package.elements[0].reference.handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 		wakeup->gpe_number =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 		    (u32) element->package.elements[1].integer.value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 	} else if (element->type == ACPI_TYPE_INTEGER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 		wakeup->gpe_device = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 		wakeup->gpe_number = element->integer.value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 	element = &(package->package.elements[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 	if (element->type != ACPI_TYPE_INTEGER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 	wakeup->sleep_state = element->integer.value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 	err = acpi_extract_power_resources(package, 2, &wakeup->resources);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 	if (!list_empty(&wakeup->resources)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 		int sleep_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 		err = acpi_power_wakeup_list_init(&wakeup->resources,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 						  &sleep_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 			acpi_handle_warn(handle, "Retrieving current states "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 					 "of wakeup power resources failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 			acpi_power_resources_list_free(&wakeup->resources);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 		if (sleep_state < wakeup->sleep_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 			acpi_handle_warn(handle, "Overriding _PRW sleep state "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 					 "(S%d) by S%d from power resources\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 					 (int)wakeup->sleep_state, sleep_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 			wakeup->sleep_state = sleep_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875)  out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 	kfree(buffer.pointer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) static bool acpi_wakeup_gpe_init(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 	static const struct acpi_device_id button_device_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 		{"PNP0C0C", 0},		/* Power button */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 		{"PNP0C0D", 0},		/* Lid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 		{"PNP0C0E", 0},		/* Sleep button */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 		{"", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 	struct acpi_device_wakeup *wakeup = &device->wakeup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 	wakeup->flags.notifier_present = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	/* Power button, Lid switch always enable wakeup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 	if (!acpi_match_device_ids(device, button_device_ids)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 		if (!acpi_match_device_ids(device, &button_device_ids[1])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 			/* Do not use Lid/sleep button for S5 wakeup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 			if (wakeup->sleep_state == ACPI_STATE_S5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 				wakeup->sleep_state = ACPI_STATE_S4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 		acpi_mark_gpe_for_wake(wakeup->gpe_device, wakeup->gpe_number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 		device_set_wakeup_capable(&device->dev, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 	status = acpi_setup_gpe_for_wake(device->handle, wakeup->gpe_device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 					 wakeup->gpe_number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 	return ACPI_SUCCESS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) static void acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 	/* Presence of _PRW indicates wake capable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 	if (!acpi_has_method(device->handle, "_PRW"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 	err = acpi_bus_extract_wakeup_device_power_package(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 		dev_err(&device->dev, "_PRW evaluation error: %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 	device->wakeup.flags.valid = acpi_wakeup_gpe_init(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 	device->wakeup.prepare_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 	 * Call _PSW/_DSW object to disable its ability to wake the sleeping
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 	 * system for the ACPI device with the _PRW object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	 * The _PSW object is deprecated in ACPI 3.0 and is replaced by _DSW.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 	 * So it is necessary to call _DSW object first. Only when it is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 	 * present will the _PSW object used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 	err = acpi_device_sleep_wake(device, 0, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 		pr_debug("error in _DSW or _PSW evaluation\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) static void acpi_bus_init_power_state(struct acpi_device *device, int state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 	struct acpi_device_power_state *ps = &device->power.states[state];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 	char pathname[5] = { '_', 'P', 'R', '0' + state, '\0' };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 	INIT_LIST_HEAD(&ps->resources);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 	/* Evaluate "_PRx" to get referenced power resources */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 	status = acpi_evaluate_object(device->handle, pathname, NULL, &buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 	if (ACPI_SUCCESS(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 		union acpi_object *package = buffer.pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 		if (buffer.length && package
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 		    && package->type == ACPI_TYPE_PACKAGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 		    && package->package.count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 			acpi_extract_power_resources(package, 0, &ps->resources);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 		ACPI_FREE(buffer.pointer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 	/* Evaluate "_PSx" to see if we can do explicit sets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 	pathname[2] = 'S';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 	if (acpi_has_method(device->handle, pathname))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 		ps->flags.explicit_set = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 	/* State is valid if there are means to put the device into it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 	if (!list_empty(&ps->resources) || ps->flags.explicit_set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 		ps->flags.valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 	ps->power = -1;		/* Unknown - driver assigned */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 	ps->latency = -1;	/* Unknown - driver assigned */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) static void acpi_bus_get_power_flags(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	u32 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 	/* Presence of _PS0|_PR0 indicates 'power manageable' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 	if (!acpi_has_method(device->handle, "_PS0") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 	    !acpi_has_method(device->handle, "_PR0"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 	device->flags.power_manageable = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 	 * Power Management Flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 	if (acpi_has_method(device->handle, "_PSC"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 		device->power.flags.explicit_get = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 	if (acpi_has_method(device->handle, "_IRC"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 		device->power.flags.inrush_current = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 	if (acpi_has_method(device->handle, "_DSW"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 		device->power.flags.dsw_present = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 	 * Enumerate supported power management states
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 	for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3_HOT; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 		acpi_bus_init_power_state(device, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 	INIT_LIST_HEAD(&device->power.states[ACPI_STATE_D3_COLD].resources);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 	/* Set the defaults for D0 and D3hot (always supported). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 	device->power.states[ACPI_STATE_D0].flags.valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 	device->power.states[ACPI_STATE_D0].power = 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 	device->power.states[ACPI_STATE_D3_HOT].flags.valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	 * Use power resources only if the D0 list of them is populated, because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 	 * some platforms may provide _PR3 only to indicate D3cold support and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 	 * in those cases the power resources list returned by it may be bogus.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 	if (!list_empty(&device->power.states[ACPI_STATE_D0].resources)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 		device->power.flags.power_resources = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 		 * D3cold is supported if the D3hot list of power resources is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 		 * not empty.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 		if (!list_empty(&device->power.states[ACPI_STATE_D3_HOT].resources))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 			device->power.states[ACPI_STATE_D3_COLD].flags.valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 	if (acpi_bus_init_power(device))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 		device->flags.power_manageable = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) static void acpi_bus_get_flags(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 	/* Presence of _STA indicates 'dynamic_status' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 	if (acpi_has_method(device->handle, "_STA"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 		device->flags.dynamic_status = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 	/* Presence of _RMV indicates 'removable' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 	if (acpi_has_method(device->handle, "_RMV"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 		device->flags.removable = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 	/* Presence of _EJD|_EJ0 indicates 'ejectable' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 	if (acpi_has_method(device->handle, "_EJD") ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 	    acpi_has_method(device->handle, "_EJ0"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 		device->flags.ejectable = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) static void acpi_device_get_busid(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 	char bus_id[5] = { '?', 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 	struct acpi_buffer buffer = { sizeof(bus_id), bus_id };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 	 * Bus ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	 * ------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 	 * The device's Bus ID is simply the object name.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 	 * TBD: Shouldn't this value be unique (within the ACPI namespace)?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 	if (ACPI_IS_ROOT_DEVICE(device)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 		strcpy(device->pnp.bus_id, "ACPI");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 	switch (device->device_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 	case ACPI_BUS_TYPE_POWER_BUTTON:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 		strcpy(device->pnp.bus_id, "PWRF");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 	case ACPI_BUS_TYPE_SLEEP_BUTTON:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 		strcpy(device->pnp.bus_id, "SLPF");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 	case ACPI_BUS_TYPE_ECDT_EC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 		strcpy(device->pnp.bus_id, "ECDT");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 		acpi_get_name(device->handle, ACPI_SINGLE_NAME, &buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 		/* Clean up trailing underscores (if any) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 		for (i = 3; i > 1; i--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 			if (bus_id[i] == '_')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 				bus_id[i] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 		strcpy(device->pnp.bus_id, bus_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086)  * acpi_ata_match - see if an acpi object is an ATA device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088)  * If an acpi object has one of the ACPI ATA methods defined,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089)  * then we can safely call it an ATA device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) bool acpi_ata_match(acpi_handle handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 	return acpi_has_method(handle, "_GTF") ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 	       acpi_has_method(handle, "_GTM") ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 	       acpi_has_method(handle, "_STM") ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 	       acpi_has_method(handle, "_SDD");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100)  * acpi_bay_match - see if an acpi object is an ejectable driver bay
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102)  * If an acpi object is ejectable and has one of the ACPI ATA methods defined,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103)  * then we can safely call it an ejectable drive bay
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) bool acpi_bay_match(acpi_handle handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 	acpi_handle phandle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 	if (!acpi_has_method(handle, "_EJ0"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 	if (acpi_ata_match(handle))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 	if (ACPI_FAILURE(acpi_get_parent(handle, &phandle)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 	return acpi_ata_match(phandle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) bool acpi_device_is_battery(struct acpi_device *adev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 	struct acpi_hardware_id *hwid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 	list_for_each_entry(hwid, &adev->pnp.ids, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 		if (!strcmp("PNP0C0A", hwid->id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 			return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) static bool is_ejectable_bay(struct acpi_device *adev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 	acpi_handle handle = adev->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 	if (acpi_has_method(handle, "_EJ0") && acpi_device_is_battery(adev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 	return acpi_bay_match(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141)  * acpi_dock_match - see if an acpi object has a _DCK method
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) bool acpi_dock_match(acpi_handle handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 	return acpi_has_method(handle, "_DCK");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) static acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) acpi_backlight_cap_match(acpi_handle handle, u32 level, void *context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 			  void **return_value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 	long *cap = context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 	if (acpi_has_method(handle, "_BCM") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 	    acpi_has_method(handle, "_BCL")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 		ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found generic backlight "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 				  "support\n"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 		*cap |= ACPI_VIDEO_BACKLIGHT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 		/* We have backlight support, no need to scan further */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 		return AE_CTRL_TERMINATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) /* Returns true if the ACPI object is a video device which can be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166)  * handled by video.ko.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167)  * The device will get a Linux specific CID added in scan.c to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168)  * identify the device as an ACPI graphics device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169)  * Be aware that the graphics device may not be physically present
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170)  * Use acpi_video_get_capabilities() to detect general ACPI video
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171)  * capabilities of present cards
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) long acpi_is_video_device(acpi_handle handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 	long video_caps = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 	/* Is this device able to support video switching ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 	if (acpi_has_method(handle, "_DOD") || acpi_has_method(handle, "_DOS"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 		video_caps |= ACPI_VIDEO_OUTPUT_SWITCHING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 	/* Is this device able to retrieve a video ROM ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 	if (acpi_has_method(handle, "_ROM"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 		video_caps |= ACPI_VIDEO_ROM_AVAILABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 	/* Is this device able to configure which video head to be POSTed ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 	if (acpi_has_method(handle, "_VPO") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 	    acpi_has_method(handle, "_GPD") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 	    acpi_has_method(handle, "_SPD"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 		video_caps |= ACPI_VIDEO_DEVICE_POSTING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 	/* Only check for backlight functionality if one of the above hit. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 	if (video_caps)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 		acpi_walk_namespace(ACPI_TYPE_DEVICE, handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 				    ACPI_UINT32_MAX, acpi_backlight_cap_match, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 				    &video_caps, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 	return video_caps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) EXPORT_SYMBOL(acpi_is_video_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) const char *acpi_device_hid(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 	struct acpi_hardware_id *hid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 	if (list_empty(&device->pnp.ids))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 		return dummy_hid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 	hid = list_first_entry(&device->pnp.ids, struct acpi_hardware_id, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 	return hid->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) EXPORT_SYMBOL(acpi_device_hid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) static void acpi_add_id(struct acpi_device_pnp *pnp, const char *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 	struct acpi_hardware_id *id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 	id = kmalloc(sizeof(*id), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 	if (!id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 	id->id = kstrdup_const(dev_id, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 	if (!id->id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 		kfree(id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 	list_add_tail(&id->list, &pnp->ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 	pnp->type.hardware_id = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232)  * Old IBM workstations have a DSDT bug wherein the SMBus object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233)  * lacks the SMBUS01 HID and the methods do not have the necessary "_"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234)  * prefix.  Work around this.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) static bool acpi_ibm_smbus_match(acpi_handle handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 	char node_name[ACPI_PATH_SEGMENT_LENGTH];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 	struct acpi_buffer path = { sizeof(node_name), node_name };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 	if (!dmi_name_in_vendors("IBM"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 	/* Look for SMBS object */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 	if (ACPI_FAILURE(acpi_get_name(handle, ACPI_SINGLE_NAME, &path)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 	    strcmp("SMBS", path.pointer))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 	/* Does it have the necessary (but misnamed) methods? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 	if (acpi_has_method(handle, "SBI") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 	    acpi_has_method(handle, "SBR") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 	    acpi_has_method(handle, "SBW"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) static bool acpi_object_is_system_bus(acpi_handle handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 	acpi_handle tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 	if (ACPI_SUCCESS(acpi_get_handle(NULL, "\\_SB", &tmp)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 	    tmp == handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 	if (ACPI_SUCCESS(acpi_get_handle(NULL, "\\_TZ", &tmp)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 	    tmp == handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) static void acpi_set_pnp_ids(acpi_handle handle, struct acpi_device_pnp *pnp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 				int device_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 	struct acpi_device_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 	struct acpi_pnp_device_id_list *cid_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 	switch (device_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 	case ACPI_BUS_TYPE_DEVICE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 		if (handle == ACPI_ROOT_OBJECT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 			acpi_add_id(pnp, ACPI_SYSTEM_HID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 		status = acpi_get_object_info(handle, &info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 		if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 			pr_err(PREFIX "%s: Error reading device info\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 					__func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 		if (info->valid & ACPI_VALID_HID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 			acpi_add_id(pnp, info->hardware_id.string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 			pnp->type.platform_id = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 		if (info->valid & ACPI_VALID_CID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 			cid_list = &info->compatible_id_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 			for (i = 0; i < cid_list->count; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 				acpi_add_id(pnp, cid_list->ids[i].string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 		if (info->valid & ACPI_VALID_ADR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 			pnp->bus_address = info->address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 			pnp->type.bus_address = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 		if (info->valid & ACPI_VALID_UID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 			pnp->unique_id = kstrdup(info->unique_id.string,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 							GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 		if (info->valid & ACPI_VALID_CLS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 			acpi_add_id(pnp, info->class_code.string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 		kfree(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 		 * Some devices don't reliably have _HIDs & _CIDs, so add
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 		 * synthetic HIDs to make sure drivers can find them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 		if (acpi_is_video_device(handle))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 			acpi_add_id(pnp, ACPI_VIDEO_HID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 		else if (acpi_bay_match(handle))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 			acpi_add_id(pnp, ACPI_BAY_HID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 		else if (acpi_dock_match(handle))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 			acpi_add_id(pnp, ACPI_DOCK_HID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 		else if (acpi_ibm_smbus_match(handle))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 			acpi_add_id(pnp, ACPI_SMBUS_IBM_HID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 		else if (list_empty(&pnp->ids) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 			 acpi_object_is_system_bus(handle)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 			/* \_SB, \_TZ, LNXSYBUS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 			acpi_add_id(pnp, ACPI_BUS_HID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 			strcpy(pnp->device_name, ACPI_BUS_DEVICE_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 			strcpy(pnp->device_class, ACPI_BUS_CLASS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 	case ACPI_BUS_TYPE_POWER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 		acpi_add_id(pnp, ACPI_POWER_HID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 	case ACPI_BUS_TYPE_PROCESSOR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 		acpi_add_id(pnp, ACPI_PROCESSOR_OBJECT_HID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 	case ACPI_BUS_TYPE_THERMAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 		acpi_add_id(pnp, ACPI_THERMAL_HID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 	case ACPI_BUS_TYPE_POWER_BUTTON:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 		acpi_add_id(pnp, ACPI_BUTTON_HID_POWERF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 	case ACPI_BUS_TYPE_SLEEP_BUTTON:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 		acpi_add_id(pnp, ACPI_BUTTON_HID_SLEEPF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 	case ACPI_BUS_TYPE_ECDT_EC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 		acpi_add_id(pnp, ACPI_ECDT_HID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) void acpi_free_pnp_ids(struct acpi_device_pnp *pnp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 	struct acpi_hardware_id *id, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 	list_for_each_entry_safe(id, tmp, &pnp->ids, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 		kfree_const(id->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 		kfree(id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 	kfree(pnp->unique_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369)  * acpi_dma_supported - Check DMA support for the specified device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370)  * @adev: The pointer to acpi device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372)  * Return false if DMA is not supported. Otherwise, return true
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) bool acpi_dma_supported(struct acpi_device *adev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 	if (!adev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) 	if (adev->flags.cca_seen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 	* Per ACPI 6.0 sec 6.2.17, assume devices can do cache-coherent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 	* DMA on "Intel platforms".  Presumably that includes all x86 and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 	* ia64, and other arches will set CONFIG_ACPI_CCA_REQUIRED=y.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 	if (!IS_ENABLED(CONFIG_ACPI_CCA_REQUIRED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394)  * acpi_get_dma_attr - Check the supported DMA attr for the specified device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395)  * @adev: The pointer to acpi device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397)  * Return enum dev_dma_attr.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) 	if (!acpi_dma_supported(adev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 		return DEV_DMA_NOT_SUPPORTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 	if (adev->flags.coherent_dma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 		return DEV_DMA_COHERENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 		return DEV_DMA_NON_COHERENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411)  * acpi_dma_get_range() - Get device DMA parameters.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413)  * @dev: device to configure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414)  * @dma_addr: pointer device DMA address result
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415)  * @offset: pointer to the DMA offset result
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416)  * @size: pointer to DMA range size result
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418)  * Evaluate DMA regions and return respectively DMA region start, offset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419)  * and size in dma_addr, offset and size on parsing success; it does not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420)  * update the passed in values on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422)  * Return 0 on success, < 0 on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) int acpi_dma_get_range(struct device *dev, u64 *dma_addr, u64 *offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) 		       u64 *size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) 	struct acpi_device *adev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) 	LIST_HEAD(list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) 	struct resource_entry *rentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) 	struct device *dma_dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) 	u64 len, dma_start = U64_MAX, dma_end = 0, dma_offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 	 * Walk the device tree chasing an ACPI companion with a _DMA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) 	 * object while we go. Stop if we find a device with an ACPI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 	 * companion containing a _DMA method.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 		adev = ACPI_COMPANION(dma_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) 		if (adev && acpi_has_method(adev->handle, METHOD_NAME__DMA))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) 		dma_dev = dma_dev->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 	} while (dma_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 	if (!dma_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) 	if (!acpi_has_method(adev->handle, METHOD_NAME__CRS)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) 		acpi_handle_warn(adev->handle, "_DMA is valid only if _CRS is present\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) 	ret = acpi_dev_get_dma_resources(adev, &list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) 	if (ret > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) 		list_for_each_entry(rentry, &list, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) 			if (dma_offset && rentry->offset != dma_offset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) 				ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) 				dev_warn(dma_dev, "Can't handle multiple windows with different offsets\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) 			dma_offset = rentry->offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) 			/* Take lower and upper limits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) 			if (rentry->res->start < dma_start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) 				dma_start = rentry->res->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) 			if (rentry->res->end > dma_end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) 				dma_end = rentry->res->end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) 		if (dma_start >= dma_end) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 			ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 			dev_dbg(dma_dev, "Invalid DMA regions configuration\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) 		*dma_addr = dma_start - dma_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 		len = dma_end - dma_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 		*size = max(len, len + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) 		*offset = dma_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483)  out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 	acpi_dev_free_resource_list(&list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) 	return ret >= 0 ? 0 : ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490)  * acpi_dma_configure_id - Set-up DMA configuration for the device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491)  * @dev: The pointer to the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492)  * @attr: device dma attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493)  * @input_id: input device id const value pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) int acpi_dma_configure_id(struct device *dev, enum dev_dma_attr attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) 			  const u32 *input_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) 	const struct iommu_ops *iommu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) 	u64 dma_addr = 0, size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) 	if (attr == DEV_DMA_NOT_SUPPORTED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) 		set_dma_ops(dev, &dma_dummy_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) 	iort_dma_setup(dev, &dma_addr, &size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) 	iommu = iort_iommu_configure_id(dev, input_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) 	if (PTR_ERR(iommu) == -EPROBE_DEFER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) 		return -EPROBE_DEFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) 	arch_setup_dma_ops(dev, dma_addr, size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) 				iommu, attr == DEV_DMA_COHERENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) EXPORT_SYMBOL_GPL(acpi_dma_configure_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) static void acpi_init_coherency(struct acpi_device *adev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) 	unsigned long long cca = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) 	struct acpi_device *parent = adev->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) 	if (parent && parent->flags.cca_seen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) 		 * From ACPI spec, OSPM will ignore _CCA if an ancestor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) 		 * already saw one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) 		adev->flags.cca_seen = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) 		cca = parent->flags.coherent_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) 		status = acpi_evaluate_integer(adev->handle, "_CCA",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) 					       NULL, &cca);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) 		if (ACPI_SUCCESS(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) 			adev->flags.cca_seen = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) 		else if (!IS_ENABLED(CONFIG_ACPI_CCA_REQUIRED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) 			 * If architecture does not specify that _CCA is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) 			 * required for DMA-able devices (e.g. x86),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) 			 * we default to _CCA=1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) 			cca = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) 			acpi_handle_debug(adev->handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) 					  "ACPI device is missing _CCA.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) 	adev->flags.coherent_dma = cca;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) static int acpi_check_serial_bus_slave(struct acpi_resource *ares, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) 	bool *is_serial_bus_slave_p = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) 	if (ares->type != ACPI_RESOURCE_TYPE_SERIAL_BUS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) 	*is_serial_bus_slave_p = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) 	 /* no need to do more checking */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) 	return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) static bool acpi_is_indirect_io_slave(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) 	struct acpi_device *parent = device->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) 	static const struct acpi_device_id indirect_io_hosts[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) 		{"HISI0191", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) 		{}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) 	return parent && !acpi_match_device_ids(parent, indirect_io_hosts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) static bool acpi_device_enumeration_by_parent(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) 	struct list_head resource_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) 	bool is_serial_bus_slave = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) 	static const struct acpi_device_id ignore_serial_bus_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) 	 * These devices have multiple I2cSerialBus resources and an i2c-client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) 	 * must be instantiated for each, each with its own i2c_device_id.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) 	 * Normally we only instantiate an i2c-client for the first resource,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) 	 * using the ACPI HID as id. These special cases are handled by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) 	 * drivers/platform/x86/i2c-multi-instantiate.c driver, which knows
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) 	 * which i2c_device_id to use for each resource.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) 		{"BSG1160", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) 		{"BSG2150", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) 		{"INT33FE", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) 		{"INT3515", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) 	 * HIDs of device with an UartSerialBusV2 resource for which userspace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) 	 * expects a regular tty cdev to be created (instead of the in kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) 	 * serdev) and which have a kernel driver which expects a platform_dev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) 	 * such as the rfkill-gpio driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) 		{"BCM4752", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) 		{"LNV4752", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) 		{}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) 	if (acpi_is_indirect_io_slave(device))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) 	/* Macs use device properties in lieu of _CRS resources */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) 	if (x86_apple_machine &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) 	    (fwnode_property_present(&device->fwnode, "spiSclkPeriod") ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) 	     fwnode_property_present(&device->fwnode, "i2cAddress") ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) 	     fwnode_property_present(&device->fwnode, "baud")))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) 	if (!acpi_match_device_ids(device, ignore_serial_bus_ids))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) 	INIT_LIST_HEAD(&resource_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) 	acpi_dev_get_resources(device, &resource_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) 			       acpi_check_serial_bus_slave,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) 			       &is_serial_bus_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) 	acpi_dev_free_resource_list(&resource_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) 	return is_serial_bus_slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) void acpi_init_device_object(struct acpi_device *device, acpi_handle handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) 			     int type, unsigned long long sta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) 	INIT_LIST_HEAD(&device->pnp.ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) 	device->device_type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) 	device->handle = handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) 	device->parent = acpi_bus_get_parent(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) 	fwnode_init(&device->fwnode, &acpi_device_fwnode_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) 	acpi_set_device_status(device, sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) 	acpi_device_get_busid(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) 	acpi_set_pnp_ids(handle, &device->pnp, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) 	acpi_init_properties(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) 	acpi_bus_get_flags(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) 	device->flags.match_driver = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) 	device->flags.initialized = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) 	device->flags.enumeration_by_parent =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) 		acpi_device_enumeration_by_parent(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) 	acpi_device_clear_enumerated(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) 	device_initialize(&device->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) 	dev_set_uevent_suppress(&device->dev, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) 	acpi_init_coherency(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) 	/* Assume there are unmet deps until acpi_device_dep_initialize() runs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) 	device->dep_unmet = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) void acpi_device_add_finalize(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) 	dev_set_uevent_suppress(&device->dev, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) 	kobject_uevent(&device->dev.kobj, KOBJ_ADD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) static int acpi_add_single_object(struct acpi_device **child,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) 				  acpi_handle handle, int type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) 				  unsigned long long sta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) 	struct acpi_device *device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) 	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) 	device = kzalloc(sizeof(struct acpi_device), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) 	if (!device) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) 		printk(KERN_ERR PREFIX "Memory allocation error\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) 	acpi_init_device_object(device, handle, type, sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) 	 * For ACPI_BUS_TYPE_DEVICE getting the status is delayed till here so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) 	 * that we can call acpi_bus_get_status() and use its quirk handling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) 	 * Note this must be done before the get power-/wakeup_dev-flags calls.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) 	if (type == ACPI_BUS_TYPE_DEVICE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) 		if (acpi_bus_get_status(device) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) 			acpi_set_device_status(device, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) 	acpi_bus_get_power_flags(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) 	acpi_bus_get_wakeup_device_flags(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) 	result = acpi_device_add(device, acpi_device_release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) 	if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) 		acpi_device_release(&device->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) 		return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) 	acpi_power_add_remove_device(device, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) 	acpi_device_add_finalize(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) 	acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) 	ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Added %s [%s] parent %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) 		dev_name(&device->dev), (char *) buffer.pointer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) 		device->parent ? dev_name(&device->parent->dev) : "(null)"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) 	kfree(buffer.pointer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) 	*child = device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) static acpi_status acpi_get_resource_memory(struct acpi_resource *ares,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) 					    void *context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) 	struct resource *res = context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) 	if (acpi_dev_resource_memory(ares, res))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) 		return AE_CTRL_TERMINATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) 	return AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) static bool acpi_device_should_be_hidden(acpi_handle handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) 	struct resource res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) 	/* Check if it should ignore the UART device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) 	if (!(spcr_uart_addr && acpi_has_method(handle, METHOD_NAME__CRS)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) 	 * The UART device described in SPCR table is assumed to have only one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) 	 * memory resource present. So we only look for the first one here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) 	status = acpi_walk_resources(handle, METHOD_NAME__CRS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) 				     acpi_get_resource_memory, &res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) 	if (ACPI_FAILURE(status) || res.start != spcr_uart_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) 	acpi_handle_info(handle, "The UART device @%pa in SPCR table will be hidden\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) 			 &res.start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) static int acpi_bus_type_and_status(acpi_handle handle, int *type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) 				    unsigned long long *sta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) 	acpi_object_type acpi_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) 	status = acpi_get_type(handle, &acpi_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) 	if (ACPI_FAILURE(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) 	switch (acpi_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) 	case ACPI_TYPE_ANY:		/* for ACPI_ROOT_OBJECT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) 	case ACPI_TYPE_DEVICE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) 		if (acpi_device_should_be_hidden(handle))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) 			return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) 		*type = ACPI_BUS_TYPE_DEVICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) 		 * acpi_add_single_object updates this once we've an acpi_device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) 		 * so that acpi_bus_get_status' quirk handling can be used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) 		*sta = ACPI_STA_DEFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) 	case ACPI_TYPE_PROCESSOR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) 		*type = ACPI_BUS_TYPE_PROCESSOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) 		status = acpi_bus_get_status_handle(handle, sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) 		if (ACPI_FAILURE(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) 			return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) 	case ACPI_TYPE_THERMAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) 		*type = ACPI_BUS_TYPE_THERMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) 		*sta = ACPI_STA_DEFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) 	case ACPI_TYPE_POWER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) 		*type = ACPI_BUS_TYPE_POWER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) 		*sta = ACPI_STA_DEFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) bool acpi_device_is_present(const struct acpi_device *adev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) 	return adev->status.present || adev->status.functional;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) static bool acpi_scan_handler_matching(struct acpi_scan_handler *handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) 				       const char *idstr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) 				       const struct acpi_device_id **matchid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) 	const struct acpi_device_id *devid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) 	if (handler->match)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) 		return handler->match(idstr, matchid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) 	for (devid = handler->ids; devid->id[0]; devid++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) 		if (!strcmp((char *)devid->id, idstr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) 			if (matchid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) 				*matchid = devid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) 			return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) static struct acpi_scan_handler *acpi_scan_match_handler(const char *idstr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) 					const struct acpi_device_id **matchid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) 	struct acpi_scan_handler *handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) 	list_for_each_entry(handler, &acpi_scan_handlers_list, list_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) 		if (acpi_scan_handler_matching(handler, idstr, matchid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) 			return handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) void acpi_scan_hotplug_enabled(struct acpi_hotplug_profile *hotplug, bool val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) 	if (!!hotplug->enabled == !!val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) 	mutex_lock(&acpi_scan_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) 	hotplug->enabled = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) 	mutex_unlock(&acpi_scan_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) static void acpi_scan_init_hotplug(struct acpi_device *adev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) 	struct acpi_hardware_id *hwid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) 	if (acpi_dock_match(adev->handle) || is_ejectable_bay(adev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) 		acpi_dock_add(adev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) 	list_for_each_entry(hwid, &adev->pnp.ids, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) 		struct acpi_scan_handler *handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) 		handler = acpi_scan_match_handler(hwid->id, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) 		if (handler) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) 			adev->flags.hotplug_notify = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) static void acpi_device_dep_initialize(struct acpi_device *adev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) 	struct acpi_dep_data *dep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) 	struct acpi_handle_list dep_devices;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) 	adev->dep_unmet = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) 	if (!acpi_has_method(adev->handle, "_DEP"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) 	status = acpi_evaluate_reference(adev->handle, "_DEP", NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) 					&dep_devices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) 	if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) 		dev_dbg(&adev->dev, "Failed to evaluate _DEP.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) 	for (i = 0; i < dep_devices.count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) 		struct acpi_device_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) 		int skip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) 		status = acpi_get_object_info(dep_devices.handles[i], &info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) 		if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) 			dev_dbg(&adev->dev, "Error reading _DEP device info\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) 		 * Skip the dependency of Windows System Power
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) 		 * Management Controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) 		skip = info->valid & ACPI_VALID_HID &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) 			!strcmp(info->hardware_id.string, "INT3396");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) 		kfree(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) 		if (skip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) 		dep = kzalloc(sizeof(struct acpi_dep_data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) 		if (!dep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) 		dep->master = dep_devices.handles[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) 		dep->slave  = adev->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) 		adev->dep_unmet++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) 		mutex_lock(&acpi_dep_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) 		list_add_tail(&dep->node , &acpi_dep_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) 		mutex_unlock(&acpi_dep_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) static acpi_status acpi_bus_check_add(acpi_handle handle, u32 lvl_not_used,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) 				      void *not_used, void **return_value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) 	struct acpi_device *device = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) 	int type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) 	unsigned long long sta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) 	acpi_bus_get_device(handle, &device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) 	if (device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) 	result = acpi_bus_type_and_status(handle, &type, &sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) 	if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) 		return AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) 	if (type == ACPI_BUS_TYPE_POWER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) 		acpi_add_power_resource(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) 		return AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) 	acpi_add_single_object(&device, handle, type, sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) 	if (!device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) 		return AE_CTRL_DEPTH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) 	acpi_scan_init_hotplug(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) 	acpi_device_dep_initialize(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931)  out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) 	if (!*return_value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) 		*return_value = device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) 	return AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) static void acpi_default_enumeration(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) 	 * Do not enumerate devices with enumeration_by_parent flag set as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) 	 * they will be enumerated by their respective parents.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) 	if (!device->flags.enumeration_by_parent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) 		acpi_create_platform_device(device, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) 		acpi_device_set_enumerated(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) 		blocking_notifier_call_chain(&acpi_reconfig_chain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) 					     ACPI_RECONFIG_DEVICE_ADD, device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) static const struct acpi_device_id generic_device_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) 	{ACPI_DT_NAMESPACE_HID, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) 	{"", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) static int acpi_generic_device_attach(struct acpi_device *adev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) 				      const struct acpi_device_id *not_used)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) 	 * Since ACPI_DT_NAMESPACE_HID is the only ID handled here, the test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) 	 * below can be unconditional.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) 	if (adev->data.of_compatible)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) 		acpi_default_enumeration(adev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) static struct acpi_scan_handler generic_device_handler = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) 	.ids = generic_device_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) 	.attach = acpi_generic_device_attach,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) static int acpi_scan_attach_handler(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) 	struct acpi_hardware_id *hwid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) 	list_for_each_entry(hwid, &device->pnp.ids, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) 		const struct acpi_device_id *devid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) 		struct acpi_scan_handler *handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) 		handler = acpi_scan_match_handler(hwid->id, &devid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) 		if (handler) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) 			if (!handler->attach) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) 				device->pnp.type.platform_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) 			device->handler = handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) 			ret = handler->attach(device, devid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) 			if (ret > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) 			device->handler = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) 			if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) static void acpi_bus_attach(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) 	struct acpi_device *child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) 	acpi_handle ejd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) 	if (ACPI_SUCCESS(acpi_bus_get_ejd(device->handle, &ejd)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) 		register_dock_dependent_device(device, ejd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) 	acpi_bus_get_status(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) 	/* Skip devices that are not present. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) 	if (!acpi_device_is_present(device)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) 		device->flags.initialized = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) 		acpi_device_clear_enumerated(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) 		device->flags.power_manageable = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) 	if (device->handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) 		goto ok;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) 	if (!device->flags.initialized) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) 		device->flags.power_manageable =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) 			device->power.states[ACPI_STATE_D0].flags.valid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) 		if (acpi_bus_init_power(device))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) 			device->flags.power_manageable = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) 		device->flags.initialized = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) 	} else if (device->flags.visited) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) 		goto ok;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) 	ret = acpi_scan_attach_handler(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) 	device->flags.match_driver = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) 	if (ret > 0 && !device->flags.enumeration_by_parent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) 		acpi_device_set_enumerated(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) 		goto ok;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) 	ret = device_attach(&device->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) 	if (device->pnp.type.platform_id || device->flags.enumeration_by_parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) 		acpi_default_enumeration(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) 		acpi_device_set_enumerated(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055)  ok:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) 	list_for_each_entry(child, &device->children, node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) 		acpi_bus_attach(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) 	if (device->handler && device->handler->hotplug.notify_online)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) 		device->handler->hotplug.notify_online(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) void acpi_walk_dep_device_list(acpi_handle handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) 	struct acpi_dep_data *dep, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) 	struct acpi_device *adev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) 	mutex_lock(&acpi_dep_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) 	list_for_each_entry_safe(dep, tmp, &acpi_dep_list, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) 		if (dep->master == handle) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) 			acpi_bus_get_device(dep->slave, &adev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) 			if (!adev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) 			adev->dep_unmet--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) 			if (!adev->dep_unmet)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) 				acpi_bus_attach(adev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) 			list_del(&dep->node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) 			kfree(dep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) 	mutex_unlock(&acpi_dep_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) EXPORT_SYMBOL_GPL(acpi_walk_dep_device_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087)  * acpi_bus_scan - Add ACPI device node objects in a given namespace scope.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088)  * @handle: Root of the namespace scope to scan.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090)  * Scan a given ACPI tree (probably recently hot-plugged) and create and add
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091)  * found devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093)  * If no devices were found, -ENODEV is returned, but it does not mean that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094)  * there has been a real error.  There just have been no suitable ACPI objects
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095)  * in the table trunk from which the kernel could create a device and add an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096)  * appropriate driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098)  * Must be called under acpi_scan_lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) int acpi_bus_scan(acpi_handle handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) 	void *device = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) 	if (ACPI_SUCCESS(acpi_bus_check_add(handle, 0, NULL, &device)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) 		acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) 				    acpi_bus_check_add, NULL, NULL, &device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) 	if (device) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) 		acpi_bus_attach(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) 	return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) EXPORT_SYMBOL(acpi_bus_scan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117)  * acpi_bus_trim - Detach scan handlers and drivers from ACPI device objects.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118)  * @adev: Root of the ACPI namespace scope to walk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120)  * Must be called under acpi_scan_lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) void acpi_bus_trim(struct acpi_device *adev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) 	struct acpi_scan_handler *handler = adev->handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) 	struct acpi_device *child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) 	list_for_each_entry_reverse(child, &adev->children, node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) 		acpi_bus_trim(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) 	adev->flags.match_driver = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) 	if (handler) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) 		if (handler->detach)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) 			handler->detach(adev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) 		adev->handler = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) 		device_release_driver(&adev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) 	 * Most likely, the device is going away, so put it into D3cold before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) 	 * that.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) 	acpi_device_set_power(adev, ACPI_STATE_D3_COLD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) 	adev->flags.initialized = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) 	acpi_device_clear_enumerated(adev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) EXPORT_SYMBOL_GPL(acpi_bus_trim);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) int acpi_bus_register_early_device(int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) 	struct acpi_device *device = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) 	result = acpi_add_single_object(&device, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) 					type, ACPI_STA_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) 	if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) 		return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) 	device->flags.match_driver = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) 	return device_attach(&device->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) EXPORT_SYMBOL_GPL(acpi_bus_register_early_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) static int acpi_bus_scan_fixed(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) 	int result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) 	 * Enumerate all fixed-feature devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) 	if (!(acpi_gbl_FADT.flags & ACPI_FADT_POWER_BUTTON)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) 		struct acpi_device *device = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) 		result = acpi_add_single_object(&device, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) 						ACPI_BUS_TYPE_POWER_BUTTON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) 						ACPI_STA_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) 		if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) 			return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) 		device->flags.match_driver = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) 		result = device_attach(&device->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) 		if (result < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) 			return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) 		device_init_wakeup(&device->dev, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) 	if (!(acpi_gbl_FADT.flags & ACPI_FADT_SLEEP_BUTTON)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) 		struct acpi_device *device = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) 		result = acpi_add_single_object(&device, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) 						ACPI_BUS_TYPE_SLEEP_BUTTON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) 						ACPI_STA_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) 		if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) 			return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) 		device->flags.match_driver = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) 		result = device_attach(&device->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) 	return result < 0 ? result : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) static void __init acpi_get_spcr_uart_addr(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) 	struct acpi_table_spcr *spcr_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) 	status = acpi_get_table(ACPI_SIG_SPCR, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) 				(struct acpi_table_header **)&spcr_ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) 	if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) 		pr_warn(PREFIX "STAO table present, but SPCR is missing\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) 	spcr_uart_addr = spcr_ptr->serial_port.address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) 	acpi_put_table((struct acpi_table_header *)spcr_ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) static bool acpi_scan_initialized;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) int __init acpi_scan_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) 	struct acpi_table_stao *stao_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) 	acpi_pci_root_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) 	acpi_pci_link_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) 	acpi_processor_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) 	acpi_platform_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) 	acpi_lpss_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) 	acpi_apd_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) 	acpi_cmos_rtc_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) 	acpi_container_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) 	acpi_memory_hotplug_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) 	acpi_watchdog_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) 	acpi_pnp_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) 	acpi_int340x_thermal_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) 	acpi_amba_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) 	acpi_init_lpit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) 	acpi_scan_add_handler(&generic_device_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) 	 * If there is STAO table, check whether it needs to ignore the UART
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) 	 * device in SPCR table.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) 	status = acpi_get_table(ACPI_SIG_STAO, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) 				(struct acpi_table_header **)&stao_ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) 	if (ACPI_SUCCESS(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252) 		if (stao_ptr->header.length > sizeof(struct acpi_table_stao))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) 			pr_info(PREFIX "STAO Name List not yet supported.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) 		if (stao_ptr->ignore_uart)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) 			acpi_get_spcr_uart_addr();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) 		acpi_put_table((struct acpi_table_header *)stao_ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) 	acpi_gpe_apply_masked_gpes();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) 	acpi_update_all_gpes();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) 	 * Although we call __add_memory() that is documented to require the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) 	 * device_hotplug_lock, it is not necessary here because this is an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) 	 * early code when userspace or any other code path cannot trigger
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) 	 * hotplug/hotunplug operations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) 	mutex_lock(&acpi_scan_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) 	 * Enumerate devices in the ACPI namespace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) 	result = acpi_bus_scan(ACPI_ROOT_OBJECT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) 	if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) 	result = acpi_bus_get_device(ACPI_ROOT_OBJECT, &acpi_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) 	if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) 	/* Fixed feature devices do not exist on HW-reduced platform */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) 	if (!acpi_gbl_reduced_hardware) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) 		result = acpi_bus_scan_fixed();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) 		if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) 			acpi_detach_data(acpi_root->handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) 					 acpi_scan_drop_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) 			acpi_device_del(acpi_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) 			put_device(&acpi_root->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) 	acpi_scan_initialized = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296)  out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) 	mutex_unlock(&acpi_scan_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) static struct acpi_probe_entry *ape;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) static int acpi_probe_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) static DEFINE_MUTEX(acpi_probe_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) static int __init acpi_match_madt(union acpi_subtable_headers *header,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) 				  const unsigned long end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) 	if (!ape->subtable_valid || ape->subtable_valid(&header->common, ape))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) 		if (!ape->probe_subtbl(header, end))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) 			acpi_probe_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) int __init __acpi_probe_device_table(struct acpi_probe_entry *ap_head, int nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) 	int count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) 	if (acpi_disabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) 	mutex_lock(&acpi_probe_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) 	for (ape = ap_head; nr; ape++, nr--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) 		if (ACPI_COMPARE_NAMESEG(ACPI_SIG_MADT, ape->id)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) 			acpi_probe_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) 			acpi_table_parse_madt(ape->type, acpi_match_madt, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) 			count += acpi_probe_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) 			int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) 			res = acpi_table_parse(ape->id, ape->probe_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) 			if (!res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) 				count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) 	mutex_unlock(&acpi_probe_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) struct acpi_table_events_work {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) 	struct work_struct work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) 	void *table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) 	u32 event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) static void acpi_table_events_fn(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) 	struct acpi_table_events_work *tew;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) 	tew = container_of(work, struct acpi_table_events_work, work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) 	if (tew->event == ACPI_TABLE_EVENT_LOAD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) 		acpi_scan_lock_acquire();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) 		acpi_bus_scan(ACPI_ROOT_OBJECT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) 		acpi_scan_lock_release();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) 	kfree(tew);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) void acpi_scan_table_handler(u32 event, void *table, void *context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) 	struct acpi_table_events_work *tew;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) 	if (!acpi_scan_initialized)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) 	if (event != ACPI_TABLE_EVENT_LOAD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) 	tew = kmalloc(sizeof(*tew), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) 	if (!tew)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) 	INIT_WORK(&tew->work, acpi_table_events_fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) 	tew->table = table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) 	tew->event = event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) 	schedule_work(&tew->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) int acpi_reconfig_notifier_register(struct notifier_block *nb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) 	return blocking_notifier_chain_register(&acpi_reconfig_chain, nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) EXPORT_SYMBOL(acpi_reconfig_notifier_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) int acpi_reconfig_notifier_unregister(struct notifier_block *nb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) 	return blocking_notifier_chain_unregister(&acpi_reconfig_chain, nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) EXPORT_SYMBOL(acpi_reconfig_notifier_unregister);