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