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 HiiLibAddPackages (1, &gEfiMiscSubClassGuid
, NULL
, &HiiHandle
, MiscSubclassStrings
);
186 if (EFI_ERROR (EfiStatus
)) {
187 DEBUG ((EFI_D_ERROR
, "Could not log default strings to Hii. %r\n", EfiStatus
));
193 for (Index
= 0; Index
< mMiscSubclassDataTableEntries
; ++Index
) {
195 // Stupidity check! Do nothing if RecordLen is zero.
196 // %%TBD - Should this be an error or a mechanism for ignoring
197 // records in the Data Table?
199 if (mMiscSubclassDataTable
[Index
].RecordLen
== 0) {
202 "mMiscSubclassDataTable[%d].RecordLen == 0\n",
209 // Initialize per-record portion of subclass header and
210 // copy static data into data portion of subclass record.
212 RecordData
.Header
.RecordType
= mMiscSubclassDataTable
[Index
].RecordType
;
214 if (mMiscSubclassDataTable
[Index
].RecordData
== NULL
) {
217 mMiscSubclassDataTable
[Index
].RecordLen
222 mMiscSubclassDataTable
[Index
].RecordData
,
223 mMiscSubclassDataTable
[Index
].RecordLen
227 // If the entry does not have a function pointer, just log the data.
229 if (mMiscSubclassDataTable
[Index
].Function
== NULL
) {
231 // Log RecordData to Data Hub.
233 EfiStatus
= DataHub
->LogData (
235 &gEfiMiscSubClassGuid
,
236 &gEfiMiscSubClassGuid
,
237 EFI_DATA_RECORD_CLASS_DATA
,
239 sizeof (EFI_SUBCLASS_TYPE1_HEADER
) + mMiscSubclassDataTable
[Index
].RecordLen
242 if (EFI_ERROR (EfiStatus
)) {
245 "LogData(%d bytes) == %r\n",
246 sizeof (EFI_SUBCLASS_TYPE1_HEADER
) + mMiscSubclassDataTable
[Index
].RecordLen
,
254 // The entry has a valid function pointer.
255 // Keep calling the function and logging data until there
256 // is no more data to log.
259 EfiStatus
= (*mMiscSubclassDataTable
[Index
].Function
)(mMiscSubclassDataTable
[Index
].RecordType
, &mMiscSubclassDataTable
[Index
].RecordLen
, &RecordData
.Record
, &LogRecordData
);
261 if (EFI_ERROR (EfiStatus
)) {
265 if (!LogRecordData
) {
271 EfiStatus
= DataHub
->LogData (
273 &gEfiMiscSubClassGuid
,
274 &gEfiMiscSubClassGuid
,
275 EFI_DATA_RECORD_CLASS_DATA
,
277 sizeof (EFI_SUBCLASS_TYPE1_HEADER
) + mMiscSubclassDataTable
[Index
].RecordLen
280 if (EFI_ERROR (EfiStatus
)) {
283 "LogData(%d bytes) == %r\n",
284 sizeof (EFI_SUBCLASS_TYPE1_HEADER
) + mMiscSubclassDataTable
[Index
].RecordLen
,
292 // Log Memory Size info based on PCD setting.
294 MemorySubClassData
.Header
.Instance
= 1;
295 MemorySubClassData
.Header
.SubInstance
= EFI_SUBCLASS_INSTANCE_NON_APPLICABLE
;
296 MemorySubClassData
.Header
.RecordType
= EFI_MEMORY_ARRAY_START_ADDRESS_RECORD_NUMBER
;
299 // Process Memory String in form size!size ...
300 // So 64!64 is 128 MB
302 UnixMemString
= PcdGetPtr (PcdUnixMemorySize
);
303 for (TotalMemorySize
= 0; *UnixMemString
!= '\0';) {
304 TotalMemorySize
+= StrDecimalToUint64 (UnixMemString
);
305 while (*UnixMemString
!= '\0') {
306 if (*UnixMemString
== '!') {
314 MemorySubClassData
.Record
.ArrayStartAddress
.MemoryArrayStartAddress
= 0;
315 MemorySubClassData
.Record
.ArrayStartAddress
.MemoryArrayEndAddress
= LShiftU64 (TotalMemorySize
, 20) - 1;
316 MemorySubClassData
.Record
.ArrayStartAddress
.PhysicalMemoryArrayLink
.ProducerName
= gEfiMemoryProducerGuid
;
317 MemorySubClassData
.Record
.ArrayStartAddress
.PhysicalMemoryArrayLink
.Instance
= 1;
318 MemorySubClassData
.Record
.ArrayStartAddress
.PhysicalMemoryArrayLink
.SubInstance
= EFI_SUBCLASS_INSTANCE_NON_APPLICABLE
;
319 MemorySubClassData
.Record
.ArrayStartAddress
.MemoryArrayPartitionWidth
= 0;
322 // Store memory size data record to data hub.
324 EfiStatus
= DataHub
->LogData (
326 &gEfiMemorySubClassGuid
,
327 &gEfiMemoryProducerGuid
,
328 EFI_DATA_RECORD_CLASS_DATA
,
330 sizeof (EFI_SUBCLASS_TYPE1_HEADER
) + sizeof (EFI_MEMORY_ARRAY_START_ADDRESS_DATA
)