hwgpe.c 13 KB

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