]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/UefiRuntimeLib/RuntimeService.c
Add IA32, x64 & EBC version of EfiConvertFunctionPointer()
[mirror_edk2.git] / MdePkg / Library / UefiRuntimeLib / RuntimeService.c
1 /** @file
2 UEFI Runtime Library implementation for non IPF processor types.
3
4 This library hides the global variable for the EFI Runtime Services so the
5 caller does not need to deal with the possiblitly of being called from an
6 OS virtual address space. All pointer values are different for a virtual
7 mapping than from the normal physical mapping at boot services time.
8
9 Copyright (c) 2006 - 2008, Intel Corporation.<BR>
10 All rights reserved. This program and the accompanying materials
11 are licensed and made available under the terms and conditions of the BSD License
12 which accompanies this distribution. The full text of the license may be found at
13 http://opensource.org/licenses/bsd-license.php
14
15 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
16 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17
18 **/
19
20 #include "RuntimeLibInternal.h"
21
22
23 /**
24 Resets the entire platform.
25
26 @param ResetType The type of reset to perform.
27 @param ResetStatus The status code for reset.
28 @param DataSize The size in bytes of reset data.
29 @param ResetData Pointer to data buffer that includes
30 Null-Terminated Unicode string.
31
32 **/
33 VOID
34 EFIAPI
35 EfiResetSystem (
36 IN EFI_RESET_TYPE ResetType,
37 IN EFI_STATUS ResetStatus,
38 IN UINTN DataSize,
39 IN CHAR16 *ResetData
40 )
41 {
42 mRT->ResetSystem (ResetType, ResetStatus, DataSize, ResetData);
43 }
44
45
46 /**
47 Return current time and date information, and time-keeping
48 capabilities of hardware platform.
49
50 @param Time A pointer to storage to receive a snapshot of the current time.
51 @param Capabilities An optional pointer to a buffer to receive the real time clock device's
52 capabilities.
53
54 @retval EFI_SUCCESS Success to execute the function.
55 @retval !EFI_SUCCESS Failed to execute the function.
56
57 **/
58 EFI_STATUS
59 EFIAPI
60 EfiGetTime (
61 OUT EFI_TIME *Time,
62 OUT EFI_TIME_CAPABILITIES *Capabilities
63 )
64 {
65 return mRT->GetTime (Time, Capabilities);
66 }
67
68
69 /**
70 Set current time and date information.
71
72 @param Time A pointer to cache of time setting.
73
74 @retval EFI_SUCCESS Success to execute the function.
75 @retval !EFI_SUCCESS Failed to execute the function.
76
77 **/
78 EFI_STATUS
79 EFIAPI
80 EfiSetTime (
81 IN EFI_TIME *Time
82 )
83 {
84 return mRT->SetTime (Time);
85 }
86
87
88 /**
89 Return current wakeup alarm clock setting.
90
91 @param Enabled Indicate if the alarm clock is enabled or disabled.
92 @param Pending Indicate if the alarm signal is pending and requires acknowledgement.
93 @param Time Current alarm clock setting.
94
95 @retval EFI_SUCCESS Success to execute the function.
96 @retval !EFI_SUCCESS Failed to execute the function.
97
98 **/
99 EFI_STATUS
100 EFIAPI
101 EfiGetWakeupTime (
102 OUT BOOLEAN *Enabled,
103 OUT BOOLEAN *Pending,
104 OUT EFI_TIME *Time
105 )
106 {
107 return mRT->GetWakeupTime (Enabled, Pending, Time);
108 }
109
110
111
112 /**
113 Set current wakeup alarm clock.
114
115 @param Enable Enable or disable current alarm clock..
116 @param Time Point to alarm clock setting.
117
118 @retval EFI_SUCCESS Success to execute the function.
119 @retval !EFI_SUCCESS Failed to execute the function.
120
121 **/
122 EFI_STATUS
123 EFIAPI
124 EfiSetWakeupTime (
125 IN BOOLEAN Enable,
126 IN EFI_TIME *Time
127 )
128 {
129 return mRT->SetWakeupTime (Enable, Time);
130 }
131
132
133 /**
134 Return value of variable.
135
136 @param VariableName the name of the vendor's variable, it's a
137 Null-Terminated Unicode String
138 @param VendorGuid Unify identifier for vendor.
139 @param Attributes Point to memory location to return the attributes of variable. If the point
140 is NULL, the parameter would be ignored.
141 @param DataSize As input, point to the maxinum size of return Data-Buffer.
142 As output, point to the actual size of the returned Data-Buffer.
143 @param Data Point to return Data-Buffer.
144
145 @retval EFI_SUCCESS Success to execute the function.
146 @retval !EFI_SUCCESS Failed to execute the function.
147
148 **/
149 EFI_STATUS
150 EFIAPI
151 EfiGetVariable (
152 IN CHAR16 *VariableName,
153 IN EFI_GUID * VendorGuid,
154 OUT UINT32 *Attributes OPTIONAL,
155 IN OUT UINTN *DataSize,
156 OUT VOID *Data
157 )
158 {
159 return mRT->GetVariable (VariableName, VendorGuid, Attributes, DataSize, Data);
160 }
161
162
163 /**
164 Enumerates variable's name.
165
166 @param VariableNameSize As input, point to maxinum size of variable name.
167 As output, point to actual size of varaible name.
168 @param VariableName As input, supplies the last VariableName that was returned by
169 GetNextVariableName().
170 As output, returns the name of variable. The name
171 string is Null-Terminated Unicode string.
172 @param VendorGuid As input, supplies the last VendorGuid that was returned by
173 GetNextVriableName().
174 As output, returns the VendorGuid of the current variable.
175
176 @retval EFI_SUCCESS Success to execute the function.
177 @retval !EFI_SUCCESS Failed to execute the function.
178
179 **/
180 EFI_STATUS
181 EFIAPI
182 EfiGetNextVariableName (
183 IN OUT UINTN *VariableNameSize,
184 IN OUT CHAR16 *VariableName,
185 IN OUT EFI_GUID *VendorGuid
186 )
187 {
188 return mRT->GetNextVariableName (VariableNameSize, VariableName, VendorGuid);
189 }
190
191
192 /**
193 Sets value of variable.
194
195 @param VariableName the name of the vendor's variable, it's a
196 Null-Terminated Unicode String
197 @param VendorGuid Unify identifier for vendor.
198 @param Attributes Point to memory location to return the attributes of variable. If the point
199 is NULL, the parameter would be ignored.
200 @param DataSize The size in bytes of Data-Buffer.
201 @param Data Point to the content of the variable.
202
203 @retval EFI_SUCCESS Success to execute the function.
204 @retval !EFI_SUCCESS Failed to execute the function.
205
206 **/
207 EFI_STATUS
208 EFIAPI
209 EfiSetVariable (
210 IN CHAR16 *VariableName,
211 IN EFI_GUID *VendorGuid,
212 IN UINT32 Attributes,
213 IN UINTN DataSize,
214 IN VOID *Data
215 )
216 {
217 return mRT->SetVariable (VariableName, VendorGuid, Attributes, DataSize, Data);
218 }
219
220
221 /**
222 Returns the next high 32 bits of platform's monotonic counter.
223
224 @param HighCount Pointer to returned value.
225
226 @retval EFI_SUCCESS Success to execute the function.
227 @retval !EFI_SUCCESS Failed to execute the function.
228
229 **/
230 EFI_STATUS
231 EFIAPI
232 EfiGetNextHighMonotonicCount (
233 OUT UINT32 *HighCount
234 )
235 {
236 return mRT->GetNextHighMonotonicCount (HighCount);
237 }
238
239
240 /**
241 Determines the new virtual address that is to be used on subsequent memory accesses.
242
243 @param DebugDisposition Supplies type information for the pointer being converted.
244 @param Address The pointer to a pointer that is to be fixed to be the
245 value needed for the new virtual address mapping being
246 applied.
247
248 @retval EFI_SUCCESS Success to execute the function.
249 @retval !EFI_SUCCESS Failed to execute the function.
250
251 **/
252 EFI_STATUS
253 EFIAPI
254 EfiConvertPointer (
255 IN UINTN DebugDisposition,
256 IN OUT VOID **Address
257 )
258 {
259 return gRT->ConvertPointer (DebugDisposition, Address);
260 }
261
262
263 /**
264 Determines the new virtual address that is to be used on subsequent memory accesses.
265
266 For IA32, X64, and EBC, this service is a wrapper for the UEFI Runtime Service
267 ConvertPointer(). See the UEFI Specification for details.
268 For IPF, this function interprets Address as a pointer to an EFI_PLABEL structure
269 and both the EntryPoint and GP fields of an EFI_PLABEL are converted from physical
270 to virtiual addressing. Since IPF allows the GP to point to an address outside
271 a PE/COFF image, the physical to virtual offset for the EntryPoint field is used
272 to adjust the GP field. The UEFI Runtime Service ConvertPointer() is used to convert
273 EntryPoint and the status code for this conversion is always returned. If the convertion
274 of EntryPoint fails, then neither EntryPoint nor GP are modified. See the UEFI
275 Specification for details on the UEFI Runtime Service ConvertPointer().
276
277 @param DebugDisposition Supplies type information for the pointer being converted.
278 @param Address The pointer to a pointer that is to be fixed to be the
279 value needed for the new virtual address mapping being
280 applied.
281
282 @retval EFI_SUCCESS Success to execute the function.
283 @retval !EFI_SUCCESS Failed to execute the function.
284
285 **/
286 EFI_STATUS
287 EFIAPI
288 EfiConvertFunctionPointer (
289 IN UINTN DebugDisposition,
290 IN OUT VOID **Address
291 )
292 {
293 return EfiConvertPointer (DebugDisposition, Address);
294 }
295
296
297 /**
298 Conver the standard Lib double linked list to a virtual mapping.
299
300 @param DebugDisposition Supplies type information for the pointer being converted.
301 @param ListHead Head of linked list to convert.
302
303 @retval EFI_SUCCESS Success to execute the function.
304 @retval !EFI_SUCCESS Failed to execute the function.
305
306 **/
307 EFI_STATUS
308 EFIAPI
309 EfiConvertList (
310 IN UINTN DebugDisposition,
311 IN OUT LIST_ENTRY *ListHead
312 )
313 {
314 LIST_ENTRY *Link;
315 LIST_ENTRY *NextLink;
316
317 //
318 // For NULL List, return EFI_SUCCESS
319 //
320 if (ListHead == NULL) {
321 return EFI_SUCCESS;
322 }
323
324 //
325 // Convert all the ForwardLink & BackLink pointers in the list
326 //
327 Link = ListHead;
328 do {
329 NextLink = Link->ForwardLink;
330
331 EfiConvertPointer (
332 Link->ForwardLink == ListHead ? DebugDisposition : 0,
333 (VOID **) &Link->ForwardLink
334 );
335
336 EfiConvertPointer (
337 Link->BackLink == ListHead ? DebugDisposition : 0,
338 (VOID **) &Link->BackLink
339 );
340
341 Link = NextLink;
342 } while (Link != ListHead);
343 return EFI_SUCCESS;
344 }
345
346
347 /**
348 Change the runtime addressing mode of EFI firmware from physical to virtual.
349
350 @param MemoryMapSize The size in bytes of VirtualMap.
351 @param DescriptorSize The size in bytes of an entry in the VirtualMap.
352 @param DescriptorVersion The version of the structure entries in VirtualMap.
353 @param VirtualMap An array of memory descriptors which contain new virtual
354 address mapping information for all runtime ranges. Type
355 EFI_MEMORY_DESCRIPTOR is defined in the
356 GetMemoryMap() function description.
357
358 @retval EFI_SUCCESS The virtual address map has been applied.
359 @retval EFI_UNSUPPORTED EFI firmware is not at runtime, or the EFI firmware is already in
360 virtual address mapped mode.
361 @retval EFI_INVALID_PARAMETER DescriptorSize or DescriptorVersion is
362 invalid.
363 @retval EFI_NO_MAPPING A virtual address was not supplied for a range in the memory
364 map that requires a mapping.
365 @retval EFI_NOT_FOUND A virtual address was supplied for an address that is not found
366 in the memory map.
367 **/
368 EFI_STATUS
369 EFIAPI
370 EfiSetVirtualAddressMap (
371 IN UINTN MemoryMapSize,
372 IN UINTN DescriptorSize,
373 IN UINT32 DescriptorVersion,
374 IN CONST EFI_MEMORY_DESCRIPTOR *VirtualMap
375 )
376 {
377 return mRT->SetVirtualAddressMap (
378 MemoryMapSize,
379 DescriptorSize,
380 DescriptorVersion,
381 (EFI_MEMORY_DESCRIPTOR *) VirtualMap
382 );
383 }
384
385
386 /**
387 Passes capsules to the firmware with both virtual and physical mapping.
388 Depending on the intended consumption, the firmware may
389 process the capsule immediately. If the payload should persist across a
390 system reset, the reset value returned from EFI_QueryCapsuleCapabilities must
391 be passed into ResetSystem() and will cause the capsule to be processed by
392 the firmware as part of the reset process.
393
394 @param CapsuleHeaderArray Virtual pointer to an array of virtual pointers to the capsules
395 being passed into update capsule. Each capsules is assumed to
396 stored in contiguous virtual memory. The capsules in the
397 CapsuleHeaderArray must be the same capsules as the
398 ScatterGatherList. The CapsuleHeaderArray must
399 have the capsules in the same order as the ScatterGatherList.
400 @param CapsuleCount Number of pointers to EFI_CAPSULE_HEADER in
401 CaspuleHeaderArray.
402 @param ScatterGatherList Physical pointer to a set of
403 EFI_CAPSULE_BLOCK_DESCRIPTOR that describes the
404 location in physical memory of a set of capsules. See Related
405 Definitions for an explanation of how more than one capsule is
406 passed via this interface. The capsules in the
407 ScatterGatherList must be in the same order as the
408 CapsuleHeaderArray. This parameter is only referenced if
409 the capsules are defined to persist across system reset.
410
411 @retval EFI_SUCCESS Valid capsule was passed. I Valid capsule was passed. If
412 CAPSULE_FLAGS_PERSIT_ACROSS_RESET is not set, the
413 capsule has been successfully processed by the firmware.
414 @retval EFI_INVALID_PARAMETER CapsuleSize is NULL or ResetTye is NULL.
415 @retval EFI_DEVICE_ERROR The capsule update was started, but failed due to a device error.
416
417 **/
418 EFI_STATUS
419 EFIAPI
420 EfiUpdateCapsule (
421 IN EFI_CAPSULE_HEADER **CapsuleHeaderArray,
422 IN UINTN CapsuleCount,
423 IN EFI_PHYSICAL_ADDRESS ScatterGatherList OPTIONAL
424 )
425 {
426 return mRT->UpdateCapsule (
427 CapsuleHeaderArray,
428 CapsuleCount,
429 ScatterGatherList
430 );
431 }
432
433
434 /**
435 The QueryCapsuleCapabilities() function allows a caller to test to see if a capsule or
436 capsules can be updated via UpdateCapsule(). The Flags values in the capsule header and
437 size of the entire capsule is checked.
438 If the caller needs to query for generic capsule capability a fake EFI_CAPSULE_HEADER can be
439 constructed where CapsuleImageSize is equal to HeaderSize that is equal to sizeof
440 (EFI_CAPSULE_HEADER). To determine reset requirements,
441 CAPSULE_FLAGS_PERSIST_ACROSS_RESET should be set in the Flags field of the
442 EFI_CAPSULE_HEADER.
443 The firmware must support any capsule that has the
444 CAPSULE_FLAGS_PERSIST_ACROSS_RESET flag set in EFI_CAPSULE_HEADER. The
445 firmware sets the policy for what capsules are supported that do not have the
446 CAPSULE_FLAGS_PERSIST_ACROSS_RESET flag set.
447
448 @param CapsuleHeaderArray Virtual pointer to an array of virtual pointers to the capsules
449 being passed into update capsule. The capsules are assumed to
450 stored in contiguous virtual memory.
451 @param CapsuleCount Number of pointers to EFI_CAPSULE_HEADER in
452 CaspuleHeaderArray.
453 @param MaximumCapsuleSize On output the maximum size that UpdateCapsule() can
454 support as an argument to UpdateCapsule() via
455 CapsuleHeaderArray and ScatterGatherList.
456 Undefined on input.
457 @param ResetType Returns the type of reset required for the capsule update.
458
459 @retval EFI_SUCCESS Valid answer returned..
460 @retval EFI_INVALID_PARAMETER MaximumCapsuleSize is NULL.
461 @retval EFI_UNSUPPORTED The capsule type is not supported on this platform, and
462 MaximumCapsuleSize and ResetType are undefined.
463
464 **/
465 EFI_STATUS
466 EFIAPI
467 EfiQueryCapsuleCapabilities (
468 IN EFI_CAPSULE_HEADER **CapsuleHeaderArray,
469 IN UINTN CapsuleCount,
470 OUT UINT64 *MaximumCapsuleSize,
471 OUT EFI_RESET_TYPE *ResetType
472 )
473 {
474 return mRT->QueryCapsuleCapabilities (
475 CapsuleHeaderArray,
476 CapsuleCount,
477 MaximumCapsuleSize,
478 ResetType
479 );
480 }
481
482
483 /**
484 The QueryVariableInfo() function allows a caller to obtain the information about the
485 maximum size of the storage space available for the EFI variables, the remaining size of the storage
486 space available for the EFI variables and the maximum size of each individual EFI variable,
487 associated with the attributes specified.
488 The returned MaximumVariableStorageSize, RemainingVariableStorageSize,
489 MaximumVariableSize information may change immediately after the call based on other
490 runtime activities including asynchronous error events. Also, these values associated with different
491 attributes are not additive in nature.
492
493 @param Attributes Attributes bitmask to specify the type of variables on
494 which to return information. Refer to the
495 GetVariable() function description.
496 @param MaximumVariableStorageSize
497 On output the maximum size of the storage space
498 available for the EFI variables associated with the
499 attributes specified.
500 @param RemainingVariableStorageSize
501 Returns the remaining size of the storage space
502 available for the EFI variables associated with the
503 attributes specified..
504 @param MaximumVariableSize Returns the maximum size of the individual EFI
505 variables associated with the attributes specified.
506
507 @retval EFI_SUCCESS Valid answer returned.
508 @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied.
509 @retval EFI_UNSUPPORTED EFI_UNSUPPORTED The attribute is not supported on this platform, and the
510 MaximumVariableStorageSize,
511 RemainingVariableStorageSize, MaximumVariableSize
512 are undefined.
513 **/
514 EFI_STATUS
515 EFIAPI
516 EfiQueryVariableInfo (
517 IN UINT32 Attributes,
518 OUT UINT64 *MaximumVariableStorageSize,
519 OUT UINT64 *RemainingVariableStorageSize,
520 OUT UINT64 *MaximumVariableSize
521 )
522 {
523 return mRT->QueryVariableInfo (
524 Attributes,
525 MaximumVariableStorageSize,
526 RemainingVariableStorageSize,
527 MaximumVariableSize
528 );
529 }