[HACK] ppc64: small hacks for running on BPA hardware, v2

Arnd Bergmann arnd at arndb.de
Fri Sep 16 16:57:16 EST 2005


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.

Unfortunately, the number of hacks in here is currently
increasing, not decreasing, compared to the previous
patch with this name.

Signed-off-by: Arnd Bergmann <arndb at de.ibm.com>

Index: linux-cg/arch/ppc64/Kconfig
===================================================================
--- linux-cg.orig/arch/ppc64/Kconfig
+++ linux-cg/arch/ppc64/Kconfig
@@ -225,6 +225,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
 
 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
@@ -245,8 +245,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
@@ -278,12 +276,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);
 
@@ -302,6 +310,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 <arndb at de.ibm.com>
+ *
+ * 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 <linux/kernel.h>
+#include <linux/pci.h>
+#include <linux/init.h>
+
+#include <asm/prom.h>
+#include <asm/machdep.h>
+#include <asm/pci-bridge.h>
+
+#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
@@ -54,6 +54,8 @@
 #define DBG(fmt...)
 #endif
 
+extern void bpa_final_fixup(void);
+
 void bpa_get_cpuinfo(struct seq_file *m)
 {
 	struct device_node *root;
@@ -198,6 +200,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)
+#else
 	STD_EXCEPTION_PSERIES(0x100, system_reset)
+#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
@@ -453,7 +453,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
@@ -1613,6 +1613,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
@@ -578,6 +578,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);
 }
 




More information about the Linuxppc64-dev mailing list