All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Alexey Kardashevskiy" <aik@ozlabs.ru>,
	"David Gibson" <david@gibson.dropbear.id.au>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	qemu-devel@nongnu.org, "Eduardo Habkost" <ehabkost@redhat.com>
Subject: [Qemu-devel] What's IOMMUMemoryRegion's super?
Date: Wed, 03 Jul 2019 07:05:56 +0200	[thread overview]
Message-ID: <878stfzozv.fsf@dusky.pond.sub.org> (raw)

The usual QOM boilerplate for defining a sub-{type,class} looks like
this:

    static const TypeInfo sysbus_device_type_info = {
        .name = TYPE_SYS_BUS_DEVICE,
        .parent = TYPE_DEVICE,
        .instance_size = sizeof(SysBusDevice),
        .abstract = true,
        .class_size = sizeof(SysBusDeviceClass),
        .class_init = sysbus_device_class_init,
    };

    typedef struct SysBusDeviceClass {
        /*< private >*/
        DeviceClass parent_class;
        [...]
    } SysBusDeviceClass;

    struct SysBusDevice {
        /*< private >*/
        DeviceState parent_obj;
        [...]
    };

Note the TypeInfo states the parent type (member @parent), and
associated class and instance structs (used members @instance_size and
@class_size) have the parent type's class and member struct as first
member.

This makes type casts to parent types work.  The checked QOM casts add
safety by checking it's actually a parent type.

Now consider TYPE_IOMMU_MEMORY_REGION:

    static const TypeInfo iommu_memory_region_info = {
        .parent             = TYPE_MEMORY_REGION,
        .name               = TYPE_IOMMU_MEMORY_REGION,
        .class_size         = sizeof(IOMMUMemoryRegionClass),
        .instance_size      = sizeof(IOMMUMemoryRegion),
        .instance_init      = iommu_memory_region_initfn,
        .abstract           = true,
    };

    typedef struct IOMMUMemoryRegionClass {
        /* private */
--->    struct DeviceClass parent_class;
        [...]
    };

    struct IOMMUMemoryRegion {
        MemoryRegion parent_obj;
        [...]
    };

The parent is TYPE_MEMORY_REGION, and the instance struct's first member is
TYPE_MEMORY_REGION's instance struct as I expect, but the class struct's
first member is something else entirely.

What's going on here?  Am I confused?

The commit message is of no help whatsoever:

    commit 1221a4746769f70231beab4db8da1c937e60340c
    Author: Alexey Kardashevskiy <aik@ozlabs.ru>
    Date:   Tue Jul 11 13:56:20 2017 +1000

        memory/iommu: introduce IOMMUMemoryRegionClass

        This finishes QOM'fication of IOMMUMemoryRegion by introducing
        a IOMMUMemoryRegionClass. This also provides a fastpath analog for
        IOMMU_MEMORY_REGION_GET_CLASS().

        This makes IOMMUMemoryRegion an abstract class.

        Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
        Message-Id: <20170711035620.4232-3-aik@ozlabs.ru>
        Acked-by: Cornelia Huck <cohuck@redhat.com>
        Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>


             reply	other threads:[~2019-07-03  5:07 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-03  5:05 Markus Armbruster [this message]
2019-07-03  5:37 ` [Qemu-devel] What's IOMMUMemoryRegion's super? Paolo Bonzini
2019-07-03  6:15   ` David Gibson
2019-07-03 10:37   ` Markus Armbruster

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=878stfzozv.fsf@dusky.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=aik@ozlabs.ru \
    --cc=berrange@redhat.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=ehabkost@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.