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