scan.c 34 KB

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