aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/container.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi/container.c')
-rw-r--r--drivers/acpi/container.c48
1 files changed, 44 insertions, 4 deletions
diff --git a/drivers/acpi/container.c b/drivers/acpi/container.c
index 83d232c10f13..0b6ae6eb5c4a 100644
--- a/drivers/acpi/container.c
+++ b/drivers/acpi/container.c
@@ -27,8 +27,7 @@
27 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 27 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28 */ 28 */
29#include <linux/acpi.h> 29#include <linux/acpi.h>
30 30#include <linux/container.h>
31#include "internal.h"
32 31
33#include "internal.h" 32#include "internal.h"
34 33
@@ -44,16 +43,56 @@ static const struct acpi_device_id container_device_ids[] = {
44 {"", 0}, 43 {"", 0},
45}; 44};
46 45
46static int acpi_container_offline(struct container_dev *cdev)
47{
48 struct acpi_device *adev = ACPI_COMPANION(&cdev->dev);
49 struct acpi_device *child;
50
51 /* Check all of the dependent devices' physical companions. */
52 list_for_each_entry(child, &adev->children, node)
53 if (!acpi_scan_is_offline(child, false))
54 return -EBUSY;
55
56 return 0;
57}
58
59static void acpi_container_release(struct device *dev)
60{
61 kfree(to_container_dev(dev));
62}
63
47static int container_device_attach(struct acpi_device *adev, 64static int container_device_attach(struct acpi_device *adev,
48 const struct acpi_device_id *not_used) 65 const struct acpi_device_id *not_used)
49{ 66{
50 kobject_uevent(&adev->dev.kobj, KOBJ_ONLINE); 67 struct container_dev *cdev;
68 struct device *dev;
69 int ret;
70
71 cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
72 if (!cdev)
73 return -ENOMEM;
74
75 cdev->offline = acpi_container_offline;
76 dev = &cdev->dev;
77 dev->bus = &container_subsys;
78 dev_set_name(dev, "%s", dev_name(&adev->dev));
79 ACPI_COMPANION_SET(dev, adev);
80 dev->release = acpi_container_release;
81 ret = device_register(dev);
82 if (ret)
83 return ret;
84
85 adev->driver_data = dev;
51 return 1; 86 return 1;
52} 87}
53 88
54static void container_device_detach(struct acpi_device *adev) 89static void container_device_detach(struct acpi_device *adev)
55{ 90{
56 kobject_uevent(&adev->dev.kobj, KOBJ_OFFLINE); 91 struct device *dev = acpi_driver_data(adev);
92
93 adev->driver_data = NULL;
94 if (dev)
95 device_unregister(dev);
57} 96}
58 97
59static struct acpi_scan_handler container_handler = { 98static struct acpi_scan_handler container_handler = {
@@ -62,6 +101,7 @@ static struct acpi_scan_handler container_handler = {
62 .detach = container_device_detach, 101 .detach = container_device_detach,
63 .hotplug = { 102 .hotplug = {
64 .enabled = true, 103 .enabled = true,
104 .demand_offline = true,
65 }, 105 },
66}; 106};
67 107