]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Library/EdkUefiRuntimeLib/Ipf/RuntimeLib.c
changed the Esal call function ids all over the tree
[mirror_edk2.git] / EdkModulePkg / Library / EdkUefiRuntimeLib / Ipf / RuntimeLib.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 RuntimeLib.c
15
16 --*/
17
18 #include <RuntimeLibInternal.h>
19
20 //
21 // Driver Lib Module Globals
22 //
23 static EFI_EVENT mEfiVirtualNotifyEvent;
24 EFI_RUNTIME_SERVICES *mRT;
25
26 VOID
27 EFIAPI
28 RuntimeDriverExitBootServices (
29 IN EFI_EVENT Event,
30 IN VOID *Context
31 )
32 /*++
33
34 Routine Description:
35
36 Set AtRuntime flag as TRUE after ExitBootServices
37
38 Arguments:
39
40 Event - The Event that is being processed
41
42 Context - Event Context
43
44 Returns:
45
46 None
47
48 --*/
49 {
50 if (EfiAtRuntime()) {
51 return;
52 }
53 }
54
55 STATIC
56 VOID
57 EFIAPI
58 RuntimeLibVirtualNotifyEvent (
59 IN EFI_EVENT Event,
60 IN VOID *Context
61 )
62 /*++
63
64 Routine Description:
65
66 Fixup internal data so that EFI can be call in virtual mode.
67 Call the passed in Child Notify event and convert any pointers in
68 lib to virtual mode.
69
70 Arguments:
71
72 Event - The Event that is being processed
73
74 Context - Event Context
75
76 Returns:
77
78 None
79
80 --*/
81 {
82 UINTN Index;
83 EFI_EVENT_NOTIFY ChildNotifyEventHandler;
84
85 for (Index = 0; _gDriverSetVirtualAddressMapEvent[Index] != NULL; Index++) {
86 ChildNotifyEventHandler = _gDriverSetVirtualAddressMapEvent[Index];
87 ChildNotifyEventHandler (Event, NULL);
88 }
89
90 //
91 // Update global for Runtime Services Table
92 //
93 EfiConvertPointer (0, (VOID **) &mRT);
94 }
95
96 EFI_STATUS
97 EFIAPI
98 RuntimeDriverLibConstruct (
99 IN EFI_HANDLE ImageHandle,
100 IN EFI_SYSTEM_TABLE *SystemTable
101 )
102 /*++
103
104 Routine Description:
105
106 Intialize runtime Driver Lib if it has not yet been initialized.
107
108 Arguments:
109
110 ImageHandle - The firmware allocated handle for the EFI image.
111
112 SystemTable - A pointer to the EFI System Table.
113
114 GoVirtualChildEvent - Caller can register a virtual notification event.
115
116 Returns:
117
118 EFI_STATUS always returns EFI_SUCCESS except EFI_ALREADY_STARTED if already started.
119
120 --*/
121 {
122 EFI_STATUS Status;
123
124 mRT = SystemTable->RuntimeServices;
125
126 //
127 // Register SetVirtualAddressMap () notify function
128 //
129 if (_gDriverSetVirtualAddressMapEvent[0] != NULL) {
130 Status = gBS->CreateEvent (
131 EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,
132 TPL_NOTIFY,
133 RuntimeLibVirtualNotifyEvent,
134 NULL,
135 &mEfiVirtualNotifyEvent
136 );
137 ASSERT_EFI_ERROR (Status);
138 }
139
140 return EFI_SUCCESS;
141 }
142
143 EFI_STATUS
144 EFIAPI
145 RuntimeDriverLibDeconstruct (
146 IN EFI_HANDLE ImageHandle,
147 IN EFI_SYSTEM_TABLE *SystemTable
148 )
149 /*++
150
151 Routine Description:
152
153 This routine will free some resources which have been allocated in
154 EfiInitializeRuntimeDriverLib(). If a runtime driver exits with an error,
155 it must call this routine to free the allocated resource before the exiting.
156
157 Arguments:
158
159 None
160
161 Returns:
162
163 EFI_SUCCESS - Shotdown the Runtime Driver Lib successfully
164 EFI_UNSUPPORTED - Runtime Driver lib was not initialized at all
165
166 --*/
167 {
168 EFI_STATUS Status;
169
170 //
171 // Close SetVirtualAddressMap () notify function
172 //
173 if (_gDriverSetVirtualAddressMapEvent[0] != NULL) {
174 Status = gBS->CloseEvent (mEfiVirtualNotifyEvent);
175 ASSERT_EFI_ERROR (Status);
176 }
177
178 return EFI_SUCCESS;
179 }
180
181 BOOLEAN
182 EFIAPI
183 EfiAtRuntime (
184 VOID
185 )
186 /*++
187
188 Routine Description:
189 Return TRUE if ExitBootService () has been called
190
191 Arguments:
192 NONE
193
194 Returns:
195 TRUE - If ExitBootService () has been called
196
197 --*/
198 {
199 EFI_GUID Guid;
200 SAL_RETURN_REGS ReturnReg;
201
202 *((UINT64 *) &Guid) = EFI_EXTENDED_SAL_VIRTUAL_SERVICES_PROTOCOL_GUID_LO;
203 *(((UINT64 *)&Guid) + 1) = EFI_EXTENDED_SAL_VIRTUAL_SERVICES_PROTOCOL_GUID_HI;
204
205 ReturnReg = EsalCall (&Guid, IsEfiRuntimeFunctionId, 0, 0, 0, 0, 0, 0, 0);
206
207 return (BOOLEAN) (ReturnReg.r9 == 1);
208 }
209
210 BOOLEAN
211 EFIAPI
212 EfiGoneVirtual (
213 VOID
214 )
215 /*++
216
217 Routine Description:
218 Return TRUE if SetVirtualAddressMap () has been called
219
220 Arguments:
221 NONE
222
223 Returns:
224 TRUE - If SetVirtualAddressMap () has been called
225
226 --*/
227 {
228 EFI_GUID Guid;
229 SAL_RETURN_REGS ReturnReg;
230
231 *((UINT64 *) &Guid) = EFI_EXTENDED_SAL_VIRTUAL_SERVICES_PROTOCOL_GUID_LO;
232 *(((UINT64 *)&Guid) + 1) = EFI_EXTENDED_SAL_VIRTUAL_SERVICES_PROTOCOL_GUID_HI;
233
234 ReturnReg = EsalCall (&Guid, IsVirtualFunctionId, 0, 0, 0, 0, 0, 0, 0);
235
236 return (BOOLEAN) (ReturnReg.r9 == 1);
237 }
238