diff options
Diffstat (limited to 'drivers/acpi/container.c')
-rw-r--r-- | drivers/acpi/container.c | 55 |
1 files changed, 50 insertions, 5 deletions
diff --git a/drivers/acpi/container.c b/drivers/acpi/container.c index e23151667655..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,19 +43,65 @@ 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 | return ret; | ||
84 | |||
85 | adev->driver_data = dev; | ||
51 | return 1; | 86 | return 1; |
52 | } | 87 | } |
53 | 88 | ||
89 | static void container_device_detach(struct acpi_device *adev) | ||
90 | { | ||
91 | struct device *dev = acpi_driver_data(adev); | ||
92 | |||
93 | adev->driver_data = NULL; | ||
94 | if (dev) | ||
95 | device_unregister(dev); | ||
96 | } | ||
97 | |||
54 | static struct acpi_scan_handler container_handler = { | 98 | static struct acpi_scan_handler container_handler = { |
55 | .ids = container_device_ids, | 99 | .ids = container_device_ids, |
56 | .attach = container_device_attach, | 100 | .attach = container_device_attach, |
101 | .detach = container_device_detach, | ||
57 | .hotplug = { | 102 | .hotplug = { |
58 | .enabled = true, | 103 | .enabled = true, |
59 | .mode = AHM_CONTAINER, | 104 | .demand_offline = true, |
60 | }, | 105 | }, |
61 | }; | 106 | }; |
62 | 107 | ||