evxfevnt.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953
  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. gpe_event_info->flags |= ACPI_GPE_CAN_WAKE;
  319. } else {
  320. status = AE_BAD_PARAMETER;
  321. }
  322. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  323. return_ACPI_STATUS(status);
  324. }
  325. ACPI_EXPORT_SYMBOL(acpi_gpe_can_wake)
  326. /*******************************************************************************
  327. *
  328. * FUNCTION: acpi_disable_event
  329. *
  330. * PARAMETERS: Event - The fixed eventto be enabled
  331. * Flags - Reserved
  332. *
  333. * RETURN: Status
  334. *
  335. * DESCRIPTION: Disable an ACPI event (fixed)
  336. *
  337. ******************************************************************************/
  338. acpi_status acpi_disable_event(u32 event, u32 flags)
  339. {
  340. acpi_status status = AE_OK;
  341. u32 value;
  342. ACPI_FUNCTION_TRACE(acpi_disable_event);
  343. /* Decode the Fixed Event */
  344. if (event > ACPI_EVENT_MAX) {
  345. return_ACPI_STATUS(AE_BAD_PARAMETER);
  346. }
  347. /*
  348. * Disable the requested fixed event (by writing a zero to the enable
  349. * register bit)
  350. */
  351. status =
  352. acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
  353. enable_register_id, ACPI_DISABLE_EVENT);
  354. if (ACPI_FAILURE(status)) {
  355. return_ACPI_STATUS(status);
  356. }
  357. status =
  358. acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
  359. enable_register_id, &value);
  360. if (ACPI_FAILURE(status)) {
  361. return_ACPI_STATUS(status);
  362. }
  363. if (value != 0) {
  364. ACPI_ERROR((AE_INFO,
  365. "Could not disable %s events",
  366. acpi_ut_get_event_name(event)));
  367. return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
  368. }
  369. return_ACPI_STATUS(status);
  370. }
  371. ACPI_EXPORT_SYMBOL(acpi_disable_event)
  372. /*******************************************************************************
  373. *
  374. * FUNCTION: acpi_clear_event
  375. *
  376. * PARAMETERS: Event - The fixed event to be cleared
  377. *
  378. * RETURN: Status
  379. *
  380. * DESCRIPTION: Clear an ACPI event (fixed)
  381. *
  382. ******************************************************************************/
  383. acpi_status acpi_clear_event(u32 event)
  384. {
  385. acpi_status status = AE_OK;
  386. ACPI_FUNCTION_TRACE(acpi_clear_event);
  387. /* Decode the Fixed Event */
  388. if (event > ACPI_EVENT_MAX) {
  389. return_ACPI_STATUS(AE_BAD_PARAMETER);
  390. }
  391. /*
  392. * Clear the requested fixed event (By writing a one to the status
  393. * register bit)
  394. */
  395. status =
  396. acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
  397. status_register_id, ACPI_CLEAR_STATUS);
  398. return_ACPI_STATUS(status);
  399. }
  400. ACPI_EXPORT_SYMBOL(acpi_clear_event)
  401. /*******************************************************************************
  402. *
  403. * FUNCTION: acpi_clear_gpe
  404. *
  405. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  406. * gpe_number - GPE level within the GPE block
  407. *
  408. * RETURN: Status
  409. *
  410. * DESCRIPTION: Clear an ACPI event (general purpose)
  411. *
  412. ******************************************************************************/
  413. acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number)
  414. {
  415. acpi_status status = AE_OK;
  416. struct acpi_gpe_event_info *gpe_event_info;
  417. acpi_cpu_flags flags;
  418. ACPI_FUNCTION_TRACE(acpi_clear_gpe);
  419. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  420. /* Ensure that we have a valid GPE number */
  421. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  422. if (!gpe_event_info) {
  423. status = AE_BAD_PARAMETER;
  424. goto unlock_and_exit;
  425. }
  426. status = acpi_hw_clear_gpe(gpe_event_info);
  427. unlock_and_exit:
  428. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  429. return_ACPI_STATUS(status);
  430. }
  431. ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
  432. /*******************************************************************************
  433. *
  434. * FUNCTION: acpi_get_event_status
  435. *
  436. * PARAMETERS: Event - The fixed event
  437. * event_status - Where the current status of the event will
  438. * be returned
  439. *
  440. * RETURN: Status
  441. *
  442. * DESCRIPTION: Obtains and returns the current status of the event
  443. *
  444. ******************************************************************************/
  445. acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
  446. {
  447. acpi_status status = AE_OK;
  448. u32 value;
  449. ACPI_FUNCTION_TRACE(acpi_get_event_status);
  450. if (!event_status) {
  451. return_ACPI_STATUS(AE_BAD_PARAMETER);
  452. }
  453. /* Decode the Fixed Event */
  454. if (event > ACPI_EVENT_MAX) {
  455. return_ACPI_STATUS(AE_BAD_PARAMETER);
  456. }
  457. /* Get the status of the requested fixed event */
  458. status =
  459. acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
  460. enable_register_id, &value);
  461. if (ACPI_FAILURE(status))
  462. return_ACPI_STATUS(status);
  463. *event_status = value;
  464. status =
  465. acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
  466. status_register_id, &value);
  467. if (ACPI_FAILURE(status))
  468. return_ACPI_STATUS(status);
  469. if (value)
  470. *event_status |= ACPI_EVENT_FLAG_SET;
  471. if (acpi_gbl_fixed_event_handlers[event].handler)
  472. *event_status |= ACPI_EVENT_FLAG_HANDLE;
  473. return_ACPI_STATUS(status);
  474. }
  475. ACPI_EXPORT_SYMBOL(acpi_get_event_status)
  476. /*******************************************************************************
  477. *
  478. * FUNCTION: acpi_get_gpe_status
  479. *
  480. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  481. * gpe_number - GPE level within the GPE block
  482. * event_status - Where the current status of the event will
  483. * be returned
  484. *
  485. * RETURN: Status
  486. *
  487. * DESCRIPTION: Get status of an event (general purpose)
  488. *
  489. ******************************************************************************/
  490. acpi_status
  491. acpi_get_gpe_status(acpi_handle gpe_device,
  492. u32 gpe_number, acpi_event_status *event_status)
  493. {
  494. acpi_status status = AE_OK;
  495. struct acpi_gpe_event_info *gpe_event_info;
  496. acpi_cpu_flags flags;
  497. ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
  498. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  499. /* Ensure that we have a valid GPE number */
  500. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  501. if (!gpe_event_info) {
  502. status = AE_BAD_PARAMETER;
  503. goto unlock_and_exit;
  504. }
  505. /* Obtain status on the requested GPE number */
  506. status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
  507. if (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)
  508. *event_status |= ACPI_EVENT_FLAG_HANDLE;
  509. unlock_and_exit:
  510. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  511. return_ACPI_STATUS(status);
  512. }
  513. ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
  514. /*******************************************************************************
  515. *
  516. * FUNCTION: acpi_install_gpe_block
  517. *
  518. * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
  519. * gpe_block_address - Address and space_iD
  520. * register_count - Number of GPE register pairs in the block
  521. * interrupt_number - H/W interrupt for the block
  522. *
  523. * RETURN: Status
  524. *
  525. * DESCRIPTION: Create and Install a block of GPE registers
  526. *
  527. ******************************************************************************/
  528. acpi_status
  529. acpi_install_gpe_block(acpi_handle gpe_device,
  530. struct acpi_generic_address *gpe_block_address,
  531. u32 register_count, u32 interrupt_number)
  532. {
  533. acpi_status status = AE_OK;
  534. union acpi_operand_object *obj_desc;
  535. struct acpi_namespace_node *node;
  536. struct acpi_gpe_block_info *gpe_block;
  537. ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
  538. if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
  539. return_ACPI_STATUS(AE_BAD_PARAMETER);
  540. }
  541. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  542. if (ACPI_FAILURE(status)) {
  543. return (status);
  544. }
  545. node = acpi_ns_validate_handle(gpe_device);
  546. if (!node) {
  547. status = AE_BAD_PARAMETER;
  548. goto unlock_and_exit;
  549. }
  550. /*
  551. * For user-installed GPE Block Devices, the gpe_block_base_number
  552. * is always zero
  553. */
  554. status =
  555. acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0,
  556. interrupt_number, &gpe_block);
  557. if (ACPI_FAILURE(status)) {
  558. goto unlock_and_exit;
  559. }
  560. /* Install block in the device_object attached to the node */
  561. obj_desc = acpi_ns_get_attached_object(node);
  562. if (!obj_desc) {
  563. /*
  564. * No object, create a new one (Device nodes do not always have
  565. * an attached object)
  566. */
  567. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
  568. if (!obj_desc) {
  569. status = AE_NO_MEMORY;
  570. goto unlock_and_exit;
  571. }
  572. status =
  573. acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
  574. /* Remove local reference to the object */
  575. acpi_ut_remove_reference(obj_desc);
  576. if (ACPI_FAILURE(status)) {
  577. goto unlock_and_exit;
  578. }
  579. }
  580. /* Now install the GPE block in the device_object */
  581. obj_desc->device.gpe_block = gpe_block;
  582. unlock_and_exit:
  583. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  584. return_ACPI_STATUS(status);
  585. }
  586. ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
  587. /*******************************************************************************
  588. *
  589. * FUNCTION: acpi_remove_gpe_block
  590. *
  591. * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
  592. *
  593. * RETURN: Status
  594. *
  595. * DESCRIPTION: Remove a previously installed block of GPE registers
  596. *
  597. ******************************************************************************/
  598. acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
  599. {
  600. union acpi_operand_object *obj_desc;
  601. acpi_status status;
  602. struct acpi_namespace_node *node;
  603. ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
  604. if (!gpe_device) {
  605. return_ACPI_STATUS(AE_BAD_PARAMETER);
  606. }
  607. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  608. if (ACPI_FAILURE(status)) {
  609. return (status);
  610. }
  611. node = acpi_ns_validate_handle(gpe_device);
  612. if (!node) {
  613. status = AE_BAD_PARAMETER;
  614. goto unlock_and_exit;
  615. }
  616. /* Get the device_object attached to the node */
  617. obj_desc = acpi_ns_get_attached_object(node);
  618. if (!obj_desc || !obj_desc->device.gpe_block) {
  619. return_ACPI_STATUS(AE_NULL_OBJECT);
  620. }
  621. /* Delete the GPE block (but not the device_object) */
  622. status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
  623. if (ACPI_SUCCESS(status)) {
  624. obj_desc->device.gpe_block = NULL;
  625. }
  626. unlock_and_exit:
  627. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  628. return_ACPI_STATUS(status);
  629. }
  630. ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)
  631. /*******************************************************************************
  632. *
  633. * FUNCTION: acpi_get_gpe_device
  634. *
  635. * PARAMETERS: Index - System GPE index (0-current_gpe_count)
  636. * gpe_device - Where the parent GPE Device is returned
  637. *
  638. * RETURN: Status
  639. *
  640. * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
  641. * gpe device indicates that the gpe number is contained in one of
  642. * the FADT-defined gpe blocks. Otherwise, the GPE block device.
  643. *
  644. ******************************************************************************/
  645. acpi_status
  646. acpi_get_gpe_device(u32 index, acpi_handle *gpe_device)
  647. {
  648. struct acpi_gpe_device_info info;
  649. acpi_status status;
  650. ACPI_FUNCTION_TRACE(acpi_get_gpe_device);
  651. if (!gpe_device) {
  652. return_ACPI_STATUS(AE_BAD_PARAMETER);
  653. }
  654. if (index >= acpi_current_gpe_count) {
  655. return_ACPI_STATUS(AE_NOT_EXIST);
  656. }
  657. /* Setup and walk the GPE list */
  658. info.index = index;
  659. info.status = AE_NOT_EXIST;
  660. info.gpe_device = NULL;
  661. info.next_block_base_index = 0;
  662. status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info);
  663. if (ACPI_FAILURE(status)) {
  664. return_ACPI_STATUS(status);
  665. }
  666. *gpe_device = info.gpe_device;
  667. return_ACPI_STATUS(info.status);
  668. }
  669. ACPI_EXPORT_SYMBOL(acpi_get_gpe_device)
  670. /*******************************************************************************
  671. *
  672. * FUNCTION: acpi_ev_get_gpe_device
  673. *
  674. * PARAMETERS: GPE_WALK_CALLBACK
  675. *
  676. * RETURN: Status
  677. *
  678. * DESCRIPTION: Matches the input GPE index (0-current_gpe_count) with a GPE
  679. * block device. NULL if the GPE is one of the FADT-defined GPEs.
  680. *
  681. ******************************************************************************/
  682. static acpi_status
  683. acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
  684. struct acpi_gpe_block_info *gpe_block, void *context)
  685. {
  686. struct acpi_gpe_device_info *info = context;
  687. /* Increment Index by the number of GPEs in this block */
  688. info->next_block_base_index += gpe_block->gpe_count;
  689. if (info->index < info->next_block_base_index) {
  690. /*
  691. * The GPE index is within this block, get the node. Leave the node
  692. * NULL for the FADT-defined GPEs
  693. */
  694. if ((gpe_block->node)->type == ACPI_TYPE_DEVICE) {
  695. info->gpe_device = gpe_block->node;
  696. }
  697. info->status = AE_OK;
  698. return (AE_CTRL_END);
  699. }
  700. return (AE_OK);
  701. }
  702. /******************************************************************************
  703. *
  704. * FUNCTION: acpi_disable_all_gpes
  705. *
  706. * PARAMETERS: None
  707. *
  708. * RETURN: Status
  709. *
  710. * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
  711. *
  712. ******************************************************************************/
  713. acpi_status acpi_disable_all_gpes(void)
  714. {
  715. acpi_status status;
  716. ACPI_FUNCTION_TRACE(acpi_disable_all_gpes);
  717. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  718. if (ACPI_FAILURE(status)) {
  719. return_ACPI_STATUS(status);
  720. }
  721. status = acpi_hw_disable_all_gpes();
  722. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  723. return_ACPI_STATUS(status);
  724. }
  725. /******************************************************************************
  726. *
  727. * FUNCTION: acpi_enable_all_runtime_gpes
  728. *
  729. * PARAMETERS: None
  730. *
  731. * RETURN: Status
  732. *
  733. * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
  734. *
  735. ******************************************************************************/
  736. acpi_status acpi_enable_all_runtime_gpes(void)
  737. {
  738. acpi_status status;
  739. ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes);
  740. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  741. if (ACPI_FAILURE(status)) {
  742. return_ACPI_STATUS(status);
  743. }
  744. status = acpi_hw_enable_all_runtime_gpes();
  745. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  746. return_ACPI_STATUS(status);
  747. }
  748. /******************************************************************************
  749. *
  750. * FUNCTION: acpi_update_gpes
  751. *
  752. * PARAMETERS: None
  753. *
  754. * RETURN: None
  755. *
  756. * DESCRIPTION: Enable all GPEs that have associated _Lxx or _Exx methods and
  757. * are not pointed to by any device _PRW methods indicating that
  758. * these GPEs are generally intended for system or device wakeup
  759. * (such GPEs have to be enabled directly when the devices whose
  760. * _PRW methods point to them are set up for wakeup signaling).
  761. *
  762. ******************************************************************************/
  763. acpi_status acpi_update_gpes(void)
  764. {
  765. acpi_status status;
  766. ACPI_FUNCTION_TRACE(acpi_update_gpes);
  767. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  768. if (ACPI_FAILURE(status)) {
  769. return_ACPI_STATUS(status);
  770. } else if (acpi_all_gpes_initialized) {
  771. goto unlock;
  772. }
  773. status = acpi_ev_walk_gpe_list(acpi_ev_initialize_gpe_block, NULL);
  774. if (ACPI_SUCCESS(status)) {
  775. acpi_all_gpes_initialized = TRUE;
  776. }
  777. unlock:
  778. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  779. return_ACPI_STATUS(status);
  780. }