All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Andreas Färber" <afaerber@suse.de>
To: Gerd Hoffmann <kraxel@redhat.com>,
	Lucas Meneghel Rodrigues <lmr@redhat.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>,
	qemu-devel@nongnu.org, Alexander Graf <agraf@suse.de>,
	Blue Swirl <blauwirbel@gmail.com>,
	Anthony Liguori <anthony@codemonkey.ws>,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 3/4] hw: Add test device for unittests execution
Date: Sun, 06 Jan 2013 19:19:00 +0100	[thread overview]
Message-ID: <50E9C014.2060508@suse.de> (raw)
In-Reply-To: <1357287364-24921-4-git-send-email-kraxel@redhat.com>

Am 04.01.2013 09:16, schrieb Gerd Hoffmann:
> From: Lucas Meneghel Rodrigues <lmr@redhat.com>
> 
> Add a test device which supports the kvmctl ioports,
> so one can run the KVM unittest suite.
> 
> Intended Usage:
> 
> qemu-system-x86_64 -nographic \
>     -device pc-testdev \
>     -device isa-debug-exit,iobase=0xf4,iosize=0x04 \
>     -kernel /path/to/kvm/unittests/msr.flat
> 
> Where msr.flat is one of the KVM unittests, present on a
> separate repo,
> 
> git://git.kernel.org/pub/scm/virt/kvm/kvm-unit-tests.git
> 
> [ kraxel: more memory api + qom fixes ]
> 
> CC: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Alexander Graf <agraf@suse.de>
> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
> Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
[...]
> diff --git a/hw/pc-testdev.c b/hw/pc-testdev.c
> new file mode 100644
> index 0000000..620c86c
> --- /dev/null
> +++ b/hw/pc-testdev.c
[...]
> +typedef struct PCTestdev {
> +    ISADevice parent_obj;
> +
> +    MemoryRegion ioport;
> +    MemoryRegion flush;
> +    MemoryRegion irq;
> +    MemoryRegion iomem;
> +    uint32_t ioport_data;
> +    char iomem_buf[IOMEM_LEN];
> +} PCTestdev;
> +
> +#define TYPE_TESTDEV "pc-testdev"
> +#define TESTDEV(obj) \
> +     OBJECT_CHECK(struct PCTestdev, (obj), TYPE_TESTDEV)

You define a typedef above but ignore it here and everywhere below. I'm
surprised that Anthony didn't complain - struct is an implementation
detail of today's QOM classes in lack of C++/etc. language support, and
even qdev used the typedefs.

Lucas/Gerd, can one of you please clean this up in a follow-up?

I only noticed this because I had to touch some of these lines rebasing
my ISA QOM realize queue - maybe some Perl wizard can add a
checkpatch.pl rule to catch this?

Thanks,
Andreas

> +
> +static void test_irq_line(void *opaque, hwaddr addr, uint64_t data,
> +                          unsigned len)
> +{
> +    struct PCTestdev *dev = opaque;
> +    struct ISADevice *isa = ISA_DEVICE(dev);
> +
> +    qemu_set_irq(isa_get_irq(isa, addr), !!data);
> +}
> +
> +static const MemoryRegionOps test_irq_ops = {
> +    .write = test_irq_line,
> +    .valid.min_access_size = 1,
> +    .valid.max_access_size = 1,
> +    .endianness = DEVICE_LITTLE_ENDIAN,
> +};
> +
> +static void test_ioport_write(void *opaque, hwaddr addr, uint64_t data,
> +                              unsigned len)
> +{
> +    struct PCTestdev *dev = opaque;
> +    dev->ioport_data = data;
> +}
> +
> +static uint64_t test_ioport_read(void *opaque, hwaddr addr, unsigned len)
> +{
> +    struct PCTestdev *dev = opaque;
> +    return dev->ioport_data;
> +}
> +
> +static const MemoryRegionOps test_ioport_ops = {
> +    .read = test_ioport_read,
> +    .write = test_ioport_write,
> +    .endianness = DEVICE_LITTLE_ENDIAN,
> +};
> +
> +static void test_flush_page(void *opaque, hwaddr addr, uint64_t data,
> +                            unsigned len)
> +{
> +    hwaddr page = 4096;
> +    void *a = cpu_physical_memory_map(data & ~0xffful, &page, 0);
> +
> +    /* We might not be able to get the full page, only mprotect what we actually
> +       have mapped */
> +    mprotect(a, page, PROT_NONE);
> +    mprotect(a, page, PROT_READ|PROT_WRITE);
> +    cpu_physical_memory_unmap(a, page, 0, 0);
> +}
> +
> +static const MemoryRegionOps test_flush_ops = {
> +    .write = test_flush_page,
> +    .valid.min_access_size = 4,
> +    .valid.max_access_size = 4,
> +    .endianness = DEVICE_LITTLE_ENDIAN,
> +};
> +
> +static uint64_t test_iomem_read(void *opaque, hwaddr addr, unsigned len)
> +{
> +    struct PCTestdev *dev = opaque;
> +    uint64_t ret = 0;
> +    memcpy(&ret, &dev->iomem_buf[addr], len);
> +    ret = le64_to_cpu(ret);
> +
> +    return ret;
> +}
> +
> +static void test_iomem_write(void *opaque, hwaddr addr, uint64_t val,
> +                             unsigned len)
> +{
> +    struct PCTestdev *dev = opaque;
> +    val = cpu_to_le64(val);
> +    memcpy(&dev->iomem_buf[addr], &val, len);
> +    dev->iomem_buf[addr] = val;
> +}
> +
> +static const MemoryRegionOps test_iomem_ops = {
> +    .read = test_iomem_read,
> +    .write = test_iomem_write,
> +    .endianness = DEVICE_LITTLE_ENDIAN,
> +};
> +
> +static int init_test_device(ISADevice *isa)
> +{
> +    struct PCTestdev *dev = TESTDEV(isa);
> +    MemoryRegion *mem = isa_address_space(isa);
> +    MemoryRegion *io = isa_address_space_io(isa);
> +
> +    memory_region_init_io(&dev->ioport, &test_ioport_ops, dev,
> +                          "pc-testdev-ioport", 4);
> +    memory_region_init_io(&dev->flush, &test_flush_ops, dev,
> +                          "pc-testdev-flush-page", 4);
> +    memory_region_init_io(&dev->irq, &test_irq_ops, dev,
> +                          "pc-testdev-irq-line", 24);
> +    memory_region_init_io(&dev->iomem, &test_iomem_ops, dev,
> +                          "pc-testdev-iomem", IOMEM_LEN);
> +
> +    memory_region_add_subregion(io,  0xe0,       &dev->ioport);
> +    memory_region_add_subregion(io,  0xe4,       &dev->flush);
> +    memory_region_add_subregion(io,  0x2000,     &dev->irq);
> +    memory_region_add_subregion(mem, 0xff000000, &dev->iomem);
> +
> +    return 0;
> +}
> +
> +static void testdev_class_init(ObjectClass *klass, void *data)
> +{
> +    ISADeviceClass *k = ISA_DEVICE_CLASS(klass);
> +
> +    k->init = init_test_device;
> +}
> +
> +static TypeInfo testdev_info = {

static const

> +    .name           = TYPE_TESTDEV,
> +    .parent         = TYPE_ISA_DEVICE,
> +    .instance_size  = sizeof(struct PCTestdev),
> +    .class_init     = testdev_class_init,
> +};
> +
> +static void testdev_register_types(void)
> +{
> +    type_register_static(&testdev_info);
> +}
> +
> +type_init(testdev_register_types)


-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg

  parent reply	other threads:[~2013-01-06 18:19 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-04  8:16 [Qemu-devel] [PULL 0/4] test and debug devices Gerd Hoffmann
2013-01-04  8:16 ` [Qemu-devel] [PATCH 1/4] switch debugcon to memory api Gerd Hoffmann
2013-01-06 18:03   ` Andreas Färber
2013-01-04  8:16 ` [Qemu-devel] [PATCH 2/4] add isa-debug-exit device Gerd Hoffmann
2013-01-04  8:16 ` [Qemu-devel] [PATCH 3/4] hw: Add test device for unittests execution Gerd Hoffmann
2013-01-04 21:44   ` Stefan Weil
2013-01-04 22:38     ` Alexander Graf
2013-01-06 18:19   ` Andreas Färber [this message]
2013-01-04  8:16 ` [Qemu-devel] [PATCH 4/4] pc: remove bochs bios debug ports Gerd Hoffmann
2013-01-04 10:28 ` [Qemu-devel] [PULL 0/4] test and debug devices Andreas Färber
2013-01-04 12:57   ` Gerd Hoffmann
2013-01-04 13:07     ` Andreas Färber
2013-01-04 13:45     ` Anthony Liguori
2013-01-04 20:21 ` Anthony Liguori

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=50E9C014.2060508@suse.de \
    --to=afaerber@suse.de \
    --cc=agraf@suse.de \
    --cc=anthony@codemonkey.ws \
    --cc=blauwirbel@gmail.com \
    --cc=kraxel@redhat.com \
    --cc=lmr@redhat.com \
    --cc=mtosatti@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.