sun4m_irq.c 14 KB

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