From: Alex Williamson <alex.williamson@redhat.com>
To: Matt Renzelmann <mjr@cs.wisc.edu>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v3] Align PCI capabilities in pci_find_space
Date: Wed, 26 Sep 2012 12:15:11 -0600 [thread overview]
Message-ID: <1348683311.28860.215.camel@bling.home> (raw)
In-Reply-To: <005e01cd9c11$7b967f10$72c37d30$@cs.wisc.edu>
On Wed, 2012-09-26 at 13:05 -0500, Matt Renzelmann wrote:
> >
> > Mismatched uses of "size" here. We need both the end of the range to
> > search and the size of the sub-range we're looking for. Maybe start,
> > end, and size. Thanks,
> >
>
> Ah of course, how's this:
>
> static int pci_find_space(PCIDevice *pdev, uint32_t start,
> uint32_t end, uint32_t size)
> {
> int offset = start;
> int i;
> uint32_t *dword_used = &pdev->used[start];
>
> /* This approach ensures the capability is dword-aligned, as
> required by the PCI and PCI-E specifications */
> for (i = start; i < end; i += 4, dword_used++) {
> if (*dword_used)
> offset = i + 4;
> else if (i - offset + 4 >= size)
> return offset;
> }
>
> return 0;
> }
Looks reasonable to me
> static int pci_find_legacy_space(PCIDevice *pdev, uint8_t size) {
> return pci_find_space(pdev, PCI_CONFIG_HEADER_SIZE,
> PCI_CONFIG_SPACE_SIZE, size);
> }
>
> static int pci_find_express_space(PCIDevice *pdev, uint16_t size) {
> assert (pci_config_size(pdev) >= PCIE_CONFIG_SPACE_SIZE);
This could be done generically in pci_find_space
assert(pci_config_size(pdev) >= end)
You could also add an alignment check
assert(!(start & 0x3))
Thanks,
Alex
> return pci_find_space(pdev, PCI_CONFIG_SPACE_SIZE,
> PCIE_CONFIG_SPACE_SIZE, size);
> }
>
prev parent reply other threads:[~2012-09-26 18:15 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-26 15:30 [Qemu-devel] [PATCH v3] Align PCI capabilities in pci_find_space mjr
2012-09-26 16:26 ` Alex Williamson
2012-09-26 16:50 ` Matt Renzelmann
2012-09-26 16:57 ` Alex Williamson
2012-09-26 17:49 ` Matt Renzelmann
2012-09-26 17:55 ` Alex Williamson
2012-09-26 18:02 ` Don Slutz
2012-09-26 18:04 ` Don Slutz
2012-09-26 18:05 ` Matt Renzelmann
2012-09-26 18:15 ` Alex Williamson [this message]
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=1348683311.28860.215.camel@bling.home \
--to=alex.williamson@redhat.com \
--cc=mjr@cs.wisc.edu \
--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;
as well as URLs for NNTP newsgroup(s).