]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: move active_console into struct kvm_config
authorSasha Levin <levinsasha928@gmail.com>
Wed, 5 Sep 2012 08:31:42 +0000 (10:31 +0200)
committerPekka Enberg <penberg@kernel.org>
Wed, 5 Sep 2012 13:22:36 +0000 (16:22 +0300)
This config option was 'extern'ed between different objects. Clean it up
and move it into struct kvm_config.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/builtin-run.c
tools/kvm/hw/serial.c
tools/kvm/include/kvm/kvm-config.h
tools/kvm/include/kvm/term.h
tools/kvm/powerpc/spapr_hvcons.c
tools/kvm/term.c
tools/kvm/virtio/console.c

index 117a9def6766711f87dbd9119581e928426e4c5a..2b4315baad927e370af31865f9e445c62f5916a1 100644 (file)
@@ -58,7 +58,6 @@ struct kvm_cpu **kvm_cpus;
 __thread struct kvm_cpu *current_kvm_cpu;
 
 static int  kvm_run_wrapper;
-extern int  active_console;
 extern int  debug_iodelay;
 
 bool do_debug_print = false;
@@ -1000,11 +999,11 @@ static int kvm_cmd_run_init(int argc, const char **argv)
                kvm->cfg.console = DEFAULT_CONSOLE;
 
        if (!strncmp(kvm->cfg.console, "virtio", 6))
-               active_console  = CONSOLE_VIRTIO;
+               kvm->cfg.active_console  = CONSOLE_VIRTIO;
        else if (!strncmp(kvm->cfg.console, "serial", 6))
-               active_console  = CONSOLE_8250;
+               kvm->cfg.active_console  = CONSOLE_8250;
        else if (!strncmp(kvm->cfg.console, "hv", 2))
-               active_console = CONSOLE_HV;
+               kvm->cfg.active_console = CONSOLE_HV;
        else
                pr_warning("No console!");
 
@@ -1182,7 +1181,7 @@ static int kvm_cmd_run_init(int argc, const char **argv)
        }
 
 
-       if (active_console == CONSOLE_VIRTIO)
+       if (kvm->cfg.active_console == CONSOLE_VIRTIO)
                virtio_console__init(kvm);
 
        if (kvm->cfg.virtio_rng)
index 956307c5d539a953017a5e7170cfcdc27e99bcc5..63dedd0c7d7aaaf0167781e4b2caa0d7bc8aaee3 100644 (file)
@@ -95,12 +95,13 @@ static struct serial8250_device devices[] = {
        },
 };
 
-static void serial8250_flush_tx(struct serial8250_device *dev)
+static void serial8250_flush_tx(struct kvm *kvm, struct serial8250_device *dev)
 {
        dev->lsr |= UART_LSR_TEMT | UART_LSR_THRE;
 
        if (dev->txcnt) {
-               term_putc(CONSOLE_8250, dev->txbuf, dev->txcnt, dev->id);
+               if (kvm->cfg.active_console == CONSOLE_8250)
+                       term_putc(dev->txbuf, dev->txcnt, dev->id);
                dev->txcnt = 0;
        }
 }
@@ -149,7 +150,7 @@ static void serial8250_update_irq(struct kvm *kvm, struct serial8250_device *dev
         * here.
         */
        if (!(dev->ier & UART_IER_THRI))
-               serial8250_flush_tx(dev);
+               serial8250_flush_tx(kvm, dev);
 }
 
 #define SYSRQ_PENDING_NONE             0
@@ -175,7 +176,7 @@ static void serial8250__receive(struct kvm *kvm, struct serial8250_device *dev,
         * should give the kernel the desired pause. That also flushes
         * the tx fifo to the terminal.
         */
-       serial8250_flush_tx(dev);
+       serial8250_flush_tx(kvm, dev);
 
        if (dev->mcr & UART_MCR_LOOP)
                return;
@@ -188,10 +189,13 @@ static void serial8250__receive(struct kvm *kvm, struct serial8250_device *dev,
                return;
        }
 
-       while (term_readable(CONSOLE_8250, dev->id) &&
+       if (kvm->cfg.active_console != CONSOLE_8250)
+               return;
+
+       while (term_readable(dev->id) &&
               dev->rxcnt < FIFO_LEN) {
 
-               c = term_getc(CONSOLE_8250, dev->id);
+               c = term_getc(dev->id);
 
                if (c < 0)
                        break;
index e3edf291ac0f9e09e67fdfc95ccb675b7d633667..fd7a5cd8efa306d22532e53fe67101318a68126e 100644 (file)
@@ -22,6 +22,7 @@ struct kvm_config {
        u8  image_count;
        u8 num_net_devices;
        bool virtio_rng;
+       int active_console;
        const char *kernel_cmdline;
        const char *kernel_filename;
        const char *vmlinux_filename;
index a6a9822a46b9c7375a7b5f901eb00c4896be3876..33d96ce2af1691cae6b3b7788717989d7e1c16a4 100644 (file)
@@ -8,12 +8,12 @@
 #define CONSOLE_VIRTIO 2
 #define CONSOLE_HV     3
 
-int term_putc_iov(int who, struct iovec *iov, int iovcnt, int term);
-int term_getc_iov(int who, struct iovec *iov, int iovcnt, int term);
-int term_putc(int who, char *addr, int cnt, int term);
-int term_getc(int who, int term);
+int term_putc_iov(struct iovec *iov, int iovcnt, int term);
+int term_getc_iov(struct iovec *iov, int iovcnt, int term);
+int term_putc(char *addr, int cnt, int term);
+int term_getc(int term);
 
-bool term_readable(int who, int term);
+bool term_readable(int term);
 void term_set_tty(int term);
 void term_init(void);
 
index 511dbe159d70130dbf3cfae24d84aa3898cf1dd6..1fe4bdb135669395b99ebcb321ba4139cdf08f66 100644 (file)
@@ -50,7 +50,10 @@ static unsigned long h_put_term_char(struct kvm_cpu *vcpu, unsigned long opcode,
        do {
                int ret;
 
-               ret = term_putc_iov(CONSOLE_HV, &iov, 1, 0);
+               if (kvm->cfg.active_console == CONSOLE_HV)
+                       ret = term_putc_iov(&iov, 1, 0);
+               else
+                       ret = 0;
                if (ret < 0) {
                        die("term_putc_iov error %d!\n", errno);
                }
@@ -71,11 +74,14 @@ static unsigned long h_get_term_char(struct kvm_cpu *vcpu, unsigned long opcode,
        union hv_chario data;
        struct iovec iov;
 
-       if (term_readable(CONSOLE_HV, 0)) {
+       if (kvm->cfg.active_console != CONSOLE_HV)
+               return H_SUCCESS;
+
+       if (term_readable(0)) {
                iov.iov_base = data.buf;
                iov.iov_len = 16;
 
-               *len = term_getc_iov(CONSOLE_HV, &iov, 1, 0);
+               *len = term_getc_iov(&iov, 1, 0);
                *char0_7 = be64_to_cpu(data.a.char0_7);
                *char8_15 = be64_to_cpu(data.a.char8_15);
        } else {
@@ -87,7 +93,7 @@ static unsigned long h_get_term_char(struct kvm_cpu *vcpu, unsigned long opcode,
 
 void spapr_hvcons_poll(struct kvm *kvm)
 {
-       if (term_readable(CONSOLE_HV, 0)) {
+       if (term_readable(0)) {
                /*
                 * We can inject an IRQ to guest here if we want.  The guest
                 * will happily poll, though, so not required.
index cc0c5a588c899deb7d9fa03c2c62381ffcec1e91..8040f5a47265b1af07c97c186759f4b66b63fc2c 100644 (file)
@@ -23,16 +23,12 @@ static struct termios       orig_term;
 int term_escape_char   = 0x01; /* ctrl-a is used for escape */
 bool term_got_escape   = false;
 
-int active_console;
-
 int term_fds[4][2];
 
-int term_getc(int who, int term)
+int term_getc(int term)
 {
        unsigned char c;
 
-       if (who != active_console)
-               return -1;
        if (read_in_full(term_fds[term][TERM_FD_IN], &c, 1) < 0)
                return -1;
 
@@ -52,13 +48,10 @@ int term_getc(int who, int term)
        return c;
 }
 
-int term_putc(int who, char *addr, int cnt, int term)
+int term_putc(char *addr, int cnt, int term)
 {
        int ret;
 
-       if (who != active_console)
-               return -1;
-
        while (cnt--) {
                ret = write(term_fds[term][TERM_FD_OUT], addr++, 1);
                if (ret < 0)
@@ -68,14 +61,11 @@ int term_putc(int who, char *addr, int cnt, int term)
        return cnt;
 }
 
-int term_getc_iov(int who, struct iovec *iov, int iovcnt, int term)
+int term_getc_iov(struct iovec *iov, int iovcnt, int term)
 {
        int c;
 
-       if (who != active_console)
-               return 0;
-
-       c = term_getc(who, term);
+       c = term_getc(term);
 
        if (c < 0)
                return 0;
@@ -85,15 +75,12 @@ int term_getc_iov(int who, struct iovec *iov, int iovcnt, int term)
        return sizeof(char);
 }
 
-int term_putc_iov(int who, struct iovec *iov, int iovcnt, int term)
+int term_putc_iov(struct iovec *iov, int iovcnt, int term)
 {
-       if (who != active_console)
-               return 0;
-
        return writev(term_fds[term][TERM_FD_OUT], iov, iovcnt);
 }
 
-bool term_readable(int who, int term)
+bool term_readable(int term)
 {
        struct pollfd pollfd = (struct pollfd) {
                .fd     = term_fds[term][TERM_FD_IN],
@@ -101,9 +88,6 @@ bool term_readable(int who, int term)
                .revents = 0,
        };
 
-       if (who != active_console)
-               return false;
-
        return poll(&pollfd, 1, 0) > 0;
 }
 
index e925a54b92e1970969ae04d23ed9c913c9a0d5bb..4a9ca9ff174a142c856d5abb0f0a0ca49781d65b 100644 (file)
@@ -62,13 +62,16 @@ static void virtio_console__inject_interrupt_callback(struct kvm *kvm, void *par
        u16 head;
        int len;
 
+       if (kvm->cfg.active_console != CONSOLE_VIRTIO)
+               return;
+
        mutex_lock(&cdev.mutex);
 
        vq = param;
 
-       if (term_readable(CONSOLE_VIRTIO, 0) && virt_queue__available(vq)) {
+       if (term_readable(0) && virt_queue__available(vq)) {
                head = virt_queue__get_iov(vq, iov, &out, &in, kvm);
-               len = term_getc_iov(CONSOLE_VIRTIO, iov, in, 0);
+               len = term_getc_iov(iov, in, 0);
                virt_queue__set_used_elem(vq, head, len);
                cdev.vdev.ops->signal_vq(kvm, &cdev.vdev, vq - cdev.vqs);
        }
@@ -99,7 +102,10 @@ static void virtio_console_handle_callback(struct kvm *kvm, void *param)
 
        while (virt_queue__available(vq)) {
                head = virt_queue__get_iov(vq, iov, &out, &in, kvm);
-               len = term_putc_iov(CONSOLE_VIRTIO, iov, out, 0);
+               if (kvm->cfg.active_console == CONSOLE_VIRTIO)
+                       len = term_putc_iov(iov, out, 0);
+               else
+                       len = 0;
                virt_queue__set_used_elem(vq, head, len);
        }