evgpe.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843
  1. // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
  2. /******************************************************************************
  3. *
  4. * Module Name: evgpe - General Purpose Event handling and dispatch
  5. *
  6. * Copyright (C) 2000 - 2018, Intel Corp.
  7. *
  8. *****************************************************************************/
  9. #include <acpi/acpi.h>
  10. #include "accommon.h"
  11. #include "acevents.h"
  12. #include "acnamesp.h"
  13. #define _COMPONENT ACPI_EVENTS
  14. ACPI_MODULE_NAME("evgpe")
  15. #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
  16. /* Local prototypes */
  17. static void ACPI_SYSTEM_XFACE acpi_ev_asynch_execute_gpe_method(void *context);
  18. static void ACPI_SYSTEM_XFACE acpi_ev_asynch_enable_gpe(void *context);
  19. /*******************************************************************************
  20. *
  21. * FUNCTION: acpi_ev_update_gpe_enable_mask
  22. *
  23. * PARAMETERS: gpe_event_info - GPE to update
  24. *
  25. * RETURN: Status
  26. *
  27. * DESCRIPTION: Updates GPE register enable mask based upon whether there are
  28. * runtime references to this GPE
  29. *
  30. ******************************************************************************/
  31. acpi_status
  32. acpi_ev_update_gpe_enable_mask(struct acpi_gpe_event_info *gpe_event_info)
  33. {
  34. struct acpi_gpe_register_info *gpe_register_info;
  35. u32 register_bit;
  36. ACPI_FUNCTION_TRACE(ev_update_gpe_enable_mask);
  37. gpe_register_info = gpe_event_info->register_info;
  38. if (!gpe_register_info) {
  39. return_ACPI_STATUS(AE_NOT_EXIST);
  40. }
  41. register_bit = acpi_hw_get_gpe_register_bit(gpe_event_info);
  42. /* Clear the run bit up front */
  43. ACPI_CLEAR_BIT(gpe_register_info->enable_for_run, register_bit);
  44. /* Set the mask bit only if there are references to this GPE */
  45. if (gpe_event_info->runtime_count) {
  46. ACPI_SET_BIT(gpe_register_info->enable_for_run,
  47. (u8)register_bit);
  48. }
  49. gpe_register_info->enable_mask = gpe_register_info->enable_for_run;
  50. return_ACPI_STATUS(AE_OK);
  51. }
  52. /*******************************************************************************
  53. *
  54. * FUNCTION: acpi_ev_enable_gpe
  55. *
  56. * PARAMETERS: gpe_event_info - GPE to enable
  57. *
  58. * RETURN: Status
  59. *
  60. * DESCRIPTION: Enable a GPE.
  61. *
  62. ******************************************************************************/
  63. acpi_status acpi_ev_enable_gpe(struct acpi_gpe_event_info *gpe_event_info)
  64. {
  65. acpi_status status;
  66. ACPI_FUNCTION_TRACE(ev_enable_gpe);
  67. /* Enable the requested GPE */
  68. status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_ENABLE);
  69. return_ACPI_STATUS(status);
  70. }
  71. /*******************************************************************************
  72. *
  73. * FUNCTION: acpi_ev_mask_gpe
  74. *
  75. * PARAMETERS: gpe_event_info - GPE to be blocked/unblocked
  76. * is_masked - Whether the GPE is masked or not
  77. *
  78. * RETURN: Status
  79. *
  80. * DESCRIPTION: Unconditionally mask/unmask a GPE during runtime.
  81. *
  82. ******************************************************************************/
  83. acpi_status
  84. acpi_ev_mask_gpe(struct acpi_gpe_event_info *gpe_event_info, u8 is_masked)
  85. {
  86. struct acpi_gpe_register_info *gpe_register_info;
  87. u32 register_bit;
  88. ACPI_FUNCTION_TRACE(ev_mask_gpe);
  89. gpe_register_info = gpe_event_info->register_info;
  90. if (!gpe_register_info) {
  91. return_ACPI_STATUS(AE_NOT_EXIST);
  92. }
  93. register_bit = acpi_hw_get_gpe_register_bit(gpe_event_info);
  94. /* Perform the action */
  95. if (is_masked) {
  96. if (register_bit & gpe_register_info->mask_for_run) {
  97. return_ACPI_STATUS(AE_BAD_PARAMETER);
  98. }
  99. (void)acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_DISABLE);
  100. ACPI_SET_BIT(gpe_register_info->mask_for_run, (u8)register_bit);
  101. } else {
  102. if (!(register_bit & gpe_register_info->mask_for_run)) {
  103. return_ACPI_STATUS(AE_BAD_PARAMETER);
  104. }
  105. ACPI_CLEAR_BIT(gpe_register_info->mask_for_run,
  106. (u8)register_bit);
  107. if (gpe_event_info->runtime_count
  108. && !gpe_event_info->disable_for_dispatch) {
  109. (void)acpi_hw_low_set_gpe(gpe_event_info,
  110. ACPI_GPE_ENABLE);
  111. }
  112. }
  113. return_ACPI_STATUS(AE_OK);
  114. }
  115. /*******************************************************************************
  116. *
  117. * FUNCTION: acpi_ev_add_gpe_reference
  118. *
  119. * PARAMETERS: gpe_event_info - Add a reference to this GPE
  120. *
  121. * RETURN: Status
  122. *
  123. * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
  124. * hardware-enabled.
  125. *
  126. ******************************************************************************/
  127. acpi_status
  128. acpi_ev_add_gpe_reference(struct acpi_gpe_event_info *gpe_event_info)
  129. {
  130. acpi_status status = AE_OK;
  131. ACPI_FUNCTION_TRACE(ev_add_gpe_reference);
  132. if (gpe_event_info->runtime_count == ACPI_UINT8_MAX) {
  133. return_ACPI_STATUS(AE_LIMIT);
  134. }
  135. gpe_event_info->runtime_count++;
  136. if (gpe_event_info->runtime_count == 1) {
  137. /* Enable on first reference */
  138. status = acpi_ev_update_gpe_enable_mask(gpe_event_info);
  139. if (ACPI_SUCCESS(status)) {
  140. status = acpi_ev_enable_gpe(gpe_event_info);
  141. }
  142. if (ACPI_FAILURE(status)) {
  143. gpe_event_info->runtime_count--;
  144. }
  145. }
  146. return_ACPI_STATUS(status);
  147. }
  148. /*******************************************************************************
  149. *
  150. * FUNCTION: acpi_ev_remove_gpe_reference
  151. *
  152. * PARAMETERS: gpe_event_info - Remove a reference to this GPE
  153. *
  154. * RETURN: Status
  155. *
  156. * DESCRIPTION: Remove a reference to a GPE. When the last reference is
  157. * removed, the GPE is hardware-disabled.
  158. *
  159. ******************************************************************************/
  160. acpi_status
  161. acpi_ev_remove_gpe_reference(struct acpi_gpe_event_info *gpe_event_info)
  162. {
  163. acpi_status status = AE_OK;
  164. ACPI_FUNCTION_TRACE(ev_remove_gpe_reference);
  165. if (!gpe_event_info->runtime_count) {
  166. return_ACPI_STATUS(AE_LIMIT);
  167. }
  168. gpe_event_info->runtime_count--;
  169. if (!gpe_event_info->runtime_count) {
  170. /* Disable on last reference */
  171. status = acpi_ev_update_gpe_enable_mask(gpe_event_info);
  172. if (ACPI_SUCCESS(status)) {
  173. status =
  174. 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 =
  254. 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. struct acpi_gpe_block_info *gpe_block;
  278. struct acpi_namespace_node *gpe_device;
  279. struct acpi_gpe_register_info *gpe_register_info;
  280. struct acpi_gpe_event_info *gpe_event_info;
  281. u32 gpe_number;
  282. u32 int_status = ACPI_INTERRUPT_NOT_HANDLED;
  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. gpe_device = gpe_block->node;
  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. ACPI_DEBUG_PRINT((ACPI_DB_INTERRUPTS,
  315. "Ignore disabled registers for GPE %02X-%02X: "
  316. "RunEnable=%02X, WakeEnable=%02X\n",
  317. gpe_register_info->
  318. base_gpe_number,
  319. gpe_register_info->
  320. base_gpe_number +
  321. (ACPI_GPE_REGISTER_WIDTH - 1),
  322. gpe_register_info->
  323. enable_for_run,
  324. gpe_register_info->
  325. enable_for_wake));
  326. continue;
  327. }
  328. /* Now look at the individual GPEs in this byte register */
  329. for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
  330. /* Detect and dispatch one GPE bit */
  331. gpe_event_info =
  332. &gpe_block->
  333. event_info[((acpi_size)i *
  334. ACPI_GPE_REGISTER_WIDTH) + j];
  335. gpe_number =
  336. j + gpe_register_info->base_gpe_number;
  337. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  338. int_status |=
  339. acpi_ev_detect_gpe(gpe_device,
  340. gpe_event_info,
  341. gpe_number);
  342. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  343. }
  344. }
  345. gpe_block = gpe_block->next;
  346. }
  347. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  348. return (int_status);
  349. }
  350. /*******************************************************************************
  351. *
  352. * FUNCTION: acpi_ev_asynch_execute_gpe_method
  353. *
  354. * PARAMETERS: Context (gpe_event_info) - Info for this GPE
  355. *
  356. * RETURN: None
  357. *
  358. * DESCRIPTION: Perform the actual execution of a GPE control method. This
  359. * function is called from an invocation of acpi_os_execute and
  360. * therefore does NOT execute at interrupt level - so that
  361. * the control method itself is not executed in the context of
  362. * an interrupt handler.
  363. *
  364. ******************************************************************************/
  365. static void ACPI_SYSTEM_XFACE acpi_ev_asynch_execute_gpe_method(void *context)
  366. {
  367. struct acpi_gpe_event_info *gpe_event_info = context;
  368. acpi_status status = AE_OK;
  369. struct acpi_evaluate_info *info;
  370. struct acpi_gpe_notify_info *notify;
  371. ACPI_FUNCTION_TRACE(ev_asynch_execute_gpe_method);
  372. /* Do the correct dispatch - normal method or implicit notify */
  373. switch (ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags)) {
  374. case ACPI_GPE_DISPATCH_NOTIFY:
  375. /*
  376. * Implicit notify.
  377. * Dispatch a DEVICE_WAKE notify to the appropriate handler.
  378. * NOTE: the request is queued for execution after this method
  379. * completes. The notify handlers are NOT invoked synchronously
  380. * from this thread -- because handlers may in turn run other
  381. * control methods.
  382. *
  383. * June 2012: Expand implicit notify mechanism to support
  384. * notifies on multiple device objects.
  385. */
  386. notify = gpe_event_info->dispatch.notify_list;
  387. while (ACPI_SUCCESS(status) && notify) {
  388. status =
  389. acpi_ev_queue_notify_request(notify->device_node,
  390. ACPI_NOTIFY_DEVICE_WAKE);
  391. notify = notify->next;
  392. }
  393. break;
  394. case ACPI_GPE_DISPATCH_METHOD:
  395. /* Allocate the evaluation information block */
  396. info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
  397. if (!info) {
  398. status = AE_NO_MEMORY;
  399. } else {
  400. /*
  401. * Invoke the GPE Method (_Lxx, _Exx) i.e., evaluate the
  402. * _Lxx/_Exx control method that corresponds to this GPE
  403. */
  404. info->prefix_node =
  405. gpe_event_info->dispatch.method_node;
  406. info->flags = ACPI_IGNORE_RETURN_VALUE;
  407. status = acpi_ns_evaluate(info);
  408. ACPI_FREE(info);
  409. }
  410. if (ACPI_FAILURE(status)) {
  411. ACPI_EXCEPTION((AE_INFO, status,
  412. "while evaluating GPE method [%4.4s]",
  413. acpi_ut_get_node_name(gpe_event_info->
  414. dispatch.
  415. method_node)));
  416. }
  417. break;
  418. default:
  419. goto error_exit; /* Should never happen */
  420. }
  421. /* Defer enabling of GPE until all notify handlers are done */
  422. status = acpi_os_execute(OSL_NOTIFY_HANDLER,
  423. acpi_ev_asynch_enable_gpe, gpe_event_info);
  424. if (ACPI_SUCCESS(status)) {
  425. return_VOID;
  426. }
  427. error_exit:
  428. acpi_ev_asynch_enable_gpe(gpe_event_info);
  429. return_VOID;
  430. }
  431. /*******************************************************************************
  432. *
  433. * FUNCTION: acpi_ev_asynch_enable_gpe
  434. *
  435. * PARAMETERS: Context (gpe_event_info) - Info for this GPE
  436. * Callback from acpi_os_execute
  437. *
  438. * RETURN: None
  439. *
  440. * DESCRIPTION: Asynchronous clear/enable for GPE. This allows the GPE to
  441. * complete (i.e., finish execution of Notify)
  442. *
  443. ******************************************************************************/
  444. static void ACPI_SYSTEM_XFACE acpi_ev_asynch_enable_gpe(void *context)
  445. {
  446. struct acpi_gpe_event_info *gpe_event_info = context;
  447. acpi_cpu_flags flags;
  448. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  449. (void)acpi_ev_finish_gpe(gpe_event_info);
  450. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  451. return;
  452. }
  453. /*******************************************************************************
  454. *
  455. * FUNCTION: acpi_ev_finish_gpe
  456. *
  457. * PARAMETERS: gpe_event_info - Info for this GPE
  458. *
  459. * RETURN: Status
  460. *
  461. * DESCRIPTION: Clear/Enable a GPE. Common code that is used after execution
  462. * of a GPE method or a synchronous or asynchronous GPE handler.
  463. *
  464. ******************************************************************************/
  465. acpi_status acpi_ev_finish_gpe(struct acpi_gpe_event_info *gpe_event_info)
  466. {
  467. acpi_status status;
  468. if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
  469. ACPI_GPE_LEVEL_TRIGGERED) {
  470. /*
  471. * GPE is level-triggered, we clear the GPE status bit after
  472. * handling the event.
  473. */
  474. status = acpi_hw_clear_gpe(gpe_event_info);
  475. if (ACPI_FAILURE(status)) {
  476. return (status);
  477. }
  478. }
  479. /*
  480. * Enable this GPE, conditionally. This means that the GPE will
  481. * only be physically enabled if the enable_mask bit is set
  482. * in the event_info.
  483. */
  484. (void)acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_CONDITIONAL_ENABLE);
  485. gpe_event_info->disable_for_dispatch = FALSE;
  486. return (AE_OK);
  487. }
  488. /*******************************************************************************
  489. *
  490. * FUNCTION: acpi_ev_detect_gpe
  491. *
  492. * PARAMETERS: gpe_device - Device node. NULL for GPE0/GPE1
  493. * gpe_event_info - Info for this GPE
  494. * gpe_number - Number relative to the parent GPE block
  495. *
  496. * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
  497. *
  498. * DESCRIPTION: Detect and dispatch a General Purpose Event to either a function
  499. * (e.g. EC) or method (e.g. _Lxx/_Exx) handler.
  500. * NOTE: GPE is W1C, so it is possible to handle a single GPE from both
  501. * task and irq context in parallel as long as the process to
  502. * detect and mask the GPE is atomic.
  503. * However the atomicity of ACPI_GPE_DISPATCH_RAW_HANDLER is
  504. * dependent on the raw handler itself.
  505. *
  506. ******************************************************************************/
  507. u32
  508. acpi_ev_detect_gpe(struct acpi_namespace_node *gpe_device,
  509. struct acpi_gpe_event_info *gpe_event_info, u32 gpe_number)
  510. {
  511. u32 int_status = ACPI_INTERRUPT_NOT_HANDLED;
  512. u8 enabled_status_byte;
  513. u64 status_reg;
  514. u64 enable_reg;
  515. u32 register_bit;
  516. struct acpi_gpe_register_info *gpe_register_info;
  517. struct acpi_gpe_handler_info *gpe_handler_info;
  518. acpi_cpu_flags flags;
  519. acpi_status status;
  520. ACPI_FUNCTION_TRACE(ev_gpe_detect);
  521. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  522. if (!gpe_event_info) {
  523. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  524. if (!gpe_event_info)
  525. goto error_exit;
  526. }
  527. /* Get the info block for the entire GPE register */
  528. gpe_register_info = gpe_event_info->register_info;
  529. /* Get the register bitmask for this GPE */
  530. register_bit = acpi_hw_get_gpe_register_bit(gpe_event_info);
  531. /* GPE currently enabled (enable bit == 1)? */
  532. status = acpi_hw_read(&enable_reg, &gpe_register_info->enable_address);
  533. if (ACPI_FAILURE(status)) {
  534. goto error_exit;
  535. }
  536. /* GPE currently active (status bit == 1)? */
  537. status = acpi_hw_read(&status_reg, &gpe_register_info->status_address);
  538. if (ACPI_FAILURE(status)) {
  539. goto error_exit;
  540. }
  541. /* Check if there is anything active at all in this GPE */
  542. ACPI_DEBUG_PRINT((ACPI_DB_INTERRUPTS,
  543. "Read registers for GPE %02X: Status=%02X, Enable=%02X, "
  544. "RunEnable=%02X, WakeEnable=%02X\n",
  545. gpe_number,
  546. (u32)(status_reg & register_bit),
  547. (u32)(enable_reg & register_bit),
  548. gpe_register_info->enable_for_run,
  549. gpe_register_info->enable_for_wake));
  550. enabled_status_byte = (u8)(status_reg & enable_reg);
  551. if (!(enabled_status_byte & register_bit)) {
  552. goto error_exit;
  553. }
  554. /* Invoke global event handler if present */
  555. acpi_gpe_count++;
  556. if (acpi_gbl_global_event_handler) {
  557. acpi_gbl_global_event_handler(ACPI_EVENT_TYPE_GPE,
  558. gpe_device, gpe_number,
  559. acpi_gbl_global_event_handler_context);
  560. }
  561. /* Found an active GPE */
  562. if (ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) ==
  563. ACPI_GPE_DISPATCH_RAW_HANDLER) {
  564. /* Dispatch the event to a raw handler */
  565. gpe_handler_info = gpe_event_info->dispatch.handler;
  566. /*
  567. * There is no protection around the namespace node
  568. * and the GPE handler to ensure a safe destruction
  569. * because:
  570. * 1. The namespace node is expected to always
  571. * exist after loading a table.
  572. * 2. The GPE handler is expected to be flushed by
  573. * acpi_os_wait_events_complete() before the
  574. * destruction.
  575. */
  576. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  577. int_status |=
  578. gpe_handler_info->address(gpe_device, gpe_number,
  579. gpe_handler_info->context);
  580. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  581. } else {
  582. /* Dispatch the event to a standard handler or method. */
  583. int_status |= acpi_ev_gpe_dispatch(gpe_device,
  584. gpe_event_info, gpe_number);
  585. }
  586. error_exit:
  587. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  588. return (int_status);
  589. }
  590. /*******************************************************************************
  591. *
  592. * FUNCTION: acpi_ev_gpe_dispatch
  593. *
  594. * PARAMETERS: gpe_device - Device node. NULL for GPE0/GPE1
  595. * gpe_event_info - Info for this GPE
  596. * gpe_number - Number relative to the parent GPE block
  597. *
  598. * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
  599. *
  600. * DESCRIPTION: Dispatch a General Purpose Event to either a function (e.g. EC)
  601. * or method (e.g. _Lxx/_Exx) handler.
  602. *
  603. ******************************************************************************/
  604. u32
  605. acpi_ev_gpe_dispatch(struct acpi_namespace_node *gpe_device,
  606. struct acpi_gpe_event_info *gpe_event_info, u32 gpe_number)
  607. {
  608. acpi_status status;
  609. u32 return_value;
  610. ACPI_FUNCTION_TRACE(ev_gpe_dispatch);
  611. /*
  612. * Always disable the GPE so that it does not keep firing before
  613. * any asynchronous activity completes (either from the execution
  614. * of a GPE method or an asynchronous GPE handler.)
  615. *
  616. * If there is no handler or method to run, just disable the
  617. * GPE and leave it disabled permanently to prevent further such
  618. * pointless events from firing.
  619. */
  620. status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_DISABLE);
  621. if (ACPI_FAILURE(status)) {
  622. ACPI_EXCEPTION((AE_INFO, status,
  623. "Unable to disable GPE %02X", gpe_number));
  624. return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);
  625. }
  626. /*
  627. * If edge-triggered, clear the GPE status bit now. Note that
  628. * level-triggered events are cleared after the GPE is serviced.
  629. */
  630. if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
  631. ACPI_GPE_EDGE_TRIGGERED) {
  632. status = acpi_hw_clear_gpe(gpe_event_info);
  633. if (ACPI_FAILURE(status)) {
  634. ACPI_EXCEPTION((AE_INFO, status,
  635. "Unable to clear GPE %02X",
  636. gpe_number));
  637. (void)acpi_hw_low_set_gpe(gpe_event_info,
  638. ACPI_GPE_CONDITIONAL_ENABLE);
  639. return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);
  640. }
  641. }
  642. gpe_event_info->disable_for_dispatch = TRUE;
  643. /*
  644. * Dispatch the GPE to either an installed handler or the control
  645. * method associated with this GPE (_Lxx or _Exx). If a handler
  646. * exists, we invoke it and do not attempt to run the method.
  647. * If there is neither a handler nor a method, leave the GPE
  648. * disabled.
  649. */
  650. switch (ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags)) {
  651. case ACPI_GPE_DISPATCH_HANDLER:
  652. /* Invoke the installed handler (at interrupt level) */
  653. return_value =
  654. gpe_event_info->dispatch.handler->address(gpe_device,
  655. gpe_number,
  656. gpe_event_info->
  657. dispatch.handler->
  658. context);
  659. /* If requested, clear (if level-triggered) and reenable the GPE */
  660. if (return_value & ACPI_REENABLE_GPE) {
  661. (void)acpi_ev_finish_gpe(gpe_event_info);
  662. }
  663. break;
  664. case ACPI_GPE_DISPATCH_METHOD:
  665. case ACPI_GPE_DISPATCH_NOTIFY:
  666. /*
  667. * Execute the method associated with the GPE
  668. * NOTE: Level-triggered GPEs are cleared after the method completes.
  669. */
  670. status = acpi_os_execute(OSL_GPE_HANDLER,
  671. acpi_ev_asynch_execute_gpe_method,
  672. gpe_event_info);
  673. if (ACPI_FAILURE(status)) {
  674. ACPI_EXCEPTION((AE_INFO, status,
  675. "Unable to queue handler for GPE %02X - event disabled",
  676. gpe_number));
  677. }
  678. break;
  679. default:
  680. /*
  681. * No handler or method to run!
  682. * 03/2010: This case should no longer be possible. We will not allow
  683. * a GPE to be enabled if it has no handler or method.
  684. */
  685. ACPI_ERROR((AE_INFO,
  686. "No handler or method for GPE %02X, disabling event",
  687. gpe_number));
  688. break;
  689. }
  690. return_UINT32(ACPI_INTERRUPT_HANDLED);
  691. }
  692. #endif /* !ACPI_REDUCED_HARDWARE */