evgpe.c 20 KB

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