From: Anthony PERARD <anthony.perard@citrix.com>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Yuji Shimada <shimada-yxb@necst.nec.co.jp>,
Xen Devel <xen-devel@lists.xensource.com>,
QEMU-devel <qemu-devel@nongnu.org>,
Stefano Stabellini <Stefano.Stabellini@eu.citrix.com>
Subject: Re: [Qemu-devel] [PATCH V8 RESEND 4/8] pci.c: Add pci_check_bar_overlap
Date: Mon, 19 Mar 2012 17:22:16 +0000 [thread overview]
Message-ID: <4F676B48.6010704@citrix.com> (raw)
In-Reply-To: <20120319131529.GB4591@redhat.com>
On 19/03/12 13:15, Michael S. Tsirkin wrote:
> On Fri, Mar 16, 2012 at 04:54:18PM +0000, Anthony PERARD wrote:
>> From: Yuji Shimada<shimada-yxb@necst.nec.co.jp>
>>
>> This function helps Xen PCI Passthrough device to check for overlap.
>>
>> Signed-off-by: Yuji Shimada<shimada-yxb@necst.nec.co.jp>
>> Signed-off-by: Anthony PERARD<anthony.perard@citrix.com>
>
> It seems that what's called for here really is
> using the new memory region infrastructure.
> That handles overlap etc nicely.
>
> That said, I don't mind, but would prefer to
> keep this mess outside the pci core. See below.
>
>> ---
>> hw/pci.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
>> hw/pci.h | 5 +++++
>> 2 files changed, 55 insertions(+), 0 deletions(-)
>>
>> diff --git a/hw/pci.c b/hw/pci.c
>> index 38e1de5..f950b4e 100644
>> --- a/hw/pci.c
>> +++ b/hw/pci.c
>> @@ -1992,6 +1992,56 @@ MemoryRegion *pci_address_space_io(PCIDevice *dev)
>> return dev->bus->address_space_io;
>> }
>>
>> +/* This function
>
> Comment blocks start with /* */
>
>> checks if an io_region overlap an io_region from another
>
> overlaps
>
>> + * device. The io_region to check is provide with (addr, size and type)
>
> provided
>
>> + * A callback can be provide and will be called for every region that is
>
> provided
>
>> + * overlapped.
>> + * The return value indicate if the region is overlappsed */
>
> indicates
>
>
>> +bool pci_check_bar_overlap(PCIDevice *device,
>> + pcibus_t addr, pcibus_t size, uint8_t type,
>> + void (*c)(void *o, const PCIDevice *d, int index),
>> + void *opaque)
>
> IMO this is inlikely to be needed by anyone except Xen.
> How about a generic pci_foreach_device and let Xen
> implement the hacks internally.
Ok, this should be better, I'll work on that.
Thanks,
>> +{
>> + PCIBus *bus = device->bus;
>> + int i, j;
>> + bool rc = false;
>> +
>> + for (i = 0; i< ARRAY_SIZE(bus->devices); i++) {
>> + PCIDevice *d = bus->devices[i];
>> + if (!d) {
>> + continue;
>> + }
>> +
>> + if (d->devfn == device->devfn) {
>> + continue;
>> + }
>> +
>> + /* xxx: This ignores bridges. */
>> + for (j = 0; j< PCI_NUM_REGIONS; j++) {
>> + PCIIORegion *r =&d->io_regions[j];
>> +
>> + if (!r->size) {
>> + continue;
>> + }
>> + if ((type& PCI_BASE_ADDRESS_SPACE_IO)
>> + != (r->type& PCI_BASE_ADDRESS_SPACE_IO)) {
>> + continue;
>> + }
>> +
>> + if (ranges_overlap(addr, size, r->addr, r->size)) {
>> + if (c) {
>> + c(opaque, d, j);
>> + rc = true;
>> + } else {
>> + return true;
>> + }
>> + }
>> + }
>> + }
>> +
>> + return rc;
>> +}
>> +
>> static void pci_device_class_init(ObjectClass *klass, void *data)
>> {
>> DeviceClass *k = DEVICE_CLASS(klass);
>> diff --git a/hw/pci.h b/hw/pci.h
>> index 4f19fdb..cbd04e1 100644
>> --- a/hw/pci.h
>> +++ b/hw/pci.h
>> @@ -628,4 +628,9 @@ extern const VMStateDescription vmstate_pci_device;
>> .offset = vmstate_offset_pointer(_state, _field, PCIDevice), \
>> }
>>
>> +bool pci_check_bar_overlap(PCIDevice *dev,
>> + pcibus_t addr, pcibus_t size, uint8_t type,
>> + void (*c)(void *o, const PCIDevice *d, int index),
>> + void *opaque);
>> +
>> #endif
>> --
>> Anthony PERARD
--
Anthony PERARD
next prev parent reply other threads:[~2012-03-19 17:22 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-16 16:54 [Qemu-devel] [PATCH V8 RESEND 0/8] Xen PCI Passthrough Anthony PERARD
2012-03-16 16:54 ` [Qemu-devel] [PATCH V8 RESEND 1/8] pci_ids: Add INTEL_82599_VF id Anthony PERARD
2012-03-19 11:50 ` Stefano Stabellini
2012-03-19 16:54 ` Anthony PERARD
2012-05-12 1:43 ` [Qemu-devel] [Xen-devel] " Konrad Rzeszutek Wilk
2012-05-14 10:52 ` Anthony PERARD
2012-03-16 16:54 ` [Qemu-devel] [PATCH V8 RESEND 2/8] configure: Introduce --enable-xen-pci-passthrough Anthony PERARD
2012-03-19 11:51 ` Stefano Stabellini
2012-05-12 1:42 ` [Qemu-devel] [Xen-devel] " Konrad Rzeszutek Wilk
2012-05-14 10:49 ` Anthony PERARD
2012-05-16 11:15 ` Konrad Rzeszutek Wilk
2012-03-16 16:54 ` [Qemu-devel] [PATCH V8 RESEND 3/8] Introduce HostPCIDevice to access a pci device on the host Anthony PERARD
2012-03-19 11:53 ` Stefano Stabellini
2012-03-16 16:54 ` [Qemu-devel] [PATCH V8 RESEND 4/8] pci.c: Add pci_check_bar_overlap Anthony PERARD
2012-03-19 11:55 ` Stefano Stabellini
2012-03-19 13:15 ` Michael S. Tsirkin
2012-03-19 17:22 ` Anthony PERARD [this message]
2012-03-16 16:54 ` [Qemu-devel] [PATCH V8 RESEND 5/8] Introduce Xen PCI Passthrough, qdevice (1/3) Anthony PERARD
2012-03-19 12:00 ` Stefano Stabellini
2012-05-12 1:53 ` [Qemu-devel] [Xen-devel] " Konrad Rzeszutek Wilk
2012-03-16 16:54 ` [Qemu-devel] [PATCH V8 RESEND 6/8] Introduce Xen PCI Passthrough, PCI config space helpers (2/3) Anthony PERARD
2012-03-19 12:01 ` Stefano Stabellini
2012-03-16 16:54 ` [Qemu-devel] [PATCH V8 RESEND 7/8] Introduce apic-msidef.h Anthony PERARD
2012-03-19 12:04 ` Stefano Stabellini
2012-03-16 16:54 ` [Qemu-devel] [PATCH V8 RESEND 8/8] Introduce Xen PCI Passthrough, MSI (3/3) Anthony PERARD
2012-03-19 12:04 ` Stefano Stabellini
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=4F676B48.6010704@citrix.com \
--to=anthony.perard@citrix.com \
--cc=Stefano.Stabellini@eu.citrix.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=shimada-yxb@necst.nec.co.jp \
--cc=xen-devel@lists.xensource.com \
/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;
as well as URLs for NNTP newsgroup(s).