diff options
Diffstat (limited to 'drivers/acpi/container.c')
-rw-r--r-- | drivers/acpi/container.c | 56 |
1 files changed, 51 insertions, 5 deletions
diff --git a/drivers/acpi/container.c b/drivers/acpi/container.c index e23151667655..368f9ddb8480 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,19 +43,66 @@ static const struct acpi_device_id container_device_ids[] = { | |||
44 | {"", 0}, | 43 | {"", 0}, |
45 | }; | 44 | }; |
46 | 45 | ||
47 | static int container_device_attach(struct acpi_device *device, | 46 | static 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 | |||
59 | static void acpi_container_release(struct device *dev) | ||
60 | { | ||
61 | kfree(to_container_dev(dev)); | ||
62 | } | ||
63 | |||
64 | static 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 | /* This is necessary for container hotplug to work. */ | 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 | put_device(dev); | ||
84 | return ret; | ||
85 | } | ||
86 | adev->driver_data = dev; | ||
51 | return 1; | 87 | return 1; |
52 | } | 88 | } |
53 | 89 | ||
90 | static void container_device_detach(struct acpi_device *adev) | ||
91 | { | ||
92 | struct device *dev = acpi_driver_data(adev); | ||
93 | |||
94 | adev->driver_data = NULL; | ||
95 | if (dev) | ||
96 | device_unregister(dev); | ||
97 | } | ||
98 | |||
54 | static struct acpi_scan_handler container_handler = { | 99 | static struct acpi_scan_handler container_handler = { |
55 | .ids = container_device_ids, | 100 | .ids = container_device_ids, |
56 | .attach = container_device_attach, | 101 | .attach = container_device_attach, |
102 | .detach = container_device_detach, | ||
57 | .hotplug = { | 103 | .hotplug = { |
58 | .enabled = true, | 104 | .enabled = true, |
59 | .mode = AHM_CONTAINER, | 105 | .demand_offline = true, |
60 | }, | 106 | }, |
61 | }; | 107 | }; |
62 | 108 | ||