container.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * container.c - ACPI Generic Container Driver
  4. *
  5. * Copyright (C) 2004 Anil S Keshavamurthy ([email protected])
  6. * Copyright (C) 2004 Keiichiro Tokunaga ([email protected])
  7. * Copyright (C) 2004 Motoyuki Ito ([email protected])
  8. * Copyright (C) 2004 FUJITSU LIMITED
  9. * Copyright (C) 2004, 2013 Intel Corp.
  10. * Author: Rafael J. Wysocki <[email protected]>
  11. */
  12. #include <linux/acpi.h>
  13. #include <linux/container.h>
  14. #include "internal.h"
  15. static const struct acpi_device_id container_device_ids[] = {
  16. {"ACPI0004", 0},
  17. {"PNP0A05", 0},
  18. {"PNP0A06", 0},
  19. {"", 0},
  20. };
  21. #ifdef CONFIG_ACPI_CONTAINER
  22. static int check_offline(struct acpi_device *adev, void *not_used)
  23. {
  24. if (acpi_scan_is_offline(adev, false))
  25. return 0;
  26. return -EBUSY;
  27. }
  28. static int acpi_container_offline(struct container_dev *cdev)
  29. {
  30. /* Check all of the dependent devices' physical companions. */
  31. return acpi_dev_for_each_child(ACPI_COMPANION(&cdev->dev), check_offline, NULL);
  32. }
  33. static void acpi_container_release(struct device *dev)
  34. {
  35. kfree(to_container_dev(dev));
  36. }
  37. static int container_device_attach(struct acpi_device *adev,
  38. const struct acpi_device_id *not_used)
  39. {
  40. struct container_dev *cdev;
  41. struct device *dev;
  42. int ret;
  43. if (adev->flags.is_dock_station)
  44. return 0;
  45. cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
  46. if (!cdev)
  47. return -ENOMEM;
  48. cdev->offline = acpi_container_offline;
  49. dev = &cdev->dev;
  50. dev->bus = &container_subsys;
  51. dev_set_name(dev, "%s", dev_name(&adev->dev));
  52. ACPI_COMPANION_SET(dev, adev);
  53. dev->release = acpi_container_release;
  54. ret = device_register(dev);
  55. if (ret) {
  56. put_device(dev);
  57. return ret;
  58. }
  59. adev->driver_data = dev;
  60. return 1;
  61. }
  62. static void container_device_detach(struct acpi_device *adev)
  63. {
  64. struct device *dev = acpi_driver_data(adev);
  65. adev->driver_data = NULL;
  66. if (dev)
  67. device_unregister(dev);
  68. }
  69. static void container_device_online(struct acpi_device *adev)
  70. {
  71. struct device *dev = acpi_driver_data(adev);
  72. kobject_uevent(&dev->kobj, KOBJ_ONLINE);
  73. }
  74. static struct acpi_scan_handler container_handler = {
  75. .ids = container_device_ids,
  76. .attach = container_device_attach,
  77. .detach = container_device_detach,
  78. .hotplug = {
  79. .enabled = true,
  80. .demand_offline = true,
  81. .notify_online = container_device_online,
  82. },
  83. };
  84. void __init acpi_container_init(void)
  85. {
  86. acpi_scan_add_handler(&container_handler);
  87. }
  88. #else
  89. static struct acpi_scan_handler container_handler = {
  90. .ids = container_device_ids,
  91. };
  92. void __init acpi_container_init(void)
  93. {
  94. acpi_scan_add_handler_with_hotplug(&container_handler, "container");
  95. }
  96. #endif /* CONFIG_ACPI_CONTAINER */