]> git.proxmox.com Git - mirror_edk2.git/blame - EmulatorPkg/MiscSubClassPlatformDxe/MiscBiosVendorFunction.c
DynamicTablesPkg: add package .dsc file
[mirror_edk2.git] / EmulatorPkg / MiscSubClassPlatformDxe / MiscBiosVendorFunction.c
CommitLineData
949f388f 1/** @file\r
2 BIOS vendor information boot time changes.\r
3 Misc. subclass type 2.\r
4 SMBIOS type 0.\r
5\r
6 Copyright (c) 2009, Intel Corporation. All rights reserved.<BR>\r
7 This program and the accompanying materials\r
8 are licensed and made available under the terms and conditions of the BSD License\r
9 which accompanies this distribution. The full text of the license may be found at\r
10 http://opensource.org/licenses/bsd-license.php\r
11\r
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15**/\r
16\r
17#include "MiscSubClassDriver.h"\r
18\r
19/**\r
20 This function returns the value & exponent to Base2 for a given\r
21 Hex value. This is used to calculate the BiosPhysicalDeviceSize.\r
22\r
23 @param Value The hex value which is to be converted into value-exponent form\r
24 @param Exponent The exponent out of the conversion\r
25\r
26 @retval EFI_SUCCESS All parameters were valid and *Value & *Exponent have been set.\r
27 @retval EFI_INVALID_PARAMETER Invalid parameter was found.\r
d18d8a1d 28\r
949f388f 29**/\r
d18d8a1d 30EFI_STATUS\r
949f388f 31GetValueExponentBase2(\r
32 IN OUT UINTN *Value,\r
33 OUT UINTN *Exponent\r
34 )\r
35{\r
36 if ((Value == NULL) || (Exponent == NULL)) {\r
37 return EFI_INVALID_PARAMETER;\r
38 }\r
d18d8a1d 39\r
949f388f 40 while ((*Value % 2) == 0) {\r
41 *Value=*Value/2;\r
42 (*Exponent)++;\r
43 }\r
44\r
45 return EFI_SUCCESS;\r
46}\r
47\r
48/**\r
49 Field Filling Function. Transform an EFI_EXP_BASE2_DATA to a byte, with '64k'\r
50 as the unit.\r
51\r
52 @param Base2Data Pointer to Base2_Data\r
53\r
d18d8a1d 54 @retval EFI_SUCCESS Transform successfully.\r
55 @retval EFI_INVALID_PARAMETER Invalid parameter was found.\r
949f388f 56\r
57**/\r
58UINT16\r
59Base2ToByteWith64KUnit (\r
60 IN EFI_EXP_BASE2_DATA *Base2Data\r
61 )\r
d18d8a1d 62{\r
949f388f 63 UINT16 Value;\r
64 UINT16 Exponent;\r
65\r
66 Value = Base2Data->Value;\r
67 Exponent = Base2Data->Exponent;\r
68 Exponent -= 16;\r
69 Value <<= Exponent;\r
70\r
71 return Value;\r
72}\r
73\r
74\r
75/**\r
76 This function makes boot time changes to the contents of the\r
77 MiscBiosVendor (Type 0).\r
78\r
79 @param RecordData Pointer to copy of RecordData from the Data Table.\r
80\r
81 @retval EFI_SUCCESS All parameters were valid.\r
82 @retval EFI_UNSUPPORTED Unexpected RecordType value.\r
83 @retval EFI_INVALID_PARAMETER Invalid parameter was found.\r
84\r
85**/\r
86MISC_SMBIOS_TABLE_FUNCTION(MiscBiosVendor)\r
87{\r
88 CHAR8 *OptionalStrStart;\r
89 UINTN VendorStrLen;\r
90 UINTN VerStrLen;\r
91 UINTN DateStrLen;\r
92 CHAR16 *Version;\r
93 CHAR16 *ReleaseDate;\r
94 EFI_STATUS Status;\r
95 EFI_STRING Char16String;\r
96 STRING_REF TokenToGet;\r
97 STRING_REF TokenToUpdate;\r
98 SMBIOS_TABLE_TYPE0 *SmbiosRecord;\r
99 EFI_SMBIOS_HANDLE SmbiosHandle;\r
100 EFI_MISC_BIOS_VENDOR *ForType0InputData;\r
101\r
102 ForType0InputData = (EFI_MISC_BIOS_VENDOR *)RecordData;\r
103\r
104 //\r
105 // First check for invalid parameters.\r
106 //\r
107 if (RecordData == NULL) {\r
108 return EFI_INVALID_PARAMETER;\r
109 }\r
110\r
111 Version = (CHAR16 *) PcdGetPtr (PcdFirmwareVersionString);\r
d18d8a1d 112 if (StrLen (Version) > 0) {\r
949f388f 113 TokenToUpdate = STRING_TOKEN (STR_MISC_BIOS_VERSION);\r
114 HiiSetString (mHiiHandle, TokenToUpdate, Version, NULL);\r
115 }\r
d18d8a1d 116\r
949f388f 117 ReleaseDate = (CHAR16 *) PcdGetPtr (PcdFirmwareReleaseDateString);\r
118 if (StrLen(ReleaseDate) > 0) {\r
119 TokenToUpdate = STRING_TOKEN (STR_MISC_BIOS_RELEASE_DATE);\r
120 HiiSetString (mHiiHandle, TokenToUpdate, ReleaseDate, NULL);\r
121 }\r
122\r
123 TokenToGet = STRING_TOKEN (STR_MISC_BIOS_VENDOR);\r
124 Char16String = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);\r
125 VendorStrLen = StrLen(Char16String);\r
126 if (VendorStrLen > SMBIOS_STRING_MAX_LENGTH) {\r
127 return EFI_UNSUPPORTED;\r
128 }\r
129\r
130 TokenToGet = STRING_TOKEN (STR_MISC_BIOS_VERSION);\r
131 Version = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);\r
132 VerStrLen = StrLen(Version);\r
133 if (VerStrLen > SMBIOS_STRING_MAX_LENGTH) {\r
134 return EFI_UNSUPPORTED;\r
135 }\r
136\r
137 TokenToGet = STRING_TOKEN (STR_MISC_BIOS_RELEASE_DATE);\r
138 ReleaseDate = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);\r
139 DateStrLen = StrLen(ReleaseDate);\r
140 if (DateStrLen > SMBIOS_STRING_MAX_LENGTH) {\r
141 return EFI_UNSUPPORTED;\r
142 }\r
d18d8a1d 143\r
949f388f 144 //\r
145 // Two zeros following the last string.\r
146 //\r
147 SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE0) + VendorStrLen + 1 + VerStrLen + 1 + DateStrLen + 1 + 1);\r
148 ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE0) + VendorStrLen + 1 + VerStrLen + 1 + DateStrLen + 1 + 1);\r
149\r
150 SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_BIOS_INFORMATION;\r
151 SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE0);\r
152 //\r
153 // Make handle chosen by smbios protocol.add automatically.\r
154 //\r
155 SmbiosRecord->Hdr.Handle = 0;\r
156 //\r
157 // Vendor will be the 1st optional string following the formatted structure.\r
158 //\r
d18d8a1d 159 SmbiosRecord->Vendor = 1;\r
949f388f 160 //\r
161 // Version will be the 2nd optional string following the formatted structure.\r
162 //\r
163 SmbiosRecord->BiosVersion = 2;\r
164 SmbiosRecord->BiosSegment = (UINT16)ForType0InputData->BiosStartingAddress;\r
165 //\r
166 // ReleaseDate will be the 3rd optional string following the formatted structure.\r
167 //\r
168 SmbiosRecord->BiosReleaseDate = 3;\r
169 //\r
170 // Nt32 has no PCD value to indicate BIOS Size, just fill 0 for simply.\r
171 //\r
172 SmbiosRecord->BiosSize = 0;\r
173 SmbiosRecord->BiosCharacteristics = *(MISC_BIOS_CHARACTERISTICS*)(&ForType0InputData->BiosCharacteristics1);\r
174 //\r
175 // CharacterExtensionBytes also store in ForType0InputData->BiosCharacteristics1 later two bytes to save size.\r
176 //\r
177 SmbiosRecord->BIOSCharacteristicsExtensionBytes[0] = *((UINT8 *) &ForType0InputData->BiosCharacteristics1 + 4);\r
178 SmbiosRecord->BIOSCharacteristicsExtensionBytes[1] = *((UINT8 *) &ForType0InputData->BiosCharacteristics1 + 5);\r
179\r
180 SmbiosRecord->SystemBiosMajorRelease = ForType0InputData->BiosMajorRelease;\r
181 SmbiosRecord->SystemBiosMinorRelease = ForType0InputData->BiosMinorRelease;\r
182 SmbiosRecord->EmbeddedControllerFirmwareMajorRelease = ForType0InputData->BiosEmbeddedFirmwareMajorRelease;\r
183 SmbiosRecord->EmbeddedControllerFirmwareMinorRelease = ForType0InputData->BiosEmbeddedFirmwareMinorRelease;\r
184\r
185 OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);\r
186 UnicodeStrToAsciiStr(Char16String, OptionalStrStart);\r
187 UnicodeStrToAsciiStr(Version, OptionalStrStart + VendorStrLen + 1);\r
188 UnicodeStrToAsciiStr(ReleaseDate, OptionalStrStart + VendorStrLen + 1 + VerStrLen + 1);\r
189 //\r
190 // Now we have got the full smbios record, call smbios protocol to add this record.\r
191 //\r
2bfd90f9 192 Status = AddSmbiosRecord (Smbios, &SmbiosHandle, (EFI_SMBIOS_TABLE_HEADER *) SmbiosRecord);\r
949f388f 193\r
194 FreePool(SmbiosRecord);\r
195 return Status;\r
196}\r