bus.c 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126
  1. /*
  2. * acpi_bus.c - ACPI Bus Driver ($Revision: 80 $)
  3. *
  4. * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
  5. *
  6. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or (at
  11. * your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  21. *
  22. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  23. */
  24. #include <linux/module.h>
  25. #include <linux/init.h>
  26. #include <linux/ioport.h>
  27. #include <linux/kernel.h>
  28. #include <linux/list.h>
  29. #include <linux/sched.h>
  30. #include <linux/pm.h>
  31. #include <linux/device.h>
  32. #include <linux/proc_fs.h>
  33. #include <linux/acpi.h>
  34. #include <linux/slab.h>
  35. #ifdef CONFIG_X86
  36. #include <asm/mpspec.h>
  37. #endif
  38. #include <linux/pci.h>
  39. #include <acpi/acpi_bus.h>
  40. #include <acpi/acpi_drivers.h>
  41. #include <acpi/apei.h>
  42. #include <linux/dmi.h>
  43. #include <linux/suspend.h>
  44. #include "internal.h"
  45. #define _COMPONENT ACPI_BUS_COMPONENT
  46. ACPI_MODULE_NAME("bus");
  47. struct acpi_device *acpi_root;
  48. struct proc_dir_entry *acpi_root_dir;
  49. EXPORT_SYMBOL(acpi_root_dir);
  50. #define STRUCT_TO_INT(s) (*((int*)&s))
  51. #ifdef CONFIG_X86
  52. static int set_copy_dsdt(const struct dmi_system_id *id)
  53. {
  54. printk(KERN_NOTICE "%s detected - "
  55. "force copy of DSDT to local memory\n", id->ident);
  56. acpi_gbl_copy_dsdt_locally = 1;
  57. return 0;
  58. }
  59. static struct dmi_system_id dsdt_dmi_table[] __initdata = {
  60. /*
  61. * Invoke DSDT corruption work-around on all Toshiba Satellite.
  62. * https://bugzilla.kernel.org/show_bug.cgi?id=14679
  63. */
  64. {
  65. .callback = set_copy_dsdt,
  66. .ident = "TOSHIBA Satellite",
  67. .matches = {
  68. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  69. DMI_MATCH(DMI_PRODUCT_NAME, "Satellite"),
  70. },
  71. },
  72. {}
  73. };
  74. #else
  75. static struct dmi_system_id dsdt_dmi_table[] __initdata = {
  76. {}
  77. };
  78. #endif
  79. /* --------------------------------------------------------------------------
  80. Device Management
  81. -------------------------------------------------------------------------- */
  82. int acpi_bus_get_device(acpi_handle handle, struct acpi_device **device)
  83. {
  84. acpi_status status = AE_OK;
  85. if (!device)
  86. return -EINVAL;
  87. /* TBD: Support fixed-feature devices */
  88. status = acpi_get_data(handle, acpi_bus_data_handler, (void **)device);
  89. if (ACPI_FAILURE(status) || !*device) {
  90. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
  91. handle));
  92. return -ENODEV;
  93. }
  94. return 0;
  95. }
  96. EXPORT_SYMBOL(acpi_bus_get_device);
  97. acpi_status acpi_bus_get_status_handle(acpi_handle handle,
  98. unsigned long long *sta)
  99. {
  100. acpi_status status;
  101. status = acpi_evaluate_integer(handle, "_STA", NULL, sta);
  102. if (ACPI_SUCCESS(status))
  103. return AE_OK;
  104. if (status == AE_NOT_FOUND) {
  105. *sta = ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED |
  106. ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING;
  107. return AE_OK;
  108. }
  109. return status;
  110. }
  111. int acpi_bus_get_status(struct acpi_device *device)
  112. {
  113. acpi_status status;
  114. unsigned long long sta;
  115. status = acpi_bus_get_status_handle(device->handle, &sta);
  116. if (ACPI_FAILURE(status))
  117. return -ENODEV;
  118. STRUCT_TO_INT(device->status) = (int) sta;
  119. if (device->status.functional && !device->status.present) {
  120. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]: "
  121. "functional but not present;\n",
  122. device->pnp.bus_id,
  123. (u32) STRUCT_TO_INT(device->status)));
  124. }
  125. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]\n",
  126. device->pnp.bus_id,
  127. (u32) STRUCT_TO_INT(device->status)));
  128. return 0;
  129. }
  130. EXPORT_SYMBOL(acpi_bus_get_status);
  131. void acpi_bus_private_data_handler(acpi_handle handle,
  132. void *context)
  133. {
  134. return;
  135. }
  136. EXPORT_SYMBOL(acpi_bus_private_data_handler);
  137. int acpi_bus_get_private_data(acpi_handle handle, void **data)
  138. {
  139. acpi_status status = AE_OK;
  140. if (!*data)
  141. return -EINVAL;
  142. status = acpi_get_data(handle, acpi_bus_private_data_handler, data);
  143. if (ACPI_FAILURE(status) || !*data) {
  144. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
  145. handle));
  146. return -ENODEV;
  147. }
  148. return 0;
  149. }
  150. EXPORT_SYMBOL(acpi_bus_get_private_data);
  151. /* --------------------------------------------------------------------------
  152. Power Management
  153. -------------------------------------------------------------------------- */
  154. static const char *state_string(int state)
  155. {
  156. switch (state) {
  157. case ACPI_STATE_D0:
  158. return "D0";
  159. case ACPI_STATE_D1:
  160. return "D1";
  161. case ACPI_STATE_D2:
  162. return "D2";
  163. case ACPI_STATE_D3_HOT:
  164. return "D3hot";
  165. case ACPI_STATE_D3_COLD:
  166. return "D3";
  167. default:
  168. return "(unknown)";
  169. }
  170. }
  171. /**
  172. * acpi_device_get_power - Get power state of an ACPI device.
  173. * @device: Device to get the power state of.
  174. * @state: Place to store the power state of the device.
  175. *
  176. * This function does not update the device's power.state field, but it may
  177. * update its parent's power.state field (when the parent's power state is
  178. * unknown and the device's power state turns out to be D0).
  179. */
  180. int acpi_device_get_power(struct acpi_device *device, int *state)
  181. {
  182. int result = ACPI_STATE_UNKNOWN;
  183. if (!device || !state)
  184. return -EINVAL;
  185. if (!device->flags.power_manageable) {
  186. /* TBD: Non-recursive algorithm for walking up hierarchy. */
  187. *state = device->parent ?
  188. device->parent->power.state : ACPI_STATE_D0;
  189. goto out;
  190. }
  191. /*
  192. * Get the device's power state either directly (via _PSC) or
  193. * indirectly (via power resources).
  194. */
  195. if (device->power.flags.explicit_get) {
  196. unsigned long long psc;
  197. acpi_status status = acpi_evaluate_integer(device->handle,
  198. "_PSC", NULL, &psc);
  199. if (ACPI_FAILURE(status))
  200. return -ENODEV;
  201. result = psc;
  202. }
  203. /* The test below covers ACPI_STATE_UNKNOWN too. */
  204. if (result <= ACPI_STATE_D2) {
  205. ; /* Do nothing. */
  206. } else if (device->power.flags.power_resources) {
  207. int error = acpi_power_get_inferred_state(device, &result);
  208. if (error)
  209. return error;
  210. } else if (result == ACPI_STATE_D3_HOT) {
  211. result = ACPI_STATE_D3;
  212. }
  213. /*
  214. * If we were unsure about the device parent's power state up to this
  215. * point, the fact that the device is in D0 implies that the parent has
  216. * to be in D0 too.
  217. */
  218. if (device->parent && device->parent->power.state == ACPI_STATE_UNKNOWN
  219. && result == ACPI_STATE_D0)
  220. device->parent->power.state = ACPI_STATE_D0;
  221. *state = result;
  222. out:
  223. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] power state is %s\n",
  224. device->pnp.bus_id, state_string(*state)));
  225. return 0;
  226. }
  227. /**
  228. * acpi_device_set_power - Set power state of an ACPI device.
  229. * @device: Device to set the power state of.
  230. * @state: New power state to set.
  231. *
  232. * Callers must ensure that the device is power manageable before using this
  233. * function.
  234. */
  235. int acpi_device_set_power(struct acpi_device *device, int state)
  236. {
  237. int result = 0;
  238. acpi_status status = AE_OK;
  239. char object_name[5] = { '_', 'P', 'S', '0' + state, '\0' };
  240. bool cut_power = false;
  241. if (!device || (state < ACPI_STATE_D0) || (state > ACPI_STATE_D3_COLD))
  242. return -EINVAL;
  243. /* Make sure this is a valid target state */
  244. if (state == device->power.state) {
  245. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at %s\n",
  246. state_string(state)));
  247. return 0;
  248. }
  249. if (!device->power.states[state].flags.valid) {
  250. printk(KERN_WARNING PREFIX "Device does not support %s\n",
  251. state_string(state));
  252. return -ENODEV;
  253. }
  254. if (device->parent && (state < device->parent->power.state)) {
  255. printk(KERN_WARNING PREFIX
  256. "Cannot set device to a higher-powered"
  257. " state than parent\n");
  258. return -ENODEV;
  259. }
  260. /* For D3cold we should first transition into D3hot. */
  261. if (state == ACPI_STATE_D3_COLD
  262. && device->power.states[ACPI_STATE_D3_COLD].flags.os_accessible) {
  263. state = ACPI_STATE_D3_HOT;
  264. object_name[3] = '3';
  265. cut_power = true;
  266. }
  267. /*
  268. * Transition Power
  269. * ----------------
  270. * On transitions to a high-powered state we first apply power (via
  271. * power resources) then evalute _PSx. Conversly for transitions to
  272. * a lower-powered state.
  273. */
  274. if (state < device->power.state) {
  275. if (device->power.state >= ACPI_STATE_D3_HOT &&
  276. state != ACPI_STATE_D0) {
  277. printk(KERN_WARNING PREFIX
  278. "Cannot transition to non-D0 state from D3\n");
  279. return -ENODEV;
  280. }
  281. if (device->power.flags.power_resources) {
  282. result = acpi_power_transition(device, state);
  283. if (result)
  284. goto end;
  285. }
  286. if (device->power.states[state].flags.explicit_set) {
  287. status = acpi_evaluate_object(device->handle,
  288. object_name, NULL, NULL);
  289. if (ACPI_FAILURE(status)) {
  290. result = -ENODEV;
  291. goto end;
  292. }
  293. }
  294. } else {
  295. if (device->power.states[state].flags.explicit_set) {
  296. status = acpi_evaluate_object(device->handle,
  297. object_name, NULL, NULL);
  298. if (ACPI_FAILURE(status)) {
  299. result = -ENODEV;
  300. goto end;
  301. }
  302. }
  303. if (device->power.flags.power_resources) {
  304. result = acpi_power_transition(device, state);
  305. if (result)
  306. goto end;
  307. }
  308. }
  309. if (cut_power)
  310. result = acpi_power_transition(device, ACPI_STATE_D3_COLD);
  311. end:
  312. if (result)
  313. printk(KERN_WARNING PREFIX
  314. "Device [%s] failed to transition to %s\n",
  315. device->pnp.bus_id, state_string(state));
  316. else {
  317. device->power.state = state;
  318. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  319. "Device [%s] transitioned to %s\n",
  320. device->pnp.bus_id, state_string(state)));
  321. }
  322. return result;
  323. }
  324. EXPORT_SYMBOL(acpi_device_set_power);
  325. int acpi_bus_set_power(acpi_handle handle, int state)
  326. {
  327. struct acpi_device *device;
  328. int result;
  329. result = acpi_bus_get_device(handle, &device);
  330. if (result)
  331. return result;
  332. if (!device->flags.power_manageable) {
  333. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  334. "Device [%s] is not power manageable\n",
  335. dev_name(&device->dev)));
  336. return -ENODEV;
  337. }
  338. return acpi_device_set_power(device, state);
  339. }
  340. EXPORT_SYMBOL(acpi_bus_set_power);
  341. int acpi_bus_init_power(struct acpi_device *device)
  342. {
  343. int state;
  344. int result;
  345. if (!device)
  346. return -EINVAL;
  347. device->power.state = ACPI_STATE_UNKNOWN;
  348. result = acpi_device_get_power(device, &state);
  349. if (result)
  350. return result;
  351. if (device->power.flags.power_resources)
  352. result = acpi_power_on_resources(device, state);
  353. if (!result)
  354. device->power.state = state;
  355. return result;
  356. }
  357. int acpi_bus_update_power(acpi_handle handle, int *state_p)
  358. {
  359. struct acpi_device *device;
  360. int state;
  361. int result;
  362. result = acpi_bus_get_device(handle, &device);
  363. if (result)
  364. return result;
  365. result = acpi_device_get_power(device, &state);
  366. if (result)
  367. return result;
  368. result = acpi_device_set_power(device, state);
  369. if (!result && state_p)
  370. *state_p = state;
  371. return result;
  372. }
  373. EXPORT_SYMBOL_GPL(acpi_bus_update_power);
  374. bool acpi_bus_power_manageable(acpi_handle handle)
  375. {
  376. struct acpi_device *device;
  377. int result;
  378. result = acpi_bus_get_device(handle, &device);
  379. return result ? false : device->flags.power_manageable;
  380. }
  381. EXPORT_SYMBOL(acpi_bus_power_manageable);
  382. bool acpi_bus_can_wakeup(acpi_handle handle)
  383. {
  384. struct acpi_device *device;
  385. int result;
  386. result = acpi_bus_get_device(handle, &device);
  387. return result ? false : device->wakeup.flags.valid;
  388. }
  389. EXPORT_SYMBOL(acpi_bus_can_wakeup);
  390. static void acpi_print_osc_error(acpi_handle handle,
  391. struct acpi_osc_context *context, char *error)
  392. {
  393. struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER};
  394. int i;
  395. if (ACPI_FAILURE(acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer)))
  396. printk(KERN_DEBUG "%s\n", error);
  397. else {
  398. printk(KERN_DEBUG "%s:%s\n", (char *)buffer.pointer, error);
  399. kfree(buffer.pointer);
  400. }
  401. printk(KERN_DEBUG"_OSC request data:");
  402. for (i = 0; i < context->cap.length; i += sizeof(u32))
  403. printk("%x ", *((u32 *)(context->cap.pointer + i)));
  404. printk("\n");
  405. }
  406. static acpi_status acpi_str_to_uuid(char *str, u8 *uuid)
  407. {
  408. int i;
  409. static int opc_map_to_uuid[16] = {6, 4, 2, 0, 11, 9, 16, 14, 19, 21,
  410. 24, 26, 28, 30, 32, 34};
  411. if (strlen(str) != 36)
  412. return AE_BAD_PARAMETER;
  413. for (i = 0; i < 36; i++) {
  414. if (i == 8 || i == 13 || i == 18 || i == 23) {
  415. if (str[i] != '-')
  416. return AE_BAD_PARAMETER;
  417. } else if (!isxdigit(str[i]))
  418. return AE_BAD_PARAMETER;
  419. }
  420. for (i = 0; i < 16; i++) {
  421. uuid[i] = hex_to_bin(str[opc_map_to_uuid[i]]) << 4;
  422. uuid[i] |= hex_to_bin(str[opc_map_to_uuid[i] + 1]);
  423. }
  424. return AE_OK;
  425. }
  426. acpi_status acpi_run_osc(acpi_handle handle, struct acpi_osc_context *context)
  427. {
  428. acpi_status status;
  429. struct acpi_object_list input;
  430. union acpi_object in_params[4];
  431. union acpi_object *out_obj;
  432. u8 uuid[16];
  433. u32 errors;
  434. struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL};
  435. if (!context)
  436. return AE_ERROR;
  437. if (ACPI_FAILURE(acpi_str_to_uuid(context->uuid_str, uuid)))
  438. return AE_ERROR;
  439. context->ret.length = ACPI_ALLOCATE_BUFFER;
  440. context->ret.pointer = NULL;
  441. /* Setting up input parameters */
  442. input.count = 4;
  443. input.pointer = in_params;
  444. in_params[0].type = ACPI_TYPE_BUFFER;
  445. in_params[0].buffer.length = 16;
  446. in_params[0].buffer.pointer = uuid;
  447. in_params[1].type = ACPI_TYPE_INTEGER;
  448. in_params[1].integer.value = context->rev;
  449. in_params[2].type = ACPI_TYPE_INTEGER;
  450. in_params[2].integer.value = context->cap.length/sizeof(u32);
  451. in_params[3].type = ACPI_TYPE_BUFFER;
  452. in_params[3].buffer.length = context->cap.length;
  453. in_params[3].buffer.pointer = context->cap.pointer;
  454. status = acpi_evaluate_object(handle, "_OSC", &input, &output);
  455. if (ACPI_FAILURE(status))
  456. return status;
  457. if (!output.length)
  458. return AE_NULL_OBJECT;
  459. out_obj = output.pointer;
  460. if (out_obj->type != ACPI_TYPE_BUFFER
  461. || out_obj->buffer.length != context->cap.length) {
  462. acpi_print_osc_error(handle, context,
  463. "_OSC evaluation returned wrong type");
  464. status = AE_TYPE;
  465. goto out_kfree;
  466. }
  467. /* Need to ignore the bit0 in result code */
  468. errors = *((u32 *)out_obj->buffer.pointer) & ~(1 << 0);
  469. if (errors) {
  470. if (errors & OSC_REQUEST_ERROR)
  471. acpi_print_osc_error(handle, context,
  472. "_OSC request failed");
  473. if (errors & OSC_INVALID_UUID_ERROR)
  474. acpi_print_osc_error(handle, context,
  475. "_OSC invalid UUID");
  476. if (errors & OSC_INVALID_REVISION_ERROR)
  477. acpi_print_osc_error(handle, context,
  478. "_OSC invalid revision");
  479. if (errors & OSC_CAPABILITIES_MASK_ERROR) {
  480. if (((u32 *)context->cap.pointer)[OSC_QUERY_TYPE]
  481. & OSC_QUERY_ENABLE)
  482. goto out_success;
  483. status = AE_SUPPORT;
  484. goto out_kfree;
  485. }
  486. status = AE_ERROR;
  487. goto out_kfree;
  488. }
  489. out_success:
  490. context->ret.length = out_obj->buffer.length;
  491. context->ret.pointer = kmalloc(context->ret.length, GFP_KERNEL);
  492. if (!context->ret.pointer) {
  493. status = AE_NO_MEMORY;
  494. goto out_kfree;
  495. }
  496. memcpy(context->ret.pointer, out_obj->buffer.pointer,
  497. context->ret.length);
  498. status = AE_OK;
  499. out_kfree:
  500. kfree(output.pointer);
  501. if (status != AE_OK)
  502. context->ret.pointer = NULL;
  503. return status;
  504. }
  505. EXPORT_SYMBOL(acpi_run_osc);
  506. bool osc_sb_apei_support_acked;
  507. static u8 sb_uuid_str[] = "0811B06E-4A27-44F9-8D60-3CBBC22E7B48";
  508. static void acpi_bus_osc_support(void)
  509. {
  510. u32 capbuf[2];
  511. struct acpi_osc_context context = {
  512. .uuid_str = sb_uuid_str,
  513. .rev = 1,
  514. .cap.length = 8,
  515. .cap.pointer = capbuf,
  516. };
  517. acpi_handle handle;
  518. capbuf[OSC_QUERY_TYPE] = OSC_QUERY_ENABLE;
  519. capbuf[OSC_SUPPORT_TYPE] = OSC_SB_PR3_SUPPORT; /* _PR3 is in use */
  520. #if defined(CONFIG_ACPI_PROCESSOR_AGGREGATOR) ||\
  521. defined(CONFIG_ACPI_PROCESSOR_AGGREGATOR_MODULE)
  522. capbuf[OSC_SUPPORT_TYPE] |= OSC_SB_PAD_SUPPORT;
  523. #endif
  524. #if defined(CONFIG_ACPI_PROCESSOR) || defined(CONFIG_ACPI_PROCESSOR_MODULE)
  525. capbuf[OSC_SUPPORT_TYPE] |= OSC_SB_PPC_OST_SUPPORT;
  526. #endif
  527. #ifdef ACPI_HOTPLUG_OST
  528. capbuf[OSC_SUPPORT_TYPE] |= OSC_SB_HOTPLUG_OST_SUPPORT;
  529. #endif
  530. if (!ghes_disable)
  531. capbuf[OSC_SUPPORT_TYPE] |= OSC_SB_APEI_SUPPORT;
  532. if (ACPI_FAILURE(acpi_get_handle(NULL, "\\_SB", &handle)))
  533. return;
  534. if (ACPI_SUCCESS(acpi_run_osc(handle, &context))) {
  535. u32 *capbuf_ret = context.ret.pointer;
  536. if (context.ret.length > OSC_SUPPORT_TYPE)
  537. osc_sb_apei_support_acked =
  538. capbuf_ret[OSC_SUPPORT_TYPE] & OSC_SB_APEI_SUPPORT;
  539. kfree(context.ret.pointer);
  540. }
  541. /* do we need to check other returned cap? Sounds no */
  542. }
  543. /* --------------------------------------------------------------------------
  544. Event Management
  545. -------------------------------------------------------------------------- */
  546. #ifdef CONFIG_ACPI_PROC_EVENT
  547. static DEFINE_SPINLOCK(acpi_bus_event_lock);
  548. LIST_HEAD(acpi_bus_event_list);
  549. DECLARE_WAIT_QUEUE_HEAD(acpi_bus_event_queue);
  550. extern int event_is_open;
  551. int acpi_bus_generate_proc_event4(const char *device_class, const char *bus_id, u8 type, int data)
  552. {
  553. struct acpi_bus_event *event;
  554. unsigned long flags = 0;
  555. /* drop event on the floor if no one's listening */
  556. if (!event_is_open)
  557. return 0;
  558. event = kzalloc(sizeof(struct acpi_bus_event), GFP_ATOMIC);
  559. if (!event)
  560. return -ENOMEM;
  561. strcpy(event->device_class, device_class);
  562. strcpy(event->bus_id, bus_id);
  563. event->type = type;
  564. event->data = data;
  565. spin_lock_irqsave(&acpi_bus_event_lock, flags);
  566. list_add_tail(&event->node, &acpi_bus_event_list);
  567. spin_unlock_irqrestore(&acpi_bus_event_lock, flags);
  568. wake_up_interruptible(&acpi_bus_event_queue);
  569. return 0;
  570. }
  571. EXPORT_SYMBOL_GPL(acpi_bus_generate_proc_event4);
  572. int acpi_bus_generate_proc_event(struct acpi_device *device, u8 type, int data)
  573. {
  574. if (!device)
  575. return -EINVAL;
  576. return acpi_bus_generate_proc_event4(device->pnp.device_class,
  577. device->pnp.bus_id, type, data);
  578. }
  579. EXPORT_SYMBOL(acpi_bus_generate_proc_event);
  580. int acpi_bus_receive_event(struct acpi_bus_event *event)
  581. {
  582. unsigned long flags = 0;
  583. struct acpi_bus_event *entry = NULL;
  584. DECLARE_WAITQUEUE(wait, current);
  585. if (!event)
  586. return -EINVAL;
  587. if (list_empty(&acpi_bus_event_list)) {
  588. set_current_state(TASK_INTERRUPTIBLE);
  589. add_wait_queue(&acpi_bus_event_queue, &wait);
  590. if (list_empty(&acpi_bus_event_list))
  591. schedule();
  592. remove_wait_queue(&acpi_bus_event_queue, &wait);
  593. set_current_state(TASK_RUNNING);
  594. if (signal_pending(current))
  595. return -ERESTARTSYS;
  596. }
  597. spin_lock_irqsave(&acpi_bus_event_lock, flags);
  598. if (!list_empty(&acpi_bus_event_list)) {
  599. entry = list_entry(acpi_bus_event_list.next,
  600. struct acpi_bus_event, node);
  601. list_del(&entry->node);
  602. }
  603. spin_unlock_irqrestore(&acpi_bus_event_lock, flags);
  604. if (!entry)
  605. return -ENODEV;
  606. memcpy(event, entry, sizeof(struct acpi_bus_event));
  607. kfree(entry);
  608. return 0;
  609. }
  610. #endif /* CONFIG_ACPI_PROC_EVENT */
  611. /* --------------------------------------------------------------------------
  612. Notification Handling
  613. -------------------------------------------------------------------------- */
  614. static void acpi_bus_check_device(acpi_handle handle)
  615. {
  616. struct acpi_device *device;
  617. acpi_status status;
  618. struct acpi_device_status old_status;
  619. if (acpi_bus_get_device(handle, &device))
  620. return;
  621. if (!device)
  622. return;
  623. old_status = device->status;
  624. /*
  625. * Make sure this device's parent is present before we go about
  626. * messing with the device.
  627. */
  628. if (device->parent && !device->parent->status.present) {
  629. device->status = device->parent->status;
  630. return;
  631. }
  632. status = acpi_bus_get_status(device);
  633. if (ACPI_FAILURE(status))
  634. return;
  635. if (STRUCT_TO_INT(old_status) == STRUCT_TO_INT(device->status))
  636. return;
  637. /*
  638. * Device Insertion/Removal
  639. */
  640. if ((device->status.present) && !(old_status.present)) {
  641. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device insertion detected\n"));
  642. /* TBD: Handle device insertion */
  643. } else if (!(device->status.present) && (old_status.present)) {
  644. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device removal detected\n"));
  645. /* TBD: Handle device removal */
  646. }
  647. }
  648. static void acpi_bus_check_scope(acpi_handle handle)
  649. {
  650. /* Status Change? */
  651. acpi_bus_check_device(handle);
  652. /*
  653. * TBD: Enumerate child devices within this device's scope and
  654. * run acpi_bus_check_device()'s on them.
  655. */
  656. }
  657. static BLOCKING_NOTIFIER_HEAD(acpi_bus_notify_list);
  658. int register_acpi_bus_notifier(struct notifier_block *nb)
  659. {
  660. return blocking_notifier_chain_register(&acpi_bus_notify_list, nb);
  661. }
  662. EXPORT_SYMBOL_GPL(register_acpi_bus_notifier);
  663. void unregister_acpi_bus_notifier(struct notifier_block *nb)
  664. {
  665. blocking_notifier_chain_unregister(&acpi_bus_notify_list, nb);
  666. }
  667. EXPORT_SYMBOL_GPL(unregister_acpi_bus_notifier);
  668. /**
  669. * acpi_bus_notify
  670. * ---------------
  671. * Callback for all 'system-level' device notifications (values 0x00-0x7F).
  672. */
  673. static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
  674. {
  675. struct acpi_device *device = NULL;
  676. struct acpi_driver *driver;
  677. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Notification %#02x to handle %p\n",
  678. type, handle));
  679. blocking_notifier_call_chain(&acpi_bus_notify_list,
  680. type, (void *)handle);
  681. switch (type) {
  682. case ACPI_NOTIFY_BUS_CHECK:
  683. acpi_bus_check_scope(handle);
  684. /*
  685. * TBD: We'll need to outsource certain events to non-ACPI
  686. * drivers via the device manager (device.c).
  687. */
  688. break;
  689. case ACPI_NOTIFY_DEVICE_CHECK:
  690. acpi_bus_check_device(handle);
  691. /*
  692. * TBD: We'll need to outsource certain events to non-ACPI
  693. * drivers via the device manager (device.c).
  694. */
  695. break;
  696. case ACPI_NOTIFY_DEVICE_WAKE:
  697. /* TBD */
  698. break;
  699. case ACPI_NOTIFY_EJECT_REQUEST:
  700. /* TBD */
  701. break;
  702. case ACPI_NOTIFY_DEVICE_CHECK_LIGHT:
  703. /* TBD: Exactly what does 'light' mean? */
  704. break;
  705. case ACPI_NOTIFY_FREQUENCY_MISMATCH:
  706. /* TBD */
  707. break;
  708. case ACPI_NOTIFY_BUS_MODE_MISMATCH:
  709. /* TBD */
  710. break;
  711. case ACPI_NOTIFY_POWER_FAULT:
  712. /* TBD */
  713. break;
  714. default:
  715. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  716. "Received unknown/unsupported notification [%08x]\n",
  717. type));
  718. break;
  719. }
  720. acpi_bus_get_device(handle, &device);
  721. if (device) {
  722. driver = device->driver;
  723. if (driver && driver->ops.notify &&
  724. (driver->flags & ACPI_DRIVER_ALL_NOTIFY_EVENTS))
  725. driver->ops.notify(device, type);
  726. }
  727. }
  728. /* --------------------------------------------------------------------------
  729. Initialization/Cleanup
  730. -------------------------------------------------------------------------- */
  731. static int __init acpi_bus_init_irq(void)
  732. {
  733. acpi_status status = AE_OK;
  734. union acpi_object arg = { ACPI_TYPE_INTEGER };
  735. struct acpi_object_list arg_list = { 1, &arg };
  736. char *message = NULL;
  737. /*
  738. * Let the system know what interrupt model we are using by
  739. * evaluating the \_PIC object, if exists.
  740. */
  741. switch (acpi_irq_model) {
  742. case ACPI_IRQ_MODEL_PIC:
  743. message = "PIC";
  744. break;
  745. case ACPI_IRQ_MODEL_IOAPIC:
  746. message = "IOAPIC";
  747. break;
  748. case ACPI_IRQ_MODEL_IOSAPIC:
  749. message = "IOSAPIC";
  750. break;
  751. case ACPI_IRQ_MODEL_PLATFORM:
  752. message = "platform specific model";
  753. break;
  754. default:
  755. printk(KERN_WARNING PREFIX "Unknown interrupt routing model\n");
  756. return -ENODEV;
  757. }
  758. printk(KERN_INFO PREFIX "Using %s for interrupt routing\n", message);
  759. arg.integer.value = acpi_irq_model;
  760. status = acpi_evaluate_object(NULL, "\\_PIC", &arg_list, NULL);
  761. if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
  762. ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PIC"));
  763. return -ENODEV;
  764. }
  765. return 0;
  766. }
  767. u8 acpi_gbl_permanent_mmap;
  768. void __init acpi_early_init(void)
  769. {
  770. acpi_status status = AE_OK;
  771. if (acpi_disabled)
  772. return;
  773. printk(KERN_INFO PREFIX "Core revision %08x\n", ACPI_CA_VERSION);
  774. /* enable workarounds, unless strict ACPI spec. compliance */
  775. if (!acpi_strict)
  776. acpi_gbl_enable_interpreter_slack = TRUE;
  777. acpi_gbl_permanent_mmap = 1;
  778. /*
  779. * If the machine falls into the DMI check table,
  780. * DSDT will be copied to memory
  781. */
  782. dmi_check_system(dsdt_dmi_table);
  783. status = acpi_reallocate_root_table();
  784. if (ACPI_FAILURE(status)) {
  785. printk(KERN_ERR PREFIX
  786. "Unable to reallocate ACPI tables\n");
  787. goto error0;
  788. }
  789. status = acpi_initialize_subsystem();
  790. if (ACPI_FAILURE(status)) {
  791. printk(KERN_ERR PREFIX
  792. "Unable to initialize the ACPI Interpreter\n");
  793. goto error0;
  794. }
  795. status = acpi_load_tables();
  796. if (ACPI_FAILURE(status)) {
  797. printk(KERN_ERR PREFIX
  798. "Unable to load the System Description Tables\n");
  799. goto error0;
  800. }
  801. #ifdef CONFIG_X86
  802. if (!acpi_ioapic) {
  803. /* compatible (0) means level (3) */
  804. if (!(acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)) {
  805. acpi_sci_flags &= ~ACPI_MADT_TRIGGER_MASK;
  806. acpi_sci_flags |= ACPI_MADT_TRIGGER_LEVEL;
  807. }
  808. /* Set PIC-mode SCI trigger type */
  809. acpi_pic_sci_set_trigger(acpi_gbl_FADT.sci_interrupt,
  810. (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2);
  811. } else {
  812. /*
  813. * now that acpi_gbl_FADT is initialized,
  814. * update it with result from INT_SRC_OVR parsing
  815. */
  816. acpi_gbl_FADT.sci_interrupt = acpi_sci_override_gsi;
  817. }
  818. #endif
  819. status = acpi_enable_subsystem(~ACPI_NO_ACPI_ENABLE);
  820. if (ACPI_FAILURE(status)) {
  821. printk(KERN_ERR PREFIX "Unable to enable ACPI\n");
  822. goto error0;
  823. }
  824. return;
  825. error0:
  826. disable_acpi();
  827. return;
  828. }
  829. static int __init acpi_bus_init(void)
  830. {
  831. int result = 0;
  832. acpi_status status = AE_OK;
  833. extern acpi_status acpi_os_initialize1(void);
  834. acpi_os_initialize1();
  835. status = acpi_enable_subsystem(ACPI_NO_ACPI_ENABLE);
  836. if (ACPI_FAILURE(status)) {
  837. printk(KERN_ERR PREFIX
  838. "Unable to start the ACPI Interpreter\n");
  839. goto error1;
  840. }
  841. /*
  842. * ACPI 2.0 requires the EC driver to be loaded and work before
  843. * the EC device is found in the namespace (i.e. before acpi_initialize_objects()
  844. * is called).
  845. *
  846. * This is accomplished by looking for the ECDT table, and getting
  847. * the EC parameters out of that.
  848. */
  849. status = acpi_ec_ecdt_probe();
  850. /* Ignore result. Not having an ECDT is not fatal. */
  851. status = acpi_initialize_objects(ACPI_FULL_INITIALIZATION);
  852. if (ACPI_FAILURE(status)) {
  853. printk(KERN_ERR PREFIX "Unable to initialize ACPI objects\n");
  854. goto error1;
  855. }
  856. /*
  857. * _OSC method may exist in module level code,
  858. * so it must be run after ACPI_FULL_INITIALIZATION
  859. */
  860. acpi_bus_osc_support();
  861. /*
  862. * _PDC control method may load dynamic SSDT tables,
  863. * and we need to install the table handler before that.
  864. */
  865. acpi_sysfs_init();
  866. acpi_early_processor_set_pdc();
  867. /*
  868. * Maybe EC region is required at bus_scan/acpi_get_devices. So it
  869. * is necessary to enable it as early as possible.
  870. */
  871. acpi_boot_ec_enable();
  872. printk(KERN_INFO PREFIX "Interpreter enabled\n");
  873. /* Initialize sleep structures */
  874. acpi_sleep_init();
  875. /*
  876. * Get the system interrupt model and evaluate \_PIC.
  877. */
  878. result = acpi_bus_init_irq();
  879. if (result)
  880. goto error1;
  881. /*
  882. * Register the for all standard device notifications.
  883. */
  884. status =
  885. acpi_install_notify_handler(ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY,
  886. &acpi_bus_notify, NULL);
  887. if (ACPI_FAILURE(status)) {
  888. printk(KERN_ERR PREFIX
  889. "Unable to register for device notifications\n");
  890. goto error1;
  891. }
  892. /*
  893. * Create the top ACPI proc directory
  894. */
  895. acpi_root_dir = proc_mkdir(ACPI_BUS_FILE_ROOT, NULL);
  896. return 0;
  897. /* Mimic structured exception handling */
  898. error1:
  899. acpi_terminate();
  900. return -ENODEV;
  901. }
  902. struct kobject *acpi_kobj;
  903. EXPORT_SYMBOL_GPL(acpi_kobj);
  904. static int __init acpi_init(void)
  905. {
  906. int result;
  907. if (acpi_disabled) {
  908. printk(KERN_INFO PREFIX "Interpreter disabled.\n");
  909. return -ENODEV;
  910. }
  911. acpi_kobj = kobject_create_and_add("acpi", firmware_kobj);
  912. if (!acpi_kobj) {
  913. printk(KERN_WARNING "%s: kset create error\n", __func__);
  914. acpi_kobj = NULL;
  915. }
  916. init_acpi_device_notify();
  917. result = acpi_bus_init();
  918. if (result) {
  919. disable_acpi();
  920. return result;
  921. }
  922. pci_mmcfg_late_init();
  923. acpi_scan_init();
  924. acpi_ec_init();
  925. acpi_debugfs_init();
  926. acpi_sleep_proc_init();
  927. acpi_wakeup_device_init();
  928. return 0;
  929. }
  930. subsys_initcall(acpi_init);