leon_kernel.c 7.3 KB

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