VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.c@ 105681

Last change on this file since 105681 was 99404, checked in by vboxsync, 2 years ago

Devices/EFI/FirmwareNew: Update to edk2-stable202302 and make it build, bugref:4643

  • Property svn:eol-style set to native
File size: 5.4 KB
Line 
1/** @file
2 Variable Flash Information Library
3
4 Copyright (c) Microsoft Corporation<BR>
5
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8**/
9
10#include <Uefi.h>
11#include <Pi/PiMultiPhase.h>
12#include <Guid/VariableFlashInfo.h>
13#include <Library/DebugLib.h>
14#include <Library/HobLib.h>
15#include <Library/VariableFlashInfoLib.h>
16
17/**
18 Get the HOB that contains variable flash information.
19
20 @param[out] VariableFlashInfo Pointer to a pointer to set to the variable flash information structure.
21
22 @retval EFI_SUCCESS Variable flash information was found successfully.
23 @retval EFI_INVALID_PARAMETER The VariableFlashInfo pointer given is NULL.
24 @retval EFI_NOT_FOUND Variable flash information could not be found.
25
26**/
27STATIC
28EFI_STATUS
29GetVariableFlashInfoFromHob (
30 OUT VARIABLE_FLASH_INFO **VariableFlashInfo
31 )
32{
33 EFI_HOB_GUID_TYPE *GuidHob;
34
35 if (VariableFlashInfo == NULL) {
36 return EFI_INVALID_PARAMETER;
37 }
38
39 GuidHob = GetFirstGuidHob (&gVariableFlashInfoHobGuid);
40 if (GuidHob == NULL) {
41 return EFI_NOT_FOUND;
42 }
43
44 *VariableFlashInfo = GET_GUID_HOB_DATA (GuidHob);
45
46 //
47 // Assert if more than one variable flash information HOB is present.
48 //
49 DEBUG_CODE (
50 if ((GetNextGuidHob (&gVariableFlashInfoHobGuid, GET_NEXT_HOB (GuidHob)) != NULL)) {
51 DEBUG ((DEBUG_ERROR, "ERROR: Found two variable flash information HOBs\n"));
52 ASSERT (FALSE);
53 }
54
55 );
56
57 return EFI_SUCCESS;
58}
59
60/**
61 Get the base address and size for the NV storage area used for UEFI variable storage.
62
63 @param[out] BaseAddress The NV storage base address.
64 @param[out] Length The NV storage length in bytes.
65
66 @retval EFI_SUCCESS NV storage information was found successfully.
67 @retval EFI_INVALID_PARAMETER A required pointer parameter is NULL.
68
69**/
70EFI_STATUS
71EFIAPI
72GetVariableFlashNvStorageInfo (
73 OUT EFI_PHYSICAL_ADDRESS *BaseAddress,
74 OUT UINT64 *Length
75 )
76{
77 EFI_STATUS Status;
78 VARIABLE_FLASH_INFO *VariableFlashInfo;
79
80 if ((BaseAddress == NULL) || (Length == NULL)) {
81 return EFI_INVALID_PARAMETER;
82 }
83
84 Status = GetVariableFlashInfoFromHob (&VariableFlashInfo);
85 if (!EFI_ERROR (Status)) {
86 *BaseAddress = VariableFlashInfo->NvVariableBaseAddress;
87 *Length = VariableFlashInfo->NvVariableLength;
88 } else {
89 *BaseAddress = (EFI_PHYSICAL_ADDRESS)(PcdGet64 (PcdFlashNvStorageVariableBase64) != 0 ?
90 PcdGet64 (PcdFlashNvStorageVariableBase64) :
91 PcdGet32 (PcdFlashNvStorageVariableBase)
92 );
93 *Length = (UINT64)PcdGet32 (PcdFlashNvStorageVariableSize);
94 }
95
96 return EFI_SUCCESS;
97}
98
99/**
100 Get the base address and size for the fault tolerant write (FTW) spare
101 area used for UEFI variable storage.
102
103 @param[out] BaseAddress The FTW spare base address.
104 @param[out] Length The FTW spare length in bytes.
105
106 @retval EFI_SUCCESS FTW spare information was found successfully.
107 @retval EFI_INVALID_PARAMETER A required pointer parameter is NULL.
108 @retval EFI_NOT_FOUND FTW spare information could not be found.
109
110**/
111EFI_STATUS
112EFIAPI
113GetVariableFlashFtwSpareInfo (
114 OUT EFI_PHYSICAL_ADDRESS *BaseAddress,
115 OUT UINT64 *Length
116 )
117{
118 EFI_STATUS Status;
119 VARIABLE_FLASH_INFO *VariableFlashInfo;
120
121 if ((BaseAddress == NULL) || (Length == NULL)) {
122 return EFI_INVALID_PARAMETER;
123 }
124
125 Status = GetVariableFlashInfoFromHob (&VariableFlashInfo);
126 if (!EFI_ERROR (Status)) {
127 *BaseAddress = VariableFlashInfo->FtwSpareBaseAddress;
128 *Length = VariableFlashInfo->FtwSpareLength;
129 } else {
130 *BaseAddress = (EFI_PHYSICAL_ADDRESS)(PcdGet64 (PcdFlashNvStorageFtwSpareBase64) != 0 ?
131 PcdGet64 (PcdFlashNvStorageFtwSpareBase64) :
132 PcdGet32 (PcdFlashNvStorageFtwSpareBase)
133 );
134 *Length = (UINT64)PcdGet32 (PcdFlashNvStorageFtwSpareSize);
135 }
136
137 return EFI_SUCCESS;
138}
139
140/**
141 Get the base address and size for the fault tolerant write (FTW) working
142 area used for UEFI variable storage.
143
144 @param[out] BaseAddress The FTW working area base address.
145 @param[out] Length The FTW working area length in bytes.
146
147 @retval EFI_SUCCESS FTW working information was found successfully.
148 @retval EFI_INVALID_PARAMETER A required pointer parameter is NULL.
149 @retval EFI_NOT_FOUND FTW working information could not be found.
150
151**/
152EFI_STATUS
153EFIAPI
154GetVariableFlashFtwWorkingInfo (
155 OUT EFI_PHYSICAL_ADDRESS *BaseAddress,
156 OUT UINT64 *Length
157 )
158{
159 EFI_STATUS Status;
160 VARIABLE_FLASH_INFO *VariableFlashInfo;
161
162 if ((BaseAddress == NULL) || (Length == NULL)) {
163 return EFI_INVALID_PARAMETER;
164 }
165
166 Status = GetVariableFlashInfoFromHob (&VariableFlashInfo);
167 if (!EFI_ERROR (Status)) {
168 *BaseAddress = VariableFlashInfo->FtwWorkingBaseAddress;
169 *Length = VariableFlashInfo->FtwWorkingLength;
170 } else {
171 *BaseAddress = (EFI_PHYSICAL_ADDRESS)(PcdGet64 (PcdFlashNvStorageFtwWorkingBase64) != 0 ?
172 PcdGet64 (PcdFlashNvStorageFtwWorkingBase64) :
173 PcdGet32 (PcdFlashNvStorageFtwWorkingBase)
174 );
175 *Length = (UINT64)PcdGet32 (PcdFlashNvStorageFtwWorkingSize);
176 }
177
178 return EFI_SUCCESS;
179}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette