Revision: 14945
          http://sourceforge.net/p/edk2/code/14945
Author:   jljusten
Date:     2013-12-08 01:36:15 +0000 (Sun, 08 Dec 2013)
Log Message:
-----------
OvmfPkg: introduce XenMemMapInitialization

This function parses E820 map provided by Xen and arrange memory maps
accordingly.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Wei Liu <[email protected]>
Reviewed-by: Jordan Justen <[email protected]>
[[email protected]: XenGetE820Map: VS2010 compat; add assert]
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jordan Justen <[email protected]>

Modified Paths:
--------------
    trunk/edk2/OvmfPkg/PlatformPei/Platform.c
    trunk/edk2/OvmfPkg/PlatformPei/Platform.h
    trunk/edk2/OvmfPkg/PlatformPei/Xen.c

Modified: trunk/edk2/OvmfPkg/PlatformPei/Platform.c
===================================================================
--- trunk/edk2/OvmfPkg/PlatformPei/Platform.c   2013-12-08 01:36:07 UTC (rev 
14944)
+++ trunk/edk2/OvmfPkg/PlatformPei/Platform.c   2013-12-08 01:36:15 UTC (rev 
14945)
@@ -34,6 +34,10 @@
 #include <Guid/MemoryTypeInformation.h>
 #include <Ppi/MasterBootMode.h>
 #include <IndustryStandard/Pci22.h>
+#include <Guid/XenInfo.h>
+#include <IndustryStandard/E820.h>
+#include <Library/ResourcePublicationLib.h>
+#include <Library/MtrrLib.h>
 
 #include "Platform.h"
 #include "Cmos.h"
@@ -163,7 +167,75 @@
   AddUntestedMemoryBaseSizeHob (MemoryBase, (UINT64)(MemoryLimit - 
MemoryBase));
 }
 
+VOID
+XenMemMapInitialization (
+  VOID
+  )
+{
+  EFI_E820_ENTRY64 *E820Map;
+  UINT32 E820EntriesCount;
+  EFI_STATUS Status;
 
+  DEBUG ((EFI_D_INFO, "Using memory map provided by Xen\n"));
+
+  //
+  // Create Memory Type Information HOB
+  //
+  BuildGuidDataHob (
+    &gEfiMemoryTypeInformationGuid,
+    mDefaultMemoryTypeInformation,
+    sizeof(mDefaultMemoryTypeInformation)
+    );
+
+  //
+  // Add PCI IO Port space available for PCI resource allocations.
+  //
+  BuildResourceDescriptorHob (
+    EFI_RESOURCE_IO,
+    EFI_RESOURCE_ATTRIBUTE_PRESENT     |
+    EFI_RESOURCE_ATTRIBUTE_INITIALIZED,
+    0xC000,
+    0x4000
+    );
+
+  //
+  // Video memory + Legacy BIOS region
+  //
+  AddIoMemoryRangeHob (0x0A0000, BASE_1MB);
+
+  //
+  // Parse RAM in E820 map
+  //
+  Status = XenGetE820Map(&E820Map, &E820EntriesCount);
+
+  ASSERT_EFI_ERROR (Status);
+
+  if (E820EntriesCount > 0) {
+    EFI_E820_ENTRY64 *Entry;
+    UINT32 Loop;
+
+    for (Loop = 0; Loop < E820EntriesCount; Loop++) {
+      Entry = E820Map + Loop;
+
+      //
+      // Only care about RAM
+      //
+      if (Entry->Type != EfiAcpiAddressRangeMemory) {
+        continue;
+      }
+
+      if (Entry->BaseAddr >= BASE_4GB) {
+        AddUntestedMemoryBaseSizeHob (Entry->BaseAddr, Entry->Length);
+      } else {
+        AddMemoryBaseSizeHob (Entry->BaseAddr, Entry->Length);
+      }
+
+      MtrrSetMemoryAttribute (Entry->BaseAddr, Entry->Length, CacheWriteBack);
+    }
+  }
+}
+
+
 VOID
 MemMapInitialization (
   EFI_PHYSICAL_ADDRESS  TopOfMemory

Modified: trunk/edk2/OvmfPkg/PlatformPei/Platform.h
===================================================================
--- trunk/edk2/OvmfPkg/PlatformPei/Platform.h   2013-12-08 01:36:07 UTC (rev 
14944)
+++ trunk/edk2/OvmfPkg/PlatformPei/Platform.h   2013-12-08 01:36:15 UTC (rev 
14945)
@@ -15,6 +15,8 @@
 #ifndef _PLATFORM_PEI_H_INCLUDED_
 #define _PLATFORM_PEI_H_INCLUDED_
 
+#include <IndustryStandard/E820.h>
+
 VOID
 AddIoMemoryBaseSizeHob (
   EFI_PHYSICAL_ADDRESS        MemoryBase,
@@ -82,4 +84,10 @@
   VOID
   );
 
+EFI_STATUS
+XenGetE820Map (
+  EFI_E820_ENTRY64 **Entries,
+  UINT32 *Count
+  );
+
 #endif // _PLATFORM_PEI_H_INCLUDED_

Modified: trunk/edk2/OvmfPkg/PlatformPei/Xen.c
===================================================================
--- trunk/edk2/OvmfPkg/PlatformPei/Xen.c        2013-12-08 01:36:07 UTC (rev 
14944)
+++ trunk/edk2/OvmfPkg/PlatformPei/Xen.c        2013-12-08 01:36:15 UTC (rev 
14945)
@@ -1,7 +1,7 @@
 /**@file
   Xen Platform PEI support
 
-  Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
   Copyright (c) 2011, Andrei Warkentin <[email protected]>
 
   This program and the accompanying materials
@@ -29,10 +29,38 @@
 #include <Guid/XenInfo.h>
 
 #include "Platform.h"
+#include "Xen.h"
 
 EFI_XEN_INFO mXenInfo;
 
+/**
+  Returns E820 map provided by Xen
 
+  @param Entries      Pointer to E820 map
+  @param Count        Number of entries
+
+  @return EFI_STATUS
+**/
+EFI_STATUS
+XenGetE820Map (
+  EFI_E820_ENTRY64 **Entries,
+  UINT32 *Count
+  )
+{
+  EFI_XEN_OVMF_INFO *Info =
+    (EFI_XEN_OVMF_INFO *)(UINTN) OVMF_INFO_PHYSICAL_ADDRESS;
+
+  if (AsciiStrCmp ((CHAR8 *) Info->Signature, "XenHVMOVMF")) {
+    return EFI_NOT_FOUND;
+  }
+
+  ASSERT (Info->E820 < MAX_ADDRESS);
+  *Entries = (EFI_E820_ENTRY64 *)(UINTN) Info->E820;
+  *Count = Info->E820EntriesCount;
+
+  return EFI_SUCCESS;
+}
+
 /**
   Connects to the Hypervisor.
  

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Sponsored by Intel(R) XDK 
Develop, test and display web and hybrid apps with a single code base.
Download it for free now!
http://pubads.g.doubleclick.net/gampad/clk?id=111408631&iu=/4140/ostg.clktrk
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to