]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Library/EdkUefiRuntimeLib/Common/RuntimeService.c
Change DxeRuntimeDriverLib name to UefiRuntimeLib.
[mirror_edk2.git] / EdkModulePkg / Library / EdkUefiRuntimeLib / Common / RuntimeService.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 RuntimeService.c
15
16 Abstract:
17
18 Light weight lib to support Tiano drivers.
19
20 --*/
21
22 #include <RuntimeLibInternal.h>
23
24 VOID
25 EfiResetSystem (
26 IN EFI_RESET_TYPE ResetType,
27 IN EFI_STATUS ResetStatus,
28 IN UINTN DataSize,
29 IN CHAR16 *ResetData
30 )
31 /*++
32
33 Routine Description:
34
35 Resets the entire platform.
36
37 Arguments:
38
39 ResetType - The type of reset to perform.
40 ResetStatus - The status code for the reset.
41 DataSize - The size, in bytes, of ResetData.
42 ResetData - A data buffer that includes a Null-terminated Unicode string, optionally
43 followed by additional binary data.
44
45 Returns:
46
47 None
48
49 --*/
50 {
51 mRT->ResetSystem (ResetType, ResetStatus, DataSize, ResetData);
52 }
53
54 //
55 // The following functions hide the mRT local global from the call to
56 // runtime service in the EFI system table.
57 //
58 EFI_STATUS
59 EfiGetTime (
60 OUT EFI_TIME *Time,
61 OUT EFI_TIME_CAPABILITIES *Capabilities
62 )
63 /*++
64
65 Routine Description:
66
67 Returns the current time and date information, and the time-keeping
68 capabilities of the hardware platform.
69
70 Arguments:
71
72 Time - A pointer to storage to receive a snapshot of the current time.
73 Capabilities - An optional pointer to a buffer to receive the real time clock device¡¯s
74 capabilities.
75
76 Returns:
77
78 Status code
79
80 --*/
81 {
82 return mRT->GetTime (Time, Capabilities);
83 }
84
85 EFI_STATUS
86 EfiSetTime (
87 IN EFI_TIME *Time
88 )
89 /*++
90
91 Routine Description:
92
93 Sets the current local time and date information.
94
95 Arguments:
96
97 Time - A pointer to the current time.
98
99 Returns:
100
101 Status code
102
103 --*/
104 {
105 return mRT->SetTime (Time);
106 }
107
108 EFI_STATUS
109 EfiGetWakeupTime (
110 OUT BOOLEAN *Enabled,
111 OUT BOOLEAN *Pending,
112 OUT EFI_TIME *Time
113 )
114 /*++
115
116 Routine Description:
117
118 Returns the current wakeup alarm clock setting.
119
120 Arguments:
121
122 Enabled - Indicates if the alarm is currently enabled or disabled.
123 Pending - Indicates if the alarm signal is pending and requires acknowledgement.
124 Time - The current alarm setting.
125
126 Returns:
127
128 Status code
129
130 --*/
131 {
132 return mRT->GetWakeupTime (Enabled, Pending, Time);
133 }
134
135 EFI_STATUS
136 EfiSetWakeupTime (
137 IN BOOLEAN Enable,
138 IN EFI_TIME *Time
139 )
140 /*++
141
142 Routine Description:
143
144 Sets the system wakeup alarm clock time.
145
146 Arguments:
147
148 Enable - Enable or disable the wakeup alarm.
149 Time - If Enable is TRUE, the time to set the wakeup alarm for.
150 If Enable is FALSE, then this parameter is optional, and may be NULL.
151
152 Returns:
153
154 Status code
155
156 --*/
157 {
158 return mRT->SetWakeupTime (Enable, Time);
159 }
160
161
162
163
164 EFI_STATUS
165 EfiGetVariable (
166 IN CHAR16 *VariableName,
167 IN EFI_GUID * VendorGuid,
168 OUT UINT32 *Attributes OPTIONAL,
169 IN OUT UINTN *DataSize,
170 OUT VOID *Data
171 )
172 /*++
173
174 Routine Description:
175
176 Returns the value of a variable.
177
178 Arguments:
179
180 VariableName - A Null-terminated Unicode string that is the name of the
181 vendor¡¯s variable.
182 VendorGuid - A unique identifier for the vendor.
183 Attributes - If not NULL, a pointer to the memory location to return the
184 attributes bitmask for the variable.
185 DataSize - On input, the size in bytes of the return Data buffer.
186 On output the size of data returned in Data.
187 Data - The buffer to return the contents of the variable.
188
189 Returns:
190
191 Status code
192
193 --*/
194 {
195 return mRT->GetVariable (VariableName, VendorGuid, Attributes, DataSize, Data);
196 }
197
198 EFI_STATUS
199 EfiGetNextVariableName (
200 IN OUT UINTN *VariableNameSize,
201 IN OUT CHAR16 *VariableName,
202 IN OUT EFI_GUID *VendorGuid
203 )
204 /*++
205
206 Routine Description:
207
208 Enumerates the current variable names.
209
210 Arguments:
211
212 VariableNameSize - The size of the VariableName buffer.
213 VariableName - On input, supplies the last VariableName that was returned
214 by GetNextVariableName().
215 On output, returns the Nullterminated Unicode string of the
216 current variable.
217 VendorGuid - On input, supplies the last VendorGuid that was returned by
218 GetNextVariableName().
219 On output, returns the VendorGuid of the current variable.
220
221 Returns:
222
223 Status code
224
225 --*/
226 {
227 return mRT->GetNextVariableName (VariableNameSize, VariableName, VendorGuid);
228 }
229
230 EFI_STATUS
231 EfiSetVariable (
232 IN CHAR16 *VariableName,
233 IN EFI_GUID *VendorGuid,
234 IN UINT32 Attributes,
235 IN UINTN DataSize,
236 IN VOID *Data
237 )
238 /*++
239
240 Routine Description:
241
242 Sets the value of a variable.
243
244 Arguments:
245
246 VariableName - A Null-terminated Unicode string that is the name of the
247 vendor¡¯s variable.
248 VendorGuid - A unique identifier for the vendor.
249 Attributes - Attributes bitmask to set for the variable.
250 DataSize - The size in bytes of the Data buffer.
251 Data - The contents for the variable.
252
253 Returns:
254
255 Status code
256
257 --*/
258 {
259 return mRT->SetVariable (VariableName, VendorGuid, Attributes, DataSize, Data);
260 }
261
262 EFI_STATUS
263 EfiGetNextHighMonotonicCount (
264 OUT UINT32 *HighCount
265 )
266 /*++
267
268 Routine Description:
269
270 Returns the next high 32 bits of the platform¡¯s monotonic counter.
271
272 Arguments:
273
274 HighCount - Pointer to returned value.
275
276 Returns:
277
278 Status code
279
280 --*/
281 {
282 return mRT->GetNextHighMonotonicCount (HighCount);
283 }
284
285 EFI_STATUS
286 EfiConvertPointer (
287 IN UINTN DebugDisposition,
288 IN OUT VOID *Address
289 )
290 /*++
291
292 Routine Description:
293
294 Determines the new virtual address that is to be used on subsequent memory accesses.
295
296 Arguments:
297
298 DebugDisposition - Supplies type information for the pointer being converted.
299 Address - A pointer to a pointer that is to be fixed to be the value needed
300 for the new virtual address mappings being applied.
301
302 Returns:
303
304 Status code
305
306 --*/
307 {
308 return mRT->ConvertPointer (DebugDisposition, Address);
309 }
310
311 EFI_STATUS
312 EfiConvertInternalPointer (
313 IN OUT VOID *Address
314 )
315 /*++
316
317 Routine Description:
318
319 Call EfiConvertPointer() to convert internal pointer.
320
321 Arguments:
322
323 Address - A pointer to a pointer that is to be fixed to be the value needed
324 for the new virtual address mappings being applied.
325
326 Returns:
327
328 Status code
329
330 --*/
331 {
332 return EfiConvertPointer (0x0, Address);
333 }
334
335 EFI_STATUS
336 EfiConvertList (
337 IN UINTN DebugDisposition,
338 IN OUT LIST_ENTRY *ListHead
339 )
340 /*++
341
342 Routine Description:
343
344 Conver the standard Lib double linked list to a virtual mapping.
345
346 Arguments:
347
348 DebugDisposition - Argument to EfiConvertPointer (EFI 1.0 API)
349
350 ListHead - Head of linked list to convert
351
352 Returns:
353
354 EFI_SUCCESS
355
356 --*/
357 {
358 LIST_ENTRY *Link;
359 LIST_ENTRY *NextLink;
360
361 //
362 // Convert all the ForwardLink & BackLink pointers in the list
363 //
364 Link = ListHead;
365 do {
366 NextLink = Link->ForwardLink;
367
368 EfiConvertPointer (
369 Link->ForwardLink == ListHead ? DebugDisposition : 0,
370 (VOID **) &Link->ForwardLink
371 );
372
373 EfiConvertPointer (
374 Link->BackLink == ListHead ? DebugDisposition : 0,
375 (VOID **) &Link->BackLink
376 );
377
378 Link = NextLink;
379 } while (Link != ListHead);
380 return EFI_SUCCESS;
381 }
382
383
384 /**
385 Change the runtime addressing mode of EFI firmware from physical to virtual.
386
387 @param MemoryMapSize The size in bytes of VirtualMap.
388 @param DescriptorSize The size in bytes of an entry in the VirtualMap.
389 @param DescriptorVersion The version of the structure entries in VirtualMap.
390 @param VirtualMap An array of memory descriptors which contain new virtual
391 address mapping information for all runtime ranges. Type
392 EFI_MEMORY_DESCRIPTOR is defined in the
393 GetMemoryMap() function description.
394
395 @retval EFI_SUCCESS The virtual address map has been applied.
396 @retval EFI_UNSUPPORTED EFI firmware is not at runtime, or the EFI firmware is already in
397 virtual address mapped mode.
398 @retval EFI_INVALID_PARAMETER DescriptorSize or DescriptorVersion is
399 invalid.
400 @retval EFI_NO_MAPPING A virtual address was not supplied for a range in the memory
401 map that requires a mapping.
402 @retval EFI_NOT_FOUND A virtual address was supplied for an address that is not found
403 in the memory map.
404 **/
405 EFI_STATUS
406 EFIAPI
407 EfiSetVirtualAddressMap (
408 IN UINTN MemoryMapSize,
409 IN UINTN DescriptorSize,
410 IN UINT32 DescriptorVersion,
411 IN CONST EFI_MEMORY_DESCRIPTOR *VirtualMap
412 )
413 {
414 return mRT->SetVirtualAddressMap (
415 MemoryMapSize,
416 DescriptorSize,
417 DescriptorVersion,
418 (EFI_MEMORY_DESCRIPTOR *) VirtualMap
419 );
420 }
421
422
423 EFI_STATUS
424 EfiUpdateCapsule (
425 IN UEFI_CAPSULE_HEADER **CapsuleHeaderArray,
426 IN UINTN CapsuleCount,
427 IN EFI_PHYSICAL_ADDRESS ScatterGatherList OPTIONAL
428 )
429 {
430 #if (EFI_SPECIFICATION_VERSION >= 0x00020000)
431 return mRT->UpdateCapsule (
432 CapsuleHeaderArray,
433 CapsuleCount,
434 ScatterGatherList
435 );
436 #else
437 return EFI_UNSUPPORTED;
438 #endif
439 }
440
441 EFI_STATUS
442 EfiQueryCapsuleCapabilities (
443 IN UEFI_CAPSULE_HEADER **CapsuleHeaderArray,
444 IN UINTN CapsuleCount,
445 OUT UINT64 *MaximumCapsuleSize,
446 OUT EFI_RESET_TYPE *ResetType
447 )
448 {
449 #if (EFI_SPECIFICATION_VERSION >= 0x00020000)
450 return mRT->QueryCapsuleCapabilities (
451 CapsuleHeaderArray,
452 CapsuleCount,
453 MaximumCapsuleSize,
454 ResetType
455 );
456 #else
457 return EFI_UNSUPPORTED;
458 #endif
459 }
460
461
462 EFI_STATUS
463 EfiQueryVariableInfo (
464 IN UINT32 Attributes,
465 OUT UINT64 *MaximumVariableStorageSize,
466 OUT UINT64 *RemainingVariableStorageSize,
467 OUT UINT64 *MaximumVariableSize
468 )
469 {
470 #if (EFI_SPECIFICATION_VERSION >= 0x00020000)
471 return mRT->QueryVariableInfo (
472 Attributes,
473 MaximumVariableStorageSize,
474 RemainingVariableStorageSize,
475 MaximumVariableSize
476 );
477 #else
478 return EFI_UNSUPPORTED;
479 #endif
480 }