kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: Avi Kivity <avi@redhat.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>, kvm@vger.kernel.org
Subject: Re: [PATCH 01/10] Add test device for use with the test suite
Date: Mon, 14 Sep 2009 09:52:42 +0200	[thread overview]
Message-ID: <4AADF64A.3010905@redhat.com> (raw)
In-Reply-To: <1252855135-2519-2-git-send-email-avi@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 575 bytes --]

On 09/13/09 17:18, Avi Kivity wrote:
> The test device implements:
> - a serial port (0xf1)
> - an exit port (0xf4)
> - a memory size port (0xd1)

> +++ b/hw/pc.c

> +    extern int testdevice;
> +
> +    if (testdevice) {
> +        create_test_device(ram_size);
> +    }

> +++ b/qemu-options.hx

> +DEF("test-device", 0, QEMU_OPTION_testdevice,
> +    "-test-device         include testsuite support device")

> +++ b/vl.c

> +            case QEMU_OPTION_testdevice:
> +                testdevice = 1;
> +                break;

This is lame, isn't it?
We have qdev now!

[-- Attachment #2: 0001-add-test-device.patch --]
[-- Type: text/plain, Size: 2768 bytes --]

>From 7c2b03ba5ac73ccf961febb727dc2b28a159c2ed Mon Sep 17 00:00:00 2001
From: Gerd Hoffmann <kraxel@redhat.com>
Date: Mon, 14 Sep 2009 09:35:15 +0200
Subject: [PATCH] add test device

Don't pollute command line option namespace without reason.  Use qdev
instead.  It is such a nice small example device!  Also we have -chardev
upstream now which makes it super easy to redirect the output anywhere
you want.

-chardev file,path=/log/file/some/where,id=testlog
-device testdev,chardev=testlog

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 Makefile.target |    2 +-
 hw/testdev.c    |   55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+), 1 deletions(-)
 create mode 100644 hw/testdev.c

diff --git a/Makefile.target b/Makefile.target
index 0fe8b6a..9867cde 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -189,7 +189,7 @@ obj-i386-y += fdc.o mc146818rtc.o serial.o i8259.o i8254.o pcspk.o pc.o
 obj-i386-y += cirrus_vga.o apic.o ioapic.o parallel.o acpi.o piix_pci.o
 obj-i386-y += usb-uhci.o vmmouse.o vmport.o vmware_vga.o hpet.o
 obj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o
-obj-i386-y += ne2000-isa.o
+obj-i386-y += ne2000-isa.o testdev.o
 
 # shared objects
 obj-ppc-y = ppc.o ide/core.o ide/isa.o ide/pci.o ide/macio.o
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)
-- 
1.6.2.5


  reply	other threads:[~2009-09-14  7:52 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-13 15:18 [PATCH 00/10][QEMU-KVM] Port test suite to multiboot Avi Kivity
2009-09-13 15:18 ` [PATCH 01/10] Add test device for use with the test suite Avi Kivity
2009-09-14  7:52   ` Gerd Hoffmann [this message]
2009-09-14  8:01     ` Avi Kivity
2009-09-14 13:30       ` Avi Kivity
2009-09-14 12:59   ` Anthony Liguori
2009-09-14 13:01     ` Avi Kivity
2009-09-13 15:18 ` [PATCH 02/10] test: load image immediately after program headers Avi Kivity
2009-09-13 15:18 ` [PATCH 03/10] test: Set up a default stack Avi Kivity
2009-09-13 15:18 ` [PATCH 04/10] test: add multiboot headers to startup files Avi Kivity
2009-09-13 15:18 ` [PATCH 05/10] test: Map 4GB of memory Avi Kivity
2009-09-13 15:18 ` [PATCH 06/10] test: use real APIC instead of fake APIC Avi Kivity
2009-09-13 15:18 ` [PATCH 07/10] test: switch output format to elf Avi Kivity
2009-09-13 15:18 ` [PATCH 08/10] test: Remove smp support from access.c Avi Kivity
2009-09-13 15:18 ` [PATCH 09/10] test: fix realmode test print_serial() direction flag Avi Kivity
2009-09-13 15:18 ` [PATCH 10/10] test: port readmode tests to multiboot Avi Kivity

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4AADF64A.3010905@redhat.com \
    --to=kraxel@redhat.com \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).