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.

341 lines
8.3 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. GbAcpi.c
  5. Abstract:
  6. Temporary support for Acpi tables in Gambit simulator environment. This
  7. file should be removed when Gambit/Vpc provides Acpi tables.
  8. The Acpi tables are created and a pointer to the RSDT is put into the
  9. Loader block.
  10. Author:
  11. Todd Kjos (HP) (v-tkjos) 1-Jun-1998
  12. Environment:
  13. Kernel mode only.
  14. Revision History:
  15. --*/
  16. #include "halp.h"
  17. #include "acpitabl.h"
  18. #include "xxacpi.h"
  19. BOOLEAN
  20. HalpFakeAcpiRegisters(
  21. VOID
  22. );
  23. #define PMIO 0x8000
  24. #define PM1a_EVT_BLK (PMIO+0x0)
  25. #define PM1a_STS PM1a_EVT_BLK
  26. #define PM1a_EN (PM1a_STS+2)
  27. #define PM1a_CNT_BLK (PMIO+0x4)
  28. #define PM1a_CNTa PM1a_CNT_BLK
  29. #define PM_TMR (PMIO+0x8)
  30. #define GP0 (PMIO+0xc)
  31. #define GP0_STS_0 GP0
  32. #define GP0_STS_1 (GP0+1)
  33. #define GP0_EN_0 (GP0+2)
  34. #define GP0_EN_1 (GP0+3)
  35. PCHAR HalpFakeAcpiRegisterFadtIds[][2] =
  36. {
  37. {"INTEL", "LIONEMU"},
  38. {"INTEL", "SR460AC"},
  39. {"INTEL", "AL460GX"},
  40. {NULL, NULL}
  41. };
  42. #ifdef ALLOC_PRAGMA
  43. #pragma alloc_text(PAGE, HalpFakeAcpiRegisters)
  44. #endif
  45. USHORT AcpiRegPM1a_STS = 0;
  46. USHORT AcpiRegPM1a_EN = 0;
  47. USHORT AcpiRegPM1_CNTa = 1; // SCI_EN
  48. ULONG AcpiRegPM_TMR = 0;
  49. UCHAR AcpiRegGP0_STS_0 = 0;
  50. UCHAR AcpiRegGP0_STS_1 = 0;
  51. UCHAR AcpiRegGP0_EN_0 = 0;
  52. UCHAR AcpiRegGP0_EN_1 = 0;
  53. UCHAR AcpiRegNeedToImplement = 0;
  54. BOOLEAN GambitAcpiDebug = FALSE;
  55. //#define TKPRINT(X,Y) if (GambitAcpiDebug) HalDebugPrint(( HAL_INFO, "%s of %s (%#x)\n",X,# Y,Y ))
  56. #define TKPRINT(x, y)
  57. BOOLEAN
  58. GbAcpiReadFakePort(
  59. UINT_PTR Port,
  60. PVOID Data,
  61. ULONG Length
  62. )
  63. {
  64. if (Port < PMIO || Port > PMIO+0xfff) return(FALSE);
  65. switch (Port) {
  66. case PM1a_STS:
  67. ASSERT(Length == 2);
  68. *(USHORT UNALIGNED *)Data = AcpiRegPM1a_STS;
  69. TKPRINT("Read",AcpiRegPM1a_STS);
  70. return TRUE;
  71. case PM1a_EN:
  72. ASSERT(Length == 2);
  73. *(USHORT UNALIGNED *)Data = AcpiRegPM1a_EN;
  74. TKPRINT("Read",AcpiRegPM1a_EN);
  75. return TRUE;
  76. case PM1a_CNTa:
  77. ASSERT(Length == 2);
  78. *(USHORT UNALIGNED *)Data = AcpiRegPM1_CNTa;
  79. TKPRINT("Read",AcpiRegPM1_CNTa);
  80. return TRUE;
  81. case PM_TMR:
  82. ASSERT(Length == 4);
  83. *(ULONG UNALIGNED *)Data = AcpiRegPM_TMR;
  84. TKPRINT("Read",AcpiRegPM_TMR);
  85. return TRUE;
  86. case GP0_STS_0:
  87. ASSERT(Length == 1);
  88. *(UCHAR UNALIGNED *)Data = AcpiRegGP0_STS_0;
  89. TKPRINT("Read",AcpiRegGP0_STS_0);
  90. return TRUE;
  91. case GP0_STS_1:
  92. ASSERT(Length == 1);
  93. *(UCHAR UNALIGNED *)Data = AcpiRegGP0_STS_1;
  94. TKPRINT("Read",AcpiRegGP0_STS_1);
  95. return TRUE;
  96. case GP0_EN_0:
  97. ASSERT(Length == 1);
  98. *(UCHAR UNALIGNED *)Data = AcpiRegGP0_EN_0;
  99. TKPRINT("Read",AcpiRegGP0_EN_0);
  100. return TRUE;
  101. case GP0_EN_1:
  102. ASSERT(Length == 1);
  103. *(UCHAR UNALIGNED *)Data = AcpiRegGP0_EN_1;
  104. TKPRINT("Read",AcpiRegGP0_EN_1);
  105. return TRUE;
  106. case 0x802b:
  107. ASSERT(Length == 1);
  108. *(UCHAR UNALIGNED *)Data = AcpiRegNeedToImplement;
  109. TKPRINT("Read",AcpiRegNeedToImplement);
  110. return TRUE;
  111. default:
  112. ;
  113. // HalDebugPrint(( HAL_ERROR, "HAL: AcpiSimulation - Unknown Acpi register: %#Ix\n", Port ));
  114. // ASSERT(0);
  115. }
  116. return(FALSE);
  117. }
  118. BOOLEAN
  119. GbAcpiWriteFakePort(
  120. UINT_PTR Port,
  121. PVOID Value,
  122. ULONG Length
  123. )
  124. {
  125. if (Port < PMIO || Port > PMIO+0xfff) return(FALSE);
  126. switch (Port) {
  127. case PM1a_STS:
  128. ASSERT(Length == 2);
  129. AcpiRegPM1a_STS &= ~(*(USHORT UNALIGNED *)Value);
  130. TKPRINT("Write",AcpiRegPM1a_STS);
  131. return TRUE;
  132. case PM1a_EN:
  133. ASSERT(Length == 2);
  134. AcpiRegPM1a_EN = *((USHORT UNALIGNED *)Value);
  135. TKPRINT("Write",AcpiRegPM1a_EN);
  136. return TRUE;
  137. case PM1a_CNTa:
  138. ASSERT(Length == 2);
  139. AcpiRegPM1_CNTa = *((USHORT UNALIGNED *)Value);
  140. TKPRINT("Write",AcpiRegPM1_CNTa);
  141. return TRUE;
  142. case PM_TMR:
  143. ASSERT(Length == 4);
  144. AcpiRegPM_TMR = *((ULONG UNALIGNED *)Value);
  145. TKPRINT("Write",AcpiRegPM_TMR);
  146. return TRUE;
  147. case GP0_STS_0:
  148. ASSERT(Length == 1);
  149. AcpiRegGP0_STS_0 &= ~(*(UCHAR UNALIGNED *)Value);
  150. TKPRINT("Write",AcpiRegGP0_STS_0);
  151. return TRUE;
  152. case GP0_STS_1:
  153. ASSERT(Length == 1);
  154. AcpiRegGP0_STS_1 &= ~(*(UCHAR UNALIGNED *)Value);
  155. TKPRINT("Write",AcpiRegGP0_STS_1);
  156. return TRUE;
  157. case GP0_EN_0:
  158. ASSERT(Length == 1);
  159. AcpiRegGP0_EN_0 = *((UCHAR UNALIGNED *)Value);
  160. TKPRINT("Write",AcpiRegGP0_EN_0);
  161. return TRUE;
  162. case GP0_EN_1:
  163. ASSERT(Length == 1);
  164. AcpiRegGP0_EN_1 = *((UCHAR UNALIGNED *)Value);
  165. TKPRINT("Write",AcpiRegGP0_EN_1);
  166. return TRUE;
  167. default:
  168. ;
  169. // HalDebugPrint(( HAL_ERROR, "HAL: AcpiSimulation - Unknown Acpi register: %#Ix\n",Port ));
  170. // ASSERT(0);
  171. }
  172. return(FALSE);
  173. }
  174. USHORT
  175. HalpReadAcpiRegister(
  176. IN ACPI_REG_TYPE AcpiReg,
  177. IN ULONG Register
  178. )
  179. {
  180. USHORT value;
  181. BOOLEAN retVal = FALSE;
  182. switch (AcpiReg) {
  183. case PM1a_ENABLE:
  184. retVal = GbAcpiReadFakePort(PM1a_EN, &value, 2);
  185. break;
  186. case PM1a_STATUS:
  187. retVal = GbAcpiReadFakePort(PM1a_STS, &value, 2);
  188. break;
  189. case PM1a_CONTROL:
  190. retVal = GbAcpiReadFakePort(PM1a_CNTa, &value, 2);
  191. break;
  192. case GP_STATUS:
  193. retVal = GbAcpiReadFakePort(GP0_STS_0, &value, 1);
  194. if (!retVal) break;
  195. retVal = GbAcpiReadFakePort(GP0_STS_1, ((PUCHAR)&value) + 1, 1);
  196. break;
  197. case GP_ENABLE:
  198. retVal = GbAcpiReadFakePort(GP0_EN_0, &value, 1);
  199. if (!retVal) break;
  200. retVal = GbAcpiReadFakePort(GP0_EN_1, ((PUCHAR)&value) + 1, 1);
  201. break;
  202. }
  203. if (retVal) {
  204. return value;
  205. } else {
  206. return 0xffff;
  207. }
  208. }
  209. VOID
  210. HalpWriteAcpiRegister(
  211. IN ACPI_REG_TYPE AcpiReg,
  212. IN ULONG Register,
  213. IN USHORT Value
  214. )
  215. {
  216. BOOLEAN retVal = FALSE;
  217. switch (AcpiReg) {
  218. case PM1a_ENABLE:
  219. retVal = GbAcpiWriteFakePort(PM1a_EN, &Value, 2);
  220. break;
  221. case PM1a_STATUS:
  222. retVal = GbAcpiWriteFakePort(PM1a_STS, &Value, 2);
  223. break;
  224. case PM1a_CONTROL:
  225. retVal = GbAcpiWriteFakePort(PM1a_CNTa, &Value, 2);
  226. break;
  227. case GP_STATUS:
  228. retVal = GbAcpiWriteFakePort(GP0_STS_0, &Value, 1);
  229. if (!retVal) break;
  230. retVal = GbAcpiWriteFakePort(GP0_STS_1, ((PUCHAR)&Value) + 1, 1);
  231. break;
  232. case GP_ENABLE:
  233. switch (Register) {
  234. case 0:
  235. retVal = GbAcpiWriteFakePort(GP0_EN_0, &Value, 1);
  236. break;
  237. case 1:
  238. retVal = GbAcpiWriteFakePort(GP0_EN_1, ((PUCHAR)&Value) + 1, 1);
  239. break;
  240. }
  241. }
  242. }
  243. BOOLEAN
  244. HalpFakeAcpiRegisters(
  245. VOID
  246. )
  247. {
  248. ULONG i = 0;
  249. PAGED_CODE();
  250. while (HalpFakeAcpiRegisterFadtIds[i][0] != NULL) {
  251. //DbgPrint("Comparing [%s]-[%s] to [%s]-[%s]\n",
  252. // HalpFixedAcpiDescTable.Header.OEMID,
  253. // HalpFixedAcpiDescTable.Header.OEMTableID,
  254. // HalpFakeAcpiRegisterFadtIds[i][0],
  255. // HalpFakeAcpiRegisterFadtIds[i][1]);
  256. if ((!strncmp(HalpFixedAcpiDescTable.Header.OEMID,
  257. HalpFakeAcpiRegisterFadtIds[i][0],
  258. 6)) &&
  259. (!strncmp(HalpFixedAcpiDescTable.Header.OEMTableID,
  260. HalpFakeAcpiRegisterFadtIds[i][1],
  261. 8))) {
  262. //
  263. // This machine matches one of the entries
  264. // in the table that tells us that we should fake
  265. // our ACPI registers.
  266. //
  267. //DbgPrint("Found a match\n");
  268. //
  269. // Make sure the oem revision is less than 3.
  270. // Then we need to fake the acpi registers
  271. //
  272. if(HalpFixedAcpiDescTable.Header.OEMRevision < 3)
  273. return TRUE;
  274. }
  275. i++;
  276. }
  277. return FALSE;
  278. }