evgpe.c 22 KB

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