From patchwork Wed Sep 16 09:25:36 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avi Kivity X-Patchwork-Id: 47866 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n8G9QJfY009548 for ; Wed, 16 Sep 2009 09:26:19 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758231AbZIPJ0K (ORCPT ); Wed, 16 Sep 2009 05:26:10 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1758219AbZIPJ0J (ORCPT ); Wed, 16 Sep 2009 05:26:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50365 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752073AbZIPJ0I (ORCPT ); Wed, 16 Sep 2009 05:26:08 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n8G9QCEg026453 for ; Wed, 16 Sep 2009 05:26:12 -0400 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n8G9QAvd013330; Wed, 16 Sep 2009 05:26:11 -0400 Received: from localhost.localdomain (cleopatra.tlv.redhat.com [10.35.255.11]) by cleopatra.tlv.redhat.com (Postfix) with ESMTP id 7539525004D; Wed, 16 Sep 2009 12:26:10 +0300 (IDT) From: Avi Kivity To: Marcelo Tosatti Cc: kvm@vger.kernel.org Subject: [PATCH QEMU-KVM 01/34] Add test device Date: Wed, 16 Sep 2009 12:25:36 +0300 Message-Id: <1253093169-1423-2-git-send-email-avi@redhat.com> In-Reply-To: <1253093169-1423-1-git-send-email-avi@redhat.com> References: <1253093169-1423-1-git-send-email-avi@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Gerd Hoffmann Add a test device which supports the kvmctl ioports, for running the test suite. Usage: qemu -chardev file,path=/log/file/some/where,id=testlog -device testdev,chardev=testlog Signed-off-by: Gerd Hoffmann Signed-off-by: Avi Kivity --- Makefile.target | 1 + hw/testdev.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 0 deletions(-) create mode 100644 hw/testdev.c diff --git a/Makefile.target b/Makefile.target index c8c9568..a08e432 100644 --- a/Makefile.target +++ b/Makefile.target @@ -216,6 +216,7 @@ obj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o obj-i386-y += extboot.o obj-i386-y += piix4.o obj-i386-y += ne2000-isa.o +obj-i386-y += testdev.o ifeq ($(USE_KVM_PIT), 1) obj-i386-y += i8254-kvm.o endif diff --git a/hw/testdev.c b/hw/testdev.c new file mode 100644 index 0000000..199731e --- /dev/null +++ b/hw/testdev.c @@ -0,0 +1,55 @@ +#include "hw.h" +#include "qdev.h" +#include "isa.h" + +struct testdev { + ISADevice dev; + CharDriverState *chr; +}; + +static void test_device_serial_write(void *opaque, uint32_t addr, uint32_t data) +{ + struct testdev *dev = opaque; + uint8_t buf[1] = { data }; + + if (dev->chr) { + qemu_chr_write(dev->chr, buf, 1); + } +} + +static void test_device_exit(void *opaque, uint32_t addr, uint32_t data) +{ + exit(data); +} + +static uint32_t test_device_memsize_read(void *opaque, uint32_t addr) +{ + return ram_size; +} + +static int init_test_device(ISADevice *isa) +{ + struct testdev *dev = DO_UPCAST(struct testdev, dev, isa); + + register_ioport_write(0xf1, 1, 1, test_device_serial_write, dev); + register_ioport_write(0xf4, 1, 4, test_device_exit, dev); + register_ioport_read(0xd1, 1, 4, test_device_memsize_read, dev); + return 0; +} + +static ISADeviceInfo testdev_info = { + .qdev.name = "testdev", + .qdev.size = sizeof(struct testdev), + .init = init_test_device, + .qdev.props = (Property[]) { + DEFINE_PROP_CHR("chardev", struct testdev, chr), + DEFINE_PROP_END_OF_LIST(), + }, +}; + +static void testdev_register_devices(void) +{ + isa_qdev_register(&testdev_info); +} + +device_init(testdev_register_devices)