evgpe.c 24 KB

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