2 Copyright (c) 2006, Intel Corporation
3 All rights reserved. This program and the accompanying materials
4 are licensed and made available under the terms and conditions of the BSD License
5 which accompanies this distribution. The full text of the license may be found at
6 http://opensource.org/licenses/bsd-license.php
8 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
9 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 2000-Feb-03 M(f)J Genesis.
29 IN OUT VOID
*BufferPtr
34 This routine calls Undi to read the desired number of eeprom bytes.
37 snp - pointer to the snp driver structure
38 RegOffset - eeprom register value relative to the base address
39 NumBytes - number of bytes to read
40 BufferPtr - pointer where to read into
49 snp
->cdb
.OpCode
= PXE_OPCODE_NVDATA
;
51 snp
->cdb
.OpFlags
= PXE_OPFLAGS_NVDATA_READ
;
53 snp
->cdb
.CPBsize
= PXE_CPBSIZE_NOT_USED
;
54 snp
->cdb
.CPBaddr
= PXE_CPBADDR_NOT_USED
;
56 snp
->cdb
.DBsize
= sizeof (PXE_DB_NVDATA
);
57 snp
->cdb
.DBaddr
= (UINT64
) (UINTN
) db
;
59 snp
->cdb
.StatCode
= PXE_STATCODE_INITIALIZE
;
60 snp
->cdb
.StatFlags
= PXE_STATFLAGS_INITIALIZE
;
61 snp
->cdb
.IFnum
= snp
->if_num
;
62 snp
->cdb
.Control
= PXE_CONTROL_LAST_CDB_IN_LIST
;
65 // Issue UNDI command and check result.
67 DEBUG ((EFI_D_NET
, "\nsnp->undi.nvdata () "));
69 (*snp
->issue_undi32_command
) ((UINT64
) (UINTN
) &snp
->cdb
);
71 switch (snp
->cdb
.StatCode
) {
72 case PXE_STATCODE_SUCCESS
:
75 case PXE_STATCODE_UNSUPPORTED
:
78 "\nsnp->undi.nvdata() %xh:%xh\n",
83 return EFI_UNSUPPORTED
;
88 "\nsnp->undi.nvdata() %xh:%xh\n",
93 return EFI_DEVICE_ERROR
;
96 CopyMem (BufferPtr
, db
->Data
.Byte
+ RegOffset
, NumBytes
);
104 IN EFI_SIMPLE_NETWORK_PROTOCOL
*this,
105 IN BOOLEAN ReadOrWrite
,
108 IN OUT VOID
*BufferPtr
113 This is an interface call provided by SNP.
114 It does the basic checking on the input parameters and retrieves snp structure
115 and then calls the read_nvdata() call which does the actual reading
118 this - context pointer
119 ReadOrWrite - true for reading and false for writing
120 RegOffset - eeprom register relative to the base
121 NumBytes - how many bytes to read
122 BufferPtr - address of memory to read into
131 // Get pointer to SNP driver instance for *this.
134 return EFI_INVALID_PARAMETER
;
137 snp
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this);
140 return EFI_DEVICE_ERROR
;
143 // Return error if the SNP is not initialized.
145 switch (snp
->mode
.State
) {
146 case EfiSimpleNetworkInitialized
:
149 case EfiSimpleNetworkStopped
:
150 return EFI_NOT_STARTED
;
152 case EfiSimpleNetworkStarted
:
153 return EFI_DEVICE_ERROR
;
156 return EFI_DEVICE_ERROR
;
159 // Return error if non-volatile memory variables are not valid.
161 if (snp
->mode
.NvRamSize
== 0 || snp
->mode
.NvRamAccessSize
== 0) {
162 return EFI_UNSUPPORTED
;
165 // Check for invalid parameter combinations.
167 if ((NumBytes
== 0) ||
168 (BufferPtr
== NULL
) ||
169 (RegOffset
>= snp
->mode
.NvRamSize
) ||
170 (RegOffset
+ NumBytes
> snp
->mode
.NvRamSize
) ||
171 (NumBytes
% snp
->mode
.NvRamAccessSize
!= 0) ||
172 (RegOffset
% snp
->mode
.NvRamAccessSize
!= 0)
174 return EFI_INVALID_PARAMETER
;
177 // check the implementation flags of undi if we can write the nvdata!
180 return EFI_UNSUPPORTED
;
182 return pxe_nvdata_read (snp
, RegOffset
, NumBytes
, BufferPtr
);