bus.c 27 KB

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