Skip to contentSkip to conversation

powerpc: Rewrite IO allocation & mapping on powerpc64

RFC/PATCH Benjamin Herrenschmidt 6 participants 18 messages May 14, 2007 – May 15, 2007

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

This patch rewrites pretty much from scratch the handling of MMIO and PIO space allocations on powerpc64. The main goals are:

- Get rid of imalloc and use more common code where possible
- Simplify the current mess so that PIO space is allocated and mapped in a single place for PCI bridges
- Handle allocation constraints of PIO for all bridges including hot plugged ones within the 2GB space reserved for IO ports, so that devices on hotplugged busses will now work with drivers that assume IO ports fit in an int.
- Cleanup and separate tracking of the ISA space in the reserved low 64K of IO space. No ISA -> Nothing mapped there.

The patch is mostly untested ! This is not aimed at 2.6.22 but rather the next merge window since it's pretty big and we need to test well the hotplug stuff among others.

With this patch, all allocations are done using the code in mm/vmalloc.c, though we use the low level __get_vm_area with explicit start/stop constraints in order to manage separate areas for vmalloc/vmap, ioremap, and PCI IOs.

This greatly simplifies a lot of things, as you can see in the diffstat of that patch :-)

A new pair of functions pcibios_map/unmap_io_space() now replace all of the previous code that used to manipulate PCI IOs space. The allocation is done at mapping time, which is now called from scan_phb's, just before the devices are probed (instead of after, which is by itself a bug fix). The only other caller is the PCI hotplug code for hot adding PCI-PCI bridges (slots).

imalloc is gone, as is the "sub-allocation" thing, but I do beleive that hotplug should still work in the sense that the space allocation is always done by the PHB, but if you unmap a child bus of this PHB (which seems to be possible), then the code should properly tear down all the PTE mappings for that area of the PHB allocated IO space.

I now always reserve the first 64K of IO space for the bridge with the ISA bus on it. I have moved the code for tracking ISA in a separate file which should also make it smarter if we ever are capable of hot unplugging or re-plugging an ISA bridge.

This should have a side effect on platforms like powermac where VGA IOs will no longer work. This is done on purpose though as they would have worked semi-randomly before. The idea at this point is to isolate drivers that might need to access those and fix them by providing a proper function to obtain an offset to the legacy IOs of a given bus.

---

Note that it depends on a patch I posted earlier today to add a prototype for __vunmap to include/linux/vmalloc.h

 arch/powerpc/kernel/Makefile                 |    2 
 arch/powerpc/kernel/isa-bridge.c             |  271 +++++++++++++++++++++++
 arch/powerpc/kernel/of_platform.c            |    6 
 arch/powerpc/kernel/pci_64.c                 |  291 +++++++------------------
 arch/powerpc/kernel/rtas_pci.c               |    7 
 arch/powerpc/mm/Makefile                     |    3 
 arch/powerpc/mm/imalloc.c                    |  313 ---------------------------
 arch/powerpc/mm/mmu_decl.h                   |   12 -
 arch/powerpc/mm/pgtable_64.c                 |  201 ++++-------------
 arch/powerpc/platforms/cell/io-workarounds.c |    2 
 arch/powerpc/platforms/maple/pci.c           |   35 ---
 arch/powerpc/platforms/pasemi/pci.c          |   20 -
 arch/powerpc/platforms/powermac/pci.c        |   32 --
 arch/powerpc/platforms/pseries/pci_dlpar.c   |    2 
 drivers/pci/hotplug/rpadlpar_core.c          |    6 
 include/asm-powerpc/floppy.h                 |    6 
 include/asm-powerpc/io.h                     |   15 -
 include/asm-powerpc/pci-bridge.h             |    6 
 include/asm-powerpc/pci.h                    |    4 
 include/asm-powerpc/pgtable-ppc64.h          |   22 +
 include/asm-powerpc/ppc-pci.h                |    2 
 21 files changed, 450 insertions(+), 808 deletions(-)
include/asm-powerpc/pgtable-ppc64.h +15 -7
Index: linux-cell/include/asm-powerpc/pgtable-ppc64.h
===================================================================
@@ -27,7 +27,7 @@ struct mm_struct;
  */
 #define PGTABLE_EADDR_SIZE (PTE_INDEX_SIZE + PMD_INDEX_SIZE + \
                 	    PUD_INDEX_SIZE + PGD_INDEX_SIZE + PAGE_SHIFT)
-#define PGTABLE_RANGE (1UL << PGTABLE_EADDR_SIZE)
+#define PGTABLE_RANGE (ASM_CONST(1) << PGTABLE_EADDR_SIZE)
 
 #if TASK_SIZE_USER64 > PGTABLE_RANGE
 #error TASK_SIZE_USER64 exceeds pagetable range
@@ -37,19 +37,27 @@ struct mm_struct;
 #error TASK_SIZE_USER64 exceeds user VSID range
 #endif
 
+
 /*
  * Define the address range of the vmalloc VM area.
  */
 #define VMALLOC_START ASM_CONST(0xD000000000000000)
-#define VMALLOC_SIZE  ASM_CONST(0x80000000000)
+#define VMALLOC_SIZE  (PGTABLE_RANGE >> 1)
 #define VMALLOC_END   (VMALLOC_START + VMALLOC_SIZE)
 
 /*
- * Define the address range of the imalloc VM area.
- */
-#define PHBS_IO_BASE	VMALLOC_END
-#define IMALLOC_BASE	(PHBS_IO_BASE + 0x80000000ul)	/* Reserve 2 gigs for PHBs */
-#define IMALLOC_END	(VMALLOC_START + PGTABLE_RANGE)
+ * Define the address ranges for MMIO and IO space :
+ *
+ *  ISA_IO_BASE = VMALLOC_END, 64K reserved area
+ *  PHB_IO_BASE = ISA_IO_BASE + 64K to ISA_IO_BASE + 2G, PHB IO spaces
+ * IOREMAP_BASE = ISA_IO_BASE + 2G to VMALLOC_START + PGTABLE_RANGE
+ */
+#define  ISA_IO_BASE	(VMALLOC_END)
+#define  ISA_IO_END	(VMALLOC_END + 0x10000ul)
+#define  PHB_IO_BASE	(ISA_IO_END)
+#define  PHB_IO_END	(VMALLOC_END + 0x80000000ul)
+#define IOREMAP_BASE	(PHB_IO_END)
+#define IOREMAP_END	(VMALLOC_START + PGTABLE_RANGE)
 
 /*
  * Region IDs
arch/powerpc/kernel/Makefile +1 -1
Index: linux-cell/arch/powerpc/kernel/Makefile
===================================================================
@@ -65,7 +65,7 @@ obj-$(CONFIG_PPC_UDBG_16550)	+= legacy_s
 module-$(CONFIG_PPC64)		+= module_64.o
 obj-$(CONFIG_MODULES)		+= $(module-y)
 
-pci64-$(CONFIG_PPC64)		+= pci_64.o pci_dn.o
+pci64-$(CONFIG_PPC64)		+= pci_64.o pci_dn.o isa-bridge.o
 pci32-$(CONFIG_PPC32)		:= pci_32.o
 obj-$(CONFIG_PCI)		+= $(pci64-y) $(pci32-y)
 obj-$(CONFIG_PCI_MSI)		+= msi.o
arch/powerpc/kernel/isa-bridge.c new file +271 -0

271 lines not on this page · raw message

arch/powerpc/kernel/of_platform.c +0 -6
Index: linux-cell/arch/powerpc/kernel/of_platform.c
===================================================================
@@ -427,12 +427,6 @@ static int __devinit of_pci_phb_probe(st
 	/* Process "ranges" property */
 	pci_process_bridge_OF_ranges(phb, dev->node, 0);
 
-	/* Setup IO space.
-	 * This will not work properly for ISA IOs, something needs to be done
-	 * about it if we ever generalize that way of probing PCI brigdes
-	 */
-	pci_setup_phb_io_dynamic(phb, 0);
-
 	/* Init pci_dn data structures */
 	pci_devs_phb_init_dynamic(phb);
 
arch/powerpc/kernel/pci_64.c +91 -200

369 lines not on this page · raw message

arch/powerpc/kernel/rtas_pci.c +2 -5
Index: linux-cell/arch/powerpc/kernel/rtas_pci.c
===================================================================
@@ -278,10 +278,8 @@ void __init find_and_init_phbs(void)
 {
 	struct device_node *node;
 	struct pci_controller *phb;
-	unsigned int index;
 	struct device_node *root = of_find_node_by_path("/");
 
-	index = 0;
 	for (node = of_get_next_child(root, NULL);
 	     node != NULL;
 	     node = of_get_next_child(root, node)) {
@@ -295,8 +293,7 @@ void __init find_and_init_phbs(void)
 			continue;
 		rtas_setup_phb(phb);
 		pci_process_bridge_OF_ranges(phb, node, 0);
-		pci_setup_phb_io(phb, index == 0);
-		index++;
+		isa_bridge_find_early(phb);
 	}
 
 	of_node_put(root);
@@ -335,7 +332,7 @@ int pcibios_remove_root_bus(struct pci_c
 		return 1;
 	}
 
-	rc = unmap_bus_range(b);
+	rc = pcibios_unmap_io_space(b);
 	if (rc) {
 		printk(KERN_ERR "%s: failed to unmap IO on bus %s\n",
 			__FUNCTION__, b->name);
arch/powerpc/mm/imalloc.c deleted +0 -313

313 lines not on this page · raw message

arch/powerpc/mm/mmu_decl.h +0 -12
Index: linux-cell/arch/powerpc/mm/mmu_decl.h
===================================================================
@@ -90,16 +90,4 @@ static inline void flush_HPTE(unsigned c
 	else
 		_tlbie(va);
 }
-#else /* CONFIG_PPC64 */
-/* imalloc region types */
-#define IM_REGION_UNUSED	0x1
-#define IM_REGION_SUBSET	0x2
-#define IM_REGION_EXISTS	0x4
-#define IM_REGION_OVERLAP	0x8
-#define IM_REGION_SUPERSET	0x10
-
-extern struct vm_struct * im_get_free_area(unsigned long size);
-extern struct vm_struct * im_get_area(unsigned long v_addr, unsigned long size,
-				      int region_type);
-extern void im_free(void *addr);
 #endif
arch/powerpc/mm/pgtable_64.c +49 -152

294 lines not on this page · raw message

arch/powerpc/platforms/maple/pci.c +0 -35
Index: linux-cell/arch/powerpc/platforms/maple/pci.c
===================================================================
@@ -519,23 +519,6 @@ void __devinit maple_pci_irq_fixup(struc
 	DBG(" <- maple_pci_irq_fixup\n");
 }
 
-static void __init maple_fixup_phb_resources(void)
-{
-	struct pci_controller *hose, *tmp;
-	
-	list_for_each_entry_safe(hose, tmp, &hose_list, list_node) {
-		unsigned long offset = (unsigned long)hose->io_base_virt - pci_io_base;
-
-		hose->io_resource.start += offset;
-		hose->io_resource.end += offset;
-
-		printk(KERN_INFO "PCI Host %d, io start: %llx; io end: %llx\n",
-		       hose->global_number,
-		       (unsigned long long)hose->io_resource.start,
-		       (unsigned long long)hose->io_resource.end);
-	}
-}
-
 void __init maple_pci_init(void)
 {
 	struct device_node *np, *root;
@@ -573,24 +556,6 @@ void __init maple_pci_init(void)
 	if (ht && add_bridge(ht) != 0)
 		of_node_put(ht);
 
-        /*
-         * We need to call pci_setup_phb_io for the HT bridge first
-         * so it gets the I/O port numbers starting at 0, and we
-         * need to call it for the AGP bridge after that so it gets
-         * small positive I/O port numbers.
-         */
-        if (u3_ht)
-                pci_setup_phb_io(u3_ht, 1);
-        if (u3_agp)
-                pci_setup_phb_io(u3_agp, 0);
-        if (u4_pcie)
-                pci_setup_phb_io(u4_pcie, 0);
-
-	/* Fixup the IO resources on our host bridges as the common code
-	 * does it only for childs of the host bridges
-	 */
-	maple_fixup_phb_resources();
-
 	/* Setup the linkage between OF nodes and PHBs */ 
 	pci_devs_phb_init();
 
arch/powerpc/platforms/pasemi/pci.c +0 -20
Index: linux-cell/arch/powerpc/platforms/pasemi/pci.c
===================================================================
@@ -150,29 +150,11 @@ static int __init add_bridge(struct devi
 	printk(KERN_INFO "Found PA-PXP PCI host bridge.\n");
 
 	/* Interpret the "ranges" property */
-	/* This also maps the I/O region and sets isa_io/mem_base */
 	pci_process_bridge_OF_ranges(hose, dev, 1);
-	pci_setup_phb_io(hose, 1);
 
 	return 0;
 }
 
-
-static void __init pas_fixup_phb_resources(void)
-{
-	struct pci_controller *hose, *tmp;
-
-	list_for_each_entry_safe(hose, tmp, &hose_list, list_node) {
-		unsigned long offset = (unsigned long)hose->io_base_virt - pci_io_base;
-		hose->io_resource.start += offset;
-		hose->io_resource.end += offset;
-		printk(KERN_INFO "PCI Host %d, io start: %lx; io end: %lx\n",
-		       hose->global_number,
-		       hose->io_resource.start, hose->io_resource.end);
-	}
-}
-
-
 void __init pas_pci_init(void)
 {
 	struct device_node *np, *root;
@@ -190,8 +172,6 @@ void __init pas_pci_init(void)
 
 	of_node_put(root);
 
-	pas_fixup_phb_resources();
-
 	/* Setup the linkage between OF nodes and PHBs */
 	pci_devs_phb_init();
 
arch/powerpc/platforms/powermac/pci.c +0 -32
Index: linux-cell/arch/powerpc/platforms/powermac/pci.c
===================================================================
@@ -1006,19 +1006,6 @@ void __devinit pmac_pci_irq_fixup(struct
 #endif /* CONFIG_PPC32 */
 }
 
-#ifdef CONFIG_PPC64
-static void __init pmac_fixup_phb_resources(void)
-{
-	struct pci_controller *hose, *tmp;
-
-	list_for_each_entry_safe(hose, tmp, &hose_list, list_node) {
-		printk(KERN_INFO "PCI Host %d, io start: %lx; io end: %lx\n",
-		       hose->global_number,
-		       hose->io_resource.start, hose->io_resource.end);
-	}
-}
-#endif
-
 void __init pmac_pci_init(void)
 {
 	struct device_node *np, *root;
@@ -1053,25 +1040,6 @@ void __init pmac_pci_init(void)
 	if (ht && add_bridge(ht) != 0)
 		of_node_put(ht);
 
-	/*
-	 * We need to call pci_setup_phb_io for the HT bridge first
-	 * so it gets the I/O port numbers starting at 0, and we
-	 * need to call it for the AGP bridge after that so it gets
-	 * small positive I/O port numbers.
-	 */
-	if (u3_ht)
-		pci_setup_phb_io(u3_ht, 1);
-	if (u3_agp)
-		pci_setup_phb_io(u3_agp, 0);
-	if (u4_pcie)
-		pci_setup_phb_io(u4_pcie, 0);
-
-	/*
-	 * On ppc64, fixup the IO resources on our host bridges as
-	 * the common code does it only for children of the host bridges
-	 */
-	pmac_fixup_phb_resources();
-
 	/* Setup the linkage between OF nodes and PHBs */
 	pci_devs_phb_init();
 
arch/powerpc/platforms/pseries/pci_dlpar.c +0 -2
Index: linux-cell/arch/powerpc/platforms/pseries/pci_dlpar.c
===================================================================
@@ -200,8 +200,6 @@ struct pci_controller * __devinit init_p
 	rtas_setup_phb(phb);
 	pci_process_bridge_OF_ranges(phb, dn, 0);
 
-	pci_setup_phb_io_dynamic(phb, primary);
-
 	pci_devs_phb_init_dynamic(phb);
 
 	if (dn->child)
drivers/pci/hotplug/rpadlpar_core.c +3 -3
Index: linux-cell/drivers/pci/hotplug/rpadlpar_core.c
===================================================================
@@ -159,8 +159,8 @@ static void dlpar_pci_add_bus(struct dev
 	/* Claim new bus resources */
 	pcibios_claim_one_bus(dev->bus);
 
-	/* ioremap() for child bus, which may or may not succeed */
-	remap_bus_range(dev->subordinate);
+	/* Map IO space for child bus, which may or may not succeed */
+	pcibios_map_io_space(dev->subordinate);
 
 	/* Add new devices to global lists.  Register in proc, sysfs. */
 	pci_bus_add_devices(phb->bus);
@@ -390,7 +390,7 @@ int dlpar_remove_pci_slot(char *drc_name
 	} else
 		pcibios_remove_pci_devices(bus);
 
-	if (unmap_bus_range(bus)) {
+	if (pcibios_unmap_io_space(bus)) {
 		printk(KERN_ERR "%s: failed to unmap bus range\n",
 			__FUNCTION__);
 		return -ERANGE;
include/asm-powerpc/pci-bridge.h +6 -0
Index: linux-cell/include/asm-powerpc/pci-bridge.h
===================================================================
@@ -31,6 +31,7 @@ struct pci_controller {
 	int last_busno;
 
 	void __iomem *io_base_virt;
+	void *io_base_alloc;
 	resource_size_t io_base_phys;
 
 	/* Some machines have a non 1:1 mapping of
@@ -164,6 +165,11 @@ static inline unsigned long pci_address_
 }
 #endif
 
+extern void isa_bridge_find_early(struct pci_controller *hose);
+
+extern int pcibios_unmap_io_space(struct pci_bus *bus);
+extern int pcibios_map_io_space(struct pci_bus *bus);
+
 /* Return values for ppc_md.pci_probe_mode function */
 #define PCI_PROBE_NONE		-1	/* Don't look at this bus at all */
 #define PCI_PROBE_NORMAL	0	/* Do normal PCI probing */
include/asm-powerpc/pci.h +0 -4
Index: linux-cell/include/asm-powerpc/pci.h
===================================================================
@@ -220,10 +220,6 @@ static inline struct resource *pcibios_s
 	return root;
 }
 
-extern int unmap_bus_range(struct pci_bus *bus);
-
-extern int remap_bus_range(struct pci_bus *bus);
-
 extern void pcibios_fixup_device_resources(struct pci_dev *dev,
 			struct pci_bus *bus);
 
include/asm-powerpc/io.h +6 -9
Index: linux-cell/include/asm-powerpc/io.h
===================================================================
@@ -607,9 +607,9 @@ static inline void iosync(void)
  *
  * * iounmap undoes such a mapping and can be hooked
  *
- * * __ioremap_explicit (and the pending __iounmap_explicit) are low level
- *   functions to create hand-made mappings for use only by the PCI code
- *   and cannot currently be hooked.
+ * * __ioremap_at (and the pending __iounmap_at) are low level functions to
+ *   create hand-made mappings for use only by the PCI code and cannot
+ *   currently be hooked. Must be page aligned.
  *
  * * __ioremap is the low level implementation used by ioremap and
  *   ioremap_flags and cannot be hooked (but can be used by a hook on one
@@ -629,12 +629,9 @@ extern void __iomem *__ioremap(phys_addr
 			       unsigned long flags);
 extern void __iounmap(volatile void __iomem *addr);
 
-extern int __ioremap_explicit(phys_addr_t p_addr, unsigned long v_addr,
-		     	      unsigned long size, unsigned long flags);
-extern int __iounmap_explicit(volatile void __iomem *start,
-			      unsigned long size);
-
-extern void __iomem * reserve_phb_iospace(unsigned long size);
+extern void __iomem * __ioremap_at(phys_addr_t pa, void *ea,
+				   unsigned long size, unsigned long flags);
+extern void __iounmap_at(void *ea, unsigned long size);
 
 /* Those are more 32 bits only functions */
 extern unsigned long iopa(unsigned long addr);
arch/powerpc/mm/Makefile +1 -2
Index: linux-cell/arch/powerpc/mm/Makefile
===================================================================
@@ -11,8 +11,7 @@ obj-$(CONFIG_PPC32)		+= init_32.o pgtabl
 hash-$(CONFIG_PPC_NATIVE)	:= hash_native_64.o
 obj-$(CONFIG_PPC64)		+= init_64.o pgtable_64.o mmu_context_64.o \
 				   hash_utils_64.o hash_low_64.o tlb_64.o \
-				   slb_low.o slb.o stab.o mmap.o imalloc.o \
-				   $(hash-y)
+				   slb_low.o slb.o stab.o mmap.o $(hash-y)
 obj-$(CONFIG_PPC_STD_MMU_32)	+= ppc_mmu_32.o hash_low_32.o tlb_32.o
 obj-$(CONFIG_40x)		+= 4xx_mmu.o
 obj-$(CONFIG_44x)		+= 44x_mmu.o
arch/powerpc/platforms/cell/io-workarounds.c +1 -1
Index: linux-cell/arch/powerpc/platforms/cell/io-workarounds.c
===================================================================
@@ -102,7 +102,7 @@ static void spider_io_flush(const volati
 		vaddr = (unsigned long)PCI_FIX_ADDR(addr);
 
 		/* Check if it's in allowed range for  PIO */
-		if (vaddr < PHBS_IO_BASE || vaddr >= IMALLOC_BASE)
+		if (vaddr < PHB_IO_BASE || vaddr > PHB_IO_END)
 			return;
 
 		/* Try to find a PTE. If not, clear the paddr, we'll do
include/asm-powerpc/floppy.h +3 -3
Index: linux-cell/include/asm-powerpc/floppy.h
===================================================================
@@ -29,7 +29,7 @@
 #define fd_free_irq()           free_irq(FLOPPY_IRQ, NULL);
 
 #include <linux/pci.h>
-#include <asm/ppc-pci.h>	/* for ppc64_isabridge_dev */
+#include <asm/ppc-pci.h>	/* for isa_bridge_pcidev */
 
 #define fd_dma_setup(addr,size,mode,io) fd_ops->_dma_setup(addr,size,mode,io)
 
@@ -139,12 +139,12 @@ static int hard_dma_setup(char *addr, un
 	if (bus_addr 
 	    && (addr != prev_addr || size != prev_size || dir != prev_dir)) {
 		/* different from last time -- unmap prev */
-		pci_unmap_single(ppc64_isabridge_dev, bus_addr, prev_size, prev_dir);
+		pci_unmap_single(isa_bridge_pcidev, bus_addr, prev_size, prev_dir);
 		bus_addr = 0;
 	}
 
 	if (!bus_addr)	/* need to map it */
-		bus_addr = pci_map_single(ppc64_isabridge_dev, addr, size, dir);
+		bus_addr = pci_map_single(isa_bridge_pcidev, addr, size, dir);
 
 	/* remember this one as prev */
 	prev_addr = addr;
include/asm-powerpc/ppc-pci.h +1 -1
Index: linux-cell/include/asm-powerpc/ppc-pci.h
===================================================================
@@ -26,7 +26,7 @@ extern int global_phb_number;
 
 extern void find_and_init_phbs(void);
 
-extern struct pci_dev *ppc64_isabridge_dev;	/* may be NULL if no ISA bus */
+extern struct pci_dev *isa_bridge_pcidev;	/* may be NULL if no ISA bus */
 
 /** Bus Unit ID macros; get low and hi 32-bits of the 64-bit BUID */
 #define BUID_HI(buid) ((buid) >> 32)
#1 lore raw
Quoted 3 lines

Note that it depends on a patch I posted earlier today to add a prototype for __vunmap to include/linux/vmalloc.h

Actually it's me being stupid, I can just use vunmap() without underscores :-) Oh well, you can still review the patch, I'll add that fix to future versions.

Ben.

#2 lore raw
In reply to Benjamin Herrenschmidt
Quoted 4 lines · Benjamin Herrenschmidt

- Handle allocation constraints of PIO for all bridges including hot plugged ones within the 2GB space reserved for IO ports, so that devices on hotplugged busses will now work with drivers that assume IO ports fit in an int.

Olof, Arnd, that should fix your problem but it's not 2.6.22 material. I'll post a separate patch for 2.6.22 that does a temporary band aid, basically calling pci_setup_phb_io() + remap_bus_range() rather than pci_setup_phb_io_dynamic() from the of_device/PCI code and add a spinlock to reserve_phb_iospace().

I found also a couple of other nits for which I'll do patches for 2.6.22. For example, we don't mask out the "tokens" at the top of IO addresses in iounmap() which means it probably doesn't work on cell. Ouch.

There's a number of other issues that my bigger patch fixes for which I won't bother with a 2.6.22 backport though.

Cheers,
Ben.

#3 lore raw
In reply to Benjamin Herrenschmidt

arch/powerpc/kernel/pci_64.c void __devinit pci_process_bridge_OF_ran · line 1020

Quoted 10 lines
arch/powerpc/kernel/pci_64.c +8 -0
+	/* If this not a PHB, we don't do anything on mapping */
+	if (bus->self) {
+		DBG("IO mapping for PCI-PCI bridge %s\n",
+		    pci_name(bus->self));
+		DBG("  virt=0x%016lx...0x%016lx\n",
+		    bus->resource[0]->start + pci_io_base,
+		    bus->resource[0]->end + pci_io_base);
+		return 0;
 	}

Hrm... the above is incorrect. Since I iounmap_at() when removing a P2P bridge, I need to ioremap_at() when mapping it back in. I'll fix that in the next iteration.

One of the cool thing is that mapping over a previous mapping is harmless, so if the PHB is inserted and create a mapping for the full PHB range, and later on, a P2P is added to this PHB, doing an ioremap_at() will work fine wether that sub-range was part of the initial PHB mapping or wether it was unmapped by a previous removal of a bridge...

Ben.

#4 lore raw
In reply to Benjamin Herrenschmidt
Quoted 5 lines

- Cleanup and separate tracking of the ISA space in the reserved low 64K of IO space. No ISA -> Nothing mapped there.

I now always reserve the first 64K of IO space for the bridge with the ISA bus on it.

This is wrong -- there are systems with ISA that also have PCI devices that require 16-bit legacy I/O windows (e.g., systems with the AMD8111 chip, like Maple).

Or do you mean you reserve the low 64k for the PHB? That would work in this case, but still not in general. Not sure if we care though.

Segher

#9 lore raw
In reply to Benjamin Herrenschmidt

include/asm-powerpc/pgtable-ppc64.h struct mm_struct; · line 60

Quoted 12 lines · Benjamin Herrenschmidt

+ * Define the address ranges for MMIO and IO space :
+ *
+ * ISA_IO_BASE = VMALLOC_END, 64K reserved area
+ * PHB_IO_BASE = ISA_IO_BASE + 64K to ISA_IO_BASE + 2G, PHB IO spaces
+ * IOREMAP_BASE = ISA_IO_BASE + 2G to VMALLOC_START + PGTABLE_RANGE
+ */

include/asm-powerpc/pgtable-ppc64.h +6 -0
+#define  ISA_IO_BASE	(VMALLOC_END)
+#define  ISA_IO_END	(VMALLOC_END + 0x10000ul)
+#define  PHB_IO_BASE	(ISA_IO_END)
+#define  PHB_IO_END	(VMALLOC_END + 0x80000000ul)
+#define IOREMAP_BASE	(PHB_IO_END)
+#define IOREMAP_END	(VMALLOC_START + PGTABLE_RANGE)

Very nice layout, it suddenly all makes sense ;-)

PHB_IO_END should probably be

#define PHB_IO_END (VMALLOC_END + PIO_RESERVED)

At least, that is how I understand the definition of PIO_RESERVED.

Do you think it's ok to not treat the range between 64k and 1M special? There might be ISA drivers that expect devices in there. Maybe we should start PHB_IO_BASE after a 1M guard area where nothing is mapped.

Where should Olof's PCMCIA space go? The ISA or the PHB range?

arch/powerpc/kernel/Makefile obj-$(CONFIG_PPC_UDBG_16550) += legacy_s · line 71

Quoted 13 lines

Index: linux-cell/arch/powerpc/kernel/Makefile
===================================================================

arch/powerpc/kernel/Makefile +1 -1
@@ -65,7 +65,7 @@ obj-$(CONFIG_PPC_UDBG_16550)	+= legacy_s
 module-$(CONFIG_PPC64)		+= module_64.o
 obj-$(CONFIG_MODULES)		+= $(module-y)
 
-pci64-$(CONFIG_PPC64)		+= pci_64.o pci_dn.o
+pci64-$(CONFIG_PPC64)		+= pci_64.o pci_dn.o isa-bridge.o
 pci32-$(CONFIG_PPC32)		:= pci_32.o
 obj-$(CONFIG_PCI)		+= $(pci64-y) $(pci32-y)
 obj-$(CONFIG_PCI_MSI)		+= msi.o

Can we make this depend on CONFIG_ISA? Most platforms don't actually want to build in ISA support.

arch/powerpc/kernel/Makefile line 17

Quoted 9 lines
arch/powerpc/kernel/Makefile +1 -1
@@ -11,7 +11,7 @@
  *      2 of the License, or (at your option) any later version.
  */
 
-#undef DEBUG
+#define DEBUG
 
 #include <linux/kernel.h>
 #include <linux/pci.h>

needs to get reverted of course

Quoted 7 lines

/* pci_io_base -- the base address from which io bars are offsets.
* This is the lowest I/O base address (so bar values are always positive),
* and it *must* be the start of ISA space if an ISA bus exists because
- * ISA drivers use hard coded offsets. If no ISA bus exists a dummy
- * page is mapped and isa_io_limit prevents access to it.
+ * ISA drivers use hard coded offsets.
*/

arch/powerpc/kernel/Makefile

Quoted 7 lines
arch/powerpc/kernel/Makefile +1 -3
-unsigned long isa_io_base;	/* NULL if no ISA bus */
-EXPORT_SYMBOL(isa_io_base);
-unsigned long pci_io_base;
+unsigned long pci_io_base = ISA_IO_BASE;
 EXPORT_SYMBOL(pci_io_base);
 
 void iSeries_pcibios_init(void);

Why do we even need to make pci_io_base a variable? There are not many places where it's used, and they are are read-only. Replacing it with the constant of ISA_IO_BASE should reduce the code size in every driver that uses port access functions.

	Arnd <><
#10 lore raw
Quoted 2 lines

Do you think it's ok to not treat the range between 64k and 1M special? There might be ISA drivers that expect devices in there.

ISA I/O space is 16-bit addressing only.

Quoted 2 lines

Maybe we should
start PHB_IO_BASE after a 1M guard area where nothing is mapped.

This can cause problems, many PCI bridges and devices don't decode all 32 bits of the legacy I/O address space.

Quoted 1 line

Where should Olof's PCMCIA space go? The ISA or the PHB range?

It uses the legacy IDE I/O addresses, so it needs to go to the 64kB space. It isn't ISA though.

Segher

#5 lore raw
In reply to Segher Boessenkool
Quoted 6 lines · Segher Boessenkool
Quoted 5 lines

- Cleanup and separate tracking of the ISA space in the reserved low 64K of IO space. No ISA -> Nothing mapped there.

I now always reserve the first 64K of IO space for the bridge with the ISA bus on it.

Quoted 8 lines

This is wrong -- there are systems with ISA that also have PCI devices that require 16-bit legacy I/O windows (e.g., systems with the AMD8111 chip, like Maple).

Or do you mean you reserve the low 64k for the PHB? That would work in this case, but still not in general. Not sure if we care though.

Yes, if you have an "isa" node, you get a 64k mapping of IO's for your PHB in the first 64K of IO space (in addition to a full mapping elsewhere for devices with proper BARs).

If you don't, you don't get that mapping. I might add a call for platforms to explicitely map those low 64K to a given PCI host though for platforms who really want it.

Ben.

#13 lore raw
In reply to Arnd Bergmann
Quoted 16 lines · Arnd Bergmann

include/asm-powerpc/pgtable-ppc64.h struct mm_struct; · line 60

Quoted 12 lines · Benjamin Herrenschmidt

+ * Define the address ranges for MMIO and IO space :
+ *
+ * ISA_IO_BASE = VMALLOC_END, 64K reserved area
+ * PHB_IO_BASE = ISA_IO_BASE + 64K to ISA_IO_BASE + 2G, PHB IO spaces
+ * IOREMAP_BASE = ISA_IO_BASE + 2G to VMALLOC_START + PGTABLE_RANGE
+ */

include/asm-powerpc/pgtable-ppc64.h +6 -0
+#define  ISA_IO_BASE	(VMALLOC_END)
+#define  ISA_IO_END	(VMALLOC_END + 0x10000ul)
+#define  PHB_IO_BASE	(ISA_IO_END)
+#define  PHB_IO_END	(VMALLOC_END + 0x80000000ul)
+#define IOREMAP_BASE	(PHB_IO_END)
+#define IOREMAP_END	(VMALLOC_START + PGTABLE_RANGE)

Very nice layout, it suddenly all makes sense ;-)

Quoted 5 lines

PHB_IO_END should probably be

#define PHB_IO_END (VMALLOC_END + PIO_RESERVED)

At least, that is how I understand the definition of PIO_RESERVED.

I was wondering what that constant was about ... 0x40000000 doesn't seem good though.

Quoted 3 lines

Do you think it's ok to not treat the range between 64k and 1M special? There might be ISA drivers that expect devices in there. Maybe we should start PHB_IO_BASE after a 1M guard area where nothing is mapped.

I though legacy IO couldn't be above 64 K ? ISA bridges definitely don't forward more than 64K...

Quoted 1 line

Where should Olof's PCMCIA space go? The ISA or the PHB range?

I'm not sure about Olof's issues with pcmcia. Usually, the PCMCIA bridge is expected to remap IOs but I suppose he can have it anywhere as part of the standard PHB ranges, unless he explicitely needs the low IOs.

I want to add a call that archs can do to explicitely bind the low 64K when there is no ISA so he can always bind them to something special.

Quoted 2 lines

Can we make this depend on CONFIG_ISA? Most platforms don't actually want to build in ISA support.

I'm not too sure about that. CONFIG_ISA means you have legacy devices or ISA slots ? or both ?

Quoted 11 lines

arch/powerpc/kernel/pci_64.c line 17

Quoted 9 lines
arch/powerpc/kernel/pci_64.c +1 -1
@@ -11,7 +11,7 @@
  *      2 of the License, or (at your option) any later version.
  */
 
-#undef DEBUG
+#define DEBUG
 
 #include <linux/kernel.h>
 #include <linux/pci.h>

needs to get reverted of course

Sure, that's still very much a WIP patch

Quoted 13 lines
Quoted 13 lines

/* pci_io_base -- the base address from which io bars are offsets.
* This is the lowest I/O base address (so bar values are always positive),
* and it *must* be the start of ISA space if an ISA bus exists because
- * ISA drivers use hard coded offsets. If no ISA bus exists a dummy
- * page is mapped and isa_io_limit prevents access to it.
+ * ISA drivers use hard coded offsets.
*/

arch/powerpc/kernel/pci_64.c +1 -3
-unsigned long isa_io_base;	/* NULL if no ISA bus */
-EXPORT_SYMBOL(isa_io_base);
-unsigned long pci_io_base;
+unsigned long pci_io_base = ISA_IO_BASE;
 EXPORT_SYMBOL(pci_io_base);
Quoted 6 lines
Quoted 1 line

void iSeries_pcibios_init(void);

Why do we even need to make pci_io_base a variable? There are not many places where it's used, and they are are read-only. Replacing it with the constant of ISA_IO_BASE should reduce the code size in every driver that uses port access functions.

I've been thinking about it yes.

Ben.

#14 lore raw
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 2 lines

Can we make this depend on CONFIG_ISA? Most platforms don't actually want to build in ISA support.

I'm not too sure about that. CONFIG_ISA means you have legacy devices or ISA slots ? or both ?

Good point, it means ISA slots, so it's probably not the right option here:

config ISA
bool "Support for ISA-bus hardware"
depends on PPC_PREP || PPC_CHRP
select PPC_I8259
help
Find out whether you have ISA slots on your motherboard. ISA is the name of a bus system, i.e. the way the CPU talks to the other stuff inside your box. If you have an Apple machine, say N here; if you have an IBM RS/6000 or pSeries machine or a PReP machine, say Y. If you have an embedded board, consult your board documentation.

(side note: funny how it recommends to say Y for pSeries, but doesn't allow it ;-).

Maybe we should instead build the new file depending on a new option and make the Kconfig read as

config ISA

	def_bool y
	depends on PPC_PREP || PPC_CHRP
	select PPC_I8259
	select LEGACY_IOPORT
	help
	  This option is for actual ISA slots

config LEGACY_IOPORT

	bool
	# maybe convert some of these into select statements
	default y if PPC_UDBG_16550
	default y if SERIO_I8042  || PPC_I8259 || PARPORT_PC 
	default y if MAPLE || MPC8641_HPCN
	default y if BLK_DEV_FD || PATA_LEGACY || IDE
	default y if VGA_CONSOLE || FB
	help
          This option enables the use of hardcoded PIO port numbers
	  in device drivers.

An interesting case is the frame buffer, most fb drivers use hardcoded register numbers for the VGA ports, without calling check_legacy_ioport, but rely on PCI probing to detect the presence of the device. Some IDE drivers do the same, but libata does not. Apparently, these are already broken if you plug such hardware into a secondary PCI bus.

	Arnd <><
#11 lore raw
In reply to Segher Boessenkool
Quoted 4 lines · Segher Boessenkool
Quoted 1 line

Where should Olof's PCMCIA space go? The ISA or the PHB range?

It uses the legacy IDE I/O addresses, so it needs to go to the 64kB space.

How so? All PCMCIA cards should get configured relative to socket->io_offset. At least that is where the address used in ide_cs.c comes from.

	Arnd <><
#12 lore raw
Quoted 9 lines · Arnd Bergmann
Quoted 4 lines · Segher Boessenkool
Quoted 1 line

Where should Olof's PCMCIA space go? The ISA or the PHB range?

It uses the legacy IDE I/O addresses, so it needs to go to the 64kB space.

How so? All PCMCIA cards should get configured relative to socket->io_offset. At least that is where the address used in ide_cs.c comes from.

And that'll require the ioaddr_t change on powerpc, but a 32-bit value is sufficient.

-Olof

#15 lore raw
In reply to Arnd Bergmann
Quoted 6 lines

An interesting case is the frame buffer, most fb drivers use hardcoded register numbers for the VGA ports, without calling check_legacy_ioport, but rely on PCI probing to detect the presence of the device. Some IDE drivers do the same, but libata does not. Apparently, these are already broken if you plug such hardware into a secondary PCI bus.

VGA is on my todo list for a fix. A lot of framebuffers don't access legacy VGA ports though. I'm pretty sure none of the ATI or nvidia ones do nowadays.

We need three different things I beleive:

- A clean/generic way to obtain the pci_dev for vgacon/vesafb
- A nice hook to provide an IO "offset" for a given PCI bus for legacy accesses (which is allowed to fail if that bus cannot do it).
- Same for VGA memory

Ben.

#6 lore raw
In reply to Segher Boessenkool
Quoted 4 lines · Segher Boessenkool

This is wrong -- there are systems with ISA that
also have PCI devices that require 16-bit legacy
I/O windows (e.g., systems with the AMD8111 chip,
like Maple).

If they are PCI devices and their drivers use a pci_dev's resources to get to the device's I/O resources, then they are fine.

The only reason for reserving the low 64k is to cater for drivers that use a hard-coded port number, e.g. video drivers using the VGA port numbers. We have been gradually getting rid of the hard coded port numbers in drivers but I don't think they're all gone yet.

Paul.

#7 lore raw
Quoted 5 lines
Quoted 4 lines

This is wrong -- there are systems with ISA that
also have PCI devices that require 16-bit legacy
I/O windows (e.g., systems with the AMD8111 chip,
like Maple).

Quoted 7 lines

If they are PCI devices and their drivers use a pci_dev's resources to get to the device's I/O resources, then they are fine.

The only reason for reserving the low 64k is to cater for drivers that use a hard-coded port number, e.g. video drivers using the VGA port numbers. We have been gradually getting rid of the hard coded port numbers in drivers but I don't think they're all gone yet.

Yes, I misunderstood (that teaches me for reading the patch description only, not the patch itself :-) ).

Ben, can we have a config option to _not_ create a mapping for the legacy hardcoded stuff, even if there is an "isa" device node? Some platforms do not need it or want it, and it can help find the remaining drivers that do this x86 nastiness.

Segher

#8 lore raw
Quoted 6 lines · Segher Boessenkool

Ben, can we have a config option to _not_ create a mapping for the legacy hardcoded stuff, even if there is an "isa" device node? Some platforms do not need it or want it, and it can help find the remaining drivers that do this x86 nastiness.

Maybe separately... let's not introduce too much breakage in one patch :-)

Ben.

#16 lore raw
In reply to Benjamin Herrenschmidt

Some comments:

- the comment above __iounmap_at needs some updates
- instead of the fake vm_struct in __iounmap_at just changed the calling conventions for unmap_vm_area to take a start and len value - there's only two callers including the powerpc ioremap code for this. At the same time it might also get a better name.

#17 lore raw
Quoted 7 lines · Christoph Hellwig

Some comments:

- the comment above __iounmap_at needs some updates
- instead of the fake vm_struct in __iounmap_at just changed the calling conventions for unmap_vm_area to take a start and len value - there's only two callers including the powerpc ioremap code for this. At the same time it might also get a better name.

Yeah, good idea, I'll have a look.

Ben.