ipipe.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /* -*- linux-c -*-
  2. * include/asm-blackfin/ipipe.h
  3. *
  4. * Copyright (C) 2002-2007 Philippe Gerum.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA 02139,
  9. * USA; either version 2 of the License, or (at your option) any later
  10. * version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20. */
  21. #ifndef __ASM_BLACKFIN_IPIPE_H
  22. #define __ASM_BLACKFIN_IPIPE_H
  23. #ifdef CONFIG_IPIPE
  24. #include <linux/cpumask.h>
  25. #include <linux/list.h>
  26. #include <linux/threads.h>
  27. #include <linux/irq.h>
  28. #include <linux/ipipe_percpu.h>
  29. #include <asm/ptrace.h>
  30. #include <asm/irq.h>
  31. #include <asm/bitops.h>
  32. #include <asm/atomic.h>
  33. #include <asm/traps.h>
  34. #define IPIPE_ARCH_STRING "1.8-00"
  35. #define IPIPE_MAJOR_NUMBER 1
  36. #define IPIPE_MINOR_NUMBER 8
  37. #define IPIPE_PATCH_NUMBER 0
  38. #ifdef CONFIG_SMP
  39. #error "I-pipe/blackfin: SMP not implemented"
  40. #else /* !CONFIG_SMP */
  41. #define ipipe_processor_id() 0
  42. #endif /* CONFIG_SMP */
  43. #define prepare_arch_switch(next) \
  44. do { \
  45. ipipe_schedule_notify(current, next); \
  46. local_irq_disable_hw(); \
  47. } while (0)
  48. #define task_hijacked(p) \
  49. ({ \
  50. int __x__ = ipipe_current_domain != ipipe_root_domain; \
  51. /* We would need to clear the SYNC flag for the root domain */ \
  52. /* over the current processor in SMP mode. */ \
  53. local_irq_enable_hw(); __x__; \
  54. })
  55. struct ipipe_domain;
  56. struct ipipe_sysinfo {
  57. int ncpus; /* Number of CPUs on board */
  58. u64 cpufreq; /* CPU frequency (in Hz) */
  59. /* Arch-dependent block */
  60. struct {
  61. unsigned tmirq; /* Timer tick IRQ */
  62. u64 tmfreq; /* Timer frequency */
  63. } archdep;
  64. };
  65. #define ipipe_read_tsc(t) \
  66. ({ \
  67. unsigned long __cy2; \
  68. __asm__ __volatile__ ("1: %0 = CYCLES2\n" \
  69. "%1 = CYCLES\n" \
  70. "%2 = CYCLES2\n" \
  71. "CC = %2 == %0\n" \
  72. "if ! CC jump 1b\n" \
  73. : "=r" (((unsigned long *)&t)[1]), \
  74. "=r" (((unsigned long *)&t)[0]), \
  75. "=r" (__cy2) \
  76. : /*no input*/ : "CC"); \
  77. t; \
  78. })
  79. #define ipipe_cpu_freq() __ipipe_core_clock
  80. #define ipipe_tsc2ns(_t) (((unsigned long)(_t)) * __ipipe_freq_scale)
  81. #define ipipe_tsc2us(_t) (ipipe_tsc2ns(_t) / 1000 + 1)
  82. /* Private interface -- Internal use only */
  83. #define __ipipe_check_platform() do { } while (0)
  84. #define __ipipe_init_platform() do { } while (0)
  85. extern atomic_t __ipipe_irq_lvdepth[IVG15 + 1];
  86. extern unsigned long __ipipe_irq_lvmask;
  87. extern struct ipipe_domain ipipe_root;
  88. /* enable/disable_irqdesc _must_ be used in pairs. */
  89. void __ipipe_enable_irqdesc(struct ipipe_domain *ipd,
  90. unsigned irq);
  91. void __ipipe_disable_irqdesc(struct ipipe_domain *ipd,
  92. unsigned irq);
  93. #define __ipipe_enable_irq(irq) (irq_desc[irq].chip->unmask(irq))
  94. #define __ipipe_disable_irq(irq) (irq_desc[irq].chip->mask(irq))
  95. #define __ipipe_lock_root() \
  96. set_bit(IPIPE_ROOTLOCK_FLAG, &ipipe_root_domain->flags)
  97. #define __ipipe_unlock_root() \
  98. clear_bit(IPIPE_ROOTLOCK_FLAG, &ipipe_root_domain->flags)
  99. void __ipipe_enable_pipeline(void);
  100. #define __ipipe_hook_critical_ipi(ipd) do { } while (0)
  101. #define __ipipe_sync_pipeline(syncmask) \
  102. do { \
  103. struct ipipe_domain *ipd = ipipe_current_domain; \
  104. if (likely(ipd != ipipe_root_domain || !test_bit(IPIPE_ROOTLOCK_FLAG, &ipd->flags))) \
  105. __ipipe_sync_stage(syncmask); \
  106. } while (0)
  107. void __ipipe_handle_irq(unsigned irq, struct pt_regs *regs);
  108. int __ipipe_get_irq_priority(unsigned irq);
  109. int __ipipe_get_irqthread_priority(unsigned irq);
  110. void __ipipe_stall_root_raw(void);
  111. void __ipipe_unstall_root_raw(void);
  112. void __ipipe_serial_debug(const char *fmt, ...);
  113. DECLARE_PER_CPU(struct pt_regs, __ipipe_tick_regs);
  114. extern unsigned long __ipipe_core_clock;
  115. extern unsigned long __ipipe_freq_scale;
  116. extern unsigned long __ipipe_irq_tail_hook;
  117. static inline unsigned long __ipipe_ffnz(unsigned long ul)
  118. {
  119. return ffs(ul) - 1;
  120. }
  121. #define __ipipe_run_irqtail() /* Must be a macro */ \
  122. do { \
  123. asmlinkage void __ipipe_call_irqtail(void); \
  124. unsigned long __pending; \
  125. CSYNC(); \
  126. __pending = bfin_read_IPEND(); \
  127. if (__pending & 0x8000) { \
  128. __pending &= ~0x8010; \
  129. if (__pending && (__pending & (__pending - 1)) == 0) \
  130. __ipipe_call_irqtail(); \
  131. } \
  132. } while (0)
  133. #define __ipipe_run_isr(ipd, irq) \
  134. do { \
  135. if (ipd == ipipe_root_domain) { \
  136. /* \
  137. * Note: the I-pipe implements a threaded interrupt model on \
  138. * this arch for Linux external IRQs. The interrupt handler we \
  139. * call here only wakes up the associated IRQ thread. \
  140. */ \
  141. if (ipipe_virtual_irq_p(irq)) { \
  142. /* No irqtail here; virtual interrupts have no effect \
  143. on IPEND so there is no need for processing \
  144. deferral. */ \
  145. local_irq_enable_nohead(ipd); \
  146. ipd->irqs[irq].handler(irq, ipd->irqs[irq].cookie); \
  147. local_irq_disable_nohead(ipd); \
  148. } else \
  149. /* \
  150. * No need to run the irqtail here either; \
  151. * we can't be preempted by hw IRQs, so \
  152. * non-Linux IRQs cannot stack over the short \
  153. * thread wakeup code. Which in turn means \
  154. * that no irqtail condition could be pending \
  155. * for domains above Linux in the pipeline. \
  156. */ \
  157. ipd->irqs[irq].handler(irq, &__raw_get_cpu_var(__ipipe_tick_regs)); \
  158. } else { \
  159. __clear_bit(IPIPE_SYNC_FLAG, &ipipe_cpudom_var(ipd, status)); \
  160. local_irq_enable_nohead(ipd); \
  161. ipd->irqs[irq].handler(irq, ipd->irqs[irq].cookie); \
  162. /* Attempt to exit the outer interrupt level before \
  163. * starting the deferred IRQ processing. */ \
  164. local_irq_disable_nohead(ipd); \
  165. __ipipe_run_irqtail(); \
  166. __set_bit(IPIPE_SYNC_FLAG, &ipipe_cpudom_var(ipd, status)); \
  167. } \
  168. } while (0)
  169. #define __ipipe_syscall_watched_p(p, sc) \
  170. (((p)->flags & PF_EVNOTIFY) || (unsigned long)sc >= NR_syscalls)
  171. void ipipe_init_irq_threads(void);
  172. int ipipe_start_irq_thread(unsigned irq, struct irq_desc *desc);
  173. #define IS_SYSIRQ(irq) ((irq) > IRQ_CORETMR && (irq) <= SYS_IRQS)
  174. #define IS_GPIOIRQ(irq) ((irq) >= GPIO_IRQ_BASE && (irq) < NR_IRQS)
  175. #define IRQ_SYSTMR IRQ_TIMER0
  176. #define IRQ_PRIOTMR CONFIG_IRQ_TIMER0
  177. #if defined(CONFIG_BF531) || defined(CONFIG_BF532) || defined(CONFIG_BF533)
  178. #define PRIO_GPIODEMUX(irq) CONFIG_PFA
  179. #elif defined(CONFIG_BF534) || defined(CONFIG_BF536) || defined(CONFIG_BF537)
  180. #define PRIO_GPIODEMUX(irq) CONFIG_IRQ_PROG_INTA
  181. #elif defined(CONFIG_BF52x)
  182. #define PRIO_GPIODEMUX(irq) ((irq) == IRQ_PORTF_INTA ? CONFIG_IRQ_PORTF_INTA : \
  183. (irq) == IRQ_PORTG_INTA ? CONFIG_IRQ_PORTG_INTA : \
  184. (irq) == IRQ_PORTH_INTA ? CONFIG_IRQ_PORTH_INTA : \
  185. -1)
  186. #elif defined(CONFIG_BF561)
  187. #define PRIO_GPIODEMUX(irq) ((irq) == IRQ_PROG0_INTA ? CONFIG_IRQ_PROG0_INTA : \
  188. (irq) == IRQ_PROG1_INTA ? CONFIG_IRQ_PROG1_INTA : \
  189. (irq) == IRQ_PROG2_INTA ? CONFIG_IRQ_PROG2_INTA : \
  190. -1)
  191. #define bfin_write_TIMER_DISABLE(val) bfin_write_TMRS8_DISABLE(val)
  192. #define bfin_write_TIMER_ENABLE(val) bfin_write_TMRS8_ENABLE(val)
  193. #define bfin_write_TIMER_STATUS(val) bfin_write_TMRS8_STATUS(val)
  194. #define bfin_read_TIMER_STATUS() bfin_read_TMRS8_STATUS()
  195. #elif defined(CONFIG_BF54x)
  196. #define PRIO_GPIODEMUX(irq) ((irq) == IRQ_PINT0 ? CONFIG_IRQ_PINT0 : \
  197. (irq) == IRQ_PINT1 ? CONFIG_IRQ_PINT1 : \
  198. (irq) == IRQ_PINT2 ? CONFIG_IRQ_PINT2 : \
  199. (irq) == IRQ_PINT3 ? CONFIG_IRQ_PINT3 : \
  200. -1)
  201. #define bfin_write_TIMER_DISABLE(val) bfin_write_TIMER_DISABLE0(val)
  202. #define bfin_write_TIMER_ENABLE(val) bfin_write_TIMER_ENABLE0(val)
  203. #define bfin_write_TIMER_STATUS(val) bfin_write_TIMER_STATUS0(val)
  204. #define bfin_read_TIMER_STATUS(val) bfin_read_TIMER_STATUS0(val)
  205. #else
  206. # error "no PRIO_GPIODEMUX() for this part"
  207. #endif
  208. #define __ipipe_root_tick_p(regs) ((regs->ipend & 0x10) != 0)
  209. #else /* !CONFIG_IPIPE */
  210. #define task_hijacked(p) 0
  211. #define ipipe_trap_notify(t, r) 0
  212. #define __ipipe_stall_root_raw() do { } while (0)
  213. #define __ipipe_unstall_root_raw() do { } while (0)
  214. #define ipipe_init_irq_threads() do { } while (0)
  215. #define ipipe_start_irq_thread(irq, desc) 0
  216. #define IRQ_SYSTMR IRQ_CORETMR
  217. #define IRQ_PRIOTMR IRQ_CORETMR
  218. #define __ipipe_root_tick_p(regs) 1
  219. #endif /* !CONFIG_IPIPE */
  220. #endif /* !__ASM_BLACKFIN_IPIPE_H */