ia64/xen-unstable

view extras/mini-os/events.c @ 10848:a10d02d20b31

[MINI-OS] unbind_virq is broken and nobody uses it. Remove it.

Signed-off-by: Steven Smith <sos22@cam.ac.uk>
author sos22@douglas.cl.cam.ac.uk
date Fri Jul 28 14:00:37 2006 +0100 (2006-07-28)
parents 43474e663b3d
children 98a802d25848
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>
25 #define NR_EVS 1024
27 /* this represents a event handler. Chaining or sharing is not allowed */
28 typedef struct _ev_action_t {
29 void (*handler)(int, struct pt_regs *, void *);
30 void *data;
31 u32 count;
32 } ev_action_t;
35 static ev_action_t ev_actions[NR_EVS];
36 void default_handler(int port, struct pt_regs *regs, void *data);
39 /*
40 * Demux events to different handlers.
41 */
42 int do_event(u32 port, struct pt_regs *regs)
43 {
44 ev_action_t *action;
45 if (port >= NR_EVS) {
46 printk("Port number too large: %d\n", port);
47 goto out;
48 }
50 action = &ev_actions[port];
51 action->count++;
53 /* call the handler */
54 action->handler(port, regs, action->data);
56 out:
57 clear_evtchn(port);
59 return 1;
61 }
63 int bind_evtchn( u32 port, void (*handler)(int, struct pt_regs *, void *),
64 void *data )
65 {
66 if(ev_actions[port].handler != default_handler)
67 printk("WARN: Handler for port %d already registered, replacing\n",
68 port);
70 ev_actions[port].data = data;
71 wmb();
72 ev_actions[port].handler = handler;
74 /* Finally unmask the port */
75 unmask_evtchn(port);
77 return port;
78 }
80 void unbind_evtchn( u32 port )
81 {
82 if (ev_actions[port].handler == default_handler)
83 printk("WARN: No handler for port %d when unbinding\n", port);
84 ev_actions[port].handler = default_handler;
85 wmb();
86 ev_actions[port].data = NULL;
87 }
89 int bind_virq( u32 virq, void (*handler)(int, struct pt_regs *, void *data),
90 void *data)
91 {
92 evtchn_op_t op;
94 /* Try to bind the virq to a port */
95 op.cmd = EVTCHNOP_bind_virq;
96 op.u.bind_virq.virq = virq;
97 op.u.bind_virq.vcpu = smp_processor_id();
99 if ( HYPERVISOR_event_channel_op(&op) != 0 )
100 {
101 printk("Failed to bind virtual IRQ %d\n", virq);
102 return 1;
103 }
104 bind_evtchn(op.u.bind_virq.port, handler, data);
105 return 0;
106 }
108 #if defined(__x86_64__)
109 /* Allocate 4 pages for the irqstack */
110 #define STACK_PAGES 4
111 char irqstack[1024 * 4 * STACK_PAGES];
113 static struct pda
114 {
115 int irqcount; /* offset 0 (used in x86_64.S) */
116 char *irqstackptr; /* 8 */
117 } cpu0_pda;
118 #endif
120 /*
121 * Initially all events are without a handler and disabled
122 */
123 void init_events(void)
124 {
125 int i;
126 #if defined(__x86_64__)
127 asm volatile("movl %0,%%fs ; movl %0,%%gs" :: "r" (0));
128 wrmsrl(0xc0000101, &cpu0_pda); /* 0xc0000101 is MSR_GS_BASE */
129 cpu0_pda.irqcount = -1;
130 cpu0_pda.irqstackptr = irqstack + 1024 * 4 * STACK_PAGES;
131 #endif
132 /* inintialise event handler */
133 for ( i = 0; i < NR_EVS; i++ )
134 {
135 ev_actions[i].handler = default_handler;
136 mask_evtchn(i);
137 }
138 }
140 void default_handler(int port, struct pt_regs *regs, void *ignore)
141 {
142 printk("[Port %d] - event received\n", port);
143 }
145 /* Unfortunate confusion of terminology: the port is unbound as far
146 as Xen is concerned, but we automatically bind a handler to it
147 from inside mini-os. */
148 int evtchn_alloc_unbound(void (*handler)(int, struct pt_regs *regs,
149 void *data),
150 void *data)
151 {
152 u32 port;
153 evtchn_op_t op;
154 int err;
156 op.cmd = EVTCHNOP_alloc_unbound;
157 op.u.alloc_unbound.dom = DOMID_SELF;
158 op.u.alloc_unbound.remote_dom = 0;
160 err = HYPERVISOR_event_channel_op(&op);
161 if (err) {
162 printk("Failed to alloc unbound evtchn: %d.\n", err);
163 return -1;
164 }
165 port = op.u.alloc_unbound.port;
166 bind_evtchn(port, handler, data);
167 return port;
168 }