scan.c 34 KB

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