system.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /*
  2. * Copyright 2010 Tilera Corporation. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation, version 2.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  11. * NON INFRINGEMENT. See the GNU General Public License for
  12. * more details.
  13. */
  14. #ifndef _ASM_TILE_SYSTEM_H
  15. #define _ASM_TILE_SYSTEM_H
  16. #ifndef __ASSEMBLY__
  17. #include <linux/types.h>
  18. #include <linux/irqflags.h>
  19. /* NOTE: we can't include <linux/ptrace.h> due to #include dependencies. */
  20. #include <asm/ptrace.h>
  21. #include <arch/chip.h>
  22. #include <arch/sim_def.h>
  23. #include <arch/spr_def.h>
  24. /*
  25. * read_barrier_depends - Flush all pending reads that subsequents reads
  26. * depend on.
  27. *
  28. * No data-dependent reads from memory-like regions are ever reordered
  29. * over this barrier. All reads preceding this primitive are guaranteed
  30. * to access memory (but not necessarily other CPUs' caches) before any
  31. * reads following this primitive that depend on the data return by
  32. * any of the preceding reads. This primitive is much lighter weight than
  33. * rmb() on most CPUs, and is never heavier weight than is
  34. * rmb().
  35. *
  36. * These ordering constraints are respected by both the local CPU
  37. * and the compiler.
  38. *
  39. * Ordering is not guaranteed by anything other than these primitives,
  40. * not even by data dependencies. See the documentation for
  41. * memory_barrier() for examples and URLs to more information.
  42. *
  43. * For example, the following code would force ordering (the initial
  44. * value of "a" is zero, "b" is one, and "p" is "&a"):
  45. *
  46. * <programlisting>
  47. * CPU 0 CPU 1
  48. *
  49. * b = 2;
  50. * memory_barrier();
  51. * p = &b; q = p;
  52. * read_barrier_depends();
  53. * d = *q;
  54. * </programlisting>
  55. *
  56. * because the read of "*q" depends on the read of "p" and these
  57. * two reads are separated by a read_barrier_depends(). However,
  58. * the following code, with the same initial values for "a" and "b":
  59. *
  60. * <programlisting>
  61. * CPU 0 CPU 1
  62. *
  63. * a = 2;
  64. * memory_barrier();
  65. * b = 3; y = b;
  66. * read_barrier_depends();
  67. * x = a;
  68. * </programlisting>
  69. *
  70. * does not enforce ordering, since there is no data dependency between
  71. * the read of "a" and the read of "b". Therefore, on some CPUs, such
  72. * as Alpha, "y" could be set to 3 and "x" to 0. Use rmb()
  73. * in cases like this where there are no data dependencies.
  74. */
  75. #define read_barrier_depends() do { } while (0)
  76. #define __sync() __insn_mf()
  77. #if CHIP_HAS_SPLIT_CYCLE()
  78. #define get_cycles_low() __insn_mfspr(SPR_CYCLE_LOW)
  79. #else
  80. #define get_cycles_low() __insn_mfspr(SPR_CYCLE) /* just get all 64 bits */
  81. #endif
  82. #if !CHIP_HAS_MF_WAITS_FOR_VICTIMS()
  83. #include <hv/syscall_public.h>
  84. /*
  85. * Issue an uncacheable load to each memory controller, then
  86. * wait until those loads have completed.
  87. */
  88. static inline void __mb_incoherent(void)
  89. {
  90. long clobber_r10;
  91. asm volatile("swint2"
  92. : "=R10" (clobber_r10)
  93. : "R10" (HV_SYS_fence_incoherent)
  94. : "r0", "r1", "r2", "r3", "r4",
  95. "r5", "r6", "r7", "r8", "r9",
  96. "r11", "r12", "r13", "r14",
  97. "r15", "r16", "r17", "r18", "r19",
  98. "r20", "r21", "r22", "r23", "r24",
  99. "r25", "r26", "r27", "r28", "r29");
  100. }
  101. #endif
  102. /* Fence to guarantee visibility of stores to incoherent memory. */
  103. static inline void
  104. mb_incoherent(void)
  105. {
  106. __insn_mf();
  107. #if !CHIP_HAS_MF_WAITS_FOR_VICTIMS()
  108. {
  109. #if CHIP_HAS_TILE_WRITE_PENDING()
  110. const unsigned long WRITE_TIMEOUT_CYCLES = 400;
  111. unsigned long start = get_cycles_low();
  112. do {
  113. if (__insn_mfspr(SPR_TILE_WRITE_PENDING) == 0)
  114. return;
  115. } while ((get_cycles_low() - start) < WRITE_TIMEOUT_CYCLES);
  116. #endif /* CHIP_HAS_TILE_WRITE_PENDING() */
  117. (void) __mb_incoherent();
  118. }
  119. #endif /* CHIP_HAS_MF_WAITS_FOR_VICTIMS() */
  120. }
  121. #define fast_wmb() __sync()
  122. #define fast_rmb() __sync()
  123. #define fast_mb() __sync()
  124. #define fast_iob() mb_incoherent()
  125. #define wmb() fast_wmb()
  126. #define rmb() fast_rmb()
  127. #define mb() fast_mb()
  128. #define iob() fast_iob()
  129. #ifdef CONFIG_SMP
  130. #define smp_mb() mb()
  131. #define smp_rmb() rmb()
  132. #define smp_wmb() wmb()
  133. #define smp_read_barrier_depends() read_barrier_depends()
  134. #else
  135. #define smp_mb() barrier()
  136. #define smp_rmb() barrier()
  137. #define smp_wmb() barrier()
  138. #define smp_read_barrier_depends() do { } while (0)
  139. #endif
  140. #define set_mb(var, value) \
  141. do { var = value; mb(); } while (0)
  142. /*
  143. * Pause the DMA engine and static network before task switching.
  144. */
  145. #define prepare_arch_switch(next) _prepare_arch_switch(next)
  146. void _prepare_arch_switch(struct task_struct *next);
  147. /*
  148. * switch_to(n) should switch tasks to task nr n, first
  149. * checking that n isn't the current task, in which case it does nothing.
  150. * The number of callee-saved registers saved on the kernel stack
  151. * is defined here for use in copy_thread() and must agree with __switch_to().
  152. */
  153. #endif /* !__ASSEMBLY__ */
  154. #define CALLEE_SAVED_FIRST_REG 30
  155. #define CALLEE_SAVED_REGS_COUNT 24 /* r30 to r52, plus an empty to align */
  156. #ifndef __ASSEMBLY__
  157. struct task_struct;
  158. #define switch_to(prev, next, last) ((last) = _switch_to((prev), (next)))
  159. extern struct task_struct *_switch_to(struct task_struct *prev,
  160. struct task_struct *next);
  161. /* Helper function for _switch_to(). */
  162. extern struct task_struct *__switch_to(struct task_struct *prev,
  163. struct task_struct *next,
  164. unsigned long new_system_save_k_0);
  165. /* Address that switched-away from tasks are at. */
  166. extern unsigned long get_switch_to_pc(void);
  167. /*
  168. * On SMP systems, when the scheduler does migration-cost autodetection,
  169. * it needs a way to flush as much of the CPU's caches as possible:
  170. *
  171. * TODO: fill this in!
  172. */
  173. static inline void sched_cacheflush(void)
  174. {
  175. }
  176. #define arch_align_stack(x) (x)
  177. /*
  178. * Is the kernel doing fixups of unaligned accesses? If <0, no kernel
  179. * intervention occurs and SIGBUS is delivered with no data address
  180. * info. If 0, the kernel single-steps the instruction to discover
  181. * the data address to provide with the SIGBUS. If 1, the kernel does
  182. * a fixup.
  183. */
  184. extern int unaligned_fixup;
  185. /* Is the kernel printing on each unaligned fixup? */
  186. extern int unaligned_printk;
  187. /* Number of unaligned fixups performed */
  188. extern unsigned int unaligned_fixup_count;
  189. /* Init-time routine to do tile-specific per-cpu setup. */
  190. void setup_cpu(int boot);
  191. /* User-level DMA management functions */
  192. void grant_dma_mpls(void);
  193. void restrict_dma_mpls(void);
  194. #ifdef CONFIG_HARDWALL
  195. /* User-level network management functions */
  196. void reset_network_state(void);
  197. void grant_network_mpls(void);
  198. void restrict_network_mpls(void);
  199. int hardwall_deactivate(struct task_struct *task);
  200. /* Hook hardwall code into changes in affinity. */
  201. #define arch_set_cpus_allowed(p, new_mask) do { \
  202. if (p->thread.hardwall && !cpumask_equal(&p->cpus_allowed, new_mask)) \
  203. hardwall_deactivate(p); \
  204. } while (0)
  205. #endif
  206. /*
  207. * Kernel threads can check to see if they need to migrate their
  208. * stack whenever they return from a context switch; for user
  209. * threads, we defer until they are returning to user-space.
  210. */
  211. #define finish_arch_switch(prev) do { \
  212. if (unlikely((prev)->state == TASK_DEAD)) \
  213. __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_OS_EXIT | \
  214. ((prev)->pid << _SIM_CONTROL_OPERATOR_BITS)); \
  215. __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_OS_SWITCH | \
  216. (current->pid << _SIM_CONTROL_OPERATOR_BITS)); \
  217. if (current->mm == NULL && !kstack_hash && \
  218. current_thread_info()->homecache_cpu != smp_processor_id()) \
  219. homecache_migrate_kthread(); \
  220. } while (0)
  221. /* Support function for forking a new task. */
  222. void ret_from_fork(void);
  223. /* Called from ret_from_fork() when a new process starts up. */
  224. struct task_struct *sim_notify_fork(struct task_struct *prev);
  225. #endif /* !__ASSEMBLY__ */
  226. #endif /* _ASM_TILE_SYSTEM_H */