hwgpe.c 14 KB

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