aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/glue.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi/glue.c')
-rw-r--r--drivers/acpi/glue.c165
1 files changed, 60 insertions, 105 deletions
diff --git a/drivers/acpi/glue.c b/drivers/acpi/glue.c
index a22a295edb69..0c789224d40d 100644
--- a/drivers/acpi/glue.c
+++ b/drivers/acpi/glue.c
@@ -37,7 +37,7 @@ int register_acpi_bus_type(struct acpi_bus_type *type)
37{ 37{
38 if (acpi_disabled) 38 if (acpi_disabled)
39 return -ENODEV; 39 return -ENODEV;
40 if (type && type->match && type->find_device) { 40 if (type && type->match && type->find_companion) {
41 down_write(&bus_type_sem); 41 down_write(&bus_type_sem);
42 list_add_tail(&type->list, &bus_type_list); 42 list_add_tail(&type->list, &bus_type_list);
43 up_write(&bus_type_sem); 43 up_write(&bus_type_sem);
@@ -82,109 +82,74 @@ static struct acpi_bus_type *acpi_get_bus_type(struct device *dev)
82#define FIND_CHILD_MIN_SCORE 1 82#define FIND_CHILD_MIN_SCORE 1
83#define FIND_CHILD_MAX_SCORE 2 83#define FIND_CHILD_MAX_SCORE 2
84 84
85static acpi_status acpi_dev_present(acpi_handle handle, u32 lvl_not_used, 85static int find_child_checks(struct acpi_device *adev, bool check_children)
86 void *not_used, void **ret_p)
87{
88 struct acpi_device *adev = NULL;
89
90 acpi_bus_get_device(handle, &adev);
91 if (adev) {
92 *ret_p = handle;
93 return AE_CTRL_TERMINATE;
94 }
95 return AE_OK;
96}
97
98static int do_find_child_checks(acpi_handle handle, bool is_bridge)
99{ 86{
100 bool sta_present = true; 87 bool sta_present = true;
101 unsigned long long sta; 88 unsigned long long sta;
102 acpi_status status; 89 acpi_status status;
103 90
104 status = acpi_evaluate_integer(handle, "_STA", NULL, &sta); 91 status = acpi_evaluate_integer(adev->handle, "_STA", NULL, &sta);
105 if (status == AE_NOT_FOUND) 92 if (status == AE_NOT_FOUND)
106 sta_present = false; 93 sta_present = false;
107 else if (ACPI_FAILURE(status) || !(sta & ACPI_STA_DEVICE_ENABLED)) 94 else if (ACPI_FAILURE(status) || !(sta & ACPI_STA_DEVICE_ENABLED))
108 return -ENODEV; 95 return -ENODEV;
109 96
110 if (is_bridge) { 97 if (check_children && list_empty(&adev->children))
111 void *test = NULL; 98 return -ENODEV;
112 99
113 /* Check if this object has at least one child device. */
114 acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, 1,
115 acpi_dev_present, NULL, NULL, &test);
116 if (!test)
117 return -ENODEV;
118 }
119 return sta_present ? FIND_CHILD_MAX_SCORE : FIND_CHILD_MIN_SCORE; 100 return sta_present ? FIND_CHILD_MAX_SCORE : FIND_CHILD_MIN_SCORE;
120} 101}
121 102
122struct find_child_context { 103struct acpi_device *acpi_find_child_device(struct acpi_device *parent,
123 u64 addr; 104 u64 address, bool check_children)
124 bool is_bridge;
125 acpi_handle ret;
126 int ret_score;
127};
128
129static acpi_status do_find_child(acpi_handle handle, u32 lvl_not_used,
130 void *data, void **not_used)
131{
132 struct find_child_context *context = data;
133 unsigned long long addr;
134 acpi_status status;
135 int score;
136
137 status = acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL, &addr);
138 if (ACPI_FAILURE(status) || addr != context->addr)
139 return AE_OK;
140
141 if (!context->ret) {
142 /* This is the first matching object. Save its handle. */
143 context->ret = handle;
144 return AE_OK;
145 }
146 /*
147 * There is more than one matching object with the same _ADR value.
148 * That really is unexpected, so we are kind of beyond the scope of the
149 * spec here. We have to choose which one to return, though.
150 *
151 * First, check if the previously found object is good enough and return
152 * its handle if so. Second, check the same for the object that we've
153 * just found.
154 */
155 if (!context->ret_score) {
156 score = do_find_child_checks(context->ret, context->is_bridge);
157 if (score == FIND_CHILD_MAX_SCORE)
158 return AE_CTRL_TERMINATE;
159 else
160 context->ret_score = score;
161 }
162 score = do_find_child_checks(handle, context->is_bridge);
163 if (score == FIND_CHILD_MAX_SCORE) {
164 context->ret = handle;
165 return AE_CTRL_TERMINATE;
166 } else if (score > context->ret_score) {
167 context->ret = handle;
168 context->ret_score = score;
169 }
170 return AE_OK;
171}
172
173acpi_handle acpi_find_child(acpi_handle parent, u64 addr, bool is_bridge)
174{ 105{
175 if (parent) { 106 struct acpi_device *adev, *ret = NULL;
176 struct find_child_context context = { 107 int ret_score = 0;
177 .addr = addr, 108
178 .is_bridge = is_bridge, 109 if (!parent)
179 }; 110 return NULL;
180 111
181 acpi_walk_namespace(ACPI_TYPE_DEVICE, parent, 1, do_find_child, 112 list_for_each_entry(adev, &parent->children, node) {
182 NULL, &context, NULL); 113 unsigned long long addr;
183 return context.ret; 114 acpi_status status;
115 int score;
116
117 status = acpi_evaluate_integer(adev->handle, METHOD_NAME__ADR,
118 NULL, &addr);
119 if (ACPI_FAILURE(status) || addr != address)
120 continue;
121
122 if (!ret) {
123 /* This is the first matching object. Save it. */
124 ret = adev;
125 continue;
126 }
127 /*
128 * There is more than one matching device object with the same
129 * _ADR value. That really is unexpected, so we are kind of
130 * beyond the scope of the spec here. We have to choose which
131 * one to return, though.
132 *
133 * First, check if the previously found object is good enough
134 * and return it if so. Second, do the same for the object that
135 * we've just found.
136 */
137 if (!ret_score) {
138 ret_score = find_child_checks(ret, check_children);
139 if (ret_score == FIND_CHILD_MAX_SCORE)
140 return ret;
141 }
142 score = find_child_checks(adev, check_children);
143 if (score == FIND_CHILD_MAX_SCORE) {
144 return adev;
145 } else if (score > ret_score) {
146 ret = adev;
147 ret_score = score;
148 }
184 } 149 }
185 return NULL; 150 return ret;
186} 151}
187EXPORT_SYMBOL_GPL(acpi_find_child); 152EXPORT_SYMBOL_GPL(acpi_find_child_device);
188 153
189static void acpi_physnode_link_name(char *buf, unsigned int node_id) 154static void acpi_physnode_link_name(char *buf, unsigned int node_id)
190{ 155{
@@ -195,9 +160,8 @@ static void acpi_physnode_link_name(char *buf, unsigned int node_id)
195 strcpy(buf, PHYSICAL_NODE_STRING); 160 strcpy(buf, PHYSICAL_NODE_STRING);
196} 161}
197 162
198int acpi_bind_one(struct device *dev, acpi_handle handle) 163int acpi_bind_one(struct device *dev, struct acpi_device *acpi_dev)
199{ 164{
200 struct acpi_device *acpi_dev = NULL;
201 struct acpi_device_physical_node *physical_node, *pn; 165 struct acpi_device_physical_node *physical_node, *pn;
202 char physical_node_name[PHYSICAL_NODE_NAME_SIZE]; 166 char physical_node_name[PHYSICAL_NODE_NAME_SIZE];
203 struct list_head *physnode_list; 167 struct list_head *physnode_list;
@@ -205,14 +169,12 @@ int acpi_bind_one(struct device *dev, acpi_handle handle)
205 int retval = -EINVAL; 169 int retval = -EINVAL;
206 170
207 if (ACPI_COMPANION(dev)) { 171 if (ACPI_COMPANION(dev)) {
208 if (handle) { 172 if (acpi_dev) {
209 dev_warn(dev, "ACPI companion already set\n"); 173 dev_warn(dev, "ACPI companion already set\n");
210 return -EINVAL; 174 return -EINVAL;
211 } else { 175 } else {
212 acpi_dev = ACPI_COMPANION(dev); 176 acpi_dev = ACPI_COMPANION(dev);
213 } 177 }
214 } else {
215 acpi_bus_get_device(handle, &acpi_dev);
216 } 178 }
217 if (!acpi_dev) 179 if (!acpi_dev)
218 return -EINVAL; 180 return -EINVAL;
@@ -322,29 +284,22 @@ int acpi_unbind_one(struct device *dev)
322} 284}
323EXPORT_SYMBOL_GPL(acpi_unbind_one); 285EXPORT_SYMBOL_GPL(acpi_unbind_one);
324 286
325void acpi_preset_companion(struct device *dev, acpi_handle parent, u64 addr)
326{
327 struct acpi_device *adev;
328
329 if (!acpi_bus_get_device(acpi_get_child(parent, addr), &adev))
330 ACPI_COMPANION_SET(dev, adev);
331}
332EXPORT_SYMBOL_GPL(acpi_preset_companion);
333
334static int acpi_platform_notify(struct device *dev) 287static int acpi_platform_notify(struct device *dev)
335{ 288{
336 struct acpi_bus_type *type = acpi_get_bus_type(dev); 289 struct acpi_bus_type *type = acpi_get_bus_type(dev);
337 acpi_handle handle;
338 int ret; 290 int ret;
339 291
340 ret = acpi_bind_one(dev, NULL); 292 ret = acpi_bind_one(dev, NULL);
341 if (ret && type) { 293 if (ret && type) {
342 ret = type->find_device(dev, &handle); 294 struct acpi_device *adev;
343 if (ret) { 295
296 adev = type->find_companion(dev);
297 if (!adev) {
344 DBG("Unable to get handle for %s\n", dev_name(dev)); 298 DBG("Unable to get handle for %s\n", dev_name(dev));
299 ret = -ENODEV;
345 goto out; 300 goto out;
346 } 301 }
347 ret = acpi_bind_one(dev, handle); 302 ret = acpi_bind_one(dev, adev);
348 if (ret) 303 if (ret)
349 goto out; 304 goto out;
350 } 305 }