direct-io.hg

view linux-2.6-xen-sparse/drivers/xen/console/xencons_ring.c @ 7786:20bd6f55b813

Clean up xenstore/console shared page initialisation, which is
now handled solely by the domain builder.

Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Mon Nov 14 11:36:42 2005 +0100 (2005-11-14)
parents 8ee7df2c18d1
children 0a81c6edf2b1
line source
1 #include <linux/version.h>
2 #include <linux/module.h>
3 #include <linux/errno.h>
4 #include <linux/signal.h>
5 #include <linux/sched.h>
6 #include <linux/interrupt.h>
7 #include <linux/tty.h>
8 #include <linux/tty_flip.h>
9 #include <linux/serial.h>
10 #include <linux/major.h>
11 #include <linux/ptrace.h>
12 #include <linux/ioport.h>
13 #include <linux/mm.h>
14 #include <linux/slab.h>
16 #include <asm/hypervisor.h>
17 #include <asm-xen/evtchn.h>
18 #include <linux/wait.h>
19 #include <linux/interrupt.h>
20 #include <linux/sched.h>
21 #include <linux/err.h>
22 #include "xencons_ring.h"
23 #include <asm-xen/xen-public/io/console.h>
25 static int xencons_irq;
26 static xencons_receiver_func *xencons_receiver;
28 static inline struct xencons_interface *xencons_interface(void)
29 {
30 return mfn_to_virt(xen_start_info->console_mfn);
31 }
33 static inline void notify_daemon(void)
34 {
35 /* Use evtchn: this is called early, before irq is set up. */
36 notify_remote_via_evtchn(xen_start_info->console_evtchn);
37 }
39 int xencons_ring_send(const char *data, unsigned len)
40 {
41 int sent = 0;
42 struct xencons_interface *intf = xencons_interface();
43 XENCONS_RING_IDX cons, prod;
45 cons = intf->out_cons;
46 prod = intf->out_prod;
47 mb();
48 BUG_ON((prod - cons) > sizeof(intf->out));
50 while ((sent < len) && ((prod - cons) < sizeof(intf->out)))
51 intf->out[MASK_XENCONS_IDX(prod++, intf->out)] = data[sent++];
53 wmb();
54 intf->out_prod = prod;
56 notify_daemon();
58 return sent;
59 }
61 static irqreturn_t handle_input(int irq, void *unused, struct pt_regs *regs)
62 {
63 struct xencons_interface *intf = xencons_interface();
64 XENCONS_RING_IDX cons, prod;
66 cons = intf->in_cons;
67 prod = intf->in_prod;
68 mb();
69 BUG_ON((prod - cons) > sizeof(intf->in));
71 while (cons != prod) {
72 if (xencons_receiver != NULL)
73 xencons_receiver(
74 intf->in + MASK_XENCONS_IDX(cons++, intf->in),
75 1, regs);
76 }
78 mb();
79 intf->in_cons = cons;
81 notify_daemon();
83 return IRQ_HANDLED;
84 }
86 void xencons_ring_register_receiver(xencons_receiver_func *f)
87 {
88 xencons_receiver = f;
89 }
91 int xencons_ring_init(void)
92 {
93 int err;
95 if (xencons_irq)
96 unbind_from_irqhandler(xencons_irq, NULL);
97 xencons_irq = 0;
99 if (!xen_start_info->console_evtchn)
100 return 0;
102 err = bind_evtchn_to_irqhandler(
103 xen_start_info->console_evtchn,
104 handle_input, 0, "xencons", NULL);
105 if (err <= 0) {
106 xprintk("XEN console request irq failed %i\n", err);
107 return err;
108 }
110 xencons_irq = err;
112 /* In case we have in-flight data after save/restore... */
113 notify_daemon();
115 return 0;
116 }
118 void xencons_resume(void)
119 {
120 (void)xencons_ring_init();
121 }
123 /*
124 * Local variables:
125 * c-file-style: "linux"
126 * indent-tabs-mode: t
127 * c-indent-level: 8
128 * c-basic-offset: 8
129 * tab-width: 8
130 * End:
131 */