Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Sam Ravnborg | aba20a8 | 2011-01-28 22:08:20 +0000 | [diff] [blame] | 2 | /* |
| 3 | * sun4m irq support |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
| 5 | * djhr: Hacked out of irq.c into a CPU dependent version. |
| 6 | * |
| 7 | * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) |
| 8 | * Copyright (C) 1995 Miguel de Icaza (miguel@nuclecu.unam.mx) |
| 9 | * Copyright (C) 1995 Pete A. Zaitcev (zaitcev@yahoo.com) |
| 10 | * Copyright (C) 1996 Dave Redman (djhr@tadpole.co.uk) |
| 11 | */ |
| 12 | |
Stephen Rothwell | a755180 | 2014-02-12 16:10:20 -0500 | [diff] [blame] | 13 | #include <linux/slab.h> |
Ingo Molnar | b17b015 | 2017-02-08 18:51:35 +0100 | [diff] [blame] | 14 | #include <linux/sched/debug.h> |
Stephen Rothwell | a755180 | 2014-02-12 16:10:20 -0500 | [diff] [blame] | 15 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <asm/timer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <asm/traps.h> |
| 18 | #include <asm/pgalloc.h> |
| 19 | #include <asm/pgtable.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <asm/irq.h> |
| 21 | #include <asm/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <asm/cacheflush.h> |
| 23 | |
Al Viro | 32231a6 | 2007-07-21 19:18:57 -0700 | [diff] [blame] | 24 | #include "irq.h" |
Sam Ravnborg | aba20a8 | 2011-01-28 22:08:20 +0000 | [diff] [blame] | 25 | #include "kernel.h" |
Al Viro | 32231a6 | 2007-07-21 19:18:57 -0700 | [diff] [blame] | 26 | |
Sam Ravnborg | aba20a8 | 2011-01-28 22:08:20 +0000 | [diff] [blame] | 27 | /* Sample sun4m IRQ layout: |
| 28 | * |
| 29 | * 0x22 - Power |
| 30 | * 0x24 - ESP SCSI |
| 31 | * 0x26 - Lance ethernet |
| 32 | * 0x2b - Floppy |
| 33 | * 0x2c - Zilog uart |
| 34 | * 0x32 - SBUS level 0 |
| 35 | * 0x33 - Parallel port, SBUS level 1 |
| 36 | * 0x35 - SBUS level 2 |
| 37 | * 0x37 - SBUS level 3 |
| 38 | * 0x39 - Audio, Graphics card, SBUS level 4 |
| 39 | * 0x3b - SBUS level 5 |
| 40 | * 0x3d - SBUS level 6 |
| 41 | * |
| 42 | * Each interrupt source has a mask bit in the interrupt registers. |
| 43 | * When the mask bit is set, this blocks interrupt deliver. So you |
| 44 | * clear the bit to enable the interrupt. |
| 45 | * |
| 46 | * Interrupts numbered less than 0x10 are software triggered interrupts |
| 47 | * and unused by Linux. |
| 48 | * |
| 49 | * Interrupt level assignment on sun4m: |
David S. Miller | 778b1c6 | 2008-09-19 15:33:21 -0700 | [diff] [blame] | 50 | * |
| 51 | * level source |
| 52 | * ------------------------------------------------------------ |
Sam Ravnborg | aba20a8 | 2011-01-28 22:08:20 +0000 | [diff] [blame] | 53 | * 1 softint-1 |
David S. Miller | 778b1c6 | 2008-09-19 15:33:21 -0700 | [diff] [blame] | 54 | * 2 softint-2, VME/SBUS level 1 |
| 55 | * 3 softint-3, VME/SBUS level 2 |
| 56 | * 4 softint-4, onboard SCSI |
| 57 | * 5 softint-5, VME/SBUS level 3 |
| 58 | * 6 softint-6, onboard ETHERNET |
| 59 | * 7 softint-7, VME/SBUS level 4 |
| 60 | * 8 softint-8, onboard VIDEO |
| 61 | * 9 softint-9, VME/SBUS level 5, Module Interrupt |
| 62 | * 10 softint-10, system counter/timer |
| 63 | * 11 softint-11, VME/SBUS level 6, Floppy |
| 64 | * 12 softint-12, Keyboard/Mouse, Serial |
| 65 | * 13 softint-13, VME/SBUS level 7, ISDN Audio |
| 66 | * 14 softint-14, per-processor counter/timer |
| 67 | * 15 softint-15, Asynchronous Errors (broadcast) |
| 68 | * |
| 69 | * Each interrupt source is masked distinctly in the sun4m interrupt |
| 70 | * registers. The PIL level alone is therefore ambiguous, since multiple |
| 71 | * interrupt sources map to a single PIL. |
| 72 | * |
| 73 | * This ambiguity is resolved in the 'intr' property for device nodes |
| 74 | * in the OF device tree. Each 'intr' property entry is composed of |
| 75 | * two 32-bit words. The first word is the IRQ priority value, which |
| 76 | * is what we're intersted in. The second word is the IRQ vector, which |
| 77 | * is unused. |
| 78 | * |
| 79 | * The low 4 bits of the IRQ priority indicate the PIL, and the upper |
| 80 | * 4 bits indicate onboard vs. SBUS leveled vs. VME leveled. 0x20 |
| 81 | * means onboard, 0x30 means SBUS leveled, and 0x40 means VME leveled. |
| 82 | * |
| 83 | * For example, an 'intr' IRQ priority value of 0x24 is onboard SCSI |
| 84 | * whereas a value of 0x33 is SBUS level 2. Here are some sample |
| 85 | * 'intr' property IRQ priority values from ss4, ss5, ss10, ss20, and |
| 86 | * Tadpole S3 GX systems. |
| 87 | * |
Sam Ravnborg | aba20a8 | 2011-01-28 22:08:20 +0000 | [diff] [blame] | 88 | * esp: 0x24 onboard ESP SCSI |
| 89 | * le: 0x26 onboard Lance ETHERNET |
David S. Miller | 778b1c6 | 2008-09-19 15:33:21 -0700 | [diff] [blame] | 90 | * p9100: 0x32 SBUS level 1 P9100 video |
Sam Ravnborg | aba20a8 | 2011-01-28 22:08:20 +0000 | [diff] [blame] | 91 | * bpp: 0x33 SBUS level 2 BPP parallel port device |
David S. Miller | 778b1c6 | 2008-09-19 15:33:21 -0700 | [diff] [blame] | 92 | * DBRI: 0x39 SBUS level 5 DBRI ISDN audio |
| 93 | * SUNW,leo: 0x39 SBUS level 5 LEO video |
| 94 | * pcmcia: 0x3b SBUS level 6 PCMCIA controller |
| 95 | * uctrl: 0x3b SBUS level 6 UCTRL device |
| 96 | * modem: 0x3d SBUS level 7 MODEM |
| 97 | * zs: 0x2c onboard keyboard/mouse/serial |
| 98 | * floppy: 0x2b onboard Floppy |
| 99 | * power: 0x22 onboard power device (XXX unknown mask bit XXX) |
| 100 | */ |
| 101 | |
Sam Ravnborg | aba20a8 | 2011-01-28 22:08:20 +0000 | [diff] [blame] | 102 | |
Sam Ravnborg | aba20a8 | 2011-01-28 22:08:20 +0000 | [diff] [blame] | 103 | /* Code in entry.S needs to get at these register mappings. */ |
| 104 | struct sun4m_irq_percpu __iomem *sun4m_irq_percpu[SUN4M_NCPUS]; |
| 105 | struct sun4m_irq_global __iomem *sun4m_irq_global; |
| 106 | |
Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 107 | struct sun4m_handler_data { |
| 108 | bool percpu; |
| 109 | long mask; |
| 110 | }; |
| 111 | |
Sam Ravnborg | aba20a8 | 2011-01-28 22:08:20 +0000 | [diff] [blame] | 112 | /* Dave Redman (djhr@tadpole.co.uk) |
| 113 | * The sun4m interrupt registers. |
| 114 | */ |
| 115 | #define SUN4M_INT_ENABLE 0x80000000 |
| 116 | #define SUN4M_INT_E14 0x00000080 |
| 117 | #define SUN4M_INT_E10 0x00080000 |
| 118 | |
Sam Ravnborg | aba20a8 | 2011-01-28 22:08:20 +0000 | [diff] [blame] | 119 | #define SUN4M_INT_MASKALL 0x80000000 /* mask all interrupts */ |
| 120 | #define SUN4M_INT_MODULE_ERR 0x40000000 /* module error */ |
| 121 | #define SUN4M_INT_M2S_WRITE_ERR 0x20000000 /* write buffer error */ |
| 122 | #define SUN4M_INT_ECC_ERR 0x10000000 /* ecc memory error */ |
| 123 | #define SUN4M_INT_VME_ERR 0x08000000 /* vme async error */ |
| 124 | #define SUN4M_INT_FLOPPY 0x00400000 /* floppy disk */ |
| 125 | #define SUN4M_INT_MODULE 0x00200000 /* module interrupt */ |
| 126 | #define SUN4M_INT_VIDEO 0x00100000 /* onboard video */ |
| 127 | #define SUN4M_INT_REALTIME 0x00080000 /* system timer */ |
| 128 | #define SUN4M_INT_SCSI 0x00040000 /* onboard scsi */ |
| 129 | #define SUN4M_INT_AUDIO 0x00020000 /* audio/isdn */ |
| 130 | #define SUN4M_INT_ETHERNET 0x00010000 /* onboard ethernet */ |
| 131 | #define SUN4M_INT_SERIAL 0x00008000 /* serial ports */ |
| 132 | #define SUN4M_INT_KBDMS 0x00004000 /* keyboard/mouse */ |
| 133 | #define SUN4M_INT_SBUSBITS 0x00003F80 /* sbus int bits */ |
| 134 | #define SUN4M_INT_VMEBITS 0x0000007F /* vme int bits */ |
| 135 | |
| 136 | #define SUN4M_INT_ERROR (SUN4M_INT_MODULE_ERR | \ |
| 137 | SUN4M_INT_M2S_WRITE_ERR | \ |
| 138 | SUN4M_INT_ECC_ERR | \ |
| 139 | SUN4M_INT_VME_ERR) |
| 140 | |
| 141 | #define SUN4M_INT_SBUS(x) (1 << (x+7)) |
| 142 | #define SUN4M_INT_VME(x) (1 << (x)) |
| 143 | |
| 144 | /* Interrupt levels used by OBP */ |
| 145 | #define OBP_INT_LEVEL_SOFT 0x10 |
| 146 | #define OBP_INT_LEVEL_ONBOARD 0x20 |
| 147 | #define OBP_INT_LEVEL_SBUS 0x30 |
| 148 | #define OBP_INT_LEVEL_VME 0x40 |
| 149 | |
Sam Ravnborg | 0399bb5 | 2011-02-25 23:02:11 -0800 | [diff] [blame] | 150 | #define SUN4M_TIMER_IRQ (OBP_INT_LEVEL_ONBOARD | 10) |
Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 151 | #define SUN4M_PROFILE_IRQ (OBP_INT_LEVEL_ONBOARD | 14) |
Sam Ravnborg | 0399bb5 | 2011-02-25 23:02:11 -0800 | [diff] [blame] | 152 | |
Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 153 | static unsigned long sun4m_imask[0x50] = { |
Sam Ravnborg | 0399bb5 | 2011-02-25 23:02:11 -0800 | [diff] [blame] | 154 | /* 0x00 - SMP */ |
Robert Reif | 6cf4a92 | 2008-10-07 15:24:02 -0700 | [diff] [blame] | 155 | 0, SUN4M_SOFT_INT(1), |
| 156 | SUN4M_SOFT_INT(2), SUN4M_SOFT_INT(3), |
| 157 | SUN4M_SOFT_INT(4), SUN4M_SOFT_INT(5), |
| 158 | SUN4M_SOFT_INT(6), SUN4M_SOFT_INT(7), |
| 159 | SUN4M_SOFT_INT(8), SUN4M_SOFT_INT(9), |
| 160 | SUN4M_SOFT_INT(10), SUN4M_SOFT_INT(11), |
| 161 | SUN4M_SOFT_INT(12), SUN4M_SOFT_INT(13), |
| 162 | SUN4M_SOFT_INT(14), SUN4M_SOFT_INT(15), |
Sam Ravnborg | 0399bb5 | 2011-02-25 23:02:11 -0800 | [diff] [blame] | 163 | /* 0x10 - soft */ |
Robert Reif | 6cf4a92 | 2008-10-07 15:24:02 -0700 | [diff] [blame] | 164 | 0, SUN4M_SOFT_INT(1), |
| 165 | SUN4M_SOFT_INT(2), SUN4M_SOFT_INT(3), |
| 166 | SUN4M_SOFT_INT(4), SUN4M_SOFT_INT(5), |
| 167 | SUN4M_SOFT_INT(6), SUN4M_SOFT_INT(7), |
| 168 | SUN4M_SOFT_INT(8), SUN4M_SOFT_INT(9), |
| 169 | SUN4M_SOFT_INT(10), SUN4M_SOFT_INT(11), |
| 170 | SUN4M_SOFT_INT(12), SUN4M_SOFT_INT(13), |
| 171 | SUN4M_SOFT_INT(14), SUN4M_SOFT_INT(15), |
Sam Ravnborg | 0399bb5 | 2011-02-25 23:02:11 -0800 | [diff] [blame] | 172 | /* 0x20 - onboard */ |
Robert Reif | 6cf4a92 | 2008-10-07 15:24:02 -0700 | [diff] [blame] | 173 | 0, 0, 0, 0, |
| 174 | SUN4M_INT_SCSI, 0, SUN4M_INT_ETHERNET, 0, |
| 175 | SUN4M_INT_VIDEO, SUN4M_INT_MODULE, |
| 176 | SUN4M_INT_REALTIME, SUN4M_INT_FLOPPY, |
| 177 | (SUN4M_INT_SERIAL | SUN4M_INT_KBDMS), |
Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 178 | SUN4M_INT_AUDIO, SUN4M_INT_E14, SUN4M_INT_MODULE_ERR, |
Sam Ravnborg | 0399bb5 | 2011-02-25 23:02:11 -0800 | [diff] [blame] | 179 | /* 0x30 - sbus */ |
Robert Reif | 6cf4a92 | 2008-10-07 15:24:02 -0700 | [diff] [blame] | 180 | 0, 0, SUN4M_INT_SBUS(0), SUN4M_INT_SBUS(1), |
| 181 | 0, SUN4M_INT_SBUS(2), 0, SUN4M_INT_SBUS(3), |
| 182 | 0, SUN4M_INT_SBUS(4), 0, SUN4M_INT_SBUS(5), |
| 183 | 0, SUN4M_INT_SBUS(6), 0, 0, |
Sam Ravnborg | 0399bb5 | 2011-02-25 23:02:11 -0800 | [diff] [blame] | 184 | /* 0x40 - vme */ |
Robert Reif | 6cf4a92 | 2008-10-07 15:24:02 -0700 | [diff] [blame] | 185 | 0, 0, SUN4M_INT_VME(0), SUN4M_INT_VME(1), |
| 186 | 0, SUN4M_INT_VME(2), 0, SUN4M_INT_VME(3), |
| 187 | 0, SUN4M_INT_VME(4), 0, SUN4M_INT_VME(5), |
| 188 | 0, SUN4M_INT_VME(6), 0, 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | }; |
| 190 | |
Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 191 | static void sun4m_mask_irq(struct irq_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | { |
Jiang Liu | 6a4a5b3 | 2015-06-01 16:05:17 +0800 | [diff] [blame] | 193 | struct sun4m_handler_data *handler_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | int cpu = smp_processor_id(); |
| 195 | |
Jiang Liu | 6a4a5b3 | 2015-06-01 16:05:17 +0800 | [diff] [blame] | 196 | handler_data = irq_data_get_irq_handler_data(data); |
Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 197 | if (handler_data->mask) { |
| 198 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | local_irq_save(flags); |
Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 201 | if (handler_data->percpu) { |
| 202 | sbus_writel(handler_data->mask, &sun4m_irq_percpu[cpu]->set); |
| 203 | } else { |
| 204 | sbus_writel(handler_data->mask, &sun4m_irq_global->mask_set); |
| 205 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | local_irq_restore(flags); |
| 207 | } |
| 208 | } |
| 209 | |
Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 210 | static void sun4m_unmask_irq(struct irq_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | { |
Jiang Liu | 6a4a5b3 | 2015-06-01 16:05:17 +0800 | [diff] [blame] | 212 | struct sun4m_handler_data *handler_data; |
Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 213 | int cpu = smp_processor_id(); |
| 214 | |
Jiang Liu | 6a4a5b3 | 2015-06-01 16:05:17 +0800 | [diff] [blame] | 215 | handler_data = irq_data_get_irq_handler_data(data); |
Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 216 | if (handler_data->mask) { |
| 217 | unsigned long flags; |
| 218 | |
| 219 | local_irq_save(flags); |
| 220 | if (handler_data->percpu) { |
| 221 | sbus_writel(handler_data->mask, &sun4m_irq_percpu[cpu]->clear); |
| 222 | } else { |
| 223 | sbus_writel(handler_data->mask, &sun4m_irq_global->mask_clear); |
| 224 | } |
| 225 | local_irq_restore(flags); |
| 226 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 229 | static unsigned int sun4m_startup_irq(struct irq_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | { |
Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 231 | irq_link(data->irq); |
| 232 | sun4m_unmask_irq(data); |
| 233 | return 0; |
| 234 | } |
| 235 | |
| 236 | static void sun4m_shutdown_irq(struct irq_data *data) |
| 237 | { |
| 238 | sun4m_mask_irq(data); |
| 239 | irq_unlink(data->irq); |
| 240 | } |
| 241 | |
| 242 | static struct irq_chip sun4m_irq = { |
| 243 | .name = "sun4m", |
| 244 | .irq_startup = sun4m_startup_irq, |
| 245 | .irq_shutdown = sun4m_shutdown_irq, |
| 246 | .irq_mask = sun4m_mask_irq, |
| 247 | .irq_unmask = sun4m_unmask_irq, |
| 248 | }; |
| 249 | |
| 250 | |
| 251 | static unsigned int sun4m_build_device_irq(struct platform_device *op, |
| 252 | unsigned int real_irq) |
| 253 | { |
| 254 | struct sun4m_handler_data *handler_data; |
| 255 | unsigned int irq; |
| 256 | unsigned int pil; |
| 257 | |
| 258 | if (real_irq >= OBP_INT_LEVEL_VME) { |
| 259 | prom_printf("Bogus sun4m IRQ %u\n", real_irq); |
| 260 | prom_halt(); |
| 261 | } |
| 262 | pil = (real_irq & 0xf); |
| 263 | irq = irq_alloc(real_irq, pil); |
| 264 | |
| 265 | if (irq == 0) |
| 266 | goto out; |
| 267 | |
| 268 | handler_data = irq_get_handler_data(irq); |
| 269 | if (unlikely(handler_data)) |
| 270 | goto out; |
| 271 | |
| 272 | handler_data = kzalloc(sizeof(struct sun4m_handler_data), GFP_ATOMIC); |
| 273 | if (unlikely(!handler_data)) { |
| 274 | prom_printf("IRQ: kzalloc(sun4m_handler_data) failed.\n"); |
| 275 | prom_halt(); |
| 276 | } |
| 277 | |
| 278 | handler_data->mask = sun4m_imask[real_irq]; |
| 279 | handler_data->percpu = real_irq < OBP_INT_LEVEL_ONBOARD; |
| 280 | irq_set_chip_and_handler_name(irq, &sun4m_irq, |
| 281 | handle_level_irq, "level"); |
| 282 | irq_set_handler_data(irq, handler_data); |
| 283 | |
| 284 | out: |
| 285 | return irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | } |
| 287 | |
David S. Miller | 9b2e43a | 2008-09-11 23:08:30 -0700 | [diff] [blame] | 288 | struct sun4m_timer_percpu { |
| 289 | u32 l14_limit; |
| 290 | u32 l14_count; |
| 291 | u32 l14_limit_noclear; |
| 292 | u32 user_timer_start_stop; |
| 293 | }; |
| 294 | |
| 295 | static struct sun4m_timer_percpu __iomem *timers_percpu[SUN4M_NCPUS]; |
| 296 | |
| 297 | struct sun4m_timer_global { |
| 298 | u32 l10_limit; |
| 299 | u32 l10_count; |
| 300 | u32 l10_limit_noclear; |
| 301 | u32 reserved; |
| 302 | u32 timer_config; |
| 303 | }; |
| 304 | |
| 305 | static struct sun4m_timer_global __iomem *timers_global; |
| 306 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | static void sun4m_clear_clock_irq(void) |
| 308 | { |
David S. Miller | 9b2e43a | 2008-09-11 23:08:30 -0700 | [diff] [blame] | 309 | sbus_readl(&timers_global->l10_limit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | } |
| 311 | |
Robert Reif | 6cf4a92 | 2008-10-07 15:24:02 -0700 | [diff] [blame] | 312 | void sun4m_nmi(struct pt_regs *regs) |
| 313 | { |
| 314 | unsigned long afsr, afar, si; |
| 315 | |
| 316 | printk(KERN_ERR "Aieee: sun4m NMI received!\n"); |
| 317 | /* XXX HyperSparc hack XXX */ |
| 318 | __asm__ __volatile__("mov 0x500, %%g1\n\t" |
| 319 | "lda [%%g1] 0x4, %0\n\t" |
| 320 | "mov 0x600, %%g1\n\t" |
| 321 | "lda [%%g1] 0x4, %1\n\t" : |
| 322 | "=r" (afsr), "=r" (afar)); |
| 323 | printk(KERN_ERR "afsr=%08lx afar=%08lx\n", afsr, afar); |
| 324 | si = sbus_readl(&sun4m_irq_global->pending); |
| 325 | printk(KERN_ERR "si=%08lx\n", si); |
| 326 | if (si & SUN4M_INT_MODULE_ERR) |
| 327 | printk(KERN_ERR "Module async error\n"); |
| 328 | if (si & SUN4M_INT_M2S_WRITE_ERR) |
| 329 | printk(KERN_ERR "MBus/SBus async error\n"); |
| 330 | if (si & SUN4M_INT_ECC_ERR) |
| 331 | printk(KERN_ERR "ECC memory error\n"); |
| 332 | if (si & SUN4M_INT_VME_ERR) |
| 333 | printk(KERN_ERR "VME async error\n"); |
| 334 | printk(KERN_ERR "you lose buddy boy...\n"); |
| 335 | show_regs(regs); |
| 336 | prom_halt(); |
| 337 | } |
| 338 | |
Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 339 | void sun4m_unmask_profile_irq(void) |
| 340 | { |
| 341 | unsigned long flags; |
| 342 | |
| 343 | local_irq_save(flags); |
| 344 | sbus_writel(sun4m_imask[SUN4M_PROFILE_IRQ], &sun4m_irq_global->mask_clear); |
| 345 | local_irq_restore(flags); |
| 346 | } |
| 347 | |
David S. Miller | 1de937a | 2008-09-13 22:07:56 -0700 | [diff] [blame] | 348 | void sun4m_clear_profile_irq(int cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | { |
David S. Miller | 9b2e43a | 2008-09-11 23:08:30 -0700 | [diff] [blame] | 350 | sbus_readl(&timers_percpu[cpu]->l14_limit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | static void sun4m_load_profile_irq(int cpu, unsigned int limit) |
| 354 | { |
Tkhai Kirill | 62f0828 | 2012-04-04 21:49:26 +0200 | [diff] [blame] | 355 | unsigned int value = limit ? timer_value(limit) : 0; |
| 356 | sbus_writel(value, &timers_percpu[cpu]->l14_limit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | } |
| 358 | |
Tkhai Kirill | 62f0828 | 2012-04-04 21:49:26 +0200 | [diff] [blame] | 359 | static void __init sun4m_init_timers(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | { |
David S. Miller | 9b2e43a | 2008-09-11 23:08:30 -0700 | [diff] [blame] | 361 | struct device_node *dp = of_find_node_by_name(NULL, "counter"); |
| 362 | int i, err, len, num_cpu_timers; |
Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 363 | unsigned int irq; |
David S. Miller | 9b2e43a | 2008-09-11 23:08:30 -0700 | [diff] [blame] | 364 | const u32 *addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | |
David S. Miller | 9b2e43a | 2008-09-11 23:08:30 -0700 | [diff] [blame] | 366 | if (!dp) { |
| 367 | printk(KERN_ERR "sun4m_init_timers: No 'counter' node.\n"); |
| 368 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | } |
| 370 | |
David S. Miller | 9b2e43a | 2008-09-11 23:08:30 -0700 | [diff] [blame] | 371 | addr = of_get_property(dp, "address", &len); |
Nicolas Palix | c2e27c3 | 2008-12-03 21:10:57 -0800 | [diff] [blame] | 372 | of_node_put(dp); |
David S. Miller | 9b2e43a | 2008-09-11 23:08:30 -0700 | [diff] [blame] | 373 | if (!addr) { |
| 374 | printk(KERN_ERR "sun4m_init_timers: No 'address' prop.\n"); |
| 375 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | } |
David S. Miller | 9b2e43a | 2008-09-11 23:08:30 -0700 | [diff] [blame] | 377 | |
| 378 | num_cpu_timers = (len / sizeof(u32)) - 1; |
| 379 | for (i = 0; i < num_cpu_timers; i++) { |
| 380 | timers_percpu[i] = (void __iomem *) |
| 381 | (unsigned long) addr[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | } |
David S. Miller | 9b2e43a | 2008-09-11 23:08:30 -0700 | [diff] [blame] | 383 | timers_global = (void __iomem *) |
| 384 | (unsigned long) addr[num_cpu_timers]; |
| 385 | |
Tkhai Kirill | e51e07e | 2012-01-10 13:17:03 +0000 | [diff] [blame] | 386 | /* Every per-cpu timer works in timer mode */ |
| 387 | sbus_writel(0x00000000, &timers_global->timer_config); |
| 388 | |
Tkhai Kirill | 62f0828 | 2012-04-04 21:49:26 +0200 | [diff] [blame] | 389 | #ifdef CONFIG_SMP |
| 390 | sparc_config.cs_period = SBUS_CLOCK_RATE * 2; /* 2 seconds */ |
| 391 | sparc_config.features |= FEAT_L14_ONESHOT; |
| 392 | #else |
| 393 | sparc_config.cs_period = SBUS_CLOCK_RATE / HZ; /* 1/HZ sec */ |
| 394 | sparc_config.features |= FEAT_L10_CLOCKEVENT; |
| 395 | #endif |
| 396 | sparc_config.features |= FEAT_L10_CLOCKSOURCE; |
| 397 | sbus_writel(timer_value(sparc_config.cs_period), |
| 398 | &timers_global->l10_limit); |
David S. Miller | 9b2e43a | 2008-09-11 23:08:30 -0700 | [diff] [blame] | 399 | |
| 400 | master_l10_counter = &timers_global->l10_count; |
David S. Miller | 9b2e43a | 2008-09-11 23:08:30 -0700 | [diff] [blame] | 401 | |
Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 402 | irq = sun4m_build_device_irq(NULL, SUN4M_TIMER_IRQ); |
| 403 | |
Tkhai Kirill | 62f0828 | 2012-04-04 21:49:26 +0200 | [diff] [blame] | 404 | err = request_irq(irq, timer_interrupt, IRQF_TIMER, "timer", NULL); |
David S. Miller | 9b2e43a | 2008-09-11 23:08:30 -0700 | [diff] [blame] | 405 | if (err) { |
| 406 | printk(KERN_ERR "sun4m_init_timers: Register IRQ error %d.\n", |
| 407 | err); |
| 408 | return; |
| 409 | } |
| 410 | |
| 411 | for (i = 0; i < num_cpu_timers; i++) |
| 412 | sbus_writel(0, &timers_percpu[i]->l14_limit); |
| 413 | if (num_cpu_timers == 4) |
David S. Miller | 69c010b | 2008-09-19 21:17:43 -0700 | [diff] [blame] | 414 | sbus_writel(SUN4M_INT_E14, &sun4m_irq_global->mask_set); |
David S. Miller | 9b2e43a | 2008-09-11 23:08:30 -0700 | [diff] [blame] | 415 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | #ifdef CONFIG_SMP |
| 417 | { |
| 418 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | struct tt_entry *trap_table = &sparc_ttable[SP_TRAP_IRQ1 + (14 - 1)]; |
| 420 | |
| 421 | /* For SMP we use the level 14 ticker, however the bootup code |
Simon Arlott | d1a78c3 | 2007-05-11 13:51:23 -0700 | [diff] [blame] | 422 | * has copied the firmware's level 14 vector into the boot cpu's |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | * trap table, we must fix this now or we get squashed. |
| 424 | */ |
| 425 | local_irq_save(flags); |
| 426 | trap_table->inst_one = lvl14_save[0]; |
| 427 | trap_table->inst_two = lvl14_save[1]; |
| 428 | trap_table->inst_three = lvl14_save[2]; |
| 429 | trap_table->inst_four = lvl14_save[3]; |
David S. Miller | 5d83d66 | 2012-05-13 20:49:31 -0700 | [diff] [blame] | 430 | local_ops->cache_all(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | local_irq_restore(flags); |
| 432 | } |
| 433 | #endif |
| 434 | } |
| 435 | |
| 436 | void __init sun4m_init_IRQ(void) |
| 437 | { |
David S. Miller | 69c010b | 2008-09-19 21:17:43 -0700 | [diff] [blame] | 438 | struct device_node *dp = of_find_node_by_name(NULL, "interrupt"); |
| 439 | int len, i, mid, num_cpu_iregs; |
| 440 | const u32 *addr; |
| 441 | |
| 442 | if (!dp) { |
| 443 | printk(KERN_ERR "sun4m_init_IRQ: No 'interrupt' node.\n"); |
| 444 | return; |
| 445 | } |
| 446 | |
| 447 | addr = of_get_property(dp, "address", &len); |
Nicolas Palix | c2e27c3 | 2008-12-03 21:10:57 -0800 | [diff] [blame] | 448 | of_node_put(dp); |
David S. Miller | 69c010b | 2008-09-19 21:17:43 -0700 | [diff] [blame] | 449 | if (!addr) { |
| 450 | printk(KERN_ERR "sun4m_init_IRQ: No 'address' prop.\n"); |
| 451 | return; |
| 452 | } |
| 453 | |
| 454 | num_cpu_iregs = (len / sizeof(u32)) - 1; |
| 455 | for (i = 0; i < num_cpu_iregs; i++) { |
| 456 | sun4m_irq_percpu[i] = (void __iomem *) |
| 457 | (unsigned long) addr[i]; |
| 458 | } |
| 459 | sun4m_irq_global = (void __iomem *) |
| 460 | (unsigned long) addr[num_cpu_iregs]; |
| 461 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | local_irq_disable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | |
David S. Miller | 69c010b | 2008-09-19 21:17:43 -0700 | [diff] [blame] | 464 | sbus_writel(~SUN4M_INT_MASKALL, &sun4m_irq_global->mask_set); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | for (i = 0; !cpu_find_by_instance(i, NULL, &mid); i++) |
David S. Miller | 69c010b | 2008-09-19 21:17:43 -0700 | [diff] [blame] | 466 | sbus_writel(~0x17fff, &sun4m_irq_percpu[mid]->clear); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | |
David S. Miller | e7913de | 2008-09-13 22:48:41 -0700 | [diff] [blame] | 468 | if (num_cpu_iregs == 4) |
David S. Miller | 69c010b | 2008-09-19 21:17:43 -0700 | [diff] [blame] | 469 | sbus_writel(0, &sun4m_irq_global->interrupt_target); |
David S. Miller | e7913de | 2008-09-13 22:48:41 -0700 | [diff] [blame] | 470 | |
Sam Ravnborg | 08c9388 | 2012-05-14 17:30:35 +0200 | [diff] [blame] | 471 | sparc_config.init_timers = sun4m_init_timers; |
Sam Ravnborg | 472bc4f | 2012-04-04 13:21:13 +0200 | [diff] [blame] | 472 | sparc_config.build_device_irq = sun4m_build_device_irq; |
Tkhai Kirill | 62f0828 | 2012-04-04 21:49:26 +0200 | [diff] [blame] | 473 | sparc_config.clock_rate = SBUS_CLOCK_RATE; |
Sam Ravnborg | 08c9388 | 2012-05-14 17:30:35 +0200 | [diff] [blame] | 474 | sparc_config.clear_clock_irq = sun4m_clear_clock_irq; |
| 475 | sparc_config.load_profile_irq = sun4m_load_profile_irq; |
| 476 | |
Sam Ravnborg | bbdc266 | 2011-02-25 23:00:19 -0800 | [diff] [blame] | 477 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | /* Cannot enable interrupts until OBP ticker is disabled. */ |
| 479 | } |