evxfgpe.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811
  1. /******************************************************************************
  2. *
  3. * Module Name: evxfgpe - External Interfaces for General Purpose Events (GPEs)
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2014, 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 ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) !=
  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_mark_gpe_for_wake
  162. *
  163. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  164. * gpe_number - GPE level within the GPE block
  165. *
  166. * RETURN: Status
  167. *
  168. * DESCRIPTION: Mark a GPE as having the ability to wake the system. Simply
  169. * sets the ACPI_GPE_CAN_WAKE flag.
  170. *
  171. * Some potential callers of acpi_setup_gpe_for_wake may know in advance that
  172. * there won't be any notify handlers installed for device wake notifications
  173. * from the given GPE (one example is a button GPE in Linux). For these cases,
  174. * acpi_mark_gpe_for_wake should be used instead of acpi_setup_gpe_for_wake.
  175. * This will set the ACPI_GPE_CAN_WAKE flag for the GPE without trying to
  176. * setup implicit wake notification for it (since there's no handler method).
  177. *
  178. ******************************************************************************/
  179. acpi_status acpi_mark_gpe_for_wake(acpi_handle gpe_device, u32 gpe_number)
  180. {
  181. struct acpi_gpe_event_info *gpe_event_info;
  182. acpi_status status = AE_BAD_PARAMETER;
  183. acpi_cpu_flags flags;
  184. ACPI_FUNCTION_TRACE(acpi_mark_gpe_for_wake);
  185. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  186. /* Ensure that we have a valid GPE number */
  187. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  188. if (gpe_event_info) {
  189. /* Mark the GPE as a possible wake event */
  190. gpe_event_info->flags |= ACPI_GPE_CAN_WAKE;
  191. status = AE_OK;
  192. }
  193. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  194. return_ACPI_STATUS(status);
  195. }
  196. ACPI_EXPORT_SYMBOL(acpi_mark_gpe_for_wake)
  197. /*******************************************************************************
  198. *
  199. * FUNCTION: acpi_setup_gpe_for_wake
  200. *
  201. * PARAMETERS: wake_device - Device associated with the GPE (via _PRW)
  202. * gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  203. * gpe_number - GPE level within the GPE block
  204. *
  205. * RETURN: Status
  206. *
  207. * DESCRIPTION: Mark a GPE as having the ability to wake the system. This
  208. * interface is intended to be used as the host executes the
  209. * _PRW methods (Power Resources for Wake) in the system tables.
  210. * Each _PRW appears under a Device Object (The wake_device), and
  211. * contains the info for the wake GPE associated with the
  212. * wake_device.
  213. *
  214. ******************************************************************************/
  215. acpi_status
  216. acpi_setup_gpe_for_wake(acpi_handle wake_device,
  217. acpi_handle gpe_device, u32 gpe_number)
  218. {
  219. acpi_status status;
  220. struct acpi_gpe_event_info *gpe_event_info;
  221. struct acpi_namespace_node *device_node;
  222. struct acpi_gpe_notify_info *notify;
  223. struct acpi_gpe_notify_info *new_notify;
  224. acpi_cpu_flags flags;
  225. ACPI_FUNCTION_TRACE(acpi_setup_gpe_for_wake);
  226. /* Parameter Validation */
  227. if (!wake_device) {
  228. /*
  229. * By forcing wake_device to be valid, we automatically enable the
  230. * implicit notify feature on all hosts.
  231. */
  232. return_ACPI_STATUS(AE_BAD_PARAMETER);
  233. }
  234. /* Handle root object case */
  235. if (wake_device == ACPI_ROOT_OBJECT) {
  236. device_node = acpi_gbl_root_node;
  237. } else {
  238. device_node =
  239. ACPI_CAST_PTR(struct acpi_namespace_node, wake_device);
  240. }
  241. /* Validate wake_device is of type Device */
  242. if (device_node->type != ACPI_TYPE_DEVICE) {
  243. return_ACPI_STATUS (AE_BAD_PARAMETER);
  244. }
  245. /*
  246. * Allocate a new notify object up front, in case it is needed.
  247. * Memory allocation while holding a spinlock is a big no-no
  248. * on some hosts.
  249. */
  250. new_notify = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_notify_info));
  251. if (!new_notify) {
  252. return_ACPI_STATUS(AE_NO_MEMORY);
  253. }
  254. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  255. /* Ensure that we have a valid GPE number */
  256. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  257. if (!gpe_event_info) {
  258. status = AE_BAD_PARAMETER;
  259. goto unlock_and_exit;
  260. }
  261. /*
  262. * If there is no method or handler for this GPE, then the
  263. * wake_device will be notified whenever this GPE fires. This is
  264. * known as an "implicit notify". Note: The GPE is assumed to be
  265. * level-triggered (for windows compatibility).
  266. */
  267. if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
  268. ACPI_GPE_DISPATCH_NONE) {
  269. /*
  270. * This is the first device for implicit notify on this GPE.
  271. * Just set the flags here, and enter the NOTIFY block below.
  272. */
  273. gpe_event_info->flags =
  274. (ACPI_GPE_DISPATCH_NOTIFY | ACPI_GPE_LEVEL_TRIGGERED);
  275. }
  276. /*
  277. * If we already have an implicit notify on this GPE, add
  278. * this device to the notify list.
  279. */
  280. if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
  281. ACPI_GPE_DISPATCH_NOTIFY) {
  282. /* Ensure that the device is not already in the list */
  283. notify = gpe_event_info->dispatch.notify_list;
  284. while (notify) {
  285. if (notify->device_node == device_node) {
  286. status = AE_ALREADY_EXISTS;
  287. goto unlock_and_exit;
  288. }
  289. notify = notify->next;
  290. }
  291. /* Add this device to the notify list for this GPE */
  292. new_notify->device_node = device_node;
  293. new_notify->next = gpe_event_info->dispatch.notify_list;
  294. gpe_event_info->dispatch.notify_list = new_notify;
  295. new_notify = NULL;
  296. }
  297. /* Mark the GPE as a possible wake event */
  298. gpe_event_info->flags |= ACPI_GPE_CAN_WAKE;
  299. status = AE_OK;
  300. unlock_and_exit:
  301. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  302. /* Delete the notify object if it was not used above */
  303. if (new_notify) {
  304. ACPI_FREE(new_notify);
  305. }
  306. return_ACPI_STATUS(status);
  307. }
  308. ACPI_EXPORT_SYMBOL(acpi_setup_gpe_for_wake)
  309. /*******************************************************************************
  310. *
  311. * FUNCTION: acpi_set_gpe_wake_mask
  312. *
  313. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  314. * gpe_number - GPE level within the GPE block
  315. * action - Enable or Disable
  316. *
  317. * RETURN: Status
  318. *
  319. * DESCRIPTION: Set or clear the GPE's wakeup enable mask bit. The GPE must
  320. * already be marked as a WAKE GPE.
  321. *
  322. ******************************************************************************/
  323. acpi_status
  324. acpi_set_gpe_wake_mask(acpi_handle gpe_device, u32 gpe_number, u8 action)
  325. {
  326. acpi_status status = AE_OK;
  327. struct acpi_gpe_event_info *gpe_event_info;
  328. struct acpi_gpe_register_info *gpe_register_info;
  329. acpi_cpu_flags flags;
  330. u32 register_bit;
  331. ACPI_FUNCTION_TRACE(acpi_set_gpe_wake_mask);
  332. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  333. /*
  334. * Ensure that we have a valid GPE number and that this GPE is in
  335. * fact a wake GPE
  336. */
  337. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  338. if (!gpe_event_info) {
  339. status = AE_BAD_PARAMETER;
  340. goto unlock_and_exit;
  341. }
  342. if (!(gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) {
  343. status = AE_TYPE;
  344. goto unlock_and_exit;
  345. }
  346. gpe_register_info = gpe_event_info->register_info;
  347. if (!gpe_register_info) {
  348. status = AE_NOT_EXIST;
  349. goto unlock_and_exit;
  350. }
  351. register_bit = acpi_hw_get_gpe_register_bit(gpe_event_info);
  352. /* Perform the action */
  353. switch (action) {
  354. case ACPI_GPE_ENABLE:
  355. ACPI_SET_BIT(gpe_register_info->enable_for_wake,
  356. (u8)register_bit);
  357. break;
  358. case ACPI_GPE_DISABLE:
  359. ACPI_CLEAR_BIT(gpe_register_info->enable_for_wake,
  360. (u8)register_bit);
  361. break;
  362. default:
  363. ACPI_ERROR((AE_INFO, "%u, Invalid action", action));
  364. status = AE_BAD_PARAMETER;
  365. break;
  366. }
  367. unlock_and_exit:
  368. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  369. return_ACPI_STATUS(status);
  370. }
  371. ACPI_EXPORT_SYMBOL(acpi_set_gpe_wake_mask)
  372. /*******************************************************************************
  373. *
  374. * FUNCTION: acpi_clear_gpe
  375. *
  376. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  377. * gpe_number - GPE level within the GPE block
  378. *
  379. * RETURN: Status
  380. *
  381. * DESCRIPTION: Clear an ACPI event (general purpose)
  382. *
  383. ******************************************************************************/
  384. acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number)
  385. {
  386. acpi_status status = AE_OK;
  387. struct acpi_gpe_event_info *gpe_event_info;
  388. acpi_cpu_flags flags;
  389. ACPI_FUNCTION_TRACE(acpi_clear_gpe);
  390. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  391. /* Ensure that we have a valid GPE number */
  392. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  393. if (!gpe_event_info) {
  394. status = AE_BAD_PARAMETER;
  395. goto unlock_and_exit;
  396. }
  397. status = acpi_hw_clear_gpe(gpe_event_info);
  398. unlock_and_exit:
  399. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  400. return_ACPI_STATUS(status);
  401. }
  402. ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
  403. /*******************************************************************************
  404. *
  405. * FUNCTION: acpi_get_gpe_status
  406. *
  407. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  408. * gpe_number - GPE level within the GPE block
  409. * event_status - Where the current status of the event
  410. * will be returned
  411. *
  412. * RETURN: Status
  413. *
  414. * DESCRIPTION: Get the current status of a GPE (signalled/not_signalled)
  415. *
  416. ******************************************************************************/
  417. acpi_status
  418. acpi_get_gpe_status(acpi_handle gpe_device,
  419. u32 gpe_number, acpi_event_status *event_status)
  420. {
  421. acpi_status status = AE_OK;
  422. struct acpi_gpe_event_info *gpe_event_info;
  423. acpi_cpu_flags flags;
  424. ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
  425. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  426. /* Ensure that we have a valid GPE number */
  427. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  428. if (!gpe_event_info) {
  429. status = AE_BAD_PARAMETER;
  430. goto unlock_and_exit;
  431. }
  432. /* Obtain status on the requested GPE number */
  433. status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
  434. if (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)
  435. *event_status |= ACPI_EVENT_FLAG_HANDLE;
  436. unlock_and_exit:
  437. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  438. return_ACPI_STATUS(status);
  439. }
  440. ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
  441. /******************************************************************************
  442. *
  443. * FUNCTION: acpi_disable_all_gpes
  444. *
  445. * PARAMETERS: None
  446. *
  447. * RETURN: Status
  448. *
  449. * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
  450. *
  451. ******************************************************************************/
  452. acpi_status acpi_disable_all_gpes(void)
  453. {
  454. acpi_status status;
  455. ACPI_FUNCTION_TRACE(acpi_disable_all_gpes);
  456. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  457. if (ACPI_FAILURE(status)) {
  458. return_ACPI_STATUS(status);
  459. }
  460. status = acpi_hw_disable_all_gpes();
  461. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  462. return_ACPI_STATUS(status);
  463. }
  464. ACPI_EXPORT_SYMBOL(acpi_disable_all_gpes)
  465. /******************************************************************************
  466. *
  467. * FUNCTION: acpi_enable_all_runtime_gpes
  468. *
  469. * PARAMETERS: None
  470. *
  471. * RETURN: Status
  472. *
  473. * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
  474. *
  475. ******************************************************************************/
  476. acpi_status acpi_enable_all_runtime_gpes(void)
  477. {
  478. acpi_status status;
  479. ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes);
  480. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  481. if (ACPI_FAILURE(status)) {
  482. return_ACPI_STATUS(status);
  483. }
  484. status = acpi_hw_enable_all_runtime_gpes();
  485. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  486. return_ACPI_STATUS(status);
  487. }
  488. ACPI_EXPORT_SYMBOL(acpi_enable_all_runtime_gpes)
  489. /*******************************************************************************
  490. *
  491. * FUNCTION: acpi_install_gpe_block
  492. *
  493. * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
  494. * gpe_block_address - Address and space_ID
  495. * register_count - Number of GPE register pairs in the block
  496. * interrupt_number - H/W interrupt for the block
  497. *
  498. * RETURN: Status
  499. *
  500. * DESCRIPTION: Create and Install a block of GPE registers. The GPEs are not
  501. * enabled here.
  502. *
  503. ******************************************************************************/
  504. acpi_status
  505. acpi_install_gpe_block(acpi_handle gpe_device,
  506. struct acpi_generic_address *gpe_block_address,
  507. u32 register_count, u32 interrupt_number)
  508. {
  509. acpi_status status;
  510. union acpi_operand_object *obj_desc;
  511. struct acpi_namespace_node *node;
  512. struct acpi_gpe_block_info *gpe_block;
  513. ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
  514. if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
  515. return_ACPI_STATUS(AE_BAD_PARAMETER);
  516. }
  517. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  518. if (ACPI_FAILURE(status)) {
  519. return_ACPI_STATUS(status);
  520. }
  521. node = acpi_ns_validate_handle(gpe_device);
  522. if (!node) {
  523. status = AE_BAD_PARAMETER;
  524. goto unlock_and_exit;
  525. }
  526. /* Validate the parent device */
  527. if (node->type != ACPI_TYPE_DEVICE) {
  528. status = AE_TYPE;
  529. goto unlock_and_exit;
  530. }
  531. if (node->object) {
  532. status = AE_ALREADY_EXISTS;
  533. goto unlock_and_exit;
  534. }
  535. /*
  536. * For user-installed GPE Block Devices, the gpe_block_base_number
  537. * is always zero
  538. */
  539. status = acpi_ev_create_gpe_block(node, gpe_block_address->address,
  540. gpe_block_address->space_id,
  541. register_count, 0, interrupt_number,
  542. &gpe_block);
  543. if (ACPI_FAILURE(status)) {
  544. goto unlock_and_exit;
  545. }
  546. /* Install block in the device_object attached to the node */
  547. obj_desc = acpi_ns_get_attached_object(node);
  548. if (!obj_desc) {
  549. /*
  550. * No object, create a new one (Device nodes do not always have
  551. * an attached object)
  552. */
  553. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
  554. if (!obj_desc) {
  555. status = AE_NO_MEMORY;
  556. goto unlock_and_exit;
  557. }
  558. status =
  559. acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
  560. /* Remove local reference to the object */
  561. acpi_ut_remove_reference(obj_desc);
  562. if (ACPI_FAILURE(status)) {
  563. goto unlock_and_exit;
  564. }
  565. }
  566. /* Now install the GPE block in the device_object */
  567. obj_desc->device.gpe_block = gpe_block;
  568. unlock_and_exit:
  569. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  570. return_ACPI_STATUS(status);
  571. }
  572. ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
  573. /*******************************************************************************
  574. *
  575. * FUNCTION: acpi_remove_gpe_block
  576. *
  577. * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
  578. *
  579. * RETURN: Status
  580. *
  581. * DESCRIPTION: Remove a previously installed block of GPE registers
  582. *
  583. ******************************************************************************/
  584. acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
  585. {
  586. union acpi_operand_object *obj_desc;
  587. acpi_status status;
  588. struct acpi_namespace_node *node;
  589. ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
  590. if (!gpe_device) {
  591. return_ACPI_STATUS(AE_BAD_PARAMETER);
  592. }
  593. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  594. if (ACPI_FAILURE(status)) {
  595. return_ACPI_STATUS(status);
  596. }
  597. node = acpi_ns_validate_handle(gpe_device);
  598. if (!node) {
  599. status = AE_BAD_PARAMETER;
  600. goto unlock_and_exit;
  601. }
  602. /* Validate the parent device */
  603. if (node->type != ACPI_TYPE_DEVICE) {
  604. status = AE_TYPE;
  605. goto unlock_and_exit;
  606. }
  607. /* Get the device_object attached to the node */
  608. obj_desc = acpi_ns_get_attached_object(node);
  609. if (!obj_desc || !obj_desc->device.gpe_block) {
  610. return_ACPI_STATUS(AE_NULL_OBJECT);
  611. }
  612. /* Delete the GPE block (but not the device_object) */
  613. status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
  614. if (ACPI_SUCCESS(status)) {
  615. obj_desc->device.gpe_block = NULL;
  616. }
  617. unlock_and_exit:
  618. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  619. return_ACPI_STATUS(status);
  620. }
  621. ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)
  622. /*******************************************************************************
  623. *
  624. * FUNCTION: acpi_get_gpe_device
  625. *
  626. * PARAMETERS: index - System GPE index (0-current_gpe_count)
  627. * gpe_device - Where the parent GPE Device is returned
  628. *
  629. * RETURN: Status
  630. *
  631. * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
  632. * gpe device indicates that the gpe number is contained in one of
  633. * the FADT-defined gpe blocks. Otherwise, the GPE block device.
  634. *
  635. ******************************************************************************/
  636. acpi_status acpi_get_gpe_device(u32 index, acpi_handle * gpe_device)
  637. {
  638. struct acpi_gpe_device_info info;
  639. acpi_status status;
  640. ACPI_FUNCTION_TRACE(acpi_get_gpe_device);
  641. if (!gpe_device) {
  642. return_ACPI_STATUS(AE_BAD_PARAMETER);
  643. }
  644. if (index >= acpi_current_gpe_count) {
  645. return_ACPI_STATUS(AE_NOT_EXIST);
  646. }
  647. /* Setup and walk the GPE list */
  648. info.index = index;
  649. info.status = AE_NOT_EXIST;
  650. info.gpe_device = NULL;
  651. info.next_block_base_index = 0;
  652. status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info);
  653. if (ACPI_FAILURE(status)) {
  654. return_ACPI_STATUS(status);
  655. }
  656. *gpe_device = ACPI_CAST_PTR(acpi_handle, info.gpe_device);
  657. return_ACPI_STATUS(info.status);
  658. }
  659. ACPI_EXPORT_SYMBOL(acpi_get_gpe_device)
  660. #endif /* !ACPI_REDUCED_HARDWARE */