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>
20 #include <xen/xen-os.h>
21 #include <xen/hypervisor.h>
22 #include <xen/xen_intr.h>
25 #include <xen/xen_intr.h>
26 #include <xen/evtchn.h>
27 #include <xen/interface/io/console.h>
29 #include <dev/xen/console/xencons_ring.h>
30 #include <xen/evtchn.h>
31 #include <xen/interface/io/console.h>
33 #define console_evtchn console.domU.evtchn
34 xen_intr_handle_t console_handle;
35 extern struct mtx cn_mtx;
36 extern device_t xencons_dev;
37 extern bool cnsl_evt_reg;
39 static inline struct xencons_interface *
40 xencons_interface(void)
42 return (struct xencons_interface *)console_page;
47 xencons_has_input(void)
49 struct xencons_interface *intf;
51 intf = xencons_interface();
53 return (intf->in_cons != intf->in_prod);
58 xencons_ring_send(const char *data, unsigned len)
60 struct xencons_interface *intf;
61 XENCONS_RING_IDX cons, prod;
63 struct evtchn_send send = {
64 .port = HYPERVISOR_start_info->console_evtchn
67 intf = xencons_interface();
68 cons = intf->out_cons;
69 prod = intf->out_prod;
73 KASSERT((prod - cons) <= sizeof(intf->out),
74 ("console send ring inconsistent"));
76 while ((sent < len) && ((prod - cons) < sizeof(intf->out)))
77 intf->out[MASK_XENCONS_IDX(prod++, intf->out)] = data[sent++];
80 intf->out_prod = prod;
83 xen_intr_signal(console_handle);
85 HYPERVISOR_event_channel_op(EVTCHNOP_send, &send);
92 static xencons_receiver_func *xencons_receiver;
95 xencons_handle_input(void *unused)
97 struct xencons_interface *intf;
98 XENCONS_RING_IDX cons, prod;
101 intf = xencons_interface();
103 cons = intf->in_cons;
104 prod = intf->in_prod;
107 /* XXX needs locking */
108 while (cons != prod) {
109 xencons_rx(intf->in + MASK_XENCONS_IDX(cons, intf->in), 1);
114 intf->in_cons = cons;
117 xen_intr_signal(console_handle);
124 xencons_ring_register_receiver(xencons_receiver_func *f)
126 xencons_receiver = f;
130 xencons_ring_init(void)
134 if (HYPERVISOR_start_info->console_evtchn == 0)
137 err = xen_intr_bind_local_port(xencons_dev,
138 HYPERVISOR_start_info->console_evtchn, NULL, xencons_handle_input, NULL,
139 INTR_TYPE_MISC | INTR_MPSAFE, &console_handle);
147 extern void xencons_suspend(void);
148 extern void xencons_resume(void);
151 xencons_suspend(void)
154 if (HYPERVISOR_start_info->console_evtchn == 0)
157 xen_intr_unbind(&console_handle);
164 (void)xencons_ring_init();
173 * indent-tabs-mode: t