Source code of Windows XP (NT5)
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.

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