All of lore.kernel.org
 help / color / mirror / Atom feed
From: Samuel Thibault <samuel.thibault@eu.citrix.com>
To: Xen-devel@lists.xensource.com
Subject: [PATCH] stubdom: Add console reading support
Date: Mon, 2 Jun 2008 17:56:41 +0100	[thread overview]
Message-ID: <20080602165641.GF7619@implementation.uk.xensource.com> (raw)

stubdom: Add console reading support

Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>

diff -r fe60bf79d96f extras/mini-os/console/console.c
--- a/extras/mini-os/console/console.c	Mon Jun 02 16:05:07 2008 +0100
+++ b/extras/mini-os/console/console.c	Mon Jun 02 17:30:52 2008 +0100
@@ -49,17 +49,13 @@
    of standard dom0 handled console */
 #define USE_XEN_CONSOLE
 
-/* Low level functions defined in xencons_ring.c */
-extern int xencons_ring_init(void);
-extern int xencons_ring_send(const char *data, unsigned len);
-extern int xencons_ring_send_no_notify(const char *data, unsigned len);
-
 
 /* If console not initialised the printk will be sent to xen serial line 
    NOTE: you need to enable verbose in xen/Rules.mk for it to work. */
 static int console_initialised = 0;
 
 
+#ifndef HAVE_LIBC
 void xencons_rx(char *buf, unsigned len, struct pt_regs *regs)
 {
     if(len > 0)
@@ -77,6 +73,7 @@
 {
     /* Do nothing, handled by _rx */
 }
+#endif
 
 
 void console_print(char *data, int length)
diff -r fe60bf79d96f extras/mini-os/console/xencons_ring.c
--- a/extras/mini-os/console/xencons_ring.c	Mon Jun 02 16:05:07 2008 +0100
+++ b/extras/mini-os/console/xencons_ring.c	Mon Jun 02 17:45:02 2008 +0100
@@ -8,6 +8,7 @@
 #include <xenbus.h>
 #include <xen/io/console.h>
 
+DECLARE_WAIT_QUEUE_HEAD(console_queue);
 
 static inline struct xencons_interface *xencons_interface(void)
 {
@@ -52,6 +53,9 @@
 
 static void handle_input(evtchn_port_t port, struct pt_regs *regs, void *ign)
 {
+#ifdef HAVE_LIBC
+        wake_up(&console_queue);
+#else
 	struct xencons_interface *intf = xencons_interface();
 	XENCONS_RING_IDX cons, prod;
 
@@ -71,7 +75,47 @@
 	notify_daemon();
 
 	xencons_tx();
+#endif
 }
+
+#ifdef HAVE_LIBC
+int xencons_ring_avail(void)
+{
+	struct xencons_interface *intf = xencons_interface();
+	XENCONS_RING_IDX cons, prod;
+
+	cons = intf->in_cons;
+	prod = intf->in_prod;
+	mb();
+	BUG_ON((prod - cons) > sizeof(intf->in));
+
+        return prod - cons;
+}
+
+int xencons_ring_recv(char *data, unsigned len)
+{
+	struct xencons_interface *intf = xencons_interface();
+	XENCONS_RING_IDX cons, prod;
+        unsigned filled = 0;
+
+	cons = intf->in_cons;
+	prod = intf->in_prod;
+	mb();
+	BUG_ON((prod - cons) > sizeof(intf->in));
+
+        while (filled < len && cons + filled != prod) {
+                data[filled] = *(intf->in + MASK_XENCONS_IDX(cons + filled, intf->in));
+                filled++;
+	}
+
+	mb();
+        intf->in_cons = cons + filled;
+
+	notify_daemon();
+
+        return filled;
+}
+#endif
 
 int xencons_ring_init(void)
 {
diff -r fe60bf79d96f extras/mini-os/include/console.h
--- a/extras/mini-os/include/console.h	Mon Jun 02 16:05:07 2008 +0100
+++ b/extras/mini-os/include/console.h	Mon Jun 02 17:45:02 2008 +0100
@@ -51,5 +51,14 @@
 
 void init_console(void);
 void console_print(char *data, int length);
+
+/* 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);
+
 
 #endif /* _LIB_CONSOLE_H_ */
diff -r fe60bf79d96f extras/mini-os/lib/sys.c
--- a/extras/mini-os/lib/sys.c	Mon Jun 02 16:05:07 2008 +0100
+++ b/extras/mini-os/lib/sys.c	Mon Jun 02 17:45:02 2008 +0100
@@ -213,8 +213,19 @@
 int read(int fd, void *buf, size_t nbytes)
 {
     switch (files[fd].type) {
-	case FTYPE_CONSOLE:
-	    return 0;
+	case FTYPE_CONSOLE: {
+	    int ret;
+            DEFINE_WAIT(w);
+            while(1) {
+                add_waiter(w, console_queue);
+                ret = xencons_ring_recv(buf, nbytes);
+                if (ret)
+                    break;
+                schedule();
+            }
+            remove_waiter(w);
+            return ret;
+        }
 	case FTYPE_FILE: {
 	    ssize_t ret;
 	    if (nbytes > PAGE_SIZE)
@@ -707,7 +718,12 @@
 	    FD_CLR(i, exceptfds);
 	    break;
 	case FTYPE_CONSOLE:
-	    FD_CLR(i, readfds);
+	    if (FD_ISSET(i, writefds)) {
+                if (xencons_ring_avail())
+		    n++;
+		else
+		    FD_CLR(i, readfds);
+            }
 	    if (FD_ISSET(i, writefds))
                 n++;
 	    FD_CLR(i, exceptfds);
@@ -809,6 +825,7 @@
     DEFINE_WAIT(w3);
     DEFINE_WAIT(w4);
     DEFINE_WAIT(w5);
+    DEFINE_WAIT(w6);
 
     assert(thread == main_thread);
 
@@ -830,6 +847,7 @@
     add_waiter(w3, blkfront_queue);
     add_waiter(w4, xenbus_watch_queue);
     add_waiter(w5, kbdfront_queue);
+    add_waiter(w6, console_queue);
 
     if (readfds)
         myread = *readfds;
@@ -916,6 +934,7 @@
     remove_waiter(w3);
     remove_waiter(w4);
     remove_waiter(w5);
+    remove_waiter(w6);
     return ret;
 }

                 reply	other threads:[~2008-06-02 16:56 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080602165641.GF7619@implementation.uk.xensource.com \
    --to=samuel.thibault@eu.citrix.com \
    --cc=Xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.