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.

237 lines
5.8 KiB

  1. /*** acpi.c - ACPI VXD to provide table access IOCTLs
  2. *
  3. * Author: Michael Tsang (MikeTs)
  4. * Created 10/08/97
  5. *
  6. * MODIFICATION HISTORY
  7. * 10/06/98 YanL Modified to be used in WUBIOS.VXD
  8. */
  9. #include "wubiosp.h"
  10. /*** Function prototypes
  11. */
  12. PRSDT CM_LOCAL FindRSDT(DWORD* pdwRSDTAddr);
  13. BYTE CM_LOCAL CheckSum(PBYTE pb, DWORD dwLen);
  14. #ifdef TRACING
  15. PSZ CM_LOCAL SigStr(DWORD dwSig);
  16. #endif
  17. #pragma CM_PAGEABLE_DATA
  18. #pragma CM_PAGEABLE_CODE
  19. /***LP FindRSDT - Find the RSDT
  20. *
  21. * ENTRY
  22. * None
  23. *
  24. * EXIT-SUCCESS
  25. * returns the RSDT pointer
  26. * EXIT-FAILURE
  27. * returns NULL
  28. */
  29. PRSDT CM_LOCAL FindRSDT(DWORD* pdwRSDTAddr)
  30. {
  31. TRACENAME("FINDRSDT")
  32. PRSDT pRSDT = NULL;
  33. PBYTE pbROM;
  34. ENTER(2, ("FindRSDT()\n"));
  35. if ((pbROM = (PBYTE)_MapPhysToLinear(RSDP_SEARCH_RANGE_BEGIN,
  36. RSDP_SEARCH_RANGE_LENGTH, 0)) !=
  37. (PBYTE)0xffffffff)
  38. {
  39. PBYTE pbROMEnd;
  40. DWORD dwRSDTAddr = 0;
  41. pbROMEnd = pbROM + RSDP_SEARCH_RANGE_LENGTH - RSDP_SEARCH_INTERVAL;
  42. while (pbROM != NULL)
  43. {
  44. if ((((PRSDP)pbROM)->Signature == RSDP_SIGNATURE) &&
  45. (CheckSum(pbROM, sizeof(RSDP)) == 0))
  46. {
  47. dwRSDTAddr = ((PRSDP)pbROM)->RsdtAddress;
  48. if (((pbROM = (PBYTE)_MapPhysToLinear(dwRSDTAddr,
  49. sizeof(DESCRIPTION_HEADER),
  50. 0)) ==
  51. (PBYTE)0xffffffff) ||
  52. (((PDESCRIPTION_HEADER)pbROM)->Signature != RSDT_SIGNATURE))
  53. {
  54. pbROM = NULL;
  55. }
  56. break;
  57. }
  58. else
  59. {
  60. pbROM += RSDP_SEARCH_INTERVAL;
  61. if (pbROM > pbROMEnd)
  62. {
  63. pbROM = NULL;
  64. }
  65. }
  66. }
  67. if (pbROM != NULL)
  68. {
  69. DWORD dwLen = ((PDESCRIPTION_HEADER)pbROM)->Length;
  70. pRSDT = (PRSDT)_MapPhysToLinear(dwRSDTAddr, dwLen, 0);
  71. if ((pRSDT == (PRSDT)0xffffffff) ||
  72. (CheckSum((PBYTE)pRSDT, dwLen) != 0))
  73. {
  74. pRSDT = NULL;
  75. }
  76. *pdwRSDTAddr = dwRSDTAddr;
  77. }
  78. }
  79. EXIT(2, ("FindRSDT=%x\n", pRSDT));
  80. return pRSDT;
  81. } //FindRSDT
  82. /***LP AcpiFindTable - Find an ACPI Table
  83. *
  84. * ENTRY
  85. * dwSig - signature of the table
  86. * pdwLen -> to hold length of table (can be NULL)
  87. *
  88. * EXIT-SUCCESS
  89. * returns physical address of table
  90. * EXIT-FAILURE
  91. * returns 0
  92. */
  93. DWORD CM_INTERNAL AcpiFindTable(DWORD dwSig, PDWORD pdwLen)
  94. {
  95. TRACENAME("AcpiFindTable")
  96. DWORD dwPhyAddr = 0;
  97. static PRSDT pRSDT = (PRSDT)0xffffffff;
  98. static DWORD dwRSDTAddr;
  99. ENTER(2, ("AcpiFindTable(Sig=%s,pdwLen=%x)\n", SigStr(dwSig), pdwLen));
  100. if (pRSDT == (PRSDT)0xffffffff)
  101. {
  102. pRSDT = FindRSDT(&dwRSDTAddr);
  103. }
  104. if (pRSDT != NULL)
  105. {
  106. PDESCRIPTION_HEADER pdh = NULL;
  107. if (dwSig == RSDT_SIGNATURE)
  108. {
  109. *pdwLen = ((PDESCRIPTION_HEADER)pRSDT)->Length;
  110. dwPhyAddr = dwRSDTAddr;
  111. }
  112. else if (dwSig == DSDT_SIGNATURE)
  113. {
  114. DWORD dwLen;
  115. PFADT pFADT;
  116. if (((dwPhyAddr = AcpiFindTable(FADT_SIGNATURE, &dwLen)) != 0) &&
  117. ((pFADT = (PFADT)_MapPhysToLinear(dwPhyAddr, dwLen, 0)) !=
  118. (PFADT)0xffffffff))
  119. {
  120. dwPhyAddr = pFADT->dsdt;
  121. if ((pdh = (PDESCRIPTION_HEADER)_MapPhysToLinear(
  122. dwPhyAddr,
  123. sizeof(DESCRIPTION_HEADER),
  124. 0)) ==
  125. (PDESCRIPTION_HEADER)0xffffffff)
  126. {
  127. dwPhyAddr = 0;
  128. }
  129. }
  130. else
  131. {
  132. dwPhyAddr = 0;
  133. }
  134. }
  135. else
  136. {
  137. int i, iNumTables = NumTableEntriesFromRSDTPointer(pRSDT);
  138. for (i = 0; i < iNumTables; ++i)
  139. {
  140. dwPhyAddr = pRSDT->Tables[i];
  141. if (((pdh = (PDESCRIPTION_HEADER)_MapPhysToLinear(
  142. dwPhyAddr,
  143. sizeof(DESCRIPTION_HEADER),
  144. 0))
  145. != (PDESCRIPTION_HEADER)0xffffffff))
  146. {
  147. if (pdh->Signature == dwSig && (CheckSum((PBYTE)pdh, pdh->Length) == 0) )
  148. {
  149. break;
  150. }
  151. }
  152. }
  153. if (i >= iNumTables)
  154. {
  155. dwPhyAddr = 0;
  156. }
  157. }
  158. if ((dwPhyAddr != 0) && (pdwLen != NULL))
  159. {
  160. *pdwLen = pdh->Length;
  161. }
  162. }
  163. EXIT(2, ("AcpiFindTable=%x (Len=%x)\n", dwPhyAddr, pdwLen? *pdwLen: 0));
  164. return dwPhyAddr;
  165. } //AcpiFindTable
  166. /***LP AcpiCopyROM - Copy ROM memory to buffer
  167. *
  168. * ENTRY
  169. * dwPhyAddr - physical address of ROM location
  170. * pbBuff -> buffer
  171. * dwLen - buffer length
  172. *
  173. * EXIT
  174. * None
  175. */
  176. VOID CM_INTERNAL AcpiCopyROM(DWORD dwPhyAddr, PBYTE pbBuff, DWORD dwLen)
  177. {
  178. TRACENAME("AcpiCopyROM")
  179. PBYTE pbROM;
  180. ENTER(2, ("AcpiCopyROM(PhyAddr=%x,pbBuff=%x,Len=%x)\n",
  181. dwPhyAddr, pbBuff, dwLen));
  182. if ((pbROM = (PBYTE)_MapPhysToLinear(dwPhyAddr, dwLen, 0)) !=
  183. (PBYTE)0xffffffff)
  184. {
  185. memcpy(pbBuff, pbROM, dwLen);
  186. }
  187. EXIT(2, ("AcpiCopyROM!\n"));
  188. } //AcpiCopyROM
  189. #ifdef TRACING
  190. /***LP SigStr - return string of DWORD signature
  191. *
  192. * ENTRY
  193. * dwSig - signature
  194. *
  195. * EXIT
  196. * returns signature string
  197. */
  198. PSZ CM_LOCAL SigStr(DWORD dwSig)
  199. {
  200. static char szSig[sizeof(DWORD) + 1] = {0};
  201. memcpy(szSig, &dwSig, sizeof(DWORD));
  202. return (PSZ)szSig;
  203. } //SigStr
  204. #endif