EDK2 doxygen online documents - Firmware Encoding Index 1
EDK2 doxygen online documents - Firmware Encoding Index

MdeModulePkg/Universal/Network/SnpDxe/Nvdata.c

Go to the documentation of this file.
00001 
00016 #include "Snp.h"
00017 
00018 
00033 EFI_STATUS
00034 PxeNvDataRead (
00035   IN SNP_DRIVER *Snp,
00036   IN UINTN      Offset,
00037   IN UINTN      BufferSize,
00038   IN OUT VOID   *Buffer
00039   )
00040 {
00041   PXE_DB_NVDATA *Db;
00042 
00043   Db                  = Snp->Db;
00044   Snp->Cdb.OpCode     = PXE_OPCODE_NVDATA;
00045 
00046   Snp->Cdb.OpFlags    = PXE_OPFLAGS_NVDATA_READ;
00047 
00048   Snp->Cdb.CPBsize    = PXE_CPBSIZE_NOT_USED;
00049   Snp->Cdb.CPBaddr    = PXE_CPBADDR_NOT_USED;
00050 
00051   Snp->Cdb.DBsize     = (UINT16) sizeof (PXE_DB_NVDATA);
00052   Snp->Cdb.DBaddr     = (UINT64)(UINTN) Db;
00053 
00054   Snp->Cdb.StatCode   = PXE_STATCODE_INITIALIZE;
00055   Snp->Cdb.StatFlags  = PXE_STATFLAGS_INITIALIZE;
00056   Snp->Cdb.IFnum      = Snp->IfNum;
00057   Snp->Cdb.Control    = PXE_CONTROL_LAST_CDB_IN_LIST;
00058 
00059   //
00060   // Issue UNDI command and check result.
00061   //
00062   DEBUG ((EFI_D_NET, "\nsnp->undi.nvdata ()  "));
00063 
00064   (*Snp->IssueUndi32Command) ((UINT64)(UINTN) &Snp->Cdb);
00065 
00066   switch (Snp->Cdb.StatCode) {
00067   case PXE_STATCODE_SUCCESS:
00068     break;
00069 
00070   case PXE_STATCODE_UNSUPPORTED:
00071     DEBUG (
00072       (EFI_D_NET,
00073       "\nsnp->undi.nvdata()  %xh:%xh\n",
00074       Snp->Cdb.StatFlags,
00075       Snp->Cdb.StatCode)
00076       );
00077 
00078     return EFI_UNSUPPORTED;
00079 
00080   default:
00081     DEBUG (
00082       (EFI_D_NET,
00083       "\nsnp->undi.nvdata()  %xh:%xh\n",
00084       Snp->Cdb.StatFlags,
00085       Snp->Cdb.StatCode)
00086       );
00087 
00088     return EFI_DEVICE_ERROR;
00089   }
00090 
00091   ASSERT (Offset < sizeof (Db->Data));
00092 
00093   CopyMem (Buffer, &Db->Data.Byte[Offset], BufferSize);
00094 
00095   return EFI_SUCCESS;
00096 }
00097 
00098 
00150 EFI_STATUS
00151 EFIAPI
00152 SnpUndi32NvData (
00153   IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
00154   IN BOOLEAN                     ReadWrite,
00155   IN UINTN                       Offset,
00156   IN UINTN                       BufferSize,
00157   IN OUT VOID                    *Buffer
00158   )
00159 {
00160   SNP_DRIVER  *Snp;
00161   EFI_TPL     OldTpl;
00162   EFI_STATUS  Status;
00163 
00164   //
00165   // Get pointer to SNP driver instance for *this.
00166   //
00167   if (This == NULL) {
00168     return EFI_INVALID_PARAMETER;
00169   }
00170 
00171   Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);
00172 
00173   OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
00174 
00175   //
00176   // Return error if the SNP is not initialized.
00177   //
00178   switch (Snp->Mode.State) {
00179   case EfiSimpleNetworkInitialized:
00180     break;
00181 
00182   case EfiSimpleNetworkStopped:
00183     Status = EFI_NOT_STARTED;
00184     goto ON_EXIT;
00185 
00186   default:
00187     Status = EFI_DEVICE_ERROR;
00188     goto ON_EXIT;
00189   }
00190   //
00191   // Return error if non-volatile memory variables are not valid.
00192   //
00193   if (Snp->Mode.NvRamSize == 0 || Snp->Mode.NvRamAccessSize == 0) {
00194     Status = EFI_UNSUPPORTED;
00195     goto ON_EXIT;
00196   }
00197   //
00198   // Check for invalid parameter combinations.
00199   //
00200   if ((BufferSize == 0) ||
00201       (Buffer == NULL) ||
00202       (Offset >= Snp->Mode.NvRamSize) ||
00203       (Offset + BufferSize > Snp->Mode.NvRamSize) ||
00204       (BufferSize % Snp->Mode.NvRamAccessSize != 0) ||
00205       (Offset % Snp->Mode.NvRamAccessSize != 0)
00206       ) {
00207     Status = EFI_INVALID_PARAMETER;
00208     goto ON_EXIT;
00209   }
00210   //
00211   // check the implementation flags of undi if we can write the nvdata!
00212   //
00213   if (!ReadWrite) {
00214     Status = EFI_UNSUPPORTED;
00215   } else {
00216     Status = PxeNvDataRead (Snp, Offset, BufferSize, Buffer);
00217   }
00218 
00219 ON_EXIT:
00220   gBS->RestoreTPL (OldTpl);
00221 
00222   return Status;
00223 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Defines