ia64/xen-unstable

view xen/arch/x86/physdev.c @ 15815:96f64f4c42f0

Xen Security Modules: XSM
Signed-off-by: George Coker <gscoker@alpha.ncsc.mil>
author kfraser@localhost.localdomain
date Fri Aug 31 11:21:35 2007 +0100 (2007-08-31)
parents e9a5c6b2acbe
children 00fec8212ae6
line source
2 #include <xen/config.h>
3 #include <xen/init.h>
4 #include <xen/lib.h>
5 #include <xen/types.h>
6 #include <xen/sched.h>
7 #include <xen/irq.h>
8 #include <xen/event.h>
9 #include <xen/guest_access.h>
10 #include <asm/current.h>
11 #include <asm/smpboot.h>
12 #include <asm/hypercall.h>
13 #include <public/xen.h>
14 #include <public/physdev.h>
15 #include <xsm/xsm.h>
17 #ifndef COMPAT
18 typedef long ret_t;
19 #endif
21 int
22 ioapic_guest_read(
23 unsigned long physbase, unsigned int reg, u32 *pval);
24 int
25 ioapic_guest_write(
26 unsigned long physbase, unsigned int reg, u32 pval);
28 ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE(void) arg)
29 {
30 int irq;
31 ret_t ret;
32 struct vcpu *v = current;
34 switch ( cmd )
35 {
36 case PHYSDEVOP_eoi: {
37 struct physdev_eoi eoi;
38 ret = -EFAULT;
39 if ( copy_from_guest(&eoi, arg, 1) != 0 )
40 break;
41 ret = pirq_guest_eoi(v->domain, eoi.irq);
42 break;
43 }
45 /* Legacy since 0x00030202. */
46 case PHYSDEVOP_IRQ_UNMASK_NOTIFY: {
47 ret = pirq_guest_unmask(v->domain);
48 break;
49 }
51 case PHYSDEVOP_irq_status_query: {
52 struct physdev_irq_status_query irq_status_query;
53 ret = -EFAULT;
54 if ( copy_from_guest(&irq_status_query, arg, 1) != 0 )
55 break;
56 irq = irq_status_query.irq;
57 ret = -EINVAL;
58 if ( (irq < 0) || (irq >= NR_IRQS) )
59 break;
60 irq_status_query.flags = 0;
61 if ( pirq_acktype(irq) != 0 )
62 irq_status_query.flags |= XENIRQSTAT_needs_eoi;
63 if ( pirq_shared(irq) )
64 irq_status_query.flags |= XENIRQSTAT_shared;
65 ret = copy_to_guest(arg, &irq_status_query, 1) ? -EFAULT : 0;
66 break;
67 }
69 case PHYSDEVOP_apic_read: {
70 struct physdev_apic apic;
71 ret = -EFAULT;
72 if ( copy_from_guest(&apic, arg, 1) != 0 )
73 break;
74 ret = -EPERM;
75 if ( !IS_PRIV(v->domain) )
76 break;
77 ret = xsm_apic(v->domain, cmd);
78 if ( ret )
79 break;
80 ret = ioapic_guest_read(apic.apic_physbase, apic.reg, &apic.value);
81 if ( copy_to_guest(arg, &apic, 1) != 0 )
82 ret = -EFAULT;
83 break;
84 }
86 case PHYSDEVOP_apic_write: {
87 struct physdev_apic apic;
88 ret = -EFAULT;
89 if ( copy_from_guest(&apic, arg, 1) != 0 )
90 break;
91 ret = -EPERM;
92 if ( !IS_PRIV(v->domain) )
93 break;
94 ret = xsm_apic(v->domain, cmd);
95 if ( ret )
96 break;
97 ret = ioapic_guest_write(apic.apic_physbase, apic.reg, apic.value);
98 break;
99 }
101 case PHYSDEVOP_alloc_irq_vector: {
102 struct physdev_irq irq_op;
104 ret = -EFAULT;
105 if ( copy_from_guest(&irq_op, arg, 1) != 0 )
106 break;
108 ret = -EPERM;
109 if ( !IS_PRIV(v->domain) )
110 break;
112 ret = xsm_assign_vector(v->domain, irq_op.irq);
113 if ( ret )
114 break;
116 irq = irq_op.irq;
117 ret = -EINVAL;
118 if ( (irq < 0) || (irq >= NR_IRQS) )
119 break;
121 irq_op.vector = assign_irq_vector(irq);
122 ret = copy_to_guest(arg, &irq_op, 1) ? -EFAULT : 0;
123 break;
124 }
126 case PHYSDEVOP_set_iopl: {
127 struct physdev_set_iopl set_iopl;
128 ret = -EFAULT;
129 if ( copy_from_guest(&set_iopl, arg, 1) != 0 )
130 break;
131 ret = -EINVAL;
132 if ( set_iopl.iopl > 3 )
133 break;
134 ret = 0;
135 v->arch.iopl = set_iopl.iopl;
136 break;
137 }
139 case PHYSDEVOP_set_iobitmap: {
140 struct physdev_set_iobitmap set_iobitmap;
141 ret = -EFAULT;
142 if ( copy_from_guest(&set_iobitmap, arg, 1) != 0 )
143 break;
144 ret = -EINVAL;
145 if ( !guest_handle_okay(set_iobitmap.bitmap, IOBMP_BYTES) ||
146 (set_iobitmap.nr_ports > 65536) )
147 break;
148 ret = 0;
149 #ifndef COMPAT
150 v->arch.iobmp = set_iobitmap.bitmap;
151 #else
152 guest_from_compat_handle(v->arch.iobmp, set_iobitmap.bitmap);
153 #endif
154 v->arch.iobmp_limit = set_iobitmap.nr_ports;
155 break;
156 }
158 default:
159 ret = -ENOSYS;
160 break;
161 }
163 return ret;
164 }
166 /*
167 * Local variables:
168 * mode: C
169 * c-set-style: "BSD"
170 * c-basic-offset: 4
171 * tab-width: 4
172 * indent-tabs-mode: nil
173 * End:
174 */