From: Mika Westerberg <mika.westerberg@linux.intel.com>
To: Bjorn Helgaas <helgaas@kernel.org>,
"Rafael J . Wysocki" <rafael@kernel.org>
Cc: Aaron Durbin <adurbin@google.com>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Mika Westerberg <mika.westerberg@linux.intel.com>,
linux-pci@vger.kernel.org, linux-acpi@vger.kernel.org
Subject: [PATCH 1/2] PCI: Add pci_find_resource()
Date: Tue, 13 Sep 2016 15:19:41 +0300 [thread overview]
Message-ID: <20160913121942.80356-1-mika.westerberg@linux.intel.com> (raw)
In-Reply-To: <CAJZ5v0gRm++9zcAtXc1jYKsrg=tw2K3Wd=kQRS=RbRxXRDj8yA@mail.gmail.com>
Add a new helper function pci_find_resource() that can be used to find out
whether a given resource (for example from a child device) is contained
within given PCI device's standard resources.
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
---
drivers/pci/pci.c | 27 +++++++++++++++++++++++++++
include/linux/pci.h | 4 ++++
2 files changed, 31 insertions(+)
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index aab9d5115a5f..491f879f34cb 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -480,6 +480,33 @@ struct resource *pci_find_parent_resource(const struct pci_dev *dev,
EXPORT_SYMBOL(pci_find_parent_resource);
/**
+ * pci_find_resource - Return matching PCI device resource
+ * @dev: PCI device to query
+ * @res: Resource to look for
+ *
+ * Goes over standard PCI resources (BARs) and checks if the given resource
+ * is partially or fully contained in any of them. In that case the
+ * matching resource is returned, %NULL otherwise.
+ */
+struct resource *pci_find_resource(struct pci_dev *dev, struct resource *res)
+{
+ int i;
+
+ if (!res)
+ return NULL;
+
+ for (i = 0; i < PCI_ROM_RESOURCE; i++) {
+ struct resource *r = &dev->resource[i];
+
+ if (r->start && resource_contains(r, res))
+ return r;
+ }
+
+ return NULL;
+}
+EXPORT_SYMBOL(pci_find_resource);
+
+/**
* pci_find_pcie_root_port - return PCIe Root Port
* @dev: PCI device to query
*
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 0ab835965669..a917d4b20554 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1126,6 +1126,7 @@ void pdev_enable_device(struct pci_dev *);
int pci_enable_resources(struct pci_dev *, int mask);
void pci_fixup_irqs(u8 (*)(struct pci_dev *, u8 *),
int (*)(const struct pci_dev *, u8, u8));
+struct resource *pci_find_resource(struct pci_dev *dev, struct resource *res);
#define HAVE_PCI_REQ_REGIONS 2
int __must_check pci_request_regions(struct pci_dev *, const char *);
int __must_check pci_request_regions_exclusive(struct pci_dev *, const char *);
@@ -1542,6 +1543,9 @@ static inline int pci_enable_wake(struct pci_dev *dev, pci_power_t state,
int enable)
{ return 0; }
+static inline struct resource *pci_find_resource(struct pci_dev *dev,
+ struct resource *res)
+{ return NULL; }
static inline int pci_request_regions(struct pci_dev *dev, const char *res_name)
{ return -EIO; }
static inline void pci_release_regions(struct pci_dev *dev) { }
--
2.9.3
next prev parent reply other threads:[~2016-09-13 12:20 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-18 15:54 ACPI device using sub-resource of PCI device Aaron Durbin
2016-05-18 21:25 ` Rafael J. Wysocki
2016-05-18 22:32 ` Aaron Durbin
2016-06-14 17:04 ` Aaron Durbin
2016-06-24 19:34 ` Aaron Durbin
2016-06-29 4:41 ` Aaron Durbin
2016-07-20 19:35 ` Bjorn Helgaas
2016-07-20 22:06 ` Aaron Durbin
2016-07-20 22:46 ` Rafael J. Wysocki
2016-07-20 23:02 ` Aaron Durbin
2016-07-21 0:40 ` Rafael J. Wysocki
2016-07-21 1:58 ` Aaron Durbin
2016-07-22 0:55 ` Rafael J. Wysocki
2016-07-22 17:26 ` Aaron Durbin
2016-07-22 21:04 ` Rafael J. Wysocki
2016-07-25 19:11 ` Aaron Durbin
2016-07-28 0:09 ` Rafael J. Wysocki
2016-07-28 4:02 ` Aaron Durbin
2016-08-12 16:45 ` Aaron Durbin
2016-08-16 9:15 ` Mika Westerberg
2016-08-16 11:23 ` Andy Shevchenko
2016-08-16 11:27 ` Rafael J. Wysocki
2016-08-16 12:20 ` Mika Westerberg
2016-08-17 23:02 ` Aaron Durbin
2016-09-09 14:12 ` Aaron Durbin
2016-09-09 14:16 ` Aaron Durbin
2016-09-12 8:10 ` Mika Westerberg
2016-09-12 12:26 ` Rafael J. Wysocki
2016-09-13 12:19 ` Mika Westerberg [this message]
2016-09-13 12:19 ` [PATCH 2/2] ACPI / platform: Pay attention to parent device's resources Mika Westerberg
2016-09-13 14:11 ` [PATCH 1/2] PCI: Add pci_find_resource() Andy Shevchenko
2016-09-14 7:45 ` Mika Westerberg
2016-09-14 22:16 ` Bjorn Helgaas
2016-09-14 22:47 ` Rafael J. Wysocki
2016-09-15 8:07 ` [PATCH v2 " Mika Westerberg
2016-09-15 8:07 ` [PATCH v2 2/2] ACPI / platform: Pay attention to parent device's resources Mika Westerberg
2016-07-22 16:40 ` ACPI device using sub-resource of PCI device Bjorn Helgaas
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=20160913121942.80356-1-mika.westerberg@linux.intel.com \
--to=mika.westerberg@linux.intel.com \
--cc=adurbin@google.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=helgaas@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=rafael@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;
as well as URLs for NNTP newsgroup(s).