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