scan.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423
  1. /*
  2. * scan.c - support for transforming the ACPI namespace into individual objects
  3. */
  4. #include <linux/module.h>
  5. #include <linux/init.h>
  6. #include <linux/kernel.h>
  7. #include <linux/acpi.h>
  8. #include <acpi/acpi_drivers.h>
  9. #include <acpi/acinterp.h> /* for acpi_ex_eisa_id_to_string() */
  10. #define _COMPONENT ACPI_BUS_COMPONENT
  11. ACPI_MODULE_NAME("scan")
  12. #define STRUCT_TO_INT(s) (*((int*)&s))
  13. extern struct acpi_device *acpi_root;
  14. #define ACPI_BUS_CLASS "system_bus"
  15. #define ACPI_BUS_HID "ACPI_BUS"
  16. #define ACPI_BUS_DRIVER_NAME "ACPI Bus Driver"
  17. #define ACPI_BUS_DEVICE_NAME "System Bus"
  18. static LIST_HEAD(acpi_device_list);
  19. static LIST_HEAD(acpi_bus_id_list);
  20. DEFINE_SPINLOCK(acpi_device_lock);
  21. LIST_HEAD(acpi_wakeup_device_list);
  22. struct acpi_device_bus_id{
  23. char bus_id[15];
  24. unsigned int instance_no;
  25. struct list_head node;
  26. };
  27. static int acpi_eject_operation(acpi_handle handle, int lockable)
  28. {
  29. struct acpi_object_list arg_list;
  30. union acpi_object arg;
  31. acpi_status status = AE_OK;
  32. /*
  33. * TBD: evaluate _PS3?
  34. */
  35. if (lockable) {
  36. arg_list.count = 1;
  37. arg_list.pointer = &arg;
  38. arg.type = ACPI_TYPE_INTEGER;
  39. arg.integer.value = 0;
  40. acpi_evaluate_object(handle, "_LCK", &arg_list, NULL);
  41. }
  42. arg_list.count = 1;
  43. arg_list.pointer = &arg;
  44. arg.type = ACPI_TYPE_INTEGER;
  45. arg.integer.value = 1;
  46. /*
  47. * TBD: _EJD support.
  48. */
  49. status = acpi_evaluate_object(handle, "_EJ0", &arg_list, NULL);
  50. if (ACPI_FAILURE(status)) {
  51. return (-ENODEV);
  52. }
  53. return (0);
  54. }
  55. static ssize_t
  56. acpi_eject_store(struct device *d, struct device_attribute *attr,
  57. const char *buf, size_t count)
  58. {
  59. int result;
  60. int ret = count;
  61. int islockable;
  62. acpi_status status;
  63. acpi_handle handle;
  64. acpi_object_type type = 0;
  65. struct acpi_device *acpi_device = to_acpi_device(d);
  66. if ((!count) || (buf[0] != '1')) {
  67. return -EINVAL;
  68. }
  69. #ifndef FORCE_EJECT
  70. if (acpi_device->driver == NULL) {
  71. ret = -ENODEV;
  72. goto err;
  73. }
  74. #endif
  75. status = acpi_get_type(acpi_device->handle, &type);
  76. if (ACPI_FAILURE(status) || (!acpi_device->flags.ejectable)) {
  77. ret = -ENODEV;
  78. goto err;
  79. }
  80. islockable = acpi_device->flags.lockable;
  81. handle = acpi_device->handle;
  82. result = acpi_bus_trim(acpi_device, 1);
  83. if (!result)
  84. result = acpi_eject_operation(handle, islockable);
  85. if (result) {
  86. ret = -EBUSY;
  87. }
  88. err:
  89. return ret;
  90. }
  91. static DEVICE_ATTR(eject, 0200, NULL, acpi_eject_store);
  92. static ssize_t
  93. acpi_device_hid_show(struct device *dev, struct device_attribute *attr, char *buf) {
  94. struct acpi_device *acpi_dev = to_acpi_device(dev);
  95. return sprintf(buf, "%s\n", acpi_dev->pnp.hardware_id);
  96. }
  97. static DEVICE_ATTR(hid, 0444, acpi_device_hid_show, NULL);
  98. static ssize_t
  99. acpi_device_path_show(struct device *dev, struct device_attribute *attr, char *buf) {
  100. struct acpi_device *acpi_dev = to_acpi_device(dev);
  101. struct acpi_buffer path = {ACPI_ALLOCATE_BUFFER, NULL};
  102. int result;
  103. result = acpi_get_name(acpi_dev->handle, ACPI_FULL_PATHNAME, &path);
  104. if(result)
  105. goto end;
  106. result = sprintf(buf, "%s\n", (char*)path.pointer);
  107. kfree(path.pointer);
  108. end:
  109. return result;
  110. }
  111. static DEVICE_ATTR(path, 0444, acpi_device_path_show, NULL);
  112. static int acpi_device_setup_files(struct acpi_device *dev)
  113. {
  114. acpi_status status;
  115. acpi_handle temp;
  116. int result = 0;
  117. /*
  118. * Devices gotten from FADT don't have a "path" attribute
  119. */
  120. if(dev->handle) {
  121. result = device_create_file(&dev->dev, &dev_attr_path);
  122. if(result)
  123. goto end;
  124. }
  125. if(dev->flags.hardware_id) {
  126. result = device_create_file(&dev->dev, &dev_attr_hid);
  127. if(result)
  128. goto end;
  129. }
  130. /*
  131. * If device has _EJ0, 'eject' file is created that is used to trigger
  132. * hot-removal function from userland.
  133. */
  134. status = acpi_get_handle(dev->handle, "_EJ0", &temp);
  135. if (ACPI_SUCCESS(status))
  136. result = device_create_file(&dev->dev, &dev_attr_eject);
  137. end:
  138. return result;
  139. }
  140. static void acpi_device_remove_files(struct acpi_device *dev)
  141. {
  142. acpi_status status;
  143. acpi_handle temp;
  144. /*
  145. * If device has _EJ0, 'eject' file is created that is used to trigger
  146. * hot-removal function from userland.
  147. */
  148. status = acpi_get_handle(dev->handle, "_EJ0", &temp);
  149. if (ACPI_SUCCESS(status))
  150. device_remove_file(&dev->dev, &dev_attr_eject);
  151. if(dev->flags.hardware_id)
  152. device_remove_file(&dev->dev, &dev_attr_hid);
  153. if(dev->handle)
  154. device_remove_file(&dev->dev, &dev_attr_path);
  155. }
  156. /* --------------------------------------------------------------------------
  157. ACPI Bus operations
  158. -------------------------------------------------------------------------- */
  159. static void acpi_device_release(struct device *dev)
  160. {
  161. struct acpi_device *acpi_dev = to_acpi_device(dev);
  162. kfree(acpi_dev->pnp.cid_list);
  163. kfree(acpi_dev);
  164. }
  165. static int acpi_device_suspend(struct device *dev, pm_message_t state)
  166. {
  167. struct acpi_device *acpi_dev = to_acpi_device(dev);
  168. struct acpi_driver *acpi_drv = acpi_dev->driver;
  169. if (acpi_drv && acpi_drv->ops.suspend)
  170. return acpi_drv->ops.suspend(acpi_dev, state);
  171. return 0;
  172. }
  173. static int acpi_device_resume(struct device *dev)
  174. {
  175. struct acpi_device *acpi_dev = to_acpi_device(dev);
  176. struct acpi_driver *acpi_drv = acpi_dev->driver;
  177. if (acpi_drv && acpi_drv->ops.resume)
  178. return acpi_drv->ops.resume(acpi_dev);
  179. return 0;
  180. }
  181. static int acpi_bus_match(struct device *dev, struct device_driver *drv)
  182. {
  183. struct acpi_device *acpi_dev = to_acpi_device(dev);
  184. struct acpi_driver *acpi_drv = to_acpi_driver(drv);
  185. return !acpi_match_ids(acpi_dev, acpi_drv->ids);
  186. }
  187. static int acpi_device_uevent(struct device *dev, char **envp, int num_envp,
  188. char *buffer, int buffer_size)
  189. {
  190. struct acpi_device *acpi_dev = to_acpi_device(dev);
  191. int i = 0, length = 0, ret = 0;
  192. if (acpi_dev->flags.hardware_id)
  193. ret = add_uevent_var(envp, num_envp, &i,
  194. buffer, buffer_size, &length,
  195. "HWID=%s", acpi_dev->pnp.hardware_id);
  196. if (ret)
  197. return -ENOMEM;
  198. if (acpi_dev->flags.compatible_ids) {
  199. int j;
  200. struct acpi_compatible_id_list *cid_list;
  201. cid_list = acpi_dev->pnp.cid_list;
  202. for (j = 0; j < cid_list->count; j++) {
  203. ret = add_uevent_var(envp, num_envp, &i, buffer,
  204. buffer_size, &length, "COMPTID=%s",
  205. cid_list->id[j].value);
  206. if (ret)
  207. return -ENOMEM;
  208. }
  209. }
  210. envp[i] = NULL;
  211. return 0;
  212. }
  213. static int acpi_bus_driver_init(struct acpi_device *, struct acpi_driver *);
  214. static int acpi_start_single_object(struct acpi_device *);
  215. static int acpi_device_probe(struct device * dev)
  216. {
  217. struct acpi_device *acpi_dev = to_acpi_device(dev);
  218. struct acpi_driver *acpi_drv = to_acpi_driver(dev->driver);
  219. int ret;
  220. ret = acpi_bus_driver_init(acpi_dev, acpi_drv);
  221. if (!ret) {
  222. if (acpi_dev->bus_ops.acpi_op_start)
  223. acpi_start_single_object(acpi_dev);
  224. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  225. "Found driver [%s] for device [%s]\n",
  226. acpi_drv->name, acpi_dev->pnp.bus_id));
  227. get_device(dev);
  228. }
  229. return ret;
  230. }
  231. static int acpi_device_remove(struct device * dev)
  232. {
  233. struct acpi_device *acpi_dev = to_acpi_device(dev);
  234. struct acpi_driver *acpi_drv = acpi_dev->driver;
  235. if (acpi_drv) {
  236. if (acpi_drv->ops.stop)
  237. acpi_drv->ops.stop(acpi_dev, acpi_dev->removal_type);
  238. if (acpi_drv->ops.remove)
  239. acpi_drv->ops.remove(acpi_dev, acpi_dev->removal_type);
  240. }
  241. acpi_dev->driver = NULL;
  242. acpi_driver_data(dev) = NULL;
  243. put_device(dev);
  244. return 0;
  245. }
  246. static void acpi_device_shutdown(struct device *dev)
  247. {
  248. struct acpi_device *acpi_dev = to_acpi_device(dev);
  249. struct acpi_driver *acpi_drv = acpi_dev->driver;
  250. if (acpi_drv && acpi_drv->ops.shutdown)
  251. acpi_drv->ops.shutdown(acpi_dev);
  252. return ;
  253. }
  254. static struct bus_type acpi_bus_type = {
  255. .name = "acpi",
  256. .suspend = acpi_device_suspend,
  257. .resume = acpi_device_resume,
  258. .shutdown = acpi_device_shutdown,
  259. .match = acpi_bus_match,
  260. .probe = acpi_device_probe,
  261. .remove = acpi_device_remove,
  262. .uevent = acpi_device_uevent,
  263. };
  264. static int acpi_device_register(struct acpi_device *device,
  265. struct acpi_device *parent)
  266. {
  267. int result;
  268. struct acpi_device_bus_id *acpi_device_bus_id, *new_bus_id;
  269. int found = 0;
  270. /*
  271. * Linkage
  272. * -------
  273. * Link this device to its parent and siblings.
  274. */
  275. INIT_LIST_HEAD(&device->children);
  276. INIT_LIST_HEAD(&device->node);
  277. INIT_LIST_HEAD(&device->g_list);
  278. INIT_LIST_HEAD(&device->wakeup_list);
  279. new_bus_id = kzalloc(sizeof(struct acpi_device_bus_id), GFP_KERNEL);
  280. if (!new_bus_id) {
  281. printk(KERN_ERR PREFIX "Memory allocation error\n");
  282. return -ENOMEM;
  283. }
  284. spin_lock(&acpi_device_lock);
  285. /*
  286. * Find suitable bus_id and instance number in acpi_bus_id_list
  287. * If failed, create one and link it into acpi_bus_id_list
  288. */
  289. list_for_each_entry(acpi_device_bus_id, &acpi_bus_id_list, node) {
  290. if(!strcmp(acpi_device_bus_id->bus_id, device->flags.hardware_id? device->pnp.hardware_id : "device")) {
  291. acpi_device_bus_id->instance_no ++;
  292. found = 1;
  293. kfree(new_bus_id);
  294. break;
  295. }
  296. }
  297. if(!found) {
  298. acpi_device_bus_id = new_bus_id;
  299. strcpy(acpi_device_bus_id->bus_id, device->flags.hardware_id ? device->pnp.hardware_id : "device");
  300. acpi_device_bus_id->instance_no = 0;
  301. list_add_tail(&acpi_device_bus_id->node, &acpi_bus_id_list);
  302. }
  303. sprintf(device->dev.bus_id, "%s:%02x", acpi_device_bus_id->bus_id, acpi_device_bus_id->instance_no);
  304. if (device->parent) {
  305. list_add_tail(&device->node, &device->parent->children);
  306. list_add_tail(&device->g_list, &device->parent->g_list);
  307. } else
  308. list_add_tail(&device->g_list, &acpi_device_list);
  309. if (device->wakeup.flags.valid)
  310. list_add_tail(&device->wakeup_list, &acpi_wakeup_device_list);
  311. spin_unlock(&acpi_device_lock);
  312. if (device->parent)
  313. device->dev.parent = &parent->dev;
  314. device->dev.bus = &acpi_bus_type;
  315. device_initialize(&device->dev);
  316. device->dev.release = &acpi_device_release;
  317. result = device_add(&device->dev);
  318. if(result) {
  319. printk("Error adding device %s", device->dev.bus_id);
  320. goto end;
  321. }
  322. result = acpi_device_setup_files(device);
  323. if(result)
  324. ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error creating sysfs interface for device %s\n", device->dev.bus_id));
  325. device->removal_type = ACPI_BUS_REMOVAL_NORMAL;
  326. return 0;
  327. end:
  328. spin_lock(&acpi_device_lock);
  329. if (device->parent) {
  330. list_del(&device->node);
  331. list_del(&device->g_list);
  332. } else
  333. list_del(&device->g_list);
  334. list_del(&device->wakeup_list);
  335. spin_unlock(&acpi_device_lock);
  336. return result;
  337. }
  338. static void acpi_device_unregister(struct acpi_device *device, int type)
  339. {
  340. spin_lock(&acpi_device_lock);
  341. if (device->parent) {
  342. list_del(&device->node);
  343. list_del(&device->g_list);
  344. } else
  345. list_del(&device->g_list);
  346. list_del(&device->wakeup_list);
  347. spin_unlock(&acpi_device_lock);
  348. acpi_detach_data(device->handle, acpi_bus_data_handler);
  349. acpi_device_remove_files(device);
  350. device_unregister(&device->dev);
  351. }
  352. /* --------------------------------------------------------------------------
  353. Driver Management
  354. -------------------------------------------------------------------------- */
  355. /**
  356. * acpi_bus_driver_init - add a device to a driver
  357. * @device: the device to add and initialize
  358. * @driver: driver for the device
  359. *
  360. * Used to initialize a device via its device driver. Called whenever a
  361. * driver is bound to a device. Invokes the driver's add() ops.
  362. */
  363. static int
  364. acpi_bus_driver_init(struct acpi_device *device, struct acpi_driver *driver)
  365. {
  366. int result = 0;
  367. if (!device || !driver)
  368. return -EINVAL;
  369. if (!driver->ops.add)
  370. return -ENOSYS;
  371. result = driver->ops.add(device);
  372. if (result) {
  373. device->driver = NULL;
  374. acpi_driver_data(device) = NULL;
  375. return result;
  376. }
  377. device->driver = driver;
  378. /*
  379. * TBD - Configuration Management: Assign resources to device based
  380. * upon possible configuration and currently allocated resources.
  381. */
  382. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  383. "Driver successfully bound to device\n"));
  384. return 0;
  385. }
  386. static int acpi_start_single_object(struct acpi_device *device)
  387. {
  388. int result = 0;
  389. struct acpi_driver *driver;
  390. if (!(driver = device->driver))
  391. return 0;
  392. if (driver->ops.start) {
  393. result = driver->ops.start(device);
  394. if (result && driver->ops.remove)
  395. driver->ops.remove(device, ACPI_BUS_REMOVAL_NORMAL);
  396. }
  397. return result;
  398. }
  399. /**
  400. * acpi_bus_register_driver - register a driver with the ACPI bus
  401. * @driver: driver being registered
  402. *
  403. * Registers a driver with the ACPI bus. Searches the namespace for all
  404. * devices that match the driver's criteria and binds. Returns zero for
  405. * success or a negative error status for failure.
  406. */
  407. int acpi_bus_register_driver(struct acpi_driver *driver)
  408. {
  409. int ret;
  410. if (acpi_disabled)
  411. return -ENODEV;
  412. driver->drv.name = driver->name;
  413. driver->drv.bus = &acpi_bus_type;
  414. driver->drv.owner = driver->owner;
  415. ret = driver_register(&driver->drv);
  416. return ret;
  417. }
  418. EXPORT_SYMBOL(acpi_bus_register_driver);
  419. /**
  420. * acpi_bus_unregister_driver - unregisters a driver with the APIC bus
  421. * @driver: driver to unregister
  422. *
  423. * Unregisters a driver with the ACPI bus. Searches the namespace for all
  424. * devices that match the driver's criteria and unbinds.
  425. */
  426. void acpi_bus_unregister_driver(struct acpi_driver *driver)
  427. {
  428. driver_unregister(&driver->drv);
  429. }
  430. EXPORT_SYMBOL(acpi_bus_unregister_driver);
  431. /* --------------------------------------------------------------------------
  432. Device Enumeration
  433. -------------------------------------------------------------------------- */
  434. acpi_status
  435. acpi_bus_get_ejd(acpi_handle handle, acpi_handle *ejd)
  436. {
  437. acpi_status status;
  438. acpi_handle tmp;
  439. struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
  440. union acpi_object *obj;
  441. status = acpi_get_handle(handle, "_EJD", &tmp);
  442. if (ACPI_FAILURE(status))
  443. return status;
  444. status = acpi_evaluate_object(handle, "_EJD", NULL, &buffer);
  445. if (ACPI_SUCCESS(status)) {
  446. obj = buffer.pointer;
  447. status = acpi_get_handle(NULL, obj->string.pointer, ejd);
  448. kfree(buffer.pointer);
  449. }
  450. return status;
  451. }
  452. EXPORT_SYMBOL_GPL(acpi_bus_get_ejd);
  453. void acpi_bus_data_handler(acpi_handle handle, u32 function, void *context)
  454. {
  455. /* TBD */
  456. return;
  457. }
  458. int acpi_match_ids(struct acpi_device *device, char *ids)
  459. {
  460. if (device->flags.hardware_id)
  461. if (strstr(ids, device->pnp.hardware_id))
  462. return 0;
  463. if (device->flags.compatible_ids) {
  464. struct acpi_compatible_id_list *cid_list = device->pnp.cid_list;
  465. int i;
  466. /* compare multiple _CID entries against driver ids */
  467. for (i = 0; i < cid_list->count; i++) {
  468. if (strstr(ids, cid_list->id[i].value))
  469. return 0;
  470. }
  471. }
  472. return -ENOENT;
  473. }
  474. static int acpi_bus_get_perf_flags(struct acpi_device *device)
  475. {
  476. device->performance.state = ACPI_STATE_UNKNOWN;
  477. return 0;
  478. }
  479. static acpi_status
  480. acpi_bus_extract_wakeup_device_power_package(struct acpi_device *device,
  481. union acpi_object *package)
  482. {
  483. int i = 0;
  484. union acpi_object *element = NULL;
  485. if (!device || !package || (package->package.count < 2))
  486. return AE_BAD_PARAMETER;
  487. element = &(package->package.elements[0]);
  488. if (!element)
  489. return AE_BAD_PARAMETER;
  490. if (element->type == ACPI_TYPE_PACKAGE) {
  491. if ((element->package.count < 2) ||
  492. (element->package.elements[0].type !=
  493. ACPI_TYPE_LOCAL_REFERENCE)
  494. || (element->package.elements[1].type != ACPI_TYPE_INTEGER))
  495. return AE_BAD_DATA;
  496. device->wakeup.gpe_device =
  497. element->package.elements[0].reference.handle;
  498. device->wakeup.gpe_number =
  499. (u32) element->package.elements[1].integer.value;
  500. } else if (element->type == ACPI_TYPE_INTEGER) {
  501. device->wakeup.gpe_number = element->integer.value;
  502. } else
  503. return AE_BAD_DATA;
  504. element = &(package->package.elements[1]);
  505. if (element->type != ACPI_TYPE_INTEGER) {
  506. return AE_BAD_DATA;
  507. }
  508. device->wakeup.sleep_state = element->integer.value;
  509. if ((package->package.count - 2) > ACPI_MAX_HANDLES) {
  510. return AE_NO_MEMORY;
  511. }
  512. device->wakeup.resources.count = package->package.count - 2;
  513. for (i = 0; i < device->wakeup.resources.count; i++) {
  514. element = &(package->package.elements[i + 2]);
  515. if (element->type != ACPI_TYPE_ANY) {
  516. return AE_BAD_DATA;
  517. }
  518. device->wakeup.resources.handles[i] = element->reference.handle;
  519. }
  520. return AE_OK;
  521. }
  522. static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
  523. {
  524. acpi_status status = 0;
  525. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  526. union acpi_object *package = NULL;
  527. /* _PRW */
  528. status = acpi_evaluate_object(device->handle, "_PRW", NULL, &buffer);
  529. if (ACPI_FAILURE(status)) {
  530. ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRW"));
  531. goto end;
  532. }
  533. package = (union acpi_object *)buffer.pointer;
  534. status = acpi_bus_extract_wakeup_device_power_package(device, package);
  535. if (ACPI_FAILURE(status)) {
  536. ACPI_EXCEPTION((AE_INFO, status, "Extracting _PRW package"));
  537. goto end;
  538. }
  539. kfree(buffer.pointer);
  540. device->wakeup.flags.valid = 1;
  541. /* Power button, Lid switch always enable wakeup */
  542. if (!acpi_match_ids(device, "PNP0C0D,PNP0C0C,PNP0C0E"))
  543. device->wakeup.flags.run_wake = 1;
  544. end:
  545. if (ACPI_FAILURE(status))
  546. device->flags.wake_capable = 0;
  547. return 0;
  548. }
  549. static int acpi_bus_get_power_flags(struct acpi_device *device)
  550. {
  551. acpi_status status = 0;
  552. acpi_handle handle = NULL;
  553. u32 i = 0;
  554. /*
  555. * Power Management Flags
  556. */
  557. status = acpi_get_handle(device->handle, "_PSC", &handle);
  558. if (ACPI_SUCCESS(status))
  559. device->power.flags.explicit_get = 1;
  560. status = acpi_get_handle(device->handle, "_IRC", &handle);
  561. if (ACPI_SUCCESS(status))
  562. device->power.flags.inrush_current = 1;
  563. /*
  564. * Enumerate supported power management states
  565. */
  566. for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3; i++) {
  567. struct acpi_device_power_state *ps = &device->power.states[i];
  568. char object_name[5] = { '_', 'P', 'R', '0' + i, '\0' };
  569. /* Evaluate "_PRx" to se if power resources are referenced */
  570. acpi_evaluate_reference(device->handle, object_name, NULL,
  571. &ps->resources);
  572. if (ps->resources.count) {
  573. device->power.flags.power_resources = 1;
  574. ps->flags.valid = 1;
  575. }
  576. /* Evaluate "_PSx" to see if we can do explicit sets */
  577. object_name[2] = 'S';
  578. status = acpi_get_handle(device->handle, object_name, &handle);
  579. if (ACPI_SUCCESS(status)) {
  580. ps->flags.explicit_set = 1;
  581. ps->flags.valid = 1;
  582. }
  583. /* State is valid if we have some power control */
  584. if (ps->resources.count || ps->flags.explicit_set)
  585. ps->flags.valid = 1;
  586. ps->power = -1; /* Unknown - driver assigned */
  587. ps->latency = -1; /* Unknown - driver assigned */
  588. }
  589. /* Set defaults for D0 and D3 states (always valid) */
  590. device->power.states[ACPI_STATE_D0].flags.valid = 1;
  591. device->power.states[ACPI_STATE_D0].power = 100;
  592. device->power.states[ACPI_STATE_D3].flags.valid = 1;
  593. device->power.states[ACPI_STATE_D3].power = 0;
  594. /* TBD: System wake support and resource requirements. */
  595. device->power.state = ACPI_STATE_UNKNOWN;
  596. return 0;
  597. }
  598. static int acpi_bus_get_flags(struct acpi_device *device)
  599. {
  600. acpi_status status = AE_OK;
  601. acpi_handle temp = NULL;
  602. /* Presence of _STA indicates 'dynamic_status' */
  603. status = acpi_get_handle(device->handle, "_STA", &temp);
  604. if (ACPI_SUCCESS(status))
  605. device->flags.dynamic_status = 1;
  606. /* Presence of _CID indicates 'compatible_ids' */
  607. status = acpi_get_handle(device->handle, "_CID", &temp);
  608. if (ACPI_SUCCESS(status))
  609. device->flags.compatible_ids = 1;
  610. /* Presence of _RMV indicates 'removable' */
  611. status = acpi_get_handle(device->handle, "_RMV", &temp);
  612. if (ACPI_SUCCESS(status))
  613. device->flags.removable = 1;
  614. /* Presence of _EJD|_EJ0 indicates 'ejectable' */
  615. status = acpi_get_handle(device->handle, "_EJD", &temp);
  616. if (ACPI_SUCCESS(status))
  617. device->flags.ejectable = 1;
  618. else {
  619. status = acpi_get_handle(device->handle, "_EJ0", &temp);
  620. if (ACPI_SUCCESS(status))
  621. device->flags.ejectable = 1;
  622. }
  623. /* Presence of _LCK indicates 'lockable' */
  624. status = acpi_get_handle(device->handle, "_LCK", &temp);
  625. if (ACPI_SUCCESS(status))
  626. device->flags.lockable = 1;
  627. /* Presence of _PS0|_PR0 indicates 'power manageable' */
  628. status = acpi_get_handle(device->handle, "_PS0", &temp);
  629. if (ACPI_FAILURE(status))
  630. status = acpi_get_handle(device->handle, "_PR0", &temp);
  631. if (ACPI_SUCCESS(status))
  632. device->flags.power_manageable = 1;
  633. /* Presence of _PRW indicates wake capable */
  634. status = acpi_get_handle(device->handle, "_PRW", &temp);
  635. if (ACPI_SUCCESS(status))
  636. device->flags.wake_capable = 1;
  637. /* TBD: Peformance management */
  638. return 0;
  639. }
  640. static void acpi_device_get_busid(struct acpi_device *device,
  641. acpi_handle handle, int type)
  642. {
  643. char bus_id[5] = { '?', 0 };
  644. struct acpi_buffer buffer = { sizeof(bus_id), bus_id };
  645. int i = 0;
  646. /*
  647. * Bus ID
  648. * ------
  649. * The device's Bus ID is simply the object name.
  650. * TBD: Shouldn't this value be unique (within the ACPI namespace)?
  651. */
  652. switch (type) {
  653. case ACPI_BUS_TYPE_SYSTEM:
  654. strcpy(device->pnp.bus_id, "ACPI");
  655. break;
  656. case ACPI_BUS_TYPE_POWER_BUTTON:
  657. strcpy(device->pnp.bus_id, "PWRF");
  658. break;
  659. case ACPI_BUS_TYPE_SLEEP_BUTTON:
  660. strcpy(device->pnp.bus_id, "SLPF");
  661. break;
  662. default:
  663. acpi_get_name(handle, ACPI_SINGLE_NAME, &buffer);
  664. /* Clean up trailing underscores (if any) */
  665. for (i = 3; i > 1; i--) {
  666. if (bus_id[i] == '_')
  667. bus_id[i] = '\0';
  668. else
  669. break;
  670. }
  671. strcpy(device->pnp.bus_id, bus_id);
  672. break;
  673. }
  674. }
  675. static int
  676. acpi_video_bus_match(struct acpi_device *device)
  677. {
  678. acpi_handle h_dummy1;
  679. acpi_handle h_dummy2;
  680. acpi_handle h_dummy3;
  681. if (!device)
  682. return -EINVAL;
  683. /* Since there is no HID, CID for ACPI Video drivers, we have
  684. * to check well known required nodes for each feature we support.
  685. */
  686. /* Does this device able to support video switching ? */
  687. if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOD", &h_dummy1)) &&
  688. ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOS", &h_dummy2)))
  689. return 0;
  690. /* Does this device able to retrieve a video ROM ? */
  691. if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_ROM", &h_dummy1)))
  692. return 0;
  693. /* Does this device able to configure which video head to be POSTed ? */
  694. if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_VPO", &h_dummy1)) &&
  695. ACPI_SUCCESS(acpi_get_handle(device->handle, "_GPD", &h_dummy2)) &&
  696. ACPI_SUCCESS(acpi_get_handle(device->handle, "_SPD", &h_dummy3)))
  697. return 0;
  698. return -ENODEV;
  699. }
  700. /*
  701. * acpi_bay_match - see if a device is an ejectable driver bay
  702. *
  703. * If an acpi object is ejectable and has one of the ACPI ATA methods defined,
  704. * then we can safely call it an ejectable drive bay
  705. */
  706. static int acpi_bay_match(struct acpi_device *device){
  707. acpi_status status;
  708. acpi_handle handle;
  709. acpi_handle tmp;
  710. acpi_handle phandle;
  711. handle = device->handle;
  712. status = acpi_get_handle(handle, "_EJ0", &tmp);
  713. if (ACPI_FAILURE(status))
  714. return -ENODEV;
  715. if ((ACPI_SUCCESS(acpi_get_handle(handle, "_GTF", &tmp))) ||
  716. (ACPI_SUCCESS(acpi_get_handle(handle, "_GTM", &tmp))) ||
  717. (ACPI_SUCCESS(acpi_get_handle(handle, "_STM", &tmp))) ||
  718. (ACPI_SUCCESS(acpi_get_handle(handle, "_SDD", &tmp))))
  719. return 0;
  720. if (acpi_get_parent(handle, &phandle))
  721. return -ENODEV;
  722. if ((ACPI_SUCCESS(acpi_get_handle(phandle, "_GTF", &tmp))) ||
  723. (ACPI_SUCCESS(acpi_get_handle(phandle, "_GTM", &tmp))) ||
  724. (ACPI_SUCCESS(acpi_get_handle(phandle, "_STM", &tmp))) ||
  725. (ACPI_SUCCESS(acpi_get_handle(phandle, "_SDD", &tmp))))
  726. return 0;
  727. return -ENODEV;
  728. }
  729. static void acpi_device_set_id(struct acpi_device *device,
  730. struct acpi_device *parent, acpi_handle handle,
  731. int type)
  732. {
  733. struct acpi_device_info *info;
  734. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  735. char *hid = NULL;
  736. char *uid = NULL;
  737. struct acpi_compatible_id_list *cid_list = NULL;
  738. acpi_status status;
  739. switch (type) {
  740. case ACPI_BUS_TYPE_DEVICE:
  741. status = acpi_get_object_info(handle, &buffer);
  742. if (ACPI_FAILURE(status)) {
  743. printk("%s: Error reading device info\n", __FUNCTION__);
  744. return;
  745. }
  746. info = buffer.pointer;
  747. if (info->valid & ACPI_VALID_HID)
  748. hid = info->hardware_id.value;
  749. if (info->valid & ACPI_VALID_UID)
  750. uid = info->unique_id.value;
  751. if (info->valid & ACPI_VALID_CID)
  752. cid_list = &info->compatibility_id;
  753. if (info->valid & ACPI_VALID_ADR) {
  754. device->pnp.bus_address = info->address;
  755. device->flags.bus_address = 1;
  756. }
  757. if(!(info->valid & (ACPI_VALID_HID | ACPI_VALID_CID))){
  758. status = acpi_video_bus_match(device);
  759. if(ACPI_SUCCESS(status))
  760. hid = ACPI_VIDEO_HID;
  761. status = acpi_bay_match(device);
  762. if (ACPI_SUCCESS(status))
  763. hid = ACPI_BAY_HID;
  764. }
  765. break;
  766. case ACPI_BUS_TYPE_POWER:
  767. hid = ACPI_POWER_HID;
  768. break;
  769. case ACPI_BUS_TYPE_PROCESSOR:
  770. hid = ACPI_PROCESSOR_HID;
  771. break;
  772. case ACPI_BUS_TYPE_SYSTEM:
  773. hid = ACPI_SYSTEM_HID;
  774. break;
  775. case ACPI_BUS_TYPE_THERMAL:
  776. hid = ACPI_THERMAL_HID;
  777. break;
  778. case ACPI_BUS_TYPE_POWER_BUTTON:
  779. hid = ACPI_BUTTON_HID_POWERF;
  780. break;
  781. case ACPI_BUS_TYPE_SLEEP_BUTTON:
  782. hid = ACPI_BUTTON_HID_SLEEPF;
  783. break;
  784. }
  785. /*
  786. * \_SB
  787. * ----
  788. * Fix for the system root bus device -- the only root-level device.
  789. */
  790. if (((acpi_handle)parent == ACPI_ROOT_OBJECT) && (type == ACPI_BUS_TYPE_DEVICE)) {
  791. hid = ACPI_BUS_HID;
  792. strcpy(device->pnp.device_name, ACPI_BUS_DEVICE_NAME);
  793. strcpy(device->pnp.device_class, ACPI_BUS_CLASS);
  794. }
  795. if (hid) {
  796. strcpy(device->pnp.hardware_id, hid);
  797. device->flags.hardware_id = 1;
  798. }
  799. if (uid) {
  800. strcpy(device->pnp.unique_id, uid);
  801. device->flags.unique_id = 1;
  802. }
  803. if (cid_list) {
  804. device->pnp.cid_list = kmalloc(cid_list->size, GFP_KERNEL);
  805. if (device->pnp.cid_list)
  806. memcpy(device->pnp.cid_list, cid_list, cid_list->size);
  807. else
  808. printk(KERN_ERR "Memory allocation error\n");
  809. }
  810. kfree(buffer.pointer);
  811. }
  812. static int acpi_device_set_context(struct acpi_device *device, int type)
  813. {
  814. acpi_status status = AE_OK;
  815. int result = 0;
  816. /*
  817. * Context
  818. * -------
  819. * Attach this 'struct acpi_device' to the ACPI object. This makes
  820. * resolutions from handle->device very efficient. Note that we need
  821. * to be careful with fixed-feature devices as they all attach to the
  822. * root object.
  823. */
  824. if (type != ACPI_BUS_TYPE_POWER_BUTTON &&
  825. type != ACPI_BUS_TYPE_SLEEP_BUTTON) {
  826. status = acpi_attach_data(device->handle,
  827. acpi_bus_data_handler, device);
  828. if (ACPI_FAILURE(status)) {
  829. printk("Error attaching device data\n");
  830. result = -ENODEV;
  831. }
  832. }
  833. return result;
  834. }
  835. static int acpi_bus_remove(struct acpi_device *dev, int rmdevice)
  836. {
  837. if (!dev)
  838. return -EINVAL;
  839. dev->removal_type = ACPI_BUS_REMOVAL_EJECT;
  840. device_release_driver(&dev->dev);
  841. if (!rmdevice)
  842. return 0;
  843. /*
  844. * unbind _ADR-Based Devices when hot removal
  845. */
  846. if (dev->flags.bus_address) {
  847. if ((dev->parent) && (dev->parent->ops.unbind))
  848. dev->parent->ops.unbind(dev);
  849. }
  850. acpi_device_unregister(dev, ACPI_BUS_REMOVAL_EJECT);
  851. return 0;
  852. }
  853. static int
  854. acpi_add_single_object(struct acpi_device **child,
  855. struct acpi_device *parent, acpi_handle handle, int type,
  856. struct acpi_bus_ops *ops)
  857. {
  858. int result = 0;
  859. struct acpi_device *device = NULL;
  860. if (!child)
  861. return -EINVAL;
  862. device = kzalloc(sizeof(struct acpi_device), GFP_KERNEL);
  863. if (!device) {
  864. printk(KERN_ERR PREFIX "Memory allocation error\n");
  865. return -ENOMEM;
  866. }
  867. device->handle = handle;
  868. device->parent = parent;
  869. device->bus_ops = *ops; /* workround for not call .start */
  870. acpi_device_get_busid(device, handle, type);
  871. /*
  872. * Flags
  873. * -----
  874. * Get prior to calling acpi_bus_get_status() so we know whether
  875. * or not _STA is present. Note that we only look for object
  876. * handles -- cannot evaluate objects until we know the device is
  877. * present and properly initialized.
  878. */
  879. result = acpi_bus_get_flags(device);
  880. if (result)
  881. goto end;
  882. /*
  883. * Status
  884. * ------
  885. * See if the device is present. We always assume that non-Device
  886. * and non-Processor objects (e.g. thermal zones, power resources,
  887. * etc.) are present, functioning, etc. (at least when parent object
  888. * is present). Note that _STA has a different meaning for some
  889. * objects (e.g. power resources) so we need to be careful how we use
  890. * it.
  891. */
  892. switch (type) {
  893. case ACPI_BUS_TYPE_PROCESSOR:
  894. case ACPI_BUS_TYPE_DEVICE:
  895. result = acpi_bus_get_status(device);
  896. if (ACPI_FAILURE(result) || !device->status.present) {
  897. result = -ENOENT;
  898. goto end;
  899. }
  900. break;
  901. default:
  902. STRUCT_TO_INT(device->status) = 0x0F;
  903. break;
  904. }
  905. /*
  906. * Initialize Device
  907. * -----------------
  908. * TBD: Synch with Core's enumeration/initialization process.
  909. */
  910. /*
  911. * Hardware ID, Unique ID, & Bus Address
  912. * -------------------------------------
  913. */
  914. acpi_device_set_id(device, parent, handle, type);
  915. /*
  916. * Power Management
  917. * ----------------
  918. */
  919. if (device->flags.power_manageable) {
  920. result = acpi_bus_get_power_flags(device);
  921. if (result)
  922. goto end;
  923. }
  924. /*
  925. * Wakeup device management
  926. *-----------------------
  927. */
  928. if (device->flags.wake_capable) {
  929. result = acpi_bus_get_wakeup_device_flags(device);
  930. if (result)
  931. goto end;
  932. }
  933. /*
  934. * Performance Management
  935. * ----------------------
  936. */
  937. if (device->flags.performance_manageable) {
  938. result = acpi_bus_get_perf_flags(device);
  939. if (result)
  940. goto end;
  941. }
  942. if ((result = acpi_device_set_context(device, type)))
  943. goto end;
  944. result = acpi_device_register(device, parent);
  945. /*
  946. * Bind _ADR-Based Devices when hot add
  947. */
  948. if (device->flags.bus_address) {
  949. if (device->parent && device->parent->ops.bind)
  950. device->parent->ops.bind(device);
  951. }
  952. end:
  953. if (!result)
  954. *child = device;
  955. else {
  956. kfree(device->pnp.cid_list);
  957. kfree(device);
  958. }
  959. return result;
  960. }
  961. static int acpi_bus_scan(struct acpi_device *start, struct acpi_bus_ops *ops)
  962. {
  963. acpi_status status = AE_OK;
  964. struct acpi_device *parent = NULL;
  965. struct acpi_device *child = NULL;
  966. acpi_handle phandle = NULL;
  967. acpi_handle chandle = NULL;
  968. acpi_object_type type = 0;
  969. u32 level = 1;
  970. if (!start)
  971. return -EINVAL;
  972. parent = start;
  973. phandle = start->handle;
  974. /*
  975. * Parse through the ACPI namespace, identify all 'devices', and
  976. * create a new 'struct acpi_device' for each.
  977. */
  978. while ((level > 0) && parent) {
  979. status = acpi_get_next_object(ACPI_TYPE_ANY, phandle,
  980. chandle, &chandle);
  981. /*
  982. * If this scope is exhausted then move our way back up.
  983. */
  984. if (ACPI_FAILURE(status)) {
  985. level--;
  986. chandle = phandle;
  987. acpi_get_parent(phandle, &phandle);
  988. if (parent->parent)
  989. parent = parent->parent;
  990. continue;
  991. }
  992. status = acpi_get_type(chandle, &type);
  993. if (ACPI_FAILURE(status))
  994. continue;
  995. /*
  996. * If this is a scope object then parse it (depth-first).
  997. */
  998. if (type == ACPI_TYPE_LOCAL_SCOPE) {
  999. level++;
  1000. phandle = chandle;
  1001. chandle = NULL;
  1002. continue;
  1003. }
  1004. /*
  1005. * We're only interested in objects that we consider 'devices'.
  1006. */
  1007. switch (type) {
  1008. case ACPI_TYPE_DEVICE:
  1009. type = ACPI_BUS_TYPE_DEVICE;
  1010. break;
  1011. case ACPI_TYPE_PROCESSOR:
  1012. type = ACPI_BUS_TYPE_PROCESSOR;
  1013. break;
  1014. case ACPI_TYPE_THERMAL:
  1015. type = ACPI_BUS_TYPE_THERMAL;
  1016. break;
  1017. case ACPI_TYPE_POWER:
  1018. type = ACPI_BUS_TYPE_POWER;
  1019. break;
  1020. default:
  1021. continue;
  1022. }
  1023. if (ops->acpi_op_add)
  1024. status = acpi_add_single_object(&child, parent,
  1025. chandle, type, ops);
  1026. else
  1027. status = acpi_bus_get_device(chandle, &child);
  1028. if (ACPI_FAILURE(status))
  1029. continue;
  1030. if (ops->acpi_op_start && !(ops->acpi_op_add)) {
  1031. status = acpi_start_single_object(child);
  1032. if (ACPI_FAILURE(status))
  1033. continue;
  1034. }
  1035. /*
  1036. * If the device is present, enabled, and functioning then
  1037. * parse its scope (depth-first). Note that we need to
  1038. * represent absent devices to facilitate PnP notifications
  1039. * -- but only the subtree head (not all of its children,
  1040. * which will be enumerated when the parent is inserted).
  1041. *
  1042. * TBD: Need notifications and other detection mechanisms
  1043. * in place before we can fully implement this.
  1044. */
  1045. if (child->status.present) {
  1046. status = acpi_get_next_object(ACPI_TYPE_ANY, chandle,
  1047. NULL, NULL);
  1048. if (ACPI_SUCCESS(status)) {
  1049. level++;
  1050. phandle = chandle;
  1051. chandle = NULL;
  1052. parent = child;
  1053. }
  1054. }
  1055. }
  1056. return 0;
  1057. }
  1058. int
  1059. acpi_bus_add(struct acpi_device **child,
  1060. struct acpi_device *parent, acpi_handle handle, int type)
  1061. {
  1062. int result;
  1063. struct acpi_bus_ops ops;
  1064. memset(&ops, 0, sizeof(ops));
  1065. ops.acpi_op_add = 1;
  1066. result = acpi_add_single_object(child, parent, handle, type, &ops);
  1067. if (!result)
  1068. result = acpi_bus_scan(*child, &ops);
  1069. return result;
  1070. }
  1071. EXPORT_SYMBOL(acpi_bus_add);
  1072. int acpi_bus_start(struct acpi_device *device)
  1073. {
  1074. int result;
  1075. struct acpi_bus_ops ops;
  1076. if (!device)
  1077. return -EINVAL;
  1078. result = acpi_start_single_object(device);
  1079. if (!result) {
  1080. memset(&ops, 0, sizeof(ops));
  1081. ops.acpi_op_start = 1;
  1082. result = acpi_bus_scan(device, &ops);
  1083. }
  1084. return result;
  1085. }
  1086. EXPORT_SYMBOL(acpi_bus_start);
  1087. int acpi_bus_trim(struct acpi_device *start, int rmdevice)
  1088. {
  1089. acpi_status status;
  1090. struct acpi_device *parent, *child;
  1091. acpi_handle phandle, chandle;
  1092. acpi_object_type type;
  1093. u32 level = 1;
  1094. int err = 0;
  1095. parent = start;
  1096. phandle = start->handle;
  1097. child = chandle = NULL;
  1098. while ((level > 0) && parent && (!err)) {
  1099. status = acpi_get_next_object(ACPI_TYPE_ANY, phandle,
  1100. chandle, &chandle);
  1101. /*
  1102. * If this scope is exhausted then move our way back up.
  1103. */
  1104. if (ACPI_FAILURE(status)) {
  1105. level--;
  1106. chandle = phandle;
  1107. acpi_get_parent(phandle, &phandle);
  1108. child = parent;
  1109. parent = parent->parent;
  1110. if (level == 0)
  1111. err = acpi_bus_remove(child, rmdevice);
  1112. else
  1113. err = acpi_bus_remove(child, 1);
  1114. continue;
  1115. }
  1116. status = acpi_get_type(chandle, &type);
  1117. if (ACPI_FAILURE(status)) {
  1118. continue;
  1119. }
  1120. /*
  1121. * If there is a device corresponding to chandle then
  1122. * parse it (depth-first).
  1123. */
  1124. if (acpi_bus_get_device(chandle, &child) == 0) {
  1125. level++;
  1126. phandle = chandle;
  1127. chandle = NULL;
  1128. parent = child;
  1129. }
  1130. continue;
  1131. }
  1132. return err;
  1133. }
  1134. EXPORT_SYMBOL_GPL(acpi_bus_trim);
  1135. static int acpi_bus_scan_fixed(struct acpi_device *root)
  1136. {
  1137. int result = 0;
  1138. struct acpi_device *device = NULL;
  1139. struct acpi_bus_ops ops;
  1140. if (!root)
  1141. return -ENODEV;
  1142. memset(&ops, 0, sizeof(ops));
  1143. ops.acpi_op_add = 1;
  1144. ops.acpi_op_start = 1;
  1145. /*
  1146. * Enumerate all fixed-feature devices.
  1147. */
  1148. if ((acpi_gbl_FADT.flags & ACPI_FADT_POWER_BUTTON) == 0) {
  1149. result = acpi_add_single_object(&device, acpi_root,
  1150. NULL,
  1151. ACPI_BUS_TYPE_POWER_BUTTON,
  1152. &ops);
  1153. }
  1154. if ((acpi_gbl_FADT.flags & ACPI_FADT_SLEEP_BUTTON) == 0) {
  1155. result = acpi_add_single_object(&device, acpi_root,
  1156. NULL,
  1157. ACPI_BUS_TYPE_SLEEP_BUTTON,
  1158. &ops);
  1159. }
  1160. return result;
  1161. }
  1162. static int __init acpi_scan_init(void)
  1163. {
  1164. int result;
  1165. struct acpi_bus_ops ops;
  1166. if (acpi_disabled)
  1167. return 0;
  1168. memset(&ops, 0, sizeof(ops));
  1169. ops.acpi_op_add = 1;
  1170. ops.acpi_op_start = 1;
  1171. result = bus_register(&acpi_bus_type);
  1172. if (result) {
  1173. /* We don't want to quit even if we failed to add suspend/resume */
  1174. printk(KERN_ERR PREFIX "Could not register bus type\n");
  1175. }
  1176. /*
  1177. * Create the root device in the bus's device tree
  1178. */
  1179. result = acpi_add_single_object(&acpi_root, NULL, ACPI_ROOT_OBJECT,
  1180. ACPI_BUS_TYPE_SYSTEM, &ops);
  1181. if (result)
  1182. goto Done;
  1183. /*
  1184. * Enumerate devices in the ACPI namespace.
  1185. */
  1186. result = acpi_bus_scan_fixed(acpi_root);
  1187. if (!result)
  1188. result = acpi_bus_scan(acpi_root, &ops);
  1189. if (result)
  1190. acpi_device_unregister(acpi_root, ACPI_BUS_REMOVAL_NORMAL);
  1191. Done:
  1192. return result;
  1193. }
  1194. subsys_initcall(acpi_scan_init);