Returns all the memory types applicable to a page.

This function is unimplemented for ARM.

Signed-off-by: Roger Pau Monné <roger....@citrix.com>
---
Changes since v5:
 - Return all types that apply to a page, since the types themselves
   are flags that can be or'ed together.
---
Cc: Stefano Stabellini <sstabell...@kernel.org>
Cc: Julien Grall <julien.gr...@arm.com>
Cc: Andrew Cooper <andrew.coop...@citrix.com>
Cc: George Dunlap <george.dun...@eu.citrix.com>
Cc: Ian Jackson <ian.jack...@eu.citrix.com>
Cc: Jan Beulich <jbeul...@suse.com>
Cc: Konrad Rzeszutek Wilk <konrad.w...@oracle.com>
Cc: Tim Deegan <t...@xen.org>
Cc: Wei Liu <wei.l...@citrix.com>
---
 xen/arch/x86/mm.c    | 42 ++++++++++++++++++++++++++++++++++++++++++
 xen/include/xen/mm.h |  3 +++
 2 files changed, 45 insertions(+)

diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
index 85ccf488f5..59de8ade27 100644
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -430,6 +430,48 @@ int page_is_ram_type(unsigned long mfn, unsigned long 
mem_type)
     return 0;
 }
 
+unsigned int page_get_ram_type(unsigned long mfn)
+{
+    uint64_t last = 0, maddr = pfn_to_paddr(mfn);
+    unsigned int i, type = 0;
+
+    for ( i = 0; i < e820.nr_map;
+          last = e820.map[i].addr + e820.map[i].size, i++ )
+    {
+        if ( (maddr + PAGE_SIZE) > last && maddr < e820.map[i].addr )
+            type |= RAM_TYPE_UNKNOWN;
+
+        if ( (maddr + PAGE_SIZE) <= e820.map[i].addr ||
+             maddr >= (e820.map[i].addr + e820.map[i].size) )
+            continue;
+
+        switch ( e820.map[i].type )
+        {
+        case E820_RAM:
+            type |= RAM_TYPE_CONVENTIONAL;
+            break;
+
+        case E820_RESERVED:
+            type |= RAM_TYPE_RESERVED;
+            break;
+
+        case E820_UNUSABLE:
+            type |= RAM_TYPE_UNUSABLE;
+            break;
+
+        case E820_ACPI:
+        case E820_NVS:
+            type |= RAM_TYPE_ACPI;
+            break;
+
+        default:
+            ASSERT_UNREACHABLE();
+        }
+    }
+
+    return type ?: RAM_TYPE_UNKNOWN;
+}
+
 unsigned long domain_get_maximum_gpfn(struct domain *d)
 {
     if ( is_hvm_domain(d) )
diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h
index 24654e8e22..dbaf10495a 100644
--- a/xen/include/xen/mm.h
+++ b/xen/include/xen/mm.h
@@ -595,8 +595,11 @@ int __must_check donate_page(struct domain *d, struct 
page_info *page,
 #define RAM_TYPE_RESERVED     0x00000002
 #define RAM_TYPE_UNUSABLE     0x00000004
 #define RAM_TYPE_ACPI         0x00000008
+#define RAM_TYPE_UNKNOWN      0x00000010
 /* TRUE if the whole page at @mfn is of the requested RAM type(s) above. */
 int page_is_ram_type(unsigned long mfn, unsigned long mem_type);
+/* Returns the page type(s). */
+unsigned int page_get_ram_type(unsigned long mfn);
 
 /* Prepare/destroy a ring for a dom0 helper. Helper with talk
  * with Xen on behalf of this domain. */
-- 
2.18.0


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reply via email to