scan.c 49 KB

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