linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yinghai Lu <yinghai@kernel.org>
To: Bjorn Helgaas <bhelgaas@google.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
	Yinghai Lu <yinghai@kernel.org>
Subject: [PATCH 02/10] PCI: introduce ioport_res/iomem_res for PCI_TEST
Date: Fri,  4 Aug 2017 23:37:53 -0700	[thread overview]
Message-ID: <20170805063801.15880-3-yinghai@kernel.org> (raw)
In-Reply-To: <20170805063801.15880-1-yinghai@kernel.org>

Make every bus to take the pointer to correct iomem_res instead of
using iomem_resource directly.

So PCI_TEST could use different iomem_res later.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 drivers/pci/probe.c     |  2 ++
 drivers/pci/quirks.c    |  2 +-
 drivers/pci/setup-bus.c |  2 +-
 drivers/pci/setup-res.c |  4 ++--
 include/linux/pci.h     | 13 +++++++++++++
 5 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index c31310d..1811016 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -881,6 +881,8 @@ static struct pci_bus *pci_alloc_child_bus(struct pci_bus *parent,
 	child->msi = parent->msi;
 	child->sysdata = parent->sysdata;
 	child->bus_flags = parent->bus_flags;
+	child->iomem_res = parent->iomem_res;
+	child->ioport_res = parent->ioport_res;
 
 	/* initialize some portions of the bus device, but don't register it
 	 * now as the parent is not properly set up yet.
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 6967c6b..dc31098 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -1617,7 +1617,7 @@ static void quirk_alder_ioapic(struct pci_dev *pdev)
 	 * not touch this (and it's already covered by the fixmap), so
 	 * forcibly insert it into the resource tree */
 	if (pci_resource_start(pdev, 0) && pci_resource_len(pdev, 0))
-		insert_resource(&iomem_resource, &pdev->resource[0]);
+		insert_resource(iomem_res(pdev->bus), &pdev->resource[0]);
 
 	/* The next five BARs all seem to be rubbish, so just clean
 	 * them out */
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 958da7d..1c30102 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -805,7 +805,7 @@ static struct resource *find_free_bus_resource(struct pci_bus *bus,
 	struct resource *r;
 
 	pci_bus_for_each_resource(bus, r, i) {
-		if (r == &ioport_resource || r == &iomem_resource)
+		if (r == ioport_res(bus) || r == iomem_res(bus))
 			continue;
 		if (r && (r->flags & type_mask) == type && !r->parent)
 			return r;
diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c
index 85774b7..43921a4 100644
--- a/drivers/pci/setup-res.c
+++ b/drivers/pci/setup-res.c
@@ -215,9 +215,9 @@ static int pci_revert_fw_address(struct resource *res, struct pci_dev *dev,
 	root = pci_find_parent_resource(dev, res);
 	if (!root) {
 		if (res->flags & IORESOURCE_IO)
-			root = &ioport_resource;
+			root = ioport_res(dev->bus);
 		else
-			root = &iomem_resource;
+			root = iomem_res(dev->bus);
 	}
 
 	dev_info(&dev->dev, "BAR %d: trying firmware assignment %pR\n",
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 4869e66..c58a635 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -524,6 +524,9 @@ struct pci_bus {
 	void		*sysdata;	/* hook for sys-specific extension */
 	struct proc_dir_entry *procdir;	/* directory entry in /proc/bus/pci */
 
+	struct resource *iomem_res;	/* pointer to root iomem_resource */
+	struct resource *ioport_res;	/* pointer to root ioport_resource */
+
 	unsigned char	number;		/* bus number */
 	unsigned char	primary;	/* number of primary bridge */
 	unsigned char	max_bus_speed;	/* enum pci_bus_speed */
@@ -545,6 +548,16 @@ struct pci_bus {
 
 #define to_pci_bus(n)	container_of(n, struct pci_bus, dev)
 
+static inline struct resource *iomem_res(struct pci_bus *bus)
+{
+	return bus->iomem_res ? : &iomem_resource;
+}
+
+static inline struct resource *ioport_res(struct pci_bus *bus)
+{
+	return bus->ioport_res ? : &ioport_resource;
+}
+
 /*
  * Returns true if the PCI bus is root (behind host-PCI bridge),
  * false otherwise
-- 
2.9.4

  parent reply	other threads:[~2017-08-05  6:38 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-05  6:37 [PATCH 00/10] PCI: pci resource allocation test module Yinghai Lu
2017-08-05  6:37 ` [PATCH 01/10] PCI: avoid arch_remove_reservations() for PCI_TEST Yinghai Lu
2017-08-05  6:37 ` Yinghai Lu [this message]
2017-08-05  6:37 ` [PATCH 03/10] PCI: export symbol for PCI_TEST module Yinghai Lu
2017-08-05  6:37 ` [PATCH 04/10] PCI: extend pci device match_driver state Yinghai Lu
2017-08-05  6:37 ` [PATCH 05/10] PCI: Add PCI_TEST module for resource allocation Yinghai Lu
2017-08-05  6:37 ` [PATCH 06/10] PCI: PCI_TEST simple data Yinghai Lu
2017-08-05  6:37 ` [PATCH 07/10] PCI: PCI_TEST data from x5-8 Yinghai Lu
2017-08-05  6:37 ` [PATCH 08/10] PCI: PCI_TEST data from x5-8 with zeroed bus number Yinghai Lu

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=20170805063801.15880-3-yinghai@kernel.org \
    --to=yinghai@kernel.org \
    --cc=bhelgaas@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=torvalds@linux-foundation.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).