evxfevnt.c 26 KB

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