direct-io.hg

view extras/mini-os/hypervisor.c @ 1443:180c1407b64f

bitkeeper revision 1.943 (40c6c10f90gVdztSEe31gGHbItwLwg)

interface.c:
Net backend rename
author kaf24@scramble.cl.cam.ac.uk
date Wed Jun 09 07:49:35 2004 +0000 (2004-06-09)
parents 71f9c171157e
children 189c87adf876 1883ec07708b
line source
1 /******************************************************************************
2 * hypervisor.c
3 *
4 * Communication to/from hypervisor.
5 *
6 * Copyright (c) 2002-2003, K A Fraser
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to
10 * deal in the Software without restriction, including without limitation the
11 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12 * sell copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
25 */
27 #include <os.h>
28 #include <hypervisor.h>
30 static unsigned long event_mask = 0;
31 static unsigned long ev_err_count;
33 void do_hypervisor_callback(struct pt_regs *regs)
34 {
35 unsigned long events, flags;
36 shared_info_t *shared = HYPERVISOR_shared_info;
38 do {
39 /* Specialised local_irq_save(). */
40 flags = test_and_clear_bit(EVENTS_MASTER_ENABLE_BIT,
41 &shared->events_mask);
42 barrier();
44 events = xchg(&shared->events, 0);
45 events &= event_mask;
47 /* 'events' now contains some pending events to handle. */
48 __asm__ __volatile__ (
49 " push %1 ;"
50 " sub $4,%%esp ;"
51 " jmp 2f ;"
52 "1: btrl %%eax,%0 ;" /* clear bit */
53 " mov %%eax,(%%esp) ;"
54 " call do_event ;" /* do_event(event) */
55 "2: bsfl %0,%%eax ;" /* %eax == bit # */
56 " jnz 1b ;"
57 " add $8,%%esp ;"
58 /* we use %ebx because it is callee-saved */
59 : : "b" (events), "r" (regs)
60 /* clobbered by callback function calls */
61 : "eax", "ecx", "edx", "memory" );
63 /* Specialised local_irq_restore(). */
64 if ( flags ) set_bit(EVENTS_MASTER_ENABLE_BIT, &shared->events_mask);
65 barrier();
66 }
67 while ( shared->events );
68 }
70 void enable_hypervisor_event(unsigned int ev)
71 {
72 set_bit(ev, &event_mask);
73 set_bit(ev, &HYPERVISOR_shared_info->events_mask);
74 if ( test_bit(EVENTS_MASTER_ENABLE_BIT,
75 &HYPERVISOR_shared_info->events_mask) )
76 do_hypervisor_callback(NULL);
77 }
79 void disable_hypervisor_event(unsigned int ev)
80 {
81 clear_bit(ev, &event_mask);
82 clear_bit(ev, &HYPERVISOR_shared_info->events_mask);
83 }
85 void ack_hypervisor_event(unsigned int ev)
86 {
87 if ( !(event_mask & (1<<ev)) )
88 atomic_inc((atomic_t *)&ev_err_count);
89 set_bit(ev, &HYPERVISOR_shared_info->events_mask);
90 }