]> xenbits.xensource.com Git - people/royger/xen.git/commitdiff
mm: introduce a helper to get the memory type of a page
authorRoger Pau Monné <roger.pau@citrix.com>
Fri, 7 Sep 2018 09:08:00 +0000 (11:08 +0200)
committerJan Beulich <jbeulich@suse.com>
Wed, 12 Sep 2018 14:32:06 +0000 (16:32 +0200)
Returns all the memory types applicable to a page.

This function is unimplemented for ARM.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/mm.c
xen/include/xen/mm.h

index baea2f5e6333c70348a4782b7d155e98a5b1361b..d37eea53d1c488fc530da2cac8ee244c5dfabb74 100644 (file)
@@ -430,6 +430,48 @@ int page_is_ram_type(unsigned long mfn, unsigned long mem_type)
     return 0;
 }
 
+unsigned int page_get_ram_type(mfn_t mfn)
+{
+    uint64_t last = 0, maddr = mfn_to_maddr(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) )
index 24654e8e22647226ee5744166063e8b63e0340a1..b3d46ab56b4e4ecb5587cb33b61a555ebcf53aea 100644 (file)
@@ -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(mfn_t mfn);
 
 /* Prepare/destroy a ring for a dom0 helper. Helper with talk
  * with Xen on behalf of this domain. */