powerpc: Rewrite IO allocation & mapping on powerpc64
Subsystems (5)
PATCH 1/1 powerpc: Rewrite IO allocation & mapping on powerpc64
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.
I booted a cell blade with IDE on PIO and MMIO and a dual G5 so far, that's it :-)
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 HPTE 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.
---
Applied on top of whatever else I posted today. This version fixes things here or there and adds more debugging. I no longer tear down the PTEs when a PCI 2 PCI bridge is unplugged as such mappings might be smaller than 64K pages on machines with 4K IOs. I flush the hash table instead (and introduced a new call for that).
arch/powerpc/kernel/Makefile | 2 arch/powerpc/kernel/isa-bridge.c | 271 ++++++++++++++++++++ arch/powerpc/kernel/of_platform.c | 8 arch/powerpc/kernel/pci_64.c | 354 +++++++++------------------ 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 | 205 +++------------ arch/powerpc/mm/tlb_64.c | 56 ++++ arch/powerpc/platforms/cell/io-workarounds.c | 2 arch/powerpc/platforms/iseries/pci.c | 5 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 arch/powerpc/platforms/pseries/pseries.h | 2 drivers/pci/hotplug/rpadlpar_core.c | 6 include/asm-powerpc/floppy.h | 6 include/asm-powerpc/io.h | 19 - include/asm-powerpc/pci-bridge.h | 6 include/asm-powerpc/pci.h | 4 include/asm-powerpc/pgtable-ppc64.h | 23 + include/asm-powerpc/ppc-pci.h | 6 include/asm-powerpc/tlbflush.h | 5 25 files changed, 556 insertions(+), 848 deletions(-)
include/asm-powerpc/pgtable-ppc64.h +16 -7
@@ -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,28 @@ 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 FULL_IO_SIZE 0x80000000ul +#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 + FULL_IO_SIZE) +#define IOREMAP_BASE (PHB_IO_END) +#define IOREMAP_END (VMALLOC_START + PGTABLE_RANGE)/* * Region IDs
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
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 -8
@@ -427,14 +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. We use the non-dynamic version of that code here, -* which doesn't quite support unplugging. Next kernel release will -* have a better fix for this. -* Note also that we don't do ISA, this will also be fixed with a -* more massive rework. -*/ -pci_setup_phb_io (phb,0 ); -/* Init pci_dn data structures */ pci_devs_phb_init_dynamic (phb);
arch/powerpc/kernel/pci_64.c +124 -230
488 lines not on this page · raw message
arch/powerpc/kernel/rtas_pci.c +2 -5
@@ -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_creturn 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
@@ -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 -156
298 lines not on this page · raw message
arch/powerpc/platforms/maple/pci.c +0 -35
@@ -519,23 +519,6 @@ void __devinit maple_pci_irq_fixup(strucDBG (" <- 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
@@ -150,29 +150,11 @@ static int __init add_bridge(struct deviprintk (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
@@ -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
@@ -200,8 +200,6 @@ struct pci_controller * __devinit init_prtas_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
@@ -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
@@ -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
@@ -220,10 +220,6 @@ static inline struct resource *pcibios_sreturn 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 +8 -11
@@ -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);
@@ -651,8 +648,8 @@ extern void io_block_mapping(unsigned lo*/ #define HAVE_ARCH_PIO_SIZE 1#define PIO_OFFSET 0x00000000UL -#define PIO_MASK 0x3fffffffUL -#define PIO_RESERVED 0x40000000UL +#define PIO_MASK (FULL_IO_SIZE - 1) +#define PIO_RESERVED (FULL_IO_SIZE)#define mmio_read16be (addr) readw_be(addr)#define mmio_read32be (addr) readl_be(addr)
arch/powerpc/mm/Makefile +1 -2
@@ -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
@@ -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
@@ -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, unif (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 +3 -3
@@ -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)
@@ -47,8 +47,8 @@ extern void init_pci_config_tokens (voidextern unsigned long get_phb_buid (struct device_node *);extern int rtas_setup_phb (struct pci_controller *phb); -/* From pSeries_pci.h */ -extern void pSeries_final_fixup (void ); +/* From iSeries PCI */ +extern void iSeries_pcibios_init (void );extern unsigned long pci_probe_only;
arch/powerpc/mm/tlb_64.c +56 -0
59 lines not on this page · raw message
include/asm-powerpc/tlbflush.h +5 -0
@@ -155,6 +155,11 @@ static inline void flush_tlb_kernel_rang { } +/* Private function for use by PCI IO mapping code */ +extern void __flush_hash_table_range (struct mm_struct *mm,unsigned long start, +unsigned long end); + +#endif /*
arch/powerpc/platforms/iseries/pci.c +5 -0
@@ -742,6 +742,11 @@ void __init iSeries_pcibios_init(void)/* Install IO hooks */ ppc_pci_io = iseries_pci_io; +/* iSeries has no IO space in the common sense, it needs to set +* the IO base to 0 +*/ + pci_io_base =0 ; +if (root ==NULL ) {printk (KERN_CRIT "iSeries_pcibios_init: can't find root " "of device tree\n" );
arch/powerpc/platforms/pseries/pseries.h +2 -0
@@ -33,6 +33,8 @@ static inline void setup_kexec_cpu_down_static inline void setup_kexec_cpu_down_mpic (void ) { }#endif +extern void pSeries_final_fixup (void ); +/* Poweron flag used for enabling auto ups restart */ extern unsigned long rtas_poweron_auto;