]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Network/SnpDxe/Nvdata.c
Update the copyright notice format
[mirror_edk2.git] / MdeModulePkg / Universal / Network / SnpDxe / Nvdata.c
CommitLineData
d007c0a2 1/** @file\r
890986ca 2 Implementation of reading and writing operations on the NVRAM device\r
3 attached to a network interface.\r
4cda7726 4 \r
e5eed7d3
HT
5Copyright (c) 2004 - 2009, Intel Corporation. All rights reserved.<BR>\r
6This program and the accompanying materials are licensed \r
4cda7726 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
7b0ae7e8 91 ASSERT (Offset < sizeof (Db->Data));\r
890986ca 92\r
7b0ae7e8 93 CopyMem (Buffer, &Db->Data.Byte[Offset], BufferSize);\r
d007c0a2 94\r
95 return EFI_SUCCESS;\r
96}\r
97\r
98\r
99/**\r
4cda7726 100 Performs read and write operations on the NVRAM device attached to a network \r
101 interface.\r
102 \r
103 This function performs read and write operations on the NVRAM device attached \r
104 to a network interface. If ReadWrite is TRUE, a read operation is performed.\r
105 If ReadWrite is FALSE, a write operation is performed. Offset specifies the \r
106 byte offset at which to start either operation. Offset must be a multiple of \r
107 NvRamAccessSize , and it must have a value between zero and NvRamSize. \r
108 BufferSize specifies the length of the read or write operation. BufferSize must\r
109 also be a multiple of NvRamAccessSize, and Offset + BufferSize must not exceed\r
110 NvRamSize. \r
111 If any of the above conditions is not met, then EFI_INVALID_PARAMETER will be \r
112 returned. \r
113 If all the conditions are met and the operation is "read," the NVRAM device \r
114 attached to the network interface will be read into Buffer and EFI_SUCCESS \r
115 will be returned. If this is a write operation, the contents of Buffer will be\r
116 used to update the contents of the NVRAM device attached to the network \r
117 interface and EFI_SUCCESS will be returned.\r
118 \r
d007c0a2 119 It does the basic checking on the input parameters and retrieves snp structure\r
120 and then calls the read_nvdata() call which does the actual reading\r
121\r
4cda7726 122 @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.\r
123 @param ReadWrite TRUE for read operations, FALSE for write operations.\r
124 @param Offset Byte offset in the NVRAM device at which to start the read or \r
125 write operation. This must be a multiple of NvRamAccessSize \r
126 and less than NvRamSize. (See EFI_SIMPLE_NETWORK_MODE) \r
127 @param BufferSize The number of bytes to read or write from the NVRAM device. \r
128 This must also be a multiple of NvramAccessSize.\r
129 @param Buffer A pointer to the data buffer.\r
130\r
131 @retval EFI_SUCCESS The NVRAM access was performed.\r
132 @retval EFI_NOT_STARTED The network interface has not been started.\r
133 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r
134 * The This parameter is NULL \r
135 * The This parameter does not point to a valid \r
136 EFI_SIMPLE_NETWORK_PROTOCOL structure\r
137 * The Offset parameter is not a multiple of \r
138 EFI_SIMPLE_NETWORK_MODE.NvRamAccessSize\r
139 * The Offset parameter is not less than \r
140 EFI_SIMPLE_NETWORK_MODE.NvRamSize\r
141 * The BufferSize parameter is not a multiple of \r
142 EFI_SIMPLE_NETWORK_MODE.NvRamAccessSize\r
143 * The Buffer parameter is NULL\r
144 @retval EFI_DEVICE_ERROR The command could not be sent to the network \r
145 interface.\r
146 @retval EFI_UNSUPPORTED This function is not supported by the network\r
147 interface.\r
d007c0a2 148\r
149**/\r
150EFI_STATUS\r
151EFIAPI\r
4cda7726 152SnpUndi32NvData (\r
153 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
154 IN BOOLEAN ReadWrite,\r
155 IN UINTN Offset,\r
156 IN UINTN BufferSize,\r
157 IN OUT VOID *Buffer\r
d007c0a2 158 )\r
159{\r
4cda7726 160 SNP_DRIVER *Snp;\r
d007c0a2 161 EFI_TPL OldTpl;\r
162 EFI_STATUS Status;\r
163\r
164 //\r
165 // Get pointer to SNP driver instance for *this.\r
166 //\r
4cda7726 167 if (This == NULL) {\r
d007c0a2 168 return EFI_INVALID_PARAMETER;\r
169 }\r
170\r
4cda7726 171 Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);\r
d007c0a2 172\r
173 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
174\r
175 //\r
176 // Return error if the SNP is not initialized.\r
177 //\r
4cda7726 178 switch (Snp->Mode.State) {\r
d007c0a2 179 case EfiSimpleNetworkInitialized:\r
180 break;\r
181\r
182 case EfiSimpleNetworkStopped:\r
183 Status = EFI_NOT_STARTED;\r
184 goto ON_EXIT;\r
185\r
186 default:\r
187 Status = EFI_DEVICE_ERROR;\r
188 goto ON_EXIT;\r
189 }\r
190 //\r
191 // Return error if non-volatile memory variables are not valid.\r
192 //\r
4cda7726 193 if (Snp->Mode.NvRamSize == 0 || Snp->Mode.NvRamAccessSize == 0) {\r
d007c0a2 194 Status = EFI_UNSUPPORTED;\r
195 goto ON_EXIT;\r
196 }\r
197 //\r
198 // Check for invalid parameter combinations.\r
199 //\r
4cda7726 200 if ((BufferSize == 0) ||\r
201 (Buffer == NULL) ||\r
202 (Offset >= Snp->Mode.NvRamSize) ||\r
203 (Offset + BufferSize > Snp->Mode.NvRamSize) ||\r
204 (BufferSize % Snp->Mode.NvRamAccessSize != 0) ||\r
205 (Offset % Snp->Mode.NvRamAccessSize != 0)\r
d007c0a2 206 ) {\r
207 Status = EFI_INVALID_PARAMETER;\r
208 goto ON_EXIT;\r
209 }\r
210 //\r
211 // check the implementation flags of undi if we can write the nvdata!\r
212 //\r
4cda7726 213 if (!ReadWrite) {\r
d007c0a2 214 Status = EFI_UNSUPPORTED;\r
215 } else {\r
4cda7726 216 Status = PxeNvDataRead (Snp, Offset, BufferSize, Buffer);\r
d007c0a2 217 }\r
218\r
219ON_EXIT:\r
220 gBS->RestoreTPL (OldTpl);\r
221\r
222 return Status;\r
223}\r