Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

282 lines
5.9 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. acpienbl.c
  5. Abstract:
  6. This module contains functions to put an ACPI machine in ACPI mode.
  7. Author:
  8. Jason Clark (jasoncl)
  9. Environment:
  10. NT Kernel Model Driver only
  11. --*/
  12. #include "pch.h"
  13. VOID
  14. ACPIEnableEnterACPIMode (
  15. IN BOOLEAN ReEnable
  16. )
  17. /*++
  18. Routine Description:
  19. This routine is called to enter ACPI mode
  20. Arguments:
  21. BOOLEAN ReEnable : TRUE if ACPI is being reenabled after S4.
  22. Return Value:
  23. None
  24. --*/
  25. {
  26. ULONG i;
  27. BOOLEAN AffinitySet = FALSE;
  28. ASSERTMSG(
  29. "ACPIEnableEnterACPIMode: System already in ACPI mode!\n",
  30. !(READ_PM1_CONTROL() & PM1_SCI_EN)
  31. );
  32. ASSERTMSG(
  33. "ACPIEnableEnterACPIMode: System SMI_CMD port is zero\n",
  34. (AcpiInformation->SMI_CMD != 0)
  35. );
  36. //
  37. // Let the world know about this
  38. //
  39. ACPIPrint( (
  40. ACPI_PRINT_LOADING,
  41. "ACPIEnableEnterACPIMode: Enabling ACPI\n"
  42. ) );
  43. //
  44. // We have seen some machines that display random bughecks (due to ECX corruption) if
  45. // this code runs on any processor other than 0. So, make sure this code always runs on
  46. // processor 0. We don't need to do this in the ReEnable case because on resume from
  47. // hibernate, we are guaranteed to be on Processor 0.
  48. //
  49. if(!ReEnable){
  50. if(KeGetCurrentIrql() < DISPATCH_LEVEL) {
  51. KeSetSystemAffinityThread((KAFFINITY)1);
  52. AffinitySet = TRUE;
  53. }
  54. else{
  55. ASSERTMSG("ACPIEnableEnterACPIMode: IRQL >= DISPATCH_LEVEL \n", FALSE);
  56. }
  57. }
  58. //
  59. // Write the magic value to the port
  60. //
  61. WRITE_ACPI_REGISTER(SMI_CMD, 0,
  62. AcpiInformation->FixedACPIDescTable->acpi_on_value);
  63. //
  64. // Make sure that we see that PM1 is in fact enabled
  65. //
  66. for (i = 0; ; i++) {
  67. if ( (READ_PM1_CONTROL() & PM1_SCI_EN) ) {
  68. break;
  69. }
  70. if (i > 0xFFFFFF) {
  71. KeBugCheckEx(
  72. ACPI_BIOS_ERROR,
  73. ACPI_SYSTEM_CANNOT_START_ACPI,
  74. 6,
  75. 0,
  76. 0
  77. );
  78. }
  79. }
  80. //
  81. // Revert to original affinity
  82. //
  83. if(AffinitySet) {
  84. KeRevertToUserAffinityThread();
  85. }
  86. }
  87. VOID
  88. ACPIEnableInitializeACPI(
  89. IN BOOLEAN ReEnable
  90. )
  91. /*++
  92. Routine Description:
  93. A function to put an ACPI machine into ACPI mode. This function should be
  94. called with the SCI IRQ masked since we cannot set the interrupt enable
  95. mask until after enabling ACPI. The SCI should be unmasked by the caller
  96. when the call returns.
  97. General Sequence:
  98. Enable ACPI through the SMI command port
  99. Clear the PM1_STS register to put it in a known state
  100. Set the PM1_EN register mask
  101. Build the GP mask
  102. Clear the GP status register bits which belong to the GP mask
  103. Set the GP enable register bits according to the GP mask built above
  104. Set the PM1_CTRL register bits.
  105. Arguments:
  106. NONE
  107. Return Value:
  108. NONE
  109. --*/
  110. {
  111. USHORT contents;
  112. USHORT clearbits;
  113. //
  114. // Read PM1_CTRL, if SCI_EN is already set then this is an ACPI only machine
  115. // and we do not need to Enable ACPI
  116. //
  117. if ( !(READ_PM1_CONTROL() & PM1_SCI_EN) ) {
  118. AcpiInformation->ACPIOnly = FALSE;
  119. ACPIEnableEnterACPIMode(ReEnable);
  120. }
  121. //
  122. // Put the pm1 status registers into a known state. We will allow the Bus
  123. // Master bit to be enabled (if we have no choice) across this reset. I do
  124. // not pretend to understand this code
  125. //
  126. CLEAR_PM1_STATUS_REGISTER();
  127. contents = (USHORT)(READ_PM1_STATUS() & ~(PM1_BM_STS | PM1_RTC_STS));
  128. if (contents) {
  129. CLEAR_PM1_STATUS_REGISTER();
  130. contents = (USHORT)(READ_PM1_STATUS() & ~(PM1_BM_STS | PM1_RTC_STS));
  131. }
  132. ASSERTMSG(
  133. "ACPIEnableInitializeACPI: Cannot clear PM1 Status Register\n",
  134. (contents == 0)
  135. );
  136. //
  137. // We determined what the PM1 enable bits are when we processed the FADT.
  138. // We should now enable those bits
  139. //
  140. WRITE_PM1_ENABLE( AcpiInformation->pm1_en_bits );
  141. ASSERTMSG(
  142. "ACPIEnableInitializeACPI: Cannot write all PM1 Enable Bits\n",
  143. (READ_PM1_ENABLE() == AcpiInformation->pm1_en_bits)
  144. );
  145. //
  146. // This is called when we renable ACPI after having woken up from sleep
  147. // or hibernate
  148. //
  149. if (ReEnable) {
  150. //
  151. // Re-enable all possible GPE events
  152. //
  153. ACPIGpeClearRegisters();
  154. ACPIGpeEnableDisableEvents( TRUE );
  155. }
  156. //
  157. // Calculate the bits that we should clear. These are the
  158. // sleep enable bit and the bus master bit.
  159. //
  160. // [vincentg] - the original implementation cleared SLP_TYP as well -
  161. // this breaks C2/C3 on Intel PIIX4 chipsets. Updated to only clear
  162. // SLP_EN and BM_RLD.
  163. //
  164. clearbits = ((0x8 << SLP_TYP_POS) | PM1_BM_RLD);
  165. //
  166. // Read the PM1 control registery, clear the unwanted bits and then
  167. // write it back
  168. //
  169. contents = (READ_PM1_CONTROL() & ~clearbits);
  170. WRITE_PM1_CONTROL ( contents, TRUE, WRITE_REGISTER_A_AND_B );
  171. }
  172. VOID
  173. ACPIEnablePMInterruptOnly(
  174. VOID
  175. )
  176. /*++
  177. Routine Descrition:
  178. Enable interrupts in the ACPI controller
  179. Arguments:
  180. None
  181. Return Value:
  182. None
  183. --*/
  184. {
  185. WRITE_PM1_ENABLE(AcpiInformation->pm1_en_bits);
  186. }
  187. ULONG
  188. ACPIEnableQueryFixedEnables (
  189. VOID
  190. )
  191. /*++
  192. Routine Descrition:
  193. Returns the enable mask
  194. Arguments:
  195. None
  196. Return Value:
  197. None
  198. --*/
  199. {
  200. return AcpiInformation->pm1_en_bits;
  201. }