]> git.proxmox.com Git - mirror_edk2.git/blob - Nt32Pkg/MiscSubClassPlatformDxe/MiscSubclassDriverEntryPoint.c
Fix ICC building issue for Nt32 platform.
[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 HiiLibAddPackages (1, &gEfiMiscSubClassGuid, NULL, &HiiHandle, MiscSubclassStrings);
184
185 if (EFI_ERROR (Status)) {
186 DEBUG ((EFI_D_ERROR, "Could not log default strings to Hii. %r\n", Status));
187 return Status;
188 }
189 //
190 //
191 //
192 for (Index = 0; Index < mMiscSubclassDataTableEntries; ++Index) {
193 //
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?
197 //
198 if (mMiscSubclassDataTable[Index].RecordLen == 0) {
199 DEBUG (
200 (EFI_D_ERROR,
201 "mMiscSubclassDataTable[%d].RecordLen == 0\n",
202 Index)
203 );
204
205 continue;
206 }
207 //
208 // Initialize per-record portion of subclass header and
209 // copy static data into data portion of subclass record.
210 //
211 RecordData.Header.RecordType = mMiscSubclassDataTable[Index].RecordType;
212
213 if (mMiscSubclassDataTable[Index].RecordData == NULL) {
214 ZeroMem (
215 &RecordData.Record,
216 mMiscSubclassDataTable[Index].RecordLen
217 );
218 } else {
219 CopyMem (
220 &RecordData.Record,
221 mMiscSubclassDataTable[Index].RecordData,
222 mMiscSubclassDataTable[Index].RecordLen
223 );
224 }
225 //
226 // If the entry does not have a function pointer, just log the data.
227 //
228 if (mMiscSubclassDataTable[Index].Function == NULL) {
229 //
230 // Log RecordData to Data Hub.
231 //
232 Status = DataHub->LogData (
233 DataHub,
234 &gEfiMiscSubClassGuid,
235 &gEfiMiscSubClassGuid,
236 EFI_DATA_RECORD_CLASS_DATA,
237 &RecordData,
238 sizeof (EFI_SUBCLASS_TYPE1_HEADER) + mMiscSubclassDataTable[Index].RecordLen
239 );
240
241 if (EFI_ERROR (Status)) {
242 DEBUG (
243 (EFI_D_ERROR,
244 "LogData(%d bytes) == %r\n",
245 sizeof (EFI_SUBCLASS_TYPE1_HEADER) + mMiscSubclassDataTable[Index].RecordLen,
246 Status)
247 );
248 }
249
250 continue;
251 }
252 //
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.
256 //
257 for (;;) {
258 Status = (*mMiscSubclassDataTable[Index].Function)(mMiscSubclassDataTable[Index].RecordType, &mMiscSubclassDataTable[Index].RecordLen, &RecordData.Record, &LogRecordData);
259 if (EFI_ERROR (Status)) {
260 break;
261 }
262
263 if (!LogRecordData) {
264 break;
265 }
266
267 Status = DataHub->LogData (
268 DataHub,
269 &gEfiMiscSubClassGuid,
270 &gEfiMiscSubClassGuid,
271 EFI_DATA_RECORD_CLASS_DATA,
272 &RecordData,
273 sizeof (EFI_SUBCLASS_TYPE1_HEADER) + mMiscSubclassDataTable[Index].RecordLen
274 );
275
276 if (EFI_ERROR (Status)) {
277 DEBUG (
278 (EFI_D_ERROR,
279 "LogData(%d bytes) == %r\n",
280 sizeof (EFI_SUBCLASS_TYPE1_HEADER) + mMiscSubclassDataTable[Index].RecordLen,
281 Status)
282 );
283 }
284 }
285 }
286
287
288 //
289 // Log Memory Size info based on PCD setting.
290 //
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;
294
295 //
296 // Process Memory String in form size!size ...
297 // So 64!64 is 128 MB
298 //
299 Nt32MemString = PcdGetPtr (PcdWinNtMemorySize);
300 for (TotalMemorySize = 0; *Nt32MemString != '\0';) {
301 TotalMemorySize += StrDecimalToUint64 (Nt32MemString);
302 while (*Nt32MemString != '\0') {
303 if (*Nt32MemString == '!') {
304 Nt32MemString++;
305 break;
306 }
307 Nt32MemString++;
308 }
309 }
310
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;
317
318 //
319 // Store memory size data record to data hub.
320 //
321 Status = DataHub->LogData (
322 DataHub,
323 &gEfiMemorySubClassGuid,
324 &gEfiMemoryProducerGuid,
325 EFI_DATA_RECORD_CLASS_DATA,
326 &MemorySubClassData,
327 sizeof (EFI_SUBCLASS_TYPE1_HEADER) + sizeof (EFI_MEMORY_ARRAY_START_ADDRESS_DATA)
328 );
329
330
331 return EFI_SUCCESS;
332 }
333
334