]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Universal/Network/Snp32_64/Dxe/nvdata.c
0167e4db30e71cebb9f559b9c029092c0d65c1c9
[mirror_edk2.git] / EdkModulePkg / Universal / Network / Snp32_64 / Dxe / nvdata.c
1 /*++
2 Copyright (c) 2006, 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 EFI_STATUS
24 pxe_nvdata_read (
25 IN SNP_DRIVER *snp,
26 IN UINTN RegOffset,
27 IN UINTN NumBytes,
28 IN OUT VOID *BufferPtr
29 )
30 /*++
31
32 Routine Description:
33 This routine calls Undi to read the desired number of eeprom bytes.
34
35 Arguments:
36 snp - pointer to the snp driver structure
37 RegOffset - eeprom register value relative to the base address
38 NumBytes - number of bytes to read
39 BufferPtr - pointer where to read into
40
41 Returns:
42
43 --*/
44 {
45 PXE_DB_NVDATA *db;
46
47 db = snp->db;
48 snp->cdb.OpCode = PXE_OPCODE_NVDATA;
49
50 snp->cdb.OpFlags = PXE_OPFLAGS_NVDATA_READ;
51
52 snp->cdb.CPBsize = PXE_CPBSIZE_NOT_USED;
53 snp->cdb.CPBaddr = PXE_CPBADDR_NOT_USED;
54
55 snp->cdb.DBsize = sizeof (PXE_DB_NVDATA);
56 snp->cdb.DBaddr = (UINT64) (UINTN) db;
57
58 snp->cdb.StatCode = PXE_STATCODE_INITIALIZE;
59 snp->cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;
60 snp->cdb.IFnum = snp->if_num;
61 snp->cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;
62
63 //
64 // Issue UNDI command and check result.
65 //
66 DEBUG ((EFI_D_NET, "\nsnp->undi.nvdata () "));
67
68 (*snp->issue_undi32_command) ((UINT64) (UINTN) &snp->cdb);
69
70 switch (snp->cdb.StatCode) {
71 case PXE_STATCODE_SUCCESS:
72 break;
73
74 case PXE_STATCODE_UNSUPPORTED:
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_UNSUPPORTED;
83
84 default:
85 DEBUG (
86 (EFI_D_NET,
87 "\nsnp->undi.nvdata() %xh:%xh\n",
88 snp->cdb.StatFlags,
89 snp->cdb.StatCode)
90 );
91
92 return EFI_DEVICE_ERROR;
93 }
94
95 CopyMem (BufferPtr, db->Data.Byte + RegOffset, NumBytes);
96
97 return EFI_SUCCESS;
98 }
99
100 EFI_STATUS
101 EFIAPI
102 snp_undi32_nvdata (
103 IN EFI_SIMPLE_NETWORK_PROTOCOL *this,
104 IN BOOLEAN ReadOrWrite,
105 IN UINTN RegOffset,
106 IN UINTN NumBytes,
107 IN OUT VOID *BufferPtr
108 )
109 /*++
110
111 Routine Description:
112 This is an interface call provided by SNP.
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 Arguments:
117 this - context pointer
118 ReadOrWrite - true for reading and false for writing
119 RegOffset - eeprom register relative to the base
120 NumBytes - how many bytes to read
121 BufferPtr - address of memory to read into
122
123 Returns:
124
125 --*/
126 {
127 SNP_DRIVER *snp;
128
129 //
130 // Get pointer to SNP driver instance for *this.
131 //
132 if (this == NULL) {
133 return EFI_INVALID_PARAMETER;
134 }
135
136 snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this);
137
138 if (snp == NULL) {
139 return EFI_DEVICE_ERROR;
140 }
141 //
142 // Return error if the SNP is not initialized.
143 //
144 switch (snp->mode.State) {
145 case EfiSimpleNetworkInitialized:
146 break;
147
148 case EfiSimpleNetworkStopped:
149 return EFI_NOT_STARTED;
150
151 case EfiSimpleNetworkStarted:
152 return EFI_DEVICE_ERROR;
153
154 default:
155 return EFI_DEVICE_ERROR;
156 }
157 //
158 // Return error if non-volatile memory variables are not valid.
159 //
160 if (snp->mode.NvRamSize == 0 || snp->mode.NvRamAccessSize == 0) {
161 return EFI_UNSUPPORTED;
162 }
163 //
164 // Check for invalid parameter combinations.
165 //
166 if ((NumBytes == 0) ||
167 (BufferPtr == NULL) ||
168 (RegOffset >= snp->mode.NvRamSize) ||
169 (RegOffset + NumBytes > snp->mode.NvRamSize) ||
170 (NumBytes % snp->mode.NvRamAccessSize != 0) ||
171 (RegOffset % snp->mode.NvRamAccessSize != 0)
172 ) {
173 return EFI_INVALID_PARAMETER;
174 }
175 //
176 // check the implementation flags of undi if we can write the nvdata!
177 //
178 if (!ReadOrWrite) {
179 return EFI_UNSUPPORTED;
180 } else {
181 return pxe_nvdata_read (snp, RegOffset, NumBytes, BufferPtr);
182 }
183 }