MiscBiosVendorFunction.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. /*++
  2. Copyright (c) 2009 - 2020, Intel Corporation. All rights reserved.<BR>
  3. SPDX-License-Identifier: BSD-2-Clause-Patent
  4. Module Name:
  5. MiscBiosVendorFunction.c
  6. Abstract:
  7. BIOS vendor information boot time changes.
  8. Misc. subclass type 2.
  9. SMBIOS type 0.
  10. --*/
  11. #include "CommonHeader.h"
  12. #include "MiscSubclassDriver.h"
  13. #include <Library/BiosIdLib.h>
  14. #include <Library/SpiFlash.H>
  15. EFI_SPI_PROTOCOL *mSpiProtocol = NULL;
  16. /**
  17. This function read the data from Spi Rom.
  18. @param BaseAddress The starting address of the read.
  19. @param Byte The pointer to the destination buffer.
  20. @param Length The number of bytes.
  21. @param SpiRegionType Spi Region Type.
  22. @retval Status
  23. **/
  24. EFI_STATUS
  25. FlashRead (
  26. IN UINTN BaseAddress,
  27. IN UINT8 *Byte,
  28. IN UINTN Length,
  29. IN SPI_REGION_TYPE SpiRegionType
  30. )
  31. {
  32. EFI_STATUS Status = EFI_SUCCESS;
  33. UINT32 SectorSize;
  34. UINT32 SpiAddress;
  35. UINT8 Buffer[SECTOR_SIZE_4KB];
  36. SpiAddress = (UINT32)(UINTN)(BaseAddress);
  37. SectorSize = SECTOR_SIZE_4KB;
  38. Status = mSpiProtocol->Execute (
  39. mSpiProtocol,
  40. SPI_READ,
  41. SPI_WREN,
  42. TRUE,
  43. TRUE,
  44. FALSE,
  45. (UINT32) SpiAddress,
  46. SectorSize,
  47. Buffer,
  48. SpiRegionType
  49. );
  50. if (EFI_ERROR (Status)) {
  51. #ifdef _SHOW_LOG_
  52. Print(L"Read SPI ROM Failed [%08x]\n", SpiAddress);
  53. #endif
  54. return Status;
  55. }
  56. CopyMem (Byte, (void *)Buffer, Length);
  57. return Status;
  58. }
  59. /**
  60. This function returns the value & exponent to Base2 for a given
  61. Hex value. This is used to calculate the BiosPhysicalDeviceSize.
  62. @param Value The hex value which is to be converted into value-exponent form
  63. @param Exponent The exponent out of the conversion
  64. @retval EFI_SUCCESS All parameters were valid and *Value & *Exponent have been set.
  65. @retval EFI_INVALID_PARAMETER Invalid parameter was found.
  66. **/
  67. EFI_STATUS
  68. GetValueExponentBase2(
  69. IN OUT UINTN *Value,
  70. OUT UINTN *Exponent
  71. )
  72. {
  73. if ((Value == NULL) || (Exponent == NULL)) {
  74. return EFI_INVALID_PARAMETER;
  75. }
  76. while ((*Value % 2) == 0) {
  77. *Value=*Value/2;
  78. (*Exponent)++;
  79. }
  80. return EFI_SUCCESS;
  81. }
  82. /**
  83. Field Filling Function. Transform an EFI_EXP_BASE2_DATA to a byte, with '64k'
  84. as the unit.
  85. @param Base2Data Pointer to Base2_Data
  86. @retval EFI_SUCCESS Transform successfully.
  87. @retval EFI_INVALID_PARAMETER Invalid parameter was found.
  88. **/
  89. UINT16
  90. Base2ToByteWith64KUnit (
  91. IN EFI_EXP_BASE2_DATA *Base2Data
  92. )
  93. {
  94. UINT16 Value;
  95. UINT16 Exponent;
  96. Value = Base2Data->Value;
  97. Exponent = Base2Data->Exponent;
  98. Exponent -= 16;
  99. Value <<= Exponent;
  100. return Value;
  101. }
  102. /**
  103. This function makes boot time changes to the contents of the
  104. MiscBiosVendor (Type 0).
  105. @param RecordData Pointer to copy of RecordData from the Data Table.
  106. @retval EFI_SUCCESS All parameters were valid.
  107. @retval EFI_UNSUPPORTED Unexpected RecordType value.
  108. @retval EFI_INVALID_PARAMETER Invalid parameter was found.
  109. **/
  110. MISC_SMBIOS_TABLE_FUNCTION(MiscBiosVendor)
  111. {
  112. CHAR8 *OptionalStrStart;
  113. UINTN OptionalStrSize;
  114. UINTN VendorStrLen;
  115. UINTN VerStrLen;
  116. UINTN DateStrLen;
  117. CHAR16 *Version;
  118. CHAR16 *ReleaseDate;
  119. CHAR16 BiosVersion[100]; //Assuming that strings are < 100 UCHAR
  120. CHAR16 BiosReleaseDate[100]; //Assuming that strings are < 100 UCHAR
  121. CHAR16 BiosReleaseTime[100]; //Assuming that strings are < 100 UCHAR
  122. EFI_STATUS Status;
  123. EFI_STRING Char16String;
  124. STRING_REF TokenToGet;
  125. STRING_REF TokenToUpdate;
  126. SMBIOS_TABLE_TYPE0 *SmbiosRecord;
  127. EFI_SMBIOS_HANDLE SmbiosHandle;
  128. EFI_MISC_BIOS_VENDOR *ForType0InputData;
  129. UINT16 BIOSVersionTemp[100];
  130. ForType0InputData = (EFI_MISC_BIOS_VENDOR *)RecordData;
  131. //
  132. // First check for invalid parameters.
  133. //
  134. if (RecordData == NULL) {
  135. return EFI_INVALID_PARAMETER;
  136. }
  137. //
  138. // Add VLV2 BIOS Version and Release data
  139. //
  140. SetMem(BiosVersion, sizeof(BiosVersion), 0);
  141. SetMem(BiosReleaseDate, sizeof(BiosReleaseDate), 0);
  142. SetMem(BiosReleaseTime, sizeof(BiosReleaseTime), 0);
  143. Status = GetBiosVersionDateTime (BiosVersion, BiosReleaseDate, BiosReleaseTime);
  144. DEBUG ((EFI_D_ERROR, "GetBiosVersionDateTime :%s %s %s \n", BiosVersion, BiosReleaseDate, BiosReleaseTime));
  145. if (StrLen (BiosVersion) > 0) {
  146. TokenToUpdate = STRING_TOKEN (STR_MISC_BIOS_VERSION);
  147. HiiSetString (mHiiHandle, TokenToUpdate, BiosVersion, NULL);
  148. }
  149. if (StrLen(BiosReleaseDate) > 0) {
  150. TokenToUpdate = STRING_TOKEN (STR_MISC_BIOS_RELEASE_DATE);
  151. HiiSetString (mHiiHandle, TokenToUpdate, BiosReleaseDate, NULL);
  152. }
  153. TokenToGet = STRING_TOKEN (STR_MISC_BIOS_VENDOR);
  154. Char16String = SmbiosMiscGetString (TokenToGet);
  155. VendorStrLen = StrLen(Char16String);
  156. if (VendorStrLen > SMBIOS_STRING_MAX_LENGTH) {
  157. return EFI_UNSUPPORTED;
  158. }
  159. TokenToGet = STRING_TOKEN (STR_MISC_BIOS_VERSION);
  160. Version = SmbiosMiscGetString (TokenToGet);
  161. ZeroMem (BIOSVersionTemp, sizeof (BIOSVersionTemp));
  162. StrCatS (BIOSVersionTemp, sizeof (BIOSVersionTemp) / sizeof (CHAR16), Version);
  163. VerStrLen = StrLen(BIOSVersionTemp);
  164. if (VerStrLen > SMBIOS_STRING_MAX_LENGTH) {
  165. return EFI_UNSUPPORTED;
  166. }
  167. TokenToGet = STRING_TOKEN (STR_MISC_BIOS_RELEASE_DATE);
  168. ReleaseDate = SmbiosMiscGetString (TokenToGet);
  169. DateStrLen = StrLen(ReleaseDate);
  170. if (DateStrLen > SMBIOS_STRING_MAX_LENGTH) {
  171. return EFI_UNSUPPORTED;
  172. }
  173. //
  174. // Two zeros following the last string.
  175. //
  176. OptionalStrSize = VendorStrLen + 1 + VerStrLen + 1 + DateStrLen + 1 + 1;
  177. SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE0) + OptionalStrSize);
  178. ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE0) + OptionalStrSize);
  179. SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_BIOS_INFORMATION;
  180. SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE0);
  181. //
  182. // Make handle chosen by smbios protocol.add automatically.
  183. //
  184. SmbiosRecord->Hdr.Handle = 0;
  185. //
  186. // Vendor will be the 1st optional string following the formatted structure.
  187. //
  188. SmbiosRecord->Vendor = 1;
  189. //
  190. // Version will be the 2nd optional string following the formatted structure.
  191. //
  192. SmbiosRecord->BiosVersion = 2;
  193. SmbiosRecord->BiosSegment = (UINT16)ForType0InputData->BiosStartingAddress;
  194. //
  195. // ReleaseDate will be the 3rd optional string following the formatted structure.
  196. //
  197. SmbiosRecord->BiosReleaseDate = 3;
  198. //
  199. // Tiger has no PCD value to indicate BIOS Size, just fill 0 for simply.
  200. //
  201. SmbiosRecord->BiosSize = 0;
  202. SmbiosRecord->BiosCharacteristics = *(MISC_BIOS_CHARACTERISTICS*)(&ForType0InputData->BiosCharacteristics1);
  203. //
  204. // CharacterExtensionBytes also store in ForType0InputData->BiosCharacteristics1 later two bytes to save size.
  205. //
  206. SmbiosRecord->BIOSCharacteristicsExtensionBytes[0] = *((UINT8 *) &ForType0InputData->BiosCharacteristics1 + 4);
  207. SmbiosRecord->BIOSCharacteristicsExtensionBytes[1] = *((UINT8 *) &ForType0InputData->BiosCharacteristics1 + 5);
  208. SmbiosRecord->SystemBiosMajorRelease = ForType0InputData->BiosMajorRelease;
  209. SmbiosRecord->SystemBiosMinorRelease = ForType0InputData->BiosMinorRelease;
  210. SmbiosRecord->EmbeddedControllerFirmwareMajorRelease = ForType0InputData->BiosEmbeddedFirmwareMajorRelease;
  211. SmbiosRecord->EmbeddedControllerFirmwareMinorRelease = ForType0InputData->BiosEmbeddedFirmwareMinorRelease;
  212. OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
  213. UnicodeStrToAsciiStrS(Char16String, OptionalStrStart, OptionalStrSize);
  214. OptionalStrStart += (VendorStrLen + 1);
  215. OptionalStrSize -= (VendorStrLen + 1);
  216. UnicodeStrToAsciiStrS(BIOSVersionTemp, OptionalStrStart, OptionalStrSize);
  217. OptionalStrStart += (VerStrLen + 1);
  218. OptionalStrSize -= (VerStrLen + 1);
  219. UnicodeStrToAsciiStrS(ReleaseDate, OptionalStrStart, OptionalStrSize);
  220. //
  221. // Now we have got the full smbios record, call smbios protocol to add this record.
  222. //
  223. SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
  224. Status = Smbios-> Add(
  225. Smbios,
  226. NULL,
  227. &SmbiosHandle,
  228. (EFI_SMBIOS_TABLE_HEADER *) SmbiosRecord
  229. );
  230. FreePool(SmbiosRecord);
  231. return Status;
  232. }