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