direct-io.hg

view linux-2.6-xen-sparse/drivers/xen/console/xencons_ring.c @ 7785:8ee7df2c18d1

Revert accidentally applied changes from changeset
7783:5aad7e145e501fbfb346954950a33b042a963633.

Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Mon Nov 14 11:35:50 2005 +0100 (2005-11-14)
parents 5aad7e145e50
children 20bd6f55b813
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 int xencons_ring_send(const char *data, unsigned len)
34 {
35 int sent = 0;
36 struct xencons_interface *intf = xencons_interface();
37 XENCONS_RING_IDX cons, prod;
39 cons = intf->out_cons;
40 prod = intf->out_prod;
41 mb();
42 BUG_ON((prod - cons) > sizeof(intf->out));
44 while ((sent < len) && ((prod - cons) < sizeof(intf->out)))
45 intf->out[MASK_XENCONS_IDX(prod++, intf->out)] = data[sent++];
47 wmb();
48 intf->out_prod = prod;
50 /* Use evtchn: this is called early, before irq is set up. */
51 notify_remote_via_evtchn(xen_start_info->console_evtchn);
53 return sent;
54 }
56 static irqreturn_t handle_input(int irq, void *unused, struct pt_regs *regs)
57 {
58 struct xencons_interface *intf = xencons_interface();
59 XENCONS_RING_IDX cons, prod;
61 cons = intf->in_cons;
62 prod = intf->in_prod;
63 mb();
64 BUG_ON((prod - cons) > sizeof(intf->in));
66 while (cons != prod) {
67 if (xencons_receiver != NULL)
68 xencons_receiver(
69 intf->in + MASK_XENCONS_IDX(cons++, intf->in),
70 1, regs);
71 }
73 wmb();
74 intf->in_cons = cons;
76 return IRQ_HANDLED;
77 }
79 void xencons_ring_register_receiver(xencons_receiver_func *f)
80 {
81 xencons_receiver = f;
82 }
84 int xencons_ring_init(void)
85 {
86 int err;
88 if (xencons_irq)
89 unbind_from_irqhandler(xencons_irq, NULL);
90 xencons_irq = 0;
92 if (!xen_start_info->console_evtchn)
93 return 0;
95 err = bind_evtchn_to_irqhandler(
96 xen_start_info->console_evtchn,
97 handle_input, 0, "xencons", NULL);
98 if (err <= 0) {
99 xprintk("XEN console request irq failed %i\n", err);
100 return err;
101 }
103 xencons_irq = err;
105 return 0;
106 }
108 void xencons_resume(void)
109 {
110 (void)xencons_ring_init();
111 }
113 /*
114 * Local variables:
115 * c-file-style: "linux"
116 * indent-tabs-mode: t
117 * c-indent-level: 8
118 * c-basic-offset: 8
119 * tab-width: 8
120 * End:
121 */