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