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