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