ia64/xen-unstable

view extras/mini-os/console/xencons_ring.c @ 15281:736e7cf0a3a5

Fix pv-on-hvm mkbuildtree script for new repo layout.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Wed Jun 06 17:32:58 2007 +0100 (2007-06-06)
parents f2151423f729
children 10101bc8181f
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 /* TODO - need to define BUG_ON for whole mini-os, need crash-dump as well */
13 #define BUG_ON(_cond) do{if(_cond) do_exit();} while(0);
15 static inline struct xencons_interface *xencons_interface(void)
16 {
17 return mfn_to_virt(start_info.console.domU.mfn);
18 }
20 static inline void notify_daemon(void)
21 {
22 /* Use evtchn: this is called early, before irq is set up. */
23 notify_remote_via_evtchn(start_info.console.domU.evtchn);
24 }
26 int xencons_ring_send_no_notify(const char *data, unsigned len)
27 {
28 int sent = 0;
29 struct xencons_interface *intf = xencons_interface();
30 XENCONS_RING_IDX cons, prod;
31 cons = intf->out_cons;
32 prod = intf->out_prod;
33 mb();
34 BUG_ON((prod - cons) > sizeof(intf->out));
36 while ((sent < len) && ((prod - cons) < sizeof(intf->out)))
37 intf->out[MASK_XENCONS_IDX(prod++, intf->out)] = data[sent++];
39 wmb();
40 intf->out_prod = prod;
42 return sent;
43 }
45 int xencons_ring_send(const char *data, unsigned len)
46 {
47 int sent;
48 sent = xencons_ring_send_no_notify(data, len);
49 notify_daemon();
51 return sent;
52 }
56 static void handle_input(evtchn_port_t port, struct pt_regs *regs, void *ign)
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 xencons_rx(intf->in+MASK_XENCONS_IDX(cons,intf->in), 1, regs);
68 cons++;
69 }
71 mb();
72 intf->in_cons = cons;
74 notify_daemon();
76 xencons_tx();
77 }
79 int xencons_ring_init(void)
80 {
81 int err;
83 if (!start_info.console.domU.evtchn)
84 return 0;
86 err = bind_evtchn(start_info.console.domU.evtchn, handle_input,
87 NULL);
88 if (err <= 0) {
89 printk("XEN console request chn bind failed %i\n", err);
90 return err;
91 }
93 /* In case we have in-flight data after save/restore... */
94 notify_daemon();
96 return 0;
97 }
99 void xencons_resume(void)
100 {
101 (void)xencons_ring_init();
102 }