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