]> git.proxmox.com Git - mirror_edk2.git/blame - EdkModulePkg/Library/EdkDxeSalLib/Ipf/EsalServiceLib.c
Move SAL "initialization/virtual address change notification" from EdkUefiRuntimeLib...
[mirror_edk2.git] / EdkModulePkg / Library / EdkDxeSalLib / Ipf / EsalServiceLib.c
CommitLineData
878ddf1f 1/*++\r
2\r
3Copyright (c) 2006, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12Module Name:\r
13\r
14 EsalServiceLib.c\r
15\r
16Abstract:\r
17\r
18--*/\r
19\r
20#include <Ipf/IpfDefines.h>\r
21\r
22\r
23STATIC EXTENDED_SAL_BOOT_SERVICE_PROTOCOL *mEsalBootService;\r
c25aaa00 24STATIC EFI_PLABEL mPlabel;\r
878ddf1f 25\r
26EFI_STATUS\r
27EFIAPI\r
28DxeSalLibConstruct (\r
29 IN EFI_HANDLE ImageHandle,\r
30 IN EFI_SYSTEM_TABLE *SystemTable\r
31 )\r
32{\r
c25aaa00 33 EFI_PLABEL *Plabel;\r
34 EFI_STATUS Status;\r
878ddf1f 35\r
c25aaa00 36 //\r
37 // The protocol contains a function pointer, which is an indirect procedure call.\r
38 // An indirect procedure call goes through a plabel, and pointer to a function is\r
39 // a pointer to a plabel. To implement indirect procedure calls that can work in\r
40 // both physical and virtual mode, two plabels are required (one physical and one\r
41 // virtual). So lets grap the physical PLABEL for the EsalEntryPoint and store it\r
42 // away. We cache it in a module global, so we can register the vitrual version.\r
43 //\r
44 Status = gBS->LocateProtocol (&gEfiExtendedSalBootServiceProtocolGuid, NULL, &mEsalBootService);\r
878ddf1f 45 ASSERT_EFI_ERROR (Status);\r
46\r
c25aaa00 47 Plabel = (EFI_PLABEL *) (UINTN) mEsalBootService->ExtendedSalProc;\r
48\r
49 mPlabel.EntryPoint = Plabel->EntryPoint;\r
50 mPlabel.GP = Plabel->GP;\r
51 SetEsalPhysicalEntryPoint (mPlabel.EntryPoint, mPlabel.GP);\r
52\r
878ddf1f 53 return Status;\r
54}\r
55\r
c25aaa00 56VOID\r
57EFIAPI\r
58DxeSalVirtualNotifyEvent (\r
59 IN EFI_EVENT Event,\r
60 IN VOID *Context\r
61 )\r
62/*++\r
63\r
64Routine Description:\r
65\r
66 Fixup virtual address pointer of label.\r
67\r
68Arguments:\r
69\r
70 Event - The Event that is being processed\r
71 \r
72 Context - Event Context\r
73\r
74Returns: \r
75\r
76 None\r
77\r
78--*/\r
79{\r
80 EfiConvertPointer (0x0, (VOID **) &mPlabel.EntryPoint);\r
81 EfiConvertPointer (EFI_IPF_GP_POINTER, (VOID **) &mPlabel.GP);\r
82\r
83 SetEsalVirtualEntryPoint (mPlabel.EntryPoint, mPlabel.GP);\r
84}\r
85\r
878ddf1f 86EFI_STATUS\r
56836fe9 87EFIAPI\r
878ddf1f 88RegisterEsalFunction (\r
89 IN UINT64 FunctionId,\r
90 IN EFI_GUID *ClassGuid,\r
91 IN SAL_INTERNAL_EXTENDED_SAL_PROC Function,\r
92 IN VOID *ModuleGlobal\r
93 )\r
94/*++\r
95\r
96Routine Description:\r
97\r
98 Register ESAL Class Function and it's asociated global.\r
99 This function is boot service only!\r
100\r
101Arguments:\r
102 FunctionId - ID of function to register\r
103 ClassGuid - GUID of function class \r
104 Function - Function to register under ClassGuid/FunctionId pair\r
105 ModuleGlobal - Module global for Function.\r
106\r
107Returns: \r
108 EFI_SUCCESS - If ClassGuid/FunctionId Function was registered.\r
109\r
110--*/\r
111{\r
112 return mEsalBootService->AddExtendedSalProc (\r
113 mEsalBootService,\r
114 ClassGuid,\r
115 FunctionId,\r
116 Function,\r
117 ModuleGlobal\r
118 );\r
119}\r
120\r
121EFI_STATUS\r
56836fe9 122EFIAPI\r
878ddf1f 123RegisterEsalClass (\r
124 IN EFI_GUID *ClassGuid,\r
125 IN VOID *ModuleGlobal,\r
126 ...\r
127 )\r
128/*++\r
129\r
130Routine Description:\r
131\r
132 Register ESAL Class and it's asociated global.\r
133 This function is boot service only!\r
134\r
135Arguments:\r
136 ClassGuid - GUID of function class \r
137 ModuleGlobal - Module global for Function.\r
138 ... - SAL_INTERNAL_EXTENDED_SAL_PROC and FunctionId pairs. NULL \r
139 indicates the end of the list.\r
140\r
141Returns: \r
142 EFI_SUCCESS - All members of ClassGuid registered\r
143\r
144--*/\r
145{\r
146 VA_LIST Args;\r
147 EFI_STATUS Status;\r
148 SAL_INTERNAL_EXTENDED_SAL_PROC Function;\r
149 UINT64 FunctionId;\r
150 EFI_HANDLE NewHandle;\r
151\r
152 VA_START (Args, ModuleGlobal);\r
153\r
154 Status = EFI_SUCCESS;\r
155 while (!EFI_ERROR (Status)) {\r
156 Function = (SAL_INTERNAL_EXTENDED_SAL_PROC) VA_ARG (Args, SAL_INTERNAL_EXTENDED_SAL_PROC);\r
157 if (Function == NULL) {\r
158 break;\r
159 }\r
160\r
161 FunctionId = VA_ARG (Args, UINT64);\r
162\r
163 Status = RegisterEsalFunction (FunctionId, ClassGuid, Function, ModuleGlobal);\r
164 }\r
165\r
166 if (EFI_ERROR (Status)) {\r
167 return Status;\r
168 }\r
169\r
170 NewHandle = NULL;\r
171 return gBS->InstallProtocolInterface (\r
172 &NewHandle,\r
173 ClassGuid,\r
174 EFI_NATIVE_INTERFACE,\r
175 NULL\r
176 );\r
177}\r
178\r
179SAL_RETURN_REGS\r
56836fe9 180EFIAPI\r
878ddf1f 181EfiCallEsalService (\r
182 IN EFI_GUID *ClassGuid,\r
183 IN UINT64 FunctionId,\r
184 IN UINT64 Arg2,\r
185 IN UINT64 Arg3,\r
186 IN UINT64 Arg4,\r
187 IN UINT64 Arg5,\r
188 IN UINT64 Arg6,\r
189 IN UINT64 Arg7,\r
190 IN UINT64 Arg8\r
191 )\r
192/*++\r
193\r
194Routine Description:\r
195\r
196 Call module that is not linked direclty to this module. This code is IP \r
197 relative and hides the binding issues of virtual or physical calling. The\r
198 function that gets dispatched has extra arguments that include the registered\r
199 module global and a boolean flag to indicate if the system is in virutal mode.\r
200\r
201Arguments:\r
202 ClassGuid - GUID of function\r
203 FunctionId - Function in ClassGuid to call\r
204 Arg2 - Argument 2 ClassGuid/FunctionId defined\r
205 Arg3 - Argument 3 ClassGuid/FunctionId defined\r
206 Arg4 - Argument 4 ClassGuid/FunctionId defined\r
207 Arg5 - Argument 5 ClassGuid/FunctionId defined\r
208 Arg6 - Argument 6 ClassGuid/FunctionId defined\r
209 Arg7 - Argument 7 ClassGuid/FunctionId defined\r
210 Arg8 - Argument 8 ClassGuid/FunctionId defined\r
211\r
212Returns: \r
213 Status of ClassGuid/FuncitonId\r
214\r
215--*/\r
216{\r
217 SAL_RETURN_REGS ReturnReg;\r
218 SAL_EXTENDED_SAL_PROC EsalProc;\r
219\r
220 ReturnReg = GetEsalEntryPoint ();\r
221 if (ReturnReg.Status != EFI_SAL_SUCCESS) {\r
222 return ReturnReg;\r
223 }\r
224\r
225 if (ReturnReg.r11 & PSR_IT_MASK) {\r
226 //\r
227 // Virtual mode plabel to entry point\r
228 //\r
229 EsalProc = (SAL_EXTENDED_SAL_PROC) ReturnReg.r10;\r
230 } else {\r
231 //\r
232 // Physical mode plabel to entry point\r
233 //\r
234 EsalProc = (SAL_EXTENDED_SAL_PROC) ReturnReg.r9;\r
235 }\r
236\r
237 return EsalProc (\r
238 ClassGuid,\r
239 FunctionId,\r
240 Arg2,\r
241 Arg3,\r
242 Arg4,\r
243 Arg5,\r
244 Arg6,\r
245 Arg7,\r
246 Arg8\r
247 );\r
248}\r