ia64/xen-unstable

view extras/mini-os/events.c @ 6685:549f4256ab3c

Remove control interface in kernels and domain builder.
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Wed Sep 07 17:43:56 2005 +0000 (2005-09-07)
parents a83ac0806d6b
children df1348e72390 cdfa7dd00c44 b2f4823b6ff0
line source
1 /* -*- Mode:C; c-basic-offset:4; tab-width:4 -*-
2 ****************************************************************************
3 * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge
4 * (C) 2005 - Grzegorz Milos - Intel Research Cambridge
5 ****************************************************************************
6 *
7 * File: events.c
8 * Author: Rolf Neugebauer (neugebar@dcs.gla.ac.uk)
9 * Changes: Grzegorz Milos (gm281@cam.ac.uk)
10 *
11 * Date: Jul 2003, changes Jun 2005
12 *
13 * Environment: Xen Minimal OS
14 * Description: Deals with events recieved on event channels
15 *
16 ****************************************************************************
17 */
19 #include <os.h>
20 #include <hypervisor.h>
21 #include <events.h>
22 #include <lib.h>
24 #include <xen/event_channel.h>
25 static ev_action_t ev_actions[NR_EVS];
26 void default_handler(u32 port, struct pt_regs *regs);
29 /*
30 * Demux events to different handlers.
31 */
32 int do_event(u32 port, struct pt_regs *regs)
33 {
34 ev_action_t *action;
36 if (port >= NR_EVS) {
37 printk("Port number too large: %d\n", port);
38 return 0;
39 }
41 action = &ev_actions[port];
42 action->count++;
44 if (!action->handler)
45 goto out;
47 if (action->status & EVS_DISABLED)
48 goto out;
50 /* call the handler */
51 action->handler(port, regs);
53 clear_evtchn(port);
55 out:
56 return 1;
58 }
60 int bind_virq( u32 virq, void (*handler)(int, struct pt_regs *) )
61 {
62 evtchn_op_t op;
63 int ret = 0;
64 u32 port;
66 /* Try to bind the virq to a port */
67 op.cmd = EVTCHNOP_bind_virq;
68 op.u.bind_virq.virq = virq;
70 if ( HYPERVISOR_event_channel_op(&op) != 0 )
71 {
72 ret = 1;
73 printk("Failed to bind virtual IRQ %d\n", virq);
74 goto out;
75 }
77 port = op.u.bind_virq.port;
79 if(ev_actions[port].handler)
80 printk("WARN: Handler for port %d already registered, replacing\n",
81 port);
83 ev_actions[port].handler = handler;
84 ev_actions[port].status &= ~EVS_DISABLED;
86 /* Finally unmask the port */
87 unmask_evtchn(port);
88 out:
89 return ret;
90 }
92 /*
93 * Initially all events are without a handler and disabled
94 */
95 void init_events(void)
96 {
97 int i;
99 /* inintialise event handler */
100 for ( i = 0; i < NR_EVS; i++ )
101 {
102 ev_actions[i].status = EVS_DISABLED;
103 ev_actions[i].handler = NULL;
104 }
105 }
107 void default_handler(u32 port, struct pt_regs *regs) {
108 printk("[Port %d] - event received\n", port);
109 }