From: Sasha Levin Date: Wed, 5 Sep 2012 08:31:42 +0000 (+0200) Subject: kvm tools: move active_console into struct kvm_config X-Git-Tag: next-20120910~8^2~21 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=221b584;p=karo-tx-linux.git kvm tools: move active_console into struct kvm_config This config option was 'extern'ed between different objects. Clean it up and move it into struct kvm_config. Signed-off-by: Sasha Levin Signed-off-by: Pekka Enberg --- diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c index 117a9def6766..2b4315baad92 100644 --- a/tools/kvm/builtin-run.c +++ b/tools/kvm/builtin-run.c @@ -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) diff --git a/tools/kvm/hw/serial.c b/tools/kvm/hw/serial.c index 956307c5d539..63dedd0c7d7a 100644 --- a/tools/kvm/hw/serial.c +++ b/tools/kvm/hw/serial.c @@ -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; diff --git a/tools/kvm/include/kvm/kvm-config.h b/tools/kvm/include/kvm/kvm-config.h index e3edf291ac0f..fd7a5cd8efa3 100644 --- a/tools/kvm/include/kvm/kvm-config.h +++ b/tools/kvm/include/kvm/kvm-config.h @@ -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; diff --git a/tools/kvm/include/kvm/term.h b/tools/kvm/include/kvm/term.h index a6a9822a46b9..33d96ce2af16 100644 --- a/tools/kvm/include/kvm/term.h +++ b/tools/kvm/include/kvm/term.h @@ -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); diff --git a/tools/kvm/powerpc/spapr_hvcons.c b/tools/kvm/powerpc/spapr_hvcons.c index 511dbe159d70..1fe4bdb13566 100644 --- a/tools/kvm/powerpc/spapr_hvcons.c +++ b/tools/kvm/powerpc/spapr_hvcons.c @@ -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. diff --git a/tools/kvm/term.c b/tools/kvm/term.c index cc0c5a588c89..8040f5a47265 100644 --- a/tools/kvm/term.c +++ b/tools/kvm/term.c @@ -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; } diff --git a/tools/kvm/virtio/console.c b/tools/kvm/virtio/console.c index e925a54b92e1..4a9ca9ff174a 100644 --- a/tools/kvm/virtio/console.c +++ b/tools/kvm/virtio/console.c @@ -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); }