From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:60331) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TJpVr-0007cQ-1B for qemu-devel@nongnu.org; Thu, 04 Oct 2012 13:47:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TJpVj-0006kj-UP for qemu-devel@nongnu.org; Thu, 04 Oct 2012 13:47:06 -0400 Received: from goliath.siemens.de ([192.35.17.28]:20378) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TJpVj-0006hx-KX for qemu-devel@nongnu.org; Thu, 04 Oct 2012 13:46:59 -0400 Message-ID: <506DCB8F.20402@siemens.com> Date: Thu, 04 Oct 2012 19:46:55 +0200 From: Jan Kiszka MIME-Version: 1.0 References: <1349371885-15091-1-git-send-email-lmr@redhat.com> <1349371885-15091-3-git-send-email-lmr@redhat.com> In-Reply-To: <1349371885-15091-3-git-send-email-lmr@redhat.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 2/2] hw: Add test device for unittests execution v2 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Lucas Meneghel Rodrigues Cc: "pbonzini@redhat.com" , Avi Kivity , Marcelo Tosatti , "qemu-devel@nongnu.org" , Gerd Hoffmann On 2012-10-04 19:31, Lucas Meneghel Rodrigues wrote: > Add a test device which supports the kvmctl ioports, > so one can run the KVM unittest suite. >=20 > Intended Usage: >=20 > qemu-system-x86_64 -device pc-testdev -serial stdio \ > -device isa-debugexit,iobase=3D0xf4,access-size=3D4 \ > -kernel /path/to/kvm/unittests/msr.flat >=20 > Where msr.flat is one of the KVM unittests, present on a > separate repo, >=20 > git://git.kernel.org/pub/scm/virt/kvm/kvm-unit-tests.git >=20 > I still didn't figure out how to port register_ioport_read > to the memory API, but hopefully we'll get there. >=20 > Changes from v2: >=20 > 1) Removed unused testdev member > 2) Renamed device to a less generic name, pc-testdev >=20 > Initial changes from initial attempt: >=20 > 1) Removed port 0xf1, since now kvm-unit-tests use > serial > 2) Removed exit code port 0xf4, since that can be > replaced by >=20 > -device isa-debugexit,iobase=3D0xf4,access-size=3D4 >=20 > 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. >=20 > CC: Paolo Bonzini > Signed-off-by: Gerd Hoffmann > Signed-off-by: Avi Kivity > Signed-off-by: Marcelo Tosatti > Signed-off-by: Lucas Meneghel Rodrigues > --- > hw/i386/Makefile.objs | 1 + > hw/pc-testdev.c | 160 ++++++++++++++++++++++++++++++++++++++++++= ++++++++ > 2 files changed, 161 insertions(+) > create mode 100644 hw/pc-testdev.c >=20 > diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs > index b34c61c..3ef3b4a 100644 > --- a/hw/i386/Makefile.objs > +++ b/hw/i386/Makefile.objs > @@ -11,5 +11,6 @@ obj-$(CONFIG_XEN_PCI_PASSTHROUGH) +=3D xen-host-pci-d= evice.o > obj-$(CONFIG_XEN_PCI_PASSTHROUGH) +=3D xen_pt.o xen_pt_config_init.o x= en_pt_msi.o > obj-y +=3D kvm/ > obj-$(CONFIG_SPICE) +=3D qxl.o qxl-logger.o qxl-render.o > +obj-y +=3D pc-testdev.o > =20 > obj-y :=3D $(addprefix ../,$(obj-y)) > diff --git a/hw/pc-testdev.c b/hw/pc-testdev.c > new file mode 100644 > index 0000000..0234adb > --- /dev/null > +++ b/hw/pc-testdev.c > @@ -0,0 +1,160 @@ > +/* > + * QEMU x86 ISA testdev > + * > + * Copyright (c) 2012 Avi Kivity, Gerd Hoffmann, Marcelo Tosatti > + * > + * Permission is hereby granted, free of charge, to any person obtaini= ng a copy > + * of this software and associated documentation files (the "Software"= ), to deal > + * in the Software without restriction, including without limitation t= he rights > + * to use, copy, modify, merge, publish, distribute, sublicense, and/o= r sell > + * copies of the Software, and to permit persons to whom the Software = is > + * furnished to do so, subject to the following conditions: > + * > + * The above copyright notice and this permission notice shall be incl= uded in > + * all copies or substantial portions of the Software. > + * > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXP= RESS OR > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABI= LITY, > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT S= HALL > + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES O= R OTHER > + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARI= SING FROM, > + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALI= NGS IN > + * THE SOFTWARE. > + */ > + > +/* > + * This device is used to test KVM features specific to the x86 port, = such > + * as emulation, power management, interrupt routing, among others. It= 's meant > + * to be used like: > + * > + * qemu-system-x86_64 -device pc-testdev -serial stdio \ > + * -device isa-debugexit,iobase=3D0xf4,access-size=3D2 \ > + * -kernel /home/lmr/Code/virt-test.git/kvm/unittests/msr.flat > + * > + * Where msr.flat is one of the KVM unittests, present on a separate r= epo, > + * git://git.kernel.org/pub/scm/virt/kvm/kvm-unit-tests.git > +*/ > + > +#include > +#include "hw.h" > +#include "qdev.h" > +#include "isa.h" > + > +struct testdev { typedef struct PCTestdev { ... } PCTestdev; > + ISADevice dev; > + MemoryRegion iomem; > +}; > + > +#define TYPE_TESTDEV "pc-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 =3D opaque; > + > + qemu_set_irq(isa_get_irq(&dev->dev, addr - 0x2000), !!data); > +} > + > +static uint32 test_device_ioport_data; Embed into PCTestdev. > + > +static void test_device_ioport_write(void *opaque, uint32_t addr, uint= 32_t data) > +{ > + test_device_ioport_data =3D 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 =3D 4096; > + void *a =3D 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; Also this. > + > +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, u= int32_t val) > +{ > + iomem_buf[addr] =3D val; > +} > + > +static void test_iomem_writew(void *opaque, target_phys_addr_t addr, u= int32_t val) > +{ > + *(uint16_t*)(iomem_buf + addr) =3D val; > +} > + > +static void test_iomem_writel(void *opaque, target_phys_addr_t addr, u= int32_t val) > +{ > + *(uint32_t*)(iomem_buf + addr) =3D val; > +} > + > +static const MemoryRegionOps test_iomem_ops =3D { > + .old_mmio =3D { > + .read =3D { test_iomem_readb, test_iomem_readw, test_iomem_rea= dl, }, > + .write =3D { test_iomem_writeb, test_iomem_writew, test_iomem_= writel, }, > + }, > + .endianness =3D DEVICE_LITTLE_ENDIAN, > +}; > + > +static int init_test_device(ISADevice *isa) > +{ > + struct testdev *dev =3D 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 =3D g_malloc0(0x10000); > + memory_region_init_io(&dev->iomem, &test_iomem_ops, dev, > + "pc-testdev", 0x10000); > + memory_region_add_subregion(isa_address_space(&dev->dev), 0xff0000= 00, > + &dev->iomem); > + return 0; > +} > + > +static void testdev_class_init(ObjectClass *klass, void *data) > +{ > + ISADeviceClass *k =3D ISA_DEVICE_CLASS(klass); > + > + k->init =3D init_test_device; > +} > + > +static TypeInfo testdev_info =3D { > + .name =3D "pc-testdev", > + .parent =3D TYPE_ISA_DEVICE, > + .instance_size =3D sizeof(struct testdev), > + .class_init =3D testdev_class_init, > +}; > + > +static void testdev_register_types(void) > +{ > + type_register_static(&testdev_info); > +} > + > +type_init(testdev_register_types) >=20 For the ioport conversion I already sent you a link. Should be straightforward, but also needs to be applied on Herv=E9's patch. What about making the port addresses configurable at this chance, just like we do in debugcon? I think the rest is fine. Jan --=20 Siemens AG, Corporate Technology, CT RTC ITP SDP-DE Corporate Competence Center Embedded Linux