Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * Copyright 2006-2008, IBM Corporation.
0004  */
0005 
0006 #undef DEBUG
0007 
0008 #include <linux/types.h>
0009 #include <linux/kernel.h>
0010 #include <linux/slab.h>
0011 #include <linux/smp.h>
0012 #include <linux/reboot.h>
0013 #include <linux/kexec.h>
0014 #include <linux/crash_dump.h>
0015 #include <linux/of.h>
0016 
0017 #include <asm/kexec.h>
0018 #include <asm/reg.h>
0019 #include <asm/io.h>
0020 #include <asm/machdep.h>
0021 #include <asm/rtas.h>
0022 #include <asm/cell-regs.h>
0023 
0024 #include "ras.h"
0025 
0026 
0027 static void dump_fir(int cpu)
0028 {
0029     struct cbe_pmd_regs __iomem *pregs = cbe_get_cpu_pmd_regs(cpu);
0030     struct cbe_iic_regs __iomem *iregs = cbe_get_cpu_iic_regs(cpu);
0031 
0032     if (pregs == NULL)
0033         return;
0034 
0035     /* Todo: do some nicer parsing of bits and based on them go down
0036      * to other sub-units FIRs and not only IIC
0037      */
0038     printk(KERN_ERR "Global Checkstop FIR    : 0x%016llx\n",
0039            in_be64(&pregs->checkstop_fir));
0040     printk(KERN_ERR "Global Recoverable FIR  : 0x%016llx\n",
0041            in_be64(&pregs->checkstop_fir));
0042     printk(KERN_ERR "Global MachineCheck FIR : 0x%016llx\n",
0043            in_be64(&pregs->spec_att_mchk_fir));
0044 
0045     if (iregs == NULL)
0046         return;
0047     printk(KERN_ERR "IOC FIR                 : 0x%016llx\n",
0048            in_be64(&iregs->ioc_fir));
0049 
0050 }
0051 
0052 DEFINE_INTERRUPT_HANDLER(cbe_system_error_exception)
0053 {
0054     int cpu = smp_processor_id();
0055 
0056     printk(KERN_ERR "System Error Interrupt on CPU %d !\n", cpu);
0057     dump_fir(cpu);
0058     dump_stack();
0059 }
0060 
0061 DEFINE_INTERRUPT_HANDLER(cbe_maintenance_exception)
0062 {
0063     int cpu = smp_processor_id();
0064 
0065     /*
0066      * Nothing implemented for the maintenance interrupt at this point
0067      */
0068 
0069     printk(KERN_ERR "Unhandled Maintenance interrupt on CPU %d !\n", cpu);
0070     dump_stack();
0071 }
0072 
0073 DEFINE_INTERRUPT_HANDLER(cbe_thermal_exception)
0074 {
0075     int cpu = smp_processor_id();
0076 
0077     /*
0078      * Nothing implemented for the thermal interrupt at this point
0079      */
0080 
0081     printk(KERN_ERR "Unhandled Thermal interrupt on CPU %d !\n", cpu);
0082     dump_stack();
0083 }
0084 
0085 static int cbe_machine_check_handler(struct pt_regs *regs)
0086 {
0087     int cpu = smp_processor_id();
0088 
0089     printk(KERN_ERR "Machine Check Interrupt on CPU %d !\n", cpu);
0090     dump_fir(cpu);
0091 
0092     /* No recovery from this code now, lets continue */
0093     return 0;
0094 }
0095 
0096 struct ptcal_area {
0097     struct list_head list;
0098     int nid;
0099     int order;
0100     struct page *pages;
0101 };
0102 
0103 static LIST_HEAD(ptcal_list);
0104 
0105 static int ptcal_start_tok, ptcal_stop_tok;
0106 
0107 static int __init cbe_ptcal_enable_on_node(int nid, int order)
0108 {
0109     struct ptcal_area *area;
0110     int ret = -ENOMEM;
0111     unsigned long addr;
0112 
0113     if (is_kdump_kernel())
0114         rtas_call(ptcal_stop_tok, 1, 1, NULL, nid);
0115 
0116     area = kmalloc(sizeof(*area), GFP_KERNEL);
0117     if (!area)
0118         goto out_err;
0119 
0120     area->nid = nid;
0121     area->order = order;
0122     area->pages = __alloc_pages_node(area->nid,
0123                         GFP_KERNEL|__GFP_THISNODE,
0124                         area->order);
0125 
0126     if (!area->pages) {
0127         printk(KERN_WARNING "%s: no page on node %d\n",
0128             __func__, area->nid);
0129         goto out_free_area;
0130     }
0131 
0132     /*
0133      * We move the ptcal area to the middle of the allocated
0134      * page, in order to avoid prefetches in memcpy and similar
0135      * functions stepping on it.
0136      */
0137     addr = __pa(page_address(area->pages)) + (PAGE_SIZE >> 1);
0138     printk(KERN_DEBUG "%s: enabling PTCAL on node %d address=0x%016lx\n",
0139             __func__, area->nid, addr);
0140 
0141     ret = -EIO;
0142     if (rtas_call(ptcal_start_tok, 3, 1, NULL, area->nid,
0143                 (unsigned int)(addr >> 32),
0144                 (unsigned int)(addr & 0xffffffff))) {
0145         printk(KERN_ERR "%s: error enabling PTCAL on node %d!\n",
0146                 __func__, nid);
0147         goto out_free_pages;
0148     }
0149 
0150     list_add(&area->list, &ptcal_list);
0151 
0152     return 0;
0153 
0154 out_free_pages:
0155     __free_pages(area->pages, area->order);
0156 out_free_area:
0157     kfree(area);
0158 out_err:
0159     return ret;
0160 }
0161 
0162 static int __init cbe_ptcal_enable(void)
0163 {
0164     const u32 *size;
0165     struct device_node *np;
0166     int order, found_mic = 0;
0167 
0168     np = of_find_node_by_path("/rtas");
0169     if (!np)
0170         return -ENODEV;
0171 
0172     size = of_get_property(np, "ibm,cbe-ptcal-size", NULL);
0173     if (!size) {
0174         of_node_put(np);
0175         return -ENODEV;
0176     }
0177 
0178     pr_debug("%s: enabling PTCAL, size = 0x%x\n", __func__, *size);
0179     order = get_order(*size);
0180     of_node_put(np);
0181 
0182     /* support for malta device trees, with be@/mic@ nodes */
0183     for_each_node_by_type(np, "mic-tm") {
0184         cbe_ptcal_enable_on_node(of_node_to_nid(np), order);
0185         found_mic = 1;
0186     }
0187 
0188     if (found_mic)
0189         return 0;
0190 
0191     /* support for older device tree - use cpu nodes */
0192     for_each_node_by_type(np, "cpu") {
0193         const u32 *nid = of_get_property(np, "node-id", NULL);
0194         if (!nid) {
0195             printk(KERN_ERR "%s: node %pOF is missing node-id?\n",
0196                     __func__, np);
0197             continue;
0198         }
0199         cbe_ptcal_enable_on_node(*nid, order);
0200         found_mic = 1;
0201     }
0202 
0203     return found_mic ? 0 : -ENODEV;
0204 }
0205 
0206 static int cbe_ptcal_disable(void)
0207 {
0208     struct ptcal_area *area, *tmp;
0209     int ret = 0;
0210 
0211     pr_debug("%s: disabling PTCAL\n", __func__);
0212 
0213     list_for_each_entry_safe(area, tmp, &ptcal_list, list) {
0214         /* disable ptcal on this node */
0215         if (rtas_call(ptcal_stop_tok, 1, 1, NULL, area->nid)) {
0216             printk(KERN_ERR "%s: error disabling PTCAL "
0217                     "on node %d!\n", __func__,
0218                     area->nid);
0219             ret = -EIO;
0220             continue;
0221         }
0222 
0223         /* ensure we can access the PTCAL area */
0224         memset(page_address(area->pages), 0,
0225                 1 << (area->order + PAGE_SHIFT));
0226 
0227         /* clean up */
0228         list_del(&area->list);
0229         __free_pages(area->pages, area->order);
0230         kfree(area);
0231     }
0232 
0233     return ret;
0234 }
0235 
0236 static int cbe_ptcal_notify_reboot(struct notifier_block *nb,
0237         unsigned long code, void *data)
0238 {
0239     return cbe_ptcal_disable();
0240 }
0241 
0242 static void cbe_ptcal_crash_shutdown(void)
0243 {
0244     cbe_ptcal_disable();
0245 }
0246 
0247 static struct notifier_block cbe_ptcal_reboot_notifier = {
0248     .notifier_call = cbe_ptcal_notify_reboot
0249 };
0250 
0251 #ifdef CONFIG_PPC_IBM_CELL_RESETBUTTON
0252 static int sysreset_hack;
0253 
0254 static int __init cbe_sysreset_init(void)
0255 {
0256     struct cbe_pmd_regs __iomem *regs;
0257 
0258     sysreset_hack = of_machine_is_compatible("IBM,CBPLUS-1.0");
0259     if (!sysreset_hack)
0260         return 0;
0261 
0262     regs = cbe_get_cpu_pmd_regs(0);
0263     if (!regs)
0264         return 0;
0265 
0266     /* Enable JTAG system-reset hack */
0267     out_be32(&regs->fir_mode_reg,
0268         in_be32(&regs->fir_mode_reg) |
0269         CBE_PMD_FIR_MODE_M8);
0270 
0271     return 0;
0272 }
0273 device_initcall(cbe_sysreset_init);
0274 
0275 int cbe_sysreset_hack(void)
0276 {
0277     struct cbe_pmd_regs __iomem *regs;
0278 
0279     /*
0280      * The BMC can inject user triggered system reset exceptions,
0281      * but cannot set the system reset reason in srr1,
0282      * so check an extra register here.
0283      */
0284     if (sysreset_hack && (smp_processor_id() == 0)) {
0285         regs = cbe_get_cpu_pmd_regs(0);
0286         if (!regs)
0287             return 0;
0288         if (in_be64(&regs->ras_esc_0) & 0x0000ffff) {
0289             out_be64(&regs->ras_esc_0, 0);
0290             return 0;
0291         }
0292     }
0293     return 1;
0294 }
0295 #endif /* CONFIG_PPC_IBM_CELL_RESETBUTTON */
0296 
0297 static int __init cbe_ptcal_init(void)
0298 {
0299     int ret;
0300     ptcal_start_tok = rtas_token("ibm,cbe-start-ptcal");
0301     ptcal_stop_tok = rtas_token("ibm,cbe-stop-ptcal");
0302 
0303     if (ptcal_start_tok == RTAS_UNKNOWN_SERVICE
0304             || ptcal_stop_tok == RTAS_UNKNOWN_SERVICE)
0305         return -ENODEV;
0306 
0307     ret = register_reboot_notifier(&cbe_ptcal_reboot_notifier);
0308     if (ret)
0309         goto out1;
0310 
0311     ret = crash_shutdown_register(&cbe_ptcal_crash_shutdown);
0312     if (ret)
0313         goto out2;
0314 
0315     return cbe_ptcal_enable();
0316 
0317 out2:
0318     unregister_reboot_notifier(&cbe_ptcal_reboot_notifier);
0319 out1:
0320     printk(KERN_ERR "Can't disable PTCAL, so not enabling\n");
0321     return ret;
0322 }
0323 
0324 arch_initcall(cbe_ptcal_init);
0325 
0326 void __init cbe_ras_init(void)
0327 {
0328     unsigned long hid0;
0329 
0330     /*
0331      * Enable System Error & thermal interrupts and wakeup conditions
0332      */
0333 
0334     hid0 = mfspr(SPRN_HID0);
0335     hid0 |= HID0_CBE_THERM_INT_EN | HID0_CBE_THERM_WAKEUP |
0336         HID0_CBE_SYSERR_INT_EN | HID0_CBE_SYSERR_WAKEUP;
0337     mtspr(SPRN_HID0, hid0);
0338     mb();
0339 
0340     /*
0341      * Install machine check handler. Leave setting of precise mode to
0342      * what the firmware did for now
0343      */
0344     ppc_md.machine_check_exception = cbe_machine_check_handler;
0345     mb();
0346 
0347     /*
0348      * For now, we assume that IOC_FIR is already set to forward some
0349      * error conditions to the System Error handler. If that is not true
0350      * then it will have to be fixed up here.
0351      */
0352 }