sun4m_irq.c 14 KB

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