hwgpe.c 15 KB

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