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