]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/SmbiosPlatformDxe/X86Xen.c
OvmfPkg: Apply uncrustify changes
[mirror_edk2.git] / OvmfPkg / SmbiosPlatformDxe / X86Xen.c
1 /** @file
2 Detect Xen hvmloader SMBIOS data for usage by OVMF.
3
4 Copyright (c) 2011, Bei Guan <gbtju85@gmail.com>
5 Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
6
7 SPDX-License-Identifier: BSD-2-Clause-Patent
8
9 **/
10
11 #include <Library/BaseLib.h> // AsciiStrnCmp()
12 #include <Library/HobLib.h> // GetFirstGuidHob()
13 #include <Pi/PiHob.h> // EFI_HOB_GUID_TYPE
14
15 #include "XenSmbiosPlatformDxe.h"
16
17 #define XEN_SMBIOS_PHYSICAL_ADDRESS 0x000EB000
18 #define XEN_SMBIOS_PHYSICAL_END 0x000F0000
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 STATIC
30 BOOLEAN
31 IsEntryPointStructureValid (
32 IN SMBIOS_TABLE_ENTRY_POINT *EntryPointStructure
33 )
34 {
35 UINTN Index;
36 UINT8 Length;
37 UINT8 Checksum;
38 UINT8 *BytePtr;
39
40 BytePtr = (UINT8 *)EntryPointStructure;
41 Length = EntryPointStructure->EntryPointLength;
42 Checksum = 0;
43
44 for (Index = 0; Index < Length; Index++) {
45 Checksum = Checksum + (UINT8)BytePtr[Index];
46 }
47
48 if (Checksum != 0) {
49 return FALSE;
50 } else {
51 return TRUE;
52 }
53 }
54
55 /**
56 Locates the Xen SMBIOS data if it exists
57
58 @return SMBIOS_TABLE_ENTRY_POINT Address of Xen SMBIOS data
59
60 **/
61 SMBIOS_TABLE_ENTRY_POINT *
62 GetXenSmbiosTables (
63 VOID
64 )
65 {
66 UINT8 *XenSmbiosPtr;
67 SMBIOS_TABLE_ENTRY_POINT *XenSmbiosEntryPointStructure;
68 EFI_HOB_GUID_TYPE *GuidHob;
69
70 //
71 // See if a XenInfo HOB is available
72 //
73 GuidHob = GetFirstGuidHob (&gEfiXenInfoGuid);
74 if (GuidHob == NULL) {
75 return NULL;
76 }
77
78 for (XenSmbiosPtr = (UINT8 *)(UINTN)XEN_SMBIOS_PHYSICAL_ADDRESS;
79 XenSmbiosPtr < (UINT8 *)(UINTN)XEN_SMBIOS_PHYSICAL_END;
80 XenSmbiosPtr += 0x10)
81 {
82 XenSmbiosEntryPointStructure = (SMBIOS_TABLE_ENTRY_POINT *)XenSmbiosPtr;
83
84 if (!AsciiStrnCmp ((CHAR8 *)XenSmbiosEntryPointStructure->AnchorString, "_SM_", 4) &&
85 !AsciiStrnCmp ((CHAR8 *)XenSmbiosEntryPointStructure->IntermediateAnchorString, "_DMI_", 5) &&
86 IsEntryPointStructureValid (XenSmbiosEntryPointStructure))
87 {
88 return XenSmbiosEntryPointStructure;
89 }
90 }
91
92 return NULL;
93 }