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