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