sun4m_irq.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. /* sun4m_irq.c
  2. * arch/sparc/kernel/sun4m_irq.c:
  3. *
  4. * djhr: Hacked out of irq.c into a CPU dependent version.
  5. *
  6. * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
  7. * Copyright (C) 1995 Miguel de Icaza (miguel@nuclecu.unam.mx)
  8. * Copyright (C) 1995 Pete A. Zaitcev (zaitcev@yahoo.com)
  9. * Copyright (C) 1996 Dave Redman (djhr@tadpole.co.uk)
  10. */
  11. #include <linux/errno.h>
  12. #include <linux/linkage.h>
  13. #include <linux/kernel_stat.h>
  14. #include <linux/signal.h>
  15. #include <linux/sched.h>
  16. #include <linux/ptrace.h>
  17. #include <linux/smp.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/slab.h>
  20. #include <linux/init.h>
  21. #include <linux/ioport.h>
  22. #include <linux/of.h>
  23. #include <linux/of_device.h>
  24. #include <asm/ptrace.h>
  25. #include <asm/processor.h>
  26. #include <asm/system.h>
  27. #include <asm/psr.h>
  28. #include <asm/vaddrs.h>
  29. #include <asm/timer.h>
  30. #include <asm/openprom.h>
  31. #include <asm/oplib.h>
  32. #include <asm/traps.h>
  33. #include <asm/pgalloc.h>
  34. #include <asm/pgtable.h>
  35. #include <asm/smp.h>
  36. #include <asm/irq.h>
  37. #include <asm/io.h>
  38. #include <asm/cacheflush.h>
  39. #include "irq.h"
  40. struct sun4m_irq_percpu {
  41. u32 pending;
  42. u32 clear;
  43. u32 set;
  44. };
  45. struct sun4m_irq_global {
  46. u32 pending;
  47. u32 mask;
  48. u32 mask_clear;
  49. u32 mask_set;
  50. u32 interrupt_target;
  51. };
  52. /* Code in entry.S needs to get at these register mappings. */
  53. struct sun4m_irq_percpu __iomem *sun4m_irq_percpu[SUN4M_NCPUS];
  54. struct sun4m_irq_global __iomem *sun4m_irq_global;
  55. /* Dave Redman (djhr@tadpole.co.uk)
  56. * The sun4m interrupt registers.
  57. */
  58. #define SUN4M_INT_ENABLE 0x80000000
  59. #define SUN4M_INT_E14 0x00000080
  60. #define SUN4M_INT_E10 0x00080000
  61. #define SUN4M_HARD_INT(x) (0x000000001 << (x))
  62. #define SUN4M_SOFT_INT(x) (0x000010000 << (x))
  63. #define SUN4M_INT_MASKALL 0x80000000 /* mask all interrupts */
  64. #define SUN4M_INT_MODULE_ERR 0x40000000 /* module error */
  65. #define SUN4M_INT_M2S_WRITE_ERR 0x20000000 /* write buffer error */
  66. #define SUN4M_INT_ECC_ERR 0x10000000 /* ecc memory error */
  67. #define SUN4M_INT_VME_ERR 0x08000000 /* vme async error */
  68. #define SUN4M_INT_FLOPPY 0x00400000 /* floppy disk */
  69. #define SUN4M_INT_MODULE 0x00200000 /* module interrupt */
  70. #define SUN4M_INT_VIDEO 0x00100000 /* onboard video */
  71. #define SUN4M_INT_REALTIME 0x00080000 /* system timer */
  72. #define SUN4M_INT_SCSI 0x00040000 /* onboard scsi */
  73. #define SUN4M_INT_AUDIO 0x00020000 /* audio/isdn */
  74. #define SUN4M_INT_ETHERNET 0x00010000 /* onboard ethernet */
  75. #define SUN4M_INT_SERIAL 0x00008000 /* serial ports */
  76. #define SUN4M_INT_KBDMS 0x00004000 /* keyboard/mouse */
  77. #define SUN4M_INT_SBUSBITS 0x00003F80 /* sbus int bits */
  78. #define SUN4M_INT_VMEBITS 0x0000007F /* vme int bits */
  79. #define SUN4M_INT_ERROR (SUN4M_INT_MODULE_ERR | \
  80. SUN4M_INT_M2S_WRITE_ERR | \
  81. SUN4M_INT_ECC_ERR | \
  82. SUN4M_INT_VME_ERR)
  83. #define SUN4M_INT_SBUS(x) (1 << (x+7))
  84. #define SUN4M_INT_VME(x) (1 << (x))
  85. /* Interrupt levels used by OBP */
  86. #define OBP_INT_LEVEL_SOFT 0x10
  87. #define OBP_INT_LEVEL_ONBOARD 0x20
  88. #define OBP_INT_LEVEL_SBUS 0x30
  89. #define OBP_INT_LEVEL_VME 0x40
  90. /* Interrupt level assignment on sun4m:
  91. *
  92. * level source
  93. * ------------------------------------------------------------
  94. * 1 softint-1
  95. * 2 softint-2, VME/SBUS level 1
  96. * 3 softint-3, VME/SBUS level 2
  97. * 4 softint-4, onboard SCSI
  98. * 5 softint-5, VME/SBUS level 3
  99. * 6 softint-6, onboard ETHERNET
  100. * 7 softint-7, VME/SBUS level 4
  101. * 8 softint-8, onboard VIDEO
  102. * 9 softint-9, VME/SBUS level 5, Module Interrupt
  103. * 10 softint-10, system counter/timer
  104. * 11 softint-11, VME/SBUS level 6, Floppy
  105. * 12 softint-12, Keyboard/Mouse, Serial
  106. * 13 softint-13, VME/SBUS level 7, ISDN Audio
  107. * 14 softint-14, per-processor counter/timer
  108. * 15 softint-15, Asynchronous Errors (broadcast)
  109. *
  110. * Each interrupt source is masked distinctly in the sun4m interrupt
  111. * registers. The PIL level alone is therefore ambiguous, since multiple
  112. * interrupt sources map to a single PIL.
  113. *
  114. * This ambiguity is resolved in the 'intr' property for device nodes
  115. * in the OF device tree. Each 'intr' property entry is composed of
  116. * two 32-bit words. The first word is the IRQ priority value, which
  117. * is what we're intersted in. The second word is the IRQ vector, which
  118. * is unused.
  119. *
  120. * The low 4 bits of the IRQ priority indicate the PIL, and the upper
  121. * 4 bits indicate onboard vs. SBUS leveled vs. VME leveled. 0x20
  122. * means onboard, 0x30 means SBUS leveled, and 0x40 means VME leveled.
  123. *
  124. * For example, an 'intr' IRQ priority value of 0x24 is onboard SCSI
  125. * whereas a value of 0x33 is SBUS level 2. Here are some sample
  126. * 'intr' property IRQ priority values from ss4, ss5, ss10, ss20, and
  127. * Tadpole S3 GX systems.
  128. *
  129. * esp: 0x24 onboard ESP SCSI
  130. * le: 0x26 onboard Lance ETHERNET
  131. * p9100: 0x32 SBUS level 1 P9100 video
  132. * bpp: 0x33 SBUS level 2 BPP parallel port device
  133. * DBRI: 0x39 SBUS level 5 DBRI ISDN audio
  134. * SUNW,leo: 0x39 SBUS level 5 LEO video
  135. * pcmcia: 0x3b SBUS level 6 PCMCIA controller
  136. * uctrl: 0x3b SBUS level 6 UCTRL device
  137. * modem: 0x3d SBUS level 7 MODEM
  138. * zs: 0x2c onboard keyboard/mouse/serial
  139. * floppy: 0x2b onboard Floppy
  140. * power: 0x22 onboard power device (XXX unknown mask bit XXX)
  141. */
  142. static unsigned long irq_mask[0x50] = {
  143. /* SMP */
  144. 0, SUN4M_SOFT_INT(1),
  145. SUN4M_SOFT_INT(2), SUN4M_SOFT_INT(3),
  146. SUN4M_SOFT_INT(4), SUN4M_SOFT_INT(5),
  147. SUN4M_SOFT_INT(6), SUN4M_SOFT_INT(7),
  148. SUN4M_SOFT_INT(8), SUN4M_SOFT_INT(9),
  149. SUN4M_SOFT_INT(10), SUN4M_SOFT_INT(11),
  150. SUN4M_SOFT_INT(12), SUN4M_SOFT_INT(13),
  151. SUN4M_SOFT_INT(14), SUN4M_SOFT_INT(15),
  152. /* soft */
  153. 0, SUN4M_SOFT_INT(1),
  154. SUN4M_SOFT_INT(2), SUN4M_SOFT_INT(3),
  155. SUN4M_SOFT_INT(4), SUN4M_SOFT_INT(5),
  156. SUN4M_SOFT_INT(6), SUN4M_SOFT_INT(7),
  157. SUN4M_SOFT_INT(8), SUN4M_SOFT_INT(9),
  158. SUN4M_SOFT_INT(10), SUN4M_SOFT_INT(11),
  159. SUN4M_SOFT_INT(12), SUN4M_SOFT_INT(13),
  160. SUN4M_SOFT_INT(14), SUN4M_SOFT_INT(15),
  161. /* onboard */
  162. 0, 0, 0, 0,
  163. SUN4M_INT_SCSI, 0, SUN4M_INT_ETHERNET, 0,
  164. SUN4M_INT_VIDEO, SUN4M_INT_MODULE,
  165. SUN4M_INT_REALTIME, SUN4M_INT_FLOPPY,
  166. (SUN4M_INT_SERIAL | SUN4M_INT_KBDMS),
  167. SUN4M_INT_AUDIO, 0, SUN4M_INT_MODULE_ERR,
  168. /* sbus */
  169. 0, 0, SUN4M_INT_SBUS(0), SUN4M_INT_SBUS(1),
  170. 0, SUN4M_INT_SBUS(2), 0, SUN4M_INT_SBUS(3),
  171. 0, SUN4M_INT_SBUS(4), 0, SUN4M_INT_SBUS(5),
  172. 0, SUN4M_INT_SBUS(6), 0, 0,
  173. /* vme */
  174. 0, 0, SUN4M_INT_VME(0), SUN4M_INT_VME(1),
  175. 0, SUN4M_INT_VME(2), 0, SUN4M_INT_VME(3),
  176. 0, SUN4M_INT_VME(4), 0, SUN4M_INT_VME(5),
  177. 0, SUN4M_INT_VME(6), 0, 0
  178. };
  179. static unsigned long sun4m_get_irqmask(unsigned int irq)
  180. {
  181. unsigned long mask;
  182. if (irq < 0x50)
  183. mask = irq_mask[irq];
  184. else
  185. mask = 0;
  186. if (!mask)
  187. printk(KERN_ERR "sun4m_get_irqmask: IRQ%d has no valid mask!\n",
  188. irq);
  189. return mask;
  190. }
  191. static void sun4m_disable_irq(unsigned int irq_nr)
  192. {
  193. unsigned long mask, flags;
  194. int cpu = smp_processor_id();
  195. mask = sun4m_get_irqmask(irq_nr);
  196. local_irq_save(flags);
  197. if (irq_nr > 15)
  198. sbus_writel(mask, &sun4m_irq_global->mask_set);
  199. else
  200. sbus_writel(mask, &sun4m_irq_percpu[cpu]->set);
  201. local_irq_restore(flags);
  202. }
  203. static void sun4m_enable_irq(unsigned int irq_nr)
  204. {
  205. unsigned long mask, flags;
  206. int cpu = smp_processor_id();
  207. /* Dreadful floppy hack. When we use 0x2b instead of
  208. * 0x0b the system blows (it starts to whistle!).
  209. * So we continue to use 0x0b. Fixme ASAP. --P3
  210. */
  211. if (irq_nr != 0x0b) {
  212. mask = sun4m_get_irqmask(irq_nr);
  213. local_irq_save(flags);
  214. if (irq_nr > 15)
  215. sbus_writel(mask, &sun4m_irq_global->mask_clear);
  216. else
  217. sbus_writel(mask, &sun4m_irq_percpu[cpu]->clear);
  218. local_irq_restore(flags);
  219. } else {
  220. local_irq_save(flags);
  221. sbus_writel(SUN4M_INT_FLOPPY, &sun4m_irq_global->mask_clear);
  222. local_irq_restore(flags);
  223. }
  224. }
  225. static unsigned long cpu_pil_to_imask[16] = {
  226. /*0*/ 0x00000000,
  227. /*1*/ 0x00000000,
  228. /*2*/ SUN4M_INT_SBUS(0) | SUN4M_INT_VME(0),
  229. /*3*/ SUN4M_INT_SBUS(1) | SUN4M_INT_VME(1),
  230. /*4*/ SUN4M_INT_SCSI,
  231. /*5*/ SUN4M_INT_SBUS(2) | SUN4M_INT_VME(2),
  232. /*6*/ SUN4M_INT_ETHERNET,
  233. /*7*/ SUN4M_INT_SBUS(3) | SUN4M_INT_VME(3),
  234. /*8*/ SUN4M_INT_VIDEO,
  235. /*9*/ SUN4M_INT_SBUS(4) | SUN4M_INT_VME(4) | SUN4M_INT_MODULE_ERR,
  236. /*10*/ SUN4M_INT_REALTIME,
  237. /*11*/ SUN4M_INT_SBUS(5) | SUN4M_INT_VME(5) | SUN4M_INT_FLOPPY,
  238. /*12*/ SUN4M_INT_SERIAL | SUN4M_INT_KBDMS,
  239. /*13*/ SUN4M_INT_SBUS(6) | SUN4M_INT_VME(6) | SUN4M_INT_AUDIO,
  240. /*14*/ SUN4M_INT_E14,
  241. /*15*/ SUN4M_INT_ERROR
  242. };
  243. /* We assume the caller has disabled local interrupts when these are called,
  244. * or else very bizarre behavior will result.
  245. */
  246. static void sun4m_disable_pil_irq(unsigned int pil)
  247. {
  248. sbus_writel(cpu_pil_to_imask[pil], &sun4m_irq_global->mask_set);
  249. }
  250. static void sun4m_enable_pil_irq(unsigned int pil)
  251. {
  252. sbus_writel(cpu_pil_to_imask[pil], &sun4m_irq_global->mask_clear);
  253. }
  254. #ifdef CONFIG_SMP
  255. static void sun4m_send_ipi(int cpu, int level)
  256. {
  257. unsigned long mask = sun4m_get_irqmask(level);
  258. sbus_writel(mask, &sun4m_irq_percpu[cpu]->set);
  259. }
  260. static void sun4m_clear_ipi(int cpu, int level)
  261. {
  262. unsigned long mask = sun4m_get_irqmask(level);
  263. sbus_writel(mask, &sun4m_irq_percpu[cpu]->clear);
  264. }
  265. static void sun4m_set_udt(int cpu)
  266. {
  267. sbus_writel(cpu, &sun4m_irq_global->interrupt_target);
  268. }
  269. #endif
  270. struct sun4m_timer_percpu {
  271. u32 l14_limit;
  272. u32 l14_count;
  273. u32 l14_limit_noclear;
  274. u32 user_timer_start_stop;
  275. };
  276. static struct sun4m_timer_percpu __iomem *timers_percpu[SUN4M_NCPUS];
  277. struct sun4m_timer_global {
  278. u32 l10_limit;
  279. u32 l10_count;
  280. u32 l10_limit_noclear;
  281. u32 reserved;
  282. u32 timer_config;
  283. };
  284. static struct sun4m_timer_global __iomem *timers_global;
  285. #define TIMER_IRQ (OBP_INT_LEVEL_ONBOARD | 10)
  286. unsigned int lvl14_resolution = (((1000000/HZ) + 1) << 10);
  287. static void sun4m_clear_clock_irq(void)
  288. {
  289. sbus_readl(&timers_global->l10_limit);
  290. }
  291. void sun4m_nmi(struct pt_regs *regs)
  292. {
  293. unsigned long afsr, afar, si;
  294. printk(KERN_ERR "Aieee: sun4m NMI received!\n");
  295. /* XXX HyperSparc hack XXX */
  296. __asm__ __volatile__("mov 0x500, %%g1\n\t"
  297. "lda [%%g1] 0x4, %0\n\t"
  298. "mov 0x600, %%g1\n\t"
  299. "lda [%%g1] 0x4, %1\n\t" :
  300. "=r" (afsr), "=r" (afar));
  301. printk(KERN_ERR "afsr=%08lx afar=%08lx\n", afsr, afar);
  302. si = sbus_readl(&sun4m_irq_global->pending);
  303. printk(KERN_ERR "si=%08lx\n", si);
  304. if (si & SUN4M_INT_MODULE_ERR)
  305. printk(KERN_ERR "Module async error\n");
  306. if (si & SUN4M_INT_M2S_WRITE_ERR)
  307. printk(KERN_ERR "MBus/SBus async error\n");
  308. if (si & SUN4M_INT_ECC_ERR)
  309. printk(KERN_ERR "ECC memory error\n");
  310. if (si & SUN4M_INT_VME_ERR)
  311. printk(KERN_ERR "VME async error\n");
  312. printk(KERN_ERR "you lose buddy boy...\n");
  313. show_regs(regs);
  314. prom_halt();
  315. }
  316. /* Exported for sun4m_smp.c */
  317. void sun4m_clear_profile_irq(int cpu)
  318. {
  319. sbus_readl(&timers_percpu[cpu]->l14_limit);
  320. }
  321. static void sun4m_load_profile_irq(int cpu, unsigned int limit)
  322. {
  323. sbus_writel(limit, &timers_percpu[cpu]->l14_limit);
  324. }
  325. static void __init sun4m_init_timers(irq_handler_t counter_fn)
  326. {
  327. struct device_node *dp = of_find_node_by_name(NULL, "counter");
  328. int i, err, len, num_cpu_timers;
  329. const u32 *addr;
  330. if (!dp) {
  331. printk(KERN_ERR "sun4m_init_timers: No 'counter' node.\n");
  332. return;
  333. }
  334. addr = of_get_property(dp, "address", &len);
  335. of_node_put(dp);
  336. if (!addr) {
  337. printk(KERN_ERR "sun4m_init_timers: No 'address' prop.\n");
  338. return;
  339. }
  340. num_cpu_timers = (len / sizeof(u32)) - 1;
  341. for (i = 0; i < num_cpu_timers; i++) {
  342. timers_percpu[i] = (void __iomem *)
  343. (unsigned long) addr[i];
  344. }
  345. timers_global = (void __iomem *)
  346. (unsigned long) addr[num_cpu_timers];
  347. sbus_writel((((1000000/HZ) + 1) << 10), &timers_global->l10_limit);
  348. master_l10_counter = &timers_global->l10_count;
  349. err = request_irq(TIMER_IRQ, counter_fn,
  350. (IRQF_DISABLED | SA_STATIC_ALLOC), "timer", NULL);
  351. if (err) {
  352. printk(KERN_ERR "sun4m_init_timers: Register IRQ error %d.\n",
  353. err);
  354. return;
  355. }
  356. for (i = 0; i < num_cpu_timers; i++)
  357. sbus_writel(0, &timers_percpu[i]->l14_limit);
  358. if (num_cpu_timers == 4)
  359. sbus_writel(SUN4M_INT_E14, &sun4m_irq_global->mask_set);
  360. #ifdef CONFIG_SMP
  361. {
  362. unsigned long flags;
  363. extern unsigned long lvl14_save[4];
  364. struct tt_entry *trap_table = &sparc_ttable[SP_TRAP_IRQ1 + (14 - 1)];
  365. /* For SMP we use the level 14 ticker, however the bootup code
  366. * has copied the firmware's level 14 vector into the boot cpu's
  367. * trap table, we must fix this now or we get squashed.
  368. */
  369. local_irq_save(flags);
  370. trap_table->inst_one = lvl14_save[0];
  371. trap_table->inst_two = lvl14_save[1];
  372. trap_table->inst_three = lvl14_save[2];
  373. trap_table->inst_four = lvl14_save[3];
  374. local_flush_cache_all();
  375. local_irq_restore(flags);
  376. }
  377. #endif
  378. }
  379. void __init sun4m_init_IRQ(void)
  380. {
  381. struct device_node *dp = of_find_node_by_name(NULL, "interrupt");
  382. int len, i, mid, num_cpu_iregs;
  383. const u32 *addr;
  384. if (!dp) {
  385. printk(KERN_ERR "sun4m_init_IRQ: No 'interrupt' node.\n");
  386. return;
  387. }
  388. addr = of_get_property(dp, "address", &len);
  389. of_node_put(dp);
  390. if (!addr) {
  391. printk(KERN_ERR "sun4m_init_IRQ: No 'address' prop.\n");
  392. return;
  393. }
  394. num_cpu_iregs = (len / sizeof(u32)) - 1;
  395. for (i = 0; i < num_cpu_iregs; i++) {
  396. sun4m_irq_percpu[i] = (void __iomem *)
  397. (unsigned long) addr[i];
  398. }
  399. sun4m_irq_global = (void __iomem *)
  400. (unsigned long) addr[num_cpu_iregs];
  401. local_irq_disable();
  402. sbus_writel(~SUN4M_INT_MASKALL, &sun4m_irq_global->mask_set);
  403. for (i = 0; !cpu_find_by_instance(i, NULL, &mid); i++)
  404. sbus_writel(~0x17fff, &sun4m_irq_percpu[mid]->clear);
  405. if (num_cpu_iregs == 4)
  406. sbus_writel(0, &sun4m_irq_global->interrupt_target);
  407. BTFIXUPSET_CALL(enable_irq, sun4m_enable_irq, BTFIXUPCALL_NORM);
  408. BTFIXUPSET_CALL(disable_irq, sun4m_disable_irq, BTFIXUPCALL_NORM);
  409. BTFIXUPSET_CALL(enable_pil_irq, sun4m_enable_pil_irq, BTFIXUPCALL_NORM);
  410. BTFIXUPSET_CALL(disable_pil_irq, sun4m_disable_pil_irq, BTFIXUPCALL_NORM);
  411. BTFIXUPSET_CALL(clear_clock_irq, sun4m_clear_clock_irq, BTFIXUPCALL_NORM);
  412. BTFIXUPSET_CALL(load_profile_irq, sun4m_load_profile_irq, BTFIXUPCALL_NORM);
  413. sparc_init_timers = sun4m_init_timers;
  414. #ifdef CONFIG_SMP
  415. BTFIXUPSET_CALL(set_cpu_int, sun4m_send_ipi, BTFIXUPCALL_NORM);
  416. BTFIXUPSET_CALL(clear_cpu_int, sun4m_clear_ipi, BTFIXUPCALL_NORM);
  417. BTFIXUPSET_CALL(set_irq_udt, sun4m_set_udt, BTFIXUPCALL_NORM);
  418. #endif
  419. /* Cannot enable interrupts until OBP ticker is disabled. */
  420. }