evxfgpe.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988
  1. // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
  2. /******************************************************************************
  3. *
  4. * Module Name: evxfgpe - External Interfaces for General Purpose Events (GPEs)
  5. *
  6. * Copyright (C) 2000 - 2018, Intel Corp.
  7. *
  8. *****************************************************************************/
  9. #define EXPORT_ACPI_INTERFACES
  10. #include <acpi/acpi.h>
  11. #include "accommon.h"
  12. #include "acevents.h"
  13. #include "acnamesp.h"
  14. #define _COMPONENT ACPI_EVENTS
  15. ACPI_MODULE_NAME("evxfgpe")
  16. #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
  17. /*******************************************************************************
  18. *
  19. * FUNCTION: acpi_update_all_gpes
  20. *
  21. * PARAMETERS: None
  22. *
  23. * RETURN: Status
  24. *
  25. * DESCRIPTION: Complete GPE initialization and enable all GPEs that have
  26. * associated _Lxx or _Exx methods and are not pointed to by any
  27. * device _PRW methods (this indicates that these GPEs are
  28. * generally intended for system or device wakeup. Such GPEs
  29. * have to be enabled directly when the devices whose _PRW
  30. * methods point to them are set up for wakeup signaling.)
  31. *
  32. * NOTE: Should be called after any GPEs are added to the system. Primarily,
  33. * after the system _PRW methods have been run, but also after a GPE Block
  34. * Device has been added or if any new GPE methods have been added via a
  35. * dynamic table load.
  36. *
  37. ******************************************************************************/
  38. acpi_status acpi_update_all_gpes(void)
  39. {
  40. acpi_status status;
  41. u8 is_polling_needed = FALSE;
  42. ACPI_FUNCTION_TRACE(acpi_update_all_gpes);
  43. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  44. if (ACPI_FAILURE(status)) {
  45. return_ACPI_STATUS(status);
  46. }
  47. if (acpi_gbl_all_gpes_initialized) {
  48. goto unlock_and_exit;
  49. }
  50. status = acpi_ev_walk_gpe_list(acpi_ev_initialize_gpe_block,
  51. &is_polling_needed);
  52. if (ACPI_SUCCESS(status)) {
  53. acpi_gbl_all_gpes_initialized = TRUE;
  54. }
  55. unlock_and_exit:
  56. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  57. if (is_polling_needed && acpi_gbl_all_gpes_initialized) {
  58. /* Poll GPEs to handle already triggered events */
  59. acpi_ev_gpe_detect(acpi_gbl_gpe_xrupt_list_head);
  60. }
  61. return_ACPI_STATUS(status);
  62. }
  63. ACPI_EXPORT_SYMBOL(acpi_update_all_gpes)
  64. /*******************************************************************************
  65. *
  66. * FUNCTION: acpi_enable_gpe
  67. *
  68. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  69. * gpe_number - GPE level within the GPE block
  70. *
  71. * RETURN: Status
  72. *
  73. * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
  74. * hardware-enabled.
  75. *
  76. ******************************************************************************/
  77. acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number)
  78. {
  79. acpi_status status = AE_BAD_PARAMETER;
  80. struct acpi_gpe_event_info *gpe_event_info;
  81. acpi_cpu_flags flags;
  82. ACPI_FUNCTION_TRACE(acpi_enable_gpe);
  83. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  84. /*
  85. * Ensure that we have a valid GPE number and that there is some way
  86. * of handling the GPE (handler or a GPE method). In other words, we
  87. * won't allow a valid GPE to be enabled if there is no way to handle it.
  88. */
  89. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  90. if (gpe_event_info) {
  91. if (ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) !=
  92. ACPI_GPE_DISPATCH_NONE) {
  93. status = acpi_ev_add_gpe_reference(gpe_event_info);
  94. if (ACPI_SUCCESS(status) &&
  95. ACPI_GPE_IS_POLLING_NEEDED(gpe_event_info)) {
  96. /* Poll edge-triggered GPEs to handle existing events */
  97. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  98. (void)acpi_ev_detect_gpe(gpe_device,
  99. gpe_event_info,
  100. gpe_number);
  101. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  102. }
  103. } else {
  104. status = AE_NO_HANDLER;
  105. }
  106. }
  107. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  108. return_ACPI_STATUS(status);
  109. }
  110. ACPI_EXPORT_SYMBOL(acpi_enable_gpe)
  111. /*******************************************************************************
  112. *
  113. * FUNCTION: acpi_disable_gpe
  114. *
  115. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  116. * gpe_number - GPE level within the GPE block
  117. *
  118. * RETURN: Status
  119. *
  120. * DESCRIPTION: Remove a reference to a GPE. When the last reference is
  121. * removed, only then is the GPE disabled (for runtime GPEs), or
  122. * the GPE mask bit disabled (for wake GPEs)
  123. *
  124. ******************************************************************************/
  125. acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number)
  126. {
  127. acpi_status status = AE_BAD_PARAMETER;
  128. struct acpi_gpe_event_info *gpe_event_info;
  129. acpi_cpu_flags flags;
  130. ACPI_FUNCTION_TRACE(acpi_disable_gpe);
  131. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  132. /* Ensure that we have a valid GPE number */
  133. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  134. if (gpe_event_info) {
  135. status = acpi_ev_remove_gpe_reference(gpe_event_info) ;
  136. }
  137. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  138. return_ACPI_STATUS(status);
  139. }
  140. ACPI_EXPORT_SYMBOL(acpi_disable_gpe)
  141. /*******************************************************************************
  142. *
  143. * FUNCTION: acpi_set_gpe
  144. *
  145. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  146. * gpe_number - GPE level within the GPE block
  147. * action - ACPI_GPE_ENABLE or ACPI_GPE_DISABLE
  148. *
  149. * RETURN: Status
  150. *
  151. * DESCRIPTION: Enable or disable an individual GPE. This function bypasses
  152. * the reference count mechanism used in the acpi_enable_gpe(),
  153. * acpi_disable_gpe() interfaces.
  154. * This API is typically used by the GPE raw handler mode driver
  155. * to switch between the polling mode and the interrupt mode after
  156. * the driver has enabled the GPE.
  157. * The APIs should be invoked in this order:
  158. * acpi_enable_gpe() <- Ensure the reference count > 0
  159. * acpi_set_gpe(ACPI_GPE_DISABLE) <- Enter polling mode
  160. * acpi_set_gpe(ACPI_GPE_ENABLE) <- Leave polling mode
  161. * acpi_disable_gpe() <- Decrease the reference count
  162. *
  163. * Note: If a GPE is shared by 2 silicon components, then both the drivers
  164. * should support GPE polling mode or disabling the GPE for long period
  165. * for one driver may break the other. So use it with care since all
  166. * firmware _Lxx/_Exx handlers currently rely on the GPE interrupt mode.
  167. *
  168. ******************************************************************************/
  169. acpi_status acpi_set_gpe(acpi_handle gpe_device, u32 gpe_number, u8 action)
  170. {
  171. struct acpi_gpe_event_info *gpe_event_info;
  172. acpi_status status;
  173. acpi_cpu_flags flags;
  174. ACPI_FUNCTION_TRACE(acpi_set_gpe);
  175. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  176. /* Ensure that we have a valid GPE number */
  177. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  178. if (!gpe_event_info) {
  179. status = AE_BAD_PARAMETER;
  180. goto unlock_and_exit;
  181. }
  182. /* Perform the action */
  183. switch (action) {
  184. case ACPI_GPE_ENABLE:
  185. status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_ENABLE);
  186. gpe_event_info->disable_for_dispatch = FALSE;
  187. break;
  188. case ACPI_GPE_DISABLE:
  189. status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_DISABLE);
  190. gpe_event_info->disable_for_dispatch = TRUE;
  191. break;
  192. default:
  193. status = AE_BAD_PARAMETER;
  194. break;
  195. }
  196. unlock_and_exit:
  197. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  198. return_ACPI_STATUS(status);
  199. }
  200. ACPI_EXPORT_SYMBOL(acpi_set_gpe)
  201. /*******************************************************************************
  202. *
  203. * FUNCTION: acpi_mask_gpe
  204. *
  205. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  206. * gpe_number - GPE level within the GPE block
  207. * is_masked - Whether the GPE is masked or not
  208. *
  209. * RETURN: Status
  210. *
  211. * DESCRIPTION: Unconditionally mask/unmask the an individual GPE, ex., to
  212. * prevent a GPE flooding.
  213. *
  214. ******************************************************************************/
  215. acpi_status acpi_mask_gpe(acpi_handle gpe_device, u32 gpe_number, u8 is_masked)
  216. {
  217. struct acpi_gpe_event_info *gpe_event_info;
  218. acpi_status status;
  219. acpi_cpu_flags flags;
  220. ACPI_FUNCTION_TRACE(acpi_mask_gpe);
  221. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  222. /* Ensure that we have a valid GPE number */
  223. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  224. if (!gpe_event_info) {
  225. status = AE_BAD_PARAMETER;
  226. goto unlock_and_exit;
  227. }
  228. status = acpi_ev_mask_gpe(gpe_event_info, is_masked);
  229. unlock_and_exit:
  230. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  231. return_ACPI_STATUS(status);
  232. }
  233. ACPI_EXPORT_SYMBOL(acpi_mask_gpe)
  234. /*******************************************************************************
  235. *
  236. * FUNCTION: acpi_mark_gpe_for_wake
  237. *
  238. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  239. * gpe_number - GPE level within the GPE block
  240. *
  241. * RETURN: Status
  242. *
  243. * DESCRIPTION: Mark a GPE as having the ability to wake the system. Simply
  244. * sets the ACPI_GPE_CAN_WAKE flag.
  245. *
  246. * Some potential callers of acpi_setup_gpe_for_wake may know in advance that
  247. * there won't be any notify handlers installed for device wake notifications
  248. * from the given GPE (one example is a button GPE in Linux). For these cases,
  249. * acpi_mark_gpe_for_wake should be used instead of acpi_setup_gpe_for_wake.
  250. * This will set the ACPI_GPE_CAN_WAKE flag for the GPE without trying to
  251. * setup implicit wake notification for it (since there's no handler method).
  252. *
  253. ******************************************************************************/
  254. acpi_status acpi_mark_gpe_for_wake(acpi_handle gpe_device, u32 gpe_number)
  255. {
  256. struct acpi_gpe_event_info *gpe_event_info;
  257. acpi_status status = AE_BAD_PARAMETER;
  258. acpi_cpu_flags flags;
  259. ACPI_FUNCTION_TRACE(acpi_mark_gpe_for_wake);
  260. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  261. /* Ensure that we have a valid GPE number */
  262. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  263. if (gpe_event_info) {
  264. /* Mark the GPE as a possible wake event */
  265. gpe_event_info->flags |= ACPI_GPE_CAN_WAKE;
  266. status = AE_OK;
  267. }
  268. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  269. return_ACPI_STATUS(status);
  270. }
  271. ACPI_EXPORT_SYMBOL(acpi_mark_gpe_for_wake)
  272. /*******************************************************************************
  273. *
  274. * FUNCTION: acpi_setup_gpe_for_wake
  275. *
  276. * PARAMETERS: wake_device - Device associated with the GPE (via _PRW)
  277. * gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  278. * gpe_number - GPE level within the GPE block
  279. *
  280. * RETURN: Status
  281. *
  282. * DESCRIPTION: Mark a GPE as having the ability to wake the system. This
  283. * interface is intended to be used as the host executes the
  284. * _PRW methods (Power Resources for Wake) in the system tables.
  285. * Each _PRW appears under a Device Object (The wake_device), and
  286. * contains the info for the wake GPE associated with the
  287. * wake_device.
  288. *
  289. ******************************************************************************/
  290. acpi_status
  291. acpi_setup_gpe_for_wake(acpi_handle wake_device,
  292. acpi_handle gpe_device, u32 gpe_number)
  293. {
  294. acpi_status status;
  295. struct acpi_gpe_event_info *gpe_event_info;
  296. struct acpi_namespace_node *device_node;
  297. struct acpi_gpe_notify_info *notify;
  298. struct acpi_gpe_notify_info *new_notify;
  299. acpi_cpu_flags flags;
  300. ACPI_FUNCTION_TRACE(acpi_setup_gpe_for_wake);
  301. /* Parameter Validation */
  302. if (!wake_device) {
  303. /*
  304. * By forcing wake_device to be valid, we automatically enable the
  305. * implicit notify feature on all hosts.
  306. */
  307. return_ACPI_STATUS(AE_BAD_PARAMETER);
  308. }
  309. /* Handle root object case */
  310. if (wake_device == ACPI_ROOT_OBJECT) {
  311. device_node = acpi_gbl_root_node;
  312. } else {
  313. device_node =
  314. ACPI_CAST_PTR(struct acpi_namespace_node, wake_device);
  315. }
  316. /* Validate wake_device is of type Device */
  317. if (device_node->type != ACPI_TYPE_DEVICE) {
  318. return_ACPI_STATUS (AE_BAD_PARAMETER);
  319. }
  320. /*
  321. * Allocate a new notify object up front, in case it is needed.
  322. * Memory allocation while holding a spinlock is a big no-no
  323. * on some hosts.
  324. */
  325. new_notify = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_notify_info));
  326. if (!new_notify) {
  327. return_ACPI_STATUS(AE_NO_MEMORY);
  328. }
  329. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  330. /* Ensure that we have a valid GPE number */
  331. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  332. if (!gpe_event_info) {
  333. status = AE_BAD_PARAMETER;
  334. goto unlock_and_exit;
  335. }
  336. /*
  337. * If there is no method or handler for this GPE, then the
  338. * wake_device will be notified whenever this GPE fires. This is
  339. * known as an "implicit notify". Note: The GPE is assumed to be
  340. * level-triggered (for windows compatibility).
  341. */
  342. if (ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) ==
  343. ACPI_GPE_DISPATCH_NONE) {
  344. /*
  345. * This is the first device for implicit notify on this GPE.
  346. * Just set the flags here, and enter the NOTIFY block below.
  347. */
  348. gpe_event_info->flags =
  349. (ACPI_GPE_DISPATCH_NOTIFY | ACPI_GPE_LEVEL_TRIGGERED);
  350. } else if (gpe_event_info->flags & ACPI_GPE_AUTO_ENABLED) {
  351. /*
  352. * A reference to this GPE has been added during the GPE block
  353. * initialization, so drop it now to prevent the GPE from being
  354. * permanently enabled and clear its ACPI_GPE_AUTO_ENABLED flag.
  355. */
  356. (void)acpi_ev_remove_gpe_reference(gpe_event_info);
  357. gpe_event_info->flags &= ~ACPI_GPE_AUTO_ENABLED;
  358. }
  359. /*
  360. * If we already have an implicit notify on this GPE, add
  361. * this device to the notify list.
  362. */
  363. if (ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) ==
  364. ACPI_GPE_DISPATCH_NOTIFY) {
  365. /* Ensure that the device is not already in the list */
  366. notify = gpe_event_info->dispatch.notify_list;
  367. while (notify) {
  368. if (notify->device_node == device_node) {
  369. status = AE_ALREADY_EXISTS;
  370. goto unlock_and_exit;
  371. }
  372. notify = notify->next;
  373. }
  374. /* Add this device to the notify list for this GPE */
  375. new_notify->device_node = device_node;
  376. new_notify->next = gpe_event_info->dispatch.notify_list;
  377. gpe_event_info->dispatch.notify_list = new_notify;
  378. new_notify = NULL;
  379. }
  380. /* Mark the GPE as a possible wake event */
  381. gpe_event_info->flags |= ACPI_GPE_CAN_WAKE;
  382. status = AE_OK;
  383. unlock_and_exit:
  384. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  385. /* Delete the notify object if it was not used above */
  386. if (new_notify) {
  387. ACPI_FREE(new_notify);
  388. }
  389. return_ACPI_STATUS(status);
  390. }
  391. ACPI_EXPORT_SYMBOL(acpi_setup_gpe_for_wake)
  392. /*******************************************************************************
  393. *
  394. * FUNCTION: acpi_set_gpe_wake_mask
  395. *
  396. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  397. * gpe_number - GPE level within the GPE block
  398. * action - Enable or Disable
  399. *
  400. * RETURN: Status
  401. *
  402. * DESCRIPTION: Set or clear the GPE's wakeup enable mask bit. The GPE must
  403. * already be marked as a WAKE GPE.
  404. *
  405. ******************************************************************************/
  406. acpi_status
  407. acpi_set_gpe_wake_mask(acpi_handle gpe_device, u32 gpe_number, u8 action)
  408. {
  409. acpi_status status = AE_OK;
  410. struct acpi_gpe_event_info *gpe_event_info;
  411. struct acpi_gpe_register_info *gpe_register_info;
  412. acpi_cpu_flags flags;
  413. u32 register_bit;
  414. ACPI_FUNCTION_TRACE(acpi_set_gpe_wake_mask);
  415. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  416. /*
  417. * Ensure that we have a valid GPE number and that this GPE is in
  418. * fact a wake GPE
  419. */
  420. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  421. if (!gpe_event_info) {
  422. status = AE_BAD_PARAMETER;
  423. goto unlock_and_exit;
  424. }
  425. if (!(gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) {
  426. status = AE_TYPE;
  427. goto unlock_and_exit;
  428. }
  429. gpe_register_info = gpe_event_info->register_info;
  430. if (!gpe_register_info) {
  431. status = AE_NOT_EXIST;
  432. goto unlock_and_exit;
  433. }
  434. register_bit = acpi_hw_get_gpe_register_bit(gpe_event_info);
  435. /* Perform the action */
  436. switch (action) {
  437. case ACPI_GPE_ENABLE:
  438. ACPI_SET_BIT(gpe_register_info->enable_for_wake,
  439. (u8)register_bit);
  440. break;
  441. case ACPI_GPE_DISABLE:
  442. ACPI_CLEAR_BIT(gpe_register_info->enable_for_wake,
  443. (u8)register_bit);
  444. break;
  445. default:
  446. ACPI_ERROR((AE_INFO, "%u, Invalid action", action));
  447. status = AE_BAD_PARAMETER;
  448. break;
  449. }
  450. unlock_and_exit:
  451. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  452. return_ACPI_STATUS(status);
  453. }
  454. ACPI_EXPORT_SYMBOL(acpi_set_gpe_wake_mask)
  455. /*******************************************************************************
  456. *
  457. * FUNCTION: acpi_clear_gpe
  458. *
  459. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  460. * gpe_number - GPE level within the GPE block
  461. *
  462. * RETURN: Status
  463. *
  464. * DESCRIPTION: Clear an ACPI event (general purpose)
  465. *
  466. ******************************************************************************/
  467. acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number)
  468. {
  469. acpi_status status = AE_OK;
  470. struct acpi_gpe_event_info *gpe_event_info;
  471. acpi_cpu_flags flags;
  472. ACPI_FUNCTION_TRACE(acpi_clear_gpe);
  473. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  474. /* Ensure that we have a valid GPE number */
  475. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  476. if (!gpe_event_info) {
  477. status = AE_BAD_PARAMETER;
  478. goto unlock_and_exit;
  479. }
  480. status = acpi_hw_clear_gpe(gpe_event_info);
  481. unlock_and_exit:
  482. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  483. return_ACPI_STATUS(status);
  484. }
  485. ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
  486. /*******************************************************************************
  487. *
  488. * FUNCTION: acpi_get_gpe_status
  489. *
  490. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  491. * gpe_number - GPE level within the GPE block
  492. * event_status - Where the current status of the event
  493. * will be returned
  494. *
  495. * RETURN: Status
  496. *
  497. * DESCRIPTION: Get the current status of a GPE (signalled/not_signalled)
  498. *
  499. ******************************************************************************/
  500. acpi_status
  501. acpi_get_gpe_status(acpi_handle gpe_device,
  502. u32 gpe_number, acpi_event_status *event_status)
  503. {
  504. acpi_status status = AE_OK;
  505. struct acpi_gpe_event_info *gpe_event_info;
  506. acpi_cpu_flags flags;
  507. ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
  508. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  509. /* Ensure that we have a valid GPE number */
  510. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  511. if (!gpe_event_info) {
  512. status = AE_BAD_PARAMETER;
  513. goto unlock_and_exit;
  514. }
  515. /* Obtain status on the requested GPE number */
  516. status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
  517. unlock_and_exit:
  518. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  519. return_ACPI_STATUS(status);
  520. }
  521. ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
  522. /*******************************************************************************
  523. *
  524. * FUNCTION: acpi_finish_gpe
  525. *
  526. * PARAMETERS: gpe_device - Namespace node for the GPE Block
  527. * (NULL for FADT defined GPEs)
  528. * gpe_number - GPE level within the GPE block
  529. *
  530. * RETURN: Status
  531. *
  532. * DESCRIPTION: Clear and conditionally reenable a GPE. This completes the GPE
  533. * processing. Intended for use by asynchronous host-installed
  534. * GPE handlers. The GPE is only reenabled if the enable_for_run bit
  535. * is set in the GPE info.
  536. *
  537. ******************************************************************************/
  538. acpi_status acpi_finish_gpe(acpi_handle gpe_device, u32 gpe_number)
  539. {
  540. struct acpi_gpe_event_info *gpe_event_info;
  541. acpi_status status;
  542. acpi_cpu_flags flags;
  543. ACPI_FUNCTION_TRACE(acpi_finish_gpe);
  544. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  545. /* Ensure that we have a valid GPE number */
  546. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  547. if (!gpe_event_info) {
  548. status = AE_BAD_PARAMETER;
  549. goto unlock_and_exit;
  550. }
  551. status = acpi_ev_finish_gpe(gpe_event_info);
  552. unlock_and_exit:
  553. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  554. return_ACPI_STATUS(status);
  555. }
  556. ACPI_EXPORT_SYMBOL(acpi_finish_gpe)
  557. /******************************************************************************
  558. *
  559. * FUNCTION: acpi_disable_all_gpes
  560. *
  561. * PARAMETERS: None
  562. *
  563. * RETURN: Status
  564. *
  565. * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
  566. *
  567. ******************************************************************************/
  568. acpi_status acpi_disable_all_gpes(void)
  569. {
  570. acpi_status status;
  571. ACPI_FUNCTION_TRACE(acpi_disable_all_gpes);
  572. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  573. if (ACPI_FAILURE(status)) {
  574. return_ACPI_STATUS(status);
  575. }
  576. status = acpi_hw_disable_all_gpes();
  577. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  578. return_ACPI_STATUS(status);
  579. }
  580. ACPI_EXPORT_SYMBOL(acpi_disable_all_gpes)
  581. /******************************************************************************
  582. *
  583. * FUNCTION: acpi_enable_all_runtime_gpes
  584. *
  585. * PARAMETERS: None
  586. *
  587. * RETURN: Status
  588. *
  589. * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
  590. *
  591. ******************************************************************************/
  592. acpi_status acpi_enable_all_runtime_gpes(void)
  593. {
  594. acpi_status status;
  595. ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes);
  596. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  597. if (ACPI_FAILURE(status)) {
  598. return_ACPI_STATUS(status);
  599. }
  600. status = acpi_hw_enable_all_runtime_gpes();
  601. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  602. return_ACPI_STATUS(status);
  603. }
  604. ACPI_EXPORT_SYMBOL(acpi_enable_all_runtime_gpes)
  605. /******************************************************************************
  606. *
  607. * FUNCTION: acpi_enable_all_wakeup_gpes
  608. *
  609. * PARAMETERS: None
  610. *
  611. * RETURN: Status
  612. *
  613. * DESCRIPTION: Enable all "wakeup" GPEs and disable all of the other GPEs, in
  614. * all GPE blocks.
  615. *
  616. ******************************************************************************/
  617. acpi_status acpi_enable_all_wakeup_gpes(void)
  618. {
  619. acpi_status status;
  620. ACPI_FUNCTION_TRACE(acpi_enable_all_wakeup_gpes);
  621. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  622. if (ACPI_FAILURE(status)) {
  623. return_ACPI_STATUS(status);
  624. }
  625. status = acpi_hw_enable_all_wakeup_gpes();
  626. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  627. return_ACPI_STATUS(status);
  628. }
  629. ACPI_EXPORT_SYMBOL(acpi_enable_all_wakeup_gpes)
  630. /*******************************************************************************
  631. *
  632. * FUNCTION: acpi_install_gpe_block
  633. *
  634. * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
  635. * gpe_block_address - Address and space_ID
  636. * register_count - Number of GPE register pairs in the block
  637. * interrupt_number - H/W interrupt for the block
  638. *
  639. * RETURN: Status
  640. *
  641. * DESCRIPTION: Create and Install a block of GPE registers. The GPEs are not
  642. * enabled here.
  643. *
  644. ******************************************************************************/
  645. acpi_status
  646. acpi_install_gpe_block(acpi_handle gpe_device,
  647. struct acpi_generic_address *gpe_block_address,
  648. u32 register_count, u32 interrupt_number)
  649. {
  650. acpi_status status;
  651. union acpi_operand_object *obj_desc;
  652. struct acpi_namespace_node *node;
  653. struct acpi_gpe_block_info *gpe_block;
  654. ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
  655. if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
  656. return_ACPI_STATUS(AE_BAD_PARAMETER);
  657. }
  658. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  659. if (ACPI_FAILURE(status)) {
  660. return_ACPI_STATUS(status);
  661. }
  662. node = acpi_ns_validate_handle(gpe_device);
  663. if (!node) {
  664. status = AE_BAD_PARAMETER;
  665. goto unlock_and_exit;
  666. }
  667. /* Validate the parent device */
  668. if (node->type != ACPI_TYPE_DEVICE) {
  669. status = AE_TYPE;
  670. goto unlock_and_exit;
  671. }
  672. if (node->object) {
  673. status = AE_ALREADY_EXISTS;
  674. goto unlock_and_exit;
  675. }
  676. /*
  677. * For user-installed GPE Block Devices, the gpe_block_base_number
  678. * is always zero
  679. */
  680. status = acpi_ev_create_gpe_block(node, gpe_block_address->address,
  681. gpe_block_address->space_id,
  682. register_count, 0, interrupt_number,
  683. &gpe_block);
  684. if (ACPI_FAILURE(status)) {
  685. goto unlock_and_exit;
  686. }
  687. /* Install block in the device_object attached to the node */
  688. obj_desc = acpi_ns_get_attached_object(node);
  689. if (!obj_desc) {
  690. /*
  691. * No object, create a new one (Device nodes do not always have
  692. * an attached object)
  693. */
  694. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
  695. if (!obj_desc) {
  696. status = AE_NO_MEMORY;
  697. goto unlock_and_exit;
  698. }
  699. status =
  700. acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
  701. /* Remove local reference to the object */
  702. acpi_ut_remove_reference(obj_desc);
  703. if (ACPI_FAILURE(status)) {
  704. goto unlock_and_exit;
  705. }
  706. }
  707. /* Now install the GPE block in the device_object */
  708. obj_desc->device.gpe_block = gpe_block;
  709. unlock_and_exit:
  710. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  711. return_ACPI_STATUS(status);
  712. }
  713. ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
  714. /*******************************************************************************
  715. *
  716. * FUNCTION: acpi_remove_gpe_block
  717. *
  718. * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
  719. *
  720. * RETURN: Status
  721. *
  722. * DESCRIPTION: Remove a previously installed block of GPE registers
  723. *
  724. ******************************************************************************/
  725. acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
  726. {
  727. union acpi_operand_object *obj_desc;
  728. acpi_status status;
  729. struct acpi_namespace_node *node;
  730. ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
  731. if (!gpe_device) {
  732. return_ACPI_STATUS(AE_BAD_PARAMETER);
  733. }
  734. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  735. if (ACPI_FAILURE(status)) {
  736. return_ACPI_STATUS(status);
  737. }
  738. node = acpi_ns_validate_handle(gpe_device);
  739. if (!node) {
  740. status = AE_BAD_PARAMETER;
  741. goto unlock_and_exit;
  742. }
  743. /* Validate the parent device */
  744. if (node->type != ACPI_TYPE_DEVICE) {
  745. status = AE_TYPE;
  746. goto unlock_and_exit;
  747. }
  748. /* Get the device_object attached to the node */
  749. obj_desc = acpi_ns_get_attached_object(node);
  750. if (!obj_desc || !obj_desc->device.gpe_block) {
  751. return_ACPI_STATUS(AE_NULL_OBJECT);
  752. }
  753. /* Delete the GPE block (but not the device_object) */
  754. status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
  755. if (ACPI_SUCCESS(status)) {
  756. obj_desc->device.gpe_block = NULL;
  757. }
  758. unlock_and_exit:
  759. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  760. return_ACPI_STATUS(status);
  761. }
  762. ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)
  763. /*******************************************************************************
  764. *
  765. * FUNCTION: acpi_get_gpe_device
  766. *
  767. * PARAMETERS: index - System GPE index (0-current_gpe_count)
  768. * gpe_device - Where the parent GPE Device is returned
  769. *
  770. * RETURN: Status
  771. *
  772. * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
  773. * gpe device indicates that the gpe number is contained in one of
  774. * the FADT-defined gpe blocks. Otherwise, the GPE block device.
  775. *
  776. ******************************************************************************/
  777. acpi_status acpi_get_gpe_device(u32 index, acpi_handle *gpe_device)
  778. {
  779. struct acpi_gpe_device_info info;
  780. acpi_status status;
  781. ACPI_FUNCTION_TRACE(acpi_get_gpe_device);
  782. if (!gpe_device) {
  783. return_ACPI_STATUS(AE_BAD_PARAMETER);
  784. }
  785. if (index >= acpi_current_gpe_count) {
  786. return_ACPI_STATUS(AE_NOT_EXIST);
  787. }
  788. /* Setup and walk the GPE list */
  789. info.index = index;
  790. info.status = AE_NOT_EXIST;
  791. info.gpe_device = NULL;
  792. info.next_block_base_index = 0;
  793. status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info);
  794. if (ACPI_FAILURE(status)) {
  795. return_ACPI_STATUS(status);
  796. }
  797. *gpe_device = ACPI_CAST_PTR(acpi_handle, info.gpe_device);
  798. return_ACPI_STATUS(info.status);
  799. }
  800. ACPI_EXPORT_SYMBOL(acpi_get_gpe_device)
  801. #endif /* !ACPI_REDUCED_HARDWARE */