From patchwork Wed Jul 15 20:20:19 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jesse Barnes X-Patchwork-Id: 35746 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n6FKKIkb014987 for ; Wed, 15 Jul 2009 20:20:23 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932260AbZGOUUW (ORCPT ); Wed, 15 Jul 2009 16:20:22 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S932266AbZGOUUW (ORCPT ); Wed, 15 Jul 2009 16:20:22 -0400 Received: from outbound-mail-309.bluehost.com ([67.222.54.2]:40119 "HELO outbound-mail-309.bluehost.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S932260AbZGOUUV (ORCPT ); Wed, 15 Jul 2009 16:20:21 -0400 Received: (qmail 8876 invoked by uid 0); 15 Jul 2009 20:20:21 -0000 Received: from unknown (HELO box514.bluehost.com) (74.220.219.114) by outboundproxy6.bluehost.com with SMTP; 15 Jul 2009 20:20:21 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=virtuousgeek.org; h=Received:Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References:X-Mailer:Mime-Version:Content-Type:Content-Transfer-Encoding:X-Identified-User; b=qhydjiRXKKdNo+X1C4zyhr/Y0srxJwLSq++mF035PQWKowwuI/qryP6FWBuPgIEgFC0a5a/Vp8r0rFi3CjByFI5hpldACTE6aX+rjHoQmzQOCq0G8dB2//VjFdnnidfS; Received: from [75.111.28.251] (helo=jbarnes-g45) by box514.bluehost.com with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69) (envelope-from ) id 1MRAxh-0002HK-0U; Wed, 15 Jul 2009 14:20:21 -0600 Date: Wed, 15 Jul 2009 13:20:19 -0700 From: Jesse Barnes To: linux-pci@vger.kernel.org Cc: Matthew Wilcox , x86@kernel.org, jacob.jun.pan@intel.com Subject: [PATCH] PCI: add pci_bus_find_ext_capability Message-ID: <20090715132019.7ff1584e@jbarnes-g45> In-Reply-To: <20090715131939.37a4836a@jbarnes-g45> References: <20090715131939.37a4836a@jbarnes-g45> X-Mailer: Claws Mail 3.6.1 (GTK+ 2.16.1; i486-pc-linux-gnu) Mime-Version: 1.0 X-Identified-User: {10642:box514.bluehost.com:virtuous:virtuousgeek.org} {sentby:smtp auth 75.111.28.251 authed with jbarnes@virtuousgeek.org} Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org For use by code that needs to walk extended capability lists before pci_dev structures are set up. Signed-off-by: Jesse Barnes --- drivers/pci/pci.c | 43 +++++++++++++++++++++++++++++++++++++++++++ include/linux/pci.h | 2 ++ 2 files changed, 45 insertions(+), 0 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index dbd0f94..4b530d5 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -272,6 +272,49 @@ int pci_find_ext_capability(struct pci_dev *dev, int cap) } EXPORT_SYMBOL_GPL(pci_find_ext_capability); +/** + * pci_bus_find_ext_capability - find an extended capability + * @bus: the PCI bus to query + * @devfn: PCI device to query + * @cap: capability code + * + * Like pci_find_ext_capability() but works for pci devices that do not have a + * pci_dev structure set up yet. + * + * Returns the address of the requested capability structure within the + * device's PCI configuration space or 0 in case the device does not + * support it. + */ +int pci_bus_find_ext_capability(struct pci_bus *bus, unsigned int devfn, + int cap) +{ + u32 header; + int ttl; + int pos = PCI_CFG_SPACE_SIZE; + + /* minimum 8 bytes per capability */ + ttl = (PCI_CFG_SPACE_EXP_SIZE - PCI_CFG_SPACE_SIZE) / 8; + + if (!pci_bus_read_config_dword(bus, devfn, pos, &header)) + return 0; + if (header == 0xffffffff || header == 0) + return 0; + + while (ttl-- > 0) { + if (PCI_EXT_CAP_ID(header) == cap) + return pos; + + pos = PCI_EXT_CAP_NEXT(header); + if (pos < PCI_CFG_SPACE_SIZE) + break; + + if (!pci_bus_read_config_dword(bus, devfn, pos, &header)) + break; + } + + return 0; +} + static int __pci_find_next_ht_cap(struct pci_dev *dev, int pos, int ht_cap) { int rc, ttl = PCI_FIND_CAP_TTL; diff --git a/include/linux/pci.h b/include/linux/pci.h index 115fb7b..9ecac99 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -621,6 +621,8 @@ enum pci_lost_interrupt_reason pci_lost_interrupt(struct pci_dev *dev); int pci_find_capability(struct pci_dev *dev, int cap); int pci_find_next_capability(struct pci_dev *dev, u8 pos, int cap); int pci_find_ext_capability(struct pci_dev *dev, int cap); +int pci_bus_find_ext_capability(struct pci_bus *bus, unsigned int devfn, + int cap); int pci_find_ht_capability(struct pci_dev *dev, int ht_cap); int pci_find_next_ht_capability(struct pci_dev *dev, int pos, int ht_cap); struct pci_bus *pci_find_next_bus(const struct pci_bus *from);