TianoCore EDK2 master
Loading...
Searching...
No Matches
Nvdata.c
Go to the documentation of this file.
1
10#include "Snp.h"
11
28 IN SNP_DRIVER *Snp,
29 IN UINTN Offset,
30 IN UINTN BufferSize,
31 IN OUT VOID *Buffer
32 )
33{
34 PXE_DB_NVDATA *Db;
35
36 Db = Snp->Db;
37 Snp->Cdb.OpCode = PXE_OPCODE_NVDATA;
38
39 Snp->Cdb.OpFlags = PXE_OPFLAGS_NVDATA_READ;
40
41 Snp->Cdb.CPBsize = PXE_CPBSIZE_NOT_USED;
42 Snp->Cdb.CPBaddr = PXE_CPBADDR_NOT_USED;
43
44 Snp->Cdb.DBsize = (UINT16)sizeof (PXE_DB_NVDATA);
45 Snp->Cdb.DBaddr = (UINT64)(UINTN)Db;
46
47 Snp->Cdb.StatCode = PXE_STATCODE_INITIALIZE;
48 Snp->Cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;
49 Snp->Cdb.IFnum = Snp->IfNum;
50 Snp->Cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;
51
52 //
53 // Issue UNDI command and check result.
54 //
55 DEBUG ((DEBUG_NET, "\nsnp->undi.nvdata () "));
56
57 (*Snp->IssueUndi32Command)((UINT64)(UINTN)&Snp->Cdb);
58
59 switch (Snp->Cdb.StatCode) {
61 break;
62
63 case PXE_STATCODE_UNSUPPORTED:
64 DEBUG (
65 (DEBUG_NET,
66 "\nsnp->undi.nvdata() %xh:%xh\n",
67 Snp->Cdb.StatFlags,
68 Snp->Cdb.StatCode)
69 );
70
71 return EFI_UNSUPPORTED;
72
73 default:
74 DEBUG (
75 (DEBUG_NET,
76 "\nsnp->undi.nvdata() %xh:%xh\n",
77 Snp->Cdb.StatFlags,
78 Snp->Cdb.StatCode)
79 );
80
81 return EFI_DEVICE_ERROR;
82 }
83
84 ASSERT (Offset < sizeof (Db->Data));
85
86 CopyMem (Buffer, &Db->Data.Byte[Offset], BufferSize);
87
88 return EFI_SUCCESS;
89}
90
143EFIAPI
146 IN BOOLEAN ReadWrite,
147 IN UINTN Offset,
148 IN UINTN BufferSize,
149 IN OUT VOID *Buffer
150 )
151{
152 SNP_DRIVER *Snp;
153 EFI_TPL OldTpl;
154 EFI_STATUS Status;
155
156 //
157 // Get pointer to SNP driver instance for *this.
158 //
159 if (This == NULL) {
160 return EFI_INVALID_PARAMETER;
161 }
162
163 Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);
164
165 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
166
167 //
168 // Return error if the SNP is not initialized.
169 //
170 switch (Snp->Mode.State) {
171 case EfiSimpleNetworkInitialized:
172 break;
173
174 case EfiSimpleNetworkStopped:
175 Status = EFI_NOT_STARTED;
176 goto ON_EXIT;
177
178 default:
179 Status = EFI_DEVICE_ERROR;
180 goto ON_EXIT;
181 }
182
183 //
184 // Return error if non-volatile memory variables are not valid.
185 //
186 if ((Snp->Mode.NvRamSize == 0) || (Snp->Mode.NvRamAccessSize == 0)) {
187 Status = EFI_UNSUPPORTED;
188 goto ON_EXIT;
189 }
190
191 //
192 // Check for invalid parameter combinations.
193 //
194 if ((BufferSize == 0) ||
195 (Buffer == NULL) ||
196 (Offset >= Snp->Mode.NvRamSize) ||
197 (Offset + BufferSize > Snp->Mode.NvRamSize) ||
198 (BufferSize % Snp->Mode.NvRamAccessSize != 0) ||
199 (Offset % Snp->Mode.NvRamAccessSize != 0)
200 )
201 {
202 Status = EFI_INVALID_PARAMETER;
203 goto ON_EXIT;
204 }
205
206 //
207 // check the implementation flags of undi if we can write the nvdata!
208 //
209 if (!ReadWrite) {
210 Status = EFI_UNSUPPORTED;
211 } else {
212 Status = PxeNvDataRead (Snp, Offset, BufferSize, Buffer);
213 }
214
215ON_EXIT:
216 gBS->RestoreTPL (OldTpl);
217
218 return Status;
219}
UINT64 UINTN
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:434
EFI_STATUS EFIAPI SnpUndi32NvData(IN EFI_SIMPLE_NETWORK_PROTOCOL *This, IN BOOLEAN ReadWrite, IN UINTN Offset, IN UINTN BufferSize, IN OUT VOID *Buffer)
Definition: Nvdata.c:144
EFI_STATUS PxeNvDataRead(IN SNP_DRIVER *Snp, IN UINTN Offset, IN UINTN BufferSize, IN OUT VOID *Buffer)
Definition: Nvdata.c:27
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
UINTN EFI_TPL
Definition: UefiBaseType.h:41
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
#define PXE_CPBSIZE_NOT_USED
zero
Definition: UefiPxe.h:57
#define PXE_CPBADDR_NOT_USED
zero
Definition: UefiPxe.h:59
#define PXE_OPCODE_NVDATA
Definition: UefiPxe.h:150
#define PXE_STATCODE_SUCCESS
Definition: UefiPxe.h:602
Definition: Snp.h:55
union s_pxe_db_nvdata::@1059 Data
PXE_UINT8 Byte[MAX_EEPROM_LEN<< 2]
Definition: UefiPxe.h:1536