evxfgpe.c 29 KB

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