[PATCH] pci_bus_address [1/5]

From: Matthew Wilcox <willy_at_debian.org>
Date: 2004-09-04 05:31:33
pci_bus_address() allows one to convert a global system address to a
local PCI bus address.  In Documentation/IO-mapping.txt terms, this is
a phys_to_bus() call, except that we pass the PCI bus or PCI device so
we know which bus is being referred to.

diff -urpNX build-tools/dontdiff linux-2.6/arch/ia64/pci/pci.c hotplug-2.6/arch/ia64/pci/pci.c
--- linux-2.6/arch/ia64/pci/pci.c	2004-07-20 16:05:26.000000000 -0600
+++ hotplug-2.6/arch/ia64/pci/pci.c	2004-09-02 13:10:03.000000000 -0600
@@ -370,6 +371,27 @@ pcibios_fixup_bus (struct pci_bus *b)
 	return;
 }
 
+unsigned long pcibios_bus_address(struct pci_controller *controller,
+		unsigned long addr, int flags)
+{
+	int i;
+	for (i = 0; i < controller->windows; i++) {
+		struct pci_window *window = &controller->window[i];
+		unsigned long offset = window->offset;
+		unsigned long bus_addr = addr - offset;
+		if ((flags & (IORESOURCE_IO | IORESOURCE_MEM)) !=
+				window->resource.flags)
+			continue;
+		if (bus_addr < window->resource.start)
+			continue;
+		if (window->resource.end < bus_addr)
+			continue;
+		return bus_addr;
+	}
+
+	return addr;
+}
+
 void __devinit
 pcibios_update_irq (struct pci_dev *dev, int irq)
 {
diff -urpNX build-tools/dontdiff linux-2.6/include/asm-ia64/pci.h hotplug-2.6/include/asm-ia64/pci.h
--- linux-2.6/include/asm-ia64/pci.h	2004-03-16 08:40:37.000000000 -0700
+++ hotplug-2.6/include/asm-ia64/pci.h	2004-09-02 13:56:21.000000000 -0600
@@ -119,6 +119,12 @@ static inline void pcibios_add_platform_
 {
 }
 
+extern unsigned long pcibios_bus_address(struct pci_controller *,
+		unsigned long, int);
+
+#define pci_bus_address(busdev, addr, flags) \
+		pcibios_bus_address(PCI_CONTROLLER(busdev), (addr), (flags))
+
 /* generic pci stuff */
 #include <asm-generic/pci.h>
 
diff -urpNX build-tools/dontdiff linux-2.6/include/linux/pci.h hotplug-2.6/include/linux/pci.h
--- linux-2.6/include/linux/pci.h	2004-08-13 08:30:23.000000000 -0600
+++ hotplug-2.6/include/linux/pci.h	2004-09-02 13:55:57.000000000 -0600
@@ -951,6 +951,14 @@ static inline int pci_name_bus(char *nam
 
 #endif /* !CONFIG_PCI */
 
+/*
+ * Convert from a global physical address to a bus-local address.  You can
+ * override this in asm/pci.h
+ */
+#ifndef pci_bus_address
+#define pci_bus_address(busdev, addr, flags) (addr)
+#endif
+
 /* these helpers provide future and backwards compatibility
  * for accessing popular PCI BAR info */
 #define pci_resource_start(dev,bar)   ((dev)->resource[(bar)].start)

-- 
"Next the statesmen will invent cheap lies, putting the blame upon 
the nation that is attacked, and every man will be glad of those
conscience-soothing falsities, and will diligently study them, and refuse
to examine any refutations of them; and thus he will by and by convince 
himself that the war is just, and will thank God for the better sleep 
he enjoys after this process of grotesque self-deception." -- Mark Twain
-
To unsubscribe from this list: send the line "unsubscribe linux-ia64" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Received on Fri Sep 3 16:09:38 2004

This archive was generated by hypermail 2.1.8 : 2005-08-02 09:20:30 EST