small hacks for running on BPA hardware, v3 This patch is not meant for inclusion in a generic kernel, but is currently needed to support the available HW. Most of the things done in here are workarounds for deficiencies in the present hardware or firmware that will be solved there in later releases. Signed-off-by: Arnd Bergmann --- arch/ppc64/Kconfig | 6 ++ arch/ppc64/kernel/Makefile | 2 arch/ppc64/kernel/bpa_iommu.c | 13 +++- arch/ppc64/kernel/bpa_pci.c | 83 +++++++++++++++++++++++++++++ arch/ppc64/kernel/bpa_setup.c | 3 + arch/ppc64/kernel/head.S | 44 +++++++++++++++ arch/ppc64/kernel/idle.c | 2 arch/ppc64/kernel/nvram.c | 114 +++++++++++++++++++---------------------- arch/ppc64/kernel/prom_init.c | 2 arch/ppc64/kernel/spider-pic.c | 16 +++-- arch/ppc64/kernel/spu_base.c | 4 + drivers/ide/pci/siimage.c | 2 include/asm-ppc64/processor.h | 2 include/linux/pci_ids.h | 2 14 files changed, 225 insertions(+), 70 deletions(-) Index: linux-cg/arch/ppc64/Kconfig =================================================================== --- linux-cg.orig/arch/ppc64/Kconfig +++ linux-cg/arch/ppc64/Kconfig @@ -221,6 +221,12 @@ config SMP If you don't know what to do here, say Y. +config BE_DD2 + bool "BE DD2.x Errata Workaround Support" + depends on PPC_BPA + ---help--- + This support enables BE DD2.x errata workarounds. + config NR_CPUS int "Maximum number of CPUs (2-128)" range 2 128 Index: linux-cg/arch/ppc64/kernel/Makefile =================================================================== --- linux-cg.orig/arch/ppc64/kernel/Makefile +++ linux-cg/arch/ppc64/kernel/Makefile @@ -33,7 +33,7 @@ obj-$(CONFIG_PPC_PSERIES) += pSeries_pci pSeries_nvram.o rtasd.o ras.o pSeries_reconfig.o \ pSeries_setup.o pSeries_iommu.o udbg_16550.o -obj-$(CONFIG_PPC_BPA) += bpa_setup.o bpa_iommu.o bpa_nvram.o \ +obj-$(CONFIG_PPC_BPA) += bpa_setup.o bpa_iommu.o bpa_nvram.o bpa_pci.o \ bpa_iic.o spider-pic.o bpa_pmd.o obj-$(CONFIG_KEXEC) += machine_kexec.o Index: linux-cg/arch/ppc64/kernel/bpa_iommu.c =================================================================== --- linux-cg.orig/arch/ppc64/kernel/bpa_iommu.c +++ linux-cg/arch/ppc64/kernel/bpa_iommu.c @@ -249,8 +249,6 @@ set_iocmd_config(void __iomem *base) } /* FIXME: get these from the device tree */ -#define ioc_base 0x20000511000ull -#define ioc_mmio_base 0x20000510000ull #define ioid 0x48a #define iopt_phys_offset (- 0x20000000) /* We have a 512MB offset from the SB */ #define io_page_size 0x1000000 @@ -282,12 +280,22 @@ static void bpa_map_iommu(void) void __iomem *base; ioste ioste; unsigned long index; + struct device_node *node; + unsigned long *handle, ioc_mmio_base, ioc_base; + int nodelen; + + for(node = of_find_node_by_type(NULL, "cpu"); + node; + node = of_find_node_by_type(node, "cpu")) { + handle = (unsigned long *) get_property(node, "ioc-translation", &nodelen); + ioc_base = *handle + 0x1000; base = __ioremap(ioc_base, 0x1000, _PAGE_NO_CACHE); pr_debug("%lx mapped to %p\n", ioc_base, base); set_iocmd_config(base); iounmap(base); + ioc_mmio_base = *handle; base = __ioremap(ioc_mmio_base, 0x1000, _PAGE_NO_CACHE); pr_debug("%lx mapped to %p\n", ioc_mmio_base, base); @@ -306,6 +314,7 @@ static void bpa_map_iommu(void) map_iopt_entry(address)); } iounmap(base); + } } Index: linux-cg/arch/ppc64/kernel/bpa_pci.c =================================================================== --- /dev/null +++ linux-cg/arch/ppc64/kernel/bpa_pci.c @@ -0,0 +1,83 @@ +/* + * BPA specific PCI code + * + * Copyright (C) 2005 IBM Corporation, + Arnd Bergmann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include + +#include +#include +#include + +#include "pci.h" +#include "bpa_iic.h" + +void __init bpa_final_fixup(void) +{ + struct pci_dev *dev = NULL; + + phbs_remap_io(); + + for_each_pci_dev(dev) { + // FIXME: fix IRQ numbers for devices on second south bridge + } +} + +static void fixup_spider_ipci_irq(struct pci_dev* dev) +{ + int irq_node_offset; + pr_debug("fixup for %04x:%04x at %02x.%1x: ", dev->vendor, dev->device, + PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn)); + switch (dev->devfn) { + case PCI_DEVFN(3,0): + /* ethernet */ + dev->irq = 8; + break; + case PCI_DEVFN(5,0): + /* OHCI 0 */ + dev->irq = 10; + break; + case PCI_DEVFN(6,0): + /* OHCI 1 */ + dev->irq = 11; + break; + case PCI_DEVFN(5,1): + /* EHCI 0 */ + dev->irq = 10; + break; + case PCI_DEVFN(6,1): + /* EHCI 1 */ + dev->irq = 11; + break; + } + + irq_node_offset = IIC_NODE_STRIDE * (pci_domain_nr(dev->bus)-1); + dev->irq += irq_node_offset; + + pr_debug("irq %0x\n", dev->irq); +} + +DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_TOSHIBA_2, + PCI_DEVICE_ID_TOSHIBA_SPIDER_NET, fixup_spider_ipci_irq); +DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_TOSHIBA_2, + PCI_DEVICE_ID_TOSHIBA_SPIDER_OHCI, fixup_spider_ipci_irq); +DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_TOSHIBA_2, + PCI_DEVICE_ID_TOSHIBA_SPIDER_EHCI, fixup_spider_ipci_irq); Index: linux-cg/arch/ppc64/kernel/bpa_setup.c =================================================================== --- linux-cg.orig/arch/ppc64/kernel/bpa_setup.c +++ linux-cg/arch/ppc64/kernel/bpa_setup.c @@ -55,6 +55,8 @@ #define DBG(fmt...) #endif +extern void bpa_final_fixup(void); + void bpa_get_cpuinfo(struct seq_file *m) { struct device_node *root; @@ -206,6 +208,7 @@ struct machdep_calls __initdata bpa_md = .setup_arch = bpa_setup_arch, .init_early = bpa_init_early, .get_cpuinfo = bpa_get_cpuinfo, + .pcibios_fixup = bpa_final_fixup, .restart = rtas_restart, .power_off = rtas_power_off, .halt = rtas_halt, Index: linux-cg/arch/ppc64/kernel/head.S =================================================================== --- linux-cg.orig/arch/ppc64/kernel/head.S +++ linux-cg/arch/ppc64/kernel/head.S @@ -304,6 +304,38 @@ label##_pSeries: \ RUNLATCH_ON(r13); \ EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common) +#define WORKAROUND_EXCEPTION_PSERIES(n, label) \ + . = n; \ + .globl label##_pSeries; \ +label##_pSeries: \ + mtspr SPRG1,r21; /* save r21 */ \ + mfspr r21, SPRN_CTRLF; \ + oris r21, r21, 0x00C0; \ + mtspr SPRN_CTRLT, r21; \ + mfspr r21,SPRG1; /* restore r21 */ \ + mtspr SPRG1,r13; /* save r13 */ \ + EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common) + +#define RES_EXCEPTION_PSERIES(n, label) \ + . = n; \ + .globl label##_pSeries; \ +label##_pSeries: \ + mtspr SPRG2,r20; /* use SPRG2 as scratch reg */ \ + mtspr SPRG1,r21; /* use SPRG1 as scratch reg */ \ + mfspr r20,SPRG3; /* get paca virtual address */ \ + cmpdi r20,0x0; /* if SPRG3 zero,thread */ \ + bne 20f; /* shouldn't run */ \ +18: /* Stop current Thread */ \ + andi. r21,0,0; \ + mtspr SPRN_CTRLT,r21; \ +19: \ + b 19b; /* Thread should be stopped */ \ +20: \ + HMT_MEDIUM; \ + mtspr SPRG1,r13; /* save r13 */ \ + RUNLATCH_ON(r13); \ + EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common) + #define STD_EXCEPTION_ISERIES(n, label, area) \ .globl label##_iSeries; \ label##_iSeries: \ @@ -383,7 +415,11 @@ label##_common: \ .globl __start_interrupts __start_interrupts: +#ifdef CONFIG_BE_DD2 + RES_EXCEPTION_PSERIES(0x100, system_reset_check) +#else STD_EXCEPTION_PSERIES(0x100, system_reset_check) +#endif . = 0x200 _machine_check_pSeries: @@ -451,11 +487,19 @@ instruction_access_slb_pSeries: mfspr r3,SRR0 /* SRR0 is faulting address */ b .do_slb_miss /* Rel. branch works in real mode */ +#ifdef CONFIG_BE_DD2 + WORKAROUND_EXCEPTION_PSERIES(0x500, hardware_interrupt) +#else STD_EXCEPTION_PSERIES(0x500, hardware_interrupt) +#endif STD_EXCEPTION_PSERIES(0x600, alignment) STD_EXCEPTION_PSERIES(0x700, program_check) STD_EXCEPTION_PSERIES(0x800, fp_unavailable) +#ifdef CONFIG_BE_DD2 + WORKAROUND_EXCEPTION_PSERIES(0x900, decrementer) +#else STD_EXCEPTION_PSERIES(0x900, decrementer) +#endif STD_EXCEPTION_PSERIES(0xa00, trap_0a) STD_EXCEPTION_PSERIES(0xb00, trap_0b) Index: linux-cg/arch/ppc64/kernel/prom_init.c =================================================================== --- linux-cg.orig/arch/ppc64/kernel/prom_init.c +++ linux-cg/arch/ppc64/kernel/prom_init.c @@ -1367,6 +1367,8 @@ static int __init prom_find_machine_type return PLATFORM_POWERMAC; if (strstr(p, RELOC("Momentum,Maple"))) return PLATFORM_MAPLE; + if (strstr(p, RELOC("IBM,CPB"))) + return PLATFORM_BPA; i += sl + 1; } } Index: linux-cg/arch/ppc64/kernel/spider-pic.c =================================================================== --- linux-cg.orig/arch/ppc64/kernel/spider-pic.c +++ linux-cg/arch/ppc64/kernel/spider-pic.c @@ -84,10 +84,11 @@ static void __iomem *spider_get_irq_conf static void spider_enable_irq(unsigned int irq) { + int nodeid = (irq / IIC_NODE_STRIDE) * 0x10; void __iomem *cfg = spider_get_irq_config(irq); irq = spider_get_nr(irq); - out_be32(cfg, in_be32(cfg) | 0x3107000eu); + out_be32(cfg, in_be32(cfg) | 0x3107000eu | nodeid); out_be32(cfg + 4, in_be32(cfg + 4) | 0x00020000u | irq); } @@ -150,13 +151,17 @@ int spider_get_irq(unsigned long int_pen void spider_init_IRQ(void) { int node; +#if 0 struct device_node *dn; unsigned int *property; +#endif long spiderpic; + long pics[] = { 0x24000008000, 0x34000008000 }; int n; /* FIXME: detect multiple PICs as soon as the device tree has them */ - for (node = 0; node < 1; node++) { + for (node = 0; node < num_present_cpus()/2; node++) { +#if 0 dn = of_find_node_by_path("/"); n = prom_n_addr_cells(dn); property = (unsigned int *) get_property(dn, @@ -166,11 +171,14 @@ void spider_init_IRQ(void) continue; for (spiderpic = 0; n > 0; --n) spiderpic = (spiderpic << 32) + *property++; +#endif + spiderpic = pics[node]; printk(KERN_DEBUG "SPIDER addr: %lx\n", spiderpic); spider_pics[node] = __ioremap(spiderpic, 0x800, _PAGE_NO_CACHE); for (n = 0; n < IIC_NUM_EXT; n++) { int irq = n + IIC_EXT_OFFSET + node * IIC_NODE_STRIDE; get_irq_desc(irq)->handler = &spider_pic; + } /* do not mask any interrupts because of level */ out_be32(spider_pics[node] + TIR_MSK, 0x0); @@ -184,8 +192,6 @@ void spider_init_IRQ(void) /* Enable the interrupt detection enable bit. Do this last! */ out_be32(spider_pics[node] + TIR_DEN, - in_be32(spider_pics[node] +TIR_DEN) | 0x1); - - } + in_be32(spider_pics[node] + TIR_DEN) | 0x1); } } Index: linux-cg/include/asm-ppc64/processor.h =================================================================== --- linux-cg.orig/include/asm-ppc64/processor.h +++ linux-cg/include/asm-ppc64/processor.h @@ -464,7 +464,7 @@ struct thread_struct { .fs = KERNEL_DS, \ .fpr = {0}, \ .fpscr = 0, \ - .fpexc_mode = MSR_FE0|MSR_FE1, \ + .fpexc_mode = 0, \ } /* Index: linux-cg/include/linux/pci_ids.h =================================================================== --- linux-cg.orig/include/linux/pci_ids.h +++ linux-cg/include/linux/pci_ids.h @@ -1651,6 +1651,8 @@ #define PCI_DEVICE_ID_TOSHIBA_TX4927 0x0180 #define PCI_DEVICE_ID_TOSHIBA_TC86C001_MISC 0x0108 #define PCI_DEVICE_ID_TOSHIBA_SPIDER_NET 0x01b3 +#define PCI_DEVICE_ID_TOSHIBA_SPIDER_OHCI 0x01b6 +#define PCI_DEVICE_ID_TOSHIBA_SPIDER_EHCI 0x01b5 #define PCI_VENDOR_ID_RICOH 0x1180 #define PCI_DEVICE_ID_RICOH_RL5C465 0x0465 Index: linux-cg/arch/ppc64/kernel/spu_base.c =================================================================== --- linux-cg.orig/arch/ppc64/kernel/spu_base.c +++ linux-cg/arch/ppc64/kernel/spu_base.c @@ -595,6 +595,10 @@ static void __iomem * __init map_spe_pro prop = p; + /* FIXME: Firmware bug */ + if (strcmp (name, "priv2") == 0 && prop->len < 0x20000) + return ioremap(prop->address, 0x20000); + return ioremap(prop->address, prop->len); } Index: linux-cg/arch/ppc64/kernel/idle.c =================================================================== --- linux-cg.orig/arch/ppc64/kernel/idle.c +++ linux-cg/arch/ppc64/kernel/idle.c @@ -44,8 +44,10 @@ int default_idle(void) while (!need_resched() && !cpu_is_offline(cpu)) { ppc64_runlatch_off(); +#if !(defined(CONFIG_BE_DD1) || defined(CONFIG_BE_DD2)) if (cpu_has_feature(CPU_FTR_PAUSE_ZERO)) pause_zero(); +#endif /* * Go into low thread priority and possibly * low power mode. Index: linux-cg/arch/ppc64/kernel/nvram.c =================================================================== --- linux-cg.orig/arch/ppc64/kernel/nvram.c +++ linux-cg/arch/ppc64/kernel/nvram.c @@ -81,80 +81,74 @@ static loff_t dev_nvram_llseek(struct fi static ssize_t dev_nvram_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) { - ssize_t len; - char *tmp_buffer; - int size; + ssize_t ret; + char *tmp = NULL; + ssize_t size; + + ret = -ENODEV; + if (!ppc_md.nvram_size) + goto out; - if (ppc_md.nvram_size == NULL) - return -ENODEV; + ret = 0; size = ppc_md.nvram_size(); + if (*ppos >= size || size < 0) + goto out; - if (!access_ok(VERIFY_WRITE, buf, count)) - return -EFAULT; - if (*ppos >= size) - return 0; - if (count > size) - count = size; - - tmp_buffer = (char *) kmalloc(count, GFP_KERNEL); - if (!tmp_buffer) { - printk(KERN_ERR "dev_read_nvram: kmalloc failed\n"); - return -ENOMEM; - } - - len = ppc_md.nvram_read(tmp_buffer, count, ppos); - if ((long)len <= 0) { - kfree(tmp_buffer); - return len; - } - - if (copy_to_user(buf, tmp_buffer, len)) { - kfree(tmp_buffer); - return -EFAULT; - } + count = min_t(size_t, count, size - *ppos); + count = min(count, PAGE_SIZE); - kfree(tmp_buffer); - return len; + ret = -ENOMEM; + tmp = kmalloc(count, GFP_KERNEL); + if (!tmp) + goto out; + + ret = ppc_md.nvram_read(tmp, count, ppos); + if (ret <= 0) + goto out; + + if (copy_to_user(buf, tmp, ret)) + ret = -EFAULT; + +out: + kfree(tmp); + return ret; } static ssize_t dev_nvram_write(struct file *file, const char __user *buf, - size_t count, loff_t *ppos) + size_t count, loff_t *ppos) { - ssize_t len; - char * tmp_buffer; - int size; + ssize_t ret; + char *tmp = NULL; + ssize_t size; + + ret = -ENODEV; + if (!ppc_md.nvram_size) + goto out; - if (ppc_md.nvram_size == NULL) - return -ENODEV; + ret = 0; size = ppc_md.nvram_size(); + if (*ppos >= size || size < 0) + goto out; - if (!access_ok(VERIFY_READ, buf, count)) - return -EFAULT; - if (*ppos >= size) - return 0; - if (count > size) - count = size; - - tmp_buffer = (char *) kmalloc(count, GFP_KERNEL); - if (!tmp_buffer) { - printk(KERN_ERR "dev_nvram_write: kmalloc failed\n"); - return -ENOMEM; - } - - if (copy_from_user(tmp_buffer, buf, count)) { - kfree(tmp_buffer); - return -EFAULT; - } + count = min_t(size_t, count, size - *ppos); + count = min(count, PAGE_SIZE); - len = ppc_md.nvram_write(tmp_buffer, count, ppos); - if ((long)len <= 0) { - kfree(tmp_buffer); - return len; - } + ret = -ENOMEM; + tmp = kmalloc(count, GFP_KERNEL); + if (!tmp) + goto out; + + ret = -EFAULT; + if (copy_from_user(tmp, buf, count)) + goto out; + + ret = ppc_md.nvram_write(tmp, count, ppos); + +out: + kfree(tmp); + return ret; - kfree(tmp_buffer); - return len; } static int dev_nvram_ioctl(struct inode *inode, struct file *file, Index: linux-cg/drivers/ide/pci/siimage.c =================================================================== --- linux-cg.orig/drivers/ide/pci/siimage.c +++ linux-cg/drivers/ide/pci/siimage.c @@ -1082,7 +1082,7 @@ static void __devinit init_hwif_siimage( .fixup = siimage_fixup, \ .channels = 2, \ .autodma = AUTODMA, \ - .bootable = ON_BOARD, \ + .bootable = OFF_BOARD, \ } static ide_pci_device_t siimage_chipsets[] __devinitdata = { --