evgpe.c 22 KB

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