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