2 Copyright (c) 2004 - 2007, 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.
25 This routine calls Undi to read the desired number of eeprom bytes.
27 @param snp pointer to the snp driver structure
28 @param RegOffset eeprom register value relative to the base address
29 @param NumBytes number of bytes to read
30 @param BufferPtr pointer where to read into
40 IN OUT VOID
*BufferPtr
46 snp
->cdb
.OpCode
= PXE_OPCODE_NVDATA
;
48 snp
->cdb
.OpFlags
= PXE_OPFLAGS_NVDATA_READ
;
50 snp
->cdb
.CPBsize
= PXE_CPBSIZE_NOT_USED
;
51 snp
->cdb
.CPBaddr
= PXE_CPBADDR_NOT_USED
;
53 snp
->cdb
.DBsize
= sizeof (PXE_DB_NVDATA
);
54 snp
->cdb
.DBaddr
= (UINT64
)(UINTN
) db
;
56 snp
->cdb
.StatCode
= PXE_STATCODE_INITIALIZE
;
57 snp
->cdb
.StatFlags
= PXE_STATFLAGS_INITIALIZE
;
58 snp
->cdb
.IFnum
= snp
->if_num
;
59 snp
->cdb
.Control
= PXE_CONTROL_LAST_CDB_IN_LIST
;
62 // Issue UNDI command and check result.
64 DEBUG ((EFI_D_NET
, "\nsnp->undi.nvdata () "));
66 (*snp
->issue_undi32_command
) ((UINT64
)(UINTN
) &snp
->cdb
);
68 switch (snp
->cdb
.StatCode
) {
69 case PXE_STATCODE_SUCCESS
:
72 case PXE_STATCODE_UNSUPPORTED
:
75 "\nsnp->undi.nvdata() %xh:%xh\n",
80 return EFI_UNSUPPORTED
;
85 "\nsnp->undi.nvdata() %xh:%xh\n",
90 return EFI_DEVICE_ERROR
;
93 CopyMem (BufferPtr
, db
->Data
.Byte
+ RegOffset
, NumBytes
);
100 This is an interface call provided by SNP.
101 It does the basic checking on the input parameters and retrieves snp structure
102 and then calls the read_nvdata() call which does the actual reading
104 @param this context pointer
105 @param ReadOrWrite true for reading and false for writing
106 @param RegOffset eeprom register relative to the base
107 @param NumBytes how many bytes to read
108 @param BufferPtr address of memory to read into
115 IN EFI_SIMPLE_NETWORK_PROTOCOL
*this,
116 IN BOOLEAN ReadOrWrite
,
119 IN OUT VOID
*BufferPtr
127 // Get pointer to SNP driver instance for *this.
130 return EFI_INVALID_PARAMETER
;
133 snp
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this);
135 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
138 // Return error if the SNP is not initialized.
140 switch (snp
->mode
.State
) {
141 case EfiSimpleNetworkInitialized
:
144 case EfiSimpleNetworkStopped
:
145 Status
= EFI_NOT_STARTED
;
149 Status
= EFI_DEVICE_ERROR
;
153 // Return error if non-volatile memory variables are not valid.
155 if (snp
->mode
.NvRamSize
== 0 || snp
->mode
.NvRamAccessSize
== 0) {
156 Status
= EFI_UNSUPPORTED
;
160 // Check for invalid parameter combinations.
162 if ((NumBytes
== 0) ||
163 (BufferPtr
== NULL
) ||
164 (RegOffset
>= snp
->mode
.NvRamSize
) ||
165 (RegOffset
+ NumBytes
> snp
->mode
.NvRamSize
) ||
166 (NumBytes
% snp
->mode
.NvRamAccessSize
!= 0) ||
167 (RegOffset
% snp
->mode
.NvRamAccessSize
!= 0)
169 Status
= EFI_INVALID_PARAMETER
;
173 // check the implementation flags of undi if we can write the nvdata!
176 Status
= EFI_UNSUPPORTED
;
178 Status
= pxe_nvdata_read (snp
, RegOffset
, NumBytes
, BufferPtr
);
182 gBS
->RestoreTPL (OldTpl
);