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