hwgpe.c 15 KB

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