evgpe.c 22 KB

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