evxfevnt.c 26 KB

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