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