]> git.proxmox.com Git - mirror_edk2.git/blob - Nt32Pkg/MiscSubClassPlatformDxe/MiscSubclassDriverEntryPoint.c
HII Library Class interface refine.
[mirror_edk2.git] / Nt32Pkg / MiscSubClassPlatformDxe / MiscSubclassDriverEntryPoint.c
1 /**@file
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_HANDLE HiiHandle;
152 EFI_STATUS Status;
153 UINTN Index;
154 BOOLEAN LogRecordData;
155 EFI_MEMORY_SUBCLASS_DRIVER_DATA MemorySubClassData;
156 UINT64 TotalMemorySize;
157 CHAR16 *Nt32MemString;
158
159
160 //
161 // Initialize constant portion of subclass header.
162 //
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;
167
168 //
169 // Locate data hub protocol.
170 //
171 Status = gBS->LocateProtocol (&gEfiDataHubProtocolGuid, NULL, (VOID**)&DataHub);
172
173 if (EFI_ERROR (Status)) {
174 DEBUG ((EFI_D_ERROR, "Could not locate DataHub protocol. %r\n", Status));
175 return Status;
176 } else if (DataHub == NULL) {
177 DEBUG ((EFI_D_ERROR, "LocateProtocol(DataHub) returned NULL pointer!\n"));
178 return EFI_DEVICE_ERROR;
179 }
180 //
181 // Add our default strings to the HII database. They will be modified later.
182 //
183 HiiHandle = HiiAddPackages (
184 &gEfiMiscSubClassGuid,
185 NULL,
186 MiscSubclassStrings,
187 NULL
188 );
189 if (HiiHandle == NULL) {
190 DEBUG ((EFI_D_ERROR, "Could not log default strings to Hii. %r\n", Status));
191 return EFI_OUT_OF_RESOURCES;
192 }
193 //
194 //
195 //
196 for (Index = 0; Index < mMiscSubclassDataTableEntries; ++Index) {
197 //
198 // Stupidity check! Do nothing if RecordLen is zero.
199 // %%TBD - Should this be an error or a mechanism for ignoring
200 // records in the Data Table?
201 //
202 if (mMiscSubclassDataTable[Index].RecordLen == 0) {
203 DEBUG (
204 (EFI_D_ERROR,
205 "mMiscSubclassDataTable[%d].RecordLen == 0\n",
206 Index)
207 );
208
209 continue;
210 }
211 //
212 // Initialize per-record portion of subclass header and
213 // copy static data into data portion of subclass record.
214 //
215 RecordData.Header.RecordType = mMiscSubclassDataTable[Index].RecordType;
216
217 if (mMiscSubclassDataTable[Index].RecordData == NULL) {
218 ZeroMem (
219 &RecordData.Record,
220 mMiscSubclassDataTable[Index].RecordLen
221 );
222 } else {
223 CopyMem (
224 &RecordData.Record,
225 mMiscSubclassDataTable[Index].RecordData,
226 mMiscSubclassDataTable[Index].RecordLen
227 );
228 }
229 //
230 // If the entry does not have a function pointer, just log the data.
231 //
232 if (mMiscSubclassDataTable[Index].Function == NULL) {
233 //
234 // Log RecordData to Data Hub.
235 //
236 Status = DataHub->LogData (
237 DataHub,
238 &gEfiMiscSubClassGuid,
239 &gEfiMiscSubClassGuid,
240 EFI_DATA_RECORD_CLASS_DATA,
241 &RecordData,
242 sizeof (EFI_SUBCLASS_TYPE1_HEADER) + mMiscSubclassDataTable[Index].RecordLen
243 );
244
245 if (EFI_ERROR (Status)) {
246 DEBUG (
247 (EFI_D_ERROR,
248 "LogData(%d bytes) == %r\n",
249 sizeof (EFI_SUBCLASS_TYPE1_HEADER) + mMiscSubclassDataTable[Index].RecordLen,
250 Status)
251 );
252 }
253
254 continue;
255 }
256 //
257 // The entry has a valid function pointer.
258 // Keep calling the function and logging data until there
259 // is no more data to log.
260 //
261 for (;;) {
262 Status = (*mMiscSubclassDataTable[Index].Function)(mMiscSubclassDataTable[Index].RecordType, &mMiscSubclassDataTable[Index].RecordLen, &RecordData.Record, &LogRecordData);
263 if (EFI_ERROR (Status)) {
264 break;
265 }
266
267 if (!LogRecordData) {
268 break;
269 }
270
271 Status = DataHub->LogData (
272 DataHub,
273 &gEfiMiscSubClassGuid,
274 &gEfiMiscSubClassGuid,
275 EFI_DATA_RECORD_CLASS_DATA,
276 &RecordData,
277 sizeof (EFI_SUBCLASS_TYPE1_HEADER) + mMiscSubclassDataTable[Index].RecordLen
278 );
279
280 if (EFI_ERROR (Status)) {
281 DEBUG (
282 (EFI_D_ERROR,
283 "LogData(%d bytes) == %r\n",
284 sizeof (EFI_SUBCLASS_TYPE1_HEADER) + mMiscSubclassDataTable[Index].RecordLen,
285 Status)
286 );
287 }
288 }
289 }
290
291
292 //
293 // Log Memory Size info based on PCD setting.
294 //
295 MemorySubClassData.Header.Instance = 1;
296 MemorySubClassData.Header.SubInstance = EFI_SUBCLASS_INSTANCE_NON_APPLICABLE;
297 MemorySubClassData.Header.RecordType = EFI_MEMORY_ARRAY_START_ADDRESS_RECORD_NUMBER;
298
299 //
300 // Process Memory String in form size!size ...
301 // So 64!64 is 128 MB
302 //
303 Nt32MemString = PcdGetPtr (PcdWinNtMemorySize);
304 for (TotalMemorySize = 0; *Nt32MemString != '\0';) {
305 TotalMemorySize += StrDecimalToUint64 (Nt32MemString);
306 while (*Nt32MemString != '\0') {
307 if (*Nt32MemString == '!') {
308 Nt32MemString++;
309 break;
310 }
311 Nt32MemString++;
312 }
313 }
314
315 MemorySubClassData.Record.ArrayStartAddress.MemoryArrayStartAddress = 0;
316 MemorySubClassData.Record.ArrayStartAddress.MemoryArrayEndAddress = LShiftU64 (TotalMemorySize, 20) - 1;
317 MemorySubClassData.Record.ArrayStartAddress.PhysicalMemoryArrayLink.ProducerName = gEfiMemoryProducerGuid;
318 MemorySubClassData.Record.ArrayStartAddress.PhysicalMemoryArrayLink.Instance = 1;
319 MemorySubClassData.Record.ArrayStartAddress.PhysicalMemoryArrayLink.SubInstance = EFI_SUBCLASS_INSTANCE_NON_APPLICABLE;
320 MemorySubClassData.Record.ArrayStartAddress.MemoryArrayPartitionWidth = 0;
321
322 //
323 // Store memory size data record to data hub.
324 //
325 Status = DataHub->LogData (
326 DataHub,
327 &gEfiMemorySubClassGuid,
328 &gEfiMemoryProducerGuid,
329 EFI_DATA_RECORD_CLASS_DATA,
330 &MemorySubClassData,
331 sizeof (EFI_SUBCLASS_TYPE1_HEADER) + sizeof (EFI_MEMORY_ARRAY_START_ADDRESS_DATA)
332 );
333
334
335 return EFI_SUCCESS;
336 }
337
338