3 * Access to xen consoles.
7 #include "../port/lib.h"
11 #include "../port/error.h"
14 extern PhysUart xenphysuart;
16 static Uart xenuart = {
23 struct xencons_interface *intf;
29 * Debug print to xen "emergency console".
30 * Output only appears if xen is built with verbose=y
33 dprint(char *fmt, ...)
40 n = vseprint(buf, buf+sizeof(buf), fmt, arg) - buf;
42 HYPERVISOR_console_io(CONSOLEIO_write, n, buf);
45 static void kick(Uart*);
47 * Emit a string to the guest OS console, bypassing the queue
48 * - before serialoq is initialised
49 * - when rdb is activated
50 * - from iprint() for messages from interrupt routines
51 * If ring is full, just throw extra output away.
54 xenuartputs(char *s, int n)
56 struct xencons_interface *con = xencons.intf;
60 ilock(&xencons.txlock);
62 while (n-- > 0 && (prod - con->out_cons) < sizeof(con->out)) {
66 con->out[MASK_XENCONS_IDX(prod++, con->out)] = '\r';
68 con->out[MASK_XENCONS_IDX(prod++, con->out)] = c;
72 xenchannotify(xencons.evtchn);
73 iunlock(&xencons.txlock);
77 * Handle channel event from console
80 interrupt(Ureg*, void *arg)
85 struct xencons_interface *con = xencons.intf;
91 while (cons != con->in_prod) {
92 c = con->in[MASK_XENCONS_IDX(cons++, con->in)];
107 enable(Uart*, int ie)
110 intrenable(xencons.evtchn, interrupt, 0, BUSUNKNOWN, "Xen console");
119 * Send queued output to guest OS console
124 struct xencons_interface *con = xencons.intf;
126 long avail, idx, n, m;
128 ilock(&xencons.txlock);
129 prod = con->out_prod;
130 avail = sizeof(con->out) - (prod - con->out_cons);
132 idx = MASK_XENCONS_IDX(prod, con->out);
133 m = sizeof(con->out) - idx;
136 n = qconsume(serialoq, con->out+idx, m);
143 con->out_prod = prod;
144 xenchannotify(xencons.evtchn);
145 iunlock(&xencons.txlock);
149 donothing(Uart*, int)
154 donothingint(Uart*, int)
160 baud(Uart *uart, int n)
170 bits(Uart *uart, int n)
185 stop(Uart *uart, int n)
194 parity(Uart *uart, int n)
203 status(Uart *uart, void *buf, long n, long offset)
212 "dev(%d) type(%d) framing(%d) overruns(%d) "
213 "berr(%d) serr(%d)\n",
223 n = readstr(offset, buf, n, p);
230 xenputc(Uart*, int c)
232 struct xencons_interface *con = xencons.intf;
235 ilock(&xencons.txlock);
236 prod = con->out_prod;
237 if((prod - con->out_cons) < sizeof(con->out)){
239 con->out[MASK_XENCONS_IDX(prod++, con->out)] = '\r';
240 con->out[MASK_XENCONS_IDX(prod++, con->out)] = c;
244 con->out_prod = prod;
245 xenchannotify(xencons.evtchn);
246 iunlock(&xencons.txlock);
252 struct xencons_interface *con = xencons.intf;
257 if(con->in_cons != con->in_prod){
259 c = con->in[MASK_XENCONS_IDX(con->in_cons++, con->in)];
260 if (con->in_cons == con->in_prod)
261 xenchannotify(xencons.evtchn);
267 PhysUart xenphysuart = {
274 .dobreak = donothing,
279 .modemctl = donothing,
289 /* console=0 to enable */
293 xencons.intf = (struct xencons_interface*)mmumapframe(XENCONSOLE, xenstart->console_mfn);
294 xencons.evtchn = xenstart->console_evtchn;
297 consuart->console = 1;
307 if((p = getconf("console")) == nil)
309 n = strtoul(p, &cmd, 0);
310 if(p == cmd || n != 0)
314 (*uart->phys->enable)(uart, 0);
315 uartctl(uart, "b9600 l8 pn s1");