debuggers.hg

view extras/mini-os/console/xencons_ring.c @ 16771:10101bc8181f

minios: use ASSERT for BUG_ON

Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jan 17 14:40:23 2008 +0000 (2008-01-17)
parents f2151423f729
children ea5ee63548e4
line source
1 #include <types.h>
2 #include <wait.h>
3 #include <mm.h>
4 #include <hypervisor.h>
5 #include <events.h>
6 #include <os.h>
7 #include <lib.h>
8 #include <xenbus.h>
9 #include <xen/io/console.h>
12 static inline struct xencons_interface *xencons_interface(void)
13 {
14 return mfn_to_virt(start_info.console.domU.mfn);
15 }
17 static inline void notify_daemon(void)
18 {
19 /* Use evtchn: this is called early, before irq is set up. */
20 notify_remote_via_evtchn(start_info.console.domU.evtchn);
21 }
23 int xencons_ring_send_no_notify(const char *data, unsigned len)
24 {
25 int sent = 0;
26 struct xencons_interface *intf = xencons_interface();
27 XENCONS_RING_IDX cons, prod;
28 cons = intf->out_cons;
29 prod = intf->out_prod;
30 mb();
31 BUG_ON((prod - cons) > sizeof(intf->out));
33 while ((sent < len) && ((prod - cons) < sizeof(intf->out)))
34 intf->out[MASK_XENCONS_IDX(prod++, intf->out)] = data[sent++];
36 wmb();
37 intf->out_prod = prod;
39 return sent;
40 }
42 int xencons_ring_send(const char *data, unsigned len)
43 {
44 int sent;
45 sent = xencons_ring_send_no_notify(data, len);
46 notify_daemon();
48 return sent;
49 }
53 static void handle_input(evtchn_port_t port, struct pt_regs *regs, void *ign)
54 {
55 struct xencons_interface *intf = xencons_interface();
56 XENCONS_RING_IDX cons, prod;
58 cons = intf->in_cons;
59 prod = intf->in_prod;
60 mb();
61 BUG_ON((prod - cons) > sizeof(intf->in));
63 while (cons != prod) {
64 xencons_rx(intf->in+MASK_XENCONS_IDX(cons,intf->in), 1, regs);
65 cons++;
66 }
68 mb();
69 intf->in_cons = cons;
71 notify_daemon();
73 xencons_tx();
74 }
76 int xencons_ring_init(void)
77 {
78 int err;
80 if (!start_info.console.domU.evtchn)
81 return 0;
83 err = bind_evtchn(start_info.console.domU.evtchn, handle_input,
84 NULL);
85 if (err <= 0) {
86 printk("XEN console request chn bind failed %i\n", err);
87 return err;
88 }
90 /* In case we have in-flight data after save/restore... */
91 notify_daemon();
93 return 0;
94 }
96 void xencons_resume(void)
97 {
98 (void)xencons_ring_init();
99 }