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