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