SmbiosPlatformDxe.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /** @file
  2. This driver installs SMBIOS information for OVMF
  3. Copyright (c) 2011, Bei Guan <gbtju85@gmail.com>
  4. Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.<BR>
  5. SPDX-License-Identifier: BSD-2-Clause-Patent
  6. **/
  7. #include <IndustryStandard/SmBios.h> // SMBIOS_TABLE_TYPE0
  8. #include <Library/DebugLib.h> // ASSERT_EFI_ERROR()
  9. #include <Library/UefiBootServicesTableLib.h> // gBS
  10. #include <Protocol/Smbios.h> // EFI_SMBIOS_PROTOCOL
  11. #include "SmbiosPlatformDxe.h"
  12. #define TYPE0_STRINGS \
  13. "EFI Development Kit II / OVMF\0" /* Vendor */ \
  14. "0.0.0\0" /* BiosVersion */ \
  15. "02/06/2015\0" /* BiosReleaseDate */
  16. //
  17. // Type definition and contents of the default Type 0 SMBIOS table.
  18. //
  19. #pragma pack(1)
  20. typedef struct {
  21. SMBIOS_TABLE_TYPE0 Base;
  22. UINT8 Strings[sizeof (TYPE0_STRINGS)];
  23. } OVMF_TYPE0;
  24. #pragma pack()
  25. STATIC CONST OVMF_TYPE0 mOvmfDefaultType0 = {
  26. {
  27. // SMBIOS_STRUCTURE Hdr
  28. {
  29. EFI_SMBIOS_TYPE_BIOS_INFORMATION, // UINT8 Type
  30. sizeof (SMBIOS_TABLE_TYPE0), // UINT8 Length
  31. },
  32. 1, // SMBIOS_TABLE_STRING Vendor
  33. 2, // SMBIOS_TABLE_STRING BiosVersion
  34. 0xE800, // UINT16 BiosSegment
  35. 3, // SMBIOS_TABLE_STRING BiosReleaseDate
  36. 0, // UINT8 BiosSize
  37. { // MISC_BIOS_CHARACTERISTICS BiosCharacteristics
  38. 0, // Reserved :2
  39. 0, // Unknown :1
  40. 1, // BiosCharacteristicsNotSupported :1
  41. // Remaining BiosCharacteristics bits left unset :60
  42. },
  43. { // BIOSCharacteristicsExtensionBytes[2]
  44. 0, // BiosReserved
  45. 0x1C // SystemReserved = VirtualMachineSupported |
  46. // UefiSpecificationSupported |
  47. // TargetContentDistributionEnabled
  48. },
  49. 0, // UINT8 SystemBiosMajorRelease
  50. 0, // UINT8 SystemBiosMinorRelease
  51. 0xFF, // UINT8 EmbeddedControllerFirmwareMajorRelease
  52. 0xFF // UINT8 EmbeddedControllerFirmwareMinorRelease
  53. },
  54. // Text strings (unformatted area)
  55. TYPE0_STRINGS
  56. };
  57. /**
  58. Get SMBIOS record length.
  59. @param SmbiosTable SMBIOS pointer.
  60. **/
  61. UINTN
  62. SmbiosTableLength (
  63. IN SMBIOS_STRUCTURE_POINTER SmbiosTable
  64. )
  65. {
  66. CHAR8 *AChar;
  67. UINTN Length;
  68. AChar = (CHAR8 *)(SmbiosTable.Raw + SmbiosTable.Hdr->Length);
  69. //
  70. // Each structure shall be terminated by a double-null (SMBIOS spec.7.1)
  71. //
  72. while ((*AChar != 0) || (*(AChar + 1) != 0)) {
  73. AChar++;
  74. }
  75. Length = ((UINTN)AChar - (UINTN)SmbiosTable.Raw + 2);
  76. return Length;
  77. }
  78. /**
  79. Install all structures from the given SMBIOS structures block
  80. @param TableAddress SMBIOS tables starting address
  81. **/
  82. EFI_STATUS
  83. InstallAllStructures (
  84. IN UINT8 *TableAddress
  85. )
  86. {
  87. EFI_SMBIOS_PROTOCOL *Smbios;
  88. EFI_STATUS Status;
  89. SMBIOS_STRUCTURE_POINTER SmbiosTable;
  90. EFI_SMBIOS_HANDLE SmbiosHandle;
  91. BOOLEAN NeedSmbiosType0;
  92. //
  93. // Find the SMBIOS protocol
  94. //
  95. Status = gBS->LocateProtocol (
  96. &gEfiSmbiosProtocolGuid,
  97. NULL,
  98. (VOID **)&Smbios
  99. );
  100. if (EFI_ERROR (Status)) {
  101. return Status;
  102. }
  103. SmbiosTable.Raw = TableAddress;
  104. if (SmbiosTable.Raw == NULL) {
  105. return EFI_INVALID_PARAMETER;
  106. }
  107. NeedSmbiosType0 = TRUE;
  108. while (SmbiosTable.Hdr->Type != 127) {
  109. //
  110. // Log the SMBIOS data for this structure
  111. //
  112. SmbiosHandle = SmbiosTable.Hdr->Handle;
  113. Status = Smbios->Add (
  114. Smbios,
  115. NULL,
  116. &SmbiosHandle,
  117. (EFI_SMBIOS_TABLE_HEADER *)SmbiosTable.Raw
  118. );
  119. ASSERT_EFI_ERROR (Status);
  120. if (SmbiosTable.Hdr->Type == 0) {
  121. NeedSmbiosType0 = FALSE;
  122. }
  123. //
  124. // Get the next structure address
  125. //
  126. SmbiosTable.Raw = (UINT8 *)(SmbiosTable.Raw + SmbiosTableLength (SmbiosTable));
  127. }
  128. if (NeedSmbiosType0) {
  129. //
  130. // Add OVMF default Type 0 (BIOS Information) table
  131. //
  132. SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
  133. Status = Smbios->Add (
  134. Smbios,
  135. NULL,
  136. &SmbiosHandle,
  137. (EFI_SMBIOS_TABLE_HEADER *)&mOvmfDefaultType0
  138. );
  139. ASSERT_EFI_ERROR (Status);
  140. }
  141. return EFI_SUCCESS;
  142. }