processor.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1994 Waldorf GMBH
  7. * Copyright (C) 1995, 1996, 1997, 1998, 1999, 2001, 2002, 2003 Ralf Baechle
  8. * Copyright (C) 1996 Paul M. Antoine
  9. * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
  10. */
  11. #ifndef _ASM_PROCESSOR_H
  12. #define _ASM_PROCESSOR_H
  13. #include <linux/cpumask.h>
  14. #include <linux/threads.h>
  15. #include <asm/cachectl.h>
  16. #include <asm/cpu.h>
  17. #include <asm/cpu-info.h>
  18. #include <asm/mipsregs.h>
  19. #include <asm/prefetch.h>
  20. #include <asm/system.h>
  21. /*
  22. * Return current * instruction pointer ("program counter").
  23. */
  24. #define current_text_addr() ({ __label__ _l; _l: &&_l;})
  25. /*
  26. * System setup and hardware flags..
  27. */
  28. extern void (*cpu_wait)(void);
  29. extern unsigned int vced_count, vcei_count;
  30. /*
  31. * MIPS does have an arch_pick_mmap_layout()
  32. */
  33. #define HAVE_ARCH_PICK_MMAP_LAYOUT 1
  34. /*
  35. * A special page (the vdso) is mapped into all processes at the very
  36. * top of the virtual memory space.
  37. */
  38. #define SPECIAL_PAGES_SIZE PAGE_SIZE
  39. #ifdef CONFIG_32BIT
  40. /*
  41. * User space process size: 2GB. This is hardcoded into a few places,
  42. * so don't change it unless you know what you are doing.
  43. */
  44. #define TASK_SIZE 0x7fff8000UL
  45. #define STACK_TOP ((TASK_SIZE & PAGE_MASK) - SPECIAL_PAGES_SIZE)
  46. /*
  47. * This decides where the kernel will search for a free chunk of vm
  48. * space during mmap's.
  49. */
  50. #define TASK_UNMAPPED_BASE ((TASK_SIZE / 3) & ~(PAGE_SIZE))
  51. #define TASK_IS_32BIT_ADDR 1
  52. #endif
  53. #ifdef CONFIG_64BIT
  54. /*
  55. * User space process size: 1TB. This is hardcoded into a few places,
  56. * so don't change it unless you know what you are doing. TASK_SIZE
  57. * is limited to 1TB by the R4000 architecture; R10000 and better can
  58. * support 16TB; the architectural reserve for future expansion is
  59. * 8192EB ...
  60. */
  61. #define TASK_SIZE32 0x7fff8000UL
  62. #define TASK_SIZE 0x10000000000UL
  63. #define STACK_TOP \
  64. (((test_thread_flag(TIF_32BIT_ADDR) ? \
  65. TASK_SIZE32 : TASK_SIZE) & PAGE_MASK) - SPECIAL_PAGES_SIZE)
  66. /*
  67. * This decides where the kernel will search for a free chunk of vm
  68. * space during mmap's.
  69. */
  70. #define TASK_UNMAPPED_BASE \
  71. (test_thread_flag(TIF_32BIT_ADDR) ? \
  72. PAGE_ALIGN(TASK_SIZE32 / 3) : PAGE_ALIGN(TASK_SIZE / 3))
  73. #define TASK_SIZE_OF(tsk) \
  74. (test_tsk_thread_flag(tsk, TIF_32BIT_ADDR) ? TASK_SIZE32 : TASK_SIZE)
  75. #define TASK_IS_32BIT_ADDR test_thread_flag(TIF_32BIT_ADDR)
  76. #endif
  77. #ifdef __KERNEL__
  78. #define STACK_TOP_MAX TASK_SIZE
  79. #endif
  80. #define NUM_FPU_REGS 32
  81. typedef __u64 fpureg_t;
  82. /*
  83. * It would be nice to add some more fields for emulator statistics, but there
  84. * are a number of fixed offsets in offset.h and elsewhere that would have to
  85. * be recalculated by hand. So the additional information will be private to
  86. * the FPU emulator for now. See asm-mips/fpu_emulator.h.
  87. */
  88. struct mips_fpu_struct {
  89. fpureg_t fpr[NUM_FPU_REGS];
  90. unsigned int fcr31;
  91. };
  92. #define NUM_DSP_REGS 6
  93. typedef __u32 dspreg_t;
  94. struct mips_dsp_state {
  95. dspreg_t dspr[NUM_DSP_REGS];
  96. unsigned int dspcontrol;
  97. };
  98. #define INIT_CPUMASK { \
  99. {0,} \
  100. }
  101. struct mips3264_watch_reg_state {
  102. /* The width of watchlo is 32 in a 32 bit kernel and 64 in a
  103. 64 bit kernel. We use unsigned long as it has the same
  104. property. */
  105. unsigned long watchlo[NUM_WATCH_REGS];
  106. /* Only the mask and IRW bits from watchhi. */
  107. u16 watchhi[NUM_WATCH_REGS];
  108. };
  109. union mips_watch_reg_state {
  110. struct mips3264_watch_reg_state mips3264;
  111. };
  112. #ifdef CONFIG_CPU_CAVIUM_OCTEON
  113. struct octeon_cop2_state {
  114. /* DMFC2 rt, 0x0201 */
  115. unsigned long cop2_crc_iv;
  116. /* DMFC2 rt, 0x0202 (Set with DMTC2 rt, 0x1202) */
  117. unsigned long cop2_crc_length;
  118. /* DMFC2 rt, 0x0200 (set with DMTC2 rt, 0x4200) */
  119. unsigned long cop2_crc_poly;
  120. /* DMFC2 rt, 0x0402; DMFC2 rt, 0x040A */
  121. unsigned long cop2_llm_dat[2];
  122. /* DMFC2 rt, 0x0084 */
  123. unsigned long cop2_3des_iv;
  124. /* DMFC2 rt, 0x0080; DMFC2 rt, 0x0081; DMFC2 rt, 0x0082 */
  125. unsigned long cop2_3des_key[3];
  126. /* DMFC2 rt, 0x0088 (Set with DMTC2 rt, 0x0098) */
  127. unsigned long cop2_3des_result;
  128. /* DMFC2 rt, 0x0111 (FIXME: Read Pass1 Errata) */
  129. unsigned long cop2_aes_inp0;
  130. /* DMFC2 rt, 0x0102; DMFC2 rt, 0x0103 */
  131. unsigned long cop2_aes_iv[2];
  132. /* DMFC2 rt, 0x0104; DMFC2 rt, 0x0105; DMFC2 rt, 0x0106; DMFC2
  133. * rt, 0x0107 */
  134. unsigned long cop2_aes_key[4];
  135. /* DMFC2 rt, 0x0110 */
  136. unsigned long cop2_aes_keylen;
  137. /* DMFC2 rt, 0x0100; DMFC2 rt, 0x0101 */
  138. unsigned long cop2_aes_result[2];
  139. /* DMFC2 rt, 0x0240; DMFC2 rt, 0x0241; DMFC2 rt, 0x0242; DMFC2
  140. * rt, 0x0243; DMFC2 rt, 0x0244; DMFC2 rt, 0x0245; DMFC2 rt,
  141. * 0x0246; DMFC2 rt, 0x0247; DMFC2 rt, 0x0248; DMFC2 rt,
  142. * 0x0249; DMFC2 rt, 0x024A; DMFC2 rt, 0x024B; DMFC2 rt,
  143. * 0x024C; DMFC2 rt, 0x024D; DMFC2 rt, 0x024E - Pass2 */
  144. unsigned long cop2_hsh_datw[15];
  145. /* DMFC2 rt, 0x0250; DMFC2 rt, 0x0251; DMFC2 rt, 0x0252; DMFC2
  146. * rt, 0x0253; DMFC2 rt, 0x0254; DMFC2 rt, 0x0255; DMFC2 rt,
  147. * 0x0256; DMFC2 rt, 0x0257 - Pass2 */
  148. unsigned long cop2_hsh_ivw[8];
  149. /* DMFC2 rt, 0x0258; DMFC2 rt, 0x0259 - Pass2 */
  150. unsigned long cop2_gfm_mult[2];
  151. /* DMFC2 rt, 0x025E - Pass2 */
  152. unsigned long cop2_gfm_poly;
  153. /* DMFC2 rt, 0x025A; DMFC2 rt, 0x025B - Pass2 */
  154. unsigned long cop2_gfm_result[2];
  155. };
  156. #define INIT_OCTEON_COP2 {0,}
  157. struct octeon_cvmseg_state {
  158. unsigned long cvmseg[CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE]
  159. [cpu_dcache_line_size() / sizeof(unsigned long)];
  160. };
  161. #endif
  162. typedef struct {
  163. unsigned long seg;
  164. } mm_segment_t;
  165. #define ARCH_MIN_TASKALIGN 8
  166. struct mips_abi;
  167. /*
  168. * If you change thread_struct remember to change the #defines below too!
  169. */
  170. struct thread_struct {
  171. /* Saved main processor registers. */
  172. unsigned long reg16;
  173. unsigned long reg17, reg18, reg19, reg20, reg21, reg22, reg23;
  174. unsigned long reg29, reg30, reg31;
  175. /* Saved cp0 stuff. */
  176. unsigned long cp0_status;
  177. /* Saved fpu/fpu emulator stuff. */
  178. struct mips_fpu_struct fpu;
  179. #ifdef CONFIG_MIPS_MT_FPAFF
  180. /* Emulated instruction count */
  181. unsigned long emulated_fp;
  182. /* Saved per-thread scheduler affinity mask */
  183. cpumask_t user_cpus_allowed;
  184. #endif /* CONFIG_MIPS_MT_FPAFF */
  185. /* Saved state of the DSP ASE, if available. */
  186. struct mips_dsp_state dsp;
  187. /* Saved watch register state, if available. */
  188. union mips_watch_reg_state watch;
  189. /* Other stuff associated with the thread. */
  190. unsigned long cp0_badvaddr; /* Last user fault */
  191. unsigned long cp0_baduaddr; /* Last kernel fault accessing USEG */
  192. unsigned long error_code;
  193. unsigned long irix_trampoline; /* Wheee... */
  194. unsigned long irix_oldctx;
  195. #ifdef CONFIG_CPU_CAVIUM_OCTEON
  196. struct octeon_cop2_state cp2 __attribute__ ((__aligned__(128)));
  197. struct octeon_cvmseg_state cvmseg __attribute__ ((__aligned__(128)));
  198. #endif
  199. struct mips_abi *abi;
  200. };
  201. #ifdef CONFIG_MIPS_MT_FPAFF
  202. #define FPAFF_INIT \
  203. .emulated_fp = 0, \
  204. .user_cpus_allowed = INIT_CPUMASK,
  205. #else
  206. #define FPAFF_INIT
  207. #endif /* CONFIG_MIPS_MT_FPAFF */
  208. #ifdef CONFIG_CPU_CAVIUM_OCTEON
  209. #define OCTEON_INIT \
  210. .cp2 = INIT_OCTEON_COP2,
  211. #else
  212. #define OCTEON_INIT
  213. #endif /* CONFIG_CPU_CAVIUM_OCTEON */
  214. #define INIT_THREAD { \
  215. /* \
  216. * Saved main processor registers \
  217. */ \
  218. .reg16 = 0, \
  219. .reg17 = 0, \
  220. .reg18 = 0, \
  221. .reg19 = 0, \
  222. .reg20 = 0, \
  223. .reg21 = 0, \
  224. .reg22 = 0, \
  225. .reg23 = 0, \
  226. .reg29 = 0, \
  227. .reg30 = 0, \
  228. .reg31 = 0, \
  229. /* \
  230. * Saved cp0 stuff \
  231. */ \
  232. .cp0_status = 0, \
  233. /* \
  234. * Saved FPU/FPU emulator stuff \
  235. */ \
  236. .fpu = { \
  237. .fpr = {0,}, \
  238. .fcr31 = 0, \
  239. }, \
  240. /* \
  241. * FPU affinity state (null if not FPAFF) \
  242. */ \
  243. FPAFF_INIT \
  244. /* \
  245. * Saved DSP stuff \
  246. */ \
  247. .dsp = { \
  248. .dspr = {0, }, \
  249. .dspcontrol = 0, \
  250. }, \
  251. /* \
  252. * saved watch register stuff \
  253. */ \
  254. .watch = {{{0,},},}, \
  255. /* \
  256. * Other stuff associated with the process \
  257. */ \
  258. .cp0_badvaddr = 0, \
  259. .cp0_baduaddr = 0, \
  260. .error_code = 0, \
  261. .irix_trampoline = 0, \
  262. .irix_oldctx = 0, \
  263. /* \
  264. * Cavium Octeon specifics (null if not Octeon) \
  265. */ \
  266. OCTEON_INIT \
  267. }
  268. struct task_struct;
  269. /* Free all resources held by a thread. */
  270. #define release_thread(thread) do { } while(0)
  271. /* Prepare to copy thread state - unlazy all lazy status */
  272. #define prepare_to_copy(tsk) do { } while (0)
  273. extern long kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
  274. extern unsigned long thread_saved_pc(struct task_struct *tsk);
  275. /*
  276. * Do necessary setup to start up a newly executed thread.
  277. */
  278. extern void start_thread(struct pt_regs * regs, unsigned long pc, unsigned long sp);
  279. unsigned long get_wchan(struct task_struct *p);
  280. #define __KSTK_TOS(tsk) ((unsigned long)task_stack_page(tsk) + \
  281. THREAD_SIZE - 32 - sizeof(struct pt_regs))
  282. #define task_pt_regs(tsk) ((struct pt_regs *)__KSTK_TOS(tsk))
  283. #define KSTK_EIP(tsk) (task_pt_regs(tsk)->cp0_epc)
  284. #define KSTK_ESP(tsk) (task_pt_regs(tsk)->regs[29])
  285. #define KSTK_STATUS(tsk) (task_pt_regs(tsk)->cp0_status)
  286. #define cpu_relax() barrier()
  287. /*
  288. * Return_address is a replacement for __builtin_return_address(count)
  289. * which on certain architectures cannot reasonably be implemented in GCC
  290. * (MIPS, Alpha) or is unuseable with -fomit-frame-pointer (i386).
  291. * Note that __builtin_return_address(x>=1) is forbidden because GCC
  292. * aborts compilation on some CPUs. It's simply not possible to unwind
  293. * some CPU's stackframes.
  294. *
  295. * __builtin_return_address works only for non-leaf functions. We avoid the
  296. * overhead of a function call by forcing the compiler to save the return
  297. * address register on the stack.
  298. */
  299. #define return_address() ({__asm__ __volatile__("":::"$31");__builtin_return_address(0);})
  300. #ifdef CONFIG_CPU_HAS_PREFETCH
  301. #define ARCH_HAS_PREFETCH
  302. #define prefetch(x) __builtin_prefetch((x), 0, 1)
  303. #define ARCH_HAS_PREFETCHW
  304. #define prefetchw(x) __builtin_prefetch((x), 1, 1)
  305. #endif
  306. #endif /* _ASM_PROCESSOR_H */