ia64/xen-unstable

view extras/mini-os/events.c @ 9788:bdcc838b9a72

Add small memory warning message to domain configuration examples.

Signed-off-by: Daniel Stekloff <dsteklof@us.ibm.com>
author stekloff@dyn9047022152.beaverton.ibm.com
date Wed Apr 19 22:58:24 2006 +0100 (2006-04-19)
parents 8c21c8ea5fff
children f6507937cb7c
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 <mm.h>
21 #include <hypervisor.h>
22 #include <events.h>
23 #include <lib.h>
26 static ev_action_t ev_actions[NR_EVS];
27 void default_handler(int port, struct pt_regs *regs);
30 /*
31 * Demux events to different handlers.
32 */
33 int do_event(u32 port, struct pt_regs *regs)
34 {
35 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_evtchn( u32 port, void (*handler)(int, struct pt_regs *) )
61 {
62 if(ev_actions[port].handler != default_handler)
63 printk("WARN: Handler for port %d already registered, replacing\n",
64 port);
66 ev_actions[port].handler = handler;
67 ev_actions[port].status &= ~EVS_DISABLED;
69 /* Finally unmask the port */
70 unmask_evtchn(port);
72 return port;
73 }
75 void unbind_evtchn( u32 port )
76 {
77 if (ev_actions[port].handler == default_handler)
78 printk("WARN: No handler for port %d when unbinding\n", port);
79 ev_actions[port].handler = default_handler;
80 ev_actions[port].status |= EVS_DISABLED;
81 }
83 int bind_virq( u32 virq, void (*handler)(int, struct pt_regs *) )
84 {
85 evtchn_op_t op;
86 int ret = 0;
88 /* Try to bind the virq to a port */
89 op.cmd = EVTCHNOP_bind_virq;
90 op.u.bind_virq.virq = virq;
91 op.u.bind_virq.vcpu = smp_processor_id();
93 if ( HYPERVISOR_event_channel_op(&op) != 0 )
94 {
95 ret = 1;
96 printk("Failed to bind virtual IRQ %d\n", virq);
97 goto out;
98 }
99 bind_evtchn(op.u.bind_virq.port, handler);
100 out:
101 return ret;
102 }
104 void unbind_virq( u32 port )
105 {
106 unbind_evtchn(port);
107 }
110 /*
111 * Initially all events are without a handler and disabled
112 */
113 void init_events(void)
114 {
115 int i;
117 /* inintialise event handler */
118 for ( i = 0; i < NR_EVS; i++ )
119 {
120 ev_actions[i].status = EVS_DISABLED;
121 ev_actions[i].handler = default_handler;
122 }
123 }
125 void default_handler(int port, struct pt_regs *regs) {
126 printk("[Port %d] - event received\n", port);
127 }