evxfevnt.c 25 KB

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