aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/acpi_memhotplug.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi/acpi_memhotplug.c')
-rw-r--r--drivers/acpi/acpi_memhotplug.c82
1 files changed, 34 insertions, 48 deletions
diff --git a/drivers/acpi/acpi_memhotplug.c b/drivers/acpi/acpi_memhotplug.c
index c7c8d537a063..b05469513842 100644
--- a/drivers/acpi/acpi_memhotplug.c
+++ b/drivers/acpi/acpi_memhotplug.c
@@ -85,12 +85,11 @@ acpi_memory_get_device_resources(struct acpi_memory_device *mem_device)
85 struct acpi_resource *resource = NULL; 85 struct acpi_resource *resource = NULL;
86 struct acpi_resource_address64 address64; 86 struct acpi_resource_address64 address64;
87 87
88 ACPI_FUNCTION_TRACE("acpi_memory_get_device_resources");
89 88
90 /* Get the range from the _CRS */ 89 /* Get the range from the _CRS */
91 status = acpi_get_current_resources(mem_device->handle, &buffer); 90 status = acpi_get_current_resources(mem_device->handle, &buffer);
92 if (ACPI_FAILURE(status)) 91 if (ACPI_FAILURE(status))
93 return_VALUE(-EINVAL); 92 return -EINVAL;
94 93
95 resource = (struct acpi_resource *)buffer.pointer; 94 resource = (struct acpi_resource *)buffer.pointer;
96 status = acpi_resource_to_address64(resource, &address64); 95 status = acpi_resource_to_address64(resource, &address64);
@@ -106,7 +105,7 @@ acpi_memory_get_device_resources(struct acpi_memory_device *mem_device)
106 } 105 }
107 106
108 acpi_os_free(buffer.pointer); 107 acpi_os_free(buffer.pointer);
109 return_VALUE(0); 108 return 0;
110} 109}
111 110
112static int 111static int
@@ -118,7 +117,6 @@ acpi_memory_get_device(acpi_handle handle,
118 struct acpi_device *device = NULL; 117 struct acpi_device *device = NULL;
119 struct acpi_device *pdevice = NULL; 118 struct acpi_device *pdevice = NULL;
120 119
121 ACPI_FUNCTION_TRACE("acpi_memory_get_device");
122 120
123 if (!acpi_bus_get_device(handle, &device) && device) 121 if (!acpi_bus_get_device(handle, &device) && device)
124 goto end; 122 goto end;
@@ -126,14 +124,14 @@ acpi_memory_get_device(acpi_handle handle,
126 status = acpi_get_parent(handle, &phandle); 124 status = acpi_get_parent(handle, &phandle);
127 if (ACPI_FAILURE(status)) { 125 if (ACPI_FAILURE(status)) {
128 ACPI_EXCEPTION((AE_INFO, status, "Cannot find acpi parent")); 126 ACPI_EXCEPTION((AE_INFO, status, "Cannot find acpi parent"));
129 return_VALUE(-EINVAL); 127 return -EINVAL;
130 } 128 }
131 129
132 /* Get the parent device */ 130 /* Get the parent device */
133 status = acpi_bus_get_device(phandle, &pdevice); 131 status = acpi_bus_get_device(phandle, &pdevice);
134 if (ACPI_FAILURE(status)) { 132 if (ACPI_FAILURE(status)) {
135 ACPI_EXCEPTION((AE_INFO, status, "Cannot get acpi bus device")); 133 ACPI_EXCEPTION((AE_INFO, status, "Cannot get acpi bus device"));
136 return_VALUE(-EINVAL); 134 return -EINVAL;
137 } 135 }
138 136
139 /* 137 /*
@@ -143,29 +141,28 @@ acpi_memory_get_device(acpi_handle handle,
143 status = acpi_bus_add(&device, pdevice, handle, ACPI_BUS_TYPE_DEVICE); 141 status = acpi_bus_add(&device, pdevice, handle, ACPI_BUS_TYPE_DEVICE);
144 if (ACPI_FAILURE(status)) { 142 if (ACPI_FAILURE(status)) {
145 ACPI_EXCEPTION((AE_INFO, status, "Cannot add acpi bus")); 143 ACPI_EXCEPTION((AE_INFO, status, "Cannot add acpi bus"));
146 return_VALUE(-EINVAL); 144 return -EINVAL;
147 } 145 }
148 146
149 end: 147 end:
150 *mem_device = acpi_driver_data(device); 148 *mem_device = acpi_driver_data(device);
151 if (!(*mem_device)) { 149 if (!(*mem_device)) {
152 printk(KERN_ERR "\n driver data not found"); 150 printk(KERN_ERR "\n driver data not found");
153 return_VALUE(-ENODEV); 151 return -ENODEV;
154 } 152 }
155 153
156 return_VALUE(0); 154 return 0;
157} 155}
158 156
159static int acpi_memory_check_device(struct acpi_memory_device *mem_device) 157static int acpi_memory_check_device(struct acpi_memory_device *mem_device)
160{ 158{
161 unsigned long current_status; 159 unsigned long current_status;
162 160
163 ACPI_FUNCTION_TRACE("acpi_memory_check_device");
164 161
165 /* Get device present/absent information from the _STA */ 162 /* Get device present/absent information from the _STA */
166 if (ACPI_FAILURE(acpi_evaluate_integer(mem_device->handle, "_STA", 163 if (ACPI_FAILURE(acpi_evaluate_integer(mem_device->handle, "_STA",
167 NULL, &current_status))) 164 NULL, &current_status)))
168 return_VALUE(-ENODEV); 165 return -ENODEV;
169 /* 166 /*
170 * Check for device status. Device should be 167 * Check for device status. Device should be
171 * present/enabled/functioning. 168 * present/enabled/functioning.
@@ -173,16 +170,15 @@ static int acpi_memory_check_device(struct acpi_memory_device *mem_device)
173 if (!((current_status & ACPI_MEMORY_STA_PRESENT) 170 if (!((current_status & ACPI_MEMORY_STA_PRESENT)
174 && (current_status & ACPI_MEMORY_STA_ENABLED) 171 && (current_status & ACPI_MEMORY_STA_ENABLED)
175 && (current_status & ACPI_MEMORY_STA_FUNCTIONAL))) 172 && (current_status & ACPI_MEMORY_STA_FUNCTIONAL)))
176 return_VALUE(-ENODEV); 173 return -ENODEV;
177 174
178 return_VALUE(0); 175 return 0;
179} 176}
180 177
181static int acpi_memory_enable_device(struct acpi_memory_device *mem_device) 178static int acpi_memory_enable_device(struct acpi_memory_device *mem_device)
182{ 179{
183 int result; 180 int result;
184 181
185 ACPI_FUNCTION_TRACE("acpi_memory_enable_device");
186 182
187 /* Get the range from the _CRS */ 183 /* Get the range from the _CRS */
188 result = acpi_memory_get_device_resources(mem_device); 184 result = acpi_memory_get_device_resources(mem_device);
@@ -213,7 +209,6 @@ static int acpi_memory_powerdown_device(struct acpi_memory_device *mem_device)
213 union acpi_object arg; 209 union acpi_object arg;
214 unsigned long current_status; 210 unsigned long current_status;
215 211
216 ACPI_FUNCTION_TRACE("acpi_memory_powerdown_device");
217 212
218 /* Issue the _EJ0 command */ 213 /* Issue the _EJ0 command */
219 arg_list.count = 1; 214 arg_list.count = 1;
@@ -225,20 +220,20 @@ static int acpi_memory_powerdown_device(struct acpi_memory_device *mem_device)
225 /* Return on _EJ0 failure */ 220 /* Return on _EJ0 failure */
226 if (ACPI_FAILURE(status)) { 221 if (ACPI_FAILURE(status)) {
227 ACPI_EXCEPTION((AE_INFO, status, "_EJ0 failed")); 222 ACPI_EXCEPTION((AE_INFO, status, "_EJ0 failed"));
228 return_VALUE(-ENODEV); 223 return -ENODEV;
229 } 224 }
230 225
231 /* Evalute _STA to check if the device is disabled */ 226 /* Evalute _STA to check if the device is disabled */
232 status = acpi_evaluate_integer(mem_device->handle, "_STA", 227 status = acpi_evaluate_integer(mem_device->handle, "_STA",
233 NULL, &current_status); 228 NULL, &current_status);
234 if (ACPI_FAILURE(status)) 229 if (ACPI_FAILURE(status))
235 return_VALUE(-ENODEV); 230 return -ENODEV;
236 231
237 /* Check for device status. Device should be disabled */ 232 /* Check for device status. Device should be disabled */
238 if (current_status & ACPI_MEMORY_STA_ENABLED) 233 if (current_status & ACPI_MEMORY_STA_ENABLED)
239 return_VALUE(-EINVAL); 234 return -EINVAL;
240 235
241 return_VALUE(0); 236 return 0;
242} 237}
243 238
244static int acpi_memory_disable_device(struct acpi_memory_device *mem_device) 239static int acpi_memory_disable_device(struct acpi_memory_device *mem_device)
@@ -247,7 +242,6 @@ static int acpi_memory_disable_device(struct acpi_memory_device *mem_device)
247 u64 start = mem_device->start_addr; 242 u64 start = mem_device->start_addr;
248 u64 len = mem_device->length; 243 u64 len = mem_device->length;
249 244
250 ACPI_FUNCTION_TRACE("acpi_memory_disable_device");
251 245
252 /* 246 /*
253 * Ask the VM to offline this memory range. 247 * Ask the VM to offline this memory range.
@@ -255,7 +249,7 @@ static int acpi_memory_disable_device(struct acpi_memory_device *mem_device)
255 */ 249 */
256 result = remove_memory(start, len); 250 result = remove_memory(start, len);
257 if (result) 251 if (result)
258 return_VALUE(result); 252 return result;
259 253
260 /* Power-off and eject the device */ 254 /* Power-off and eject the device */
261 result = acpi_memory_powerdown_device(mem_device); 255 result = acpi_memory_powerdown_device(mem_device);
@@ -274,7 +268,6 @@ static void acpi_memory_device_notify(acpi_handle handle, u32 event, void *data)
274 struct acpi_memory_device *mem_device; 268 struct acpi_memory_device *mem_device;
275 struct acpi_device *device; 269 struct acpi_device *device;
276 270
277 ACPI_FUNCTION_TRACE("acpi_memory_device_notify");
278 271
279 switch (event) { 272 switch (event) {
280 case ACPI_NOTIFY_BUS_CHECK: 273 case ACPI_NOTIFY_BUS_CHECK:
@@ -287,7 +280,7 @@ static void acpi_memory_device_notify(acpi_handle handle, u32 event, void *data)
287 "\nReceived DEVICE CHECK notification for device\n")); 280 "\nReceived DEVICE CHECK notification for device\n"));
288 if (acpi_memory_get_device(handle, &mem_device)) { 281 if (acpi_memory_get_device(handle, &mem_device)) {
289 printk(KERN_ERR PREFIX "Cannot find driver data\n"); 282 printk(KERN_ERR PREFIX "Cannot find driver data\n");
290 return_VOID; 283 return;
291 } 284 }
292 285
293 if (!acpi_memory_check_device(mem_device)) { 286 if (!acpi_memory_check_device(mem_device)) {
@@ -329,7 +322,7 @@ static void acpi_memory_device_notify(acpi_handle handle, u32 event, void *data)
329 break; 322 break;
330 } 323 }
331 324
332 return_VOID; 325 return;
333} 326}
334 327
335static int acpi_memory_device_add(struct acpi_device *device) 328static int acpi_memory_device_add(struct acpi_device *device)
@@ -337,14 +330,13 @@ static int acpi_memory_device_add(struct acpi_device *device)
337 int result; 330 int result;
338 struct acpi_memory_device *mem_device = NULL; 331 struct acpi_memory_device *mem_device = NULL;
339 332
340 ACPI_FUNCTION_TRACE("acpi_memory_device_add");
341 333
342 if (!device) 334 if (!device)
343 return_VALUE(-EINVAL); 335 return -EINVAL;
344 336
345 mem_device = kmalloc(sizeof(struct acpi_memory_device), GFP_KERNEL); 337 mem_device = kmalloc(sizeof(struct acpi_memory_device), GFP_KERNEL);
346 if (!mem_device) 338 if (!mem_device)
347 return_VALUE(-ENOMEM); 339 return -ENOMEM;
348 memset(mem_device, 0, sizeof(struct acpi_memory_device)); 340 memset(mem_device, 0, sizeof(struct acpi_memory_device));
349 341
350 mem_device->handle = device->handle; 342 mem_device->handle = device->handle;
@@ -356,7 +348,7 @@ static int acpi_memory_device_add(struct acpi_device *device)
356 result = acpi_memory_get_device_resources(mem_device); 348 result = acpi_memory_get_device_resources(mem_device);
357 if (result) { 349 if (result) {
358 kfree(mem_device); 350 kfree(mem_device);
359 return_VALUE(result); 351 return result;
360 } 352 }
361 353
362 /* Set the device state */ 354 /* Set the device state */
@@ -364,22 +356,21 @@ static int acpi_memory_device_add(struct acpi_device *device)
364 356
365 printk(KERN_INFO "%s \n", acpi_device_name(device)); 357 printk(KERN_INFO "%s \n", acpi_device_name(device));
366 358
367 return_VALUE(result); 359 return result;
368} 360}
369 361
370static int acpi_memory_device_remove(struct acpi_device *device, int type) 362static int acpi_memory_device_remove(struct acpi_device *device, int type)
371{ 363{
372 struct acpi_memory_device *mem_device = NULL; 364 struct acpi_memory_device *mem_device = NULL;
373 365
374 ACPI_FUNCTION_TRACE("acpi_memory_device_remove");
375 366
376 if (!device || !acpi_driver_data(device)) 367 if (!device || !acpi_driver_data(device))
377 return_VALUE(-EINVAL); 368 return -EINVAL;
378 369
379 mem_device = (struct acpi_memory_device *)acpi_driver_data(device); 370 mem_device = (struct acpi_memory_device *)acpi_driver_data(device);
380 kfree(mem_device); 371 kfree(mem_device);
381 372
382 return_VALUE(0); 373 return 0;
383} 374}
384 375
385/* 376/*
@@ -392,16 +383,15 @@ static acpi_status is_memory_device(acpi_handle handle)
392 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 383 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
393 struct acpi_device_info *info; 384 struct acpi_device_info *info;
394 385
395 ACPI_FUNCTION_TRACE("is_memory_device");
396 386
397 status = acpi_get_object_info(handle, &buffer); 387 status = acpi_get_object_info(handle, &buffer);
398 if (ACPI_FAILURE(status)) 388 if (ACPI_FAILURE(status))
399 return_ACPI_STATUS(status); 389 return status;
400 390
401 info = buffer.pointer; 391 info = buffer.pointer;
402 if (!(info->valid & ACPI_VALID_HID)) { 392 if (!(info->valid & ACPI_VALID_HID)) {
403 acpi_os_free(buffer.pointer); 393 acpi_os_free(buffer.pointer);
404 return_ACPI_STATUS(AE_ERROR); 394 return AE_ERROR;
405 } 395 }
406 396
407 hardware_id = info->hardware_id.value; 397 hardware_id = info->hardware_id.value;
@@ -410,7 +400,7 @@ static acpi_status is_memory_device(acpi_handle handle)
410 status = AE_ERROR; 400 status = AE_ERROR;
411 401
412 acpi_os_free(buffer.pointer); 402 acpi_os_free(buffer.pointer);
413 return_ACPI_STATUS(status); 403 return status;
414} 404}
415 405
416static acpi_status 406static acpi_status
@@ -419,18 +409,17 @@ acpi_memory_register_notify_handler(acpi_handle handle,
419{ 409{
420 acpi_status status; 410 acpi_status status;
421 411
422 ACPI_FUNCTION_TRACE("acpi_memory_register_notify_handler");
423 412
424 status = is_memory_device(handle); 413 status = is_memory_device(handle);
425 if (ACPI_FAILURE(status)){ 414 if (ACPI_FAILURE(status)){
426 ACPI_EXCEPTION((AE_INFO, status, "handle is no memory device")); 415 ACPI_EXCEPTION((AE_INFO, status, "handle is no memory device"));
427 return_ACPI_STATUS(AE_OK); /* continue */ 416 return AE_OK; /* continue */
428 } 417 }
429 418
430 status = acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY, 419 status = acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
431 acpi_memory_device_notify, NULL); 420 acpi_memory_device_notify, NULL);
432 /* continue */ 421 /* continue */
433 return_ACPI_STATUS(AE_OK); 422 return AE_OK;
434} 423}
435 424
436static acpi_status 425static acpi_status
@@ -439,19 +428,18 @@ acpi_memory_deregister_notify_handler(acpi_handle handle,
439{ 428{
440 acpi_status status; 429 acpi_status status;
441 430
442 ACPI_FUNCTION_TRACE("acpi_memory_deregister_notify_handler");
443 431
444 status = is_memory_device(handle); 432 status = is_memory_device(handle);
445 if (ACPI_FAILURE(status)){ 433 if (ACPI_FAILURE(status)){
446 ACPI_EXCEPTION((AE_INFO, status, "handle is no memory device")); 434 ACPI_EXCEPTION((AE_INFO, status, "handle is no memory device"));
447 return_ACPI_STATUS(AE_OK); /* continue */ 435 return AE_OK; /* continue */
448 } 436 }
449 437
450 status = acpi_remove_notify_handler(handle, 438 status = acpi_remove_notify_handler(handle,
451 ACPI_SYSTEM_NOTIFY, 439 ACPI_SYSTEM_NOTIFY,
452 acpi_memory_device_notify); 440 acpi_memory_device_notify);
453 441
454 return_ACPI_STATUS(AE_OK); /* continue */ 442 return AE_OK; /* continue */
455} 443}
456 444
457static int __init acpi_memory_device_init(void) 445static int __init acpi_memory_device_init(void)
@@ -459,12 +447,11 @@ static int __init acpi_memory_device_init(void)
459 int result; 447 int result;
460 acpi_status status; 448 acpi_status status;
461 449
462 ACPI_FUNCTION_TRACE("acpi_memory_device_init");
463 450
464 result = acpi_bus_register_driver(&acpi_memory_device_driver); 451 result = acpi_bus_register_driver(&acpi_memory_device_driver);
465 452
466 if (result < 0) 453 if (result < 0)
467 return_VALUE(-ENODEV); 454 return -ENODEV;
468 455
469 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, 456 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
470 ACPI_UINT32_MAX, 457 ACPI_UINT32_MAX,
@@ -474,17 +461,16 @@ static int __init acpi_memory_device_init(void)
474 if (ACPI_FAILURE(status)) { 461 if (ACPI_FAILURE(status)) {
475 ACPI_EXCEPTION((AE_INFO, status, "walk_namespace failed")); 462 ACPI_EXCEPTION((AE_INFO, status, "walk_namespace failed"));
476 acpi_bus_unregister_driver(&acpi_memory_device_driver); 463 acpi_bus_unregister_driver(&acpi_memory_device_driver);
477 return_VALUE(-ENODEV); 464 return -ENODEV;
478 } 465 }
479 466
480 return_VALUE(0); 467 return 0;
481} 468}
482 469
483static void __exit acpi_memory_device_exit(void) 470static void __exit acpi_memory_device_exit(void)
484{ 471{
485 acpi_status status; 472 acpi_status status;
486 473
487 ACPI_FUNCTION_TRACE("acpi_memory_device_exit");
488 474
489 /* 475 /*
490 * Adding this to un-install notification handlers for all the device 476 * Adding this to un-install notification handlers for all the device
@@ -500,7 +486,7 @@ static void __exit acpi_memory_device_exit(void)
500 486
501 acpi_bus_unregister_driver(&acpi_memory_device_driver); 487 acpi_bus_unregister_driver(&acpi_memory_device_driver);
502 488
503 return_VOID; 489 return;
504} 490}
505 491
506module_init(acpi_memory_device_init); 492module_init(acpi_memory_device_init);