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