evxfevnt.c 27 KB

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