blob: 01a1bd239263bcaa416050ae8184482e1ebbc9e8 [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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 unsigned short cache_attribute; /* memory cache attribute */
Len Brown4be44fc2005-08-05 00:44:28 -040075 unsigned short read_write_attribute; /* memory read/write attribute */
76 u64 start_addr; /* Memory Range start physical addr */
77 u64 end_addr; /* Memory Range end physical addr */
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 */
100 mem_device->cache_attribute =
Len Brown4be44fc2005-08-05 00:44:28 -0400101 address64.attribute.memory.cache_attribute;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 mem_device->read_write_attribute =
Len Brown4be44fc2005-08-05 00:44:28 -0400103 address64.attribute.memory.read_write_attribute;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 mem_device->start_addr = address64.min_address_range;
105 mem_device->end_addr = address64.max_address_range;
106 }
107 }
108
109 acpi_os_free(buffer.pointer);
110 return_VALUE(0);
111}
112
113static int
114acpi_memory_get_device(acpi_handle handle,
Len Brown4be44fc2005-08-05 00:44:28 -0400115 struct acpi_memory_device **mem_device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116{
117 acpi_status status;
118 acpi_handle phandle;
119 struct acpi_device *device = NULL;
120 struct acpi_device *pdevice = NULL;
121
122 ACPI_FUNCTION_TRACE("acpi_memory_get_device");
123
124 if (!acpi_bus_get_device(handle, &device) && device)
125 goto end;
126
127 status = acpi_get_parent(handle, &phandle);
128 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400129 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error in acpi_get_parent\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 return_VALUE(-EINVAL);
131 }
132
133 /* Get the parent device */
134 status = acpi_bus_get_device(phandle, &pdevice);
135 if (ACPI_FAILURE(status)) {
136 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -0400137 "Error in acpi_bus_get_device\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 return_VALUE(-EINVAL);
139 }
140
141 /*
142 * Now add the notified device. This creates the acpi_device
143 * and invokes .add function
144 */
145 status = acpi_bus_add(&device, pdevice, handle, ACPI_BUS_TYPE_DEVICE);
146 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400147 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error in acpi_bus_add\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 return_VALUE(-EINVAL);
149 }
150
Len Brown4be44fc2005-08-05 00:44:28 -0400151 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 *mem_device = acpi_driver_data(device);
153 if (!(*mem_device)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400154 printk(KERN_ERR "\n driver data not found");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 return_VALUE(-ENODEV);
156 }
157
158 return_VALUE(0);
159}
160
Len Brown4be44fc2005-08-05 00:44:28 -0400161static int acpi_memory_check_device(struct acpi_memory_device *mem_device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162{
163 unsigned long current_status;
164
165 ACPI_FUNCTION_TRACE("acpi_memory_check_device");
166
167 /* Get device present/absent information from the _STA */
168 if (ACPI_FAILURE(acpi_evaluate_integer(mem_device->handle, "_STA",
Len Brown4be44fc2005-08-05 00:44:28 -0400169 NULL, &current_status)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 return_VALUE(-ENODEV);
171 /*
172 * Check for device status. Device should be
173 * present/enabled/functioning.
174 */
175 if (!((current_status & ACPI_MEMORY_STA_PRESENT)
Len Brown4be44fc2005-08-05 00:44:28 -0400176 && (current_status & ACPI_MEMORY_STA_ENABLED)
177 && (current_status & ACPI_MEMORY_STA_FUNCTIONAL)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 return_VALUE(-ENODEV);
179
180 return_VALUE(0);
181}
182
Len Brown4be44fc2005-08-05 00:44:28 -0400183static int acpi_memory_enable_device(struct acpi_memory_device *mem_device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184{
185 int result;
186
187 ACPI_FUNCTION_TRACE("acpi_memory_enable_device");
188
189 /* Get the range from the _CRS */
190 result = acpi_memory_get_device_resources(mem_device);
191 if (result) {
192 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -0400193 "\nget_device_resources failed\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 mem_device->state = MEMORY_INVALID_STATE;
195 return result;
196 }
197
198 /*
199 * Tell the VM there is more memory here...
200 * Note: Assume that this function returns zero on success
201 */
202 result = add_memory(mem_device->start_addr,
Len Brown4be44fc2005-08-05 00:44:28 -0400203 (mem_device->end_addr - mem_device->start_addr) + 1,
204 mem_device->read_write_attribute);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 if (result) {
Len Brown4be44fc2005-08-05 00:44:28 -0400206 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "\nadd_memory failed\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 mem_device->state = MEMORY_INVALID_STATE;
208 return result;
209 }
210
211 return result;
212}
213
Len Brown4be44fc2005-08-05 00:44:28 -0400214static int acpi_memory_powerdown_device(struct acpi_memory_device *mem_device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215{
216 acpi_status status;
Len Brown4be44fc2005-08-05 00:44:28 -0400217 struct acpi_object_list arg_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 union acpi_object arg;
219 unsigned long current_status;
220
221 ACPI_FUNCTION_TRACE("acpi_memory_powerdown_device");
222
223 /* Issue the _EJ0 command */
224 arg_list.count = 1;
225 arg_list.pointer = &arg;
226 arg.type = ACPI_TYPE_INTEGER;
227 arg.integer.value = 1;
228 status = acpi_evaluate_object(mem_device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -0400229 "_EJ0", &arg_list, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 /* Return on _EJ0 failure */
231 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400232 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "_EJ0 failed.\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 return_VALUE(-ENODEV);
234 }
235
236 /* Evalute _STA to check if the device is disabled */
237 status = acpi_evaluate_integer(mem_device->handle, "_STA",
Len Brown4be44fc2005-08-05 00:44:28 -0400238 NULL, &current_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 if (ACPI_FAILURE(status))
240 return_VALUE(-ENODEV);
241
242 /* Check for device status. Device should be disabled */
243 if (current_status & ACPI_MEMORY_STA_ENABLED)
244 return_VALUE(-EINVAL);
245
246 return_VALUE(0);
247}
248
Len Brown4be44fc2005-08-05 00:44:28 -0400249static int acpi_memory_disable_device(struct acpi_memory_device *mem_device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250{
251 int result;
252 u64 start = mem_device->start_addr;
253 u64 len = mem_device->end_addr - start + 1;
254 unsigned long attr = mem_device->read_write_attribute;
255
256 ACPI_FUNCTION_TRACE("acpi_memory_disable_device");
257
258 /*
259 * Ask the VM to offline this memory range.
260 * Note: Assume that this function returns zero on success
261 */
262 result = remove_memory(start, len, attr);
263 if (result) {
264 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Hot-Remove failed.\n"));
265 return_VALUE(result);
266 }
267
268 /* Power-off and eject the device */
269 result = acpi_memory_powerdown_device(mem_device);
270 if (result) {
271 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -0400272 "Device Power Down failed.\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 /* Set the status of the device to invalid */
274 mem_device->state = MEMORY_INVALID_STATE;
275 return result;
276 }
277
278 mem_device->state = MEMORY_POWER_OFF_STATE;
279 return result;
280}
281
Len Brown4be44fc2005-08-05 00:44:28 -0400282static void acpi_memory_device_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283{
284 struct acpi_memory_device *mem_device;
285 struct acpi_device *device;
286
287 ACPI_FUNCTION_TRACE("acpi_memory_device_notify");
288
289 switch (event) {
290 case ACPI_NOTIFY_BUS_CHECK:
291 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400292 "\nReceived BUS CHECK notification for device\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 /* Fall Through */
294 case ACPI_NOTIFY_DEVICE_CHECK:
295 if (event == ACPI_NOTIFY_DEVICE_CHECK)
296 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400297 "\nReceived DEVICE CHECK notification for device\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 if (acpi_memory_get_device(handle, &mem_device)) {
299 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -0400300 "Error in finding driver data\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 return_VOID;
302 }
303
304 if (!acpi_memory_check_device(mem_device)) {
305 if (acpi_memory_enable_device(mem_device))
306 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -0400307 "Error in acpi_memory_enable_device\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 }
309 break;
310 case ACPI_NOTIFY_EJECT_REQUEST:
311 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400312 "\nReceived EJECT REQUEST notification for device\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
314 if (acpi_bus_get_device(handle, &device)) {
315 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -0400316 "Device doesn't exist\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 break;
318 }
319 mem_device = acpi_driver_data(device);
320 if (!mem_device) {
321 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -0400322 "Driver Data is NULL\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 break;
324 }
325
326 /*
327 * Currently disabling memory device from kernel mode
328 * TBD: Can also be disabled from user mode scripts
329 * TBD: Can also be disabled by Callback registration
Len Brown4be44fc2005-08-05 00:44:28 -0400330 * with generic sysfs driver
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 */
332 if (acpi_memory_disable_device(mem_device))
333 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -0400334 "Error in acpi_memory_disable_device\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 /*
336 * TBD: Invoke acpi_bus_remove to cleanup data structures
337 */
338 break;
339 default:
340 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400341 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 break;
343 }
344
345 return_VOID;
346}
347
Len Brown4be44fc2005-08-05 00:44:28 -0400348static int acpi_memory_device_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349{
350 int result;
351 struct acpi_memory_device *mem_device = NULL;
352
353 ACPI_FUNCTION_TRACE("acpi_memory_device_add");
354
355 if (!device)
356 return_VALUE(-EINVAL);
357
358 mem_device = kmalloc(sizeof(struct acpi_memory_device), GFP_KERNEL);
359 if (!mem_device)
360 return_VALUE(-ENOMEM);
361 memset(mem_device, 0, sizeof(struct acpi_memory_device));
362
363 mem_device->handle = device->handle;
364 sprintf(acpi_device_name(device), "%s", ACPI_MEMORY_DEVICE_NAME);
365 sprintf(acpi_device_class(device), "%s", ACPI_MEMORY_DEVICE_CLASS);
366 acpi_driver_data(device) = mem_device;
367
368 /* Get the range from the _CRS */
369 result = acpi_memory_get_device_resources(mem_device);
370 if (result) {
371 kfree(mem_device);
372 return_VALUE(result);
373 }
374
375 /* Set the device state */
376 mem_device->state = MEMORY_POWER_ON_STATE;
377
378 printk(KERN_INFO "%s \n", acpi_device_name(device));
379
380 return_VALUE(result);
381}
382
Len Brown4be44fc2005-08-05 00:44:28 -0400383static int acpi_memory_device_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384{
385 struct acpi_memory_device *mem_device = NULL;
386
387 ACPI_FUNCTION_TRACE("acpi_memory_device_remove");
388
389 if (!device || !acpi_driver_data(device))
390 return_VALUE(-EINVAL);
391
Len Brown4be44fc2005-08-05 00:44:28 -0400392 mem_device = (struct acpi_memory_device *)acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 kfree(mem_device);
394
395 return_VALUE(0);
396}
397
398/*
399 * Helper function to check for memory device
400 */
Len Brown4be44fc2005-08-05 00:44:28 -0400401static acpi_status is_memory_device(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402{
403 char *hardware_id;
404 acpi_status status;
Len Brown4be44fc2005-08-05 00:44:28 -0400405 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 struct acpi_device_info *info;
407
408 ACPI_FUNCTION_TRACE("is_memory_device");
409
410 status = acpi_get_object_info(handle, &buffer);
411 if (ACPI_FAILURE(status))
412 return_ACPI_STATUS(AE_ERROR);
413
414 info = buffer.pointer;
415 if (!(info->valid & ACPI_VALID_HID)) {
416 acpi_os_free(buffer.pointer);
417 return_ACPI_STATUS(AE_ERROR);
418 }
419
420 hardware_id = info->hardware_id.value;
421 if ((hardware_id == NULL) ||
Len Brown4be44fc2005-08-05 00:44:28 -0400422 (strcmp(hardware_id, ACPI_MEMORY_DEVICE_HID)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 status = AE_ERROR;
424
425 acpi_os_free(buffer.pointer);
426 return_ACPI_STATUS(status);
427}
428
429static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400430acpi_memory_register_notify_handler(acpi_handle handle,
431 u32 level, void *ctxt, void **retv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432{
433 acpi_status status;
434
435 ACPI_FUNCTION_TRACE("acpi_memory_register_notify_handler");
436
437 status = is_memory_device(handle);
438 if (ACPI_FAILURE(status))
439 return_ACPI_STATUS(AE_OK); /* continue */
440
441 status = acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
Len Brown4be44fc2005-08-05 00:44:28 -0400442 acpi_memory_device_notify, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 if (ACPI_FAILURE(status)) {
444 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -0400445 "Error installing notify handler\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 return_ACPI_STATUS(AE_OK); /* continue */
447 }
448
449 return_ACPI_STATUS(status);
450}
451
452static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400453acpi_memory_deregister_notify_handler(acpi_handle handle,
454 u32 level, void *ctxt, void **retv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455{
456 acpi_status status;
457
458 ACPI_FUNCTION_TRACE("acpi_memory_deregister_notify_handler");
459
460 status = is_memory_device(handle);
461 if (ACPI_FAILURE(status))
462 return_ACPI_STATUS(AE_OK); /* continue */
463
464 status = acpi_remove_notify_handler(handle,
Len Brown4be44fc2005-08-05 00:44:28 -0400465 ACPI_SYSTEM_NOTIFY,
466 acpi_memory_device_notify);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 if (ACPI_FAILURE(status)) {
468 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -0400469 "Error removing notify handler\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 return_ACPI_STATUS(AE_OK); /* continue */
471 }
472
473 return_ACPI_STATUS(status);
474}
475
Len Brown4be44fc2005-08-05 00:44:28 -0400476static int __init acpi_memory_device_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477{
478 int result;
479 acpi_status status;
480
481 ACPI_FUNCTION_TRACE("acpi_memory_device_init");
482
483 result = acpi_bus_register_driver(&acpi_memory_device_driver);
484
485 if (result < 0)
486 return_VALUE(-ENODEV);
487
488 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
Len Brown4be44fc2005-08-05 00:44:28 -0400489 ACPI_UINT32_MAX,
490 acpi_memory_register_notify_handler,
491 NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
Len Brown4be44fc2005-08-05 00:44:28 -0400493 if (ACPI_FAILURE(status)) {
494 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "walk_namespace failed\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 acpi_bus_unregister_driver(&acpi_memory_device_driver);
496 return_VALUE(-ENODEV);
Len Brown4be44fc2005-08-05 00:44:28 -0400497 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498
499 return_VALUE(0);
500}
501
Len Brown4be44fc2005-08-05 00:44:28 -0400502static void __exit acpi_memory_device_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503{
504 acpi_status status;
505
506 ACPI_FUNCTION_TRACE("acpi_memory_device_exit");
507
508 /*
509 * Adding this to un-install notification handlers for all the device
510 * handles.
511 */
512 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
Len Brown4be44fc2005-08-05 00:44:28 -0400513 ACPI_UINT32_MAX,
514 acpi_memory_deregister_notify_handler,
515 NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
Len Brown4be44fc2005-08-05 00:44:28 -0400517 if (ACPI_FAILURE(status))
518 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "walk_namespace failed\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
520 acpi_bus_unregister_driver(&acpi_memory_device_driver);
521
522 return_VOID;
523}
524
525module_init(acpi_memory_device_init);
526module_exit(acpi_memory_device_exit);