]> git.proxmox.com Git - mirror_edk2.git/blame - EmulatorPkg/MiscSubClassPlatformDxe/MiscSubclassDriverEntryPoint.c
EmulatorPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / EmulatorPkg / MiscSubClassPlatformDxe / MiscSubclassDriverEntryPoint.c
CommitLineData
949f388f 1/*++\r
2\r
3e570e6e 3Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
e3ba31da 4SPDX-License-Identifier: BSD-2-Clause-Patent\r
949f388f 5\r
6Module Name:\r
7\r
8 MiscSubclassDriverEntryPoint.c\r
9\r
10Abstract:\r
11\r
12 This driver parses the mMiscSubclassDataTable structure and reports\r
13 any generated data to the DataHub.\r
14\r
15**/\r
16\r
17#include "MiscSubClassDriver.h"\r
18\r
19EFI_HII_HANDLE mHiiHandle;\r
20\r
21/**\r
22 This is the standard EFI driver point that detects whether there is a\r
23 MemoryConfigurationData Variable and, if so, reports memory configuration info\r
24 to the DataHub.\r
25\r
26 @param ImageHandle Handle for the image of this driver\r
27 @param SystemTable Pointer to the EFI System Table\r
28\r
29 @return EFI_SUCCESS if the data is successfully reported\r
30 @return EFI_NOT_FOUND if the HOB list could not be located.\r
31\r
32**/\r
33EFI_STATUS\r
34LogMemorySmbiosRecord (\r
35 VOID\r
36 )\r
37{\r
38 EFI_STATUS Status;\r
39 UINT64 TotalMemorySize;\r
40 UINT8 NumSlots;\r
41 SMBIOS_TABLE_TYPE19 *Type19Record;\r
42 EFI_SMBIOS_HANDLE MemArrayMappedAddrSmbiosHandle;\r
43 EFI_SMBIOS_PROTOCOL *Smbios;\r
44 CHAR16 *MemString;\r
45\r
46 Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID**)&Smbios);\r
47 ASSERT_EFI_ERROR (Status);\r
d18d8a1d 48\r
949f388f 49 NumSlots = 1;\r
50\r
51 //\r
52 // Process Memory String in form size!size ...\r
53 // So 64!64 is 128 MB\r
54 //\r
55 MemString = (CHAR16 *)PcdGetPtr (PcdEmuMemorySize);\r
56 for (TotalMemorySize = 0; *MemString != '\0';) {\r
57 TotalMemorySize += StrDecimalToUint64 (MemString);\r
58 while (*MemString != '\0') {\r
59 if (*MemString == '!') {\r
d18d8a1d 60 MemString++;\r
949f388f 61 break;\r
62 }\r
63 MemString++;\r
64 }\r
65 }\r
66\r
67 //\r
68 // Convert Total Memory Size to based on KiloByte\r
69 //\r
70 TotalMemorySize = LShiftU64 (TotalMemorySize, 20);\r
71 //\r
72 // Generate Memory Array Mapped Address info\r
73 //\r
3e570e6e 74 Type19Record = AllocateZeroPool(sizeof (SMBIOS_TABLE_TYPE19) + 2);\r
949f388f 75 Type19Record->Hdr.Type = EFI_SMBIOS_TYPE_MEMORY_ARRAY_MAPPED_ADDRESS;\r
76 Type19Record->Hdr.Length = sizeof(SMBIOS_TABLE_TYPE19);\r
77 Type19Record->Hdr.Handle = 0;\r
78 Type19Record->StartingAddress = 0;\r
79 Type19Record->EndingAddress = (UINT32)RShiftU64(TotalMemorySize, 10) - 1;\r
80 Type19Record->MemoryArrayHandle = 0;\r
d18d8a1d 81 Type19Record->PartitionWidth = (UINT8)(NumSlots);\r
949f388f 82\r
83 //\r
84 // Generate Memory Array Mapped Address info (TYPE 19)\r
85 //\r
2bfd90f9
SZ
86 Status = AddSmbiosRecord (Smbios, &MemArrayMappedAddrSmbiosHandle, (EFI_SMBIOS_TABLE_HEADER*) Type19Record);\r
87\r
949f388f 88 FreePool(Type19Record);\r
89 ASSERT_EFI_ERROR (Status);\r
90\r
91 return Status;\r
92}\r
93\r
94\r
95EFI_STATUS\r
96EFIAPI\r
97MiscSubclassDriverEntryPoint (\r
98 IN EFI_HANDLE ImageHandle,\r
99 IN EFI_SYSTEM_TABLE *SystemTable\r
100 )\r
101/*++\r
102Description:\r
103\r
104 Standard EFI driver point. This driver parses the mMiscSubclassDataTable\r
105 structure and reports any generated data to the DataHub.\r
106\r
107Arguments:\r
108\r
109 ImageHandle\r
110 Handle for the image of this driver\r
111\r
112 SystemTable\r
113 Pointer to the EFI System Table\r
114\r
115Returns:\r
116\r
117 EFI_SUCCESS\r
118 The data was successfully reported to the Data Hub.\r
119\r
120**/\r
121{\r
122 UINTN Index;\r
123 EFI_STATUS EfiStatus;\r
d18d8a1d 124 EFI_SMBIOS_PROTOCOL *Smbios;\r
949f388f 125\r
126 EfiStatus = gBS->LocateProtocol(&gEfiSmbiosProtocolGuid, NULL, (VOID**)&Smbios);\r
127\r
128 if (EFI_ERROR(EfiStatus)) {\r
129 DEBUG((EFI_D_ERROR, "Could not locate SMBIOS protocol. %r\n", EfiStatus));\r
130 return EfiStatus;\r
131 }\r
132\r
133 mHiiHandle = HiiAddPackages (\r
134 &gEfiCallerIdGuid,\r
135 NULL,\r
136 MiscSubclassStrings,\r
137 NULL\r
138 );\r
139 ASSERT (mHiiHandle != NULL);\r
140\r
141 for (Index = 0; Index < mMiscSubclassDataTableEntries; ++Index) {\r
142 //\r
143 // If the entry have a function pointer, just log the data.\r
144 //\r
145 if (mMiscSubclassDataTable[Index].Function != NULL) {\r
146 EfiStatus = (*mMiscSubclassDataTable[Index].Function)(\r
147 mMiscSubclassDataTable[Index].RecordData,\r
148 Smbios\r
149 );\r
150\r
151 if (EFI_ERROR(EfiStatus)) {\r
152 DEBUG((EFI_D_ERROR, "Misc smbios store error. Index=%d, ReturnStatus=%r\n", Index, EfiStatus));\r
153 return EfiStatus;\r
154 }\r
155 }\r
156 }\r
157\r
158 //\r
159 // Log Memory SMBIOS Record\r
160 //\r
161 EfiStatus = LogMemorySmbiosRecord();\r
162 return EfiStatus;\r
163}\r
2bfd90f9
SZ
164\r
165/**\r
166 Add an SMBIOS record.\r
167\r
168 @param Smbios The EFI_SMBIOS_PROTOCOL instance.\r
169 @param SmbiosHandle A unique handle will be assigned to the SMBIOS record.\r
170 @param Record The data for the fixed portion of the SMBIOS record. The format of the record is\r
79e4f2a5
RN
171 determined by EFI_SMBIOS_TABLE_HEADER.Type. The size of the formatted area is defined\r
172 by EFI_SMBIOS_TABLE_HEADER.Length and either followed by a double-null (0x0000) or\r
2bfd90f9
SZ
173 a set of null terminated strings and a null.\r
174\r
175 @retval EFI_SUCCESS Record was added.\r
176 @retval EFI_OUT_OF_RESOURCES Record was not added due to lack of system resources.\r
177\r
178**/\r
179EFI_STATUS\r
180AddSmbiosRecord (\r
181 IN EFI_SMBIOS_PROTOCOL *Smbios,\r
182 OUT EFI_SMBIOS_HANDLE *SmbiosHandle,\r
183 IN EFI_SMBIOS_TABLE_HEADER *Record\r
184 )\r
185{\r
186 *SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;\r
187 return Smbios->Add (\r
188 Smbios,\r
189 NULL,\r
190 SmbiosHandle,\r
191 Record\r
192 );\r
193}\r
194\r