evxfgpe.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996
  1. /******************************************************************************
  2. *
  3. * Module Name: evxfgpe - External Interfaces for General Purpose Events (GPEs)
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2016, Intel Corp.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #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. }
  369. /*
  370. * If we already have an implicit notify on this GPE, add
  371. * this device to the notify list.
  372. */
  373. if (ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) ==
  374. ACPI_GPE_DISPATCH_NOTIFY) {
  375. /* Ensure that the device is not already in the list */
  376. notify = gpe_event_info->dispatch.notify_list;
  377. while (notify) {
  378. if (notify->device_node == device_node) {
  379. status = AE_ALREADY_EXISTS;
  380. goto unlock_and_exit;
  381. }
  382. notify = notify->next;
  383. }
  384. /* Add this device to the notify list for this GPE */
  385. new_notify->device_node = device_node;
  386. new_notify->next = gpe_event_info->dispatch.notify_list;
  387. gpe_event_info->dispatch.notify_list = new_notify;
  388. new_notify = NULL;
  389. }
  390. /* Mark the GPE as a possible wake event */
  391. gpe_event_info->flags |= ACPI_GPE_CAN_WAKE;
  392. status = AE_OK;
  393. unlock_and_exit:
  394. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  395. /* Delete the notify object if it was not used above */
  396. if (new_notify) {
  397. ACPI_FREE(new_notify);
  398. }
  399. return_ACPI_STATUS(status);
  400. }
  401. ACPI_EXPORT_SYMBOL(acpi_setup_gpe_for_wake)
  402. /*******************************************************************************
  403. *
  404. * FUNCTION: acpi_set_gpe_wake_mask
  405. *
  406. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  407. * gpe_number - GPE level within the GPE block
  408. * action - Enable or Disable
  409. *
  410. * RETURN: Status
  411. *
  412. * DESCRIPTION: Set or clear the GPE's wakeup enable mask bit. The GPE must
  413. * already be marked as a WAKE GPE.
  414. *
  415. ******************************************************************************/
  416. acpi_status
  417. acpi_set_gpe_wake_mask(acpi_handle gpe_device, u32 gpe_number, u8 action)
  418. {
  419. acpi_status status = AE_OK;
  420. struct acpi_gpe_event_info *gpe_event_info;
  421. struct acpi_gpe_register_info *gpe_register_info;
  422. acpi_cpu_flags flags;
  423. u32 register_bit;
  424. ACPI_FUNCTION_TRACE(acpi_set_gpe_wake_mask);
  425. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  426. /*
  427. * Ensure that we have a valid GPE number and that this GPE is in
  428. * fact a wake GPE
  429. */
  430. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  431. if (!gpe_event_info) {
  432. status = AE_BAD_PARAMETER;
  433. goto unlock_and_exit;
  434. }
  435. if (!(gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) {
  436. status = AE_TYPE;
  437. goto unlock_and_exit;
  438. }
  439. gpe_register_info = gpe_event_info->register_info;
  440. if (!gpe_register_info) {
  441. status = AE_NOT_EXIST;
  442. goto unlock_and_exit;
  443. }
  444. register_bit = acpi_hw_get_gpe_register_bit(gpe_event_info);
  445. /* Perform the action */
  446. switch (action) {
  447. case ACPI_GPE_ENABLE:
  448. ACPI_SET_BIT(gpe_register_info->enable_for_wake,
  449. (u8)register_bit);
  450. break;
  451. case ACPI_GPE_DISABLE:
  452. ACPI_CLEAR_BIT(gpe_register_info->enable_for_wake,
  453. (u8)register_bit);
  454. break;
  455. default:
  456. ACPI_ERROR((AE_INFO, "%u, Invalid action", action));
  457. status = AE_BAD_PARAMETER;
  458. break;
  459. }
  460. unlock_and_exit:
  461. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  462. return_ACPI_STATUS(status);
  463. }
  464. ACPI_EXPORT_SYMBOL(acpi_set_gpe_wake_mask)
  465. /*******************************************************************************
  466. *
  467. * FUNCTION: acpi_clear_gpe
  468. *
  469. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  470. * gpe_number - GPE level within the GPE block
  471. *
  472. * RETURN: Status
  473. *
  474. * DESCRIPTION: Clear an ACPI event (general purpose)
  475. *
  476. ******************************************************************************/
  477. acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number)
  478. {
  479. acpi_status status = AE_OK;
  480. struct acpi_gpe_event_info *gpe_event_info;
  481. acpi_cpu_flags flags;
  482. ACPI_FUNCTION_TRACE(acpi_clear_gpe);
  483. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  484. /* Ensure that we have a valid GPE number */
  485. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  486. if (!gpe_event_info) {
  487. status = AE_BAD_PARAMETER;
  488. goto unlock_and_exit;
  489. }
  490. status = acpi_hw_clear_gpe(gpe_event_info);
  491. unlock_and_exit:
  492. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  493. return_ACPI_STATUS(status);
  494. }
  495. ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
  496. /*******************************************************************************
  497. *
  498. * FUNCTION: acpi_get_gpe_status
  499. *
  500. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  501. * gpe_number - GPE level within the GPE block
  502. * event_status - Where the current status of the event
  503. * will be returned
  504. *
  505. * RETURN: Status
  506. *
  507. * DESCRIPTION: Get the current status of a GPE (signalled/not_signalled)
  508. *
  509. ******************************************************************************/
  510. acpi_status
  511. acpi_get_gpe_status(acpi_handle gpe_device,
  512. u32 gpe_number, acpi_event_status *event_status)
  513. {
  514. acpi_status status = AE_OK;
  515. struct acpi_gpe_event_info *gpe_event_info;
  516. acpi_cpu_flags flags;
  517. ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
  518. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  519. /* Ensure that we have a valid GPE number */
  520. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  521. if (!gpe_event_info) {
  522. status = AE_BAD_PARAMETER;
  523. goto unlock_and_exit;
  524. }
  525. /* Obtain status on the requested GPE number */
  526. status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
  527. unlock_and_exit:
  528. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  529. return_ACPI_STATUS(status);
  530. }
  531. ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
  532. /*******************************************************************************
  533. *
  534. * FUNCTION: acpi_finish_gpe
  535. *
  536. * PARAMETERS: gpe_device - Namespace node for the GPE Block
  537. * (NULL for FADT defined GPEs)
  538. * gpe_number - GPE level within the GPE block
  539. *
  540. * RETURN: Status
  541. *
  542. * DESCRIPTION: Clear and conditionally reenable a GPE. This completes the GPE
  543. * processing. Intended for use by asynchronous host-installed
  544. * GPE handlers. The GPE is only reenabled if the enable_for_run bit
  545. * is set in the GPE info.
  546. *
  547. ******************************************************************************/
  548. acpi_status acpi_finish_gpe(acpi_handle gpe_device, u32 gpe_number)
  549. {
  550. struct acpi_gpe_event_info *gpe_event_info;
  551. acpi_status status;
  552. acpi_cpu_flags flags;
  553. ACPI_FUNCTION_TRACE(acpi_finish_gpe);
  554. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  555. /* Ensure that we have a valid GPE number */
  556. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  557. if (!gpe_event_info) {
  558. status = AE_BAD_PARAMETER;
  559. goto unlock_and_exit;
  560. }
  561. status = acpi_ev_finish_gpe(gpe_event_info);
  562. unlock_and_exit:
  563. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  564. return_ACPI_STATUS(status);
  565. }
  566. ACPI_EXPORT_SYMBOL(acpi_finish_gpe)
  567. /******************************************************************************
  568. *
  569. * FUNCTION: acpi_disable_all_gpes
  570. *
  571. * PARAMETERS: None
  572. *
  573. * RETURN: Status
  574. *
  575. * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
  576. *
  577. ******************************************************************************/
  578. acpi_status acpi_disable_all_gpes(void)
  579. {
  580. acpi_status status;
  581. ACPI_FUNCTION_TRACE(acpi_disable_all_gpes);
  582. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  583. if (ACPI_FAILURE(status)) {
  584. return_ACPI_STATUS(status);
  585. }
  586. status = acpi_hw_disable_all_gpes();
  587. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  588. return_ACPI_STATUS(status);
  589. }
  590. ACPI_EXPORT_SYMBOL(acpi_disable_all_gpes)
  591. /******************************************************************************
  592. *
  593. * FUNCTION: acpi_enable_all_runtime_gpes
  594. *
  595. * PARAMETERS: None
  596. *
  597. * RETURN: Status
  598. *
  599. * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
  600. *
  601. ******************************************************************************/
  602. acpi_status acpi_enable_all_runtime_gpes(void)
  603. {
  604. acpi_status status;
  605. ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes);
  606. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  607. if (ACPI_FAILURE(status)) {
  608. return_ACPI_STATUS(status);
  609. }
  610. status = acpi_hw_enable_all_runtime_gpes();
  611. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  612. return_ACPI_STATUS(status);
  613. }
  614. ACPI_EXPORT_SYMBOL(acpi_enable_all_runtime_gpes)
  615. /******************************************************************************
  616. *
  617. * FUNCTION: acpi_enable_all_wakeup_gpes
  618. *
  619. * PARAMETERS: None
  620. *
  621. * RETURN: Status
  622. *
  623. * DESCRIPTION: Enable all "wakeup" GPEs and disable all of the other GPEs, in
  624. * all GPE blocks.
  625. *
  626. ******************************************************************************/
  627. acpi_status acpi_enable_all_wakeup_gpes(void)
  628. {
  629. acpi_status status;
  630. ACPI_FUNCTION_TRACE(acpi_enable_all_wakeup_gpes);
  631. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  632. if (ACPI_FAILURE(status)) {
  633. return_ACPI_STATUS(status);
  634. }
  635. status = acpi_hw_enable_all_wakeup_gpes();
  636. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  637. return_ACPI_STATUS(status);
  638. }
  639. ACPI_EXPORT_SYMBOL(acpi_enable_all_wakeup_gpes)
  640. /*******************************************************************************
  641. *
  642. * FUNCTION: acpi_install_gpe_block
  643. *
  644. * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
  645. * gpe_block_address - Address and space_ID
  646. * register_count - Number of GPE register pairs in the block
  647. * interrupt_number - H/W interrupt for the block
  648. *
  649. * RETURN: Status
  650. *
  651. * DESCRIPTION: Create and Install a block of GPE registers. The GPEs are not
  652. * enabled here.
  653. *
  654. ******************************************************************************/
  655. acpi_status
  656. acpi_install_gpe_block(acpi_handle gpe_device,
  657. struct acpi_generic_address *gpe_block_address,
  658. u32 register_count, u32 interrupt_number)
  659. {
  660. acpi_status status;
  661. union acpi_operand_object *obj_desc;
  662. struct acpi_namespace_node *node;
  663. struct acpi_gpe_block_info *gpe_block;
  664. ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
  665. if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
  666. return_ACPI_STATUS(AE_BAD_PARAMETER);
  667. }
  668. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  669. if (ACPI_FAILURE(status)) {
  670. return_ACPI_STATUS(status);
  671. }
  672. node = acpi_ns_validate_handle(gpe_device);
  673. if (!node) {
  674. status = AE_BAD_PARAMETER;
  675. goto unlock_and_exit;
  676. }
  677. /* Validate the parent device */
  678. if (node->type != ACPI_TYPE_DEVICE) {
  679. status = AE_TYPE;
  680. goto unlock_and_exit;
  681. }
  682. if (node->object) {
  683. status = AE_ALREADY_EXISTS;
  684. goto unlock_and_exit;
  685. }
  686. /*
  687. * For user-installed GPE Block Devices, the gpe_block_base_number
  688. * is always zero
  689. */
  690. status = acpi_ev_create_gpe_block(node, gpe_block_address->address,
  691. gpe_block_address->space_id,
  692. register_count, 0, interrupt_number,
  693. &gpe_block);
  694. if (ACPI_FAILURE(status)) {
  695. goto unlock_and_exit;
  696. }
  697. /* Install block in the device_object attached to the node */
  698. obj_desc = acpi_ns_get_attached_object(node);
  699. if (!obj_desc) {
  700. /*
  701. * No object, create a new one (Device nodes do not always have
  702. * an attached object)
  703. */
  704. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
  705. if (!obj_desc) {
  706. status = AE_NO_MEMORY;
  707. goto unlock_and_exit;
  708. }
  709. status =
  710. acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
  711. /* Remove local reference to the object */
  712. acpi_ut_remove_reference(obj_desc);
  713. if (ACPI_FAILURE(status)) {
  714. goto unlock_and_exit;
  715. }
  716. }
  717. /* Now install the GPE block in the device_object */
  718. obj_desc->device.gpe_block = gpe_block;
  719. unlock_and_exit:
  720. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  721. return_ACPI_STATUS(status);
  722. }
  723. ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
  724. /*******************************************************************************
  725. *
  726. * FUNCTION: acpi_remove_gpe_block
  727. *
  728. * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
  729. *
  730. * RETURN: Status
  731. *
  732. * DESCRIPTION: Remove a previously installed block of GPE registers
  733. *
  734. ******************************************************************************/
  735. acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
  736. {
  737. union acpi_operand_object *obj_desc;
  738. acpi_status status;
  739. struct acpi_namespace_node *node;
  740. ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
  741. if (!gpe_device) {
  742. return_ACPI_STATUS(AE_BAD_PARAMETER);
  743. }
  744. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  745. if (ACPI_FAILURE(status)) {
  746. return_ACPI_STATUS(status);
  747. }
  748. node = acpi_ns_validate_handle(gpe_device);
  749. if (!node) {
  750. status = AE_BAD_PARAMETER;
  751. goto unlock_and_exit;
  752. }
  753. /* Validate the parent device */
  754. if (node->type != ACPI_TYPE_DEVICE) {
  755. status = AE_TYPE;
  756. goto unlock_and_exit;
  757. }
  758. /* Get the device_object attached to the node */
  759. obj_desc = acpi_ns_get_attached_object(node);
  760. if (!obj_desc || !obj_desc->device.gpe_block) {
  761. return_ACPI_STATUS(AE_NULL_OBJECT);
  762. }
  763. /* Delete the GPE block (but not the device_object) */
  764. status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
  765. if (ACPI_SUCCESS(status)) {
  766. obj_desc->device.gpe_block = NULL;
  767. }
  768. unlock_and_exit:
  769. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  770. return_ACPI_STATUS(status);
  771. }
  772. ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)
  773. /*******************************************************************************
  774. *
  775. * FUNCTION: acpi_get_gpe_device
  776. *
  777. * PARAMETERS: index - System GPE index (0-current_gpe_count)
  778. * gpe_device - Where the parent GPE Device is returned
  779. *
  780. * RETURN: Status
  781. *
  782. * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
  783. * gpe device indicates that the gpe number is contained in one of
  784. * the FADT-defined gpe blocks. Otherwise, the GPE block device.
  785. *
  786. ******************************************************************************/
  787. acpi_status acpi_get_gpe_device(u32 index, acpi_handle *gpe_device)
  788. {
  789. struct acpi_gpe_device_info info;
  790. acpi_status status;
  791. ACPI_FUNCTION_TRACE(acpi_get_gpe_device);
  792. if (!gpe_device) {
  793. return_ACPI_STATUS(AE_BAD_PARAMETER);
  794. }
  795. if (index >= acpi_current_gpe_count) {
  796. return_ACPI_STATUS(AE_NOT_EXIST);
  797. }
  798. /* Setup and walk the GPE list */
  799. info.index = index;
  800. info.status = AE_NOT_EXIST;
  801. info.gpe_device = NULL;
  802. info.next_block_base_index = 0;
  803. status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info);
  804. if (ACPI_FAILURE(status)) {
  805. return_ACPI_STATUS(status);
  806. }
  807. *gpe_device = ACPI_CAST_PTR(acpi_handle, info.gpe_device);
  808. return_ACPI_STATUS(info.status);
  809. }
  810. ACPI_EXPORT_SYMBOL(acpi_get_gpe_device)
  811. #endif /* !ACPI_REDUCED_HARDWARE */