sun4m_irq.c 13 KB

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