From: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro>
To: kvm@vger.kernel.org, qemu-devel@nongnu.org
Cc: joro@8bytes.org
Subject: [RFC] Getting specific device from qdev structs
Date: Mon, 21 Jun 2010 16:48:59 +0300 [thread overview]
Message-ID: <20100621134858.GA8275@localhost> (raw)
Hi,
I'm working on implementing AMD IOMMU emulation in QEMU/KVM and I'm also
creating an API for address translation and access checking. Ideally,
this API should work with different kinds of devices and IOMMUs. These
operations would typically require specific device information to figure
out which IOMMU is responsible and how it refers to the actual device
(bus-device-function number for example).
At the same time, I need to get this from deep within AIO/DMA code, so
adding specific members in those structures doesn't seem to be the best
way.
So I've been looking for a way to obtain things like a PCIDevice from a
more generic structure (say from hw/qdev.h), e.g. DeviceInfo. Is there
something like that already implemented? My searches turned up nothing.
If not, perhaps something like this would be acceptable?
enum DeviceType {
DEV_TYPE_PCI,
DEV_TYPE_ISA,
[...]
};
struct GenericDevice {
enum DeviceType type;
union {
PCIDevice *pci_dev;
ISADevice *isa_dev;
[...]
};
}; /*
* Embed this in DeviceState for example. Make it
* somehow accesible from AIO/DMA code.
*/
Or some container_of() / DO_UPCAST() magic might do:
struct GenericDevice {
enum DeviceType type;
DeviceState qdev;
}; /* Embed this in PCIDevice and pass a pointer to GenericDevice around. */
struct PCIDevice {
GenericDevice gdev;
[...]
}
int iommu_translate(struct GenericDevice *dev, [other args])
{
PCIDevice *pci_dev;
ISADevice *isa_dev;
switch (dev->type) {
case DEV_TYPE_PCI:
pci_dev = container_of(dev, PCIDevice, gdev);
return iommu_pci_translate(pci_dev, [other args]);
case DEV_TYPE_ISA:
isa_dev = container_of(dev, ISADevice, gdev);
return iommu_pci_translate(isa_dev, [other args]);
[...]
default:
break;
}
[sensible default]
return 0;
}
Note we can't actually do any container_of() magic without recording the
type of the container structure somewhere.
What do you think? I'd appreciate some help here. Perhaps there are
other (simpler) ways I didn't think of.
Thanks,
Eduard
next reply other threads:[~2010-06-21 13:49 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-21 13:48 Eduard - Gabriel Munteanu [this message]
2010-06-21 14:07 ` [Qemu-devel] [RFC] Getting specific device from qdev structs Paul Brook
2010-06-21 14:32 ` Eduard - Gabriel Munteanu
2010-06-21 15:08 ` Paul Brook
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=20100621134858.GA8275@localhost \
--to=eduard.munteanu@linux360.ro \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox