The type is only returned if the full page has the same type. This
function is unimplemented for ARM.

Signed-off-by: Roger Pau MonnĂ© <[email protected]>
---
Cc: Stefano Stabellini <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>
---
 xen/arch/arm/mm.c    |  6 ++++++
 xen/arch/x86/mm.c    | 34 ++++++++++++++++++++++++++++++++++
 xen/include/xen/mm.h |  2 ++
 3 files changed, 42 insertions(+)

diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c
index d234c46e41..f734b9287a 100644
--- a/xen/arch/arm/mm.c
+++ b/xen/arch/arm/mm.c
@@ -1181,6 +1181,12 @@ int page_is_ram_type(unsigned long mfn, unsigned long 
mem_type)
     return 0;
 }
 
+int page_get_type(unsigned long mfn)
+{
+    ASSERT_UNREACHABLE();
+    return -1;
+}
+
 unsigned long domain_get_maximum_gpfn(struct domain *d)
 {
     return gfn_x(d->arch.p2m.max_mapped_gfn);
diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
index a1a1f5f3c3..cb4b68b2a9 100644
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -430,6 +430,40 @@ int page_is_ram_type(unsigned long mfn, unsigned long 
mem_type)
     return 0;
 }
 
+int page_get_type(unsigned long mfn)
+{
+    uint64_t maddr = pfn_to_paddr(mfn);
+    unsigned int i;
+
+    for ( i = 0; i < e820.nr_map; i++ )
+    {
+        /* Test the range. */
+        if ( (e820.map[i].addr <= maddr) &&
+             ((e820.map[i].addr + e820.map[i].size) >= (maddr + PAGE_SIZE)) )
+            switch ( e820.map[i].type )
+            {
+            case E820_RAM:
+                return RAM_TYPE_CONVENTIONAL;
+
+            case E820_RESERVED:
+                return RAM_TYPE_RESERVED;
+
+            case E820_UNUSABLE:
+                return RAM_TYPE_UNUSABLE;
+
+            case E820_ACPI:
+            case E820_NVS:
+                return RAM_TYPE_ACPI;
+
+            default:
+                ASSERT_UNREACHABLE();
+                return -1;
+            }
+    }
+
+    return -1;
+}
+
 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..9584fe3a77 100644
--- a/xen/include/xen/mm.h
+++ b/xen/include/xen/mm.h
@@ -597,6 +597,8 @@ int __must_check donate_page(struct domain *d, struct 
page_info *page,
 #define RAM_TYPE_ACPI         0x00000008
 /* 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 if the whole page is of the same type. */
+int page_get_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
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reply via email to