]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Library/EdkDxeRuntimeDriverLib/Ipf/RuntimeLib.c
Add in the 1st version of ECP.
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / EdkIIGlueLib / Library / EdkDxeRuntimeDriverLib / Ipf / RuntimeLib.c
1 /*++
2
3 Copyright (c) 2004 - 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
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 VOID
61 EFIAPI
62 RuntimeLibVirtualNotifyEvent (
63 IN EFI_EVENT Event,
64 IN VOID *Context
65 )
66 /*++
67
68 Routine Description:
69
70 Fixup internal data so that EFI can be call in virtual mode.
71 Call the passed in Child Notify event and convert any pointers in
72 lib to virtual mode.
73
74 Arguments:
75
76 Event - The Event that is being processed
77
78 Context - Event Context
79
80 Returns:
81
82 None
83
84 --*/
85 {
86 UINTN Index;
87 EFI_EVENT_NOTIFY ChildNotifyEventHandler;
88
89 for (Index = 0; _gDriverSetVirtualAddressMapEvent[Index] != NULL; Index++) {
90 ChildNotifyEventHandler = _gDriverSetVirtualAddressMapEvent[Index];
91 ChildNotifyEventHandler (Event, NULL);
92 }
93
94 //
95 // Update global for Runtime Services Table
96 //
97 EfiConvertPointer (0, (VOID **) &mRT);
98 }
99
100 EFI_STATUS
101 EFIAPI
102 RuntimeDriverLibConstruct (
103 IN EFI_HANDLE ImageHandle,
104 IN EFI_SYSTEM_TABLE *SystemTable
105 )
106 /*++
107
108 Routine Description:
109
110 Intialize runtime Driver Lib if it has not yet been initialized.
111
112 Arguments:
113
114 ImageHandle - The firmware allocated handle for the EFI image.
115
116 SystemTable - A pointer to the EFI System Table.
117
118 GoVirtualChildEvent - Caller can register a virtual notification event.
119
120 Returns:
121
122 EFI_STATUS always returns EFI_SUCCESS except EFI_ALREADY_STARTED if already started.
123
124 --*/
125 {
126 EFI_STATUS Status;
127
128 mRT = SystemTable->RuntimeServices;
129
130 //
131 // Register SetVirtualAddressMap () notify function
132 //
133 if (_gDriverSetVirtualAddressMapEvent[0] != NULL) {
134 Status = gBS->CreateEvent (
135 EFI_EVENT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,
136 EFI_TPL_NOTIFY,
137 RuntimeLibVirtualNotifyEvent,
138 NULL,
139 &mEfiVirtualNotifyEvent
140 );
141 ASSERT_EFI_ERROR (Status);
142 }
143
144 return EFI_SUCCESS;
145 }
146
147 EFI_STATUS
148 EFIAPI
149 RuntimeDriverLibDeconstruct (
150 VOID
151 )
152 /*++
153
154 Routine Description:
155
156 This routine will free some resources which have been allocated in
157 EfiInitializeRuntimeDriverLib(). If a runtime driver exits with an error,
158 it must call this routine to free the allocated resource before the exiting.
159
160 Arguments:
161
162 None
163
164 Returns:
165
166 EFI_SUCCESS - Shotdown the Runtime Driver Lib successfully
167 EFI_UNSUPPORTED - Runtime Driver lib was not initialized at all
168
169 --*/
170 {
171 EFI_STATUS Status;
172
173 //
174 // Close SetVirtualAddressMap () notify function
175 //
176 if (_gDriverSetVirtualAddressMapEvent[0] != NULL) {
177 Status = gBS->CloseEvent (mEfiVirtualNotifyEvent);
178 ASSERT_EFI_ERROR (Status);
179 }
180
181 return EFI_SUCCESS;
182 }
183
184 BOOLEAN
185 EFIAPI
186 EfiAtRuntime (
187 VOID
188 )
189 /*++
190
191 Routine Description:
192 Return TRUE if ExitBootService () has been called
193
194 Arguments:
195 NONE
196
197 Returns:
198 TRUE - If ExitBootService () has been called
199
200 --*/
201 {
202 EFI_GUID Guid = EFI_EXTENDED_SAL_VIRTUAL_SERVICES_PROTOCOL_GUID;
203 SAL_RETURN_REGS ReturnReg;
204
205 ReturnReg = EfiCallEsalService (&Guid, IsEfiRuntime, 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 = EFI_EXTENDED_SAL_VIRTUAL_SERVICES_PROTOCOL_GUID;
229 SAL_RETURN_REGS ReturnReg;
230
231 ReturnReg = EfiCallEsalService (&Guid, IsVirtual, 0, 0, 0, 0, 0, 0, 0);
232
233 return (BOOLEAN) (ReturnReg.r9 == 1);
234 }
235