All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] libxc: Add xc_domain_hvm_get_mtrr_type() call
@ 2012-12-17 11:38 Razvan Cojocaru
  2012-12-18 17:04 ` Ian Campbell
  0 siblings, 1 reply; 22+ messages in thread
From: Razvan Cojocaru @ 2012-12-17 11:38 UTC (permalink / raw)
  To: xen-devel

Add a xc_domain_hvm_get_mtrr_type() call to the libxc API,
to support functionality similar to get_mtrr_type() (which
is only available at the hypervisor level).

Signed-off-by: Razvan Cojocaru <rzvncj@gmail.com>

diff -r f50aab21f9f2 -r a23515aabc91 tools/libxc/xc_domain.c
--- a/tools/libxc/xc_domain.c	Thu Dec 13 14:39:31 2012 +0000
+++ b/tools/libxc/xc_domain.c	Mon Dec 17 12:53:11 2012 +0200
@@ -379,6 +379,45 @@ int xc_domain_hvm_setcontext(xc_interfac
     return ret;
 }
 
+#define MTRR_PHYSMASK_VALID_BIT  11
+#define MTRR_PHYSMASK_SHIFT      12
+#define MTRR_PHYSBASE_TYPE_MASK  0xff   /* lowest 8 bits */
+
+int xc_domain_hvm_get_mtrr_type(xc_interface *xch, 
+                                uint32_t domid,
+                                unsigned long paddress,
+                                uint8_t *type)
+{
+    struct      hvm_hw_mtrr hw_mtrr;
+    int32_t     seg;
+    uint8_t     num_var_ranges;
+    uint64_t    phys_base;
+    uint64_t    phys_mask;
+
+    if ( xc_domain_hvm_getcontext_partial(xch, domid, HVM_SAVE_CODE(MTRR), 0, &hw_mtrr, sizeof hw_mtrr) )
+        return -1;
+
+    num_var_ranges = hw_mtrr.msr_mtrr_cap & 0xff;
+
+    for ( seg = 0; seg < num_var_ranges; seg++ )
+    {
+        phys_base = hw_mtrr.msr_mtrr_var[seg*2];
+        phys_mask = hw_mtrr.msr_mtrr_var[seg*2 + 1];
+
+        if ( phys_mask & (1 << MTRR_PHYSMASK_VALID_BIT) )
+        {
+            if ( ((uint64_t) paddress & phys_mask) >> MTRR_PHYSMASK_SHIFT ==
+                 (phys_base & phys_mask) >> MTRR_PHYSMASK_SHIFT )
+            {
+                *type = phys_base & MTRR_PHYSBASE_TYPE_MASK;
+                return 0;
+            }
+        }
+    }
+
+    return -1;
+}
+
 int xc_vcpu_getcontext(xc_interface *xch,
                        uint32_t domid,
                        uint32_t vcpu,
diff -r f50aab21f9f2 -r a23515aabc91 tools/libxc/xenctrl.h
--- a/tools/libxc/xenctrl.h	Thu Dec 13 14:39:31 2012 +0000
+++ b/tools/libxc/xenctrl.h	Mon Dec 17 12:53:11 2012 +0200
@@ -633,6 +633,15 @@ int xc_domain_hvm_setcontext(xc_interfac
                              uint32_t size);
 
 /**
+ * This function returns information about the MTRR type of
+ * a given guest physical address/
+ */
+int xc_domain_hvm_get_mtrr_type(xc_interface *xch, 
+                                uint32_t domid,
+                                unsigned long paddress,
+                                uint8_t *type);
+
+/**
  * This function returns information about the execution context of a
  * particular vcpu of a domain.
  *

^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2012-12-20 13:40 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-17 11:38 [PATCH] libxc: Add xc_domain_hvm_get_mtrr_type() call Razvan Cojocaru
2012-12-18 17:04 ` Ian Campbell
2012-12-18 17:24   ` Razvan Cojocaru
2012-12-19 10:14     ` Ian Campbell
2012-12-19 10:42       ` Razvan Cojocaru
2012-12-19 11:28         ` Ian Campbell
2012-12-19 11:49           ` Razvan Cojocaru
2012-12-19 12:00             ` Razvan Cojocaru
2012-12-19 14:57             ` Razvan Cojocaru
2012-12-19 15:00               ` Ian Campbell
2012-12-19 15:10                 ` Razvan Cojocaru
2012-12-19 15:27                 ` Andrew Cooper
2012-12-19 15:54                   ` Ian Campbell
2012-12-19 16:11                     ` Andrew Cooper
2012-12-19 16:15                       ` Ian Campbell
2012-12-19 16:29                         ` Razvan Cojocaru
2012-12-19 17:46                           ` Tim Deegan
2012-12-19 19:35                             ` Razvan Cojocaru
2012-12-20 11:57                               ` Tim Deegan
2012-12-20 13:40                                 ` Razvan Cojocaru
2012-12-19 15:43                 ` Razvan Cojocaru
2012-12-20 11:54               ` Tim Deegan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.