sun4c_irq.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. /*
  2. * sun4c irq support
  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/init.h>
  12. #include <asm/oplib.h>
  13. #include <asm/timer.h>
  14. #include <asm/irq.h>
  15. #include <asm/io.h>
  16. #include "irq.h"
  17. /* Sun4c interrupts are typically laid out as follows:
  18. *
  19. * 1 - Software interrupt, SBUS level 1
  20. * 2 - SBUS level 2
  21. * 3 - ESP SCSI, SBUS level 3
  22. * 4 - Software interrupt
  23. * 5 - Lance ethernet, SBUS level 4
  24. * 6 - Software interrupt
  25. * 7 - Graphics card, SBUS level 5
  26. * 8 - SBUS level 6
  27. * 9 - SBUS level 7
  28. * 10 - Counter timer
  29. * 11 - Floppy
  30. * 12 - Zilog uart
  31. * 13 - CS4231 audio
  32. * 14 - Profiling timer
  33. * 15 - NMI
  34. *
  35. * The interrupt enable bits in the interrupt mask register are
  36. * really only used to enable/disable the timer interrupts, and
  37. * for signalling software interrupts. There is also a master
  38. * interrupt enable bit in this register.
  39. *
  40. * Interrupts are enabled by setting the SUN4C_INT_* bits, they
  41. * are disabled by clearing those bits.
  42. */
  43. /*
  44. * Bit field defines for the interrupt registers on various
  45. * Sparc machines.
  46. */
  47. /* The sun4c interrupt register. */
  48. #define SUN4C_INT_ENABLE 0x01 /* Allow interrupts. */
  49. #define SUN4C_INT_E14 0x80 /* Enable level 14 IRQ. */
  50. #define SUN4C_INT_E10 0x20 /* Enable level 10 IRQ. */
  51. #define SUN4C_INT_E8 0x10 /* Enable level 8 IRQ. */
  52. #define SUN4C_INT_E6 0x08 /* Enable level 6 IRQ. */
  53. #define SUN4C_INT_E4 0x04 /* Enable level 4 IRQ. */
  54. #define SUN4C_INT_E1 0x02 /* Enable level 1 IRQ. */
  55. /*
  56. * Pointer to the interrupt enable byte
  57. * Used by entry.S
  58. */
  59. unsigned char __iomem *interrupt_enable;
  60. static void sun4c_mask_irq(struct irq_data *data)
  61. {
  62. unsigned long mask = (unsigned long)data->chip_data;
  63. if (mask) {
  64. unsigned long flags;
  65. local_irq_save(flags);
  66. mask = sbus_readb(interrupt_enable) & ~mask;
  67. sbus_writeb(mask, interrupt_enable);
  68. local_irq_restore(flags);
  69. }
  70. }
  71. static void sun4c_unmask_irq(struct irq_data *data)
  72. {
  73. unsigned long mask = (unsigned long)data->chip_data;
  74. if (mask) {
  75. unsigned long flags;
  76. local_irq_save(flags);
  77. mask = sbus_readb(interrupt_enable) | mask;
  78. sbus_writeb(mask, interrupt_enable);
  79. local_irq_restore(flags);
  80. }
  81. }
  82. static unsigned int sun4c_startup_irq(struct irq_data *data)
  83. {
  84. irq_link(data->irq);
  85. sun4c_unmask_irq(data);
  86. return 0;
  87. }
  88. static void sun4c_shutdown_irq(struct irq_data *data)
  89. {
  90. sun4c_mask_irq(data);
  91. irq_unlink(data->irq);
  92. }
  93. static struct irq_chip sun4c_irq = {
  94. .name = "sun4c",
  95. .irq_startup = sun4c_startup_irq,
  96. .irq_shutdown = sun4c_shutdown_irq,
  97. .irq_mask = sun4c_mask_irq,
  98. .irq_unmask = sun4c_unmask_irq,
  99. };
  100. static unsigned int sun4c_build_device_irq(struct platform_device *op,
  101. unsigned int real_irq)
  102. {
  103. unsigned int irq;
  104. if (real_irq >= 16) {
  105. prom_printf("Bogus sun4c IRQ %u\n", real_irq);
  106. prom_halt();
  107. }
  108. irq = irq_alloc(real_irq, real_irq);
  109. if (irq) {
  110. unsigned long mask = 0UL;
  111. switch (real_irq) {
  112. case 1:
  113. mask = SUN4C_INT_E1;
  114. break;
  115. case 8:
  116. mask = SUN4C_INT_E8;
  117. break;
  118. case 10:
  119. mask = SUN4C_INT_E10;
  120. break;
  121. case 14:
  122. mask = SUN4C_INT_E14;
  123. break;
  124. default:
  125. /* All the rest are either always enabled,
  126. * or are for signalling software interrupts.
  127. */
  128. break;
  129. }
  130. irq_set_chip_and_handler_name(irq, &sun4c_irq,
  131. handle_level_irq, "level");
  132. irq_set_chip_data(irq, (void *)mask);
  133. }
  134. return irq;
  135. }
  136. struct sun4c_timer_info {
  137. u32 l10_count;
  138. u32 l10_limit;
  139. u32 l14_count;
  140. u32 l14_limit;
  141. };
  142. static struct sun4c_timer_info __iomem *sun4c_timers;
  143. static void sun4c_clear_clock_irq(void)
  144. {
  145. sbus_readl(&sun4c_timers->l10_limit);
  146. }
  147. static void sun4c_load_profile_irq(int cpu, unsigned int limit)
  148. {
  149. /* Errm.. not sure how to do this.. */
  150. }
  151. static void __init sun4c_init_timers(irq_handler_t counter_fn)
  152. {
  153. const struct linux_prom_irqs *prom_irqs;
  154. struct device_node *dp;
  155. unsigned int irq;
  156. const u32 *addr;
  157. int err;
  158. dp = of_find_node_by_name(NULL, "counter-timer");
  159. if (!dp) {
  160. prom_printf("sun4c_init_timers: Unable to find counter-timer\n");
  161. prom_halt();
  162. }
  163. addr = of_get_property(dp, "address", NULL);
  164. if (!addr) {
  165. prom_printf("sun4c_init_timers: No address property\n");
  166. prom_halt();
  167. }
  168. sun4c_timers = (void __iomem *) (unsigned long) addr[0];
  169. prom_irqs = of_get_property(dp, "intr", NULL);
  170. of_node_put(dp);
  171. if (!prom_irqs) {
  172. prom_printf("sun4c_init_timers: No intr property\n");
  173. prom_halt();
  174. }
  175. /* Have the level 10 timer tick at 100HZ. We don't touch the
  176. * level 14 timer limit since we are letting the prom handle
  177. * them until we have a real console driver so L1-A works.
  178. */
  179. sbus_writel((((1000000/HZ) + 1) << 10), &sun4c_timers->l10_limit);
  180. master_l10_counter = &sun4c_timers->l10_count;
  181. irq = sun4c_build_device_irq(NULL, prom_irqs[0].pri);
  182. err = request_irq(irq, counter_fn, IRQF_TIMER, "timer", NULL);
  183. if (err) {
  184. prom_printf("sun4c_init_timers: request_irq() fails with %d\n", err);
  185. prom_halt();
  186. }
  187. /* disable timer interrupt */
  188. sun4c_mask_irq(irq_get_irq_data(irq));
  189. }
  190. #ifdef CONFIG_SMP
  191. static void sun4c_nop(void)
  192. {
  193. }
  194. #endif
  195. void __init sun4c_init_IRQ(void)
  196. {
  197. struct device_node *dp;
  198. const u32 *addr;
  199. dp = of_find_node_by_name(NULL, "interrupt-enable");
  200. if (!dp) {
  201. prom_printf("sun4c_init_IRQ: Unable to find interrupt-enable\n");
  202. prom_halt();
  203. }
  204. addr = of_get_property(dp, "address", NULL);
  205. of_node_put(dp);
  206. if (!addr) {
  207. prom_printf("sun4c_init_IRQ: No address property\n");
  208. prom_halt();
  209. }
  210. interrupt_enable = (void __iomem *) (unsigned long) addr[0];
  211. BTFIXUPSET_CALL(clear_clock_irq, sun4c_clear_clock_irq, BTFIXUPCALL_NORM);
  212. BTFIXUPSET_CALL(load_profile_irq, sun4c_load_profile_irq, BTFIXUPCALL_NOP);
  213. sparc_irq_config.init_timers = sun4c_init_timers;
  214. sparc_irq_config.build_device_irq = sun4c_build_device_irq;
  215. #ifdef CONFIG_SMP
  216. BTFIXUPSET_CALL(set_cpu_int, sun4c_nop, BTFIXUPCALL_NOP);
  217. BTFIXUPSET_CALL(clear_cpu_int, sun4c_nop, BTFIXUPCALL_NOP);
  218. BTFIXUPSET_CALL(set_irq_udt, sun4c_nop, BTFIXUPCALL_NOP);
  219. #endif
  220. sbus_writeb(SUN4C_INT_ENABLE, interrupt_enable);
  221. /* Cannot enable interrupts until OBP ticker is disabled. */
  222. }