From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:55983) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TGuou-0004IF-Qp for qemu-devel@nongnu.org; Wed, 26 Sep 2012 12:50:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TGuok-0002vJ-Ss for qemu-devel@nongnu.org; Wed, 26 Sep 2012 12:50:44 -0400 Received: from sabe.cs.wisc.edu ([128.105.6.20]:41190) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TGuok-0002tj-Ha for qemu-devel@nongnu.org; Wed, 26 Sep 2012 12:50:34 -0400 From: "Matt Renzelmann" References: <1348673453-3248-1-git-send-email-mjr@cs.wisc.edu> <1348676771.28860.199.camel@bling.home> In-Reply-To: <1348676771.28860.199.camel@bling.home> Date: Wed, 26 Sep 2012 11:50:27 -0500 Message-ID: <004401cd9c07$0b36d760$21a48620$@cs.wisc.edu> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Content-Language: en-us Subject: Re: [Qemu-devel] [PATCH v3] Align PCI capabilities in pci_find_space List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: 'Alex Williamson' Cc: qemu-devel@nongnu.org > > > > hw/pci.c | 28 +++++++++++++++++++++------- > > 1 files changed, 21 insertions(+), 7 deletions(-) > > > > diff --git a/hw/pci.c b/hw/pci.c > > index f855cf3..2217dda 100644 > > --- a/hw/pci.c > > +++ b/hw/pci.c > > @@ -1626,16 +1626,30 @@ PCIDevice *pci_create_simple(PCIBus *bus, = int devfn, > const char *name) > > return pci_create_simple_multifunction(bus, devfn, false, = name); > > } > > > > -static int pci_find_space(PCIDevice *pdev, uint8_t size) > > +static int pci_find_space(PCIDevice *pdev, uint8_t size, bool = include_pcie) > > { > > - int config_size =3D pci_config_size(pdev); > > + int config_size; > > int offset =3D PCI_CONFIG_HEADER_SIZE; > > int i; > > - for (i =3D PCI_CONFIG_HEADER_SIZE; i < config_size; ++i) > > - if (pdev->used[i]) > > - offset =3D i + 1; > > - else if (i - offset + 1 =3D=3D size) > > + uint32_t *dword_used =3D &pdev->used[PCI_CONFIG_HEADER_SIZE]; > > + > > + if (include_pcie) { > > + assert (pci_config_size(pdev) >=3D PCIE_CONFIG_SPACE_SIZE); > > + config_size =3D PCIE_CONFIG_SPACE_SIZE; > > + } else { > > + config_size =3D PCI_CONFIG_SPACE_SIZE; > > + } > > + > > + /* This approach ensures the capability is dword-aligned, as > > + required by the PCI specification */ > > + for (i =3D PCI_CONFIG_HEADER_SIZE; i < config_size; i +=3D 4, = dword_used++) > { >=20 > I don't believe there's ever a case where a driver would want space = and > not care if it's in standard or extended config space. They'll want = one > or the other. So we'd be searching two distinct ranges. Thanks, >=20 > Alex Ah, that makes sense, so would something like this work? I can re-send = as a patch once we've got it. static int pci_find_space(PCIDevice *pdev, uint8_t size, bool = pcie_space) { int config_base; int config_size; int offset =3D PCI_CONFIG_HEADER_SIZE; int i; uint32_t *dword_used =3D &pdev->used[PCI_CONFIG_HEADER_SIZE]; if (pcie_space) { assert (pci_config_size(pdev) >=3D PCIE_CONFIG_SPACE_SIZE); config_base =3D PCI_CONFIG_SPACE_SIZE; config_size =3D PCIE_CONFIG_SPACE_SIZE; } else { =20 config_base =3D PCI_CONFIG_HEADER_SIZE; config_size =3D PCI_CONFIG_SPACE_SIZE; } /* This approach ensures the capability is dword-aligned, as = =20 required by the PCI specification */ for (i =3D config_base; i < config_size; i +=3D 4, dword_used++) { = =20 if (*dword_used) offset =3D i + 4; else if (i - offset + 4 >=3D size) return offset; } =20 return 0; } Thanks for all your help with this, Matt >=20 > > + if (*dword_used) { > > + offset =3D i + 4; > > + } else if (i - offset + 4 >=3D size) { > > return offset; > > + } > > + } > > + > > return 0; > > } > > > > @@ -1826,7 +1840,7 @@ int pci_add_capability(PCIDevice *pdev, = uint8_t > cap_id, > > int i, overlapping_cap; > > > > if (!offset) { > > - offset =3D pci_find_space(pdev, size); > > + offset =3D pci_find_space(pdev, size, false); > > if (!offset) { > > return -ENOSPC; > > } >=20 >=20