evgpe.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. /******************************************************************************
  2. *
  3. * Module Name: evgpe - General Purpose Event handling and dispatch
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2008, Intel Corp.
  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 "accommon.h"
  44. #include "acevents.h"
  45. #include "acnamesp.h"
  46. #define _COMPONENT ACPI_EVENTS
  47. ACPI_MODULE_NAME("evgpe")
  48. /* Local prototypes */
  49. static void ACPI_SYSTEM_XFACE acpi_ev_asynch_execute_gpe_method(void *context);
  50. /*******************************************************************************
  51. *
  52. * FUNCTION: acpi_ev_set_gpe_type
  53. *
  54. * PARAMETERS: gpe_event_info - GPE to set
  55. * Type - New type
  56. *
  57. * RETURN: Status
  58. *
  59. * DESCRIPTION: Sets the new type for the GPE (wake, run, or wake/run)
  60. *
  61. ******************************************************************************/
  62. acpi_status
  63. acpi_ev_set_gpe_type(struct acpi_gpe_event_info *gpe_event_info, u8 type)
  64. {
  65. acpi_status status;
  66. ACPI_FUNCTION_TRACE(ev_set_gpe_type);
  67. /* Validate type and update register enable masks */
  68. switch (type) {
  69. case ACPI_GPE_TYPE_WAKE:
  70. case ACPI_GPE_TYPE_RUNTIME:
  71. case ACPI_GPE_TYPE_WAKE_RUN:
  72. break;
  73. default:
  74. return_ACPI_STATUS(AE_BAD_PARAMETER);
  75. }
  76. /* Disable the GPE if currently enabled */
  77. status = acpi_ev_disable_gpe(gpe_event_info);
  78. /* Clear the type bits and insert the new Type */
  79. gpe_event_info->flags &= ~ACPI_GPE_TYPE_MASK;
  80. gpe_event_info->flags |= type;
  81. return_ACPI_STATUS(status);
  82. }
  83. /*******************************************************************************
  84. *
  85. * FUNCTION: acpi_ev_update_gpe_enable_masks
  86. *
  87. * PARAMETERS: gpe_event_info - GPE to update
  88. * Type - What to do: ACPI_GPE_DISABLE or
  89. * ACPI_GPE_ENABLE
  90. *
  91. * RETURN: Status
  92. *
  93. * DESCRIPTION: Updates GPE register enable masks based on the GPE type
  94. *
  95. ******************************************************************************/
  96. acpi_status
  97. acpi_ev_update_gpe_enable_masks(struct acpi_gpe_event_info *gpe_event_info,
  98. u8 type)
  99. {
  100. struct acpi_gpe_register_info *gpe_register_info;
  101. u8 register_bit;
  102. ACPI_FUNCTION_TRACE(ev_update_gpe_enable_masks);
  103. gpe_register_info = gpe_event_info->register_info;
  104. if (!gpe_register_info) {
  105. return_ACPI_STATUS(AE_NOT_EXIST);
  106. }
  107. register_bit = (u8)
  108. (1 <<
  109. (gpe_event_info->gpe_number - gpe_register_info->base_gpe_number));
  110. /* 1) Disable case. Simply clear all enable bits */
  111. if (type == ACPI_GPE_DISABLE) {
  112. ACPI_CLEAR_BIT(gpe_register_info->enable_for_wake,
  113. register_bit);
  114. ACPI_CLEAR_BIT(gpe_register_info->enable_for_run, register_bit);
  115. return_ACPI_STATUS(AE_OK);
  116. }
  117. /* 2) Enable case. Set/Clear the appropriate enable bits */
  118. switch (gpe_event_info->flags & ACPI_GPE_TYPE_MASK) {
  119. case ACPI_GPE_TYPE_WAKE:
  120. ACPI_SET_BIT(gpe_register_info->enable_for_wake, register_bit);
  121. ACPI_CLEAR_BIT(gpe_register_info->enable_for_run, register_bit);
  122. break;
  123. case ACPI_GPE_TYPE_RUNTIME:
  124. ACPI_CLEAR_BIT(gpe_register_info->enable_for_wake,
  125. register_bit);
  126. ACPI_SET_BIT(gpe_register_info->enable_for_run, register_bit);
  127. break;
  128. case ACPI_GPE_TYPE_WAKE_RUN:
  129. ACPI_SET_BIT(gpe_register_info->enable_for_wake, register_bit);
  130. ACPI_SET_BIT(gpe_register_info->enable_for_run, register_bit);
  131. break;
  132. default:
  133. return_ACPI_STATUS(AE_BAD_PARAMETER);
  134. }
  135. return_ACPI_STATUS(AE_OK);
  136. }
  137. /*******************************************************************************
  138. *
  139. * FUNCTION: acpi_ev_enable_gpe
  140. *
  141. * PARAMETERS: gpe_event_info - GPE to enable
  142. * write_to_hardware - Enable now, or just mark data structs
  143. * (WAKE GPEs should be deferred)
  144. *
  145. * RETURN: Status
  146. *
  147. * DESCRIPTION: Enable a GPE based on the GPE type
  148. *
  149. ******************************************************************************/
  150. acpi_status
  151. acpi_ev_enable_gpe(struct acpi_gpe_event_info *gpe_event_info,
  152. u8 write_to_hardware)
  153. {
  154. acpi_status status;
  155. ACPI_FUNCTION_TRACE(ev_enable_gpe);
  156. /* Make sure HW enable masks are updated */
  157. status =
  158. acpi_ev_update_gpe_enable_masks(gpe_event_info, ACPI_GPE_ENABLE);
  159. if (ACPI_FAILURE(status)) {
  160. return_ACPI_STATUS(status);
  161. }
  162. /* Mark wake-enabled or HW enable, or both */
  163. switch (gpe_event_info->flags & ACPI_GPE_TYPE_MASK) {
  164. case ACPI_GPE_TYPE_WAKE:
  165. ACPI_SET_BIT(gpe_event_info->flags, ACPI_GPE_WAKE_ENABLED);
  166. break;
  167. case ACPI_GPE_TYPE_WAKE_RUN:
  168. ACPI_SET_BIT(gpe_event_info->flags, ACPI_GPE_WAKE_ENABLED);
  169. /*lint -fallthrough */
  170. case ACPI_GPE_TYPE_RUNTIME:
  171. ACPI_SET_BIT(gpe_event_info->flags, ACPI_GPE_RUN_ENABLED);
  172. if (write_to_hardware) {
  173. /* Clear the GPE (of stale events), then enable it */
  174. status = acpi_hw_clear_gpe(gpe_event_info);
  175. if (ACPI_FAILURE(status)) {
  176. return_ACPI_STATUS(status);
  177. }
  178. /* Enable the requested runtime GPE */
  179. status = acpi_hw_write_gpe_enable_reg(gpe_event_info);
  180. }
  181. break;
  182. default:
  183. return_ACPI_STATUS(AE_BAD_PARAMETER);
  184. }
  185. return_ACPI_STATUS(AE_OK);
  186. }
  187. /*******************************************************************************
  188. *
  189. * FUNCTION: acpi_ev_disable_gpe
  190. *
  191. * PARAMETERS: gpe_event_info - GPE to disable
  192. *
  193. * RETURN: Status
  194. *
  195. * DESCRIPTION: Disable a GPE based on the GPE type
  196. *
  197. ******************************************************************************/
  198. acpi_status acpi_ev_disable_gpe(struct acpi_gpe_event_info *gpe_event_info)
  199. {
  200. acpi_status status;
  201. ACPI_FUNCTION_TRACE(ev_disable_gpe);
  202. /* Make sure HW enable masks are updated */
  203. status =
  204. acpi_ev_update_gpe_enable_masks(gpe_event_info, ACPI_GPE_DISABLE);
  205. if (ACPI_FAILURE(status)) {
  206. return_ACPI_STATUS(status);
  207. }
  208. /* Clear the appropriate enabled flags for this GPE */
  209. switch (gpe_event_info->flags & ACPI_GPE_TYPE_MASK) {
  210. case ACPI_GPE_TYPE_WAKE:
  211. ACPI_CLEAR_BIT(gpe_event_info->flags, ACPI_GPE_WAKE_ENABLED);
  212. break;
  213. case ACPI_GPE_TYPE_WAKE_RUN:
  214. ACPI_CLEAR_BIT(gpe_event_info->flags, ACPI_GPE_WAKE_ENABLED);
  215. /* fallthrough */
  216. case ACPI_GPE_TYPE_RUNTIME:
  217. /* Disable the requested runtime GPE */
  218. ACPI_CLEAR_BIT(gpe_event_info->flags, ACPI_GPE_RUN_ENABLED);
  219. break;
  220. default:
  221. break;
  222. }
  223. /*
  224. * Even if we don't know the GPE type, make sure that we always
  225. * disable it. low_disable_gpe will just clear the enable bit for this
  226. * GPE and write it. It will not write out the current GPE enable mask,
  227. * since this may inadvertently enable GPEs too early, if a rogue GPE has
  228. * come in during ACPICA initialization - possibly as a result of AML or
  229. * other code that has enabled the GPE.
  230. */
  231. status = acpi_hw_low_disable_gpe(gpe_event_info);
  232. return_ACPI_STATUS(status);
  233. }
  234. /*******************************************************************************
  235. *
  236. * FUNCTION: acpi_ev_get_gpe_event_info
  237. *
  238. * PARAMETERS: gpe_device - Device node. NULL for GPE0/GPE1
  239. * gpe_number - Raw GPE number
  240. *
  241. * RETURN: A GPE event_info struct. NULL if not a valid GPE
  242. *
  243. * DESCRIPTION: Returns the event_info struct associated with this GPE.
  244. * Validates the gpe_block and the gpe_number
  245. *
  246. * Should be called only when the GPE lists are semaphore locked
  247. * and not subject to change.
  248. *
  249. ******************************************************************************/
  250. struct acpi_gpe_event_info *acpi_ev_get_gpe_event_info(acpi_handle gpe_device,
  251. u32 gpe_number)
  252. {
  253. union acpi_operand_object *obj_desc;
  254. struct acpi_gpe_block_info *gpe_block;
  255. u32 i;
  256. ACPI_FUNCTION_ENTRY();
  257. /* A NULL gpe_block means use the FADT-defined GPE block(s) */
  258. if (!gpe_device) {
  259. /* Examine GPE Block 0 and 1 (These blocks are permanent) */
  260. for (i = 0; i < ACPI_MAX_GPE_BLOCKS; i++) {
  261. gpe_block = acpi_gbl_gpe_fadt_blocks[i];
  262. if (gpe_block) {
  263. if ((gpe_number >= gpe_block->block_base_number)
  264. && (gpe_number <
  265. gpe_block->block_base_number +
  266. (gpe_block->register_count * 8))) {
  267. return (&gpe_block->
  268. event_info[gpe_number -
  269. gpe_block->
  270. block_base_number]);
  271. }
  272. }
  273. }
  274. /* The gpe_number was not in the range of either FADT GPE block */
  275. return (NULL);
  276. }
  277. /* A Non-NULL gpe_device means this is a GPE Block Device */
  278. obj_desc = acpi_ns_get_attached_object((struct acpi_namespace_node *)
  279. gpe_device);
  280. if (!obj_desc || !obj_desc->device.gpe_block) {
  281. return (NULL);
  282. }
  283. gpe_block = obj_desc->device.gpe_block;
  284. if ((gpe_number >= gpe_block->block_base_number) &&
  285. (gpe_number <
  286. gpe_block->block_base_number + (gpe_block->register_count * 8))) {
  287. return (&gpe_block->
  288. event_info[gpe_number - gpe_block->block_base_number]);
  289. }
  290. return (NULL);
  291. }
  292. /*******************************************************************************
  293. *
  294. * FUNCTION: acpi_ev_gpe_detect
  295. *
  296. * PARAMETERS: gpe_xrupt_list - Interrupt block for this interrupt.
  297. * Can have multiple GPE blocks attached.
  298. *
  299. * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
  300. *
  301. * DESCRIPTION: Detect if any GP events have occurred. This function is
  302. * executed at interrupt level.
  303. *
  304. ******************************************************************************/
  305. u32 acpi_ev_gpe_detect(struct acpi_gpe_xrupt_info * gpe_xrupt_list)
  306. {
  307. acpi_status status;
  308. struct acpi_gpe_block_info *gpe_block;
  309. struct acpi_gpe_register_info *gpe_register_info;
  310. u32 int_status = ACPI_INTERRUPT_NOT_HANDLED;
  311. u8 enabled_status_byte;
  312. u32 status_reg;
  313. u32 enable_reg;
  314. acpi_cpu_flags flags;
  315. u32 i;
  316. u32 j;
  317. ACPI_FUNCTION_NAME(ev_gpe_detect);
  318. /* Check for the case where there are no GPEs */
  319. if (!gpe_xrupt_list) {
  320. return (int_status);
  321. }
  322. /*
  323. * We need to obtain the GPE lock for both the data structs and registers
  324. * Note: Not necessary to obtain the hardware lock, since the GPE
  325. * registers are owned by the gpe_lock.
  326. */
  327. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  328. /* Examine all GPE blocks attached to this interrupt level */
  329. gpe_block = gpe_xrupt_list->gpe_block_list_head;
  330. while (gpe_block) {
  331. /*
  332. * Read all of the 8-bit GPE status and enable registers in this GPE
  333. * block, saving all of them. Find all currently active GP events.
  334. */
  335. for (i = 0; i < gpe_block->register_count; i++) {
  336. /* Get the next status/enable pair */
  337. gpe_register_info = &gpe_block->register_info[i];
  338. /* Read the Status Register */
  339. status =
  340. acpi_read(&status_reg,
  341. &gpe_register_info->status_address);
  342. if (ACPI_FAILURE(status)) {
  343. goto unlock_and_exit;
  344. }
  345. /* Read the Enable Register */
  346. status =
  347. acpi_read(&enable_reg,
  348. &gpe_register_info->enable_address);
  349. if (ACPI_FAILURE(status)) {
  350. goto unlock_and_exit;
  351. }
  352. ACPI_DEBUG_PRINT((ACPI_DB_INTERRUPTS,
  353. "Read GPE Register at GPE%X: Status=%02X, Enable=%02X\n",
  354. gpe_register_info->base_gpe_number,
  355. status_reg, enable_reg));
  356. /* Check if there is anything active at all in this register */
  357. enabled_status_byte = (u8) (status_reg & enable_reg);
  358. if (!enabled_status_byte) {
  359. /* No active GPEs in this register, move on */
  360. continue;
  361. }
  362. /* Now look at the individual GPEs in this byte register */
  363. for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
  364. /* Examine one GPE bit */
  365. if (enabled_status_byte & (1 << j)) {
  366. /*
  367. * Found an active GPE. Dispatch the event to a handler
  368. * or method.
  369. */
  370. int_status |=
  371. acpi_ev_gpe_dispatch(&gpe_block->
  372. event_info[((acpi_size) i * ACPI_GPE_REGISTER_WIDTH) + j], j + gpe_register_info->base_gpe_number);
  373. }
  374. }
  375. }
  376. gpe_block = gpe_block->next;
  377. }
  378. unlock_and_exit:
  379. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  380. return (int_status);
  381. }
  382. /*******************************************************************************
  383. *
  384. * FUNCTION: acpi_ev_asynch_execute_gpe_method
  385. *
  386. * PARAMETERS: Context (gpe_event_info) - Info for this GPE
  387. *
  388. * RETURN: None
  389. *
  390. * DESCRIPTION: Perform the actual execution of a GPE control method. This
  391. * function is called from an invocation of acpi_os_execute and
  392. * therefore does NOT execute at interrupt level - so that
  393. * the control method itself is not executed in the context of
  394. * an interrupt handler.
  395. *
  396. ******************************************************************************/
  397. static void acpi_ev_asynch_enable_gpe(void *context);
  398. static void ACPI_SYSTEM_XFACE acpi_ev_asynch_execute_gpe_method(void *context)
  399. {
  400. struct acpi_gpe_event_info *gpe_event_info = (void *)context;
  401. acpi_status status;
  402. struct acpi_gpe_event_info local_gpe_event_info;
  403. struct acpi_evaluate_info *info;
  404. ACPI_FUNCTION_TRACE(ev_asynch_execute_gpe_method);
  405. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  406. if (ACPI_FAILURE(status)) {
  407. return_VOID;
  408. }
  409. /* Must revalidate the gpe_number/gpe_block */
  410. if (!acpi_ev_valid_gpe_event(gpe_event_info)) {
  411. status = acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  412. return_VOID;
  413. }
  414. /* Set the GPE flags for return to enabled state */
  415. (void)acpi_ev_enable_gpe(gpe_event_info, FALSE);
  416. /*
  417. * Take a snapshot of the GPE info for this level - we copy the info to
  418. * prevent a race condition with remove_handler/remove_block.
  419. */
  420. ACPI_MEMCPY(&local_gpe_event_info, gpe_event_info,
  421. sizeof(struct acpi_gpe_event_info));
  422. status = acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  423. if (ACPI_FAILURE(status)) {
  424. return_VOID;
  425. }
  426. /*
  427. * Must check for control method type dispatch one more time to avoid a
  428. * race with ev_gpe_install_handler
  429. */
  430. if ((local_gpe_event_info.flags & ACPI_GPE_DISPATCH_MASK) ==
  431. ACPI_GPE_DISPATCH_METHOD) {
  432. /* Allocate the evaluation information block */
  433. info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
  434. if (!info) {
  435. status = AE_NO_MEMORY;
  436. } else {
  437. /*
  438. * Invoke the GPE Method (_Lxx, _Exx) i.e., evaluate the _Lxx/_Exx
  439. * control method that corresponds to this GPE
  440. */
  441. info->prefix_node =
  442. local_gpe_event_info.dispatch.method_node;
  443. info->flags = ACPI_IGNORE_RETURN_VALUE;
  444. status = acpi_ns_evaluate(info);
  445. ACPI_FREE(info);
  446. }
  447. if (ACPI_FAILURE(status)) {
  448. ACPI_EXCEPTION((AE_INFO, status,
  449. "while evaluating GPE method [%4.4s]",
  450. acpi_ut_get_node_name
  451. (local_gpe_event_info.dispatch.
  452. method_node)));
  453. }
  454. }
  455. /* Defer enabling of GPE until all notify handlers are done */
  456. acpi_os_execute(OSL_NOTIFY_HANDLER, acpi_ev_asynch_enable_gpe,
  457. gpe_event_info);
  458. return_VOID;
  459. }
  460. static void acpi_ev_asynch_enable_gpe(void *context)
  461. {
  462. struct acpi_gpe_event_info *gpe_event_info = context;
  463. acpi_status status;
  464. if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
  465. ACPI_GPE_LEVEL_TRIGGERED) {
  466. /*
  467. * GPE is level-triggered, we clear the GPE status bit after handling
  468. * the event.
  469. */
  470. status = acpi_hw_clear_gpe(gpe_event_info);
  471. if (ACPI_FAILURE(status)) {
  472. return_VOID;
  473. }
  474. }
  475. /* Enable this GPE */
  476. (void)acpi_hw_write_gpe_enable_reg(gpe_event_info);
  477. return_VOID;
  478. }
  479. /*******************************************************************************
  480. *
  481. * FUNCTION: acpi_ev_gpe_dispatch
  482. *
  483. * PARAMETERS: gpe_event_info - Info for this GPE
  484. * gpe_number - Number relative to the parent GPE block
  485. *
  486. * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
  487. *
  488. * DESCRIPTION: Dispatch a General Purpose Event to either a function (e.g. EC)
  489. * or method (e.g. _Lxx/_Exx) handler.
  490. *
  491. * This function executes at interrupt level.
  492. *
  493. ******************************************************************************/
  494. u32
  495. acpi_ev_gpe_dispatch(struct acpi_gpe_event_info *gpe_event_info, u32 gpe_number)
  496. {
  497. acpi_status status;
  498. ACPI_FUNCTION_TRACE(ev_gpe_dispatch);
  499. acpi_os_gpe_count(gpe_number);
  500. /*
  501. * If edge-triggered, clear the GPE status bit now. Note that
  502. * level-triggered events are cleared after the GPE is serviced.
  503. */
  504. if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
  505. ACPI_GPE_EDGE_TRIGGERED) {
  506. status = acpi_hw_clear_gpe(gpe_event_info);
  507. if (ACPI_FAILURE(status)) {
  508. ACPI_EXCEPTION((AE_INFO, status,
  509. "Unable to clear GPE[%2X]",
  510. gpe_number));
  511. return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);
  512. }
  513. }
  514. /*
  515. * Dispatch the GPE to either an installed handler, or the control method
  516. * associated with this GPE (_Lxx or _Exx). If a handler exists, we invoke
  517. * it and do not attempt to run the method. If there is neither a handler
  518. * nor a method, we disable this GPE to prevent further such pointless
  519. * events from firing.
  520. */
  521. switch (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) {
  522. case ACPI_GPE_DISPATCH_HANDLER:
  523. /*
  524. * Invoke the installed handler (at interrupt level)
  525. * Ignore return status for now.
  526. * TBD: leave GPE disabled on error?
  527. */
  528. (void)gpe_event_info->dispatch.handler->address(gpe_event_info->
  529. dispatch.
  530. handler->
  531. context);
  532. /* It is now safe to clear level-triggered events. */
  533. if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
  534. ACPI_GPE_LEVEL_TRIGGERED) {
  535. status = acpi_hw_clear_gpe(gpe_event_info);
  536. if (ACPI_FAILURE(status)) {
  537. ACPI_EXCEPTION((AE_INFO, status,
  538. "Unable to clear GPE[%2X]",
  539. gpe_number));
  540. return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);
  541. }
  542. }
  543. break;
  544. case ACPI_GPE_DISPATCH_METHOD:
  545. /*
  546. * Disable the GPE, so it doesn't keep firing before the method has a
  547. * chance to run (it runs asynchronously with interrupts enabled).
  548. */
  549. status = acpi_ev_disable_gpe(gpe_event_info);
  550. if (ACPI_FAILURE(status)) {
  551. ACPI_EXCEPTION((AE_INFO, status,
  552. "Unable to disable GPE[%2X]",
  553. gpe_number));
  554. return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);
  555. }
  556. /*
  557. * Execute the method associated with the GPE
  558. * NOTE: Level-triggered GPEs are cleared after the method completes.
  559. */
  560. status = acpi_os_execute(OSL_GPE_HANDLER,
  561. acpi_ev_asynch_execute_gpe_method,
  562. gpe_event_info);
  563. if (ACPI_FAILURE(status)) {
  564. ACPI_EXCEPTION((AE_INFO, status,
  565. "Unable to queue handler for GPE[%2X] - event disabled",
  566. gpe_number));
  567. }
  568. break;
  569. default:
  570. /* No handler or method to run! */
  571. ACPI_ERROR((AE_INFO,
  572. "No handler or method for GPE[%2X], disabling event",
  573. gpe_number));
  574. /*
  575. * Disable the GPE. The GPE will remain disabled until the ACPICA
  576. * Core Subsystem is restarted, or a handler is installed.
  577. */
  578. status = acpi_ev_disable_gpe(gpe_event_info);
  579. if (ACPI_FAILURE(status)) {
  580. ACPI_EXCEPTION((AE_INFO, status,
  581. "Unable to disable GPE[%2X]",
  582. gpe_number));
  583. return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);
  584. }
  585. break;
  586. }
  587. return_UINT32(ACPI_INTERRUPT_HANDLED);
  588. }