salpal.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. /*++
  2. Copyright (c) 1999 Intel Corporation
  3. Module Name:
  4. salpal.c
  5. Abstract:
  6. Functions to make SAL and PAL proc calls
  7. Revision History
  8. --*/
  9. #include "lib.h"
  10. #include "palproc.h"
  11. #include "salproc.h"
  12. /*++
  13. Copyright (c) 1999 Intel Corporation
  14. Module Name:
  15. EfiRtLib.h
  16. Abstract:
  17. EFI Runtime library functions
  18. Revision History
  19. --*/
  20. #include "efi.h"
  21. #include "efilib.h"
  22. rArg
  23. MakeStaticPALCall (
  24. IN UINT64 PALPROCPtr,
  25. IN UINT64 Arg1,
  26. IN UINT64 Arg2,
  27. IN UINT64 Arg3,
  28. IN UINT64 Arg4
  29. );
  30. rArg
  31. MakeStackedPALCall (
  32. IN UINT64 PALPROCPtr,
  33. IN UINT64 Arg1,
  34. IN UINT64 Arg2,
  35. IN UINT64 Arg3,
  36. IN UINT64 Arg4
  37. );
  38. PLABEL SalProcPlabel;
  39. PLABEL PalProcPlabel;
  40. CALL_SAL_PROC GlobalSalProc;
  41. CALL_PAL_PROC GlobalPalProc;
  42. VOID
  43. LibInitSalAndPalProc (
  44. OUT PLABEL *SalPlabel,
  45. OUT UINT64 *PalEntry
  46. )
  47. {
  48. SAL_SYSTEM_TABLE_ASCENDING_ORDER *SalSystemTable;
  49. EFI_STATUS Status;
  50. GlobalSalProc = NULL;
  51. GlobalPalProc = NULL;
  52. Status = LibGetSystemConfigurationTable(&SalSystemTableGuid, (VOID **)&SalSystemTable);
  53. if (EFI_ERROR(Status)) {
  54. return;
  55. }
  56. //
  57. // BugBug: Add code to test checksum on the Sal System Table
  58. //
  59. if (SalSystemTable->Entry0.Type != 0) {
  60. return;
  61. }
  62. SalProcPlabel.ProcEntryPoint = SalSystemTable->Entry0.SalProcEntry;
  63. SalProcPlabel.GP = SalSystemTable->Entry0.GlobalDataPointer;
  64. GlobalSalProc = (CALL_SAL_PROC)&SalProcPlabel.ProcEntryPoint;
  65. //
  66. // Need to check the PAL spec to make sure I'm not responsible for
  67. // storing more state.
  68. // We are passing in a Plabel that should be ignorred by the PAL. Call
  69. // this way will cause use to retore our gp after the PAL returns.
  70. //
  71. PalProcPlabel.ProcEntryPoint = SalSystemTable->Entry0.PalProcEntry;
  72. PalProcPlabel.GP = SalSystemTable->Entry0.GlobalDataPointer;
  73. GlobalPalProc = (CALL_PAL_PROC)PalProcPlabel.ProcEntryPoint;
  74. *PalEntry = PalProcPlabel.ProcEntryPoint;
  75. *SalPlabel = SalProcPlabel;
  76. }
  77. EFI_STATUS
  78. LibGetSalIoPortMapping (
  79. OUT UINT64 *IoPortMapping
  80. )
  81. /*++
  82. Get the IO Port Map from the SAL System Table.
  83. DO NOT USE THIS TO DO YOU OWN IO's!!!!!!!!!!!!
  84. Only use this for getting info, or initing the built in EFI IO abstraction.
  85. Always use the EFI Device IO protoocl to access IO space.
  86. --*/
  87. {
  88. SAL_SYSTEM_TABLE_ASCENDING_ORDER *SalSystemTable;
  89. SAL_ST_MEMORY_DESCRIPTOR_ENTRY *SalMemDesc;
  90. EFI_STATUS Status;
  91. Status = LibGetSystemConfigurationTable(&SalSystemTableGuid, (VOID **)&SalSystemTable);
  92. if (EFI_ERROR(Status)) {
  93. return EFI_UNSUPPORTED;
  94. }
  95. //
  96. // BugBug: Add code to test checksum on the Sal System Table
  97. //
  98. if (SalSystemTable->Entry0.Type != 0) {
  99. return EFI_UNSUPPORTED;
  100. }
  101. //
  102. // The SalSystemTable pointer includes the Type 0 entry.
  103. // The SalMemDesc is Type 1 so it comes next.
  104. //
  105. SalMemDesc = (SAL_ST_MEMORY_DESCRIPTOR_ENTRY *)(SalSystemTable + 1);
  106. while (SalMemDesc->Type == SAL_ST_MEMORY_DESCRIPTOR) {
  107. if (SalMemDesc->MemoryType == SAL_IO_PORT_MAPPING) {
  108. *IoPortMapping = SalMemDesc->PhysicalMemoryAddress;
  109. return EFI_SUCCESS;
  110. }
  111. SalMemDesc++;
  112. }
  113. return EFI_UNSUPPORTED;
  114. }
  115. EFI_STATUS
  116. LibGetSalIpiBlock (
  117. OUT UINT64 *IpiBlock
  118. )
  119. /*++
  120. Get the IPI block from the SAL system table
  121. --*/
  122. {
  123. SAL_SYSTEM_TABLE_ASCENDING_ORDER *SalSystemTable;
  124. SAL_ST_MEMORY_DESCRIPTOR_ENTRY *SalMemDesc;
  125. EFI_STATUS Status;
  126. Status = LibGetSystemConfigurationTable(&SalSystemTableGuid, (VOID*)&SalSystemTable);
  127. if (EFI_ERROR(Status)) {
  128. return EFI_UNSUPPORTED;
  129. }
  130. //
  131. // BugBug: Add code to test checksum on the Sal System Table
  132. //
  133. if (SalSystemTable->Entry0.Type != 0) {
  134. return EFI_UNSUPPORTED;
  135. }
  136. //
  137. // The SalSystemTable pointer includes the Type 0 entry.
  138. // The SalMemDesc is Type 1 so it comes next.
  139. //
  140. SalMemDesc = (SAL_ST_MEMORY_DESCRIPTOR_ENTRY *)(SalSystemTable + 1);
  141. while (SalMemDesc->Type == SAL_ST_MEMORY_DESCRIPTOR) {
  142. if (SalMemDesc->MemoryType == SAL_SAPIC_IPI_BLOCK ) {
  143. *IpiBlock = SalMemDesc->PhysicalMemoryAddress;
  144. return EFI_SUCCESS;
  145. }
  146. SalMemDesc++;
  147. }
  148. return EFI_UNSUPPORTED;
  149. }
  150. EFI_STATUS
  151. LibGetSalWakeupVector (
  152. OUT UINT64 *WakeVector
  153. )
  154. /*++
  155. Get the wakeup vector from the SAL system table
  156. --*/
  157. {
  158. SAL_ST_AP_WAKEUP_DECRIPTOR *ApWakeUp;
  159. ApWakeUp = LibSearchSalSystemTable (SAL_ST_AP_WAKEUP);
  160. if (!ApWakeUp) {
  161. *WakeVector = -1;
  162. return EFI_UNSUPPORTED;
  163. }
  164. *WakeVector = ApWakeUp->ExternalInterruptVector;
  165. return EFI_SUCCESS;
  166. }
  167. VOID *
  168. LibSearchSalSystemTable (
  169. IN UINT8 EntryType
  170. )
  171. {
  172. EFI_STATUS Status;
  173. UINT8 *SalTableHack;
  174. SAL_SYSTEM_TABLE_ASCENDING_ORDER *SalSystemTable;
  175. UINT16 EntryCount;
  176. UINT16 Count;
  177. Status = LibGetSystemConfigurationTable(&SalSystemTableGuid, (VOID*)&SalSystemTable);
  178. if (EFI_ERROR(Status)) {
  179. return NULL;
  180. }
  181. EntryCount = SalSystemTable->Header.EntryCount;
  182. if (EntryCount == 0) {
  183. return NULL;
  184. }
  185. //
  186. // BugBug: Add code to test checksum on the Sal System Table
  187. //
  188. SalTableHack = (UINT8 *)&SalSystemTable->Entry0;
  189. for (Count = 0; Count < EntryCount ;Count++) {
  190. if (*SalTableHack == EntryType) {
  191. return (VOID *)SalTableHack;
  192. }
  193. switch (*SalTableHack) {
  194. case SAL_ST_ENTRY_POINT:
  195. SalTableHack += 48;
  196. break;
  197. case SAL_ST_MEMORY_DESCRIPTOR:
  198. SalTableHack += 32;
  199. break;
  200. case SAL_ST_PLATFORM_FEATURES:
  201. SalTableHack += 16;
  202. break;
  203. case SAL_ST_TR_USAGE:
  204. SalTableHack += 32;
  205. break;
  206. case SAL_ST_PTC:
  207. SalTableHack += 16;
  208. break;
  209. case SAL_ST_AP_WAKEUP:
  210. SalTableHack += 16;
  211. break;
  212. default:
  213. ASSERT(FALSE);
  214. break;
  215. }
  216. }
  217. return NULL;
  218. }
  219. VOID
  220. LibSalProc (
  221. IN UINT64 Arg1,
  222. IN UINT64 Arg2,
  223. IN UINT64 Arg3,
  224. IN UINT64 Arg4,
  225. IN UINT64 Arg5,
  226. IN UINT64 Arg6,
  227. IN UINT64 Arg7,
  228. IN UINT64 Arg8,
  229. OUT rArg *Results OPTIONAL
  230. )
  231. {
  232. rArg ReturnValue;
  233. ReturnValue.p0 = -3; // SAL status return completed with error
  234. if (GlobalSalProc) {
  235. ReturnValue = GlobalSalProc(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8);
  236. }
  237. if (Results) {
  238. CopyMem (Results, &ReturnValue, sizeof(rArg));
  239. }
  240. }
  241. VOID
  242. LibPalProc (
  243. IN UINT64 Arg1, // Pal Proc index
  244. IN UINT64 Arg2,
  245. IN UINT64 Arg3,
  246. IN UINT64 Arg4,
  247. OUT rArg *Results OPTIONAL
  248. )
  249. {
  250. rArg ReturnValue;
  251. ReturnValue.p0 = -3; // PAL status return completed with error
  252. //
  253. // check for valid PalProc entry point
  254. //
  255. if (!GlobalPalProc) {
  256. if (Results)
  257. CopyMem (Results, &ReturnValue, sizeof(rArg));
  258. return;
  259. }
  260. //
  261. // check if index falls within stacked or static register calling conventions
  262. // and call appropriate Pal stub call
  263. //
  264. if (((Arg1 >=255) && (Arg1 <=511)) ||
  265. ((Arg1 >=768) && (Arg1 <=1023))) {
  266. ReturnValue = MakeStackedPALCall((UINT64)GlobalPalProc,Arg1,Arg2,Arg3,Arg4);
  267. }
  268. else {
  269. ReturnValue = MakeStaticPALCall((UINT64)GlobalPalProc,Arg1,Arg2,Arg3,Arg4);
  270. }
  271. if (Results)
  272. CopyMem (Results, &ReturnValue, sizeof(rArg));
  273. return;
  274. }