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