evxfgpe.c 20 KB

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