hw: Add test device for unittests execution
PATCH 1/1 hw: Add test device for unittests execution
Add a test device which supports the kvmctl ioports, so one can run the KVM unittest suite [1].
Usage:
qemu -device testdev
1) Removed port 0xf1, since now kvm-unit-tests use serial
2) Removed exit code port 0xf4, since that can be replaced by
-device isa-debugexit,iobase=0xf4,access-size=2
3) Removed ram size port 0xd1, since guest memory size can be retrieved from firmware, there's a patch for kvm-unit-tests including an API to retrieve that value.
[1] Preliminary versions of this patch were posted to the mailing list about a year ago, I re-read the comments of the thread, and had guidance from Paolo about which ports to remove from the test device.
--- hw/i386/Makefile.objs | 1 + hw/testdev.c | 131 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 132 insertions(+) create mode 100644 hw/testdev.c
hw/i386/Makefile.objs +1 -0
@@ -11,5 +11,6 @@ obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt.o xen_pt_config_init.o xen_pt_msi.o obj-y += kvm/ obj-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.o +obj-y += testdev.o obj-y := $(addprefix ../,$(obj-y))
hw/testdev.c new file +131 -0
131 lines not on this page · raw message
Signature · 1 line
1.7.11.4
Quoted 7 lines · Lucas Meneghel Rodrigues
Add a test device which supports the kvmctl ioports, so one can run the KVM unittest suite [1].
Usage:
qemu -device testdev
Quoted 7 lines
1) Removed port
0xf1, since now kvm-unit-tests use serial2) Removed exit code port
0xf4, since that can be replaced by-device isa-debugexit,iobase=0xf4,access-size=2
I forgot to mention that this would work *if* the isa-debugexit device gets upstream. Paolo pointed this thread:
http://lists.gnu.org/archive/html/qemu-devel/2012-07/msg00818.html
But it appears that no consensus was reached.
Quoted 171 lines
3) Removed ram size port
0xd1, since guest memory size can be retrieved from firmware, there's a patch for kvm-unit-tests including an API to retrieve that value.[1] Preliminary versions of this patch were posted to the mailing list about a year ago, I re-read the comments of the thread, and had guidance from Paolo about which ports to remove from the test device.
CC Paolo Bonzini <[email protected]>Signed-off-by Gerd Hoffmann <[email protected]>Signed-off-by Avi Kivity <[email protected]>Signed-off-by Marcelo Tosatti <[email protected]>Signed-off-by Lucas Meneghel Rodrigues <[email protected]>--- hw/i386/Makefile.objs | 1 + hw/testdev.c | 131 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 132 insertions(+)create mode 100644
hw/testdev.chw/i386/Makefile.objs +1
-0@@ -11,5 +11,6 @@ obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt.o xen_pt_config_init.o xen_pt_msi.o obj-y += kvm/ obj-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.o +obj-y += testdev.o obj-y := $(addprefix ../,$(obj-y))hw/testdev.c new file +131
-0@@ -0,0 +1,131 @@ +#include <sys/mman.h> +#include "hw.h" +#include "qdev.h" +#include "isa.h" + +struct testdev { +ISADevice dev; +MemoryRegion iomem; +CharDriverState *chr; +}; + +#define TYPE_TESTDEV "testdev" +#define TESTDEV (obj) \ + OBJECT_CHECK(struct testdev, (obj), TYPE_TESTDEV) + +static void test_device_irq_line (void *opaque,uint32_t addr,uint32_t data) +{ +struct testdev *dev = opaque; + +qemu_set_irq (isa_get_irq (&dev->dev, addr -0x2000 ), !!data); +} + +static uint32 test_device_ioport_data; + +static void test_device_ioport_write (void *opaque,uint32_t addr,uint32_t data) +{ + test_device_ioport_data = data; +} + +static uint32_t test_device_ioport_read (void *opaque,uint32_t addr) +{ +return test_device_ioport_data; +} + +static void test_device_flush_page (void *opaque,uint32_t addr,uint32_t data) +{ +target_phys_addr_t len =4096 ; +void *a =cpu_physical_memory_map (data & ~0xffful , &len,0 ); + +mprotect (a,4096 ,PROT_NONE ); +mprotect (a,4096 ,PROT_READ |PROT_WRITE ); +cpu_physical_memory_unmap (a, len,0 ,0 ); +} + +static char *iomem_buf; + +static uint32_t test_iomem_readb (void *opaque,target_phys_addr_t addr) +{ +return iomem_buf[addr]; +} + +static uint32_t test_iomem_readw (void *opaque,target_phys_addr_t addr) +{ +return *(uint16_t *)(iomem_buf + addr); +} + +static uint32_t test_iomem_readl (void *opaque,target_phys_addr_t addr) +{ +return *(uint32_t *)(iomem_buf + addr); +} + +static void test_iomem_writeb (void *opaque,target_phys_addr_t addr,uint32_t val) +{ + iomem_buf[addr] = val; +} + +static void test_iomem_writew (void *opaque,target_phys_addr_t addr,uint32_t val) +{ + *(uint16_t *)(iomem_buf + addr) = val; +} + +static void test_iomem_writel (void *opaque,target_phys_addr_t addr,uint32_t val) +{ + *(uint32_t *)(iomem_buf + addr) = val; +} + +static const MemoryRegionOps test_iomem_ops = { + .old_mmio = { + .read = { test_iomem_readb, test_iomem_readw, test_iomem_readl, }, + .write = { test_iomem_writeb, test_iomem_writew, test_iomem_writel, }, + }, + .endianness =DEVICE_LITTLE_ENDIAN , +}; + +static int init_test_device (ISADevice *isa) +{ + struct testdev *dev = DO_UPCAST(struct testdev, dev, isa); + +register_ioport_read (0xe0 ,1 ,1 , test_device_ioport_read, dev); +register_ioport_write (0xe0 ,1 ,1 , test_device_ioport_write, dev); +register_ioport_read (0xe0 ,1 ,2 , test_device_ioport_read, dev); +register_ioport_write (0xe0 ,1 ,2 , test_device_ioport_write, dev); +register_ioport_read (0xe0 ,1 ,4 , test_device_ioport_read, dev); +register_ioport_write (0xe0 ,1 ,4 , test_device_ioport_write, dev); +register_ioport_write (0xe4 ,1 ,4 , test_device_flush_page, dev); +register_ioport_write (0x2000 ,24 ,1 , test_device_irq_line,NULL ); + iomem_buf =g_malloc0 (0x10000 ); +memory_region_init_io (&dev->iomem, &test_iomem_ops, dev, +"testdev" ,0x10000 ); +memory_region_add_subregion (isa_address_space (&dev->dev),0xff000000 , + &dev->iomem); +return 0 ; +} + +static Property testdev_isa_properties[] = { + DEFINE_PROP_CHR("chardev", struct testdev, chr), +DEFINE_PROP_END_OF_LIST (), +}; + +static void testdev_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +ISADeviceClass *k =ISA_DEVICE_CLASS (klass); + + k->init = init_test_device; + dc->props = testdev_isa_properties; +} + +static TypeInfo testdev_info = { + .name ="testdev" , + .parent =TYPE_ISA_DEVICE , + .instance_size =sizeof (struct testdev ), + .class_init = testdev_class_init, +}; + +static void testdev_register_types (void ) +{ +type_register_static (&testdev_info); +} + +type_init (testdev_register_types)
Paolo Bonzini
maintainerIl 04/10/2012 05:49, Lucas Meneghel Rodrigues ha scritto:
Quoted 7 lines
Add a test device which supports the kvmctl ioports, so one can run the KVM unittest suite [1].
Usage:
qemu -device testdev
Quoted 7 lines
1) Removed port
0xf1, since now kvm-unit-tests use serial2) Removed exit code port
0xf4, since that can be replaced by-device isa-debugexit,iobase=0xf4,access-size=2
Can you include this in your series?
Quoted 39 lines
3) Removed ram size port
0xd1, since guest memory size can be retrieved from firmware, there's a patch for kvm-unit-tests including an API to retrieve that value.[1] Preliminary versions of this patch were posted to the mailing list about a year ago, I re-read the comments of the thread, and had guidance from Paolo about which ports to remove from the test device.
CC Paolo Bonzini <[email protected]>Signed-off-by Gerd Hoffmann <[email protected]>Signed-off-by Avi Kivity <[email protected]>Signed-off-by Marcelo Tosatti <[email protected]>Signed-off-by Lucas Meneghel Rodrigues <[email protected]>--- hw/i386/Makefile.objs | 1 + hw/testdev.c | 131 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 132 insertions(+) create mode 100644 hw/testdev.chw/i386/Makefile.objs +1
-0@@ -11,5 +11,6 @@ obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt.o xen_pt_config_init.o xen_pt_msi.o obj-y += kvm/ obj-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.o +obj-y += testdev.o obj-y := $(addprefix ../,$(obj-y))hw/testdev.c new file +0
-0
hw/testdev.c line 9
Quoted 9 lines
hw/testdev.c new file +9
-0@@ -0,0 +1,131 @@ +#include <sys/mman.h> +#include "hw.h" +#include "qdev.h" +#include "isa.h" + +struct testdev { +ISADevice dev; +MemoryRegion iomem; +CharDriverState *chr;
This member is not necessary anymore.
Paolo
Quoted 123 lines
hw/testdev.c new file +122
-0+}; + +#define TYPE_TESTDEV "testdev" +#define TESTDEV (obj) \ + OBJECT_CHECK(struct testdev, (obj), TYPE_TESTDEV) + +static void test_device_irq_line (void *opaque,uint32_t addr,uint32_t data) +{ +struct testdev *dev = opaque; + +qemu_set_irq (isa_get_irq (&dev->dev, addr -0x2000 ), !!data); +} + +static uint32 test_device_ioport_data; + +static void test_device_ioport_write (void *opaque,uint32_t addr,uint32_t data) +{ + test_device_ioport_data = data; +} + +static uint32_t test_device_ioport_read (void *opaque,uint32_t addr) +{ +return test_device_ioport_data; +} + +static void test_device_flush_page (void *opaque,uint32_t addr,uint32_t data) +{ +target_phys_addr_t len =4096 ; +void *a =cpu_physical_memory_map (data & ~0xffful , &len,0 ); + +mprotect (a,4096 ,PROT_NONE ); +mprotect (a,4096 ,PROT_READ |PROT_WRITE ); +cpu_physical_memory_unmap (a, len,0 ,0 ); +} + +static char *iomem_buf; + +static uint32_t test_iomem_readb (void *opaque,target_phys_addr_t addr) +{ +return iomem_buf[addr]; +} + +static uint32_t test_iomem_readw (void *opaque,target_phys_addr_t addr) +{ +return *(uint16_t *)(iomem_buf + addr); +} + +static uint32_t test_iomem_readl (void *opaque,target_phys_addr_t addr) +{ +return *(uint32_t *)(iomem_buf + addr); +} + +static void test_iomem_writeb (void *opaque,target_phys_addr_t addr,uint32_t val) +{ + iomem_buf[addr] = val; +} + +static void test_iomem_writew (void *opaque,target_phys_addr_t addr,uint32_t val) +{ + *(uint16_t *)(iomem_buf + addr) = val; +} + +static void test_iomem_writel (void *opaque,target_phys_addr_t addr,uint32_t val) +{ + *(uint32_t *)(iomem_buf + addr) = val; +} + +static const MemoryRegionOps test_iomem_ops = { + .old_mmio = { + .read = { test_iomem_readb, test_iomem_readw, test_iomem_readl, }, + .write = { test_iomem_writeb, test_iomem_writew, test_iomem_writel, }, + }, + .endianness =DEVICE_LITTLE_ENDIAN , +}; + +static int init_test_device (ISADevice *isa) +{ + struct testdev *dev = DO_UPCAST(struct testdev, dev, isa); + +register_ioport_read (0xe0 ,1 ,1 , test_device_ioport_read, dev); +register_ioport_write (0xe0 ,1 ,1 , test_device_ioport_write, dev); +register_ioport_read (0xe0 ,1 ,2 , test_device_ioport_read, dev); +register_ioport_write (0xe0 ,1 ,2 , test_device_ioport_write, dev); +register_ioport_read (0xe0 ,1 ,4 , test_device_ioport_read, dev); +register_ioport_write (0xe0 ,1 ,4 , test_device_ioport_write, dev); +register_ioport_write (0xe4 ,1 ,4 , test_device_flush_page, dev); +register_ioport_write (0x2000 ,24 ,1 , test_device_irq_line,NULL ); + iomem_buf =g_malloc0 (0x10000 ); +memory_region_init_io (&dev->iomem, &test_iomem_ops, dev, +"testdev" ,0x10000 ); +memory_region_add_subregion (isa_address_space (&dev->dev),0xff000000 , + &dev->iomem); +return 0 ; +} + +static Property testdev_isa_properties[] = { + DEFINE_PROP_CHR("chardev", struct testdev, chr), +DEFINE_PROP_END_OF_LIST (), +}; + +static void testdev_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +ISADeviceClass *k =ISA_DEVICE_CLASS (klass); + + k->init = init_test_device; + dc->props = testdev_isa_properties; +} + +static TypeInfo testdev_info = { + .name ="testdev" , + .parent =TYPE_ISA_DEVICE , + .instance_size =sizeof (struct testdev ), + .class_init = testdev_class_init, +}; + +static void testdev_register_types (void ) +{ +type_register_static (&testdev_info); +} + +type_init (testdev_register_types)
Quoted 20 lines · Lucas Meneghel Rodrigues
Add a test device which supports the kvmctl ioports, so one can run the KVM unittest suite [1].
Usage:
qemu -device testdev
1) Removed port
0xf1, since now kvm-unit-tests use serial2) Removed exit code port
0xf4, since that can be replaced by-device isa-debugexit,iobase=0xf4,access-size=2
3) Removed ram size port
0xd1, since guest memory size can be retrieved from firmware, there's a patch for kvm-unit-tests including an API to retrieve that value.
Quoted 5 lines
[1] Preliminary versions of this patch were posted to the mailing list about a year ago, I re-read the comments of the thread, and had guidance from Paolo about which ports to remove from the test device.
General remark: there's no documentation anywhere in this patch. I don't necessarily mean user-facing docs, but at least a descriptive comment saying what the heck this device is and what it does would be helpful.
Quoted 17 lines
CC Paolo Bonzini <[email protected]>Signed-off-by Gerd Hoffmann <[email protected]>Signed-off-by Avi Kivity <[email protected]>Signed-off-by Marcelo Tosatti <[email protected]>Signed-off-by Lucas Meneghel Rodrigues <[email protected]>--- hw/i386/Makefile.objs | 1 + hw/testdev.c | 131 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 132 insertions(+) create mode 100644 hw/testdev.chw/i386/Makefile.objs +0
-0
hw/i386/Makefile.objs obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o · line 14
Quoted 4 lines
hw/i386/Makefile.objs +1
-0@@ -11,5 +11,6 @@ obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt.o xen_pt_config_init.o xen_pt_msi.o obj-y += kvm/ obj-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.o +obj-y += testdev.o
...the device is useful even in non-KVM configs, then?
hw/testdev.c line 1
Quoted 8 lines
hw/i386/Makefile.objs +0
-0obj-y := $(addprefix ../,$(obj-y))hw/testdev.c new file +1
-0@@ -0,0 +1,131 @@ +#include <sys/mman.h>
This file needs a leading comment with the usual copyright/license/ description of what the file does.
Quoted 109 lines
hw/testdev.c new file +109
-0+#include "hw.h" +#include "qdev.h" +#include "isa.h" + +struct testdev { +ISADevice dev; +MemoryRegion iomem; +CharDriverState *chr; +}; + +#define TYPE_TESTDEV "testdev" +#define TESTDEV (obj) \ + OBJECT_CHECK(struct testdev, (obj), TYPE_TESTDEV) + +static void test_device_irq_line (void *opaque,uint32_t addr,uint32_t data) +{ +struct testdev *dev = opaque; + +qemu_set_irq (isa_get_irq (&dev->dev, addr -0x2000 ), !!data); +} + +static uint32 test_device_ioport_data; + +static void test_device_ioport_write (void *opaque,uint32_t addr,uint32_t data) +{ + test_device_ioport_data = data; +} + +static uint32_t test_device_ioport_read (void *opaque,uint32_t addr) +{ +return test_device_ioport_data; +} + +static void test_device_flush_page (void *opaque,uint32_t addr,uint32_t data) +{ +target_phys_addr_t len =4096 ; +void *a =cpu_physical_memory_map (data & ~0xffful , &len,0 ); + +mprotect (a,4096 ,PROT_NONE ); +mprotect (a,4096 ,PROT_READ |PROT_WRITE ); +cpu_physical_memory_unmap (a, len,0 ,0 ); +} + +static char *iomem_buf; + +static uint32_t test_iomem_readb (void *opaque,target_phys_addr_t addr) +{ +return iomem_buf[addr]; +} + +static uint32_t test_iomem_readw (void *opaque,target_phys_addr_t addr) +{ +return *(uint16_t *)(iomem_buf + addr); +} + +static uint32_t test_iomem_readl (void *opaque,target_phys_addr_t addr) +{ +return *(uint32_t *)(iomem_buf + addr); +} + +static void test_iomem_writeb (void *opaque,target_phys_addr_t addr,uint32_t val) +{ + iomem_buf[addr] = val; +} + +static void test_iomem_writew (void *opaque,target_phys_addr_t addr,uint32_t val) +{ + *(uint16_t *)(iomem_buf + addr) = val; +} + +static void test_iomem_writel (void *opaque,target_phys_addr_t addr,uint32_t val) +{ + *(uint32_t *)(iomem_buf + addr) = val; +} + +static const MemoryRegionOps test_iomem_ops = { + .old_mmio = { + .read = { test_iomem_readb, test_iomem_readw, test_iomem_readl, }, + .write = { test_iomem_writeb, test_iomem_writew, test_iomem_writel, }, + }, + .endianness =DEVICE_LITTLE_ENDIAN , +}; + +static int init_test_device (ISADevice *isa) +{ + struct testdev *dev = DO_UPCAST(struct testdev, dev, isa); + +register_ioport_read (0xe0 ,1 ,1 , test_device_ioport_read, dev); +register_ioport_write (0xe0 ,1 ,1 , test_device_ioport_write, dev); +register_ioport_read (0xe0 ,1 ,2 , test_device_ioport_read, dev); +register_ioport_write (0xe0 ,1 ,2 , test_device_ioport_write, dev); +register_ioport_read (0xe0 ,1 ,4 , test_device_ioport_read, dev); +register_ioport_write (0xe0 ,1 ,4 , test_device_ioport_write, dev); +register_ioport_write (0xe4 ,1 ,4 , test_device_flush_page, dev); +register_ioport_write (0x2000 ,24 ,1 , test_device_irq_line,NULL ); + iomem_buf =g_malloc0 (0x10000 ); +memory_region_init_io (&dev->iomem, &test_iomem_ops, dev, +"testdev" ,0x10000 ); +memory_region_add_subregion (isa_address_space (&dev->dev),0xff000000 , + &dev->iomem); +return 0 ; +} + +static Property testdev_isa_properties[] = { + DEFINE_PROP_CHR("chardev", struct testdev, chr), +DEFINE_PROP_END_OF_LIST (), +}; + +static void testdev_class_init (ObjectClass *klass,void *data)
hw/testdev.c line 120
Quoted 10 lines
hw/testdev.c new file +10
-0+{ +DeviceClass *dc =DEVICE_CLASS (klass); +ISADeviceClass *k =ISA_DEVICE_CLASS (klass); + + k->init = init_test_device; + dc->props = testdev_isa_properties; +} + +static TypeInfo testdev_info = { + .name ="testdev" ,
Overly generic name?
hw/testdev.c line 124
Quoted 4 lines
hw/testdev.c new file +4
-0+ .parent = TYPE_ISA_DEVICE, + .instance_size = sizeof(struct testdev), + .class_init = testdev_class_init, +};
Can this be generalised to not be specifically an ISA device? (that's rather an x86-ism). Would the device be useful for unit tests of other KVM architectures? Or are we providing it purely for a legacy x86 testsuite?
Quoted 11 lines
hw/testdev.c new file +7
-1+ +static void testdev_register_types (void ) +{ +type_register_static (&testdev_info); +} + +type_init (testdev_register_types) --1.7.11.4
thanks
-- PMM
Paolo Bonzini
maintainerIl 04/10/2012 10:02, Peter Maydell ha scritto:
Quoted 191 lines · Lucas Meneghel Rodrigues
Quoted 20 lines
Add a test device which supports the kvmctl ioports, so one can run the KVM unittest suite [1].
Usage:
qemu -device testdev
1) Removed port
0xf1, since now kvm-unit-tests use serial2) Removed exit code port
0xf4, since that can be replaced by-device isa-debugexit,iobase=0xf4,access-size=2
3) Removed ram size port
0xd1, since guest memory size can be retrieved from firmware, there's a patch for kvm-unit-tests including an API to retrieve that value.Quoted 5 lines
[1] Preliminary versions of this patch were posted to the mailing list about a year ago, I re-read the comments of the thread, and had guidance from Paolo about which ports to remove from the test device.
General remark: there's no documentation anywhere in this patch. I don't necessarily mean user-facing docs, but at least a descriptive comment saying what the heck this device is and what it does would be helpful.
Quoted 17 lines
CC Paolo Bonzini <[email protected]>Signed-off-by Gerd Hoffmann <[email protected]>Signed-off-by Avi Kivity <[email protected]>Signed-off-by Marcelo Tosatti <[email protected]>Signed-off-by Lucas Meneghel Rodrigues <[email protected]>--- hw/i386/Makefile.objs | 1 + hw/testdev.c | 131 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 132 insertions(+) create mode 100644 hw/testdev.chw/i386/Makefile.objs +0
-0hw/i386/Makefile.objs obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o · line 14
Quoted 4 lines
hw/i386/Makefile.objs +1
-0@@ -11,5 +11,6 @@ obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt.o xen_pt_config_init.o xen_pt_msi.o obj-y += kvm/ obj-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.o +obj-y += testdev.o...the device is useful even in non-KVM configs, then?
hw/testdev.c line 1
Quoted 8 lines
hw/i386/Makefile.objs +0
-0obj-y := $(addprefix ../,$(obj-y))hw/testdev.c new file +1
-0@@ -0,0 +1,131 @@ +#include <sys/mman.h> This file needs a leading comment with the usual copyright/license/ description of what the file does.
Quoted 109 lines
hw/testdev.c new file +109
-0+#include "hw.h" +#include "qdev.h" +#include "isa.h" + +struct testdev { +ISADevice dev; +MemoryRegion iomem; +CharDriverState *chr; +}; + +#define TYPE_TESTDEV "testdev" +#define TESTDEV (obj) \ + OBJECT_CHECK(struct testdev, (obj), TYPE_TESTDEV) + +static void test_device_irq_line (void *opaque,uint32_t addr,uint32_t data) +{ +struct testdev *dev = opaque; + +qemu_set_irq (isa_get_irq (&dev->dev, addr -0x2000 ), !!data); +} + +static uint32 test_device_ioport_data; + +static void test_device_ioport_write (void *opaque,uint32_t addr,uint32_t data) +{ + test_device_ioport_data = data; +} + +static uint32_t test_device_ioport_read (void *opaque,uint32_t addr) +{ +return test_device_ioport_data; +} + +static void test_device_flush_page (void *opaque,uint32_t addr,uint32_t data) +{ +target_phys_addr_t len =4096 ; +void *a =cpu_physical_memory_map (data & ~0xffful , &len,0 ); + +mprotect (a,4096 ,PROT_NONE ); +mprotect (a,4096 ,PROT_READ |PROT_WRITE ); +cpu_physical_memory_unmap (a, len,0 ,0 ); +} + +static char *iomem_buf; + +static uint32_t test_iomem_readb (void *opaque,target_phys_addr_t addr) +{ +return iomem_buf[addr]; +} + +static uint32_t test_iomem_readw (void *opaque,target_phys_addr_t addr) +{ +return *(uint16_t *)(iomem_buf + addr); +} + +static uint32_t test_iomem_readl (void *opaque,target_phys_addr_t addr) +{ +return *(uint32_t *)(iomem_buf + addr); +} + +static void test_iomem_writeb (void *opaque,target_phys_addr_t addr,uint32_t val) +{ + iomem_buf[addr] = val; +} + +static void test_iomem_writew (void *opaque,target_phys_addr_t addr,uint32_t val) +{ + *(uint16_t *)(iomem_buf + addr) = val; +} + +static void test_iomem_writel (void *opaque,target_phys_addr_t addr,uint32_t val) +{ + *(uint32_t *)(iomem_buf + addr) = val; +} + +static const MemoryRegionOps test_iomem_ops = { + .old_mmio = { + .read = { test_iomem_readb, test_iomem_readw, test_iomem_readl, }, + .write = { test_iomem_writeb, test_iomem_writew, test_iomem_writel, }, + }, + .endianness =DEVICE_LITTLE_ENDIAN , +}; + +static int init_test_device (ISADevice *isa) +{ + struct testdev *dev = DO_UPCAST(struct testdev, dev, isa); + +register_ioport_read (0xe0 ,1 ,1 , test_device_ioport_read, dev); +register_ioport_write (0xe0 ,1 ,1 , test_device_ioport_write, dev); +register_ioport_read (0xe0 ,1 ,2 , test_device_ioport_read, dev); +register_ioport_write (0xe0 ,1 ,2 , test_device_ioport_write, dev); +register_ioport_read (0xe0 ,1 ,4 , test_device_ioport_read, dev); +register_ioport_write (0xe0 ,1 ,4 , test_device_ioport_write, dev); +register_ioport_write (0xe4 ,1 ,4 , test_device_flush_page, dev); +register_ioport_write (0x2000 ,24 ,1 , test_device_irq_line,NULL ); + iomem_buf =g_malloc0 (0x10000 ); +memory_region_init_io (&dev->iomem, &test_iomem_ops, dev, +"testdev" ,0x10000 ); +memory_region_add_subregion (isa_address_space (&dev->dev),0xff000000 , + &dev->iomem); +return 0 ; +} + +static Property testdev_isa_properties[] = { + DEFINE_PROP_CHR("chardev", struct testdev, chr), +DEFINE_PROP_END_OF_LIST (), +}; + +static void testdev_class_init (ObjectClass *klass,void *data)hw/testdev.c line 120
Quoted 10 lines
hw/testdev.c new file +10
-0+{ +DeviceClass *dc =DEVICE_CLASS (klass); +ISADeviceClass *k =ISA_DEVICE_CLASS (klass); + + k->init = init_test_device; + dc->props = testdev_isa_properties; +} + +static TypeInfo testdev_info = { + .name ="testdev" ,Overly generic name?
Quoted 7 lines
hw/testdev.c line 124
Quoted 4 lines
hw/testdev.c new file +4
-0+ .parent = TYPE_ISA_DEVICE, + .instance_size = sizeof(struct testdev), + .class_init = testdev_class_init, +};Can this be generalised to not be specifically an ISA device? (that's rather an x86-ism).
The IRQ parts are specifically ISA.
Quoted 3 lines
Would the device be
useful for unit tests of other KVM architectures? Or are we providing it purely for a legacy x86 testsuite?
It's not a legacy testsuite, but it's mostly x86-specific, testing features that are exclusive to the x86 port (such as emulation, power management, interrupt routing, etc.).
Paolo
Quoted 15 lines
Quoted 11 lines
hw/testdev.c new file +7
-1+ +static void testdev_register_types (void ) +{ +type_register_static (&testdev_info); +} + +type_init (testdev_register_types) --1.7.11.4
thanks
-- PMM