evxfgpe.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049
  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 - 2022, 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, TRUE);
  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_gispatch_gpe
  525. *
  526. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  527. * gpe_number - GPE level within the GPE block
  528. *
  529. * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
  530. *
  531. * DESCRIPTION: Detect and dispatch a General Purpose Event to either a function
  532. * (e.g. EC) or method (e.g. _Lxx/_Exx) handler.
  533. *
  534. ******************************************************************************/
  535. u32 acpi_dispatch_gpe(acpi_handle gpe_device, u32 gpe_number)
  536. {
  537. ACPI_FUNCTION_TRACE(acpi_dispatch_gpe);
  538. return acpi_ev_detect_gpe(gpe_device, NULL, gpe_number);
  539. }
  540. ACPI_EXPORT_SYMBOL(acpi_dispatch_gpe)
  541. /*******************************************************************************
  542. *
  543. * FUNCTION: acpi_finish_gpe
  544. *
  545. * PARAMETERS: gpe_device - Namespace node for the GPE Block
  546. * (NULL for FADT defined GPEs)
  547. * gpe_number - GPE level within the GPE block
  548. *
  549. * RETURN: Status
  550. *
  551. * DESCRIPTION: Clear and conditionally re-enable a GPE. This completes the GPE
  552. * processing. Intended for use by asynchronous host-installed
  553. * GPE handlers. The GPE is only re-enabled if the enable_for_run bit
  554. * is set in the GPE info.
  555. *
  556. ******************************************************************************/
  557. acpi_status acpi_finish_gpe(acpi_handle gpe_device, u32 gpe_number)
  558. {
  559. struct acpi_gpe_event_info *gpe_event_info;
  560. acpi_status status;
  561. acpi_cpu_flags flags;
  562. ACPI_FUNCTION_TRACE(acpi_finish_gpe);
  563. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  564. /* Ensure that we have a valid GPE number */
  565. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  566. if (!gpe_event_info) {
  567. status = AE_BAD_PARAMETER;
  568. goto unlock_and_exit;
  569. }
  570. status = acpi_ev_finish_gpe(gpe_event_info);
  571. unlock_and_exit:
  572. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  573. return_ACPI_STATUS(status);
  574. }
  575. ACPI_EXPORT_SYMBOL(acpi_finish_gpe)
  576. /******************************************************************************
  577. *
  578. * FUNCTION: acpi_disable_all_gpes
  579. *
  580. * PARAMETERS: None
  581. *
  582. * RETURN: Status
  583. *
  584. * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
  585. *
  586. ******************************************************************************/
  587. acpi_status acpi_disable_all_gpes(void)
  588. {
  589. acpi_status status;
  590. ACPI_FUNCTION_TRACE(acpi_disable_all_gpes);
  591. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  592. if (ACPI_FAILURE(status)) {
  593. return_ACPI_STATUS(status);
  594. }
  595. status = acpi_hw_disable_all_gpes();
  596. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  597. return_ACPI_STATUS(status);
  598. }
  599. ACPI_EXPORT_SYMBOL(acpi_disable_all_gpes)
  600. /******************************************************************************
  601. *
  602. * FUNCTION: acpi_enable_all_runtime_gpes
  603. *
  604. * PARAMETERS: None
  605. *
  606. * RETURN: Status
  607. *
  608. * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
  609. *
  610. ******************************************************************************/
  611. acpi_status acpi_enable_all_runtime_gpes(void)
  612. {
  613. acpi_status status;
  614. ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes);
  615. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  616. if (ACPI_FAILURE(status)) {
  617. return_ACPI_STATUS(status);
  618. }
  619. status = acpi_hw_enable_all_runtime_gpes();
  620. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  621. return_ACPI_STATUS(status);
  622. }
  623. ACPI_EXPORT_SYMBOL(acpi_enable_all_runtime_gpes)
  624. /******************************************************************************
  625. *
  626. * FUNCTION: acpi_enable_all_wakeup_gpes
  627. *
  628. * PARAMETERS: None
  629. *
  630. * RETURN: Status
  631. *
  632. * DESCRIPTION: Enable all "wakeup" GPEs and disable all of the other GPEs, in
  633. * all GPE blocks.
  634. *
  635. ******************************************************************************/
  636. acpi_status acpi_enable_all_wakeup_gpes(void)
  637. {
  638. acpi_status status;
  639. ACPI_FUNCTION_TRACE(acpi_enable_all_wakeup_gpes);
  640. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  641. if (ACPI_FAILURE(status)) {
  642. return_ACPI_STATUS(status);
  643. }
  644. status = acpi_hw_enable_all_wakeup_gpes();
  645. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  646. return_ACPI_STATUS(status);
  647. }
  648. ACPI_EXPORT_SYMBOL(acpi_enable_all_wakeup_gpes)
  649. /******************************************************************************
  650. *
  651. * FUNCTION: acpi_any_gpe_status_set
  652. *
  653. * PARAMETERS: gpe_skip_number - Number of the GPE to skip
  654. *
  655. * RETURN: Whether or not the status bit is set for any GPE
  656. *
  657. * DESCRIPTION: Check the status bits of all enabled GPEs, except for the one
  658. * represented by the "skip" argument, and return TRUE if any of
  659. * them is set or FALSE otherwise.
  660. *
  661. ******************************************************************************/
  662. u32 acpi_any_gpe_status_set(u32 gpe_skip_number)
  663. {
  664. acpi_status status;
  665. acpi_handle gpe_device;
  666. u8 ret;
  667. ACPI_FUNCTION_TRACE(acpi_any_gpe_status_set);
  668. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  669. if (ACPI_FAILURE(status)) {
  670. return (FALSE);
  671. }
  672. status = acpi_get_gpe_device(gpe_skip_number, &gpe_device);
  673. if (ACPI_FAILURE(status)) {
  674. gpe_device = NULL;
  675. }
  676. ret = acpi_hw_check_all_gpes(gpe_device, gpe_skip_number);
  677. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  678. return (ret);
  679. }
  680. ACPI_EXPORT_SYMBOL(acpi_any_gpe_status_set)
  681. /*******************************************************************************
  682. *
  683. * FUNCTION: acpi_install_gpe_block
  684. *
  685. * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
  686. * gpe_block_address - Address and space_ID
  687. * register_count - Number of GPE register pairs in the block
  688. * interrupt_number - H/W interrupt for the block
  689. *
  690. * RETURN: Status
  691. *
  692. * DESCRIPTION: Create and Install a block of GPE registers. The GPEs are not
  693. * enabled here.
  694. *
  695. ******************************************************************************/
  696. acpi_status
  697. acpi_install_gpe_block(acpi_handle gpe_device,
  698. struct acpi_generic_address *gpe_block_address,
  699. u32 register_count, u32 interrupt_number)
  700. {
  701. acpi_status status;
  702. union acpi_operand_object *obj_desc;
  703. struct acpi_namespace_node *node;
  704. struct acpi_gpe_block_info *gpe_block;
  705. ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
  706. if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
  707. return_ACPI_STATUS(AE_BAD_PARAMETER);
  708. }
  709. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  710. if (ACPI_FAILURE(status)) {
  711. return_ACPI_STATUS(status);
  712. }
  713. node = acpi_ns_validate_handle(gpe_device);
  714. if (!node) {
  715. status = AE_BAD_PARAMETER;
  716. goto unlock_and_exit;
  717. }
  718. /* Validate the parent device */
  719. if (node->type != ACPI_TYPE_DEVICE) {
  720. status = AE_TYPE;
  721. goto unlock_and_exit;
  722. }
  723. if (node->object) {
  724. status = AE_ALREADY_EXISTS;
  725. goto unlock_and_exit;
  726. }
  727. /*
  728. * For user-installed GPE Block Devices, the gpe_block_base_number
  729. * is always zero
  730. */
  731. status = acpi_ev_create_gpe_block(node, gpe_block_address->address,
  732. gpe_block_address->space_id,
  733. register_count, 0, interrupt_number,
  734. &gpe_block);
  735. if (ACPI_FAILURE(status)) {
  736. goto unlock_and_exit;
  737. }
  738. /* Install block in the device_object attached to the node */
  739. obj_desc = acpi_ns_get_attached_object(node);
  740. if (!obj_desc) {
  741. /*
  742. * No object, create a new one (Device nodes do not always have
  743. * an attached object)
  744. */
  745. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
  746. if (!obj_desc) {
  747. status = AE_NO_MEMORY;
  748. goto unlock_and_exit;
  749. }
  750. status =
  751. acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
  752. /* Remove local reference to the object */
  753. acpi_ut_remove_reference(obj_desc);
  754. if (ACPI_FAILURE(status)) {
  755. goto unlock_and_exit;
  756. }
  757. }
  758. /* Now install the GPE block in the device_object */
  759. obj_desc->device.gpe_block = gpe_block;
  760. unlock_and_exit:
  761. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  762. return_ACPI_STATUS(status);
  763. }
  764. ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
  765. /*******************************************************************************
  766. *
  767. * FUNCTION: acpi_remove_gpe_block
  768. *
  769. * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
  770. *
  771. * RETURN: Status
  772. *
  773. * DESCRIPTION: Remove a previously installed block of GPE registers
  774. *
  775. ******************************************************************************/
  776. acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
  777. {
  778. union acpi_operand_object *obj_desc;
  779. acpi_status status;
  780. struct acpi_namespace_node *node;
  781. ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
  782. if (!gpe_device) {
  783. return_ACPI_STATUS(AE_BAD_PARAMETER);
  784. }
  785. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  786. if (ACPI_FAILURE(status)) {
  787. return_ACPI_STATUS(status);
  788. }
  789. node = acpi_ns_validate_handle(gpe_device);
  790. if (!node) {
  791. status = AE_BAD_PARAMETER;
  792. goto unlock_and_exit;
  793. }
  794. /* Validate the parent device */
  795. if (node->type != ACPI_TYPE_DEVICE) {
  796. status = AE_TYPE;
  797. goto unlock_and_exit;
  798. }
  799. /* Get the device_object attached to the node */
  800. obj_desc = acpi_ns_get_attached_object(node);
  801. if (!obj_desc || !obj_desc->device.gpe_block) {
  802. return_ACPI_STATUS(AE_NULL_OBJECT);
  803. }
  804. /* Delete the GPE block (but not the device_object) */
  805. status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
  806. if (ACPI_SUCCESS(status)) {
  807. obj_desc->device.gpe_block = NULL;
  808. }
  809. unlock_and_exit:
  810. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  811. return_ACPI_STATUS(status);
  812. }
  813. ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)
  814. /*******************************************************************************
  815. *
  816. * FUNCTION: acpi_get_gpe_device
  817. *
  818. * PARAMETERS: index - System GPE index (0-current_gpe_count)
  819. * gpe_device - Where the parent GPE Device is returned
  820. *
  821. * RETURN: Status
  822. *
  823. * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
  824. * gpe device indicates that the gpe number is contained in one of
  825. * the FADT-defined gpe blocks. Otherwise, the GPE block device.
  826. *
  827. ******************************************************************************/
  828. acpi_status acpi_get_gpe_device(u32 index, acpi_handle *gpe_device)
  829. {
  830. struct acpi_gpe_device_info info;
  831. acpi_status status;
  832. ACPI_FUNCTION_TRACE(acpi_get_gpe_device);
  833. if (!gpe_device) {
  834. return_ACPI_STATUS(AE_BAD_PARAMETER);
  835. }
  836. if (index >= acpi_current_gpe_count) {
  837. return_ACPI_STATUS(AE_NOT_EXIST);
  838. }
  839. /* Setup and walk the GPE list */
  840. info.index = index;
  841. info.status = AE_NOT_EXIST;
  842. info.gpe_device = NULL;
  843. info.next_block_base_index = 0;
  844. status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info);
  845. if (ACPI_FAILURE(status)) {
  846. return_ACPI_STATUS(status);
  847. }
  848. *gpe_device = ACPI_CAST_PTR(acpi_handle, info.gpe_device);
  849. return_ACPI_STATUS(info.status);
  850. }
  851. ACPI_EXPORT_SYMBOL(acpi_get_gpe_device)
  852. #endif /* !ACPI_REDUCED_HARDWARE */