system.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. int __mb_incoherent(void); /* Helper routine for mb_incoherent(). */
  84. #endif
  85. /* Fence to guarantee visibility of stores to incoherent memory. */
  86. static inline void
  87. mb_incoherent(void)
  88. {
  89. __insn_mf();
  90. #if !CHIP_HAS_MF_WAITS_FOR_VICTIMS()
  91. {
  92. #if CHIP_HAS_TILE_WRITE_PENDING()
  93. const unsigned long WRITE_TIMEOUT_CYCLES = 400;
  94. unsigned long start = get_cycles_low();
  95. do {
  96. if (__insn_mfspr(SPR_TILE_WRITE_PENDING) == 0)
  97. return;
  98. } while ((get_cycles_low() - start) < WRITE_TIMEOUT_CYCLES);
  99. #endif /* CHIP_HAS_TILE_WRITE_PENDING() */
  100. (void) __mb_incoherent();
  101. }
  102. #endif /* CHIP_HAS_MF_WAITS_FOR_VICTIMS() */
  103. }
  104. #define fast_wmb() __sync()
  105. #define fast_rmb() __sync()
  106. #define fast_mb() __sync()
  107. #define fast_iob() mb_incoherent()
  108. #define wmb() fast_wmb()
  109. #define rmb() fast_rmb()
  110. #define mb() fast_mb()
  111. #define iob() fast_iob()
  112. #ifdef CONFIG_SMP
  113. #define smp_mb() mb()
  114. #define smp_rmb() rmb()
  115. #define smp_wmb() wmb()
  116. #define smp_read_barrier_depends() read_barrier_depends()
  117. #else
  118. #define smp_mb() barrier()
  119. #define smp_rmb() barrier()
  120. #define smp_wmb() barrier()
  121. #define smp_read_barrier_depends() do { } while (0)
  122. #endif
  123. #define set_mb(var, value) \
  124. do { var = value; mb(); } while (0)
  125. /*
  126. * Pause the DMA engine and static network before task switching.
  127. */
  128. #define prepare_arch_switch(next) _prepare_arch_switch(next)
  129. void _prepare_arch_switch(struct task_struct *next);
  130. /*
  131. * switch_to(n) should switch tasks to task nr n, first
  132. * checking that n isn't the current task, in which case it does nothing.
  133. * The number of callee-saved registers saved on the kernel stack
  134. * is defined here for use in copy_thread() and must agree with __switch_to().
  135. */
  136. #endif /* !__ASSEMBLY__ */
  137. #define CALLEE_SAVED_FIRST_REG 30
  138. #define CALLEE_SAVED_REGS_COUNT 24 /* r30 to r52, plus an empty to align */
  139. #ifndef __ASSEMBLY__
  140. struct task_struct;
  141. #define switch_to(prev, next, last) ((last) = _switch_to((prev), (next)))
  142. extern struct task_struct *_switch_to(struct task_struct *prev,
  143. struct task_struct *next);
  144. /* Helper function for _switch_to(). */
  145. extern struct task_struct *__switch_to(struct task_struct *prev,
  146. struct task_struct *next,
  147. unsigned long new_system_save_k_0);
  148. /* Address that switched-away from tasks are at. */
  149. extern unsigned long get_switch_to_pc(void);
  150. /*
  151. * On SMP systems, when the scheduler does migration-cost autodetection,
  152. * it needs a way to flush as much of the CPU's caches as possible:
  153. *
  154. * TODO: fill this in!
  155. */
  156. static inline void sched_cacheflush(void)
  157. {
  158. }
  159. #define arch_align_stack(x) (x)
  160. /*
  161. * Is the kernel doing fixups of unaligned accesses? If <0, no kernel
  162. * intervention occurs and SIGBUS is delivered with no data address
  163. * info. If 0, the kernel single-steps the instruction to discover
  164. * the data address to provide with the SIGBUS. If 1, the kernel does
  165. * a fixup.
  166. */
  167. extern int unaligned_fixup;
  168. /* Is the kernel printing on each unaligned fixup? */
  169. extern int unaligned_printk;
  170. /* Number of unaligned fixups performed */
  171. extern unsigned int unaligned_fixup_count;
  172. /* Init-time routine to do tile-specific per-cpu setup. */
  173. void setup_cpu(int boot);
  174. /* User-level DMA management functions */
  175. void grant_dma_mpls(void);
  176. void restrict_dma_mpls(void);
  177. #ifdef CONFIG_HARDWALL
  178. /* User-level network management functions */
  179. void reset_network_state(void);
  180. void grant_network_mpls(void);
  181. void restrict_network_mpls(void);
  182. int hardwall_deactivate(struct task_struct *task);
  183. /* Hook hardwall code into changes in affinity. */
  184. #define arch_set_cpus_allowed(p, new_mask) do { \
  185. if (p->thread.hardwall && !cpumask_equal(&p->cpus_allowed, new_mask)) \
  186. hardwall_deactivate(p); \
  187. } while (0)
  188. #endif
  189. /*
  190. * Kernel threads can check to see if they need to migrate their
  191. * stack whenever they return from a context switch; for user
  192. * threads, we defer until they are returning to user-space.
  193. */
  194. #define finish_arch_switch(prev) do { \
  195. if (unlikely((prev)->state == TASK_DEAD)) \
  196. __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_OS_EXIT | \
  197. ((prev)->pid << _SIM_CONTROL_OPERATOR_BITS)); \
  198. __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_OS_SWITCH | \
  199. (current->pid << _SIM_CONTROL_OPERATOR_BITS)); \
  200. if (current->mm == NULL && !kstack_hash && \
  201. current_thread_info()->homecache_cpu != smp_processor_id()) \
  202. homecache_migrate_kthread(); \
  203. } while (0)
  204. /* Support function for forking a new task. */
  205. void ret_from_fork(void);
  206. /* Called from ret_from_fork() when a new process starts up. */
  207. struct task_struct *sim_notify_fork(struct task_struct *prev);
  208. #endif /* !__ASSEMBLY__ */
  209. #endif /* _ASM_TILE_SYSTEM_H */