evxfevnt.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967
  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) {
  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_OK;
  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 = AE_BAD_PARAMETER;
  253. goto unlock_and_exit;
  254. }
  255. if (gpe_event_info->runtime_count == ACPI_UINT8_MAX) {
  256. status = AE_LIMIT; /* Too many references */
  257. goto unlock_and_exit;
  258. }
  259. gpe_event_info->runtime_count++;
  260. if (gpe_event_info->runtime_count == 1) {
  261. status = acpi_ev_update_gpe_enable_mask(gpe_event_info);
  262. if (ACPI_SUCCESS(status)) {
  263. status = acpi_ev_enable_gpe(gpe_event_info);
  264. }
  265. if (ACPI_FAILURE(status)) {
  266. gpe_event_info->runtime_count--;
  267. }
  268. }
  269. unlock_and_exit:
  270. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  271. return_ACPI_STATUS(status);
  272. }
  273. ACPI_EXPORT_SYMBOL(acpi_enable_gpe)
  274. /*******************************************************************************
  275. *
  276. * FUNCTION: acpi_disable_gpe
  277. *
  278. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  279. * gpe_number - GPE level within the GPE block
  280. *
  281. * RETURN: Status
  282. *
  283. * DESCRIPTION: Remove a reference to a GPE. When the last reference is
  284. * removed, only then is the GPE disabled (for runtime GPEs), or
  285. * the GPE mask bit disabled (for wake GPEs)
  286. *
  287. ******************************************************************************/
  288. acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number)
  289. {
  290. acpi_status status = AE_OK;
  291. struct acpi_gpe_event_info *gpe_event_info;
  292. acpi_cpu_flags flags;
  293. ACPI_FUNCTION_TRACE(acpi_disable_gpe);
  294. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  295. /* Ensure that we have a valid GPE number */
  296. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  297. if (!gpe_event_info) {
  298. status = AE_BAD_PARAMETER;
  299. goto unlock_and_exit;
  300. }
  301. /* Hardware-disable a runtime GPE on removal of the last reference */
  302. if (!gpe_event_info->runtime_count) {
  303. status = AE_LIMIT; /* There are no references to remove */
  304. goto unlock_and_exit;
  305. }
  306. gpe_event_info->runtime_count--;
  307. if (!gpe_event_info->runtime_count) {
  308. status = acpi_ev_update_gpe_enable_mask(gpe_event_info);
  309. if (ACPI_SUCCESS(status)) {
  310. status =
  311. acpi_hw_low_set_gpe(gpe_event_info,
  312. ACPI_GPE_DISABLE);
  313. }
  314. if (ACPI_FAILURE(status)) {
  315. gpe_event_info->runtime_count++;
  316. }
  317. }
  318. unlock_and_exit:
  319. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  320. return_ACPI_STATUS(status);
  321. }
  322. ACPI_EXPORT_SYMBOL(acpi_disable_gpe)
  323. /*******************************************************************************
  324. *
  325. * FUNCTION: acpi_gpe_can_wake
  326. *
  327. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  328. * gpe_number - GPE level within the GPE block
  329. *
  330. * RETURN: Status
  331. *
  332. * DESCRIPTION: Set the ACPI_GPE_CAN_WAKE flag for the given GPE. If the GPE
  333. * has a corresponding method and is currently enabled, disable it
  334. * (GPEs with corresponding methods are enabled unconditionally
  335. * during initialization, but GPEs that can wake up are expected
  336. * to be initially disabled).
  337. *
  338. ******************************************************************************/
  339. acpi_status acpi_gpe_can_wake(acpi_handle gpe_device, u32 gpe_number)
  340. {
  341. acpi_status status = AE_OK;
  342. struct acpi_gpe_event_info *gpe_event_info;
  343. acpi_cpu_flags flags;
  344. u8 disable = 0;
  345. ACPI_FUNCTION_TRACE(acpi_gpe_can_wake);
  346. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  347. /* Ensure that we have a valid GPE number */
  348. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  349. if (!gpe_event_info) {
  350. status = AE_BAD_PARAMETER;
  351. goto unlock_and_exit;
  352. }
  353. if (gpe_event_info->flags & ACPI_GPE_CAN_WAKE) {
  354. goto unlock_and_exit;
  355. }
  356. gpe_event_info->flags |= ACPI_GPE_CAN_WAKE;
  357. disable = (gpe_event_info->flags & ACPI_GPE_DISPATCH_METHOD)
  358. && gpe_event_info->runtime_count;
  359. unlock_and_exit:
  360. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  361. if (disable)
  362. status = acpi_disable_gpe(gpe_device, gpe_number);
  363. return_ACPI_STATUS(status);
  364. }
  365. ACPI_EXPORT_SYMBOL(acpi_gpe_can_wake)
  366. /*******************************************************************************
  367. *
  368. * FUNCTION: acpi_disable_event
  369. *
  370. * PARAMETERS: Event - The fixed eventto be enabled
  371. * Flags - Reserved
  372. *
  373. * RETURN: Status
  374. *
  375. * DESCRIPTION: Disable an ACPI event (fixed)
  376. *
  377. ******************************************************************************/
  378. acpi_status acpi_disable_event(u32 event, u32 flags)
  379. {
  380. acpi_status status = AE_OK;
  381. u32 value;
  382. ACPI_FUNCTION_TRACE(acpi_disable_event);
  383. /* Decode the Fixed Event */
  384. if (event > ACPI_EVENT_MAX) {
  385. return_ACPI_STATUS(AE_BAD_PARAMETER);
  386. }
  387. /*
  388. * Disable the requested fixed event (by writing a zero to the enable
  389. * register bit)
  390. */
  391. status =
  392. acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
  393. enable_register_id, ACPI_DISABLE_EVENT);
  394. if (ACPI_FAILURE(status)) {
  395. return_ACPI_STATUS(status);
  396. }
  397. status =
  398. acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
  399. enable_register_id, &value);
  400. if (ACPI_FAILURE(status)) {
  401. return_ACPI_STATUS(status);
  402. }
  403. if (value != 0) {
  404. ACPI_ERROR((AE_INFO,
  405. "Could not disable %s events",
  406. acpi_ut_get_event_name(event)));
  407. return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
  408. }
  409. return_ACPI_STATUS(status);
  410. }
  411. ACPI_EXPORT_SYMBOL(acpi_disable_event)
  412. /*******************************************************************************
  413. *
  414. * FUNCTION: acpi_clear_event
  415. *
  416. * PARAMETERS: Event - The fixed event to be cleared
  417. *
  418. * RETURN: Status
  419. *
  420. * DESCRIPTION: Clear an ACPI event (fixed)
  421. *
  422. ******************************************************************************/
  423. acpi_status acpi_clear_event(u32 event)
  424. {
  425. acpi_status status = AE_OK;
  426. ACPI_FUNCTION_TRACE(acpi_clear_event);
  427. /* Decode the Fixed Event */
  428. if (event > ACPI_EVENT_MAX) {
  429. return_ACPI_STATUS(AE_BAD_PARAMETER);
  430. }
  431. /*
  432. * Clear the requested fixed event (By writing a one to the status
  433. * register bit)
  434. */
  435. status =
  436. acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
  437. status_register_id, ACPI_CLEAR_STATUS);
  438. return_ACPI_STATUS(status);
  439. }
  440. ACPI_EXPORT_SYMBOL(acpi_clear_event)
  441. /*******************************************************************************
  442. *
  443. * FUNCTION: acpi_clear_gpe
  444. *
  445. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  446. * gpe_number - GPE level within the GPE block
  447. *
  448. * RETURN: Status
  449. *
  450. * DESCRIPTION: Clear an ACPI event (general purpose)
  451. *
  452. ******************************************************************************/
  453. acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number)
  454. {
  455. acpi_status status = AE_OK;
  456. struct acpi_gpe_event_info *gpe_event_info;
  457. acpi_cpu_flags flags;
  458. ACPI_FUNCTION_TRACE(acpi_clear_gpe);
  459. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  460. /* Ensure that we have a valid GPE number */
  461. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  462. if (!gpe_event_info) {
  463. status = AE_BAD_PARAMETER;
  464. goto unlock_and_exit;
  465. }
  466. status = acpi_hw_clear_gpe(gpe_event_info);
  467. unlock_and_exit:
  468. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  469. return_ACPI_STATUS(status);
  470. }
  471. ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
  472. /*******************************************************************************
  473. *
  474. * FUNCTION: acpi_get_event_status
  475. *
  476. * PARAMETERS: Event - The fixed event
  477. * event_status - Where the current status of the event will
  478. * be returned
  479. *
  480. * RETURN: Status
  481. *
  482. * DESCRIPTION: Obtains and returns the current status of the event
  483. *
  484. ******************************************************************************/
  485. acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
  486. {
  487. acpi_status status = AE_OK;
  488. u32 value;
  489. ACPI_FUNCTION_TRACE(acpi_get_event_status);
  490. if (!event_status) {
  491. return_ACPI_STATUS(AE_BAD_PARAMETER);
  492. }
  493. /* Decode the Fixed Event */
  494. if (event > ACPI_EVENT_MAX) {
  495. return_ACPI_STATUS(AE_BAD_PARAMETER);
  496. }
  497. /* Get the status of the requested fixed event */
  498. status =
  499. acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
  500. enable_register_id, &value);
  501. if (ACPI_FAILURE(status))
  502. return_ACPI_STATUS(status);
  503. *event_status = value;
  504. status =
  505. acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
  506. status_register_id, &value);
  507. if (ACPI_FAILURE(status))
  508. return_ACPI_STATUS(status);
  509. if (value)
  510. *event_status |= ACPI_EVENT_FLAG_SET;
  511. if (acpi_gbl_fixed_event_handlers[event].handler)
  512. *event_status |= ACPI_EVENT_FLAG_HANDLE;
  513. return_ACPI_STATUS(status);
  514. }
  515. ACPI_EXPORT_SYMBOL(acpi_get_event_status)
  516. /*******************************************************************************
  517. *
  518. * FUNCTION: acpi_get_gpe_status
  519. *
  520. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  521. * gpe_number - GPE level within the GPE block
  522. * event_status - Where the current status of the event will
  523. * be returned
  524. *
  525. * RETURN: Status
  526. *
  527. * DESCRIPTION: Get status of an event (general purpose)
  528. *
  529. ******************************************************************************/
  530. acpi_status
  531. acpi_get_gpe_status(acpi_handle gpe_device,
  532. u32 gpe_number, acpi_event_status *event_status)
  533. {
  534. acpi_status status = AE_OK;
  535. struct acpi_gpe_event_info *gpe_event_info;
  536. acpi_cpu_flags flags;
  537. ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
  538. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  539. /* Ensure that we have a valid GPE number */
  540. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  541. if (!gpe_event_info) {
  542. status = AE_BAD_PARAMETER;
  543. goto unlock_and_exit;
  544. }
  545. /* Obtain status on the requested GPE number */
  546. status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
  547. if (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)
  548. *event_status |= ACPI_EVENT_FLAG_HANDLE;
  549. unlock_and_exit:
  550. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  551. return_ACPI_STATUS(status);
  552. }
  553. ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
  554. /*******************************************************************************
  555. *
  556. * FUNCTION: acpi_install_gpe_block
  557. *
  558. * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
  559. * gpe_block_address - Address and space_iD
  560. * register_count - Number of GPE register pairs in the block
  561. * interrupt_number - H/W interrupt for the block
  562. *
  563. * RETURN: Status
  564. *
  565. * DESCRIPTION: Create and Install a block of GPE registers
  566. *
  567. ******************************************************************************/
  568. acpi_status
  569. acpi_install_gpe_block(acpi_handle gpe_device,
  570. struct acpi_generic_address *gpe_block_address,
  571. u32 register_count, u32 interrupt_number)
  572. {
  573. acpi_status status;
  574. union acpi_operand_object *obj_desc;
  575. struct acpi_namespace_node *node;
  576. struct acpi_gpe_block_info *gpe_block;
  577. ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
  578. if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
  579. return_ACPI_STATUS(AE_BAD_PARAMETER);
  580. }
  581. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  582. if (ACPI_FAILURE(status)) {
  583. return (status);
  584. }
  585. node = acpi_ns_validate_handle(gpe_device);
  586. if (!node) {
  587. status = AE_BAD_PARAMETER;
  588. goto unlock_and_exit;
  589. }
  590. /*
  591. * For user-installed GPE Block Devices, the gpe_block_base_number
  592. * is always zero
  593. */
  594. status =
  595. acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0,
  596. interrupt_number, &gpe_block);
  597. if (ACPI_FAILURE(status)) {
  598. goto unlock_and_exit;
  599. }
  600. /* Install block in the device_object attached to the node */
  601. obj_desc = acpi_ns_get_attached_object(node);
  602. if (!obj_desc) {
  603. /*
  604. * No object, create a new one (Device nodes do not always have
  605. * an attached object)
  606. */
  607. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
  608. if (!obj_desc) {
  609. status = AE_NO_MEMORY;
  610. goto unlock_and_exit;
  611. }
  612. status =
  613. acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
  614. /* Remove local reference to the object */
  615. acpi_ut_remove_reference(obj_desc);
  616. if (ACPI_FAILURE(status)) {
  617. goto unlock_and_exit;
  618. }
  619. }
  620. /* Now install the GPE block in the device_object */
  621. obj_desc->device.gpe_block = gpe_block;
  622. /* Enable the runtime GPEs in the new block */
  623. status = acpi_ev_initialize_gpe_block(node, gpe_block);
  624. unlock_and_exit:
  625. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  626. return_ACPI_STATUS(status);
  627. }
  628. ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
  629. /*******************************************************************************
  630. *
  631. * FUNCTION: acpi_remove_gpe_block
  632. *
  633. * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
  634. *
  635. * RETURN: Status
  636. *
  637. * DESCRIPTION: Remove a previously installed block of GPE registers
  638. *
  639. ******************************************************************************/
  640. acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
  641. {
  642. union acpi_operand_object *obj_desc;
  643. acpi_status status;
  644. struct acpi_namespace_node *node;
  645. ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
  646. if (!gpe_device) {
  647. return_ACPI_STATUS(AE_BAD_PARAMETER);
  648. }
  649. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  650. if (ACPI_FAILURE(status)) {
  651. return (status);
  652. }
  653. node = acpi_ns_validate_handle(gpe_device);
  654. if (!node) {
  655. status = AE_BAD_PARAMETER;
  656. goto unlock_and_exit;
  657. }
  658. /* Get the device_object attached to the node */
  659. obj_desc = acpi_ns_get_attached_object(node);
  660. if (!obj_desc || !obj_desc->device.gpe_block) {
  661. return_ACPI_STATUS(AE_NULL_OBJECT);
  662. }
  663. /* Delete the GPE block (but not the device_object) */
  664. status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
  665. if (ACPI_SUCCESS(status)) {
  666. obj_desc->device.gpe_block = NULL;
  667. }
  668. unlock_and_exit:
  669. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  670. return_ACPI_STATUS(status);
  671. }
  672. ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)
  673. /*******************************************************************************
  674. *
  675. * FUNCTION: acpi_get_gpe_device
  676. *
  677. * PARAMETERS: Index - System GPE index (0-current_gpe_count)
  678. * gpe_device - Where the parent GPE Device is returned
  679. *
  680. * RETURN: Status
  681. *
  682. * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
  683. * gpe device indicates that the gpe number is contained in one of
  684. * the FADT-defined gpe blocks. Otherwise, the GPE block device.
  685. *
  686. ******************************************************************************/
  687. acpi_status
  688. acpi_get_gpe_device(u32 index, acpi_handle *gpe_device)
  689. {
  690. struct acpi_gpe_device_info info;
  691. acpi_status status;
  692. ACPI_FUNCTION_TRACE(acpi_get_gpe_device);
  693. if (!gpe_device) {
  694. return_ACPI_STATUS(AE_BAD_PARAMETER);
  695. }
  696. if (index >= acpi_current_gpe_count) {
  697. return_ACPI_STATUS(AE_NOT_EXIST);
  698. }
  699. /* Setup and walk the GPE list */
  700. info.index = index;
  701. info.status = AE_NOT_EXIST;
  702. info.gpe_device = NULL;
  703. info.next_block_base_index = 0;
  704. status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info);
  705. if (ACPI_FAILURE(status)) {
  706. return_ACPI_STATUS(status);
  707. }
  708. *gpe_device = info.gpe_device;
  709. return_ACPI_STATUS(info.status);
  710. }
  711. ACPI_EXPORT_SYMBOL(acpi_get_gpe_device)
  712. /*******************************************************************************
  713. *
  714. * FUNCTION: acpi_ev_get_gpe_device
  715. *
  716. * PARAMETERS: GPE_WALK_CALLBACK
  717. *
  718. * RETURN: Status
  719. *
  720. * DESCRIPTION: Matches the input GPE index (0-current_gpe_count) with a GPE
  721. * block device. NULL if the GPE is one of the FADT-defined GPEs.
  722. *
  723. ******************************************************************************/
  724. static acpi_status
  725. acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
  726. struct acpi_gpe_block_info *gpe_block, void *context)
  727. {
  728. struct acpi_gpe_device_info *info = context;
  729. /* Increment Index by the number of GPEs in this block */
  730. info->next_block_base_index += gpe_block->gpe_count;
  731. if (info->index < info->next_block_base_index) {
  732. /*
  733. * The GPE index is within this block, get the node. Leave the node
  734. * NULL for the FADT-defined GPEs
  735. */
  736. if ((gpe_block->node)->type == ACPI_TYPE_DEVICE) {
  737. info->gpe_device = gpe_block->node;
  738. }
  739. info->status = AE_OK;
  740. return (AE_CTRL_END);
  741. }
  742. return (AE_OK);
  743. }
  744. /******************************************************************************
  745. *
  746. * FUNCTION: acpi_disable_all_gpes
  747. *
  748. * PARAMETERS: None
  749. *
  750. * RETURN: Status
  751. *
  752. * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
  753. *
  754. ******************************************************************************/
  755. acpi_status acpi_disable_all_gpes(void)
  756. {
  757. acpi_status status;
  758. ACPI_FUNCTION_TRACE(acpi_disable_all_gpes);
  759. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  760. if (ACPI_FAILURE(status)) {
  761. return_ACPI_STATUS(status);
  762. }
  763. status = acpi_hw_disable_all_gpes();
  764. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  765. return_ACPI_STATUS(status);
  766. }
  767. /******************************************************************************
  768. *
  769. * FUNCTION: acpi_enable_all_runtime_gpes
  770. *
  771. * PARAMETERS: None
  772. *
  773. * RETURN: Status
  774. *
  775. * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
  776. *
  777. ******************************************************************************/
  778. acpi_status acpi_enable_all_runtime_gpes(void)
  779. {
  780. acpi_status status;
  781. ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes);
  782. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  783. if (ACPI_FAILURE(status)) {
  784. return_ACPI_STATUS(status);
  785. }
  786. status = acpi_hw_enable_all_runtime_gpes();
  787. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  788. return_ACPI_STATUS(status);
  789. }