evxfgpe.c 21 KB

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