]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c
OvmfPkg: AcpiPlatformDxe: make dependency on PCI enumeration dynamic
[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, Intel Corporation. All rights reserved.<BR>
6
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
15 **/
16
17 #include "SmbiosPlatformDxe.h"
18
19 //
20 // Type definition and contents of the default Type 0 SMBIOS table.
21 //
22 #pragma pack(1)
23 typedef struct {
24 SMBIOS_TABLE_TYPE0 Base;
25 UINT8 Strings[];
26 } OVMF_TYPE0;
27 #pragma pack()
28
29 STATIC CONST OVMF_TYPE0 mOvmfDefaultType0 = {
30 {
31 // SMBIOS_STRUCTURE Hdr
32 {
33 EFI_SMBIOS_TYPE_BIOS_INFORMATION, // UINT8 Type
34 sizeof (SMBIOS_TABLE_TYPE0), // UINT8 Length
35 },
36 1, // SMBIOS_TABLE_STRING Vendor
37 2, // SMBIOS_TABLE_STRING BiosVersion
38 0xE800,// UINT16 BiosSegment
39 3, // SMBIOS_TABLE_STRING BiosReleaseDate
40 0, // UINT8 BiosSize
41 { // MISC_BIOS_CHARACTERISTICS BiosCharacteristics
42 0, // Reserved :2
43 0, // Unknown :1
44 1, // BiosCharacteristicsNotSupported :1
45 // Remaining BiosCharacteristics bits left unset :60
46 },
47 { // BIOSCharacteristicsExtensionBytes[2]
48 0, // BiosReserved
49 0x1C // SystemReserved = VirtualMachineSupported |
50 // UefiSpecificationSupported |
51 // TargetContentDistributionEnabled
52 },
53 0, // UINT8 SystemBiosMajorRelease
54 0, // UINT8 SystemBiosMinorRelease
55 0xFF, // UINT8 EmbeddedControllerFirmwareMajorRelease
56 0xFF // UINT8 EmbeddedControllerFirmwareMinorRelease
57 },
58 // Text strings (unformatted area)
59 "EFI Development Kit II / OVMF\0" // Vendor
60 "0.0.0\0" // BiosVersion
61 "02/06/2015\0" // BiosReleaseDate
62 };
63
64
65 /**
66 Validates the SMBIOS entry point structure
67
68 @param EntryPointStructure SMBIOS entry point structure
69
70 @retval TRUE The entry point structure is valid
71 @retval FALSE The entry point structure is not valid
72
73 **/
74 BOOLEAN
75 IsEntryPointStructureValid (
76 IN SMBIOS_TABLE_ENTRY_POINT *EntryPointStructure
77 )
78 {
79 UINTN Index;
80 UINT8 Length;
81 UINT8 Checksum;
82 UINT8 *BytePtr;
83
84 BytePtr = (UINT8*) EntryPointStructure;
85 Length = EntryPointStructure->EntryPointLength;
86 Checksum = 0;
87
88 for (Index = 0; Index < Length; Index++) {
89 Checksum = Checksum + (UINT8) BytePtr[Index];
90 }
91
92 if (Checksum != 0) {
93 return FALSE;
94 } else {
95 return TRUE;
96 }
97 }
98
99
100 /**
101 Get SMBIOS record length.
102
103 @param SmbiosTable SMBIOS pointer.
104
105 **/
106 UINTN
107 SmbiosTableLength (
108 IN SMBIOS_STRUCTURE_POINTER SmbiosTable
109 )
110 {
111 CHAR8 *AChar;
112 UINTN Length;
113
114 AChar = (CHAR8 *)(SmbiosTable.Raw + SmbiosTable.Hdr->Length);
115
116 //
117 // Each structure shall be terminated by a double-null (SMBIOS spec.7.1)
118 //
119 while ((*AChar != 0) || (*(AChar + 1) != 0)) {
120 AChar ++;
121 }
122 Length = ((UINTN)AChar - (UINTN)SmbiosTable.Raw + 2);
123
124 return Length;
125 }
126
127
128 /**
129 Install all structures from the given SMBIOS structures block
130
131 @param Smbios SMBIOS protocol
132 @param TableAddress SMBIOS tables starting address
133
134 **/
135 EFI_STATUS
136 InstallAllStructures (
137 IN EFI_SMBIOS_PROTOCOL *Smbios,
138 IN UINT8 *TableAddress
139 )
140 {
141 EFI_STATUS Status;
142 SMBIOS_STRUCTURE_POINTER SmbiosTable;
143 EFI_SMBIOS_HANDLE SmbiosHandle;
144 BOOLEAN NeedSmbiosType0;
145
146 SmbiosTable.Raw = TableAddress;
147 if (SmbiosTable.Raw == NULL) {
148 return EFI_INVALID_PARAMETER;
149 }
150
151 NeedSmbiosType0 = TRUE;
152
153 while (SmbiosTable.Hdr->Type != 127) {
154 //
155 // Log the SMBIOS data for this structure
156 //
157 SmbiosHandle = SmbiosTable.Hdr->Handle;
158 Status = Smbios->Add (
159 Smbios,
160 NULL,
161 &SmbiosHandle,
162 (EFI_SMBIOS_TABLE_HEADER*) SmbiosTable.Raw
163 );
164 ASSERT_EFI_ERROR (Status);
165
166 if (SmbiosTable.Hdr->Type == 0) {
167 NeedSmbiosType0 = FALSE;
168 }
169
170 //
171 // Get the next structure address
172 //
173 SmbiosTable.Raw = (UINT8 *)(SmbiosTable.Raw + SmbiosTableLength (SmbiosTable));
174 }
175
176 if (NeedSmbiosType0) {
177 //
178 // Add OVMF default Type 0 (BIOS Information) table
179 //
180 SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
181 Status = Smbios->Add (
182 Smbios,
183 NULL,
184 &SmbiosHandle,
185 (EFI_SMBIOS_TABLE_HEADER*) &mOvmfDefaultType0
186 );
187 ASSERT_EFI_ERROR (Status);
188 }
189
190 return EFI_SUCCESS;
191 }
192
193
194 /**
195 Installs SMBIOS information for OVMF
196
197 @param ImageHandle Module's image handle
198 @param SystemTable Pointer of EFI_SYSTEM_TABLE
199
200 @retval EFI_SUCCESS Smbios data successfully installed
201 @retval Other Smbios data was not installed
202
203 **/
204 EFI_STATUS
205 EFIAPI
206 SmbiosTablePublishEntry (
207 IN EFI_HANDLE ImageHandle,
208 IN EFI_SYSTEM_TABLE *SystemTable
209 )
210 {
211 EFI_STATUS Status;
212 EFI_SMBIOS_PROTOCOL *Smbios;
213 SMBIOS_TABLE_ENTRY_POINT *EntryPointStructure;
214 UINT8 *SmbiosTables;
215
216 //
217 // Find the SMBIOS protocol
218 //
219 Status = gBS->LocateProtocol (
220 &gEfiSmbiosProtocolGuid,
221 NULL,
222 (VOID**)&Smbios
223 );
224 if (EFI_ERROR (Status)) {
225 return Status;
226 }
227
228 //
229 // Add Xen or QEMU SMBIOS data if found
230 //
231 EntryPointStructure = GetXenSmbiosTables ();
232 if (EntryPointStructure != NULL) {
233 SmbiosTables = (UINT8*)(UINTN)EntryPointStructure->TableAddress;
234 } else {
235 SmbiosTables = GetQemuSmbiosTables ();
236 }
237
238 if (SmbiosTables != NULL) {
239 Status = InstallAllStructures (Smbios, SmbiosTables);
240
241 //
242 // Free SmbiosTables if allocated by Qemu (i.e., NOT by Xen):
243 //
244 if (EntryPointStructure == NULL) {
245 FreePool (SmbiosTables);
246 }
247 }
248
249 return Status;
250 }