Path: blob/master/arch/powerpc/platforms/pasemi/setup.c
10819 views
/*1* Copyright (C) 2006-2007 PA Semi, Inc2*3* Authors: Kip Walker, PA Semi4* Olof Johansson, PA Semi5*6* Maintained by: Olof Johansson <[email protected]>7*8* Based on arch/powerpc/platforms/maple/setup.c9*10* This program is free software; you can redistribute it and/or modify11* it under the terms of the GNU General Public License version 2 as12* published by the Free Software Foundation.13*14* This program is distributed in the hope that it will be useful,15* but WITHOUT ANY WARRANTY; without even the implied warranty of16* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the17* GNU General Public License for more details.18*19* You should have received a copy of the GNU General Public License20* along with this program; if not, write to the Free Software21* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA22*/2324#include <linux/errno.h>25#include <linux/kernel.h>26#include <linux/delay.h>27#include <linux/console.h>28#include <linux/pci.h>29#include <linux/of_platform.h>30#include <linux/gfp.h>3132#include <asm/prom.h>33#include <asm/system.h>34#include <asm/iommu.h>35#include <asm/machdep.h>36#include <asm/mpic.h>37#include <asm/smp.h>38#include <asm/time.h>39#include <asm/mmu.h>4041#include <pcmcia/ss.h>42#include <pcmcia/cistpl.h>43#include <pcmcia/ds.h>4445#include "pasemi.h"4647/* SDC reset register, must be pre-mapped at reset time */48static void __iomem *reset_reg;4950/* Various error status registers, must be pre-mapped at MCE time */5152#define MAX_MCE_REGS 3253struct mce_regs {54char *name;55void __iomem *addr;56};5758static struct mce_regs mce_regs[MAX_MCE_REGS];59static int num_mce_regs;60static int nmi_virq = NO_IRQ;616263static void pas_restart(char *cmd)64{65/* Need to put others cpu in hold loop so they're not sleeping */66smp_send_stop();67udelay(10000);68printk("Restarting...\n");69while (1)70out_le32(reset_reg, 0x6000000);71}7273#ifdef CONFIG_SMP74static arch_spinlock_t timebase_lock;75static unsigned long timebase;7677static void __devinit pas_give_timebase(void)78{79unsigned long flags;8081local_irq_save(flags);82hard_irq_disable();83arch_spin_lock(&timebase_lock);84mtspr(SPRN_TBCTL, TBCTL_FREEZE);85isync();86timebase = get_tb();87arch_spin_unlock(&timebase_lock);8889while (timebase)90barrier();91mtspr(SPRN_TBCTL, TBCTL_RESTART);92local_irq_restore(flags);93}9495static void __devinit pas_take_timebase(void)96{97while (!timebase)98smp_rmb();99100arch_spin_lock(&timebase_lock);101set_tb(timebase >> 32, timebase & 0xffffffff);102timebase = 0;103arch_spin_unlock(&timebase_lock);104}105106struct smp_ops_t pas_smp_ops = {107.probe = smp_mpic_probe,108.message_pass = smp_mpic_message_pass,109.kick_cpu = smp_generic_kick_cpu,110.setup_cpu = smp_mpic_setup_cpu,111.give_timebase = pas_give_timebase,112.take_timebase = pas_take_timebase,113};114#endif /* CONFIG_SMP */115116void __init pas_setup_arch(void)117{118#ifdef CONFIG_SMP119/* Setup SMP callback */120smp_ops = &pas_smp_ops;121#endif122/* Lookup PCI hosts */123pas_pci_init();124125#ifdef CONFIG_DUMMY_CONSOLE126conswitchp = &dummy_con;127#endif128129/* Remap SDC register for doing reset */130/* XXXOJN This should maybe come out of the device tree */131reset_reg = ioremap(0xfc101100, 4);132}133134static int __init pas_setup_mce_regs(void)135{136struct pci_dev *dev;137int reg;138139/* Remap various SoC status registers for use by the MCE handler */140141reg = 0;142143dev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa00a, NULL);144while (dev && reg < MAX_MCE_REGS) {145mce_regs[reg].name = kasprintf(GFP_KERNEL,146"mc%d_mcdebug_errsta", reg);147mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0x730);148dev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa00a, dev);149reg++;150}151152dev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa001, NULL);153if (dev && reg+4 < MAX_MCE_REGS) {154mce_regs[reg].name = "iobdbg_IntStatus1";155mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0x438);156reg++;157mce_regs[reg].name = "iobdbg_IOCTbusIntDbgReg";158mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0x454);159reg++;160mce_regs[reg].name = "iobiom_IntStatus";161mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0xc10);162reg++;163mce_regs[reg].name = "iobiom_IntDbgReg";164mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0xc1c);165reg++;166}167168dev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa009, NULL);169if (dev && reg+2 < MAX_MCE_REGS) {170mce_regs[reg].name = "l2csts_IntStatus";171mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0x200);172reg++;173mce_regs[reg].name = "l2csts_Cnt";174mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0x214);175reg++;176}177178num_mce_regs = reg;179180return 0;181}182machine_device_initcall(pasemi, pas_setup_mce_regs);183184static __init void pas_init_IRQ(void)185{186struct device_node *np;187struct device_node *root, *mpic_node;188unsigned long openpic_addr;189const unsigned int *opprop;190int naddr, opplen;191int mpic_flags;192const unsigned int *nmiprop;193struct mpic *mpic;194195mpic_node = NULL;196197for_each_node_by_type(np, "interrupt-controller")198if (of_device_is_compatible(np, "open-pic")) {199mpic_node = np;200break;201}202if (!mpic_node)203for_each_node_by_type(np, "open-pic") {204mpic_node = np;205break;206}207if (!mpic_node) {208printk(KERN_ERR209"Failed to locate the MPIC interrupt controller\n");210return;211}212213/* Find address list in /platform-open-pic */214root = of_find_node_by_path("/");215naddr = of_n_addr_cells(root);216opprop = of_get_property(root, "platform-open-pic", &opplen);217if (!opprop) {218printk(KERN_ERR "No platform-open-pic property.\n");219of_node_put(root);220return;221}222openpic_addr = of_read_number(opprop, naddr);223printk(KERN_DEBUG "OpenPIC addr: %lx\n", openpic_addr);224225mpic_flags = MPIC_PRIMARY | MPIC_LARGE_VECTORS | MPIC_NO_BIAS;226227nmiprop = of_get_property(mpic_node, "nmi-source", NULL);228if (nmiprop)229mpic_flags |= MPIC_ENABLE_MCK;230231mpic = mpic_alloc(mpic_node, openpic_addr,232mpic_flags, 0, 0, "PASEMI-OPIC");233BUG_ON(!mpic);234235mpic_assign_isu(mpic, 0, openpic_addr + 0x10000);236mpic_init(mpic);237/* The NMI/MCK source needs to be prio 15 */238if (nmiprop) {239nmi_virq = irq_create_mapping(NULL, *nmiprop);240mpic_irq_set_priority(nmi_virq, 15);241irq_set_irq_type(nmi_virq, IRQ_TYPE_EDGE_RISING);242mpic_unmask_irq(irq_get_irq_data(nmi_virq));243}244245of_node_put(mpic_node);246of_node_put(root);247}248249static void __init pas_progress(char *s, unsigned short hex)250{251printk("[%04x] : %s\n", hex, s ? s : "");252}253254255static int pas_machine_check_handler(struct pt_regs *regs)256{257int cpu = smp_processor_id();258unsigned long srr0, srr1, dsisr;259int dump_slb = 0;260int i;261262srr0 = regs->nip;263srr1 = regs->msr;264265if (nmi_virq != NO_IRQ && mpic_get_mcirq() == nmi_virq) {266printk(KERN_ERR "NMI delivered\n");267debugger(regs);268mpic_end_irq(irq_get_irq_data(nmi_virq));269goto out;270}271272dsisr = mfspr(SPRN_DSISR);273printk(KERN_ERR "Machine Check on CPU %d\n", cpu);274printk(KERN_ERR "SRR0 0x%016lx SRR1 0x%016lx\n", srr0, srr1);275printk(KERN_ERR "DSISR 0x%016lx DAR 0x%016lx\n", dsisr, regs->dar);276printk(KERN_ERR "BER 0x%016lx MER 0x%016lx\n", mfspr(SPRN_PA6T_BER),277mfspr(SPRN_PA6T_MER));278printk(KERN_ERR "IER 0x%016lx DER 0x%016lx\n", mfspr(SPRN_PA6T_IER),279mfspr(SPRN_PA6T_DER));280printk(KERN_ERR "Cause:\n");281282if (srr1 & 0x200000)283printk(KERN_ERR "Signalled by SDC\n");284285if (srr1 & 0x100000) {286printk(KERN_ERR "Load/Store detected error:\n");287if (dsisr & 0x8000)288printk(KERN_ERR "D-cache ECC double-bit error or bus error\n");289if (dsisr & 0x4000)290printk(KERN_ERR "LSU snoop response error\n");291if (dsisr & 0x2000) {292printk(KERN_ERR "MMU SLB multi-hit or invalid B field\n");293dump_slb = 1;294}295if (dsisr & 0x1000)296printk(KERN_ERR "Recoverable Duptags\n");297if (dsisr & 0x800)298printk(KERN_ERR "Recoverable D-cache parity error count overflow\n");299if (dsisr & 0x400)300printk(KERN_ERR "TLB parity error count overflow\n");301}302303if (srr1 & 0x80000)304printk(KERN_ERR "Bus Error\n");305306if (srr1 & 0x40000) {307printk(KERN_ERR "I-side SLB multiple hit\n");308dump_slb = 1;309}310311if (srr1 & 0x20000)312printk(KERN_ERR "I-cache parity error hit\n");313314if (num_mce_regs == 0)315printk(KERN_ERR "No MCE registers mapped yet, can't dump\n");316else317printk(KERN_ERR "SoC debug registers:\n");318319for (i = 0; i < num_mce_regs; i++)320printk(KERN_ERR "%s: 0x%08x\n", mce_regs[i].name,321in_le32(mce_regs[i].addr));322323if (dump_slb) {324unsigned long e, v;325int i;326327printk(KERN_ERR "slb contents:\n");328for (i = 0; i < mmu_slb_size; i++) {329asm volatile("slbmfee %0,%1" : "=r" (e) : "r" (i));330asm volatile("slbmfev %0,%1" : "=r" (v) : "r" (i));331printk(KERN_ERR "%02d %016lx %016lx\n", i, e, v);332}333}334335out:336/* SRR1[62] is from MSR[62] if recoverable, so pass that back */337return !!(srr1 & 0x2);338}339340static void __init pas_init_early(void)341{342iommu_init_early_pasemi();343}344345#ifdef CONFIG_PCMCIA346static int pcmcia_notify(struct notifier_block *nb, unsigned long action,347void *data)348{349struct device *dev = data;350struct device *parent;351struct pcmcia_device *pdev = to_pcmcia_dev(dev);352353/* We are only intereted in device addition */354if (action != BUS_NOTIFY_ADD_DEVICE)355return 0;356357parent = pdev->socket->dev.parent;358359/* We know electra_cf devices will always have of_node set, since360* electra_cf is an of_platform driver.361*/362if (!parent->of_node)363return 0;364365if (!of_device_is_compatible(parent->of_node, "electra-cf"))366return 0;367368/* We use the direct ops for localbus */369dev->archdata.dma_ops = &dma_direct_ops;370371return 0;372}373374static struct notifier_block pcmcia_notifier = {375.notifier_call = pcmcia_notify,376};377378static inline void pasemi_pcmcia_init(void)379{380extern struct bus_type pcmcia_bus_type;381382bus_register_notifier(&pcmcia_bus_type, &pcmcia_notifier);383}384385#else386387static inline void pasemi_pcmcia_init(void)388{389}390391#endif392393394static struct of_device_id pasemi_bus_ids[] = {395/* Unfortunately needed for legacy firmwares */396{ .type = "localbus", },397{ .type = "sdc", },398/* These are the proper entries, which newer firmware uses */399{ .compatible = "pasemi,localbus", },400{ .compatible = "pasemi,sdc", },401{},402};403404static int __init pasemi_publish_devices(void)405{406pasemi_pcmcia_init();407408/* Publish OF platform devices for SDC and other non-PCI devices */409of_platform_bus_probe(NULL, pasemi_bus_ids, NULL);410411return 0;412}413machine_device_initcall(pasemi, pasemi_publish_devices);414415416/*417* Called very early, MMU is off, device-tree isn't unflattened418*/419static int __init pas_probe(void)420{421unsigned long root = of_get_flat_dt_root();422423if (!of_flat_dt_is_compatible(root, "PA6T-1682M") &&424!of_flat_dt_is_compatible(root, "pasemi,pwrficient"))425return 0;426427hpte_init_native();428429alloc_iobmap_l2();430431return 1;432}433434define_machine(pasemi) {435.name = "PA Semi PWRficient",436.probe = pas_probe,437.setup_arch = pas_setup_arch,438.init_early = pas_init_early,439.init_IRQ = pas_init_IRQ,440.get_irq = mpic_get_irq,441.restart = pas_restart,442.get_boot_time = pas_get_boot_time,443.calibrate_decr = generic_calibrate_decr,444.progress = pas_progress,445.machine_check_exception = pas_machine_check_handler,446};447448449