direct-io.hg

view xen/arch/x86/platform_hypercall.c @ 11711:9dabb06c66f5

[XEN] Fix memtype accessor domctls.
From: Jan Beulich <jbeulich@novell.com>
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Thu Oct 05 16:42:27 2006 +0100 (2006-10-05)
parents 609b10b17bf0
children 5c8c5925c7e2
line source
1 /******************************************************************************
2 * platform_hypercall.c
3 *
4 * Hardware platform operations. Intended for use by domain-0 kernel.
5 *
6 * Copyright (c) 2002-2006, K Fraser
7 */
9 #include <xen/config.h>
10 #include <xen/types.h>
11 #include <xen/lib.h>
12 #include <xen/mm.h>
13 #include <xen/sched.h>
14 #include <xen/domain.h>
15 #include <xen/event.h>
16 #include <xen/domain_page.h>
17 #include <xen/trace.h>
18 #include <xen/console.h>
19 #include <xen/iocap.h>
20 #include <xen/guest_access.h>
21 #include <asm/current.h>
22 #include <public/platform.h>
23 #include <asm/mtrr.h>
24 #include "cpu/mtrr/mtrr.h"
26 long do_platform_op(XEN_GUEST_HANDLE(xen_platform_op_t) u_xenpf_op)
27 {
28 long ret = 0;
29 struct xen_platform_op curop, *op = &curop;
30 static DEFINE_SPINLOCK(xenpf_lock);
32 if ( !IS_PRIV(current->domain) )
33 return -EPERM;
35 if ( copy_from_guest(op, u_xenpf_op, 1) )
36 return -EFAULT;
38 if ( op->interface_version != XENPF_INTERFACE_VERSION )
39 return -EACCES;
41 spin_lock(&xenpf_lock);
43 switch ( op->cmd )
44 {
45 case XENPF_settime:
46 {
47 do_settime(op->u.settime.secs,
48 op->u.settime.nsecs,
49 op->u.settime.system_time);
50 ret = 0;
51 }
52 break;
54 case XENPF_add_memtype:
55 {
56 ret = mtrr_add_page(
57 op->u.add_memtype.mfn,
58 op->u.add_memtype.nr_mfns,
59 op->u.add_memtype.type,
60 1);
61 if ( ret >= 0 )
62 {
63 op->u.add_memtype.handle = 0;
64 op->u.add_memtype.reg = ret;
65 ret = copy_to_guest(u_xenpf_op, op, 1) ? -EFAULT : 0;
66 if ( ret != 0 )
67 mtrr_del_page(ret, 0, 0);
68 }
69 }
70 break;
72 case XENPF_del_memtype:
73 {
74 if (op->u.del_memtype.handle == 0
75 /* mtrr/main.c otherwise does a lookup */
76 && (int)op->u.del_memtype.reg >= 0)
77 {
78 ret = mtrr_del_page(op->u.del_memtype.reg, 0, 0);
79 if ( ret > 0 )
80 ret = 0;
81 }
82 else
83 ret = -EINVAL;
84 }
85 break;
87 case XENPF_read_memtype:
88 {
89 unsigned long mfn;
90 unsigned int nr_mfns;
91 mtrr_type type;
93 ret = -EINVAL;
94 if ( op->u.read_memtype.reg < num_var_ranges )
95 {
96 mtrr_if->get(op->u.read_memtype.reg, &mfn, &nr_mfns, &type);
97 op->u.read_memtype.mfn = mfn;
98 op->u.read_memtype.nr_mfns = nr_mfns;
99 op->u.read_memtype.type = type;
100 ret = copy_to_guest(u_xenpf_op, op, 1) ? -EFAULT : 0;
101 }
102 }
103 break;
105 case XENPF_microcode_update:
106 {
107 extern int microcode_update(XEN_GUEST_HANDLE(void), unsigned long len);
108 ret = microcode_update(op->u.microcode.data,
109 op->u.microcode.length);
110 }
111 break;
113 case XENPF_platform_quirk:
114 {
115 extern int opt_noirqbalance;
116 int quirk_id = op->u.platform_quirk.quirk_id;
117 switch ( quirk_id )
118 {
119 case QUIRK_NOIRQBALANCING:
120 printk("Platform quirk -- Disabling IRQ balancing/affinity.\n");
121 opt_noirqbalance = 1;
122 setup_ioapic_dest();
123 break;
124 case QUIRK_IOAPIC_BAD_REGSEL:
125 case QUIRK_IOAPIC_GOOD_REGSEL:
126 #ifndef sis_apic_bug
127 sis_apic_bug = (quirk_id == QUIRK_IOAPIC_BAD_REGSEL);
128 DPRINTK("Domain 0 says that IO-APIC REGSEL is %s\n",
129 sis_apic_bug ? "bad" : "good");
130 #else
131 BUG_ON(sis_apic_bug != (quirk_id == QUIRK_IOAPIC_BAD_REGSEL));
132 #endif
133 break;
134 default:
135 ret = -EINVAL;
136 break;
137 }
138 }
139 break;
141 default:
142 ret = -ENOSYS;
143 break;
144 }
146 spin_unlock(&xenpf_lock);
148 return ret;
149 }
151 /*
152 * Local variables:
153 * mode: C
154 * c-set-style: "BSD"
155 * c-basic-offset: 4
156 * tab-width: 4
157 * indent-tabs-mode: nil
158 * End:
159 */