]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/SnpDxe/Nvdata.c
19d43be8bdb92821a194f0e1f43bd011ce0da36a
[mirror_edk2.git] / MdeModulePkg / Universal / Network / SnpDxe / Nvdata.c
1 /** @file
2 Copyright (c) 2004 - 2007, Intel Corporation
3 All rights reserved. This program and the accompanying materials
4 are licensed and made available under the terms and conditions of the BSD License
5 which accompanies this distribution. The full text of the license may be found at
6 http://opensource.org/licenses/bsd-license.php
7
8 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
9 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
10
11 Module name:
12 nvdata.c
13
14 Abstract:
15
16 Revision history:
17 2000-Feb-03 M(f)J Genesis.
18
19 **/
20
21 #include "Snp.h"
22
23
24 /**
25 This routine calls Undi to read the desired number of eeprom bytes.
26
27 @param snp pointer to the snp driver structure
28 @param RegOffset eeprom register value relative to the base address
29 @param NumBytes number of bytes to read
30 @param BufferPtr pointer where to read into
31
32
33 **/
34 EFI_STATUS
35 pxe_nvdata_read (
36 IN SNP_DRIVER *snp,
37 IN UINTN RegOffset,
38 IN UINTN NumBytes,
39 IN OUT VOID *BufferPtr
40 )
41 {
42 PXE_DB_NVDATA *db;
43
44 db = snp->db;
45 snp->cdb.OpCode = PXE_OPCODE_NVDATA;
46
47 snp->cdb.OpFlags = PXE_OPFLAGS_NVDATA_READ;
48
49 snp->cdb.CPBsize = PXE_CPBSIZE_NOT_USED;
50 snp->cdb.CPBaddr = PXE_CPBADDR_NOT_USED;
51
52 snp->cdb.DBsize = sizeof (PXE_DB_NVDATA);
53 snp->cdb.DBaddr = (UINT64)(UINTN) db;
54
55 snp->cdb.StatCode = PXE_STATCODE_INITIALIZE;
56 snp->cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;
57 snp->cdb.IFnum = snp->if_num;
58 snp->cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;
59
60 //
61 // Issue UNDI command and check result.
62 //
63 DEBUG ((EFI_D_NET, "\nsnp->undi.nvdata () "));
64
65 (*snp->issue_undi32_command) ((UINT64)(UINTN) &snp->cdb);
66
67 switch (snp->cdb.StatCode) {
68 case PXE_STATCODE_SUCCESS:
69 break;
70
71 case PXE_STATCODE_UNSUPPORTED:
72 DEBUG (
73 (EFI_D_NET,
74 "\nsnp->undi.nvdata() %xh:%xh\n",
75 snp->cdb.StatFlags,
76 snp->cdb.StatCode)
77 );
78
79 return EFI_UNSUPPORTED;
80
81 default:
82 DEBUG (
83 (EFI_D_NET,
84 "\nsnp->undi.nvdata() %xh:%xh\n",
85 snp->cdb.StatFlags,
86 snp->cdb.StatCode)
87 );
88
89 return EFI_DEVICE_ERROR;
90 }
91
92 CopyMem (BufferPtr, db->Data.Byte + RegOffset, NumBytes);
93
94 return EFI_SUCCESS;
95 }
96
97
98 /**
99 This is an interface call provided by SNP.
100 It does the basic checking on the input parameters and retrieves snp structure
101 and then calls the read_nvdata() call which does the actual reading
102
103 @param this context pointer
104 @param ReadOrWrite true for reading and false for writing
105 @param RegOffset eeprom register relative to the base
106 @param NumBytes how many bytes to read
107 @param BufferPtr address of memory to read into
108
109
110 **/
111 EFI_STATUS
112 EFIAPI
113 snp_undi32_nvdata (
114 IN EFI_SIMPLE_NETWORK_PROTOCOL *this,
115 IN BOOLEAN ReadOrWrite,
116 IN UINTN RegOffset,
117 IN UINTN NumBytes,
118 IN OUT VOID *BufferPtr
119 )
120 {
121 SNP_DRIVER *snp;
122 EFI_TPL OldTpl;
123 EFI_STATUS Status;
124
125 //
126 // Get pointer to SNP driver instance for *this.
127 //
128 if (this == NULL) {
129 return EFI_INVALID_PARAMETER;
130 }
131
132 snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this);
133
134 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
135
136 //
137 // Return error if the SNP is not initialized.
138 //
139 switch (snp->mode.State) {
140 case EfiSimpleNetworkInitialized:
141 break;
142
143 case EfiSimpleNetworkStopped:
144 Status = EFI_NOT_STARTED;
145 goto ON_EXIT;
146
147 default:
148 Status = EFI_DEVICE_ERROR;
149 goto ON_EXIT;
150 }
151 //
152 // Return error if non-volatile memory variables are not valid.
153 //
154 if (snp->mode.NvRamSize == 0 || snp->mode.NvRamAccessSize == 0) {
155 Status = EFI_UNSUPPORTED;
156 goto ON_EXIT;
157 }
158 //
159 // Check for invalid parameter combinations.
160 //
161 if ((NumBytes == 0) ||
162 (BufferPtr == NULL) ||
163 (RegOffset >= snp->mode.NvRamSize) ||
164 (RegOffset + NumBytes > snp->mode.NvRamSize) ||
165 (NumBytes % snp->mode.NvRamAccessSize != 0) ||
166 (RegOffset % snp->mode.NvRamAccessSize != 0)
167 ) {
168 Status = EFI_INVALID_PARAMETER;
169 goto ON_EXIT;
170 }
171 //
172 // check the implementation flags of undi if we can write the nvdata!
173 //
174 if (!ReadOrWrite) {
175 Status = EFI_UNSUPPORTED;
176 } else {
177 Status = pxe_nvdata_read (snp, RegOffset, NumBytes, BufferPtr);
178 }
179
180 ON_EXIT:
181 gBS->RestoreTPL (OldTpl);
182
183 return Status;
184 }