leon_kernel.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. /*
  2. * Copyright (C) 2009 Daniel Hellstrom (daniel@gaisler.com) Aeroflex Gaisler AB
  3. * Copyright (C) 2009 Konrad Eisele (konrad@gaisler.com) Aeroflex Gaisler AB
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/module.h>
  7. #include <linux/errno.h>
  8. #include <linux/mutex.h>
  9. #include <linux/of.h>
  10. #include <linux/of_platform.h>
  11. #include <linux/interrupt.h>
  12. #include <linux/of_device.h>
  13. #include <asm/oplib.h>
  14. #include <asm/timer.h>
  15. #include <asm/prom.h>
  16. #include <asm/leon.h>
  17. #include <asm/leon_amba.h>
  18. #include <asm/traps.h>
  19. #include <asm/cacheflush.h>
  20. #include "prom.h"
  21. #include "irq.h"
  22. struct leon3_irqctrl_regs_map *leon3_irqctrl_regs; /* interrupt controller base address, initialized by amba_init() */
  23. struct leon3_gptimer_regs_map *leon3_gptimer_regs; /* timer controller base address, initialized by amba_init() */
  24. struct amba_apb_device leon_percpu_timer_dev[16];
  25. int leondebug_irq_disable;
  26. int leon_debug_irqout;
  27. static int dummy_master_l10_counter;
  28. unsigned long leon3_gptimer_irq; /* interrupt controller irq number, initialized by amba_init() */
  29. unsigned int sparc_leon_eirq;
  30. #define LEON_IMASK ((&leon3_irqctrl_regs->mask[0]))
  31. /* Return the IRQ of the pending IRQ on the extended IRQ controller */
  32. int sparc_leon_eirq_get(int eirq, int cpu)
  33. {
  34. return LEON3_BYPASS_LOAD_PA(&leon3_irqctrl_regs->intid[cpu]) & 0x1f;
  35. }
  36. irqreturn_t sparc_leon_eirq_isr(int dummy, void *dev_id)
  37. {
  38. printk(KERN_ERR "sparc_leon_eirq_isr: ERROR EXTENDED IRQ\n");
  39. return IRQ_HANDLED;
  40. }
  41. /* The extended IRQ controller has been found, this function registers it */
  42. void sparc_leon_eirq_register(int eirq)
  43. {
  44. int irq;
  45. /* Register a "BAD" handler for this interrupt, it should never happen */
  46. irq = request_irq(eirq, sparc_leon_eirq_isr,
  47. (IRQF_DISABLED | SA_STATIC_ALLOC), "extirq", NULL);
  48. if (irq) {
  49. printk(KERN_ERR
  50. "sparc_leon_eirq_register: unable to attach IRQ%d\n",
  51. eirq);
  52. } else {
  53. sparc_leon_eirq = eirq;
  54. }
  55. }
  56. static inline unsigned long get_irqmask(unsigned int irq)
  57. {
  58. unsigned long mask;
  59. if (!irq || ((irq > 0xf) && !sparc_leon_eirq)
  60. || ((irq > 0x1f) && sparc_leon_eirq)) {
  61. printk(KERN_ERR
  62. "leon_get_irqmask: false irq number: %d\n", irq);
  63. mask = 0;
  64. } else {
  65. mask = LEON_HARD_INT(irq);
  66. }
  67. return mask;
  68. }
  69. static void leon_enable_irq(unsigned int irq_nr)
  70. {
  71. unsigned long mask, flags;
  72. mask = get_irqmask(irq_nr);
  73. local_irq_save(flags);
  74. LEON3_BYPASS_STORE_PA(LEON_IMASK,
  75. (LEON3_BYPASS_LOAD_PA(LEON_IMASK) | (mask)));
  76. local_irq_restore(flags);
  77. }
  78. static void leon_disable_irq(unsigned int irq_nr)
  79. {
  80. unsigned long mask, flags;
  81. mask = get_irqmask(irq_nr);
  82. local_irq_save(flags);
  83. LEON3_BYPASS_STORE_PA(LEON_IMASK,
  84. (LEON3_BYPASS_LOAD_PA(LEON_IMASK) & ~(mask)));
  85. local_irq_restore(flags);
  86. }
  87. void __init leon_init_timers(irq_handler_t counter_fn)
  88. {
  89. int irq;
  90. leondebug_irq_disable = 0;
  91. leon_debug_irqout = 0;
  92. master_l10_counter = (unsigned int *)&dummy_master_l10_counter;
  93. dummy_master_l10_counter = 0;
  94. if (leon3_gptimer_regs && leon3_irqctrl_regs) {
  95. LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[0].val, 0);
  96. LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[0].rld,
  97. (((1000000 / 100) - 1)));
  98. LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[0].ctrl, 0);
  99. #ifdef CONFIG_SMP
  100. leon_percpu_timer_dev[0].start = (int)leon3_gptimer_regs;
  101. leon_percpu_timer_dev[0].irq = leon3_gptimer_irq+1;
  102. if (!(LEON3_BYPASS_LOAD_PA(&leon3_gptimer_regs->config) &
  103. (1<<LEON3_GPTIMER_SEPIRQ))) {
  104. prom_printf("irq timer not configured with separate irqs\n");
  105. BUG();
  106. }
  107. LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[1].val, 0);
  108. LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[1].rld, (((1000000/100) - 1)));
  109. LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[1].ctrl, 0);
  110. # endif
  111. } else {
  112. printk(KERN_ERR "No Timer/irqctrl found\n");
  113. BUG();
  114. }
  115. irq = request_irq(leon3_gptimer_irq,
  116. counter_fn,
  117. (IRQF_DISABLED | SA_STATIC_ALLOC), "timer", NULL);
  118. if (irq) {
  119. printk(KERN_ERR "leon_time_init: unable to attach IRQ%d\n",
  120. LEON_INTERRUPT_TIMER1);
  121. prom_halt();
  122. }
  123. # ifdef CONFIG_SMP
  124. {
  125. unsigned long flags;
  126. struct tt_entry *trap_table = &sparc_ttable[SP_TRAP_IRQ1 + (leon_percpu_timer_dev[0].irq - 1)];
  127. /* For SMP we use the level 14 ticker, however the bootup code
  128. * has copied the firmwares level 14 vector into boot cpu's
  129. * trap table, we must fix this now or we get squashed.
  130. */
  131. local_irq_save(flags);
  132. patchme_maybe_smp_msg[0] = 0x01000000; /* NOP out the branch */
  133. /* Adjust so that we jump directly to smpleon_ticker */
  134. trap_table->inst_three += smpleon_ticker - real_irq_entry;
  135. local_flush_cache_all();
  136. local_irq_restore(flags);
  137. }
  138. # endif
  139. if (leon3_gptimer_regs) {
  140. LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[0].ctrl,
  141. LEON3_GPTIMER_EN |
  142. LEON3_GPTIMER_RL |
  143. LEON3_GPTIMER_LD | LEON3_GPTIMER_IRQEN);
  144. #ifdef CONFIG_SMP
  145. LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[1].ctrl,
  146. LEON3_GPTIMER_EN |
  147. LEON3_GPTIMER_RL |
  148. LEON3_GPTIMER_LD |
  149. LEON3_GPTIMER_IRQEN);
  150. #endif
  151. }
  152. }
  153. void leon_clear_clock_irq(void)
  154. {
  155. }
  156. void leon_load_profile_irq(int cpu, unsigned int limit)
  157. {
  158. BUG();
  159. }
  160. void __init leon_trans_init(struct device_node *dp)
  161. {
  162. if (strcmp(dp->type, "cpu") == 0 && strcmp(dp->name, "<NULL>") == 0) {
  163. struct property *p;
  164. p = of_find_property(dp, "mid", (void *)0);
  165. if (p) {
  166. int mid;
  167. dp->name = prom_early_alloc(5 + 1);
  168. memcpy(&mid, p->value, p->length);
  169. sprintf((char *)dp->name, "cpu%.2d", mid);
  170. }
  171. }
  172. }
  173. void __initdata (*prom_amba_init)(struct device_node *dp, struct device_node ***nextp) = 0;
  174. void __init leon_node_init(struct device_node *dp, struct device_node ***nextp)
  175. {
  176. if (prom_amba_init &&
  177. strcmp(dp->type, "ambapp") == 0 &&
  178. strcmp(dp->name, "ambapp0") == 0) {
  179. prom_amba_init(dp, nextp);
  180. }
  181. }
  182. #ifdef CONFIG_SMP
  183. void leon_set_cpu_int(int cpu, int level)
  184. {
  185. unsigned long mask;
  186. mask = get_irqmask(level);
  187. LEON3_BYPASS_STORE_PA(&leon3_irqctrl_regs->force[cpu], mask);
  188. }
  189. static void leon_clear_ipi(int cpu, int level)
  190. {
  191. unsigned long mask;
  192. mask = get_irqmask(level);
  193. LEON3_BYPASS_STORE_PA(&leon3_irqctrl_regs->force[cpu], mask<<16);
  194. }
  195. static void leon_set_udt(int cpu)
  196. {
  197. }
  198. void leon_clear_profile_irq(int cpu)
  199. {
  200. }
  201. void leon_enable_irq_cpu(unsigned int irq_nr, unsigned int cpu)
  202. {
  203. unsigned long mask, flags, *addr;
  204. mask = get_irqmask(irq_nr);
  205. local_irq_save(flags);
  206. addr = (unsigned long *)&(leon3_irqctrl_regs->mask[cpu]);
  207. LEON3_BYPASS_STORE_PA(addr, (LEON3_BYPASS_LOAD_PA(addr) | (mask)));
  208. local_irq_restore(flags);
  209. }
  210. #endif
  211. void __init leon_init_IRQ(void)
  212. {
  213. sparc_init_timers = leon_init_timers;
  214. BTFIXUPSET_CALL(enable_irq, leon_enable_irq, BTFIXUPCALL_NORM);
  215. BTFIXUPSET_CALL(disable_irq, leon_disable_irq, BTFIXUPCALL_NORM);
  216. BTFIXUPSET_CALL(enable_pil_irq, leon_enable_irq, BTFIXUPCALL_NORM);
  217. BTFIXUPSET_CALL(disable_pil_irq, leon_disable_irq, BTFIXUPCALL_NORM);
  218. BTFIXUPSET_CALL(clear_clock_irq, leon_clear_clock_irq,
  219. BTFIXUPCALL_NORM);
  220. BTFIXUPSET_CALL(load_profile_irq, leon_load_profile_irq,
  221. BTFIXUPCALL_NOP);
  222. #ifdef CONFIG_SMP
  223. BTFIXUPSET_CALL(set_cpu_int, leon_set_cpu_int, BTFIXUPCALL_NORM);
  224. BTFIXUPSET_CALL(clear_cpu_int, leon_clear_ipi, BTFIXUPCALL_NORM);
  225. BTFIXUPSET_CALL(set_irq_udt, leon_set_udt, BTFIXUPCALL_NORM);
  226. #endif
  227. }
  228. void __init leon_init(void)
  229. {
  230. prom_build_more = &leon_node_init;
  231. }