ia64/xen-unstable

annotate 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
rev   line source
iap10@792 1 /* -*- Mode:C; c-basic-offset:4; tab-width:4 -*-
iap10@792 2 ****************************************************************************
iap10@792 3 * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge
kaf24@5675 4 * (C) 2005 - Grzegorz Milos - Intel Research Cambridge
iap10@792 5 ****************************************************************************
iap10@792 6 *
iap10@792 7 * File: events.c
iap10@792 8 * Author: Rolf Neugebauer (neugebar@dcs.gla.ac.uk)
kaf24@5675 9 * Changes: Grzegorz Milos (gm281@cam.ac.uk)
iap10@792 10 *
kaf24@5675 11 * Date: Jul 2003, changes Jun 2005
iap10@792 12 *
iap10@792 13 * Environment: Xen Minimal OS
kaf24@5675 14 * Description: Deals with events recieved on event channels
iap10@792 15 *
iap10@792 16 ****************************************************************************
iap10@792 17 */
iap10@792 18
iap10@792 19 #include <os.h>
kaf24@6714 20 #include <mm.h>
iap10@792 21 #include <hypervisor.h>
iap10@792 22 #include <events.h>
iap10@792 23 #include <lib.h>
iap10@792 24
kaf24@9298 25
iap10@792 26 static ev_action_t ev_actions[NR_EVS];
kaf24@6714 27 void default_handler(int port, struct pt_regs *regs);
iap10@792 28
iap10@792 29
iap10@792 30 /*
kaf24@5675 31 * Demux events to different handlers.
iap10@792 32 */
kaf24@5675 33 int do_event(u32 port, struct pt_regs *regs)
iap10@792 34 {
iap10@792 35 ev_action_t *action;
kaf24@5675 36 if (port >= NR_EVS) {
kaf24@5675 37 printk("Port number too large: %d\n", port);
iap10@792 38 return 0;
iap10@792 39 }
iap10@792 40
kaf24@5675 41 action = &ev_actions[port];
iap10@792 42 action->count++;
iap10@792 43
iap10@792 44 if (!action->handler)
iap10@792 45 goto out;
iap10@792 46
iap10@792 47 if (action->status & EVS_DISABLED)
iap10@792 48 goto out;
iap10@792 49
iap10@792 50 /* call the handler */
kaf24@5675 51 action->handler(port, regs);
kaf24@5675 52
kaf24@5675 53 clear_evtchn(port);
iap10@792 54
iap10@792 55 out:
iap10@792 56 return 1;
iap10@792 57
iap10@792 58 }
iap10@792 59
kaf24@8284 60 int bind_evtchn( u32 port, void (*handler)(int, struct pt_regs *) )
kaf24@6714 61 {
kaf24@9298 62 if(ev_actions[port].handler != default_handler)
kaf24@6714 63 printk("WARN: Handler for port %d already registered, replacing\n",
kaf24@6714 64 port);
kaf24@6714 65
kaf24@6714 66 ev_actions[port].handler = handler;
kaf24@6714 67 ev_actions[port].status &= ~EVS_DISABLED;
kaf24@6714 68
kaf24@6714 69 /* Finally unmask the port */
kaf24@6714 70 unmask_evtchn(port);
kaf24@8284 71
kaf24@8284 72 return port;
kaf24@8284 73 }
kaf24@8284 74
kaf24@8284 75 void unbind_evtchn( u32 port )
kaf24@8284 76 {
kaf24@9444 77 if (ev_actions[port].handler == default_handler)
kaf24@8284 78 printk("WARN: No handler for port %d when unbinding\n", port);
kaf24@9444 79 ev_actions[port].handler = default_handler;
kaf24@8284 80 ev_actions[port].status |= EVS_DISABLED;
kaf24@6714 81 }
kaf24@6714 82
kaf24@5675 83 int bind_virq( u32 virq, void (*handler)(int, struct pt_regs *) )
iap10@792 84 {
kaf24@5675 85 evtchn_op_t op;
kaf24@5675 86 int ret = 0;
kaf24@5675 87
kaf24@5675 88 /* Try to bind the virq to a port */
kaf24@5675 89 op.cmd = EVTCHNOP_bind_virq;
kaf24@5675 90 op.u.bind_virq.virq = virq;
kaf24@8251 91 op.u.bind_virq.vcpu = smp_processor_id();
kaf24@5675 92
kaf24@5675 93 if ( HYPERVISOR_event_channel_op(&op) != 0 )
kaf24@5675 94 {
kaf24@5675 95 ret = 1;
kaf24@5675 96 printk("Failed to bind virtual IRQ %d\n", virq);
kaf24@5675 97 goto out;
iap10@792 98 }
kaf24@6714 99 bind_evtchn(op.u.bind_virq.port, handler);
kaf24@5675 100 out:
kaf24@5675 101 return ret;
iap10@792 102 }
iap10@792 103
kaf24@8284 104 void unbind_virq( u32 port )
kaf24@8284 105 {
kaf24@8284 106 unbind_evtchn(port);
kaf24@8284 107 }
kaf24@6714 108
kaf24@6714 109
iap10@792 110 /*
kaf24@5675 111 * Initially all events are without a handler and disabled
iap10@792 112 */
iap10@792 113 void init_events(void)
iap10@792 114 {
iap10@792 115 int i;
iap10@792 116
iap10@792 117 /* inintialise event handler */
iap10@792 118 for ( i = 0; i < NR_EVS; i++ )
iap10@792 119 {
iap10@792 120 ev_actions[i].status = EVS_DISABLED;
kaf24@6714 121 ev_actions[i].handler = default_handler;
iap10@792 122 }
iap10@792 123 }
iap10@792 124
kaf24@6714 125 void default_handler(int port, struct pt_regs *regs) {
kaf24@5675 126 printk("[Port %d] - event received\n", port);
iap10@792 127 }