From: Yijing Wang <wangyijing@huawei.com>
To: Bjorn Helgaas <bhelgaas@google.com>
Cc: <linux-kernel@vger.kernel.org>, <linux-pci@vger.kernel.org>,
Yijing Wang <wangyijing@huawei.com>,
Hanjun Guo <guohanjun@huawei.com>
Subject: [PATCH part1 v6 2/7] PCI: introduce pci_bus_find_ext_capability()
Date: Wed, 12 Feb 2014 10:52:48 +0800 [thread overview]
Message-ID: <1392173573-59844-3-git-send-email-wangyijing@huawei.com> (raw)
In-Reply-To: <1392173573-59844-1-git-send-email-wangyijing@huawei.com>
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 <wangyijing@huawei.com>
---
drivers/pci/pci.c | 32 ++++++++++++++++++++++++++++++++
include/linux/pci.h | 1 +
2 files changed, 33 insertions(+), 0 deletions(-)
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index a263c0a..4502e6f 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -327,6 +327,38 @@ 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);
--
1.7.1
next prev parent reply other threads:[~2014-02-12 2:53 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-12 2:52 [PATCH part1 v6 0/7] Introduce PCIe Device Serial Number capability support Yijing Wang
2014-02-12 2:52 ` [PATCH part1 v6 1/7] PCI: rework pci_find_next_ext_capability() Yijing Wang
2014-02-12 2:52 ` Yijing Wang [this message]
2014-02-12 2:52 ` [PATCH part1 v6 3/7] PCI: Add support for Device Serial Number capability Yijing Wang
2014-02-12 2:52 ` [PATCH part1 v6 4/7] PCI: Introduce pci_serial_number_changed() Yijing Wang
2014-02-12 7:26 ` Gu Zheng
2014-02-12 7:57 ` Yijing Wang
2014-02-12 2:52 ` [PATCH part1 v6 5/7] PCI: Add pci_dummy_ops to isolate pci device temporarily Yijing Wang
2014-02-12 7:46 ` Gu Zheng
2014-02-12 7:59 ` Yijing Wang
2014-02-12 2:52 ` [PATCH part1 v6 6/7] PCI: Check pci device serial number when scan device Yijing Wang
2014-02-12 2:52 ` [PATCH part1 v6 7/7] PCI: pciehp: Don't enable/disable slot on resume unless status changed Yijing Wang
2014-02-17 8:52 ` [PATCH part1 v6 0/7] Introduce PCIe Device Serial Number capability support Yijing Wang
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=1392173573-59844-3-git-send-email-wangyijing@huawei.com \
--to=wangyijing@huawei.com \
--cc=bhelgaas@google.com \
--cc=guohanjun@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.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
all inboxes | Powered by JetHome®