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