ia64/xen-unstable

view extras/mini-os/hypervisor.c @ 810:3f44ecdcb631

bitkeeper revision 1.499 (3f867c85oOyUdtcboCzrLgktKtvdgA)

ac_timer.h, ac_timer.c:
Xen ac timers now use a heap to find earliest timeout.
author kaf24@scramble.cl.cam.ac.uk
date Fri Oct 10 09:31:49 2003 +0000 (2003-10-10)
parents 209fcea923d4
children 71f9c171157e
line source
1 /******************************************************************************
2 * hypervisor.c
3 *
4 * Communication to/from hypervisor.
5 *
6 * Copied from XenoLinux and adjusted by Rolf.Neugebauer@intel.com
7 *
8 * Copyright (c) 2002, K A Fraser
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
25 #include <os.h>
26 #include <hypervisor.h>
28 static unsigned long event_mask = 0;
29 static unsigned long ev_err_count;
31 void do_hypervisor_callback(struct pt_regs *regs)
32 {
33 unsigned long events, flags;
34 shared_info_t *shared = HYPERVISOR_shared_info;
36 do {
37 /* Specialised local_irq_save(). */
38 flags = test_and_clear_bit(EVENTS_MASTER_ENABLE_BIT,
39 &shared->events_mask);
40 barrier();
42 events = xchg(&shared->events, 0);
43 events &= event_mask;
45 /* 'events' now contains some pending events to handle. */
46 __asm__ __volatile__ (
47 " push %1 ;"
48 " sub $4,%%esp ;"
49 " jmp 2f ;"
50 "1: btrl %%eax,%0 ;" /* clear bit */
51 " mov %%eax,(%%esp) ;"
52 " call do_event ;" /* do_event(event) */
53 "2: bsfl %0,%%eax ;" /* %eax == bit # */
54 " jnz 1b ;"
55 " add $8,%%esp ;"
56 /* we use %ebx because it is callee-saved */
57 : : "b" (events), "r" (regs)
58 /* clobbered by callback function calls */
59 : "eax", "ecx", "edx", "memory" );
61 /* Specialised local_irq_restore(). */
62 if ( flags ) set_bit(EVENTS_MASTER_ENABLE_BIT, &shared->events_mask);
63 barrier();
64 }
65 while ( shared->events );
66 }
70 /*
71 * Define interface to generic handling in irq.c
72 */
74 void enable_hypervisor_event(unsigned int ev)
75 {
76 set_bit(ev, &event_mask);
77 set_bit(ev, &HYPERVISOR_shared_info->events_mask);
78 if ( test_bit(EVENTS_MASTER_ENABLE_BIT,
79 &HYPERVISOR_shared_info->events_mask) )
80 do_hypervisor_callback(NULL);
81 }
83 void disable_hypervisor_event(unsigned int ev)
84 {
85 clear_bit(ev, &event_mask);
86 clear_bit(ev, &HYPERVISOR_shared_info->events_mask);
87 }
89 void ack_hypervisor_event(unsigned int ev)
90 {
91 if ( !(event_mask & (1<<ev)) )
92 {
93 //printk("Unexpected hypervisor event %d\n", ev);
94 atomic_inc((atomic_t *)&ev_err_count);
95 }
96 set_bit(ev, &HYPERVISOR_shared_info->events_mask);
97 }