Path: blob/master/arch/powerpc/platforms/cell/ras.c
10818 views
/*1* Copyright 2006-2008, IBM Corporation.2*3* This program is free software; you can redistribute it and/or4* modify it under the terms of the GNU General Public License5* as published by the Free Software Foundation; either version6* 2 of the License, or (at your option) any later version.7*/89#undef DEBUG1011#include <linux/types.h>12#include <linux/kernel.h>13#include <linux/slab.h>14#include <linux/smp.h>15#include <linux/reboot.h>16#include <linux/kexec.h>17#include <linux/crash_dump.h>1819#include <asm/kexec.h>20#include <asm/reg.h>21#include <asm/io.h>22#include <asm/prom.h>23#include <asm/machdep.h>24#include <asm/rtas.h>25#include <asm/cell-regs.h>2627#include "ras.h"282930static void dump_fir(int cpu)31{32struct cbe_pmd_regs __iomem *pregs = cbe_get_cpu_pmd_regs(cpu);33struct cbe_iic_regs __iomem *iregs = cbe_get_cpu_iic_regs(cpu);3435if (pregs == NULL)36return;3738/* Todo: do some nicer parsing of bits and based on them go down39* to other sub-units FIRs and not only IIC40*/41printk(KERN_ERR "Global Checkstop FIR : 0x%016llx\n",42in_be64(&pregs->checkstop_fir));43printk(KERN_ERR "Global Recoverable FIR : 0x%016llx\n",44in_be64(&pregs->checkstop_fir));45printk(KERN_ERR "Global MachineCheck FIR : 0x%016llx\n",46in_be64(&pregs->spec_att_mchk_fir));4748if (iregs == NULL)49return;50printk(KERN_ERR "IOC FIR : 0x%016llx\n",51in_be64(&iregs->ioc_fir));5253}5455void cbe_system_error_exception(struct pt_regs *regs)56{57int cpu = smp_processor_id();5859printk(KERN_ERR "System Error Interrupt on CPU %d !\n", cpu);60dump_fir(cpu);61dump_stack();62}6364void cbe_maintenance_exception(struct pt_regs *regs)65{66int cpu = smp_processor_id();6768/*69* Nothing implemented for the maintenance interrupt at this point70*/7172printk(KERN_ERR "Unhandled Maintenance interrupt on CPU %d !\n", cpu);73dump_stack();74}7576void cbe_thermal_exception(struct pt_regs *regs)77{78int cpu = smp_processor_id();7980/*81* Nothing implemented for the thermal interrupt at this point82*/8384printk(KERN_ERR "Unhandled Thermal interrupt on CPU %d !\n", cpu);85dump_stack();86}8788static int cbe_machine_check_handler(struct pt_regs *regs)89{90int cpu = smp_processor_id();9192printk(KERN_ERR "Machine Check Interrupt on CPU %d !\n", cpu);93dump_fir(cpu);9495/* No recovery from this code now, lets continue */96return 0;97}9899struct ptcal_area {100struct list_head list;101int nid;102int order;103struct page *pages;104};105106static LIST_HEAD(ptcal_list);107108static int ptcal_start_tok, ptcal_stop_tok;109110static int __init cbe_ptcal_enable_on_node(int nid, int order)111{112struct ptcal_area *area;113int ret = -ENOMEM;114unsigned long addr;115116if (is_kdump_kernel())117rtas_call(ptcal_stop_tok, 1, 1, NULL, nid);118119area = kmalloc(sizeof(*area), GFP_KERNEL);120if (!area)121goto out_err;122123area->nid = nid;124area->order = order;125area->pages = alloc_pages_exact_node(area->nid, GFP_KERNEL|GFP_THISNODE,126area->order);127128if (!area->pages) {129printk(KERN_WARNING "%s: no page on node %d\n",130__func__, area->nid);131goto out_free_area;132}133134/*135* We move the ptcal area to the middle of the allocated136* page, in order to avoid prefetches in memcpy and similar137* functions stepping on it.138*/139addr = __pa(page_address(area->pages)) + (PAGE_SIZE >> 1);140printk(KERN_DEBUG "%s: enabling PTCAL on node %d address=0x%016lx\n",141__func__, area->nid, addr);142143ret = -EIO;144if (rtas_call(ptcal_start_tok, 3, 1, NULL, area->nid,145(unsigned int)(addr >> 32),146(unsigned int)(addr & 0xffffffff))) {147printk(KERN_ERR "%s: error enabling PTCAL on node %d!\n",148__func__, nid);149goto out_free_pages;150}151152list_add(&area->list, &ptcal_list);153154return 0;155156out_free_pages:157__free_pages(area->pages, area->order);158out_free_area:159kfree(area);160out_err:161return ret;162}163164static int __init cbe_ptcal_enable(void)165{166const u32 *size;167struct device_node *np;168int order, found_mic = 0;169170np = of_find_node_by_path("/rtas");171if (!np)172return -ENODEV;173174size = of_get_property(np, "ibm,cbe-ptcal-size", NULL);175if (!size) {176of_node_put(np);177return -ENODEV;178}179180pr_debug("%s: enabling PTCAL, size = 0x%x\n", __func__, *size);181order = get_order(*size);182of_node_put(np);183184/* support for malta device trees, with be@/mic@ nodes */185for_each_node_by_type(np, "mic-tm") {186cbe_ptcal_enable_on_node(of_node_to_nid(np), order);187found_mic = 1;188}189190if (found_mic)191return 0;192193/* support for older device tree - use cpu nodes */194for_each_node_by_type(np, "cpu") {195const u32 *nid = of_get_property(np, "node-id", NULL);196if (!nid) {197printk(KERN_ERR "%s: node %s is missing node-id?\n",198__func__, np->full_name);199continue;200}201cbe_ptcal_enable_on_node(*nid, order);202found_mic = 1;203}204205return found_mic ? 0 : -ENODEV;206}207208static int cbe_ptcal_disable(void)209{210struct ptcal_area *area, *tmp;211int ret = 0;212213pr_debug("%s: disabling PTCAL\n", __func__);214215list_for_each_entry_safe(area, tmp, &ptcal_list, list) {216/* disable ptcal on this node */217if (rtas_call(ptcal_stop_tok, 1, 1, NULL, area->nid)) {218printk(KERN_ERR "%s: error disabling PTCAL "219"on node %d!\n", __func__,220area->nid);221ret = -EIO;222continue;223}224225/* ensure we can access the PTCAL area */226memset(page_address(area->pages), 0,2271 << (area->order + PAGE_SHIFT));228229/* clean up */230list_del(&area->list);231__free_pages(area->pages, area->order);232kfree(area);233}234235return ret;236}237238static int cbe_ptcal_notify_reboot(struct notifier_block *nb,239unsigned long code, void *data)240{241return cbe_ptcal_disable();242}243244static void cbe_ptcal_crash_shutdown(void)245{246cbe_ptcal_disable();247}248249static struct notifier_block cbe_ptcal_reboot_notifier = {250.notifier_call = cbe_ptcal_notify_reboot251};252253#ifdef CONFIG_PPC_IBM_CELL_RESETBUTTON254static int sysreset_hack;255256static int __init cbe_sysreset_init(void)257{258struct cbe_pmd_regs __iomem *regs;259260sysreset_hack = of_machine_is_compatible("IBM,CBPLUS-1.0");261if (!sysreset_hack)262return 0;263264regs = cbe_get_cpu_pmd_regs(0);265if (!regs)266return 0;267268/* Enable JTAG system-reset hack */269out_be32(®s->fir_mode_reg,270in_be32(®s->fir_mode_reg) |271CBE_PMD_FIR_MODE_M8);272273return 0;274}275device_initcall(cbe_sysreset_init);276277int cbe_sysreset_hack(void)278{279struct cbe_pmd_regs __iomem *regs;280281/*282* The BMC can inject user triggered system reset exceptions,283* but cannot set the system reset reason in srr1,284* so check an extra register here.285*/286if (sysreset_hack && (smp_processor_id() == 0)) {287regs = cbe_get_cpu_pmd_regs(0);288if (!regs)289return 0;290if (in_be64(®s->ras_esc_0) & 0x0000ffff) {291out_be64(®s->ras_esc_0, 0);292return 0;293}294}295return 1;296}297#endif /* CONFIG_PPC_IBM_CELL_RESETBUTTON */298299int __init cbe_ptcal_init(void)300{301int ret;302ptcal_start_tok = rtas_token("ibm,cbe-start-ptcal");303ptcal_stop_tok = rtas_token("ibm,cbe-stop-ptcal");304305if (ptcal_start_tok == RTAS_UNKNOWN_SERVICE306|| ptcal_stop_tok == RTAS_UNKNOWN_SERVICE)307return -ENODEV;308309ret = register_reboot_notifier(&cbe_ptcal_reboot_notifier);310if (ret)311goto out1;312313ret = crash_shutdown_register(&cbe_ptcal_crash_shutdown);314if (ret)315goto out2;316317return cbe_ptcal_enable();318319out2:320unregister_reboot_notifier(&cbe_ptcal_reboot_notifier);321out1:322printk(KERN_ERR "Can't disable PTCAL, so not enabling\n");323return ret;324}325326arch_initcall(cbe_ptcal_init);327328void __init cbe_ras_init(void)329{330unsigned long hid0;331332/*333* Enable System Error & thermal interrupts and wakeup conditions334*/335336hid0 = mfspr(SPRN_HID0);337hid0 |= HID0_CBE_THERM_INT_EN | HID0_CBE_THERM_WAKEUP |338HID0_CBE_SYSERR_INT_EN | HID0_CBE_SYSERR_WAKEUP;339mtspr(SPRN_HID0, hid0);340mb();341342/*343* Install machine check handler. Leave setting of precise mode to344* what the firmware did for now345*/346ppc_md.machine_check_exception = cbe_machine_check_handler;347mb();348349/*350* For now, we assume that IOC_FIR is already set to forward some351* error conditions to the System Error handler. If that is not true352* then it will have to be fixed up here.353*/354}355356357