evxfevnt.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011
  1. /******************************************************************************
  2. *
  3. * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2010, Intel Corp.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #include <acpi/acpi.h>
  43. #include "accommon.h"
  44. #include "acevents.h"
  45. #include "acnamesp.h"
  46. #include "actables.h"
  47. #define _COMPONENT ACPI_EVENTS
  48. ACPI_MODULE_NAME("evxfevnt")
  49. /* Local prototypes */
  50. static acpi_status
  51. acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
  52. struct acpi_gpe_block_info *gpe_block, void *context);
  53. /*******************************************************************************
  54. *
  55. * FUNCTION: acpi_enable
  56. *
  57. * PARAMETERS: None
  58. *
  59. * RETURN: Status
  60. *
  61. * DESCRIPTION: Transfers the system into ACPI mode.
  62. *
  63. ******************************************************************************/
  64. acpi_status acpi_enable(void)
  65. {
  66. acpi_status status;
  67. int retry;
  68. ACPI_FUNCTION_TRACE(acpi_enable);
  69. /* ACPI tables must be present */
  70. if (!acpi_tb_tables_loaded()) {
  71. return_ACPI_STATUS(AE_NO_ACPI_TABLES);
  72. }
  73. /* Check current mode */
  74. if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
  75. ACPI_DEBUG_PRINT((ACPI_DB_INIT,
  76. "System is already in ACPI mode\n"));
  77. return_ACPI_STATUS(AE_OK);
  78. }
  79. /* Transition to ACPI mode */
  80. status = acpi_hw_set_mode(ACPI_SYS_MODE_ACPI);
  81. if (ACPI_FAILURE(status)) {
  82. ACPI_ERROR((AE_INFO,
  83. "Could not transition to ACPI mode"));
  84. return_ACPI_STATUS(status);
  85. }
  86. /* Sanity check that transition succeeded */
  87. for (retry = 0; retry < 30000; ++retry) {
  88. if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
  89. if (retry != 0)
  90. ACPI_WARNING((AE_INFO,
  91. "Platform took > %d00 usec to enter ACPI mode", retry));
  92. return_ACPI_STATUS(AE_OK);
  93. }
  94. acpi_os_stall(100); /* 100 usec */
  95. }
  96. ACPI_ERROR((AE_INFO, "Hardware did not enter ACPI mode"));
  97. return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
  98. }
  99. ACPI_EXPORT_SYMBOL(acpi_enable)
  100. /*******************************************************************************
  101. *
  102. * FUNCTION: acpi_disable
  103. *
  104. * PARAMETERS: None
  105. *
  106. * RETURN: Status
  107. *
  108. * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
  109. *
  110. ******************************************************************************/
  111. acpi_status acpi_disable(void)
  112. {
  113. acpi_status status = AE_OK;
  114. ACPI_FUNCTION_TRACE(acpi_disable);
  115. if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {
  116. ACPI_DEBUG_PRINT((ACPI_DB_INIT,
  117. "System is already in legacy (non-ACPI) mode\n"));
  118. } else {
  119. /* Transition to LEGACY mode */
  120. status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY);
  121. if (ACPI_FAILURE(status)) {
  122. ACPI_ERROR((AE_INFO,
  123. "Could not exit ACPI mode to legacy mode"));
  124. return_ACPI_STATUS(status);
  125. }
  126. ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI mode disabled\n"));
  127. }
  128. return_ACPI_STATUS(status);
  129. }
  130. ACPI_EXPORT_SYMBOL(acpi_disable)
  131. /*******************************************************************************
  132. *
  133. * FUNCTION: acpi_enable_event
  134. *
  135. * PARAMETERS: Event - The fixed eventto be enabled
  136. * Flags - Reserved
  137. *
  138. * RETURN: Status
  139. *
  140. * DESCRIPTION: Enable an ACPI event (fixed)
  141. *
  142. ******************************************************************************/
  143. acpi_status acpi_enable_event(u32 event, u32 flags)
  144. {
  145. acpi_status status = AE_OK;
  146. u32 value;
  147. ACPI_FUNCTION_TRACE(acpi_enable_event);
  148. /* Decode the Fixed Event */
  149. if (event > ACPI_EVENT_MAX) {
  150. return_ACPI_STATUS(AE_BAD_PARAMETER);
  151. }
  152. /*
  153. * Enable the requested fixed event (by writing a one to the enable
  154. * register bit)
  155. */
  156. status =
  157. acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
  158. enable_register_id, ACPI_ENABLE_EVENT);
  159. if (ACPI_FAILURE(status)) {
  160. return_ACPI_STATUS(status);
  161. }
  162. /* Make sure that the hardware responded */
  163. status =
  164. acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
  165. enable_register_id, &value);
  166. if (ACPI_FAILURE(status)) {
  167. return_ACPI_STATUS(status);
  168. }
  169. if (value != 1) {
  170. ACPI_ERROR((AE_INFO,
  171. "Could not enable %s event",
  172. acpi_ut_get_event_name(event)));
  173. return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
  174. }
  175. return_ACPI_STATUS(status);
  176. }
  177. ACPI_EXPORT_SYMBOL(acpi_enable_event)
  178. /*******************************************************************************
  179. *
  180. * FUNCTION: acpi_clear_and_enable_gpe
  181. *
  182. * PARAMETERS: gpe_event_info - GPE to enable
  183. *
  184. * RETURN: Status
  185. *
  186. * DESCRIPTION: Clear the given GPE from stale events and enable it.
  187. *
  188. ******************************************************************************/
  189. static acpi_status
  190. acpi_clear_and_enable_gpe(struct acpi_gpe_event_info *gpe_event_info)
  191. {
  192. acpi_status status;
  193. /*
  194. * We will only allow a GPE to be enabled if it has either an
  195. * associated method (_Lxx/_Exx) or a handler. Otherwise, the
  196. * GPE will be immediately disabled by acpi_ev_gpe_dispatch the
  197. * first time it fires.
  198. */
  199. if (!(gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)) {
  200. return_ACPI_STATUS(AE_NO_HANDLER);
  201. }
  202. /* Clear the GPE (of stale events) */
  203. status = acpi_hw_clear_gpe(gpe_event_info);
  204. if (ACPI_FAILURE(status)) {
  205. return_ACPI_STATUS(status);
  206. }
  207. /* Enable the requested GPE */
  208. status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_ENABLE);
  209. return_ACPI_STATUS(status);
  210. }
  211. /*******************************************************************************
  212. *
  213. * FUNCTION: acpi_set_gpe
  214. *
  215. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  216. * gpe_number - GPE level within the GPE block
  217. * action - ACPI_GPE_ENABLE or ACPI_GPE_DISABLE
  218. *
  219. * RETURN: Status
  220. *
  221. * DESCRIPTION: Enable or disable an individual GPE. This function bypasses
  222. * the reference count mechanism used in the acpi_enable_gpe and
  223. * acpi_disable_gpe interfaces -- and should be used with care.
  224. *
  225. * Note: Typically used to disable a runtime GPE for short period of time,
  226. * then re-enable it, without disturbing the existing reference counts. This
  227. * is useful, for example, in the Embedded Controller (EC) driver.
  228. *
  229. ******************************************************************************/
  230. acpi_status acpi_set_gpe(acpi_handle gpe_device, u32 gpe_number, u8 action)
  231. {
  232. struct acpi_gpe_event_info *gpe_event_info;
  233. acpi_status status;
  234. acpi_cpu_flags flags;
  235. ACPI_FUNCTION_TRACE(acpi_set_gpe);
  236. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  237. /* Ensure that we have a valid GPE number */
  238. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  239. if (!gpe_event_info) {
  240. status = AE_BAD_PARAMETER;
  241. goto unlock_and_exit;
  242. }
  243. /* Perform the action */
  244. switch (action) {
  245. case ACPI_GPE_ENABLE:
  246. status = acpi_clear_and_enable_gpe(gpe_event_info);
  247. break;
  248. case ACPI_GPE_DISABLE:
  249. status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_DISABLE);
  250. break;
  251. default:
  252. status = AE_BAD_PARAMETER;
  253. break;
  254. }
  255. unlock_and_exit:
  256. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  257. return_ACPI_STATUS(status);
  258. }
  259. ACPI_EXPORT_SYMBOL(acpi_set_gpe)
  260. /*******************************************************************************
  261. *
  262. * FUNCTION: acpi_enable_gpe
  263. *
  264. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  265. * gpe_number - GPE level within the GPE block
  266. * gpe_type - ACPI_GPE_TYPE_RUNTIME or ACPI_GPE_TYPE_WAKE
  267. * or both
  268. *
  269. * RETURN: Status
  270. *
  271. * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
  272. * hardware-enabled (for runtime GPEs), or the GPE register mask
  273. * is updated (for wake GPEs).
  274. *
  275. ******************************************************************************/
  276. acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 gpe_type)
  277. {
  278. acpi_status status = AE_OK;
  279. struct acpi_gpe_event_info *gpe_event_info;
  280. acpi_cpu_flags flags;
  281. ACPI_FUNCTION_TRACE(acpi_enable_gpe);
  282. /* Parameter validation */
  283. if (!gpe_type || (gpe_type & ~ACPI_GPE_TYPE_WAKE_RUN)) {
  284. return_ACPI_STATUS(AE_BAD_PARAMETER);
  285. }
  286. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  287. /* Ensure that we have a valid GPE number */
  288. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  289. if (!gpe_event_info) {
  290. status = AE_BAD_PARAMETER;
  291. goto unlock_and_exit;
  292. }
  293. if (gpe_type & ACPI_GPE_TYPE_RUNTIME) {
  294. if (gpe_event_info->runtime_count == ACPI_UINT8_MAX) {
  295. status = AE_LIMIT; /* Too many references */
  296. goto unlock_and_exit;
  297. }
  298. gpe_event_info->runtime_count++;
  299. if (gpe_event_info->runtime_count == 1) {
  300. status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
  301. if (ACPI_SUCCESS(status)) {
  302. status = acpi_clear_and_enable_gpe(gpe_event_info);
  303. }
  304. if (ACPI_FAILURE(status)) {
  305. gpe_event_info->runtime_count--;
  306. goto unlock_and_exit;
  307. }
  308. }
  309. }
  310. if (gpe_type & ACPI_GPE_TYPE_WAKE) {
  311. /* The GPE must have the ability to wake the system */
  312. if (!(gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) {
  313. status = AE_TYPE;
  314. goto unlock_and_exit;
  315. }
  316. if (gpe_event_info->wakeup_count == ACPI_UINT8_MAX) {
  317. status = AE_LIMIT; /* Too many references */
  318. goto unlock_and_exit;
  319. }
  320. /*
  321. * Update the enable mask on the first wakeup reference. Wake GPEs
  322. * are only hardware-enabled just before sleeping.
  323. */
  324. gpe_event_info->wakeup_count++;
  325. if (gpe_event_info->wakeup_count == 1) {
  326. status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
  327. }
  328. }
  329. unlock_and_exit:
  330. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  331. return_ACPI_STATUS(status);
  332. }
  333. ACPI_EXPORT_SYMBOL(acpi_enable_gpe)
  334. /*******************************************************************************
  335. *
  336. * FUNCTION: acpi_disable_gpe
  337. *
  338. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  339. * gpe_number - GPE level within the GPE block
  340. * gpe_type - ACPI_GPE_TYPE_RUNTIME or ACPI_GPE_TYPE_WAKE
  341. * or both
  342. *
  343. * RETURN: Status
  344. *
  345. * DESCRIPTION: Remove a reference to a GPE. When the last reference is
  346. * removed, only then is the GPE disabled (for runtime GPEs), or
  347. * the GPE mask bit disabled (for wake GPEs)
  348. *
  349. ******************************************************************************/
  350. acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 gpe_type)
  351. {
  352. acpi_status status = AE_OK;
  353. struct acpi_gpe_event_info *gpe_event_info;
  354. acpi_cpu_flags flags;
  355. ACPI_FUNCTION_TRACE(acpi_disable_gpe);
  356. /* Parameter validation */
  357. if (!gpe_type || (gpe_type & ~ACPI_GPE_TYPE_WAKE_RUN)) {
  358. return_ACPI_STATUS(AE_BAD_PARAMETER);
  359. }
  360. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  361. /* Ensure that we have a valid GPE number */
  362. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  363. if (!gpe_event_info) {
  364. status = AE_BAD_PARAMETER;
  365. goto unlock_and_exit;
  366. }
  367. /* Hardware-disable a runtime GPE on removal of the last reference */
  368. if (gpe_type & ACPI_GPE_TYPE_RUNTIME) {
  369. if (!gpe_event_info->runtime_count) {
  370. status = AE_LIMIT; /* There are no references to remove */
  371. goto unlock_and_exit;
  372. }
  373. gpe_event_info->runtime_count--;
  374. if (!gpe_event_info->runtime_count) {
  375. status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
  376. if (ACPI_SUCCESS(status)) {
  377. status = acpi_hw_low_set_gpe(gpe_event_info,
  378. ACPI_GPE_DISABLE);
  379. }
  380. if (ACPI_FAILURE(status)) {
  381. gpe_event_info->runtime_count++;
  382. goto unlock_and_exit;
  383. }
  384. }
  385. }
  386. /*
  387. * Update masks for wake GPE on removal of the last reference.
  388. * No need to hardware-disable wake GPEs here, they are not currently
  389. * enabled.
  390. */
  391. if (gpe_type & ACPI_GPE_TYPE_WAKE) {
  392. if (!gpe_event_info->wakeup_count) {
  393. status = AE_LIMIT; /* There are no references to remove */
  394. goto unlock_and_exit;
  395. }
  396. gpe_event_info->wakeup_count--;
  397. if (!gpe_event_info->wakeup_count) {
  398. status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
  399. }
  400. }
  401. unlock_and_exit:
  402. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  403. return_ACPI_STATUS(status);
  404. }
  405. ACPI_EXPORT_SYMBOL(acpi_disable_gpe)
  406. /*******************************************************************************
  407. *
  408. * FUNCTION: acpi_disable_event
  409. *
  410. * PARAMETERS: Event - The fixed eventto be enabled
  411. * Flags - Reserved
  412. *
  413. * RETURN: Status
  414. *
  415. * DESCRIPTION: Disable an ACPI event (fixed)
  416. *
  417. ******************************************************************************/
  418. acpi_status acpi_disable_event(u32 event, u32 flags)
  419. {
  420. acpi_status status = AE_OK;
  421. u32 value;
  422. ACPI_FUNCTION_TRACE(acpi_disable_event);
  423. /* Decode the Fixed Event */
  424. if (event > ACPI_EVENT_MAX) {
  425. return_ACPI_STATUS(AE_BAD_PARAMETER);
  426. }
  427. /*
  428. * Disable the requested fixed event (by writing a zero to the enable
  429. * register bit)
  430. */
  431. status =
  432. acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
  433. enable_register_id, ACPI_DISABLE_EVENT);
  434. if (ACPI_FAILURE(status)) {
  435. return_ACPI_STATUS(status);
  436. }
  437. status =
  438. acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
  439. enable_register_id, &value);
  440. if (ACPI_FAILURE(status)) {
  441. return_ACPI_STATUS(status);
  442. }
  443. if (value != 0) {
  444. ACPI_ERROR((AE_INFO,
  445. "Could not disable %s events",
  446. acpi_ut_get_event_name(event)));
  447. return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
  448. }
  449. return_ACPI_STATUS(status);
  450. }
  451. ACPI_EXPORT_SYMBOL(acpi_disable_event)
  452. /*******************************************************************************
  453. *
  454. * FUNCTION: acpi_clear_event
  455. *
  456. * PARAMETERS: Event - The fixed event to be cleared
  457. *
  458. * RETURN: Status
  459. *
  460. * DESCRIPTION: Clear an ACPI event (fixed)
  461. *
  462. ******************************************************************************/
  463. acpi_status acpi_clear_event(u32 event)
  464. {
  465. acpi_status status = AE_OK;
  466. ACPI_FUNCTION_TRACE(acpi_clear_event);
  467. /* Decode the Fixed Event */
  468. if (event > ACPI_EVENT_MAX) {
  469. return_ACPI_STATUS(AE_BAD_PARAMETER);
  470. }
  471. /*
  472. * Clear the requested fixed event (By writing a one to the status
  473. * register bit)
  474. */
  475. status =
  476. acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
  477. status_register_id, ACPI_CLEAR_STATUS);
  478. return_ACPI_STATUS(status);
  479. }
  480. ACPI_EXPORT_SYMBOL(acpi_clear_event)
  481. /*******************************************************************************
  482. *
  483. * FUNCTION: acpi_clear_gpe
  484. *
  485. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  486. * gpe_number - GPE level within the GPE block
  487. *
  488. * RETURN: Status
  489. *
  490. * DESCRIPTION: Clear an ACPI event (general purpose)
  491. *
  492. ******************************************************************************/
  493. acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number)
  494. {
  495. acpi_status status = AE_OK;
  496. struct acpi_gpe_event_info *gpe_event_info;
  497. acpi_cpu_flags flags;
  498. ACPI_FUNCTION_TRACE(acpi_clear_gpe);
  499. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  500. /* Ensure that we have a valid GPE number */
  501. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  502. if (!gpe_event_info) {
  503. status = AE_BAD_PARAMETER;
  504. goto unlock_and_exit;
  505. }
  506. status = acpi_hw_clear_gpe(gpe_event_info);
  507. unlock_and_exit:
  508. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  509. return_ACPI_STATUS(status);
  510. }
  511. ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
  512. /*******************************************************************************
  513. *
  514. * FUNCTION: acpi_get_event_status
  515. *
  516. * PARAMETERS: Event - The fixed event
  517. * event_status - Where the current status of the event will
  518. * be returned
  519. *
  520. * RETURN: Status
  521. *
  522. * DESCRIPTION: Obtains and returns the current status of the event
  523. *
  524. ******************************************************************************/
  525. acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
  526. {
  527. acpi_status status = AE_OK;
  528. u32 value;
  529. ACPI_FUNCTION_TRACE(acpi_get_event_status);
  530. if (!event_status) {
  531. return_ACPI_STATUS(AE_BAD_PARAMETER);
  532. }
  533. /* Decode the Fixed Event */
  534. if (event > ACPI_EVENT_MAX) {
  535. return_ACPI_STATUS(AE_BAD_PARAMETER);
  536. }
  537. /* Get the status of the requested fixed event */
  538. status =
  539. acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
  540. enable_register_id, &value);
  541. if (ACPI_FAILURE(status))
  542. return_ACPI_STATUS(status);
  543. *event_status = value;
  544. status =
  545. acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
  546. status_register_id, &value);
  547. if (ACPI_FAILURE(status))
  548. return_ACPI_STATUS(status);
  549. if (value)
  550. *event_status |= ACPI_EVENT_FLAG_SET;
  551. if (acpi_gbl_fixed_event_handlers[event].handler)
  552. *event_status |= ACPI_EVENT_FLAG_HANDLE;
  553. return_ACPI_STATUS(status);
  554. }
  555. ACPI_EXPORT_SYMBOL(acpi_get_event_status)
  556. /*******************************************************************************
  557. *
  558. * FUNCTION: acpi_get_gpe_status
  559. *
  560. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  561. * gpe_number - GPE level within the GPE block
  562. * event_status - Where the current status of the event will
  563. * be returned
  564. *
  565. * RETURN: Status
  566. *
  567. * DESCRIPTION: Get status of an event (general purpose)
  568. *
  569. ******************************************************************************/
  570. acpi_status
  571. acpi_get_gpe_status(acpi_handle gpe_device,
  572. u32 gpe_number, acpi_event_status *event_status)
  573. {
  574. acpi_status status = AE_OK;
  575. struct acpi_gpe_event_info *gpe_event_info;
  576. acpi_cpu_flags flags;
  577. ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
  578. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  579. /* Ensure that we have a valid GPE number */
  580. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  581. if (!gpe_event_info) {
  582. status = AE_BAD_PARAMETER;
  583. goto unlock_and_exit;
  584. }
  585. /* Obtain status on the requested GPE number */
  586. status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
  587. if (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)
  588. *event_status |= ACPI_EVENT_FLAG_HANDLE;
  589. unlock_and_exit:
  590. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  591. return_ACPI_STATUS(status);
  592. }
  593. ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
  594. /*******************************************************************************
  595. *
  596. * FUNCTION: acpi_install_gpe_block
  597. *
  598. * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
  599. * gpe_block_address - Address and space_iD
  600. * register_count - Number of GPE register pairs in the block
  601. * interrupt_number - H/W interrupt for the block
  602. *
  603. * RETURN: Status
  604. *
  605. * DESCRIPTION: Create and Install a block of GPE registers
  606. *
  607. ******************************************************************************/
  608. acpi_status
  609. acpi_install_gpe_block(acpi_handle gpe_device,
  610. struct acpi_generic_address *gpe_block_address,
  611. u32 register_count, u32 interrupt_number)
  612. {
  613. acpi_status status;
  614. union acpi_operand_object *obj_desc;
  615. struct acpi_namespace_node *node;
  616. struct acpi_gpe_block_info *gpe_block;
  617. ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
  618. if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
  619. return_ACPI_STATUS(AE_BAD_PARAMETER);
  620. }
  621. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  622. if (ACPI_FAILURE(status)) {
  623. return (status);
  624. }
  625. node = acpi_ns_validate_handle(gpe_device);
  626. if (!node) {
  627. status = AE_BAD_PARAMETER;
  628. goto unlock_and_exit;
  629. }
  630. /*
  631. * For user-installed GPE Block Devices, the gpe_block_base_number
  632. * is always zero
  633. */
  634. status =
  635. acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0,
  636. interrupt_number, &gpe_block);
  637. if (ACPI_FAILURE(status)) {
  638. goto unlock_and_exit;
  639. }
  640. /* Install block in the device_object attached to the node */
  641. obj_desc = acpi_ns_get_attached_object(node);
  642. if (!obj_desc) {
  643. /*
  644. * No object, create a new one (Device nodes do not always have
  645. * an attached object)
  646. */
  647. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
  648. if (!obj_desc) {
  649. status = AE_NO_MEMORY;
  650. goto unlock_and_exit;
  651. }
  652. status =
  653. acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
  654. /* Remove local reference to the object */
  655. acpi_ut_remove_reference(obj_desc);
  656. if (ACPI_FAILURE(status)) {
  657. goto unlock_and_exit;
  658. }
  659. }
  660. /* Now install the GPE block in the device_object */
  661. obj_desc->device.gpe_block = gpe_block;
  662. /* Run the _PRW methods and enable the runtime GPEs in the new block */
  663. status = acpi_ev_initialize_gpe_block(node, gpe_block);
  664. unlock_and_exit:
  665. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  666. return_ACPI_STATUS(status);
  667. }
  668. ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
  669. /*******************************************************************************
  670. *
  671. * FUNCTION: acpi_remove_gpe_block
  672. *
  673. * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
  674. *
  675. * RETURN: Status
  676. *
  677. * DESCRIPTION: Remove a previously installed block of GPE registers
  678. *
  679. ******************************************************************************/
  680. acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
  681. {
  682. union acpi_operand_object *obj_desc;
  683. acpi_status status;
  684. struct acpi_namespace_node *node;
  685. ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
  686. if (!gpe_device) {
  687. return_ACPI_STATUS(AE_BAD_PARAMETER);
  688. }
  689. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  690. if (ACPI_FAILURE(status)) {
  691. return (status);
  692. }
  693. node = acpi_ns_validate_handle(gpe_device);
  694. if (!node) {
  695. status = AE_BAD_PARAMETER;
  696. goto unlock_and_exit;
  697. }
  698. /* Get the device_object attached to the node */
  699. obj_desc = acpi_ns_get_attached_object(node);
  700. if (!obj_desc || !obj_desc->device.gpe_block) {
  701. return_ACPI_STATUS(AE_NULL_OBJECT);
  702. }
  703. /* Delete the GPE block (but not the device_object) */
  704. status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
  705. if (ACPI_SUCCESS(status)) {
  706. obj_desc->device.gpe_block = NULL;
  707. }
  708. unlock_and_exit:
  709. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  710. return_ACPI_STATUS(status);
  711. }
  712. ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)
  713. /*******************************************************************************
  714. *
  715. * FUNCTION: acpi_get_gpe_device
  716. *
  717. * PARAMETERS: Index - System GPE index (0-current_gpe_count)
  718. * gpe_device - Where the parent GPE Device is returned
  719. *
  720. * RETURN: Status
  721. *
  722. * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
  723. * gpe device indicates that the gpe number is contained in one of
  724. * the FADT-defined gpe blocks. Otherwise, the GPE block device.
  725. *
  726. ******************************************************************************/
  727. acpi_status
  728. acpi_get_gpe_device(u32 index, acpi_handle *gpe_device)
  729. {
  730. struct acpi_gpe_device_info info;
  731. acpi_status status;
  732. ACPI_FUNCTION_TRACE(acpi_get_gpe_device);
  733. if (!gpe_device) {
  734. return_ACPI_STATUS(AE_BAD_PARAMETER);
  735. }
  736. if (index >= acpi_current_gpe_count) {
  737. return_ACPI_STATUS(AE_NOT_EXIST);
  738. }
  739. /* Setup and walk the GPE list */
  740. info.index = index;
  741. info.status = AE_NOT_EXIST;
  742. info.gpe_device = NULL;
  743. info.next_block_base_index = 0;
  744. status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info);
  745. if (ACPI_FAILURE(status)) {
  746. return_ACPI_STATUS(status);
  747. }
  748. *gpe_device = info.gpe_device;
  749. return_ACPI_STATUS(info.status);
  750. }
  751. ACPI_EXPORT_SYMBOL(acpi_get_gpe_device)
  752. /*******************************************************************************
  753. *
  754. * FUNCTION: acpi_ev_get_gpe_device
  755. *
  756. * PARAMETERS: GPE_WALK_CALLBACK
  757. *
  758. * RETURN: Status
  759. *
  760. * DESCRIPTION: Matches the input GPE index (0-current_gpe_count) with a GPE
  761. * block device. NULL if the GPE is one of the FADT-defined GPEs.
  762. *
  763. ******************************************************************************/
  764. static acpi_status
  765. acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
  766. struct acpi_gpe_block_info *gpe_block, void *context)
  767. {
  768. struct acpi_gpe_device_info *info = context;
  769. /* Increment Index by the number of GPEs in this block */
  770. info->next_block_base_index += gpe_block->gpe_count;
  771. if (info->index < info->next_block_base_index) {
  772. /*
  773. * The GPE index is within this block, get the node. Leave the node
  774. * NULL for the FADT-defined GPEs
  775. */
  776. if ((gpe_block->node)->type == ACPI_TYPE_DEVICE) {
  777. info->gpe_device = gpe_block->node;
  778. }
  779. info->status = AE_OK;
  780. return (AE_CTRL_END);
  781. }
  782. return (AE_OK);
  783. }
  784. /******************************************************************************
  785. *
  786. * FUNCTION: acpi_disable_all_gpes
  787. *
  788. * PARAMETERS: None
  789. *
  790. * RETURN: Status
  791. *
  792. * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
  793. *
  794. ******************************************************************************/
  795. acpi_status acpi_disable_all_gpes(void)
  796. {
  797. acpi_status status;
  798. ACPI_FUNCTION_TRACE(acpi_disable_all_gpes);
  799. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  800. if (ACPI_FAILURE(status)) {
  801. return_ACPI_STATUS(status);
  802. }
  803. status = acpi_hw_disable_all_gpes();
  804. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  805. return_ACPI_STATUS(status);
  806. }
  807. /******************************************************************************
  808. *
  809. * FUNCTION: acpi_enable_all_runtime_gpes
  810. *
  811. * PARAMETERS: None
  812. *
  813. * RETURN: Status
  814. *
  815. * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
  816. *
  817. ******************************************************************************/
  818. acpi_status acpi_enable_all_runtime_gpes(void)
  819. {
  820. acpi_status status;
  821. ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes);
  822. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  823. if (ACPI_FAILURE(status)) {
  824. return_ACPI_STATUS(status);
  825. }
  826. status = acpi_hw_enable_all_runtime_gpes();
  827. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  828. return_ACPI_STATUS(status);
  829. }