5 #include <sys/module.h>
7 #include <sys/consio.h>
11 #include <sys/systm.h>
12 #include <sys/taskqueue.h>
14 #include <sys/kernel.h>
18 #include <machine/stdarg.h>
19 #include <machine/xen/xen-os.h>
20 #include <xen/hypervisor.h>
21 #include <xen/xen_intr.h>
24 #include <xen/xen_intr.h>
25 #include <xen/evtchn.h>
26 #include <xen/interface/io/console.h>
28 #include <dev/xen/console/xencons_ring.h>
29 #include <xen/evtchn.h>
30 #include <xen/interface/io/console.h>
32 #define console_evtchn console.domU.evtchn
33 static unsigned int console_irq;
34 extern char *console_page;
35 extern struct mtx cn_mtx;
37 static inline struct xencons_interface *
38 xencons_interface(void)
40 return (struct xencons_interface *)console_page;
45 xencons_has_input(void)
47 struct xencons_interface *intf;
49 intf = xencons_interface();
51 return (intf->in_cons != intf->in_prod);
56 xencons_ring_send(const char *data, unsigned len)
58 struct xencons_interface *intf;
59 XENCONS_RING_IDX cons, prod;
62 intf = xencons_interface();
63 cons = intf->out_cons;
64 prod = intf->out_prod;
68 KASSERT((prod - cons) <= sizeof(intf->out),
69 ("console send ring inconsistent"));
71 while ((sent < len) && ((prod - cons) < sizeof(intf->out)))
72 intf->out[MASK_XENCONS_IDX(prod++, intf->out)] = data[sent++];
75 intf->out_prod = prod;
77 notify_remote_via_evtchn(xen_start_info->console_evtchn);
84 static xencons_receiver_func *xencons_receiver;
87 xencons_handle_input(void *unused)
89 struct xencons_interface *intf;
90 XENCONS_RING_IDX cons, prod;
93 intf = xencons_interface();
99 /* XXX needs locking */
100 while (cons != prod) {
101 xencons_rx(intf->in + MASK_XENCONS_IDX(cons, intf->in), 1);
106 intf->in_cons = cons;
109 notify_remote_via_evtchn(xen_start_info->console_evtchn);
116 xencons_ring_register_receiver(xencons_receiver_func *f)
118 xencons_receiver = f;
122 xencons_ring_init(void)
126 if (!xen_start_info->console_evtchn)
129 err = bind_caller_port_to_irqhandler(xen_start_info->console_evtchn,
130 "xencons", xencons_handle_input, NULL,
131 INTR_TYPE_MISC | INTR_MPSAFE, &console_irq);
139 extern void xencons_suspend(void);
140 extern void xencons_resume(void);
143 xencons_suspend(void)
146 if (!xen_start_info->console_evtchn)
149 unbind_from_irqhandler(console_irq);
156 (void)xencons_ring_init();
165 * indent-tabs-mode: t