evxfevnt.c 26 KB

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