]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: Make 8250 serial use infrastructure provided by term.c
authorAsias He <asias.hejun@gmail.com>
Fri, 8 Apr 2011 14:12:51 +0000 (22:12 +0800)
committerPekka Enberg <penberg@kernel.org>
Fri, 8 Apr 2011 11:53:25 +0000 (14:53 +0300)
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/8250-serial.c
tools/kvm/include/kvm/8250-serial.h
tools/kvm/main.c

index 939e9f53a0ca8c84a50fc8a20947dfdebfba4498..e92ff89ebec5ecbff3d2233faf54acfb5c8c7715 100644 (file)
@@ -3,12 +3,11 @@
 #include "kvm/read-write.h"
 #include "kvm/ioport.h"
 #include "kvm/util.h"
+#include "kvm/term.h"
 #include "kvm/kvm.h"
 
 #include <linux/serial_reg.h>
 
-#include <stdbool.h>
-#include <poll.h>
 
 struct serial8250_device {
        uint16_t                iobase;
@@ -54,26 +53,6 @@ static struct serial8250_device devices[] = {
        },
 };
 
-static int read_char(int fd)
-{
-       char c;
-
-       if (read_in_full(fd, &c, 1) == 0)
-               return -1;
-
-       return c;
-}
-
-static bool is_readable(int fd)
-{
-       struct pollfd pollfd = (struct pollfd) {
-               .fd     = fd,
-               .events = POLLIN,
-       };
-
-       return poll(&pollfd, 1, 0) > 0;
-}
-
 static void serial8250__receive(struct kvm *self, struct serial8250_device *dev)
 {
        int c;
@@ -81,10 +60,11 @@ static void serial8250__receive(struct kvm *self, struct serial8250_device *dev)
        if (dev->lsr & UART_LSR_DR)
                return;
 
-       if (!is_readable(STDIN_FILENO))
+       if (!term_readable(CONSOLE_8250))
                return;
 
-       c               = read_char(STDIN_FILENO);
+       c               = term_getc(CONSOLE_8250);
+
        if (c < 0)
                return;
 
@@ -95,7 +75,7 @@ static void serial8250__receive(struct kvm *self, struct serial8250_device *dev)
 /*
  * Interrupts are injected for ttyS0 only.
  */
-void serial8250__interrupt(struct kvm *self)
+void serial8250__inject_interrupt(struct kvm *self)
 {
        struct serial8250_device *dev = &devices[0];
 
@@ -170,15 +150,9 @@ static bool serial8250_out(struct kvm *self, uint16_t port, void *data, int size
        } else {
                switch (offset) {
                case UART_TX: {
-                       char *p = data;
-                       int i;
-
+                       char *addr = data;
                        if (!(dev->mcr & UART_MCR_LOOP)) {
-                               while (count--) {
-                                       for (i = 0; i < size; i++)
-                                               fprintf(stdout, "%c", *p++);
-                               }
-                               fflush(stdout);
+                               term_putc(CONSOLE_8250, addr, size * count);
                        }
                        dev->iir                = UART_IIR_NO_INT;
                        break;
index 05ee0964d844456d9bd04ce39038c21f1390de26..73ed078547e1c82ea967cbb786fb74d142f93b2b 100644 (file)
@@ -4,6 +4,6 @@
 struct kvm;
 
 void serial8250__init(struct kvm *kvm);
-void serial8250__interrupt(struct kvm *kvm);
+void serial8250__inject_interrupt(struct kvm *kvm);
 
 #endif /* KVM__8250_SERIAL_H */
index 46fb9fd58ac993e14d9199f6638597ee57aafbca..159453504888c1dce593625131b7f5f868fe8964 100644 (file)
@@ -181,7 +181,7 @@ int main(int argc, char *argv[])
                        break;
                }
                case KVM_EXIT_INTR: {
-                       serial8250__interrupt(kvm);
+                       serial8250__inject_interrupt(kvm);
                        break;
                }
                case KVM_EXIT_SHUTDOWN: