evxfevnt.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871
  1. /******************************************************************************
  2. *
  3. * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2008, 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 <acpi/acpi.h>
  43. #include "accommon.h"
  44. #include "acevents.h"
  45. #include "acnamesp.h"
  46. #include "actables.h"
  47. #define _COMPONENT ACPI_EVENTS
  48. ACPI_MODULE_NAME("evxfevnt")
  49. /* Local prototypes */
  50. acpi_status
  51. acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
  52. struct acpi_gpe_block_info *gpe_block, void *context);
  53. /*******************************************************************************
  54. *
  55. * FUNCTION: acpi_enable
  56. *
  57. * PARAMETERS: None
  58. *
  59. * RETURN: Status
  60. *
  61. * DESCRIPTION: Transfers the system into ACPI mode.
  62. *
  63. ******************************************************************************/
  64. acpi_status acpi_enable(void)
  65. {
  66. acpi_status status = AE_OK;
  67. ACPI_FUNCTION_TRACE(acpi_enable);
  68. /* ACPI tables must be present */
  69. if (!acpi_tb_tables_loaded()) {
  70. return_ACPI_STATUS(AE_NO_ACPI_TABLES);
  71. }
  72. /* Check current mode */
  73. if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
  74. ACPI_DEBUG_PRINT((ACPI_DB_INIT,
  75. "System is already in ACPI mode\n"));
  76. } else {
  77. /* Transition to ACPI mode */
  78. status = acpi_hw_set_mode(ACPI_SYS_MODE_ACPI);
  79. if (ACPI_FAILURE(status)) {
  80. ACPI_ERROR((AE_INFO,
  81. "Could not transition to ACPI mode"));
  82. return_ACPI_STATUS(status);
  83. }
  84. ACPI_DEBUG_PRINT((ACPI_DB_INIT,
  85. "Transition to ACPI mode successful\n"));
  86. }
  87. return_ACPI_STATUS(status);
  88. }
  89. ACPI_EXPORT_SYMBOL(acpi_enable)
  90. /*******************************************************************************
  91. *
  92. * FUNCTION: acpi_disable
  93. *
  94. * PARAMETERS: None
  95. *
  96. * RETURN: Status
  97. *
  98. * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
  99. *
  100. ******************************************************************************/
  101. acpi_status acpi_disable(void)
  102. {
  103. acpi_status status = AE_OK;
  104. ACPI_FUNCTION_TRACE(acpi_disable);
  105. if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {
  106. ACPI_DEBUG_PRINT((ACPI_DB_INIT,
  107. "System is already in legacy (non-ACPI) mode\n"));
  108. } else {
  109. /* Transition to LEGACY mode */
  110. status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY);
  111. if (ACPI_FAILURE(status)) {
  112. ACPI_ERROR((AE_INFO,
  113. "Could not exit ACPI mode to legacy mode"));
  114. return_ACPI_STATUS(status);
  115. }
  116. ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI mode disabled\n"));
  117. }
  118. return_ACPI_STATUS(status);
  119. }
  120. ACPI_EXPORT_SYMBOL(acpi_disable)
  121. /*******************************************************************************
  122. *
  123. * FUNCTION: acpi_enable_event
  124. *
  125. * PARAMETERS: Event - The fixed eventto be enabled
  126. * Flags - Reserved
  127. *
  128. * RETURN: Status
  129. *
  130. * DESCRIPTION: Enable an ACPI event (fixed)
  131. *
  132. ******************************************************************************/
  133. acpi_status acpi_enable_event(u32 event, u32 flags)
  134. {
  135. acpi_status status = AE_OK;
  136. u32 value;
  137. ACPI_FUNCTION_TRACE(acpi_enable_event);
  138. /* Decode the Fixed Event */
  139. if (event > ACPI_EVENT_MAX) {
  140. return_ACPI_STATUS(AE_BAD_PARAMETER);
  141. }
  142. /*
  143. * Enable the requested fixed event (by writing a one to the enable
  144. * register bit)
  145. */
  146. status =
  147. acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
  148. enable_register_id, ACPI_ENABLE_EVENT);
  149. if (ACPI_FAILURE(status)) {
  150. return_ACPI_STATUS(status);
  151. }
  152. /* Make sure that the hardware responded */
  153. status =
  154. acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
  155. enable_register_id, &value);
  156. if (ACPI_FAILURE(status)) {
  157. return_ACPI_STATUS(status);
  158. }
  159. if (value != 1) {
  160. ACPI_ERROR((AE_INFO,
  161. "Could not enable %s event",
  162. acpi_ut_get_event_name(event)));
  163. return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
  164. }
  165. return_ACPI_STATUS(status);
  166. }
  167. ACPI_EXPORT_SYMBOL(acpi_enable_event)
  168. /*******************************************************************************
  169. *
  170. * FUNCTION: acpi_set_gpe_type
  171. *
  172. * PARAMETERS: gpe_device - Parent GPE Device
  173. * gpe_number - GPE level within the GPE block
  174. * Type - New GPE type
  175. *
  176. * RETURN: Status
  177. *
  178. * DESCRIPTION: Set the type of an individual GPE
  179. *
  180. ******************************************************************************/
  181. acpi_status acpi_set_gpe_type(acpi_handle gpe_device, u32 gpe_number, u8 type)
  182. {
  183. acpi_status status = AE_OK;
  184. struct acpi_gpe_event_info *gpe_event_info;
  185. ACPI_FUNCTION_TRACE(acpi_set_gpe_type);
  186. /* Ensure that we have a valid GPE number */
  187. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  188. if (!gpe_event_info) {
  189. status = AE_BAD_PARAMETER;
  190. goto unlock_and_exit;
  191. }
  192. if ((gpe_event_info->flags & ACPI_GPE_TYPE_MASK) == type) {
  193. return_ACPI_STATUS(AE_OK);
  194. }
  195. /* Set the new type (will disable GPE if currently enabled) */
  196. status = acpi_ev_set_gpe_type(gpe_event_info, type);
  197. unlock_and_exit:
  198. return_ACPI_STATUS(status);
  199. }
  200. ACPI_EXPORT_SYMBOL(acpi_set_gpe_type)
  201. /*******************************************************************************
  202. *
  203. * FUNCTION: acpi_enable_gpe
  204. *
  205. * PARAMETERS: gpe_device - Parent GPE Device
  206. * gpe_number - GPE level within the GPE block
  207. * Flags - Just enable, or also wake enable?
  208. * Called from ISR or not
  209. *
  210. * RETURN: Status
  211. *
  212. * DESCRIPTION: Enable an ACPI event (general purpose)
  213. *
  214. ******************************************************************************/
  215. acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number)
  216. {
  217. acpi_status status = AE_OK;
  218. acpi_cpu_flags flags;
  219. struct acpi_gpe_event_info *gpe_event_info;
  220. ACPI_FUNCTION_TRACE(acpi_enable_gpe);
  221. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  222. /* Ensure that we have a valid GPE number */
  223. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  224. if (!gpe_event_info) {
  225. status = AE_BAD_PARAMETER;
  226. goto unlock_and_exit;
  227. }
  228. /* Perform the enable */
  229. status = acpi_ev_enable_gpe(gpe_event_info, TRUE);
  230. unlock_and_exit:
  231. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  232. return_ACPI_STATUS(status);
  233. }
  234. ACPI_EXPORT_SYMBOL(acpi_enable_gpe)
  235. /*******************************************************************************
  236. *
  237. * FUNCTION: acpi_disable_gpe
  238. *
  239. * PARAMETERS: gpe_device - Parent GPE Device
  240. * gpe_number - GPE level within the GPE block
  241. * Flags - Just disable, or also wake disable?
  242. * Called from ISR or not
  243. *
  244. * RETURN: Status
  245. *
  246. * DESCRIPTION: Disable an ACPI event (general purpose)
  247. *
  248. ******************************************************************************/
  249. acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number)
  250. {
  251. acpi_status status = AE_OK;
  252. acpi_cpu_flags flags;
  253. struct acpi_gpe_event_info *gpe_event_info;
  254. ACPI_FUNCTION_TRACE(acpi_disable_gpe);
  255. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  256. /* Ensure that we have a valid GPE number */
  257. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  258. if (!gpe_event_info) {
  259. status = AE_BAD_PARAMETER;
  260. goto unlock_and_exit;
  261. }
  262. status = acpi_ev_disable_gpe(gpe_event_info);
  263. unlock_and_exit:
  264. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  265. return_ACPI_STATUS(status);
  266. }
  267. ACPI_EXPORT_SYMBOL(acpi_disable_gpe)
  268. /*******************************************************************************
  269. *
  270. * FUNCTION: acpi_disable_event
  271. *
  272. * PARAMETERS: Event - The fixed eventto be enabled
  273. * Flags - Reserved
  274. *
  275. * RETURN: Status
  276. *
  277. * DESCRIPTION: Disable an ACPI event (fixed)
  278. *
  279. ******************************************************************************/
  280. acpi_status acpi_disable_event(u32 event, u32 flags)
  281. {
  282. acpi_status status = AE_OK;
  283. u32 value;
  284. ACPI_FUNCTION_TRACE(acpi_disable_event);
  285. /* Decode the Fixed Event */
  286. if (event > ACPI_EVENT_MAX) {
  287. return_ACPI_STATUS(AE_BAD_PARAMETER);
  288. }
  289. /*
  290. * Disable the requested fixed event (by writing a zero to the enable
  291. * register bit)
  292. */
  293. status =
  294. acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
  295. enable_register_id, ACPI_DISABLE_EVENT);
  296. if (ACPI_FAILURE(status)) {
  297. return_ACPI_STATUS(status);
  298. }
  299. status =
  300. acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
  301. enable_register_id, &value);
  302. if (ACPI_FAILURE(status)) {
  303. return_ACPI_STATUS(status);
  304. }
  305. if (value != 0) {
  306. ACPI_ERROR((AE_INFO,
  307. "Could not disable %s events",
  308. acpi_ut_get_event_name(event)));
  309. return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
  310. }
  311. return_ACPI_STATUS(status);
  312. }
  313. ACPI_EXPORT_SYMBOL(acpi_disable_event)
  314. /*******************************************************************************
  315. *
  316. * FUNCTION: acpi_clear_event
  317. *
  318. * PARAMETERS: Event - The fixed event to be cleared
  319. *
  320. * RETURN: Status
  321. *
  322. * DESCRIPTION: Clear an ACPI event (fixed)
  323. *
  324. ******************************************************************************/
  325. acpi_status acpi_clear_event(u32 event)
  326. {
  327. acpi_status status = AE_OK;
  328. ACPI_FUNCTION_TRACE(acpi_clear_event);
  329. /* Decode the Fixed Event */
  330. if (event > ACPI_EVENT_MAX) {
  331. return_ACPI_STATUS(AE_BAD_PARAMETER);
  332. }
  333. /*
  334. * Clear the requested fixed event (By writing a one to the status
  335. * register bit)
  336. */
  337. status =
  338. acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
  339. status_register_id, ACPI_CLEAR_STATUS);
  340. return_ACPI_STATUS(status);
  341. }
  342. ACPI_EXPORT_SYMBOL(acpi_clear_event)
  343. /*******************************************************************************
  344. *
  345. * FUNCTION: acpi_clear_gpe
  346. *
  347. * PARAMETERS: gpe_device - Parent GPE Device
  348. * gpe_number - GPE level within the GPE block
  349. * Flags - Called from an ISR or not
  350. *
  351. * RETURN: Status
  352. *
  353. * DESCRIPTION: Clear an ACPI event (general purpose)
  354. *
  355. ******************************************************************************/
  356. acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
  357. {
  358. acpi_status status = AE_OK;
  359. struct acpi_gpe_event_info *gpe_event_info;
  360. ACPI_FUNCTION_TRACE(acpi_clear_gpe);
  361. /* Use semaphore lock if not executing at interrupt level */
  362. if (flags & ACPI_NOT_ISR) {
  363. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  364. if (ACPI_FAILURE(status)) {
  365. return_ACPI_STATUS(status);
  366. }
  367. }
  368. /* Ensure that we have a valid GPE number */
  369. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  370. if (!gpe_event_info) {
  371. status = AE_BAD_PARAMETER;
  372. goto unlock_and_exit;
  373. }
  374. status = acpi_hw_clear_gpe(gpe_event_info);
  375. unlock_and_exit:
  376. if (flags & ACPI_NOT_ISR) {
  377. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  378. }
  379. return_ACPI_STATUS(status);
  380. }
  381. ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
  382. /*******************************************************************************
  383. *
  384. * FUNCTION: acpi_get_event_status
  385. *
  386. * PARAMETERS: Event - The fixed event
  387. * event_status - Where the current status of the event will
  388. * be returned
  389. *
  390. * RETURN: Status
  391. *
  392. * DESCRIPTION: Obtains and returns the current status of the event
  393. *
  394. ******************************************************************************/
  395. acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
  396. {
  397. acpi_status status = AE_OK;
  398. u32 value;
  399. ACPI_FUNCTION_TRACE(acpi_get_event_status);
  400. if (!event_status) {
  401. return_ACPI_STATUS(AE_BAD_PARAMETER);
  402. }
  403. /* Decode the Fixed Event */
  404. if (event > ACPI_EVENT_MAX) {
  405. return_ACPI_STATUS(AE_BAD_PARAMETER);
  406. }
  407. /* Get the status of the requested fixed event */
  408. status =
  409. acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
  410. enable_register_id, &value);
  411. if (ACPI_FAILURE(status))
  412. return_ACPI_STATUS(status);
  413. *event_status = value;
  414. status =
  415. acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
  416. status_register_id, &value);
  417. if (ACPI_FAILURE(status))
  418. return_ACPI_STATUS(status);
  419. if (value)
  420. *event_status |= ACPI_EVENT_FLAG_SET;
  421. if (acpi_gbl_fixed_event_handlers[event].handler)
  422. *event_status |= ACPI_EVENT_FLAG_HANDLE;
  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. if (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)
  464. *event_status |= ACPI_EVENT_FLAG_HANDLE;
  465. unlock_and_exit:
  466. if (flags & ACPI_NOT_ISR) {
  467. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  468. }
  469. return_ACPI_STATUS(status);
  470. }
  471. ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
  472. /*******************************************************************************
  473. *
  474. * FUNCTION: acpi_install_gpe_block
  475. *
  476. * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
  477. * gpe_block_address - Address and space_iD
  478. * register_count - Number of GPE register pairs in the block
  479. * interrupt_number - H/W interrupt for the block
  480. *
  481. * RETURN: Status
  482. *
  483. * DESCRIPTION: Create and Install a block of GPE registers
  484. *
  485. ******************************************************************************/
  486. acpi_status
  487. acpi_install_gpe_block(acpi_handle gpe_device,
  488. struct acpi_generic_address *gpe_block_address,
  489. u32 register_count, u32 interrupt_number)
  490. {
  491. acpi_status status;
  492. union acpi_operand_object *obj_desc;
  493. struct acpi_namespace_node *node;
  494. struct acpi_gpe_block_info *gpe_block;
  495. ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
  496. if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
  497. return_ACPI_STATUS(AE_BAD_PARAMETER);
  498. }
  499. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  500. if (ACPI_FAILURE(status)) {
  501. return (status);
  502. }
  503. node = acpi_ns_map_handle_to_node(gpe_device);
  504. if (!node) {
  505. status = AE_BAD_PARAMETER;
  506. goto unlock_and_exit;
  507. }
  508. /*
  509. * For user-installed GPE Block Devices, the gpe_block_base_number
  510. * is always zero
  511. */
  512. status =
  513. acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0,
  514. interrupt_number, &gpe_block);
  515. if (ACPI_FAILURE(status)) {
  516. goto unlock_and_exit;
  517. }
  518. /* Run the _PRW methods and enable the GPEs */
  519. status = acpi_ev_initialize_gpe_block(node, gpe_block);
  520. if (ACPI_FAILURE(status)) {
  521. goto unlock_and_exit;
  522. }
  523. /* Get the device_object attached to the node */
  524. obj_desc = acpi_ns_get_attached_object(node);
  525. if (!obj_desc) {
  526. /* No object, create a new one */
  527. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
  528. if (!obj_desc) {
  529. status = AE_NO_MEMORY;
  530. goto unlock_and_exit;
  531. }
  532. status =
  533. acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
  534. /* Remove local reference to the object */
  535. acpi_ut_remove_reference(obj_desc);
  536. if (ACPI_FAILURE(status)) {
  537. goto unlock_and_exit;
  538. }
  539. }
  540. /* Install the GPE block in the device_object */
  541. obj_desc->device.gpe_block = gpe_block;
  542. unlock_and_exit:
  543. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  544. return_ACPI_STATUS(status);
  545. }
  546. ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
  547. /*******************************************************************************
  548. *
  549. * FUNCTION: acpi_remove_gpe_block
  550. *
  551. * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
  552. *
  553. * RETURN: Status
  554. *
  555. * DESCRIPTION: Remove a previously installed block of GPE registers
  556. *
  557. ******************************************************************************/
  558. acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
  559. {
  560. union acpi_operand_object *obj_desc;
  561. acpi_status status;
  562. struct acpi_namespace_node *node;
  563. ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
  564. if (!gpe_device) {
  565. return_ACPI_STATUS(AE_BAD_PARAMETER);
  566. }
  567. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  568. if (ACPI_FAILURE(status)) {
  569. return (status);
  570. }
  571. node = acpi_ns_map_handle_to_node(gpe_device);
  572. if (!node) {
  573. status = AE_BAD_PARAMETER;
  574. goto unlock_and_exit;
  575. }
  576. /* Get the device_object attached to the node */
  577. obj_desc = acpi_ns_get_attached_object(node);
  578. if (!obj_desc || !obj_desc->device.gpe_block) {
  579. return_ACPI_STATUS(AE_NULL_OBJECT);
  580. }
  581. /* Delete the GPE block (but not the device_object) */
  582. status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
  583. if (ACPI_SUCCESS(status)) {
  584. obj_desc->device.gpe_block = NULL;
  585. }
  586. unlock_and_exit:
  587. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  588. return_ACPI_STATUS(status);
  589. }
  590. ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)
  591. /*******************************************************************************
  592. *
  593. * FUNCTION: acpi_get_gpe_device
  594. *
  595. * PARAMETERS: Index - System GPE index (0-current_gpe_count)
  596. * gpe_device - Where the parent GPE Device is returned
  597. *
  598. * RETURN: Status
  599. *
  600. * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
  601. * gpe device indicates that the gpe number is contained in one of
  602. * the FADT-defined gpe blocks. Otherwise, the GPE block device.
  603. *
  604. ******************************************************************************/
  605. acpi_status
  606. acpi_get_gpe_device(u32 index, acpi_handle *gpe_device)
  607. {
  608. struct acpi_gpe_device_info info;
  609. acpi_status status;
  610. ACPI_FUNCTION_TRACE(acpi_get_gpe_device);
  611. if (!gpe_device) {
  612. return_ACPI_STATUS(AE_BAD_PARAMETER);
  613. }
  614. if (index >= acpi_current_gpe_count) {
  615. return_ACPI_STATUS(AE_NOT_EXIST);
  616. }
  617. /* Setup and walk the GPE list */
  618. info.index = index;
  619. info.status = AE_NOT_EXIST;
  620. info.gpe_device = NULL;
  621. info.next_block_base_index = 0;
  622. status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info);
  623. if (ACPI_FAILURE(status)) {
  624. return_ACPI_STATUS(status);
  625. }
  626. *gpe_device = info.gpe_device;
  627. return_ACPI_STATUS(info.status);
  628. }
  629. ACPI_EXPORT_SYMBOL(acpi_get_gpe_device)
  630. /*******************************************************************************
  631. *
  632. * FUNCTION: acpi_ev_get_gpe_device
  633. *
  634. * PARAMETERS: GPE_WALK_CALLBACK
  635. *
  636. * RETURN: Status
  637. *
  638. * DESCRIPTION: Matches the input GPE index (0-current_gpe_count) with a GPE
  639. * block device. NULL if the GPE is one of the FADT-defined GPEs.
  640. *
  641. ******************************************************************************/
  642. acpi_status
  643. acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
  644. struct acpi_gpe_block_info *gpe_block, void *context)
  645. {
  646. struct acpi_gpe_device_info *info = context;
  647. /* Increment Index by the number of GPEs in this block */
  648. info->next_block_base_index +=
  649. (gpe_block->register_count * ACPI_GPE_REGISTER_WIDTH);
  650. if (info->index < info->next_block_base_index) {
  651. /*
  652. * The GPE index is within this block, get the node. Leave the node
  653. * NULL for the FADT-defined GPEs
  654. */
  655. if ((gpe_block->node)->type == ACPI_TYPE_DEVICE) {
  656. info->gpe_device = gpe_block->node;
  657. }
  658. info->status = AE_OK;
  659. return (AE_CTRL_END);
  660. }
  661. return (AE_OK);
  662. }
  663. /******************************************************************************
  664. *
  665. * FUNCTION: acpi_disable_all_gpes
  666. *
  667. * PARAMETERS: None
  668. *
  669. * RETURN: Status
  670. *
  671. * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
  672. *
  673. ******************************************************************************/
  674. acpi_status acpi_disable_all_gpes(void)
  675. {
  676. acpi_status status;
  677. ACPI_FUNCTION_TRACE(acpi_disable_all_gpes);
  678. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  679. if (ACPI_FAILURE(status)) {
  680. return_ACPI_STATUS(status);
  681. }
  682. status = acpi_hw_disable_all_gpes();
  683. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  684. return_ACPI_STATUS(status);
  685. }
  686. /******************************************************************************
  687. *
  688. * FUNCTION: acpi_enable_all_runtime_gpes
  689. *
  690. * PARAMETERS: None
  691. *
  692. * RETURN: Status
  693. *
  694. * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
  695. *
  696. ******************************************************************************/
  697. acpi_status acpi_enable_all_runtime_gpes(void)
  698. {
  699. acpi_status status;
  700. ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes);
  701. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  702. if (ACPI_FAILURE(status)) {
  703. return_ACPI_STATUS(status);
  704. }
  705. status = acpi_hw_enable_all_runtime_gpes();
  706. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  707. return_ACPI_STATUS(status);
  708. }