WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH] stubdom: Add console reading support

To: Xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH] stubdom: Add console reading support
From: Samuel Thibault <samuel.thibault@xxxxxxxxxxxxx>
Date: Mon, 2 Jun 2008 17:56:41 +0100
Delivery-date: Mon, 02 Jun 2008 09:57:02 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Mail-followup-to: Samuel Thibault <samuel.thibault@xxxxxxxxxxxxx>, Xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mutt/1.5.12-2006-07-14
stubdom: Add console reading support

Signed-off-by: Samuel Thibault <samuel.thibault@xxxxxxxxxxxxx>

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;
 }
 

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] [PATCH] stubdom: Add console reading support, Samuel Thibault <=