sun4m_irq.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  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 <asm/ptrace.h>
  23. #include <asm/processor.h>
  24. #include <asm/system.h>
  25. #include <asm/psr.h>
  26. #include <asm/vaddrs.h>
  27. #include <asm/timer.h>
  28. #include <asm/openprom.h>
  29. #include <asm/oplib.h>
  30. #include <asm/traps.h>
  31. #include <asm/pgalloc.h>
  32. #include <asm/pgtable.h>
  33. #include <asm/smp.h>
  34. #include <asm/irq.h>
  35. #include <asm/io.h>
  36. #include <asm/sbus.h>
  37. #include <asm/cacheflush.h>
  38. #include "irq.h"
  39. /* On the sun4m, just like the timers, we have both per-cpu and master
  40. * interrupt registers.
  41. */
  42. /* These registers are used for sending/receiving irqs from/to
  43. * different cpu's.
  44. */
  45. struct sun4m_intreg_percpu {
  46. unsigned int tbt; /* Interrupts still pending for this cpu. */
  47. /* These next two registers are WRITE-ONLY and are only
  48. * "on bit" sensitive, "off bits" written have NO affect.
  49. */
  50. unsigned int clear; /* Clear this cpus irqs here. */
  51. unsigned int set; /* Set this cpus irqs here. */
  52. unsigned char space[PAGE_SIZE - 12];
  53. };
  54. /*
  55. * djhr
  56. * Actually the clear and set fields in this struct are misleading..
  57. * according to the SLAVIO manual (and the same applies for the SEC)
  58. * the clear field clears bits in the mask which will ENABLE that IRQ
  59. * the set field sets bits in the mask to DISABLE the IRQ.
  60. *
  61. * Also the undirected_xx address in the SLAVIO is defined as
  62. * RESERVED and write only..
  63. *
  64. * DAVEM_NOTE: The SLAVIO only specifies behavior on uniprocessor
  65. * sun4m machines, for MP the layout makes more sense.
  66. */
  67. struct sun4m_intregs {
  68. struct sun4m_intreg_percpu cpu_intregs[SUN4M_NCPUS];
  69. unsigned int tbt; /* IRQ's that are still pending. */
  70. unsigned int irqs; /* Master IRQ bits. */
  71. /* Again, like the above, two these registers are WRITE-ONLY. */
  72. unsigned int clear; /* Clear master IRQ's by setting bits here. */
  73. unsigned int set; /* Set master IRQ's by setting bits here. */
  74. /* This register is both READ and WRITE. */
  75. unsigned int undirected_target; /* Which cpu gets undirected irqs. */
  76. };
  77. static unsigned long dummy;
  78. struct sun4m_intregs *sun4m_interrupts;
  79. unsigned long *irq_rcvreg = &dummy;
  80. /* Dave Redman (djhr@tadpole.co.uk)
  81. * The sun4m interrupt registers.
  82. */
  83. #define SUN4M_INT_ENABLE 0x80000000
  84. #define SUN4M_INT_E14 0x00000080
  85. #define SUN4M_INT_E10 0x00080000
  86. #define SUN4M_HARD_INT(x) (0x000000001 << (x))
  87. #define SUN4M_SOFT_INT(x) (0x000010000 << (x))
  88. #define SUN4M_INT_MASKALL 0x80000000 /* mask all interrupts */
  89. #define SUN4M_INT_MODULE_ERR 0x40000000 /* module error */
  90. #define SUN4M_INT_M2S_WRITE 0x20000000 /* write buffer error */
  91. #define SUN4M_INT_ECC 0x10000000 /* ecc memory error */
  92. #define SUN4M_INT_FLOPPY 0x00400000 /* floppy disk */
  93. #define SUN4M_INT_MODULE 0x00200000 /* module interrupt */
  94. #define SUN4M_INT_VIDEO 0x00100000 /* onboard video */
  95. #define SUN4M_INT_REALTIME 0x00080000 /* system timer */
  96. #define SUN4M_INT_SCSI 0x00040000 /* onboard scsi */
  97. #define SUN4M_INT_AUDIO 0x00020000 /* audio/isdn */
  98. #define SUN4M_INT_ETHERNET 0x00010000 /* onboard ethernet */
  99. #define SUN4M_INT_SERIAL 0x00008000 /* serial ports */
  100. #define SUN4M_INT_KBDMS 0x00004000 /* keyboard/mouse */
  101. #define SUN4M_INT_SBUSBITS 0x00003F80 /* sbus int bits */
  102. #define SUN4M_INT_SBUS(x) (1 << (x+7))
  103. #define SUN4M_INT_VME(x) (1 << (x))
  104. /* These tables only apply for interrupts greater than 15..
  105. *
  106. * any intr value below 0x10 is considered to be a soft-int
  107. * this may be useful or it may not.. but that's how I've done it.
  108. * and it won't clash with what OBP is telling us about devices.
  109. *
  110. * take an encoded intr value and lookup if it's valid
  111. * then get the mask bits that match from irq_mask
  112. *
  113. * P3: Translation from irq 0x0d to mask 0x2000 is for MrCoffee.
  114. */
  115. static unsigned char irq_xlate[32] = {
  116. /* 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f */
  117. 0, 0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 5, 6, 14, 0, 7,
  118. 0, 0, 8, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 0
  119. };
  120. static unsigned long irq_mask[] = {
  121. 0, /* illegal index */
  122. SUN4M_INT_SCSI, /* 1 irq 4 */
  123. SUN4M_INT_ETHERNET, /* 2 irq 6 */
  124. SUN4M_INT_VIDEO, /* 3 irq 8 */
  125. SUN4M_INT_REALTIME, /* 4 irq 10 */
  126. SUN4M_INT_FLOPPY, /* 5 irq 11 */
  127. (SUN4M_INT_SERIAL | SUN4M_INT_KBDMS), /* 6 irq 12 */
  128. SUN4M_INT_MODULE_ERR, /* 7 irq 15 */
  129. SUN4M_INT_SBUS(0), /* 8 irq 2 */
  130. SUN4M_INT_SBUS(1), /* 9 irq 3 */
  131. SUN4M_INT_SBUS(2), /* 10 irq 5 */
  132. SUN4M_INT_SBUS(3), /* 11 irq 7 */
  133. SUN4M_INT_SBUS(4), /* 12 irq 9 */
  134. SUN4M_INT_SBUS(5), /* 13 irq 11 */
  135. SUN4M_INT_SBUS(6) /* 14 irq 13 */
  136. };
  137. static int sun4m_pil_map[] = { 0, 2, 3, 5, 7, 9, 11, 13 };
  138. static unsigned int sun4m_sbint_to_irq(struct sbus_dev *sdev,
  139. unsigned int sbint)
  140. {
  141. if (sbint >= sizeof(sun4m_pil_map)) {
  142. printk(KERN_ERR "%s: bogus SBINT %d\n", sdev->prom_name, sbint);
  143. BUG();
  144. }
  145. return sun4m_pil_map[sbint] | 0x30;
  146. }
  147. static unsigned long sun4m_get_irqmask(unsigned int irq)
  148. {
  149. unsigned long mask;
  150. if (irq > 0x20) {
  151. /* OBIO/SBUS interrupts */
  152. irq &= 0x1f;
  153. mask = irq_mask[irq_xlate[irq]];
  154. if (!mask)
  155. printk("sun4m_get_irqmask: IRQ%d has no valid mask!\n",irq);
  156. } else {
  157. /* Soft Interrupts will come here.
  158. * Currently there is no way to trigger them but I'm sure
  159. * something could be cooked up.
  160. */
  161. irq &= 0xf;
  162. mask = SUN4M_SOFT_INT(irq);
  163. }
  164. return mask;
  165. }
  166. static void sun4m_disable_irq(unsigned int irq_nr)
  167. {
  168. unsigned long mask, flags;
  169. int cpu = smp_processor_id();
  170. mask = sun4m_get_irqmask(irq_nr);
  171. local_irq_save(flags);
  172. if (irq_nr > 15)
  173. sun4m_interrupts->set = mask;
  174. else
  175. sun4m_interrupts->cpu_intregs[cpu].set = mask;
  176. local_irq_restore(flags);
  177. }
  178. static void sun4m_enable_irq(unsigned int irq_nr)
  179. {
  180. unsigned long mask, flags;
  181. int cpu = smp_processor_id();
  182. /* Dreadful floppy hack. When we use 0x2b instead of
  183. * 0x0b the system blows (it starts to whistle!).
  184. * So we continue to use 0x0b. Fixme ASAP. --P3
  185. */
  186. if (irq_nr != 0x0b) {
  187. mask = sun4m_get_irqmask(irq_nr);
  188. local_irq_save(flags);
  189. if (irq_nr > 15)
  190. sun4m_interrupts->clear = mask;
  191. else
  192. sun4m_interrupts->cpu_intregs[cpu].clear = mask;
  193. local_irq_restore(flags);
  194. } else {
  195. local_irq_save(flags);
  196. sun4m_interrupts->clear = SUN4M_INT_FLOPPY;
  197. local_irq_restore(flags);
  198. }
  199. }
  200. static unsigned long cpu_pil_to_imask[16] = {
  201. /*0*/ 0x00000000,
  202. /*1*/ 0x00000000,
  203. /*2*/ SUN4M_INT_SBUS(0) | SUN4M_INT_VME(0),
  204. /*3*/ SUN4M_INT_SBUS(1) | SUN4M_INT_VME(1),
  205. /*4*/ SUN4M_INT_SCSI,
  206. /*5*/ SUN4M_INT_SBUS(2) | SUN4M_INT_VME(2),
  207. /*6*/ SUN4M_INT_ETHERNET,
  208. /*7*/ SUN4M_INT_SBUS(3) | SUN4M_INT_VME(3),
  209. /*8*/ SUN4M_INT_VIDEO,
  210. /*9*/ SUN4M_INT_SBUS(4) | SUN4M_INT_VME(4) | SUN4M_INT_MODULE_ERR,
  211. /*10*/ SUN4M_INT_REALTIME,
  212. /*11*/ SUN4M_INT_SBUS(5) | SUN4M_INT_VME(5) | SUN4M_INT_FLOPPY,
  213. /*12*/ SUN4M_INT_SERIAL | SUN4M_INT_KBDMS,
  214. /*13*/ SUN4M_INT_AUDIO,
  215. /*14*/ SUN4M_INT_E14,
  216. /*15*/ 0x00000000
  217. };
  218. /* We assume the caller has disabled local interrupts when these are called,
  219. * or else very bizarre behavior will result.
  220. */
  221. static void sun4m_disable_pil_irq(unsigned int pil)
  222. {
  223. sun4m_interrupts->set = cpu_pil_to_imask[pil];
  224. }
  225. static void sun4m_enable_pil_irq(unsigned int pil)
  226. {
  227. sun4m_interrupts->clear = cpu_pil_to_imask[pil];
  228. }
  229. #ifdef CONFIG_SMP
  230. static void sun4m_send_ipi(int cpu, int level)
  231. {
  232. unsigned long mask;
  233. mask = sun4m_get_irqmask(level);
  234. sun4m_interrupts->cpu_intregs[cpu].set = mask;
  235. }
  236. static void sun4m_clear_ipi(int cpu, int level)
  237. {
  238. unsigned long mask;
  239. mask = sun4m_get_irqmask(level);
  240. sun4m_interrupts->cpu_intregs[cpu].clear = mask;
  241. }
  242. static void sun4m_set_udt(int cpu)
  243. {
  244. sun4m_interrupts->undirected_target = cpu;
  245. }
  246. #endif
  247. #define OBIO_INTR 0x20
  248. #define TIMER_IRQ (OBIO_INTR | 10)
  249. #define PROFILE_IRQ (OBIO_INTR | 14)
  250. static struct sun4m_timer_regs *sun4m_timers;
  251. unsigned int lvl14_resolution = (((1000000/HZ) + 1) << 10);
  252. static void sun4m_clear_clock_irq(void)
  253. {
  254. volatile unsigned int clear_intr;
  255. clear_intr = sun4m_timers->l10_timer_limit;
  256. }
  257. static void sun4m_clear_profile_irq(int cpu)
  258. {
  259. volatile unsigned int clear;
  260. clear = sun4m_timers->cpu_timers[cpu].l14_timer_limit;
  261. }
  262. static void sun4m_load_profile_irq(int cpu, unsigned int limit)
  263. {
  264. sun4m_timers->cpu_timers[cpu].l14_timer_limit = limit;
  265. }
  266. static void __init sun4m_init_timers(irq_handler_t counter_fn)
  267. {
  268. int reg_count, irq, cpu;
  269. struct linux_prom_registers cnt_regs[PROMREG_MAX];
  270. int obio_node, cnt_node;
  271. struct resource r;
  272. cnt_node = 0;
  273. if((obio_node =
  274. prom_searchsiblings (prom_getchild(prom_root_node), "obio")) == 0 ||
  275. (obio_node = prom_getchild (obio_node)) == 0 ||
  276. (cnt_node = prom_searchsiblings (obio_node, "counter")) == 0) {
  277. prom_printf("Cannot find /obio/counter node\n");
  278. prom_halt();
  279. }
  280. reg_count = prom_getproperty(cnt_node, "reg",
  281. (void *) cnt_regs, sizeof(cnt_regs));
  282. reg_count = (reg_count/sizeof(struct linux_prom_registers));
  283. /* Apply the obio ranges to the timer registers. */
  284. prom_apply_obio_ranges(cnt_regs, reg_count);
  285. cnt_regs[4].phys_addr = cnt_regs[reg_count-1].phys_addr;
  286. cnt_regs[4].reg_size = cnt_regs[reg_count-1].reg_size;
  287. cnt_regs[4].which_io = cnt_regs[reg_count-1].which_io;
  288. for(obio_node = 1; obio_node < 4; obio_node++) {
  289. cnt_regs[obio_node].phys_addr =
  290. cnt_regs[obio_node-1].phys_addr + PAGE_SIZE;
  291. cnt_regs[obio_node].reg_size = cnt_regs[obio_node-1].reg_size;
  292. cnt_regs[obio_node].which_io = cnt_regs[obio_node-1].which_io;
  293. }
  294. memset((char*)&r, 0, sizeof(struct resource));
  295. /* Map the per-cpu Counter registers. */
  296. r.flags = cnt_regs[0].which_io;
  297. r.start = cnt_regs[0].phys_addr;
  298. sun4m_timers = (struct sun4m_timer_regs *) sbus_ioremap(&r, 0,
  299. PAGE_SIZE*SUN4M_NCPUS, "sun4m_cpu_cnt");
  300. /* Map the system Counter register. */
  301. /* XXX Here we expect consequent calls to yeld adjusent maps. */
  302. r.flags = cnt_regs[4].which_io;
  303. r.start = cnt_regs[4].phys_addr;
  304. sbus_ioremap(&r, 0, cnt_regs[4].reg_size, "sun4m_sys_cnt");
  305. sun4m_timers->l10_timer_limit = (((1000000/HZ) + 1) << 10);
  306. master_l10_counter = &sun4m_timers->l10_cur_count;
  307. master_l10_limit = &sun4m_timers->l10_timer_limit;
  308. irq = request_irq(TIMER_IRQ,
  309. counter_fn,
  310. (IRQF_DISABLED | SA_STATIC_ALLOC),
  311. "timer", NULL);
  312. if (irq) {
  313. prom_printf("time_init: unable to attach IRQ%d\n",TIMER_IRQ);
  314. prom_halt();
  315. }
  316. if (!cpu_find_by_instance(1, NULL, NULL)) {
  317. for(cpu = 0; cpu < 4; cpu++)
  318. sun4m_timers->cpu_timers[cpu].l14_timer_limit = 0;
  319. sun4m_interrupts->set = SUN4M_INT_E14;
  320. } else {
  321. sun4m_timers->cpu_timers[0].l14_timer_limit = 0;
  322. }
  323. #ifdef CONFIG_SMP
  324. {
  325. unsigned long flags;
  326. extern unsigned long lvl14_save[4];
  327. struct tt_entry *trap_table = &sparc_ttable[SP_TRAP_IRQ1 + (14 - 1)];
  328. /* For SMP we use the level 14 ticker, however the bootup code
  329. * has copied the firmware's level 14 vector into the boot cpu's
  330. * trap table, we must fix this now or we get squashed.
  331. */
  332. local_irq_save(flags);
  333. trap_table->inst_one = lvl14_save[0];
  334. trap_table->inst_two = lvl14_save[1];
  335. trap_table->inst_three = lvl14_save[2];
  336. trap_table->inst_four = lvl14_save[3];
  337. local_flush_cache_all();
  338. local_irq_restore(flags);
  339. }
  340. #endif
  341. }
  342. void __init sun4m_init_IRQ(void)
  343. {
  344. int ie_node,i;
  345. struct linux_prom_registers int_regs[PROMREG_MAX];
  346. int num_regs;
  347. struct resource r;
  348. int mid;
  349. local_irq_disable();
  350. if((ie_node = prom_searchsiblings(prom_getchild(prom_root_node), "obio")) == 0 ||
  351. (ie_node = prom_getchild (ie_node)) == 0 ||
  352. (ie_node = prom_searchsiblings (ie_node, "interrupt")) == 0) {
  353. prom_printf("Cannot find /obio/interrupt node\n");
  354. prom_halt();
  355. }
  356. num_regs = prom_getproperty(ie_node, "reg", (char *) int_regs,
  357. sizeof(int_regs));
  358. num_regs = (num_regs/sizeof(struct linux_prom_registers));
  359. /* Apply the obio ranges to these registers. */
  360. prom_apply_obio_ranges(int_regs, num_regs);
  361. int_regs[4].phys_addr = int_regs[num_regs-1].phys_addr;
  362. int_regs[4].reg_size = int_regs[num_regs-1].reg_size;
  363. int_regs[4].which_io = int_regs[num_regs-1].which_io;
  364. for(ie_node = 1; ie_node < 4; ie_node++) {
  365. int_regs[ie_node].phys_addr = int_regs[ie_node-1].phys_addr + PAGE_SIZE;
  366. int_regs[ie_node].reg_size = int_regs[ie_node-1].reg_size;
  367. int_regs[ie_node].which_io = int_regs[ie_node-1].which_io;
  368. }
  369. memset((char *)&r, 0, sizeof(struct resource));
  370. /* Map the interrupt registers for all possible cpus. */
  371. r.flags = int_regs[0].which_io;
  372. r.start = int_regs[0].phys_addr;
  373. sun4m_interrupts = (struct sun4m_intregs *) sbus_ioremap(&r, 0,
  374. PAGE_SIZE*SUN4M_NCPUS, "interrupts_percpu");
  375. /* Map the system interrupt control registers. */
  376. r.flags = int_regs[4].which_io;
  377. r.start = int_regs[4].phys_addr;
  378. sbus_ioremap(&r, 0, int_regs[4].reg_size, "interrupts_system");
  379. sun4m_interrupts->set = ~SUN4M_INT_MASKALL;
  380. for (i = 0; !cpu_find_by_instance(i, NULL, &mid); i++)
  381. sun4m_interrupts->cpu_intregs[mid].clear = ~0x17fff;
  382. if (!cpu_find_by_instance(1, NULL, NULL)) {
  383. /* system wide interrupts go to cpu 0, this should always
  384. * be safe because it is guaranteed to be fitted or OBP doesn't
  385. * come up
  386. *
  387. * Not sure, but writing here on SLAVIO systems may puke
  388. * so I don't do it unless there is more than 1 cpu.
  389. */
  390. irq_rcvreg = (unsigned long *)
  391. &sun4m_interrupts->undirected_target;
  392. sun4m_interrupts->undirected_target = 0;
  393. }
  394. BTFIXUPSET_CALL(sbint_to_irq, sun4m_sbint_to_irq, BTFIXUPCALL_NORM);
  395. BTFIXUPSET_CALL(enable_irq, sun4m_enable_irq, BTFIXUPCALL_NORM);
  396. BTFIXUPSET_CALL(disable_irq, sun4m_disable_irq, BTFIXUPCALL_NORM);
  397. BTFIXUPSET_CALL(enable_pil_irq, sun4m_enable_pil_irq, BTFIXUPCALL_NORM);
  398. BTFIXUPSET_CALL(disable_pil_irq, sun4m_disable_pil_irq, BTFIXUPCALL_NORM);
  399. BTFIXUPSET_CALL(clear_clock_irq, sun4m_clear_clock_irq, BTFIXUPCALL_NORM);
  400. BTFIXUPSET_CALL(clear_profile_irq, sun4m_clear_profile_irq, BTFIXUPCALL_NORM);
  401. BTFIXUPSET_CALL(load_profile_irq, sun4m_load_profile_irq, BTFIXUPCALL_NORM);
  402. sparc_init_timers = sun4m_init_timers;
  403. #ifdef CONFIG_SMP
  404. BTFIXUPSET_CALL(set_cpu_int, sun4m_send_ipi, BTFIXUPCALL_NORM);
  405. BTFIXUPSET_CALL(clear_cpu_int, sun4m_clear_ipi, BTFIXUPCALL_NORM);
  406. BTFIXUPSET_CALL(set_irq_udt, sun4m_set_udt, BTFIXUPCALL_NORM);
  407. #endif
  408. /* Cannot enable interrupts until OBP ticker is disabled. */
  409. }