evgpe.c 22 KB

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