evgpe.c 20 KB

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