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