hwgpe.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. /******************************************************************************
  2. *
  3. * Module Name: hwgpe - Low level GPE enable/disable/clear functions
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2014, 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. #define _COMPONENT ACPI_HARDWARE
  46. ACPI_MODULE_NAME("hwgpe")
  47. #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
  48. /* Local prototypes */
  49. static acpi_status
  50. acpi_hw_enable_wakeup_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
  51. struct acpi_gpe_block_info *gpe_block,
  52. void *context);
  53. /******************************************************************************
  54. *
  55. * FUNCTION: acpi_hw_get_gpe_register_bit
  56. *
  57. * PARAMETERS: gpe_event_info - Info block for the GPE
  58. *
  59. * RETURN: Register mask with a one in the GPE bit position
  60. *
  61. * DESCRIPTION: Compute the register mask for this GPE. One bit is set in the
  62. * correct position for the input GPE.
  63. *
  64. ******************************************************************************/
  65. u32 acpi_hw_get_gpe_register_bit(struct acpi_gpe_event_info *gpe_event_info)
  66. {
  67. return ((u32)1 <<
  68. (gpe_event_info->gpe_number -
  69. gpe_event_info->register_info->base_gpe_number));
  70. }
  71. /******************************************************************************
  72. *
  73. * FUNCTION: acpi_hw_low_set_gpe
  74. *
  75. * PARAMETERS: gpe_event_info - Info block for the GPE to be disabled
  76. * action - Enable or disable
  77. *
  78. * RETURN: Status
  79. *
  80. * DESCRIPTION: Enable or disable a single GPE in the parent enable register.
  81. *
  82. ******************************************************************************/
  83. acpi_status
  84. acpi_hw_low_set_gpe(struct acpi_gpe_event_info *gpe_event_info, u32 action)
  85. {
  86. struct acpi_gpe_register_info *gpe_register_info;
  87. acpi_status status;
  88. u32 enable_mask;
  89. u32 register_bit;
  90. ACPI_FUNCTION_ENTRY();
  91. /* Get the info block for the entire GPE register */
  92. gpe_register_info = gpe_event_info->register_info;
  93. if (!gpe_register_info) {
  94. return (AE_NOT_EXIST);
  95. }
  96. /* Get current value of the enable register that contains this GPE */
  97. status = acpi_hw_read(&enable_mask, &gpe_register_info->enable_address);
  98. if (ACPI_FAILURE(status)) {
  99. return (status);
  100. }
  101. /* Set or clear just the bit that corresponds to this GPE */
  102. register_bit = acpi_hw_get_gpe_register_bit(gpe_event_info);
  103. switch (action) {
  104. case ACPI_GPE_CONDITIONAL_ENABLE:
  105. /* Only enable if the enable_for_run bit is set */
  106. if (!(register_bit & gpe_register_info->enable_for_run)) {
  107. return (AE_BAD_PARAMETER);
  108. }
  109. /*lint -fallthrough */
  110. case ACPI_GPE_ENABLE:
  111. ACPI_SET_BIT(enable_mask, register_bit);
  112. break;
  113. case ACPI_GPE_DISABLE:
  114. ACPI_CLEAR_BIT(enable_mask, register_bit);
  115. break;
  116. default:
  117. ACPI_ERROR((AE_INFO, "Invalid GPE Action, %u", action));
  118. return (AE_BAD_PARAMETER);
  119. }
  120. /* Write the updated enable mask */
  121. status = acpi_hw_write(enable_mask, &gpe_register_info->enable_address);
  122. return (status);
  123. }
  124. /******************************************************************************
  125. *
  126. * FUNCTION: acpi_hw_clear_gpe
  127. *
  128. * PARAMETERS: gpe_event_info - Info block for the GPE to be cleared
  129. *
  130. * RETURN: Status
  131. *
  132. * DESCRIPTION: Clear the status bit for a single GPE.
  133. *
  134. ******************************************************************************/
  135. acpi_status acpi_hw_clear_gpe(struct acpi_gpe_event_info * gpe_event_info)
  136. {
  137. struct acpi_gpe_register_info *gpe_register_info;
  138. acpi_status status;
  139. u32 register_bit;
  140. ACPI_FUNCTION_ENTRY();
  141. /* Get the info block for the entire GPE register */
  142. gpe_register_info = gpe_event_info->register_info;
  143. if (!gpe_register_info) {
  144. return (AE_NOT_EXIST);
  145. }
  146. /*
  147. * Write a one to the appropriate bit in the status register to
  148. * clear this GPE.
  149. */
  150. register_bit = acpi_hw_get_gpe_register_bit(gpe_event_info);
  151. status = acpi_hw_write(register_bit,
  152. &gpe_register_info->status_address);
  153. return (status);
  154. }
  155. /******************************************************************************
  156. *
  157. * FUNCTION: acpi_hw_get_gpe_status
  158. *
  159. * PARAMETERS: gpe_event_info - Info block for the GPE to queried
  160. * event_status - Where the GPE status is returned
  161. *
  162. * RETURN: Status
  163. *
  164. * DESCRIPTION: Return the status of a single GPE.
  165. *
  166. ******************************************************************************/
  167. acpi_status
  168. acpi_hw_get_gpe_status(struct acpi_gpe_event_info * gpe_event_info,
  169. acpi_event_status *event_status)
  170. {
  171. u32 in_byte;
  172. u32 register_bit;
  173. struct acpi_gpe_register_info *gpe_register_info;
  174. acpi_event_status local_event_status = 0;
  175. acpi_status status;
  176. ACPI_FUNCTION_ENTRY();
  177. if (!event_status) {
  178. return (AE_BAD_PARAMETER);
  179. }
  180. /* GPE currently handled? */
  181. if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) !=
  182. ACPI_GPE_DISPATCH_NONE) {
  183. local_event_status |= ACPI_EVENT_FLAG_HAS_HANDLER;
  184. }
  185. /* Get the info block for the entire GPE register */
  186. gpe_register_info = gpe_event_info->register_info;
  187. /* Get the register bitmask for this GPE */
  188. register_bit = acpi_hw_get_gpe_register_bit(gpe_event_info);
  189. /* GPE currently enabled? (enabled for runtime?) */
  190. if (register_bit & gpe_register_info->enable_for_run) {
  191. local_event_status |= ACPI_EVENT_FLAG_ENABLED;
  192. }
  193. /* GPE enabled for wake? */
  194. if (register_bit & gpe_register_info->enable_for_wake) {
  195. local_event_status |= ACPI_EVENT_FLAG_WAKE_ENABLED;
  196. }
  197. /* GPE currently active (status bit == 1)? */
  198. status = acpi_hw_read(&in_byte, &gpe_register_info->status_address);
  199. if (ACPI_FAILURE(status)) {
  200. return (status);
  201. }
  202. if (register_bit & in_byte) {
  203. local_event_status |= ACPI_EVENT_FLAG_SET;
  204. }
  205. /* Set return value */
  206. (*event_status) = local_event_status;
  207. return (AE_OK);
  208. }
  209. /******************************************************************************
  210. *
  211. * FUNCTION: acpi_hw_disable_gpe_block
  212. *
  213. * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
  214. * gpe_block - Gpe Block info
  215. *
  216. * RETURN: Status
  217. *
  218. * DESCRIPTION: Disable all GPEs within a single GPE block
  219. *
  220. ******************************************************************************/
  221. acpi_status
  222. acpi_hw_disable_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
  223. struct acpi_gpe_block_info *gpe_block, void *context)
  224. {
  225. u32 i;
  226. acpi_status status;
  227. /* Examine each GPE Register within the block */
  228. for (i = 0; i < gpe_block->register_count; i++) {
  229. /* Disable all GPEs in this register */
  230. status =
  231. acpi_hw_write(0x00,
  232. &gpe_block->register_info[i].enable_address);
  233. if (ACPI_FAILURE(status)) {
  234. return (status);
  235. }
  236. }
  237. return (AE_OK);
  238. }
  239. /******************************************************************************
  240. *
  241. * FUNCTION: acpi_hw_clear_gpe_block
  242. *
  243. * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
  244. * gpe_block - Gpe Block info
  245. *
  246. * RETURN: Status
  247. *
  248. * DESCRIPTION: Clear status bits for all GPEs within a single GPE block
  249. *
  250. ******************************************************************************/
  251. acpi_status
  252. acpi_hw_clear_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
  253. struct acpi_gpe_block_info *gpe_block, void *context)
  254. {
  255. u32 i;
  256. acpi_status status;
  257. /* Examine each GPE Register within the block */
  258. for (i = 0; i < gpe_block->register_count; i++) {
  259. /* Clear status on all GPEs in this register */
  260. status =
  261. acpi_hw_write(0xFF,
  262. &gpe_block->register_info[i].status_address);
  263. if (ACPI_FAILURE(status)) {
  264. return (status);
  265. }
  266. }
  267. return (AE_OK);
  268. }
  269. /******************************************************************************
  270. *
  271. * FUNCTION: acpi_hw_enable_runtime_gpe_block
  272. *
  273. * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
  274. * gpe_block - Gpe Block info
  275. *
  276. * RETURN: Status
  277. *
  278. * DESCRIPTION: Enable all "runtime" GPEs within a single GPE block. Includes
  279. * combination wake/run GPEs.
  280. *
  281. ******************************************************************************/
  282. acpi_status
  283. acpi_hw_enable_runtime_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
  284. struct acpi_gpe_block_info * gpe_block,
  285. void *context)
  286. {
  287. u32 i;
  288. acpi_status status;
  289. /* NOTE: assumes that all GPEs are currently disabled */
  290. /* Examine each GPE Register within the block */
  291. for (i = 0; i < gpe_block->register_count; i++) {
  292. if (!gpe_block->register_info[i].enable_for_run) {
  293. continue;
  294. }
  295. /* Enable all "runtime" GPEs in this register */
  296. status =
  297. acpi_hw_write(gpe_block->register_info[i].enable_for_run,
  298. &gpe_block->register_info[i].enable_address);
  299. if (ACPI_FAILURE(status)) {
  300. return (status);
  301. }
  302. }
  303. return (AE_OK);
  304. }
  305. /******************************************************************************
  306. *
  307. * FUNCTION: acpi_hw_enable_wakeup_gpe_block
  308. *
  309. * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
  310. * gpe_block - Gpe Block info
  311. *
  312. * RETURN: Status
  313. *
  314. * DESCRIPTION: Enable all "wake" GPEs within a single GPE block. Includes
  315. * combination wake/run GPEs.
  316. *
  317. ******************************************************************************/
  318. static acpi_status
  319. acpi_hw_enable_wakeup_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
  320. struct acpi_gpe_block_info *gpe_block,
  321. void *context)
  322. {
  323. u32 i;
  324. acpi_status status;
  325. /* Examine each GPE Register within the block */
  326. for (i = 0; i < gpe_block->register_count; i++) {
  327. /*
  328. * Enable all "wake" GPEs in this register and disable the
  329. * remaining ones.
  330. */
  331. status =
  332. acpi_hw_write(gpe_block->register_info[i].enable_for_wake,
  333. &gpe_block->register_info[i].enable_address);
  334. if (ACPI_FAILURE(status)) {
  335. return (status);
  336. }
  337. }
  338. return (AE_OK);
  339. }
  340. /******************************************************************************
  341. *
  342. * FUNCTION: acpi_hw_disable_all_gpes
  343. *
  344. * PARAMETERS: None
  345. *
  346. * RETURN: Status
  347. *
  348. * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
  349. *
  350. ******************************************************************************/
  351. acpi_status acpi_hw_disable_all_gpes(void)
  352. {
  353. acpi_status status;
  354. ACPI_FUNCTION_TRACE(hw_disable_all_gpes);
  355. status = acpi_ev_walk_gpe_list(acpi_hw_disable_gpe_block, NULL);
  356. status = acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block, NULL);
  357. return_ACPI_STATUS(status);
  358. }
  359. /******************************************************************************
  360. *
  361. * FUNCTION: acpi_hw_enable_all_runtime_gpes
  362. *
  363. * PARAMETERS: None
  364. *
  365. * RETURN: Status
  366. *
  367. * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
  368. *
  369. ******************************************************************************/
  370. acpi_status acpi_hw_enable_all_runtime_gpes(void)
  371. {
  372. acpi_status status;
  373. ACPI_FUNCTION_TRACE(hw_enable_all_runtime_gpes);
  374. status = acpi_ev_walk_gpe_list(acpi_hw_enable_runtime_gpe_block, NULL);
  375. return_ACPI_STATUS(status);
  376. }
  377. /******************************************************************************
  378. *
  379. * FUNCTION: acpi_hw_enable_all_wakeup_gpes
  380. *
  381. * PARAMETERS: None
  382. *
  383. * RETURN: Status
  384. *
  385. * DESCRIPTION: Enable all "wakeup" GPEs, in all GPE blocks
  386. *
  387. ******************************************************************************/
  388. acpi_status acpi_hw_enable_all_wakeup_gpes(void)
  389. {
  390. acpi_status status;
  391. ACPI_FUNCTION_TRACE(hw_enable_all_wakeup_gpes);
  392. status = acpi_ev_walk_gpe_list(acpi_hw_enable_wakeup_gpe_block, NULL);
  393. return_ACPI_STATUS(status);
  394. }
  395. #endif /* !ACPI_REDUCED_HARDWARE */