3 Copyright (c) 2006, 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
[];
32 LogRecordDataToDataHub (
33 EFI_DATA_HUB_PROTOCOL
*DataHub
,
65 EFI_MISC_SUBCLASS_DRIVER_DATA MiscSubclass
;
69 // Do nothing if data parameters are not valid.
71 if (RecordLen
== 0 || RecordData
== NULL
) {
74 "RecordLen == %d RecordData == %xh\n",
79 return EFI_INVALID_PARAMETER
;
82 // Assemble Data Hub record.
84 MiscSubclass
.Header
.Version
= EFI_MISC_SUBCLASS_VERSION
;
85 MiscSubclass
.Header
.HeaderSize
= sizeof (EFI_SUBCLASS_TYPE1_HEADER
);
86 MiscSubclass
.Header
.Instance
= 1;
87 MiscSubclass
.Header
.SubInstance
= 1;
88 MiscSubclass
.Header
.RecordType
= RecordType
;
97 // Log Data Hub record.
99 EfiStatus
= DataHub
->LogData (
101 &gEfiMiscSubClassGuid
,
102 &gEfiMiscSubClassGuid
,
103 EFI_DATA_RECORD_CLASS_DATA
,
105 sizeof (EFI_SUBCLASS_TYPE1_HEADER
) + RecordLen
108 if (EFI_ERROR (EfiStatus
)) {
111 "LogData(%d bytes) == %r\n",
112 sizeof (EFI_SUBCLASS_TYPE1_HEADER
) + RecordLen
,
123 MiscSubclassDriverEntryPoint (
124 IN EFI_HANDLE ImageHandle
,
125 IN EFI_SYSTEM_TABLE
*SystemTable
130 Standard EFI driver point. This driver parses the mMiscSubclassDataTable
131 structure and reports any generated data to the DataHub.
136 Handle for the image of this driver
139 Pointer to the EFI System Table
144 The data was successfully reported to the Data Hub.
148 EFI_MISC_SUBCLASS_DRIVER_DATA RecordData
;
149 EFI_DATA_HUB_PROTOCOL
*DataHub
;
150 EFI_HII_HANDLE HiiHandle
;
151 EFI_STATUS EfiStatus
;
153 BOOLEAN LogRecordData
;
154 EFI_MEMORY_SUBCLASS_DRIVER_DATA MemorySubClassData
;
155 UINT64 TotalMemorySize
;
156 CHAR16
*UnixMemString
;
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 EfiStatus
= gBS
->LocateProtocol (&gEfiDataHubProtocolGuid
, NULL
, (VOID
**) &DataHub
);
173 if (EFI_ERROR (EfiStatus
)) {
174 DEBUG ((EFI_D_ERROR
, "Could not locate DataHub protocol. %r\n", EfiStatus
));
176 } else if (DataHub
== NULL
) {
177 DEBUG ((EFI_D_ERROR
, "LocateProtocol(DataHub) returned NULL pointer!\n"));
178 return EFI_DEVICE_ERROR
;
182 // Add our default strings to the HII database. They will be modified later.
184 HiiHandle
= HiiAddPackages (
185 &gEfiMiscSubClassGuid
,
190 if (HiiHandle
== NULL
) {
191 DEBUG ((EFI_D_ERROR
, "Could not log default strings to Hii. %r\n", EfiStatus
));
192 return EFI_OUT_OF_RESOURCES
;
198 for (Index
= 0; Index
< mMiscSubclassDataTableEntries
; ++Index
) {
200 // Stupidity check! Do nothing if RecordLen is zero.
201 // %%TBD - Should this be an error or a mechanism for ignoring
202 // records in the Data Table?
204 if (mMiscSubclassDataTable
[Index
].RecordLen
== 0) {
207 "mMiscSubclassDataTable[%d].RecordLen == 0\n",
214 // Initialize per-record portion of subclass header and
215 // copy static data into data portion of subclass record.
217 RecordData
.Header
.RecordType
= mMiscSubclassDataTable
[Index
].RecordType
;
219 if (mMiscSubclassDataTable
[Index
].RecordData
== NULL
) {
222 mMiscSubclassDataTable
[Index
].RecordLen
227 mMiscSubclassDataTable
[Index
].RecordData
,
228 mMiscSubclassDataTable
[Index
].RecordLen
232 // If the entry does not have a function pointer, just log the data.
234 if (mMiscSubclassDataTable
[Index
].Function
== NULL
) {
236 // Log RecordData to Data Hub.
238 EfiStatus
= DataHub
->LogData (
240 &gEfiMiscSubClassGuid
,
241 &gEfiMiscSubClassGuid
,
242 EFI_DATA_RECORD_CLASS_DATA
,
244 sizeof (EFI_SUBCLASS_TYPE1_HEADER
) + mMiscSubclassDataTable
[Index
].RecordLen
247 if (EFI_ERROR (EfiStatus
)) {
250 "LogData(%d bytes) == %r\n",
251 sizeof (EFI_SUBCLASS_TYPE1_HEADER
) + mMiscSubclassDataTable
[Index
].RecordLen
,
259 // The entry has a valid function pointer.
260 // Keep calling the function and logging data until there
261 // is no more data to log.
264 EfiStatus
= (*mMiscSubclassDataTable
[Index
].Function
)(mMiscSubclassDataTable
[Index
].RecordType
, &mMiscSubclassDataTable
[Index
].RecordLen
, &RecordData
.Record
, &LogRecordData
);
266 if (EFI_ERROR (EfiStatus
)) {
270 if (!LogRecordData
) {
276 EfiStatus
= DataHub
->LogData (
278 &gEfiMiscSubClassGuid
,
279 &gEfiMiscSubClassGuid
,
280 EFI_DATA_RECORD_CLASS_DATA
,
282 sizeof (EFI_SUBCLASS_TYPE1_HEADER
) + mMiscSubclassDataTable
[Index
].RecordLen
285 if (EFI_ERROR (EfiStatus
)) {
288 "LogData(%d bytes) == %r\n",
289 sizeof (EFI_SUBCLASS_TYPE1_HEADER
) + mMiscSubclassDataTable
[Index
].RecordLen
,
297 // Log Memory Size info based on PCD setting.
299 MemorySubClassData
.Header
.Instance
= 1;
300 MemorySubClassData
.Header
.SubInstance
= EFI_SUBCLASS_INSTANCE_NON_APPLICABLE
;
301 MemorySubClassData
.Header
.RecordType
= EFI_MEMORY_ARRAY_START_ADDRESS_RECORD_NUMBER
;
304 // Process Memory String in form size!size ...
305 // So 64!64 is 128 MB
307 UnixMemString
= PcdGetPtr (PcdUnixMemorySize
);
308 for (TotalMemorySize
= 0; *UnixMemString
!= '\0';) {
309 TotalMemorySize
+= StrDecimalToUint64 (UnixMemString
);
310 while (*UnixMemString
!= '\0') {
311 if (*UnixMemString
== '!') {
319 MemorySubClassData
.Record
.ArrayStartAddress
.MemoryArrayStartAddress
= 0;
320 MemorySubClassData
.Record
.ArrayStartAddress
.MemoryArrayEndAddress
= LShiftU64 (TotalMemorySize
, 20) - 1;
321 MemorySubClassData
.Record
.ArrayStartAddress
.PhysicalMemoryArrayLink
.ProducerName
= gEfiCallerIdGuid
;
322 MemorySubClassData
.Record
.ArrayStartAddress
.PhysicalMemoryArrayLink
.Instance
= 1;
323 MemorySubClassData
.Record
.ArrayStartAddress
.PhysicalMemoryArrayLink
.SubInstance
= EFI_SUBCLASS_INSTANCE_NON_APPLICABLE
;
324 MemorySubClassData
.Record
.ArrayStartAddress
.MemoryArrayPartitionWidth
= 0;
327 // Store memory size data record to data hub.
329 EfiStatus
= DataHub
->LogData (
331 &gEfiMemorySubClassGuid
,
333 EFI_DATA_RECORD_CLASS_DATA
,
335 sizeof (EFI_SUBCLASS_TYPE1_HEADER
) + sizeof (EFI_MEMORY_ARRAY_START_ADDRESS_DATA
)