]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Library/EdkDxeSalLib/Ipf/EsalServiceLib.c
83b6aa2c4cfb106e4659c386471069abafd1c603
[mirror_edk2.git] / EdkModulePkg / Library / EdkDxeSalLib / Ipf / EsalServiceLib.c
1 /*++
2
3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 EsalServiceLib.c
15
16 Abstract:
17
18 --*/
19
20 #include <Ipf/IpfDefines.h>
21
22
23 STATIC EXTENDED_SAL_BOOT_SERVICE_PROTOCOL *mEsalBootService;
24
25 EFI_STATUS
26 EFIAPI
27 DxeSalLibConstruct (
28 IN EFI_HANDLE ImageHandle,
29 IN EFI_SYSTEM_TABLE *SystemTable
30 )
31 {
32 EFI_STATUS Status;
33
34 Status = gBS->LocateProtocol (&gEfiExtendedSalBootServiceProtocolGuid, NULL, &mEsalBootService);
35 ASSERT_EFI_ERROR (Status);
36
37 return Status;
38 }
39
40 EFI_STATUS
41 EFIAPI
42 RegisterEsalFunction (
43 IN UINT64 FunctionId,
44 IN EFI_GUID *ClassGuid,
45 IN SAL_INTERNAL_EXTENDED_SAL_PROC Function,
46 IN VOID *ModuleGlobal
47 )
48 /*++
49
50 Routine Description:
51
52 Register ESAL Class Function and it's asociated global.
53 This function is boot service only!
54
55 Arguments:
56 FunctionId - ID of function to register
57 ClassGuid - GUID of function class
58 Function - Function to register under ClassGuid/FunctionId pair
59 ModuleGlobal - Module global for Function.
60
61 Returns:
62 EFI_SUCCESS - If ClassGuid/FunctionId Function was registered.
63
64 --*/
65 {
66 return mEsalBootService->AddExtendedSalProc (
67 mEsalBootService,
68 ClassGuid,
69 FunctionId,
70 Function,
71 ModuleGlobal
72 );
73 }
74
75 EFI_STATUS
76 EFIAPI
77 RegisterEsalClass (
78 IN EFI_GUID *ClassGuid,
79 IN VOID *ModuleGlobal,
80 ...
81 )
82 /*++
83
84 Routine Description:
85
86 Register ESAL Class and it's asociated global.
87 This function is boot service only!
88
89 Arguments:
90 ClassGuid - GUID of function class
91 ModuleGlobal - Module global for Function.
92 ... - SAL_INTERNAL_EXTENDED_SAL_PROC and FunctionId pairs. NULL
93 indicates the end of the list.
94
95 Returns:
96 EFI_SUCCESS - All members of ClassGuid registered
97
98 --*/
99 {
100 VA_LIST Args;
101 EFI_STATUS Status;
102 SAL_INTERNAL_EXTENDED_SAL_PROC Function;
103 UINT64 FunctionId;
104 EFI_HANDLE NewHandle;
105
106 VA_START (Args, ModuleGlobal);
107
108 Status = EFI_SUCCESS;
109 while (!EFI_ERROR (Status)) {
110 Function = (SAL_INTERNAL_EXTENDED_SAL_PROC) VA_ARG (Args, SAL_INTERNAL_EXTENDED_SAL_PROC);
111 if (Function == NULL) {
112 break;
113 }
114
115 FunctionId = VA_ARG (Args, UINT64);
116
117 Status = RegisterEsalFunction (FunctionId, ClassGuid, Function, ModuleGlobal);
118 }
119
120 if (EFI_ERROR (Status)) {
121 return Status;
122 }
123
124 NewHandle = NULL;
125 return gBS->InstallProtocolInterface (
126 &NewHandle,
127 ClassGuid,
128 EFI_NATIVE_INTERFACE,
129 NULL
130 );
131 }
132
133 SAL_RETURN_REGS
134 EFIAPI
135 EfiCallEsalService (
136 IN EFI_GUID *ClassGuid,
137 IN UINT64 FunctionId,
138 IN UINT64 Arg2,
139 IN UINT64 Arg3,
140 IN UINT64 Arg4,
141 IN UINT64 Arg5,
142 IN UINT64 Arg6,
143 IN UINT64 Arg7,
144 IN UINT64 Arg8
145 )
146 /*++
147
148 Routine Description:
149
150 Call module that is not linked direclty to this module. This code is IP
151 relative and hides the binding issues of virtual or physical calling. The
152 function that gets dispatched has extra arguments that include the registered
153 module global and a boolean flag to indicate if the system is in virutal mode.
154
155 Arguments:
156 ClassGuid - GUID of function
157 FunctionId - Function in ClassGuid to call
158 Arg2 - Argument 2 ClassGuid/FunctionId defined
159 Arg3 - Argument 3 ClassGuid/FunctionId defined
160 Arg4 - Argument 4 ClassGuid/FunctionId defined
161 Arg5 - Argument 5 ClassGuid/FunctionId defined
162 Arg6 - Argument 6 ClassGuid/FunctionId defined
163 Arg7 - Argument 7 ClassGuid/FunctionId defined
164 Arg8 - Argument 8 ClassGuid/FunctionId defined
165
166 Returns:
167 Status of ClassGuid/FuncitonId
168
169 --*/
170 {
171 SAL_RETURN_REGS ReturnReg;
172 SAL_EXTENDED_SAL_PROC EsalProc;
173
174 ReturnReg = GetEsalEntryPoint ();
175 if (ReturnReg.Status != EFI_SAL_SUCCESS) {
176 return ReturnReg;
177 }
178
179 if (ReturnReg.r11 & PSR_IT_MASK) {
180 //
181 // Virtual mode plabel to entry point
182 //
183 EsalProc = (SAL_EXTENDED_SAL_PROC) ReturnReg.r10;
184 } else {
185 //
186 // Physical mode plabel to entry point
187 //
188 EsalProc = (SAL_EXTENDED_SAL_PROC) ReturnReg.r9;
189 }
190
191 return EsalProc (
192 ClassGuid,
193 FunctionId,
194 Arg2,
195 Arg3,
196 Arg4,
197 Arg5,
198 Arg6,
199 Arg7,
200 Arg8
201 );
202 }