]> xenbits.xensource.com Git - people/ssmith/netchannel2-pvops.git/commitdiff
xen/mtrr: Add mtrr_if support for Xen mtrr
authorStephen Tweedie <sct@redhat.com>
Thu, 18 Jun 2009 23:54:24 +0000 (16:54 -0700)
committerJeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
Fri, 19 Jun 2009 19:13:13 +0000 (12:13 -0700)
Add a Xen mtrr type, and reorganise mtrr initialisation slightly to
allow the mtrr driver to set up num_var_ranges (Xen needs to do this by
querying the hypervisor itself.)

Only the boot path is handled for now: we set up a xen-specific mtrr_if
and set up the mtrr tables based on hypervisor information, but we don't
yet handle mtrr entry add/delete.

[ Impact: add basic MTRR support (enough to get started) ]

Signed-off-by: Stephen Tweedie <sct@redhat.com>
Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
arch/x86/kernel/cpu/mtrr/Makefile
arch/x86/kernel/cpu/mtrr/main.c
arch/x86/kernel/cpu/mtrr/mtrr.h
arch/x86/kernel/cpu/mtrr/xen.c [new file with mode: 0644]

index f4361b56f8e92efab75d05b1f361f1416d9aec03..404e4581d191090a863bb57643fe98efd51e3e04 100644 (file)
@@ -1,3 +1,4 @@
 obj-y          := main.o if.o generic.o state.o cleanup.o
 obj-$(CONFIG_X86_32) += amd.o cyrix.o centaur.o
+obj-$(CONFIG_XEN_DOM0) += xen.o
 
index 5fbbe6b8cb3019c04231e29cd1ba9f3bf1419f05..072eeda434739405844b0aa60fa4c55833ca5dfc 100644 (file)
@@ -670,6 +670,9 @@ void __init mtrr_bp_init(void)
                }
        }
 
+       /* Let Xen code override the above if it wants */
+       xen_init_mtrr();
+
        if (mtrr_if) {
                num_var_ranges = mtrr_if->num_var_ranges();
                init_table();
index 35b61dde5b6bbd3f639815716ff21eb3efde6b37..d664390c603873fa24bd1b6b9c39aaa206925719 100644 (file)
@@ -76,6 +76,13 @@ void mtrr_wrmsr(unsigned, unsigned, unsigned);
 int amd_init_mtrr(void);
 int cyrix_init_mtrr(void);
 int centaur_init_mtrr(void);
+#ifdef CONFIG_XEN
+void xen_init_mtrr(void);
+#else
+static inline void xen_init_mtrr(void)
+{
+}
+#endif
 
 extern int changed_by_mtrr_cleanup;
 extern int mtrr_cleanup(unsigned address_bits);
diff --git a/arch/x86/kernel/cpu/mtrr/xen.c b/arch/x86/kernel/cpu/mtrr/xen.c
new file mode 100644 (file)
index 0000000..031331c
--- /dev/null
@@ -0,0 +1,55 @@
+#include <linux/init.h>
+#include <linux/mm.h>
+
+#include "mtrr.h"
+
+#include <xen/interface/platform.h>
+#include <asm/xen/hypervisor.h>
+#include <asm/xen/hypercall.h>
+
+static int __init xen_num_var_ranges(void)
+{
+       int ranges;
+       struct xen_platform_op op;
+
+       op.cmd = XENPF_read_memtype;
+
+       for (ranges = 0; ; ranges++) {
+               op.u.read_memtype.reg = ranges;
+               if (HYPERVISOR_dom0_op(&op) != 0)
+                       break;
+       }
+       return ranges;
+}
+
+/*
+ * DOM0 TODO: Need to fill in the remaining mtrr methods to have full
+ * working userland mtrr support.
+ */
+static struct mtrr_ops xen_mtrr_ops = {
+       .vendor            = X86_VENDOR_UNKNOWN,
+       .get_free_region   = generic_get_free_region,
+       .have_wrcomb       = positive_have_wrcomb,
+       .use_intel_if      = 0,
+       .num_var_ranges    = xen_num_var_ranges,
+};
+
+void __init xen_init_mtrr(void)
+{
+       /* 
+        * Check that we're running under Xen, and privileged enough
+        * to play with MTRRs.
+        */
+       if (!xen_initial_domain())
+               return;
+
+       /* 
+        * Check that the CPU has an MTRR implementation we can
+        * support.
+        */
+       if (cpu_has_mtrr ||
+           cpu_has_k6_mtrr ||
+           cpu_has_cyrix_arr ||
+           cpu_has_centaur_mcr)
+               mtrr_if = &xen_mtrr_ops;
+}