arcregs.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. /*
  2. * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #ifndef _ASM_ARC_ARCREGS_H
  9. #define _ASM_ARC_ARCREGS_H
  10. #ifdef __KERNEL__
  11. /* Build Configuration Registers */
  12. #define ARC_REG_VECBASE_BCR 0x68
  13. #define ARC_REG_MMU_BCR 0x6f
  14. /* status32 Bits Positions */
  15. #define STATUS_H_BIT 0 /* CPU Halted */
  16. #define STATUS_E1_BIT 1 /* Int 1 enable */
  17. #define STATUS_E2_BIT 2 /* Int 2 enable */
  18. #define STATUS_A1_BIT 3 /* Int 1 active */
  19. #define STATUS_A2_BIT 4 /* Int 2 active */
  20. #define STATUS_AE_BIT 5 /* Exception active */
  21. #define STATUS_DE_BIT 6 /* PC is in delay slot */
  22. #define STATUS_U_BIT 7 /* User/Kernel mode */
  23. #define STATUS_L_BIT 12 /* Loop inhibit */
  24. /* These masks correspond to the status word(STATUS_32) bits */
  25. #define STATUS_H_MASK (1<<STATUS_H_BIT)
  26. #define STATUS_E1_MASK (1<<STATUS_E1_BIT)
  27. #define STATUS_E2_MASK (1<<STATUS_E2_BIT)
  28. #define STATUS_A1_MASK (1<<STATUS_A1_BIT)
  29. #define STATUS_A2_MASK (1<<STATUS_A2_BIT)
  30. #define STATUS_AE_MASK (1<<STATUS_AE_BIT)
  31. #define STATUS_DE_MASK (1<<STATUS_DE_BIT)
  32. #define STATUS_U_MASK (1<<STATUS_U_BIT)
  33. #define STATUS_L_MASK (1<<STATUS_L_BIT)
  34. /*
  35. * ECR: Exception Cause Reg bits-n-pieces
  36. * [23:16] = Exception Vector
  37. * [15: 8] = Exception Cause Code
  38. * [ 7: 0] = Exception Parameters (for certain types only)
  39. */
  40. #define ECR_VEC_MASK 0xff0000
  41. #define ECR_CODE_MASK 0x00ff00
  42. #define ECR_PARAM_MASK 0x0000ff
  43. /* Exception Cause Vector Values */
  44. #define ECR_V_INSN_ERR 0x02
  45. #define ECR_V_MACH_CHK 0x20
  46. #define ECR_V_ITLB_MISS 0x21
  47. #define ECR_V_DTLB_MISS 0x22
  48. #define ECR_V_PROTV 0x23
  49. /* Protection Violation Exception Cause Code Values */
  50. #define ECR_C_PROTV_INST_FETCH 0x00
  51. #define ECR_C_PROTV_LOAD 0x01
  52. #define ECR_C_PROTV_STORE 0x02
  53. #define ECR_C_PROTV_XCHG 0x03
  54. #define ECR_C_PROTV_MISALIG_DATA 0x04
  55. /* DTLB Miss Exception Cause Code Values */
  56. #define ECR_C_BIT_DTLB_LD_MISS 8
  57. #define ECR_C_BIT_DTLB_ST_MISS 9
  58. /* Auxiliary registers */
  59. #define AUX_IDENTITY 4
  60. #define AUX_INTR_VEC_BASE 0x25
  61. #define AUX_IRQ_LEV 0x200 /* IRQ Priority: L1 or L2 */
  62. #define AUX_IRQ_HINT 0x201 /* For generating Soft Interrupts */
  63. #define AUX_IRQ_LV12 0x43 /* interrupt level register */
  64. #define AUX_IENABLE 0x40c
  65. #define AUX_ITRIGGER 0x40d
  66. #define AUX_IPULSE 0x415
  67. /* Timer related Aux registers */
  68. #define ARC_REG_TIMER0_LIMIT 0x23 /* timer 0 limit */
  69. #define ARC_REG_TIMER0_CTRL 0x22 /* timer 0 control */
  70. #define ARC_REG_TIMER0_CNT 0x21 /* timer 0 count */
  71. #define ARC_REG_TIMER1_LIMIT 0x102 /* timer 1 limit */
  72. #define ARC_REG_TIMER1_CTRL 0x101 /* timer 1 control */
  73. #define ARC_REG_TIMER1_CNT 0x100 /* timer 1 count */
  74. #define TIMER_CTRL_IE (1 << 0) /* Interupt when Count reachs limit */
  75. #define TIMER_CTRL_NH (1 << 1) /* Count only when CPU NOT halted */
  76. #if defined(CONFIG_ARC_MMU_V1)
  77. #define CONFIG_ARC_MMU_VER 1
  78. #elif defined(CONFIG_ARC_MMU_V2)
  79. #define CONFIG_ARC_MMU_VER 2
  80. #elif defined(CONFIG_ARC_MMU_V3)
  81. #define CONFIG_ARC_MMU_VER 3
  82. #else
  83. #error "Error: MMU ver"
  84. #endif
  85. /* MMU Management regs */
  86. #define ARC_REG_TLBPD0 0x405
  87. #define ARC_REG_TLBPD1 0x406
  88. #define ARC_REG_TLBINDEX 0x407
  89. #define ARC_REG_TLBCOMMAND 0x408
  90. #define ARC_REG_PID 0x409
  91. #define ARC_REG_SCRATCH_DATA0 0x418
  92. /* Bits in MMU PID register */
  93. #define MMU_ENABLE (1 << 31) /* Enable MMU for process */
  94. /* Error code if probe fails */
  95. #define TLB_LKUP_ERR 0x80000000
  96. /* TLB Commands */
  97. #define TLBWrite 0x1
  98. #define TLBRead 0x2
  99. #define TLBGetIndex 0x3
  100. #define TLBProbe 0x4
  101. #if (CONFIG_ARC_MMU_VER >= 2)
  102. #define TLBWriteNI 0x5 /* write JTLB without inv uTLBs */
  103. #define TLBIVUTLB 0x6 /* explicitly inv uTLBs */
  104. #else
  105. #undef TLBWriteNI /* These cmds don't exist on older MMU */
  106. #undef TLBIVUTLB
  107. #endif
  108. /* Instruction cache related Auxiliary registers */
  109. #define ARC_REG_IC_BCR 0x77 /* Build Config reg */
  110. #define ARC_REG_IC_IVIC 0x10
  111. #define ARC_REG_IC_CTRL 0x11
  112. #define ARC_REG_IC_IVIL 0x19
  113. #if (CONFIG_ARC_MMU_VER > 2)
  114. #define ARC_REG_IC_PTAG 0x1E
  115. #endif
  116. /* Bit val in IC_CTRL */
  117. #define IC_CTRL_CACHE_DISABLE 0x1
  118. /* Data cache related Auxiliary registers */
  119. #define ARC_REG_DC_BCR 0x72
  120. #define ARC_REG_DC_IVDC 0x47
  121. #define ARC_REG_DC_CTRL 0x48
  122. #define ARC_REG_DC_IVDL 0x4A
  123. #define ARC_REG_DC_FLSH 0x4B
  124. #define ARC_REG_DC_FLDL 0x4C
  125. #if (CONFIG_ARC_MMU_VER > 2)
  126. #define ARC_REG_DC_PTAG 0x5C
  127. #endif
  128. /* Bit val in DC_CTRL */
  129. #define DC_CTRL_INV_MODE_FLUSH 0x40
  130. #define DC_CTRL_FLUSH_STATUS 0x100
  131. /* MMU Management regs */
  132. #define ARC_REG_PID 0x409
  133. #define ARC_REG_SCRATCH_DATA0 0x418
  134. /* Bits in MMU PID register */
  135. #define MMU_ENABLE (1 << 31) /* Enable MMU for process */
  136. /*
  137. * Floating Pt Registers
  138. * Status regs are read-only (build-time) so need not be saved/restored
  139. */
  140. #define ARC_AUX_FP_STAT 0x300
  141. #define ARC_AUX_DPFP_1L 0x301
  142. #define ARC_AUX_DPFP_1H 0x302
  143. #define ARC_AUX_DPFP_2L 0x303
  144. #define ARC_AUX_DPFP_2H 0x304
  145. #define ARC_AUX_DPFP_STAT 0x305
  146. #ifndef __ASSEMBLY__
  147. /*
  148. ******************************************************************
  149. * Inline ASM macros to read/write AUX Regs
  150. * Essentially invocation of lr/sr insns from "C"
  151. */
  152. #if 1
  153. #define read_aux_reg(reg) __builtin_arc_lr(reg)
  154. /* gcc builtin sr needs reg param to be long immediate */
  155. #define write_aux_reg(reg_immed, val) \
  156. __builtin_arc_sr((unsigned int)val, reg_immed)
  157. #else
  158. #define read_aux_reg(reg) \
  159. ({ \
  160. unsigned int __ret; \
  161. __asm__ __volatile__( \
  162. " lr %0, [%1]" \
  163. : "=r"(__ret) \
  164. : "i"(reg)); \
  165. __ret; \
  166. })
  167. /*
  168. * Aux Reg address is specified as long immediate by caller
  169. * e.g.
  170. * write_aux_reg(0x69, some_val);
  171. * This generates tightest code.
  172. */
  173. #define write_aux_reg(reg_imm, val) \
  174. ({ \
  175. __asm__ __volatile__( \
  176. " sr %0, [%1] \n" \
  177. : \
  178. : "ir"(val), "i"(reg_imm)); \
  179. })
  180. /*
  181. * Aux Reg address is specified in a variable
  182. * * e.g.
  183. * reg_num = 0x69
  184. * write_aux_reg2(reg_num, some_val);
  185. * This has to generate glue code to load the reg num from
  186. * memory to a reg hence not recommended.
  187. */
  188. #define write_aux_reg2(reg_in_var, val) \
  189. ({ \
  190. unsigned int tmp; \
  191. \
  192. __asm__ __volatile__( \
  193. " ld %0, [%2] \n\t" \
  194. " sr %1, [%0] \n\t" \
  195. : "=&r"(tmp) \
  196. : "r"(val), "memory"(&reg_in_var)); \
  197. })
  198. #endif
  199. #define READ_BCR(reg, into) \
  200. { \
  201. unsigned int tmp; \
  202. tmp = read_aux_reg(reg); \
  203. if (sizeof(tmp) == sizeof(into)) { \
  204. into = *((typeof(into) *)&tmp); \
  205. } else { \
  206. extern void bogus_undefined(void); \
  207. bogus_undefined(); \
  208. } \
  209. }
  210. #define WRITE_BCR(reg, into) \
  211. { \
  212. unsigned int tmp; \
  213. if (sizeof(tmp) == sizeof(into)) { \
  214. tmp = (*(unsigned int *)(into)); \
  215. write_aux_reg(reg, tmp); \
  216. } else { \
  217. extern void bogus_undefined(void); \
  218. bogus_undefined(); \
  219. } \
  220. }
  221. /* Helpers */
  222. #define TO_KB(bytes) ((bytes) >> 10)
  223. #define TO_MB(bytes) (TO_KB(bytes) >> 10)
  224. #define PAGES_TO_KB(n_pages) ((n_pages) << (PAGE_SHIFT - 10))
  225. #define PAGES_TO_MB(n_pages) (PAGES_TO_KB(n_pages) >> 10)
  226. #ifdef CONFIG_ARC_FPU_SAVE_RESTORE
  227. /* These DPFP regs need to be saved/restored across ctx-sw */
  228. struct arc_fpu {
  229. struct {
  230. unsigned int l, h;
  231. } aux_dpfp[2];
  232. };
  233. #endif
  234. /*
  235. ***************************************************************
  236. * Build Configuration Registers, with encoded hardware config
  237. */
  238. struct bcr_mmu_1_2 {
  239. #ifdef CONFIG_CPU_BIG_ENDIAN
  240. unsigned int ver:8, ways:4, sets:4, u_itlb:8, u_dtlb:8;
  241. #else
  242. unsigned int u_dtlb:8, u_itlb:8, sets:4, ways:4, ver:8;
  243. #endif
  244. };
  245. struct bcr_mmu_3 {
  246. #ifdef CONFIG_CPU_BIG_ENDIAN
  247. unsigned int ver:8, ways:4, sets:4, osm:1, reserv:3, pg_sz:4,
  248. u_itlb:4, u_dtlb:4;
  249. #else
  250. unsigned int u_dtlb:4, u_itlb:4, pg_sz:4, reserv:3, osm:1, sets:4,
  251. ways:4, ver:8;
  252. #endif
  253. };
  254. struct bcr_cache {
  255. #ifdef CONFIG_CPU_BIG_ENDIAN
  256. unsigned int pad:12, line_len:4, sz:4, config:4, ver:8;
  257. #else
  258. unsigned int ver:8, config:4, sz:4, line_len:4, pad:12;
  259. #endif
  260. };
  261. /*
  262. *******************************************************************
  263. * Generic structures to hold build configuration used at runtime
  264. */
  265. struct cpuinfo_arc_mmu {
  266. unsigned int ver, pg_sz, sets, ways, u_dtlb, u_itlb, num_tlb;
  267. };
  268. struct cpuinfo_arc_cache {
  269. unsigned int has_aliasing, sz, line_len, assoc, ver;
  270. };
  271. struct cpuinfo_arc {
  272. struct cpuinfo_arc_cache icache, dcache;
  273. struct cpuinfo_arc_mmu mmu;
  274. };
  275. extern struct cpuinfo_arc cpuinfo_arc700[];
  276. #endif /* __ASEMBLY__ */
  277. #endif /* __KERNEL__ */
  278. #endif /* _ASM_ARC_ARCREGS_H */