evxfgpe.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. /******************************************************************************
  2. *
  3. * Module Name: evxfgpe - External Interfaces for General Purpose Events (GPEs)
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2011, 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. #include <acpi/acpi.h>
  43. #include "accommon.h"
  44. #include "acevents.h"
  45. #include "acnamesp.h"
  46. #define _COMPONENT ACPI_EVENTS
  47. ACPI_MODULE_NAME("evxfgpe")
  48. /******************************************************************************
  49. *
  50. * FUNCTION: acpi_update_all_gpes
  51. *
  52. * PARAMETERS: None
  53. *
  54. * RETURN: Status
  55. *
  56. * DESCRIPTION: Complete GPE initialization and enable all GPEs that have
  57. * associated _Lxx or _Exx methods and are not pointed to by any
  58. * device _PRW methods (this indicates that these GPEs are
  59. * generally intended for system or device wakeup. Such GPEs
  60. * have to be enabled directly when the devices whose _PRW
  61. * methods point to them are set up for wakeup signaling.)
  62. *
  63. * NOTE: Should be called after any GPEs are added to the system. Primarily,
  64. * after the system _PRW methods have been run, but also after a GPE Block
  65. * Device has been added or if any new GPE methods have been added via a
  66. * dynamic table load.
  67. *
  68. ******************************************************************************/
  69. acpi_status acpi_update_all_gpes(void)
  70. {
  71. acpi_status status;
  72. ACPI_FUNCTION_TRACE(acpi_update_all_gpes);
  73. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  74. if (ACPI_FAILURE(status)) {
  75. return_ACPI_STATUS(status);
  76. }
  77. if (acpi_gbl_all_gpes_initialized) {
  78. goto unlock_and_exit;
  79. }
  80. status = acpi_ev_walk_gpe_list(acpi_ev_initialize_gpe_block, NULL);
  81. if (ACPI_SUCCESS(status)) {
  82. acpi_gbl_all_gpes_initialized = TRUE;
  83. }
  84. unlock_and_exit:
  85. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  86. return_ACPI_STATUS(status);
  87. }
  88. ACPI_EXPORT_SYMBOL(acpi_update_all_gpes)
  89. /*******************************************************************************
  90. *
  91. * FUNCTION: acpi_enable_gpe
  92. *
  93. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  94. * gpe_number - GPE level within the GPE block
  95. *
  96. * RETURN: Status
  97. *
  98. * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
  99. * hardware-enabled.
  100. *
  101. ******************************************************************************/
  102. acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number)
  103. {
  104. acpi_status status = AE_BAD_PARAMETER;
  105. struct acpi_gpe_event_info *gpe_event_info;
  106. acpi_cpu_flags flags;
  107. ACPI_FUNCTION_TRACE(acpi_enable_gpe);
  108. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  109. /* Ensure that we have a valid GPE number */
  110. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  111. if (gpe_event_info) {
  112. status = acpi_ev_add_gpe_reference(gpe_event_info);
  113. }
  114. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  115. return_ACPI_STATUS(status);
  116. }
  117. ACPI_EXPORT_SYMBOL(acpi_enable_gpe)
  118. /*******************************************************************************
  119. *
  120. * FUNCTION: acpi_disable_gpe
  121. *
  122. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  123. * gpe_number - GPE level within the GPE block
  124. *
  125. * RETURN: Status
  126. *
  127. * DESCRIPTION: Remove a reference to a GPE. When the last reference is
  128. * removed, only then is the GPE disabled (for runtime GPEs), or
  129. * the GPE mask bit disabled (for wake GPEs)
  130. *
  131. ******************************************************************************/
  132. acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number)
  133. {
  134. acpi_status status = AE_BAD_PARAMETER;
  135. struct acpi_gpe_event_info *gpe_event_info;
  136. acpi_cpu_flags flags;
  137. ACPI_FUNCTION_TRACE(acpi_disable_gpe);
  138. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  139. /* Ensure that we have a valid GPE number */
  140. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  141. if (gpe_event_info) {
  142. status = acpi_ev_remove_gpe_reference(gpe_event_info) ;
  143. }
  144. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  145. return_ACPI_STATUS(status);
  146. }
  147. ACPI_EXPORT_SYMBOL(acpi_disable_gpe)
  148. /*******************************************************************************
  149. *
  150. * FUNCTION: acpi_setup_gpe_for_wake
  151. *
  152. * PARAMETERS: wake_device - Device associated with the GPE (via _PRW)
  153. * gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  154. * gpe_number - GPE level within the GPE block
  155. *
  156. * RETURN: Status
  157. *
  158. * DESCRIPTION: Mark a GPE as having the ability to wake the system. This
  159. * interface is intended to be used as the host executes the
  160. * _PRW methods (Power Resources for Wake) in the system tables.
  161. * Each _PRW appears under a Device Object (The wake_device), and
  162. * contains the info for the wake GPE associated with the
  163. * wake_device.
  164. *
  165. ******************************************************************************/
  166. acpi_status
  167. acpi_setup_gpe_for_wake(acpi_handle wake_device,
  168. acpi_handle gpe_device, u32 gpe_number)
  169. {
  170. acpi_status status = AE_BAD_PARAMETER;
  171. struct acpi_gpe_event_info *gpe_event_info;
  172. struct acpi_namespace_node *device_node;
  173. acpi_cpu_flags flags;
  174. ACPI_FUNCTION_TRACE(acpi_setup_gpe_for_wake);
  175. /* Parameter Validation */
  176. if (!wake_device) {
  177. /*
  178. * By forcing wake_device to be valid, we automatically enable the
  179. * implicit notify feature on all hosts.
  180. */
  181. return_ACPI_STATUS(AE_BAD_PARAMETER);
  182. }
  183. /* Validate wake_device is of type Device */
  184. device_node = ACPI_CAST_PTR(struct acpi_namespace_node, wake_device);
  185. if (device_node->type != ACPI_TYPE_DEVICE) {
  186. return_ACPI_STATUS(AE_BAD_PARAMETER);
  187. }
  188. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  189. /* Ensure that we have a valid GPE number */
  190. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  191. if (gpe_event_info) {
  192. /*
  193. * If there is no method or handler for this GPE, then the
  194. * wake_device will be notified whenever this GPE fires (aka
  195. * "implicit notify") Note: The GPE is assumed to be
  196. * level-triggered (for windows compatibility).
  197. */
  198. if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
  199. ACPI_GPE_DISPATCH_NONE) {
  200. gpe_event_info->flags =
  201. (ACPI_GPE_DISPATCH_NOTIFY |
  202. ACPI_GPE_LEVEL_TRIGGERED);
  203. gpe_event_info->dispatch.device_node = device_node;
  204. }
  205. gpe_event_info->flags |= ACPI_GPE_CAN_WAKE;
  206. status = AE_OK;
  207. }
  208. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  209. return_ACPI_STATUS(status);
  210. }
  211. ACPI_EXPORT_SYMBOL(acpi_setup_gpe_for_wake)
  212. /*******************************************************************************
  213. *
  214. * FUNCTION: acpi_set_gpe_wake_mask
  215. *
  216. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  217. * gpe_number - GPE level within the GPE block
  218. * Action - Enable or Disable
  219. *
  220. * RETURN: Status
  221. *
  222. * DESCRIPTION: Set or clear the GPE's wakeup enable mask bit. The GPE must
  223. * already be marked as a WAKE GPE.
  224. *
  225. ******************************************************************************/
  226. acpi_status acpi_set_gpe_wake_mask(acpi_handle gpe_device, u32 gpe_number, u8 action)
  227. {
  228. acpi_status status = AE_OK;
  229. struct acpi_gpe_event_info *gpe_event_info;
  230. struct acpi_gpe_register_info *gpe_register_info;
  231. acpi_cpu_flags flags;
  232. u32 register_bit;
  233. ACPI_FUNCTION_TRACE(acpi_set_gpe_wake_mask);
  234. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  235. /*
  236. * Ensure that we have a valid GPE number and that this GPE is in
  237. * fact a wake GPE
  238. */
  239. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  240. if (!gpe_event_info) {
  241. status = AE_BAD_PARAMETER;
  242. goto unlock_and_exit;
  243. }
  244. if (!(gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) {
  245. status = AE_TYPE;
  246. goto unlock_and_exit;
  247. }
  248. gpe_register_info = gpe_event_info->register_info;
  249. if (!gpe_register_info) {
  250. status = AE_NOT_EXIST;
  251. goto unlock_and_exit;
  252. }
  253. register_bit =
  254. acpi_hw_get_gpe_register_bit(gpe_event_info, gpe_register_info);
  255. /* Perform the action */
  256. switch (action) {
  257. case ACPI_GPE_ENABLE:
  258. ACPI_SET_BIT(gpe_register_info->enable_for_wake,
  259. (u8)register_bit);
  260. break;
  261. case ACPI_GPE_DISABLE:
  262. ACPI_CLEAR_BIT(gpe_register_info->enable_for_wake,
  263. (u8)register_bit);
  264. break;
  265. default:
  266. ACPI_ERROR((AE_INFO, "%u, Invalid action", action));
  267. status = AE_BAD_PARAMETER;
  268. break;
  269. }
  270. unlock_and_exit:
  271. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  272. return_ACPI_STATUS(status);
  273. }
  274. ACPI_EXPORT_SYMBOL(acpi_set_gpe_wake_mask)
  275. /*******************************************************************************
  276. *
  277. * FUNCTION: acpi_clear_gpe
  278. *
  279. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  280. * gpe_number - GPE level within the GPE block
  281. *
  282. * RETURN: Status
  283. *
  284. * DESCRIPTION: Clear an ACPI event (general purpose)
  285. *
  286. ******************************************************************************/
  287. acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number)
  288. {
  289. acpi_status status = AE_OK;
  290. struct acpi_gpe_event_info *gpe_event_info;
  291. acpi_cpu_flags flags;
  292. ACPI_FUNCTION_TRACE(acpi_clear_gpe);
  293. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  294. /* Ensure that we have a valid GPE number */
  295. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  296. if (!gpe_event_info) {
  297. status = AE_BAD_PARAMETER;
  298. goto unlock_and_exit;
  299. }
  300. status = acpi_hw_clear_gpe(gpe_event_info);
  301. unlock_and_exit:
  302. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  303. return_ACPI_STATUS(status);
  304. }
  305. ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
  306. /*******************************************************************************
  307. *
  308. * FUNCTION: acpi_get_gpe_status
  309. *
  310. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  311. * gpe_number - GPE level within the GPE block
  312. * event_status - Where the current status of the event will
  313. * be returned
  314. *
  315. * RETURN: Status
  316. *
  317. * DESCRIPTION: Get the current status of a GPE (signalled/not_signalled)
  318. *
  319. ******************************************************************************/
  320. acpi_status
  321. acpi_get_gpe_status(acpi_handle gpe_device,
  322. u32 gpe_number, acpi_event_status *event_status)
  323. {
  324. acpi_status status = AE_OK;
  325. struct acpi_gpe_event_info *gpe_event_info;
  326. acpi_cpu_flags flags;
  327. ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
  328. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  329. /* Ensure that we have a valid GPE number */
  330. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  331. if (!gpe_event_info) {
  332. status = AE_BAD_PARAMETER;
  333. goto unlock_and_exit;
  334. }
  335. /* Obtain status on the requested GPE number */
  336. status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
  337. if (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)
  338. *event_status |= ACPI_EVENT_FLAG_HANDLE;
  339. unlock_and_exit:
  340. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  341. return_ACPI_STATUS(status);
  342. }
  343. ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
  344. /******************************************************************************
  345. *
  346. * FUNCTION: acpi_disable_all_gpes
  347. *
  348. * PARAMETERS: None
  349. *
  350. * RETURN: Status
  351. *
  352. * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
  353. *
  354. ******************************************************************************/
  355. acpi_status acpi_disable_all_gpes(void)
  356. {
  357. acpi_status status;
  358. ACPI_FUNCTION_TRACE(acpi_disable_all_gpes);
  359. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  360. if (ACPI_FAILURE(status)) {
  361. return_ACPI_STATUS(status);
  362. }
  363. status = acpi_hw_disable_all_gpes();
  364. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  365. return_ACPI_STATUS(status);
  366. }
  367. ACPI_EXPORT_SYMBOL(acpi_disable_all_gpes)
  368. /******************************************************************************
  369. *
  370. * FUNCTION: acpi_enable_all_runtime_gpes
  371. *
  372. * PARAMETERS: None
  373. *
  374. * RETURN: Status
  375. *
  376. * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
  377. *
  378. ******************************************************************************/
  379. acpi_status acpi_enable_all_runtime_gpes(void)
  380. {
  381. acpi_status status;
  382. ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes);
  383. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  384. if (ACPI_FAILURE(status)) {
  385. return_ACPI_STATUS(status);
  386. }
  387. status = acpi_hw_enable_all_runtime_gpes();
  388. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  389. return_ACPI_STATUS(status);
  390. }
  391. ACPI_EXPORT_SYMBOL(acpi_enable_all_runtime_gpes)
  392. /*******************************************************************************
  393. *
  394. * FUNCTION: acpi_install_gpe_block
  395. *
  396. * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
  397. * gpe_block_address - Address and space_iD
  398. * register_count - Number of GPE register pairs in the block
  399. * interrupt_number - H/W interrupt for the block
  400. *
  401. * RETURN: Status
  402. *
  403. * DESCRIPTION: Create and Install a block of GPE registers. The GPEs are not
  404. * enabled here.
  405. *
  406. ******************************************************************************/
  407. acpi_status
  408. acpi_install_gpe_block(acpi_handle gpe_device,
  409. struct acpi_generic_address *gpe_block_address,
  410. u32 register_count, u32 interrupt_number)
  411. {
  412. acpi_status status;
  413. union acpi_operand_object *obj_desc;
  414. struct acpi_namespace_node *node;
  415. struct acpi_gpe_block_info *gpe_block;
  416. ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
  417. if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
  418. return_ACPI_STATUS(AE_BAD_PARAMETER);
  419. }
  420. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  421. if (ACPI_FAILURE(status)) {
  422. return (status);
  423. }
  424. node = acpi_ns_validate_handle(gpe_device);
  425. if (!node) {
  426. status = AE_BAD_PARAMETER;
  427. goto unlock_and_exit;
  428. }
  429. /*
  430. * For user-installed GPE Block Devices, the gpe_block_base_number
  431. * is always zero
  432. */
  433. status =
  434. acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0,
  435. interrupt_number, &gpe_block);
  436. if (ACPI_FAILURE(status)) {
  437. goto unlock_and_exit;
  438. }
  439. /* Install block in the device_object attached to the node */
  440. obj_desc = acpi_ns_get_attached_object(node);
  441. if (!obj_desc) {
  442. /*
  443. * No object, create a new one (Device nodes do not always have
  444. * an attached object)
  445. */
  446. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
  447. if (!obj_desc) {
  448. status = AE_NO_MEMORY;
  449. goto unlock_and_exit;
  450. }
  451. status =
  452. acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
  453. /* Remove local reference to the object */
  454. acpi_ut_remove_reference(obj_desc);
  455. if (ACPI_FAILURE(status)) {
  456. goto unlock_and_exit;
  457. }
  458. }
  459. /* Now install the GPE block in the device_object */
  460. obj_desc->device.gpe_block = gpe_block;
  461. unlock_and_exit:
  462. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  463. return_ACPI_STATUS(status);
  464. }
  465. ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
  466. /*******************************************************************************
  467. *
  468. * FUNCTION: acpi_remove_gpe_block
  469. *
  470. * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
  471. *
  472. * RETURN: Status
  473. *
  474. * DESCRIPTION: Remove a previously installed block of GPE registers
  475. *
  476. ******************************************************************************/
  477. acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
  478. {
  479. union acpi_operand_object *obj_desc;
  480. acpi_status status;
  481. struct acpi_namespace_node *node;
  482. ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
  483. if (!gpe_device) {
  484. return_ACPI_STATUS(AE_BAD_PARAMETER);
  485. }
  486. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  487. if (ACPI_FAILURE(status)) {
  488. return (status);
  489. }
  490. node = acpi_ns_validate_handle(gpe_device);
  491. if (!node) {
  492. status = AE_BAD_PARAMETER;
  493. goto unlock_and_exit;
  494. }
  495. /* Get the device_object attached to the node */
  496. obj_desc = acpi_ns_get_attached_object(node);
  497. if (!obj_desc || !obj_desc->device.gpe_block) {
  498. return_ACPI_STATUS(AE_NULL_OBJECT);
  499. }
  500. /* Delete the GPE block (but not the device_object) */
  501. status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
  502. if (ACPI_SUCCESS(status)) {
  503. obj_desc->device.gpe_block = NULL;
  504. }
  505. unlock_and_exit:
  506. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  507. return_ACPI_STATUS(status);
  508. }
  509. ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)
  510. /*******************************************************************************
  511. *
  512. * FUNCTION: acpi_get_gpe_device
  513. *
  514. * PARAMETERS: Index - System GPE index (0-current_gpe_count)
  515. * gpe_device - Where the parent GPE Device is returned
  516. *
  517. * RETURN: Status
  518. *
  519. * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
  520. * gpe device indicates that the gpe number is contained in one of
  521. * the FADT-defined gpe blocks. Otherwise, the GPE block device.
  522. *
  523. ******************************************************************************/
  524. acpi_status
  525. acpi_get_gpe_device(u32 index, acpi_handle *gpe_device)
  526. {
  527. struct acpi_gpe_device_info info;
  528. acpi_status status;
  529. ACPI_FUNCTION_TRACE(acpi_get_gpe_device);
  530. if (!gpe_device) {
  531. return_ACPI_STATUS(AE_BAD_PARAMETER);
  532. }
  533. if (index >= acpi_current_gpe_count) {
  534. return_ACPI_STATUS(AE_NOT_EXIST);
  535. }
  536. /* Setup and walk the GPE list */
  537. info.index = index;
  538. info.status = AE_NOT_EXIST;
  539. info.gpe_device = NULL;
  540. info.next_block_base_index = 0;
  541. status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info);
  542. if (ACPI_FAILURE(status)) {
  543. return_ACPI_STATUS(status);
  544. }
  545. *gpe_device = ACPI_CAST_PTR(acpi_handle, info.gpe_device);
  546. return_ACPI_STATUS(info.status);
  547. }
  548. ACPI_EXPORT_SYMBOL(acpi_get_gpe_device)