processor.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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. /*
  21. * Return current * instruction pointer ("program counter").
  22. */
  23. #define current_text_addr() ({ __label__ _l; _l: &&_l;})
  24. /*
  25. * System setup and hardware flags..
  26. */
  27. extern unsigned int vced_count, vcei_count;
  28. /*
  29. * MIPS does have an arch_pick_mmap_layout()
  30. */
  31. #define HAVE_ARCH_PICK_MMAP_LAYOUT 1
  32. /*
  33. * A special page (the vdso) is mapped into all processes at the very
  34. * top of the virtual memory space.
  35. */
  36. #define SPECIAL_PAGES_SIZE PAGE_SIZE
  37. #ifdef CONFIG_32BIT
  38. #ifdef CONFIG_KVM_GUEST
  39. /* User space process size is limited to 1GB in KVM Guest Mode */
  40. #define TASK_SIZE 0x3fff8000UL
  41. #else
  42. /*
  43. * User space process size: 2GB. This is hardcoded into a few places,
  44. * so don't change it unless you know what you are doing.
  45. */
  46. #define TASK_SIZE 0x7fff8000UL
  47. #endif
  48. #ifdef __KERNEL__
  49. #define STACK_TOP_MAX TASK_SIZE
  50. #endif
  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_SIZE64 0x10000000000UL
  63. #define TASK_SIZE (test_thread_flag(TIF_32BIT_ADDR) ? TASK_SIZE32 : TASK_SIZE64)
  64. #ifdef __KERNEL__
  65. #define STACK_TOP_MAX TASK_SIZE64
  66. #endif
  67. #define TASK_SIZE_OF(tsk) \
  68. (test_tsk_thread_flag(tsk, TIF_32BIT_ADDR) ? TASK_SIZE32 : TASK_SIZE64)
  69. #define TASK_IS_32BIT_ADDR test_thread_flag(TIF_32BIT_ADDR)
  70. #endif
  71. #define STACK_TOP ((TASK_SIZE & PAGE_MASK) - SPECIAL_PAGES_SIZE)
  72. /*
  73. * This decides where the kernel will search for a free chunk of vm
  74. * space during mmap's.
  75. */
  76. #define TASK_UNMAPPED_BASE PAGE_ALIGN(TASK_SIZE / 3)
  77. #define NUM_FPU_REGS 32
  78. #define FPU_REG_WIDTH 64
  79. union fpureg {
  80. __u32 val32[FPU_REG_WIDTH / 32];
  81. __u64 val64[FPU_REG_WIDTH / 64];
  82. };
  83. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  84. # define FPR_IDX(width, idx) (idx)
  85. #else
  86. # define FPR_IDX(width, idx) ((FPU_REG_WIDTH / (width)) - 1 - (idx))
  87. #endif
  88. #define BUILD_FPR_ACCESS(width) \
  89. static inline u##width get_fpr##width(union fpureg *fpr, unsigned idx) \
  90. { \
  91. return fpr->val##width[FPR_IDX(width, idx)]; \
  92. } \
  93. \
  94. static inline void set_fpr##width(union fpureg *fpr, unsigned idx, \
  95. u##width val) \
  96. { \
  97. fpr->val##width[FPR_IDX(width, idx)] = val; \
  98. }
  99. BUILD_FPR_ACCESS(32)
  100. BUILD_FPR_ACCESS(64)
  101. /*
  102. * It would be nice to add some more fields for emulator statistics,
  103. * the additional information is private to the FPU emulator for now.
  104. * See arch/mips/include/asm/fpu_emulator.h.
  105. */
  106. struct mips_fpu_struct {
  107. union fpureg fpr[NUM_FPU_REGS];
  108. unsigned int fcr31;
  109. };
  110. #define NUM_DSP_REGS 6
  111. typedef __u32 dspreg_t;
  112. struct mips_dsp_state {
  113. dspreg_t dspr[NUM_DSP_REGS];
  114. unsigned int dspcontrol;
  115. };
  116. #define INIT_CPUMASK { \
  117. {0,} \
  118. }
  119. struct mips3264_watch_reg_state {
  120. /* The width of watchlo is 32 in a 32 bit kernel and 64 in a
  121. 64 bit kernel. We use unsigned long as it has the same
  122. property. */
  123. unsigned long watchlo[NUM_WATCH_REGS];
  124. /* Only the mask and IRW bits from watchhi. */
  125. u16 watchhi[NUM_WATCH_REGS];
  126. };
  127. union mips_watch_reg_state {
  128. struct mips3264_watch_reg_state mips3264;
  129. };
  130. #if defined(CONFIG_CPU_CAVIUM_OCTEON)
  131. struct octeon_cop2_state {
  132. /* DMFC2 rt, 0x0201 */
  133. unsigned long cop2_crc_iv;
  134. /* DMFC2 rt, 0x0202 (Set with DMTC2 rt, 0x1202) */
  135. unsigned long cop2_crc_length;
  136. /* DMFC2 rt, 0x0200 (set with DMTC2 rt, 0x4200) */
  137. unsigned long cop2_crc_poly;
  138. /* DMFC2 rt, 0x0402; DMFC2 rt, 0x040A */
  139. unsigned long cop2_llm_dat[2];
  140. /* DMFC2 rt, 0x0084 */
  141. unsigned long cop2_3des_iv;
  142. /* DMFC2 rt, 0x0080; DMFC2 rt, 0x0081; DMFC2 rt, 0x0082 */
  143. unsigned long cop2_3des_key[3];
  144. /* DMFC2 rt, 0x0088 (Set with DMTC2 rt, 0x0098) */
  145. unsigned long cop2_3des_result;
  146. /* DMFC2 rt, 0x0111 (FIXME: Read Pass1 Errata) */
  147. unsigned long cop2_aes_inp0;
  148. /* DMFC2 rt, 0x0102; DMFC2 rt, 0x0103 */
  149. unsigned long cop2_aes_iv[2];
  150. /* DMFC2 rt, 0x0104; DMFC2 rt, 0x0105; DMFC2 rt, 0x0106; DMFC2
  151. * rt, 0x0107 */
  152. unsigned long cop2_aes_key[4];
  153. /* DMFC2 rt, 0x0110 */
  154. unsigned long cop2_aes_keylen;
  155. /* DMFC2 rt, 0x0100; DMFC2 rt, 0x0101 */
  156. unsigned long cop2_aes_result[2];
  157. /* DMFC2 rt, 0x0240; DMFC2 rt, 0x0241; DMFC2 rt, 0x0242; DMFC2
  158. * rt, 0x0243; DMFC2 rt, 0x0244; DMFC2 rt, 0x0245; DMFC2 rt,
  159. * 0x0246; DMFC2 rt, 0x0247; DMFC2 rt, 0x0248; DMFC2 rt,
  160. * 0x0249; DMFC2 rt, 0x024A; DMFC2 rt, 0x024B; DMFC2 rt,
  161. * 0x024C; DMFC2 rt, 0x024D; DMFC2 rt, 0x024E - Pass2 */
  162. unsigned long cop2_hsh_datw[15];
  163. /* DMFC2 rt, 0x0250; DMFC2 rt, 0x0251; DMFC2 rt, 0x0252; DMFC2
  164. * rt, 0x0253; DMFC2 rt, 0x0254; DMFC2 rt, 0x0255; DMFC2 rt,
  165. * 0x0256; DMFC2 rt, 0x0257 - Pass2 */
  166. unsigned long cop2_hsh_ivw[8];
  167. /* DMFC2 rt, 0x0258; DMFC2 rt, 0x0259 - Pass2 */
  168. unsigned long cop2_gfm_mult[2];
  169. /* DMFC2 rt, 0x025E - Pass2 */
  170. unsigned long cop2_gfm_poly;
  171. /* DMFC2 rt, 0x025A; DMFC2 rt, 0x025B - Pass2 */
  172. unsigned long cop2_gfm_result[2];
  173. };
  174. #define COP2_INIT \
  175. .cp2 = {0,},
  176. struct octeon_cvmseg_state {
  177. unsigned long cvmseg[CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE]
  178. [cpu_dcache_line_size() / sizeof(unsigned long)];
  179. };
  180. #elif defined(CONFIG_CPU_XLP)
  181. struct nlm_cop2_state {
  182. u64 rx[4];
  183. u64 tx[4];
  184. u32 tx_msg_status;
  185. u32 rx_msg_status;
  186. };
  187. #define COP2_INIT \
  188. .cp2 = {{0}, {0}, 0, 0},
  189. #else
  190. #define COP2_INIT
  191. #endif
  192. typedef struct {
  193. unsigned long seg;
  194. } mm_segment_t;
  195. #define ARCH_MIN_TASKALIGN 8
  196. struct mips_abi;
  197. /*
  198. * If you change thread_struct remember to change the #defines below too!
  199. */
  200. struct thread_struct {
  201. /* Saved main processor registers. */
  202. unsigned long reg16;
  203. unsigned long reg17, reg18, reg19, reg20, reg21, reg22, reg23;
  204. unsigned long reg29, reg30, reg31;
  205. /* Saved cp0 stuff. */
  206. unsigned long cp0_status;
  207. /* Saved fpu/fpu emulator stuff. */
  208. struct mips_fpu_struct fpu;
  209. #ifdef CONFIG_MIPS_MT_FPAFF
  210. /* Emulated instruction count */
  211. unsigned long emulated_fp;
  212. /* Saved per-thread scheduler affinity mask */
  213. cpumask_t user_cpus_allowed;
  214. #endif /* CONFIG_MIPS_MT_FPAFF */
  215. /* Saved state of the DSP ASE, if available. */
  216. struct mips_dsp_state dsp;
  217. /* Saved watch register state, if available. */
  218. union mips_watch_reg_state watch;
  219. /* Other stuff associated with the thread. */
  220. unsigned long cp0_badvaddr; /* Last user fault */
  221. unsigned long cp0_baduaddr; /* Last kernel fault accessing USEG */
  222. unsigned long error_code;
  223. #ifdef CONFIG_CPU_CAVIUM_OCTEON
  224. struct octeon_cop2_state cp2 __attribute__ ((__aligned__(128)));
  225. struct octeon_cvmseg_state cvmseg __attribute__ ((__aligned__(128)));
  226. #endif
  227. #ifdef CONFIG_CPU_XLP
  228. struct nlm_cop2_state cp2;
  229. #endif
  230. struct mips_abi *abi;
  231. };
  232. #ifdef CONFIG_MIPS_MT_FPAFF
  233. #define FPAFF_INIT \
  234. .emulated_fp = 0, \
  235. .user_cpus_allowed = INIT_CPUMASK,
  236. #else
  237. #define FPAFF_INIT
  238. #endif /* CONFIG_MIPS_MT_FPAFF */
  239. #define INIT_THREAD { \
  240. /* \
  241. * Saved main processor registers \
  242. */ \
  243. .reg16 = 0, \
  244. .reg17 = 0, \
  245. .reg18 = 0, \
  246. .reg19 = 0, \
  247. .reg20 = 0, \
  248. .reg21 = 0, \
  249. .reg22 = 0, \
  250. .reg23 = 0, \
  251. .reg29 = 0, \
  252. .reg30 = 0, \
  253. .reg31 = 0, \
  254. /* \
  255. * Saved cp0 stuff \
  256. */ \
  257. .cp0_status = 0, \
  258. /* \
  259. * Saved FPU/FPU emulator stuff \
  260. */ \
  261. .fpu = { \
  262. .fpr = {{{0,},},}, \
  263. .fcr31 = 0, \
  264. }, \
  265. /* \
  266. * FPU affinity state (null if not FPAFF) \
  267. */ \
  268. FPAFF_INIT \
  269. /* \
  270. * Saved DSP stuff \
  271. */ \
  272. .dsp = { \
  273. .dspr = {0, }, \
  274. .dspcontrol = 0, \
  275. }, \
  276. /* \
  277. * saved watch register stuff \
  278. */ \
  279. .watch = {{{0,},},}, \
  280. /* \
  281. * Other stuff associated with the process \
  282. */ \
  283. .cp0_badvaddr = 0, \
  284. .cp0_baduaddr = 0, \
  285. .error_code = 0, \
  286. /* \
  287. * Platform specific cop2 registers(null if no COP2) \
  288. */ \
  289. COP2_INIT \
  290. }
  291. struct task_struct;
  292. /* Free all resources held by a thread. */
  293. #define release_thread(thread) do { } while(0)
  294. extern unsigned long thread_saved_pc(struct task_struct *tsk);
  295. /*
  296. * Do necessary setup to start up a newly executed thread.
  297. */
  298. extern void start_thread(struct pt_regs * regs, unsigned long pc, unsigned long sp);
  299. unsigned long get_wchan(struct task_struct *p);
  300. #define __KSTK_TOS(tsk) ((unsigned long)task_stack_page(tsk) + \
  301. THREAD_SIZE - 32 - sizeof(struct pt_regs))
  302. #define task_pt_regs(tsk) ((struct pt_regs *)__KSTK_TOS(tsk))
  303. #define KSTK_EIP(tsk) (task_pt_regs(tsk)->cp0_epc)
  304. #define KSTK_ESP(tsk) (task_pt_regs(tsk)->regs[29])
  305. #define KSTK_STATUS(tsk) (task_pt_regs(tsk)->cp0_status)
  306. #define cpu_relax() barrier()
  307. /*
  308. * Return_address is a replacement for __builtin_return_address(count)
  309. * which on certain architectures cannot reasonably be implemented in GCC
  310. * (MIPS, Alpha) or is unusable with -fomit-frame-pointer (i386).
  311. * Note that __builtin_return_address(x>=1) is forbidden because GCC
  312. * aborts compilation on some CPUs. It's simply not possible to unwind
  313. * some CPU's stackframes.
  314. *
  315. * __builtin_return_address works only for non-leaf functions. We avoid the
  316. * overhead of a function call by forcing the compiler to save the return
  317. * address register on the stack.
  318. */
  319. #define return_address() ({__asm__ __volatile__("":::"$31");__builtin_return_address(0);})
  320. #ifdef CONFIG_CPU_HAS_PREFETCH
  321. #define ARCH_HAS_PREFETCH
  322. #define prefetch(x) __builtin_prefetch((x), 0, 1)
  323. #define ARCH_HAS_PREFETCHW
  324. #define prefetchw(x) __builtin_prefetch((x), 1, 1)
  325. /*
  326. * See Documentation/scheduler/sched-arch.txt; prevents deadlock on SMP
  327. * systems.
  328. */
  329. #define __ARCH_WANT_UNLOCKED_CTXSW
  330. #endif
  331. #endif /* _ASM_PROCESSOR_H */