+++ /dev/null
-/*++\r
-Copyright (c) 2006, 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
-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
-\r
-Routine Description:\r
- This routine calls Undi to read the desired number of eeprom bytes.\r
-\r
-Arguments:\r
- snp - pointer to the snp driver structure\r
- RegOffset - eeprom register value relative to the base address\r
- NumBytes - number of bytes to read\r
- BufferPtr - pointer where to read into\r
-\r
-Returns:\r
-\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
-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
-\r
-Routine Description:\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
-Arguments:\r
- this - context pointer\r
- ReadOrWrite - true for reading and false for writing\r
- RegOffset - eeprom register relative to the base\r
- NumBytes - how many bytes to read\r
- BufferPtr - address of memory to read into\r
-\r
-Returns:\r
-\r
---*/\r
-{\r
- SNP_DRIVER *snp;\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
- if (snp == NULL) {\r
- return EFI_DEVICE_ERROR;\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
- return EFI_NOT_STARTED;\r
-\r
- case EfiSimpleNetworkStarted:\r
- return EFI_DEVICE_ERROR;\r
-\r
- default:\r
- return EFI_DEVICE_ERROR;\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
- return EFI_UNSUPPORTED;\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
- return EFI_INVALID_PARAMETER;\r
- }\r
- //\r
- // check the implementation flags of undi if we can write the nvdata!\r
- //\r
- if (!ReadOrWrite) {\r
- return EFI_UNSUPPORTED;\r
- } else {\r
- return pxe_nvdata_read (snp, RegOffset, NumBytes, BufferPtr);\r
- }\r
-}\r