sun4m_irq.c 13 KB

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