]> git.proxmox.com Git - mirror_edk2.git/blame - UnixPkg/MiscSubClassPlatformDxe/MiscSubclassDriverEntryPoint.c
According to PI errata 0000654 and 000811, we need use 0xFFFE to instead of 0 for...
[mirror_edk2.git] / UnixPkg / MiscSubClassPlatformDxe / MiscSubclassDriverEntryPoint.c
CommitLineData
804405e7 1/*++\r
2\r
a762a877 3Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
f9b8ab56 4This program and the accompanying materials\r
804405e7 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
aaa2cc19 25EFI_HII_HANDLE mHiiHandle;\r
804405e7 26\r
aaa2cc19 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
804405e7 31\r
aaa2cc19 32 @param ImageHandle Handle for the image of this driver\r
33 @param SystemTable Pointer to the EFI System Table\r
804405e7 34\r
aaa2cc19 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
804405e7 37\r
aaa2cc19 38**/\r
39EFI_STATUS\r
40LogMemorySmbiosRecord (\r
41 VOID\r
42 )\r
804405e7 43{\r
aaa2cc19 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 *UnixMemString;\r
51\r
52 Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID**)&Smbios);\r
53 ASSERT_EFI_ERROR (Status);\r
54 \r
55 NumSlots = 1;\r
804405e7 56\r
57 //\r
aaa2cc19 58 // Process Memory String in form size!size ...\r
59 // So 64!64 is 128 MB\r
804405e7 60 //\r
aaa2cc19 61 UnixMemString = PcdGetPtr (PcdUnixMemorySize);\r
62 for (TotalMemorySize = 0; *UnixMemString != '\0';) {\r
63 TotalMemorySize += StrDecimalToUint64 (UnixMemString);\r
64 while (*UnixMemString != '\0') {\r
65 if (*UnixMemString == '!') {\r
66 UnixMemString++; \r
67 break;\r
68 }\r
69 UnixMemString++;\r
70 }\r
804405e7 71 }\r
aaa2cc19 72\r
73 //\r
74 // Convert Total Memory Size to based on KiloByte\r
804405e7 75 //\r
aaa2cc19 76 TotalMemorySize = LShiftU64 (TotalMemorySize, 20);\r
804405e7 77 //\r
aaa2cc19 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
88 Type19Record->PartitionWidth = (UINT8)(NumSlots); \r
804405e7 89\r
90 //\r
aaa2cc19 91 // Generate Memory Array Mapped Address info (TYPE 19)\r
804405e7 92 //\r
a762a877
SZ
93 Status = AddSmbiosRecord (Smbios, &MemArrayMappedAddrSmbiosHandle, (EFI_SMBIOS_TABLE_HEADER*) Type19Record);\r
94\r
aaa2cc19 95 FreePool(Type19Record);\r
96 ASSERT_EFI_ERROR (Status);\r
804405e7 97\r
aaa2cc19 98 return Status;\r
804405e7 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
aaa2cc19 129 UINTN Index;\r
130 EFI_STATUS EfiStatus;\r
131 EFI_SMBIOS_PROTOCOL *Smbios; \r
804405e7 132\r
aaa2cc19 133 EfiStatus = gBS->LocateProtocol(&gEfiSmbiosProtocolGuid, NULL, (VOID**)&Smbios);\r
804405e7 134\r
aaa2cc19 135 if (EFI_ERROR(EfiStatus)) {\r
136 DEBUG((EFI_D_ERROR, "Could not locate SMBIOS protocol. %r\n", EfiStatus));\r
804405e7 137 return EfiStatus;\r
804405e7 138 }\r
139\r
aaa2cc19 140 mHiiHandle = HiiAddPackages (\r
141 &gEfiCallerIdGuid,\r
142 NULL,\r
143 MiscSubclassStrings,\r
144 NULL\r
145 );\r
146 ASSERT (mHiiHandle != NULL);\r
cb7d01c0 147\r
804405e7 148 for (Index = 0; Index < mMiscSubclassDataTableEntries; ++Index) {\r
149 //\r
aaa2cc19 150 // If the entry have a function pointer, just log the data.\r
804405e7 151 //\r
aaa2cc19 152 if (mMiscSubclassDataTable[Index].Function != NULL) {\r
153 EfiStatus = (*mMiscSubclassDataTable[Index].Function)(\r
804405e7 154 mMiscSubclassDataTable[Index].RecordData,\r
aaa2cc19 155 Smbios\r
804405e7 156 );\r
804405e7 157\r
aaa2cc19 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
804405e7 161 }\r
804405e7 162 }\r
163 }\r
164\r
804405e7 165 //\r
aaa2cc19 166 // Log Memory SMBIOS Record\r
804405e7 167 //\r
aaa2cc19 168 EfiStatus = LogMemorySmbiosRecord();\r
169 return EfiStatus;\r
804405e7 170}\r
a762a877
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