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