From patchwork Fri Apr 8 14:12:51 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Asias He X-Patchwork-Id: 692561 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p37EELMJ001715 for ; Thu, 7 Apr 2011 14:14:22 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751702Ab1DGOOT (ORCPT ); Thu, 7 Apr 2011 10:14:19 -0400 Received: from mail-iw0-f174.google.com ([209.85.214.174]:39679 "EHLO mail-iw0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751562Ab1DGOOS (ORCPT ); Thu, 7 Apr 2011 10:14:18 -0400 Received: by mail-iw0-f174.google.com with SMTP id 34so2508726iwn.19 for ; Thu, 07 Apr 2011 07:14:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=G4qMQLY2m3pb367O1jhJVwJ/+KbXQbwPwz1gPHd38io=; b=Dij0MADa4Xh2p/siNTblLriwEL81j8PKzS3hZ1W/XvGxB105D3OA4Rf6oGUkpycdQU sjFZN6oY9Bvy56QKoyj2dBErsWN8RUlWXpS5lxnSg9X3KCboiScXlk75tgxmMA6EufBx gDV4RI3KDMnEt5S8YtAB4muTXBLjgTP/9HcUM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=iOSye9UQWAZuXF3FLQk4dZGQc5UzqbM+mcKVla7RxNL6Mdp+ax5cpo1gfiNPMORG+q cT3Jbm2sLeIjDw5BQxQNJQ+IrVa2KoQp+yOM08hpV40o8CgbfKxh39lOROyFZII8eAR7 GbjOsnGs/KMi2aKClAjA/sP0U81dGZvo34feg= Received: by 10.42.157.193 with SMTP id e1mr1544145icx.178.1302185658296; Thu, 07 Apr 2011 07:14:18 -0700 (PDT) Received: from localhost.localdomain ([219.224.169.130]) by mx.google.com with ESMTPS id m10sm2277615wfl.11.2011.04.07.07.14.13 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 07 Apr 2011 07:14:17 -0700 (PDT) From: Asias He To: Pekka Enberg , Cyrill Gorcunov Cc: kvm@vger.kernel.org, Ingo Molnar , Asias He Subject: [PATCH 4/6] kvm tools: make 8250 serial use infrastructure provided by term.c Date: Fri, 8 Apr 2011 22:12:51 +0800 Message-Id: <1302271973-7604-4-git-send-email-asias.hejun@gmail.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1302271973-7604-1-git-send-email-asias.hejun@gmail.com> References: <1302271973-7604-1-git-send-email-asias.hejun@gmail.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Thu, 07 Apr 2011 14:14:22 +0000 (UTC) Signed-off-by: Asias He --- tools/kvm/8250-serial.c | 40 ++++++---------------------------- tools/kvm/include/kvm/8250-serial.h | 2 +- tools/kvm/main.c | 2 +- 3 files changed, 9 insertions(+), 35 deletions(-) diff --git a/tools/kvm/8250-serial.c b/tools/kvm/8250-serial.c index 939e9f5..e92ff89 100644 --- a/tools/kvm/8250-serial.c +++ b/tools/kvm/8250-serial.c @@ -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 -#include -#include 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; diff --git a/tools/kvm/include/kvm/8250-serial.h b/tools/kvm/include/kvm/8250-serial.h index 05ee096..73ed078 100644 --- a/tools/kvm/include/kvm/8250-serial.h +++ b/tools/kvm/include/kvm/8250-serial.h @@ -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 */ diff --git a/tools/kvm/main.c b/tools/kvm/main.c index 46fb9fd..1594535 100644 --- a/tools/kvm/main.c +++ b/tools/kvm/main.c @@ -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: