aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/scan.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi/scan.c')
-rw-r--r--drivers/acpi/scan.c125
1 files changed, 69 insertions, 56 deletions
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index f8316a05ede7..698a1540e303 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -4,6 +4,7 @@
4 4
5#include <linux/module.h> 5#include <linux/module.h>
6#include <linux/init.h> 6#include <linux/init.h>
7#include <linux/kernel.h>
7#include <linux/acpi.h> 8#include <linux/acpi.h>
8 9
9#include <acpi/acpi_drivers.h> 10#include <acpi/acpi_drivers.h>
@@ -113,6 +114,8 @@ static struct kset acpi_namespace_kset = {
113static void acpi_device_register(struct acpi_device *device, 114static void acpi_device_register(struct acpi_device *device,
114 struct acpi_device *parent) 115 struct acpi_device *parent)
115{ 116{
117 int err;
118
116 /* 119 /*
117 * Linkage 120 * Linkage
118 * ------- 121 * -------
@@ -138,7 +141,10 @@ static void acpi_device_register(struct acpi_device *device,
138 device->kobj.parent = &parent->kobj; 141 device->kobj.parent = &parent->kobj;
139 device->kobj.ktype = &ktype_acpi_ns; 142 device->kobj.ktype = &ktype_acpi_ns;
140 device->kobj.kset = &acpi_namespace_kset; 143 device->kobj.kset = &acpi_namespace_kset;
141 kobject_register(&device->kobj); 144 err = kobject_register(&device->kobj);
145 if (err < 0)
146 printk(KERN_WARNING "%s: kobject_register error: %d\n",
147 __FUNCTION__, err);
142 create_sysfs_device_files(device); 148 create_sysfs_device_files(device);
143} 149}
144 150
@@ -162,11 +168,10 @@ static void acpi_device_unregister(struct acpi_device *device, int type)
162 168
163void acpi_bus_data_handler(acpi_handle handle, u32 function, void *context) 169void acpi_bus_data_handler(acpi_handle handle, u32 function, void *context)
164{ 170{
165 ACPI_FUNCTION_TRACE("acpi_bus_data_handler");
166 171
167 /* TBD */ 172 /* TBD */
168 173
169 return_VOID; 174 return;
170} 175}
171 176
172static int acpi_bus_get_power_flags(struct acpi_device *device) 177static int acpi_bus_get_power_flags(struct acpi_device *device)
@@ -175,7 +180,6 @@ static int acpi_bus_get_power_flags(struct acpi_device *device)
175 acpi_handle handle = NULL; 180 acpi_handle handle = NULL;
176 u32 i = 0; 181 u32 i = 0;
177 182
178 ACPI_FUNCTION_TRACE("acpi_bus_get_power_flags");
179 183
180 /* 184 /*
181 * Power Management Flags 185 * Power Management Flags
@@ -228,7 +232,7 @@ static int acpi_bus_get_power_flags(struct acpi_device *device)
228 232
229 device->power.state = ACPI_STATE_UNKNOWN; 233 device->power.state = ACPI_STATE_UNKNOWN;
230 234
231 return_VALUE(0); 235 return 0;
232} 236}
233 237
234int acpi_match_ids(struct acpi_device *device, char *ids) 238int acpi_match_ids(struct acpi_device *device, char *ids)
@@ -306,24 +310,22 @@ static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
306 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 310 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
307 union acpi_object *package = NULL; 311 union acpi_object *package = NULL;
308 312
309 ACPI_FUNCTION_TRACE("acpi_bus_get_wakeup_flags");
310 313
311 /* _PRW */ 314 /* _PRW */
312 status = acpi_evaluate_object(device->handle, "_PRW", NULL, &buffer); 315 status = acpi_evaluate_object(device->handle, "_PRW", NULL, &buffer);
313 if (ACPI_FAILURE(status)) { 316 if (ACPI_FAILURE(status)) {
314 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PRW\n")); 317 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRW"));
315 goto end; 318 goto end;
316 } 319 }
317 320
318 package = (union acpi_object *)buffer.pointer; 321 package = (union acpi_object *)buffer.pointer;
319 status = acpi_bus_extract_wakeup_device_power_package(device, package); 322 status = acpi_bus_extract_wakeup_device_power_package(device, package);
320 if (ACPI_FAILURE(status)) { 323 if (ACPI_FAILURE(status)) {
321 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 324 ACPI_EXCEPTION((AE_INFO, status, "Extracting _PRW package"));
322 "Error extracting _PRW package\n"));
323 goto end; 325 goto end;
324 } 326 }
325 327
326 acpi_os_free(buffer.pointer); 328 kfree(buffer.pointer);
327 329
328 device->wakeup.flags.valid = 1; 330 device->wakeup.flags.valid = 1;
329 /* Power button, Lid switch always enable wakeup */ 331 /* Power button, Lid switch always enable wakeup */
@@ -333,7 +335,7 @@ static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
333 end: 335 end:
334 if (ACPI_FAILURE(status)) 336 if (ACPI_FAILURE(status))
335 device->flags.wake_capable = 0; 337 device->flags.wake_capable = 0;
336 return_VALUE(0); 338 return 0;
337} 339}
338 340
339/* -------------------------------------------------------------------------- 341/* --------------------------------------------------------------------------
@@ -489,19 +491,18 @@ acpi_bus_driver_init(struct acpi_device *device, struct acpi_driver *driver)
489{ 491{
490 int result = 0; 492 int result = 0;
491 493
492 ACPI_FUNCTION_TRACE("acpi_bus_driver_init");
493 494
494 if (!device || !driver) 495 if (!device || !driver)
495 return_VALUE(-EINVAL); 496 return -EINVAL;
496 497
497 if (!driver->ops.add) 498 if (!driver->ops.add)
498 return_VALUE(-ENOSYS); 499 return -ENOSYS;
499 500
500 result = driver->ops.add(device); 501 result = driver->ops.add(device);
501 if (result) { 502 if (result) {
502 device->driver = NULL; 503 device->driver = NULL;
503 acpi_driver_data(device) = NULL; 504 acpi_driver_data(device) = NULL;
504 return_VALUE(result); 505 return result;
505 } 506 }
506 507
507 device->driver = driver; 508 device->driver = driver;
@@ -513,7 +514,7 @@ acpi_bus_driver_init(struct acpi_device *device, struct acpi_driver *driver)
513 514
514 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 515 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
515 "Driver successfully bound to device\n")); 516 "Driver successfully bound to device\n"));
516 return_VALUE(0); 517 return 0;
517} 518}
518 519
519static int acpi_start_single_object(struct acpi_device *device) 520static int acpi_start_single_object(struct acpi_device *device)
@@ -521,10 +522,9 @@ static int acpi_start_single_object(struct acpi_device *device)
521 int result = 0; 522 int result = 0;
522 struct acpi_driver *driver; 523 struct acpi_driver *driver;
523 524
524 ACPI_FUNCTION_TRACE("acpi_start_single_object");
525 525
526 if (!(driver = device->driver)) 526 if (!(driver = device->driver))
527 return_VALUE(0); 527 return 0;
528 528
529 if (driver->ops.start) { 529 if (driver->ops.start) {
530 result = driver->ops.start(device); 530 result = driver->ops.start(device);
@@ -532,14 +532,13 @@ static int acpi_start_single_object(struct acpi_device *device)
532 driver->ops.remove(device, ACPI_BUS_REMOVAL_NORMAL); 532 driver->ops.remove(device, ACPI_BUS_REMOVAL_NORMAL);
533 } 533 }
534 534
535 return_VALUE(result); 535 return result;
536} 536}
537 537
538static void acpi_driver_attach(struct acpi_driver *drv) 538static void acpi_driver_attach(struct acpi_driver *drv)
539{ 539{
540 struct list_head *node, *next; 540 struct list_head *node, *next;
541 541
542 ACPI_FUNCTION_TRACE("acpi_driver_attach");
543 542
544 spin_lock(&acpi_device_lock); 543 spin_lock(&acpi_device_lock);
545 list_for_each_safe(node, next, &acpi_device_list) { 544 list_for_each_safe(node, next, &acpi_device_list) {
@@ -568,7 +567,6 @@ static void acpi_driver_detach(struct acpi_driver *drv)
568{ 567{
569 struct list_head *node, *next; 568 struct list_head *node, *next;
570 569
571 ACPI_FUNCTION_TRACE("acpi_driver_detach");
572 570
573 spin_lock(&acpi_device_lock); 571 spin_lock(&acpi_device_lock);
574 list_for_each_safe(node, next, &acpi_device_list) { 572 list_for_each_safe(node, next, &acpi_device_list) {
@@ -598,17 +596,16 @@ static void acpi_driver_detach(struct acpi_driver *drv)
598 */ 596 */
599int acpi_bus_register_driver(struct acpi_driver *driver) 597int acpi_bus_register_driver(struct acpi_driver *driver)
600{ 598{
601 ACPI_FUNCTION_TRACE("acpi_bus_register_driver");
602 599
603 if (acpi_disabled) 600 if (acpi_disabled)
604 return_VALUE(-ENODEV); 601 return -ENODEV;
605 602
606 spin_lock(&acpi_device_lock); 603 spin_lock(&acpi_device_lock);
607 list_add_tail(&driver->node, &acpi_bus_drivers); 604 list_add_tail(&driver->node, &acpi_bus_drivers);
608 spin_unlock(&acpi_device_lock); 605 spin_unlock(&acpi_device_lock);
609 acpi_driver_attach(driver); 606 acpi_driver_attach(driver);
610 607
611 return_VALUE(0); 608 return 0;
612} 609}
613 610
614EXPORT_SYMBOL(acpi_bus_register_driver); 611EXPORT_SYMBOL(acpi_bus_register_driver);
@@ -646,7 +643,6 @@ static int acpi_bus_find_driver(struct acpi_device *device)
646 int result = 0; 643 int result = 0;
647 struct list_head *node, *next; 644 struct list_head *node, *next;
648 645
649 ACPI_FUNCTION_TRACE("acpi_bus_find_driver");
650 646
651 spin_lock(&acpi_device_lock); 647 spin_lock(&acpi_device_lock);
652 list_for_each_safe(node, next, &acpi_bus_drivers) { 648 list_for_each_safe(node, next, &acpi_bus_drivers) {
@@ -666,19 +662,41 @@ static int acpi_bus_find_driver(struct acpi_device *device)
666 spin_unlock(&acpi_device_lock); 662 spin_unlock(&acpi_device_lock);
667 663
668 Done: 664 Done:
669 return_VALUE(result); 665 return result;
670} 666}
671 667
672/* -------------------------------------------------------------------------- 668/* --------------------------------------------------------------------------
673 Device Enumeration 669 Device Enumeration
674 -------------------------------------------------------------------------- */ 670 -------------------------------------------------------------------------- */
675 671
672acpi_status
673acpi_bus_get_ejd(acpi_handle handle, acpi_handle *ejd)
674{
675 acpi_status status;
676 acpi_handle tmp;
677 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
678 union acpi_object *obj;
679
680 status = acpi_get_handle(handle, "_EJD", &tmp);
681 if (ACPI_FAILURE(status))
682 return status;
683
684 status = acpi_evaluate_object(handle, "_EJD", NULL, &buffer);
685 if (ACPI_SUCCESS(status)) {
686 obj = buffer.pointer;
687 status = acpi_get_handle(NULL, obj->string.pointer, ejd);
688 kfree(buffer.pointer);
689 }
690 return status;
691}
692EXPORT_SYMBOL_GPL(acpi_bus_get_ejd);
693
694
676static int acpi_bus_get_flags(struct acpi_device *device) 695static int acpi_bus_get_flags(struct acpi_device *device)
677{ 696{
678 acpi_status status = AE_OK; 697 acpi_status status = AE_OK;
679 acpi_handle temp = NULL; 698 acpi_handle temp = NULL;
680 699
681 ACPI_FUNCTION_TRACE("acpi_bus_get_flags");
682 700
683 /* Presence of _STA indicates 'dynamic_status' */ 701 /* Presence of _STA indicates 'dynamic_status' */
684 status = acpi_get_handle(device->handle, "_STA", &temp); 702 status = acpi_get_handle(device->handle, "_STA", &temp);
@@ -724,7 +742,7 @@ static int acpi_bus_get_flags(struct acpi_device *device)
724 742
725 /* TBD: Peformance management */ 743 /* TBD: Peformance management */
726 744
727 return_VALUE(0); 745 return 0;
728} 746}
729 747
730static void acpi_device_get_busid(struct acpi_device *device, 748static void acpi_device_get_busid(struct acpi_device *device,
@@ -842,7 +860,7 @@ static void acpi_device_set_id(struct acpi_device *device,
842 printk(KERN_ERR "Memory allocation error\n"); 860 printk(KERN_ERR "Memory allocation error\n");
843 } 861 }
844 862
845 acpi_os_free(buffer.pointer); 863 kfree(buffer.pointer);
846} 864}
847 865
848static int acpi_device_set_context(struct acpi_device *device, int type) 866static int acpi_device_set_context(struct acpi_device *device, int type)
@@ -918,10 +936,9 @@ static int acpi_bus_remove(struct acpi_device *dev, int rmdevice)
918 int result = 0; 936 int result = 0;
919 struct acpi_driver *driver; 937 struct acpi_driver *driver;
920 938
921 ACPI_FUNCTION_TRACE("acpi_bus_remove");
922 939
923 if (!dev) 940 if (!dev)
924 return_VALUE(-EINVAL); 941 return -EINVAL;
925 942
926 driver = dev->driver; 943 driver = dev->driver;
927 944
@@ -930,12 +947,12 @@ static int acpi_bus_remove(struct acpi_device *dev, int rmdevice)
930 if (driver->ops.stop) { 947 if (driver->ops.stop) {
931 result = driver->ops.stop(dev, ACPI_BUS_REMOVAL_EJECT); 948 result = driver->ops.stop(dev, ACPI_BUS_REMOVAL_EJECT);
932 if (result) 949 if (result)
933 return_VALUE(result); 950 return result;
934 } 951 }
935 952
936 result = dev->driver->ops.remove(dev, ACPI_BUS_REMOVAL_EJECT); 953 result = dev->driver->ops.remove(dev, ACPI_BUS_REMOVAL_EJECT);
937 if (result) { 954 if (result) {
938 return_VALUE(result); 955 return result;
939 } 956 }
940 957
941 atomic_dec(&dev->driver->references); 958 atomic_dec(&dev->driver->references);
@@ -944,7 +961,7 @@ static int acpi_bus_remove(struct acpi_device *dev, int rmdevice)
944 } 961 }
945 962
946 if (!rmdevice) 963 if (!rmdevice)
947 return_VALUE(0); 964 return 0;
948 965
949 if (dev->flags.bus_address) { 966 if (dev->flags.bus_address) {
950 if ((dev->parent) && (dev->parent->ops.unbind)) 967 if ((dev->parent) && (dev->parent->ops.unbind))
@@ -953,7 +970,7 @@ static int acpi_bus_remove(struct acpi_device *dev, int rmdevice)
953 970
954 acpi_device_unregister(dev, ACPI_BUS_REMOVAL_EJECT); 971 acpi_device_unregister(dev, ACPI_BUS_REMOVAL_EJECT);
955 972
956 return_VALUE(0); 973 return 0;
957} 974}
958 975
959static int 976static int
@@ -963,15 +980,14 @@ acpi_add_single_object(struct acpi_device **child,
963 int result = 0; 980 int result = 0;
964 struct acpi_device *device = NULL; 981 struct acpi_device *device = NULL;
965 982
966 ACPI_FUNCTION_TRACE("acpi_add_single_object");
967 983
968 if (!child) 984 if (!child)
969 return_VALUE(-EINVAL); 985 return -EINVAL;
970 986
971 device = kmalloc(sizeof(struct acpi_device), GFP_KERNEL); 987 device = kmalloc(sizeof(struct acpi_device), GFP_KERNEL);
972 if (!device) { 988 if (!device) {
973 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Memory allocation error\n")); 989 printk(KERN_ERR PREFIX "Memory allocation error\n");
974 return_VALUE(-ENOMEM); 990 return -ENOMEM;
975 } 991 }
976 memset(device, 0, sizeof(struct acpi_device)); 992 memset(device, 0, sizeof(struct acpi_device));
977 993
@@ -1096,7 +1112,7 @@ acpi_add_single_object(struct acpi_device **child,
1096 kfree(device); 1112 kfree(device);
1097 } 1113 }
1098 1114
1099 return_VALUE(result); 1115 return result;
1100} 1116}
1101 1117
1102static int acpi_bus_scan(struct acpi_device *start, struct acpi_bus_ops *ops) 1118static int acpi_bus_scan(struct acpi_device *start, struct acpi_bus_ops *ops)
@@ -1109,10 +1125,9 @@ static int acpi_bus_scan(struct acpi_device *start, struct acpi_bus_ops *ops)
1109 acpi_object_type type = 0; 1125 acpi_object_type type = 0;
1110 u32 level = 1; 1126 u32 level = 1;
1111 1127
1112 ACPI_FUNCTION_TRACE("acpi_bus_scan");
1113 1128
1114 if (!start) 1129 if (!start)
1115 return_VALUE(-EINVAL); 1130 return -EINVAL;
1116 1131
1117 parent = start; 1132 parent = start;
1118 phandle = start->handle; 1133 phandle = start->handle;
@@ -1209,7 +1224,7 @@ static int acpi_bus_scan(struct acpi_device *start, struct acpi_bus_ops *ops)
1209 } 1224 }
1210 } 1225 }
1211 1226
1212 return_VALUE(0); 1227 return 0;
1213} 1228}
1214 1229
1215int 1230int
@@ -1219,7 +1234,6 @@ acpi_bus_add(struct acpi_device **child,
1219 int result; 1234 int result;
1220 struct acpi_bus_ops ops; 1235 struct acpi_bus_ops ops;
1221 1236
1222 ACPI_FUNCTION_TRACE("acpi_bus_add");
1223 1237
1224 result = acpi_add_single_object(child, parent, handle, type); 1238 result = acpi_add_single_object(child, parent, handle, type);
1225 if (!result) { 1239 if (!result) {
@@ -1227,7 +1241,7 @@ acpi_bus_add(struct acpi_device **child,
1227 ops.acpi_op_add = 1; 1241 ops.acpi_op_add = 1;
1228 result = acpi_bus_scan(*child, &ops); 1242 result = acpi_bus_scan(*child, &ops);
1229 } 1243 }
1230 return_VALUE(result); 1244 return result;
1231} 1245}
1232 1246
1233EXPORT_SYMBOL(acpi_bus_add); 1247EXPORT_SYMBOL(acpi_bus_add);
@@ -1237,10 +1251,9 @@ int acpi_bus_start(struct acpi_device *device)
1237 int result; 1251 int result;
1238 struct acpi_bus_ops ops; 1252 struct acpi_bus_ops ops;
1239 1253
1240 ACPI_FUNCTION_TRACE("acpi_bus_start");
1241 1254
1242 if (!device) 1255 if (!device)
1243 return_VALUE(-EINVAL); 1256 return -EINVAL;
1244 1257
1245 result = acpi_start_single_object(device); 1258 result = acpi_start_single_object(device);
1246 if (!result) { 1259 if (!result) {
@@ -1248,7 +1261,7 @@ int acpi_bus_start(struct acpi_device *device)
1248 ops.acpi_op_start = 1; 1261 ops.acpi_op_start = 1;
1249 result = acpi_bus_scan(device, &ops); 1262 result = acpi_bus_scan(device, &ops);
1250 } 1263 }
1251 return_VALUE(result); 1264 return result;
1252} 1265}
1253 1266
1254EXPORT_SYMBOL(acpi_bus_start); 1267EXPORT_SYMBOL(acpi_bus_start);
@@ -1314,10 +1327,9 @@ static int acpi_bus_scan_fixed(struct acpi_device *root)
1314 int result = 0; 1327 int result = 0;
1315 struct acpi_device *device = NULL; 1328 struct acpi_device *device = NULL;
1316 1329
1317 ACPI_FUNCTION_TRACE("acpi_bus_scan_fixed");
1318 1330
1319 if (!root) 1331 if (!root)
1320 return_VALUE(-ENODEV); 1332 return -ENODEV;
1321 1333
1322 /* 1334 /*
1323 * Enumerate all fixed-feature devices. 1335 * Enumerate all fixed-feature devices.
@@ -1338,7 +1350,7 @@ static int acpi_bus_scan_fixed(struct acpi_device *root)
1338 result = acpi_start_single_object(device); 1350 result = acpi_start_single_object(device);
1339 } 1351 }
1340 1352
1341 return_VALUE(result); 1353 return result;
1342} 1354}
1343 1355
1344 1356
@@ -1427,7 +1439,7 @@ static int acpi_device_resume(struct device * dev)
1427} 1439}
1428 1440
1429 1441
1430struct bus_type acpi_bus_type = { 1442static struct bus_type acpi_bus_type = {
1431 .name = "acpi", 1443 .name = "acpi",
1432 .suspend = acpi_device_suspend, 1444 .suspend = acpi_device_suspend,
1433 .resume = acpi_device_resume, 1445 .resume = acpi_device_resume,
@@ -1440,12 +1452,13 @@ static int __init acpi_scan_init(void)
1440 int result; 1452 int result;
1441 struct acpi_bus_ops ops; 1453 struct acpi_bus_ops ops;
1442 1454
1443 ACPI_FUNCTION_TRACE("acpi_scan_init");
1444 1455
1445 if (acpi_disabled) 1456 if (acpi_disabled)
1446 return_VALUE(0); 1457 return 0;
1447 1458
1448 kset_register(&acpi_namespace_kset); 1459 result = kset_register(&acpi_namespace_kset);
1460 if (result < 0)
1461 printk(KERN_ERR PREFIX "kset_register error: %d\n", result);
1449 1462
1450 result = bus_register(&acpi_bus_type); 1463 result = bus_register(&acpi_bus_type);
1451 if (result) { 1464 if (result) {
@@ -1488,7 +1501,7 @@ static int __init acpi_scan_init(void)
1488 acpi_device_unregister(acpi_root, ACPI_BUS_REMOVAL_NORMAL); 1501 acpi_device_unregister(acpi_root, ACPI_BUS_REMOVAL_NORMAL);
1489 1502
1490 Done: 1503 Done:
1491 return_VALUE(result); 1504 return result;
1492} 1505}
1493 1506
1494subsys_initcall(acpi_scan_init); 1507subsys_initcall(acpi_scan_init);