evgpe.c 23 KB

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