EDK2 doxygen online documents - Firmware Encoding Index 1
EDK2 doxygen online documents - Firmware Encoding Index

OvmfPkg/PlatformPei/Xen.c

Go to the documentation of this file.
00001 
00017 //
00018 // The package level header files this module uses
00019 //
00020 #include <PiPei.h>
00021 
00022 //
00023 // The Library classes this module consumes
00024 //
00025 #include <Library/DebugLib.h>
00026 #include <Library/HobLib.h>
00027 #include <Library/MemoryAllocationLib.h>
00028 #include <Library/PcdLib.h>
00029 #include <Guid/XenInfo.h>
00030 
00031 #include "Platform.h"
00032 
00033 EFI_XEN_INFO mXenInfo;
00034 
00035 
00044 EFI_STATUS
00045 XenConnect (
00046   UINT32 XenLeaf
00047   )
00048 {
00049   UINT32 Index;
00050   UINT32 TransferReg;
00051   UINT32 TransferPages;
00052   UINT32 XenVersion;
00053 
00054   AsmCpuid (XenLeaf + 2, &TransferPages, &TransferReg, NULL, NULL);
00055   mXenInfo.HyperPages = AllocatePages (TransferPages);
00056   if (!mXenInfo.HyperPages) {
00057     return EFI_OUT_OF_RESOURCES;
00058   }
00059 
00060   for (Index = 0; Index < TransferPages; Index++) {
00061     AsmWriteMsr64 (TransferReg,
00062                    (UINTN) mXenInfo.HyperPages +
00063                    (Index << EFI_PAGE_SHIFT) + Index);
00064   }
00065 
00066   AsmCpuid (XenLeaf + 1, &XenVersion, NULL, NULL, NULL);
00067   DEBUG ((EFI_D_ERROR, "Detected Xen version %d.%d\n",
00068           XenVersion >> 16, XenVersion & 0xFFFF));
00069   mXenInfo.VersionMajor = (UINT16)(XenVersion >> 16);
00070   mXenInfo.VersionMinor = (UINT16)(XenVersion & 0xFFFF);
00071 
00072   /* TBD: Locate hvm_info and reserve it away. */
00073   mXenInfo.HvmInfo = NULL;
00074 
00075   BuildGuidDataHob (
00076     &gEfiXenInfoGuid,
00077     &mXenInfo,
00078     sizeof(mXenInfo)
00079     );
00080 
00081   return EFI_SUCCESS;
00082 }
00083 
00090 UINT32
00091 XenDetect (
00092   VOID
00093   )
00094 {
00095 
00096   UINT32 XenLeaf;
00097   UINT8 Signature[13];
00098 
00099   for (XenLeaf = 0x40000000; XenLeaf < 0x40010000; XenLeaf += 0x100) {
00100     AsmCpuid (XenLeaf, NULL, (UINT32 *) &Signature[0],
00101               (UINT32 *) &Signature[4],
00102               (UINT32 *) &Signature[8]);
00103     Signature[12] = '\0';
00104 
00105     if (!AsciiStrCmp ((CHAR8 *) Signature, "XenVMMXenVMM")) {
00106       return XenLeaf;
00107     }
00108   }
00109 
00110   return 0;
00111 }
00112 
00120 EFI_STATUS
00121 InitializeXen (
00122   VOID
00123   )
00124 {
00125   UINT32 XenLeaf;
00126 
00127   XenLeaf = XenDetect ();
00128 
00129   if (XenLeaf == 0) {
00130     return EFI_NOT_FOUND;
00131   }
00132 
00133   DEBUG ((EFI_D_INFO, "Xen was detected\n"));
00134 
00135   XenConnect (XenLeaf);
00136 
00137   //
00138   // Reserve away HVMLOADER reserved memory [0xFC000000,0xFD000000).
00139   // This needs to match HVMLOADER RESERVED_MEMBASE/RESERVED_MEMSIZE.
00140   //
00141   AddReservedMemoryBaseSizeHob (0xFC000000, 0x1000000);
00142 
00143   return EFI_SUCCESS;
00144 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Defines