scan.c (ace8238b00eafd493b8dbcc7db813ed72b8b6e87) scan.c (a3b1b1ef78cd2ffb5d3a223465064dee05929dc3)
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>

--- 271 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
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>

--- 271 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
288static void acpi_bus_device_eject(void *context)
288static void acpi_bus_device_eject(struct acpi_device *device, u32 ost_src)
289{
289{
290 acpi_handle handle = context;
291 struct acpi_device *device = NULL;
290 acpi_handle handle = device->handle;
292 struct acpi_scan_handler *handler;
293 u32 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE;
294 int error;
295
296 lock_device_hotplug();
297 mutex_lock(&acpi_scan_lock);
298
291 struct acpi_scan_handler *handler;
292 u32 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE;
293 int error;
294
295 lock_device_hotplug();
296 mutex_lock(&acpi_scan_lock);
297
299 acpi_bus_get_device(handle, &device);
300 if (!device)
301 goto err_out;
302
303 handler = device->handler;
298 handler = device->handler;
304 if (!handler || !handler->hotplug.enabled)
299 if (!handler || !handler->hotplug.enabled) {
300 put_device(&device->dev);
305 goto err_support;
301 goto err_support;
302 }
306
303
307 acpi_evaluate_hotplug_ost(handle, ACPI_NOTIFY_EJECT_REQUEST,
308 ACPI_OST_SC_EJECT_IN_PROGRESS, NULL);
304 if (ost_src == ACPI_NOTIFY_EJECT_REQUEST)
305 acpi_evaluate_hotplug_ost(handle, ACPI_NOTIFY_EJECT_REQUEST,
306 ACPI_OST_SC_EJECT_IN_PROGRESS, NULL);
307
309 if (handler->hotplug.mode == AHM_CONTAINER)
310 kobject_uevent(&device->dev.kobj, KOBJ_OFFLINE);
311
308 if (handler->hotplug.mode == AHM_CONTAINER)
309 kobject_uevent(&device->dev.kobj, KOBJ_OFFLINE);
310
312 get_device(&device->dev);
313 error = acpi_scan_hot_remove(device);
314 if (error == -EPERM) {
315 goto err_support;
316 } else if (error) {
317 goto err_out;
318 }
319
320 out:
321 mutex_unlock(&acpi_scan_lock);
322 unlock_device_hotplug();
323 return;
324
325 err_support:
326 ost_code = ACPI_OST_SC_EJECT_NOT_SUPPORTED;
327 err_out:
311 error = acpi_scan_hot_remove(device);
312 if (error == -EPERM) {
313 goto err_support;
314 } else if (error) {
315 goto err_out;
316 }
317
318 out:
319 mutex_unlock(&acpi_scan_lock);
320 unlock_device_hotplug();
321 return;
322
323 err_support:
324 ost_code = ACPI_OST_SC_EJECT_NOT_SUPPORTED;
325 err_out:
328 acpi_evaluate_hotplug_ost(handle, ACPI_NOTIFY_EJECT_REQUEST, ost_code,
329 NULL);
326 acpi_evaluate_hotplug_ost(handle, ost_src, ost_code, NULL);
330 goto out;
331}
332
333static void acpi_scan_bus_device_check(acpi_handle handle, u32 ost_source)
334{
335 struct acpi_device *device = NULL;
336 u32 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE;
337 int error;

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

403 default:
404 /* non-hotplug event; possibly handled by other handler */
405 return;
406 }
407
408 acpi_evaluate_hotplug_ost(handle, type, ost_status, NULL);
409}
410
327 goto out;
328}
329
330static void acpi_scan_bus_device_check(acpi_handle handle, u32 ost_source)
331{
332 struct acpi_device *device = NULL;
333 u32 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE;
334 int error;

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

400 default:
401 /* non-hotplug event; possibly handled by other handler */
402 return;
403 }
404
405 acpi_evaluate_hotplug_ost(handle, type, ost_status, NULL);
406}
407
408/**
409 * acpi_bus_hot_remove_device: Hot-remove a device and its children.
410 * @context: Address of the ACPI device object to hot-remove.
411 */
412void acpi_bus_hot_remove_device(void *context)
413{
414 acpi_bus_device_eject(context, ACPI_NOTIFY_EJECT_REQUEST);
415}
416
411static void acpi_hotplug_notify_cb(acpi_handle handle, u32 type, void *data)
412{
413 acpi_osd_exec_callback callback;
414 struct acpi_scan_handler *handler = data;
417static void acpi_hotplug_notify_cb(acpi_handle handle, u32 type, void *data)
418{
419 acpi_osd_exec_callback callback;
420 struct acpi_scan_handler *handler = data;
421 struct acpi_device *adev;
415 acpi_status status;
416
417 if (!handler->hotplug.enabled)
418 return acpi_hotplug_unsupported(handle, type);
419
420 switch (type) {
421 case ACPI_NOTIFY_BUS_CHECK:
422 acpi_handle_debug(handle, "ACPI_NOTIFY_BUS_CHECK event\n");
423 callback = acpi_scan_bus_check;
424 break;
425 case ACPI_NOTIFY_DEVICE_CHECK:
426 acpi_handle_debug(handle, "ACPI_NOTIFY_DEVICE_CHECK event\n");
427 callback = acpi_scan_device_check;
428 break;
429 case ACPI_NOTIFY_EJECT_REQUEST:
430 acpi_handle_debug(handle, "ACPI_NOTIFY_EJECT_REQUEST event\n");
422 acpi_status status;
423
424 if (!handler->hotplug.enabled)
425 return acpi_hotplug_unsupported(handle, type);
426
427 switch (type) {
428 case ACPI_NOTIFY_BUS_CHECK:
429 acpi_handle_debug(handle, "ACPI_NOTIFY_BUS_CHECK event\n");
430 callback = acpi_scan_bus_check;
431 break;
432 case ACPI_NOTIFY_DEVICE_CHECK:
433 acpi_handle_debug(handle, "ACPI_NOTIFY_DEVICE_CHECK event\n");
434 callback = acpi_scan_device_check;
435 break;
436 case ACPI_NOTIFY_EJECT_REQUEST:
437 acpi_handle_debug(handle, "ACPI_NOTIFY_EJECT_REQUEST event\n");
431 callback = acpi_bus_device_eject;
432 break;
438 status = acpi_bus_get_device(handle, &adev);
439 if (ACPI_FAILURE(status))
440 goto err_out;
441
442 get_device(&adev->dev);
443 callback = acpi_bus_hot_remove_device;
444 status = acpi_os_hotplug_execute(callback, adev);
445 if (ACPI_SUCCESS(status))
446 return;
447
448 put_device(&adev->dev);
449 goto err_out;
433 default:
434 /* non-hotplug event; possibly handled by other handler */
435 return;
436 }
437 status = acpi_os_hotplug_execute(callback, handle);
450 default:
451 /* non-hotplug event; possibly handled by other handler */
452 return;
453 }
454 status = acpi_os_hotplug_execute(callback, handle);
438 if (ACPI_FAILURE(status))
439 acpi_evaluate_hotplug_ost(handle, type,
440 ACPI_OST_SC_NON_SPECIFIC_FAILURE,
441 NULL);
442}
455 if (ACPI_SUCCESS(status))
456 return;
443
457
444void __acpi_bus_hot_remove_device(struct acpi_device *device, u32 ost_src)
445{
446 acpi_handle handle = device->handle;
447 int error;
448
449 lock_device_hotplug();
450 mutex_lock(&acpi_scan_lock);
451
452 error = acpi_scan_hot_remove(device);
453 if (error && handle)
454 acpi_evaluate_hotplug_ost(handle, ost_src,
455 ACPI_OST_SC_NON_SPECIFIC_FAILURE,
456 NULL);
457
458 mutex_unlock(&acpi_scan_lock);
459 unlock_device_hotplug();
458 err_out:
459 acpi_evaluate_hotplug_ost(handle, type,
460 ACPI_OST_SC_NON_SPECIFIC_FAILURE, NULL);
460}
461
461}
462
462/**
463 * acpi_bus_hot_remove_device: Hot-remove a device and its children.
464 * @context: Address of the ACPI device object to hot-remove.
465 */
466void acpi_bus_hot_remove_device(void *context)
467{
468 __acpi_bus_hot_remove_device(context, ACPI_NOTIFY_EJECT_REQUEST);
469}
470
471static ssize_t real_power_state_show(struct device *dev,
472 struct device_attribute *attr, char *buf)
473{
474 struct acpi_device *adev = to_acpi_device(dev);
475 int state;
476 int ret;
477
478 ret = acpi_device_get_power(adev, &state);

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

491
492 return sprintf(buf, "%s\n", acpi_power_state_string(adev->power.state));
493}
494
495static DEVICE_ATTR(power_state, 0444, power_state_show, NULL);
496
497static void acpi_eject_store_work(void *context)
498{
463static ssize_t real_power_state_show(struct device *dev,
464 struct device_attribute *attr, char *buf)
465{
466 struct acpi_device *adev = to_acpi_device(dev);
467 int state;
468 int ret;
469
470 ret = acpi_device_get_power(adev, &state);

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

483
484 return sprintf(buf, "%s\n", acpi_power_state_string(adev->power.state));
485}
486
487static DEVICE_ATTR(power_state, 0444, power_state_show, NULL);
488
489static void acpi_eject_store_work(void *context)
490{
499 __acpi_bus_hot_remove_device(context, ACPI_OST_EC_OSPM_EJECT);
491 acpi_bus_device_eject(context, ACPI_OST_EC_OSPM_EJECT);
500}
501
502static ssize_t
503acpi_eject_store(struct device *d, struct device_attribute *attr,
504 const char *buf, size_t count)
505{
506 struct acpi_device *acpi_device = to_acpi_device(d);
507 acpi_object_type not_used;

--- 1598 unchanged lines hidden ---
492}
493
494static ssize_t
495acpi_eject_store(struct device *d, struct device_attribute *attr,
496 const char *buf, size_t count)
497{
498 struct acpi_device *acpi_device = to_acpi_device(d);
499 acpi_object_type not_used;

--- 1598 unchanged lines hidden ---