]> git.proxmox.com Git - mirror_edk2.git/blame - 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
CommitLineData
fb511817 1/** @file\r
2 This driver installs SMBIOS information for OVMF\r
3\r
4 Copyright (c) 2011, Bei Guan <gbtju85@gmail.com>\r
5 Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
6\r
7 This program and the accompanying materials\r
8 are licensed and made available under the terms and conditions of the BSD License\r
9 which accompanies this distribution. The full text of the license may be found at\r
10 http://opensource.org/licenses/bsd-license.php\r
11\r
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15**/\r
16\r
17#include "SmbiosPlatformDxe.h"\r
18\r
19\r
20/**\r
21 Validates the SMBIOS entry point structure\r
22\r
23 @param EntryPointStructure SMBIOS entry point structure\r
24\r
25 @retval TRUE The entry point structure is valid\r
26 @retval FALSE The entry point structure is not valid\r
27\r
28**/\r
29BOOLEAN\r
30IsEntryPointStructureValid (\r
31 IN SMBIOS_TABLE_ENTRY_POINT *EntryPointStructure\r
32 )\r
33{\r
34 UINTN Index;\r
35 UINT8 Length;\r
36 UINT8 Checksum;\r
37 UINT8 *BytePtr;\r
38\r
39 BytePtr = (UINT8*) EntryPointStructure;\r
40 Length = EntryPointStructure->EntryPointLength;\r
41 Checksum = 0;\r
42\r
43 for (Index = 0; Index < Length; Index++) {\r
670a64e7 44 Checksum = Checksum + (UINT8) BytePtr[Index];\r
fb511817 45 }\r
46\r
47 if (Checksum != 0) {\r
48 return FALSE;\r
49 } else {\r
50 return TRUE;\r
51 }\r
52}\r
53\r
54\r
55/**\r
56 Get SMBIOS record length.\r
57\r
58 @param SmbiosTable SMBIOS pointer.\r
59\r
60**/\r
61UINTN\r
62SmbiosTableLength (\r
63 IN SMBIOS_STRUCTURE_POINTER SmbiosTable\r
64 )\r
65{\r
66 CHAR8 *AChar;\r
67 UINTN Length;\r
68\r
69 AChar = (CHAR8 *)(SmbiosTable.Raw + SmbiosTable.Hdr->Length);\r
70\r
71 //\r
72 // Each structure shall be terminated by a double-null (SMBIOS spec.7.1)\r
73 //\r
74 while ((*AChar != 0) || (*(AChar + 1) != 0)) {\r
75 AChar ++;\r
76 }\r
77 Length = ((UINTN)AChar - (UINTN)SmbiosTable.Raw + 2);\r
78\r
79 return Length;\r
80}\r
81\r
82\r
83/**\r
84 Install all structures from the given SMBIOS structures block\r
85\r
86 @param Smbios SMBIOS protocol\r
87 @param EntryPointStructure SMBIOS entry point structures block\r
88\r
89**/\r
90EFI_STATUS\r
91InstallAllStructures (\r
92 IN EFI_SMBIOS_PROTOCOL *Smbios,\r
93 IN SMBIOS_TABLE_ENTRY_POINT *EntryPointStructure\r
94 )\r
95{\r
96 EFI_STATUS Status;\r
97 SMBIOS_STRUCTURE_POINTER SmbiosTable;\r
98 EFI_SMBIOS_HANDLE SmbiosHandle;\r
99\r
100 SmbiosTable.Raw = (UINT8*)(UINTN) EntryPointStructure->TableAddress;\r
101 if (SmbiosTable.Raw == NULL) {\r
102 return EFI_INVALID_PARAMETER;\r
103 }\r
104\r
105 while (SmbiosTable.Hdr->Type != 127) {\r
106 //\r
107 // Log the SMBIOS data for this structure\r
108 //\r
109 SmbiosHandle = 0;\r
110 Status = Smbios->Add (\r
111 Smbios,\r
112 NULL,\r
113 &SmbiosHandle,\r
114 (EFI_SMBIOS_TABLE_HEADER*) SmbiosTable.Raw\r
115 );\r
116 ASSERT_EFI_ERROR (Status);\r
117\r
118 //\r
119 // Get the next structure address\r
120 //\r
121 SmbiosTable.Raw = (UINT8 *)(SmbiosTable.Raw + SmbiosTableLength (SmbiosTable));\r
122 }\r
123\r
124 return EFI_SUCCESS;\r
125}\r
126\r
127\r
128/**\r
129 Installs SMBIOS information for OVMF\r
130\r
131 @param ImageHandle Module's image handle\r
132 @param SystemTable Pointer of EFI_SYSTEM_TABLE\r
133\r
134 @retval EFI_SUCCESS Smbios data successfully installed\r
135 @retval Other Smbios data was not installed\r
136\r
137**/\r
138EFI_STATUS\r
139EFIAPI\r
140SmbiosTablePublishEntry (\r
141 IN EFI_HANDLE ImageHandle,\r
142 IN EFI_SYSTEM_TABLE *SystemTable\r
143 )\r
144{\r
145 EFI_STATUS Status;\r
146 EFI_SMBIOS_PROTOCOL *Smbios;\r
147 SMBIOS_TABLE_ENTRY_POINT *EntryPointStructure;\r
148\r
149 //\r
150 // Find the SMBIOS protocol\r
151 //\r
152 Status = gBS->LocateProtocol (\r
153 &gEfiSmbiosProtocolGuid,\r
154 NULL,\r
155 (VOID**)&Smbios\r
156 );\r
157 if (EFI_ERROR (Status)) {\r
158 return Status;\r
159 }\r
160\r
161 //\r
162 // Add Xen SMBIOS data if found\r
163 //\r
164 EntryPointStructure = GetXenSmbiosTables ();\r
165 if (EntryPointStructure != NULL) {\r
166 Status = InstallAllStructures (Smbios, EntryPointStructure);\r
167 }\r
168\r
169 return Status;\r
170}\r