blob: e49d327ccf4cd747c59dc4ddc34b088789472cf4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (C) 2004 Intel Corporation <naveen.b.s@intel.com>
3 *
4 * All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or (at
9 * your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
14 * NON INFRINGEMENT. See the GNU General Public License for more
15 * details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 *
21 *
22 * ACPI based HotPlug driver that supports Memory Hotplug
23 * This driver fields notifications from firmare for memory add
24 * and remove operations and alerts the VM of the affected memory
25 * ranges.
26 */
27
28#include <linux/kernel.h>
29#include <linux/module.h>
30#include <linux/init.h>
31#include <linux/types.h>
32#include <linux/memory_hotplug.h>
33#include <acpi/acpi_drivers.h>
34
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#define ACPI_MEMORY_DEVICE_COMPONENT 0x08000000UL
36#define ACPI_MEMORY_DEVICE_CLASS "memory"
37#define ACPI_MEMORY_DEVICE_HID "PNP0C80"
38#define ACPI_MEMORY_DEVICE_DRIVER_NAME "Hotplug Mem Driver"
39#define ACPI_MEMORY_DEVICE_NAME "Hotplug Mem Device"
40
41#define _COMPONENT ACPI_MEMORY_DEVICE_COMPONENT
42
Len Brown4be44fc2005-08-05 00:44:28 -040043ACPI_MODULE_NAME("acpi_memory")
44 MODULE_AUTHOR("Naveen B S <naveen.b.s@intel.com>");
Linus Torvalds1da177e2005-04-16 15:20:36 -070045MODULE_DESCRIPTION(ACPI_MEMORY_DEVICE_DRIVER_NAME);
46MODULE_LICENSE("GPL");
47
48/* ACPI _STA method values */
49#define ACPI_MEMORY_STA_PRESENT (0x00000001UL)
50#define ACPI_MEMORY_STA_ENABLED (0x00000002UL)
51#define ACPI_MEMORY_STA_FUNCTIONAL (0x00000008UL)
52
53/* Memory Device States */
54#define MEMORY_INVALID_STATE 0
55#define MEMORY_POWER_ON_STATE 1
56#define MEMORY_POWER_OFF_STATE 2
57
Len Brown4be44fc2005-08-05 00:44:28 -040058static int acpi_memory_device_add(struct acpi_device *device);
59static int acpi_memory_device_remove(struct acpi_device *device, int type);
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61static struct acpi_driver acpi_memory_device_driver = {
Len Brown4be44fc2005-08-05 00:44:28 -040062 .name = ACPI_MEMORY_DEVICE_DRIVER_NAME,
63 .class = ACPI_MEMORY_DEVICE_CLASS,
64 .ids = ACPI_MEMORY_DEVICE_HID,
65 .ops = {
66 .add = acpi_memory_device_add,
67 .remove = acpi_memory_device_remove,
68 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070069};
70
71struct acpi_memory_device {
72 acpi_handle handle;
Len Brown4be44fc2005-08-05 00:44:28 -040073 unsigned int state; /* State of the memory device */
KAMEZAWA Hiroyuki3963f002006-01-06 01:31:00 -050074 unsigned short caching; /* memory cache attribute */
75 unsigned short write_protect; /* memory read/write attribute */
Len Brown4be44fc2005-08-05 00:44:28 -040076 u64 start_addr; /* Memory Range start physical addr */
Bjorn Helgaas459c7262006-03-28 17:04:00 -050077 u64 length; /* Memory Range length */
Linus Torvalds1da177e2005-04-16 15:20:36 -070078};
79
Linus Torvalds1da177e2005-04-16 15:20:36 -070080static int
81acpi_memory_get_device_resources(struct acpi_memory_device *mem_device)
82{
83 acpi_status status;
Len Brown4be44fc2005-08-05 00:44:28 -040084 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 struct acpi_resource *resource = NULL;
86 struct acpi_resource_address64 address64;
87
88 ACPI_FUNCTION_TRACE("acpi_memory_get_device_resources");
89
90 /* Get the range from the _CRS */
91 status = acpi_get_current_resources(mem_device->handle, &buffer);
92 if (ACPI_FAILURE(status))
93 return_VALUE(-EINVAL);
94
Len Brown4be44fc2005-08-05 00:44:28 -040095 resource = (struct acpi_resource *)buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 status = acpi_resource_to_address64(resource, &address64);
97 if (ACPI_SUCCESS(status)) {
98 if (address64.resource_type == ACPI_MEMORY_RANGE) {
99 /* Populate the structure */
Bjorn Helgaas459c7262006-03-28 17:04:00 -0500100 mem_device->caching = address64.info.mem.caching;
KAMEZAWA Hiroyuki3963f002006-01-06 01:31:00 -0500101 mem_device->write_protect =
102 address64.info.mem.write_protect;
Bob Moore50eca3e2005-09-30 19:03:00 -0400103 mem_device->start_addr = address64.minimum;
Bjorn Helgaas459c7262006-03-28 17:04:00 -0500104 mem_device->length = address64.address_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 }
106 }
107
108 acpi_os_free(buffer.pointer);
109 return_VALUE(0);
110}
111
112static int
113acpi_memory_get_device(acpi_handle handle,
Len Brown4be44fc2005-08-05 00:44:28 -0400114 struct acpi_memory_device **mem_device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115{
116 acpi_status status;
117 acpi_handle phandle;
118 struct acpi_device *device = NULL;
119 struct acpi_device *pdevice = NULL;
120
121 ACPI_FUNCTION_TRACE("acpi_memory_get_device");
122
123 if (!acpi_bus_get_device(handle, &device) && device)
124 goto end;
125
126 status = acpi_get_parent(handle, &phandle);
127 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400128 ACPI_EXCEPTION((AE_INFO, status, "Cannot find acpi parent"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 return_VALUE(-EINVAL);
130 }
131
132 /* Get the parent device */
133 status = acpi_bus_get_device(phandle, &pdevice);
134 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400135 ACPI_EXCEPTION((AE_INFO, status, "Cannot get acpi bus device"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 return_VALUE(-EINVAL);
137 }
138
139 /*
140 * Now add the notified device. This creates the acpi_device
141 * and invokes .add function
142 */
143 status = acpi_bus_add(&device, pdevice, handle, ACPI_BUS_TYPE_DEVICE);
144 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400145 ACPI_EXCEPTION((AE_INFO, status, "Cannot add acpi bus"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 return_VALUE(-EINVAL);
147 }
148
Len Brown4be44fc2005-08-05 00:44:28 -0400149 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 *mem_device = acpi_driver_data(device);
151 if (!(*mem_device)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400152 printk(KERN_ERR "\n driver data not found");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 return_VALUE(-ENODEV);
154 }
155
156 return_VALUE(0);
157}
158
Len Brown4be44fc2005-08-05 00:44:28 -0400159static int acpi_memory_check_device(struct acpi_memory_device *mem_device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160{
161 unsigned long current_status;
162
163 ACPI_FUNCTION_TRACE("acpi_memory_check_device");
164
165 /* Get device present/absent information from the _STA */
166 if (ACPI_FAILURE(acpi_evaluate_integer(mem_device->handle, "_STA",
Len Brown4be44fc2005-08-05 00:44:28 -0400167 NULL, &current_status)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 return_VALUE(-ENODEV);
169 /*
170 * Check for device status. Device should be
171 * present/enabled/functioning.
172 */
173 if (!((current_status & ACPI_MEMORY_STA_PRESENT)
Len Brown4be44fc2005-08-05 00:44:28 -0400174 && (current_status & ACPI_MEMORY_STA_ENABLED)
175 && (current_status & ACPI_MEMORY_STA_FUNCTIONAL)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 return_VALUE(-ENODEV);
177
178 return_VALUE(0);
179}
180
Len Brown4be44fc2005-08-05 00:44:28 -0400181static int acpi_memory_enable_device(struct acpi_memory_device *mem_device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182{
183 int result;
184
185 ACPI_FUNCTION_TRACE("acpi_memory_enable_device");
186
187 /* Get the range from the _CRS */
188 result = acpi_memory_get_device_resources(mem_device);
189 if (result) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400190 ACPI_ERROR((AE_INFO, "get_device_resources failed"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 mem_device->state = MEMORY_INVALID_STATE;
192 return result;
193 }
194
195 /*
196 * Tell the VM there is more memory here...
197 * Note: Assume that this function returns zero on success
198 */
Bjorn Helgaas459c7262006-03-28 17:04:00 -0500199 result = add_memory(mem_device->start_addr, mem_device->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 if (result) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400201 ACPI_ERROR((AE_INFO, "add_memory failed"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 mem_device->state = MEMORY_INVALID_STATE;
203 return result;
204 }
205
206 return result;
207}
208
Len Brown4be44fc2005-08-05 00:44:28 -0400209static int acpi_memory_powerdown_device(struct acpi_memory_device *mem_device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210{
211 acpi_status status;
Len Brown4be44fc2005-08-05 00:44:28 -0400212 struct acpi_object_list arg_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 union acpi_object arg;
214 unsigned long current_status;
215
216 ACPI_FUNCTION_TRACE("acpi_memory_powerdown_device");
217
218 /* Issue the _EJ0 command */
219 arg_list.count = 1;
220 arg_list.pointer = &arg;
221 arg.type = ACPI_TYPE_INTEGER;
222 arg.integer.value = 1;
223 status = acpi_evaluate_object(mem_device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -0400224 "_EJ0", &arg_list, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 /* Return on _EJ0 failure */
226 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400227 ACPI_EXCEPTION((AE_INFO, status, "_EJ0 failed"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 return_VALUE(-ENODEV);
229 }
230
231 /* Evalute _STA to check if the device is disabled */
232 status = acpi_evaluate_integer(mem_device->handle, "_STA",
Len Brown4be44fc2005-08-05 00:44:28 -0400233 NULL, &current_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 if (ACPI_FAILURE(status))
235 return_VALUE(-ENODEV);
236
237 /* Check for device status. Device should be disabled */
238 if (current_status & ACPI_MEMORY_STA_ENABLED)
239 return_VALUE(-EINVAL);
240
241 return_VALUE(0);
242}
243
Len Brown4be44fc2005-08-05 00:44:28 -0400244static int acpi_memory_disable_device(struct acpi_memory_device *mem_device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245{
246 int result;
247 u64 start = mem_device->start_addr;
Bjorn Helgaas459c7262006-03-28 17:04:00 -0500248 u64 len = mem_device->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
250 ACPI_FUNCTION_TRACE("acpi_memory_disable_device");
251
252 /*
253 * Ask the VM to offline this memory range.
254 * Note: Assume that this function returns zero on success
255 */
Dave Hansen0b0acbe2005-10-29 18:16:55 -0700256 result = remove_memory(start, len);
Thomas Renningera6fc6722006-06-26 23:58:43 -0400257 if (result)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 return_VALUE(result);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
260 /* Power-off and eject the device */
261 result = acpi_memory_powerdown_device(mem_device);
262 if (result) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 /* Set the status of the device to invalid */
264 mem_device->state = MEMORY_INVALID_STATE;
265 return result;
266 }
267
268 mem_device->state = MEMORY_POWER_OFF_STATE;
269 return result;
270}
271
Len Brown4be44fc2005-08-05 00:44:28 -0400272static void acpi_memory_device_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273{
274 struct acpi_memory_device *mem_device;
275 struct acpi_device *device;
276
277 ACPI_FUNCTION_TRACE("acpi_memory_device_notify");
278
279 switch (event) {
280 case ACPI_NOTIFY_BUS_CHECK:
281 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400282 "\nReceived BUS CHECK notification for device\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 /* Fall Through */
284 case ACPI_NOTIFY_DEVICE_CHECK:
285 if (event == ACPI_NOTIFY_DEVICE_CHECK)
286 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400287 "\nReceived DEVICE CHECK notification for device\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 if (acpi_memory_get_device(handle, &mem_device)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400289 ACPI_ERROR((AE_INFO, "Cannot find driver data"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 return_VOID;
291 }
292
293 if (!acpi_memory_check_device(mem_device)) {
294 if (acpi_memory_enable_device(mem_device))
Thomas Renningera6fc6722006-06-26 23:58:43 -0400295 ACPI_ERROR((AE_INFO,
296 "Cannot enable memory device"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 }
298 break;
299 case ACPI_NOTIFY_EJECT_REQUEST:
300 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400301 "\nReceived EJECT REQUEST notification for device\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
303 if (acpi_bus_get_device(handle, &device)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400304 ACPI_ERROR((AE_INFO, "Device doesn't exist"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 break;
306 }
307 mem_device = acpi_driver_data(device);
308 if (!mem_device) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400309 ACPI_ERROR((AE_INFO, "Driver Data is NULL"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 break;
311 }
312
313 /*
314 * Currently disabling memory device from kernel mode
315 * TBD: Can also be disabled from user mode scripts
316 * TBD: Can also be disabled by Callback registration
Len Brown4be44fc2005-08-05 00:44:28 -0400317 * with generic sysfs driver
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 */
319 if (acpi_memory_disable_device(mem_device))
Thomas Renningera6fc6722006-06-26 23:58:43 -0400320 ACPI_ERROR((AE_INFO,
321 "Disable memory device\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 /*
323 * TBD: Invoke acpi_bus_remove to cleanup data structures
324 */
325 break;
326 default:
327 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400328 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 break;
330 }
331
332 return_VOID;
333}
334
Len Brown4be44fc2005-08-05 00:44:28 -0400335static int acpi_memory_device_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336{
337 int result;
338 struct acpi_memory_device *mem_device = NULL;
339
340 ACPI_FUNCTION_TRACE("acpi_memory_device_add");
341
342 if (!device)
343 return_VALUE(-EINVAL);
344
345 mem_device = kmalloc(sizeof(struct acpi_memory_device), GFP_KERNEL);
346 if (!mem_device)
347 return_VALUE(-ENOMEM);
348 memset(mem_device, 0, sizeof(struct acpi_memory_device));
349
350 mem_device->handle = device->handle;
351 sprintf(acpi_device_name(device), "%s", ACPI_MEMORY_DEVICE_NAME);
352 sprintf(acpi_device_class(device), "%s", ACPI_MEMORY_DEVICE_CLASS);
353 acpi_driver_data(device) = mem_device;
354
355 /* Get the range from the _CRS */
356 result = acpi_memory_get_device_resources(mem_device);
357 if (result) {
358 kfree(mem_device);
359 return_VALUE(result);
360 }
361
362 /* Set the device state */
363 mem_device->state = MEMORY_POWER_ON_STATE;
364
365 printk(KERN_INFO "%s \n", acpi_device_name(device));
366
367 return_VALUE(result);
368}
369
Len Brown4be44fc2005-08-05 00:44:28 -0400370static int acpi_memory_device_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371{
372 struct acpi_memory_device *mem_device = NULL;
373
374 ACPI_FUNCTION_TRACE("acpi_memory_device_remove");
375
376 if (!device || !acpi_driver_data(device))
377 return_VALUE(-EINVAL);
378
Len Brown4be44fc2005-08-05 00:44:28 -0400379 mem_device = (struct acpi_memory_device *)acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 kfree(mem_device);
381
382 return_VALUE(0);
383}
384
385/*
386 * Helper function to check for memory device
387 */
Len Brown4be44fc2005-08-05 00:44:28 -0400388static acpi_status is_memory_device(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389{
390 char *hardware_id;
391 acpi_status status;
Len Brown4be44fc2005-08-05 00:44:28 -0400392 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 struct acpi_device_info *info;
394
395 ACPI_FUNCTION_TRACE("is_memory_device");
396
397 status = acpi_get_object_info(handle, &buffer);
398 if (ACPI_FAILURE(status))
Thomas Renningera6fc6722006-06-26 23:58:43 -0400399 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
401 info = buffer.pointer;
402 if (!(info->valid & ACPI_VALID_HID)) {
403 acpi_os_free(buffer.pointer);
404 return_ACPI_STATUS(AE_ERROR);
405 }
406
407 hardware_id = info->hardware_id.value;
408 if ((hardware_id == NULL) ||
Len Brown4be44fc2005-08-05 00:44:28 -0400409 (strcmp(hardware_id, ACPI_MEMORY_DEVICE_HID)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 status = AE_ERROR;
411
412 acpi_os_free(buffer.pointer);
413 return_ACPI_STATUS(status);
414}
415
416static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400417acpi_memory_register_notify_handler(acpi_handle handle,
418 u32 level, void *ctxt, void **retv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419{
420 acpi_status status;
421
422 ACPI_FUNCTION_TRACE("acpi_memory_register_notify_handler");
423
424 status = is_memory_device(handle);
Thomas Renningera6fc6722006-06-26 23:58:43 -0400425 if (ACPI_FAILURE(status)){
426 ACPI_EXCEPTION((AE_INFO, status, "handle is no memory device"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 return_ACPI_STATUS(AE_OK); /* continue */
428 }
429
Thomas Renningera6fc6722006-06-26 23:58:43 -0400430 status = acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
431 acpi_memory_device_notify, NULL);
432 /* continue */
433 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434}
435
436static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400437acpi_memory_deregister_notify_handler(acpi_handle handle,
438 u32 level, void *ctxt, void **retv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439{
440 acpi_status status;
441
442 ACPI_FUNCTION_TRACE("acpi_memory_deregister_notify_handler");
443
444 status = is_memory_device(handle);
Thomas Renningera6fc6722006-06-26 23:58:43 -0400445 if (ACPI_FAILURE(status)){
446 ACPI_EXCEPTION((AE_INFO, status, "handle is no memory device"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 return_ACPI_STATUS(AE_OK); /* continue */
Thomas Renningera6fc6722006-06-26 23:58:43 -0400448 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
450 status = acpi_remove_notify_handler(handle,
Len Brown4be44fc2005-08-05 00:44:28 -0400451 ACPI_SYSTEM_NOTIFY,
452 acpi_memory_device_notify);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453
Thomas Renningera6fc6722006-06-26 23:58:43 -0400454 return_ACPI_STATUS(AE_OK); /* continue */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455}
456
Len Brown4be44fc2005-08-05 00:44:28 -0400457static int __init acpi_memory_device_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458{
459 int result;
460 acpi_status status;
461
462 ACPI_FUNCTION_TRACE("acpi_memory_device_init");
463
464 result = acpi_bus_register_driver(&acpi_memory_device_driver);
465
466 if (result < 0)
467 return_VALUE(-ENODEV);
468
469 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
Len Brown4be44fc2005-08-05 00:44:28 -0400470 ACPI_UINT32_MAX,
471 acpi_memory_register_notify_handler,
472 NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473
Len Brown4be44fc2005-08-05 00:44:28 -0400474 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400475 ACPI_EXCEPTION((AE_INFO, status, "walk_namespace failed"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 acpi_bus_unregister_driver(&acpi_memory_device_driver);
477 return_VALUE(-ENODEV);
Len Brown4be44fc2005-08-05 00:44:28 -0400478 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
480 return_VALUE(0);
481}
482
Len Brown4be44fc2005-08-05 00:44:28 -0400483static void __exit acpi_memory_device_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484{
485 acpi_status status;
486
487 ACPI_FUNCTION_TRACE("acpi_memory_device_exit");
488
489 /*
490 * Adding this to un-install notification handlers for all the device
491 * handles.
492 */
493 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
Len Brown4be44fc2005-08-05 00:44:28 -0400494 ACPI_UINT32_MAX,
495 acpi_memory_deregister_notify_handler,
496 NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497
Len Brown4be44fc2005-08-05 00:44:28 -0400498 if (ACPI_FAILURE(status))
Thomas Renningera6fc6722006-06-26 23:58:43 -0400499 ACPI_EXCEPTION((AE_INFO, status, "walk_namespace failed"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500
501 acpi_bus_unregister_driver(&acpi_memory_device_driver);
502
503 return_VOID;
504}
505
506module_init(acpi_memory_device_init);
507module_exit(acpi_memory_device_exit);