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