evgpeblk.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213
  1. /******************************************************************************
  2. *
  3. * Module Name: evgpeblk - GPE block creation and initialization.
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2007, R. Byron Moore
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #include <acpi/acpi.h>
  43. #include <acpi/acevents.h>
  44. #include <acpi/acnamesp.h>
  45. #define _COMPONENT ACPI_EVENTS
  46. ACPI_MODULE_NAME("evgpeblk")
  47. /* Local prototypes */
  48. static acpi_status
  49. acpi_ev_save_method_info(acpi_handle obj_handle,
  50. u32 level, void *obj_desc, void **return_value);
  51. static acpi_status
  52. acpi_ev_match_prw_and_gpe(acpi_handle obj_handle,
  53. u32 level, void *info, void **return_value);
  54. static struct acpi_gpe_xrupt_info *acpi_ev_get_gpe_xrupt_block(u32
  55. interrupt_number);
  56. static acpi_status
  57. acpi_ev_delete_gpe_xrupt(struct acpi_gpe_xrupt_info *gpe_xrupt);
  58. static acpi_status
  59. acpi_ev_install_gpe_block(struct acpi_gpe_block_info *gpe_block,
  60. u32 interrupt_number);
  61. static acpi_status
  62. acpi_ev_create_gpe_info_blocks(struct acpi_gpe_block_info *gpe_block);
  63. /*******************************************************************************
  64. *
  65. * FUNCTION: acpi_ev_valid_gpe_event
  66. *
  67. * PARAMETERS: gpe_event_info - Info for this GPE
  68. *
  69. * RETURN: TRUE if the gpe_event is valid
  70. *
  71. * DESCRIPTION: Validate a GPE event. DO NOT CALL FROM INTERRUPT LEVEL.
  72. * Should be called only when the GPE lists are semaphore locked
  73. * and not subject to change.
  74. *
  75. ******************************************************************************/
  76. u8 acpi_ev_valid_gpe_event(struct acpi_gpe_event_info *gpe_event_info)
  77. {
  78. struct acpi_gpe_xrupt_info *gpe_xrupt_block;
  79. struct acpi_gpe_block_info *gpe_block;
  80. ACPI_FUNCTION_ENTRY();
  81. /* No need for spin lock since we are not changing any list elements */
  82. /* Walk the GPE interrupt levels */
  83. gpe_xrupt_block = acpi_gbl_gpe_xrupt_list_head;
  84. while (gpe_xrupt_block) {
  85. gpe_block = gpe_xrupt_block->gpe_block_list_head;
  86. /* Walk the GPE blocks on this interrupt level */
  87. while (gpe_block) {
  88. if ((&gpe_block->event_info[0] <= gpe_event_info) &&
  89. (&gpe_block->
  90. event_info[((acpi_size) gpe_block->
  91. register_count) * 8] >
  92. gpe_event_info)) {
  93. return (TRUE);
  94. }
  95. gpe_block = gpe_block->next;
  96. }
  97. gpe_xrupt_block = gpe_xrupt_block->next;
  98. }
  99. return (FALSE);
  100. }
  101. /*******************************************************************************
  102. *
  103. * FUNCTION: acpi_ev_walk_gpe_list
  104. *
  105. * PARAMETERS: gpe_walk_callback - Routine called for each GPE block
  106. *
  107. * RETURN: Status
  108. *
  109. * DESCRIPTION: Walk the GPE lists.
  110. *
  111. ******************************************************************************/
  112. acpi_status acpi_ev_walk_gpe_list(acpi_gpe_callback gpe_walk_callback)
  113. {
  114. struct acpi_gpe_block_info *gpe_block;
  115. struct acpi_gpe_xrupt_info *gpe_xrupt_info;
  116. acpi_status status = AE_OK;
  117. acpi_cpu_flags flags;
  118. ACPI_FUNCTION_TRACE(ev_walk_gpe_list);
  119. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  120. /* Walk the interrupt level descriptor list */
  121. gpe_xrupt_info = acpi_gbl_gpe_xrupt_list_head;
  122. while (gpe_xrupt_info) {
  123. /* Walk all Gpe Blocks attached to this interrupt level */
  124. gpe_block = gpe_xrupt_info->gpe_block_list_head;
  125. while (gpe_block) {
  126. /* One callback per GPE block */
  127. status = gpe_walk_callback(gpe_xrupt_info, gpe_block);
  128. if (ACPI_FAILURE(status)) {
  129. goto unlock_and_exit;
  130. }
  131. gpe_block = gpe_block->next;
  132. }
  133. gpe_xrupt_info = gpe_xrupt_info->next;
  134. }
  135. unlock_and_exit:
  136. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  137. return_ACPI_STATUS(status);
  138. }
  139. /*******************************************************************************
  140. *
  141. * FUNCTION: acpi_ev_delete_gpe_handlers
  142. *
  143. * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
  144. * gpe_block - Gpe Block info
  145. *
  146. * RETURN: Status
  147. *
  148. * DESCRIPTION: Delete all Handler objects found in the GPE data structs.
  149. * Used only prior to termination.
  150. *
  151. ******************************************************************************/
  152. acpi_status
  153. acpi_ev_delete_gpe_handlers(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
  154. struct acpi_gpe_block_info *gpe_block)
  155. {
  156. struct acpi_gpe_event_info *gpe_event_info;
  157. acpi_native_uint i;
  158. acpi_native_uint j;
  159. ACPI_FUNCTION_TRACE(ev_delete_gpe_handlers);
  160. /* Examine each GPE Register within the block */
  161. for (i = 0; i < gpe_block->register_count; i++) {
  162. /* Now look at the individual GPEs in this byte register */
  163. for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
  164. gpe_event_info =
  165. &gpe_block->
  166. event_info[(i * ACPI_GPE_REGISTER_WIDTH) + j];
  167. if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
  168. ACPI_GPE_DISPATCH_HANDLER) {
  169. ACPI_FREE(gpe_event_info->dispatch.handler);
  170. gpe_event_info->dispatch.handler = NULL;
  171. gpe_event_info->flags &=
  172. ~ACPI_GPE_DISPATCH_MASK;
  173. }
  174. }
  175. }
  176. return_ACPI_STATUS(AE_OK);
  177. }
  178. /*******************************************************************************
  179. *
  180. * FUNCTION: acpi_ev_save_method_info
  181. *
  182. * PARAMETERS: Callback from walk_namespace
  183. *
  184. * RETURN: Status
  185. *
  186. * DESCRIPTION: Called from acpi_walk_namespace. Expects each object to be a
  187. * control method under the _GPE portion of the namespace.
  188. * Extract the name and GPE type from the object, saving this
  189. * information for quick lookup during GPE dispatch
  190. *
  191. * The name of each GPE control method is of the form:
  192. * "_Lxx" or "_Exx"
  193. * Where:
  194. * L - means that the GPE is level triggered
  195. * E - means that the GPE is edge triggered
  196. * xx - is the GPE number [in HEX]
  197. *
  198. ******************************************************************************/
  199. static acpi_status
  200. acpi_ev_save_method_info(acpi_handle obj_handle,
  201. u32 level, void *obj_desc, void **return_value)
  202. {
  203. struct acpi_gpe_block_info *gpe_block = (void *)obj_desc;
  204. struct acpi_gpe_event_info *gpe_event_info;
  205. u32 gpe_number;
  206. char name[ACPI_NAME_SIZE + 1];
  207. u8 type;
  208. acpi_status status;
  209. ACPI_FUNCTION_TRACE(ev_save_method_info);
  210. /*
  211. * _Lxx and _Exx GPE method support
  212. *
  213. * 1) Extract the name from the object and convert to a string
  214. */
  215. ACPI_MOVE_32_TO_32(name,
  216. &((struct acpi_namespace_node *)obj_handle)->name.
  217. integer);
  218. name[ACPI_NAME_SIZE] = 0;
  219. /*
  220. * 2) Edge/Level determination is based on the 2nd character
  221. * of the method name
  222. *
  223. * NOTE: Default GPE type is RUNTIME. May be changed later to WAKE
  224. * if a _PRW object is found that points to this GPE.
  225. */
  226. switch (name[1]) {
  227. case 'L':
  228. type = ACPI_GPE_LEVEL_TRIGGERED;
  229. break;
  230. case 'E':
  231. type = ACPI_GPE_EDGE_TRIGGERED;
  232. break;
  233. default:
  234. /* Unknown method type, just ignore it! */
  235. ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
  236. "Ignoring unknown GPE method type: %s (name not of form _Lxx or _Exx)",
  237. name));
  238. return_ACPI_STATUS(AE_OK);
  239. }
  240. /* Convert the last two characters of the name to the GPE Number */
  241. gpe_number = ACPI_STRTOUL(&name[2], NULL, 16);
  242. if (gpe_number == ACPI_UINT32_MAX) {
  243. /* Conversion failed; invalid method, just ignore it */
  244. ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
  245. "Could not extract GPE number from name: %s (name is not of form _Lxx or _Exx)",
  246. name));
  247. return_ACPI_STATUS(AE_OK);
  248. }
  249. /* Ensure that we have a valid GPE number for this GPE block */
  250. if ((gpe_number < gpe_block->block_base_number) ||
  251. (gpe_number >=
  252. (gpe_block->block_base_number +
  253. (gpe_block->register_count * 8)))) {
  254. /*
  255. * Not valid for this GPE block, just ignore it
  256. * However, it may be valid for a different GPE block, since GPE0 and GPE1
  257. * methods both appear under \_GPE.
  258. */
  259. return_ACPI_STATUS(AE_OK);
  260. }
  261. /*
  262. * Now we can add this information to the gpe_event_info block
  263. * for use during dispatch of this GPE. Default type is RUNTIME, although
  264. * this may change when the _PRW methods are executed later.
  265. */
  266. gpe_event_info =
  267. &gpe_block->event_info[gpe_number - gpe_block->block_base_number];
  268. gpe_event_info->flags = (u8)
  269. (type | ACPI_GPE_DISPATCH_METHOD | ACPI_GPE_TYPE_RUNTIME);
  270. gpe_event_info->dispatch.method_node =
  271. (struct acpi_namespace_node *)obj_handle;
  272. /* Update enable mask, but don't enable the HW GPE as of yet */
  273. status = acpi_ev_enable_gpe(gpe_event_info, FALSE);
  274. ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
  275. "Registered GPE method %s as GPE number 0x%.2X\n",
  276. name, gpe_number));
  277. return_ACPI_STATUS(status);
  278. }
  279. /*******************************************************************************
  280. *
  281. * FUNCTION: acpi_ev_match_prw_and_gpe
  282. *
  283. * PARAMETERS: Callback from walk_namespace
  284. *
  285. * RETURN: Status. NOTE: We ignore errors so that the _PRW walk is
  286. * not aborted on a single _PRW failure.
  287. *
  288. * DESCRIPTION: Called from acpi_walk_namespace. Expects each object to be a
  289. * Device. Run the _PRW method. If present, extract the GPE
  290. * number and mark the GPE as a WAKE GPE.
  291. *
  292. ******************************************************************************/
  293. static acpi_status
  294. acpi_ev_match_prw_and_gpe(acpi_handle obj_handle,
  295. u32 level, void *info, void **return_value)
  296. {
  297. struct acpi_gpe_walk_info *gpe_info = (void *)info;
  298. struct acpi_namespace_node *gpe_device;
  299. struct acpi_gpe_block_info *gpe_block;
  300. struct acpi_namespace_node *target_gpe_device;
  301. struct acpi_gpe_event_info *gpe_event_info;
  302. union acpi_operand_object *pkg_desc;
  303. union acpi_operand_object *obj_desc;
  304. u32 gpe_number;
  305. acpi_status status;
  306. ACPI_FUNCTION_TRACE(ev_match_prw_and_gpe);
  307. /* Check for a _PRW method under this device */
  308. status = acpi_ut_evaluate_object(obj_handle, METHOD_NAME__PRW,
  309. ACPI_BTYPE_PACKAGE, &pkg_desc);
  310. if (ACPI_FAILURE(status)) {
  311. /* Ignore all errors from _PRW, we don't want to abort the subsystem */
  312. return_ACPI_STATUS(AE_OK);
  313. }
  314. /* The returned _PRW package must have at least two elements */
  315. if (pkg_desc->package.count < 2) {
  316. goto cleanup;
  317. }
  318. /* Extract pointers from the input context */
  319. gpe_device = gpe_info->gpe_device;
  320. gpe_block = gpe_info->gpe_block;
  321. /*
  322. * The _PRW object must return a package, we are only interested
  323. * in the first element
  324. */
  325. obj_desc = pkg_desc->package.elements[0];
  326. if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_INTEGER) {
  327. /* Use FADT-defined GPE device (from definition of _PRW) */
  328. target_gpe_device = acpi_gbl_fadt_gpe_device;
  329. /* Integer is the GPE number in the FADT described GPE blocks */
  330. gpe_number = (u32) obj_desc->integer.value;
  331. } else if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_PACKAGE) {
  332. /* Package contains a GPE reference and GPE number within a GPE block */
  333. if ((obj_desc->package.count < 2) ||
  334. (ACPI_GET_OBJECT_TYPE(obj_desc->package.elements[0]) !=
  335. ACPI_TYPE_LOCAL_REFERENCE)
  336. || (ACPI_GET_OBJECT_TYPE(obj_desc->package.elements[1]) !=
  337. ACPI_TYPE_INTEGER)) {
  338. goto cleanup;
  339. }
  340. /* Get GPE block reference and decode */
  341. target_gpe_device =
  342. obj_desc->package.elements[0]->reference.node;
  343. gpe_number = (u32) obj_desc->package.elements[1]->integer.value;
  344. } else {
  345. /* Unknown type, just ignore it */
  346. goto cleanup;
  347. }
  348. /*
  349. * Is this GPE within this block?
  350. *
  351. * TRUE iff these conditions are true:
  352. * 1) The GPE devices match.
  353. * 2) The GPE index(number) is within the range of the Gpe Block
  354. * associated with the GPE device.
  355. */
  356. if ((gpe_device == target_gpe_device) &&
  357. (gpe_number >= gpe_block->block_base_number) &&
  358. (gpe_number <
  359. gpe_block->block_base_number + (gpe_block->register_count * 8))) {
  360. gpe_event_info =
  361. &gpe_block->event_info[gpe_number -
  362. gpe_block->block_base_number];
  363. /* Mark GPE for WAKE-ONLY but WAKE_DISABLED */
  364. gpe_event_info->flags &=
  365. ~(ACPI_GPE_WAKE_ENABLED | ACPI_GPE_RUN_ENABLED);
  366. status =
  367. acpi_ev_set_gpe_type(gpe_event_info, ACPI_GPE_TYPE_WAKE);
  368. if (ACPI_FAILURE(status)) {
  369. goto cleanup;
  370. }
  371. status =
  372. acpi_ev_update_gpe_enable_masks(gpe_event_info,
  373. ACPI_GPE_DISABLE);
  374. }
  375. cleanup:
  376. acpi_ut_remove_reference(pkg_desc);
  377. return_ACPI_STATUS(AE_OK);
  378. }
  379. /*******************************************************************************
  380. *
  381. * FUNCTION: acpi_ev_get_gpe_xrupt_block
  382. *
  383. * PARAMETERS: interrupt_number - Interrupt for a GPE block
  384. *
  385. * RETURN: A GPE interrupt block
  386. *
  387. * DESCRIPTION: Get or Create a GPE interrupt block. There is one interrupt
  388. * block per unique interrupt level used for GPEs.
  389. * Should be called only when the GPE lists are semaphore locked
  390. * and not subject to change.
  391. *
  392. ******************************************************************************/
  393. static struct acpi_gpe_xrupt_info *acpi_ev_get_gpe_xrupt_block(u32
  394. interrupt_number)
  395. {
  396. struct acpi_gpe_xrupt_info *next_gpe_xrupt;
  397. struct acpi_gpe_xrupt_info *gpe_xrupt;
  398. acpi_status status;
  399. acpi_cpu_flags flags;
  400. ACPI_FUNCTION_TRACE(ev_get_gpe_xrupt_block);
  401. /* No need for lock since we are not changing any list elements here */
  402. next_gpe_xrupt = acpi_gbl_gpe_xrupt_list_head;
  403. while (next_gpe_xrupt) {
  404. if (next_gpe_xrupt->interrupt_number == interrupt_number) {
  405. return_PTR(next_gpe_xrupt);
  406. }
  407. next_gpe_xrupt = next_gpe_xrupt->next;
  408. }
  409. /* Not found, must allocate a new xrupt descriptor */
  410. gpe_xrupt = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_xrupt_info));
  411. if (!gpe_xrupt) {
  412. return_PTR(NULL);
  413. }
  414. gpe_xrupt->interrupt_number = interrupt_number;
  415. /* Install new interrupt descriptor with spin lock */
  416. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  417. if (acpi_gbl_gpe_xrupt_list_head) {
  418. next_gpe_xrupt = acpi_gbl_gpe_xrupt_list_head;
  419. while (next_gpe_xrupt->next) {
  420. next_gpe_xrupt = next_gpe_xrupt->next;
  421. }
  422. next_gpe_xrupt->next = gpe_xrupt;
  423. gpe_xrupt->previous = next_gpe_xrupt;
  424. } else {
  425. acpi_gbl_gpe_xrupt_list_head = gpe_xrupt;
  426. }
  427. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  428. /* Install new interrupt handler if not SCI_INT */
  429. if (interrupt_number != acpi_gbl_FADT.sci_interrupt) {
  430. status = acpi_os_install_interrupt_handler(interrupt_number,
  431. acpi_ev_gpe_xrupt_handler,
  432. gpe_xrupt);
  433. if (ACPI_FAILURE(status)) {
  434. ACPI_ERROR((AE_INFO,
  435. "Could not install GPE interrupt handler at level 0x%X",
  436. interrupt_number));
  437. return_PTR(NULL);
  438. }
  439. }
  440. return_PTR(gpe_xrupt);
  441. }
  442. /*******************************************************************************
  443. *
  444. * FUNCTION: acpi_ev_delete_gpe_xrupt
  445. *
  446. * PARAMETERS: gpe_xrupt - A GPE interrupt info block
  447. *
  448. * RETURN: Status
  449. *
  450. * DESCRIPTION: Remove and free a gpe_xrupt block. Remove an associated
  451. * interrupt handler if not the SCI interrupt.
  452. *
  453. ******************************************************************************/
  454. static acpi_status
  455. acpi_ev_delete_gpe_xrupt(struct acpi_gpe_xrupt_info *gpe_xrupt)
  456. {
  457. acpi_status status;
  458. acpi_cpu_flags flags;
  459. ACPI_FUNCTION_TRACE(ev_delete_gpe_xrupt);
  460. /* We never want to remove the SCI interrupt handler */
  461. if (gpe_xrupt->interrupt_number == acpi_gbl_FADT.sci_interrupt) {
  462. gpe_xrupt->gpe_block_list_head = NULL;
  463. return_ACPI_STATUS(AE_OK);
  464. }
  465. /* Disable this interrupt */
  466. status =
  467. acpi_os_remove_interrupt_handler(gpe_xrupt->interrupt_number,
  468. acpi_ev_gpe_xrupt_handler);
  469. if (ACPI_FAILURE(status)) {
  470. return_ACPI_STATUS(status);
  471. }
  472. /* Unlink the interrupt block with lock */
  473. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  474. if (gpe_xrupt->previous) {
  475. gpe_xrupt->previous->next = gpe_xrupt->next;
  476. } else {
  477. /* No previous, update list head */
  478. acpi_gbl_gpe_xrupt_list_head = gpe_xrupt->next;
  479. }
  480. if (gpe_xrupt->next) {
  481. gpe_xrupt->next->previous = gpe_xrupt->previous;
  482. }
  483. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  484. /* Free the block */
  485. ACPI_FREE(gpe_xrupt);
  486. return_ACPI_STATUS(AE_OK);
  487. }
  488. /*******************************************************************************
  489. *
  490. * FUNCTION: acpi_ev_install_gpe_block
  491. *
  492. * PARAMETERS: gpe_block - New GPE block
  493. * interrupt_number - Xrupt to be associated with this GPE block
  494. *
  495. * RETURN: Status
  496. *
  497. * DESCRIPTION: Install new GPE block with mutex support
  498. *
  499. ******************************************************************************/
  500. static acpi_status
  501. acpi_ev_install_gpe_block(struct acpi_gpe_block_info *gpe_block,
  502. u32 interrupt_number)
  503. {
  504. struct acpi_gpe_block_info *next_gpe_block;
  505. struct acpi_gpe_xrupt_info *gpe_xrupt_block;
  506. acpi_status status;
  507. acpi_cpu_flags flags;
  508. ACPI_FUNCTION_TRACE(ev_install_gpe_block);
  509. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  510. if (ACPI_FAILURE(status)) {
  511. return_ACPI_STATUS(status);
  512. }
  513. gpe_xrupt_block = acpi_ev_get_gpe_xrupt_block(interrupt_number);
  514. if (!gpe_xrupt_block) {
  515. status = AE_NO_MEMORY;
  516. goto unlock_and_exit;
  517. }
  518. /* Install the new block at the end of the list with lock */
  519. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  520. if (gpe_xrupt_block->gpe_block_list_head) {
  521. next_gpe_block = gpe_xrupt_block->gpe_block_list_head;
  522. while (next_gpe_block->next) {
  523. next_gpe_block = next_gpe_block->next;
  524. }
  525. next_gpe_block->next = gpe_block;
  526. gpe_block->previous = next_gpe_block;
  527. } else {
  528. gpe_xrupt_block->gpe_block_list_head = gpe_block;
  529. }
  530. gpe_block->xrupt_block = gpe_xrupt_block;
  531. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  532. unlock_and_exit:
  533. status = acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  534. return_ACPI_STATUS(status);
  535. }
  536. /*******************************************************************************
  537. *
  538. * FUNCTION: acpi_ev_delete_gpe_block
  539. *
  540. * PARAMETERS: gpe_block - Existing GPE block
  541. *
  542. * RETURN: Status
  543. *
  544. * DESCRIPTION: Remove a GPE block
  545. *
  546. ******************************************************************************/
  547. acpi_status acpi_ev_delete_gpe_block(struct acpi_gpe_block_info *gpe_block)
  548. {
  549. acpi_status status;
  550. acpi_cpu_flags flags;
  551. ACPI_FUNCTION_TRACE(ev_install_gpe_block);
  552. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  553. if (ACPI_FAILURE(status)) {
  554. return_ACPI_STATUS(status);
  555. }
  556. /* Disable all GPEs in this block */
  557. status = acpi_hw_disable_gpe_block(gpe_block->xrupt_block, gpe_block);
  558. if (!gpe_block->previous && !gpe_block->next) {
  559. /* This is the last gpe_block on this interrupt */
  560. status = acpi_ev_delete_gpe_xrupt(gpe_block->xrupt_block);
  561. if (ACPI_FAILURE(status)) {
  562. goto unlock_and_exit;
  563. }
  564. } else {
  565. /* Remove the block on this interrupt with lock */
  566. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  567. if (gpe_block->previous) {
  568. gpe_block->previous->next = gpe_block->next;
  569. } else {
  570. gpe_block->xrupt_block->gpe_block_list_head =
  571. gpe_block->next;
  572. }
  573. if (gpe_block->next) {
  574. gpe_block->next->previous = gpe_block->previous;
  575. }
  576. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  577. }
  578. /* Free the gpe_block */
  579. ACPI_FREE(gpe_block->register_info);
  580. ACPI_FREE(gpe_block->event_info);
  581. ACPI_FREE(gpe_block);
  582. unlock_and_exit:
  583. status = acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  584. return_ACPI_STATUS(status);
  585. }
  586. /*******************************************************************************
  587. *
  588. * FUNCTION: acpi_ev_create_gpe_info_blocks
  589. *
  590. * PARAMETERS: gpe_block - New GPE block
  591. *
  592. * RETURN: Status
  593. *
  594. * DESCRIPTION: Create the register_info and event_info blocks for this GPE block
  595. *
  596. ******************************************************************************/
  597. static acpi_status
  598. acpi_ev_create_gpe_info_blocks(struct acpi_gpe_block_info *gpe_block)
  599. {
  600. struct acpi_gpe_register_info *gpe_register_info = NULL;
  601. struct acpi_gpe_event_info *gpe_event_info = NULL;
  602. struct acpi_gpe_event_info *this_event;
  603. struct acpi_gpe_register_info *this_register;
  604. acpi_native_uint i;
  605. acpi_native_uint j;
  606. acpi_status status;
  607. ACPI_FUNCTION_TRACE(ev_create_gpe_info_blocks);
  608. /* Allocate the GPE register information block */
  609. gpe_register_info = ACPI_ALLOCATE_ZEROED((acpi_size) gpe_block->
  610. register_count *
  611. sizeof(struct
  612. acpi_gpe_register_info));
  613. if (!gpe_register_info) {
  614. ACPI_ERROR((AE_INFO,
  615. "Could not allocate the GpeRegisterInfo table"));
  616. return_ACPI_STATUS(AE_NO_MEMORY);
  617. }
  618. /*
  619. * Allocate the GPE event_info block. There are eight distinct GPEs
  620. * per register. Initialization to zeros is sufficient.
  621. */
  622. gpe_event_info = ACPI_ALLOCATE_ZEROED(((acpi_size) gpe_block->
  623. register_count *
  624. ACPI_GPE_REGISTER_WIDTH) *
  625. sizeof(struct
  626. acpi_gpe_event_info));
  627. if (!gpe_event_info) {
  628. ACPI_ERROR((AE_INFO,
  629. "Could not allocate the GpeEventInfo table"));
  630. status = AE_NO_MEMORY;
  631. goto error_exit;
  632. }
  633. /* Save the new Info arrays in the GPE block */
  634. gpe_block->register_info = gpe_register_info;
  635. gpe_block->event_info = gpe_event_info;
  636. /*
  637. * Initialize the GPE Register and Event structures. A goal of these
  638. * tables is to hide the fact that there are two separate GPE register sets
  639. * in a given GPE hardware block, the status registers occupy the first half,
  640. * and the enable registers occupy the second half.
  641. */
  642. this_register = gpe_register_info;
  643. this_event = gpe_event_info;
  644. for (i = 0; i < gpe_block->register_count; i++) {
  645. /* Init the register_info for this GPE register (8 GPEs) */
  646. this_register->base_gpe_number =
  647. (u8) (gpe_block->block_base_number +
  648. (i * ACPI_GPE_REGISTER_WIDTH));
  649. this_register->status_address.address =
  650. gpe_block->block_address.address + i;
  651. this_register->enable_address.address =
  652. gpe_block->block_address.address + i +
  653. gpe_block->register_count;
  654. this_register->status_address.space_id =
  655. gpe_block->block_address.space_id;
  656. this_register->enable_address.space_id =
  657. gpe_block->block_address.space_id;
  658. this_register->status_address.bit_width =
  659. ACPI_GPE_REGISTER_WIDTH;
  660. this_register->enable_address.bit_width =
  661. ACPI_GPE_REGISTER_WIDTH;
  662. this_register->status_address.bit_offset =
  663. ACPI_GPE_REGISTER_WIDTH;
  664. this_register->enable_address.bit_offset =
  665. ACPI_GPE_REGISTER_WIDTH;
  666. /* Init the event_info for each GPE within this register */
  667. for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
  668. this_event->gpe_number =
  669. (u8) (this_register->base_gpe_number + j);
  670. this_event->register_info = this_register;
  671. this_event++;
  672. }
  673. /* Disable all GPEs within this register */
  674. status = acpi_hw_low_level_write(ACPI_GPE_REGISTER_WIDTH, 0x00,
  675. &this_register->
  676. enable_address);
  677. if (ACPI_FAILURE(status)) {
  678. goto error_exit;
  679. }
  680. /* Clear any pending GPE events within this register */
  681. status = acpi_hw_low_level_write(ACPI_GPE_REGISTER_WIDTH, 0xFF,
  682. &this_register->
  683. status_address);
  684. if (ACPI_FAILURE(status)) {
  685. goto error_exit;
  686. }
  687. this_register++;
  688. }
  689. return_ACPI_STATUS(AE_OK);
  690. error_exit:
  691. if (gpe_register_info) {
  692. ACPI_FREE(gpe_register_info);
  693. }
  694. if (gpe_event_info) {
  695. ACPI_FREE(gpe_event_info);
  696. }
  697. return_ACPI_STATUS(status);
  698. }
  699. /*******************************************************************************
  700. *
  701. * FUNCTION: acpi_ev_create_gpe_block
  702. *
  703. * PARAMETERS: gpe_device - Handle to the parent GPE block
  704. * gpe_block_address - Address and space_iD
  705. * register_count - Number of GPE register pairs in the block
  706. * gpe_block_base_number - Starting GPE number for the block
  707. * interrupt_number - H/W interrupt for the block
  708. * return_gpe_block - Where the new block descriptor is returned
  709. *
  710. * RETURN: Status
  711. *
  712. * DESCRIPTION: Create and Install a block of GPE registers. All GPEs within
  713. * the block are disabled at exit.
  714. * Note: Assumes namespace is locked.
  715. *
  716. ******************************************************************************/
  717. acpi_status
  718. acpi_ev_create_gpe_block(struct acpi_namespace_node *gpe_device,
  719. struct acpi_generic_address *gpe_block_address,
  720. u32 register_count,
  721. u8 gpe_block_base_number,
  722. u32 interrupt_number,
  723. struct acpi_gpe_block_info **return_gpe_block)
  724. {
  725. acpi_status status;
  726. struct acpi_gpe_block_info *gpe_block;
  727. ACPI_FUNCTION_TRACE(ev_create_gpe_block);
  728. if (!register_count) {
  729. return_ACPI_STATUS(AE_OK);
  730. }
  731. /* Allocate a new GPE block */
  732. gpe_block = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_block_info));
  733. if (!gpe_block) {
  734. return_ACPI_STATUS(AE_NO_MEMORY);
  735. }
  736. /* Initialize the new GPE block */
  737. gpe_block->node = gpe_device;
  738. gpe_block->register_count = register_count;
  739. gpe_block->block_base_number = gpe_block_base_number;
  740. ACPI_MEMCPY(&gpe_block->block_address, gpe_block_address,
  741. sizeof(struct acpi_generic_address));
  742. /*
  743. * Create the register_info and event_info sub-structures
  744. * Note: disables and clears all GPEs in the block
  745. */
  746. status = acpi_ev_create_gpe_info_blocks(gpe_block);
  747. if (ACPI_FAILURE(status)) {
  748. ACPI_FREE(gpe_block);
  749. return_ACPI_STATUS(status);
  750. }
  751. /* Install the new block in the global lists */
  752. status = acpi_ev_install_gpe_block(gpe_block, interrupt_number);
  753. if (ACPI_FAILURE(status)) {
  754. ACPI_FREE(gpe_block);
  755. return_ACPI_STATUS(status);
  756. }
  757. /* Find all GPE methods (_Lxx, _Exx) for this block */
  758. status = acpi_ns_walk_namespace(ACPI_TYPE_METHOD, gpe_device,
  759. ACPI_UINT32_MAX, ACPI_NS_WALK_NO_UNLOCK,
  760. acpi_ev_save_method_info, gpe_block,
  761. NULL);
  762. /* Return the new block */
  763. if (return_gpe_block) {
  764. (*return_gpe_block) = gpe_block;
  765. }
  766. ACPI_DEBUG_PRINT((ACPI_DB_INIT,
  767. "GPE %02X to %02X [%4.4s] %u regs on int 0x%X\n",
  768. (u32) gpe_block->block_base_number,
  769. (u32) (gpe_block->block_base_number +
  770. ((gpe_block->register_count *
  771. ACPI_GPE_REGISTER_WIDTH) - 1)),
  772. gpe_device->name.ascii, gpe_block->register_count,
  773. interrupt_number));
  774. return_ACPI_STATUS(AE_OK);
  775. }
  776. /*******************************************************************************
  777. *
  778. * FUNCTION: acpi_ev_initialize_gpe_block
  779. *
  780. * PARAMETERS: gpe_device - Handle to the parent GPE block
  781. * gpe_block - Gpe Block info
  782. *
  783. * RETURN: Status
  784. *
  785. * DESCRIPTION: Initialize and enable a GPE block. First find and run any
  786. * _PRT methods associated with the block, then enable the
  787. * appropriate GPEs.
  788. * Note: Assumes namespace is locked.
  789. *
  790. ******************************************************************************/
  791. acpi_status
  792. acpi_ev_initialize_gpe_block(struct acpi_namespace_node *gpe_device,
  793. struct acpi_gpe_block_info *gpe_block)
  794. {
  795. acpi_status status;
  796. struct acpi_gpe_event_info *gpe_event_info;
  797. struct acpi_gpe_walk_info gpe_info;
  798. u32 wake_gpe_count;
  799. u32 gpe_enabled_count;
  800. acpi_native_uint i;
  801. acpi_native_uint j;
  802. ACPI_FUNCTION_TRACE(ev_initialize_gpe_block);
  803. /* Ignore a null GPE block (e.g., if no GPE block 1 exists) */
  804. if (!gpe_block) {
  805. return_ACPI_STATUS(AE_OK);
  806. }
  807. /*
  808. * Runtime option: Should wake GPEs be enabled at runtime? The default
  809. * is no, they should only be enabled just as the machine goes to sleep.
  810. */
  811. if (acpi_gbl_leave_wake_gpes_disabled) {
  812. /*
  813. * Differentiate runtime vs wake GPEs, via the _PRW control methods.
  814. * Each GPE that has one or more _PRWs that reference it is by
  815. * definition a wake GPE and will not be enabled while the machine
  816. * is running.
  817. */
  818. gpe_info.gpe_block = gpe_block;
  819. gpe_info.gpe_device = gpe_device;
  820. status =
  821. acpi_ns_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
  822. ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK,
  823. acpi_ev_match_prw_and_gpe, &gpe_info,
  824. NULL);
  825. }
  826. /*
  827. * Enable all GPEs in this block that have these attributes:
  828. * 1) are "runtime" or "run/wake" GPEs, and
  829. * 2) have a corresponding _Lxx or _Exx method
  830. *
  831. * Any other GPEs within this block must be enabled via the acpi_enable_gpe()
  832. * external interface.
  833. */
  834. wake_gpe_count = 0;
  835. gpe_enabled_count = 0;
  836. for (i = 0; i < gpe_block->register_count; i++) {
  837. for (j = 0; j < 8; j++) {
  838. /* Get the info block for this particular GPE */
  839. gpe_event_info =
  840. &gpe_block->
  841. event_info[(i * ACPI_GPE_REGISTER_WIDTH) + j];
  842. if (((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
  843. ACPI_GPE_DISPATCH_METHOD)
  844. && (gpe_event_info->flags & ACPI_GPE_TYPE_RUNTIME)) {
  845. gpe_enabled_count++;
  846. }
  847. if (gpe_event_info->flags & ACPI_GPE_TYPE_WAKE) {
  848. wake_gpe_count++;
  849. }
  850. }
  851. }
  852. ACPI_DEBUG_PRINT((ACPI_DB_INIT,
  853. "Found %u Wake, Enabled %u Runtime GPEs in this block\n",
  854. wake_gpe_count, gpe_enabled_count));
  855. /* Enable all valid runtime GPEs found above */
  856. status = acpi_hw_enable_runtime_gpe_block(NULL, gpe_block);
  857. if (ACPI_FAILURE(status)) {
  858. ACPI_ERROR((AE_INFO, "Could not enable GPEs in GpeBlock %p",
  859. gpe_block));
  860. }
  861. return_ACPI_STATUS(status);
  862. }
  863. /*******************************************************************************
  864. *
  865. * FUNCTION: acpi_ev_gpe_initialize
  866. *
  867. * PARAMETERS: None
  868. *
  869. * RETURN: Status
  870. *
  871. * DESCRIPTION: Initialize the GPE data structures
  872. *
  873. ******************************************************************************/
  874. acpi_status acpi_ev_gpe_initialize(void)
  875. {
  876. u32 register_count0 = 0;
  877. u32 register_count1 = 0;
  878. u32 gpe_number_max = 0;
  879. acpi_status status;
  880. ACPI_FUNCTION_TRACE(ev_gpe_initialize);
  881. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  882. if (ACPI_FAILURE(status)) {
  883. return_ACPI_STATUS(status);
  884. }
  885. /*
  886. * Initialize the GPE Block(s) defined in the FADT
  887. *
  888. * Why the GPE register block lengths are divided by 2: From the ACPI Spec,
  889. * section "General-Purpose Event Registers", we have:
  890. *
  891. * "Each register block contains two registers of equal length
  892. * GPEx_STS and GPEx_EN (where x is 0 or 1). The length of the
  893. * GPE0_STS and GPE0_EN registers is equal to half the GPE0_LEN
  894. * The length of the GPE1_STS and GPE1_EN registers is equal to
  895. * half the GPE1_LEN. If a generic register block is not supported
  896. * then its respective block pointer and block length values in the
  897. * FADT table contain zeros. The GPE0_LEN and GPE1_LEN do not need
  898. * to be the same size."
  899. */
  900. /*
  901. * Determine the maximum GPE number for this machine.
  902. *
  903. * Note: both GPE0 and GPE1 are optional, and either can exist without
  904. * the other.
  905. *
  906. * If EITHER the register length OR the block address are zero, then that
  907. * particular block is not supported.
  908. */
  909. if (acpi_gbl_FADT.gpe0_block_length &&
  910. acpi_gbl_FADT.xgpe0_block.address) {
  911. /* GPE block 0 exists (has both length and address > 0) */
  912. register_count0 = (u16) (acpi_gbl_FADT.gpe0_block_length / 2);
  913. gpe_number_max =
  914. (register_count0 * ACPI_GPE_REGISTER_WIDTH) - 1;
  915. /* Install GPE Block 0 */
  916. status = acpi_ev_create_gpe_block(acpi_gbl_fadt_gpe_device,
  917. &acpi_gbl_FADT.xgpe0_block,
  918. register_count0, 0,
  919. acpi_gbl_FADT.sci_interrupt,
  920. &acpi_gbl_gpe_fadt_blocks[0]);
  921. if (ACPI_FAILURE(status)) {
  922. ACPI_EXCEPTION((AE_INFO, status,
  923. "Could not create GPE Block 0"));
  924. }
  925. }
  926. if (acpi_gbl_FADT.gpe1_block_length &&
  927. acpi_gbl_FADT.xgpe1_block.address) {
  928. /* GPE block 1 exists (has both length and address > 0) */
  929. register_count1 = (u16) (acpi_gbl_FADT.gpe1_block_length / 2);
  930. /* Check for GPE0/GPE1 overlap (if both banks exist) */
  931. if ((register_count0) &&
  932. (gpe_number_max >= acpi_gbl_FADT.gpe1_base)) {
  933. ACPI_ERROR((AE_INFO,
  934. "GPE0 block (GPE 0 to %d) overlaps the GPE1 block (GPE %d to %d) - Ignoring GPE1",
  935. gpe_number_max, acpi_gbl_FADT.gpe1_base,
  936. acpi_gbl_FADT.gpe1_base +
  937. ((register_count1 *
  938. ACPI_GPE_REGISTER_WIDTH) - 1)));
  939. /* Ignore GPE1 block by setting the register count to zero */
  940. register_count1 = 0;
  941. } else {
  942. /* Install GPE Block 1 */
  943. status =
  944. acpi_ev_create_gpe_block(acpi_gbl_fadt_gpe_device,
  945. &acpi_gbl_FADT.xgpe1_block,
  946. register_count1,
  947. acpi_gbl_FADT.gpe1_base,
  948. acpi_gbl_FADT.
  949. sci_interrupt,
  950. &acpi_gbl_gpe_fadt_blocks
  951. [1]);
  952. if (ACPI_FAILURE(status)) {
  953. ACPI_EXCEPTION((AE_INFO, status,
  954. "Could not create GPE Block 1"));
  955. }
  956. /*
  957. * GPE0 and GPE1 do not have to be contiguous in the GPE number
  958. * space. However, GPE0 always starts at GPE number zero.
  959. */
  960. gpe_number_max = acpi_gbl_FADT.gpe1_base +
  961. ((register_count1 * ACPI_GPE_REGISTER_WIDTH) - 1);
  962. }
  963. }
  964. /* Exit if there are no GPE registers */
  965. if ((register_count0 + register_count1) == 0) {
  966. /* GPEs are not required by ACPI, this is OK */
  967. ACPI_DEBUG_PRINT((ACPI_DB_INIT,
  968. "There are no GPE blocks defined in the FADT\n"));
  969. status = AE_OK;
  970. goto cleanup;
  971. }
  972. /* Check for Max GPE number out-of-range */
  973. if (gpe_number_max > ACPI_GPE_MAX) {
  974. ACPI_ERROR((AE_INFO,
  975. "Maximum GPE number from FADT is too large: 0x%X",
  976. gpe_number_max));
  977. status = AE_BAD_VALUE;
  978. goto cleanup;
  979. }
  980. cleanup:
  981. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  982. return_ACPI_STATUS(AE_OK);
  983. }