evgpe.c 21 KB

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