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.

220 lines
4.3 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. fakeacpi.c
  5. Abstract:
  6. Temporary support for Acpi tables in SIMICS simulator environment. This
  7. file should be removed when SIMICS provides Acpi tables.
  8. Author:
  9. Forrest Foltz (forrestf) 04-02-2001
  10. Environment:
  11. Kernel mode only.
  12. Revision History:
  13. --*/
  14. #if defined(_AMD64_SIMULATOR_)
  15. #include "halcmn.h"
  16. typedef struct _FAKE_ACPI_PORT_DESC {
  17. ACPI_REG_TYPE AcpiReg;
  18. USHORT PortSize;
  19. USHORT BlockSize;
  20. BOOLEAN Mask;
  21. ULONG Data;
  22. PUCHAR IoPortName;
  23. } FAKE_ACPI_PORT_DESC, *PFAKE_ACPI_PORT_DESC;
  24. #define FPE(p,r,s,b,d) { p, r, s, b, d, #p }
  25. FAKE_ACPI_PORT_DESC HalpFakePortDescriptions[] = {
  26. FPE( PM1a_ENABLE, 2, 2, FALSE, 1 ),
  27. FPE( PM1b_ENABLE, 2, 2, FALSE, 0 ),
  28. FPE( PM1a_STATUS, 2, 2, TRUE, 0 ),
  29. FPE( PM1b_STATUS, 2, 2, TRUE, 0 ),
  30. FPE( PM1a_CONTROL, 2, 2, FALSE, 0 ),
  31. FPE( PM1b_CONTROL, 2, 2, FALSE, 0 ),
  32. FPE( GP_STATUS, 1, 2, TRUE, 0 ),
  33. FPE( GP_ENABLE, 1, 2, FALSE, 0 ),
  34. FPE( SMI_CMD, 1, 1, FALSE, 0 )
  35. };
  36. #if DBG
  37. BOOLEAN HalpDebugFakeAcpi = FALSE;
  38. #else
  39. #define HalpDebugFakeAcpi FALSE
  40. #endif
  41. PFAKE_ACPI_PORT_DESC
  42. HalpFindFakeAcpiPortDesc (
  43. ACPI_REG_TYPE AcpiReg
  44. )
  45. /*++
  46. Routine Description:
  47. Locates the FAKE_ACPI_PORT_DESC structure appropriate to the
  48. supplied AcpiReg.
  49. Arguments:
  50. AcpiReg - Specifies which ACPI fixed register to find the structure for.
  51. Return Value:
  52. Returns a pointer to the appropriate FAKE_ACPI_PORT_DESC structure if
  53. it was found, or NULL otherwise.
  54. --*/
  55. {
  56. ULONG i;
  57. PFAKE_ACPI_PORT_DESC portDesc;
  58. for (i = 0; i < RTL_NUMBER_OF(HalpFakePortDescriptions); i += 1) {
  59. portDesc = &HalpFakePortDescriptions[i];
  60. if (portDesc->AcpiReg == AcpiReg) {
  61. return portDesc;
  62. }
  63. }
  64. DbgPrint("AMD64: Need to emulate ACPI I/O port 0x%x\n",AcpiReg);
  65. return NULL;
  66. }
  67. USHORT
  68. HalpReadAcpiRegister (
  69. IN ACPI_REG_TYPE AcpiReg,
  70. IN ULONG Register
  71. )
  72. /*++
  73. Routine Description:
  74. Read from the specified ACPI fixed register.
  75. Arguments:
  76. AcpiReg - Specifies which ACPI fixed register to read from.
  77. Register - Specifies which GP register to read from. Not used for PM1x
  78. registers.
  79. Return Value:
  80. Value of the specified ACPI fixed register.
  81. --*/
  82. {
  83. PFAKE_ACPI_PORT_DESC portDesc;
  84. PUCHAR source;
  85. USHORT retVal;
  86. portDesc = HalpFindFakeAcpiPortDesc(AcpiReg);
  87. if (portDesc == NULL) {
  88. return 0xffff;
  89. }
  90. ASSERT((Register + portDesc->PortSize) <= portDesc->BlockSize);
  91. source = (PUCHAR)&portDesc->Data + Register;
  92. retVal = 0;
  93. RtlCopyMemory((PUCHAR)&retVal, source, portDesc->PortSize);
  94. if (HalpDebugFakeAcpi != FALSE) {
  95. DbgPrint("HalpReadAcpiRegister(%s,0x%x) returns 0x%x\n",
  96. portDesc->IoPortName,
  97. Register,
  98. retVal);
  99. }
  100. return retVal;
  101. }
  102. VOID
  103. HalpWriteAcpiRegister (
  104. IN ACPI_REG_TYPE AcpiReg,
  105. IN ULONG Register,
  106. IN USHORT Value
  107. )
  108. /*++
  109. Routine Description:
  110. Write to the specified ACPI fixed register.
  111. Arguments:
  112. AcpiReg - Specifies which ACPI fixed register to write to.
  113. Register - Specifies which GP register to write to. Not used for PM1x
  114. registers.
  115. Value - Data to write.
  116. Return Value:
  117. None.
  118. --*/
  119. {
  120. PFAKE_ACPI_PORT_DESC portDesc;
  121. PUCHAR source;
  122. PUCHAR destination;
  123. ULONG i;
  124. portDesc = HalpFindFakeAcpiPortDesc(AcpiReg);
  125. if (portDesc == NULL) {
  126. return;
  127. }
  128. ASSERT((Register + portDesc->PortSize) <= portDesc->BlockSize);
  129. source = (PUCHAR)&Value;
  130. destination = (PUCHAR)&portDesc->Data + Register;
  131. if (HalpDebugFakeAcpi != FALSE) {
  132. DbgPrint("HalpWriteAcpiRegister(%s,0x%x) with value 0x%x\n",
  133. portDesc->IoPortName,
  134. Register,
  135. Value);
  136. }
  137. for (i = 0; i < portDesc->PortSize; i++) {
  138. if (portDesc->Mask != FALSE) {
  139. *destination &= ~(*source);
  140. } else {
  141. *destination = *source;
  142. }
  143. source += 1;
  144. destination += 1;
  145. }
  146. if (AcpiReg == SMI_CMD && Register == 0) {
  147. //
  148. // Assume that we have just turned ACPI on.
  149. //
  150. HalpFindFakeAcpiPortDesc(PM1a_CONTROL)->Data |= 1;
  151. }
  152. }
  153. #endif // _AMD64_SIMULATOR_