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