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