TianoCore EDK2 master
Loading...
Searching...
No Matches
BaseVariableFlashInfoLib.c
Go to the documentation of this file.
1
10#include <Uefi.h>
11#include <Pi/PiMultiPhase.h>
13#include <Library/DebugLib.h>
14#include <Library/HobLib.h>
16
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 //
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
71EFIAPI
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
112EFIAPI
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
153EFIAPI
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}
VOID *EFIAPI GetFirstGuidHob(IN CONST EFI_GUID *Guid)
Definition: HobLib.c:215
VOID *EFIAPI GetNextGuidHob(IN CONST EFI_GUID *Guid, IN CONST VOID *HobStart)
Definition: HobLib.c:176
STATIC EFI_STATUS GetVariableFlashInfoFromHob(OUT VARIABLE_FLASH_INFO **VariableFlashInfo)
EFI_STATUS EFIAPI GetVariableFlashFtwWorkingInfo(OUT EFI_PHYSICAL_ADDRESS *BaseAddress, OUT UINT64 *Length)
EFI_STATUS EFIAPI GetVariableFlashFtwSpareInfo(OUT EFI_PHYSICAL_ADDRESS *BaseAddress, OUT UINT64 *Length)
EFI_STATUS EFIAPI GetVariableFlashNvStorageInfo(OUT EFI_PHYSICAL_ADDRESS *BaseAddress, OUT UINT64 *Length)
#define NULL
Definition: Base.h:319
#define STATIC
Definition: Base.h:264
#define FALSE
Definition: Base.h:307
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define DEBUG_CODE(Expression)
Definition: DebugLib.h:590
#define PcdGet64(TokenName)
Definition: PcdLib.h:375
#define PcdGet32(TokenName)
Definition: PcdLib.h:362
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_PHYSICAL_ADDRESS FtwWorkingBaseAddress
EFI_PHYSICAL_ADDRESS NvVariableBaseAddress
EFI_PHYSICAL_ADDRESS FtwSpareBaseAddress