]> git.proxmox.com Git - mirror_edk2.git/blob - UnixPkg/MiscSubClassPlatformDxe/MiscSubclassDriverEntryPoint.c
HII Library Class interface refine.
[mirror_edk2.git] / UnixPkg / MiscSubClassPlatformDxe / MiscSubclassDriverEntryPoint.c
1 /*++
2
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
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 EFI_STATUS
32 LogRecordDataToDataHub (
33 EFI_DATA_HUB_PROTOCOL *DataHub,
34 UINT32 RecordType,
35 UINT32 RecordLen,
36 VOID *RecordData
37 )
38 /*++
39 Description:
40
41 Parameters:
42
43 DataHub
44 %%TBD
45
46 RecordType
47 %%TBD
48
49 RecordLen
50 %%TBD
51
52 RecordData
53 %%TBD
54
55 Returns:
56
57 EFI_INVALID_PARAMETER
58
59 EFI_SUCCESS
60
61 Other Data Hub errors
62
63 --*/
64 {
65 EFI_MISC_SUBCLASS_DRIVER_DATA MiscSubclass;
66 EFI_STATUS EfiStatus;
67
68 //
69 // Do nothing if data parameters are not valid.
70 //
71 if (RecordLen == 0 || RecordData == NULL) {
72 DEBUG (
73 (EFI_D_ERROR,
74 "RecordLen == %d RecordData == %xh\n",
75 RecordLen,
76 RecordData)
77 );
78
79 return EFI_INVALID_PARAMETER;
80 }
81 //
82 // Assemble Data Hub record.
83 //
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;
89
90 CopyMem (
91 &MiscSubclass.Record,
92 RecordData,
93 RecordLen
94 );
95
96 //
97 // Log Data Hub record.
98 //
99 EfiStatus = DataHub->LogData (
100 DataHub,
101 &gEfiMiscSubClassGuid,
102 &gEfiMiscSubClassGuid,
103 EFI_DATA_RECORD_CLASS_DATA,
104 &MiscSubclass,
105 sizeof (EFI_SUBCLASS_TYPE1_HEADER) + RecordLen
106 );
107
108 if (EFI_ERROR (EfiStatus)) {
109 DEBUG (
110 (EFI_D_ERROR,
111 "LogData(%d bytes) == %r\n",
112 sizeof (EFI_SUBCLASS_TYPE1_HEADER) + RecordLen,
113 EfiStatus)
114 );
115 }
116
117 return EfiStatus;
118 }
119
120
121 EFI_STATUS
122 EFIAPI
123 MiscSubclassDriverEntryPoint (
124 IN EFI_HANDLE ImageHandle,
125 IN EFI_SYSTEM_TABLE *SystemTable
126 )
127 /*++
128 Description:
129
130 Standard EFI driver point. This driver parses the mMiscSubclassDataTable
131 structure and reports any generated data to the DataHub.
132
133 Arguments:
134
135 ImageHandle
136 Handle for the image of this driver
137
138 SystemTable
139 Pointer to the EFI System Table
140
141 Returns:
142
143 EFI_SUCCESS
144 The data was successfully reported to the Data Hub.
145
146 --*/
147 {
148 EFI_MISC_SUBCLASS_DRIVER_DATA RecordData;
149 EFI_DATA_HUB_PROTOCOL *DataHub;
150 EFI_HII_HANDLE HiiHandle;
151 EFI_STATUS EfiStatus;
152 UINTN Index;
153 BOOLEAN LogRecordData;
154 EFI_MEMORY_SUBCLASS_DRIVER_DATA MemorySubClassData;
155 UINT64 TotalMemorySize;
156 CHAR16 *UnixMemString;
157
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 EfiStatus = gBS->LocateProtocol (&gEfiDataHubProtocolGuid, NULL, (VOID**) &DataHub);
172
173 if (EFI_ERROR (EfiStatus)) {
174 DEBUG ((EFI_D_ERROR, "Could not locate DataHub protocol. %r\n", EfiStatus));
175 return EfiStatus;
176 } else if (DataHub == NULL) {
177 DEBUG ((EFI_D_ERROR, "LocateProtocol(DataHub) returned NULL pointer!\n"));
178 return EFI_DEVICE_ERROR;
179 }
180
181 //
182 // Add our default strings to the HII database. They will be modified later.
183 //
184 HiiHandle = HiiAddPackages (
185 &gEfiMiscSubClassGuid,
186 NULL,
187 MiscSubclassStrings,
188 NULL
189 );
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;
193 }
194
195 //
196 //
197 //
198 for (Index = 0; Index < mMiscSubclassDataTableEntries; ++Index) {
199 //
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?
203 //
204 if (mMiscSubclassDataTable[Index].RecordLen == 0) {
205 DEBUG (
206 (EFI_D_ERROR,
207 "mMiscSubclassDataTable[%d].RecordLen == 0\n",
208 Index)
209 );
210
211 continue;
212 }
213 //
214 // Initialize per-record portion of subclass header and
215 // copy static data into data portion of subclass record.
216 //
217 RecordData.Header.RecordType = mMiscSubclassDataTable[Index].RecordType;
218
219 if (mMiscSubclassDataTable[Index].RecordData == NULL) {
220 ZeroMem (
221 &RecordData.Record,
222 mMiscSubclassDataTable[Index].RecordLen
223 );
224 } else {
225 CopyMem (
226 &RecordData.Record,
227 mMiscSubclassDataTable[Index].RecordData,
228 mMiscSubclassDataTable[Index].RecordLen
229 );
230 }
231 //
232 // If the entry does not have a function pointer, just log the data.
233 //
234 if (mMiscSubclassDataTable[Index].Function == NULL) {
235 //
236 // Log RecordData to Data Hub.
237 //
238 EfiStatus = DataHub->LogData (
239 DataHub,
240 &gEfiMiscSubClassGuid,
241 &gEfiMiscSubClassGuid,
242 EFI_DATA_RECORD_CLASS_DATA,
243 &RecordData,
244 sizeof (EFI_SUBCLASS_TYPE1_HEADER) + mMiscSubclassDataTable[Index].RecordLen
245 );
246
247 if (EFI_ERROR (EfiStatus)) {
248 DEBUG (
249 (EFI_D_ERROR,
250 "LogData(%d bytes) == %r\n",
251 sizeof (EFI_SUBCLASS_TYPE1_HEADER) + mMiscSubclassDataTable[Index].RecordLen,
252 EfiStatus)
253 );
254 }
255
256 continue;
257 }
258 //
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.
262 //
263 for (;;) {
264 EfiStatus = (*mMiscSubclassDataTable[Index].Function)(mMiscSubclassDataTable[Index].RecordType, &mMiscSubclassDataTable[Index].RecordLen, &RecordData.Record, &LogRecordData);
265
266 if (EFI_ERROR (EfiStatus)) {
267 break;
268 }
269
270 if (!LogRecordData) {
271 break;
272 }
273 //
274 //
275 //
276 EfiStatus = DataHub->LogData (
277 DataHub,
278 &gEfiMiscSubClassGuid,
279 &gEfiMiscSubClassGuid,
280 EFI_DATA_RECORD_CLASS_DATA,
281 &RecordData,
282 sizeof (EFI_SUBCLASS_TYPE1_HEADER) + mMiscSubclassDataTable[Index].RecordLen
283 );
284
285 if (EFI_ERROR (EfiStatus)) {
286 DEBUG (
287 (EFI_D_ERROR,
288 "LogData(%d bytes) == %r\n",
289 sizeof (EFI_SUBCLASS_TYPE1_HEADER) + mMiscSubclassDataTable[Index].RecordLen,
290 EfiStatus)
291 );
292 }
293 }
294 }
295
296 //
297 // Log Memory Size info based on PCD setting.
298 //
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;
302
303 //
304 // Process Memory String in form size!size ...
305 // So 64!64 is 128 MB
306 //
307 UnixMemString = PcdGetPtr (PcdUnixMemorySize);
308 for (TotalMemorySize = 0; *UnixMemString != '\0';) {
309 TotalMemorySize += StrDecimalToUint64 (UnixMemString);
310 while (*UnixMemString != '\0') {
311 if (*UnixMemString == '!') {
312 UnixMemString++;
313 break;
314 }
315 UnixMemString++;
316 }
317 }
318
319 MemorySubClassData.Record.ArrayStartAddress.MemoryArrayStartAddress = 0;
320 MemorySubClassData.Record.ArrayStartAddress.MemoryArrayEndAddress = LShiftU64 (TotalMemorySize, 20) - 1;
321 MemorySubClassData.Record.ArrayStartAddress.PhysicalMemoryArrayLink.ProducerName = gEfiMemoryProducerGuid;
322 MemorySubClassData.Record.ArrayStartAddress.PhysicalMemoryArrayLink.Instance = 1;
323 MemorySubClassData.Record.ArrayStartAddress.PhysicalMemoryArrayLink.SubInstance = EFI_SUBCLASS_INSTANCE_NON_APPLICABLE;
324 MemorySubClassData.Record.ArrayStartAddress.MemoryArrayPartitionWidth = 0;
325
326 //
327 // Store memory size data record to data hub.
328 //
329 EfiStatus = DataHub->LogData (
330 DataHub,
331 &gEfiMemorySubClassGuid,
332 &gEfiMemoryProducerGuid,
333 EFI_DATA_RECORD_CLASS_DATA,
334 &MemorySubClassData,
335 sizeof (EFI_SUBCLASS_TYPE1_HEADER) + sizeof (EFI_MEMORY_ARRAY_START_ADDRESS_DATA)
336 );
337
338 return EFI_SUCCESS;
339 }