scan.c (fce6bd84d663b92997e0fa9c971ed2b2cdf08fb4) scan.c (c713cd7f2d799c50a0721bf51d178ea9567215dd)
1/*
2 * scan.c - support for transforming the ACPI namespace into individual objects
3 */
4
5#include <linux/module.h>
6#include <linux/init.h>
7#include <linux/slab.h>
8#include <linux/kernel.h>
9#include <linux/acpi.h>
10#include <linux/signal.h>
11#include <linux/kthread.h>
12#include <linux/dmi.h>
13#include <linux/nls.h>
14
1/*
2 * scan.c - support for transforming the ACPI namespace into individual objects
3 */
4
5#include <linux/module.h>
6#include <linux/init.h>
7#include <linux/slab.h>
8#include <linux/kernel.h>
9#include <linux/acpi.h>
10#include <linux/signal.h>
11#include <linux/kthread.h>
12#include <linux/dmi.h>
13#include <linux/nls.h>
14
15#include <acpi/acpi_drivers.h>
15#include <asm/pgtable.h>
16
17#include "internal.h"
18
19#define _COMPONENT ACPI_BUS_COMPONENT
20ACPI_MODULE_NAME("scan");
16
17#include "internal.h"
18
19#define _COMPONENT ACPI_BUS_COMPONENT
20ACPI_MODULE_NAME("scan");
21#define STRUCT_TO_INT(s) (*((int*)&s))
22extern struct acpi_device *acpi_root;
23
24#define ACPI_BUS_CLASS "system_bus"
25#define ACPI_BUS_HID "LNXSYBUS"
26#define ACPI_BUS_DEVICE_NAME "System Bus"
27
28#define ACPI_IS_ROOT_DEVICE(device) (!(device)->parent)
29
21extern struct acpi_device *acpi_root;
22
23#define ACPI_BUS_CLASS "system_bus"
24#define ACPI_BUS_HID "LNXSYBUS"
25#define ACPI_BUS_DEVICE_NAME "System Bus"
26
27#define ACPI_IS_ROOT_DEVICE(device) (!(device)->parent)
28
29#define INVALID_ACPI_HANDLE ((acpi_handle)empty_zero_page)
30
30/*
31 * If set, devices will be hot-removed even if they cannot be put offline
32 * gracefully (from the kernel's standpoint).
33 */
34bool acpi_force_hot_remove;
35
36static const char *dummy_hid = "device";
37

--- 82 unchanged lines hidden (view full) ---

120 len = create_modalias(acpi_dev, buf, 1024);
121 if (len <= 0)
122 return 0;
123 buf[len++] = '\n';
124 return len;
125}
126static DEVICE_ATTR(modalias, 0444, acpi_device_modalias_show, NULL);
127
31/*
32 * If set, devices will be hot-removed even if they cannot be put offline
33 * gracefully (from the kernel's standpoint).
34 */
35bool acpi_force_hot_remove;
36
37static const char *dummy_hid = "device";
38

--- 82 unchanged lines hidden (view full) ---

121 len = create_modalias(acpi_dev, buf, 1024);
122 if (len <= 0)
123 return 0;
124 buf[len++] = '\n';
125 return len;
126}
127static DEVICE_ATTR(modalias, 0444, acpi_device_modalias_show, NULL);
128
129bool acpi_scan_is_offline(struct acpi_device *adev, bool uevent)
130{
131 struct acpi_device_physical_node *pn;
132 bool offline = true;
133
134 mutex_lock(&adev->physical_node_lock);
135
136 list_for_each_entry(pn, &adev->physical_node_list, node)
137 if (device_supports_offline(pn->dev) && !pn->dev->offline) {
138 if (uevent)
139 kobject_uevent(&pn->dev->kobj, KOBJ_CHANGE);
140
141 offline = false;
142 break;
143 }
144
145 mutex_unlock(&adev->physical_node_lock);
146 return offline;
147}
148
128static acpi_status acpi_bus_offline(acpi_handle handle, u32 lvl, void *data,
129 void **ret_p)
130{
131 struct acpi_device *device = NULL;
132 struct acpi_device_physical_node *pn;
133 bool second_pass = (bool)data;
134 acpi_status status = AE_OK;
135

--- 54 unchanged lines hidden (view full) ---

190 pn->put_online = false;
191 }
192
193 mutex_unlock(&device->physical_node_lock);
194
195 return AE_OK;
196}
197
149static acpi_status acpi_bus_offline(acpi_handle handle, u32 lvl, void *data,
150 void **ret_p)
151{
152 struct acpi_device *device = NULL;
153 struct acpi_device_physical_node *pn;
154 bool second_pass = (bool)data;
155 acpi_status status = AE_OK;
156

--- 54 unchanged lines hidden (view full) ---

211 pn->put_online = false;
212 }
213
214 mutex_unlock(&device->physical_node_lock);
215
216 return AE_OK;
217}
218
198static int acpi_scan_hot_remove(struct acpi_device *device)
219static int acpi_scan_try_to_offline(struct acpi_device *device)
199{
200 acpi_handle handle = device->handle;
220{
221 acpi_handle handle = device->handle;
201 struct device *errdev;
222 struct device *errdev = NULL;
202 acpi_status status;
223 acpi_status status;
203 unsigned long long sta;
204
224
205 /* If there is no handle, the device node has been unregistered. */
206 if (!handle) {
207 dev_dbg(&device->dev, "ACPI handle missing\n");
208 put_device(&device->dev);
209 return -EINVAL;
210 }
211
212 /*
213 * Carry out two passes here and ignore errors in the first pass,
214 * because if the devices in question are memory blocks and
215 * CONFIG_MEMCG is set, one of the blocks may hold data structures
216 * that the other blocks depend on, but it is not known in advance which
217 * block holds them.
218 *
219 * If the first pass is successful, the second one isn't needed, though.
220 */
225 /*
226 * Carry out two passes here and ignore errors in the first pass,
227 * because if the devices in question are memory blocks and
228 * CONFIG_MEMCG is set, one of the blocks may hold data structures
229 * that the other blocks depend on, but it is not known in advance which
230 * block holds them.
231 *
232 * If the first pass is successful, the second one isn't needed, though.
233 */
221 errdev = NULL;
222 status = acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
223 NULL, acpi_bus_offline, (void *)false,
224 (void **)&errdev);
225 if (status == AE_SUPPORT) {
226 dev_warn(errdev, "Offline disabled.\n");
227 acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
228 acpi_bus_online, NULL, NULL, NULL);
234 status = acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
235 NULL, acpi_bus_offline, (void *)false,
236 (void **)&errdev);
237 if (status == AE_SUPPORT) {
238 dev_warn(errdev, "Offline disabled.\n");
239 acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
240 acpi_bus_online, NULL, NULL, NULL);
229 put_device(&device->dev);
230 return -EPERM;
231 }
232 acpi_bus_offline(handle, 0, (void *)false, (void **)&errdev);
233 if (errdev) {
234 errdev = NULL;
235 acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
236 NULL, acpi_bus_offline, (void *)true,
237 (void **)&errdev);
238 if (!errdev || acpi_force_hot_remove)
239 acpi_bus_offline(handle, 0, (void *)true,
240 (void **)&errdev);
241
242 if (errdev && !acpi_force_hot_remove) {
243 dev_warn(errdev, "Offline failed.\n");
244 acpi_bus_online(handle, 0, NULL, NULL);
245 acpi_walk_namespace(ACPI_TYPE_ANY, handle,
246 ACPI_UINT32_MAX, acpi_bus_online,
247 NULL, NULL, NULL);
241 return -EPERM;
242 }
243 acpi_bus_offline(handle, 0, (void *)false, (void **)&errdev);
244 if (errdev) {
245 errdev = NULL;
246 acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
247 NULL, acpi_bus_offline, (void *)true,
248 (void **)&errdev);
249 if (!errdev || acpi_force_hot_remove)
250 acpi_bus_offline(handle, 0, (void *)true,
251 (void **)&errdev);
252
253 if (errdev && !acpi_force_hot_remove) {
254 dev_warn(errdev, "Offline failed.\n");
255 acpi_bus_online(handle, 0, NULL, NULL);
256 acpi_walk_namespace(ACPI_TYPE_ANY, handle,
257 ACPI_UINT32_MAX, acpi_bus_online,
258 NULL, NULL, NULL);
248 put_device(&device->dev);
249 return -EBUSY;
250 }
251 }
259 return -EBUSY;
260 }
261 }
262 return 0;
263}
252
264
265static int acpi_scan_hot_remove(struct acpi_device *device)
266{
267 acpi_handle handle = device->handle;
268 unsigned long long sta;
269 acpi_status status;
270
271 if (device->handler->hotplug.demand_offline && !acpi_force_hot_remove) {
272 if (!acpi_scan_is_offline(device, true))
273 return -EBUSY;
274 } else {
275 int error = acpi_scan_try_to_offline(device);
276 if (error)
277 return error;
278 }
279
253 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
254 "Hot-removing device %s...\n", dev_name(&device->dev)));
255
256 acpi_bus_trim(device);
257
280 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
281 "Hot-removing device %s...\n", dev_name(&device->dev)));
282
283 acpi_bus_trim(device);
284
258 /* Device node has been unregistered. */
259 put_device(&device->dev);
260 device = NULL;
261
262 acpi_evaluate_lck(handle, 0);
263 /*
264 * TBD: _EJD support.
265 */
266 status = acpi_evaluate_ej0(handle);
267 if (status == AE_NOT_FOUND)
268 return -ENODEV;
269 else if (ACPI_FAILURE(status))

--- 10 unchanged lines hidden (view full) ---

280 } else if (sta & ACPI_STA_DEVICE_ENABLED) {
281 acpi_handle_warn(handle,
282 "Eject incomplete - status 0x%llx\n", sta);
283 }
284
285 return 0;
286}
287
285 acpi_evaluate_lck(handle, 0);
286 /*
287 * TBD: _EJD support.
288 */
289 status = acpi_evaluate_ej0(handle);
290 if (status == AE_NOT_FOUND)
291 return -ENODEV;
292 else if (ACPI_FAILURE(status))

--- 10 unchanged lines hidden (view full) ---

303 } else if (sta & ACPI_STA_DEVICE_ENABLED) {
304 acpi_handle_warn(handle,
305 "Eject incomplete - status 0x%llx\n", sta);
306 }
307
308 return 0;
309}
310
288void acpi_bus_device_eject(void *data, u32 ost_src)
311static int acpi_scan_device_not_present(struct acpi_device *adev)
289{
312{
290 struct acpi_device *device = data;
291 acpi_handle handle = device->handle;
292 u32 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE;
313 if (!acpi_device_enumerated(adev)) {
314 dev_warn(&adev->dev, "Still not present\n");
315 return -EALREADY;
316 }
317 acpi_bus_trim(adev);
318 return 0;
319}
320
321static int acpi_scan_device_check(struct acpi_device *adev)
322{
293 int error;
294
323 int error;
324
295 lock_device_hotplug();
296 mutex_lock(&acpi_scan_lock);
325 acpi_bus_get_status(adev);
326 if (adev->status.present || adev->status.functional) {
327 /*
328 * This function is only called for device objects for which
329 * matching scan handlers exist. The only situation in which
330 * the scan handler is not attached to this device object yet
331 * is when the device has just appeared (either it wasn't
332 * present at all before or it was removed and then added
333 * again).
334 */
335 if (adev->handler) {
336 dev_warn(&adev->dev, "Already enumerated\n");
337 return -EALREADY;
338 }
339 error = acpi_bus_scan(adev->handle);
340 if (error) {
341 dev_warn(&adev->dev, "Namespace scan failure\n");
342 return error;
343 }
344 if (!adev->handler) {
345 dev_warn(&adev->dev, "Enumeration failure\n");
346 error = -ENODEV;
347 }
348 } else {
349 error = acpi_scan_device_not_present(adev);
350 }
351 return error;
352}
297
353
298 if (ost_src == ACPI_NOTIFY_EJECT_REQUEST)
299 acpi_evaluate_hotplug_ost(handle, ACPI_NOTIFY_EJECT_REQUEST,
300 ACPI_OST_SC_EJECT_IN_PROGRESS, NULL);
354static int acpi_scan_bus_check(struct acpi_device *adev)
355{
356 struct acpi_scan_handler *handler = adev->handler;
357 struct acpi_device *child;
358 int error;
301
359
302 if (device->handler && device->handler->hotplug.mode == AHM_CONTAINER)
303 kobject_uevent(&device->dev.kobj, KOBJ_OFFLINE);
304
305 error = acpi_scan_hot_remove(device);
306 if (error == -EPERM) {
307 goto err_support;
308 } else if (error) {
309 goto err_out;
360 acpi_bus_get_status(adev);
361 if (!(adev->status.present || adev->status.functional)) {
362 acpi_scan_device_not_present(adev);
363 return 0;
310 }
364 }
365 if (handler && handler->hotplug.scan_dependent)
366 return handler->hotplug.scan_dependent(adev);
311
367
312 out:
313 mutex_unlock(&acpi_scan_lock);
314 unlock_device_hotplug();
315 return;
316
317 err_support:
318 ost_code = ACPI_OST_SC_EJECT_NOT_SUPPORTED;
319 err_out:
320 acpi_evaluate_hotplug_ost(handle, ost_src, ost_code, NULL);
321 goto out;
368 error = acpi_bus_scan(adev->handle);
369 if (error) {
370 dev_warn(&adev->dev, "Namespace scan failure\n");
371 return error;
372 }
373 list_for_each_entry(child, &adev->children, node) {
374 error = acpi_scan_bus_check(child);
375 if (error)
376 return error;
377 }
378 return 0;
322}
323
379}
380
324static void acpi_scan_bus_device_check(void *data, u32 ost_source)
381static void acpi_device_hotplug(void *data, u32 src)
325{
382{
326 acpi_handle handle = data;
327 struct acpi_device *device = NULL;
328 u32 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE;
383 u32 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE;
384 struct acpi_device *adev = data;
329 int error;
330
331 lock_device_hotplug();
332 mutex_lock(&acpi_scan_lock);
333
385 int error;
386
387 lock_device_hotplug();
388 mutex_lock(&acpi_scan_lock);
389
334 if (ost_source != ACPI_NOTIFY_BUS_CHECK) {
335 acpi_bus_get_device(handle, &device);
336 if (device) {
337 dev_warn(&device->dev, "Attempt to re-insert\n");
338 goto out;
339 }
340 }
341 error = acpi_bus_scan(handle);
342 if (error) {
343 acpi_handle_warn(handle, "Namespace scan failure\n");
390 /*
391 * The device object's ACPI handle cannot become invalid as long as we
392 * are holding acpi_scan_lock, but it may have become invalid before
393 * that lock was acquired.
394 */
395 if (adev->handle == INVALID_ACPI_HANDLE)
344 goto out;
396 goto out;
345 }
346 error = acpi_bus_get_device(handle, &device);
347 if (error) {
348 acpi_handle_warn(handle, "Missing device node object\n");
349 goto out;
350 }
351 ost_code = ACPI_OST_SC_SUCCESS;
352 if (device->handler && device->handler->hotplug.mode == AHM_CONTAINER)
353 kobject_uevent(&device->dev.kobj, KOBJ_ONLINE);
354
397
355 out:
356 acpi_evaluate_hotplug_ost(handle, ost_source, ost_code, NULL);
357 mutex_unlock(&acpi_scan_lock);
358 unlock_device_hotplug();
359}
360
361static void acpi_hotplug_unsupported(acpi_handle handle, u32 type)
362{
363 u32 ost_status;
364
365 switch (type) {
398 switch (src) {
366 case ACPI_NOTIFY_BUS_CHECK:
399 case ACPI_NOTIFY_BUS_CHECK:
367 acpi_handle_debug(handle,
368 "ACPI_NOTIFY_BUS_CHECK event: unsupported\n");
369 ost_status = ACPI_OST_SC_INSERT_NOT_SUPPORTED;
400 error = acpi_scan_bus_check(adev);
370 break;
371 case ACPI_NOTIFY_DEVICE_CHECK:
401 break;
402 case ACPI_NOTIFY_DEVICE_CHECK:
372 acpi_handle_debug(handle,
373 "ACPI_NOTIFY_DEVICE_CHECK event: unsupported\n");
374 ost_status = ACPI_OST_SC_INSERT_NOT_SUPPORTED;
403 error = acpi_scan_device_check(adev);
375 break;
376 case ACPI_NOTIFY_EJECT_REQUEST:
404 break;
405 case ACPI_NOTIFY_EJECT_REQUEST:
377 acpi_handle_debug(handle,
378 "ACPI_NOTIFY_EJECT_REQUEST event: unsupported\n");
379 ost_status = ACPI_OST_SC_EJECT_NOT_SUPPORTED;
406 case ACPI_OST_EC_OSPM_EJECT:
407 error = acpi_scan_hot_remove(adev);
380 break;
381 default:
408 break;
409 default:
382 /* non-hotplug event; possibly handled by other handler */
383 return;
410 error = -EINVAL;
411 break;
384 }
412 }
413 if (!error)
414 ost_code = ACPI_OST_SC_SUCCESS;
385
415
386 acpi_evaluate_hotplug_ost(handle, type, ost_status, NULL);
416 out:
417 acpi_evaluate_hotplug_ost(adev->handle, src, ost_code, NULL);
418 put_device(&adev->dev);
419 mutex_unlock(&acpi_scan_lock);
420 unlock_device_hotplug();
387}
388
389static void acpi_hotplug_notify_cb(acpi_handle handle, u32 type, void *data)
390{
421}
422
423static void acpi_hotplug_notify_cb(acpi_handle handle, u32 type, void *data)
424{
425 u32 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE;
391 struct acpi_scan_handler *handler = data;
392 struct acpi_device *adev;
393 acpi_status status;
394
426 struct acpi_scan_handler *handler = data;
427 struct acpi_device *adev;
428 acpi_status status;
429
395 if (!handler->hotplug.enabled)
396 return acpi_hotplug_unsupported(handle, type);
430 if (acpi_bus_get_device(handle, &adev))
431 goto err_out;
397
398 switch (type) {
399 case ACPI_NOTIFY_BUS_CHECK:
400 acpi_handle_debug(handle, "ACPI_NOTIFY_BUS_CHECK event\n");
401 break;
402 case ACPI_NOTIFY_DEVICE_CHECK:
403 acpi_handle_debug(handle, "ACPI_NOTIFY_DEVICE_CHECK event\n");
404 break;
405 case ACPI_NOTIFY_EJECT_REQUEST:
406 acpi_handle_debug(handle, "ACPI_NOTIFY_EJECT_REQUEST event\n");
432
433 switch (type) {
434 case ACPI_NOTIFY_BUS_CHECK:
435 acpi_handle_debug(handle, "ACPI_NOTIFY_BUS_CHECK event\n");
436 break;
437 case ACPI_NOTIFY_DEVICE_CHECK:
438 acpi_handle_debug(handle, "ACPI_NOTIFY_DEVICE_CHECK event\n");
439 break;
440 case ACPI_NOTIFY_EJECT_REQUEST:
441 acpi_handle_debug(handle, "ACPI_NOTIFY_EJECT_REQUEST event\n");
407 if (acpi_bus_get_device(handle, &adev))
442 if (!handler->hotplug.enabled) {
443 acpi_handle_err(handle, "Eject disabled\n");
444 ost_code = ACPI_OST_SC_EJECT_NOT_SUPPORTED;
408 goto err_out;
445 goto err_out;
409
410 get_device(&adev->dev);
411 status = acpi_hotplug_execute(acpi_bus_device_eject, adev, type);
412 if (ACPI_SUCCESS(status))
413 return;
414
415 put_device(&adev->dev);
416 goto err_out;
446 }
447 acpi_evaluate_hotplug_ost(handle, ACPI_NOTIFY_EJECT_REQUEST,
448 ACPI_OST_SC_EJECT_IN_PROGRESS, NULL);
449 break;
417 default:
418 /* non-hotplug event; possibly handled by other handler */
419 return;
420 }
450 default:
451 /* non-hotplug event; possibly handled by other handler */
452 return;
453 }
421 status = acpi_hotplug_execute(acpi_scan_bus_device_check, handle, type);
454 get_device(&adev->dev);
455 status = acpi_hotplug_execute(acpi_device_hotplug, adev, type);
422 if (ACPI_SUCCESS(status))
423 return;
424
456 if (ACPI_SUCCESS(status))
457 return;
458
459 put_device(&adev->dev);
460
425 err_out:
461 err_out:
426 acpi_evaluate_hotplug_ost(handle, type,
427 ACPI_OST_SC_NON_SPECIFIC_FAILURE, NULL);
462 acpi_evaluate_hotplug_ost(handle, type, ost_code, NULL);
428}
429
430static ssize_t real_power_state_show(struct device *dev,
431 struct device_attribute *attr, char *buf)
432{
433 struct acpi_device *adev = to_acpi_device(dev);
434 int state;
435 int ret;

--- 34 unchanged lines hidden (view full) ---

470
471 status = acpi_get_type(acpi_device->handle, &not_used);
472 if (ACPI_FAILURE(status) || !acpi_device->flags.ejectable)
473 return -ENODEV;
474
475 acpi_evaluate_hotplug_ost(acpi_device->handle, ACPI_OST_EC_OSPM_EJECT,
476 ACPI_OST_SC_EJECT_IN_PROGRESS, NULL);
477 get_device(&acpi_device->dev);
463}
464
465static ssize_t real_power_state_show(struct device *dev,
466 struct device_attribute *attr, char *buf)
467{
468 struct acpi_device *adev = to_acpi_device(dev);
469 int state;
470 int ret;

--- 34 unchanged lines hidden (view full) ---

505
506 status = acpi_get_type(acpi_device->handle, &not_used);
507 if (ACPI_FAILURE(status) || !acpi_device->flags.ejectable)
508 return -ENODEV;
509
510 acpi_evaluate_hotplug_ost(acpi_device->handle, ACPI_OST_EC_OSPM_EJECT,
511 ACPI_OST_SC_EJECT_IN_PROGRESS, NULL);
512 get_device(&acpi_device->dev);
478 status = acpi_hotplug_execute(acpi_bus_device_eject, acpi_device,
513 status = acpi_hotplug_execute(acpi_device_hotplug, acpi_device,
479 ACPI_OST_EC_OSPM_EJECT);
480 if (ACPI_SUCCESS(status))
481 return count;
482
483 put_device(&acpi_device->dev);
484 acpi_evaluate_hotplug_ost(acpi_device->handle, ACPI_OST_EC_OSPM_EJECT,
485 ACPI_OST_SC_NON_SPECIFIC_FAILURE, NULL);
486 return status == AE_NO_MEMORY ? -ENOMEM : -EAGAIN;

--- 75 unchanged lines hidden (view full) ---

562acpi_device_sun_show(struct device *dev, struct device_attribute *attr,
563 char *buf) {
564 struct acpi_device *acpi_dev = to_acpi_device(dev);
565
566 return sprintf(buf, "%lu\n", acpi_dev->pnp.sun);
567}
568static DEVICE_ATTR(sun, 0444, acpi_device_sun_show, NULL);
569
514 ACPI_OST_EC_OSPM_EJECT);
515 if (ACPI_SUCCESS(status))
516 return count;
517
518 put_device(&acpi_device->dev);
519 acpi_evaluate_hotplug_ost(acpi_device->handle, ACPI_OST_EC_OSPM_EJECT,
520 ACPI_OST_SC_NON_SPECIFIC_FAILURE, NULL);
521 return status == AE_NO_MEMORY ? -ENOMEM : -EAGAIN;

--- 75 unchanged lines hidden (view full) ---

597acpi_device_sun_show(struct device *dev, struct device_attribute *attr,
598 char *buf) {
599 struct acpi_device *acpi_dev = to_acpi_device(dev);
600
601 return sprintf(buf, "%lu\n", acpi_dev->pnp.sun);
602}
603static DEVICE_ATTR(sun, 0444, acpi_device_sun_show, NULL);
604
605static ssize_t status_show(struct device *dev, struct device_attribute *attr,
606 char *buf) {
607 struct acpi_device *acpi_dev = to_acpi_device(dev);
608 acpi_status status;
609 unsigned long long sta;
610
611 status = acpi_evaluate_integer(acpi_dev->handle, "_STA", NULL, &sta);
612 if (ACPI_FAILURE(status))
613 return -ENODEV;
614
615 return sprintf(buf, "%llu\n", sta);
616}
617static DEVICE_ATTR_RO(status);
618
570static int acpi_device_setup_files(struct acpi_device *dev)
571{
572 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
573 acpi_status status;
574 unsigned long long sun;
575 int result = 0;
576
577 /*

--- 39 unchanged lines hidden (view full) ---

617 dev->pnp.sun = (unsigned long)sun;
618 result = device_create_file(&dev->dev, &dev_attr_sun);
619 if (result)
620 goto end;
621 } else {
622 dev->pnp.sun = (unsigned long)-1;
623 }
624
619static int acpi_device_setup_files(struct acpi_device *dev)
620{
621 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
622 acpi_status status;
623 unsigned long long sun;
624 int result = 0;
625
626 /*

--- 39 unchanged lines hidden (view full) ---

666 dev->pnp.sun = (unsigned long)sun;
667 result = device_create_file(&dev->dev, &dev_attr_sun);
668 if (result)
669 goto end;
670 } else {
671 dev->pnp.sun = (unsigned long)-1;
672 }
673
674 if (acpi_has_method(dev->handle, "_STA")) {
675 result = device_create_file(&dev->dev, &dev_attr_status);
676 if (result)
677 goto end;
678 }
679
625 /*
626 * If device has _EJ0, 'eject' file is created that is used to trigger
627 * hot-removal function from userland.
628 */
629 if (acpi_has_method(dev->handle, "_EJ0")) {
630 result = device_create_file(&dev->dev, &dev_attr_eject);
631 if (result)
632 return result;

--- 39 unchanged lines hidden (view full) ---

672 device_remove_file(&dev->dev, &dev_attr_sun);
673
674 if (dev->pnp.unique_id)
675 device_remove_file(&dev->dev, &dev_attr_uid);
676 if (dev->pnp.type.bus_address)
677 device_remove_file(&dev->dev, &dev_attr_adr);
678 device_remove_file(&dev->dev, &dev_attr_modalias);
679 device_remove_file(&dev->dev, &dev_attr_hid);
680 /*
681 * If device has _EJ0, 'eject' file is created that is used to trigger
682 * hot-removal function from userland.
683 */
684 if (acpi_has_method(dev->handle, "_EJ0")) {
685 result = device_create_file(&dev->dev, &dev_attr_eject);
686 if (result)
687 return result;

--- 39 unchanged lines hidden (view full) ---

727 device_remove_file(&dev->dev, &dev_attr_sun);
728
729 if (dev->pnp.unique_id)
730 device_remove_file(&dev->dev, &dev_attr_uid);
731 if (dev->pnp.type.bus_address)
732 device_remove_file(&dev->dev, &dev_attr_adr);
733 device_remove_file(&dev->dev, &dev_attr_modalias);
734 device_remove_file(&dev->dev, &dev_attr_hid);
735 if (acpi_has_method(dev->handle, "_STA"))
736 device_remove_file(&dev->dev, &dev_attr_status);
680 if (dev->handle)
681 device_remove_file(&dev->dev, &dev_attr_path);
682}
683/* --------------------------------------------------------------------------
684 ACPI Bus operations
685 -------------------------------------------------------------------------- */
686
687static const struct acpi_device_id *__acpi_match_device(

--- 214 unchanged lines hidden (view full) ---

902struct bus_type acpi_bus_type = {
903 .name = "acpi",
904 .match = acpi_bus_match,
905 .probe = acpi_device_probe,
906 .remove = acpi_device_remove,
907 .uevent = acpi_device_uevent,
908};
909
737 if (dev->handle)
738 device_remove_file(&dev->dev, &dev_attr_path);
739}
740/* --------------------------------------------------------------------------
741 ACPI Bus operations
742 -------------------------------------------------------------------------- */
743
744static const struct acpi_device_id *__acpi_match_device(

--- 214 unchanged lines hidden (view full) ---

959struct bus_type acpi_bus_type = {
960 .name = "acpi",
961 .match = acpi_bus_match,
962 .probe = acpi_device_probe,
963 .remove = acpi_device_remove,
964 .uevent = acpi_device_uevent,
965};
966
910static void acpi_bus_data_handler(acpi_handle handle, void *context)
967static void acpi_device_del(struct acpi_device *device)
911{
968{
912 /* Intentionally empty. */
969 mutex_lock(&acpi_device_lock);
970 if (device->parent)
971 list_del(&device->node);
972
973 list_del(&device->wakeup_list);
974 mutex_unlock(&acpi_device_lock);
975
976 acpi_power_add_remove_device(device, false);
977 acpi_device_remove_files(device);
978 if (device->remove)
979 device->remove(device);
980
981 device_del(&device->dev);
913}
914
982}
983
984static LIST_HEAD(acpi_device_del_list);
985static DEFINE_MUTEX(acpi_device_del_lock);
986
987static void acpi_device_del_work_fn(struct work_struct *work_not_used)
988{
989 for (;;) {
990 struct acpi_device *adev;
991
992 mutex_lock(&acpi_device_del_lock);
993
994 if (list_empty(&acpi_device_del_list)) {
995 mutex_unlock(&acpi_device_del_lock);
996 break;
997 }
998 adev = list_first_entry(&acpi_device_del_list,
999 struct acpi_device, del_list);
1000 list_del(&adev->del_list);
1001
1002 mutex_unlock(&acpi_device_del_lock);
1003
1004 acpi_device_del(adev);
1005 /*
1006 * Drop references to all power resources that might have been
1007 * used by the device.
1008 */
1009 acpi_power_transition(adev, ACPI_STATE_D3_COLD);
1010 put_device(&adev->dev);
1011 }
1012}
1013
1014/**
1015 * acpi_scan_drop_device - Drop an ACPI device object.
1016 * @handle: Handle of an ACPI namespace node, not used.
1017 * @context: Address of the ACPI device object to drop.
1018 *
1019 * This is invoked by acpi_ns_delete_node() during the removal of the ACPI
1020 * namespace node the device object pointed to by @context is attached to.
1021 *
1022 * The unregistration is carried out asynchronously to avoid running
1023 * acpi_device_del() under the ACPICA's namespace mutex and the list is used to
1024 * ensure the correct ordering (the device objects must be unregistered in the
1025 * same order in which the corresponding namespace nodes are deleted).
1026 */
1027static void acpi_scan_drop_device(acpi_handle handle, void *context)
1028{
1029 static DECLARE_WORK(work, acpi_device_del_work_fn);
1030 struct acpi_device *adev = context;
1031
1032 mutex_lock(&acpi_device_del_lock);
1033
1034 /*
1035 * Use the ACPI hotplug workqueue which is ordered, so this work item
1036 * won't run after any hotplug work items submitted subsequently. That
1037 * prevents attempts to register device objects identical to those being
1038 * deleted from happening concurrently (such attempts result from
1039 * hotplug events handled via the ACPI hotplug workqueue). It also will
1040 * run after all of the work items submitted previosuly, which helps
1041 * those work items to ensure that they are not accessing stale device
1042 * objects.
1043 */
1044 if (list_empty(&acpi_device_del_list))
1045 acpi_queue_hotplug_work(&work);
1046
1047 list_add_tail(&adev->del_list, &acpi_device_del_list);
1048 /* Make acpi_ns_validate_handle() return NULL for this handle. */
1049 adev->handle = INVALID_ACPI_HANDLE;
1050
1051 mutex_unlock(&acpi_device_del_lock);
1052}
1053
915int acpi_bus_get_device(acpi_handle handle, struct acpi_device **device)
916{
917 acpi_status status;
918
919 if (!device)
920 return -EINVAL;
921
1054int acpi_bus_get_device(acpi_handle handle, struct acpi_device **device)
1055{
1056 acpi_status status;
1057
1058 if (!device)
1059 return -EINVAL;
1060
922 status = acpi_get_data(handle, acpi_bus_data_handler, (void **)device);
1061 status = acpi_get_data(handle, acpi_scan_drop_device, (void **)device);
923 if (ACPI_FAILURE(status) || !*device) {
924 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
925 handle));
926 return -ENODEV;
927 }
928 return 0;
929}
930EXPORT_SYMBOL(acpi_bus_get_device);
931
932int acpi_device_add(struct acpi_device *device,
933 void (*release)(struct device *))
934{
935 int result;
936 struct acpi_device_bus_id *acpi_device_bus_id, *new_bus_id;
937 int found = 0;
938
939 if (device->handle) {
940 acpi_status status;
941
1062 if (ACPI_FAILURE(status) || !*device) {
1063 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
1064 handle));
1065 return -ENODEV;
1066 }
1067 return 0;
1068}
1069EXPORT_SYMBOL(acpi_bus_get_device);
1070
1071int acpi_device_add(struct acpi_device *device,
1072 void (*release)(struct device *))
1073{
1074 int result;
1075 struct acpi_device_bus_id *acpi_device_bus_id, *new_bus_id;
1076 int found = 0;
1077
1078 if (device->handle) {
1079 acpi_status status;
1080
942 status = acpi_attach_data(device->handle, acpi_bus_data_handler,
1081 status = acpi_attach_data(device->handle, acpi_scan_drop_device,
943 device);
944 if (ACPI_FAILURE(status)) {
945 acpi_handle_err(device->handle,
946 "Unable to attach device data\n");
947 return -ENODEV;
948 }
949 }
950
951 /*
952 * Linkage
953 * -------
954 * Link this device to its parent and siblings.
955 */
956 INIT_LIST_HEAD(&device->children);
957 INIT_LIST_HEAD(&device->node);
958 INIT_LIST_HEAD(&device->wakeup_list);
959 INIT_LIST_HEAD(&device->physical_node_list);
1082 device);
1083 if (ACPI_FAILURE(status)) {
1084 acpi_handle_err(device->handle,
1085 "Unable to attach device data\n");
1086 return -ENODEV;
1087 }
1088 }
1089
1090 /*
1091 * Linkage
1092 * -------
1093 * Link this device to its parent and siblings.
1094 */
1095 INIT_LIST_HEAD(&device->children);
1096 INIT_LIST_HEAD(&device->node);
1097 INIT_LIST_HEAD(&device->wakeup_list);
1098 INIT_LIST_HEAD(&device->physical_node_list);
1099 INIT_LIST_HEAD(&device->del_list);
960 mutex_init(&device->physical_node_lock);
961
962 new_bus_id = kzalloc(sizeof(struct acpi_device_bus_id), GFP_KERNEL);
963 if (!new_bus_id) {
964 pr_err(PREFIX "Memory allocation error\n");
965 result = -ENOMEM;
966 goto err_detach;
967 }

--- 47 unchanged lines hidden (view full) ---

1015 err:
1016 mutex_lock(&acpi_device_lock);
1017 if (device->parent)
1018 list_del(&device->node);
1019 list_del(&device->wakeup_list);
1020 mutex_unlock(&acpi_device_lock);
1021
1022 err_detach:
1100 mutex_init(&device->physical_node_lock);
1101
1102 new_bus_id = kzalloc(sizeof(struct acpi_device_bus_id), GFP_KERNEL);
1103 if (!new_bus_id) {
1104 pr_err(PREFIX "Memory allocation error\n");
1105 result = -ENOMEM;
1106 goto err_detach;
1107 }

--- 47 unchanged lines hidden (view full) ---

1155 err:
1156 mutex_lock(&acpi_device_lock);
1157 if (device->parent)
1158 list_del(&device->node);
1159 list_del(&device->wakeup_list);
1160 mutex_unlock(&acpi_device_lock);
1161
1162 err_detach:
1023 acpi_detach_data(device->handle, acpi_bus_data_handler);
1163 acpi_detach_data(device->handle, acpi_scan_drop_device);
1024 return result;
1025}
1026
1164 return result;
1165}
1166
1027static void acpi_device_unregister(struct acpi_device *device)
1028{
1029 mutex_lock(&acpi_device_lock);
1030 if (device->parent)
1031 list_del(&device->node);
1032
1033 list_del(&device->wakeup_list);
1034 mutex_unlock(&acpi_device_lock);
1035
1036 acpi_detach_data(device->handle, acpi_bus_data_handler);
1037
1038 acpi_power_add_remove_device(device, false);
1039 acpi_device_remove_files(device);
1040 if (device->remove)
1041 device->remove(device);
1042
1043 device_del(&device->dev);
1044 /*
1045 * Transition the device to D3cold to drop the reference counts of all
1046 * power resources the device depends on and turn off the ones that have
1047 * no more references.
1048 */
1049 acpi_device_set_power(device, ACPI_STATE_D3_COLD);
1050 device->handle = NULL;
1051 put_device(&device->dev);
1052}
1053
1054/* --------------------------------------------------------------------------
1055 Driver Management
1056 -------------------------------------------------------------------------- */
1057/**
1058 * acpi_bus_register_driver - register a driver with the ACPI bus
1059 * @driver: driver being registered
1060 *
1061 * Registers a driver with the ACPI bus. Searches the namespace for all

--- 557 unchanged lines hidden (view full) ---

1619
1620void acpi_init_device_object(struct acpi_device *device, acpi_handle handle,
1621 int type, unsigned long long sta)
1622{
1623 INIT_LIST_HEAD(&device->pnp.ids);
1624 device->device_type = type;
1625 device->handle = handle;
1626 device->parent = acpi_bus_get_parent(handle);
1167/* --------------------------------------------------------------------------
1168 Driver Management
1169 -------------------------------------------------------------------------- */
1170/**
1171 * acpi_bus_register_driver - register a driver with the ACPI bus
1172 * @driver: driver being registered
1173 *
1174 * Registers a driver with the ACPI bus. Searches the namespace for all

--- 557 unchanged lines hidden (view full) ---

1732
1733void acpi_init_device_object(struct acpi_device *device, acpi_handle handle,
1734 int type, unsigned long long sta)
1735{
1736 INIT_LIST_HEAD(&device->pnp.ids);
1737 device->device_type = type;
1738 device->handle = handle;
1739 device->parent = acpi_bus_get_parent(handle);
1627 STRUCT_TO_INT(device->status) = sta;
1740 acpi_set_device_status(device, sta);
1628 acpi_device_get_busid(device);
1629 acpi_set_pnp_ids(handle, &device->pnp, type);
1630 acpi_bus_get_flags(device);
1631 device->flags.match_driver = false;
1741 acpi_device_get_busid(device);
1742 acpi_set_pnp_ids(handle, &device->pnp, type);
1743 acpi_bus_get_flags(device);
1744 device->flags.match_driver = false;
1745 device->flags.initialized = true;
1746 device->flags.visited = false;
1632 device_initialize(&device->dev);
1633 dev_set_uevent_suppress(&device->dev, true);
1634}
1635
1636void acpi_device_add_finalize(struct acpi_device *device)
1637{
1638 dev_set_uevent_suppress(&device->dev, false);
1639 kobject_uevent(&device->dev.kobj, KOBJ_ADD);

--- 68 unchanged lines hidden (view full) ---

1708 break;
1709 default:
1710 return -ENODEV;
1711 }
1712
1713 return 0;
1714}
1715
1747 device_initialize(&device->dev);
1748 dev_set_uevent_suppress(&device->dev, true);
1749}
1750
1751void acpi_device_add_finalize(struct acpi_device *device)
1752{
1753 dev_set_uevent_suppress(&device->dev, false);
1754 kobject_uevent(&device->dev.kobj, KOBJ_ADD);

--- 68 unchanged lines hidden (view full) ---

1823 break;
1824 default:
1825 return -ENODEV;
1826 }
1827
1828 return 0;
1829}
1830
1831bool acpi_device_is_present(struct acpi_device *adev)
1832{
1833 if (adev->status.present || adev->status.functional)
1834 return true;
1835
1836 adev->flags.initialized = false;
1837 return false;
1838}
1839
1716static bool acpi_scan_handler_matching(struct acpi_scan_handler *handler,
1717 char *idstr,
1718 const struct acpi_device_id **matchid)
1719{
1720 const struct acpi_device_id *devid;
1721
1722 for (devid = handler->ids; devid->id[0]; devid++)
1723 if (!strcmp((char *)devid->id, idstr)) {

--- 43 unchanged lines hidden (view full) ---

1767 goto out;
1768
1769 /*
1770 * This relies on the fact that acpi_install_notify_handler() will not
1771 * install the same notify handler routine twice for the same handle.
1772 */
1773 list_for_each_entry(hwid, &pnp.ids, list) {
1774 handler = acpi_scan_match_handler(hwid->id, NULL);
1840static bool acpi_scan_handler_matching(struct acpi_scan_handler *handler,
1841 char *idstr,
1842 const struct acpi_device_id **matchid)
1843{
1844 const struct acpi_device_id *devid;
1845
1846 for (devid = handler->ids; devid->id[0]; devid++)
1847 if (!strcmp((char *)devid->id, idstr)) {

--- 43 unchanged lines hidden (view full) ---

1891 goto out;
1892
1893 /*
1894 * This relies on the fact that acpi_install_notify_handler() will not
1895 * install the same notify handler routine twice for the same handle.
1896 */
1897 list_for_each_entry(hwid, &pnp.ids, list) {
1898 handler = acpi_scan_match_handler(hwid->id, NULL);
1775 if (handler && !handler->hotplug.ignore) {
1899 if (handler) {
1776 acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
1777 acpi_hotplug_notify_cb, handler);
1778 break;
1779 }
1780 }
1781
1782out:
1783 acpi_free_pnp_ids(&pnp);

--- 17 unchanged lines hidden (view full) ---

1801
1802 if (type == ACPI_BUS_TYPE_POWER) {
1803 acpi_add_power_resource(handle);
1804 return AE_OK;
1805 }
1806
1807 acpi_scan_init_hotplug(handle, type);
1808
1900 acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
1901 acpi_hotplug_notify_cb, handler);
1902 break;
1903 }
1904 }
1905
1906out:
1907 acpi_free_pnp_ids(&pnp);

--- 17 unchanged lines hidden (view full) ---

1925
1926 if (type == ACPI_BUS_TYPE_POWER) {
1927 acpi_add_power_resource(handle);
1928 return AE_OK;
1929 }
1930
1931 acpi_scan_init_hotplug(handle, type);
1932
1809 if (!(sta & ACPI_STA_DEVICE_PRESENT) &&
1810 !(sta & ACPI_STA_DEVICE_FUNCTIONING)) {
1811 struct acpi_device_wakeup wakeup;
1812
1813 if (acpi_has_method(handle, "_PRW")) {
1814 acpi_bus_extract_wakeup_device_power_package(handle,
1815 &wakeup);
1816 acpi_power_resources_list_free(&wakeup.resources);
1817 }
1818 return AE_CTRL_DEPTH;
1819 }
1820
1821 acpi_add_single_object(&device, handle, type, sta);
1822 if (!device)
1823 return AE_CTRL_DEPTH;
1824
1825 out:
1826 if (!*return_value)
1827 *return_value = device;
1828

--- 18 unchanged lines hidden (view full) ---

1847 } else if (ret < 0) {
1848 break;
1849 }
1850 }
1851 }
1852 return ret;
1853}
1854
1933 acpi_add_single_object(&device, handle, type, sta);
1934 if (!device)
1935 return AE_CTRL_DEPTH;
1936
1937 out:
1938 if (!*return_value)
1939 *return_value = device;
1940

--- 18 unchanged lines hidden (view full) ---

1959 } else if (ret < 0) {
1960 break;
1961 }
1962 }
1963 }
1964 return ret;
1965}
1966
1855static acpi_status acpi_bus_device_attach(acpi_handle handle, u32 lvl_not_used,
1856 void *not_used, void **ret_not_used)
1967static void acpi_bus_attach(struct acpi_device *device)
1857{
1968{
1858 struct acpi_device *device;
1859 unsigned long long sta_not_used;
1969 struct acpi_device *child;
1860 int ret;
1861
1970 int ret;
1971
1862 /*
1863 * Ignore errors ignored by acpi_bus_check_add() to avoid terminating
1864 * namespace walks prematurely.
1865 */
1866 if (acpi_bus_type_and_status(handle, &ret, &sta_not_used))
1867 return AE_OK;
1868
1869 if (acpi_bus_get_device(handle, &device))
1870 return AE_CTRL_DEPTH;
1871
1972 acpi_bus_get_status(device);
1973 /* Skip devices that are not present. */
1974 if (!acpi_device_is_present(device)) {
1975 device->flags.visited = false;
1976 return;
1977 }
1872 if (device->handler)
1978 if (device->handler)
1873 return AE_OK;
1979 goto ok;
1874
1980
1981 if (!device->flags.initialized) {
1982 acpi_bus_update_power(device, NULL);
1983 device->flags.initialized = true;
1984 }
1985 device->flags.visited = false;
1875 ret = acpi_scan_attach_handler(device);
1876 if (ret < 0)
1986 ret = acpi_scan_attach_handler(device);
1987 if (ret < 0)
1877 return AE_CTRL_DEPTH;
1988 return;
1878
1879 device->flags.match_driver = true;
1989
1990 device->flags.match_driver = true;
1880 if (ret > 0)
1881 return AE_OK;
1991 if (!ret) {
1992 ret = device_attach(&device->dev);
1993 if (ret < 0)
1994 return;
1995 }
1996 device->flags.visited = true;
1882
1997
1883 ret = device_attach(&device->dev);
1884 return ret >= 0 ? AE_OK : AE_CTRL_DEPTH;
1998 ok:
1999 list_for_each_entry(child, &device->children, node)
2000 acpi_bus_attach(child);
1885}
1886
1887/**
1888 * acpi_bus_scan - Add ACPI device node objects in a given namespace scope.
1889 * @handle: Root of the namespace scope to scan.
1890 *
1891 * Scan a given ACPI tree (probably recently hot-plugged) and create and add
1892 * found devices.
1893 *
1894 * If no devices were found, -ENODEV is returned, but it does not mean that
1895 * there has been a real error. There just have been no suitable ACPI objects
1896 * in the table trunk from which the kernel could create a device and add an
1897 * appropriate driver.
1898 *
1899 * Must be called under acpi_scan_lock.
1900 */
1901int acpi_bus_scan(acpi_handle handle)
1902{
1903 void *device = NULL;
2001}
2002
2003/**
2004 * acpi_bus_scan - Add ACPI device node objects in a given namespace scope.
2005 * @handle: Root of the namespace scope to scan.
2006 *
2007 * Scan a given ACPI tree (probably recently hot-plugged) and create and add
2008 * found devices.
2009 *
2010 * If no devices were found, -ENODEV is returned, but it does not mean that
2011 * there has been a real error. There just have been no suitable ACPI objects
2012 * in the table trunk from which the kernel could create a device and add an
2013 * appropriate driver.
2014 *
2015 * Must be called under acpi_scan_lock.
2016 */
2017int acpi_bus_scan(acpi_handle handle)
2018{
2019 void *device = NULL;
1904 int error = 0;
1905
1906 if (ACPI_SUCCESS(acpi_bus_check_add(handle, 0, NULL, &device)))
1907 acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
1908 acpi_bus_check_add, NULL, NULL, &device);
1909
2020
2021 if (ACPI_SUCCESS(acpi_bus_check_add(handle, 0, NULL, &device)))
2022 acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
2023 acpi_bus_check_add, NULL, NULL, &device);
2024
1910 if (!device)
1911 error = -ENODEV;
1912 else if (ACPI_SUCCESS(acpi_bus_device_attach(handle, 0, NULL, NULL)))
1913 acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
1914 acpi_bus_device_attach, NULL, NULL, NULL);
1915
1916 return error;
2025 if (device) {
2026 acpi_bus_attach(device);
2027 return 0;
2028 }
2029 return -ENODEV;
1917}
1918EXPORT_SYMBOL(acpi_bus_scan);
1919
2030}
2031EXPORT_SYMBOL(acpi_bus_scan);
2032
1920static acpi_status acpi_bus_device_detach(acpi_handle handle, u32 lvl_not_used,
1921 void *not_used, void **ret_not_used)
1922{
1923 struct acpi_device *device = NULL;
1924
1925 if (!acpi_bus_get_device(handle, &device)) {
1926 struct acpi_scan_handler *dev_handler = device->handler;
1927
1928 if (dev_handler) {
1929 if (dev_handler->detach)
1930 dev_handler->detach(device);
1931
1932 device->handler = NULL;
1933 } else {
1934 device_release_driver(&device->dev);
1935 }
1936 }
1937 return AE_OK;
1938}
1939
1940static acpi_status acpi_bus_remove(acpi_handle handle, u32 lvl_not_used,
1941 void *not_used, void **ret_not_used)
1942{
1943 struct acpi_device *device = NULL;
1944
1945 if (!acpi_bus_get_device(handle, &device))
1946 acpi_device_unregister(device);
1947
1948 return AE_OK;
1949}
1950
1951/**
2033/**
1952 * acpi_bus_trim - Remove ACPI device node and all of its descendants
1953 * @start: Root of the ACPI device nodes subtree to remove.
2034 * acpi_bus_trim - Detach scan handlers and drivers from ACPI device objects.
2035 * @adev: Root of the ACPI namespace scope to walk.
1954 *
1955 * Must be called under acpi_scan_lock.
1956 */
2036 *
2037 * Must be called under acpi_scan_lock.
2038 */
1957void acpi_bus_trim(struct acpi_device *start)
2039void acpi_bus_trim(struct acpi_device *adev)
1958{
2040{
2041 struct acpi_scan_handler *handler = adev->handler;
2042 struct acpi_device *child;
2043
2044 list_for_each_entry_reverse(child, &adev->children, node)
2045 acpi_bus_trim(child);
2046
2047 if (handler) {
2048 if (handler->detach)
2049 handler->detach(adev);
2050
2051 adev->handler = NULL;
2052 } else {
2053 device_release_driver(&adev->dev);
2054 }
1959 /*
2055 /*
1960 * Execute acpi_bus_device_detach() as a post-order callback to detach
1961 * all ACPI drivers from the device nodes being removed.
2056 * Most likely, the device is going away, so put it into D3cold before
2057 * that.
1962 */
2058 */
1963 acpi_walk_namespace(ACPI_TYPE_ANY, start->handle, ACPI_UINT32_MAX, NULL,
1964 acpi_bus_device_detach, NULL, NULL);
1965 acpi_bus_device_detach(start->handle, 0, NULL, NULL);
1966 /*
1967 * Execute acpi_bus_remove() as a post-order callback to remove device
1968 * nodes in the given namespace scope.
1969 */
1970 acpi_walk_namespace(ACPI_TYPE_ANY, start->handle, ACPI_UINT32_MAX, NULL,
1971 acpi_bus_remove, NULL, NULL);
1972 acpi_bus_remove(start->handle, 0, NULL, NULL);
2059 acpi_device_set_power(adev, ACPI_STATE_D3_COLD);
2060 adev->flags.initialized = false;
2061 adev->flags.visited = false;
1973}
1974EXPORT_SYMBOL_GPL(acpi_bus_trim);
1975
1976static int acpi_bus_scan_fixed(void)
1977{
1978 int result = 0;
1979
1980 /*

--- 61 unchanged lines hidden (view full) ---

2042 goto out;
2043
2044 result = acpi_bus_get_device(ACPI_ROOT_OBJECT, &acpi_root);
2045 if (result)
2046 goto out;
2047
2048 result = acpi_bus_scan_fixed();
2049 if (result) {
2062}
2063EXPORT_SYMBOL_GPL(acpi_bus_trim);
2064
2065static int acpi_bus_scan_fixed(void)
2066{
2067 int result = 0;
2068
2069 /*

--- 61 unchanged lines hidden (view full) ---

2131 goto out;
2132
2133 result = acpi_bus_get_device(ACPI_ROOT_OBJECT, &acpi_root);
2134 if (result)
2135 goto out;
2136
2137 result = acpi_bus_scan_fixed();
2138 if (result) {
2050 acpi_device_unregister(acpi_root);
2139 acpi_detach_data(acpi_root->handle, acpi_scan_drop_device);
2140 acpi_device_del(acpi_root);
2141 put_device(&acpi_root->dev);
2051 goto out;
2052 }
2053
2054 acpi_update_all_gpes();
2055
2142 goto out;
2143 }
2144
2145 acpi_update_all_gpes();
2146
2056 acpi_pci_root_hp_init();
2057
2058 out:
2059 mutex_unlock(&acpi_scan_lock);
2060 return result;
2061}
2147 out:
2148 mutex_unlock(&acpi_scan_lock);
2149 return result;
2150}