scan.c 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005
  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/slab.h>
  7. #include <linux/kernel.h>
  8. #include <linux/acpi.h>
  9. #include <linux/signal.h>
  10. #include <linux/kthread.h>
  11. #include <linux/dmi.h>
  12. #include <linux/nls.h>
  13. #include <linux/dma-mapping.h>
  14. #include <asm/pgtable.h>
  15. #include "internal.h"
  16. #define _COMPONENT ACPI_BUS_COMPONENT
  17. ACPI_MODULE_NAME("scan");
  18. extern struct acpi_device *acpi_root;
  19. #define ACPI_BUS_CLASS "system_bus"
  20. #define ACPI_BUS_HID "LNXSYBUS"
  21. #define ACPI_BUS_DEVICE_NAME "System Bus"
  22. #define ACPI_IS_ROOT_DEVICE(device) (!(device)->parent)
  23. #define INVALID_ACPI_HANDLE ((acpi_handle)empty_zero_page)
  24. /*
  25. * If set, devices will be hot-removed even if they cannot be put offline
  26. * gracefully (from the kernel's standpoint).
  27. */
  28. bool acpi_force_hot_remove;
  29. static const char *dummy_hid = "device";
  30. static LIST_HEAD(acpi_dep_list);
  31. static DEFINE_MUTEX(acpi_dep_list_lock);
  32. LIST_HEAD(acpi_bus_id_list);
  33. static DEFINE_MUTEX(acpi_scan_lock);
  34. static LIST_HEAD(acpi_scan_handlers_list);
  35. DEFINE_MUTEX(acpi_device_lock);
  36. LIST_HEAD(acpi_wakeup_device_list);
  37. static DEFINE_MUTEX(acpi_hp_context_lock);
  38. struct acpi_dep_data {
  39. struct list_head node;
  40. acpi_handle master;
  41. acpi_handle slave;
  42. };
  43. void acpi_scan_lock_acquire(void)
  44. {
  45. mutex_lock(&acpi_scan_lock);
  46. }
  47. EXPORT_SYMBOL_GPL(acpi_scan_lock_acquire);
  48. void acpi_scan_lock_release(void)
  49. {
  50. mutex_unlock(&acpi_scan_lock);
  51. }
  52. EXPORT_SYMBOL_GPL(acpi_scan_lock_release);
  53. void acpi_lock_hp_context(void)
  54. {
  55. mutex_lock(&acpi_hp_context_lock);
  56. }
  57. void acpi_unlock_hp_context(void)
  58. {
  59. mutex_unlock(&acpi_hp_context_lock);
  60. }
  61. void acpi_initialize_hp_context(struct acpi_device *adev,
  62. struct acpi_hotplug_context *hp,
  63. int (*notify)(struct acpi_device *, u32),
  64. void (*uevent)(struct acpi_device *, u32))
  65. {
  66. acpi_lock_hp_context();
  67. hp->notify = notify;
  68. hp->uevent = uevent;
  69. acpi_set_hp_context(adev, hp);
  70. acpi_unlock_hp_context();
  71. }
  72. EXPORT_SYMBOL_GPL(acpi_initialize_hp_context);
  73. int acpi_scan_add_handler(struct acpi_scan_handler *handler)
  74. {
  75. if (!handler)
  76. return -EINVAL;
  77. list_add_tail(&handler->list_node, &acpi_scan_handlers_list);
  78. return 0;
  79. }
  80. int acpi_scan_add_handler_with_hotplug(struct acpi_scan_handler *handler,
  81. const char *hotplug_profile_name)
  82. {
  83. int error;
  84. error = acpi_scan_add_handler(handler);
  85. if (error)
  86. return error;
  87. acpi_sysfs_add_hotplug_profile(&handler->hotplug, hotplug_profile_name);
  88. return 0;
  89. }
  90. bool acpi_scan_is_offline(struct acpi_device *adev, bool uevent)
  91. {
  92. struct acpi_device_physical_node *pn;
  93. bool offline = true;
  94. /*
  95. * acpi_container_offline() calls this for all of the container's
  96. * children under the container's physical_node_lock lock.
  97. */
  98. mutex_lock_nested(&adev->physical_node_lock, SINGLE_DEPTH_NESTING);
  99. list_for_each_entry(pn, &adev->physical_node_list, node)
  100. if (device_supports_offline(pn->dev) && !pn->dev->offline) {
  101. if (uevent)
  102. kobject_uevent(&pn->dev->kobj, KOBJ_CHANGE);
  103. offline = false;
  104. break;
  105. }
  106. mutex_unlock(&adev->physical_node_lock);
  107. return offline;
  108. }
  109. static acpi_status acpi_bus_offline(acpi_handle handle, u32 lvl, void *data,
  110. void **ret_p)
  111. {
  112. struct acpi_device *device = NULL;
  113. struct acpi_device_physical_node *pn;
  114. bool second_pass = (bool)data;
  115. acpi_status status = AE_OK;
  116. if (acpi_bus_get_device(handle, &device))
  117. return AE_OK;
  118. if (device->handler && !device->handler->hotplug.enabled) {
  119. *ret_p = &device->dev;
  120. return AE_SUPPORT;
  121. }
  122. mutex_lock(&device->physical_node_lock);
  123. list_for_each_entry(pn, &device->physical_node_list, node) {
  124. int ret;
  125. if (second_pass) {
  126. /* Skip devices offlined by the first pass. */
  127. if (pn->put_online)
  128. continue;
  129. } else {
  130. pn->put_online = false;
  131. }
  132. ret = device_offline(pn->dev);
  133. if (acpi_force_hot_remove)
  134. continue;
  135. if (ret >= 0) {
  136. pn->put_online = !ret;
  137. } else {
  138. *ret_p = pn->dev;
  139. if (second_pass) {
  140. status = AE_ERROR;
  141. break;
  142. }
  143. }
  144. }
  145. mutex_unlock(&device->physical_node_lock);
  146. return status;
  147. }
  148. static acpi_status acpi_bus_online(acpi_handle handle, u32 lvl, void *data,
  149. void **ret_p)
  150. {
  151. struct acpi_device *device = NULL;
  152. struct acpi_device_physical_node *pn;
  153. if (acpi_bus_get_device(handle, &device))
  154. return AE_OK;
  155. mutex_lock(&device->physical_node_lock);
  156. list_for_each_entry(pn, &device->physical_node_list, node)
  157. if (pn->put_online) {
  158. device_online(pn->dev);
  159. pn->put_online = false;
  160. }
  161. mutex_unlock(&device->physical_node_lock);
  162. return AE_OK;
  163. }
  164. static int acpi_scan_try_to_offline(struct acpi_device *device)
  165. {
  166. acpi_handle handle = device->handle;
  167. struct device *errdev = NULL;
  168. acpi_status status;
  169. /*
  170. * Carry out two passes here and ignore errors in the first pass,
  171. * because if the devices in question are memory blocks and
  172. * CONFIG_MEMCG is set, one of the blocks may hold data structures
  173. * that the other blocks depend on, but it is not known in advance which
  174. * block holds them.
  175. *
  176. * If the first pass is successful, the second one isn't needed, though.
  177. */
  178. status = acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
  179. NULL, acpi_bus_offline, (void *)false,
  180. (void **)&errdev);
  181. if (status == AE_SUPPORT) {
  182. dev_warn(errdev, "Offline disabled.\n");
  183. acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
  184. acpi_bus_online, NULL, NULL, NULL);
  185. return -EPERM;
  186. }
  187. acpi_bus_offline(handle, 0, (void *)false, (void **)&errdev);
  188. if (errdev) {
  189. errdev = NULL;
  190. acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
  191. NULL, acpi_bus_offline, (void *)true,
  192. (void **)&errdev);
  193. if (!errdev || acpi_force_hot_remove)
  194. acpi_bus_offline(handle, 0, (void *)true,
  195. (void **)&errdev);
  196. if (errdev && !acpi_force_hot_remove) {
  197. dev_warn(errdev, "Offline failed.\n");
  198. acpi_bus_online(handle, 0, NULL, NULL);
  199. acpi_walk_namespace(ACPI_TYPE_ANY, handle,
  200. ACPI_UINT32_MAX, acpi_bus_online,
  201. NULL, NULL, NULL);
  202. return -EBUSY;
  203. }
  204. }
  205. return 0;
  206. }
  207. static int acpi_scan_hot_remove(struct acpi_device *device)
  208. {
  209. acpi_handle handle = device->handle;
  210. unsigned long long sta;
  211. acpi_status status;
  212. if (device->handler && device->handler->hotplug.demand_offline
  213. && !acpi_force_hot_remove) {
  214. if (!acpi_scan_is_offline(device, true))
  215. return -EBUSY;
  216. } else {
  217. int error = acpi_scan_try_to_offline(device);
  218. if (error)
  219. return error;
  220. }
  221. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  222. "Hot-removing device %s...\n", dev_name(&device->dev)));
  223. acpi_bus_trim(device);
  224. acpi_evaluate_lck(handle, 0);
  225. /*
  226. * TBD: _EJD support.
  227. */
  228. status = acpi_evaluate_ej0(handle);
  229. if (status == AE_NOT_FOUND)
  230. return -ENODEV;
  231. else if (ACPI_FAILURE(status))
  232. return -EIO;
  233. /*
  234. * Verify if eject was indeed successful. If not, log an error
  235. * message. No need to call _OST since _EJ0 call was made OK.
  236. */
  237. status = acpi_evaluate_integer(handle, "_STA", NULL, &sta);
  238. if (ACPI_FAILURE(status)) {
  239. acpi_handle_warn(handle,
  240. "Status check after eject failed (0x%x)\n", status);
  241. } else if (sta & ACPI_STA_DEVICE_ENABLED) {
  242. acpi_handle_warn(handle,
  243. "Eject incomplete - status 0x%llx\n", sta);
  244. }
  245. return 0;
  246. }
  247. static int acpi_scan_device_not_present(struct acpi_device *adev)
  248. {
  249. if (!acpi_device_enumerated(adev)) {
  250. dev_warn(&adev->dev, "Still not present\n");
  251. return -EALREADY;
  252. }
  253. acpi_bus_trim(adev);
  254. return 0;
  255. }
  256. static int acpi_scan_device_check(struct acpi_device *adev)
  257. {
  258. int error;
  259. acpi_bus_get_status(adev);
  260. if (adev->status.present || adev->status.functional) {
  261. /*
  262. * This function is only called for device objects for which
  263. * matching scan handlers exist. The only situation in which
  264. * the scan handler is not attached to this device object yet
  265. * is when the device has just appeared (either it wasn't
  266. * present at all before or it was removed and then added
  267. * again).
  268. */
  269. if (adev->handler) {
  270. dev_warn(&adev->dev, "Already enumerated\n");
  271. return -EALREADY;
  272. }
  273. error = acpi_bus_scan(adev->handle);
  274. if (error) {
  275. dev_warn(&adev->dev, "Namespace scan failure\n");
  276. return error;
  277. }
  278. if (!adev->handler) {
  279. dev_warn(&adev->dev, "Enumeration failure\n");
  280. error = -ENODEV;
  281. }
  282. } else {
  283. error = acpi_scan_device_not_present(adev);
  284. }
  285. return error;
  286. }
  287. static int acpi_scan_bus_check(struct acpi_device *adev)
  288. {
  289. struct acpi_scan_handler *handler = adev->handler;
  290. struct acpi_device *child;
  291. int error;
  292. acpi_bus_get_status(adev);
  293. if (!(adev->status.present || adev->status.functional)) {
  294. acpi_scan_device_not_present(adev);
  295. return 0;
  296. }
  297. if (handler && handler->hotplug.scan_dependent)
  298. return handler->hotplug.scan_dependent(adev);
  299. error = acpi_bus_scan(adev->handle);
  300. if (error) {
  301. dev_warn(&adev->dev, "Namespace scan failure\n");
  302. return error;
  303. }
  304. list_for_each_entry(child, &adev->children, node) {
  305. error = acpi_scan_bus_check(child);
  306. if (error)
  307. return error;
  308. }
  309. return 0;
  310. }
  311. static int acpi_generic_hotplug_event(struct acpi_device *adev, u32 type)
  312. {
  313. switch (type) {
  314. case ACPI_NOTIFY_BUS_CHECK:
  315. return acpi_scan_bus_check(adev);
  316. case ACPI_NOTIFY_DEVICE_CHECK:
  317. return acpi_scan_device_check(adev);
  318. case ACPI_NOTIFY_EJECT_REQUEST:
  319. case ACPI_OST_EC_OSPM_EJECT:
  320. if (adev->handler && !adev->handler->hotplug.enabled) {
  321. dev_info(&adev->dev, "Eject disabled\n");
  322. return -EPERM;
  323. }
  324. acpi_evaluate_ost(adev->handle, ACPI_NOTIFY_EJECT_REQUEST,
  325. ACPI_OST_SC_EJECT_IN_PROGRESS, NULL);
  326. return acpi_scan_hot_remove(adev);
  327. }
  328. return -EINVAL;
  329. }
  330. void acpi_device_hotplug(struct acpi_device *adev, u32 src)
  331. {
  332. u32 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE;
  333. int error = -ENODEV;
  334. lock_device_hotplug();
  335. mutex_lock(&acpi_scan_lock);
  336. /*
  337. * The device object's ACPI handle cannot become invalid as long as we
  338. * are holding acpi_scan_lock, but it might have become invalid before
  339. * that lock was acquired.
  340. */
  341. if (adev->handle == INVALID_ACPI_HANDLE)
  342. goto err_out;
  343. if (adev->flags.is_dock_station) {
  344. error = dock_notify(adev, src);
  345. } else if (adev->flags.hotplug_notify) {
  346. error = acpi_generic_hotplug_event(adev, src);
  347. if (error == -EPERM) {
  348. ost_code = ACPI_OST_SC_EJECT_NOT_SUPPORTED;
  349. goto err_out;
  350. }
  351. } else {
  352. int (*notify)(struct acpi_device *, u32);
  353. acpi_lock_hp_context();
  354. notify = adev->hp ? adev->hp->notify : NULL;
  355. acpi_unlock_hp_context();
  356. /*
  357. * There may be additional notify handlers for device objects
  358. * without the .event() callback, so ignore them here.
  359. */
  360. if (notify)
  361. error = notify(adev, src);
  362. else
  363. goto out;
  364. }
  365. if (!error)
  366. ost_code = ACPI_OST_SC_SUCCESS;
  367. err_out:
  368. acpi_evaluate_ost(adev->handle, src, ost_code, NULL);
  369. out:
  370. acpi_bus_put_acpi_device(adev);
  371. mutex_unlock(&acpi_scan_lock);
  372. unlock_device_hotplug();
  373. }
  374. static void acpi_free_power_resources_lists(struct acpi_device *device)
  375. {
  376. int i;
  377. if (device->wakeup.flags.valid)
  378. acpi_power_resources_list_free(&device->wakeup.resources);
  379. if (!device->power.flags.power_resources)
  380. return;
  381. for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3_HOT; i++) {
  382. struct acpi_device_power_state *ps = &device->power.states[i];
  383. acpi_power_resources_list_free(&ps->resources);
  384. }
  385. }
  386. static void acpi_device_release(struct device *dev)
  387. {
  388. struct acpi_device *acpi_dev = to_acpi_device(dev);
  389. acpi_free_properties(acpi_dev);
  390. acpi_free_pnp_ids(&acpi_dev->pnp);
  391. acpi_free_power_resources_lists(acpi_dev);
  392. kfree(acpi_dev);
  393. }
  394. static void acpi_device_del(struct acpi_device *device)
  395. {
  396. struct acpi_device_bus_id *acpi_device_bus_id;
  397. mutex_lock(&acpi_device_lock);
  398. if (device->parent)
  399. list_del(&device->node);
  400. list_for_each_entry(acpi_device_bus_id, &acpi_bus_id_list, node)
  401. if (!strcmp(acpi_device_bus_id->bus_id,
  402. acpi_device_hid(device))) {
  403. if (acpi_device_bus_id->instance_no > 0)
  404. acpi_device_bus_id->instance_no--;
  405. else {
  406. list_del(&acpi_device_bus_id->node);
  407. kfree(acpi_device_bus_id);
  408. }
  409. break;
  410. }
  411. list_del(&device->wakeup_list);
  412. mutex_unlock(&acpi_device_lock);
  413. acpi_power_add_remove_device(device, false);
  414. acpi_device_remove_files(device);
  415. if (device->remove)
  416. device->remove(device);
  417. device_del(&device->dev);
  418. }
  419. static LIST_HEAD(acpi_device_del_list);
  420. static DEFINE_MUTEX(acpi_device_del_lock);
  421. static void acpi_device_del_work_fn(struct work_struct *work_not_used)
  422. {
  423. for (;;) {
  424. struct acpi_device *adev;
  425. mutex_lock(&acpi_device_del_lock);
  426. if (list_empty(&acpi_device_del_list)) {
  427. mutex_unlock(&acpi_device_del_lock);
  428. break;
  429. }
  430. adev = list_first_entry(&acpi_device_del_list,
  431. struct acpi_device, del_list);
  432. list_del(&adev->del_list);
  433. mutex_unlock(&acpi_device_del_lock);
  434. acpi_device_del(adev);
  435. /*
  436. * Drop references to all power resources that might have been
  437. * used by the device.
  438. */
  439. acpi_power_transition(adev, ACPI_STATE_D3_COLD);
  440. put_device(&adev->dev);
  441. }
  442. }
  443. /**
  444. * acpi_scan_drop_device - Drop an ACPI device object.
  445. * @handle: Handle of an ACPI namespace node, not used.
  446. * @context: Address of the ACPI device object to drop.
  447. *
  448. * This is invoked by acpi_ns_delete_node() during the removal of the ACPI
  449. * namespace node the device object pointed to by @context is attached to.
  450. *
  451. * The unregistration is carried out asynchronously to avoid running
  452. * acpi_device_del() under the ACPICA's namespace mutex and the list is used to
  453. * ensure the correct ordering (the device objects must be unregistered in the
  454. * same order in which the corresponding namespace nodes are deleted).
  455. */
  456. static void acpi_scan_drop_device(acpi_handle handle, void *context)
  457. {
  458. static DECLARE_WORK(work, acpi_device_del_work_fn);
  459. struct acpi_device *adev = context;
  460. mutex_lock(&acpi_device_del_lock);
  461. /*
  462. * Use the ACPI hotplug workqueue which is ordered, so this work item
  463. * won't run after any hotplug work items submitted subsequently. That
  464. * prevents attempts to register device objects identical to those being
  465. * deleted from happening concurrently (such attempts result from
  466. * hotplug events handled via the ACPI hotplug workqueue). It also will
  467. * run after all of the work items submitted previosuly, which helps
  468. * those work items to ensure that they are not accessing stale device
  469. * objects.
  470. */
  471. if (list_empty(&acpi_device_del_list))
  472. acpi_queue_hotplug_work(&work);
  473. list_add_tail(&adev->del_list, &acpi_device_del_list);
  474. /* Make acpi_ns_validate_handle() return NULL for this handle. */
  475. adev->handle = INVALID_ACPI_HANDLE;
  476. mutex_unlock(&acpi_device_del_lock);
  477. }
  478. static int acpi_get_device_data(acpi_handle handle, struct acpi_device **device,
  479. void (*callback)(void *))
  480. {
  481. acpi_status status;
  482. if (!device)
  483. return -EINVAL;
  484. status = acpi_get_data_full(handle, acpi_scan_drop_device,
  485. (void **)device, callback);
  486. if (ACPI_FAILURE(status) || !*device) {
  487. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
  488. handle));
  489. return -ENODEV;
  490. }
  491. return 0;
  492. }
  493. int acpi_bus_get_device(acpi_handle handle, struct acpi_device **device)
  494. {
  495. return acpi_get_device_data(handle, device, NULL);
  496. }
  497. EXPORT_SYMBOL(acpi_bus_get_device);
  498. static void get_acpi_device(void *dev)
  499. {
  500. if (dev)
  501. get_device(&((struct acpi_device *)dev)->dev);
  502. }
  503. struct acpi_device *acpi_bus_get_acpi_device(acpi_handle handle)
  504. {
  505. struct acpi_device *adev = NULL;
  506. acpi_get_device_data(handle, &adev, get_acpi_device);
  507. return adev;
  508. }
  509. void acpi_bus_put_acpi_device(struct acpi_device *adev)
  510. {
  511. put_device(&adev->dev);
  512. }
  513. int acpi_device_add(struct acpi_device *device,
  514. void (*release)(struct device *))
  515. {
  516. int result;
  517. struct acpi_device_bus_id *acpi_device_bus_id, *new_bus_id;
  518. int found = 0;
  519. if (device->handle) {
  520. acpi_status status;
  521. status = acpi_attach_data(device->handle, acpi_scan_drop_device,
  522. device);
  523. if (ACPI_FAILURE(status)) {
  524. acpi_handle_err(device->handle,
  525. "Unable to attach device data\n");
  526. return -ENODEV;
  527. }
  528. }
  529. /*
  530. * Linkage
  531. * -------
  532. * Link this device to its parent and siblings.
  533. */
  534. INIT_LIST_HEAD(&device->children);
  535. INIT_LIST_HEAD(&device->node);
  536. INIT_LIST_HEAD(&device->wakeup_list);
  537. INIT_LIST_HEAD(&device->physical_node_list);
  538. INIT_LIST_HEAD(&device->del_list);
  539. mutex_init(&device->physical_node_lock);
  540. new_bus_id = kzalloc(sizeof(struct acpi_device_bus_id), GFP_KERNEL);
  541. if (!new_bus_id) {
  542. pr_err(PREFIX "Memory allocation error\n");
  543. result = -ENOMEM;
  544. goto err_detach;
  545. }
  546. mutex_lock(&acpi_device_lock);
  547. /*
  548. * Find suitable bus_id and instance number in acpi_bus_id_list
  549. * If failed, create one and link it into acpi_bus_id_list
  550. */
  551. list_for_each_entry(acpi_device_bus_id, &acpi_bus_id_list, node) {
  552. if (!strcmp(acpi_device_bus_id->bus_id,
  553. acpi_device_hid(device))) {
  554. acpi_device_bus_id->instance_no++;
  555. found = 1;
  556. kfree(new_bus_id);
  557. break;
  558. }
  559. }
  560. if (!found) {
  561. acpi_device_bus_id = new_bus_id;
  562. strcpy(acpi_device_bus_id->bus_id, acpi_device_hid(device));
  563. acpi_device_bus_id->instance_no = 0;
  564. list_add_tail(&acpi_device_bus_id->node, &acpi_bus_id_list);
  565. }
  566. dev_set_name(&device->dev, "%s:%02x", acpi_device_bus_id->bus_id, acpi_device_bus_id->instance_no);
  567. if (device->parent)
  568. list_add_tail(&device->node, &device->parent->children);
  569. if (device->wakeup.flags.valid)
  570. list_add_tail(&device->wakeup_list, &acpi_wakeup_device_list);
  571. mutex_unlock(&acpi_device_lock);
  572. if (device->parent)
  573. device->dev.parent = &device->parent->dev;
  574. device->dev.bus = &acpi_bus_type;
  575. device->dev.release = release;
  576. result = device_add(&device->dev);
  577. if (result) {
  578. dev_err(&device->dev, "Error registering device\n");
  579. goto err;
  580. }
  581. result = acpi_device_setup_files(device);
  582. if (result)
  583. printk(KERN_ERR PREFIX "Error creating sysfs interface for device %s\n",
  584. dev_name(&device->dev));
  585. return 0;
  586. err:
  587. mutex_lock(&acpi_device_lock);
  588. if (device->parent)
  589. list_del(&device->node);
  590. list_del(&device->wakeup_list);
  591. mutex_unlock(&acpi_device_lock);
  592. err_detach:
  593. acpi_detach_data(device->handle, acpi_scan_drop_device);
  594. return result;
  595. }
  596. /* --------------------------------------------------------------------------
  597. Device Enumeration
  598. -------------------------------------------------------------------------- */
  599. static struct acpi_device *acpi_bus_get_parent(acpi_handle handle)
  600. {
  601. struct acpi_device *device = NULL;
  602. acpi_status status;
  603. /*
  604. * Fixed hardware devices do not appear in the namespace and do not
  605. * have handles, but we fabricate acpi_devices for them, so we have
  606. * to deal with them specially.
  607. */
  608. if (!handle)
  609. return acpi_root;
  610. do {
  611. status = acpi_get_parent(handle, &handle);
  612. if (ACPI_FAILURE(status))
  613. return status == AE_NULL_ENTRY ? NULL : acpi_root;
  614. } while (acpi_bus_get_device(handle, &device));
  615. return device;
  616. }
  617. acpi_status
  618. acpi_bus_get_ejd(acpi_handle handle, acpi_handle *ejd)
  619. {
  620. acpi_status status;
  621. acpi_handle tmp;
  622. struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
  623. union acpi_object *obj;
  624. status = acpi_get_handle(handle, "_EJD", &tmp);
  625. if (ACPI_FAILURE(status))
  626. return status;
  627. status = acpi_evaluate_object(handle, "_EJD", NULL, &buffer);
  628. if (ACPI_SUCCESS(status)) {
  629. obj = buffer.pointer;
  630. status = acpi_get_handle(ACPI_ROOT_OBJECT, obj->string.pointer,
  631. ejd);
  632. kfree(buffer.pointer);
  633. }
  634. return status;
  635. }
  636. EXPORT_SYMBOL_GPL(acpi_bus_get_ejd);
  637. static int acpi_bus_extract_wakeup_device_power_package(acpi_handle handle,
  638. struct acpi_device_wakeup *wakeup)
  639. {
  640. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  641. union acpi_object *package = NULL;
  642. union acpi_object *element = NULL;
  643. acpi_status status;
  644. int err = -ENODATA;
  645. if (!wakeup)
  646. return -EINVAL;
  647. INIT_LIST_HEAD(&wakeup->resources);
  648. /* _PRW */
  649. status = acpi_evaluate_object(handle, "_PRW", NULL, &buffer);
  650. if (ACPI_FAILURE(status)) {
  651. ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRW"));
  652. return err;
  653. }
  654. package = (union acpi_object *)buffer.pointer;
  655. if (!package || package->package.count < 2)
  656. goto out;
  657. element = &(package->package.elements[0]);
  658. if (!element)
  659. goto out;
  660. if (element->type == ACPI_TYPE_PACKAGE) {
  661. if ((element->package.count < 2) ||
  662. (element->package.elements[0].type !=
  663. ACPI_TYPE_LOCAL_REFERENCE)
  664. || (element->package.elements[1].type != ACPI_TYPE_INTEGER))
  665. goto out;
  666. wakeup->gpe_device =
  667. element->package.elements[0].reference.handle;
  668. wakeup->gpe_number =
  669. (u32) element->package.elements[1].integer.value;
  670. } else if (element->type == ACPI_TYPE_INTEGER) {
  671. wakeup->gpe_device = NULL;
  672. wakeup->gpe_number = element->integer.value;
  673. } else {
  674. goto out;
  675. }
  676. element = &(package->package.elements[1]);
  677. if (element->type != ACPI_TYPE_INTEGER)
  678. goto out;
  679. wakeup->sleep_state = element->integer.value;
  680. err = acpi_extract_power_resources(package, 2, &wakeup->resources);
  681. if (err)
  682. goto out;
  683. if (!list_empty(&wakeup->resources)) {
  684. int sleep_state;
  685. err = acpi_power_wakeup_list_init(&wakeup->resources,
  686. &sleep_state);
  687. if (err) {
  688. acpi_handle_warn(handle, "Retrieving current states "
  689. "of wakeup power resources failed\n");
  690. acpi_power_resources_list_free(&wakeup->resources);
  691. goto out;
  692. }
  693. if (sleep_state < wakeup->sleep_state) {
  694. acpi_handle_warn(handle, "Overriding _PRW sleep state "
  695. "(S%d) by S%d from power resources\n",
  696. (int)wakeup->sleep_state, sleep_state);
  697. wakeup->sleep_state = sleep_state;
  698. }
  699. }
  700. out:
  701. kfree(buffer.pointer);
  702. return err;
  703. }
  704. static void acpi_wakeup_gpe_init(struct acpi_device *device)
  705. {
  706. static const struct acpi_device_id button_device_ids[] = {
  707. {"PNP0C0C", 0},
  708. {"PNP0C0D", 0},
  709. {"PNP0C0E", 0},
  710. {"", 0},
  711. };
  712. struct acpi_device_wakeup *wakeup = &device->wakeup;
  713. acpi_status status;
  714. acpi_event_status event_status;
  715. wakeup->flags.notifier_present = 0;
  716. /* Power button, Lid switch always enable wakeup */
  717. if (!acpi_match_device_ids(device, button_device_ids)) {
  718. wakeup->flags.run_wake = 1;
  719. if (!acpi_match_device_ids(device, &button_device_ids[1])) {
  720. /* Do not use Lid/sleep button for S5 wakeup */
  721. if (wakeup->sleep_state == ACPI_STATE_S5)
  722. wakeup->sleep_state = ACPI_STATE_S4;
  723. }
  724. acpi_mark_gpe_for_wake(wakeup->gpe_device, wakeup->gpe_number);
  725. device_set_wakeup_capable(&device->dev, true);
  726. return;
  727. }
  728. acpi_setup_gpe_for_wake(device->handle, wakeup->gpe_device,
  729. wakeup->gpe_number);
  730. status = acpi_get_gpe_status(wakeup->gpe_device, wakeup->gpe_number,
  731. &event_status);
  732. if (ACPI_FAILURE(status))
  733. return;
  734. wakeup->flags.run_wake = !!(event_status & ACPI_EVENT_FLAG_HAS_HANDLER);
  735. }
  736. static void acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
  737. {
  738. int err;
  739. /* Presence of _PRW indicates wake capable */
  740. if (!acpi_has_method(device->handle, "_PRW"))
  741. return;
  742. err = acpi_bus_extract_wakeup_device_power_package(device->handle,
  743. &device->wakeup);
  744. if (err) {
  745. dev_err(&device->dev, "_PRW evaluation error: %d\n", err);
  746. return;
  747. }
  748. device->wakeup.flags.valid = 1;
  749. device->wakeup.prepare_count = 0;
  750. acpi_wakeup_gpe_init(device);
  751. /* Call _PSW/_DSW object to disable its ability to wake the sleeping
  752. * system for the ACPI device with the _PRW object.
  753. * The _PSW object is depreciated in ACPI 3.0 and is replaced by _DSW.
  754. * So it is necessary to call _DSW object first. Only when it is not
  755. * present will the _PSW object used.
  756. */
  757. err = acpi_device_sleep_wake(device, 0, 0, 0);
  758. if (err)
  759. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  760. "error in _DSW or _PSW evaluation\n"));
  761. }
  762. static void acpi_bus_init_power_state(struct acpi_device *device, int state)
  763. {
  764. struct acpi_device_power_state *ps = &device->power.states[state];
  765. char pathname[5] = { '_', 'P', 'R', '0' + state, '\0' };
  766. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  767. acpi_status status;
  768. INIT_LIST_HEAD(&ps->resources);
  769. /* Evaluate "_PRx" to get referenced power resources */
  770. status = acpi_evaluate_object(device->handle, pathname, NULL, &buffer);
  771. if (ACPI_SUCCESS(status)) {
  772. union acpi_object *package = buffer.pointer;
  773. if (buffer.length && package
  774. && package->type == ACPI_TYPE_PACKAGE
  775. && package->package.count) {
  776. int err = acpi_extract_power_resources(package, 0,
  777. &ps->resources);
  778. if (!err)
  779. device->power.flags.power_resources = 1;
  780. }
  781. ACPI_FREE(buffer.pointer);
  782. }
  783. /* Evaluate "_PSx" to see if we can do explicit sets */
  784. pathname[2] = 'S';
  785. if (acpi_has_method(device->handle, pathname))
  786. ps->flags.explicit_set = 1;
  787. /* State is valid if there are means to put the device into it. */
  788. if (!list_empty(&ps->resources) || ps->flags.explicit_set)
  789. ps->flags.valid = 1;
  790. ps->power = -1; /* Unknown - driver assigned */
  791. ps->latency = -1; /* Unknown - driver assigned */
  792. }
  793. static void acpi_bus_get_power_flags(struct acpi_device *device)
  794. {
  795. u32 i;
  796. /* Presence of _PS0|_PR0 indicates 'power manageable' */
  797. if (!acpi_has_method(device->handle, "_PS0") &&
  798. !acpi_has_method(device->handle, "_PR0"))
  799. return;
  800. device->flags.power_manageable = 1;
  801. /*
  802. * Power Management Flags
  803. */
  804. if (acpi_has_method(device->handle, "_PSC"))
  805. device->power.flags.explicit_get = 1;
  806. if (acpi_has_method(device->handle, "_IRC"))
  807. device->power.flags.inrush_current = 1;
  808. if (acpi_has_method(device->handle, "_DSW"))
  809. device->power.flags.dsw_present = 1;
  810. /*
  811. * Enumerate supported power management states
  812. */
  813. for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3_HOT; i++)
  814. acpi_bus_init_power_state(device, i);
  815. INIT_LIST_HEAD(&device->power.states[ACPI_STATE_D3_COLD].resources);
  816. if (!list_empty(&device->power.states[ACPI_STATE_D3_HOT].resources))
  817. device->power.states[ACPI_STATE_D3_COLD].flags.valid = 1;
  818. /* Set defaults for D0 and D3hot states (always valid) */
  819. device->power.states[ACPI_STATE_D0].flags.valid = 1;
  820. device->power.states[ACPI_STATE_D0].power = 100;
  821. device->power.states[ACPI_STATE_D3_HOT].flags.valid = 1;
  822. if (acpi_bus_init_power(device))
  823. device->flags.power_manageable = 0;
  824. }
  825. static void acpi_bus_get_flags(struct acpi_device *device)
  826. {
  827. /* Presence of _STA indicates 'dynamic_status' */
  828. if (acpi_has_method(device->handle, "_STA"))
  829. device->flags.dynamic_status = 1;
  830. /* Presence of _RMV indicates 'removable' */
  831. if (acpi_has_method(device->handle, "_RMV"))
  832. device->flags.removable = 1;
  833. /* Presence of _EJD|_EJ0 indicates 'ejectable' */
  834. if (acpi_has_method(device->handle, "_EJD") ||
  835. acpi_has_method(device->handle, "_EJ0"))
  836. device->flags.ejectable = 1;
  837. }
  838. static void acpi_device_get_busid(struct acpi_device *device)
  839. {
  840. char bus_id[5] = { '?', 0 };
  841. struct acpi_buffer buffer = { sizeof(bus_id), bus_id };
  842. int i = 0;
  843. /*
  844. * Bus ID
  845. * ------
  846. * The device's Bus ID is simply the object name.
  847. * TBD: Shouldn't this value be unique (within the ACPI namespace)?
  848. */
  849. if (ACPI_IS_ROOT_DEVICE(device)) {
  850. strcpy(device->pnp.bus_id, "ACPI");
  851. return;
  852. }
  853. switch (device->device_type) {
  854. case ACPI_BUS_TYPE_POWER_BUTTON:
  855. strcpy(device->pnp.bus_id, "PWRF");
  856. break;
  857. case ACPI_BUS_TYPE_SLEEP_BUTTON:
  858. strcpy(device->pnp.bus_id, "SLPF");
  859. break;
  860. default:
  861. acpi_get_name(device->handle, ACPI_SINGLE_NAME, &buffer);
  862. /* Clean up trailing underscores (if any) */
  863. for (i = 3; i > 1; i--) {
  864. if (bus_id[i] == '_')
  865. bus_id[i] = '\0';
  866. else
  867. break;
  868. }
  869. strcpy(device->pnp.bus_id, bus_id);
  870. break;
  871. }
  872. }
  873. /*
  874. * acpi_ata_match - see if an acpi object is an ATA device
  875. *
  876. * If an acpi object has one of the ACPI ATA methods defined,
  877. * then we can safely call it an ATA device.
  878. */
  879. bool acpi_ata_match(acpi_handle handle)
  880. {
  881. return acpi_has_method(handle, "_GTF") ||
  882. acpi_has_method(handle, "_GTM") ||
  883. acpi_has_method(handle, "_STM") ||
  884. acpi_has_method(handle, "_SDD");
  885. }
  886. /*
  887. * acpi_bay_match - see if an acpi object is an ejectable driver bay
  888. *
  889. * If an acpi object is ejectable and has one of the ACPI ATA methods defined,
  890. * then we can safely call it an ejectable drive bay
  891. */
  892. bool acpi_bay_match(acpi_handle handle)
  893. {
  894. acpi_handle phandle;
  895. if (!acpi_has_method(handle, "_EJ0"))
  896. return false;
  897. if (acpi_ata_match(handle))
  898. return true;
  899. if (ACPI_FAILURE(acpi_get_parent(handle, &phandle)))
  900. return false;
  901. return acpi_ata_match(phandle);
  902. }
  903. bool acpi_device_is_battery(struct acpi_device *adev)
  904. {
  905. struct acpi_hardware_id *hwid;
  906. list_for_each_entry(hwid, &adev->pnp.ids, list)
  907. if (!strcmp("PNP0C0A", hwid->id))
  908. return true;
  909. return false;
  910. }
  911. static bool is_ejectable_bay(struct acpi_device *adev)
  912. {
  913. acpi_handle handle = adev->handle;
  914. if (acpi_has_method(handle, "_EJ0") && acpi_device_is_battery(adev))
  915. return true;
  916. return acpi_bay_match(handle);
  917. }
  918. /*
  919. * acpi_dock_match - see if an acpi object has a _DCK method
  920. */
  921. bool acpi_dock_match(acpi_handle handle)
  922. {
  923. return acpi_has_method(handle, "_DCK");
  924. }
  925. static acpi_status
  926. acpi_backlight_cap_match(acpi_handle handle, u32 level, void *context,
  927. void **return_value)
  928. {
  929. long *cap = context;
  930. if (acpi_has_method(handle, "_BCM") &&
  931. acpi_has_method(handle, "_BCL")) {
  932. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found generic backlight "
  933. "support\n"));
  934. *cap |= ACPI_VIDEO_BACKLIGHT;
  935. if (!acpi_has_method(handle, "_BQC"))
  936. printk(KERN_WARNING FW_BUG PREFIX "No _BQC method, "
  937. "cannot determine initial brightness\n");
  938. /* We have backlight support, no need to scan further */
  939. return AE_CTRL_TERMINATE;
  940. }
  941. return 0;
  942. }
  943. /* Returns true if the ACPI object is a video device which can be
  944. * handled by video.ko.
  945. * The device will get a Linux specific CID added in scan.c to
  946. * identify the device as an ACPI graphics device
  947. * Be aware that the graphics device may not be physically present
  948. * Use acpi_video_get_capabilities() to detect general ACPI video
  949. * capabilities of present cards
  950. */
  951. long acpi_is_video_device(acpi_handle handle)
  952. {
  953. long video_caps = 0;
  954. /* Is this device able to support video switching ? */
  955. if (acpi_has_method(handle, "_DOD") || acpi_has_method(handle, "_DOS"))
  956. video_caps |= ACPI_VIDEO_OUTPUT_SWITCHING;
  957. /* Is this device able to retrieve a video ROM ? */
  958. if (acpi_has_method(handle, "_ROM"))
  959. video_caps |= ACPI_VIDEO_ROM_AVAILABLE;
  960. /* Is this device able to configure which video head to be POSTed ? */
  961. if (acpi_has_method(handle, "_VPO") &&
  962. acpi_has_method(handle, "_GPD") &&
  963. acpi_has_method(handle, "_SPD"))
  964. video_caps |= ACPI_VIDEO_DEVICE_POSTING;
  965. /* Only check for backlight functionality if one of the above hit. */
  966. if (video_caps)
  967. acpi_walk_namespace(ACPI_TYPE_DEVICE, handle,
  968. ACPI_UINT32_MAX, acpi_backlight_cap_match, NULL,
  969. &video_caps, NULL);
  970. return video_caps;
  971. }
  972. EXPORT_SYMBOL(acpi_is_video_device);
  973. const char *acpi_device_hid(struct acpi_device *device)
  974. {
  975. struct acpi_hardware_id *hid;
  976. if (list_empty(&device->pnp.ids))
  977. return dummy_hid;
  978. hid = list_first_entry(&device->pnp.ids, struct acpi_hardware_id, list);
  979. return hid->id;
  980. }
  981. EXPORT_SYMBOL(acpi_device_hid);
  982. static void acpi_add_id(struct acpi_device_pnp *pnp, const char *dev_id)
  983. {
  984. struct acpi_hardware_id *id;
  985. id = kmalloc(sizeof(*id), GFP_KERNEL);
  986. if (!id)
  987. return;
  988. id->id = kstrdup_const(dev_id, GFP_KERNEL);
  989. if (!id->id) {
  990. kfree(id);
  991. return;
  992. }
  993. list_add_tail(&id->list, &pnp->ids);
  994. pnp->type.hardware_id = 1;
  995. }
  996. /*
  997. * Old IBM workstations have a DSDT bug wherein the SMBus object
  998. * lacks the SMBUS01 HID and the methods do not have the necessary "_"
  999. * prefix. Work around this.
  1000. */
  1001. static bool acpi_ibm_smbus_match(acpi_handle handle)
  1002. {
  1003. char node_name[ACPI_PATH_SEGMENT_LENGTH];
  1004. struct acpi_buffer path = { sizeof(node_name), node_name };
  1005. if (!dmi_name_in_vendors("IBM"))
  1006. return false;
  1007. /* Look for SMBS object */
  1008. if (ACPI_FAILURE(acpi_get_name(handle, ACPI_SINGLE_NAME, &path)) ||
  1009. strcmp("SMBS", path.pointer))
  1010. return false;
  1011. /* Does it have the necessary (but misnamed) methods? */
  1012. if (acpi_has_method(handle, "SBI") &&
  1013. acpi_has_method(handle, "SBR") &&
  1014. acpi_has_method(handle, "SBW"))
  1015. return true;
  1016. return false;
  1017. }
  1018. static bool acpi_object_is_system_bus(acpi_handle handle)
  1019. {
  1020. acpi_handle tmp;
  1021. if (ACPI_SUCCESS(acpi_get_handle(NULL, "\\_SB", &tmp)) &&
  1022. tmp == handle)
  1023. return true;
  1024. if (ACPI_SUCCESS(acpi_get_handle(NULL, "\\_TZ", &tmp)) &&
  1025. tmp == handle)
  1026. return true;
  1027. return false;
  1028. }
  1029. static void acpi_set_pnp_ids(acpi_handle handle, struct acpi_device_pnp *pnp,
  1030. int device_type)
  1031. {
  1032. acpi_status status;
  1033. struct acpi_device_info *info;
  1034. struct acpi_pnp_device_id_list *cid_list;
  1035. int i;
  1036. switch (device_type) {
  1037. case ACPI_BUS_TYPE_DEVICE:
  1038. if (handle == ACPI_ROOT_OBJECT) {
  1039. acpi_add_id(pnp, ACPI_SYSTEM_HID);
  1040. break;
  1041. }
  1042. status = acpi_get_object_info(handle, &info);
  1043. if (ACPI_FAILURE(status)) {
  1044. pr_err(PREFIX "%s: Error reading device info\n",
  1045. __func__);
  1046. return;
  1047. }
  1048. if (info->valid & ACPI_VALID_HID) {
  1049. acpi_add_id(pnp, info->hardware_id.string);
  1050. pnp->type.platform_id = 1;
  1051. }
  1052. if (info->valid & ACPI_VALID_CID) {
  1053. cid_list = &info->compatible_id_list;
  1054. for (i = 0; i < cid_list->count; i++)
  1055. acpi_add_id(pnp, cid_list->ids[i].string);
  1056. }
  1057. if (info->valid & ACPI_VALID_ADR) {
  1058. pnp->bus_address = info->address;
  1059. pnp->type.bus_address = 1;
  1060. }
  1061. if (info->valid & ACPI_VALID_UID)
  1062. pnp->unique_id = kstrdup(info->unique_id.string,
  1063. GFP_KERNEL);
  1064. if (info->valid & ACPI_VALID_CLS)
  1065. acpi_add_id(pnp, info->class_code.string);
  1066. kfree(info);
  1067. /*
  1068. * Some devices don't reliably have _HIDs & _CIDs, so add
  1069. * synthetic HIDs to make sure drivers can find them.
  1070. */
  1071. if (acpi_is_video_device(handle))
  1072. acpi_add_id(pnp, ACPI_VIDEO_HID);
  1073. else if (acpi_bay_match(handle))
  1074. acpi_add_id(pnp, ACPI_BAY_HID);
  1075. else if (acpi_dock_match(handle))
  1076. acpi_add_id(pnp, ACPI_DOCK_HID);
  1077. else if (acpi_ibm_smbus_match(handle))
  1078. acpi_add_id(pnp, ACPI_SMBUS_IBM_HID);
  1079. else if (list_empty(&pnp->ids) &&
  1080. acpi_object_is_system_bus(handle)) {
  1081. /* \_SB, \_TZ, LNXSYBUS */
  1082. acpi_add_id(pnp, ACPI_BUS_HID);
  1083. strcpy(pnp->device_name, ACPI_BUS_DEVICE_NAME);
  1084. strcpy(pnp->device_class, ACPI_BUS_CLASS);
  1085. }
  1086. break;
  1087. case ACPI_BUS_TYPE_POWER:
  1088. acpi_add_id(pnp, ACPI_POWER_HID);
  1089. break;
  1090. case ACPI_BUS_TYPE_PROCESSOR:
  1091. acpi_add_id(pnp, ACPI_PROCESSOR_OBJECT_HID);
  1092. break;
  1093. case ACPI_BUS_TYPE_THERMAL:
  1094. acpi_add_id(pnp, ACPI_THERMAL_HID);
  1095. break;
  1096. case ACPI_BUS_TYPE_POWER_BUTTON:
  1097. acpi_add_id(pnp, ACPI_BUTTON_HID_POWERF);
  1098. break;
  1099. case ACPI_BUS_TYPE_SLEEP_BUTTON:
  1100. acpi_add_id(pnp, ACPI_BUTTON_HID_SLEEPF);
  1101. break;
  1102. }
  1103. }
  1104. void acpi_free_pnp_ids(struct acpi_device_pnp *pnp)
  1105. {
  1106. struct acpi_hardware_id *id, *tmp;
  1107. list_for_each_entry_safe(id, tmp, &pnp->ids, list) {
  1108. kfree_const(id->id);
  1109. kfree(id);
  1110. }
  1111. kfree(pnp->unique_id);
  1112. }
  1113. /**
  1114. * acpi_dma_supported - Check DMA support for the specified device.
  1115. * @adev: The pointer to acpi device
  1116. *
  1117. * Return false if DMA is not supported. Otherwise, return true
  1118. */
  1119. bool acpi_dma_supported(struct acpi_device *adev)
  1120. {
  1121. if (!adev)
  1122. return false;
  1123. if (adev->flags.cca_seen)
  1124. return true;
  1125. /*
  1126. * Per ACPI 6.0 sec 6.2.17, assume devices can do cache-coherent
  1127. * DMA on "Intel platforms". Presumably that includes all x86 and
  1128. * ia64, and other arches will set CONFIG_ACPI_CCA_REQUIRED=y.
  1129. */
  1130. if (!IS_ENABLED(CONFIG_ACPI_CCA_REQUIRED))
  1131. return true;
  1132. return false;
  1133. }
  1134. /**
  1135. * acpi_get_dma_attr - Check the supported DMA attr for the specified device.
  1136. * @adev: The pointer to acpi device
  1137. *
  1138. * Return enum dev_dma_attr.
  1139. */
  1140. enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev)
  1141. {
  1142. if (!acpi_dma_supported(adev))
  1143. return DEV_DMA_NOT_SUPPORTED;
  1144. if (adev->flags.coherent_dma)
  1145. return DEV_DMA_COHERENT;
  1146. else
  1147. return DEV_DMA_NON_COHERENT;
  1148. }
  1149. static void acpi_init_coherency(struct acpi_device *adev)
  1150. {
  1151. unsigned long long cca = 0;
  1152. acpi_status status;
  1153. struct acpi_device *parent = adev->parent;
  1154. if (parent && parent->flags.cca_seen) {
  1155. /*
  1156. * From ACPI spec, OSPM will ignore _CCA if an ancestor
  1157. * already saw one.
  1158. */
  1159. adev->flags.cca_seen = 1;
  1160. cca = parent->flags.coherent_dma;
  1161. } else {
  1162. status = acpi_evaluate_integer(adev->handle, "_CCA",
  1163. NULL, &cca);
  1164. if (ACPI_SUCCESS(status))
  1165. adev->flags.cca_seen = 1;
  1166. else if (!IS_ENABLED(CONFIG_ACPI_CCA_REQUIRED))
  1167. /*
  1168. * If architecture does not specify that _CCA is
  1169. * required for DMA-able devices (e.g. x86),
  1170. * we default to _CCA=1.
  1171. */
  1172. cca = 1;
  1173. else
  1174. acpi_handle_debug(adev->handle,
  1175. "ACPI device is missing _CCA.\n");
  1176. }
  1177. adev->flags.coherent_dma = cca;
  1178. }
  1179. void acpi_init_device_object(struct acpi_device *device, acpi_handle handle,
  1180. int type, unsigned long long sta)
  1181. {
  1182. INIT_LIST_HEAD(&device->pnp.ids);
  1183. device->device_type = type;
  1184. device->handle = handle;
  1185. device->parent = acpi_bus_get_parent(handle);
  1186. device->fwnode.type = FWNODE_ACPI;
  1187. acpi_set_device_status(device, sta);
  1188. acpi_device_get_busid(device);
  1189. acpi_set_pnp_ids(handle, &device->pnp, type);
  1190. acpi_init_properties(device);
  1191. acpi_bus_get_flags(device);
  1192. device->flags.match_driver = false;
  1193. device->flags.initialized = true;
  1194. device->flags.visited = false;
  1195. device_initialize(&device->dev);
  1196. dev_set_uevent_suppress(&device->dev, true);
  1197. acpi_init_coherency(device);
  1198. }
  1199. void acpi_device_add_finalize(struct acpi_device *device)
  1200. {
  1201. dev_set_uevent_suppress(&device->dev, false);
  1202. kobject_uevent(&device->dev.kobj, KOBJ_ADD);
  1203. }
  1204. static int acpi_add_single_object(struct acpi_device **child,
  1205. acpi_handle handle, int type,
  1206. unsigned long long sta)
  1207. {
  1208. int result;
  1209. struct acpi_device *device;
  1210. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  1211. device = kzalloc(sizeof(struct acpi_device), GFP_KERNEL);
  1212. if (!device) {
  1213. printk(KERN_ERR PREFIX "Memory allocation error\n");
  1214. return -ENOMEM;
  1215. }
  1216. acpi_init_device_object(device, handle, type, sta);
  1217. acpi_bus_get_power_flags(device);
  1218. acpi_bus_get_wakeup_device_flags(device);
  1219. result = acpi_device_add(device, acpi_device_release);
  1220. if (result) {
  1221. acpi_device_release(&device->dev);
  1222. return result;
  1223. }
  1224. acpi_power_add_remove_device(device, true);
  1225. acpi_device_add_finalize(device);
  1226. acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
  1227. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Added %s [%s] parent %s\n",
  1228. dev_name(&device->dev), (char *) buffer.pointer,
  1229. device->parent ? dev_name(&device->parent->dev) : "(null)"));
  1230. kfree(buffer.pointer);
  1231. *child = device;
  1232. return 0;
  1233. }
  1234. static int acpi_bus_type_and_status(acpi_handle handle, int *type,
  1235. unsigned long long *sta)
  1236. {
  1237. acpi_status status;
  1238. acpi_object_type acpi_type;
  1239. status = acpi_get_type(handle, &acpi_type);
  1240. if (ACPI_FAILURE(status))
  1241. return -ENODEV;
  1242. switch (acpi_type) {
  1243. case ACPI_TYPE_ANY: /* for ACPI_ROOT_OBJECT */
  1244. case ACPI_TYPE_DEVICE:
  1245. *type = ACPI_BUS_TYPE_DEVICE;
  1246. status = acpi_bus_get_status_handle(handle, sta);
  1247. if (ACPI_FAILURE(status))
  1248. *sta = 0;
  1249. break;
  1250. case ACPI_TYPE_PROCESSOR:
  1251. *type = ACPI_BUS_TYPE_PROCESSOR;
  1252. status = acpi_bus_get_status_handle(handle, sta);
  1253. if (ACPI_FAILURE(status))
  1254. return -ENODEV;
  1255. break;
  1256. case ACPI_TYPE_THERMAL:
  1257. *type = ACPI_BUS_TYPE_THERMAL;
  1258. *sta = ACPI_STA_DEFAULT;
  1259. break;
  1260. case ACPI_TYPE_POWER:
  1261. *type = ACPI_BUS_TYPE_POWER;
  1262. *sta = ACPI_STA_DEFAULT;
  1263. break;
  1264. default:
  1265. return -ENODEV;
  1266. }
  1267. return 0;
  1268. }
  1269. bool acpi_device_is_present(struct acpi_device *adev)
  1270. {
  1271. if (adev->status.present || adev->status.functional)
  1272. return true;
  1273. adev->flags.initialized = false;
  1274. return false;
  1275. }
  1276. static bool acpi_scan_handler_matching(struct acpi_scan_handler *handler,
  1277. const char *idstr,
  1278. const struct acpi_device_id **matchid)
  1279. {
  1280. const struct acpi_device_id *devid;
  1281. if (handler->match)
  1282. return handler->match(idstr, matchid);
  1283. for (devid = handler->ids; devid->id[0]; devid++)
  1284. if (!strcmp((char *)devid->id, idstr)) {
  1285. if (matchid)
  1286. *matchid = devid;
  1287. return true;
  1288. }
  1289. return false;
  1290. }
  1291. static struct acpi_scan_handler *acpi_scan_match_handler(const char *idstr,
  1292. const struct acpi_device_id **matchid)
  1293. {
  1294. struct acpi_scan_handler *handler;
  1295. list_for_each_entry(handler, &acpi_scan_handlers_list, list_node)
  1296. if (acpi_scan_handler_matching(handler, idstr, matchid))
  1297. return handler;
  1298. return NULL;
  1299. }
  1300. void acpi_scan_hotplug_enabled(struct acpi_hotplug_profile *hotplug, bool val)
  1301. {
  1302. if (!!hotplug->enabled == !!val)
  1303. return;
  1304. mutex_lock(&acpi_scan_lock);
  1305. hotplug->enabled = val;
  1306. mutex_unlock(&acpi_scan_lock);
  1307. }
  1308. static void acpi_scan_init_hotplug(struct acpi_device *adev)
  1309. {
  1310. struct acpi_hardware_id *hwid;
  1311. if (acpi_dock_match(adev->handle) || is_ejectable_bay(adev)) {
  1312. acpi_dock_add(adev);
  1313. return;
  1314. }
  1315. list_for_each_entry(hwid, &adev->pnp.ids, list) {
  1316. struct acpi_scan_handler *handler;
  1317. handler = acpi_scan_match_handler(hwid->id, NULL);
  1318. if (handler) {
  1319. adev->flags.hotplug_notify = true;
  1320. break;
  1321. }
  1322. }
  1323. }
  1324. static void acpi_device_dep_initialize(struct acpi_device *adev)
  1325. {
  1326. struct acpi_dep_data *dep;
  1327. struct acpi_handle_list dep_devices;
  1328. acpi_status status;
  1329. int i;
  1330. if (!acpi_has_method(adev->handle, "_DEP"))
  1331. return;
  1332. status = acpi_evaluate_reference(adev->handle, "_DEP", NULL,
  1333. &dep_devices);
  1334. if (ACPI_FAILURE(status)) {
  1335. dev_dbg(&adev->dev, "Failed to evaluate _DEP.\n");
  1336. return;
  1337. }
  1338. for (i = 0; i < dep_devices.count; i++) {
  1339. struct acpi_device_info *info;
  1340. int skip;
  1341. status = acpi_get_object_info(dep_devices.handles[i], &info);
  1342. if (ACPI_FAILURE(status)) {
  1343. dev_dbg(&adev->dev, "Error reading _DEP device info\n");
  1344. continue;
  1345. }
  1346. /*
  1347. * Skip the dependency of Windows System Power
  1348. * Management Controller
  1349. */
  1350. skip = info->valid & ACPI_VALID_HID &&
  1351. !strcmp(info->hardware_id.string, "INT3396");
  1352. kfree(info);
  1353. if (skip)
  1354. continue;
  1355. dep = kzalloc(sizeof(struct acpi_dep_data), GFP_KERNEL);
  1356. if (!dep)
  1357. return;
  1358. dep->master = dep_devices.handles[i];
  1359. dep->slave = adev->handle;
  1360. adev->dep_unmet++;
  1361. mutex_lock(&acpi_dep_list_lock);
  1362. list_add_tail(&dep->node , &acpi_dep_list);
  1363. mutex_unlock(&acpi_dep_list_lock);
  1364. }
  1365. }
  1366. static acpi_status acpi_bus_check_add(acpi_handle handle, u32 lvl_not_used,
  1367. void *not_used, void **return_value)
  1368. {
  1369. struct acpi_device *device = NULL;
  1370. int type;
  1371. unsigned long long sta;
  1372. int result;
  1373. acpi_bus_get_device(handle, &device);
  1374. if (device)
  1375. goto out;
  1376. result = acpi_bus_type_and_status(handle, &type, &sta);
  1377. if (result)
  1378. return AE_OK;
  1379. if (type == ACPI_BUS_TYPE_POWER) {
  1380. acpi_add_power_resource(handle);
  1381. return AE_OK;
  1382. }
  1383. acpi_add_single_object(&device, handle, type, sta);
  1384. if (!device)
  1385. return AE_CTRL_DEPTH;
  1386. acpi_scan_init_hotplug(device);
  1387. acpi_device_dep_initialize(device);
  1388. out:
  1389. if (!*return_value)
  1390. *return_value = device;
  1391. return AE_OK;
  1392. }
  1393. static int acpi_check_spi_i2c_slave(struct acpi_resource *ares, void *data)
  1394. {
  1395. bool *is_spi_i2c_slave_p = data;
  1396. if (ares->type != ACPI_RESOURCE_TYPE_SERIAL_BUS)
  1397. return 1;
  1398. /*
  1399. * devices that are connected to UART still need to be enumerated to
  1400. * platform bus
  1401. */
  1402. if (ares->data.common_serial_bus.type != ACPI_RESOURCE_SERIAL_TYPE_UART)
  1403. *is_spi_i2c_slave_p = true;
  1404. /* no need to do more checking */
  1405. return -1;
  1406. }
  1407. static void acpi_default_enumeration(struct acpi_device *device)
  1408. {
  1409. struct list_head resource_list;
  1410. bool is_spi_i2c_slave = false;
  1411. /*
  1412. * Do not enemerate SPI/I2C slaves as they will be enuerated by their
  1413. * respective parents.
  1414. */
  1415. INIT_LIST_HEAD(&resource_list);
  1416. acpi_dev_get_resources(device, &resource_list, acpi_check_spi_i2c_slave,
  1417. &is_spi_i2c_slave);
  1418. acpi_dev_free_resource_list(&resource_list);
  1419. if (!is_spi_i2c_slave)
  1420. acpi_create_platform_device(device);
  1421. }
  1422. static const struct acpi_device_id generic_device_ids[] = {
  1423. {ACPI_DT_NAMESPACE_HID, },
  1424. {"", },
  1425. };
  1426. static int acpi_generic_device_attach(struct acpi_device *adev,
  1427. const struct acpi_device_id *not_used)
  1428. {
  1429. /*
  1430. * Since ACPI_DT_NAMESPACE_HID is the only ID handled here, the test
  1431. * below can be unconditional.
  1432. */
  1433. if (adev->data.of_compatible)
  1434. acpi_default_enumeration(adev);
  1435. return 1;
  1436. }
  1437. static struct acpi_scan_handler generic_device_handler = {
  1438. .ids = generic_device_ids,
  1439. .attach = acpi_generic_device_attach,
  1440. };
  1441. static int acpi_scan_attach_handler(struct acpi_device *device)
  1442. {
  1443. struct acpi_hardware_id *hwid;
  1444. int ret = 0;
  1445. list_for_each_entry(hwid, &device->pnp.ids, list) {
  1446. const struct acpi_device_id *devid;
  1447. struct acpi_scan_handler *handler;
  1448. handler = acpi_scan_match_handler(hwid->id, &devid);
  1449. if (handler) {
  1450. if (!handler->attach) {
  1451. device->pnp.type.platform_id = 0;
  1452. continue;
  1453. }
  1454. device->handler = handler;
  1455. ret = handler->attach(device, devid);
  1456. if (ret > 0)
  1457. break;
  1458. device->handler = NULL;
  1459. if (ret < 0)
  1460. break;
  1461. }
  1462. }
  1463. return ret;
  1464. }
  1465. static void acpi_bus_attach(struct acpi_device *device)
  1466. {
  1467. struct acpi_device *child;
  1468. acpi_handle ejd;
  1469. int ret;
  1470. if (ACPI_SUCCESS(acpi_bus_get_ejd(device->handle, &ejd)))
  1471. register_dock_dependent_device(device, ejd);
  1472. acpi_bus_get_status(device);
  1473. /* Skip devices that are not present. */
  1474. if (!acpi_device_is_present(device)) {
  1475. device->flags.visited = false;
  1476. device->flags.power_manageable = 0;
  1477. return;
  1478. }
  1479. if (device->handler)
  1480. goto ok;
  1481. if (!device->flags.initialized) {
  1482. device->flags.power_manageable =
  1483. device->power.states[ACPI_STATE_D0].flags.valid;
  1484. if (acpi_bus_init_power(device))
  1485. device->flags.power_manageable = 0;
  1486. device->flags.initialized = true;
  1487. }
  1488. device->flags.visited = false;
  1489. ret = acpi_scan_attach_handler(device);
  1490. if (ret < 0)
  1491. return;
  1492. device->flags.match_driver = true;
  1493. if (!ret) {
  1494. ret = device_attach(&device->dev);
  1495. if (ret < 0)
  1496. return;
  1497. if (!ret && device->pnp.type.platform_id)
  1498. acpi_default_enumeration(device);
  1499. }
  1500. device->flags.visited = true;
  1501. ok:
  1502. list_for_each_entry(child, &device->children, node)
  1503. acpi_bus_attach(child);
  1504. if (device->handler && device->handler->hotplug.notify_online)
  1505. device->handler->hotplug.notify_online(device);
  1506. }
  1507. void acpi_walk_dep_device_list(acpi_handle handle)
  1508. {
  1509. struct acpi_dep_data *dep, *tmp;
  1510. struct acpi_device *adev;
  1511. mutex_lock(&acpi_dep_list_lock);
  1512. list_for_each_entry_safe(dep, tmp, &acpi_dep_list, node) {
  1513. if (dep->master == handle) {
  1514. acpi_bus_get_device(dep->slave, &adev);
  1515. if (!adev)
  1516. continue;
  1517. adev->dep_unmet--;
  1518. if (!adev->dep_unmet)
  1519. acpi_bus_attach(adev);
  1520. list_del(&dep->node);
  1521. kfree(dep);
  1522. }
  1523. }
  1524. mutex_unlock(&acpi_dep_list_lock);
  1525. }
  1526. EXPORT_SYMBOL_GPL(acpi_walk_dep_device_list);
  1527. /**
  1528. * acpi_bus_scan - Add ACPI device node objects in a given namespace scope.
  1529. * @handle: Root of the namespace scope to scan.
  1530. *
  1531. * Scan a given ACPI tree (probably recently hot-plugged) and create and add
  1532. * found devices.
  1533. *
  1534. * If no devices were found, -ENODEV is returned, but it does not mean that
  1535. * there has been a real error. There just have been no suitable ACPI objects
  1536. * in the table trunk from which the kernel could create a device and add an
  1537. * appropriate driver.
  1538. *
  1539. * Must be called under acpi_scan_lock.
  1540. */
  1541. int acpi_bus_scan(acpi_handle handle)
  1542. {
  1543. void *device = NULL;
  1544. if (ACPI_SUCCESS(acpi_bus_check_add(handle, 0, NULL, &device)))
  1545. acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
  1546. acpi_bus_check_add, NULL, NULL, &device);
  1547. if (device) {
  1548. acpi_bus_attach(device);
  1549. return 0;
  1550. }
  1551. return -ENODEV;
  1552. }
  1553. EXPORT_SYMBOL(acpi_bus_scan);
  1554. /**
  1555. * acpi_bus_trim - Detach scan handlers and drivers from ACPI device objects.
  1556. * @adev: Root of the ACPI namespace scope to walk.
  1557. *
  1558. * Must be called under acpi_scan_lock.
  1559. */
  1560. void acpi_bus_trim(struct acpi_device *adev)
  1561. {
  1562. struct acpi_scan_handler *handler = adev->handler;
  1563. struct acpi_device *child;
  1564. list_for_each_entry_reverse(child, &adev->children, node)
  1565. acpi_bus_trim(child);
  1566. adev->flags.match_driver = false;
  1567. if (handler) {
  1568. if (handler->detach)
  1569. handler->detach(adev);
  1570. adev->handler = NULL;
  1571. } else {
  1572. device_release_driver(&adev->dev);
  1573. }
  1574. /*
  1575. * Most likely, the device is going away, so put it into D3cold before
  1576. * that.
  1577. */
  1578. acpi_device_set_power(adev, ACPI_STATE_D3_COLD);
  1579. adev->flags.initialized = false;
  1580. adev->flags.visited = false;
  1581. }
  1582. EXPORT_SYMBOL_GPL(acpi_bus_trim);
  1583. static int acpi_bus_scan_fixed(void)
  1584. {
  1585. int result = 0;
  1586. /*
  1587. * Enumerate all fixed-feature devices.
  1588. */
  1589. if (!(acpi_gbl_FADT.flags & ACPI_FADT_POWER_BUTTON)) {
  1590. struct acpi_device *device = NULL;
  1591. result = acpi_add_single_object(&device, NULL,
  1592. ACPI_BUS_TYPE_POWER_BUTTON,
  1593. ACPI_STA_DEFAULT);
  1594. if (result)
  1595. return result;
  1596. device->flags.match_driver = true;
  1597. result = device_attach(&device->dev);
  1598. if (result < 0)
  1599. return result;
  1600. device_init_wakeup(&device->dev, true);
  1601. }
  1602. if (!(acpi_gbl_FADT.flags & ACPI_FADT_SLEEP_BUTTON)) {
  1603. struct acpi_device *device = NULL;
  1604. result = acpi_add_single_object(&device, NULL,
  1605. ACPI_BUS_TYPE_SLEEP_BUTTON,
  1606. ACPI_STA_DEFAULT);
  1607. if (result)
  1608. return result;
  1609. device->flags.match_driver = true;
  1610. result = device_attach(&device->dev);
  1611. }
  1612. return result < 0 ? result : 0;
  1613. }
  1614. int __init acpi_scan_init(void)
  1615. {
  1616. int result;
  1617. acpi_pci_root_init();
  1618. acpi_pci_link_init();
  1619. acpi_processor_init();
  1620. acpi_lpss_init();
  1621. acpi_apd_init();
  1622. acpi_cmos_rtc_init();
  1623. acpi_container_init();
  1624. acpi_memory_hotplug_init();
  1625. acpi_pnp_init();
  1626. acpi_int340x_thermal_init();
  1627. acpi_amba_init();
  1628. acpi_scan_add_handler(&generic_device_handler);
  1629. mutex_lock(&acpi_scan_lock);
  1630. /*
  1631. * Enumerate devices in the ACPI namespace.
  1632. */
  1633. result = acpi_bus_scan(ACPI_ROOT_OBJECT);
  1634. if (result)
  1635. goto out;
  1636. result = acpi_bus_get_device(ACPI_ROOT_OBJECT, &acpi_root);
  1637. if (result)
  1638. goto out;
  1639. /* Fixed feature devices do not exist on HW-reduced platform */
  1640. if (!acpi_gbl_reduced_hardware) {
  1641. result = acpi_bus_scan_fixed();
  1642. if (result) {
  1643. acpi_detach_data(acpi_root->handle,
  1644. acpi_scan_drop_device);
  1645. acpi_device_del(acpi_root);
  1646. put_device(&acpi_root->dev);
  1647. goto out;
  1648. }
  1649. }
  1650. acpi_update_all_gpes();
  1651. out:
  1652. mutex_unlock(&acpi_scan_lock);
  1653. return result;
  1654. }
  1655. static struct acpi_probe_entry *ape;
  1656. static int acpi_probe_count;
  1657. static DEFINE_SPINLOCK(acpi_probe_lock);
  1658. static int __init acpi_match_madt(struct acpi_subtable_header *header,
  1659. const unsigned long end)
  1660. {
  1661. if (!ape->subtable_valid || ape->subtable_valid(header, ape))
  1662. if (!ape->probe_subtbl(header, end))
  1663. acpi_probe_count++;
  1664. return 0;
  1665. }
  1666. int __init __acpi_probe_device_table(struct acpi_probe_entry *ap_head, int nr)
  1667. {
  1668. int count = 0;
  1669. if (acpi_disabled)
  1670. return 0;
  1671. spin_lock(&acpi_probe_lock);
  1672. for (ape = ap_head; nr; ape++, nr--) {
  1673. if (ACPI_COMPARE_NAME(ACPI_SIG_MADT, ape->id)) {
  1674. acpi_probe_count = 0;
  1675. acpi_table_parse_madt(ape->type, acpi_match_madt, 0);
  1676. count += acpi_probe_count;
  1677. } else {
  1678. int res;
  1679. res = acpi_table_parse(ape->id, ape->probe_table);
  1680. if (!res)
  1681. count++;
  1682. }
  1683. }
  1684. spin_unlock(&acpi_probe_lock);
  1685. return count;
  1686. }