qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Matt Renzelmann" <mjr@cs.wisc.edu>
To: 'Alex Williamson' <alex.williamson@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v3] Align PCI capabilities in pci_find_space
Date: Wed, 26 Sep 2012 12:49:34 -0500	[thread overview]
Message-ID: <005901cd9c0f$4d3f9ef0$e7bedcd0$@cs.wisc.edu> (raw)
In-Reply-To: <1348678672.28860.204.camel@bling.home>

> > static int pci_find_space(PCIDevice *pdev, uint8_t size, bool pcie_space)
> > {
> >     int config_base;
> >     int config_size;
> >     int offset = PCI_CONFIG_HEADER_SIZE;
> >     int i;
> >     uint32_t *dword_used = &pdev->used[PCI_CONFIG_HEADER_SIZE];
> 
> This needs to change too.
> 
> Is there a different alignment requirement for pcie?  Seems like you
> might be better off creating some helper like:

I found a copy of the PCI-E 1.0 specification -- I don't have any later copy available -- and it contains this text:

============
7.9. PCI Express Extended Capabilities

PCI Express Extended Capability registers are located in device configuration space at offsets 256 or greater ...

Each capability structure must be DWORD aligned.

...

7.9.3. PCI Express Enhanced Capability Header

Next Capability Offset – This field contains the
offset to the next PCI Express capability structure or
000h if no other items exist in the linked list of
capabilities.

...

The bottom two bits of this offset are reserved and
must be implemented as 00b although software
must mask them to allow for future uses of these
bits.
============

so, I think it's reasonable to align everything to 4-bytes all the time.  Here's another draft:


static int pci_find_space(PCIDevice *pdev, uint32_t start, 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 < size; i += 4, dword_used++) {
        if (*dword_used)
            offset = i + 4;
        else if (i - offset + 4 >= size)
            return offset;
    }

    return 0;
}

static int pci_find_legacy_space(PCIDevice *pdev, uint8_t size) {
    return pci_find_space(pdev, PCI_CONFIG_HEADER_SIZE, PCI_CONFIG_SPACE_SIZE);
}

static int pci_find_express_space(PCIDevice *pdev, uint16_t size) {
    assert (pci_config_size(pdev) >= PCIE_CONFIG_SPACE_SIZE);
    return pci_find_space(pdev, PCI_CONFIG_SPACE_SIZE, PCIE_CONFIG_SPACE_SIZE);
}

  reply	other threads:[~2012-09-26 17:49 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 [this message]
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

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='005901cd9c0f$4d3f9ef0$e7bedcd0$@cs.wisc.edu' \
    --to=mjr@cs.wisc.edu \
    --cc=alex.williamson@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 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).