processor.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  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/atomic.h>
  14. #include <linux/cpumask.h>
  15. #include <linux/sizes.h>
  16. #include <linux/threads.h>
  17. #include <asm/cachectl.h>
  18. #include <asm/cpu.h>
  19. #include <asm/cpu-info.h>
  20. #include <asm/dsemul.h>
  21. #include <asm/mipsregs.h>
  22. #include <asm/prefetch.h>
  23. /*
  24. * Return current * instruction pointer ("program counter").
  25. */
  26. #define current_text_addr() ({ __label__ _l; _l: &&_l;})
  27. /*
  28. * System setup and hardware flags..
  29. */
  30. extern unsigned int vced_count, vcei_count;
  31. /*
  32. * MIPS does have an arch_pick_mmap_layout()
  33. */
  34. #define HAVE_ARCH_PICK_MMAP_LAYOUT 1
  35. #ifdef CONFIG_32BIT
  36. #ifdef CONFIG_KVM_GUEST
  37. /* User space process size is limited to 1GB in KVM Guest Mode */
  38. #define TASK_SIZE 0x3fff8000UL
  39. #else
  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 0x80000000UL
  45. #endif
  46. #define STACK_TOP_MAX TASK_SIZE
  47. #define TASK_IS_32BIT_ADDR 1
  48. #endif
  49. #ifdef CONFIG_64BIT
  50. /*
  51. * User space process size: 1TB. This is hardcoded into a few places,
  52. * so don't change it unless you know what you are doing. TASK_SIZE
  53. * is limited to 1TB by the R4000 architecture; R10000 and better can
  54. * support 16TB; the architectural reserve for future expansion is
  55. * 8192EB ...
  56. */
  57. #define TASK_SIZE32 0x7fff8000UL
  58. #ifdef CONFIG_MIPS_VA_BITS_48
  59. #define TASK_SIZE64 (0x1UL << ((cpu_data[0].vmbits>48)?48:cpu_data[0].vmbits))
  60. #else
  61. #define TASK_SIZE64 0x10000000000UL
  62. #endif
  63. #define TASK_SIZE (test_thread_flag(TIF_32BIT_ADDR) ? TASK_SIZE32 : TASK_SIZE64)
  64. #define STACK_TOP_MAX TASK_SIZE64
  65. #define TASK_SIZE_OF(tsk) \
  66. (test_tsk_thread_flag(tsk, TIF_32BIT_ADDR) ? TASK_SIZE32 : TASK_SIZE64)
  67. #define TASK_IS_32BIT_ADDR test_thread_flag(TIF_32BIT_ADDR)
  68. #endif
  69. #define VDSO_RANDOMIZE_SIZE (TASK_IS_32BIT_ADDR ? SZ_1M : SZ_64M)
  70. extern unsigned long mips_stack_top(void);
  71. #define STACK_TOP mips_stack_top()
  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. #ifdef CONFIG_CPU_HAS_MSA
  79. # define FPU_REG_WIDTH 128
  80. #else
  81. # define FPU_REG_WIDTH 64
  82. #endif
  83. union fpureg {
  84. __u32 val32[FPU_REG_WIDTH / 32];
  85. __u64 val64[FPU_REG_WIDTH / 64];
  86. };
  87. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  88. # define FPR_IDX(width, idx) (idx)
  89. #else
  90. # define FPR_IDX(width, idx) ((idx) ^ ((64 / (width)) - 1))
  91. #endif
  92. #define BUILD_FPR_ACCESS(width) \
  93. static inline u##width get_fpr##width(union fpureg *fpr, unsigned idx) \
  94. { \
  95. return fpr->val##width[FPR_IDX(width, idx)]; \
  96. } \
  97. \
  98. static inline void set_fpr##width(union fpureg *fpr, unsigned idx, \
  99. u##width val) \
  100. { \
  101. fpr->val##width[FPR_IDX(width, idx)] = val; \
  102. }
  103. BUILD_FPR_ACCESS(32)
  104. BUILD_FPR_ACCESS(64)
  105. /*
  106. * It would be nice to add some more fields for emulator statistics,
  107. * the additional information is private to the FPU emulator for now.
  108. * See arch/mips/include/asm/fpu_emulator.h.
  109. */
  110. struct mips_fpu_struct {
  111. union fpureg fpr[NUM_FPU_REGS];
  112. unsigned int fcr31;
  113. unsigned int msacsr;
  114. };
  115. #define NUM_DSP_REGS 6
  116. typedef unsigned long dspreg_t;
  117. struct mips_dsp_state {
  118. dspreg_t dspr[NUM_DSP_REGS];
  119. unsigned int dspcontrol;
  120. };
  121. #define INIT_CPUMASK { \
  122. {0,} \
  123. }
  124. struct mips3264_watch_reg_state {
  125. /* The width of watchlo is 32 in a 32 bit kernel and 64 in a
  126. 64 bit kernel. We use unsigned long as it has the same
  127. property. */
  128. unsigned long watchlo[NUM_WATCH_REGS];
  129. /* Only the mask and IRW bits from watchhi. */
  130. u16 watchhi[NUM_WATCH_REGS];
  131. };
  132. union mips_watch_reg_state {
  133. struct mips3264_watch_reg_state mips3264;
  134. };
  135. #if defined(CONFIG_CPU_CAVIUM_OCTEON)
  136. struct octeon_cop2_state {
  137. /* DMFC2 rt, 0x0201 */
  138. unsigned long cop2_crc_iv;
  139. /* DMFC2 rt, 0x0202 (Set with DMTC2 rt, 0x1202) */
  140. unsigned long cop2_crc_length;
  141. /* DMFC2 rt, 0x0200 (set with DMTC2 rt, 0x4200) */
  142. unsigned long cop2_crc_poly;
  143. /* DMFC2 rt, 0x0402; DMFC2 rt, 0x040A */
  144. unsigned long cop2_llm_dat[2];
  145. /* DMFC2 rt, 0x0084 */
  146. unsigned long cop2_3des_iv;
  147. /* DMFC2 rt, 0x0080; DMFC2 rt, 0x0081; DMFC2 rt, 0x0082 */
  148. unsigned long cop2_3des_key[3];
  149. /* DMFC2 rt, 0x0088 (Set with DMTC2 rt, 0x0098) */
  150. unsigned long cop2_3des_result;
  151. /* DMFC2 rt, 0x0111 (FIXME: Read Pass1 Errata) */
  152. unsigned long cop2_aes_inp0;
  153. /* DMFC2 rt, 0x0102; DMFC2 rt, 0x0103 */
  154. unsigned long cop2_aes_iv[2];
  155. /* DMFC2 rt, 0x0104; DMFC2 rt, 0x0105; DMFC2 rt, 0x0106; DMFC2
  156. * rt, 0x0107 */
  157. unsigned long cop2_aes_key[4];
  158. /* DMFC2 rt, 0x0110 */
  159. unsigned long cop2_aes_keylen;
  160. /* DMFC2 rt, 0x0100; DMFC2 rt, 0x0101 */
  161. unsigned long cop2_aes_result[2];
  162. /* DMFC2 rt, 0x0240; DMFC2 rt, 0x0241; DMFC2 rt, 0x0242; DMFC2
  163. * rt, 0x0243; DMFC2 rt, 0x0244; DMFC2 rt, 0x0245; DMFC2 rt,
  164. * 0x0246; DMFC2 rt, 0x0247; DMFC2 rt, 0x0248; DMFC2 rt,
  165. * 0x0249; DMFC2 rt, 0x024A; DMFC2 rt, 0x024B; DMFC2 rt,
  166. * 0x024C; DMFC2 rt, 0x024D; DMFC2 rt, 0x024E - Pass2 */
  167. unsigned long cop2_hsh_datw[15];
  168. /* DMFC2 rt, 0x0250; DMFC2 rt, 0x0251; DMFC2 rt, 0x0252; DMFC2
  169. * rt, 0x0253; DMFC2 rt, 0x0254; DMFC2 rt, 0x0255; DMFC2 rt,
  170. * 0x0256; DMFC2 rt, 0x0257 - Pass2 */
  171. unsigned long cop2_hsh_ivw[8];
  172. /* DMFC2 rt, 0x0258; DMFC2 rt, 0x0259 - Pass2 */
  173. unsigned long cop2_gfm_mult[2];
  174. /* DMFC2 rt, 0x025E - Pass2 */
  175. unsigned long cop2_gfm_poly;
  176. /* DMFC2 rt, 0x025A; DMFC2 rt, 0x025B - Pass2 */
  177. unsigned long cop2_gfm_result[2];
  178. /* DMFC2 rt, 0x24F, DMFC2 rt, 0x50, OCTEON III */
  179. unsigned long cop2_sha3[2];
  180. };
  181. #define COP2_INIT \
  182. .cp2 = {0,},
  183. struct octeon_cvmseg_state {
  184. unsigned long cvmseg[CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE]
  185. [cpu_dcache_line_size() / sizeof(unsigned long)];
  186. };
  187. #elif defined(CONFIG_CPU_XLP)
  188. struct nlm_cop2_state {
  189. u64 rx[4];
  190. u64 tx[4];
  191. u32 tx_msg_status;
  192. u32 rx_msg_status;
  193. };
  194. #define COP2_INIT \
  195. .cp2 = {{0}, {0}, 0, 0},
  196. #else
  197. #define COP2_INIT
  198. #endif
  199. typedef struct {
  200. unsigned long seg;
  201. } mm_segment_t;
  202. #ifdef CONFIG_CPU_HAS_MSA
  203. # define ARCH_MIN_TASKALIGN 16
  204. # define FPU_ALIGN __aligned(16)
  205. #else
  206. # define ARCH_MIN_TASKALIGN 8
  207. # define FPU_ALIGN
  208. #endif
  209. struct mips_abi;
  210. /*
  211. * If you change thread_struct remember to change the #defines below too!
  212. */
  213. struct thread_struct {
  214. /* Saved main processor registers. */
  215. unsigned long reg16;
  216. unsigned long reg17, reg18, reg19, reg20, reg21, reg22, reg23;
  217. unsigned long reg29, reg30, reg31;
  218. /* Saved cp0 stuff. */
  219. unsigned long cp0_status;
  220. /* Saved fpu/fpu emulator stuff. */
  221. struct mips_fpu_struct fpu FPU_ALIGN;
  222. /* Assigned branch delay slot 'emulation' frame */
  223. atomic_t bd_emu_frame;
  224. /* PC of the branch from a branch delay slot 'emulation' */
  225. unsigned long bd_emu_branch_pc;
  226. /* PC to continue from following a branch delay slot 'emulation' */
  227. unsigned long bd_emu_cont_pc;
  228. #ifdef CONFIG_MIPS_MT_FPAFF
  229. /* Emulated instruction count */
  230. unsigned long emulated_fp;
  231. /* Saved per-thread scheduler affinity mask */
  232. cpumask_t user_cpus_allowed;
  233. #endif /* CONFIG_MIPS_MT_FPAFF */
  234. /* Saved state of the DSP ASE, if available. */
  235. struct mips_dsp_state dsp;
  236. /* Saved watch register state, if available. */
  237. union mips_watch_reg_state watch;
  238. /* Other stuff associated with the thread. */
  239. unsigned long cp0_badvaddr; /* Last user fault */
  240. unsigned long cp0_baduaddr; /* Last kernel fault accessing USEG */
  241. unsigned long error_code;
  242. unsigned long trap_nr;
  243. #ifdef CONFIG_CPU_CAVIUM_OCTEON
  244. struct octeon_cop2_state cp2 __attribute__ ((__aligned__(128)));
  245. struct octeon_cvmseg_state cvmseg __attribute__ ((__aligned__(128)));
  246. #endif
  247. #ifdef CONFIG_CPU_XLP
  248. struct nlm_cop2_state cp2;
  249. #endif
  250. struct mips_abi *abi;
  251. };
  252. #ifdef CONFIG_MIPS_MT_FPAFF
  253. #define FPAFF_INIT \
  254. .emulated_fp = 0, \
  255. .user_cpus_allowed = INIT_CPUMASK,
  256. #else
  257. #define FPAFF_INIT
  258. #endif /* CONFIG_MIPS_MT_FPAFF */
  259. #define INIT_THREAD { \
  260. /* \
  261. * Saved main processor registers \
  262. */ \
  263. .reg16 = 0, \
  264. .reg17 = 0, \
  265. .reg18 = 0, \
  266. .reg19 = 0, \
  267. .reg20 = 0, \
  268. .reg21 = 0, \
  269. .reg22 = 0, \
  270. .reg23 = 0, \
  271. .reg29 = 0, \
  272. .reg30 = 0, \
  273. .reg31 = 0, \
  274. /* \
  275. * Saved cp0 stuff \
  276. */ \
  277. .cp0_status = 0, \
  278. /* \
  279. * Saved FPU/FPU emulator stuff \
  280. */ \
  281. .fpu = { \
  282. .fpr = {{{0,},},}, \
  283. .fcr31 = 0, \
  284. .msacsr = 0, \
  285. }, \
  286. /* \
  287. * FPU affinity state (null if not FPAFF) \
  288. */ \
  289. FPAFF_INIT \
  290. /* Delay slot emulation */ \
  291. .bd_emu_frame = ATOMIC_INIT(BD_EMUFRAME_NONE), \
  292. .bd_emu_branch_pc = 0, \
  293. .bd_emu_cont_pc = 0, \
  294. /* \
  295. * Saved DSP stuff \
  296. */ \
  297. .dsp = { \
  298. .dspr = {0, }, \
  299. .dspcontrol = 0, \
  300. }, \
  301. /* \
  302. * saved watch register stuff \
  303. */ \
  304. .watch = {{{0,},},}, \
  305. /* \
  306. * Other stuff associated with the process \
  307. */ \
  308. .cp0_badvaddr = 0, \
  309. .cp0_baduaddr = 0, \
  310. .error_code = 0, \
  311. .trap_nr = 0, \
  312. /* \
  313. * Platform specific cop2 registers(null if no COP2) \
  314. */ \
  315. COP2_INIT \
  316. }
  317. struct task_struct;
  318. /* Free all resources held by a thread. */
  319. #define release_thread(thread) do { } while(0)
  320. /*
  321. * Do necessary setup to start up a newly executed thread.
  322. */
  323. extern void start_thread(struct pt_regs * regs, unsigned long pc, unsigned long sp);
  324. static inline void flush_thread(void)
  325. {
  326. }
  327. unsigned long get_wchan(struct task_struct *p);
  328. #define __KSTK_TOS(tsk) ((unsigned long)task_stack_page(tsk) + \
  329. THREAD_SIZE - 32 - sizeof(struct pt_regs))
  330. #define task_pt_regs(tsk) ((struct pt_regs *)__KSTK_TOS(tsk))
  331. #define KSTK_EIP(tsk) (task_pt_regs(tsk)->cp0_epc)
  332. #define KSTK_ESP(tsk) (task_pt_regs(tsk)->regs[29])
  333. #define KSTK_STATUS(tsk) (task_pt_regs(tsk)->cp0_status)
  334. #ifdef CONFIG_CPU_LOONGSON3
  335. /*
  336. * Loongson-3's SFB (Store-Fill-Buffer) may buffer writes indefinitely when a
  337. * tight read loop is executed, because reads take priority over writes & the
  338. * hardware (incorrectly) doesn't ensure that writes will eventually occur.
  339. *
  340. * Since spin loops of any kind should have a cpu_relax() in them, force an SFB
  341. * flush from cpu_relax() such that any pending writes will become visible as
  342. * expected.
  343. */
  344. #define cpu_relax() smp_mb()
  345. #else
  346. #define cpu_relax() barrier()
  347. #endif
  348. /*
  349. * Return_address is a replacement for __builtin_return_address(count)
  350. * which on certain architectures cannot reasonably be implemented in GCC
  351. * (MIPS, Alpha) or is unusable with -fomit-frame-pointer (i386).
  352. * Note that __builtin_return_address(x>=1) is forbidden because GCC
  353. * aborts compilation on some CPUs. It's simply not possible to unwind
  354. * some CPU's stackframes.
  355. *
  356. * __builtin_return_address works only for non-leaf functions. We avoid the
  357. * overhead of a function call by forcing the compiler to save the return
  358. * address register on the stack.
  359. */
  360. #define return_address() ({__asm__ __volatile__("":::"$31");__builtin_return_address(0);})
  361. #ifdef CONFIG_CPU_HAS_PREFETCH
  362. #define ARCH_HAS_PREFETCH
  363. #define prefetch(x) __builtin_prefetch((x), 0, 1)
  364. #define ARCH_HAS_PREFETCHW
  365. #define prefetchw(x) __builtin_prefetch((x), 1, 1)
  366. #endif
  367. /*
  368. * Functions & macros implementing the PR_GET_FP_MODE & PR_SET_FP_MODE options
  369. * to the prctl syscall.
  370. */
  371. extern int mips_get_process_fp_mode(struct task_struct *task);
  372. extern int mips_set_process_fp_mode(struct task_struct *task,
  373. unsigned int value);
  374. #define GET_FP_MODE(task) mips_get_process_fp_mode(task)
  375. #define SET_FP_MODE(task,value) mips_set_process_fp_mode(task, value)
  376. #endif /* _ASM_PROCESSOR_H */