evevent.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. /******************************************************************************
  2. *
  3. * Module Name: evevent - Fixed Event handling and dispatch
  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.h"
  43. #include "accommon.h"
  44. #include "acevents.h"
  45. #define _COMPONENT ACPI_EVENTS
  46. ACPI_MODULE_NAME ("evevent")
  47. #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
  48. /* Local prototypes */
  49. static ACPI_STATUS
  50. AcpiEvFixedEventInitialize (
  51. void);
  52. static UINT32
  53. AcpiEvFixedEventDispatch (
  54. UINT32 Event);
  55. /*******************************************************************************
  56. *
  57. * FUNCTION: AcpiEvInitializeEvents
  58. *
  59. * PARAMETERS: None
  60. *
  61. * RETURN: Status
  62. *
  63. * DESCRIPTION: Initialize global data structures for ACPI events (Fixed, GPE)
  64. *
  65. ******************************************************************************/
  66. ACPI_STATUS
  67. AcpiEvInitializeEvents (
  68. void)
  69. {
  70. ACPI_STATUS Status;
  71. ACPI_FUNCTION_TRACE (EvInitializeEvents);
  72. /* If Hardware Reduced flag is set, there are no fixed events */
  73. if (AcpiGbl_ReducedHardware)
  74. {
  75. return_ACPI_STATUS (AE_OK);
  76. }
  77. /*
  78. * Initialize the Fixed and General Purpose Events. This is done prior to
  79. * enabling SCIs to prevent interrupts from occurring before the handlers
  80. * are installed.
  81. */
  82. Status = AcpiEvFixedEventInitialize ();
  83. if (ACPI_FAILURE (Status))
  84. {
  85. ACPI_EXCEPTION ((AE_INFO, Status,
  86. "Unable to initialize fixed events"));
  87. return_ACPI_STATUS (Status);
  88. }
  89. Status = AcpiEvGpeInitialize ();
  90. if (ACPI_FAILURE (Status))
  91. {
  92. ACPI_EXCEPTION ((AE_INFO, Status,
  93. "Unable to initialize general purpose events"));
  94. return_ACPI_STATUS (Status);
  95. }
  96. return_ACPI_STATUS (Status);
  97. }
  98. /*******************************************************************************
  99. *
  100. * FUNCTION: AcpiEvInstallXruptHandlers
  101. *
  102. * PARAMETERS: None
  103. *
  104. * RETURN: Status
  105. *
  106. * DESCRIPTION: Install interrupt handlers for the SCI and Global Lock
  107. *
  108. ******************************************************************************/
  109. ACPI_STATUS
  110. AcpiEvInstallXruptHandlers (
  111. void)
  112. {
  113. ACPI_STATUS Status;
  114. ACPI_FUNCTION_TRACE (EvInstallXruptHandlers);
  115. /* If Hardware Reduced flag is set, there is no ACPI h/w */
  116. if (AcpiGbl_ReducedHardware)
  117. {
  118. return_ACPI_STATUS (AE_OK);
  119. }
  120. /* Install the SCI handler */
  121. Status = AcpiEvInstallSciHandler ();
  122. if (ACPI_FAILURE (Status))
  123. {
  124. ACPI_EXCEPTION ((AE_INFO, Status,
  125. "Unable to install System Control Interrupt handler"));
  126. return_ACPI_STATUS (Status);
  127. }
  128. /* Install the handler for the Global Lock */
  129. Status = AcpiEvInitGlobalLockHandler ();
  130. if (ACPI_FAILURE (Status))
  131. {
  132. ACPI_EXCEPTION ((AE_INFO, Status,
  133. "Unable to initialize Global Lock handler"));
  134. return_ACPI_STATUS (Status);
  135. }
  136. AcpiGbl_EventsInitialized = TRUE;
  137. return_ACPI_STATUS (Status);
  138. }
  139. /*******************************************************************************
  140. *
  141. * FUNCTION: AcpiEvFixedEventInitialize
  142. *
  143. * PARAMETERS: None
  144. *
  145. * RETURN: Status
  146. *
  147. * DESCRIPTION: Install the fixed event handlers and disable all fixed events.
  148. *
  149. ******************************************************************************/
  150. static ACPI_STATUS
  151. AcpiEvFixedEventInitialize (
  152. void)
  153. {
  154. UINT32 i;
  155. ACPI_STATUS Status;
  156. /*
  157. * Initialize the structure that keeps track of fixed event handlers and
  158. * enable the fixed events.
  159. */
  160. for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++)
  161. {
  162. AcpiGbl_FixedEventHandlers[i].Handler = NULL;
  163. AcpiGbl_FixedEventHandlers[i].Context = NULL;
  164. /* Disable the fixed event */
  165. if (AcpiGbl_FixedEventInfo[i].EnableRegisterId != 0xFF)
  166. {
  167. Status = AcpiWriteBitRegister (
  168. AcpiGbl_FixedEventInfo[i].EnableRegisterId,
  169. ACPI_DISABLE_EVENT);
  170. if (ACPI_FAILURE (Status))
  171. {
  172. return (Status);
  173. }
  174. }
  175. }
  176. return (AE_OK);
  177. }
  178. /*******************************************************************************
  179. *
  180. * FUNCTION: AcpiEvFixedEventDetect
  181. *
  182. * PARAMETERS: None
  183. *
  184. * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
  185. *
  186. * DESCRIPTION: Checks the PM status register for active fixed events
  187. *
  188. ******************************************************************************/
  189. UINT32
  190. AcpiEvFixedEventDetect (
  191. void)
  192. {
  193. UINT32 IntStatus = ACPI_INTERRUPT_NOT_HANDLED;
  194. UINT32 FixedStatus;
  195. UINT32 FixedEnable;
  196. UINT32 i;
  197. ACPI_FUNCTION_NAME (EvFixedEventDetect);
  198. /*
  199. * Read the fixed feature status and enable registers, as all the cases
  200. * depend on their values. Ignore errors here.
  201. */
  202. (void) AcpiHwRegisterRead (ACPI_REGISTER_PM1_STATUS, &FixedStatus);
  203. (void) AcpiHwRegisterRead (ACPI_REGISTER_PM1_ENABLE, &FixedEnable);
  204. ACPI_DEBUG_PRINT ((ACPI_DB_INTERRUPTS,
  205. "Fixed Event Block: Enable %08X Status %08X\n",
  206. FixedEnable, FixedStatus));
  207. /*
  208. * Check for all possible Fixed Events and dispatch those that are active
  209. */
  210. for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++)
  211. {
  212. /* Both the status and enable bits must be on for this event */
  213. if ((FixedStatus & AcpiGbl_FixedEventInfo[i].StatusBitMask) &&
  214. (FixedEnable & AcpiGbl_FixedEventInfo[i].EnableBitMask))
  215. {
  216. /*
  217. * Found an active (signalled) event. Invoke global event
  218. * handler if present.
  219. */
  220. AcpiFixedEventCount[i]++;
  221. if (AcpiGbl_GlobalEventHandler)
  222. {
  223. AcpiGbl_GlobalEventHandler (ACPI_EVENT_TYPE_FIXED, NULL,
  224. i, AcpiGbl_GlobalEventHandlerContext);
  225. }
  226. IntStatus |= AcpiEvFixedEventDispatch (i);
  227. }
  228. }
  229. return (IntStatus);
  230. }
  231. /*******************************************************************************
  232. *
  233. * FUNCTION: AcpiEvFixedEventDispatch
  234. *
  235. * PARAMETERS: Event - Event type
  236. *
  237. * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
  238. *
  239. * DESCRIPTION: Clears the status bit for the requested event, calls the
  240. * handler that previously registered for the event.
  241. * NOTE: If there is no handler for the event, the event is
  242. * disabled to prevent further interrupts.
  243. *
  244. ******************************************************************************/
  245. static UINT32
  246. AcpiEvFixedEventDispatch (
  247. UINT32 Event)
  248. {
  249. ACPI_FUNCTION_ENTRY ();
  250. /* Clear the status bit */
  251. (void) AcpiWriteBitRegister (
  252. AcpiGbl_FixedEventInfo[Event].StatusRegisterId,
  253. ACPI_CLEAR_STATUS);
  254. /*
  255. * Make sure that a handler exists. If not, report an error
  256. * and disable the event to prevent further interrupts.
  257. */
  258. if (!AcpiGbl_FixedEventHandlers[Event].Handler)
  259. {
  260. (void) AcpiWriteBitRegister (
  261. AcpiGbl_FixedEventInfo[Event].EnableRegisterId,
  262. ACPI_DISABLE_EVENT);
  263. ACPI_ERROR ((AE_INFO,
  264. "No installed handler for fixed event - %s (%u), disabling",
  265. AcpiUtGetEventName (Event), Event));
  266. return (ACPI_INTERRUPT_NOT_HANDLED);
  267. }
  268. /* Invoke the Fixed Event handler */
  269. return ((AcpiGbl_FixedEventHandlers[Event].Handler)(
  270. AcpiGbl_FixedEventHandlers[Event].Context));
  271. }
  272. #endif /* !ACPI_REDUCED_HARDWARE */