scan.c 34 KB

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