evgpe.c 24 KB

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