evgpe.c 21 KB

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