]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c
Fix build crash while using MSFT to build OVMF, also fix some build warning report...
[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 /**
21 Validates the SMBIOS entry point structure
22
23 @param EntryPointStructure SMBIOS entry point structure
24
25 @retval TRUE The entry point structure is valid
26 @retval FALSE The entry point structure is not valid
27
28 **/
29 BOOLEAN
30 IsEntryPointStructureValid (
31 IN SMBIOS_TABLE_ENTRY_POINT *EntryPointStructure
32 )
33 {
34 UINTN Index;
35 UINT8 Length;
36 UINT8 Checksum;
37 UINT8 *BytePtr;
38
39 BytePtr = (UINT8*) EntryPointStructure;
40 Length = EntryPointStructure->EntryPointLength;
41 Checksum = 0;
42
43 for (Index = 0; Index < Length; Index++) {
44 Checksum = Checksum + (UINT8) BytePtr[Index];
45 }
46
47 if (Checksum != 0) {
48 return FALSE;
49 } else {
50 return TRUE;
51 }
52 }
53
54
55 /**
56 Get SMBIOS record length.
57
58 @param SmbiosTable SMBIOS pointer.
59
60 **/
61 UINTN
62 SmbiosTableLength (
63 IN SMBIOS_STRUCTURE_POINTER SmbiosTable
64 )
65 {
66 CHAR8 *AChar;
67 UINTN Length;
68
69 AChar = (CHAR8 *)(SmbiosTable.Raw + SmbiosTable.Hdr->Length);
70
71 //
72 // Each structure shall be terminated by a double-null (SMBIOS spec.7.1)
73 //
74 while ((*AChar != 0) || (*(AChar + 1) != 0)) {
75 AChar ++;
76 }
77 Length = ((UINTN)AChar - (UINTN)SmbiosTable.Raw + 2);
78
79 return Length;
80 }
81
82
83 /**
84 Install all structures from the given SMBIOS structures block
85
86 @param Smbios SMBIOS protocol
87 @param EntryPointStructure SMBIOS entry point structures block
88
89 **/
90 EFI_STATUS
91 InstallAllStructures (
92 IN EFI_SMBIOS_PROTOCOL *Smbios,
93 IN SMBIOS_TABLE_ENTRY_POINT *EntryPointStructure
94 )
95 {
96 EFI_STATUS Status;
97 SMBIOS_STRUCTURE_POINTER SmbiosTable;
98 EFI_SMBIOS_HANDLE SmbiosHandle;
99
100 SmbiosTable.Raw = (UINT8*)(UINTN) EntryPointStructure->TableAddress;
101 if (SmbiosTable.Raw == NULL) {
102 return EFI_INVALID_PARAMETER;
103 }
104
105 while (SmbiosTable.Hdr->Type != 127) {
106 //
107 // Log the SMBIOS data for this structure
108 //
109 SmbiosHandle = 0;
110 Status = Smbios->Add (
111 Smbios,
112 NULL,
113 &SmbiosHandle,
114 (EFI_SMBIOS_TABLE_HEADER*) SmbiosTable.Raw
115 );
116 ASSERT_EFI_ERROR (Status);
117
118 //
119 // Get the next structure address
120 //
121 SmbiosTable.Raw = (UINT8 *)(SmbiosTable.Raw + SmbiosTableLength (SmbiosTable));
122 }
123
124 return EFI_SUCCESS;
125 }
126
127
128 /**
129 Installs SMBIOS information for OVMF
130
131 @param ImageHandle Module's image handle
132 @param SystemTable Pointer of EFI_SYSTEM_TABLE
133
134 @retval EFI_SUCCESS Smbios data successfully installed
135 @retval Other Smbios data was not installed
136
137 **/
138 EFI_STATUS
139 EFIAPI
140 SmbiosTablePublishEntry (
141 IN EFI_HANDLE ImageHandle,
142 IN EFI_SYSTEM_TABLE *SystemTable
143 )
144 {
145 EFI_STATUS Status;
146 EFI_SMBIOS_PROTOCOL *Smbios;
147 SMBIOS_TABLE_ENTRY_POINT *EntryPointStructure;
148
149 //
150 // Find the SMBIOS protocol
151 //
152 Status = gBS->LocateProtocol (
153 &gEfiSmbiosProtocolGuid,
154 NULL,
155 (VOID**)&Smbios
156 );
157 if (EFI_ERROR (Status)) {
158 return Status;
159 }
160
161 //
162 // Add Xen SMBIOS data if found
163 //
164 EntryPointStructure = GetXenSmbiosTables ();
165 if (EntryPointStructure != NULL) {
166 Status = InstallAllStructures (Smbios, EntryPointStructure);
167 }
168
169 return Status;
170 }