1*1da177e4SLinus Torvalds #include <linux/kallsyms.h> 2*1da177e4SLinus Torvalds #include <linux/kernel.h> 3*1da177e4SLinus Torvalds #include <linux/mmzone.h> 4*1da177e4SLinus Torvalds #include <linux/nodemask.h> 5*1da177e4SLinus Torvalds #include <linux/spinlock.h> 6*1da177e4SLinus Torvalds #include <linux/smp.h> 7*1da177e4SLinus Torvalds #include <asm/atomic.h> 8*1da177e4SLinus Torvalds #include <asm/sn/types.h> 9*1da177e4SLinus Torvalds #include <asm/sn/addrs.h> 10*1da177e4SLinus Torvalds #include <asm/sn/nmi.h> 11*1da177e4SLinus Torvalds #include <asm/sn/arch.h> 12*1da177e4SLinus Torvalds #include <asm/sn/sn0/hub.h> 13*1da177e4SLinus Torvalds 14*1da177e4SLinus Torvalds #if 0 15*1da177e4SLinus Torvalds #define NODE_NUM_CPUS(n) CNODE_NUM_CPUS(n) 16*1da177e4SLinus Torvalds #else 17*1da177e4SLinus Torvalds #define NODE_NUM_CPUS(n) CPUS_PER_NODE 18*1da177e4SLinus Torvalds #endif 19*1da177e4SLinus Torvalds 20*1da177e4SLinus Torvalds #define CNODEID_NONE (cnodeid_t)-1 21*1da177e4SLinus Torvalds #define enter_panic_mode() spin_lock(&nmi_lock) 22*1da177e4SLinus Torvalds 23*1da177e4SLinus Torvalds typedef unsigned long machreg_t; 24*1da177e4SLinus Torvalds 25*1da177e4SLinus Torvalds DEFINE_SPINLOCK(nmi_lock); 26*1da177e4SLinus Torvalds 27*1da177e4SLinus Torvalds /* 28*1da177e4SLinus Torvalds * Lets see what else we need to do here. Set up sp, gp? 29*1da177e4SLinus Torvalds */ 30*1da177e4SLinus Torvalds void nmi_dump(void) 31*1da177e4SLinus Torvalds { 32*1da177e4SLinus Torvalds void cont_nmi_dump(void); 33*1da177e4SLinus Torvalds 34*1da177e4SLinus Torvalds cont_nmi_dump(); 35*1da177e4SLinus Torvalds } 36*1da177e4SLinus Torvalds 37*1da177e4SLinus Torvalds void install_cpu_nmi_handler(int slice) 38*1da177e4SLinus Torvalds { 39*1da177e4SLinus Torvalds nmi_t *nmi_addr; 40*1da177e4SLinus Torvalds 41*1da177e4SLinus Torvalds nmi_addr = (nmi_t *)NMI_ADDR(get_nasid(), slice); 42*1da177e4SLinus Torvalds if (nmi_addr->call_addr) 43*1da177e4SLinus Torvalds return; 44*1da177e4SLinus Torvalds nmi_addr->magic = NMI_MAGIC; 45*1da177e4SLinus Torvalds nmi_addr->call_addr = (void *)nmi_dump; 46*1da177e4SLinus Torvalds nmi_addr->call_addr_c = 47*1da177e4SLinus Torvalds (void *)(~((unsigned long)(nmi_addr->call_addr))); 48*1da177e4SLinus Torvalds nmi_addr->call_parm = 0; 49*1da177e4SLinus Torvalds } 50*1da177e4SLinus Torvalds 51*1da177e4SLinus Torvalds /* 52*1da177e4SLinus Torvalds * Copy the cpu registers which have been saved in the IP27prom format 53*1da177e4SLinus Torvalds * into the eframe format for the node under consideration. 54*1da177e4SLinus Torvalds */ 55*1da177e4SLinus Torvalds 56*1da177e4SLinus Torvalds void nmi_cpu_eframe_save(nasid_t nasid, int slice) 57*1da177e4SLinus Torvalds { 58*1da177e4SLinus Torvalds struct reg_struct *nr; 59*1da177e4SLinus Torvalds int i; 60*1da177e4SLinus Torvalds 61*1da177e4SLinus Torvalds /* Get the pointer to the current cpu's register set. */ 62*1da177e4SLinus Torvalds nr = (struct reg_struct *) 63*1da177e4SLinus Torvalds (TO_UNCAC(TO_NODE(nasid, IP27_NMI_KREGS_OFFSET)) + 64*1da177e4SLinus Torvalds slice * IP27_NMI_KREGS_CPU_SIZE); 65*1da177e4SLinus Torvalds 66*1da177e4SLinus Torvalds printk("NMI nasid %d: slice %d\n", nasid, slice); 67*1da177e4SLinus Torvalds 68*1da177e4SLinus Torvalds /* 69*1da177e4SLinus Torvalds * Saved main processor registers 70*1da177e4SLinus Torvalds */ 71*1da177e4SLinus Torvalds for (i = 0; i < 32; ) { 72*1da177e4SLinus Torvalds if ((i % 4) == 0) 73*1da177e4SLinus Torvalds printk("$%2d :", i); 74*1da177e4SLinus Torvalds printk(" %016lx", nr->gpr[i]); 75*1da177e4SLinus Torvalds 76*1da177e4SLinus Torvalds i++; 77*1da177e4SLinus Torvalds if ((i % 4) == 0) 78*1da177e4SLinus Torvalds printk("\n"); 79*1da177e4SLinus Torvalds } 80*1da177e4SLinus Torvalds 81*1da177e4SLinus Torvalds printk("Hi : (value lost)\n"); 82*1da177e4SLinus Torvalds printk("Lo : (value lost)\n"); 83*1da177e4SLinus Torvalds 84*1da177e4SLinus Torvalds /* 85*1da177e4SLinus Torvalds * Saved cp0 registers 86*1da177e4SLinus Torvalds */ 87*1da177e4SLinus Torvalds printk("epc : %016lx ", nr->epc); 88*1da177e4SLinus Torvalds print_symbol("%s ", nr->epc); 89*1da177e4SLinus Torvalds printk("%s\n", print_tainted()); 90*1da177e4SLinus Torvalds printk("ErrEPC: %016lx ", nr->error_epc); 91*1da177e4SLinus Torvalds print_symbol("%s\n", nr->error_epc); 92*1da177e4SLinus Torvalds printk("ra : %016lx ", nr->gpr[31]); 93*1da177e4SLinus Torvalds print_symbol("%s\n", nr->gpr[31]); 94*1da177e4SLinus Torvalds printk("Status: %08lx ", nr->sr); 95*1da177e4SLinus Torvalds 96*1da177e4SLinus Torvalds if (nr->sr & ST0_KX) 97*1da177e4SLinus Torvalds printk("KX "); 98*1da177e4SLinus Torvalds if (nr->sr & ST0_SX) 99*1da177e4SLinus Torvalds printk("SX "); 100*1da177e4SLinus Torvalds if (nr->sr & ST0_UX) 101*1da177e4SLinus Torvalds printk("UX "); 102*1da177e4SLinus Torvalds 103*1da177e4SLinus Torvalds switch (nr->sr & ST0_KSU) { 104*1da177e4SLinus Torvalds case KSU_USER: 105*1da177e4SLinus Torvalds printk("USER "); 106*1da177e4SLinus Torvalds break; 107*1da177e4SLinus Torvalds case KSU_SUPERVISOR: 108*1da177e4SLinus Torvalds printk("SUPERVISOR "); 109*1da177e4SLinus Torvalds break; 110*1da177e4SLinus Torvalds case KSU_KERNEL: 111*1da177e4SLinus Torvalds printk("KERNEL "); 112*1da177e4SLinus Torvalds break; 113*1da177e4SLinus Torvalds default: 114*1da177e4SLinus Torvalds printk("BAD_MODE "); 115*1da177e4SLinus Torvalds break; 116*1da177e4SLinus Torvalds } 117*1da177e4SLinus Torvalds 118*1da177e4SLinus Torvalds if (nr->sr & ST0_ERL) 119*1da177e4SLinus Torvalds printk("ERL "); 120*1da177e4SLinus Torvalds if (nr->sr & ST0_EXL) 121*1da177e4SLinus Torvalds printk("EXL "); 122*1da177e4SLinus Torvalds if (nr->sr & ST0_IE) 123*1da177e4SLinus Torvalds printk("IE "); 124*1da177e4SLinus Torvalds printk("\n"); 125*1da177e4SLinus Torvalds 126*1da177e4SLinus Torvalds printk("Cause : %08lx\n", nr->cause); 127*1da177e4SLinus Torvalds printk("PrId : %08x\n", read_c0_prid()); 128*1da177e4SLinus Torvalds printk("BadVA : %016lx\n", nr->badva); 129*1da177e4SLinus Torvalds printk("CErr : %016lx\n", nr->cache_err); 130*1da177e4SLinus Torvalds printk("NMI_SR: %016lx\n", nr->nmi_sr); 131*1da177e4SLinus Torvalds 132*1da177e4SLinus Torvalds printk("\n"); 133*1da177e4SLinus Torvalds } 134*1da177e4SLinus Torvalds 135*1da177e4SLinus Torvalds void nmi_dump_hub_irq(nasid_t nasid, int slice) 136*1da177e4SLinus Torvalds { 137*1da177e4SLinus Torvalds hubreg_t mask0, mask1, pend0, pend1; 138*1da177e4SLinus Torvalds 139*1da177e4SLinus Torvalds if (slice == 0) { /* Slice A */ 140*1da177e4SLinus Torvalds mask0 = REMOTE_HUB_L(nasid, PI_INT_MASK0_A); 141*1da177e4SLinus Torvalds mask1 = REMOTE_HUB_L(nasid, PI_INT_MASK1_A); 142*1da177e4SLinus Torvalds } else { /* Slice B */ 143*1da177e4SLinus Torvalds mask0 = REMOTE_HUB_L(nasid, PI_INT_MASK0_B); 144*1da177e4SLinus Torvalds mask1 = REMOTE_HUB_L(nasid, PI_INT_MASK1_B); 145*1da177e4SLinus Torvalds } 146*1da177e4SLinus Torvalds 147*1da177e4SLinus Torvalds pend0 = REMOTE_HUB_L(nasid, PI_INT_PEND0); 148*1da177e4SLinus Torvalds pend1 = REMOTE_HUB_L(nasid, PI_INT_PEND1); 149*1da177e4SLinus Torvalds 150*1da177e4SLinus Torvalds printk("PI_INT_MASK0: %16lx PI_INT_MASK1: %16lx\n", mask0, mask1); 151*1da177e4SLinus Torvalds printk("PI_INT_PEND0: %16lx PI_INT_PEND1: %16lx\n", pend0, pend1); 152*1da177e4SLinus Torvalds printk("\n\n"); 153*1da177e4SLinus Torvalds } 154*1da177e4SLinus Torvalds 155*1da177e4SLinus Torvalds /* 156*1da177e4SLinus Torvalds * Copy the cpu registers which have been saved in the IP27prom format 157*1da177e4SLinus Torvalds * into the eframe format for the node under consideration. 158*1da177e4SLinus Torvalds */ 159*1da177e4SLinus Torvalds void nmi_node_eframe_save(cnodeid_t cnode) 160*1da177e4SLinus Torvalds { 161*1da177e4SLinus Torvalds nasid_t nasid; 162*1da177e4SLinus Torvalds int slice; 163*1da177e4SLinus Torvalds 164*1da177e4SLinus Torvalds /* Make sure that we have a valid node */ 165*1da177e4SLinus Torvalds if (cnode == CNODEID_NONE) 166*1da177e4SLinus Torvalds return; 167*1da177e4SLinus Torvalds 168*1da177e4SLinus Torvalds nasid = COMPACT_TO_NASID_NODEID(cnode); 169*1da177e4SLinus Torvalds if (nasid == INVALID_NASID) 170*1da177e4SLinus Torvalds return; 171*1da177e4SLinus Torvalds 172*1da177e4SLinus Torvalds /* Save the registers into eframe for each cpu */ 173*1da177e4SLinus Torvalds for (slice = 0; slice < NODE_NUM_CPUS(slice); slice++) { 174*1da177e4SLinus Torvalds nmi_cpu_eframe_save(nasid, slice); 175*1da177e4SLinus Torvalds nmi_dump_hub_irq(nasid, slice); 176*1da177e4SLinus Torvalds } 177*1da177e4SLinus Torvalds } 178*1da177e4SLinus Torvalds 179*1da177e4SLinus Torvalds /* 180*1da177e4SLinus Torvalds * Save the nmi cpu registers for all cpus in the system. 181*1da177e4SLinus Torvalds */ 182*1da177e4SLinus Torvalds void 183*1da177e4SLinus Torvalds nmi_eframes_save(void) 184*1da177e4SLinus Torvalds { 185*1da177e4SLinus Torvalds cnodeid_t cnode; 186*1da177e4SLinus Torvalds 187*1da177e4SLinus Torvalds for_each_online_node(cnode) 188*1da177e4SLinus Torvalds nmi_node_eframe_save(cnode); 189*1da177e4SLinus Torvalds } 190*1da177e4SLinus Torvalds 191*1da177e4SLinus Torvalds void 192*1da177e4SLinus Torvalds cont_nmi_dump(void) 193*1da177e4SLinus Torvalds { 194*1da177e4SLinus Torvalds #ifndef REAL_NMI_SIGNAL 195*1da177e4SLinus Torvalds static atomic_t nmied_cpus = ATOMIC_INIT(0); 196*1da177e4SLinus Torvalds 197*1da177e4SLinus Torvalds atomic_inc(&nmied_cpus); 198*1da177e4SLinus Torvalds #endif 199*1da177e4SLinus Torvalds /* 200*1da177e4SLinus Torvalds * Use enter_panic_mode to allow only 1 cpu to proceed 201*1da177e4SLinus Torvalds */ 202*1da177e4SLinus Torvalds enter_panic_mode(); 203*1da177e4SLinus Torvalds 204*1da177e4SLinus Torvalds #ifdef REAL_NMI_SIGNAL 205*1da177e4SLinus Torvalds /* 206*1da177e4SLinus Torvalds * Wait up to 15 seconds for the other cpus to respond to the NMI. 207*1da177e4SLinus Torvalds * If a cpu has not responded after 10 sec, send it 1 additional NMI. 208*1da177e4SLinus Torvalds * This is for 2 reasons: 209*1da177e4SLinus Torvalds * - sometimes a MMSC fail to NMI all cpus. 210*1da177e4SLinus Torvalds * - on 512p SN0 system, the MMSC will only send NMIs to 211*1da177e4SLinus Torvalds * half the cpus. Unfortunately, we don't know which cpus may be 212*1da177e4SLinus Torvalds * NMIed - it depends on how the site chooses to configure. 213*1da177e4SLinus Torvalds * 214*1da177e4SLinus Torvalds * Note: it has been measure that it takes the MMSC up to 2.3 secs to 215*1da177e4SLinus Torvalds * send NMIs to all cpus on a 256p system. 216*1da177e4SLinus Torvalds */ 217*1da177e4SLinus Torvalds for (i=0; i < 1500; i++) { 218*1da177e4SLinus Torvalds for_each_online_node(node) 219*1da177e4SLinus Torvalds if (NODEPDA(node)->dump_count == 0) 220*1da177e4SLinus Torvalds break; 221*1da177e4SLinus Torvalds if (node == MAX_NUMNODES) 222*1da177e4SLinus Torvalds break; 223*1da177e4SLinus Torvalds if (i == 1000) { 224*1da177e4SLinus Torvalds for_each_online_node(node) 225*1da177e4SLinus Torvalds if (NODEPDA(node)->dump_count == 0) { 226*1da177e4SLinus Torvalds cpu = node_to_first_cpu(node); 227*1da177e4SLinus Torvalds for (n=0; n < CNODE_NUM_CPUS(node); cpu++, n++) { 228*1da177e4SLinus Torvalds CPUMASK_SETB(nmied_cpus, cpu); 229*1da177e4SLinus Torvalds /* 230*1da177e4SLinus Torvalds * cputonasid, cputoslice 231*1da177e4SLinus Torvalds * needs kernel cpuid 232*1da177e4SLinus Torvalds */ 233*1da177e4SLinus Torvalds SEND_NMI((cputonasid(cpu)), (cputoslice(cpu))); 234*1da177e4SLinus Torvalds } 235*1da177e4SLinus Torvalds } 236*1da177e4SLinus Torvalds 237*1da177e4SLinus Torvalds } 238*1da177e4SLinus Torvalds udelay(10000); 239*1da177e4SLinus Torvalds } 240*1da177e4SLinus Torvalds #else 241*1da177e4SLinus Torvalds while (atomic_read(&nmied_cpus) != num_online_cpus()); 242*1da177e4SLinus Torvalds #endif 243*1da177e4SLinus Torvalds 244*1da177e4SLinus Torvalds /* 245*1da177e4SLinus Torvalds * Save the nmi cpu registers for all cpu in the eframe format. 246*1da177e4SLinus Torvalds */ 247*1da177e4SLinus Torvalds nmi_eframes_save(); 248*1da177e4SLinus Torvalds LOCAL_HUB_S(NI_PORT_RESET, NPR_PORTRESET | NPR_LOCALRESET); 249*1da177e4SLinus Torvalds } 250