]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - Nt32Pkg/MiscSubClassPlatformDxe/MiscSubclassDriverEntryPoint.c
1. PI SMBIOS Checkin. Major change include:
[mirror_edk2.git] / Nt32Pkg / MiscSubClassPlatformDxe / MiscSubclassDriverEntryPoint.c
... / ...
CommitLineData
1/**@file\r
2\r
3Copyright (c) 2006 - 2007, Intel Corporation\r
4All rights reserved. This program and the accompanying materials\r
5are licensed and made available under the terms and conditions of the BSD License\r
6which accompanies this distribution. The full text of the license may be found at\r
7http://opensource.org/licenses/bsd-license.php\r
8\r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12Module Name:\r
13\r
14 MiscSubclassDriverEntryPoint.c\r
15\r
16Abstract:\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
26extern UINT8 MiscSubclassStrings[];\r
27\r
28\r
29//\r
30//\r
31//\r
32EFI_STATUS\r
33LogRecordDataToDataHub (\r
34 EFI_DATA_HUB_PROTOCOL *DataHub,\r
35 UINT32 RecordType,\r
36 UINT32 RecordLen,\r
37 VOID *RecordData\r
38 )\r
39/*++\r
40Description:\r
41\r
42Parameters:\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
56Returns:\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
122EFI_STATUS\r
123EFIAPI\r
124MiscSubclassDriverEntryPoint (\r
125 IN EFI_HANDLE ImageHandle,\r
126 IN EFI_SYSTEM_TABLE *SystemTable\r
127 )\r
128/*++\r
129Description:\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
134Arguments:\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
142Returns:\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_HANDLE HiiHandle;\r
152 EFI_STATUS Status;\r
153 UINTN Index;\r
154 BOOLEAN LogRecordData;\r
155 EFI_MEMORY_SUBCLASS_DRIVER_DATA MemorySubClassData; \r
156 UINT64 TotalMemorySize;\r
157 CHAR16 *Nt32MemString;\r
158\r
159\r
160 //\r
161 // Initialize constant portion of subclass header.\r
162 //\r
163 RecordData.Header.Version = EFI_MISC_SUBCLASS_VERSION;\r
164 RecordData.Header.HeaderSize = sizeof (EFI_SUBCLASS_TYPE1_HEADER);\r
165 RecordData.Header.Instance = 1;\r
166 RecordData.Header.SubInstance = 1;\r
167\r
168 //\r
169 // Locate data hub protocol.\r
170 //\r
171 Status = gBS->LocateProtocol (&gEfiDataHubProtocolGuid, NULL, (VOID**)&DataHub);\r
172\r
173 if (EFI_ERROR (Status)) {\r
174 DEBUG ((EFI_D_ERROR, "Could not locate DataHub protocol. %r\n", Status));\r
175 return Status;\r
176 } else if (DataHub == NULL) {\r
177 DEBUG ((EFI_D_ERROR, "LocateProtocol(DataHub) returned NULL pointer!\n"));\r
178 return EFI_DEVICE_ERROR;\r
179 }\r
180 //\r
181 // Add our default strings to the HII database. They will be modified later.\r
182 //\r
183 HiiHandle = HiiAddPackages (\r
184 &gEfiMiscSubClassGuid,\r
185 NULL,\r
186 MiscSubclassStrings,\r
187 NULL\r
188 );\r
189 if (HiiHandle == NULL) {\r
190 DEBUG ((EFI_D_ERROR, "Could not log default strings to Hii. %r\n", Status));\r
191 return EFI_OUT_OF_RESOURCES;\r
192 }\r
193 //\r
194 //\r
195 //\r
196 for (Index = 0; Index < mMiscSubclassDataTableEntries; ++Index) {\r
197 //\r
198 // Stupidity check! Do nothing if RecordLen is zero.\r
199 // %%TBD - Should this be an error or a mechanism for ignoring\r
200 // records in the Data Table?\r
201 //\r
202 if (mMiscSubclassDataTable[Index].RecordLen == 0) {\r
203 DEBUG (\r
204 (EFI_D_ERROR,\r
205 "mMiscSubclassDataTable[%d].RecordLen == 0\n",\r
206 Index)\r
207 );\r
208\r
209 continue;\r
210 }\r
211 //\r
212 // Initialize per-record portion of subclass header and\r
213 // copy static data into data portion of subclass record.\r
214 //\r
215 RecordData.Header.RecordType = mMiscSubclassDataTable[Index].RecordType;\r
216\r
217 if (mMiscSubclassDataTable[Index].RecordData == NULL) {\r
218 ZeroMem (\r
219 &RecordData.Record,\r
220 mMiscSubclassDataTable[Index].RecordLen\r
221 );\r
222 } else {\r
223 CopyMem (\r
224 &RecordData.Record,\r
225 mMiscSubclassDataTable[Index].RecordData,\r
226 mMiscSubclassDataTable[Index].RecordLen\r
227 );\r
228 }\r
229 //\r
230 // If the entry does not have a function pointer, just log the data.\r
231 //\r
232 if (mMiscSubclassDataTable[Index].Function == NULL) {\r
233 //\r
234 // Log RecordData to Data Hub.\r
235 //\r
236 Status = DataHub->LogData (\r
237 DataHub,\r
238 &gEfiMiscSubClassGuid,\r
239 &gEfiMiscSubClassGuid,\r
240 EFI_DATA_RECORD_CLASS_DATA,\r
241 &RecordData,\r
242 sizeof (EFI_SUBCLASS_TYPE1_HEADER) + mMiscSubclassDataTable[Index].RecordLen\r
243 );\r
244\r
245 if (EFI_ERROR (Status)) {\r
246 DEBUG (\r
247 (EFI_D_ERROR,\r
248 "LogData(%d bytes) == %r\n",\r
249 sizeof (EFI_SUBCLASS_TYPE1_HEADER) + mMiscSubclassDataTable[Index].RecordLen,\r
250 Status)\r
251 );\r
252 }\r
253\r
254 continue;\r
255 }\r
256 //\r
257 // The entry has a valid function pointer.\r
258 // Keep calling the function and logging data until there\r
259 // is no more data to log.\r
260 //\r
261 for (;;) {\r
262 Status = (*mMiscSubclassDataTable[Index].Function)(mMiscSubclassDataTable[Index].RecordType, &mMiscSubclassDataTable[Index].RecordLen, &RecordData.Record, &LogRecordData);\r
263 if (EFI_ERROR (Status)) {\r
264 break;\r
265 }\r
266\r
267 if (!LogRecordData) {\r
268 break;\r
269 }\r
270\r
271 Status = DataHub->LogData (\r
272 DataHub,\r
273 &gEfiMiscSubClassGuid,\r
274 &gEfiMiscSubClassGuid,\r
275 EFI_DATA_RECORD_CLASS_DATA,\r
276 &RecordData,\r
277 sizeof (EFI_SUBCLASS_TYPE1_HEADER) + mMiscSubclassDataTable[Index].RecordLen\r
278 );\r
279\r
280 if (EFI_ERROR (Status)) {\r
281 DEBUG (\r
282 (EFI_D_ERROR,\r
283 "LogData(%d bytes) == %r\n",\r
284 sizeof (EFI_SUBCLASS_TYPE1_HEADER) + mMiscSubclassDataTable[Index].RecordLen,\r
285 Status)\r
286 );\r
287 }\r
288 }\r
289 }\r
290\r
291 \r
292 //\r
293 // Log Memory Size info based on PCD setting.\r
294 //\r
295 MemorySubClassData.Header.Instance = 1;\r
296 MemorySubClassData.Header.SubInstance = EFI_SUBCLASS_INSTANCE_NON_APPLICABLE;\r
297 MemorySubClassData.Header.RecordType = EFI_MEMORY_ARRAY_START_ADDRESS_RECORD_NUMBER;\r
298\r
299 //\r
300 // Process Memory String in form size!size ...\r
301 // So 64!64 is 128 MB\r
302 //\r
303 Nt32MemString = PcdGetPtr (PcdWinNtMemorySize);\r
304 for (TotalMemorySize = 0; *Nt32MemString != '\0';) {\r
305 TotalMemorySize += StrDecimalToUint64 (Nt32MemString);\r
306 while (*Nt32MemString != '\0') {\r
307 if (*Nt32MemString == '!') {\r
308 Nt32MemString++; \r
309 break;\r
310 }\r
311 Nt32MemString++;\r
312 }\r
313 }\r
314\r
315 MemorySubClassData.Record.ArrayStartAddress.MemoryArrayStartAddress = 0;\r
316 MemorySubClassData.Record.ArrayStartAddress.MemoryArrayEndAddress = LShiftU64 (TotalMemorySize, 20) - 1;\r
317 MemorySubClassData.Record.ArrayStartAddress.PhysicalMemoryArrayLink.ProducerName = gEfiCallerIdGuid;\r
318 MemorySubClassData.Record.ArrayStartAddress.PhysicalMemoryArrayLink.Instance = 1;\r
319 MemorySubClassData.Record.ArrayStartAddress.PhysicalMemoryArrayLink.SubInstance = EFI_SUBCLASS_INSTANCE_NON_APPLICABLE;\r
320 MemorySubClassData.Record.ArrayStartAddress.MemoryArrayPartitionWidth = 0;\r
321\r
322 //\r
323 // Store memory size data record to data hub.\r
324 //\r
325 Status = DataHub->LogData (\r
326 DataHub,\r
327 &gEfiMemorySubClassGuid,\r
328 &gEfiCallerIdGuid,\r
329 EFI_DATA_RECORD_CLASS_DATA,\r
330 &MemorySubClassData,\r
331 sizeof (EFI_SUBCLASS_TYPE1_HEADER) + sizeof (EFI_MEMORY_ARRAY_START_ADDRESS_DATA)\r
332 );\r
333\r
334\r
335 return EFI_SUCCESS;\r
336}\r
337\r
338\r