2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License version 2
4 * as published by the Free Software Foundation; or, when distributed
5 * separately from the Linux kernel or incorporated into other
6 * software packages, subject to the following license:
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this source file (the "Software"), to deal in the Software without
10 * restriction, including without limitation the rights to use, copy, modify,
11 * merge, publish, distribute, sublicense, and/or sell copies of the Software,
12 * and to permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
27 #include <linux/version.h>
28 #include <linux/module.h>
29 #include <linux/errno.h>
30 #include <linux/signal.h>
31 #include <linux/sched.h>
32 #include <linux/interrupt.h>
33 #include <linux/tty.h>
34 #include <linux/tty_flip.h>
35 #include <linux/serial.h>
36 #include <linux/major.h>
37 #include <linux/ptrace.h>
38 #include <linux/ioport.h>
40 #include <linux/slab.h>
42 #include <asm/hypervisor.h>
43 #include <xen/evtchn.h>
44 #include <xen/xencons.h>
45 #include <linux/wait.h>
46 #include <linux/interrupt.h>
47 #include <linux/sched.h>
48 #include <linux/err.h>
49 #include <xen/interface/io/console.h>
51 static int xencons_irq;
53 static inline struct xencons_interface *xencons_interface(void)
55 return mfn_to_virt(xen_start_info->console_mfn);
58 static inline void notify_daemon(void)
60 /* Use evtchn: this is called early, before irq is set up. */
61 notify_remote_via_evtchn(xen_start_info->console_evtchn);
64 int xencons_ring_send(const char *data, unsigned len)
67 struct xencons_interface *intf = xencons_interface();
68 XENCONS_RING_IDX cons, prod;
70 cons = intf->out_cons;
71 prod = intf->out_prod;
73 BUG_ON((prod - cons) > sizeof(intf->out));
75 while ((sent < len) && ((prod - cons) < sizeof(intf->out)))
76 intf->out[MASK_XENCONS_IDX(prod++, intf->out)] = data[sent++];
79 intf->out_prod = prod;
86 static irqreturn_t handle_input(int irq, void *unused, struct pt_regs *regs)
88 struct xencons_interface *intf = xencons_interface();
89 XENCONS_RING_IDX cons, prod;
94 BUG_ON((prod - cons) > sizeof(intf->in));
96 while (cons != prod) {
97 xencons_rx(intf->in+MASK_XENCONS_IDX(cons,intf->in), 1, regs);
102 intf->in_cons = cons;
111 int xencons_ring_init(void)
116 unbind_from_irqhandler(xencons_irq, NULL);
119 if (!xen_start_info->console_evtchn)
122 err = bind_evtchn_to_irqhandler(
123 xen_start_info->console_evtchn,
124 handle_input, 0, "xencons", NULL);
126 printk(KERN_ERR "XEN console request irq failed %i\n", err);
132 /* In case we have in-flight data after save/restore... */
138 void xencons_resume(void)
140 (void)xencons_ring_init();