proc: Supply a function to remove a proc entry by PDE
[linux-2.6.git] / drivers / acpi / container.c
blob5523ba7d764dff989c108f5262cbc283c95f329f
1 /*
2 * acpi_container.c - ACPI Generic Container Driver
3 * ($Revision: )
5 * Copyright (C) 2004 Anil S Keshavamurthy (anil.s.keshavamurthy@intel.com)
6 * Copyright (C) 2004 Keiichiro Tokunaga (tokunaga.keiich@jp.fujitsu.com)
7 * Copyright (C) 2004 Motoyuki Ito (motoyuki@soft.fujitsu.com)
8 * Copyright (C) 2004 Intel Corp.
9 * Copyright (C) 2004 FUJITSU LIMITED
11 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or (at
16 * your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * General Public License for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
27 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
29 #include <linux/kernel.h>
30 #include <linux/module.h>
31 #include <linux/init.h>
32 #include <linux/slab.h>
33 #include <linux/types.h>
34 #include <linux/acpi.h>
35 #include <acpi/acpi_bus.h>
36 #include <acpi/acpi_drivers.h>
38 #define PREFIX "ACPI: "
40 #define _COMPONENT ACPI_CONTAINER_COMPONENT
41 ACPI_MODULE_NAME("container");
43 static const struct acpi_device_id container_device_ids[] = {
44 {"ACPI0004", 0},
45 {"PNP0A05", 0},
46 {"PNP0A06", 0},
47 {"", 0},
50 static int container_device_attach(struct acpi_device *device,
51 const struct acpi_device_id *not_used)
54 * FIXME: This is necessary, so that acpi_eject_store() doesn't return
55 * -ENODEV for containers.
57 return 1;
60 static struct acpi_scan_handler container_device_handler = {
61 .ids = container_device_ids,
62 .attach = container_device_attach,
65 static int is_device_present(acpi_handle handle)
67 acpi_handle temp;
68 acpi_status status;
69 unsigned long long sta;
72 status = acpi_get_handle(handle, "_STA", &temp);
73 if (ACPI_FAILURE(status))
74 return 1; /* _STA not found, assume device present */
76 status = acpi_evaluate_integer(handle, "_STA", NULL, &sta);
77 if (ACPI_FAILURE(status))
78 return 0; /* Firmware error */
80 return ((sta & ACPI_STA_DEVICE_PRESENT) == ACPI_STA_DEVICE_PRESENT);
83 static void container_notify_cb(acpi_handle handle, u32 type, void *context)
85 struct acpi_device *device = NULL;
86 int result;
87 int present;
88 acpi_status status;
89 u32 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE; /* default */
91 acpi_scan_lock_acquire();
93 switch (type) {
94 case ACPI_NOTIFY_BUS_CHECK:
95 /* Fall through */
96 case ACPI_NOTIFY_DEVICE_CHECK:
97 pr_debug("Container driver received %s event\n",
98 (type == ACPI_NOTIFY_BUS_CHECK) ?
99 "ACPI_NOTIFY_BUS_CHECK" : "ACPI_NOTIFY_DEVICE_CHECK");
101 present = is_device_present(handle);
102 status = acpi_bus_get_device(handle, &device);
103 if (!present) {
104 if (ACPI_SUCCESS(status)) {
105 /* device exist and this is a remove request */
106 device->flags.eject_pending = 1;
107 kobject_uevent(&device->dev.kobj, KOBJ_OFFLINE);
108 goto out;
110 break;
113 if (!ACPI_FAILURE(status) || device)
114 break;
116 result = acpi_bus_scan(handle);
117 if (result) {
118 acpi_handle_warn(handle, "Failed to add container\n");
119 break;
121 result = acpi_bus_get_device(handle, &device);
122 if (result) {
123 acpi_handle_warn(handle, "Missing device object\n");
124 break;
127 kobject_uevent(&device->dev.kobj, KOBJ_ONLINE);
128 ost_code = ACPI_OST_SC_SUCCESS;
129 break;
131 case ACPI_NOTIFY_EJECT_REQUEST:
132 if (!acpi_bus_get_device(handle, &device) && device) {
133 device->flags.eject_pending = 1;
134 kobject_uevent(&device->dev.kobj, KOBJ_OFFLINE);
135 goto out;
137 break;
139 default:
140 /* non-hotplug event; possibly handled by other handler */
141 goto out;
144 /* Inform firmware that the hotplug operation has completed */
145 (void) acpi_evaluate_hotplug_ost(handle, type, ost_code, NULL);
147 out:
148 acpi_scan_lock_release();
151 static bool is_container(acpi_handle handle)
153 struct acpi_device_info *info;
154 bool ret = false;
156 if (ACPI_FAILURE(acpi_get_object_info(handle, &info)))
157 return false;
159 if (info->valid & ACPI_VALID_HID) {
160 const struct acpi_device_id *id;
162 for (id = container_device_ids; id->id[0]; id++) {
163 ret = !strcmp((char *)id->id, info->hardware_id.string);
164 if (ret)
165 break;
168 kfree(info);
169 return ret;
172 static acpi_status acpi_container_register_notify_handler(acpi_handle handle,
173 u32 lvl, void *ctxt,
174 void **retv)
176 if (is_container(handle))
177 acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
178 container_notify_cb, NULL);
180 return AE_OK;
183 void __init acpi_container_init(void)
185 acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
186 acpi_container_register_notify_handler, NULL,
187 NULL, NULL);
189 acpi_scan_add_handler(&container_device_handler);