From patchwork Tue Aug 30 23:51:05 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Meneghel Rodrigues X-Patchwork-Id: 1114652 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p7UNpO2A025345 for ; Tue, 30 Aug 2011 23:51:27 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754028Ab1H3XvY (ORCPT ); Tue, 30 Aug 2011 19:51:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35799 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753759Ab1H3XvV (ORCPT ); Tue, 30 Aug 2011 19:51:21 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p7UNpKJQ023262 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 30 Aug 2011 19:51:20 -0400 Received: from freedom.local.com (vpn-8-93.rdu.redhat.com [10.11.8.93]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p7UNpEeD012690; Tue, 30 Aug 2011 19:51:18 -0400 From: Lucas Meneghel Rodrigues To: kvm@vger.kernel.org Cc: avi@redhat.com, Lucas Meneghel Rodrigues , Anthony Liguori Subject: [PATCH 2/2] kvm-unit-tests: make I/O more friendly to existing QEMU hardware Date: Tue, 30 Aug 2011 20:51:05 -0300 Message-Id: <1314748265-15488-3-git-send-email-lmr@redhat.com> In-Reply-To: <1314748265-15488-1-git-send-email-lmr@redhat.com> References: <1314748265-15488-1-git-send-email-lmr@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 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 (demeter2.kernel.org [140.211.167.43]); Tue, 30 Aug 2011 23:51:27 +0000 (UTC) Use the serial port for printf() and use the Bochs bios exit port if the testdev port isn't available. This unconditionally switches to use the serial port but tries to use the testdev exit port since that lets you pass an exit status. This version puts the old behavior on an IFDEF block, as Avi asked on the first review of the patch. Signed-off-by: Anthony Liguori Signed-off-by: Lucas Meneghel Rodrigues --- lib/x86/io.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 59 insertions(+), 1 deletions(-) diff --git a/lib/x86/io.c b/lib/x86/io.c index 894f398..1f550b5 100644 --- a/lib/x86/io.c +++ b/lib/x86/io.c @@ -1,13 +1,58 @@ #include "libcflat.h" #include "smp.h" +#include "io.h" +#ifndef USE_SERIAL +#define USE_SERIAL static struct spinlock lock; +static int serial_iobase = 0x3f8; +static int serial_inited = 0; + +static void serial_outb(char ch) +{ + u8 lsr; + + do { + lsr = inb(serial_iobase + 0x05); + } while (!(lsr & 0x20)); + + outb(ch, serial_iobase + 0x00); +} + +static void serial_init(void) +{ + u8 lcr; + + /* set DLAB */ + lcr = inb(serial_iobase + 0x03); + lcr |= 0x80; + outb(lcr, serial_iobase + 0x03); + + /* set baud rate to 115200 */ + outb(0x01, serial_iobase + 0x00); + outb(0x00, serial_iobase + 0x01); + + /* clear DLAB */ + lcr = inb(serial_iobase + 0x03); + lcr &= ~0x80; + outb(lcr, serial_iobase + 0x03); +} static void print_serial(const char *buf) { unsigned long len = strlen(buf); +#ifdef USE_SERIAL + unsigned long i; + if (!serial_inited) { + serial_init(); + } - asm volatile ("rep/outsb" : "+S"(buf), "+c"(len) : "d"(0xf1)); + for (i = 0; i < len; i++) { + serial_outb(buf[i]); + } +#else + asm volatile ("rep/outsb" : "+S"(buf), "+c"(len) : "d"(0xf1)); +#endif } void puts(const char *s) @@ -19,5 +64,18 @@ void puts(const char *s) void exit(int code) { +#ifdef USE_SERIAL + static const char shutdown_str[8] = "Shutdown"; + int i; + + /* test device exit (with status) */ + outl(code, 0xf4); + + /* if that failed, try the Bochs poweroff port */ + for (i = 0; i < 8; i++) { + outb(shutdown_str[i], 0x8900); + } +#else asm volatile("out %0, %1" : : "a"(code), "d"((short)0xf4)); +#endif }