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