TianoCore EDK2 master
Loading...
Searching...
No Matches
PlatformConfig.c
Go to the documentation of this file.
1
13#include <Library/DebugLib.h>
15#include <Library/UefiLib.h>
18
19#include "PlatformConfig.h"
20
21//
22// Name of the UEFI variable that we use for persistent storage.
23//
24CHAR16 mVariableName[] = L"PlatformConfig";
25CHAR16 mHiiFormName[] = L"MainFormState";
26
35EFIAPI
37 IN PLATFORM_CONFIG *PlatformConfig
38 )
39{
40 EFI_STATUS Status;
41
42 //
43 // We could implement any kind of translation here, as part of serialization.
44 // For example, we could expose the platform configuration in separate
45 // variables with human-readable contents, allowing other tools to access
46 // them more easily. For now, just save a binary dump.
47 //
48 Status = gRT->SetVariable (
49 mVariableName,
50 &gOvmfPlatformConfigGuid,
51 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS |
52 EFI_VARIABLE_RUNTIME_ACCESS,
53 sizeof *PlatformConfig,
54 PlatformConfig
55 );
56 return Status;
57}
58
77EFIAPI
79 OUT PLATFORM_CONFIG *PlatformConfig,
80 OUT UINT64 *OptionalElements
81 )
82{
83 VOID *Data;
84 UINTN DataSize;
85 EFI_STATUS Status;
86
87 //
88 // Any translation done in PlatformConfigSave() would have to be mirrored
89 // here. For now, just load the binary dump.
90 //
91 // Versioning of the binary wire format is implemented based on size
92 // (only incremental changes, ie. new fields), and on GUID.
93 // (Incompatible changes require a GUID change.)
94 //
95 Status = GetVariable2 (
96 mVariableName,
97 &gOvmfPlatformConfigGuid,
98 &Data,
99 &DataSize
100 );
101 if (EFI_ERROR (Status)) {
102 return Status;
103 }
104
105 *OptionalElements = 0;
106 if (DataSize > sizeof *PlatformConfig) {
107 //
108 // Handle firmware downgrade -- keep only leading part.
109 //
110 CopyMem (PlatformConfig, Data, sizeof *PlatformConfig);
111 *OptionalElements |= PLATFORM_CONFIG_F_DOWNGRADE;
112 } else {
113 CopyMem (PlatformConfig, Data, DataSize);
114
115 //
116 // Handle firmware upgrade -- zero out missing fields.
117 //
118 ZeroMem (
119 (UINT8 *)PlatformConfig + DataSize,
120 sizeof *PlatformConfig - DataSize
121 );
122 }
123
124 //
125 // Based on DataSize, report the optional features that we recognize.
126 //
127 if (DataSize >= (OFFSET_OF (PLATFORM_CONFIG, VerticalResolution) +
128 sizeof PlatformConfig->VerticalResolution))
129 {
130 *OptionalElements |= PLATFORM_CONFIG_F_GRAPHICS_RESOLUTION;
131 }
132
133 FreePool (Data);
134 return EFI_SUCCESS;
135}
UINT64 UINTN
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_RUNTIME_SERVICES * gRT
#define IN
Definition: Base.h:279
#define OFFSET_OF(TYPE, Field)
Definition: Base.h:758
#define OUT
Definition: Base.h:284
EFI_STATUS EFIAPI PlatformConfigSave(IN PLATFORM_CONFIG *PlatformConfig)
EFI_STATUS EFIAPI PlatformConfigLoad(OUT PLATFORM_CONFIG *PlatformConfig, OUT UINT64 *OptionalElements)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_STATUS EFIAPI GetVariable2(IN CONST CHAR16 *Name, IN CONST EFI_GUID *Guid, OUT VOID **Value, OUT UINTN *Size OPTIONAL)
Definition: UefiLib.c:1317
#define EFI_VARIABLE_NON_VOLATILE