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
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.
14 MiscSubclassDriverEntryPoint.c
18 This driver parses the mMiscSubclassDataTable structure and reports
19 any generated data to the DataHub.
23 #include "MiscSubclassDriver.h"
26 extern UINT8 MiscSubclassStrings
[];
33 LogRecordDataToDataHub (
34 EFI_DATA_HUB_PROTOCOL
*DataHub
,
66 EFI_MISC_SUBCLASS_DRIVER_DATA MiscSubclass
;
70 // Do nothing if data parameters are not valid.
72 if (RecordLen
== 0 || RecordData
== NULL
) {
75 "RecordLen == %d RecordData == %xh\n",
80 return EFI_INVALID_PARAMETER
;
83 // Assemble Data Hub record.
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
;
98 // Log Data Hub record.
100 Status
= DataHub
->LogData (
102 &gEfiMiscSubClassGuid
,
103 &gEfiMiscSubClassGuid
,
104 EFI_DATA_RECORD_CLASS_DATA
,
106 sizeof (EFI_SUBCLASS_TYPE1_HEADER
) + RecordLen
109 if (EFI_ERROR (Status
)) {
112 "LogData(%d bytes) == %r\n",
113 sizeof (EFI_SUBCLASS_TYPE1_HEADER
) + RecordLen
,
124 MiscSubclassDriverEntryPoint (
125 IN EFI_HANDLE ImageHandle
,
126 IN EFI_SYSTEM_TABLE
*SystemTable
131 Standard EFI driver point. This driver parses the mMiscSubclassDataTable
132 structure and reports any generated data to the DataHub.
137 Handle for the image of this driver
140 Pointer to the EFI System Table
145 The data was successfully reported to the Data Hub.
149 EFI_MISC_SUBCLASS_DRIVER_DATA RecordData
;
150 EFI_DATA_HUB_PROTOCOL
*DataHub
;
151 EFI_HII_HANDLE HiiHandle
;
154 BOOLEAN LogRecordData
;
155 EFI_MEMORY_SUBCLASS_DRIVER_DATA MemorySubClassData
;
156 UINT64 TotalMemorySize
;
157 CHAR16
*Nt32MemString
;
161 // Initialize constant portion of subclass header.
163 RecordData
.Header
.Version
= EFI_MISC_SUBCLASS_VERSION
;
164 RecordData
.Header
.HeaderSize
= sizeof (EFI_SUBCLASS_TYPE1_HEADER
);
165 RecordData
.Header
.Instance
= 1;
166 RecordData
.Header
.SubInstance
= 1;
169 // Locate data hub protocol.
171 Status
= gBS
->LocateProtocol (&gEfiDataHubProtocolGuid
, NULL
, &DataHub
);
173 if (EFI_ERROR (Status
)) {
174 DEBUG ((EFI_D_ERROR
, "Could not locate DataHub protocol. %r\n", Status
));
176 } else if (DataHub
== NULL
) {
177 DEBUG ((EFI_D_ERROR
, "LocateProtocol(DataHub) returned NULL pointer!\n"));
178 return EFI_DEVICE_ERROR
;
181 // Add our default strings to the HII database. They will be modified later.
183 HiiLibAddPackages (1, &gEfiMiscSubClassGuid
, NULL
, &HiiHandle
, MiscSubclassStrings
);
185 if (EFI_ERROR (Status
)) {
186 DEBUG ((EFI_D_ERROR
, "Could not log default strings to Hii. %r\n", Status
));
192 for (Index
= 0; Index
< mMiscSubclassDataTableEntries
; ++Index
) {
194 // Stupidity check! Do nothing if RecordLen is zero.
195 // %%TBD - Should this be an error or a mechanism for ignoring
196 // records in the Data Table?
198 if (mMiscSubclassDataTable
[Index
].RecordLen
== 0) {
201 "mMiscSubclassDataTable[%d].RecordLen == 0\n",
208 // Initialize per-record portion of subclass header and
209 // copy static data into data portion of subclass record.
211 RecordData
.Header
.RecordType
= mMiscSubclassDataTable
[Index
].RecordType
;
213 if (mMiscSubclassDataTable
[Index
].RecordData
== NULL
) {
216 mMiscSubclassDataTable
[Index
].RecordLen
221 mMiscSubclassDataTable
[Index
].RecordData
,
222 mMiscSubclassDataTable
[Index
].RecordLen
226 // If the entry does not have a function pointer, just log the data.
228 if (mMiscSubclassDataTable
[Index
].Function
== NULL
) {
230 // Log RecordData to Data Hub.
232 Status
= DataHub
->LogData (
234 &gEfiMiscSubClassGuid
,
235 &gEfiMiscSubClassGuid
,
236 EFI_DATA_RECORD_CLASS_DATA
,
238 sizeof (EFI_SUBCLASS_TYPE1_HEADER
) + mMiscSubclassDataTable
[Index
].RecordLen
241 if (EFI_ERROR (Status
)) {
244 "LogData(%d bytes) == %r\n",
245 sizeof (EFI_SUBCLASS_TYPE1_HEADER
) + mMiscSubclassDataTable
[Index
].RecordLen
,
253 // The entry has a valid function pointer.
254 // Keep calling the function and logging data until there
255 // is no more data to log.
258 Status
= (*mMiscSubclassDataTable
[Index
].Function
)(mMiscSubclassDataTable
[Index
].RecordType
, &mMiscSubclassDataTable
[Index
].RecordLen
, &RecordData
.Record
, &LogRecordData
);
259 if (EFI_ERROR (Status
)) {
263 if (!LogRecordData
) {
267 Status
= DataHub
->LogData (
269 &gEfiMiscSubClassGuid
,
270 &gEfiMiscSubClassGuid
,
271 EFI_DATA_RECORD_CLASS_DATA
,
273 sizeof (EFI_SUBCLASS_TYPE1_HEADER
) + mMiscSubclassDataTable
[Index
].RecordLen
276 if (EFI_ERROR (Status
)) {
279 "LogData(%d bytes) == %r\n",
280 sizeof (EFI_SUBCLASS_TYPE1_HEADER
) + mMiscSubclassDataTable
[Index
].RecordLen
,
289 // Log Memory Size info based on PCD setting.
291 MemorySubClassData
.Header
.Instance
= 1;
292 MemorySubClassData
.Header
.SubInstance
= EFI_SUBCLASS_INSTANCE_NON_APPLICABLE
;
293 MemorySubClassData
.Header
.RecordType
= EFI_MEMORY_ARRAY_START_ADDRESS_RECORD_NUMBER
;
296 // Process Memory String in form size!size ...
297 // So 64!64 is 128 MB
299 Nt32MemString
= PcdGetPtr (PcdWinNtMemorySize
);
300 for (TotalMemorySize
= 0; *Nt32MemString
!= '\0';) {
301 TotalMemorySize
+= StrDecimalToUint64 (Nt32MemString
);
302 while (*Nt32MemString
!= '\0') {
303 if (*Nt32MemString
== '!') {
311 MemorySubClassData
.Record
.ArrayStartAddress
.MemoryArrayStartAddress
= 0;
312 MemorySubClassData
.Record
.ArrayStartAddress
.MemoryArrayEndAddress
= LShiftU64 (TotalMemorySize
, 20) - 1;
313 MemorySubClassData
.Record
.ArrayStartAddress
.PhysicalMemoryArrayLink
.ProducerName
= gEfiMemoryProducerGuid
;
314 MemorySubClassData
.Record
.ArrayStartAddress
.PhysicalMemoryArrayLink
.Instance
= 1;
315 MemorySubClassData
.Record
.ArrayStartAddress
.PhysicalMemoryArrayLink
.SubInstance
= EFI_SUBCLASS_INSTANCE_NON_APPLICABLE
;
316 MemorySubClassData
.Record
.ArrayStartAddress
.MemoryArrayPartitionWidth
= 0;
319 // Store memory size data record to data hub.
321 Status
= DataHub
->LogData (
323 &gEfiMemorySubClassGuid
,
324 &gEfiMemoryProducerGuid
,
325 EFI_DATA_RECORD_CLASS_DATA
,
327 sizeof (EFI_SUBCLASS_TYPE1_HEADER
) + sizeof (EFI_MEMORY_ARRAY_START_ADDRESS_DATA
)