sun4m_irq.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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/config.h>
  12. #include <linux/errno.h>
  13. #include <linux/linkage.h>
  14. #include <linux/kernel_stat.h>
  15. #include <linux/signal.h>
  16. #include <linux/sched.h>
  17. #include <linux/ptrace.h>
  18. #include <linux/smp.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/slab.h>
  21. #include <linux/init.h>
  22. #include <linux/ioport.h>
  23. #include <asm/ptrace.h>
  24. #include <asm/processor.h>
  25. #include <asm/system.h>
  26. #include <asm/psr.h>
  27. #include <asm/vaddrs.h>
  28. #include <asm/timer.h>
  29. #include <asm/openprom.h>
  30. #include <asm/oplib.h>
  31. #include <asm/traps.h>
  32. #include <asm/pgalloc.h>
  33. #include <asm/pgtable.h>
  34. #include <asm/smp.h>
  35. #include <asm/irq.h>
  36. #include <asm/io.h>
  37. #include <asm/sbus.h>
  38. #include <asm/cacheflush.h>
  39. static unsigned long dummy;
  40. struct sun4m_intregs *sun4m_interrupts;
  41. unsigned long *irq_rcvreg = &dummy;
  42. /* These tables only apply for interrupts greater than 15..
  43. *
  44. * any intr value below 0x10 is considered to be a soft-int
  45. * this may be useful or it may not.. but that's how I've done it.
  46. * and it won't clash with what OBP is telling us about devices.
  47. *
  48. * take an encoded intr value and lookup if it's valid
  49. * then get the mask bits that match from irq_mask
  50. *
  51. * P3: Translation from irq 0x0d to mask 0x2000 is for MrCoffee.
  52. */
  53. static unsigned char irq_xlate[32] = {
  54. /* 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f */
  55. 0, 0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 5, 6, 14, 0, 7,
  56. 0, 0, 8, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 0
  57. };
  58. static unsigned long irq_mask[] = {
  59. 0, /* illegal index */
  60. SUN4M_INT_SCSI, /* 1 irq 4 */
  61. SUN4M_INT_ETHERNET, /* 2 irq 6 */
  62. SUN4M_INT_VIDEO, /* 3 irq 8 */
  63. SUN4M_INT_REALTIME, /* 4 irq 10 */
  64. SUN4M_INT_FLOPPY, /* 5 irq 11 */
  65. (SUN4M_INT_SERIAL | SUN4M_INT_KBDMS), /* 6 irq 12 */
  66. SUN4M_INT_MODULE_ERR, /* 7 irq 15 */
  67. SUN4M_INT_SBUS(0), /* 8 irq 2 */
  68. SUN4M_INT_SBUS(1), /* 9 irq 3 */
  69. SUN4M_INT_SBUS(2), /* 10 irq 5 */
  70. SUN4M_INT_SBUS(3), /* 11 irq 7 */
  71. SUN4M_INT_SBUS(4), /* 12 irq 9 */
  72. SUN4M_INT_SBUS(5), /* 13 irq 11 */
  73. SUN4M_INT_SBUS(6) /* 14 irq 13 */
  74. };
  75. static int sun4m_pil_map[] = { 0, 2, 3, 5, 7, 9, 11, 13 };
  76. unsigned int sun4m_sbint_to_irq(struct sbus_dev *sdev, unsigned int sbint)
  77. {
  78. if (sbint >= sizeof(sun4m_pil_map)) {
  79. printk(KERN_ERR "%s: bogus SBINT %d\n", sdev->prom_name, sbint);
  80. BUG();
  81. }
  82. return sun4m_pil_map[sbint] | 0x30;
  83. }
  84. inline unsigned long sun4m_get_irqmask(unsigned int irq)
  85. {
  86. unsigned long mask;
  87. if (irq > 0x20) {
  88. /* OBIO/SBUS interrupts */
  89. irq &= 0x1f;
  90. mask = irq_mask[irq_xlate[irq]];
  91. if (!mask)
  92. printk("sun4m_get_irqmask: IRQ%d has no valid mask!\n",irq);
  93. } else {
  94. /* Soft Interrupts will come here.
  95. * Currently there is no way to trigger them but I'm sure
  96. * something could be cooked up.
  97. */
  98. irq &= 0xf;
  99. mask = SUN4M_SOFT_INT(irq);
  100. }
  101. return mask;
  102. }
  103. static void sun4m_disable_irq(unsigned int irq_nr)
  104. {
  105. unsigned long mask, flags;
  106. int cpu = smp_processor_id();
  107. mask = sun4m_get_irqmask(irq_nr);
  108. local_irq_save(flags);
  109. if (irq_nr > 15)
  110. sun4m_interrupts->set = mask;
  111. else
  112. sun4m_interrupts->cpu_intregs[cpu].set = mask;
  113. local_irq_restore(flags);
  114. }
  115. static void sun4m_enable_irq(unsigned int irq_nr)
  116. {
  117. unsigned long mask, flags;
  118. int cpu = smp_processor_id();
  119. /* Dreadful floppy hack. When we use 0x2b instead of
  120. * 0x0b the system blows (it starts to whistle!).
  121. * So we continue to use 0x0b. Fixme ASAP. --P3
  122. */
  123. if (irq_nr != 0x0b) {
  124. mask = sun4m_get_irqmask(irq_nr);
  125. local_irq_save(flags);
  126. if (irq_nr > 15)
  127. sun4m_interrupts->clear = mask;
  128. else
  129. sun4m_interrupts->cpu_intregs[cpu].clear = mask;
  130. local_irq_restore(flags);
  131. } else {
  132. local_irq_save(flags);
  133. sun4m_interrupts->clear = SUN4M_INT_FLOPPY;
  134. local_irq_restore(flags);
  135. }
  136. }
  137. static unsigned long cpu_pil_to_imask[16] = {
  138. /*0*/ 0x00000000,
  139. /*1*/ 0x00000000,
  140. /*2*/ SUN4M_INT_SBUS(0) | SUN4M_INT_VME(0),
  141. /*3*/ SUN4M_INT_SBUS(1) | SUN4M_INT_VME(1),
  142. /*4*/ SUN4M_INT_SCSI,
  143. /*5*/ SUN4M_INT_SBUS(2) | SUN4M_INT_VME(2),
  144. /*6*/ SUN4M_INT_ETHERNET,
  145. /*7*/ SUN4M_INT_SBUS(3) | SUN4M_INT_VME(3),
  146. /*8*/ SUN4M_INT_VIDEO,
  147. /*9*/ SUN4M_INT_SBUS(4) | SUN4M_INT_VME(4) | SUN4M_INT_MODULE_ERR,
  148. /*10*/ SUN4M_INT_REALTIME,
  149. /*11*/ SUN4M_INT_SBUS(5) | SUN4M_INT_VME(5) | SUN4M_INT_FLOPPY,
  150. /*12*/ SUN4M_INT_SERIAL | SUN4M_INT_KBDMS,
  151. /*13*/ SUN4M_INT_AUDIO,
  152. /*14*/ SUN4M_INT_E14,
  153. /*15*/ 0x00000000
  154. };
  155. /* We assume the caller has disabled local interrupts when these are called,
  156. * or else very bizarre behavior will result.
  157. */
  158. static void sun4m_disable_pil_irq(unsigned int pil)
  159. {
  160. sun4m_interrupts->set = cpu_pil_to_imask[pil];
  161. }
  162. static void sun4m_enable_pil_irq(unsigned int pil)
  163. {
  164. sun4m_interrupts->clear = cpu_pil_to_imask[pil];
  165. }
  166. #ifdef CONFIG_SMP
  167. static void sun4m_send_ipi(int cpu, int level)
  168. {
  169. unsigned long mask;
  170. mask = sun4m_get_irqmask(level);
  171. sun4m_interrupts->cpu_intregs[cpu].set = mask;
  172. }
  173. static void sun4m_clear_ipi(int cpu, int level)
  174. {
  175. unsigned long mask;
  176. mask = sun4m_get_irqmask(level);
  177. sun4m_interrupts->cpu_intregs[cpu].clear = mask;
  178. }
  179. static void sun4m_set_udt(int cpu)
  180. {
  181. sun4m_interrupts->undirected_target = cpu;
  182. }
  183. #endif
  184. #define OBIO_INTR 0x20
  185. #define TIMER_IRQ (OBIO_INTR | 10)
  186. #define PROFILE_IRQ (OBIO_INTR | 14)
  187. struct sun4m_timer_regs *sun4m_timers;
  188. unsigned int lvl14_resolution = (((1000000/HZ) + 1) << 10);
  189. static void sun4m_clear_clock_irq(void)
  190. {
  191. volatile unsigned int clear_intr;
  192. clear_intr = sun4m_timers->l10_timer_limit;
  193. }
  194. static void sun4m_clear_profile_irq(int cpu)
  195. {
  196. volatile unsigned int clear;
  197. clear = sun4m_timers->cpu_timers[cpu].l14_timer_limit;
  198. }
  199. static void sun4m_load_profile_irq(int cpu, unsigned int limit)
  200. {
  201. sun4m_timers->cpu_timers[cpu].l14_timer_limit = limit;
  202. }
  203. char *sun4m_irq_itoa(unsigned int irq)
  204. {
  205. static char buff[16];
  206. sprintf(buff, "%d", irq);
  207. return buff;
  208. }
  209. static void __init sun4m_init_timers(irqreturn_t (*counter_fn)(int, void *, struct pt_regs *))
  210. {
  211. int reg_count, irq, cpu;
  212. struct linux_prom_registers cnt_regs[PROMREG_MAX];
  213. int obio_node, cnt_node;
  214. struct resource r;
  215. cnt_node = 0;
  216. if((obio_node =
  217. prom_searchsiblings (prom_getchild(prom_root_node), "obio")) == 0 ||
  218. (obio_node = prom_getchild (obio_node)) == 0 ||
  219. (cnt_node = prom_searchsiblings (obio_node, "counter")) == 0) {
  220. prom_printf("Cannot find /obio/counter node\n");
  221. prom_halt();
  222. }
  223. reg_count = prom_getproperty(cnt_node, "reg",
  224. (void *) cnt_regs, sizeof(cnt_regs));
  225. reg_count = (reg_count/sizeof(struct linux_prom_registers));
  226. /* Apply the obio ranges to the timer registers. */
  227. prom_apply_obio_ranges(cnt_regs, reg_count);
  228. cnt_regs[4].phys_addr = cnt_regs[reg_count-1].phys_addr;
  229. cnt_regs[4].reg_size = cnt_regs[reg_count-1].reg_size;
  230. cnt_regs[4].which_io = cnt_regs[reg_count-1].which_io;
  231. for(obio_node = 1; obio_node < 4; obio_node++) {
  232. cnt_regs[obio_node].phys_addr =
  233. cnt_regs[obio_node-1].phys_addr + PAGE_SIZE;
  234. cnt_regs[obio_node].reg_size = cnt_regs[obio_node-1].reg_size;
  235. cnt_regs[obio_node].which_io = cnt_regs[obio_node-1].which_io;
  236. }
  237. memset((char*)&r, 0, sizeof(struct resource));
  238. /* Map the per-cpu Counter registers. */
  239. r.flags = cnt_regs[0].which_io;
  240. r.start = cnt_regs[0].phys_addr;
  241. sun4m_timers = (struct sun4m_timer_regs *) sbus_ioremap(&r, 0,
  242. PAGE_SIZE*SUN4M_NCPUS, "sun4m_cpu_cnt");
  243. /* Map the system Counter register. */
  244. /* XXX Here we expect consequent calls to yeld adjusent maps. */
  245. r.flags = cnt_regs[4].which_io;
  246. r.start = cnt_regs[4].phys_addr;
  247. sbus_ioremap(&r, 0, cnt_regs[4].reg_size, "sun4m_sys_cnt");
  248. sun4m_timers->l10_timer_limit = (((1000000/HZ) + 1) << 10);
  249. master_l10_counter = &sun4m_timers->l10_cur_count;
  250. master_l10_limit = &sun4m_timers->l10_timer_limit;
  251. irq = request_irq(TIMER_IRQ,
  252. counter_fn,
  253. (SA_INTERRUPT | SA_STATIC_ALLOC),
  254. "timer", NULL);
  255. if (irq) {
  256. prom_printf("time_init: unable to attach IRQ%d\n",TIMER_IRQ);
  257. prom_halt();
  258. }
  259. if (!cpu_find_by_instance(1, NULL, NULL)) {
  260. for(cpu = 0; cpu < 4; cpu++)
  261. sun4m_timers->cpu_timers[cpu].l14_timer_limit = 0;
  262. sun4m_interrupts->set = SUN4M_INT_E14;
  263. } else {
  264. sun4m_timers->cpu_timers[0].l14_timer_limit = 0;
  265. }
  266. #ifdef CONFIG_SMP
  267. {
  268. unsigned long flags;
  269. extern unsigned long lvl14_save[4];
  270. struct tt_entry *trap_table = &sparc_ttable[SP_TRAP_IRQ1 + (14 - 1)];
  271. /* For SMP we use the level 14 ticker, however the bootup code
  272. * has copied the firmwares level 14 vector into boot cpu's
  273. * trap table, we must fix this now or we get squashed.
  274. */
  275. local_irq_save(flags);
  276. trap_table->inst_one = lvl14_save[0];
  277. trap_table->inst_two = lvl14_save[1];
  278. trap_table->inst_three = lvl14_save[2];
  279. trap_table->inst_four = lvl14_save[3];
  280. local_flush_cache_all();
  281. local_irq_restore(flags);
  282. }
  283. #endif
  284. }
  285. void __init sun4m_init_IRQ(void)
  286. {
  287. int ie_node,i;
  288. struct linux_prom_registers int_regs[PROMREG_MAX];
  289. int num_regs;
  290. struct resource r;
  291. int mid;
  292. local_irq_disable();
  293. if((ie_node = prom_searchsiblings(prom_getchild(prom_root_node), "obio")) == 0 ||
  294. (ie_node = prom_getchild (ie_node)) == 0 ||
  295. (ie_node = prom_searchsiblings (ie_node, "interrupt")) == 0) {
  296. prom_printf("Cannot find /obio/interrupt node\n");
  297. prom_halt();
  298. }
  299. num_regs = prom_getproperty(ie_node, "reg", (char *) int_regs,
  300. sizeof(int_regs));
  301. num_regs = (num_regs/sizeof(struct linux_prom_registers));
  302. /* Apply the obio ranges to these registers. */
  303. prom_apply_obio_ranges(int_regs, num_regs);
  304. int_regs[4].phys_addr = int_regs[num_regs-1].phys_addr;
  305. int_regs[4].reg_size = int_regs[num_regs-1].reg_size;
  306. int_regs[4].which_io = int_regs[num_regs-1].which_io;
  307. for(ie_node = 1; ie_node < 4; ie_node++) {
  308. int_regs[ie_node].phys_addr = int_regs[ie_node-1].phys_addr + PAGE_SIZE;
  309. int_regs[ie_node].reg_size = int_regs[ie_node-1].reg_size;
  310. int_regs[ie_node].which_io = int_regs[ie_node-1].which_io;
  311. }
  312. memset((char *)&r, 0, sizeof(struct resource));
  313. /* Map the interrupt registers for all possible cpus. */
  314. r.flags = int_regs[0].which_io;
  315. r.start = int_regs[0].phys_addr;
  316. sun4m_interrupts = (struct sun4m_intregs *) sbus_ioremap(&r, 0,
  317. PAGE_SIZE*SUN4M_NCPUS, "interrupts_percpu");
  318. /* Map the system interrupt control registers. */
  319. r.flags = int_regs[4].which_io;
  320. r.start = int_regs[4].phys_addr;
  321. sbus_ioremap(&r, 0, int_regs[4].reg_size, "interrupts_system");
  322. sun4m_interrupts->set = ~SUN4M_INT_MASKALL;
  323. for (i = 0; !cpu_find_by_instance(i, NULL, &mid); i++)
  324. sun4m_interrupts->cpu_intregs[mid].clear = ~0x17fff;
  325. if (!cpu_find_by_instance(1, NULL, NULL)) {
  326. /* system wide interrupts go to cpu 0, this should always
  327. * be safe because it is guaranteed to be fitted or OBP doesn't
  328. * come up
  329. *
  330. * Not sure, but writing here on SLAVIO systems may puke
  331. * so I don't do it unless there is more than 1 cpu.
  332. */
  333. irq_rcvreg = (unsigned long *)
  334. &sun4m_interrupts->undirected_target;
  335. sun4m_interrupts->undirected_target = 0;
  336. }
  337. BTFIXUPSET_CALL(sbint_to_irq, sun4m_sbint_to_irq, BTFIXUPCALL_NORM);
  338. BTFIXUPSET_CALL(enable_irq, sun4m_enable_irq, BTFIXUPCALL_NORM);
  339. BTFIXUPSET_CALL(disable_irq, sun4m_disable_irq, BTFIXUPCALL_NORM);
  340. BTFIXUPSET_CALL(enable_pil_irq, sun4m_enable_pil_irq, BTFIXUPCALL_NORM);
  341. BTFIXUPSET_CALL(disable_pil_irq, sun4m_disable_pil_irq, BTFIXUPCALL_NORM);
  342. BTFIXUPSET_CALL(clear_clock_irq, sun4m_clear_clock_irq, BTFIXUPCALL_NORM);
  343. BTFIXUPSET_CALL(clear_profile_irq, sun4m_clear_profile_irq, BTFIXUPCALL_NORM);
  344. BTFIXUPSET_CALL(load_profile_irq, sun4m_load_profile_irq, BTFIXUPCALL_NORM);
  345. BTFIXUPSET_CALL(__irq_itoa, sun4m_irq_itoa, BTFIXUPCALL_NORM);
  346. sparc_init_timers = sun4m_init_timers;
  347. #ifdef CONFIG_SMP
  348. BTFIXUPSET_CALL(set_cpu_int, sun4m_send_ipi, BTFIXUPCALL_NORM);
  349. BTFIXUPSET_CALL(clear_cpu_int, sun4m_clear_ipi, BTFIXUPCALL_NORM);
  350. BTFIXUPSET_CALL(set_irq_udt, sun4m_set_udt, BTFIXUPCALL_NORM);
  351. #endif
  352. /* Cannot enable interrupts until OBP ticker is disabled. */
  353. }