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.
28 IN OUT VOID
*BufferPtr
33 This routine calls Undi to read the desired number of eeprom bytes.
36 snp - pointer to the snp driver structure
37 RegOffset - eeprom register value relative to the base address
38 NumBytes - number of bytes to read
39 BufferPtr - pointer where to read into
48 snp
->cdb
.OpCode
= PXE_OPCODE_NVDATA
;
50 snp
->cdb
.OpFlags
= PXE_OPFLAGS_NVDATA_READ
;
52 snp
->cdb
.CPBsize
= PXE_CPBSIZE_NOT_USED
;
53 snp
->cdb
.CPBaddr
= PXE_CPBADDR_NOT_USED
;
55 snp
->cdb
.DBsize
= sizeof (PXE_DB_NVDATA
);
56 snp
->cdb
.DBaddr
= (UINT64
) (UINTN
) db
;
58 snp
->cdb
.StatCode
= PXE_STATCODE_INITIALIZE
;
59 snp
->cdb
.StatFlags
= PXE_STATFLAGS_INITIALIZE
;
60 snp
->cdb
.IFnum
= snp
->if_num
;
61 snp
->cdb
.Control
= PXE_CONTROL_LAST_CDB_IN_LIST
;
64 // Issue UNDI command and check result.
66 DEBUG ((EFI_D_NET
, "\nsnp->undi.nvdata () "));
68 (*snp
->issue_undi32_command
) ((UINT64
) (UINTN
) &snp
->cdb
);
70 switch (snp
->cdb
.StatCode
) {
71 case PXE_STATCODE_SUCCESS
:
74 case PXE_STATCODE_UNSUPPORTED
:
77 "\nsnp->undi.nvdata() %xh:%xh\n",
82 return EFI_UNSUPPORTED
;
87 "\nsnp->undi.nvdata() %xh:%xh\n",
92 return EFI_DEVICE_ERROR
;
95 CopyMem (BufferPtr
, db
->Data
.Byte
+ RegOffset
, NumBytes
);
103 IN EFI_SIMPLE_NETWORK_PROTOCOL
*this,
104 IN BOOLEAN ReadOrWrite
,
107 IN OUT VOID
*BufferPtr
112 This is an interface call provided by SNP.
113 It does the basic checking on the input parameters and retrieves snp structure
114 and then calls the read_nvdata() call which does the actual reading
117 this - context pointer
118 ReadOrWrite - true for reading and false for writing
119 RegOffset - eeprom register relative to the base
120 NumBytes - how many bytes to read
121 BufferPtr - address of memory to read into
130 // Get pointer to SNP driver instance for *this.
133 return EFI_INVALID_PARAMETER
;
136 snp
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this);
139 return EFI_DEVICE_ERROR
;
142 // Return error if the SNP is not initialized.
144 switch (snp
->mode
.State
) {
145 case EfiSimpleNetworkInitialized
:
148 case EfiSimpleNetworkStopped
:
149 return EFI_NOT_STARTED
;
151 case EfiSimpleNetworkStarted
:
152 return EFI_DEVICE_ERROR
;
155 return EFI_DEVICE_ERROR
;
158 // Return error if non-volatile memory variables are not valid.
160 if (snp
->mode
.NvRamSize
== 0 || snp
->mode
.NvRamAccessSize
== 0) {
161 return EFI_UNSUPPORTED
;
164 // Check for invalid parameter combinations.
166 if ((NumBytes
== 0) ||
167 (BufferPtr
== NULL
) ||
168 (RegOffset
>= snp
->mode
.NvRamSize
) ||
169 (RegOffset
+ NumBytes
> snp
->mode
.NvRamSize
) ||
170 (NumBytes
% snp
->mode
.NvRamAccessSize
!= 0) ||
171 (RegOffset
% snp
->mode
.NvRamAccessSize
!= 0)
173 return EFI_INVALID_PARAMETER
;
176 // check the implementation flags of undi if we can write the nvdata!
179 return EFI_UNSUPPORTED
;
181 return pxe_nvdata_read (snp
, RegOffset
, NumBytes
, BufferPtr
);