scan.c 35 KB

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