evxfevnt.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923
  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;
  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. return_ACPI_STATUS(AE_OK);
  77. }
  78. /* Transition to ACPI mode */
  79. status = acpi_hw_set_mode(ACPI_SYS_MODE_ACPI);
  80. if (ACPI_FAILURE(status)) {
  81. ACPI_ERROR((AE_INFO,
  82. "Could not transition to ACPI mode"));
  83. return_ACPI_STATUS(status);
  84. }
  85. /* Sanity check that transition succeeded */
  86. if (acpi_hw_get_mode() != ACPI_SYS_MODE_ACPI) {
  87. ACPI_ERROR((AE_INFO,
  88. "Hardware did not enter ACPI mode"));
  89. return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
  90. }
  91. ACPI_DEBUG_PRINT((ACPI_DB_INIT,
  92. "Transition to ACPI mode successful\n"));
  93. return_ACPI_STATUS(AE_OK);
  94. }
  95. ACPI_EXPORT_SYMBOL(acpi_enable)
  96. /*******************************************************************************
  97. *
  98. * FUNCTION: acpi_disable
  99. *
  100. * PARAMETERS: None
  101. *
  102. * RETURN: Status
  103. *
  104. * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
  105. *
  106. ******************************************************************************/
  107. acpi_status acpi_disable(void)
  108. {
  109. acpi_status status = AE_OK;
  110. ACPI_FUNCTION_TRACE(acpi_disable);
  111. if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {
  112. ACPI_DEBUG_PRINT((ACPI_DB_INIT,
  113. "System is already in legacy (non-ACPI) mode\n"));
  114. } else {
  115. /* Transition to LEGACY mode */
  116. status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY);
  117. if (ACPI_FAILURE(status)) {
  118. ACPI_ERROR((AE_INFO,
  119. "Could not exit ACPI mode to legacy mode"));
  120. return_ACPI_STATUS(status);
  121. }
  122. ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI mode disabled\n"));
  123. }
  124. return_ACPI_STATUS(status);
  125. }
  126. ACPI_EXPORT_SYMBOL(acpi_disable)
  127. /*******************************************************************************
  128. *
  129. * FUNCTION: acpi_enable_event
  130. *
  131. * PARAMETERS: Event - The fixed eventto be enabled
  132. * Flags - Reserved
  133. *
  134. * RETURN: Status
  135. *
  136. * DESCRIPTION: Enable an ACPI event (fixed)
  137. *
  138. ******************************************************************************/
  139. acpi_status acpi_enable_event(u32 event, u32 flags)
  140. {
  141. acpi_status status = AE_OK;
  142. u32 value;
  143. ACPI_FUNCTION_TRACE(acpi_enable_event);
  144. /* Decode the Fixed Event */
  145. if (event > ACPI_EVENT_MAX) {
  146. return_ACPI_STATUS(AE_BAD_PARAMETER);
  147. }
  148. /*
  149. * Enable the requested fixed event (by writing a one to the enable
  150. * register bit)
  151. */
  152. status =
  153. acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
  154. enable_register_id, ACPI_ENABLE_EVENT);
  155. if (ACPI_FAILURE(status)) {
  156. return_ACPI_STATUS(status);
  157. }
  158. /* Make sure that the hardware responded */
  159. status =
  160. acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
  161. enable_register_id, &value);
  162. if (ACPI_FAILURE(status)) {
  163. return_ACPI_STATUS(status);
  164. }
  165. if (value != 1) {
  166. ACPI_ERROR((AE_INFO,
  167. "Could not enable %s event",
  168. acpi_ut_get_event_name(event)));
  169. return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
  170. }
  171. return_ACPI_STATUS(status);
  172. }
  173. ACPI_EXPORT_SYMBOL(acpi_enable_event)
  174. /*******************************************************************************
  175. *
  176. * FUNCTION: acpi_gpe_wakeup
  177. *
  178. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  179. * gpe_number - GPE level within the GPE block
  180. * Action - Enable or Disable
  181. *
  182. * RETURN: Status
  183. *
  184. * DESCRIPTION: Set or clear the GPE's wakeup enable mask bit.
  185. *
  186. ******************************************************************************/
  187. acpi_status acpi_gpe_wakeup(acpi_handle gpe_device, u32 gpe_number, u8 action)
  188. {
  189. acpi_status status = AE_OK;
  190. struct acpi_gpe_event_info *gpe_event_info;
  191. struct acpi_gpe_register_info *gpe_register_info;
  192. acpi_cpu_flags flags;
  193. u32 register_bit;
  194. ACPI_FUNCTION_TRACE(acpi_gpe_wakeup);
  195. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  196. /* Ensure that we have a valid GPE number */
  197. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  198. if (!gpe_event_info || !(gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) {
  199. status = AE_BAD_PARAMETER;
  200. goto unlock_and_exit;
  201. }
  202. gpe_register_info = gpe_event_info->register_info;
  203. if (!gpe_register_info) {
  204. status = AE_NOT_EXIST;
  205. goto unlock_and_exit;
  206. }
  207. register_bit =
  208. acpi_hw_get_gpe_register_bit(gpe_event_info, gpe_register_info);
  209. /* Perform the action */
  210. switch (action) {
  211. case ACPI_GPE_ENABLE:
  212. ACPI_SET_BIT(gpe_register_info->enable_for_wake,
  213. (u8)register_bit);
  214. break;
  215. case ACPI_GPE_DISABLE:
  216. ACPI_CLEAR_BIT(gpe_register_info->enable_for_wake,
  217. (u8)register_bit);
  218. break;
  219. default:
  220. ACPI_ERROR((AE_INFO, "%u, Invalid action", action));
  221. status = AE_BAD_PARAMETER;
  222. break;
  223. }
  224. unlock_and_exit:
  225. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  226. return_ACPI_STATUS(status);
  227. }
  228. ACPI_EXPORT_SYMBOL(acpi_gpe_wakeup)
  229. /*******************************************************************************
  230. *
  231. * FUNCTION: acpi_enable_gpe
  232. *
  233. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  234. * gpe_number - GPE level within the GPE block
  235. *
  236. * RETURN: Status
  237. *
  238. * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
  239. * hardware-enabled.
  240. *
  241. ******************************************************************************/
  242. acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number)
  243. {
  244. acpi_status status = AE_BAD_PARAMETER;
  245. struct acpi_gpe_event_info *gpe_event_info;
  246. acpi_cpu_flags flags;
  247. ACPI_FUNCTION_TRACE(acpi_enable_gpe);
  248. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  249. /* Ensure that we have a valid GPE number */
  250. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  251. if (gpe_event_info) {
  252. status = acpi_raw_enable_gpe(gpe_event_info);
  253. }
  254. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  255. return_ACPI_STATUS(status);
  256. }
  257. ACPI_EXPORT_SYMBOL(acpi_enable_gpe)
  258. /*******************************************************************************
  259. *
  260. * FUNCTION: acpi_disable_gpe
  261. *
  262. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  263. * gpe_number - GPE level within the GPE block
  264. *
  265. * RETURN: Status
  266. *
  267. * DESCRIPTION: Remove a reference to a GPE. When the last reference is
  268. * removed, only then is the GPE disabled (for runtime GPEs), or
  269. * the GPE mask bit disabled (for wake GPEs)
  270. *
  271. ******************************************************************************/
  272. acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number)
  273. {
  274. acpi_status status = AE_BAD_PARAMETER;
  275. struct acpi_gpe_event_info *gpe_event_info;
  276. acpi_cpu_flags flags;
  277. ACPI_FUNCTION_TRACE(acpi_disable_gpe);
  278. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  279. /* Ensure that we have a valid GPE number */
  280. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  281. if (gpe_event_info) {
  282. status = acpi_raw_disable_gpe(gpe_event_info) ;
  283. }
  284. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  285. return_ACPI_STATUS(status);
  286. }
  287. ACPI_EXPORT_SYMBOL(acpi_disable_gpe)
  288. /*******************************************************************************
  289. *
  290. * FUNCTION: acpi_gpe_can_wake
  291. *
  292. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  293. * gpe_number - GPE level within the GPE block
  294. *
  295. * RETURN: Status
  296. *
  297. * DESCRIPTION: Set the ACPI_GPE_CAN_WAKE flag for the given GPE. If the GPE
  298. * has a corresponding method and is currently enabled, disable it
  299. * (GPEs with corresponding methods are enabled unconditionally
  300. * during initialization, but GPEs that can wake up are expected
  301. * to be initially disabled).
  302. *
  303. ******************************************************************************/
  304. acpi_status acpi_gpe_can_wake(acpi_handle gpe_device, u32 gpe_number)
  305. {
  306. acpi_status status = AE_OK;
  307. struct acpi_gpe_event_info *gpe_event_info;
  308. acpi_cpu_flags flags;
  309. ACPI_FUNCTION_TRACE(acpi_gpe_can_wake);
  310. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  311. /* Ensure that we have a valid GPE number */
  312. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  313. if (!gpe_event_info) {
  314. status = AE_BAD_PARAMETER;
  315. goto unlock_and_exit;
  316. }
  317. if (gpe_event_info->flags & ACPI_GPE_CAN_WAKE) {
  318. goto unlock_and_exit;
  319. }
  320. gpe_event_info->flags |= ACPI_GPE_CAN_WAKE;
  321. if (gpe_event_info->flags & ACPI_GPE_DISPATCH_METHOD) {
  322. (void)acpi_raw_disable_gpe(gpe_event_info);
  323. }
  324. unlock_and_exit:
  325. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  326. return_ACPI_STATUS(status);
  327. }
  328. ACPI_EXPORT_SYMBOL(acpi_gpe_can_wake)
  329. /*******************************************************************************
  330. *
  331. * FUNCTION: acpi_disable_event
  332. *
  333. * PARAMETERS: Event - The fixed eventto be enabled
  334. * Flags - Reserved
  335. *
  336. * RETURN: Status
  337. *
  338. * DESCRIPTION: Disable an ACPI event (fixed)
  339. *
  340. ******************************************************************************/
  341. acpi_status acpi_disable_event(u32 event, u32 flags)
  342. {
  343. acpi_status status = AE_OK;
  344. u32 value;
  345. ACPI_FUNCTION_TRACE(acpi_disable_event);
  346. /* Decode the Fixed Event */
  347. if (event > ACPI_EVENT_MAX) {
  348. return_ACPI_STATUS(AE_BAD_PARAMETER);
  349. }
  350. /*
  351. * Disable the requested fixed event (by writing a zero to the enable
  352. * register bit)
  353. */
  354. status =
  355. acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
  356. enable_register_id, ACPI_DISABLE_EVENT);
  357. if (ACPI_FAILURE(status)) {
  358. return_ACPI_STATUS(status);
  359. }
  360. status =
  361. acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
  362. enable_register_id, &value);
  363. if (ACPI_FAILURE(status)) {
  364. return_ACPI_STATUS(status);
  365. }
  366. if (value != 0) {
  367. ACPI_ERROR((AE_INFO,
  368. "Could not disable %s events",
  369. acpi_ut_get_event_name(event)));
  370. return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
  371. }
  372. return_ACPI_STATUS(status);
  373. }
  374. ACPI_EXPORT_SYMBOL(acpi_disable_event)
  375. /*******************************************************************************
  376. *
  377. * FUNCTION: acpi_clear_event
  378. *
  379. * PARAMETERS: Event - The fixed event to be cleared
  380. *
  381. * RETURN: Status
  382. *
  383. * DESCRIPTION: Clear an ACPI event (fixed)
  384. *
  385. ******************************************************************************/
  386. acpi_status acpi_clear_event(u32 event)
  387. {
  388. acpi_status status = AE_OK;
  389. ACPI_FUNCTION_TRACE(acpi_clear_event);
  390. /* Decode the Fixed Event */
  391. if (event > ACPI_EVENT_MAX) {
  392. return_ACPI_STATUS(AE_BAD_PARAMETER);
  393. }
  394. /*
  395. * Clear the requested fixed event (By writing a one to the status
  396. * register bit)
  397. */
  398. status =
  399. acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
  400. status_register_id, ACPI_CLEAR_STATUS);
  401. return_ACPI_STATUS(status);
  402. }
  403. ACPI_EXPORT_SYMBOL(acpi_clear_event)
  404. /*******************************************************************************
  405. *
  406. * FUNCTION: acpi_clear_gpe
  407. *
  408. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  409. * gpe_number - GPE level within the GPE block
  410. *
  411. * RETURN: Status
  412. *
  413. * DESCRIPTION: Clear an ACPI event (general purpose)
  414. *
  415. ******************************************************************************/
  416. acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number)
  417. {
  418. acpi_status status = AE_OK;
  419. struct acpi_gpe_event_info *gpe_event_info;
  420. acpi_cpu_flags flags;
  421. ACPI_FUNCTION_TRACE(acpi_clear_gpe);
  422. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  423. /* Ensure that we have a valid GPE number */
  424. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  425. if (!gpe_event_info) {
  426. status = AE_BAD_PARAMETER;
  427. goto unlock_and_exit;
  428. }
  429. status = acpi_hw_clear_gpe(gpe_event_info);
  430. unlock_and_exit:
  431. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  432. return_ACPI_STATUS(status);
  433. }
  434. ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
  435. /*******************************************************************************
  436. *
  437. * FUNCTION: acpi_get_event_status
  438. *
  439. * PARAMETERS: Event - The fixed event
  440. * event_status - Where the current status of the event will
  441. * be returned
  442. *
  443. * RETURN: Status
  444. *
  445. * DESCRIPTION: Obtains and returns the current status of the event
  446. *
  447. ******************************************************************************/
  448. acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
  449. {
  450. acpi_status status = AE_OK;
  451. u32 value;
  452. ACPI_FUNCTION_TRACE(acpi_get_event_status);
  453. if (!event_status) {
  454. return_ACPI_STATUS(AE_BAD_PARAMETER);
  455. }
  456. /* Decode the Fixed Event */
  457. if (event > ACPI_EVENT_MAX) {
  458. return_ACPI_STATUS(AE_BAD_PARAMETER);
  459. }
  460. /* Get the status of the requested fixed event */
  461. status =
  462. acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
  463. enable_register_id, &value);
  464. if (ACPI_FAILURE(status))
  465. return_ACPI_STATUS(status);
  466. *event_status = value;
  467. status =
  468. acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
  469. status_register_id, &value);
  470. if (ACPI_FAILURE(status))
  471. return_ACPI_STATUS(status);
  472. if (value)
  473. *event_status |= ACPI_EVENT_FLAG_SET;
  474. if (acpi_gbl_fixed_event_handlers[event].handler)
  475. *event_status |= ACPI_EVENT_FLAG_HANDLE;
  476. return_ACPI_STATUS(status);
  477. }
  478. ACPI_EXPORT_SYMBOL(acpi_get_event_status)
  479. /*******************************************************************************
  480. *
  481. * FUNCTION: acpi_get_gpe_status
  482. *
  483. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  484. * gpe_number - GPE level within the GPE block
  485. * event_status - Where the current status of the event will
  486. * be returned
  487. *
  488. * RETURN: Status
  489. *
  490. * DESCRIPTION: Get status of an event (general purpose)
  491. *
  492. ******************************************************************************/
  493. acpi_status
  494. acpi_get_gpe_status(acpi_handle gpe_device,
  495. u32 gpe_number, acpi_event_status *event_status)
  496. {
  497. acpi_status status = AE_OK;
  498. struct acpi_gpe_event_info *gpe_event_info;
  499. acpi_cpu_flags flags;
  500. ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
  501. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  502. /* Ensure that we have a valid GPE number */
  503. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  504. if (!gpe_event_info) {
  505. status = AE_BAD_PARAMETER;
  506. goto unlock_and_exit;
  507. }
  508. /* Obtain status on the requested GPE number */
  509. status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
  510. if (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)
  511. *event_status |= ACPI_EVENT_FLAG_HANDLE;
  512. unlock_and_exit:
  513. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  514. return_ACPI_STATUS(status);
  515. }
  516. ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
  517. /*******************************************************************************
  518. *
  519. * FUNCTION: acpi_install_gpe_block
  520. *
  521. * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
  522. * gpe_block_address - Address and space_iD
  523. * register_count - Number of GPE register pairs in the block
  524. * interrupt_number - H/W interrupt for the block
  525. *
  526. * RETURN: Status
  527. *
  528. * DESCRIPTION: Create and Install a block of GPE registers
  529. *
  530. ******************************************************************************/
  531. acpi_status
  532. acpi_install_gpe_block(acpi_handle gpe_device,
  533. struct acpi_generic_address *gpe_block_address,
  534. u32 register_count, u32 interrupt_number)
  535. {
  536. acpi_status status;
  537. union acpi_operand_object *obj_desc;
  538. struct acpi_namespace_node *node;
  539. struct acpi_gpe_block_info *gpe_block;
  540. ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
  541. if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
  542. return_ACPI_STATUS(AE_BAD_PARAMETER);
  543. }
  544. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  545. if (ACPI_FAILURE(status)) {
  546. return (status);
  547. }
  548. node = acpi_ns_validate_handle(gpe_device);
  549. if (!node) {
  550. status = AE_BAD_PARAMETER;
  551. goto unlock_and_exit;
  552. }
  553. /*
  554. * For user-installed GPE Block Devices, the gpe_block_base_number
  555. * is always zero
  556. */
  557. status =
  558. acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0,
  559. interrupt_number, &gpe_block);
  560. if (ACPI_FAILURE(status)) {
  561. goto unlock_and_exit;
  562. }
  563. /* Install block in the device_object attached to the node */
  564. obj_desc = acpi_ns_get_attached_object(node);
  565. if (!obj_desc) {
  566. /*
  567. * No object, create a new one (Device nodes do not always have
  568. * an attached object)
  569. */
  570. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
  571. if (!obj_desc) {
  572. status = AE_NO_MEMORY;
  573. goto unlock_and_exit;
  574. }
  575. status =
  576. acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
  577. /* Remove local reference to the object */
  578. acpi_ut_remove_reference(obj_desc);
  579. if (ACPI_FAILURE(status)) {
  580. goto unlock_and_exit;
  581. }
  582. }
  583. /* Now install the GPE block in the device_object */
  584. obj_desc->device.gpe_block = gpe_block;
  585. /* Enable the runtime GPEs in the new block */
  586. status = acpi_ev_initialize_gpe_block(node, gpe_block);
  587. unlock_and_exit:
  588. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  589. return_ACPI_STATUS(status);
  590. }
  591. ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
  592. /*******************************************************************************
  593. *
  594. * FUNCTION: acpi_remove_gpe_block
  595. *
  596. * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
  597. *
  598. * RETURN: Status
  599. *
  600. * DESCRIPTION: Remove a previously installed block of GPE registers
  601. *
  602. ******************************************************************************/
  603. acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
  604. {
  605. union acpi_operand_object *obj_desc;
  606. acpi_status status;
  607. struct acpi_namespace_node *node;
  608. ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
  609. if (!gpe_device) {
  610. return_ACPI_STATUS(AE_BAD_PARAMETER);
  611. }
  612. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  613. if (ACPI_FAILURE(status)) {
  614. return (status);
  615. }
  616. node = acpi_ns_validate_handle(gpe_device);
  617. if (!node) {
  618. status = AE_BAD_PARAMETER;
  619. goto unlock_and_exit;
  620. }
  621. /* Get the device_object attached to the node */
  622. obj_desc = acpi_ns_get_attached_object(node);
  623. if (!obj_desc || !obj_desc->device.gpe_block) {
  624. return_ACPI_STATUS(AE_NULL_OBJECT);
  625. }
  626. /* Delete the GPE block (but not the device_object) */
  627. status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
  628. if (ACPI_SUCCESS(status)) {
  629. obj_desc->device.gpe_block = NULL;
  630. }
  631. unlock_and_exit:
  632. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  633. return_ACPI_STATUS(status);
  634. }
  635. ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)
  636. /*******************************************************************************
  637. *
  638. * FUNCTION: acpi_get_gpe_device
  639. *
  640. * PARAMETERS: Index - System GPE index (0-current_gpe_count)
  641. * gpe_device - Where the parent GPE Device is returned
  642. *
  643. * RETURN: Status
  644. *
  645. * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
  646. * gpe device indicates that the gpe number is contained in one of
  647. * the FADT-defined gpe blocks. Otherwise, the GPE block device.
  648. *
  649. ******************************************************************************/
  650. acpi_status
  651. acpi_get_gpe_device(u32 index, acpi_handle *gpe_device)
  652. {
  653. struct acpi_gpe_device_info info;
  654. acpi_status status;
  655. ACPI_FUNCTION_TRACE(acpi_get_gpe_device);
  656. if (!gpe_device) {
  657. return_ACPI_STATUS(AE_BAD_PARAMETER);
  658. }
  659. if (index >= acpi_current_gpe_count) {
  660. return_ACPI_STATUS(AE_NOT_EXIST);
  661. }
  662. /* Setup and walk the GPE list */
  663. info.index = index;
  664. info.status = AE_NOT_EXIST;
  665. info.gpe_device = NULL;
  666. info.next_block_base_index = 0;
  667. status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info);
  668. if (ACPI_FAILURE(status)) {
  669. return_ACPI_STATUS(status);
  670. }
  671. *gpe_device = info.gpe_device;
  672. return_ACPI_STATUS(info.status);
  673. }
  674. ACPI_EXPORT_SYMBOL(acpi_get_gpe_device)
  675. /*******************************************************************************
  676. *
  677. * FUNCTION: acpi_ev_get_gpe_device
  678. *
  679. * PARAMETERS: GPE_WALK_CALLBACK
  680. *
  681. * RETURN: Status
  682. *
  683. * DESCRIPTION: Matches the input GPE index (0-current_gpe_count) with a GPE
  684. * block device. NULL if the GPE is one of the FADT-defined GPEs.
  685. *
  686. ******************************************************************************/
  687. static acpi_status
  688. acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
  689. struct acpi_gpe_block_info *gpe_block, void *context)
  690. {
  691. struct acpi_gpe_device_info *info = context;
  692. /* Increment Index by the number of GPEs in this block */
  693. info->next_block_base_index += gpe_block->gpe_count;
  694. if (info->index < info->next_block_base_index) {
  695. /*
  696. * The GPE index is within this block, get the node. Leave the node
  697. * NULL for the FADT-defined GPEs
  698. */
  699. if ((gpe_block->node)->type == ACPI_TYPE_DEVICE) {
  700. info->gpe_device = gpe_block->node;
  701. }
  702. info->status = AE_OK;
  703. return (AE_CTRL_END);
  704. }
  705. return (AE_OK);
  706. }
  707. /******************************************************************************
  708. *
  709. * FUNCTION: acpi_disable_all_gpes
  710. *
  711. * PARAMETERS: None
  712. *
  713. * RETURN: Status
  714. *
  715. * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
  716. *
  717. ******************************************************************************/
  718. acpi_status acpi_disable_all_gpes(void)
  719. {
  720. acpi_status status;
  721. ACPI_FUNCTION_TRACE(acpi_disable_all_gpes);
  722. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  723. if (ACPI_FAILURE(status)) {
  724. return_ACPI_STATUS(status);
  725. }
  726. status = acpi_hw_disable_all_gpes();
  727. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  728. return_ACPI_STATUS(status);
  729. }
  730. /******************************************************************************
  731. *
  732. * FUNCTION: acpi_enable_all_runtime_gpes
  733. *
  734. * PARAMETERS: None
  735. *
  736. * RETURN: Status
  737. *
  738. * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
  739. *
  740. ******************************************************************************/
  741. acpi_status acpi_enable_all_runtime_gpes(void)
  742. {
  743. acpi_status status;
  744. ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes);
  745. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  746. if (ACPI_FAILURE(status)) {
  747. return_ACPI_STATUS(status);
  748. }
  749. status = acpi_hw_enable_all_runtime_gpes();
  750. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  751. return_ACPI_STATUS(status);
  752. }