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)  * Link physical devices with ACPI devices support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (c) 2005 David Shaohua Li <shaohua.li@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (c) 2005 Intel Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/acpi_iort.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/rwsem.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/dma-mapping.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/platform_device.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 ACPI_GLUE_DEBUG	0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #if ACPI_GLUE_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define DBG(fmt, ...)						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	printk(KERN_DEBUG PREFIX fmt, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define DBG(fmt, ...)						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) do {								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	if (0)							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 		printk(KERN_DEBUG PREFIX fmt, ##__VA_ARGS__);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) static LIST_HEAD(bus_type_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) static DECLARE_RWSEM(bus_type_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #define PHYSICAL_NODE_STRING "physical_node"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #define PHYSICAL_NODE_NAME_SIZE (sizeof(PHYSICAL_NODE_STRING) + 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) int register_acpi_bus_type(struct acpi_bus_type *type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	if (acpi_disabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	if (type && type->match && type->find_companion) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		down_write(&bus_type_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		list_add_tail(&type->list, &bus_type_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		up_write(&bus_type_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		printk(KERN_INFO PREFIX "bus type %s registered\n", type->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) EXPORT_SYMBOL_GPL(register_acpi_bus_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) int unregister_acpi_bus_type(struct acpi_bus_type *type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	if (acpi_disabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	if (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		down_write(&bus_type_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		list_del_init(&type->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		up_write(&bus_type_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		printk(KERN_INFO PREFIX "bus type %s unregistered\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		       type->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) EXPORT_SYMBOL_GPL(unregister_acpi_bus_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) static struct acpi_bus_type *acpi_get_bus_type(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	struct acpi_bus_type *tmp, *ret = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	down_read(&bus_type_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	list_for_each_entry(tmp, &bus_type_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		if (tmp->match(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 			ret = tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	up_read(&bus_type_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) #define FIND_CHILD_MIN_SCORE	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) #define FIND_CHILD_MAX_SCORE	2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) static int find_child_checks(struct acpi_device *adev, bool check_children)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	bool sta_present = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	unsigned long long sta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	status = acpi_evaluate_integer(adev->handle, "_STA", NULL, &sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	if (status == AE_NOT_FOUND)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		sta_present = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	else if (ACPI_FAILURE(status) || !(sta & ACPI_STA_DEVICE_ENABLED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	if (check_children && list_empty(&adev->children))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	 * If the device has a _HID returning a valid ACPI/PNP device ID, it is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	 * better to make it look less attractive here, so that the other device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	 * with the same _ADR value (that may not have a valid device ID) can be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	 * matched going forward.  [This means a second spec violation in a row,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	 * so whatever we do here is best effort anyway.]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	return sta_present && !adev->pnp.type.platform_id ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 			FIND_CHILD_MAX_SCORE : FIND_CHILD_MIN_SCORE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) struct acpi_device *acpi_find_child_device(struct acpi_device *parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 					   u64 address, bool check_children)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	struct acpi_device *adev, *ret = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	int ret_score = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	if (!parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	list_for_each_entry(adev, &parent->children, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		unsigned long long addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		int score;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		status = acpi_evaluate_integer(adev->handle, METHOD_NAME__ADR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 					       NULL, &addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		if (ACPI_FAILURE(status) || addr != address)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 			/* This is the first matching object.  Save it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 			ret = adev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		 * There is more than one matching device object with the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		 * _ADR value.  That really is unexpected, so we are kind of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		 * beyond the scope of the spec here.  We have to choose which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		 * one to return, though.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		 * First, check if the previously found object is good enough
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		 * and return it if so.  Second, do the same for the object that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		 * we've just found.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		if (!ret_score) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 			ret_score = find_child_checks(ret, check_children);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 			if (ret_score == FIND_CHILD_MAX_SCORE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 				return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		score = find_child_checks(adev, check_children);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		if (score == FIND_CHILD_MAX_SCORE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 			return adev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		} else if (score > ret_score) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 			ret = adev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			ret_score = score;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) EXPORT_SYMBOL_GPL(acpi_find_child_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) static void acpi_physnode_link_name(char *buf, unsigned int node_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	if (node_id > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		snprintf(buf, PHYSICAL_NODE_NAME_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 			 PHYSICAL_NODE_STRING "%u", node_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		strcpy(buf, PHYSICAL_NODE_STRING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) int acpi_bind_one(struct device *dev, struct acpi_device *acpi_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	struct acpi_device_physical_node *physical_node, *pn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	char physical_node_name[PHYSICAL_NODE_NAME_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	struct list_head *physnode_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	unsigned int node_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	int retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	if (has_acpi_companion(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		if (acpi_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 			dev_warn(dev, "ACPI companion already set\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 			acpi_dev = ACPI_COMPANION(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	if (!acpi_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	get_device(&acpi_dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	get_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	physical_node = kzalloc(sizeof(*physical_node), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	if (!physical_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		retval = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	mutex_lock(&acpi_dev->physical_node_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	 * Keep the list sorted by node_id so that the IDs of removed nodes can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	 * be recycled easily.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	physnode_list = &acpi_dev->physical_node_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	node_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	list_for_each_entry(pn, &acpi_dev->physical_node_list, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		/* Sanity check. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		if (pn->dev == dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 			mutex_unlock(&acpi_dev->physical_node_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 			dev_warn(dev, "Already associated with ACPI node\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 			kfree(physical_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 			if (ACPI_COMPANION(dev) != acpi_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 				goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 			put_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 			put_device(&acpi_dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		if (pn->node_id == node_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 			physnode_list = &pn->node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 			node_id++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	physical_node->node_id = node_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	physical_node->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	list_add(&physical_node->node, physnode_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	acpi_dev->physical_node_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	if (!has_acpi_companion(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		ACPI_COMPANION_SET(dev, acpi_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	acpi_physnode_link_name(physical_node_name, node_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	retval = sysfs_create_link(&acpi_dev->dev.kobj, &dev->kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 				   physical_node_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		dev_err(&acpi_dev->dev, "Failed to create link %s (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 			physical_node_name, retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	retval = sysfs_create_link(&dev->kobj, &acpi_dev->dev.kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 				   "firmware_node");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		dev_err(dev, "Failed to create link firmware_node (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 			retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	mutex_unlock(&acpi_dev->physical_node_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	if (acpi_dev->wakeup.flags.valid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		device_set_wakeup_capable(dev, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)  err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	ACPI_COMPANION_SET(dev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	put_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	put_device(&acpi_dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) EXPORT_SYMBOL_GPL(acpi_bind_one);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) int acpi_unbind_one(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	struct acpi_device *acpi_dev = ACPI_COMPANION(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	struct acpi_device_physical_node *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	if (!acpi_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	mutex_lock(&acpi_dev->physical_node_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	list_for_each_entry(entry, &acpi_dev->physical_node_list, node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		if (entry->dev == dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 			char physnode_name[PHYSICAL_NODE_NAME_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 			list_del(&entry->node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 			acpi_dev->physical_node_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 			acpi_physnode_link_name(physnode_name, entry->node_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 			sysfs_remove_link(&acpi_dev->dev.kobj, physnode_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 			sysfs_remove_link(&dev->kobj, "firmware_node");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 			ACPI_COMPANION_SET(dev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 			/* Drop references taken by acpi_bind_one(). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 			put_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 			put_device(&acpi_dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 			kfree(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	mutex_unlock(&acpi_dev->physical_node_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) EXPORT_SYMBOL_GPL(acpi_unbind_one);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) static int acpi_device_notify(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	struct acpi_bus_type *type = acpi_get_bus_type(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	struct acpi_device *adev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	ret = acpi_bind_one(dev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	if (ret && type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		struct acpi_device *adev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		adev = type->find_companion(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		if (!adev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 			DBG("Unable to get handle for %s\n", dev_name(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 			ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		ret = acpi_bind_one(dev, adev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	adev = ACPI_COMPANION(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	if (!adev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	if (dev_is_platform(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		acpi_configure_pmsi_domain(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	if (type && type->setup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		type->setup(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	else if (adev->handler && adev->handler->bind)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 		adev->handler->bind(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)  out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) #if ACPI_GLUE_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		acpi_get_name(ACPI_HANDLE(dev), ACPI_FULL_PATHNAME, &buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		DBG("Device %s -> %s\n", dev_name(dev), (char *)buffer.pointer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		kfree(buffer.pointer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		DBG("Device %s -> No ACPI support\n", dev_name(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) static int acpi_device_notify_remove(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	struct acpi_device *adev = ACPI_COMPANION(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	struct acpi_bus_type *type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	if (!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) 	type = acpi_get_bus_type(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	if (type && type->cleanup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		type->cleanup(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	else if (adev->handler && adev->handler->unbind)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		adev->handler->unbind(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	acpi_unbind_one(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) int acpi_platform_notify(struct device *dev, enum kobject_action action)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	switch (action) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	case KOBJ_ADD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 		acpi_device_notify(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	case KOBJ_REMOVE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		acpi_device_notify_remove(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) }