evxfevnt.c 26 KB

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