evxfevnt.c 29 KB

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