evxfevnt.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917
  1. /******************************************************************************
  2. *
  3. * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2010, 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. static 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
  171. *
  172. * PARAMETERS: gpe_device - Parent GPE Device
  173. * gpe_number - GPE level within the GPE block
  174. * action - Enable or disable
  175. * Called from ISR or not
  176. *
  177. * RETURN: Status
  178. *
  179. * DESCRIPTION: Enable or disable an ACPI event (general purpose)
  180. *
  181. ******************************************************************************/
  182. acpi_status acpi_set_gpe(acpi_handle gpe_device, u32 gpe_number, u8 action)
  183. {
  184. acpi_status status = AE_OK;
  185. acpi_cpu_flags flags;
  186. struct acpi_gpe_event_info *gpe_event_info;
  187. ACPI_FUNCTION_TRACE(acpi_set_gpe);
  188. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  189. /* Ensure that we have a valid GPE number */
  190. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  191. if (!gpe_event_info) {
  192. status = AE_BAD_PARAMETER;
  193. goto unlock_and_exit;
  194. }
  195. /* Perform the action */
  196. switch (action) {
  197. case ACPI_GPE_ENABLE:
  198. status = acpi_ev_enable_gpe(gpe_event_info);
  199. break;
  200. case ACPI_GPE_DISABLE:
  201. status = acpi_ev_disable_gpe(gpe_event_info);
  202. break;
  203. default:
  204. ACPI_ERROR((AE_INFO, "Invalid action\n"));
  205. status = AE_BAD_PARAMETER;
  206. break;
  207. }
  208. unlock_and_exit:
  209. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  210. return_ACPI_STATUS(status);
  211. }
  212. ACPI_EXPORT_SYMBOL(acpi_set_gpe)
  213. /*******************************************************************************
  214. *
  215. * FUNCTION: acpi_enable_gpe
  216. *
  217. * PARAMETERS: gpe_device - Parent GPE Device
  218. * gpe_number - GPE level within the GPE block
  219. * type - Purpose the GPE will be used for
  220. *
  221. * RETURN: Status
  222. *
  223. * DESCRIPTION: Take a reference to a GPE and enable it if necessary
  224. *
  225. ******************************************************************************/
  226. acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 type)
  227. {
  228. acpi_status status = AE_OK;
  229. acpi_cpu_flags flags;
  230. struct acpi_gpe_event_info *gpe_event_info;
  231. ACPI_FUNCTION_TRACE(acpi_enable_gpe);
  232. if (type & ~ACPI_GPE_TYPE_WAKE_RUN)
  233. return_ACPI_STATUS(AE_BAD_PARAMETER);
  234. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  235. /* Ensure that we have a valid GPE number */
  236. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  237. if (!gpe_event_info) {
  238. status = AE_BAD_PARAMETER;
  239. goto unlock_and_exit;
  240. }
  241. if (type & ACPI_GPE_TYPE_RUNTIME) {
  242. if (++gpe_event_info->runtime_count == 1) {
  243. status = acpi_ev_enable_gpe(gpe_event_info);
  244. if (ACPI_FAILURE(status))
  245. gpe_event_info->runtime_count--;
  246. }
  247. }
  248. if (type & ACPI_GPE_TYPE_WAKE) {
  249. if (!(gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) {
  250. status = AE_BAD_PARAMETER;
  251. goto unlock_and_exit;
  252. }
  253. /*
  254. * Wake-up GPEs are only enabled right prior to putting the
  255. * system into a sleep state.
  256. */
  257. if (++gpe_event_info->wakeup_count == 1)
  258. acpi_ev_update_gpe_enable_masks(gpe_event_info);
  259. }
  260. unlock_and_exit:
  261. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  262. return_ACPI_STATUS(status);
  263. }
  264. ACPI_EXPORT_SYMBOL(acpi_enable_gpe)
  265. /*******************************************************************************
  266. *
  267. * FUNCTION: acpi_disable_gpe
  268. *
  269. * PARAMETERS: gpe_device - Parent GPE Device
  270. * gpe_number - GPE level within the GPE block
  271. * type - Purpose the GPE won't be used for any more
  272. *
  273. * RETURN: Status
  274. *
  275. * DESCRIPTION: Release a reference to a GPE and disable it if necessary
  276. *
  277. ******************************************************************************/
  278. acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 type)
  279. {
  280. acpi_status status = AE_OK;
  281. acpi_cpu_flags flags;
  282. struct acpi_gpe_event_info *gpe_event_info;
  283. ACPI_FUNCTION_TRACE(acpi_disable_gpe);
  284. if (type & ~ACPI_GPE_TYPE_WAKE_RUN)
  285. return_ACPI_STATUS(AE_BAD_PARAMETER);
  286. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  287. /* Ensure that we have a valid GPE number */
  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 ((type & ACPI_GPE_TYPE_RUNTIME) && gpe_event_info->runtime_count) {
  294. if (--gpe_event_info->runtime_count == 0)
  295. status = acpi_ev_disable_gpe(gpe_event_info);
  296. }
  297. if ((type & ACPI_GPE_TYPE_WAKE) && gpe_event_info->wakeup_count) {
  298. /*
  299. * Wake-up GPEs are not enabled after leaving system sleep
  300. * states, so we don't need to disable them here.
  301. */
  302. if (--gpe_event_info->wakeup_count == 0)
  303. acpi_ev_update_gpe_enable_masks(gpe_event_info);
  304. }
  305. unlock_and_exit:
  306. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  307. return_ACPI_STATUS(status);
  308. }
  309. ACPI_EXPORT_SYMBOL(acpi_disable_gpe)
  310. /*******************************************************************************
  311. *
  312. * FUNCTION: acpi_disable_event
  313. *
  314. * PARAMETERS: Event - The fixed eventto be enabled
  315. * Flags - Reserved
  316. *
  317. * RETURN: Status
  318. *
  319. * DESCRIPTION: Disable an ACPI event (fixed)
  320. *
  321. ******************************************************************************/
  322. acpi_status acpi_disable_event(u32 event, u32 flags)
  323. {
  324. acpi_status status = AE_OK;
  325. u32 value;
  326. ACPI_FUNCTION_TRACE(acpi_disable_event);
  327. /* Decode the Fixed Event */
  328. if (event > ACPI_EVENT_MAX) {
  329. return_ACPI_STATUS(AE_BAD_PARAMETER);
  330. }
  331. /*
  332. * Disable the requested fixed event (by writing a zero to the enable
  333. * register bit)
  334. */
  335. status =
  336. acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
  337. enable_register_id, ACPI_DISABLE_EVENT);
  338. if (ACPI_FAILURE(status)) {
  339. return_ACPI_STATUS(status);
  340. }
  341. status =
  342. acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
  343. enable_register_id, &value);
  344. if (ACPI_FAILURE(status)) {
  345. return_ACPI_STATUS(status);
  346. }
  347. if (value != 0) {
  348. ACPI_ERROR((AE_INFO,
  349. "Could not disable %s events",
  350. acpi_ut_get_event_name(event)));
  351. return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
  352. }
  353. return_ACPI_STATUS(status);
  354. }
  355. ACPI_EXPORT_SYMBOL(acpi_disable_event)
  356. /*******************************************************************************
  357. *
  358. * FUNCTION: acpi_clear_event
  359. *
  360. * PARAMETERS: Event - The fixed event to be cleared
  361. *
  362. * RETURN: Status
  363. *
  364. * DESCRIPTION: Clear an ACPI event (fixed)
  365. *
  366. ******************************************************************************/
  367. acpi_status acpi_clear_event(u32 event)
  368. {
  369. acpi_status status = AE_OK;
  370. ACPI_FUNCTION_TRACE(acpi_clear_event);
  371. /* Decode the Fixed Event */
  372. if (event > ACPI_EVENT_MAX) {
  373. return_ACPI_STATUS(AE_BAD_PARAMETER);
  374. }
  375. /*
  376. * Clear the requested fixed event (By writing a one to the status
  377. * register bit)
  378. */
  379. status =
  380. acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
  381. status_register_id, ACPI_CLEAR_STATUS);
  382. return_ACPI_STATUS(status);
  383. }
  384. ACPI_EXPORT_SYMBOL(acpi_clear_event)
  385. /*******************************************************************************
  386. *
  387. * FUNCTION: acpi_clear_gpe
  388. *
  389. * PARAMETERS: gpe_device - Parent GPE Device
  390. * gpe_number - GPE level within the GPE block
  391. * Flags - Called from an ISR or not
  392. *
  393. * RETURN: Status
  394. *
  395. * DESCRIPTION: Clear an ACPI event (general purpose)
  396. *
  397. ******************************************************************************/
  398. acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
  399. {
  400. acpi_status status = AE_OK;
  401. struct acpi_gpe_event_info *gpe_event_info;
  402. ACPI_FUNCTION_TRACE(acpi_clear_gpe);
  403. /* Use semaphore lock if not executing at interrupt level */
  404. if (flags & ACPI_NOT_ISR) {
  405. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  406. if (ACPI_FAILURE(status)) {
  407. return_ACPI_STATUS(status);
  408. }
  409. }
  410. /* Ensure that we have a valid GPE number */
  411. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  412. if (!gpe_event_info) {
  413. status = AE_BAD_PARAMETER;
  414. goto unlock_and_exit;
  415. }
  416. status = acpi_hw_clear_gpe(gpe_event_info);
  417. unlock_and_exit:
  418. if (flags & ACPI_NOT_ISR) {
  419. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  420. }
  421. return_ACPI_STATUS(status);
  422. }
  423. ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
  424. /*******************************************************************************
  425. *
  426. * FUNCTION: acpi_get_event_status
  427. *
  428. * PARAMETERS: Event - The fixed event
  429. * event_status - Where the current status of the event will
  430. * be returned
  431. *
  432. * RETURN: Status
  433. *
  434. * DESCRIPTION: Obtains and returns the current status of the event
  435. *
  436. ******************************************************************************/
  437. acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
  438. {
  439. acpi_status status = AE_OK;
  440. u32 value;
  441. ACPI_FUNCTION_TRACE(acpi_get_event_status);
  442. if (!event_status) {
  443. return_ACPI_STATUS(AE_BAD_PARAMETER);
  444. }
  445. /* Decode the Fixed Event */
  446. if (event > ACPI_EVENT_MAX) {
  447. return_ACPI_STATUS(AE_BAD_PARAMETER);
  448. }
  449. /* Get the status of the requested fixed event */
  450. status =
  451. acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
  452. enable_register_id, &value);
  453. if (ACPI_FAILURE(status))
  454. return_ACPI_STATUS(status);
  455. *event_status = value;
  456. status =
  457. acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
  458. status_register_id, &value);
  459. if (ACPI_FAILURE(status))
  460. return_ACPI_STATUS(status);
  461. if (value)
  462. *event_status |= ACPI_EVENT_FLAG_SET;
  463. if (acpi_gbl_fixed_event_handlers[event].handler)
  464. *event_status |= ACPI_EVENT_FLAG_HANDLE;
  465. return_ACPI_STATUS(status);
  466. }
  467. ACPI_EXPORT_SYMBOL(acpi_get_event_status)
  468. /*******************************************************************************
  469. *
  470. * FUNCTION: acpi_get_gpe_status
  471. *
  472. * PARAMETERS: gpe_device - Parent GPE Device
  473. * gpe_number - GPE level within the GPE block
  474. * Flags - Called from an ISR or not
  475. * event_status - Where the current status of the event will
  476. * be returned
  477. *
  478. * RETURN: Status
  479. *
  480. * DESCRIPTION: Get status of an event (general purpose)
  481. *
  482. ******************************************************************************/
  483. acpi_status
  484. acpi_get_gpe_status(acpi_handle gpe_device,
  485. u32 gpe_number, u32 flags, acpi_event_status * event_status)
  486. {
  487. acpi_status status = AE_OK;
  488. struct acpi_gpe_event_info *gpe_event_info;
  489. ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
  490. /* Use semaphore lock if not executing at interrupt level */
  491. if (flags & ACPI_NOT_ISR) {
  492. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  493. if (ACPI_FAILURE(status)) {
  494. return_ACPI_STATUS(status);
  495. }
  496. }
  497. /* Ensure that we have a valid GPE number */
  498. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  499. if (!gpe_event_info) {
  500. status = AE_BAD_PARAMETER;
  501. goto unlock_and_exit;
  502. }
  503. /* Obtain status on the requested GPE number */
  504. status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
  505. if (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)
  506. *event_status |= ACPI_EVENT_FLAG_HANDLE;
  507. unlock_and_exit:
  508. if (flags & ACPI_NOT_ISR) {
  509. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  510. }
  511. return_ACPI_STATUS(status);
  512. }
  513. ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
  514. /*******************************************************************************
  515. *
  516. * FUNCTION: acpi_install_gpe_block
  517. *
  518. * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
  519. * gpe_block_address - Address and space_iD
  520. * register_count - Number of GPE register pairs in the block
  521. * interrupt_number - H/W interrupt for the block
  522. *
  523. * RETURN: Status
  524. *
  525. * DESCRIPTION: Create and Install a block of GPE registers
  526. *
  527. ******************************************************************************/
  528. acpi_status
  529. acpi_install_gpe_block(acpi_handle gpe_device,
  530. struct acpi_generic_address *gpe_block_address,
  531. u32 register_count, u32 interrupt_number)
  532. {
  533. acpi_status status;
  534. union acpi_operand_object *obj_desc;
  535. struct acpi_namespace_node *node;
  536. struct acpi_gpe_block_info *gpe_block;
  537. ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
  538. if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
  539. return_ACPI_STATUS(AE_BAD_PARAMETER);
  540. }
  541. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  542. if (ACPI_FAILURE(status)) {
  543. return (status);
  544. }
  545. node = acpi_ns_validate_handle(gpe_device);
  546. if (!node) {
  547. status = AE_BAD_PARAMETER;
  548. goto unlock_and_exit;
  549. }
  550. /*
  551. * For user-installed GPE Block Devices, the gpe_block_base_number
  552. * is always zero
  553. */
  554. status =
  555. acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0,
  556. interrupt_number, &gpe_block);
  557. if (ACPI_FAILURE(status)) {
  558. goto unlock_and_exit;
  559. }
  560. /* Run the _PRW methods and enable the GPEs */
  561. status = acpi_ev_initialize_gpe_block(node, gpe_block);
  562. if (ACPI_FAILURE(status)) {
  563. goto unlock_and_exit;
  564. }
  565. /* Get the device_object attached to the node */
  566. obj_desc = acpi_ns_get_attached_object(node);
  567. if (!obj_desc) {
  568. /* No object, create a new one */
  569. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
  570. if (!obj_desc) {
  571. status = AE_NO_MEMORY;
  572. goto unlock_and_exit;
  573. }
  574. status =
  575. acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
  576. /* Remove local reference to the object */
  577. acpi_ut_remove_reference(obj_desc);
  578. if (ACPI_FAILURE(status)) {
  579. goto unlock_and_exit;
  580. }
  581. }
  582. /* Install the GPE block in the device_object */
  583. obj_desc->device.gpe_block = gpe_block;
  584. unlock_and_exit:
  585. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  586. return_ACPI_STATUS(status);
  587. }
  588. ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
  589. /*******************************************************************************
  590. *
  591. * FUNCTION: acpi_remove_gpe_block
  592. *
  593. * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
  594. *
  595. * RETURN: Status
  596. *
  597. * DESCRIPTION: Remove a previously installed block of GPE registers
  598. *
  599. ******************************************************************************/
  600. acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
  601. {
  602. union acpi_operand_object *obj_desc;
  603. acpi_status status;
  604. struct acpi_namespace_node *node;
  605. ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
  606. if (!gpe_device) {
  607. return_ACPI_STATUS(AE_BAD_PARAMETER);
  608. }
  609. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  610. if (ACPI_FAILURE(status)) {
  611. return (status);
  612. }
  613. node = acpi_ns_validate_handle(gpe_device);
  614. if (!node) {
  615. status = AE_BAD_PARAMETER;
  616. goto unlock_and_exit;
  617. }
  618. /* Get the device_object attached to the node */
  619. obj_desc = acpi_ns_get_attached_object(node);
  620. if (!obj_desc || !obj_desc->device.gpe_block) {
  621. return_ACPI_STATUS(AE_NULL_OBJECT);
  622. }
  623. /* Delete the GPE block (but not the device_object) */
  624. status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
  625. if (ACPI_SUCCESS(status)) {
  626. obj_desc->device.gpe_block = NULL;
  627. }
  628. unlock_and_exit:
  629. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  630. return_ACPI_STATUS(status);
  631. }
  632. ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)
  633. /*******************************************************************************
  634. *
  635. * FUNCTION: acpi_get_gpe_device
  636. *
  637. * PARAMETERS: Index - System GPE index (0-current_gpe_count)
  638. * gpe_device - Where the parent GPE Device is returned
  639. *
  640. * RETURN: Status
  641. *
  642. * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
  643. * gpe device indicates that the gpe number is contained in one of
  644. * the FADT-defined gpe blocks. Otherwise, the GPE block device.
  645. *
  646. ******************************************************************************/
  647. acpi_status
  648. acpi_get_gpe_device(u32 index, acpi_handle *gpe_device)
  649. {
  650. struct acpi_gpe_device_info info;
  651. acpi_status status;
  652. ACPI_FUNCTION_TRACE(acpi_get_gpe_device);
  653. if (!gpe_device) {
  654. return_ACPI_STATUS(AE_BAD_PARAMETER);
  655. }
  656. if (index >= acpi_current_gpe_count) {
  657. return_ACPI_STATUS(AE_NOT_EXIST);
  658. }
  659. /* Setup and walk the GPE list */
  660. info.index = index;
  661. info.status = AE_NOT_EXIST;
  662. info.gpe_device = NULL;
  663. info.next_block_base_index = 0;
  664. status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info);
  665. if (ACPI_FAILURE(status)) {
  666. return_ACPI_STATUS(status);
  667. }
  668. *gpe_device = info.gpe_device;
  669. return_ACPI_STATUS(info.status);
  670. }
  671. ACPI_EXPORT_SYMBOL(acpi_get_gpe_device)
  672. /*******************************************************************************
  673. *
  674. * FUNCTION: acpi_ev_get_gpe_device
  675. *
  676. * PARAMETERS: GPE_WALK_CALLBACK
  677. *
  678. * RETURN: Status
  679. *
  680. * DESCRIPTION: Matches the input GPE index (0-current_gpe_count) with a GPE
  681. * block device. NULL if the GPE is one of the FADT-defined GPEs.
  682. *
  683. ******************************************************************************/
  684. static acpi_status
  685. acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
  686. struct acpi_gpe_block_info *gpe_block, void *context)
  687. {
  688. struct acpi_gpe_device_info *info = context;
  689. /* Increment Index by the number of GPEs in this block */
  690. info->next_block_base_index +=
  691. (gpe_block->register_count * ACPI_GPE_REGISTER_WIDTH);
  692. if (info->index < info->next_block_base_index) {
  693. /*
  694. * The GPE index is within this block, get the node. Leave the node
  695. * NULL for the FADT-defined GPEs
  696. */
  697. if ((gpe_block->node)->type == ACPI_TYPE_DEVICE) {
  698. info->gpe_device = gpe_block->node;
  699. }
  700. info->status = AE_OK;
  701. return (AE_CTRL_END);
  702. }
  703. return (AE_OK);
  704. }
  705. /******************************************************************************
  706. *
  707. * FUNCTION: acpi_disable_all_gpes
  708. *
  709. * PARAMETERS: None
  710. *
  711. * RETURN: Status
  712. *
  713. * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
  714. *
  715. ******************************************************************************/
  716. acpi_status acpi_disable_all_gpes(void)
  717. {
  718. acpi_status status;
  719. ACPI_FUNCTION_TRACE(acpi_disable_all_gpes);
  720. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  721. if (ACPI_FAILURE(status)) {
  722. return_ACPI_STATUS(status);
  723. }
  724. status = acpi_hw_disable_all_gpes();
  725. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  726. return_ACPI_STATUS(status);
  727. }
  728. /******************************************************************************
  729. *
  730. * FUNCTION: acpi_enable_all_runtime_gpes
  731. *
  732. * PARAMETERS: None
  733. *
  734. * RETURN: Status
  735. *
  736. * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
  737. *
  738. ******************************************************************************/
  739. acpi_status acpi_enable_all_runtime_gpes(void)
  740. {
  741. acpi_status status;
  742. ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes);
  743. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  744. if (ACPI_FAILURE(status)) {
  745. return_ACPI_STATUS(status);
  746. }
  747. status = acpi_hw_enable_all_runtime_gpes();
  748. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  749. return_ACPI_STATUS(status);
  750. }