--- /dev/null
+/** @file\r
+Copyright (c) 2004 - 2007, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution. The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+Module name:\r
+ nvdata.c\r
+\r
+Abstract:\r
+\r
+Revision history:\r
+ 2000-Feb-03 M(f)J Genesis.\r
+\r
+**/\r
+\r
+#include "snp.h"\r
+\r
+\r
+/**\r
+ This routine calls Undi to read the desired number of eeprom bytes.\r
+\r
+ @param snp pointer to the snp driver structure\r
+ @param RegOffset eeprom register value relative to the base address\r
+ @param NumBytes number of bytes to read\r
+ @param BufferPtr pointer where to read into\r
+\r
+\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+pxe_nvdata_read (\r
+ IN SNP_DRIVER *snp,\r
+ IN UINTN RegOffset,\r
+ IN UINTN NumBytes,\r
+ IN OUT VOID *BufferPtr\r
+ )\r
+{\r
+ PXE_DB_NVDATA *db;\r
+\r
+ db = snp->db;\r
+ snp->cdb.OpCode = PXE_OPCODE_NVDATA;\r
+\r
+ snp->cdb.OpFlags = PXE_OPFLAGS_NVDATA_READ;\r
+\r
+ snp->cdb.CPBsize = PXE_CPBSIZE_NOT_USED;\r
+ snp->cdb.CPBaddr = PXE_CPBADDR_NOT_USED;\r
+\r
+ snp->cdb.DBsize = sizeof (PXE_DB_NVDATA);\r
+ snp->cdb.DBaddr = (UINT64)(UINTN) db;\r
+\r
+ snp->cdb.StatCode = PXE_STATCODE_INITIALIZE;\r
+ snp->cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;\r
+ snp->cdb.IFnum = snp->if_num;\r
+ snp->cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;\r
+\r
+ //\r
+ // Issue UNDI command and check result.\r
+ //\r
+ DEBUG ((EFI_D_NET, "\nsnp->undi.nvdata () "));\r
+\r
+ (*snp->issue_undi32_command) ((UINT64)(UINTN) &snp->cdb);\r
+\r
+ switch (snp->cdb.StatCode) {\r
+ case PXE_STATCODE_SUCCESS:\r
+ break;\r
+\r
+ case PXE_STATCODE_UNSUPPORTED:\r
+ DEBUG (\r
+ (EFI_D_NET,\r
+ "\nsnp->undi.nvdata() %xh:%xh\n",\r
+ snp->cdb.StatFlags,\r
+ snp->cdb.StatCode)\r
+ );\r
+\r
+ return EFI_UNSUPPORTED;\r
+\r
+ default:\r
+ DEBUG (\r
+ (EFI_D_NET,\r
+ "\nsnp->undi.nvdata() %xh:%xh\n",\r
+ snp->cdb.StatFlags,\r
+ snp->cdb.StatCode)\r
+ );\r
+\r
+ return EFI_DEVICE_ERROR;\r
+ }\r
+\r
+ CopyMem (BufferPtr, db->Data.Byte + RegOffset, NumBytes);\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+ This is an interface call provided by SNP.\r
+ It does the basic checking on the input parameters and retrieves snp structure\r
+ and then calls the read_nvdata() call which does the actual reading\r
+\r
+ @param this context pointer\r
+ @param ReadOrWrite true for reading and false for writing\r
+ @param RegOffset eeprom register relative to the base\r
+ @param NumBytes how many bytes to read\r
+ @param BufferPtr address of memory to read into\r
+\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+snp_undi32_nvdata (\r
+ IN EFI_SIMPLE_NETWORK_PROTOCOL *this,\r
+ IN BOOLEAN ReadOrWrite,\r
+ IN UINTN RegOffset,\r
+ IN UINTN NumBytes,\r
+ IN OUT VOID *BufferPtr\r
+ )\r
+{\r
+ SNP_DRIVER *snp;\r
+ EFI_TPL OldTpl;\r
+ EFI_STATUS Status;\r
+\r
+ //\r
+ // Get pointer to SNP driver instance for *this.\r
+ //\r
+ if (this == NULL) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this);\r
+\r
+ OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+\r
+ //\r
+ // Return error if the SNP is not initialized.\r
+ //\r
+ switch (snp->mode.State) {\r
+ case EfiSimpleNetworkInitialized:\r
+ break;\r
+\r
+ case EfiSimpleNetworkStopped:\r
+ Status = EFI_NOT_STARTED;\r
+ goto ON_EXIT;\r
+\r
+ default:\r
+ Status = EFI_DEVICE_ERROR;\r
+ goto ON_EXIT;\r
+ }\r
+ //\r
+ // Return error if non-volatile memory variables are not valid.\r
+ //\r
+ if (snp->mode.NvRamSize == 0 || snp->mode.NvRamAccessSize == 0) {\r
+ Status = EFI_UNSUPPORTED;\r
+ goto ON_EXIT;\r
+ }\r
+ //\r
+ // Check for invalid parameter combinations.\r
+ //\r
+ if ((NumBytes == 0) ||\r
+ (BufferPtr == NULL) ||\r
+ (RegOffset >= snp->mode.NvRamSize) ||\r
+ (RegOffset + NumBytes > snp->mode.NvRamSize) ||\r
+ (NumBytes % snp->mode.NvRamAccessSize != 0) ||\r
+ (RegOffset % snp->mode.NvRamAccessSize != 0)\r
+ ) {\r
+ Status = EFI_INVALID_PARAMETER;\r
+ goto ON_EXIT;\r
+ }\r
+ //\r
+ // check the implementation flags of undi if we can write the nvdata!\r
+ //\r
+ if (!ReadOrWrite) {\r
+ Status = EFI_UNSUPPORTED;\r
+ } else {\r
+ Status = pxe_nvdata_read (snp, RegOffset, NumBytes, BufferPtr);\r
+ }\r
+\r
+ON_EXIT:\r
+ gBS->RestoreTPL (OldTpl);\r
+\r
+ return Status;\r
+}\r