ia64/xen-unstable

view extras/mini-os/hypervisor.c @ 18811:390ef36eb596

Remove Xen-private definitions from kexec public header.

Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Nov 19 13:13:39 2008 +0000 (2008-11-19)
parents 433d1b26fd51
children
line source
1 /******************************************************************************
2 * hypervisor.c
3 *
4 * Communication to/from hypervisor.
5 *
6 * Copyright (c) 2002-2003, K A Fraser
7 * Copyright (c) 2005, Grzegorz Milos, gm281@cam.ac.uk,Intel Research Cambridge
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to
11 * deal in the Software without restriction, including without limitation the
12 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
13 * sell copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
26 */
28 #include <os.h>
29 #include <hypervisor.h>
30 #include <events.h>
32 #define active_evtchns(cpu,sh,idx) \
33 ((sh)->evtchn_pending[idx] & \
34 ~(sh)->evtchn_mask[idx])
36 int in_callback;
38 void do_hypervisor_callback(struct pt_regs *regs)
39 {
40 unsigned long l1, l2, l1i, l2i;
41 unsigned int port;
42 int cpu = 0;
43 shared_info_t *s = HYPERVISOR_shared_info;
44 vcpu_info_t *vcpu_info = &s->vcpu_info[cpu];
46 in_callback = 1;
48 vcpu_info->evtchn_upcall_pending = 0;
49 /* NB x86. No need for a barrier here -- XCHG is a barrier on x86. */
50 #if !defined(__i386__) && !defined(__x86_64__)
51 /* Clear master flag /before/ clearing selector flag. */
52 wmb();
53 #endif
54 l1 = xchg(&vcpu_info->evtchn_pending_sel, 0);
55 while ( l1 != 0 )
56 {
57 l1i = __ffs(l1);
58 l1 &= ~(1UL << l1i);
60 while ( (l2 = active_evtchns(cpu, s, l1i)) != 0 )
61 {
62 l2i = __ffs(l2);
63 l2 &= ~(1UL << l2i);
65 port = (l1i * (sizeof(unsigned long) * 8)) + l2i;
66 do_event(port, regs);
67 }
68 }
70 in_callback = 0;
71 }
73 void force_evtchn_callback(void)
74 {
75 int save;
76 vcpu_info_t *vcpu;
77 vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()];
78 save = vcpu->evtchn_upcall_mask;
80 while (vcpu->evtchn_upcall_pending) {
81 vcpu->evtchn_upcall_mask = 1;
82 barrier();
83 do_hypervisor_callback(NULL);
84 barrier();
85 vcpu->evtchn_upcall_mask = save;
86 barrier();
87 };
88 }
90 inline void mask_evtchn(u32 port)
91 {
92 shared_info_t *s = HYPERVISOR_shared_info;
93 synch_set_bit(port, &s->evtchn_mask[0]);
94 }
96 inline void unmask_evtchn(u32 port)
97 {
98 shared_info_t *s = HYPERVISOR_shared_info;
99 vcpu_info_t *vcpu_info = &s->vcpu_info[smp_processor_id()];
101 synch_clear_bit(port, &s->evtchn_mask[0]);
103 /*
104 * The following is basically the equivalent of 'hw_resend_irq'. Just like
105 * a real IO-APIC we 'lose the interrupt edge' if the channel is masked.
106 */
107 if ( synch_test_bit (port, &s->evtchn_pending[0]) &&
108 !synch_test_and_set_bit(port / (sizeof(unsigned long) * 8),
109 &vcpu_info->evtchn_pending_sel) )
110 {
111 vcpu_info->evtchn_upcall_pending = 1;
112 if ( !vcpu_info->evtchn_upcall_mask )
113 force_evtchn_callback();
114 }
115 }
117 inline void clear_evtchn(u32 port)
118 {
119 shared_info_t *s = HYPERVISOR_shared_info;
120 synch_clear_bit(port, &s->evtchn_pending[0]);
121 }