evxfevnt.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. /******************************************************************************
  2. *
  3. * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2006, R. Byron Moore
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #include <acpi/acpi.h>
  43. #include <acpi/acevents.h>
  44. #include <acpi/acnamesp.h>
  45. #define _COMPONENT ACPI_EVENTS
  46. ACPI_MODULE_NAME("evxfevnt")
  47. /*******************************************************************************
  48. *
  49. * FUNCTION: acpi_enable
  50. *
  51. * PARAMETERS: None
  52. *
  53. * RETURN: Status
  54. *
  55. * DESCRIPTION: Transfers the system into ACPI mode.
  56. *
  57. ******************************************************************************/
  58. acpi_status acpi_enable(void)
  59. {
  60. acpi_status status = AE_OK;
  61. ACPI_FUNCTION_TRACE(acpi_enable);
  62. /* Make sure we have the FADT */
  63. if (!acpi_gbl_FADT) {
  64. ACPI_WARNING((AE_INFO, "No FADT information present!"));
  65. return_ACPI_STATUS(AE_NO_ACPI_TABLES);
  66. }
  67. if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
  68. ACPI_DEBUG_PRINT((ACPI_DB_INIT,
  69. "System is already in ACPI mode\n"));
  70. } else {
  71. /* Transition to ACPI mode */
  72. status = acpi_hw_set_mode(ACPI_SYS_MODE_ACPI);
  73. if (ACPI_FAILURE(status)) {
  74. ACPI_ERROR((AE_INFO,
  75. "Could not transition to ACPI mode"));
  76. return_ACPI_STATUS(status);
  77. }
  78. ACPI_DEBUG_PRINT((ACPI_DB_INIT,
  79. "Transition to ACPI mode successful\n"));
  80. }
  81. return_ACPI_STATUS(status);
  82. }
  83. ACPI_EXPORT_SYMBOL(acpi_enable)
  84. /*******************************************************************************
  85. *
  86. * FUNCTION: acpi_disable
  87. *
  88. * PARAMETERS: None
  89. *
  90. * RETURN: Status
  91. *
  92. * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
  93. *
  94. ******************************************************************************/
  95. acpi_status acpi_disable(void)
  96. {
  97. acpi_status status = AE_OK;
  98. ACPI_FUNCTION_TRACE(acpi_disable);
  99. if (!acpi_gbl_FADT) {
  100. ACPI_WARNING((AE_INFO, "No FADT information present!"));
  101. return_ACPI_STATUS(AE_NO_ACPI_TABLES);
  102. }
  103. if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {
  104. ACPI_DEBUG_PRINT((ACPI_DB_INIT,
  105. "System is already in legacy (non-ACPI) mode\n"));
  106. } else {
  107. /* Transition to LEGACY mode */
  108. status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY);
  109. if (ACPI_FAILURE(status)) {
  110. ACPI_ERROR((AE_INFO,
  111. "Could not exit ACPI mode to legacy mode"));
  112. return_ACPI_STATUS(status);
  113. }
  114. ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI mode disabled\n"));
  115. }
  116. return_ACPI_STATUS(status);
  117. }
  118. ACPI_EXPORT_SYMBOL(acpi_disable)
  119. /*******************************************************************************
  120. *
  121. * FUNCTION: acpi_enable_event
  122. *
  123. * PARAMETERS: Event - The fixed eventto be enabled
  124. * Flags - Reserved
  125. *
  126. * RETURN: Status
  127. *
  128. * DESCRIPTION: Enable an ACPI event (fixed)
  129. *
  130. ******************************************************************************/
  131. acpi_status acpi_enable_event(u32 event, u32 flags)
  132. {
  133. acpi_status status = AE_OK;
  134. u32 value;
  135. ACPI_FUNCTION_TRACE(acpi_enable_event);
  136. /* Decode the Fixed Event */
  137. if (event > ACPI_EVENT_MAX) {
  138. return_ACPI_STATUS(AE_BAD_PARAMETER);
  139. }
  140. /*
  141. * Enable the requested fixed event (by writing a one to the
  142. * enable register bit)
  143. */
  144. status =
  145. acpi_set_register(acpi_gbl_fixed_event_info[event].
  146. enable_register_id, 1, ACPI_MTX_LOCK);
  147. if (ACPI_FAILURE(status)) {
  148. return_ACPI_STATUS(status);
  149. }
  150. /* Make sure that the hardware responded */
  151. status =
  152. acpi_get_register(acpi_gbl_fixed_event_info[event].
  153. enable_register_id, &value, ACPI_MTX_LOCK);
  154. if (ACPI_FAILURE(status)) {
  155. return_ACPI_STATUS(status);
  156. }
  157. if (value != 1) {
  158. ACPI_ERROR((AE_INFO,
  159. "Could not enable %s event",
  160. acpi_ut_get_event_name(event)));
  161. return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
  162. }
  163. return_ACPI_STATUS(status);
  164. }
  165. ACPI_EXPORT_SYMBOL(acpi_enable_event)
  166. /*******************************************************************************
  167. *
  168. * FUNCTION: acpi_set_gpe_type
  169. *
  170. * PARAMETERS: gpe_device - Parent GPE Device
  171. * gpe_number - GPE level within the GPE block
  172. * Type - New GPE type
  173. *
  174. * RETURN: Status
  175. *
  176. * DESCRIPTION: Set the type of an individual GPE
  177. *
  178. ******************************************************************************/
  179. acpi_status acpi_set_gpe_type(acpi_handle gpe_device, u32 gpe_number, u8 type)
  180. {
  181. acpi_status status = AE_OK;
  182. struct acpi_gpe_event_info *gpe_event_info;
  183. ACPI_FUNCTION_TRACE(acpi_set_gpe_type);
  184. /* Ensure that we have a valid GPE number */
  185. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  186. if (!gpe_event_info) {
  187. status = AE_BAD_PARAMETER;
  188. goto unlock_and_exit;
  189. }
  190. if ((gpe_event_info->flags & ACPI_GPE_TYPE_MASK) == type) {
  191. return_ACPI_STATUS(AE_OK);
  192. }
  193. /* Set the new type (will disable GPE if currently enabled) */
  194. status = acpi_ev_set_gpe_type(gpe_event_info, type);
  195. unlock_and_exit:
  196. return_ACPI_STATUS(status);
  197. }
  198. ACPI_EXPORT_SYMBOL(acpi_set_gpe_type)
  199. /*******************************************************************************
  200. *
  201. * FUNCTION: acpi_enable_gpe
  202. *
  203. * PARAMETERS: gpe_device - Parent GPE Device
  204. * gpe_number - GPE level within the GPE block
  205. * Flags - Just enable, or also wake enable?
  206. * Called from ISR or not
  207. *
  208. * RETURN: Status
  209. *
  210. * DESCRIPTION: Enable an ACPI event (general purpose)
  211. *
  212. ******************************************************************************/
  213. acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
  214. {
  215. acpi_status status = AE_OK;
  216. struct acpi_gpe_event_info *gpe_event_info;
  217. ACPI_FUNCTION_TRACE(acpi_enable_gpe);
  218. /* Use semaphore lock if not executing at interrupt level */
  219. if (flags & ACPI_NOT_ISR) {
  220. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  221. if (ACPI_FAILURE(status)) {
  222. return_ACPI_STATUS(status);
  223. }
  224. }
  225. /* Ensure that we have a valid GPE number */
  226. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  227. if (!gpe_event_info) {
  228. status = AE_BAD_PARAMETER;
  229. goto unlock_and_exit;
  230. }
  231. /* Perform the enable */
  232. status = acpi_ev_enable_gpe(gpe_event_info, TRUE);
  233. unlock_and_exit:
  234. if (flags & ACPI_NOT_ISR) {
  235. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  236. }
  237. return_ACPI_STATUS(status);
  238. }
  239. ACPI_EXPORT_SYMBOL(acpi_enable_gpe)
  240. /*******************************************************************************
  241. *
  242. * FUNCTION: acpi_disable_gpe
  243. *
  244. * PARAMETERS: gpe_device - Parent GPE Device
  245. * gpe_number - GPE level within the GPE block
  246. * Flags - Just disable, or also wake disable?
  247. * Called from ISR or not
  248. *
  249. * RETURN: Status
  250. *
  251. * DESCRIPTION: Disable an ACPI event (general purpose)
  252. *
  253. ******************************************************************************/
  254. acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
  255. {
  256. acpi_status status = AE_OK;
  257. struct acpi_gpe_event_info *gpe_event_info;
  258. ACPI_FUNCTION_TRACE(acpi_disable_gpe);
  259. /* Use semaphore lock if not executing at interrupt level */
  260. if (flags & ACPI_NOT_ISR) {
  261. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  262. if (ACPI_FAILURE(status)) {
  263. return_ACPI_STATUS(status);
  264. }
  265. }
  266. /* Ensure that we have a valid GPE number */
  267. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  268. if (!gpe_event_info) {
  269. status = AE_BAD_PARAMETER;
  270. goto unlock_and_exit;
  271. }
  272. status = acpi_ev_disable_gpe(gpe_event_info);
  273. unlock_and_exit:
  274. if (flags & ACPI_NOT_ISR) {
  275. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  276. }
  277. return_ACPI_STATUS(status);
  278. }
  279. ACPI_EXPORT_SYMBOL(acpi_disable_gpe)
  280. /*******************************************************************************
  281. *
  282. * FUNCTION: acpi_disable_event
  283. *
  284. * PARAMETERS: Event - The fixed eventto be enabled
  285. * Flags - Reserved
  286. *
  287. * RETURN: Status
  288. *
  289. * DESCRIPTION: Disable an ACPI event (fixed)
  290. *
  291. ******************************************************************************/
  292. acpi_status acpi_disable_event(u32 event, u32 flags)
  293. {
  294. acpi_status status = AE_OK;
  295. u32 value;
  296. ACPI_FUNCTION_TRACE(acpi_disable_event);
  297. /* Decode the Fixed Event */
  298. if (event > ACPI_EVENT_MAX) {
  299. return_ACPI_STATUS(AE_BAD_PARAMETER);
  300. }
  301. /*
  302. * Disable the requested fixed event (by writing a zero to the
  303. * enable register bit)
  304. */
  305. status =
  306. acpi_set_register(acpi_gbl_fixed_event_info[event].
  307. enable_register_id, 0, ACPI_MTX_LOCK);
  308. if (ACPI_FAILURE(status)) {
  309. return_ACPI_STATUS(status);
  310. }
  311. status =
  312. acpi_get_register(acpi_gbl_fixed_event_info[event].
  313. enable_register_id, &value, ACPI_MTX_LOCK);
  314. if (ACPI_FAILURE(status)) {
  315. return_ACPI_STATUS(status);
  316. }
  317. if (value != 0) {
  318. ACPI_ERROR((AE_INFO,
  319. "Could not disable %s events",
  320. acpi_ut_get_event_name(event)));
  321. return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
  322. }
  323. return_ACPI_STATUS(status);
  324. }
  325. ACPI_EXPORT_SYMBOL(acpi_disable_event)
  326. /*******************************************************************************
  327. *
  328. * FUNCTION: acpi_clear_event
  329. *
  330. * PARAMETERS: Event - The fixed event to be cleared
  331. *
  332. * RETURN: Status
  333. *
  334. * DESCRIPTION: Clear an ACPI event (fixed)
  335. *
  336. ******************************************************************************/
  337. acpi_status acpi_clear_event(u32 event)
  338. {
  339. acpi_status status = AE_OK;
  340. ACPI_FUNCTION_TRACE(acpi_clear_event);
  341. /* Decode the Fixed Event */
  342. if (event > ACPI_EVENT_MAX) {
  343. return_ACPI_STATUS(AE_BAD_PARAMETER);
  344. }
  345. /*
  346. * Clear the requested fixed event (By writing a one to the
  347. * status register bit)
  348. */
  349. status =
  350. acpi_set_register(acpi_gbl_fixed_event_info[event].
  351. status_register_id, 1, ACPI_MTX_LOCK);
  352. return_ACPI_STATUS(status);
  353. }
  354. ACPI_EXPORT_SYMBOL(acpi_clear_event)
  355. /*******************************************************************************
  356. *
  357. * FUNCTION: acpi_clear_gpe
  358. *
  359. * PARAMETERS: gpe_device - Parent GPE Device
  360. * gpe_number - GPE level within the GPE block
  361. * Flags - Called from an ISR or not
  362. *
  363. * RETURN: Status
  364. *
  365. * DESCRIPTION: Clear an ACPI event (general purpose)
  366. *
  367. ******************************************************************************/
  368. acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
  369. {
  370. acpi_status status = AE_OK;
  371. struct acpi_gpe_event_info *gpe_event_info;
  372. ACPI_FUNCTION_TRACE(acpi_clear_gpe);
  373. /* Use semaphore lock if not executing at interrupt level */
  374. if (flags & ACPI_NOT_ISR) {
  375. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  376. if (ACPI_FAILURE(status)) {
  377. return_ACPI_STATUS(status);
  378. }
  379. }
  380. /* Ensure that we have a valid GPE number */
  381. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  382. if (!gpe_event_info) {
  383. status = AE_BAD_PARAMETER;
  384. goto unlock_and_exit;
  385. }
  386. status = acpi_hw_clear_gpe(gpe_event_info);
  387. unlock_and_exit:
  388. if (flags & ACPI_NOT_ISR) {
  389. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  390. }
  391. return_ACPI_STATUS(status);
  392. }
  393. ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
  394. #ifdef ACPI_FUTURE_USAGE
  395. /*******************************************************************************
  396. *
  397. * FUNCTION: acpi_get_event_status
  398. *
  399. * PARAMETERS: Event - The fixed event
  400. * event_status - Where the current status of the event will
  401. * be returned
  402. *
  403. * RETURN: Status
  404. *
  405. * DESCRIPTION: Obtains and returns the current status of the event
  406. *
  407. ******************************************************************************/
  408. acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
  409. {
  410. acpi_status status = AE_OK;
  411. ACPI_FUNCTION_TRACE(acpi_get_event_status);
  412. if (!event_status) {
  413. return_ACPI_STATUS(AE_BAD_PARAMETER);
  414. }
  415. /* Decode the Fixed Event */
  416. if (event > ACPI_EVENT_MAX) {
  417. return_ACPI_STATUS(AE_BAD_PARAMETER);
  418. }
  419. /* Get the status of the requested fixed event */
  420. status =
  421. acpi_get_register(acpi_gbl_fixed_event_info[event].
  422. status_register_id, event_status, ACPI_MTX_LOCK);
  423. return_ACPI_STATUS(status);
  424. }
  425. ACPI_EXPORT_SYMBOL(acpi_get_event_status)
  426. /*******************************************************************************
  427. *
  428. * FUNCTION: acpi_get_gpe_status
  429. *
  430. * PARAMETERS: gpe_device - Parent GPE Device
  431. * gpe_number - GPE level within the GPE block
  432. * Flags - Called from an ISR or not
  433. * event_status - Where the current status of the event will
  434. * be returned
  435. *
  436. * RETURN: Status
  437. *
  438. * DESCRIPTION: Get status of an event (general purpose)
  439. *
  440. ******************************************************************************/
  441. acpi_status
  442. acpi_get_gpe_status(acpi_handle gpe_device,
  443. u32 gpe_number, u32 flags, acpi_event_status * event_status)
  444. {
  445. acpi_status status = AE_OK;
  446. struct acpi_gpe_event_info *gpe_event_info;
  447. ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
  448. /* Use semaphore lock if not executing at interrupt level */
  449. if (flags & ACPI_NOT_ISR) {
  450. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  451. if (ACPI_FAILURE(status)) {
  452. return_ACPI_STATUS(status);
  453. }
  454. }
  455. /* Ensure that we have a valid GPE number */
  456. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  457. if (!gpe_event_info) {
  458. status = AE_BAD_PARAMETER;
  459. goto unlock_and_exit;
  460. }
  461. /* Obtain status on the requested GPE number */
  462. status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
  463. unlock_and_exit:
  464. if (flags & ACPI_NOT_ISR) {
  465. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  466. }
  467. return_ACPI_STATUS(status);
  468. }
  469. ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
  470. #endif /* ACPI_FUTURE_USAGE */
  471. /*******************************************************************************
  472. *
  473. * FUNCTION: acpi_install_gpe_block
  474. *
  475. * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
  476. * gpe_block_address - Address and space_iD
  477. * register_count - Number of GPE register pairs in the block
  478. * interrupt_number - H/W interrupt for the block
  479. *
  480. * RETURN: Status
  481. *
  482. * DESCRIPTION: Create and Install a block of GPE registers
  483. *
  484. ******************************************************************************/
  485. acpi_status
  486. acpi_install_gpe_block(acpi_handle gpe_device,
  487. struct acpi_generic_address *gpe_block_address,
  488. u32 register_count, u32 interrupt_number)
  489. {
  490. acpi_status status;
  491. union acpi_operand_object *obj_desc;
  492. struct acpi_namespace_node *node;
  493. struct acpi_gpe_block_info *gpe_block;
  494. ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
  495. if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
  496. return_ACPI_STATUS(AE_BAD_PARAMETER);
  497. }
  498. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  499. if (ACPI_FAILURE(status)) {
  500. return (status);
  501. }
  502. node = acpi_ns_map_handle_to_node(gpe_device);
  503. if (!node) {
  504. status = AE_BAD_PARAMETER;
  505. goto unlock_and_exit;
  506. }
  507. /*
  508. * For user-installed GPE Block Devices, the gpe_block_base_number
  509. * is always zero
  510. */
  511. status =
  512. acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0,
  513. interrupt_number, &gpe_block);
  514. if (ACPI_FAILURE(status)) {
  515. goto unlock_and_exit;
  516. }
  517. /* Run the _PRW methods and enable the GPEs */
  518. status = acpi_ev_initialize_gpe_block(node, gpe_block);
  519. if (ACPI_FAILURE(status)) {
  520. goto unlock_and_exit;
  521. }
  522. /* Get the device_object attached to the node */
  523. obj_desc = acpi_ns_get_attached_object(node);
  524. if (!obj_desc) {
  525. /* No object, create a new one */
  526. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
  527. if (!obj_desc) {
  528. status = AE_NO_MEMORY;
  529. goto unlock_and_exit;
  530. }
  531. status =
  532. acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
  533. /* Remove local reference to the object */
  534. acpi_ut_remove_reference(obj_desc);
  535. if (ACPI_FAILURE(status)) {
  536. goto unlock_and_exit;
  537. }
  538. }
  539. /* Install the GPE block in the device_object */
  540. obj_desc->device.gpe_block = gpe_block;
  541. unlock_and_exit:
  542. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  543. return_ACPI_STATUS(status);
  544. }
  545. ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
  546. /*******************************************************************************
  547. *
  548. * FUNCTION: acpi_remove_gpe_block
  549. *
  550. * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
  551. *
  552. * RETURN: Status
  553. *
  554. * DESCRIPTION: Remove a previously installed block of GPE registers
  555. *
  556. ******************************************************************************/
  557. acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
  558. {
  559. union acpi_operand_object *obj_desc;
  560. acpi_status status;
  561. struct acpi_namespace_node *node;
  562. ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
  563. if (!gpe_device) {
  564. return_ACPI_STATUS(AE_BAD_PARAMETER);
  565. }
  566. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  567. if (ACPI_FAILURE(status)) {
  568. return (status);
  569. }
  570. node = acpi_ns_map_handle_to_node(gpe_device);
  571. if (!node) {
  572. status = AE_BAD_PARAMETER;
  573. goto unlock_and_exit;
  574. }
  575. /* Get the device_object attached to the node */
  576. obj_desc = acpi_ns_get_attached_object(node);
  577. if (!obj_desc || !obj_desc->device.gpe_block) {
  578. return_ACPI_STATUS(AE_NULL_OBJECT);
  579. }
  580. /* Delete the GPE block (but not the device_object) */
  581. status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
  582. if (ACPI_SUCCESS(status)) {
  583. obj_desc->device.gpe_block = NULL;
  584. }
  585. unlock_and_exit:
  586. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  587. return_ACPI_STATUS(status);
  588. }
  589. ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)