arcregs.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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. /* Build Configuration Registers */
  11. #define ARC_REG_DCCMBASE_BCR 0x61 /* DCCM Base Addr */
  12. #define ARC_REG_CRC_BCR 0x62
  13. #define ARC_REG_VECBASE_BCR 0x68
  14. #define ARC_REG_PERIBASE_BCR 0x69
  15. #define ARC_REG_FP_BCR 0x6B /* ARCompact: Single-Precision FPU */
  16. #define ARC_REG_DPFP_BCR 0x6C /* ARCompact: Dbl Precision FPU */
  17. #define ARC_REG_FP_V2_BCR 0xc8 /* ARCv2 FPU */
  18. #define ARC_REG_SLC_BCR 0xce
  19. #define ARC_REG_DCCM_BCR 0x74 /* DCCM Present + SZ */
  20. #define ARC_REG_TIMERS_BCR 0x75
  21. #define ARC_REG_AP_BCR 0x76
  22. #define ARC_REG_ICCM_BCR 0x78
  23. #define ARC_REG_XY_MEM_BCR 0x79
  24. #define ARC_REG_MAC_BCR 0x7a
  25. #define ARC_REG_MUL_BCR 0x7b
  26. #define ARC_REG_SWAP_BCR 0x7c
  27. #define ARC_REG_NORM_BCR 0x7d
  28. #define ARC_REG_MIXMAX_BCR 0x7e
  29. #define ARC_REG_BARREL_BCR 0x7f
  30. #define ARC_REG_D_UNCACH_BCR 0x6A
  31. #define ARC_REG_BPU_BCR 0xc0
  32. #define ARC_REG_ISA_CFG_BCR 0xc1
  33. #define ARC_REG_RTT_BCR 0xF2
  34. #define ARC_REG_IRQ_BCR 0xF3
  35. #define ARC_REG_SMART_BCR 0xFF
  36. /* status32 Bits Positions */
  37. #define STATUS_AE_BIT 5 /* Exception active */
  38. #define STATUS_DE_BIT 6 /* PC is in delay slot */
  39. #define STATUS_U_BIT 7 /* User/Kernel mode */
  40. #define STATUS_L_BIT 12 /* Loop inhibit */
  41. /* These masks correspond to the status word(STATUS_32) bits */
  42. #define STATUS_AE_MASK (1<<STATUS_AE_BIT)
  43. #define STATUS_DE_MASK (1<<STATUS_DE_BIT)
  44. #define STATUS_U_MASK (1<<STATUS_U_BIT)
  45. #define STATUS_L_MASK (1<<STATUS_L_BIT)
  46. /*
  47. * ECR: Exception Cause Reg bits-n-pieces
  48. * [23:16] = Exception Vector
  49. * [15: 8] = Exception Cause Code
  50. * [ 7: 0] = Exception Parameters (for certain types only)
  51. */
  52. #ifdef CONFIG_ISA_ARCOMPACT
  53. #define ECR_V_MEM_ERR 0x01
  54. #define ECR_V_INSN_ERR 0x02
  55. #define ECR_V_MACH_CHK 0x20
  56. #define ECR_V_ITLB_MISS 0x21
  57. #define ECR_V_DTLB_MISS 0x22
  58. #define ECR_V_PROTV 0x23
  59. #define ECR_V_TRAP 0x25
  60. #else
  61. #define ECR_V_MEM_ERR 0x01
  62. #define ECR_V_INSN_ERR 0x02
  63. #define ECR_V_MACH_CHK 0x03
  64. #define ECR_V_ITLB_MISS 0x04
  65. #define ECR_V_DTLB_MISS 0x05
  66. #define ECR_V_PROTV 0x06
  67. #define ECR_V_TRAP 0x09
  68. #endif
  69. /* DTLB Miss and Protection Violation Cause Codes */
  70. #define ECR_C_PROTV_INST_FETCH 0x00
  71. #define ECR_C_PROTV_LOAD 0x01
  72. #define ECR_C_PROTV_STORE 0x02
  73. #define ECR_C_PROTV_XCHG 0x03
  74. #define ECR_C_PROTV_MISALIG_DATA 0x04
  75. #define ECR_C_BIT_PROTV_MISALIG_DATA 10
  76. /* Machine Check Cause Code Values */
  77. #define ECR_C_MCHK_DUP_TLB 0x01
  78. /* DTLB Miss Exception Cause Code Values */
  79. #define ECR_C_BIT_DTLB_LD_MISS 8
  80. #define ECR_C_BIT_DTLB_ST_MISS 9
  81. /* Auxiliary registers */
  82. #define AUX_IDENTITY 4
  83. #define AUX_INTR_VEC_BASE 0x25
  84. #define AUX_NON_VOL 0x5e
  85. /*
  86. * Floating Pt Registers
  87. * Status regs are read-only (build-time) so need not be saved/restored
  88. */
  89. #define ARC_AUX_FP_STAT 0x300
  90. #define ARC_AUX_DPFP_1L 0x301
  91. #define ARC_AUX_DPFP_1H 0x302
  92. #define ARC_AUX_DPFP_2L 0x303
  93. #define ARC_AUX_DPFP_2H 0x304
  94. #define ARC_AUX_DPFP_STAT 0x305
  95. #ifndef __ASSEMBLY__
  96. /*
  97. ******************************************************************
  98. * Inline ASM macros to read/write AUX Regs
  99. * Essentially invocation of lr/sr insns from "C"
  100. */
  101. #if 1
  102. #define read_aux_reg(reg) __builtin_arc_lr(reg)
  103. /* gcc builtin sr needs reg param to be long immediate */
  104. #define write_aux_reg(reg_immed, val) \
  105. __builtin_arc_sr((unsigned int)val, reg_immed)
  106. #else
  107. #define read_aux_reg(reg) \
  108. ({ \
  109. unsigned int __ret; \
  110. __asm__ __volatile__( \
  111. " lr %0, [%1]" \
  112. : "=r"(__ret) \
  113. : "i"(reg)); \
  114. __ret; \
  115. })
  116. /*
  117. * Aux Reg address is specified as long immediate by caller
  118. * e.g.
  119. * write_aux_reg(0x69, some_val);
  120. * This generates tightest code.
  121. */
  122. #define write_aux_reg(reg_imm, val) \
  123. ({ \
  124. __asm__ __volatile__( \
  125. " sr %0, [%1] \n" \
  126. : \
  127. : "ir"(val), "i"(reg_imm)); \
  128. })
  129. /*
  130. * Aux Reg address is specified in a variable
  131. * * e.g.
  132. * reg_num = 0x69
  133. * write_aux_reg2(reg_num, some_val);
  134. * This has to generate glue code to load the reg num from
  135. * memory to a reg hence not recommended.
  136. */
  137. #define write_aux_reg2(reg_in_var, val) \
  138. ({ \
  139. unsigned int tmp; \
  140. \
  141. __asm__ __volatile__( \
  142. " ld %0, [%2] \n\t" \
  143. " sr %1, [%0] \n\t" \
  144. : "=&r"(tmp) \
  145. : "r"(val), "memory"(&reg_in_var)); \
  146. })
  147. #endif
  148. #define READ_BCR(reg, into) \
  149. { \
  150. unsigned int tmp; \
  151. tmp = read_aux_reg(reg); \
  152. if (sizeof(tmp) == sizeof(into)) { \
  153. into = *((typeof(into) *)&tmp); \
  154. } else { \
  155. extern void bogus_undefined(void); \
  156. bogus_undefined(); \
  157. } \
  158. }
  159. #define WRITE_AUX(reg, into) \
  160. { \
  161. unsigned int tmp; \
  162. if (sizeof(tmp) == sizeof(into)) { \
  163. tmp = (*(unsigned int *)&(into)); \
  164. write_aux_reg(reg, tmp); \
  165. } else { \
  166. extern void bogus_undefined(void); \
  167. bogus_undefined(); \
  168. } \
  169. }
  170. /* Helpers */
  171. #define TO_KB(bytes) ((bytes) >> 10)
  172. #define TO_MB(bytes) (TO_KB(bytes) >> 10)
  173. #define PAGES_TO_KB(n_pages) ((n_pages) << (PAGE_SHIFT - 10))
  174. #define PAGES_TO_MB(n_pages) (PAGES_TO_KB(n_pages) >> 10)
  175. /*
  176. ***************************************************************
  177. * Build Configuration Registers, with encoded hardware config
  178. */
  179. struct bcr_identity {
  180. #ifdef CONFIG_CPU_BIG_ENDIAN
  181. unsigned int chip_id:16, cpu_id:8, family:8;
  182. #else
  183. unsigned int family:8, cpu_id:8, chip_id:16;
  184. #endif
  185. };
  186. struct bcr_isa {
  187. #ifdef CONFIG_CPU_BIG_ENDIAN
  188. unsigned int div_rem:4, pad2:4, ldd:1, unalign:1, atomic:1, be:1,
  189. pad1:11, atomic1:1, ver:8;
  190. #else
  191. unsigned int ver:8, atomic1:1, pad1:11, be:1, atomic:1, unalign:1,
  192. ldd:1, pad2:4, div_rem:4;
  193. #endif
  194. };
  195. struct bcr_mpy {
  196. #ifdef CONFIG_CPU_BIG_ENDIAN
  197. unsigned int pad:8, x1616:8, dsp:4, cycles:2, type:2, ver:8;
  198. #else
  199. unsigned int ver:8, type:2, cycles:2, dsp:4, x1616:8, pad:8;
  200. #endif
  201. };
  202. struct bcr_extn_xymem {
  203. #ifdef CONFIG_CPU_BIG_ENDIAN
  204. unsigned int ram_org:2, num_banks:4, bank_sz:4, ver:8;
  205. #else
  206. unsigned int ver:8, bank_sz:4, num_banks:4, ram_org:2;
  207. #endif
  208. };
  209. struct bcr_perip {
  210. #ifdef CONFIG_CPU_BIG_ENDIAN
  211. unsigned int start:8, pad2:8, sz:8, ver:8;
  212. #else
  213. unsigned int ver:8, sz:8, pad2:8, start:8;
  214. #endif
  215. };
  216. struct bcr_iccm {
  217. #ifdef CONFIG_CPU_BIG_ENDIAN
  218. unsigned int base:16, pad:5, sz:3, ver:8;
  219. #else
  220. unsigned int ver:8, sz:3, pad:5, base:16;
  221. #endif
  222. };
  223. /* DCCM Base Address Register: ARC_REG_DCCMBASE_BCR */
  224. struct bcr_dccm_base {
  225. #ifdef CONFIG_CPU_BIG_ENDIAN
  226. unsigned int addr:24, ver:8;
  227. #else
  228. unsigned int ver:8, addr:24;
  229. #endif
  230. };
  231. /* DCCM RAM Configuration Register: ARC_REG_DCCM_BCR */
  232. struct bcr_dccm {
  233. #ifdef CONFIG_CPU_BIG_ENDIAN
  234. unsigned int res:21, sz:3, ver:8;
  235. #else
  236. unsigned int ver:8, sz:3, res:21;
  237. #endif
  238. };
  239. /* ARCompact: Both SP and DP FPU BCRs have same format */
  240. struct bcr_fp_arcompact {
  241. #ifdef CONFIG_CPU_BIG_ENDIAN
  242. unsigned int fast:1, ver:8;
  243. #else
  244. unsigned int ver:8, fast:1;
  245. #endif
  246. };
  247. struct bcr_fp_arcv2 {
  248. #ifdef CONFIG_CPU_BIG_ENDIAN
  249. unsigned int pad2:15, dp:1, pad1:7, sp:1, ver:8;
  250. #else
  251. unsigned int ver:8, sp:1, pad1:7, dp:1, pad2:15;
  252. #endif
  253. };
  254. struct bcr_timer {
  255. #ifdef CONFIG_CPU_BIG_ENDIAN
  256. unsigned int pad2:15, rtsc:1, pad1:5, rtc:1, t1:1, t0:1, ver:8;
  257. #else
  258. unsigned int ver:8, t0:1, t1:1, rtc:1, pad1:5, rtsc:1, pad2:15;
  259. #endif
  260. };
  261. struct bcr_bpu_arcompact {
  262. #ifdef CONFIG_CPU_BIG_ENDIAN
  263. unsigned int pad2:19, fam:1, pad:2, ent:2, ver:8;
  264. #else
  265. unsigned int ver:8, ent:2, pad:2, fam:1, pad2:19;
  266. #endif
  267. };
  268. struct bcr_bpu_arcv2 {
  269. #ifdef CONFIG_CPU_BIG_ENDIAN
  270. unsigned int pad:6, fbe:2, tqe:2, ts:4, ft:1, rse:2, pte:3, bce:3, ver:8;
  271. #else
  272. unsigned int ver:8, bce:3, pte:3, rse:2, ft:1, ts:4, tqe:2, fbe:2, pad:6;
  273. #endif
  274. };
  275. struct bcr_generic {
  276. #ifdef CONFIG_CPU_BIG_ENDIAN
  277. unsigned int pad:24, ver:8;
  278. #else
  279. unsigned int ver:8, pad:24;
  280. #endif
  281. };
  282. /*
  283. *******************************************************************
  284. * Generic structures to hold build configuration used at runtime
  285. */
  286. struct cpuinfo_arc_mmu {
  287. unsigned int ver:4, pg_sz_k:8, s_pg_sz_m:8, u_dtlb:6, u_itlb:6;
  288. unsigned int num_tlb:16, sets:12, ways:4;
  289. };
  290. struct cpuinfo_arc_cache {
  291. unsigned int sz_k:14, line_len:8, assoc:4, ver:4, alias:1, vipt:1;
  292. };
  293. struct cpuinfo_arc_bpu {
  294. unsigned int ver, full, num_cache, num_pred;
  295. };
  296. struct cpuinfo_arc_ccm {
  297. unsigned int base_addr, sz;
  298. };
  299. struct cpuinfo_arc {
  300. struct cpuinfo_arc_cache icache, dcache, slc;
  301. struct cpuinfo_arc_mmu mmu;
  302. struct cpuinfo_arc_bpu bpu;
  303. struct bcr_identity core;
  304. struct bcr_isa isa;
  305. struct bcr_timer timers;
  306. unsigned int vec_base;
  307. struct cpuinfo_arc_ccm iccm, dccm;
  308. struct {
  309. unsigned int swap:1, norm:1, minmax:1, barrel:1, crc:1, pad1:3,
  310. fpu_sp:1, fpu_dp:1, pad2:6,
  311. debug:1, ap:1, smart:1, rtt:1, pad3:4,
  312. pad4:8;
  313. } extn;
  314. struct bcr_mpy extn_mpy;
  315. struct bcr_extn_xymem extn_xymem;
  316. };
  317. extern struct cpuinfo_arc cpuinfo_arc700[];
  318. static inline int is_isa_arcv2(void)
  319. {
  320. return IS_ENABLED(CONFIG_ISA_ARCV2);
  321. }
  322. static inline int is_isa_arcompact(void)
  323. {
  324. return IS_ENABLED(CONFIG_ISA_ARCOMPACT);
  325. }
  326. #if defined(CONFIG_ISA_ARCOMPACT) && !defined(_CPU_DEFAULT_A7)
  327. #error "Toolchain not configured for ARCompact builds"
  328. #elif defined(CONFIG_ISA_ARCV2) && !defined(_CPU_DEFAULT_HS)
  329. #error "Toolchain not configured for ARCv2 builds"
  330. #endif
  331. #endif /* __ASEMBLY__ */
  332. #endif /* _ASM_ARC_ARCREGS_H */