From patchwork Thu Feb 24 21:48:05 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 588561 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 p1OLm95w025662 for ; Thu, 24 Feb 2011 21:48:10 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754399Ab1BXVsD (ORCPT ); Thu, 24 Feb 2011 16:48:03 -0500 Received: from e6.ny.us.ibm.com ([32.97.182.146]:40657 "EHLO e6.ny.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753461Ab1BXVsA (ORCPT ); Thu, 24 Feb 2011 16:48:00 -0500 Received: from d01relay01.pok.ibm.com (d01relay01.pok.ibm.com [9.56.227.233]) by e6.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id p1OLNhRu023195 for ; Thu, 24 Feb 2011 16:23:43 -0500 Received: from d01av04.pok.ibm.com (d01av04.pok.ibm.com [9.56.224.64]) by d01relay01.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p1OLlxU4392876 for ; Thu, 24 Feb 2011 16:47:59 -0500 Received: from d01av04.pok.ibm.com (loopback [127.0.0.1]) by d01av04.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p1OLlwPG032148 for ; Thu, 24 Feb 2011 16:47:59 -0500 Received: from localhost.localdomain (sig-9-65-47-229.mts.ibm.com [9.65.47.229]) by d01av04.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p1OLlsLP031906; Thu, 24 Feb 2011 16:47:57 -0500 From: Anthony Liguori To: kvm@vger.kernel.org Cc: qemu-devel@nongnu.org, Avi Kivity , Anthony Liguori Subject: [PATCH 3/3] kvm-unit-tests: make I/O more friendly to existing QEMU hardware Date: Thu, 24 Feb 2011 15:48:05 -0600 Message-Id: <1298584085-13129-4-git-send-email-aliguori@us.ibm.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1298584085-13129-1-git-send-email-aliguori@us.ibm.com> References: <1298584085-13129-1-git-send-email-aliguori@us.ibm.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, 24 Feb 2011 21:48:11 +0000 (UTC) diff --git a/lib/x86/io.c b/lib/x86/io.c index 894f398..edc9437 100644 --- a/lib/x86/io.c +++ b/lib/x86/io.c @@ -1,13 +1,53 @@ #include "libcflat.h" #include "smp.h" +#include "io.h" 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); + unsigned long i; - asm volatile ("rep/outsb" : "+S"(buf), "+c"(len) : "d"(0xf1)); + if (!serial_inited) { + serial_init(); + } + + for (i = 0; i < len; i++) { + serial_outb(buf[i]); + } } void puts(const char *s) @@ -19,5 +59,14 @@ void puts(const char *s) void exit(int code) { - asm volatile("out %0, %1" : : "a"(code), "d"((short)0xf4)); + 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); + } }