evxfgpe.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. /******************************************************************************
  2. *
  3. * Module Name: evxfgpe - External Interfaces for General Purpose Events (GPEs)
  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. #define _COMPONENT ACPI_EVENTS
  47. ACPI_MODULE_NAME("evxfgpe")
  48. /******************************************************************************
  49. *
  50. * FUNCTION: acpi_update_gpes
  51. *
  52. * PARAMETERS: None
  53. *
  54. * RETURN: None
  55. *
  56. * DESCRIPTION: Enable all GPEs that have associated _Lxx or _Exx methods and
  57. * are not pointed to by any device _PRW methods indicating that
  58. * these GPEs are generally intended for system or device wakeup
  59. * (such GPEs have to be enabled directly when the devices whose
  60. * _PRW methods point to them are set up for wakeup signaling).
  61. *
  62. ******************************************************************************/
  63. acpi_status acpi_update_gpes(void)
  64. {
  65. acpi_status status;
  66. ACPI_FUNCTION_TRACE(acpi_update_gpes);
  67. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  68. if (ACPI_FAILURE(status)) {
  69. return_ACPI_STATUS(status);
  70. } else if (acpi_all_gpes_initialized) {
  71. goto unlock;
  72. }
  73. status = acpi_ev_walk_gpe_list(acpi_ev_initialize_gpe_block, NULL);
  74. if (ACPI_SUCCESS(status)) {
  75. acpi_all_gpes_initialized = TRUE;
  76. }
  77. unlock:
  78. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  79. return_ACPI_STATUS(status);
  80. }
  81. /*******************************************************************************
  82. *
  83. * FUNCTION: acpi_enable_gpe
  84. *
  85. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  86. * gpe_number - GPE level within the GPE block
  87. *
  88. * RETURN: Status
  89. *
  90. * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
  91. * hardware-enabled.
  92. *
  93. ******************************************************************************/
  94. acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number)
  95. {
  96. acpi_status status = AE_BAD_PARAMETER;
  97. struct acpi_gpe_event_info *gpe_event_info;
  98. acpi_cpu_flags flags;
  99. ACPI_FUNCTION_TRACE(acpi_enable_gpe);
  100. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  101. /* Ensure that we have a valid GPE number */
  102. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  103. if (gpe_event_info) {
  104. status = acpi_raw_enable_gpe(gpe_event_info);
  105. }
  106. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  107. return_ACPI_STATUS(status);
  108. }
  109. ACPI_EXPORT_SYMBOL(acpi_enable_gpe)
  110. /*******************************************************************************
  111. *
  112. * FUNCTION: acpi_disable_gpe
  113. *
  114. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  115. * gpe_number - GPE level within the GPE block
  116. *
  117. * RETURN: Status
  118. *
  119. * DESCRIPTION: Remove a reference to a GPE. When the last reference is
  120. * removed, only then is the GPE disabled (for runtime GPEs), or
  121. * the GPE mask bit disabled (for wake GPEs)
  122. *
  123. ******************************************************************************/
  124. acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number)
  125. {
  126. acpi_status status = AE_BAD_PARAMETER;
  127. struct acpi_gpe_event_info *gpe_event_info;
  128. acpi_cpu_flags flags;
  129. ACPI_FUNCTION_TRACE(acpi_disable_gpe);
  130. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  131. /* Ensure that we have a valid GPE number */
  132. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  133. if (gpe_event_info) {
  134. status = acpi_raw_disable_gpe(gpe_event_info) ;
  135. }
  136. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  137. return_ACPI_STATUS(status);
  138. }
  139. ACPI_EXPORT_SYMBOL(acpi_disable_gpe)
  140. /*******************************************************************************
  141. *
  142. * FUNCTION: acpi_gpe_can_wake
  143. *
  144. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  145. * gpe_number - GPE level within the GPE block
  146. *
  147. * RETURN: Status
  148. *
  149. * DESCRIPTION: Set the ACPI_GPE_CAN_WAKE flag for the given GPE. If the GPE
  150. * has a corresponding method and is currently enabled, disable it
  151. * (GPEs with corresponding methods are enabled unconditionally
  152. * during initialization, but GPEs that can wake up are expected
  153. * to be initially disabled).
  154. *
  155. ******************************************************************************/
  156. acpi_status acpi_gpe_can_wake(acpi_handle gpe_device, u32 gpe_number)
  157. {
  158. acpi_status status = AE_OK;
  159. struct acpi_gpe_event_info *gpe_event_info;
  160. acpi_cpu_flags flags;
  161. ACPI_FUNCTION_TRACE(acpi_gpe_can_wake);
  162. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  163. /* Ensure that we have a valid GPE number */
  164. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  165. if (gpe_event_info) {
  166. gpe_event_info->flags |= ACPI_GPE_CAN_WAKE;
  167. } else {
  168. status = AE_BAD_PARAMETER;
  169. }
  170. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  171. return_ACPI_STATUS(status);
  172. }
  173. ACPI_EXPORT_SYMBOL(acpi_gpe_can_wake)
  174. /*******************************************************************************
  175. *
  176. * FUNCTION: acpi_gpe_wakeup
  177. *
  178. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  179. * gpe_number - GPE level within the GPE block
  180. * Action - Enable or Disable
  181. *
  182. * RETURN: Status
  183. *
  184. * DESCRIPTION: Set or clear the GPE's wakeup enable mask bit.
  185. *
  186. ******************************************************************************/
  187. acpi_status acpi_gpe_wakeup(acpi_handle gpe_device, u32 gpe_number, u8 action)
  188. {
  189. acpi_status status = AE_OK;
  190. struct acpi_gpe_event_info *gpe_event_info;
  191. struct acpi_gpe_register_info *gpe_register_info;
  192. acpi_cpu_flags flags;
  193. u32 register_bit;
  194. ACPI_FUNCTION_TRACE(acpi_gpe_wakeup);
  195. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  196. /* Ensure that we have a valid GPE number */
  197. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  198. if (!gpe_event_info || !(gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) {
  199. status = AE_BAD_PARAMETER;
  200. goto unlock_and_exit;
  201. }
  202. gpe_register_info = gpe_event_info->register_info;
  203. if (!gpe_register_info) {
  204. status = AE_NOT_EXIST;
  205. goto unlock_and_exit;
  206. }
  207. register_bit =
  208. acpi_hw_get_gpe_register_bit(gpe_event_info, gpe_register_info);
  209. /* Perform the action */
  210. switch (action) {
  211. case ACPI_GPE_ENABLE:
  212. ACPI_SET_BIT(gpe_register_info->enable_for_wake,
  213. (u8)register_bit);
  214. break;
  215. case ACPI_GPE_DISABLE:
  216. ACPI_CLEAR_BIT(gpe_register_info->enable_for_wake,
  217. (u8)register_bit);
  218. break;
  219. default:
  220. ACPI_ERROR((AE_INFO, "%u, Invalid action", action));
  221. status = AE_BAD_PARAMETER;
  222. break;
  223. }
  224. unlock_and_exit:
  225. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  226. return_ACPI_STATUS(status);
  227. }
  228. ACPI_EXPORT_SYMBOL(acpi_gpe_wakeup)
  229. /*******************************************************************************
  230. *
  231. * FUNCTION: acpi_clear_gpe
  232. *
  233. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  234. * gpe_number - GPE level within the GPE block
  235. *
  236. * RETURN: Status
  237. *
  238. * DESCRIPTION: Clear an ACPI event (general purpose)
  239. *
  240. ******************************************************************************/
  241. acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number)
  242. {
  243. acpi_status status = AE_OK;
  244. struct acpi_gpe_event_info *gpe_event_info;
  245. acpi_cpu_flags flags;
  246. ACPI_FUNCTION_TRACE(acpi_clear_gpe);
  247. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  248. /* Ensure that we have a valid GPE number */
  249. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  250. if (!gpe_event_info) {
  251. status = AE_BAD_PARAMETER;
  252. goto unlock_and_exit;
  253. }
  254. status = acpi_hw_clear_gpe(gpe_event_info);
  255. unlock_and_exit:
  256. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  257. return_ACPI_STATUS(status);
  258. }
  259. ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
  260. /*******************************************************************************
  261. *
  262. * FUNCTION: acpi_get_gpe_status
  263. *
  264. * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
  265. * gpe_number - GPE level within the GPE block
  266. * event_status - Where the current status of the event will
  267. * be returned
  268. *
  269. * RETURN: Status
  270. *
  271. * DESCRIPTION: Get status of an event (general purpose)
  272. *
  273. ******************************************************************************/
  274. acpi_status
  275. acpi_get_gpe_status(acpi_handle gpe_device,
  276. u32 gpe_number, acpi_event_status *event_status)
  277. {
  278. acpi_status status = AE_OK;
  279. struct acpi_gpe_event_info *gpe_event_info;
  280. acpi_cpu_flags flags;
  281. ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
  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 = AE_BAD_PARAMETER;
  287. goto unlock_and_exit;
  288. }
  289. /* Obtain status on the requested GPE number */
  290. status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
  291. if (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)
  292. *event_status |= ACPI_EVENT_FLAG_HANDLE;
  293. unlock_and_exit:
  294. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  295. return_ACPI_STATUS(status);
  296. }
  297. ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
  298. /******************************************************************************
  299. *
  300. * FUNCTION: acpi_disable_all_gpes
  301. *
  302. * PARAMETERS: None
  303. *
  304. * RETURN: Status
  305. *
  306. * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
  307. *
  308. ******************************************************************************/
  309. acpi_status acpi_disable_all_gpes(void)
  310. {
  311. acpi_status status;
  312. ACPI_FUNCTION_TRACE(acpi_disable_all_gpes);
  313. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  314. if (ACPI_FAILURE(status)) {
  315. return_ACPI_STATUS(status);
  316. }
  317. status = acpi_hw_disable_all_gpes();
  318. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  319. return_ACPI_STATUS(status);
  320. }
  321. /******************************************************************************
  322. *
  323. * FUNCTION: acpi_enable_all_runtime_gpes
  324. *
  325. * PARAMETERS: None
  326. *
  327. * RETURN: Status
  328. *
  329. * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
  330. *
  331. ******************************************************************************/
  332. acpi_status acpi_enable_all_runtime_gpes(void)
  333. {
  334. acpi_status status;
  335. ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes);
  336. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  337. if (ACPI_FAILURE(status)) {
  338. return_ACPI_STATUS(status);
  339. }
  340. status = acpi_hw_enable_all_runtime_gpes();
  341. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  342. return_ACPI_STATUS(status);
  343. }
  344. /*******************************************************************************
  345. *
  346. * FUNCTION: acpi_install_gpe_block
  347. *
  348. * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
  349. * gpe_block_address - Address and space_iD
  350. * register_count - Number of GPE register pairs in the block
  351. * interrupt_number - H/W interrupt for the block
  352. *
  353. * RETURN: Status
  354. *
  355. * DESCRIPTION: Create and Install a block of GPE registers
  356. *
  357. ******************************************************************************/
  358. acpi_status
  359. acpi_install_gpe_block(acpi_handle gpe_device,
  360. struct acpi_generic_address *gpe_block_address,
  361. u32 register_count, u32 interrupt_number)
  362. {
  363. acpi_status status = AE_OK;
  364. union acpi_operand_object *obj_desc;
  365. struct acpi_namespace_node *node;
  366. struct acpi_gpe_block_info *gpe_block;
  367. ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
  368. if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
  369. return_ACPI_STATUS(AE_BAD_PARAMETER);
  370. }
  371. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  372. if (ACPI_FAILURE(status)) {
  373. return (status);
  374. }
  375. node = acpi_ns_validate_handle(gpe_device);
  376. if (!node) {
  377. status = AE_BAD_PARAMETER;
  378. goto unlock_and_exit;
  379. }
  380. /*
  381. * For user-installed GPE Block Devices, the gpe_block_base_number
  382. * is always zero
  383. */
  384. status =
  385. acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0,
  386. interrupt_number, &gpe_block);
  387. if (ACPI_FAILURE(status)) {
  388. goto unlock_and_exit;
  389. }
  390. /* Install block in the device_object attached to the node */
  391. obj_desc = acpi_ns_get_attached_object(node);
  392. if (!obj_desc) {
  393. /*
  394. * No object, create a new one (Device nodes do not always have
  395. * an attached object)
  396. */
  397. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
  398. if (!obj_desc) {
  399. status = AE_NO_MEMORY;
  400. goto unlock_and_exit;
  401. }
  402. status =
  403. acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
  404. /* Remove local reference to the object */
  405. acpi_ut_remove_reference(obj_desc);
  406. if (ACPI_FAILURE(status)) {
  407. goto unlock_and_exit;
  408. }
  409. }
  410. /* Now install the GPE block in the device_object */
  411. obj_desc->device.gpe_block = gpe_block;
  412. unlock_and_exit:
  413. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  414. return_ACPI_STATUS(status);
  415. }
  416. ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
  417. /*******************************************************************************
  418. *
  419. * FUNCTION: acpi_remove_gpe_block
  420. *
  421. * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
  422. *
  423. * RETURN: Status
  424. *
  425. * DESCRIPTION: Remove a previously installed block of GPE registers
  426. *
  427. ******************************************************************************/
  428. acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
  429. {
  430. union acpi_operand_object *obj_desc;
  431. acpi_status status;
  432. struct acpi_namespace_node *node;
  433. ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
  434. if (!gpe_device) {
  435. return_ACPI_STATUS(AE_BAD_PARAMETER);
  436. }
  437. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  438. if (ACPI_FAILURE(status)) {
  439. return (status);
  440. }
  441. node = acpi_ns_validate_handle(gpe_device);
  442. if (!node) {
  443. status = AE_BAD_PARAMETER;
  444. goto unlock_and_exit;
  445. }
  446. /* Get the device_object attached to the node */
  447. obj_desc = acpi_ns_get_attached_object(node);
  448. if (!obj_desc || !obj_desc->device.gpe_block) {
  449. return_ACPI_STATUS(AE_NULL_OBJECT);
  450. }
  451. /* Delete the GPE block (but not the device_object) */
  452. status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
  453. if (ACPI_SUCCESS(status)) {
  454. obj_desc->device.gpe_block = NULL;
  455. }
  456. unlock_and_exit:
  457. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  458. return_ACPI_STATUS(status);
  459. }
  460. ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)
  461. /*******************************************************************************
  462. *
  463. * FUNCTION: acpi_get_gpe_device
  464. *
  465. * PARAMETERS: Index - System GPE index (0-current_gpe_count)
  466. * gpe_device - Where the parent GPE Device is returned
  467. *
  468. * RETURN: Status
  469. *
  470. * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
  471. * gpe device indicates that the gpe number is contained in one of
  472. * the FADT-defined gpe blocks. Otherwise, the GPE block device.
  473. *
  474. ******************************************************************************/
  475. acpi_status
  476. acpi_get_gpe_device(u32 index, acpi_handle *gpe_device)
  477. {
  478. struct acpi_gpe_device_info info;
  479. acpi_status status;
  480. ACPI_FUNCTION_TRACE(acpi_get_gpe_device);
  481. if (!gpe_device) {
  482. return_ACPI_STATUS(AE_BAD_PARAMETER);
  483. }
  484. if (index >= acpi_current_gpe_count) {
  485. return_ACPI_STATUS(AE_NOT_EXIST);
  486. }
  487. /* Setup and walk the GPE list */
  488. info.index = index;
  489. info.status = AE_NOT_EXIST;
  490. info.gpe_device = NULL;
  491. info.next_block_base_index = 0;
  492. status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info);
  493. if (ACPI_FAILURE(status)) {
  494. return_ACPI_STATUS(status);
  495. }
  496. *gpe_device = info.gpe_device;
  497. return_ACPI_STATUS(info.status);
  498. }
  499. ACPI_EXPORT_SYMBOL(acpi_get_gpe_device)