ia64/xen-unstable

view extras/mini-os/events.c @ 3017:d0006e7baa9a

bitkeeper revision 1.1159.170.41 (419b5697bEIXHXiSbTxwpjfvjHraWw)

Reassert 2.1-devel after push to 2.0 tree.
author kaf24@freefall.cl.cam.ac.uk
date Wed Nov 17 13:48:07 2004 +0000 (2004-11-17)
parents 71f9c171157e
children 189c87adf876 1883ec07708b
line source
1 /* -*- Mode:C; c-basic-offset:4; tab-width:4 -*-
2 ****************************************************************************
3 * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge
4 ****************************************************************************
5 *
6 * File: events.c
7 * Author: Rolf Neugebauer (neugebar@dcs.gla.ac.uk)
8 * Changes:
9 *
10 * Date: Jul 2003
11 *
12 * Environment: Xen Minimal OS
13 * Description: Deal with events
14 *
15 ****************************************************************************
16 * $Id: c-insert.c,v 1.7 2002/11/08 16:04:34 rn Exp $
17 ****************************************************************************
18 */
20 #include <os.h>
21 #include <hypervisor.h>
22 #include <events.h>
23 #include <lib.h>
25 static ev_action_t ev_actions[NR_EVS];
26 void default_handler(int ev, struct pt_regs *regs);
29 /*
30 * demux events to different handlers
31 */
32 unsigned int do_event(int ev, struct pt_regs *regs)
33 {
34 ev_action_t *action;
36 if (ev >= NR_EVS) {
37 printk("Large event number %d\n", ev);
38 return 0;
39 }
41 action = &ev_actions[ev];
42 action->count++;
43 ack_hypervisor_event(ev);
45 if (!action->handler)
46 goto out;
48 if (action->status & EVS_DISABLED)
49 goto out;
51 /* call the handler */
52 action->handler(ev, regs);
54 out:
55 return 1;
57 }
59 /*
60 * add a handler
61 */
62 unsigned int add_ev_action( int ev, void (*handler)(int, struct pt_regs *) )
63 {
64 if (ev_actions[ev].handler) {
65 printk ("event[%d] already handled by %p", ev, ev_actions[ev].handler);
66 return 0;
67 }
69 ev_actions[ev].handler = handler;
70 return 1;
71 }
73 unsigned int enable_ev_action( int ev )
74 {
75 if (!ev_actions[ev].handler) {
76 printk ("enable event[%d], no handler installed", ev);
77 return 0;
78 }
79 ev_actions[ev].status &= ~EVS_DISABLED;
80 return 1;
81 }
83 unsigned int disable_ev_action( int ev )
84 {
85 ev_actions[ev].status |= EVS_DISABLED;
86 return 1;
87 }
89 /*
90 * initially all events are without a handler and disabled
91 */
92 void init_events(void)
93 {
94 int i;
96 /* inintialise event handler */
97 for ( i = 0; i < NR_EVS; i++ )
98 {
99 ev_actions[i].status = EVS_DISABLED;
100 ev_actions[i].handler = NULL;
101 }
102 }
104 void default_handler(int ev, struct pt_regs *regs) {
105 printk("X[%d] ", ev);
106 }