scan.c 34 KB

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