]>
Commit | Line | Data |
---|---|---|
1 | /*++\r | |
2 | \r | |
3 | Copyright (c) 2006 - 2007, Intel Corporation\r | |
4 | All rights reserved. This program and the accompanying materials\r | |
5 | are licensed and made available under the terms and conditions of the BSD License\r | |
6 | which accompanies this distribution. The full text of the license may be found at\r | |
7 | http://opensource.org/licenses/bsd-license.php\r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
11 | \r | |
12 | Module Name:\r | |
13 | \r | |
14 | MiscSubclassDriverEntryPoint.c\r | |
15 | \r | |
16 | Abstract:\r | |
17 | \r | |
18 | This driver parses the mMiscSubclassDataTable structure and reports\r | |
19 | any generated data to the DataHub.\r | |
20 | \r | |
21 | --*/\r | |
22 | \r | |
23 | #include "MiscSubclassDriver.h"\r | |
24 | \r | |
25 | \r | |
26 | extern UINT8 MiscSubclassStrings[];\r | |
27 | \r | |
28 | \r | |
29 | //\r | |
30 | //\r | |
31 | //\r | |
32 | EFI_STATUS\r | |
33 | LogRecordDataToDataHub (\r | |
34 | EFI_DATA_HUB_PROTOCOL *DataHub,\r | |
35 | UINT32 RecordType,\r | |
36 | UINT32 RecordLen,\r | |
37 | VOID *RecordData\r | |
38 | )\r | |
39 | /*++\r | |
40 | Description:\r | |
41 | \r | |
42 | Parameters:\r | |
43 | \r | |
44 | DataHub\r | |
45 | %%TBD\r | |
46 | \r | |
47 | RecordType\r | |
48 | %%TBD\r | |
49 | \r | |
50 | RecordLen\r | |
51 | %%TBD\r | |
52 | \r | |
53 | RecordData\r | |
54 | %%TBD\r | |
55 | \r | |
56 | Returns:\r | |
57 | \r | |
58 | EFI_INVALID_PARAMETER\r | |
59 | \r | |
60 | EFI_SUCCESS\r | |
61 | \r | |
62 | Other Data Hub errors\r | |
63 | \r | |
64 | --*/\r | |
65 | {\r | |
66 | EFI_MISC_SUBCLASS_DRIVER_DATA MiscSubclass;\r | |
67 | EFI_STATUS Status;\r | |
68 | \r | |
69 | //\r | |
70 | // Do nothing if data parameters are not valid.\r | |
71 | //\r | |
72 | if (RecordLen == 0 || RecordData == NULL) {\r | |
73 | DEBUG (\r | |
74 | (EFI_D_ERROR,\r | |
75 | "RecordLen == %d RecordData == %xh\n",\r | |
76 | RecordLen,\r | |
77 | RecordData)\r | |
78 | );\r | |
79 | \r | |
80 | return EFI_INVALID_PARAMETER;\r | |
81 | }\r | |
82 | //\r | |
83 | // Assemble Data Hub record.\r | |
84 | //\r | |
85 | MiscSubclass.Header.Version = EFI_MISC_SUBCLASS_VERSION;\r | |
86 | MiscSubclass.Header.HeaderSize = sizeof (EFI_SUBCLASS_TYPE1_HEADER);\r | |
87 | MiscSubclass.Header.Instance = 1;\r | |
88 | MiscSubclass.Header.SubInstance = 1;\r | |
89 | MiscSubclass.Header.RecordType = RecordType;\r | |
90 | \r | |
91 | CopyMem (\r | |
92 | &MiscSubclass.Record,\r | |
93 | RecordData,\r | |
94 | RecordLen\r | |
95 | );\r | |
96 | \r | |
97 | //\r | |
98 | // Log Data Hub record.\r | |
99 | //\r | |
100 | Status = DataHub->LogData (\r | |
101 | DataHub,\r | |
102 | &gEfiMiscSubClassGuid,\r | |
103 | &gEfiMiscSubClassGuid,\r | |
104 | EFI_DATA_RECORD_CLASS_DATA,\r | |
105 | &MiscSubclass,\r | |
106 | sizeof (EFI_SUBCLASS_TYPE1_HEADER) + RecordLen\r | |
107 | );\r | |
108 | \r | |
109 | if (EFI_ERROR (Status)) {\r | |
110 | DEBUG (\r | |
111 | (EFI_D_ERROR,\r | |
112 | "LogData(%d bytes) == %r\n",\r | |
113 | sizeof (EFI_SUBCLASS_TYPE1_HEADER) + RecordLen,\r | |
114 | Status)\r | |
115 | );\r | |
116 | }\r | |
117 | \r | |
118 | return Status;\r | |
119 | }\r | |
120 | \r | |
121 | \r | |
122 | EFI_STATUS\r | |
123 | EFIAPI\r | |
124 | MiscSubclassDriverEntryPoint (\r | |
125 | IN EFI_HANDLE ImageHandle,\r | |
126 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
127 | )\r | |
128 | /*++\r | |
129 | Description:\r | |
130 | \r | |
131 | Standard EFI driver point. This driver parses the mMiscSubclassDataTable\r | |
132 | structure and reports any generated data to the DataHub.\r | |
133 | \r | |
134 | Arguments:\r | |
135 | \r | |
136 | ImageHandle\r | |
137 | Handle for the image of this driver\r | |
138 | \r | |
139 | SystemTable\r | |
140 | Pointer to the EFI System Table\r | |
141 | \r | |
142 | Returns:\r | |
143 | \r | |
144 | EFI_SUCCESS\r | |
145 | The data was successfully reported to the Data Hub.\r | |
146 | \r | |
147 | --*/\r | |
148 | {\r | |
149 | EFI_MISC_SUBCLASS_DRIVER_DATA RecordData;\r | |
150 | EFI_DATA_HUB_PROTOCOL *DataHub;\r | |
151 | EFI_HII_PROTOCOL *Hii;\r | |
152 | EFI_HII_PACKAGES *PackageList;\r | |
153 | EFI_HII_HANDLE HiiHandle;\r | |
154 | EFI_STATUS Status;\r | |
155 | UINTN Index;\r | |
156 | BOOLEAN LogRecordData;\r | |
157 | EFI_MEMORY_SUBCLASS_DRIVER_DATA MemorySubClassData; \r | |
158 | UINT64 TotalMemorySize;\r | |
159 | CHAR16 *Nt32MemString;\r | |
160 | \r | |
161 | \r | |
162 | //\r | |
163 | // Initialize constant portion of subclass header.\r | |
164 | //\r | |
165 | RecordData.Header.Version = EFI_MISC_SUBCLASS_VERSION;\r | |
166 | RecordData.Header.HeaderSize = sizeof (EFI_SUBCLASS_TYPE1_HEADER);\r | |
167 | RecordData.Header.Instance = 1;\r | |
168 | RecordData.Header.SubInstance = 1;\r | |
169 | \r | |
170 | //\r | |
171 | // Locate data hub protocol.\r | |
172 | //\r | |
173 | Status = gBS->LocateProtocol (&gEfiDataHubProtocolGuid, NULL, &DataHub);\r | |
174 | \r | |
175 | if (EFI_ERROR (Status)) {\r | |
176 | DEBUG ((EFI_D_ERROR, "Could not locate DataHub protocol. %r\n", Status));\r | |
177 | return Status;\r | |
178 | } else if (DataHub == NULL) {\r | |
179 | DEBUG ((EFI_D_ERROR, "LocateProtocol(DataHub) returned NULL pointer!\n"));\r | |
180 | return EFI_DEVICE_ERROR;\r | |
181 | }\r | |
182 | //\r | |
183 | // Locate hii protocol.\r | |
184 | //\r | |
185 | Status = gBS->LocateProtocol (&gEfiHiiProtocolGuid, NULL, &Hii);\r | |
186 | \r | |
187 | if (EFI_ERROR (Status)) {\r | |
188 | DEBUG ((EFI_D_ERROR, "Could not locate Hii protocol. %r\n", Status));\r | |
189 | return Status;\r | |
190 | } else if (Hii == NULL) {\r | |
191 | DEBUG ((EFI_D_ERROR, "LocateProtocol(Hii) returned NULL pointer!\n"));\r | |
192 | return EFI_DEVICE_ERROR;\r | |
193 | }\r | |
194 | //\r | |
195 | // Add our default strings to the HII database. They will be modified later.\r | |
196 | //\r | |
197 | PackageList = PreparePackages (1, &gEfiMiscSubClassGuid, MiscSubclassStrings);\r | |
198 | Status = Hii->NewPack (Hii, PackageList, &HiiHandle);\r | |
199 | FreePool (PackageList);\r | |
200 | \r | |
201 | if (EFI_ERROR (Status)) {\r | |
202 | DEBUG ((EFI_D_ERROR, "Could not log default strings to Hii. %r\n", Status));\r | |
203 | return Status;\r | |
204 | }\r | |
205 | //\r | |
206 | //\r | |
207 | //\r | |
208 | for (Index = 0; Index < mMiscSubclassDataTableEntries; ++Index) {\r | |
209 | //\r | |
210 | // Stupidity check! Do nothing if RecordLen is zero.\r | |
211 | // %%TBD - Should this be an error or a mechanism for ignoring\r | |
212 | // records in the Data Table?\r | |
213 | //\r | |
214 | if (mMiscSubclassDataTable[Index].RecordLen == 0) {\r | |
215 | DEBUG (\r | |
216 | (EFI_D_ERROR,\r | |
217 | "mMiscSubclassDataTable[%d].RecordLen == 0\n",\r | |
218 | Index)\r | |
219 | );\r | |
220 | \r | |
221 | continue;\r | |
222 | }\r | |
223 | //\r | |
224 | // Initialize per-record portion of subclass header and\r | |
225 | // copy static data into data portion of subclass record.\r | |
226 | //\r | |
227 | RecordData.Header.RecordType = mMiscSubclassDataTable[Index].RecordType;\r | |
228 | \r | |
229 | if (mMiscSubclassDataTable[Index].RecordData == NULL) {\r | |
230 | ZeroMem (\r | |
231 | &RecordData.Record,\r | |
232 | mMiscSubclassDataTable[Index].RecordLen\r | |
233 | );\r | |
234 | } else {\r | |
235 | CopyMem (\r | |
236 | &RecordData.Record,\r | |
237 | mMiscSubclassDataTable[Index].RecordData,\r | |
238 | mMiscSubclassDataTable[Index].RecordLen\r | |
239 | );\r | |
240 | }\r | |
241 | //\r | |
242 | // If the entry does not have a function pointer, just log the data.\r | |
243 | //\r | |
244 | if (mMiscSubclassDataTable[Index].Function == NULL) {\r | |
245 | //\r | |
246 | // Log RecordData to Data Hub.\r | |
247 | //\r | |
248 | Status = DataHub->LogData (\r | |
249 | DataHub,\r | |
250 | &gEfiMiscSubClassGuid,\r | |
251 | &gEfiMiscSubClassGuid,\r | |
252 | EFI_DATA_RECORD_CLASS_DATA,\r | |
253 | &RecordData,\r | |
254 | sizeof (EFI_SUBCLASS_TYPE1_HEADER) + mMiscSubclassDataTable[Index].RecordLen\r | |
255 | );\r | |
256 | \r | |
257 | if (EFI_ERROR (Status)) {\r | |
258 | DEBUG (\r | |
259 | (EFI_D_ERROR,\r | |
260 | "LogData(%d bytes) == %r\n",\r | |
261 | sizeof (EFI_SUBCLASS_TYPE1_HEADER) + mMiscSubclassDataTable[Index].RecordLen,\r | |
262 | Status)\r | |
263 | );\r | |
264 | }\r | |
265 | \r | |
266 | continue;\r | |
267 | }\r | |
268 | //\r | |
269 | // The entry has a valid function pointer.\r | |
270 | // Keep calling the function and logging data until there\r | |
271 | // is no more data to log.\r | |
272 | //\r | |
273 | for (;;) {\r | |
274 | Status = (*mMiscSubclassDataTable[Index].Function)(mMiscSubclassDataTable[Index].RecordType, &mMiscSubclassDataTable[Index].RecordLen, &RecordData.Record, &LogRecordData);\r | |
275 | if (EFI_ERROR (Status)) {\r | |
276 | break;\r | |
277 | }\r | |
278 | \r | |
279 | if (!LogRecordData) {\r | |
280 | break;\r | |
281 | }\r | |
282 | \r | |
283 | Status = DataHub->LogData (\r | |
284 | DataHub,\r | |
285 | &gEfiMiscSubClassGuid,\r | |
286 | &gEfiMiscSubClassGuid,\r | |
287 | EFI_DATA_RECORD_CLASS_DATA,\r | |
288 | &RecordData,\r | |
289 | sizeof (EFI_SUBCLASS_TYPE1_HEADER) + mMiscSubclassDataTable[Index].RecordLen\r | |
290 | );\r | |
291 | \r | |
292 | if (EFI_ERROR (Status)) {\r | |
293 | DEBUG (\r | |
294 | (EFI_D_ERROR,\r | |
295 | "LogData(%d bytes) == %r\n",\r | |
296 | sizeof (EFI_SUBCLASS_TYPE1_HEADER) + mMiscSubclassDataTable[Index].RecordLen,\r | |
297 | Status)\r | |
298 | );\r | |
299 | }\r | |
300 | }\r | |
301 | }\r | |
302 | \r | |
303 | \r | |
304 | //\r | |
305 | // Log Memory Size info based on PCD setting.\r | |
306 | //\r | |
307 | MemorySubClassData.Header.Instance = 1;\r | |
308 | MemorySubClassData.Header.SubInstance = EFI_SUBCLASS_INSTANCE_NON_APPLICABLE;\r | |
309 | MemorySubClassData.Header.RecordType = EFI_MEMORY_ARRAY_START_ADDRESS_RECORD_NUMBER;\r | |
310 | \r | |
311 | //\r | |
312 | // Process Memory String in form size!size ...\r | |
313 | // So 64!64 is 128 MB\r | |
314 | //\r | |
315 | Nt32MemString = PcdGetPtr (PcdWinNtMemorySize);\r | |
316 | for (TotalMemorySize = 0; *Nt32MemString != '\0';) {\r | |
317 | TotalMemorySize += StrDecimalToUint64 (Nt32MemString);\r | |
318 | while (*Nt32MemString != '\0') {\r | |
319 | if (*Nt32MemString == '!') {\r | |
320 | Nt32MemString++; \r | |
321 | break;\r | |
322 | }\r | |
323 | Nt32MemString++;\r | |
324 | }\r | |
325 | }\r | |
326 | \r | |
327 | MemorySubClassData.Record.ArrayStartAddress.MemoryArrayStartAddress = 0;\r | |
328 | MemorySubClassData.Record.ArrayStartAddress.MemoryArrayEndAddress = LShiftU64 (TotalMemorySize, 20) - 1;\r | |
329 | MemorySubClassData.Record.ArrayStartAddress.PhysicalMemoryArrayLink.ProducerName = gEfiMemoryProducerGuid;\r | |
330 | MemorySubClassData.Record.ArrayStartAddress.PhysicalMemoryArrayLink.Instance = 1;\r | |
331 | MemorySubClassData.Record.ArrayStartAddress.PhysicalMemoryArrayLink.SubInstance = EFI_SUBCLASS_INSTANCE_NON_APPLICABLE;\r | |
332 | MemorySubClassData.Record.ArrayStartAddress.MemoryArrayPartitionWidth = 0;\r | |
333 | \r | |
334 | //\r | |
335 | // Store memory size data record to data hub.\r | |
336 | //\r | |
337 | Status = DataHub->LogData (\r | |
338 | DataHub,\r | |
339 | &gEfiMemorySubClassGuid,\r | |
340 | &gEfiMemoryProducerGuid,\r | |
341 | EFI_DATA_RECORD_CLASS_DATA,\r | |
342 | &MemorySubClassData,\r | |
343 | sizeof (EFI_SUBCLASS_TYPE1_HEADER) + sizeof (EFI_MEMORY_ARRAY_START_ADDRESS_DATA)\r | |
344 | );\r | |
345 | \r | |
346 | \r | |
347 | return EFI_SUCCESS;\r | |
348 | }\r | |
349 | \r | |
350 | \r |