Ensure the validity of Ffs Sections when adding a new Sections to Ffs.
[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
24\r
25EFI_STATUS\r
26EFIAPI\r
27DxeSalLibConstruct (\r
28 IN EFI_HANDLE ImageHandle,\r
29 IN EFI_SYSTEM_TABLE *SystemTable\r
30 )\r
31{\r
32 EFI_STATUS Status;\r
33\r
34 Status = gBS->LocateProtocol (&gEfiExtendedSalBootServiceProtocolGuid, NULL, &mEsalBootService);\r
35 ASSERT_EFI_ERROR (Status);\r
36\r
37 return Status;\r
38}\r
39\r
40EFI_STATUS\r
56836fe9 41EFIAPI\r
878ddf1f 42RegisterEsalFunction (\r
43 IN UINT64 FunctionId,\r
44 IN EFI_GUID *ClassGuid,\r
45 IN SAL_INTERNAL_EXTENDED_SAL_PROC Function,\r
46 IN VOID *ModuleGlobal\r
47 )\r
48/*++\r
49\r
50Routine Description:\r
51\r
52 Register ESAL Class Function and it's asociated global.\r
53 This function is boot service only!\r
54\r
55Arguments:\r
56 FunctionId - ID of function to register\r
57 ClassGuid - GUID of function class \r
58 Function - Function to register under ClassGuid/FunctionId pair\r
59 ModuleGlobal - Module global for Function.\r
60\r
61Returns: \r
62 EFI_SUCCESS - If ClassGuid/FunctionId Function was registered.\r
63\r
64--*/\r
65{\r
66 return mEsalBootService->AddExtendedSalProc (\r
67 mEsalBootService,\r
68 ClassGuid,\r
69 FunctionId,\r
70 Function,\r
71 ModuleGlobal\r
72 );\r
73}\r
74\r
75EFI_STATUS\r
56836fe9 76EFIAPI\r
878ddf1f 77RegisterEsalClass (\r
78 IN EFI_GUID *ClassGuid,\r
79 IN VOID *ModuleGlobal,\r
80 ...\r
81 )\r
82/*++\r
83\r
84Routine Description:\r
85\r
86 Register ESAL Class and it's asociated global.\r
87 This function is boot service only!\r
88\r
89Arguments:\r
90 ClassGuid - GUID of function class \r
91 ModuleGlobal - Module global for Function.\r
92 ... - SAL_INTERNAL_EXTENDED_SAL_PROC and FunctionId pairs. NULL \r
93 indicates the end of the list.\r
94\r
95Returns: \r
96 EFI_SUCCESS - All members of ClassGuid registered\r
97\r
98--*/\r
99{\r
100 VA_LIST Args;\r
101 EFI_STATUS Status;\r
102 SAL_INTERNAL_EXTENDED_SAL_PROC Function;\r
103 UINT64 FunctionId;\r
104 EFI_HANDLE NewHandle;\r
105\r
106 VA_START (Args, ModuleGlobal);\r
107\r
108 Status = EFI_SUCCESS;\r
109 while (!EFI_ERROR (Status)) {\r
110 Function = (SAL_INTERNAL_EXTENDED_SAL_PROC) VA_ARG (Args, SAL_INTERNAL_EXTENDED_SAL_PROC);\r
111 if (Function == NULL) {\r
112 break;\r
113 }\r
114\r
115 FunctionId = VA_ARG (Args, UINT64);\r
116\r
117 Status = RegisterEsalFunction (FunctionId, ClassGuid, Function, ModuleGlobal);\r
118 }\r
119\r
120 if (EFI_ERROR (Status)) {\r
121 return Status;\r
122 }\r
123\r
124 NewHandle = NULL;\r
125 return gBS->InstallProtocolInterface (\r
126 &NewHandle,\r
127 ClassGuid,\r
128 EFI_NATIVE_INTERFACE,\r
129 NULL\r
130 );\r
131}\r
132\r
133SAL_RETURN_REGS\r
56836fe9 134EFIAPI\r
878ddf1f 135EfiCallEsalService (\r
136 IN EFI_GUID *ClassGuid,\r
137 IN UINT64 FunctionId,\r
138 IN UINT64 Arg2,\r
139 IN UINT64 Arg3,\r
140 IN UINT64 Arg4,\r
141 IN UINT64 Arg5,\r
142 IN UINT64 Arg6,\r
143 IN UINT64 Arg7,\r
144 IN UINT64 Arg8\r
145 )\r
146/*++\r
147\r
148Routine Description:\r
149\r
150 Call module that is not linked direclty to this module. This code is IP \r
151 relative and hides the binding issues of virtual or physical calling. The\r
152 function that gets dispatched has extra arguments that include the registered\r
153 module global and a boolean flag to indicate if the system is in virutal mode.\r
154\r
155Arguments:\r
156 ClassGuid - GUID of function\r
157 FunctionId - Function in ClassGuid to call\r
158 Arg2 - Argument 2 ClassGuid/FunctionId defined\r
159 Arg3 - Argument 3 ClassGuid/FunctionId defined\r
160 Arg4 - Argument 4 ClassGuid/FunctionId defined\r
161 Arg5 - Argument 5 ClassGuid/FunctionId defined\r
162 Arg6 - Argument 6 ClassGuid/FunctionId defined\r
163 Arg7 - Argument 7 ClassGuid/FunctionId defined\r
164 Arg8 - Argument 8 ClassGuid/FunctionId defined\r
165\r
166Returns: \r
167 Status of ClassGuid/FuncitonId\r
168\r
169--*/\r
170{\r
171 SAL_RETURN_REGS ReturnReg;\r
172 SAL_EXTENDED_SAL_PROC EsalProc;\r
173\r
174 ReturnReg = GetEsalEntryPoint ();\r
175 if (ReturnReg.Status != EFI_SAL_SUCCESS) {\r
176 return ReturnReg;\r
177 }\r
178\r
179 if (ReturnReg.r11 & PSR_IT_MASK) {\r
180 //\r
181 // Virtual mode plabel to entry point\r
182 //\r
183 EsalProc = (SAL_EXTENDED_SAL_PROC) ReturnReg.r10;\r
184 } else {\r
185 //\r
186 // Physical mode plabel to entry point\r
187 //\r
188 EsalProc = (SAL_EXTENDED_SAL_PROC) ReturnReg.r9;\r
189 }\r
190\r
191 return EsalProc (\r
192 ClassGuid,\r
193 FunctionId,\r
194 Arg2,\r
195 Arg3,\r
196 Arg4,\r
197 Arg5,\r
198 Arg6,\r
199 Arg7,\r
200 Arg8\r
201 );\r
202}\r