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 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. if (dev->pnp.cid_list)
  25. kfree(dev->pnp.cid_list);
  26. kfree(dev);
  27. }
  28. struct acpi_device_attribute {
  29. struct attribute attr;
  30. ssize_t(*show) (struct acpi_device *, char *);
  31. ssize_t(*store) (struct acpi_device *, const char *, size_t);
  32. };
  33. typedef void acpi_device_sysfs_files(struct kobject *,
  34. const struct attribute *);
  35. static void setup_sys_fs_device_files(struct acpi_device *dev,
  36. acpi_device_sysfs_files * func);
  37. #define create_sysfs_device_files(dev) \
  38. setup_sys_fs_device_files(dev, (acpi_device_sysfs_files *)&sysfs_create_file)
  39. #define remove_sysfs_device_files(dev) \
  40. setup_sys_fs_device_files(dev, (acpi_device_sysfs_files *)&sysfs_remove_file)
  41. #define to_acpi_device(n) container_of(n, struct acpi_device, kobj)
  42. #define to_handle_attr(n) container_of(n, struct acpi_device_attribute, attr);
  43. static ssize_t acpi_device_attr_show(struct kobject *kobj,
  44. struct attribute *attr, char *buf)
  45. {
  46. struct acpi_device *device = to_acpi_device(kobj);
  47. struct acpi_device_attribute *attribute = to_handle_attr(attr);
  48. return attribute->show ? attribute->show(device, buf) : -EIO;
  49. }
  50. static ssize_t acpi_device_attr_store(struct kobject *kobj,
  51. struct attribute *attr, const char *buf,
  52. size_t len)
  53. {
  54. struct acpi_device *device = to_acpi_device(kobj);
  55. struct acpi_device_attribute *attribute = to_handle_attr(attr);
  56. return attribute->store ? attribute->store(device, buf, len) : -EIO;
  57. }
  58. static struct sysfs_ops acpi_device_sysfs_ops = {
  59. .show = acpi_device_attr_show,
  60. .store = acpi_device_attr_store,
  61. };
  62. static struct kobj_type ktype_acpi_ns = {
  63. .sysfs_ops = &acpi_device_sysfs_ops,
  64. .release = acpi_device_release,
  65. };
  66. static int namespace_hotplug(struct kset *kset, struct kobject *kobj,
  67. char **envp, int num_envp, char *buffer,
  68. int buffer_size)
  69. {
  70. struct acpi_device *dev = to_acpi_device(kobj);
  71. int i = 0;
  72. int len = 0;
  73. if (!dev->driver)
  74. return 0;
  75. if (add_hotplug_env_var(envp, num_envp, &i, buffer, buffer_size, &len,
  76. "PHYSDEVDRIVER=%s", dev->driver->name))
  77. return -ENOMEM;
  78. envp[i] = NULL;
  79. return 0;
  80. }
  81. static struct kset_hotplug_ops namespace_hotplug_ops = {
  82. .hotplug = &namespace_hotplug,
  83. };
  84. static struct kset acpi_namespace_kset = {
  85. .kobj = {
  86. .name = "namespace",
  87. },
  88. .subsys = &acpi_subsys,
  89. .ktype = &ktype_acpi_ns,
  90. .hotplug_ops = &namespace_hotplug_ops,
  91. };
  92. static void acpi_device_register(struct acpi_device *device,
  93. struct acpi_device *parent)
  94. {
  95. /*
  96. * Linkage
  97. * -------
  98. * Link this device to its parent and siblings.
  99. */
  100. INIT_LIST_HEAD(&device->children);
  101. INIT_LIST_HEAD(&device->node);
  102. INIT_LIST_HEAD(&device->g_list);
  103. INIT_LIST_HEAD(&device->wakeup_list);
  104. spin_lock(&acpi_device_lock);
  105. if (device->parent) {
  106. list_add_tail(&device->node, &device->parent->children);
  107. list_add_tail(&device->g_list, &device->parent->g_list);
  108. } else
  109. list_add_tail(&device->g_list, &acpi_device_list);
  110. if (device->wakeup.flags.valid)
  111. list_add_tail(&device->wakeup_list, &acpi_wakeup_device_list);
  112. spin_unlock(&acpi_device_lock);
  113. strlcpy(device->kobj.name, device->pnp.bus_id, KOBJ_NAME_LEN);
  114. if (parent)
  115. device->kobj.parent = &parent->kobj;
  116. device->kobj.ktype = &ktype_acpi_ns;
  117. device->kobj.kset = &acpi_namespace_kset;
  118. kobject_register(&device->kobj);
  119. create_sysfs_device_files(device);
  120. }
  121. static int acpi_device_unregister(struct acpi_device *device, int type)
  122. {
  123. spin_lock(&acpi_device_lock);
  124. if (device->parent) {
  125. list_del(&device->node);
  126. list_del(&device->g_list);
  127. } else
  128. list_del(&device->g_list);
  129. list_del(&device->wakeup_list);
  130. spin_unlock(&acpi_device_lock);
  131. acpi_detach_data(device->handle, acpi_bus_data_handler);
  132. remove_sysfs_device_files(device);
  133. kobject_unregister(&device->kobj);
  134. return 0;
  135. }
  136. void acpi_bus_data_handler(acpi_handle handle, u32 function, void *context)
  137. {
  138. ACPI_FUNCTION_TRACE("acpi_bus_data_handler");
  139. /* TBD */
  140. return_VOID;
  141. }
  142. static int acpi_bus_get_power_flags(struct acpi_device *device)
  143. {
  144. acpi_status status = 0;
  145. acpi_handle handle = NULL;
  146. u32 i = 0;
  147. ACPI_FUNCTION_TRACE("acpi_bus_get_power_flags");
  148. /*
  149. * Power Management Flags
  150. */
  151. status = acpi_get_handle(device->handle, "_PSC", &handle);
  152. if (ACPI_SUCCESS(status))
  153. device->power.flags.explicit_get = 1;
  154. status = acpi_get_handle(device->handle, "_IRC", &handle);
  155. if (ACPI_SUCCESS(status))
  156. device->power.flags.inrush_current = 1;
  157. /*
  158. * Enumerate supported power management states
  159. */
  160. for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3; i++) {
  161. struct acpi_device_power_state *ps = &device->power.states[i];
  162. char object_name[5] = { '_', 'P', 'R', '0' + i, '\0' };
  163. /* Evaluate "_PRx" to se if power resources are referenced */
  164. acpi_evaluate_reference(device->handle, object_name, NULL,
  165. &ps->resources);
  166. if (ps->resources.count) {
  167. device->power.flags.power_resources = 1;
  168. ps->flags.valid = 1;
  169. }
  170. /* Evaluate "_PSx" to see if we can do explicit sets */
  171. object_name[2] = 'S';
  172. status = acpi_get_handle(device->handle, object_name, &handle);
  173. if (ACPI_SUCCESS(status)) {
  174. ps->flags.explicit_set = 1;
  175. ps->flags.valid = 1;
  176. }
  177. /* State is valid if we have some power control */
  178. if (ps->resources.count || ps->flags.explicit_set)
  179. ps->flags.valid = 1;
  180. ps->power = -1; /* Unknown - driver assigned */
  181. ps->latency = -1; /* Unknown - driver assigned */
  182. }
  183. /* Set defaults for D0 and D3 states (always valid) */
  184. device->power.states[ACPI_STATE_D0].flags.valid = 1;
  185. device->power.states[ACPI_STATE_D0].power = 100;
  186. device->power.states[ACPI_STATE_D3].flags.valid = 1;
  187. device->power.states[ACPI_STATE_D3].power = 0;
  188. /* TBD: System wake support and resource requirements. */
  189. device->power.state = ACPI_STATE_UNKNOWN;
  190. return_VALUE(0);
  191. }
  192. int acpi_match_ids(struct acpi_device *device, char *ids)
  193. {
  194. int error = 0;
  195. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  196. if (device->flags.hardware_id)
  197. if (strstr(ids, device->pnp.hardware_id))
  198. goto Done;
  199. if (device->flags.compatible_ids) {
  200. struct acpi_compatible_id_list *cid_list = device->pnp.cid_list;
  201. int i;
  202. /* compare multiple _CID entries against driver ids */
  203. for (i = 0; i < cid_list->count; i++) {
  204. if (strstr(ids, cid_list->id[i].value))
  205. goto Done;
  206. }
  207. }
  208. error = -ENOENT;
  209. Done:
  210. if (buffer.pointer)
  211. acpi_os_free(buffer.pointer);
  212. return error;
  213. }
  214. static acpi_status
  215. acpi_bus_extract_wakeup_device_power_package(struct acpi_device *device,
  216. union acpi_object *package)
  217. {
  218. int i = 0;
  219. union acpi_object *element = NULL;
  220. if (!device || !package || (package->package.count < 2))
  221. return AE_BAD_PARAMETER;
  222. element = &(package->package.elements[0]);
  223. if (!element)
  224. return AE_BAD_PARAMETER;
  225. if (element->type == ACPI_TYPE_PACKAGE) {
  226. if ((element->package.count < 2) ||
  227. (element->package.elements[0].type !=
  228. ACPI_TYPE_LOCAL_REFERENCE)
  229. || (element->package.elements[1].type != ACPI_TYPE_INTEGER))
  230. return AE_BAD_DATA;
  231. device->wakeup.gpe_device =
  232. element->package.elements[0].reference.handle;
  233. device->wakeup.gpe_number =
  234. (u32) element->package.elements[1].integer.value;
  235. } else if (element->type == ACPI_TYPE_INTEGER) {
  236. device->wakeup.gpe_number = element->integer.value;
  237. } else
  238. return AE_BAD_DATA;
  239. element = &(package->package.elements[1]);
  240. if (element->type != ACPI_TYPE_INTEGER) {
  241. return AE_BAD_DATA;
  242. }
  243. device->wakeup.sleep_state = element->integer.value;
  244. if ((package->package.count - 2) > ACPI_MAX_HANDLES) {
  245. return AE_NO_MEMORY;
  246. }
  247. device->wakeup.resources.count = package->package.count - 2;
  248. for (i = 0; i < device->wakeup.resources.count; i++) {
  249. element = &(package->package.elements[i + 2]);
  250. if (element->type != ACPI_TYPE_ANY) {
  251. return AE_BAD_DATA;
  252. }
  253. device->wakeup.resources.handles[i] = element->reference.handle;
  254. }
  255. return AE_OK;
  256. }
  257. static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
  258. {
  259. acpi_status status = 0;
  260. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  261. union acpi_object *package = NULL;
  262. ACPI_FUNCTION_TRACE("acpi_bus_get_wakeup_flags");
  263. /* _PRW */
  264. status = acpi_evaluate_object(device->handle, "_PRW", NULL, &buffer);
  265. if (ACPI_FAILURE(status)) {
  266. ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PRW\n"));
  267. goto end;
  268. }
  269. package = (union acpi_object *)buffer.pointer;
  270. status = acpi_bus_extract_wakeup_device_power_package(device, package);
  271. if (ACPI_FAILURE(status)) {
  272. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  273. "Error extracting _PRW package\n"));
  274. goto end;
  275. }
  276. acpi_os_free(buffer.pointer);
  277. device->wakeup.flags.valid = 1;
  278. /* Power button, Lid switch always enable wakeup */
  279. if (!acpi_match_ids(device, "PNP0C0D,PNP0C0C,PNP0C0E"))
  280. device->wakeup.flags.run_wake = 1;
  281. end:
  282. if (ACPI_FAILURE(status))
  283. device->flags.wake_capable = 0;
  284. return_VALUE(0);
  285. }
  286. /* --------------------------------------------------------------------------
  287. ACPI hotplug sysfs device file support
  288. -------------------------------------------------------------------------- */
  289. static ssize_t acpi_eject_store(struct acpi_device *device,
  290. const char *buf, size_t count);
  291. #define ACPI_DEVICE_ATTR(_name,_mode,_show,_store) \
  292. static struct acpi_device_attribute acpi_device_attr_##_name = \
  293. __ATTR(_name, _mode, _show, _store)
  294. ACPI_DEVICE_ATTR(eject, 0200, NULL, acpi_eject_store);
  295. /**
  296. * setup_sys_fs_device_files - sets up the device files under device namespace
  297. * @dev: acpi_device object
  298. * @func: function pointer to create or destroy the device file
  299. */
  300. static void
  301. setup_sys_fs_device_files(struct acpi_device *dev,
  302. acpi_device_sysfs_files * func)
  303. {
  304. acpi_status status;
  305. acpi_handle temp = NULL;
  306. /*
  307. * If device has _EJ0, 'eject' file is created that is used to trigger
  308. * hot-removal function from userland.
  309. */
  310. status = acpi_get_handle(dev->handle, "_EJ0", &temp);
  311. if (ACPI_SUCCESS(status))
  312. (*(func)) (&dev->kobj, &acpi_device_attr_eject.attr);
  313. }
  314. static int acpi_eject_operation(acpi_handle handle, int lockable)
  315. {
  316. struct acpi_object_list arg_list;
  317. union acpi_object arg;
  318. acpi_status status = AE_OK;
  319. /*
  320. * TBD: evaluate _PS3?
  321. */
  322. if (lockable) {
  323. arg_list.count = 1;
  324. arg_list.pointer = &arg;
  325. arg.type = ACPI_TYPE_INTEGER;
  326. arg.integer.value = 0;
  327. acpi_evaluate_object(handle, "_LCK", &arg_list, NULL);
  328. }
  329. arg_list.count = 1;
  330. arg_list.pointer = &arg;
  331. arg.type = ACPI_TYPE_INTEGER;
  332. arg.integer.value = 1;
  333. /*
  334. * TBD: _EJD support.
  335. */
  336. status = acpi_evaluate_object(handle, "_EJ0", &arg_list, NULL);
  337. if (ACPI_FAILURE(status)) {
  338. return (-ENODEV);
  339. }
  340. return (0);
  341. }
  342. static ssize_t
  343. acpi_eject_store(struct acpi_device *device, const char *buf, size_t count)
  344. {
  345. int result;
  346. int ret = count;
  347. int islockable;
  348. acpi_status status;
  349. acpi_handle handle;
  350. acpi_object_type type = 0;
  351. if ((!count) || (buf[0] != '1')) {
  352. return -EINVAL;
  353. }
  354. #ifndef FORCE_EJECT
  355. if (device->driver == NULL) {
  356. ret = -ENODEV;
  357. goto err;
  358. }
  359. #endif
  360. status = acpi_get_type(device->handle, &type);
  361. if (ACPI_FAILURE(status) || (!device->flags.ejectable)) {
  362. ret = -ENODEV;
  363. goto err;
  364. }
  365. islockable = device->flags.lockable;
  366. handle = device->handle;
  367. if (type == ACPI_TYPE_PROCESSOR)
  368. result = acpi_bus_trim(device, 0);
  369. else
  370. result = acpi_bus_trim(device, 1);
  371. if (!result)
  372. result = acpi_eject_operation(handle, islockable);
  373. if (result) {
  374. ret = -EBUSY;
  375. }
  376. err:
  377. return ret;
  378. }
  379. /* --------------------------------------------------------------------------
  380. Performance Management
  381. -------------------------------------------------------------------------- */
  382. static int acpi_bus_get_perf_flags(struct acpi_device *device)
  383. {
  384. device->performance.state = ACPI_STATE_UNKNOWN;
  385. return 0;
  386. }
  387. /* --------------------------------------------------------------------------
  388. Driver Management
  389. -------------------------------------------------------------------------- */
  390. static LIST_HEAD(acpi_bus_drivers);
  391. static DECLARE_MUTEX(acpi_bus_drivers_lock);
  392. /**
  393. * acpi_bus_match
  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
  407. * --------------------
  408. * Used to initialize a device via its device driver. Called whenever a
  409. * driver is bound to a device. Invokes the driver's add() and start() ops.
  410. */
  411. static int
  412. acpi_bus_driver_init(struct acpi_device *device, struct acpi_driver *driver)
  413. {
  414. int result = 0;
  415. ACPI_FUNCTION_TRACE("acpi_bus_driver_init");
  416. if (!device || !driver)
  417. return_VALUE(-EINVAL);
  418. if (!driver->ops.add)
  419. return_VALUE(-ENOSYS);
  420. result = driver->ops.add(device);
  421. if (result) {
  422. device->driver = NULL;
  423. acpi_driver_data(device) = NULL;
  424. return_VALUE(result);
  425. }
  426. device->driver = driver;
  427. /*
  428. * TBD - Configuration Management: Assign resources to device based
  429. * upon possible configuration and currently allocated resources.
  430. */
  431. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  432. "Driver successfully bound to device\n"));
  433. return_VALUE(0);
  434. }
  435. static int acpi_start_single_object(struct acpi_device *device)
  436. {
  437. int result = 0;
  438. struct acpi_driver *driver;
  439. ACPI_FUNCTION_TRACE("acpi_start_single_object");
  440. if (!(driver = device->driver))
  441. return_VALUE(0);
  442. if (driver->ops.start) {
  443. result = driver->ops.start(device);
  444. if (result && driver->ops.remove)
  445. driver->ops.remove(device, ACPI_BUS_REMOVAL_NORMAL);
  446. }
  447. return_VALUE(result);
  448. }
  449. static int acpi_driver_attach(struct acpi_driver *drv)
  450. {
  451. struct list_head *node, *next;
  452. int count = 0;
  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. count++;
  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. return_VALUE(count);
  475. }
  476. static int acpi_driver_detach(struct acpi_driver *drv)
  477. {
  478. struct list_head *node, *next;
  479. ACPI_FUNCTION_TRACE("acpi_driver_detach");
  480. spin_lock(&acpi_device_lock);
  481. list_for_each_safe(node, next, &acpi_device_list) {
  482. struct acpi_device *dev =
  483. container_of(node, struct acpi_device, g_list);
  484. if (dev->driver == drv) {
  485. spin_unlock(&acpi_device_lock);
  486. if (drv->ops.remove)
  487. drv->ops.remove(dev, ACPI_BUS_REMOVAL_NORMAL);
  488. spin_lock(&acpi_device_lock);
  489. dev->driver = NULL;
  490. dev->driver_data = NULL;
  491. atomic_dec(&drv->references);
  492. }
  493. }
  494. spin_unlock(&acpi_device_lock);
  495. return_VALUE(0);
  496. }
  497. /**
  498. * acpi_bus_register_driver
  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 the
  502. * number of devices that were claimed by the driver, or a negative
  503. * error status for failure.
  504. */
  505. int acpi_bus_register_driver(struct acpi_driver *driver)
  506. {
  507. int count;
  508. ACPI_FUNCTION_TRACE("acpi_bus_register_driver");
  509. if (acpi_disabled)
  510. return_VALUE(-ENODEV);
  511. if (!driver)
  512. return_VALUE(-EINVAL);
  513. spin_lock(&acpi_device_lock);
  514. list_add_tail(&driver->node, &acpi_bus_drivers);
  515. spin_unlock(&acpi_device_lock);
  516. count = acpi_driver_attach(driver);
  517. return_VALUE(count);
  518. }
  519. EXPORT_SYMBOL(acpi_bus_register_driver);
  520. /**
  521. * acpi_bus_unregister_driver
  522. * --------------------------
  523. * Unregisters a driver with the ACPI bus. Searches the namespace for all
  524. * devices that match the driver's criteria and unbinds.
  525. */
  526. int acpi_bus_unregister_driver(struct acpi_driver *driver)
  527. {
  528. int error = 0;
  529. ACPI_FUNCTION_TRACE("acpi_bus_unregister_driver");
  530. if (driver) {
  531. acpi_driver_detach(driver);
  532. if (!atomic_read(&driver->references)) {
  533. spin_lock(&acpi_device_lock);
  534. list_del_init(&driver->node);
  535. spin_unlock(&acpi_device_lock);
  536. }
  537. } else
  538. error = -EINVAL;
  539. return_VALUE(error);
  540. }
  541. EXPORT_SYMBOL(acpi_bus_unregister_driver);
  542. /**
  543. * acpi_bus_find_driver
  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 ((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. result = acpi_bus_find_driver(device);
  935. end:
  936. if (!result)
  937. *child = device;
  938. else {
  939. if (device->pnp.cid_list)
  940. kfree(device->pnp.cid_list);
  941. kfree(device);
  942. }
  943. return_VALUE(result);
  944. }
  945. static int acpi_bus_scan(struct acpi_device *start, struct acpi_bus_ops *ops)
  946. {
  947. acpi_status status = AE_OK;
  948. struct acpi_device *parent = NULL;
  949. struct acpi_device *child = NULL;
  950. acpi_handle phandle = NULL;
  951. acpi_handle chandle = NULL;
  952. acpi_object_type type = 0;
  953. u32 level = 1;
  954. ACPI_FUNCTION_TRACE("acpi_bus_scan");
  955. if (!start)
  956. return_VALUE(-EINVAL);
  957. parent = start;
  958. phandle = start->handle;
  959. /*
  960. * Parse through the ACPI namespace, identify all 'devices', and
  961. * create a new 'struct acpi_device' for each.
  962. */
  963. while ((level > 0) && parent) {
  964. status = acpi_get_next_object(ACPI_TYPE_ANY, phandle,
  965. chandle, &chandle);
  966. /*
  967. * If this scope is exhausted then move our way back up.
  968. */
  969. if (ACPI_FAILURE(status)) {
  970. level--;
  971. chandle = phandle;
  972. acpi_get_parent(phandle, &phandle);
  973. if (parent->parent)
  974. parent = parent->parent;
  975. continue;
  976. }
  977. status = acpi_get_type(chandle, &type);
  978. if (ACPI_FAILURE(status))
  979. continue;
  980. /*
  981. * If this is a scope object then parse it (depth-first).
  982. */
  983. if (type == ACPI_TYPE_LOCAL_SCOPE) {
  984. level++;
  985. phandle = chandle;
  986. chandle = NULL;
  987. continue;
  988. }
  989. /*
  990. * We're only interested in objects that we consider 'devices'.
  991. */
  992. switch (type) {
  993. case ACPI_TYPE_DEVICE:
  994. type = ACPI_BUS_TYPE_DEVICE;
  995. break;
  996. case ACPI_TYPE_PROCESSOR:
  997. type = ACPI_BUS_TYPE_PROCESSOR;
  998. break;
  999. case ACPI_TYPE_THERMAL:
  1000. type = ACPI_BUS_TYPE_THERMAL;
  1001. break;
  1002. case ACPI_TYPE_POWER:
  1003. type = ACPI_BUS_TYPE_POWER;
  1004. break;
  1005. default:
  1006. continue;
  1007. }
  1008. if (ops->acpi_op_add)
  1009. status = acpi_add_single_object(&child, parent,
  1010. chandle, type);
  1011. else
  1012. status = acpi_bus_get_device(chandle, &child);
  1013. if (ACPI_FAILURE(status))
  1014. continue;
  1015. if (ops->acpi_op_start) {
  1016. status = acpi_start_single_object(child);
  1017. if (ACPI_FAILURE(status))
  1018. continue;
  1019. }
  1020. /*
  1021. * If the device is present, enabled, and functioning then
  1022. * parse its scope (depth-first). Note that we need to
  1023. * represent absent devices to facilitate PnP notifications
  1024. * -- but only the subtree head (not all of its children,
  1025. * which will be enumerated when the parent is inserted).
  1026. *
  1027. * TBD: Need notifications and other detection mechanisms
  1028. * in place before we can fully implement this.
  1029. */
  1030. if (child->status.present) {
  1031. status = acpi_get_next_object(ACPI_TYPE_ANY, chandle,
  1032. NULL, NULL);
  1033. if (ACPI_SUCCESS(status)) {
  1034. level++;
  1035. phandle = chandle;
  1036. chandle = NULL;
  1037. parent = child;
  1038. }
  1039. }
  1040. }
  1041. return_VALUE(0);
  1042. }
  1043. int
  1044. acpi_bus_add(struct acpi_device **child,
  1045. struct acpi_device *parent, acpi_handle handle, int type)
  1046. {
  1047. int result;
  1048. struct acpi_bus_ops ops;
  1049. ACPI_FUNCTION_TRACE("acpi_bus_add");
  1050. result = acpi_add_single_object(child, parent, handle, type);
  1051. if (!result) {
  1052. memset(&ops, 0, sizeof(ops));
  1053. ops.acpi_op_add = 1;
  1054. result = acpi_bus_scan(*child, &ops);
  1055. }
  1056. return_VALUE(result);
  1057. }
  1058. EXPORT_SYMBOL(acpi_bus_add);
  1059. int acpi_bus_start(struct acpi_device *device)
  1060. {
  1061. int result;
  1062. struct acpi_bus_ops ops;
  1063. ACPI_FUNCTION_TRACE("acpi_bus_start");
  1064. if (!device)
  1065. return_VALUE(-EINVAL);
  1066. result = acpi_start_single_object(device);
  1067. if (!result) {
  1068. memset(&ops, 0, sizeof(ops));
  1069. ops.acpi_op_start = 1;
  1070. result = acpi_bus_scan(device, &ops);
  1071. }
  1072. return_VALUE(result);
  1073. }
  1074. EXPORT_SYMBOL(acpi_bus_start);
  1075. static int acpi_bus_trim(struct acpi_device *start, int rmdevice)
  1076. {
  1077. acpi_status status;
  1078. struct acpi_device *parent, *child;
  1079. acpi_handle phandle, chandle;
  1080. acpi_object_type type;
  1081. u32 level = 1;
  1082. int err = 0;
  1083. parent = start;
  1084. phandle = start->handle;
  1085. child = chandle = NULL;
  1086. while ((level > 0) && parent && (!err)) {
  1087. status = acpi_get_next_object(ACPI_TYPE_ANY, phandle,
  1088. chandle, &chandle);
  1089. /*
  1090. * If this scope is exhausted then move our way back up.
  1091. */
  1092. if (ACPI_FAILURE(status)) {
  1093. level--;
  1094. chandle = phandle;
  1095. acpi_get_parent(phandle, &phandle);
  1096. child = parent;
  1097. parent = parent->parent;
  1098. if (level == 0)
  1099. err = acpi_bus_remove(child, rmdevice);
  1100. else
  1101. err = acpi_bus_remove(child, 1);
  1102. continue;
  1103. }
  1104. status = acpi_get_type(chandle, &type);
  1105. if (ACPI_FAILURE(status)) {
  1106. continue;
  1107. }
  1108. /*
  1109. * If there is a device corresponding to chandle then
  1110. * parse it (depth-first).
  1111. */
  1112. if (acpi_bus_get_device(chandle, &child) == 0) {
  1113. level++;
  1114. phandle = chandle;
  1115. chandle = NULL;
  1116. parent = child;
  1117. }
  1118. continue;
  1119. }
  1120. return err;
  1121. }
  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);