From patchwork Mon Feb 10 04:04:06 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yijing Wang X-Patchwork-Id: 318658 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 53D0C2C00B1 for ; Mon, 10 Feb 2014 15:07:35 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752206AbaBJEFA (ORCPT ); Sun, 9 Feb 2014 23:05:00 -0500 Received: from szxga02-in.huawei.com ([119.145.14.65]:34400 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751962AbaBJEE7 (ORCPT ); Sun, 9 Feb 2014 23:04:59 -0500 Received: from 172.24.2.119 (EHLO szxeml206-edg.china.huawei.com) ([172.24.2.119]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id BPP67817; Mon, 10 Feb 2014 12:04:56 +0800 (CST) Received: from SZXEML463-HUB.china.huawei.com (10.82.67.206) by szxeml206-edg.china.huawei.com (172.24.2.59) with Microsoft SMTP Server (TLS) id 14.3.158.1; Mon, 10 Feb 2014 12:04:46 +0800 Received: from localhost (10.177.27.212) by szxeml463-hub.china.huawei.com (10.82.67.206) with Microsoft SMTP Server id 14.3.158.1; Mon, 10 Feb 2014 12:04:50 +0800 From: Yijing Wang To: Bjorn Helgaas CC: , , Yijing Wang , Hanjun Guo Subject: [PATCH part1 v5 2/7] PCI: introduce pci_bus_find_ext_capability() Date: Mon, 10 Feb 2014 12:04:06 +0800 Message-ID: <1392005051-54508-3-git-send-email-wangyijing@huawei.com> X-Mailer: git-send-email 1.7.11.msysgit.1 In-Reply-To: <1392005051-54508-1-git-send-email-wangyijing@huawei.com> References: <1392005051-54508-1-git-send-email-wangyijing@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.27.212] X-CFilter-Loop: Reflected Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Sometimes we need to find PCI EXT CAP before pci_dev set up. So introduce pci_bus_find_ext_capability(), it will be used to get PCI EXT DSN before pci_dev set up. Signed-off-by: Yijing Wang --- drivers/pci/pci.c | 31 +++++++++++++++++++++++++++++++ include/linux/pci.h | 1 + 2 files changed, 32 insertions(+), 0 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index a263c0a..432ac86 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -327,6 +327,37 @@ 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, int devfn, int cap) +{ + int pos; + u32 status; + + pos = pci_bus_find_capability(bus, devfn, PCI_CAP_ID_EXP); + if (!pos) + return 0; + + if (pci_bus_read_config_dword(bus, devfn, PCI_CFG_SPACE_SIZE, &status) != + PCIBIOS_SUCCESSFUL || status == 0xffffffff) + return 0; + + return pci_find_next_ext_capability(bus, devfn, 0, cap); +} + + 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 df495e9..470de02 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -797,6 +797,7 @@ 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_find_next_ext_capability(struct pci_bus *bus, int devfn, int pos, int cap); +int pci_bus_find_ext_capability(struct pci_bus *bus, 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);