processor.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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_PROCESSOR_H
  15. #define _ASM_TILE_PROCESSOR_H
  16. #ifndef __ASSEMBLY__
  17. /*
  18. * NOTE: we don't include <linux/ptrace.h> or <linux/percpu.h> as one
  19. * normally would, due to #include dependencies.
  20. */
  21. #include <linux/types.h>
  22. #include <asm/ptrace.h>
  23. #include <asm/percpu.h>
  24. #include <arch/chip.h>
  25. #include <arch/spr_def.h>
  26. struct task_struct;
  27. struct thread_struct;
  28. typedef struct {
  29. unsigned long seg;
  30. } mm_segment_t;
  31. /*
  32. * Default implementation of macro that returns current
  33. * instruction pointer ("program counter").
  34. */
  35. void *current_text_addr(void);
  36. #if CHIP_HAS_TILE_DMA()
  37. /* Capture the state of a suspended DMA. */
  38. struct tile_dma_state {
  39. int enabled;
  40. unsigned long src;
  41. unsigned long dest;
  42. unsigned long strides;
  43. unsigned long chunk_size;
  44. unsigned long src_chunk;
  45. unsigned long dest_chunk;
  46. unsigned long byte;
  47. unsigned long status;
  48. };
  49. /*
  50. * A mask of the DMA status register for selecting only the 'running'
  51. * and 'done' bits.
  52. */
  53. #define DMA_STATUS_MASK \
  54. (SPR_DMA_STATUS__RUNNING_MASK | SPR_DMA_STATUS__DONE_MASK)
  55. #endif
  56. /*
  57. * Track asynchronous TLB events (faults and access violations)
  58. * that occur while we are in kernel mode from DMA or the SN processor.
  59. */
  60. struct async_tlb {
  61. short fault_num; /* original fault number; 0 if none */
  62. char is_fault; /* was it a fault (vs an access violation) */
  63. char is_write; /* for fault: was it caused by a write? */
  64. unsigned long address; /* what address faulted? */
  65. };
  66. #ifdef CONFIG_HARDWALL
  67. struct hardwall_info;
  68. struct hardwall_task {
  69. /* Which hardwall is this task tied to? (or NULL if none) */
  70. struct hardwall_info *info;
  71. /* Chains this task into the list at info->task_head. */
  72. struct list_head list;
  73. };
  74. #ifdef __tilepro__
  75. #define HARDWALL_TYPES 1 /* udn */
  76. #else
  77. #define HARDWALL_TYPES 3 /* udn, idn, and ipi */
  78. #endif
  79. #endif
  80. struct thread_struct {
  81. /* kernel stack pointer */
  82. unsigned long ksp;
  83. /* kernel PC */
  84. unsigned long pc;
  85. /* starting user stack pointer (for page migration) */
  86. unsigned long usp0;
  87. /* pid of process that created this one */
  88. pid_t creator_pid;
  89. #if CHIP_HAS_TILE_DMA()
  90. /* DMA info for suspended threads (byte == 0 means no DMA state) */
  91. struct tile_dma_state tile_dma_state;
  92. #endif
  93. /* User EX_CONTEXT registers */
  94. unsigned long ex_context[2];
  95. /* User SYSTEM_SAVE registers */
  96. unsigned long system_save[4];
  97. /* User interrupt mask */
  98. unsigned long long interrupt_mask;
  99. /* User interrupt-control 0 state */
  100. unsigned long intctrl_0;
  101. /* Is this task currently doing a backtrace? */
  102. bool in_backtrace;
  103. #if CHIP_HAS_PROC_STATUS_SPR()
  104. /* Any other miscellaneous processor state bits */
  105. unsigned long proc_status;
  106. #endif
  107. #if !CHIP_HAS_FIXED_INTVEC_BASE()
  108. /* Interrupt base for PL0 interrupts */
  109. unsigned long interrupt_vector_base;
  110. #endif
  111. #if CHIP_HAS_TILE_RTF_HWM()
  112. /* Tile cache retry fifo high-water mark */
  113. unsigned long tile_rtf_hwm;
  114. #endif
  115. #if CHIP_HAS_DSTREAM_PF()
  116. /* Data stream prefetch control */
  117. unsigned long dstream_pf;
  118. #endif
  119. #ifdef CONFIG_HARDWALL
  120. /* Hardwall information for various resources. */
  121. struct hardwall_task hardwall[HARDWALL_TYPES];
  122. #endif
  123. #if CHIP_HAS_TILE_DMA()
  124. /* Async DMA TLB fault information */
  125. struct async_tlb dma_async_tlb;
  126. #endif
  127. #if CHIP_HAS_SN_PROC()
  128. /* Was static network processor when we were switched out? */
  129. int sn_proc_running;
  130. /* Async SNI TLB fault information */
  131. struct async_tlb sn_async_tlb;
  132. #endif
  133. };
  134. #endif /* !__ASSEMBLY__ */
  135. /*
  136. * Start with "sp" this many bytes below the top of the kernel stack.
  137. * This preserves the invariant that a called function may write to *sp.
  138. */
  139. #define STACK_TOP_DELTA 8
  140. /*
  141. * When entering the kernel via a fault, start with the top of the
  142. * pt_regs structure this many bytes below the top of the page.
  143. * This aligns the pt_regs structure optimally for cache-line access.
  144. */
  145. #ifdef __tilegx__
  146. #define KSTK_PTREGS_GAP 48
  147. #else
  148. #define KSTK_PTREGS_GAP 56
  149. #endif
  150. #ifndef __ASSEMBLY__
  151. #ifdef __tilegx__
  152. #define TASK_SIZE_MAX (MEM_LOW_END + 1)
  153. #else
  154. #define TASK_SIZE_MAX PAGE_OFFSET
  155. #endif
  156. /* TASK_SIZE and related variables are always checked in "current" context. */
  157. #ifdef CONFIG_COMPAT
  158. #define COMPAT_TASK_SIZE (1UL << 31)
  159. #define TASK_SIZE ((current_thread_info()->status & TS_COMPAT) ?\
  160. COMPAT_TASK_SIZE : TASK_SIZE_MAX)
  161. #else
  162. #define TASK_SIZE TASK_SIZE_MAX
  163. #endif
  164. #define VDSO_BASE ((unsigned long)current->active_mm->context.vdso_base)
  165. #define VDSO_SYM(x) (VDSO_BASE + (unsigned long)(x))
  166. #define STACK_TOP TASK_SIZE
  167. /* STACK_TOP_MAX is used temporarily in execve and should not check COMPAT. */
  168. #define STACK_TOP_MAX TASK_SIZE_MAX
  169. /*
  170. * This decides where the kernel will search for a free chunk of vm
  171. * space during mmap's, if it is using bottom-up mapping.
  172. */
  173. #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
  174. #define HAVE_ARCH_PICK_MMAP_LAYOUT
  175. #define INIT_THREAD { \
  176. .ksp = (unsigned long)init_stack + THREAD_SIZE - STACK_TOP_DELTA, \
  177. .interrupt_mask = -1ULL \
  178. }
  179. /* Kernel stack top for the task that first boots on this cpu. */
  180. DECLARE_PER_CPU(unsigned long, boot_sp);
  181. /* PC to boot from on this cpu. */
  182. DECLARE_PER_CPU(unsigned long, boot_pc);
  183. /* Do necessary setup to start up a newly executed thread. */
  184. static inline void start_thread(struct pt_regs *regs,
  185. unsigned long pc, unsigned long usp)
  186. {
  187. regs->pc = pc;
  188. regs->sp = usp;
  189. single_step_execve();
  190. }
  191. /* Free all resources held by a thread. */
  192. static inline void release_thread(struct task_struct *dead_task)
  193. {
  194. /* Nothing for now */
  195. }
  196. extern int do_work_pending(struct pt_regs *regs, u32 flags);
  197. /*
  198. * Return saved (kernel) PC of a blocked thread.
  199. * Only used in a printk() in kernel/sched/core.c, so don't work too hard.
  200. */
  201. #define thread_saved_pc(t) ((t)->thread.pc)
  202. unsigned long get_wchan(struct task_struct *p);
  203. /* Return initial ksp value for given task. */
  204. #define task_ksp0(task) ((unsigned long)(task)->stack + THREAD_SIZE)
  205. /* Return some info about the user process TASK. */
  206. #define KSTK_TOP(task) (task_ksp0(task) - STACK_TOP_DELTA)
  207. #define task_pt_regs(task) \
  208. ((struct pt_regs *)(task_ksp0(task) - KSTK_PTREGS_GAP) - 1)
  209. #define current_pt_regs() \
  210. ((struct pt_regs *)((stack_pointer | (THREAD_SIZE - 1)) - \
  211. (KSTK_PTREGS_GAP - 1)) - 1)
  212. #define task_sp(task) (task_pt_regs(task)->sp)
  213. #define task_pc(task) (task_pt_regs(task)->pc)
  214. /* Aliases for pc and sp (used in fs/proc/array.c) */
  215. #define KSTK_EIP(task) task_pc(task)
  216. #define KSTK_ESP(task) task_sp(task)
  217. /* Fine-grained unaligned JIT support */
  218. #define GET_UNALIGN_CTL(tsk, adr) get_unalign_ctl((tsk), (adr))
  219. #define SET_UNALIGN_CTL(tsk, val) set_unalign_ctl((tsk), (val))
  220. extern int get_unalign_ctl(struct task_struct *tsk, unsigned long adr);
  221. extern int set_unalign_ctl(struct task_struct *tsk, unsigned int val);
  222. /* Standard format for printing registers and other word-size data. */
  223. #ifdef __tilegx__
  224. # define REGFMT "0x%016lx"
  225. #else
  226. # define REGFMT "0x%08lx"
  227. #endif
  228. /*
  229. * Do some slow action (e.g. read a slow SPR).
  230. * Note that this must also have compiler-barrier semantics since
  231. * it may be used in a busy loop reading memory.
  232. */
  233. static inline void cpu_relax(void)
  234. {
  235. __insn_mfspr(SPR_PASS);
  236. barrier();
  237. }
  238. /* Info on this processor (see fs/proc/cpuinfo.c) */
  239. struct seq_operations;
  240. extern const struct seq_operations cpuinfo_op;
  241. /* Provide information about the chip model. */
  242. extern char chip_model[64];
  243. /* Data on which physical memory controller corresponds to which NUMA node. */
  244. extern int node_controller[];
  245. #if CHIP_HAS_CBOX_HOME_MAP()
  246. /* Does the heap allocator return hash-for-home pages by default? */
  247. extern int hash_default;
  248. /* Should kernel stack pages be hash-for-home? */
  249. extern int kstack_hash;
  250. /* Does MAP_ANONYMOUS return hash-for-home pages by default? */
  251. #define uheap_hash hash_default
  252. #else
  253. #define hash_default 0
  254. #define kstack_hash 0
  255. #define uheap_hash 0
  256. #endif
  257. /* Are we using huge pages in the TLB for kernel data? */
  258. extern int kdata_huge;
  259. /* Support standard Linux prefetching. */
  260. #define ARCH_HAS_PREFETCH
  261. #define prefetch(x) __builtin_prefetch(x)
  262. #define PREFETCH_STRIDE CHIP_L2_LINE_SIZE()
  263. /* Bring a value into the L1D, faulting the TLB if necessary. */
  264. #ifdef __tilegx__
  265. #define prefetch_L1(x) __insn_prefetch_l1_fault((void *)(x))
  266. #else
  267. #define prefetch_L1(x) __insn_prefetch_L1((void *)(x))
  268. #endif
  269. #else /* __ASSEMBLY__ */
  270. /* Do some slow action (e.g. read a slow SPR). */
  271. #define CPU_RELAX mfspr zero, SPR_PASS
  272. #endif /* !__ASSEMBLY__ */
  273. /* Assembly code assumes that the PL is in the low bits. */
  274. #if SPR_EX_CONTEXT_1_1__PL_SHIFT != 0
  275. # error Fix assembly assumptions about PL
  276. #endif
  277. /* We sometimes use these macros for EX_CONTEXT_0_1 as well. */
  278. #if SPR_EX_CONTEXT_1_1__PL_SHIFT != SPR_EX_CONTEXT_0_1__PL_SHIFT || \
  279. SPR_EX_CONTEXT_1_1__PL_RMASK != SPR_EX_CONTEXT_0_1__PL_RMASK || \
  280. SPR_EX_CONTEXT_1_1__ICS_SHIFT != SPR_EX_CONTEXT_0_1__ICS_SHIFT || \
  281. SPR_EX_CONTEXT_1_1__ICS_RMASK != SPR_EX_CONTEXT_0_1__ICS_RMASK
  282. # error Fix assumptions that EX1 macros work for both PL0 and PL1
  283. #endif
  284. /* Allow pulling apart and recombining the PL and ICS bits in EX_CONTEXT. */
  285. #define EX1_PL(ex1) \
  286. (((ex1) >> SPR_EX_CONTEXT_1_1__PL_SHIFT) & SPR_EX_CONTEXT_1_1__PL_RMASK)
  287. #define EX1_ICS(ex1) \
  288. (((ex1) >> SPR_EX_CONTEXT_1_1__ICS_SHIFT) & SPR_EX_CONTEXT_1_1__ICS_RMASK)
  289. #define PL_ICS_EX1(pl, ics) \
  290. (((pl) << SPR_EX_CONTEXT_1_1__PL_SHIFT) | \
  291. ((ics) << SPR_EX_CONTEXT_1_1__ICS_SHIFT))
  292. /*
  293. * Provide symbolic constants for PLs.
  294. * Note that assembly code assumes that USER_PL is zero.
  295. */
  296. #define USER_PL 0
  297. #if CONFIG_KERNEL_PL == 2
  298. #define GUEST_PL 1
  299. #endif
  300. #define KERNEL_PL CONFIG_KERNEL_PL
  301. /* SYSTEM_SAVE_K_0 holds the current cpu number ORed with ksp0. */
  302. #define CPU_LOG_MASK_VALUE 12
  303. #define CPU_MASK_VALUE ((1 << CPU_LOG_MASK_VALUE) - 1)
  304. #if CONFIG_NR_CPUS > CPU_MASK_VALUE
  305. # error Too many cpus!
  306. #endif
  307. #define raw_smp_processor_id() \
  308. ((int)__insn_mfspr(SPR_SYSTEM_SAVE_K_0) & CPU_MASK_VALUE)
  309. #define get_current_ksp0() \
  310. (__insn_mfspr(SPR_SYSTEM_SAVE_K_0) & ~CPU_MASK_VALUE)
  311. #define next_current_ksp0(task) ({ \
  312. unsigned long __ksp0 = task_ksp0(task); \
  313. int __cpu = raw_smp_processor_id(); \
  314. BUG_ON(__ksp0 & CPU_MASK_VALUE); \
  315. __ksp0 | __cpu; \
  316. })
  317. #endif /* _ASM_TILE_PROCESSOR_H */