evxfevnt.c 24 KB

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