]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/SmbiosPlatformDxe/X86Xen.c
EmbeddedPkg: Extend NvVarStoreFormattedLib LIBRARY_CLASS
[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 "SmbiosPlatformDxe.h"
12 #include <Library/HobLib.h>
13 #include <Guid/XenInfo.h>
14
15 #define XEN_SMBIOS_PHYSICAL_ADDRESS 0x000EB000
16 #define XEN_SMBIOS_PHYSICAL_END 0x000F0000
17
18 /**
19 Validates the SMBIOS entry point structure
20
21 @param EntryPointStructure SMBIOS entry point structure
22
23 @retval TRUE The entry point structure is valid
24 @retval FALSE The entry point structure is not valid
25
26 **/
27 STATIC
28 BOOLEAN
29 IsEntryPointStructureValid (
30 IN SMBIOS_TABLE_ENTRY_POINT *EntryPointStructure
31 )
32 {
33 UINTN Index;
34 UINT8 Length;
35 UINT8 Checksum;
36 UINT8 *BytePtr;
37
38 BytePtr = (UINT8*) EntryPointStructure;
39 Length = EntryPointStructure->EntryPointLength;
40 Checksum = 0;
41
42 for (Index = 0; Index < Length; Index++) {
43 Checksum = Checksum + (UINT8) BytePtr[Index];
44 }
45
46 if (Checksum != 0) {
47 return FALSE;
48 } else {
49 return TRUE;
50 }
51 }
52
53 /**
54 Locates the Xen SMBIOS data if it exists
55
56 @return SMBIOS_TABLE_ENTRY_POINT Address of Xen SMBIOS data
57
58 **/
59 SMBIOS_TABLE_ENTRY_POINT *
60 GetXenSmbiosTables (
61 VOID
62 )
63 {
64 UINT8 *XenSmbiosPtr;
65 SMBIOS_TABLE_ENTRY_POINT *XenSmbiosEntryPointStructure;
66 EFI_HOB_GUID_TYPE *GuidHob;
67
68 //
69 // See if a XenInfo HOB is available
70 //
71 GuidHob = GetFirstGuidHob (&gEfiXenInfoGuid);
72 if (GuidHob == NULL) {
73 return NULL;
74 }
75
76 for (XenSmbiosPtr = (UINT8*)(UINTN) XEN_SMBIOS_PHYSICAL_ADDRESS;
77 XenSmbiosPtr < (UINT8*)(UINTN) XEN_SMBIOS_PHYSICAL_END;
78 XenSmbiosPtr += 0x10) {
79
80 XenSmbiosEntryPointStructure = (SMBIOS_TABLE_ENTRY_POINT *) XenSmbiosPtr;
81
82 if (!AsciiStrnCmp ((CHAR8 *) XenSmbiosEntryPointStructure->AnchorString, "_SM_", 4) &&
83 !AsciiStrnCmp ((CHAR8 *) XenSmbiosEntryPointStructure->IntermediateAnchorString, "_DMI_", 5) &&
84 IsEntryPointStructureValid (XenSmbiosEntryPointStructure)) {
85
86 return XenSmbiosEntryPointStructure;
87
88 }
89 }
90
91 return NULL;
92 }