+++ /dev/null
-/** @file\r
- Implementation of reading and writing operations on the NVRAM device\r
- attached to a network interface.\r
-\r
-Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>\r
-SPDX-License-Identifier: BSD-2-Clause-Patent\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 Offset eeprom register value relative to the base address\r
- @param BufferSize number of bytes to read\r
- @param Buffer pointer where to read into\r
-\r
- @retval EFI_SUCCESS The NVRAM access was performed.\r
- @retval EFI_INVALID_PARAMETER Invalid UNDI command.\r
- @retval EFI_UNSUPPORTED Command is not supported by UNDI.\r
- @retval EFI_DEVICE_ERROR Fail to execute UNDI command.\r
-\r
-**/\r
-EFI_STATUS\r
-PxeNvDataRead (\r
- IN SNP_DRIVER *Snp,\r
- IN UINTN Offset,\r
- IN UINTN BufferSize,\r
- IN OUT VOID *Buffer\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 = (UINT16) 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->IfNum;\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->IssueUndi32Command) ((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
- ASSERT (Offset < sizeof (Db->Data));\r
-\r
- CopyMem (Buffer, &Db->Data.Byte[Offset], BufferSize);\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-\r
-/**\r
- Performs read and write operations on the NVRAM device attached to a network\r
- interface.\r
-\r
- This function performs read and write operations on the NVRAM device attached\r
- to a network interface. If ReadWrite is TRUE, a read operation is performed.\r
- If ReadWrite is FALSE, a write operation is performed. Offset specifies the\r
- byte offset at which to start either operation. Offset must be a multiple of\r
- NvRamAccessSize , and it must have a value between zero and NvRamSize.\r
- BufferSize specifies the length of the read or write operation. BufferSize must\r
- also be a multiple of NvRamAccessSize, and Offset + BufferSize must not exceed\r
- NvRamSize.\r
- If any of the above conditions is not met, then EFI_INVALID_PARAMETER will be\r
- returned.\r
- If all the conditions are met and the operation is "read," the NVRAM device\r
- attached to the network interface will be read into Buffer and EFI_SUCCESS\r
- will be returned. If this is a write operation, the contents of Buffer will be\r
- used to update the contents of the NVRAM device attached to the network\r
- interface and EFI_SUCCESS will be returned.\r
-\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 A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.\r
- @param ReadWrite TRUE for read operations, FALSE for write operations.\r
- @param Offset Byte offset in the NVRAM device at which to start the read or\r
- write operation. This must be a multiple of NvRamAccessSize\r
- and less than NvRamSize. (See EFI_SIMPLE_NETWORK_MODE)\r
- @param BufferSize The number of bytes to read or write from the NVRAM device.\r
- This must also be a multiple of NvramAccessSize.\r
- @param Buffer A pointer to the data buffer.\r
-\r
- @retval EFI_SUCCESS The NVRAM access was performed.\r
- @retval EFI_NOT_STARTED The network interface has not been started.\r
- @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r
- * The This parameter is NULL\r
- * The This parameter does not point to a valid\r
- EFI_SIMPLE_NETWORK_PROTOCOL structure\r
- * The Offset parameter is not a multiple of\r
- EFI_SIMPLE_NETWORK_MODE.NvRamAccessSize\r
- * The Offset parameter is not less than\r
- EFI_SIMPLE_NETWORK_MODE.NvRamSize\r
- * The BufferSize parameter is not a multiple of\r
- EFI_SIMPLE_NETWORK_MODE.NvRamAccessSize\r
- * The Buffer parameter is NULL\r
- @retval EFI_DEVICE_ERROR The command could not be sent to the network\r
- interface.\r
- @retval EFI_UNSUPPORTED This function is not supported by the network\r
- interface.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SnpUndi32NvData (\r
- IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
- IN BOOLEAN ReadWrite,\r
- IN UINTN Offset,\r
- IN UINTN BufferSize,\r
- IN OUT VOID *Buffer\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 ((BufferSize == 0) ||\r
- (Buffer == NULL) ||\r
- (Offset >= Snp->Mode.NvRamSize) ||\r
- (Offset + BufferSize > Snp->Mode.NvRamSize) ||\r
- (BufferSize % Snp->Mode.NvRamAccessSize != 0) ||\r
- (Offset % 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 (!ReadWrite) {\r
- Status = EFI_UNSUPPORTED;\r
- } else {\r
- Status = PxeNvDataRead (Snp, Offset, BufferSize, Buffer);\r
- }\r
-\r
-ON_EXIT:\r
- gBS->RestoreTPL (OldTpl);\r
-\r
- return Status;\r
-}\r