linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bjorn Helgaas <bhelgaas@google.com>
To: linux-pci@vger.kernel.org
Cc: linux-arch@vger.kernel.org
Subject: [PATCH v2 03/18] PCI: add struct pci_host_bridge_window with CPU/bus address offset
Date: Thu, 09 Feb 2012 19:36:36 -0700	[thread overview]
Message-ID: <20120210023636.10311.79110.stgit@bhelgaas.mtv.corp.google.com> (raw)
In-Reply-To: <20120210023424.10311.82445.stgit@bhelgaas.mtv.corp.google.com>

Some PCI host bridges apply an address offset, so bus addresses on PCI are
different from CPU addresses.  This patch adds a way for architectures to
tell the PCI core about this offset.  For example:

    LIST_HEAD(resources);
    pci_add_resource_offset(&resources, host->io_space, host->io_offset);
    pci_add_resource_offset(&resources, host->mem_space, host->mem_offset);
    pci_scan_root_bus(parent, bus, ops, sysdata, &resources);

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
---
 drivers/pci/bus.c   |   30 +++++++++++++++++++-----------
 drivers/pci/probe.c |   32 +++++++++++++++++++++++---------
 include/linux/pci.h |    9 +++++++++
 3 files changed, 51 insertions(+), 20 deletions(-)

diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
index 398f5d8..4ce5ef2 100644
--- a/drivers/pci/bus.c
+++ b/drivers/pci/bus.c
@@ -18,28 +18,36 @@
 
 #include "pci.h"
 
-void pci_add_resource(struct list_head *resources, struct resource *res)
+void pci_add_resource_offset(struct list_head *resources, struct resource *res,
+			     resource_size_t offset)
 {
-	struct pci_bus_resource *bus_res;
+	struct pci_host_bridge_window *window;
 
-	bus_res = kzalloc(sizeof(struct pci_bus_resource), GFP_KERNEL);
-	if (!bus_res) {
-		printk(KERN_ERR "PCI: can't add bus resource %pR\n", res);
+	window = kzalloc(sizeof(struct pci_host_bridge_window), GFP_KERNEL);
+	if (!window) {
+		printk(KERN_ERR "PCI: can't add host bridge window %pR\n", res);
 		return;
 	}
 
-	bus_res->res = res;
-	list_add_tail(&bus_res->list, resources);
+	window->res = res;
+	window->offset = offset;
+	list_add_tail(&window->list, resources);
+}
+EXPORT_SYMBOL(pci_add_resource_offset);
+
+void pci_add_resource(struct list_head *resources, struct resource *res)
+{
+	pci_add_resource_offset(resources, res, 0);
 }
 EXPORT_SYMBOL(pci_add_resource);
 
 void pci_free_resource_list(struct list_head *resources)
 {
-	struct pci_bus_resource *bus_res, *tmp;
+	struct pci_host_bridge_window *window, *tmp;
 
-	list_for_each_entry_safe(bus_res, tmp, resources, list) {
-		list_del(&bus_res->list);
-		kfree(bus_res);
+	list_for_each_entry_safe(window, tmp, resources, list) {
+		list_del(&window->list);
+		kfree(window);
 	}
 }
 EXPORT_SYMBOL(pci_free_resource_list);
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 2ffe8a3..69c1b11 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -1544,12 +1544,15 @@ unsigned int __devinit pci_scan_child_bus(struct pci_bus *bus)
 struct pci_bus *pci_create_root_bus(struct device *parent, int bus,
 		struct pci_ops *ops, void *sysdata, struct list_head *resources)
 {
-	int error, i;
+	int error;
 	struct pci_host_bridge *bridge;
 	struct pci_bus *b, *b2;
 	struct device *dev;
-	struct pci_bus_resource *bus_res, *n;
+	struct pci_host_bridge_window *window, *n;
 	struct resource *res;
+	resource_size_t offset;
+	char bus_addr[64];
+	char *fmt;
 
 	bridge = kzalloc(sizeof(*bridge), GFP_KERNEL);
 	if (!bridge)
@@ -1599,19 +1602,30 @@ struct pci_bus *pci_create_root_bus(struct device *parent, int bus,
 	b->number = b->secondary = bus;
 
 	bridge->bus = b;
-
-	/* Add initial resources to the bus */
-	list_for_each_entry_safe(bus_res, n, resources, list)
-		list_move_tail(&bus_res->list, &b->resources);
+	INIT_LIST_HEAD(&bridge->windows);
 
 	if (parent)
 		dev_info(parent, "PCI host bridge to bus %s\n", dev_name(&b->dev));
 	else
 		printk(KERN_INFO "PCI host bridge to bus %s\n", dev_name(&b->dev));
 
-	pci_bus_for_each_resource(b, res, i) {
-		if (res)
-			dev_info(&b->dev, "root bus resource %pR\n", res);
+	/* Add initial resources to the bus */
+	list_for_each_entry_safe(window, n, resources, list) {
+		list_move_tail(&window->list, &bridge->windows);
+		res = window->res;
+		offset = window->offset;
+		pci_bus_add_resource(b, res, 0);
+		if (offset) {
+			if (resource_type(res) == IORESOURCE_IO)
+				fmt = " (bus address [%#06llx-%#06llx])";
+			else
+				fmt = " (bus address [%#010llx-%#010llx])";
+			snprintf(bus_addr, sizeof(bus_addr), fmt,
+				 (unsigned long long) (res->start - offset),
+				 (unsigned long long) (res->end - offset));
+		} else
+			bus_addr[0] = '\0';
+		dev_info(&b->dev, "root bus resource %pR%s\n", res, bus_addr);
 	}
 
 	down_write(&pci_bus_sem);
diff --git a/include/linux/pci.h b/include/linux/pci.h
index dfb2b64..35ef2d1 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -388,9 +388,16 @@ static inline void pci_add_saved_cap(struct pci_dev *pci_dev,
 	hlist_add_head(&new_cap->next, &pci_dev->saved_cap_space);
 }
 
+struct pci_host_bridge_window {
+	struct list_head list;
+	struct resource *res;		/* host bridge aperture (CPU address) */
+	resource_size_t offset;		/* bus address + offset = CPU address */
+};
+
 struct pci_host_bridge {
 	struct list_head list;
 	struct pci_bus *bus;		/* root bus */
+	struct list_head windows;	/* pci_host_bridge_windows */
 };
 
 /*
@@ -919,6 +926,8 @@ void pci_release_selected_regions(struct pci_dev *, int);
 
 /* drivers/pci/bus.c */
 void pci_add_resource(struct list_head *resources, struct resource *res);
+void pci_add_resource_offset(struct list_head *resources, struct resource *res,
+			     resource_size_t offset);
 void pci_free_resource_list(struct list_head *resources);
 void pci_bus_add_resource(struct pci_bus *bus, struct resource *res, unsigned int flags);
 struct resource *pci_bus_resource_n(const struct pci_bus *bus, int n);

  parent reply	other threads:[~2012-02-10  2:36 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-10  2:36 [PATCH v2 00/18] add PCI bus-to-resource offset support in core Bjorn Helgaas
2012-02-10  2:36 ` [PATCH v2 01/18] PCI: don't publish new root bus until it's fully initialized Bjorn Helgaas
2012-02-10  2:36 ` [PATCH v2 02/18] PCI: add struct pci_host_bridge and a list of all bridges found Bjorn Helgaas
2012-02-10  3:47   ` Yinghai Lu
2012-02-10  3:47     ` Yinghai Lu
2012-02-10  4:16     ` Bjorn Helgaas
2012-02-10  2:36 ` Bjorn Helgaas [this message]
2012-02-10  2:36   ` [PATCH v2 03/18] PCI: add struct pci_host_bridge_window with CPU/bus address offset Bjorn Helgaas
2012-02-10  3:49   ` Yinghai Lu
2012-02-10  4:37     ` Bjorn Helgaas
2012-02-10  2:36 ` [PATCH v2 04/18] PCI: convert bus addresses to resource when reading BARs Bjorn Helgaas
2012-02-10  2:36 ` [PATCH v2 05/18] PCI: add generic pcibios_resource_to_bus() Bjorn Helgaas
2012-02-10  2:36 ` [PATCH v2 06/18] alpha/PCI: get rid of device resource fixups Bjorn Helgaas
2012-02-10  2:36 ` [PATCH v2 07/18] arm/PCI: " Bjorn Helgaas
2012-02-10  2:36   ` Bjorn Helgaas
2012-02-10  2:37 ` [PATCH v2 08/18] ia64/PCI: SN: convert to pci_scan_root_bus() for correct root bus resources Bjorn Helgaas
2012-02-10  2:46   ` Bjorn Helgaas
2012-02-10  2:37 ` [PATCH v2 09/18] ia64/PCI: get rid of device resource fixups Bjorn Helgaas
2012-02-10  2:37 ` [PATCH v2 10/18] microblaze/PCI: " Bjorn Helgaas
2012-02-10  2:37   ` Bjorn Helgaas
2012-02-10  2:37 ` [PATCH v2 11/18] mips/PCI: " Bjorn Helgaas
2012-02-10  2:37   ` Bjorn Helgaas
2012-02-10  2:43   ` Bjorn Helgaas
2012-02-10  2:37 ` [PATCH v2 12/18] mn10300/PCI: " Bjorn Helgaas
2012-02-10  2:37 ` [PATCH v2 13/18] parisc/PCI: " Bjorn Helgaas
2012-02-10  2:37   ` Bjorn Helgaas
2012-02-10  2:37 ` [PATCH v2 14/18] powerpc/PCI: " Bjorn Helgaas
2012-02-10  2:37   ` Bjorn Helgaas
2012-02-10  2:37 ` [PATCH v2 15/18] sh/PCI: " Bjorn Helgaas
2012-02-10  2:37   ` Bjorn Helgaas
2012-02-10  2:37 ` [PATCH v2 16/18] sparc/PCI: " Bjorn Helgaas
2012-02-10  2:37   ` Bjorn Helgaas
2012-02-10  2:37 ` [PATCH v2 17/18] xtensa/PCI: " Bjorn Helgaas
2012-02-10  2:37 ` [PATCH v2 18/18] PCI: collapse pcibios_resource_to_bus Bjorn Helgaas
2012-02-10  2:37   ` Bjorn Helgaas
2012-02-10  4:03 ` [PATCH v2 00/18] add PCI bus-to-resource offset support in core Yinghai Lu
2012-02-10  4:34   ` Bjorn Helgaas
2012-02-10  4:50     ` Yinghai Lu
2012-02-10 16:55       ` Bjorn Helgaas
2012-02-10 17:20         ` Yinghai Lu
2012-02-10 17:24           ` Bjorn Helgaas
2012-02-10 20:25             ` Yinghai Lu
2012-02-10 20:25               ` Yinghai Lu
2012-02-10 22:37               ` 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=20120210023636.10311.79110.stgit@bhelgaas.mtv.corp.google.com \
    --to=bhelgaas@google.com \
    --cc=linux-arch@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;
as well as URLs for NNTP newsgroup(s).