]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/SnpDxe/Nvdata.c
Roll back the DEBUG mask change which cause SerialIo read_conf test item failure.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / SnpDxe / Nvdata.c
1 /** @file
2 Implementation of reading and writing operations on the NVRAM device
3 attached to a network interface.
4
5 Copyright (c) 2004 - 2007, Intel Corporation. <BR>
6 All rights reserved. This program and the accompanying materials are licensed
7 and made available under the terms and conditions of the BSD License which
8 accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #include "Snp.h"
17
18
19 /**
20 This routine calls Undi to read the desired number of eeprom bytes.
21
22 @param Snp pointer to the snp driver structure
23 @param Offset eeprom register value relative to the base address
24 @param BufferSize number of bytes to read
25 @param Buffer pointer where to read into
26
27 @retval EFI_SUCCESS The NVRAM access was performed.
28 @retval EFI_INVALID_PARAMETER Invalid UNDI command.
29 @retval EFI_UNSUPPORTED Command is not supported by UNDI.
30 @retval EFI_DEVICE_ERROR Fail to execute UNDI command.
31
32 **/
33 EFI_STATUS
34 PxeNvDataRead (
35 IN SNP_DRIVER *Snp,
36 IN UINTN Offset,
37 IN UINTN BufferSize,
38 IN OUT VOID *Buffer
39 )
40 {
41 PXE_DB_NVDATA *Db;
42
43 Db = Snp->Db;
44 Snp->Cdb.OpCode = PXE_OPCODE_NVDATA;
45
46 Snp->Cdb.OpFlags = PXE_OPFLAGS_NVDATA_READ;
47
48 Snp->Cdb.CPBsize = PXE_CPBSIZE_NOT_USED;
49 Snp->Cdb.CPBaddr = PXE_CPBADDR_NOT_USED;
50
51 Snp->Cdb.DBsize = sizeof (PXE_DB_NVDATA);
52 Snp->Cdb.DBaddr = (UINT64)(UINTN) Db;
53
54 Snp->Cdb.StatCode = PXE_STATCODE_INITIALIZE;
55 Snp->Cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;
56 Snp->Cdb.IFnum = Snp->IfNum;
57 Snp->Cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;
58
59 //
60 // Issue UNDI command and check result.
61 //
62 DEBUG ((EFI_D_NET, "\nsnp->undi.nvdata () "));
63
64 (*Snp->IssueUndi32Command) ((UINT64)(UINTN) &Snp->Cdb);
65
66 switch (Snp->Cdb.StatCode) {
67 case PXE_STATCODE_SUCCESS:
68 break;
69
70 case PXE_STATCODE_UNSUPPORTED:
71 DEBUG (
72 (EFI_D_NET,
73 "\nsnp->undi.nvdata() %xh:%xh\n",
74 Snp->Cdb.StatFlags,
75 Snp->Cdb.StatCode)
76 );
77
78 return EFI_UNSUPPORTED;
79
80 default:
81 DEBUG (
82 (EFI_D_NET,
83 "\nsnp->undi.nvdata() %xh:%xh\n",
84 Snp->Cdb.StatFlags,
85 Snp->Cdb.StatCode)
86 );
87
88 return EFI_DEVICE_ERROR;
89 }
90
91 CopyMem (Buffer, Db->Data.Byte + Offset, BufferSize);
92
93 return EFI_SUCCESS;
94 }
95
96
97 /**
98 Performs read and write operations on the NVRAM device attached to a network
99 interface.
100
101 This function performs read and write operations on the NVRAM device attached
102 to a network interface. If ReadWrite is TRUE, a read operation is performed.
103 If ReadWrite is FALSE, a write operation is performed. Offset specifies the
104 byte offset at which to start either operation. Offset must be a multiple of
105 NvRamAccessSize , and it must have a value between zero and NvRamSize.
106 BufferSize specifies the length of the read or write operation. BufferSize must
107 also be a multiple of NvRamAccessSize, and Offset + BufferSize must not exceed
108 NvRamSize.
109 If any of the above conditions is not met, then EFI_INVALID_PARAMETER will be
110 returned.
111 If all the conditions are met and the operation is "read," the NVRAM device
112 attached to the network interface will be read into Buffer and EFI_SUCCESS
113 will be returned. If this is a write operation, the contents of Buffer will be
114 used to update the contents of the NVRAM device attached to the network
115 interface and EFI_SUCCESS will be returned.
116
117 It does the basic checking on the input parameters and retrieves snp structure
118 and then calls the read_nvdata() call which does the actual reading
119
120 @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.
121 @param ReadWrite TRUE for read operations, FALSE for write operations.
122 @param Offset Byte offset in the NVRAM device at which to start the read or
123 write operation. This must be a multiple of NvRamAccessSize
124 and less than NvRamSize. (See EFI_SIMPLE_NETWORK_MODE)
125 @param BufferSize The number of bytes to read or write from the NVRAM device.
126 This must also be a multiple of NvramAccessSize.
127 @param Buffer A pointer to the data buffer.
128
129 @retval EFI_SUCCESS The NVRAM access was performed.
130 @retval EFI_NOT_STARTED The network interface has not been started.
131 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
132 * The This parameter is NULL
133 * The This parameter does not point to a valid
134 EFI_SIMPLE_NETWORK_PROTOCOL structure
135 * The Offset parameter is not a multiple of
136 EFI_SIMPLE_NETWORK_MODE.NvRamAccessSize
137 * The Offset parameter is not less than
138 EFI_SIMPLE_NETWORK_MODE.NvRamSize
139 * The BufferSize parameter is not a multiple of
140 EFI_SIMPLE_NETWORK_MODE.NvRamAccessSize
141 * The Buffer parameter is NULL
142 @retval EFI_DEVICE_ERROR The command could not be sent to the network
143 interface.
144 @retval EFI_UNSUPPORTED This function is not supported by the network
145 interface.
146
147 **/
148 EFI_STATUS
149 EFIAPI
150 SnpUndi32NvData (
151 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
152 IN BOOLEAN ReadWrite,
153 IN UINTN Offset,
154 IN UINTN BufferSize,
155 IN OUT VOID *Buffer
156 )
157 {
158 SNP_DRIVER *Snp;
159 EFI_TPL OldTpl;
160 EFI_STATUS Status;
161
162 //
163 // Get pointer to SNP driver instance for *this.
164 //
165 if (This == NULL) {
166 return EFI_INVALID_PARAMETER;
167 }
168
169 Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);
170
171 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
172
173 //
174 // Return error if the SNP is not initialized.
175 //
176 switch (Snp->Mode.State) {
177 case EfiSimpleNetworkInitialized:
178 break;
179
180 case EfiSimpleNetworkStopped:
181 Status = EFI_NOT_STARTED;
182 goto ON_EXIT;
183
184 default:
185 Status = EFI_DEVICE_ERROR;
186 goto ON_EXIT;
187 }
188 //
189 // Return error if non-volatile memory variables are not valid.
190 //
191 if (Snp->Mode.NvRamSize == 0 || Snp->Mode.NvRamAccessSize == 0) {
192 Status = EFI_UNSUPPORTED;
193 goto ON_EXIT;
194 }
195 //
196 // Check for invalid parameter combinations.
197 //
198 if ((BufferSize == 0) ||
199 (Buffer == NULL) ||
200 (Offset >= Snp->Mode.NvRamSize) ||
201 (Offset + BufferSize > Snp->Mode.NvRamSize) ||
202 (BufferSize % Snp->Mode.NvRamAccessSize != 0) ||
203 (Offset % Snp->Mode.NvRamAccessSize != 0)
204 ) {
205 Status = EFI_INVALID_PARAMETER;
206 goto ON_EXIT;
207 }
208 //
209 // check the implementation flags of undi if we can write the nvdata!
210 //
211 if (!ReadWrite) {
212 Status = EFI_UNSUPPORTED;
213 } else {
214 Status = PxeNvDataRead (Snp, Offset, BufferSize, Buffer);
215 }
216
217 ON_EXIT:
218 gBS->RestoreTPL (OldTpl);
219
220 return Status;
221 }