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