blob: e0a95ba72371562fc1c250ebcadd0b170eb50881 [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)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400128 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error in acpi_get_parent\n"));
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)) {
135 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -0400136 "Error in acpi_bus_get_device\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 return_VALUE(-EINVAL);
138 }
139
140 /*
141 * Now add the notified device. This creates the acpi_device
142 * and invokes .add function
143 */
144 status = acpi_bus_add(&device, pdevice, handle, ACPI_BUS_TYPE_DEVICE);
145 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400146 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error in acpi_bus_add\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 return_VALUE(-EINVAL);
148 }
149
Len Brown4be44fc2005-08-05 00:44:28 -0400150 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 *mem_device = acpi_driver_data(device);
152 if (!(*mem_device)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400153 printk(KERN_ERR "\n driver data not found");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 return_VALUE(-ENODEV);
155 }
156
157 return_VALUE(0);
158}
159
Len Brown4be44fc2005-08-05 00:44:28 -0400160static int acpi_memory_check_device(struct acpi_memory_device *mem_device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161{
162 unsigned long current_status;
163
164 ACPI_FUNCTION_TRACE("acpi_memory_check_device");
165
166 /* Get device present/absent information from the _STA */
167 if (ACPI_FAILURE(acpi_evaluate_integer(mem_device->handle, "_STA",
Len Brown4be44fc2005-08-05 00:44:28 -0400168 NULL, &current_status)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 return_VALUE(-ENODEV);
170 /*
171 * Check for device status. Device should be
172 * present/enabled/functioning.
173 */
174 if (!((current_status & ACPI_MEMORY_STA_PRESENT)
Len Brown4be44fc2005-08-05 00:44:28 -0400175 && (current_status & ACPI_MEMORY_STA_ENABLED)
176 && (current_status & ACPI_MEMORY_STA_FUNCTIONAL)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 return_VALUE(-ENODEV);
178
179 return_VALUE(0);
180}
181
Len Brown4be44fc2005-08-05 00:44:28 -0400182static int acpi_memory_enable_device(struct acpi_memory_device *mem_device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183{
184 int result;
185
186 ACPI_FUNCTION_TRACE("acpi_memory_enable_device");
187
188 /* Get the range from the _CRS */
189 result = acpi_memory_get_device_resources(mem_device);
190 if (result) {
191 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -0400192 "\nget_device_resources failed\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 mem_device->state = MEMORY_INVALID_STATE;
194 return result;
195 }
196
197 /*
198 * Tell the VM there is more memory here...
199 * Note: Assume that this function returns zero on success
200 */
Bjorn Helgaas459c7262006-03-28 17:04:00 -0500201 result = add_memory(mem_device->start_addr, mem_device->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 if (result) {
Len Brown4be44fc2005-08-05 00:44:28 -0400203 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "\nadd_memory failed\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 mem_device->state = MEMORY_INVALID_STATE;
205 return result;
206 }
207
208 return result;
209}
210
Len Brown4be44fc2005-08-05 00:44:28 -0400211static int acpi_memory_powerdown_device(struct acpi_memory_device *mem_device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212{
213 acpi_status status;
Len Brown4be44fc2005-08-05 00:44:28 -0400214 struct acpi_object_list arg_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 union acpi_object arg;
216 unsigned long current_status;
217
218 ACPI_FUNCTION_TRACE("acpi_memory_powerdown_device");
219
220 /* Issue the _EJ0 command */
221 arg_list.count = 1;
222 arg_list.pointer = &arg;
223 arg.type = ACPI_TYPE_INTEGER;
224 arg.integer.value = 1;
225 status = acpi_evaluate_object(mem_device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -0400226 "_EJ0", &arg_list, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 /* Return on _EJ0 failure */
228 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400229 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "_EJ0 failed.\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 return_VALUE(-ENODEV);
231 }
232
233 /* Evalute _STA to check if the device is disabled */
234 status = acpi_evaluate_integer(mem_device->handle, "_STA",
Len Brown4be44fc2005-08-05 00:44:28 -0400235 NULL, &current_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 if (ACPI_FAILURE(status))
237 return_VALUE(-ENODEV);
238
239 /* Check for device status. Device should be disabled */
240 if (current_status & ACPI_MEMORY_STA_ENABLED)
241 return_VALUE(-EINVAL);
242
243 return_VALUE(0);
244}
245
Len Brown4be44fc2005-08-05 00:44:28 -0400246static int acpi_memory_disable_device(struct acpi_memory_device *mem_device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247{
248 int result;
249 u64 start = mem_device->start_addr;
Bjorn Helgaas459c7262006-03-28 17:04:00 -0500250 u64 len = mem_device->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
252 ACPI_FUNCTION_TRACE("acpi_memory_disable_device");
253
254 /*
255 * Ask the VM to offline this memory range.
256 * Note: Assume that this function returns zero on success
257 */
Dave Hansen0b0acbe2005-10-29 18:16:55 -0700258 result = remove_memory(start, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 if (result) {
260 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Hot-Remove failed.\n"));
261 return_VALUE(result);
262 }
263
264 /* Power-off and eject the device */
265 result = acpi_memory_powerdown_device(mem_device);
266 if (result) {
267 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -0400268 "Device Power Down failed.\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 /* Set the status of the device to invalid */
270 mem_device->state = MEMORY_INVALID_STATE;
271 return result;
272 }
273
274 mem_device->state = MEMORY_POWER_OFF_STATE;
275 return result;
276}
277
Len Brown4be44fc2005-08-05 00:44:28 -0400278static void acpi_memory_device_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279{
280 struct acpi_memory_device *mem_device;
281 struct acpi_device *device;
282
283 ACPI_FUNCTION_TRACE("acpi_memory_device_notify");
284
285 switch (event) {
286 case ACPI_NOTIFY_BUS_CHECK:
287 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400288 "\nReceived BUS CHECK notification for device\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 /* Fall Through */
290 case ACPI_NOTIFY_DEVICE_CHECK:
291 if (event == ACPI_NOTIFY_DEVICE_CHECK)
292 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400293 "\nReceived DEVICE CHECK notification for device\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 if (acpi_memory_get_device(handle, &mem_device)) {
295 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -0400296 "Error in finding driver data\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 return_VOID;
298 }
299
300 if (!acpi_memory_check_device(mem_device)) {
301 if (acpi_memory_enable_device(mem_device))
302 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -0400303 "Error in acpi_memory_enable_device\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 }
305 break;
306 case ACPI_NOTIFY_EJECT_REQUEST:
307 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400308 "\nReceived EJECT REQUEST notification for device\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
310 if (acpi_bus_get_device(handle, &device)) {
311 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -0400312 "Device doesn't exist\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 break;
314 }
315 mem_device = acpi_driver_data(device);
316 if (!mem_device) {
317 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -0400318 "Driver Data is NULL\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 break;
320 }
321
322 /*
323 * Currently disabling memory device from kernel mode
324 * TBD: Can also be disabled from user mode scripts
325 * TBD: Can also be disabled by Callback registration
Len Brown4be44fc2005-08-05 00:44:28 -0400326 * with generic sysfs driver
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 */
328 if (acpi_memory_disable_device(mem_device))
329 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -0400330 "Error in acpi_memory_disable_device\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 /*
332 * TBD: Invoke acpi_bus_remove to cleanup data structures
333 */
334 break;
335 default:
336 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400337 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 break;
339 }
340
341 return_VOID;
342}
343
Len Brown4be44fc2005-08-05 00:44:28 -0400344static int acpi_memory_device_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345{
346 int result;
347 struct acpi_memory_device *mem_device = NULL;
348
349 ACPI_FUNCTION_TRACE("acpi_memory_device_add");
350
351 if (!device)
352 return_VALUE(-EINVAL);
353
354 mem_device = kmalloc(sizeof(struct acpi_memory_device), GFP_KERNEL);
355 if (!mem_device)
356 return_VALUE(-ENOMEM);
357 memset(mem_device, 0, sizeof(struct acpi_memory_device));
358
359 mem_device->handle = device->handle;
360 sprintf(acpi_device_name(device), "%s", ACPI_MEMORY_DEVICE_NAME);
361 sprintf(acpi_device_class(device), "%s", ACPI_MEMORY_DEVICE_CLASS);
362 acpi_driver_data(device) = mem_device;
363
364 /* Get the range from the _CRS */
365 result = acpi_memory_get_device_resources(mem_device);
366 if (result) {
367 kfree(mem_device);
368 return_VALUE(result);
369 }
370
371 /* Set the device state */
372 mem_device->state = MEMORY_POWER_ON_STATE;
373
374 printk(KERN_INFO "%s \n", acpi_device_name(device));
375
376 return_VALUE(result);
377}
378
Len Brown4be44fc2005-08-05 00:44:28 -0400379static int acpi_memory_device_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380{
381 struct acpi_memory_device *mem_device = NULL;
382
383 ACPI_FUNCTION_TRACE("acpi_memory_device_remove");
384
385 if (!device || !acpi_driver_data(device))
386 return_VALUE(-EINVAL);
387
Len Brown4be44fc2005-08-05 00:44:28 -0400388 mem_device = (struct acpi_memory_device *)acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 kfree(mem_device);
390
391 return_VALUE(0);
392}
393
394/*
395 * Helper function to check for memory device
396 */
Len Brown4be44fc2005-08-05 00:44:28 -0400397static acpi_status is_memory_device(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398{
399 char *hardware_id;
400 acpi_status status;
Len Brown4be44fc2005-08-05 00:44:28 -0400401 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 struct acpi_device_info *info;
403
404 ACPI_FUNCTION_TRACE("is_memory_device");
405
406 status = acpi_get_object_info(handle, &buffer);
407 if (ACPI_FAILURE(status))
408 return_ACPI_STATUS(AE_ERROR);
409
410 info = buffer.pointer;
411 if (!(info->valid & ACPI_VALID_HID)) {
412 acpi_os_free(buffer.pointer);
413 return_ACPI_STATUS(AE_ERROR);
414 }
415
416 hardware_id = info->hardware_id.value;
417 if ((hardware_id == NULL) ||
Len Brown4be44fc2005-08-05 00:44:28 -0400418 (strcmp(hardware_id, ACPI_MEMORY_DEVICE_HID)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 status = AE_ERROR;
420
421 acpi_os_free(buffer.pointer);
422 return_ACPI_STATUS(status);
423}
424
425static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400426acpi_memory_register_notify_handler(acpi_handle handle,
427 u32 level, void *ctxt, void **retv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428{
429 acpi_status status;
430
431 ACPI_FUNCTION_TRACE("acpi_memory_register_notify_handler");
432
433 status = is_memory_device(handle);
434 if (ACPI_FAILURE(status))
435 return_ACPI_STATUS(AE_OK); /* continue */
436
437 status = acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
Len Brown4be44fc2005-08-05 00:44:28 -0400438 acpi_memory_device_notify, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 if (ACPI_FAILURE(status)) {
440 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -0400441 "Error installing notify handler\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 return_ACPI_STATUS(AE_OK); /* continue */
443 }
444
445 return_ACPI_STATUS(status);
446}
447
448static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400449acpi_memory_deregister_notify_handler(acpi_handle handle,
450 u32 level, void *ctxt, void **retv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451{
452 acpi_status status;
453
454 ACPI_FUNCTION_TRACE("acpi_memory_deregister_notify_handler");
455
456 status = is_memory_device(handle);
457 if (ACPI_FAILURE(status))
458 return_ACPI_STATUS(AE_OK); /* continue */
459
460 status = acpi_remove_notify_handler(handle,
Len Brown4be44fc2005-08-05 00:44:28 -0400461 ACPI_SYSTEM_NOTIFY,
462 acpi_memory_device_notify);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 if (ACPI_FAILURE(status)) {
464 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -0400465 "Error removing notify handler\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 return_ACPI_STATUS(AE_OK); /* continue */
467 }
468
469 return_ACPI_STATUS(status);
470}
471
Len Brown4be44fc2005-08-05 00:44:28 -0400472static int __init acpi_memory_device_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473{
474 int result;
475 acpi_status status;
476
477 ACPI_FUNCTION_TRACE("acpi_memory_device_init");
478
479 result = acpi_bus_register_driver(&acpi_memory_device_driver);
480
481 if (result < 0)
482 return_VALUE(-ENODEV);
483
484 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
Len Brown4be44fc2005-08-05 00:44:28 -0400485 ACPI_UINT32_MAX,
486 acpi_memory_register_notify_handler,
487 NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
Len Brown4be44fc2005-08-05 00:44:28 -0400489 if (ACPI_FAILURE(status)) {
490 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "walk_namespace failed\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 acpi_bus_unregister_driver(&acpi_memory_device_driver);
492 return_VALUE(-ENODEV);
Len Brown4be44fc2005-08-05 00:44:28 -0400493 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
495 return_VALUE(0);
496}
497
Len Brown4be44fc2005-08-05 00:44:28 -0400498static void __exit acpi_memory_device_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499{
500 acpi_status status;
501
502 ACPI_FUNCTION_TRACE("acpi_memory_device_exit");
503
504 /*
505 * Adding this to un-install notification handlers for all the device
506 * handles.
507 */
508 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
Len Brown4be44fc2005-08-05 00:44:28 -0400509 ACPI_UINT32_MAX,
510 acpi_memory_deregister_notify_handler,
511 NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512
Len Brown4be44fc2005-08-05 00:44:28 -0400513 if (ACPI_FAILURE(status))
514 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "walk_namespace failed\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
516 acpi_bus_unregister_driver(&acpi_memory_device_driver);
517
518 return_VOID;
519}
520
521module_init(acpi_memory_device_init);
522module_exit(acpi_memory_device_exit);