evxfgpe.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952
  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. break;
  205. case ACPI_GPE_DISABLE:
  206. status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_DISABLE);
  207. break;
  208. default:
  209. status = AE_BAD_PARAMETER;
  210. break;
  211. }
  212. unlock_and_exit:
  213. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  214. return_ACPI_STATUS(status);
  215. }
  216. ACPI_EXPORT_SYMBOL(acpi_set_gpe)
  217. /*******************************************************************************
  218. *
  219. * FUNCTION: acpi_mark_gpe_for_wake
  220. *
  221. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  222. * gpe_number - GPE level within the GPE block
  223. *
  224. * RETURN: Status
  225. *
  226. * DESCRIPTION: Mark a GPE as having the ability to wake the system. Simply
  227. * sets the ACPI_GPE_CAN_WAKE flag.
  228. *
  229. * Some potential callers of acpi_setup_gpe_for_wake may know in advance that
  230. * there won't be any notify handlers installed for device wake notifications
  231. * from the given GPE (one example is a button GPE in Linux). For these cases,
  232. * acpi_mark_gpe_for_wake should be used instead of acpi_setup_gpe_for_wake.
  233. * This will set the ACPI_GPE_CAN_WAKE flag for the GPE without trying to
  234. * setup implicit wake notification for it (since there's no handler method).
  235. *
  236. ******************************************************************************/
  237. acpi_status acpi_mark_gpe_for_wake(acpi_handle gpe_device, u32 gpe_number)
  238. {
  239. struct acpi_gpe_event_info *gpe_event_info;
  240. acpi_status status = AE_BAD_PARAMETER;
  241. acpi_cpu_flags flags;
  242. ACPI_FUNCTION_TRACE(acpi_mark_gpe_for_wake);
  243. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  244. /* Ensure that we have a valid GPE number */
  245. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  246. if (gpe_event_info) {
  247. /* Mark the GPE as a possible wake event */
  248. gpe_event_info->flags |= ACPI_GPE_CAN_WAKE;
  249. status = AE_OK;
  250. }
  251. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  252. return_ACPI_STATUS(status);
  253. }
  254. ACPI_EXPORT_SYMBOL(acpi_mark_gpe_for_wake)
  255. /*******************************************************************************
  256. *
  257. * FUNCTION: acpi_setup_gpe_for_wake
  258. *
  259. * PARAMETERS: wake_device - Device associated with the GPE (via _PRW)
  260. * gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  261. * gpe_number - GPE level within the GPE block
  262. *
  263. * RETURN: Status
  264. *
  265. * DESCRIPTION: Mark a GPE as having the ability to wake the system. This
  266. * interface is intended to be used as the host executes the
  267. * _PRW methods (Power Resources for Wake) in the system tables.
  268. * Each _PRW appears under a Device Object (The wake_device), and
  269. * contains the info for the wake GPE associated with the
  270. * wake_device.
  271. *
  272. ******************************************************************************/
  273. acpi_status
  274. acpi_setup_gpe_for_wake(acpi_handle wake_device,
  275. acpi_handle gpe_device, u32 gpe_number)
  276. {
  277. acpi_status status;
  278. struct acpi_gpe_event_info *gpe_event_info;
  279. struct acpi_namespace_node *device_node;
  280. struct acpi_gpe_notify_info *notify;
  281. struct acpi_gpe_notify_info *new_notify;
  282. acpi_cpu_flags flags;
  283. ACPI_FUNCTION_TRACE(acpi_setup_gpe_for_wake);
  284. /* Parameter Validation */
  285. if (!wake_device) {
  286. /*
  287. * By forcing wake_device to be valid, we automatically enable the
  288. * implicit notify feature on all hosts.
  289. */
  290. return_ACPI_STATUS(AE_BAD_PARAMETER);
  291. }
  292. /* Handle root object case */
  293. if (wake_device == ACPI_ROOT_OBJECT) {
  294. device_node = acpi_gbl_root_node;
  295. } else {
  296. device_node =
  297. ACPI_CAST_PTR(struct acpi_namespace_node, wake_device);
  298. }
  299. /* Validate wake_device is of type Device */
  300. if (device_node->type != ACPI_TYPE_DEVICE) {
  301. return_ACPI_STATUS (AE_BAD_PARAMETER);
  302. }
  303. /*
  304. * Allocate a new notify object up front, in case it is needed.
  305. * Memory allocation while holding a spinlock is a big no-no
  306. * on some hosts.
  307. */
  308. new_notify = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_notify_info));
  309. if (!new_notify) {
  310. return_ACPI_STATUS(AE_NO_MEMORY);
  311. }
  312. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  313. /* Ensure that we have a valid GPE number */
  314. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  315. if (!gpe_event_info) {
  316. status = AE_BAD_PARAMETER;
  317. goto unlock_and_exit;
  318. }
  319. /*
  320. * If there is no method or handler for this GPE, then the
  321. * wake_device will be notified whenever this GPE fires. This is
  322. * known as an "implicit notify". Note: The GPE is assumed to be
  323. * level-triggered (for windows compatibility).
  324. */
  325. if (ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) ==
  326. ACPI_GPE_DISPATCH_NONE) {
  327. /*
  328. * This is the first device for implicit notify on this GPE.
  329. * Just set the flags here, and enter the NOTIFY block below.
  330. */
  331. gpe_event_info->flags =
  332. (ACPI_GPE_DISPATCH_NOTIFY | ACPI_GPE_LEVEL_TRIGGERED);
  333. }
  334. /*
  335. * If we already have an implicit notify on this GPE, add
  336. * this device to the notify list.
  337. */
  338. if (ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) ==
  339. ACPI_GPE_DISPATCH_NOTIFY) {
  340. /* Ensure that the device is not already in the list */
  341. notify = gpe_event_info->dispatch.notify_list;
  342. while (notify) {
  343. if (notify->device_node == device_node) {
  344. status = AE_ALREADY_EXISTS;
  345. goto unlock_and_exit;
  346. }
  347. notify = notify->next;
  348. }
  349. /* Add this device to the notify list for this GPE */
  350. new_notify->device_node = device_node;
  351. new_notify->next = gpe_event_info->dispatch.notify_list;
  352. gpe_event_info->dispatch.notify_list = new_notify;
  353. new_notify = NULL;
  354. }
  355. /* Mark the GPE as a possible wake event */
  356. gpe_event_info->flags |= ACPI_GPE_CAN_WAKE;
  357. status = AE_OK;
  358. unlock_and_exit:
  359. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  360. /* Delete the notify object if it was not used above */
  361. if (new_notify) {
  362. ACPI_FREE(new_notify);
  363. }
  364. return_ACPI_STATUS(status);
  365. }
  366. ACPI_EXPORT_SYMBOL(acpi_setup_gpe_for_wake)
  367. /*******************************************************************************
  368. *
  369. * FUNCTION: acpi_set_gpe_wake_mask
  370. *
  371. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  372. * gpe_number - GPE level within the GPE block
  373. * action - Enable or Disable
  374. *
  375. * RETURN: Status
  376. *
  377. * DESCRIPTION: Set or clear the GPE's wakeup enable mask bit. The GPE must
  378. * already be marked as a WAKE GPE.
  379. *
  380. ******************************************************************************/
  381. acpi_status
  382. acpi_set_gpe_wake_mask(acpi_handle gpe_device, u32 gpe_number, u8 action)
  383. {
  384. acpi_status status = AE_OK;
  385. struct acpi_gpe_event_info *gpe_event_info;
  386. struct acpi_gpe_register_info *gpe_register_info;
  387. acpi_cpu_flags flags;
  388. u32 register_bit;
  389. ACPI_FUNCTION_TRACE(acpi_set_gpe_wake_mask);
  390. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  391. /*
  392. * Ensure that we have a valid GPE number and that this GPE is in
  393. * fact a wake GPE
  394. */
  395. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  396. if (!gpe_event_info) {
  397. status = AE_BAD_PARAMETER;
  398. goto unlock_and_exit;
  399. }
  400. if (!(gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) {
  401. status = AE_TYPE;
  402. goto unlock_and_exit;
  403. }
  404. gpe_register_info = gpe_event_info->register_info;
  405. if (!gpe_register_info) {
  406. status = AE_NOT_EXIST;
  407. goto unlock_and_exit;
  408. }
  409. register_bit = acpi_hw_get_gpe_register_bit(gpe_event_info);
  410. /* Perform the action */
  411. switch (action) {
  412. case ACPI_GPE_ENABLE:
  413. ACPI_SET_BIT(gpe_register_info->enable_for_wake,
  414. (u8)register_bit);
  415. break;
  416. case ACPI_GPE_DISABLE:
  417. ACPI_CLEAR_BIT(gpe_register_info->enable_for_wake,
  418. (u8)register_bit);
  419. break;
  420. default:
  421. ACPI_ERROR((AE_INFO, "%u, Invalid action", action));
  422. status = AE_BAD_PARAMETER;
  423. break;
  424. }
  425. unlock_and_exit:
  426. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  427. return_ACPI_STATUS(status);
  428. }
  429. ACPI_EXPORT_SYMBOL(acpi_set_gpe_wake_mask)
  430. /*******************************************************************************
  431. *
  432. * FUNCTION: acpi_clear_gpe
  433. *
  434. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  435. * gpe_number - GPE level within the GPE block
  436. *
  437. * RETURN: Status
  438. *
  439. * DESCRIPTION: Clear an ACPI event (general purpose)
  440. *
  441. ******************************************************************************/
  442. acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number)
  443. {
  444. acpi_status status = AE_OK;
  445. struct acpi_gpe_event_info *gpe_event_info;
  446. acpi_cpu_flags flags;
  447. ACPI_FUNCTION_TRACE(acpi_clear_gpe);
  448. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  449. /* Ensure that we have a valid GPE number */
  450. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  451. if (!gpe_event_info) {
  452. status = AE_BAD_PARAMETER;
  453. goto unlock_and_exit;
  454. }
  455. status = acpi_hw_clear_gpe(gpe_event_info);
  456. unlock_and_exit:
  457. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  458. return_ACPI_STATUS(status);
  459. }
  460. ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
  461. /*******************************************************************************
  462. *
  463. * FUNCTION: acpi_get_gpe_status
  464. *
  465. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  466. * gpe_number - GPE level within the GPE block
  467. * event_status - Where the current status of the event
  468. * will be returned
  469. *
  470. * RETURN: Status
  471. *
  472. * DESCRIPTION: Get the current status of a GPE (signalled/not_signalled)
  473. *
  474. ******************************************************************************/
  475. acpi_status
  476. acpi_get_gpe_status(acpi_handle gpe_device,
  477. u32 gpe_number, acpi_event_status *event_status)
  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_get_gpe_status);
  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. /* Obtain status on the requested GPE number */
  491. status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
  492. unlock_and_exit:
  493. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  494. return_ACPI_STATUS(status);
  495. }
  496. ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
  497. /*******************************************************************************
  498. *
  499. * FUNCTION: acpi_finish_gpe
  500. *
  501. * PARAMETERS: gpe_device - Namespace node for the GPE Block
  502. * (NULL for FADT defined GPEs)
  503. * gpe_number - GPE level within the GPE block
  504. *
  505. * RETURN: Status
  506. *
  507. * DESCRIPTION: Clear and conditionally reenable a GPE. This completes the GPE
  508. * processing. Intended for use by asynchronous host-installed
  509. * GPE handlers. The GPE is only reenabled if the enable_for_run bit
  510. * is set in the GPE info.
  511. *
  512. ******************************************************************************/
  513. acpi_status acpi_finish_gpe(acpi_handle gpe_device, u32 gpe_number)
  514. {
  515. struct acpi_gpe_event_info *gpe_event_info;
  516. acpi_status status;
  517. acpi_cpu_flags flags;
  518. ACPI_FUNCTION_TRACE(acpi_finish_gpe);
  519. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  520. /* Ensure that we have a valid GPE number */
  521. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  522. if (!gpe_event_info) {
  523. status = AE_BAD_PARAMETER;
  524. goto unlock_and_exit;
  525. }
  526. status = acpi_ev_finish_gpe(gpe_event_info);
  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_finish_gpe)
  532. /******************************************************************************
  533. *
  534. * FUNCTION: acpi_disable_all_gpes
  535. *
  536. * PARAMETERS: None
  537. *
  538. * RETURN: Status
  539. *
  540. * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
  541. *
  542. ******************************************************************************/
  543. acpi_status acpi_disable_all_gpes(void)
  544. {
  545. acpi_status status;
  546. ACPI_FUNCTION_TRACE(acpi_disable_all_gpes);
  547. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  548. if (ACPI_FAILURE(status)) {
  549. return_ACPI_STATUS(status);
  550. }
  551. status = acpi_hw_disable_all_gpes();
  552. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  553. return_ACPI_STATUS(status);
  554. }
  555. ACPI_EXPORT_SYMBOL(acpi_disable_all_gpes)
  556. /******************************************************************************
  557. *
  558. * FUNCTION: acpi_enable_all_runtime_gpes
  559. *
  560. * PARAMETERS: None
  561. *
  562. * RETURN: Status
  563. *
  564. * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
  565. *
  566. ******************************************************************************/
  567. acpi_status acpi_enable_all_runtime_gpes(void)
  568. {
  569. acpi_status status;
  570. ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes);
  571. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  572. if (ACPI_FAILURE(status)) {
  573. return_ACPI_STATUS(status);
  574. }
  575. status = acpi_hw_enable_all_runtime_gpes();
  576. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  577. return_ACPI_STATUS(status);
  578. }
  579. ACPI_EXPORT_SYMBOL(acpi_enable_all_runtime_gpes)
  580. /******************************************************************************
  581. *
  582. * FUNCTION: acpi_enable_all_wakeup_gpes
  583. *
  584. * PARAMETERS: None
  585. *
  586. * RETURN: Status
  587. *
  588. * DESCRIPTION: Enable all "wakeup" GPEs and disable all of the other GPEs, in
  589. * all GPE blocks.
  590. *
  591. ******************************************************************************/
  592. acpi_status acpi_enable_all_wakeup_gpes(void)
  593. {
  594. acpi_status status;
  595. ACPI_FUNCTION_TRACE(acpi_enable_all_wakeup_gpes);
  596. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  597. if (ACPI_FAILURE(status)) {
  598. return_ACPI_STATUS(status);
  599. }
  600. status = acpi_hw_enable_all_wakeup_gpes();
  601. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  602. return_ACPI_STATUS(status);
  603. }
  604. ACPI_EXPORT_SYMBOL(acpi_enable_all_wakeup_gpes)
  605. /*******************************************************************************
  606. *
  607. * FUNCTION: acpi_install_gpe_block
  608. *
  609. * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
  610. * gpe_block_address - Address and space_ID
  611. * register_count - Number of GPE register pairs in the block
  612. * interrupt_number - H/W interrupt for the block
  613. *
  614. * RETURN: Status
  615. *
  616. * DESCRIPTION: Create and Install a block of GPE registers. The GPEs are not
  617. * enabled here.
  618. *
  619. ******************************************************************************/
  620. acpi_status
  621. acpi_install_gpe_block(acpi_handle gpe_device,
  622. struct acpi_generic_address *gpe_block_address,
  623. u32 register_count, u32 interrupt_number)
  624. {
  625. acpi_status status;
  626. union acpi_operand_object *obj_desc;
  627. struct acpi_namespace_node *node;
  628. struct acpi_gpe_block_info *gpe_block;
  629. ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
  630. if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
  631. return_ACPI_STATUS(AE_BAD_PARAMETER);
  632. }
  633. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  634. if (ACPI_FAILURE(status)) {
  635. return_ACPI_STATUS(status);
  636. }
  637. node = acpi_ns_validate_handle(gpe_device);
  638. if (!node) {
  639. status = AE_BAD_PARAMETER;
  640. goto unlock_and_exit;
  641. }
  642. /* Validate the parent device */
  643. if (node->type != ACPI_TYPE_DEVICE) {
  644. status = AE_TYPE;
  645. goto unlock_and_exit;
  646. }
  647. if (node->object) {
  648. status = AE_ALREADY_EXISTS;
  649. goto unlock_and_exit;
  650. }
  651. /*
  652. * For user-installed GPE Block Devices, the gpe_block_base_number
  653. * is always zero
  654. */
  655. status = acpi_ev_create_gpe_block(node, gpe_block_address->address,
  656. gpe_block_address->space_id,
  657. register_count, 0, interrupt_number,
  658. &gpe_block);
  659. if (ACPI_FAILURE(status)) {
  660. goto unlock_and_exit;
  661. }
  662. /* Install block in the device_object attached to the node */
  663. obj_desc = acpi_ns_get_attached_object(node);
  664. if (!obj_desc) {
  665. /*
  666. * No object, create a new one (Device nodes do not always have
  667. * an attached object)
  668. */
  669. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
  670. if (!obj_desc) {
  671. status = AE_NO_MEMORY;
  672. goto unlock_and_exit;
  673. }
  674. status =
  675. acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
  676. /* Remove local reference to the object */
  677. acpi_ut_remove_reference(obj_desc);
  678. if (ACPI_FAILURE(status)) {
  679. goto unlock_and_exit;
  680. }
  681. }
  682. /* Now install the GPE block in the device_object */
  683. obj_desc->device.gpe_block = gpe_block;
  684. unlock_and_exit:
  685. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  686. return_ACPI_STATUS(status);
  687. }
  688. ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
  689. /*******************************************************************************
  690. *
  691. * FUNCTION: acpi_remove_gpe_block
  692. *
  693. * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
  694. *
  695. * RETURN: Status
  696. *
  697. * DESCRIPTION: Remove a previously installed block of GPE registers
  698. *
  699. ******************************************************************************/
  700. acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
  701. {
  702. union acpi_operand_object *obj_desc;
  703. acpi_status status;
  704. struct acpi_namespace_node *node;
  705. ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
  706. if (!gpe_device) {
  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. /* Get the device_object attached to the node */
  724. obj_desc = acpi_ns_get_attached_object(node);
  725. if (!obj_desc || !obj_desc->device.gpe_block) {
  726. return_ACPI_STATUS(AE_NULL_OBJECT);
  727. }
  728. /* Delete the GPE block (but not the device_object) */
  729. status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
  730. if (ACPI_SUCCESS(status)) {
  731. obj_desc->device.gpe_block = NULL;
  732. }
  733. unlock_and_exit:
  734. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  735. return_ACPI_STATUS(status);
  736. }
  737. ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)
  738. /*******************************************************************************
  739. *
  740. * FUNCTION: acpi_get_gpe_device
  741. *
  742. * PARAMETERS: index - System GPE index (0-current_gpe_count)
  743. * gpe_device - Where the parent GPE Device is returned
  744. *
  745. * RETURN: Status
  746. *
  747. * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
  748. * gpe device indicates that the gpe number is contained in one of
  749. * the FADT-defined gpe blocks. Otherwise, the GPE block device.
  750. *
  751. ******************************************************************************/
  752. acpi_status acpi_get_gpe_device(u32 index, acpi_handle *gpe_device)
  753. {
  754. struct acpi_gpe_device_info info;
  755. acpi_status status;
  756. ACPI_FUNCTION_TRACE(acpi_get_gpe_device);
  757. if (!gpe_device) {
  758. return_ACPI_STATUS(AE_BAD_PARAMETER);
  759. }
  760. if (index >= acpi_current_gpe_count) {
  761. return_ACPI_STATUS(AE_NOT_EXIST);
  762. }
  763. /* Setup and walk the GPE list */
  764. info.index = index;
  765. info.status = AE_NOT_EXIST;
  766. info.gpe_device = NULL;
  767. info.next_block_base_index = 0;
  768. status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info);
  769. if (ACPI_FAILURE(status)) {
  770. return_ACPI_STATUS(status);
  771. }
  772. *gpe_device = ACPI_CAST_PTR(acpi_handle, info.gpe_device);
  773. return_ACPI_STATUS(info.status);
  774. }
  775. ACPI_EXPORT_SYMBOL(acpi_get_gpe_device)
  776. #endif /* !ACPI_REDUCED_HARDWARE */