sun4m_irq.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  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. static unsigned long dummy;
  56. unsigned long *irq_rcvreg = &dummy;
  57. /* Dave Redman (djhr@tadpole.co.uk)
  58. * The sun4m interrupt registers.
  59. */
  60. #define SUN4M_INT_ENABLE 0x80000000
  61. #define SUN4M_INT_E14 0x00000080
  62. #define SUN4M_INT_E10 0x00080000
  63. #define SUN4M_HARD_INT(x) (0x000000001 << (x))
  64. #define SUN4M_SOFT_INT(x) (0x000010000 << (x))
  65. #define SUN4M_INT_MASKALL 0x80000000 /* mask all interrupts */
  66. #define SUN4M_INT_MODULE_ERR 0x40000000 /* module error */
  67. #define SUN4M_INT_M2S_WRITE 0x20000000 /* write buffer error */
  68. #define SUN4M_INT_ECC 0x10000000 /* ecc memory error */
  69. #define SUN4M_INT_FLOPPY 0x00400000 /* floppy disk */
  70. #define SUN4M_INT_MODULE 0x00200000 /* module interrupt */
  71. #define SUN4M_INT_VIDEO 0x00100000 /* onboard video */
  72. #define SUN4M_INT_REALTIME 0x00080000 /* system timer */
  73. #define SUN4M_INT_SCSI 0x00040000 /* onboard scsi */
  74. #define SUN4M_INT_AUDIO 0x00020000 /* audio/isdn */
  75. #define SUN4M_INT_ETHERNET 0x00010000 /* onboard ethernet */
  76. #define SUN4M_INT_SERIAL 0x00008000 /* serial ports */
  77. #define SUN4M_INT_KBDMS 0x00004000 /* keyboard/mouse */
  78. #define SUN4M_INT_SBUSBITS 0x00003F80 /* sbus int bits */
  79. #define SUN4M_INT_SBUS(x) (1 << (x+7))
  80. #define SUN4M_INT_VME(x) (1 << (x))
  81. /* These tables only apply for interrupts greater than 15..
  82. *
  83. * any intr value below 0x10 is considered to be a soft-int
  84. * this may be useful or it may not.. but that's how I've done it.
  85. * and it won't clash with what OBP is telling us about devices.
  86. *
  87. * take an encoded intr value and lookup if it's valid
  88. * then get the mask bits that match from irq_mask
  89. *
  90. * P3: Translation from irq 0x0d to mask 0x2000 is for MrCoffee.
  91. */
  92. static unsigned char irq_xlate[32] = {
  93. /* 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f */
  94. 0, 0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 5, 6, 14, 0, 7,
  95. 0, 0, 8, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 0
  96. };
  97. static unsigned long irq_mask[] = {
  98. 0, /* illegal index */
  99. SUN4M_INT_SCSI, /* 1 irq 4 */
  100. SUN4M_INT_ETHERNET, /* 2 irq 6 */
  101. SUN4M_INT_VIDEO, /* 3 irq 8 */
  102. SUN4M_INT_REALTIME, /* 4 irq 10 */
  103. SUN4M_INT_FLOPPY, /* 5 irq 11 */
  104. (SUN4M_INT_SERIAL | SUN4M_INT_KBDMS), /* 6 irq 12 */
  105. SUN4M_INT_MODULE_ERR, /* 7 irq 15 */
  106. SUN4M_INT_SBUS(0), /* 8 irq 2 */
  107. SUN4M_INT_SBUS(1), /* 9 irq 3 */
  108. SUN4M_INT_SBUS(2), /* 10 irq 5 */
  109. SUN4M_INT_SBUS(3), /* 11 irq 7 */
  110. SUN4M_INT_SBUS(4), /* 12 irq 9 */
  111. SUN4M_INT_SBUS(5), /* 13 irq 11 */
  112. SUN4M_INT_SBUS(6) /* 14 irq 13 */
  113. };
  114. static unsigned long sun4m_get_irqmask(unsigned int irq)
  115. {
  116. unsigned long mask;
  117. if (irq > 0x20) {
  118. /* OBIO/SBUS interrupts */
  119. irq &= 0x1f;
  120. mask = irq_mask[irq_xlate[irq]];
  121. if (!mask)
  122. printk("sun4m_get_irqmask: IRQ%d has no valid mask!\n",irq);
  123. } else {
  124. /* Soft Interrupts will come here.
  125. * Currently there is no way to trigger them but I'm sure
  126. * something could be cooked up.
  127. */
  128. irq &= 0xf;
  129. mask = SUN4M_SOFT_INT(irq);
  130. }
  131. return mask;
  132. }
  133. static void sun4m_disable_irq(unsigned int irq_nr)
  134. {
  135. unsigned long mask, flags;
  136. int cpu = smp_processor_id();
  137. mask = sun4m_get_irqmask(irq_nr);
  138. local_irq_save(flags);
  139. if (irq_nr > 15)
  140. sbus_writel(mask, &sun4m_irq_global->mask_set);
  141. else
  142. sbus_writel(mask, &sun4m_irq_percpu[cpu]->set);
  143. local_irq_restore(flags);
  144. }
  145. static void sun4m_enable_irq(unsigned int irq_nr)
  146. {
  147. unsigned long mask, flags;
  148. int cpu = smp_processor_id();
  149. /* Dreadful floppy hack. When we use 0x2b instead of
  150. * 0x0b the system blows (it starts to whistle!).
  151. * So we continue to use 0x0b. Fixme ASAP. --P3
  152. */
  153. if (irq_nr != 0x0b) {
  154. mask = sun4m_get_irqmask(irq_nr);
  155. local_irq_save(flags);
  156. if (irq_nr > 15)
  157. sbus_writel(mask, &sun4m_irq_global->mask_clear);
  158. else
  159. sbus_writel(mask, &sun4m_irq_percpu[cpu]->clear);
  160. local_irq_restore(flags);
  161. } else {
  162. local_irq_save(flags);
  163. sbus_writel(SUN4M_INT_FLOPPY, &sun4m_irq_global->mask_clear);
  164. local_irq_restore(flags);
  165. }
  166. }
  167. static unsigned long cpu_pil_to_imask[16] = {
  168. /*0*/ 0x00000000,
  169. /*1*/ 0x00000000,
  170. /*2*/ SUN4M_INT_SBUS(0) | SUN4M_INT_VME(0),
  171. /*3*/ SUN4M_INT_SBUS(1) | SUN4M_INT_VME(1),
  172. /*4*/ SUN4M_INT_SCSI,
  173. /*5*/ SUN4M_INT_SBUS(2) | SUN4M_INT_VME(2),
  174. /*6*/ SUN4M_INT_ETHERNET,
  175. /*7*/ SUN4M_INT_SBUS(3) | SUN4M_INT_VME(3),
  176. /*8*/ SUN4M_INT_VIDEO,
  177. /*9*/ SUN4M_INT_SBUS(4) | SUN4M_INT_VME(4) | SUN4M_INT_MODULE_ERR,
  178. /*10*/ SUN4M_INT_REALTIME,
  179. /*11*/ SUN4M_INT_SBUS(5) | SUN4M_INT_VME(5) | SUN4M_INT_FLOPPY,
  180. /*12*/ SUN4M_INT_SERIAL | SUN4M_INT_KBDMS,
  181. /*13*/ SUN4M_INT_AUDIO,
  182. /*14*/ SUN4M_INT_E14,
  183. /*15*/ 0x00000000
  184. };
  185. /* We assume the caller has disabled local interrupts when these are called,
  186. * or else very bizarre behavior will result.
  187. */
  188. static void sun4m_disable_pil_irq(unsigned int pil)
  189. {
  190. sbus_writel(cpu_pil_to_imask[pil], &sun4m_irq_global->mask_set);
  191. }
  192. static void sun4m_enable_pil_irq(unsigned int pil)
  193. {
  194. sbus_writel(cpu_pil_to_imask[pil], &sun4m_irq_global->mask_clear);
  195. }
  196. #ifdef CONFIG_SMP
  197. static void sun4m_send_ipi(int cpu, int level)
  198. {
  199. unsigned long mask = sun4m_get_irqmask(level);
  200. sbus_writel(mask, &sun4m_irq_percpu[cpu]->set);
  201. }
  202. static void sun4m_clear_ipi(int cpu, int level)
  203. {
  204. unsigned long mask = sun4m_get_irqmask(level);
  205. sbus_writel(mask, &sun4m_irq_percpu[cpu]->clear);
  206. }
  207. static void sun4m_set_udt(int cpu)
  208. {
  209. sbus_writel(cpu, &sun4m_irq_global->interrupt_target);
  210. }
  211. #endif
  212. struct sun4m_timer_percpu {
  213. u32 l14_limit;
  214. u32 l14_count;
  215. u32 l14_limit_noclear;
  216. u32 user_timer_start_stop;
  217. };
  218. static struct sun4m_timer_percpu __iomem *timers_percpu[SUN4M_NCPUS];
  219. struct sun4m_timer_global {
  220. u32 l10_limit;
  221. u32 l10_count;
  222. u32 l10_limit_noclear;
  223. u32 reserved;
  224. u32 timer_config;
  225. };
  226. static struct sun4m_timer_global __iomem *timers_global;
  227. #define OBIO_INTR 0x20
  228. #define TIMER_IRQ (OBIO_INTR | 10)
  229. unsigned int lvl14_resolution = (((1000000/HZ) + 1) << 10);
  230. static void sun4m_clear_clock_irq(void)
  231. {
  232. sbus_readl(&timers_global->l10_limit);
  233. }
  234. /* Exported for sun4m_smp.c */
  235. void sun4m_clear_profile_irq(int cpu)
  236. {
  237. sbus_readl(&timers_percpu[cpu]->l14_limit);
  238. }
  239. static void sun4m_load_profile_irq(int cpu, unsigned int limit)
  240. {
  241. sbus_writel(limit, &timers_percpu[cpu]->l14_limit);
  242. }
  243. static void __init sun4m_init_timers(irq_handler_t counter_fn)
  244. {
  245. struct device_node *dp = of_find_node_by_name(NULL, "counter");
  246. int i, err, len, num_cpu_timers;
  247. const u32 *addr;
  248. if (!dp) {
  249. printk(KERN_ERR "sun4m_init_timers: No 'counter' node.\n");
  250. return;
  251. }
  252. addr = of_get_property(dp, "address", &len);
  253. if (!addr) {
  254. printk(KERN_ERR "sun4m_init_timers: No 'address' prop.\n");
  255. return;
  256. }
  257. num_cpu_timers = (len / sizeof(u32)) - 1;
  258. for (i = 0; i < num_cpu_timers; i++) {
  259. timers_percpu[i] = (void __iomem *)
  260. (unsigned long) addr[i];
  261. }
  262. timers_global = (void __iomem *)
  263. (unsigned long) addr[num_cpu_timers];
  264. sbus_writel((((1000000/HZ) + 1) << 10), &timers_global->l10_limit);
  265. master_l10_counter = &timers_global->l10_count;
  266. master_l10_limit = &timers_global->l10_limit;
  267. err = request_irq(TIMER_IRQ, counter_fn,
  268. (IRQF_DISABLED | SA_STATIC_ALLOC), "timer", NULL);
  269. if (err) {
  270. printk(KERN_ERR "sun4m_init_timers: Register IRQ error %d.\n",
  271. err);
  272. return;
  273. }
  274. for (i = 0; i < num_cpu_timers; i++)
  275. sbus_writel(0, &timers_percpu[i]->l14_limit);
  276. if (num_cpu_timers == 4)
  277. sbus_writel(SUN4M_INT_E14, &sun4m_irq_global->mask_set);
  278. #ifdef CONFIG_SMP
  279. {
  280. unsigned long flags;
  281. extern unsigned long lvl14_save[4];
  282. struct tt_entry *trap_table = &sparc_ttable[SP_TRAP_IRQ1 + (14 - 1)];
  283. /* For SMP we use the level 14 ticker, however the bootup code
  284. * has copied the firmware's level 14 vector into the boot cpu's
  285. * trap table, we must fix this now or we get squashed.
  286. */
  287. local_irq_save(flags);
  288. trap_table->inst_one = lvl14_save[0];
  289. trap_table->inst_two = lvl14_save[1];
  290. trap_table->inst_three = lvl14_save[2];
  291. trap_table->inst_four = lvl14_save[3];
  292. local_flush_cache_all();
  293. local_irq_restore(flags);
  294. }
  295. #endif
  296. }
  297. void __init sun4m_init_IRQ(void)
  298. {
  299. struct device_node *dp = of_find_node_by_name(NULL, "interrupt");
  300. int len, i, mid, num_cpu_iregs;
  301. const u32 *addr;
  302. if (!dp) {
  303. printk(KERN_ERR "sun4m_init_IRQ: No 'interrupt' node.\n");
  304. return;
  305. }
  306. addr = of_get_property(dp, "address", &len);
  307. if (!addr) {
  308. printk(KERN_ERR "sun4m_init_IRQ: No 'address' prop.\n");
  309. return;
  310. }
  311. num_cpu_iregs = (len / sizeof(u32)) - 1;
  312. for (i = 0; i < num_cpu_iregs; i++) {
  313. sun4m_irq_percpu[i] = (void __iomem *)
  314. (unsigned long) addr[i];
  315. }
  316. sun4m_irq_global = (void __iomem *)
  317. (unsigned long) addr[num_cpu_iregs];
  318. local_irq_disable();
  319. sbus_writel(~SUN4M_INT_MASKALL, &sun4m_irq_global->mask_set);
  320. for (i = 0; !cpu_find_by_instance(i, NULL, &mid); i++)
  321. sbus_writel(~0x17fff, &sun4m_irq_percpu[mid]->clear);
  322. if (num_cpu_iregs == 4) {
  323. irq_rcvreg = (unsigned long *) &sun4m_irq_global->interrupt_target;
  324. sbus_writel(0, &sun4m_irq_global->interrupt_target);
  325. }
  326. BTFIXUPSET_CALL(enable_irq, sun4m_enable_irq, BTFIXUPCALL_NORM);
  327. BTFIXUPSET_CALL(disable_irq, sun4m_disable_irq, BTFIXUPCALL_NORM);
  328. BTFIXUPSET_CALL(enable_pil_irq, sun4m_enable_pil_irq, BTFIXUPCALL_NORM);
  329. BTFIXUPSET_CALL(disable_pil_irq, sun4m_disable_pil_irq, BTFIXUPCALL_NORM);
  330. BTFIXUPSET_CALL(clear_clock_irq, sun4m_clear_clock_irq, BTFIXUPCALL_NORM);
  331. BTFIXUPSET_CALL(clear_profile_irq, sun4m_clear_profile_irq, BTFIXUPCALL_NORM);
  332. BTFIXUPSET_CALL(load_profile_irq, sun4m_load_profile_irq, BTFIXUPCALL_NORM);
  333. sparc_init_timers = sun4m_init_timers;
  334. #ifdef CONFIG_SMP
  335. BTFIXUPSET_CALL(set_cpu_int, sun4m_send_ipi, BTFIXUPCALL_NORM);
  336. BTFIXUPSET_CALL(clear_cpu_int, sun4m_clear_ipi, BTFIXUPCALL_NORM);
  337. BTFIXUPSET_CALL(set_irq_udt, sun4m_set_udt, BTFIXUPCALL_NORM);
  338. #endif
  339. /* Cannot enable interrupts until OBP ticker is disabled. */
  340. }