From: Dulloor Subject: Re: [PATCH] 1 of 5: secondary consoles in minos Date: Fri, 12 Jun 2009 00:55:23 -0400 Message-ID: <940bcfd20906112155v1f86fdcif0d8d7131dde31d0@mail.gmail.com> References: <4A311DC7.6080801@eu.citrix.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1890323051==" Return-path: In-Reply-To: <4A311DC7.6080801@eu.citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Stefano Stabellini Cc: xen-devel List-Id: xen-devel@lists.xenproject.org --===============1890323051== Content-Type: multipart/alternative; boundary=0016364992811f40f8046c1f84d5 --0016364992811f40f8046c1f84d5 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit For completeness, we should be freeing up memory(malloced for dev) in case of an error in xencons_ring_init. There could be other such instances. Also, is it too difficult to create a consfront_dev for the first console and get rid of those !dev checks. -dulloor On Thu, Jun 11, 2009 at 11:07 AM, Stefano Stabellini < stefano.stabellini@eu.citrix.com> wrote: > This patch implements support for more than one serial in MiniOS console > frontend. > The code to setup the first console remains a little bit different from > the rest because of the particular way the first console is provided to > a pv guests. > The new code to handle secondary consoles is much more similar to other > frontends. > > Signed-off-by: Stefano Stabellini > > --- > > diff -r 112680f620bf extras/mini-os/console/console.c > --- a/extras/mini-os/console/console.c Mon Jun 08 18:23:57 2009 +0100 > +++ b/extras/mini-os/console/console.c Thu Jun 11 15:19:43 2009 +0100 > @@ -76,11 +76,11 @@ > #endif > > > -void console_print(char *data, int length) > +void console_print(struct consfront_dev *dev, char *data, int length) > { > char *curr_char, saved_char; > int part_len; > - int (*ring_send_fn)(const char *data, unsigned length); > + int (*ring_send_fn)(struct consfront_dev *dev, const char *data, > unsigned length); > > if(!console_initialised) > ring_send_fn = xencons_ring_send_no_notify; > @@ -94,17 +94,17 @@ > saved_char = *(curr_char+1); > *(curr_char+1) = '\r'; > part_len = curr_char - data + 2; > - ring_send_fn(data, part_len); > + ring_send_fn(dev, data, part_len); > *(curr_char+1) = saved_char; > data = curr_char+1; > length -= part_len - 1; > } > } > > - ring_send_fn(data, length); > + ring_send_fn(dev, data, length); > > if(data[length-1] == '\n') > - ring_send_fn("\r", 1); > + ring_send_fn(dev, "\r", 1); > } > > void print(int direct, const char *fmt, va_list args) > @@ -123,7 +123,7 @@ > #endif > (void)HYPERVISOR_console_io(CONSOLEIO_write, strlen(buf), buf); > > - console_print(buf, strlen(buf)); > + console_print(NULL, buf, strlen(buf)); > } > } > > @@ -151,7 +151,7 @@ > printk("done.\n"); > } > > -void fini_console(void) > +void fini_console(struct consfront_dev *dev) > { > - /* Destruct the console and get the parameters of the restarted one */ > + if (dev) free_consfront(dev); > } > diff -r 112680f620bf extras/mini-os/console/xencons_ring.c > --- a/extras/mini-os/console/xencons_ring.c Mon Jun 08 18:23:57 2009 > +0100 > +++ b/extras/mini-os/console/xencons_ring.c Thu Jun 11 15:19:43 2009 > +0100 > @@ -7,25 +7,38 @@ > #include > #include > #include > +#include > +#include > +#include > +#include > > DECLARE_WAIT_QUEUE_HEAD(console_queue); > + > +static inline void notify_daemon(struct consfront_dev *dev) > +{ > + /* Use evtchn: this is called early, before irq is set up. */ > + if (!dev) > + notify_remote_via_evtchn(start_info.console.domU.evtchn); > + else > + notify_remote_via_evtchn(dev->evtchn); > +} > > static inline struct xencons_interface *xencons_interface(void) > { > return mfn_to_virt(start_info.console.domU.mfn); > -} > - > -static inline void notify_daemon(void) > -{ > - /* Use evtchn: this is called early, before irq is set up. */ > - notify_remote_via_evtchn(start_info.console.domU.evtchn); > -} > - > -int xencons_ring_send_no_notify(const char *data, unsigned len) > +} > + > +int xencons_ring_send_no_notify(struct consfront_dev *dev, const char > *data, unsigned len) > { > int sent = 0; > - struct xencons_interface *intf = xencons_interface(); > + struct xencons_interface *intf; > XENCONS_RING_IDX cons, prod; > + > + if (!dev) > + intf = xencons_interface(); > + else > + intf = dev->ring; > + > cons = intf->out_cons; > prod = intf->out_prod; > mb(); > @@ -40,20 +53,27 @@ > return sent; > } > > -int xencons_ring_send(const char *data, unsigned len) > +int xencons_ring_send(struct consfront_dev *dev, const char *data, > unsigned len) > { > int sent; > - sent = xencons_ring_send_no_notify(data, len); > - notify_daemon(); > > - return sent; > + sent = xencons_ring_send_no_notify(dev, data, len); > + notify_daemon(dev); > + > + return sent; > } > > > > -static void handle_input(evtchn_port_t port, struct pt_regs *regs, void > *ign) > +static void handle_input(evtchn_port_t port, struct pt_regs *regs, void > *data) > { > #ifdef HAVE_LIBC > + struct consfront_dev *dev = (struct consfront_dev *) data; > + int fd = dev ? dev->fd : -1; > + > + if (fd != -1) > + files[fd].read = 1; > + > wake_up(&console_queue); > #else > struct xencons_interface *intf = xencons_interface(); > @@ -72,17 +92,22 @@ > mb(); > intf->in_cons = cons; > > - notify_daemon(); > + notify_daemon(dev); > > xencons_tx(); > #endif > } > > #ifdef HAVE_LIBC > -int xencons_ring_avail(void) > +int xencons_ring_avail(struct consfront_dev *dev) > { > - struct xencons_interface *intf = xencons_interface(); > + struct xencons_interface *intf; > XENCONS_RING_IDX cons, prod; > + > + if (!dev) > + intf = xencons_interface(); > + else > + intf = dev->ring; > > cons = intf->in_cons; > prod = intf->in_prod; > @@ -92,11 +117,16 @@ > return prod - cons; > } > > -int xencons_ring_recv(char *data, unsigned len) > +int xencons_ring_recv(struct consfront_dev *dev, char *data, unsigned len) > { > - struct xencons_interface *intf = xencons_interface(); > + struct xencons_interface *intf; > XENCONS_RING_IDX cons, prod; > unsigned filled = 0; > + > + if (!dev) > + intf = xencons_interface(); > + else > + intf = dev->ring; > > cons = intf->in_cons; > prod = intf->in_prod; > @@ -111,31 +141,188 @@ > mb(); > intf->in_cons = cons + filled; > > - notify_daemon(); > + notify_daemon(dev); > > return filled; > } > #endif > > -int xencons_ring_init(void) > +struct consfront_dev *xencons_ring_init(void) > { > int err; > + struct consfront_dev *dev; > > if (!start_info.console.domU.evtchn) > return 0; > > - err = bind_evtchn(start_info.console.domU.evtchn, handle_input, > - NULL); > + dev = malloc(sizeof(struct consfront_dev)); > + memset(dev, 0, sizeof(struct consfront_dev)); > + dev->nodename = "device/console"; > + dev->dom = 0; > + dev->backend = 0; > + dev->ring_ref = 0; > + > +#ifdef HAVE_LIBC > + dev->fd = -1; > +#endif > + dev->evtchn = start_info.console.domU.evtchn; > + dev->ring = (struct xencons_interface *) > mfn_to_virt(start_info.console.domU.mfn); > + > + err = bind_evtchn(dev->evtchn, handle_input, dev); > if (err <= 0) { > printk("XEN console request chn bind failed %i\n", err); > - return err; > + return NULL; > } > - unmask_evtchn(start_info.console.domU.evtchn); > + unmask_evtchn(dev->evtchn); > > /* In case we have in-flight data after save/restore... */ > - notify_daemon(); > + notify_daemon(dev); > > - return 0; > + return dev; > +} > + > +static void free_consfront(struct consfront_dev *dev) > +{ > + mask_evtchn(dev->evtchn); > + > + free(dev->backend); > + > + gnttab_end_access(dev->ring_ref); > + free_page(dev->ring); > + > + unbind_evtchn(dev->evtchn); > + > + free(dev->nodename); > + free(dev); > +} > + > +struct consfront_dev *init_consfront(char *_nodename) > +{ > + xenbus_transaction_t xbt; > + char* err; > + char* message=NULL; > + int retry=0; > + char* msg; > + char nodename[256]; > + char path[256]; > + static int consfrontends = 1; > + struct consfront_dev *dev; > + int res; > + > + if (!_nodename) > + snprintf(nodename, sizeof(nodename), "device/console/%d", > consfrontends); > + else > + strncpy(nodename, _nodename, sizeof(nodename)); > + > + printk("******************* CONSFRONT for %s **********\n\n\n", > nodename); > + > + dev = malloc(sizeof(*dev)); > + memset(dev, 0, sizeof(*dev)); > + dev->nodename = strdup(nodename); > +#ifdef HAVE_LIBC > + dev->fd = -1; > +#endif > + > + snprintf(path, sizeof(path), "%s/backend-id", nodename); > + if ((res = xenbus_read_integer(path)) < 0) > + return NULL; > + else > + dev->dom = res; > + evtchn_alloc_unbound(dev->dom, handle_input, dev, &dev->evtchn); > + > + dev->ring = (struct xencons_interface *) alloc_page(); > + memset(dev->ring, 0, PAGE_SIZE); > + dev->ring_ref = gnttab_grant_access(dev->dom, virt_to_mfn(dev->ring), > 0); > + > + dev->events = NULL; > + > +again: > + err = xenbus_transaction_start(&xbt); > + if (err) { > + printk("starting transaction\n"); > + } > + > + err = xenbus_printf(xbt, nodename, "ring-ref","%u", > + dev->ring_ref); > + if (err) { > + message = "writing ring-ref"; > + goto abort_transaction; > + } > + err = xenbus_printf(xbt, nodename, > + "port", "%u", dev->evtchn); > + if (err) { > + message = "writing event-channel"; > + goto abort_transaction; > + } > + err = xenbus_printf(xbt, nodename, > + "protocol", "%s", XEN_IO_PROTO_ABI_NATIVE); > + if (err) { > + message = "writing protocol"; > + goto abort_transaction; > + } > + > + err = xenbus_printf(xbt, nodename, "type", "%s", "ioemu"); > + if (err) { > + message = "writing type"; > + goto abort_transaction; > + } > + > + snprintf(path, sizeof(path), "%s/state", nodename); > + err = xenbus_switch_state(xbt, path, XenbusStateConnected); > + if (err) { > + message = "switching state"; > + goto abort_transaction; > + } > + > + > + err = xenbus_transaction_end(xbt, 0, &retry); > + if (retry) { > + goto again; > + printk("completing transaction\n"); > + } > + > + goto done; > + > +abort_transaction: > + xenbus_transaction_end(xbt, 1, &retry); > + goto error; > + > +done: > + > + snprintf(path, sizeof(path), "%s/backend", nodename); > + msg = xenbus_read(XBT_NIL, path, &dev->backend); > + if (msg) { > + printk("Error %s when reading the backend path %s\n", msg, path); > + goto error; > + } > + > + printk("backend at %s\n", dev->backend); > + > + { > + XenbusState state; > + char path[strlen(dev->backend) + 1 + 19 + 1]; > + snprintf(path, sizeof(path), "%s/state", dev->backend); > + > + xenbus_watch_path_token(XBT_NIL, path, path, &dev->events); > + msg = NULL; > + state = xenbus_read_integer(path); > + while (msg == NULL && state < XenbusStateConnected) > + msg = xenbus_wait_for_state_change(path, &state, > &dev->events); > + if (msg != NULL || state != XenbusStateConnected) { > + printk("backend not available, state=%d\n", state); > + xenbus_unwatch_path(XBT_NIL, path); > + goto error; > + } > + } > + unmask_evtchn(dev->evtchn); > + > + printk("**************************\n"); > + > + return dev; > + > +error: > + free_consfront(dev); > + return NULL; > } > > void xencons_resume(void) > diff -r 112680f620bf extras/mini-os/include/console.h > --- a/extras/mini-os/include/console.h Mon Jun 08 18:23:57 2009 +0100 > +++ b/extras/mini-os/include/console.h Thu Jun 11 15:19:43 2009 +0100 > @@ -36,9 +36,32 @@ > #ifndef _LIB_CONSOLE_H_ > #define _LIB_CONSOLE_H_ > > -#include > -#include > -#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +struct consfront_dev { > + domid_t dom; > + > + struct xencons_interface *ring; > + grant_ref_t ring_ref; > + evtchn_port_t evtchn; > + > + char *nodename; > + char *backend; > + > + xenbus_event_queue events; > + > +#ifdef HAVE_LIBC > + int fd; > +#endif > +}; > + > + > > void print(int direct, const char *fmt, va_list args); > void printk(const char *fmt, ...); > @@ -50,16 +73,17 @@ > void xencons_tx(void); > > void init_console(void); > -void console_print(char *data, int length); > -void fini_console(void); > +void console_print(struct consfront_dev *dev, char *data, int length); > +void fini_console(struct consfront_dev *dev); > > /* Low level functions defined in xencons_ring.c */ > extern struct wait_queue_head console_queue; > -int xencons_ring_init(void); > -int xencons_ring_send(const char *data, unsigned len); > -int xencons_ring_send_no_notify(const char *data, unsigned len); > -int xencons_ring_avail(void); > -int xencons_ring_recv(char *data, unsigned len); > +struct consfront_dev *xencons_ring_init(void); > +struct consfront_dev *init_consfront(char *_nodename); > +int xencons_ring_send(struct consfront_dev *dev, const char *data, > unsigned len); > +int xencons_ring_send_no_notify(struct consfront_dev *dev, const char > *data, unsigned len); > +int xencons_ring_avail(struct consfront_dev *dev); > +int xencons_ring_recv(struct consfront_dev *dev, char *data, unsigned > len); > > > #endif /* _LIB_CONSOLE_H_ */ > diff -r 112680f620bf extras/mini-os/include/lib.h > --- a/extras/mini-os/include/lib.h Mon Jun 08 18:23:57 2009 +0100 > +++ b/extras/mini-os/include/lib.h Thu Jun 11 15:19:43 2009 +0100 > @@ -101,6 +101,7 @@ > char *strdup(const char *s); > #endif > #include > +int openpty(void); > > #define RAND_MIX 2654435769U > > @@ -183,6 +184,9 @@ > struct { > struct fbfront_dev *dev; > } fb; > + struct { > + struct consfront_dev *dev; > + } cons; > struct { > /* To each xenbus FD is associated a queue of watch events for > this > * FD. */ > diff -r 112680f620bf extras/mini-os/lib/sys.c > --- a/extras/mini-os/lib/sys.c Mon Jun 08 18:23:57 2009 +0100 > +++ b/extras/mini-os/lib/sys.c Thu Jun 11 15:19:43 2009 +0100 > @@ -167,6 +167,18 @@ > return 0; > } > > +int openpty(void) > +{ > + struct consfront_dev *dev; > + > + dev = init_consfront(NULL); > + dev->fd = alloc_fd(FTYPE_CONSOLE); > + files[dev->fd].cons.dev = dev; > + > + printk("fd(%d) = openpty\n", dev->fd); > + return(dev->fd); > +} > + > int open(const char *pathname, int flags, ...) > { > int fs_fd, fd; > @@ -219,7 +231,7 @@ > DEFINE_WAIT(w); > while(1) { > add_waiter(w, console_queue); > - ret = xencons_ring_recv(buf, nbytes); > + ret = xencons_ring_recv(files[fd].cons.dev, buf, nbytes); > if (ret) > break; > schedule(); > @@ -286,7 +298,7 @@ > { > switch (files[fd].type) { > case FTYPE_CONSOLE: > - console_print((char *)buf, nbytes); > + console_print(files[fd].cons.dev, (char *)buf, nbytes); > return nbytes; > case FTYPE_FILE: { > ssize_t ret; > @@ -414,6 +426,10 @@ > return 0; > case FTYPE_FB: > shutdown_fbfront(files[fd].fb.dev); > + files[fd].type = FTYPE_NONE; > + return 0; > + case FTYPE_CONSOLE: > + fini_console(files[fd].fb.dev); > files[fd].type = FTYPE_NONE; > return 0; > case FTYPE_NONE: > @@ -735,7 +751,7 @@ > break; > case FTYPE_CONSOLE: > if (FD_ISSET(i, readfds)) { > - if (xencons_ring_avail()) > + if (xencons_ring_avail(files[i].cons.dev)) > n++; > else > FD_CLR(i, readfds); > diff -r 112680f620bf stubdom/grub/mini-os.c > --- a/stubdom/grub/mini-os.c Mon Jun 08 18:23:57 2009 +0100 > +++ b/stubdom/grub/mini-os.c Thu Jun 11 15:19:43 2009 +0100 > @@ -329,7 +329,7 @@ > serial_hw_put (int _c) > { > char c = _c; > - console_print(&c, 1); > + console_print(NULL, &c, 1); > } > > int > @@ -337,7 +337,7 @@ > { > char key; > > - if (!xencons_ring_avail()) > + if (!xencons_ring_avail(NULL)) > return -1; > > read(STDIN_FILENO, &key, 1); > > _______________________________________________ > Xen-devel mailing list > Xen-devel@lists.xensource.com > http://lists.xensource.com/xen-devel > --0016364992811f40f8046c1f84d5 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable For completeness, we should be freeing up memory(malloced for dev) in case = of an error in xencons_ring_init. There could be other such instances.
<= br>Also, is it too difficult to create a consfront_dev for the first consol= e and get rid of those !dev checks.

-dulloor

On Thu, Jun 11, 2009 at 11:0= 7 AM, Stefano Stabellini <stefano.stabellini@eu.citrix.com> wro= te:
This patch implem= ents support for more than one serial in MiniOS console
frontend.
The code to setup the first console remains a little bit different from
the rest because of the particular way the first console is provided to
a pv guests.
The new code to handle secondary consoles is much more similar to other
frontends.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>

---

diff -r 112680f620bf extras/mini-os/console/console.c
--- a/extras/mini-os/console/console.c =A0Mon Jun 08 18:23:57 2009 +0100 +++ b/extras/mini-os/console/console.c =A0Thu Jun 11 15:19:43 2009 +0100 @@ -76,11 +76,11 @@
=A0#endif


-void console_print(char *data, int length)
+void console_print(struct consfront_dev *dev, char *data, int length)
=A0{
=A0 =A0 char *curr_char, saved_char;
=A0 =A0 int part_len;
- =A0 =A0int (*ring_send_fn)(const char *data, unsigned length);
+ =A0 =A0int (*ring_send_fn)(struct consfront_dev *dev, const char *data, u= nsigned length);

=A0 =A0 if(!console_initialised)
=A0 =A0 =A0 =A0 ring_send_fn =3D xencons_ring_send_no_notify;
@@ -94,17 +94,17 @@
=A0 =A0 =A0 =A0 =A0 =A0 saved_char =3D *(curr_char+1);
=A0 =A0 =A0 =A0 =A0 =A0 *(curr_char+1) =3D '\r';
=A0 =A0 =A0 =A0 =A0 =A0 part_len =3D curr_char - data + 2;
- =A0 =A0 =A0 =A0 =A0 =A0ring_send_fn(data, part_len);
+ =A0 =A0 =A0 =A0 =A0 =A0ring_send_fn(dev, data, part_len);
=A0 =A0 =A0 =A0 =A0 =A0 *(curr_char+1) =3D saved_char;
=A0 =A0 =A0 =A0 =A0 =A0 data =3D curr_char+1;
=A0 =A0 =A0 =A0 =A0 =A0 length -=3D part_len - 1;
=A0 =A0 =A0 =A0 }
=A0 =A0 }

- =A0 =A0ring_send_fn(data, length);
+ =A0 =A0ring_send_fn(dev, data, length);

=A0 =A0 if(data[length-1] =3D=3D '\n')
- =A0 =A0 =A0 =A0ring_send_fn("\r", 1);
+ =A0 =A0 =A0 =A0ring_send_fn(dev, "\r", 1);
=A0}

=A0void print(int direct, const char *fmt, va_list args)
@@ -123,7 +123,7 @@
=A0#endif
=A0 =A0 =A0 =A0 =A0 =A0 (void)HYPERVISOR_console_io(CONSOLEIO_write, strle= n(buf), buf);

- =A0 =A0 =A0 =A0console_print(buf, strlen(buf));
+ =A0 =A0 =A0 =A0console_print(NULL, buf, strlen(buf));
=A0 =A0 }
=A0}

@@ -151,7 +151,7 @@
=A0 =A0 printk("done.\n");
=A0}

-void fini_console(void)
+void fini_console(struct consfront_dev *dev)
=A0{
- =A0 =A0/* Destruct the console and get the parameters of the restarted on= e */
+ =A0 =A0if (dev) free_consfront(dev);
=A0}
diff -r 112680f620bf extras/mini-os/console/xencons_ring.c
--- a/extras/mini-os/console/xencons_ring.c =A0 =A0 Mon Jun 08 18:23:57 200= 9 +0100
+++ b/extras/mini-os/console/xencons_ring.c =A0 =A0 Thu Jun 11 15:19:43 200= 9 +0100
@@ -7,25 +7,38 @@
=A0#include <lib.h>
=A0#include <xenbus.h>
=A0#include <xen/io/console.h>
+#include <xen/io/protocols.h>
+#include <xen/io/ring.h>
+#include <xmalloc.h>
+#include <gnttab.h>

=A0DECLARE_WAIT_QUEUE_HEAD(console_queue);
+
+static inline void notify_daemon(struct consfront_dev *dev)
+{
+ =A0 =A0/* Use evtchn: this is called early, before irq is set up. */
+ =A0 =A0if (!dev)
+ =A0 =A0 =A0 =A0notify_remote_via_evtchn(start_info.console.domU.evtchn);<= br> + =A0 =A0else
+ =A0 =A0 =A0 =A0notify_remote_via_evtchn(dev->evtchn);
+}

=A0static inline struct xencons_interface *xencons_interface(void)
=A0{
=A0 =A0 return mfn_to_virt(start_info.console.domU.mfn);
-}
-
-static inline void notify_daemon(void)
-{
- =A0 =A0/* Use evtchn: this is called early, before irq is set up. */
- =A0 =A0notify_remote_via_evtchn(start_info.console.domU.evtchn);
-}
-
-int xencons_ring_send_no_notify(const char *data, unsigned len)
+}
+
+int xencons_ring_send_no_notify(struct consfront_dev *dev, const char *dat= a, unsigned len)
=A0{
=A0 =A0 int sent =3D 0;
- =A0 =A0 =A0 struct xencons_interface *intf =3D xencons_interface();
+ =A0 =A0 =A0 struct xencons_interface *intf;
=A0 =A0 =A0 =A0XENCONS_RING_IDX cons, prod;
+
+ =A0 =A0 =A0 if (!dev)
+ =A0 =A0 =A0 =A0 =A0 =A0intf =3D xencons_interface();
+ =A0 =A0 =A0 =A0else
+ =A0 =A0 =A0 =A0 =A0 =A0intf =3D dev->ring;
+
=A0 =A0 =A0 =A0cons =3D intf->out_cons;
=A0 =A0 =A0 =A0prod =3D intf->out_prod;
=A0 =A0 =A0 =A0mb();
@@ -40,20 +53,27 @@
=A0 =A0 return sent;
=A0}

-int xencons_ring_send(const char *data, unsigned len)
+int xencons_ring_send(struct consfront_dev *dev, const char *data, unsigne= d len)
=A0{
=A0 =A0 int sent;
- =A0 =A0sent =3D xencons_ring_send_no_notify(data, len);
- =A0 =A0 =A0 notify_daemon();

- =A0 =A0 =A0 return sent;
+ =A0 =A0sent =3D xencons_ring_send_no_notify(dev, data, len);
+ =A0 =A0notify_daemon(dev);
+
+ =A0 =A0return sent;
=A0}



-static void handle_input(evtchn_port_t port, struct pt_regs *regs, void *i= gn)
+static void handle_input(evtchn_port_t port, struct pt_regs *regs, void *d= ata)
=A0{
=A0#ifdef HAVE_LIBC
+ =A0 =A0 =A0 struct consfront_dev *dev =3D (struct consfront_dev *) data;<= br> + =A0 =A0 =A0 =A0int fd =3D dev ? dev->fd : -1;
+
+ =A0 =A0 =A0 =A0if (fd !=3D -1)
+ =A0 =A0 =A0 =A0 =A0 =A0files[fd].read =3D 1;
+
=A0 =A0 =A0 =A0 wake_up(&console_queue);
=A0#else
=A0 =A0 =A0 =A0struct xencons_interface *intf =3D xencons_interface();
@@ -72,17 +92,22 @@
=A0 =A0 =A0 =A0mb();
=A0 =A0 =A0 =A0intf->in_cons =3D cons;

- =A0 =A0 =A0 notify_daemon();
+ =A0 =A0 =A0 notify_daemon(dev);

=A0 =A0 =A0 =A0xencons_tx();
=A0#endif
=A0}

=A0#ifdef HAVE_LIBC
-int xencons_ring_avail(void)
+int xencons_ring_avail(struct consfront_dev *dev)
=A0{
- =A0 =A0 =A0 struct xencons_interface *intf =3D xencons_interface();
+ =A0 =A0 =A0 struct xencons_interface *intf;
=A0 =A0 =A0 =A0XENCONS_RING_IDX cons, prod;
+
+ =A0 =A0 =A0 =A0if (!dev)
+ =A0 =A0 =A0 =A0 =A0 =A0intf =3D xencons_interface();
+ =A0 =A0 =A0 =A0else
+ =A0 =A0 =A0 =A0 =A0 =A0intf =3D dev->ring;

=A0 =A0 =A0 =A0cons =3D intf->in_cons;
=A0 =A0 =A0 =A0prod =3D intf->in_prod;
@@ -92,11 +117,16 @@
=A0 =A0 =A0 =A0 return prod - cons;
=A0}

-int xencons_ring_recv(char *data, unsigned len)
+int xencons_ring_recv(struct consfront_dev *dev, char *data, unsigned len)=
=A0{
- =A0 =A0 =A0 struct xencons_interface *intf =3D xencons_interface();
+ =A0 =A0 =A0 struct xencons_interface *intf;
=A0 =A0 =A0 =A0XENCONS_RING_IDX cons, prod;
=A0 =A0 =A0 =A0 unsigned filled =3D 0;
+
+ =A0 =A0 =A0 =A0if (!dev)
+ =A0 =A0 =A0 =A0 =A0 =A0intf =3D xencons_interface();
+ =A0 =A0 =A0 =A0else
+ =A0 =A0 =A0 =A0 =A0 =A0intf =3D dev->ring;

=A0 =A0 =A0 =A0cons =3D intf->in_cons;
=A0 =A0 =A0 =A0prod =3D intf->in_prod;
@@ -111,31 +141,188 @@
=A0 =A0 =A0 =A0mb();
=A0 =A0 =A0 =A0 intf->in_cons =3D cons + filled;

- =A0 =A0 =A0 notify_daemon();
+ =A0 =A0 =A0 notify_daemon(dev);

=A0 =A0 =A0 =A0 return filled;
=A0}
=A0#endif

-int xencons_ring_init(void)
+struct consfront_dev *xencons_ring_init(void)
=A0{
=A0 =A0 =A0 =A0int err;
+ =A0 =A0 =A0 struct consfront_dev *dev;

=A0 =A0 =A0 =A0if (!start_info.console.domU.evtchn)
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return 0;

- =A0 =A0 =A0 err =3D bind_evtchn(start_info.console.domU.evtchn, handle_in= put,
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 NULL);
+ =A0 =A0 =A0 dev =3D malloc(sizeof(struct consfront_dev));
+ =A0 =A0 =A0 memset(dev, 0, sizeof(struct consfront_dev));
+ =A0 =A0 =A0 dev->nodename =3D "device/console";
+ =A0 =A0 =A0 dev->dom =3D 0;
+ =A0 =A0 =A0 dev->backend =3D 0;
+ =A0 =A0 =A0 dev->ring_ref =3D 0;
+
+#ifdef HAVE_LIBC
+ =A0 =A0 =A0 dev->fd =3D -1;
+#endif
+ =A0 =A0 =A0 dev->evtchn =3D start_info.console.domU.evtchn;
+ =A0 =A0 =A0 dev->ring =3D (struct xencons_interface *) mfn_to_virt(sta= rt_info.console.domU.mfn);
+
+ =A0 =A0 =A0 err =3D bind_evtchn(dev->evtchn, handle_input, dev);
=A0 =A0 =A0 =A0if (err <=3D 0) {
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0printk("XEN console request chn bind f= ailed %i\n", err);
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 return err;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return NULL;
=A0 =A0 =A0 =A0}
- =A0 =A0 =A0 =A0unmask_evtchn(start_info.console.domU.evtchn);
+ =A0 =A0 =A0 =A0unmask_evtchn(dev->evtchn);

=A0 =A0 =A0 =A0/* In case we have in-flight data after save/restore... */<= br> - =A0 =A0 =A0 notify_daemon();
+ =A0 =A0 =A0 notify_daemon(dev);

- =A0 =A0 =A0 return 0;
+ =A0 =A0 =A0 return dev;
+}
+
+static void free_consfront(struct consfront_dev *dev)
+{
+ =A0 =A0mask_evtchn(dev->evtchn);
+
+ =A0 =A0free(dev->backend);
+
+ =A0 =A0gnttab_end_access(dev->ring_ref);
+ =A0 =A0free_page(dev->ring);
+
+ =A0 =A0unbind_evtchn(dev->evtchn);
+
+ =A0 =A0free(dev->nodename);
+ =A0 =A0free(dev);
+}
+
+struct consfront_dev *init_consfront(char *_nodename)
+{
+ =A0 =A0xenbus_transaction_t xbt;
+ =A0 =A0char* err;
+ =A0 =A0char* message=3DNULL;
+ =A0 =A0int retry=3D0;
+ =A0 =A0char* msg;
+ =A0 =A0char nodename[256];
+ =A0 =A0char path[256];
+ =A0 =A0static int consfrontends =3D 1;
+ =A0 =A0struct consfront_dev *dev;
+ =A0 =A0int res;
+
+ =A0 =A0if (!_nodename)
+ =A0 =A0 =A0 =A0snprintf(nodename, sizeof(nodename), "device/console/= %d", consfrontends);
+ =A0 =A0else
+ =A0 =A0 =A0 =A0strncpy(nodename, _nodename, sizeof(nodename));
+
+ =A0 =A0printk("******************* CONSFRONT for %s **********\n\n\n= ", nodename);
+
+ =A0 =A0dev =3D malloc(sizeof(*dev));
+ =A0 =A0memset(dev, 0, sizeof(*dev));
+ =A0 =A0dev->nodename =3D strdup(nodename);
+#ifdef HAVE_LIBC
+ =A0 =A0dev->fd =3D -1;
+#endif
+
+ =A0 =A0snprintf(path, sizeof(path), "%s/backend-id", nodename);=
+ =A0 =A0if ((res =3D xenbus_read_integer(path)) < 0)
+ =A0 =A0 =A0 =A0return NULL;
+ =A0 =A0else
+ =A0 =A0 =A0 =A0dev->dom =3D res;
+ =A0 =A0evtchn_alloc_unbound(dev->dom, handle_input, dev, &dev->= evtchn);
+
+ =A0 =A0dev->ring =3D (struct xencons_interface *) alloc_page();
+ =A0 =A0memset(dev->ring, 0, PAGE_SIZE);
+ =A0 =A0dev->ring_ref =3D gnttab_grant_access(dev->dom, virt_to_mfn(= dev->ring), 0);
+
+ =A0 =A0dev->events =3D NULL;
+
+again:
+ =A0 =A0err =3D xenbus_transaction_start(&xbt);
+ =A0 =A0if (err) {
+ =A0 =A0 =A0 =A0printk("starting transaction\n");
+ =A0 =A0}
+
+ =A0 =A0err =3D xenbus_printf(xbt, nodename, "ring-ref","%u= ",
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0dev->ring_ref);
+ =A0 =A0if (err) {
+ =A0 =A0 =A0 =A0message =3D "writing ring-ref";
+ =A0 =A0 =A0 =A0goto abort_transaction;
+ =A0 =A0}
+ =A0 =A0err =3D xenbus_printf(xbt, nodename,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"port", "%u", dev->= evtchn);
+ =A0 =A0if (err) {
+ =A0 =A0 =A0 =A0message =3D "writing event-channel";
+ =A0 =A0 =A0 =A0goto abort_transaction;
+ =A0 =A0}
+ =A0 =A0err =3D xenbus_printf(xbt, nodename,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"protocol", "%s", XEN_= IO_PROTO_ABI_NATIVE);
+ =A0 =A0if (err) {
+ =A0 =A0 =A0 =A0message =3D "writing protocol";
+ =A0 =A0 =A0 =A0goto abort_transaction;
+ =A0 =A0}
+
+ =A0 =A0err =3D xenbus_printf(xbt, nodename, "type", "%s&qu= ot;, "ioemu");
+ =A0 =A0if (err) {
+ =A0 =A0 =A0 =A0message =3D "writing type";
+ =A0 =A0 =A0 =A0goto abort_transaction;
+ =A0 =A0}
+
+ =A0 =A0snprintf(path, sizeof(path), "%s/state", nodename);
+ =A0 =A0err =3D xenbus_switch_state(xbt, path, XenbusStateConnected);
+ =A0 =A0if (err) {
+ =A0 =A0 =A0 =A0message =3D "switching state";
+ =A0 =A0 =A0 =A0goto abort_transaction;
+ =A0 =A0}
+
+
+ =A0 =A0err =3D xenbus_transaction_end(xbt, 0, &retry);
+ =A0 =A0if (retry) {
+ =A0 =A0 =A0 =A0 =A0 =A0goto again;
+ =A0 =A0 =A0 =A0printk("completing transaction\n");
+ =A0 =A0}
+
+ =A0 =A0goto done;
+
+abort_transaction:
+ =A0 =A0xenbus_transaction_end(xbt, 1, &retry);
+ =A0 =A0goto error;
+
+done:
+
+ =A0 =A0snprintf(path, sizeof(path), "%s/backend", nodename); + =A0 =A0msg =3D xenbus_read(XBT_NIL, path, &dev->backend);
+ =A0 =A0if (msg) {
+ =A0 =A0 =A0 =A0printk("Error %s when reading the backend path %s\n&q= uot;, msg, path);
+ =A0 =A0 =A0 =A0goto error;
+ =A0 =A0}
+
+ =A0 =A0printk("backend at %s\n", dev->backend);
+
+ =A0 =A0{
+ =A0 =A0 =A0 =A0XenbusState state;
+ =A0 =A0 =A0 =A0char path[strlen(dev->backend) + 1 + 19 + 1];
+ =A0 =A0 =A0 =A0snprintf(path, sizeof(path), "%s/state", dev->= ;backend);
+
+ =A0 =A0 =A0 xenbus_watch_path_token(XBT_NIL, path, path, &dev->eve= nts);
+ =A0 =A0 =A0 =A0msg =3D NULL;
+ =A0 =A0 =A0 =A0state =3D xenbus_read_integer(path);
+ =A0 =A0 =A0 =A0while (msg =3D=3D NULL && state < XenbusStateCo= nnected)
+ =A0 =A0 =A0 =A0 =A0 =A0msg =3D xenbus_wait_for_state_change(path, &st= ate, &dev->events);
+ =A0 =A0 =A0 =A0if (msg !=3D NULL || state !=3D XenbusStateConnected) { + =A0 =A0 =A0 =A0 =A0 =A0printk("backend not available, state=3D%d\n&q= uot;, state);
+ =A0 =A0 =A0 =A0 =A0 =A0xenbus_unwatch_path(XBT_NIL, path);
+ =A0 =A0 =A0 =A0 =A0 =A0goto error;
+ =A0 =A0 =A0 =A0}
+ =A0 =A0}
+ =A0 =A0unmask_evtchn(dev->evtchn);
+
+ =A0 =A0printk("**************************\n");
+
+ =A0 =A0return dev;
+
+error:
+ =A0 =A0free_consfront(dev);
+ =A0 =A0return NULL;
=A0}

=A0void xencons_resume(void)
diff -r 112680f620bf extras/mini-os/include/console.h
--- a/extras/mini-os/include/console.h =A0Mon Jun 08 18:23:57 2009 +0100 +++ b/extras/mini-os/include/console.h =A0Thu Jun 11 15:19:43 2009 +0100 @@ -36,9 +36,32 @@
=A0#ifndef _LIB_CONSOLE_H_
=A0#define _LIB_CONSOLE_H_

-#include<mini-os/os.h>
-#include<mini-os/traps.h>
-#include<stdarg.h>
+#include <mini-os/os.h>
+#include <mini-os/traps.h>
+#include <mini-os/types.h>
+#include <xen/grant_table.h>
+#include <xenbus.h>
+#include <xen/io/console.h>
+#include <stdarg.h>
+
+struct consfront_dev {
+ =A0 =A0domid_t dom;
+
+ =A0 =A0struct xencons_interface *ring;
+ =A0 =A0grant_ref_t ring_ref;
+ =A0 =A0evtchn_port_t evtchn;
+
+ =A0 =A0char *nodename;
+ =A0 =A0char *backend;
+
+ =A0 =A0xenbus_event_queue events;
+
+#ifdef HAVE_LIBC
+ =A0 =A0int fd;
+#endif
+};
+
+

=A0void print(int direct, const char *fmt, va_list args);
=A0void printk(const char *fmt, ...);
@@ -50,16 +73,17 @@
=A0void xencons_tx(void);

=A0void init_console(void);
-void console_print(char *data, int length);
-void fini_console(void);
+void console_print(struct consfront_dev *dev, char *data, int length);
+void fini_console(struct consfront_dev *dev);

=A0/* Low level functions defined in xencons_ring.c */
=A0extern struct wait_queue_head console_queue;
-int xencons_ring_init(void);
-int xencons_ring_send(const char *data, unsigned len);
-int xencons_ring_send_no_notify(const char *data, unsigned len);
-int xencons_ring_avail(void);
-int xencons_ring_recv(char *data, unsigned len);
+struct consfront_dev *xencons_ring_init(void);
+struct consfront_dev *init_consfront(char *_nodename);
+int xencons_ring_send(struct consfront_dev *dev, const char *data, unsigne= d len);
+int xencons_ring_send_no_notify(struct consfront_dev *dev, const char *dat= a, unsigned len);
+int xencons_ring_avail(struct consfront_dev *dev);
+int xencons_ring_recv(struct consfront_dev *dev, char *data, unsigned len)= ;


=A0#endif /* _LIB_CONSOLE_H_ */
diff -r 112680f620bf extras/mini-os/include/lib.h
--- a/extras/mini-os/include/lib.h =A0 =A0 =A0Mon Jun 08 18:23:57 2009 +010= 0
+++ b/extras/mini-os/include/lib.h =A0 =A0 =A0Thu Jun 11 15:19:43 2009 +010= 0
@@ -101,6 +101,7 @@
=A0char =A0*strdup(const char *s);
=A0#endif
=A0#include <mini-os/console.h>
+int openpty(void);

=A0#define RAND_MIX 2654435769U

@@ -183,6 +184,9 @@
=A0 =A0 =A0 =A0struct {
=A0 =A0 =A0 =A0 =A0 =A0struct fbfront_dev *dev;
=A0 =A0 =A0 =A0} fb;
+ =A0 =A0 =A0 struct {
+ =A0 =A0 =A0 =A0 =A0 struct consfront_dev *dev;
+ =A0 =A0 =A0 } cons;
=A0 =A0 =A0 =A0 struct {
=A0 =A0 =A0 =A0 =A0 =A0 /* To each xenbus FD is associated a queue of watc= h events for this
=A0 =A0 =A0 =A0 =A0 =A0 =A0* FD. =A0*/
diff -r 112680f620bf extras/mini-os/lib/sys.c
--- a/extras/mini-os/lib/sys.c =A0Mon Jun 08 18:23:57 2009 +0100
+++ b/extras/mini-os/lib/sys.c =A0Thu Jun 11 15:19:43 2009 +0100
@@ -167,6 +167,18 @@
=A0 =A0 return 0;
=A0}

+int openpty(void)
+{
+ =A0 =A0struct consfront_dev *dev;
+
+ =A0 =A0dev =3D init_consfront(NULL);
+ =A0 =A0dev->fd =3D alloc_fd(FTYPE_CONSOLE);
+ =A0 =A0files[dev->fd].cons.dev =3D dev;
+
+ =A0 =A0printk("fd(%d) =3D openpty\n", dev->fd);
+ =A0 =A0return(dev->fd);
+}
+
=A0int open(const char *pathname, int flags, ...)
=A0{
=A0 =A0 int fs_fd, fd;
@@ -219,7 +231,7 @@
=A0 =A0 =A0 =A0 =A0 =A0 DEFINE_WAIT(w);
=A0 =A0 =A0 =A0 =A0 =A0 while(1) {
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 add_waiter(w, console_queue);
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0ret =3D xencons_ring_recv(buf, nbytes); + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0ret =3D xencons_ring_recv(files[fd].cons.d= ev, buf, nbytes);
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (ret)
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 break;
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 schedule();
@@ -286,7 +298,7 @@
=A0{
=A0 =A0 switch (files[fd].type) {
=A0 =A0 =A0 =A0case FTYPE_CONSOLE:
- =A0 =A0 =A0 =A0 =A0 console_print((char *)buf, nbytes);
+ =A0 =A0 =A0 =A0 =A0 console_print(files[fd].cons.dev, (char *)buf, nbytes= );
=A0 =A0 =A0 =A0 =A0 =A0return nbytes;
=A0 =A0 =A0 =A0case FTYPE_FILE: {
=A0 =A0 =A0 =A0 =A0 =A0ssize_t ret;
@@ -414,6 +426,10 @@
=A0 =A0 =A0 =A0 =A0 =A0 return 0;
=A0 =A0 =A0 =A0case FTYPE_FB:
=A0 =A0 =A0 =A0 =A0 =A0 shutdown_fbfront(files[fd].fb.dev);
+ =A0 =A0 =A0 =A0 =A0 =A0files[fd].type =3D FTYPE_NONE;
+ =A0 =A0 =A0 =A0 =A0 =A0return 0;
+ =A0 =A0 =A0 =A0case FTYPE_CONSOLE:
+ =A0 =A0 =A0 =A0 =A0 =A0fini_console(files[fd].fb.dev);
=A0 =A0 =A0 =A0 =A0 =A0 files[fd].type =3D FTYPE_NONE;
=A0 =A0 =A0 =A0 =A0 =A0 return 0;
=A0 =A0 =A0 =A0case FTYPE_NONE:
@@ -735,7 +751,7 @@
=A0 =A0 =A0 =A0 =A0 =A0break;
=A0 =A0 =A0 =A0case FTYPE_CONSOLE:
=A0 =A0 =A0 =A0 =A0 =A0if (FD_ISSET(i, readfds)) {
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (xencons_ring_avail())
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (xencons_ring_avail(files[i].cons.dev))=
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0n++;
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0else
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0FD_CLR(i, readfds);
diff -r 112680f620bf stubdom/grub/mini-os.c
--- a/stubdom/grub/mini-os.c =A0 =A0Mon Jun 08 18:23:57 2009 +0100
+++ b/stubdom/grub/mini-os.c =A0 =A0Thu Jun 11 15:19:43 2009 +0100
@@ -329,7 +329,7 @@
=A0serial_hw_put (int _c)
=A0{
=A0 char c =3D _c;
- =A0console_print(&c, 1);
+ =A0console_print(NULL, &c, 1);
=A0}

=A0int
@@ -337,7 +337,7 @@
=A0{
=A0 =A0 char key;

- =A0 =A0if (!xencons_ring_avail())
+ =A0 =A0if (!xencons_ring_avail(NULL))
=A0 =A0 =A0 =A0 return -1;

=A0 =A0 read(STDIN_FILENO, &key, 1);

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.= com
http://l= ists.xensource.com/xen-devel

--0016364992811f40f8046c1f84d5-- --===============1890323051== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --===============1890323051==--