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