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