evxfgpe.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  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. struct acpi_gpe_notify_object *notify_object;
  174. acpi_cpu_flags flags;
  175. u8 gpe_dispatch_mask;
  176. ACPI_FUNCTION_TRACE(acpi_setup_gpe_for_wake);
  177. /* Parameter Validation */
  178. if (!wake_device) {
  179. /*
  180. * By forcing wake_device to be valid, we automatically enable the
  181. * implicit notify feature on all hosts.
  182. */
  183. return_ACPI_STATUS(AE_BAD_PARAMETER);
  184. }
  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. goto unlock_and_exit;
  190. }
  191. if (wake_device == ACPI_ROOT_OBJECT) {
  192. goto out;
  193. }
  194. /*
  195. * If there is no method or handler for this GPE, then the
  196. * wake_device will be notified whenever this GPE fires (aka
  197. * "implicit notify") Note: The GPE is assumed to be
  198. * level-triggered (for windows compatibility).
  199. */
  200. gpe_dispatch_mask = gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK;
  201. if (gpe_dispatch_mask != ACPI_GPE_DISPATCH_NONE
  202. && gpe_dispatch_mask != ACPI_GPE_DISPATCH_NOTIFY) {
  203. goto out;
  204. }
  205. /* Validate wake_device is of type Device */
  206. device_node = ACPI_CAST_PTR(struct acpi_namespace_node, wake_device);
  207. if (device_node->type != ACPI_TYPE_DEVICE) {
  208. goto unlock_and_exit;
  209. }
  210. if (gpe_dispatch_mask == ACPI_GPE_DISPATCH_NONE) {
  211. gpe_event_info->flags = (ACPI_GPE_DISPATCH_NOTIFY |
  212. ACPI_GPE_LEVEL_TRIGGERED);
  213. gpe_event_info->dispatch.device.node = device_node;
  214. gpe_event_info->dispatch.device.next = NULL;
  215. } else {
  216. /* There are multiple devices to notify implicitly. */
  217. notify_object = ACPI_ALLOCATE_ZEROED(sizeof(*notify_object));
  218. if (!notify_object) {
  219. status = AE_NO_MEMORY;
  220. goto unlock_and_exit;
  221. }
  222. notify_object->node = device_node;
  223. notify_object->next = gpe_event_info->dispatch.device.next;
  224. gpe_event_info->dispatch.device.next = notify_object;
  225. }
  226. out:
  227. gpe_event_info->flags |= ACPI_GPE_CAN_WAKE;
  228. status = AE_OK;
  229. unlock_and_exit:
  230. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  231. return_ACPI_STATUS(status);
  232. }
  233. ACPI_EXPORT_SYMBOL(acpi_setup_gpe_for_wake)
  234. /*******************************************************************************
  235. *
  236. * FUNCTION: acpi_set_gpe_wake_mask
  237. *
  238. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  239. * gpe_number - GPE level within the GPE block
  240. * Action - Enable or Disable
  241. *
  242. * RETURN: Status
  243. *
  244. * DESCRIPTION: Set or clear the GPE's wakeup enable mask bit. The GPE must
  245. * already be marked as a WAKE GPE.
  246. *
  247. ******************************************************************************/
  248. acpi_status acpi_set_gpe_wake_mask(acpi_handle gpe_device, u32 gpe_number, u8 action)
  249. {
  250. acpi_status status = AE_OK;
  251. struct acpi_gpe_event_info *gpe_event_info;
  252. struct acpi_gpe_register_info *gpe_register_info;
  253. acpi_cpu_flags flags;
  254. u32 register_bit;
  255. ACPI_FUNCTION_TRACE(acpi_set_gpe_wake_mask);
  256. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  257. /*
  258. * Ensure that we have a valid GPE number and that this GPE is in
  259. * fact a wake GPE
  260. */
  261. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  262. if (!gpe_event_info) {
  263. status = AE_BAD_PARAMETER;
  264. goto unlock_and_exit;
  265. }
  266. if (!(gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) {
  267. status = AE_TYPE;
  268. goto unlock_and_exit;
  269. }
  270. gpe_register_info = gpe_event_info->register_info;
  271. if (!gpe_register_info) {
  272. status = AE_NOT_EXIST;
  273. goto unlock_and_exit;
  274. }
  275. register_bit =
  276. acpi_hw_get_gpe_register_bit(gpe_event_info, gpe_register_info);
  277. /* Perform the action */
  278. switch (action) {
  279. case ACPI_GPE_ENABLE:
  280. ACPI_SET_BIT(gpe_register_info->enable_for_wake,
  281. (u8)register_bit);
  282. break;
  283. case ACPI_GPE_DISABLE:
  284. ACPI_CLEAR_BIT(gpe_register_info->enable_for_wake,
  285. (u8)register_bit);
  286. break;
  287. default:
  288. ACPI_ERROR((AE_INFO, "%u, Invalid action", action));
  289. status = AE_BAD_PARAMETER;
  290. break;
  291. }
  292. unlock_and_exit:
  293. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  294. return_ACPI_STATUS(status);
  295. }
  296. ACPI_EXPORT_SYMBOL(acpi_set_gpe_wake_mask)
  297. /*******************************************************************************
  298. *
  299. * FUNCTION: acpi_clear_gpe
  300. *
  301. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  302. * gpe_number - GPE level within the GPE block
  303. *
  304. * RETURN: Status
  305. *
  306. * DESCRIPTION: Clear an ACPI event (general purpose)
  307. *
  308. ******************************************************************************/
  309. acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number)
  310. {
  311. acpi_status status = AE_OK;
  312. struct acpi_gpe_event_info *gpe_event_info;
  313. acpi_cpu_flags flags;
  314. ACPI_FUNCTION_TRACE(acpi_clear_gpe);
  315. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  316. /* Ensure that we have a valid GPE number */
  317. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  318. if (!gpe_event_info) {
  319. status = AE_BAD_PARAMETER;
  320. goto unlock_and_exit;
  321. }
  322. status = acpi_hw_clear_gpe(gpe_event_info);
  323. unlock_and_exit:
  324. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  325. return_ACPI_STATUS(status);
  326. }
  327. ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
  328. /*******************************************************************************
  329. *
  330. * FUNCTION: acpi_get_gpe_status
  331. *
  332. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  333. * gpe_number - GPE level within the GPE block
  334. * event_status - Where the current status of the event will
  335. * be returned
  336. *
  337. * RETURN: Status
  338. *
  339. * DESCRIPTION: Get the current status of a GPE (signalled/not_signalled)
  340. *
  341. ******************************************************************************/
  342. acpi_status
  343. acpi_get_gpe_status(acpi_handle gpe_device,
  344. u32 gpe_number, acpi_event_status *event_status)
  345. {
  346. acpi_status status = AE_OK;
  347. struct acpi_gpe_event_info *gpe_event_info;
  348. acpi_cpu_flags flags;
  349. ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
  350. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  351. /* Ensure that we have a valid GPE number */
  352. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  353. if (!gpe_event_info) {
  354. status = AE_BAD_PARAMETER;
  355. goto unlock_and_exit;
  356. }
  357. /* Obtain status on the requested GPE number */
  358. status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
  359. if (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)
  360. *event_status |= ACPI_EVENT_FLAG_HANDLE;
  361. unlock_and_exit:
  362. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  363. return_ACPI_STATUS(status);
  364. }
  365. ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
  366. /******************************************************************************
  367. *
  368. * FUNCTION: acpi_disable_all_gpes
  369. *
  370. * PARAMETERS: None
  371. *
  372. * RETURN: Status
  373. *
  374. * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
  375. *
  376. ******************************************************************************/
  377. acpi_status acpi_disable_all_gpes(void)
  378. {
  379. acpi_status status;
  380. ACPI_FUNCTION_TRACE(acpi_disable_all_gpes);
  381. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  382. if (ACPI_FAILURE(status)) {
  383. return_ACPI_STATUS(status);
  384. }
  385. status = acpi_hw_disable_all_gpes();
  386. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  387. return_ACPI_STATUS(status);
  388. }
  389. ACPI_EXPORT_SYMBOL(acpi_disable_all_gpes)
  390. /******************************************************************************
  391. *
  392. * FUNCTION: acpi_enable_all_runtime_gpes
  393. *
  394. * PARAMETERS: None
  395. *
  396. * RETURN: Status
  397. *
  398. * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
  399. *
  400. ******************************************************************************/
  401. acpi_status acpi_enable_all_runtime_gpes(void)
  402. {
  403. acpi_status status;
  404. ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes);
  405. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  406. if (ACPI_FAILURE(status)) {
  407. return_ACPI_STATUS(status);
  408. }
  409. status = acpi_hw_enable_all_runtime_gpes();
  410. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  411. return_ACPI_STATUS(status);
  412. }
  413. ACPI_EXPORT_SYMBOL(acpi_enable_all_runtime_gpes)
  414. /*******************************************************************************
  415. *
  416. * FUNCTION: acpi_install_gpe_block
  417. *
  418. * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
  419. * gpe_block_address - Address and space_iD
  420. * register_count - Number of GPE register pairs in the block
  421. * interrupt_number - H/W interrupt for the block
  422. *
  423. * RETURN: Status
  424. *
  425. * DESCRIPTION: Create and Install a block of GPE registers. The GPEs are not
  426. * enabled here.
  427. *
  428. ******************************************************************************/
  429. acpi_status
  430. acpi_install_gpe_block(acpi_handle gpe_device,
  431. struct acpi_generic_address *gpe_block_address,
  432. u32 register_count, u32 interrupt_number)
  433. {
  434. acpi_status status;
  435. union acpi_operand_object *obj_desc;
  436. struct acpi_namespace_node *node;
  437. struct acpi_gpe_block_info *gpe_block;
  438. ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
  439. if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
  440. return_ACPI_STATUS(AE_BAD_PARAMETER);
  441. }
  442. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  443. if (ACPI_FAILURE(status)) {
  444. return (status);
  445. }
  446. node = acpi_ns_validate_handle(gpe_device);
  447. if (!node) {
  448. status = AE_BAD_PARAMETER;
  449. goto unlock_and_exit;
  450. }
  451. /*
  452. * For user-installed GPE Block Devices, the gpe_block_base_number
  453. * is always zero
  454. */
  455. status =
  456. acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0,
  457. interrupt_number, &gpe_block);
  458. if (ACPI_FAILURE(status)) {
  459. goto unlock_and_exit;
  460. }
  461. /* Install block in the device_object attached to the node */
  462. obj_desc = acpi_ns_get_attached_object(node);
  463. if (!obj_desc) {
  464. /*
  465. * No object, create a new one (Device nodes do not always have
  466. * an attached object)
  467. */
  468. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
  469. if (!obj_desc) {
  470. status = AE_NO_MEMORY;
  471. goto unlock_and_exit;
  472. }
  473. status =
  474. acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
  475. /* Remove local reference to the object */
  476. acpi_ut_remove_reference(obj_desc);
  477. if (ACPI_FAILURE(status)) {
  478. goto unlock_and_exit;
  479. }
  480. }
  481. /* Now install the GPE block in the device_object */
  482. obj_desc->device.gpe_block = gpe_block;
  483. unlock_and_exit:
  484. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  485. return_ACPI_STATUS(status);
  486. }
  487. ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
  488. /*******************************************************************************
  489. *
  490. * FUNCTION: acpi_remove_gpe_block
  491. *
  492. * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
  493. *
  494. * RETURN: Status
  495. *
  496. * DESCRIPTION: Remove a previously installed block of GPE registers
  497. *
  498. ******************************************************************************/
  499. acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
  500. {
  501. union acpi_operand_object *obj_desc;
  502. acpi_status status;
  503. struct acpi_namespace_node *node;
  504. ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
  505. if (!gpe_device) {
  506. return_ACPI_STATUS(AE_BAD_PARAMETER);
  507. }
  508. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  509. if (ACPI_FAILURE(status)) {
  510. return (status);
  511. }
  512. node = acpi_ns_validate_handle(gpe_device);
  513. if (!node) {
  514. status = AE_BAD_PARAMETER;
  515. goto unlock_and_exit;
  516. }
  517. /* Get the device_object attached to the node */
  518. obj_desc = acpi_ns_get_attached_object(node);
  519. if (!obj_desc || !obj_desc->device.gpe_block) {
  520. return_ACPI_STATUS(AE_NULL_OBJECT);
  521. }
  522. /* Delete the GPE block (but not the device_object) */
  523. status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
  524. if (ACPI_SUCCESS(status)) {
  525. obj_desc->device.gpe_block = NULL;
  526. }
  527. unlock_and_exit:
  528. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  529. return_ACPI_STATUS(status);
  530. }
  531. ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)
  532. /*******************************************************************************
  533. *
  534. * FUNCTION: acpi_get_gpe_device
  535. *
  536. * PARAMETERS: Index - System GPE index (0-current_gpe_count)
  537. * gpe_device - Where the parent GPE Device is returned
  538. *
  539. * RETURN: Status
  540. *
  541. * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
  542. * gpe device indicates that the gpe number is contained in one of
  543. * the FADT-defined gpe blocks. Otherwise, the GPE block device.
  544. *
  545. ******************************************************************************/
  546. acpi_status
  547. acpi_get_gpe_device(u32 index, acpi_handle *gpe_device)
  548. {
  549. struct acpi_gpe_device_info info;
  550. acpi_status status;
  551. ACPI_FUNCTION_TRACE(acpi_get_gpe_device);
  552. if (!gpe_device) {
  553. return_ACPI_STATUS(AE_BAD_PARAMETER);
  554. }
  555. if (index >= acpi_current_gpe_count) {
  556. return_ACPI_STATUS(AE_NOT_EXIST);
  557. }
  558. /* Setup and walk the GPE list */
  559. info.index = index;
  560. info.status = AE_NOT_EXIST;
  561. info.gpe_device = NULL;
  562. info.next_block_base_index = 0;
  563. status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info);
  564. if (ACPI_FAILURE(status)) {
  565. return_ACPI_STATUS(status);
  566. }
  567. *gpe_device = ACPI_CAST_PTR(acpi_handle, info.gpe_device);
  568. return_ACPI_STATUS(info.status);
  569. }
  570. ACPI_EXPORT_SYMBOL(acpi_get_gpe_device)