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
39 IN OUT VOID
*BufferPtr
45 snp
->cdb
.OpCode
= PXE_OPCODE_NVDATA
;
47 snp
->cdb
.OpFlags
= PXE_OPFLAGS_NVDATA_READ
;
49 snp
->cdb
.CPBsize
= PXE_CPBSIZE_NOT_USED
;
50 snp
->cdb
.CPBaddr
= PXE_CPBADDR_NOT_USED
;
52 snp
->cdb
.DBsize
= sizeof (PXE_DB_NVDATA
);
53 snp
->cdb
.DBaddr
= (UINT64
)(UINTN
) db
;
55 snp
->cdb
.StatCode
= PXE_STATCODE_INITIALIZE
;
56 snp
->cdb
.StatFlags
= PXE_STATFLAGS_INITIALIZE
;
57 snp
->cdb
.IFnum
= snp
->if_num
;
58 snp
->cdb
.Control
= PXE_CONTROL_LAST_CDB_IN_LIST
;
61 // Issue UNDI command and check result.
63 DEBUG ((EFI_D_NET
, "\nsnp->undi.nvdata () "));
65 (*snp
->issue_undi32_command
) ((UINT64
)(UINTN
) &snp
->cdb
);
67 switch (snp
->cdb
.StatCode
) {
68 case PXE_STATCODE_SUCCESS
:
71 case PXE_STATCODE_UNSUPPORTED
:
74 "\nsnp->undi.nvdata() %xh:%xh\n",
79 return EFI_UNSUPPORTED
;
84 "\nsnp->undi.nvdata() %xh:%xh\n",
89 return EFI_DEVICE_ERROR
;
92 CopyMem (BufferPtr
, db
->Data
.Byte
+ RegOffset
, NumBytes
);
99 This is an interface call provided by SNP.
100 It does the basic checking on the input parameters and retrieves snp structure
101 and then calls the read_nvdata() call which does the actual reading
103 @param this context pointer
104 @param ReadOrWrite true for reading and false for writing
105 @param RegOffset eeprom register relative to the base
106 @param NumBytes how many bytes to read
107 @param BufferPtr address of memory to read into
114 IN EFI_SIMPLE_NETWORK_PROTOCOL
*this,
115 IN BOOLEAN ReadOrWrite
,
118 IN OUT VOID
*BufferPtr
126 // Get pointer to SNP driver instance for *this.
129 return EFI_INVALID_PARAMETER
;
132 snp
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this);
134 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
137 // Return error if the SNP is not initialized.
139 switch (snp
->mode
.State
) {
140 case EfiSimpleNetworkInitialized
:
143 case EfiSimpleNetworkStopped
:
144 Status
= EFI_NOT_STARTED
;
148 Status
= EFI_DEVICE_ERROR
;
152 // Return error if non-volatile memory variables are not valid.
154 if (snp
->mode
.NvRamSize
== 0 || snp
->mode
.NvRamAccessSize
== 0) {
155 Status
= EFI_UNSUPPORTED
;
159 // Check for invalid parameter combinations.
161 if ((NumBytes
== 0) ||
162 (BufferPtr
== NULL
) ||
163 (RegOffset
>= snp
->mode
.NvRamSize
) ||
164 (RegOffset
+ NumBytes
> snp
->mode
.NvRamSize
) ||
165 (NumBytes
% snp
->mode
.NvRamAccessSize
!= 0) ||
166 (RegOffset
% snp
->mode
.NvRamAccessSize
!= 0)
168 Status
= EFI_INVALID_PARAMETER
;
172 // check the implementation flags of undi if we can write the nvdata!
175 Status
= EFI_UNSUPPORTED
;
177 Status
= pxe_nvdata_read (snp
, RegOffset
, NumBytes
, BufferPtr
);
181 gBS
->RestoreTPL (OldTpl
);