cpu-features.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  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) 2003, 2004 Ralf Baechle
  7. * Copyright (C) 2004 Maciej W. Rozycki
  8. */
  9. #ifndef __ASM_CPU_FEATURES_H
  10. #define __ASM_CPU_FEATURES_H
  11. #include <asm/cpu.h>
  12. #include <asm/cpu-info.h>
  13. #include <cpu-feature-overrides.h>
  14. /*
  15. * SMP assumption: Options of CPU 0 are a superset of all processors.
  16. * This is true for all known MIPS systems.
  17. */
  18. #ifndef cpu_has_tlb
  19. #define cpu_has_tlb (cpu_data[0].options & MIPS_CPU_TLB)
  20. #endif
  21. #ifndef cpu_has_ftlb
  22. #define cpu_has_ftlb (cpu_data[0].options & MIPS_CPU_FTLB)
  23. #endif
  24. #ifndef cpu_has_tlbinv
  25. #define cpu_has_tlbinv (cpu_data[0].options & MIPS_CPU_TLBINV)
  26. #endif
  27. #ifndef cpu_has_segments
  28. #define cpu_has_segments (cpu_data[0].options & MIPS_CPU_SEGMENTS)
  29. #endif
  30. #ifndef cpu_has_eva
  31. #define cpu_has_eva (cpu_data[0].options & MIPS_CPU_EVA)
  32. #endif
  33. #ifndef cpu_has_htw
  34. #define cpu_has_htw (cpu_data[0].options & MIPS_CPU_HTW)
  35. #endif
  36. #ifndef cpu_has_ldpte
  37. #define cpu_has_ldpte (cpu_data[0].options & MIPS_CPU_LDPTE)
  38. #endif
  39. #ifndef cpu_has_rixiex
  40. #define cpu_has_rixiex (cpu_data[0].options & MIPS_CPU_RIXIEX)
  41. #endif
  42. #ifndef cpu_has_maar
  43. #define cpu_has_maar (cpu_data[0].options & MIPS_CPU_MAAR)
  44. #endif
  45. #ifndef cpu_has_rw_llb
  46. #define cpu_has_rw_llb (cpu_data[0].options & MIPS_CPU_RW_LLB)
  47. #endif
  48. /*
  49. * For the moment we don't consider R6000 and R8000 so we can assume that
  50. * anything that doesn't support R4000-style exceptions and interrupts is
  51. * R3000-like. Users should still treat these two macro definitions as
  52. * opaque.
  53. */
  54. #ifndef cpu_has_3kex
  55. #define cpu_has_3kex (!cpu_has_4kex)
  56. #endif
  57. #ifndef cpu_has_4kex
  58. #define cpu_has_4kex (cpu_data[0].options & MIPS_CPU_4KEX)
  59. #endif
  60. #ifndef cpu_has_3k_cache
  61. #define cpu_has_3k_cache (cpu_data[0].options & MIPS_CPU_3K_CACHE)
  62. #endif
  63. #define cpu_has_6k_cache 0
  64. #define cpu_has_8k_cache 0
  65. #ifndef cpu_has_4k_cache
  66. #define cpu_has_4k_cache (cpu_data[0].options & MIPS_CPU_4K_CACHE)
  67. #endif
  68. #ifndef cpu_has_tx39_cache
  69. #define cpu_has_tx39_cache (cpu_data[0].options & MIPS_CPU_TX39_CACHE)
  70. #endif
  71. #ifndef cpu_has_octeon_cache
  72. #define cpu_has_octeon_cache 0
  73. #endif
  74. /* Don't override `cpu_has_fpu' to 1 or the "nofpu" option won't work. */
  75. #ifndef cpu_has_fpu
  76. #define cpu_has_fpu (current_cpu_data.options & MIPS_CPU_FPU)
  77. #define raw_cpu_has_fpu (raw_current_cpu_data.options & MIPS_CPU_FPU)
  78. #else
  79. #define raw_cpu_has_fpu cpu_has_fpu
  80. #endif
  81. #ifndef cpu_has_32fpr
  82. #define cpu_has_32fpr (cpu_data[0].options & MIPS_CPU_32FPR)
  83. #endif
  84. #ifndef cpu_has_counter
  85. #define cpu_has_counter (cpu_data[0].options & MIPS_CPU_COUNTER)
  86. #endif
  87. #ifndef cpu_has_watch
  88. #define cpu_has_watch (cpu_data[0].options & MIPS_CPU_WATCH)
  89. #endif
  90. #ifndef cpu_has_divec
  91. #define cpu_has_divec (cpu_data[0].options & MIPS_CPU_DIVEC)
  92. #endif
  93. #ifndef cpu_has_vce
  94. #define cpu_has_vce (cpu_data[0].options & MIPS_CPU_VCE)
  95. #endif
  96. #ifndef cpu_has_cache_cdex_p
  97. #define cpu_has_cache_cdex_p (cpu_data[0].options & MIPS_CPU_CACHE_CDEX_P)
  98. #endif
  99. #ifndef cpu_has_cache_cdex_s
  100. #define cpu_has_cache_cdex_s (cpu_data[0].options & MIPS_CPU_CACHE_CDEX_S)
  101. #endif
  102. #ifndef cpu_has_prefetch
  103. #define cpu_has_prefetch (cpu_data[0].options & MIPS_CPU_PREFETCH)
  104. #endif
  105. #ifndef cpu_has_mcheck
  106. #define cpu_has_mcheck (cpu_data[0].options & MIPS_CPU_MCHECK)
  107. #endif
  108. #ifndef cpu_has_ejtag
  109. #define cpu_has_ejtag (cpu_data[0].options & MIPS_CPU_EJTAG)
  110. #endif
  111. #ifndef cpu_has_llsc
  112. #define cpu_has_llsc (cpu_data[0].options & MIPS_CPU_LLSC)
  113. #endif
  114. #ifndef cpu_has_bp_ghist
  115. #define cpu_has_bp_ghist (cpu_data[0].options & MIPS_CPU_BP_GHIST)
  116. #endif
  117. #ifndef kernel_uses_llsc
  118. #define kernel_uses_llsc cpu_has_llsc
  119. #endif
  120. #ifndef cpu_has_mips16
  121. #define cpu_has_mips16 (cpu_data[0].ases & MIPS_ASE_MIPS16)
  122. #endif
  123. #ifndef cpu_has_mdmx
  124. #define cpu_has_mdmx (cpu_data[0].ases & MIPS_ASE_MDMX)
  125. #endif
  126. #ifndef cpu_has_mips3d
  127. #define cpu_has_mips3d (cpu_data[0].ases & MIPS_ASE_MIPS3D)
  128. #endif
  129. #ifndef cpu_has_smartmips
  130. #define cpu_has_smartmips (cpu_data[0].ases & MIPS_ASE_SMARTMIPS)
  131. #endif
  132. #ifndef cpu_has_rixi
  133. #define cpu_has_rixi (cpu_data[0].options & MIPS_CPU_RIXI)
  134. #endif
  135. #ifndef cpu_has_mmips
  136. # ifdef CONFIG_SYS_SUPPORTS_MICROMIPS
  137. # define cpu_has_mmips (cpu_data[0].options & MIPS_CPU_MICROMIPS)
  138. # else
  139. # define cpu_has_mmips 0
  140. # endif
  141. #endif
  142. #ifndef cpu_has_lpa
  143. #define cpu_has_lpa (cpu_data[0].options & MIPS_CPU_LPA)
  144. #endif
  145. #ifndef cpu_has_mvh
  146. #define cpu_has_mvh (cpu_data[0].options & MIPS_CPU_MVH)
  147. #endif
  148. #ifndef cpu_has_xpa
  149. #define cpu_has_xpa (cpu_has_lpa && cpu_has_mvh)
  150. #endif
  151. #ifndef cpu_has_vtag_icache
  152. #define cpu_has_vtag_icache (cpu_data[0].icache.flags & MIPS_CACHE_VTAG)
  153. #endif
  154. #ifndef cpu_has_dc_aliases
  155. #define cpu_has_dc_aliases (cpu_data[0].dcache.flags & MIPS_CACHE_ALIASES)
  156. #endif
  157. #ifndef cpu_has_ic_fills_f_dc
  158. #define cpu_has_ic_fills_f_dc (cpu_data[0].icache.flags & MIPS_CACHE_IC_F_DC)
  159. #endif
  160. #ifndef cpu_has_pindexed_dcache
  161. #define cpu_has_pindexed_dcache (cpu_data[0].dcache.flags & MIPS_CACHE_PINDEX)
  162. #endif
  163. #ifndef cpu_has_local_ebase
  164. #define cpu_has_local_ebase 1
  165. #endif
  166. /*
  167. * I-Cache snoops remote store. This only matters on SMP. Some multiprocessors
  168. * such as the R10000 have I-Caches that snoop local stores; the embedded ones
  169. * don't. For maintaining I-cache coherency this means we need to flush the
  170. * D-cache all the way back to whever the I-cache does refills from, so the
  171. * I-cache has a chance to see the new data at all. Then we have to flush the
  172. * I-cache also.
  173. * Note we may have been rescheduled and may no longer be running on the CPU
  174. * that did the store so we can't optimize this into only doing the flush on
  175. * the local CPU.
  176. */
  177. #ifndef cpu_icache_snoops_remote_store
  178. #ifdef CONFIG_SMP
  179. #define cpu_icache_snoops_remote_store (cpu_data[0].icache.flags & MIPS_IC_SNOOPS_REMOTE)
  180. #else
  181. #define cpu_icache_snoops_remote_store 1
  182. #endif
  183. #endif
  184. #ifndef cpu_has_mips_1
  185. # define cpu_has_mips_1 (!cpu_has_mips_r6)
  186. #endif
  187. #ifndef cpu_has_mips_2
  188. # define cpu_has_mips_2 (cpu_data[0].isa_level & MIPS_CPU_ISA_II)
  189. #endif
  190. #ifndef cpu_has_mips_3
  191. # define cpu_has_mips_3 (cpu_data[0].isa_level & MIPS_CPU_ISA_III)
  192. #endif
  193. #ifndef cpu_has_mips_4
  194. # define cpu_has_mips_4 (cpu_data[0].isa_level & MIPS_CPU_ISA_IV)
  195. #endif
  196. #ifndef cpu_has_mips_5
  197. # define cpu_has_mips_5 (cpu_data[0].isa_level & MIPS_CPU_ISA_V)
  198. #endif
  199. #ifndef cpu_has_mips32r1
  200. # define cpu_has_mips32r1 (cpu_data[0].isa_level & MIPS_CPU_ISA_M32R1)
  201. #endif
  202. #ifndef cpu_has_mips32r2
  203. # define cpu_has_mips32r2 (cpu_data[0].isa_level & MIPS_CPU_ISA_M32R2)
  204. #endif
  205. #ifndef cpu_has_mips32r6
  206. # define cpu_has_mips32r6 (cpu_data[0].isa_level & MIPS_CPU_ISA_M32R6)
  207. #endif
  208. #ifndef cpu_has_mips64r1
  209. # define cpu_has_mips64r1 (cpu_data[0].isa_level & MIPS_CPU_ISA_M64R1)
  210. #endif
  211. #ifndef cpu_has_mips64r2
  212. # define cpu_has_mips64r2 (cpu_data[0].isa_level & MIPS_CPU_ISA_M64R2)
  213. #endif
  214. #ifndef cpu_has_mips64r6
  215. # define cpu_has_mips64r6 (cpu_data[0].isa_level & MIPS_CPU_ISA_M64R6)
  216. #endif
  217. /*
  218. * Shortcuts ...
  219. */
  220. #define cpu_has_mips_2_3_4_5 (cpu_has_mips_2 | cpu_has_mips_3_4_5)
  221. #define cpu_has_mips_3_4_5 (cpu_has_mips_3 | cpu_has_mips_4_5)
  222. #define cpu_has_mips_4_5 (cpu_has_mips_4 | cpu_has_mips_5)
  223. #define cpu_has_mips_2_3_4_5_r (cpu_has_mips_2 | cpu_has_mips_3_4_5_r)
  224. #define cpu_has_mips_3_4_5_r (cpu_has_mips_3 | cpu_has_mips_4_5_r)
  225. #define cpu_has_mips_4_5_r (cpu_has_mips_4 | cpu_has_mips_5_r)
  226. #define cpu_has_mips_5_r (cpu_has_mips_5 | cpu_has_mips_r)
  227. #define cpu_has_mips_3_4_5_64_r2_r6 \
  228. (cpu_has_mips_3 | cpu_has_mips_4_5_64_r2_r6)
  229. #define cpu_has_mips_4_5_64_r2_r6 \
  230. (cpu_has_mips_4_5 | cpu_has_mips64r1 | \
  231. cpu_has_mips_r2 | cpu_has_mips_r6)
  232. #define cpu_has_mips32 (cpu_has_mips32r1 | cpu_has_mips32r2 | cpu_has_mips32r6)
  233. #define cpu_has_mips64 (cpu_has_mips64r1 | cpu_has_mips64r2 | cpu_has_mips64r6)
  234. #define cpu_has_mips_r1 (cpu_has_mips32r1 | cpu_has_mips64r1)
  235. #define cpu_has_mips_r2 (cpu_has_mips32r2 | cpu_has_mips64r2)
  236. #define cpu_has_mips_r6 (cpu_has_mips32r6 | cpu_has_mips64r6)
  237. #define cpu_has_mips_r (cpu_has_mips32r1 | cpu_has_mips32r2 | \
  238. cpu_has_mips32r6 | cpu_has_mips64r1 | \
  239. cpu_has_mips64r2 | cpu_has_mips64r6)
  240. /* MIPSR2 and MIPSR6 have a lot of similarities */
  241. #define cpu_has_mips_r2_r6 (cpu_has_mips_r2 | cpu_has_mips_r6)
  242. /*
  243. * cpu_has_mips_r2_exec_hazard - return if IHB is required on current processor
  244. *
  245. * Returns non-zero value if the current processor implementation requires
  246. * an IHB instruction to deal with an instruction hazard as per MIPS R2
  247. * architecture specification, zero otherwise.
  248. */
  249. #ifndef cpu_has_mips_r2_exec_hazard
  250. #define cpu_has_mips_r2_exec_hazard \
  251. ({ \
  252. int __res; \
  253. \
  254. switch (current_cpu_type()) { \
  255. case CPU_M14KC: \
  256. case CPU_74K: \
  257. case CPU_1074K: \
  258. case CPU_PROAPTIV: \
  259. case CPU_P5600: \
  260. case CPU_M5150: \
  261. case CPU_QEMU_GENERIC: \
  262. case CPU_CAVIUM_OCTEON: \
  263. case CPU_CAVIUM_OCTEON_PLUS: \
  264. case CPU_CAVIUM_OCTEON2: \
  265. case CPU_CAVIUM_OCTEON3: \
  266. __res = 0; \
  267. break; \
  268. \
  269. default: \
  270. __res = 1; \
  271. } \
  272. \
  273. __res; \
  274. })
  275. #endif
  276. /*
  277. * MIPS32, MIPS64, VR5500, IDT32332, IDT32334 and maybe a few other
  278. * pre-MIPS32/MIPS64 processors have CLO, CLZ. The IDT RC64574 is 64-bit and
  279. * has CLO and CLZ but not DCLO nor DCLZ. For 64-bit kernels
  280. * cpu_has_clo_clz also indicates the availability of DCLO and DCLZ.
  281. */
  282. #ifndef cpu_has_clo_clz
  283. #define cpu_has_clo_clz cpu_has_mips_r
  284. #endif
  285. /*
  286. * MIPS32 R2, MIPS64 R2, Loongson 3A and Octeon have WSBH.
  287. * MIPS64 R2, Loongson 3A and Octeon have WSBH, DSBH and DSHD.
  288. * This indicates the availability of WSBH and in case of 64 bit CPUs also
  289. * DSBH and DSHD.
  290. */
  291. #ifndef cpu_has_wsbh
  292. #define cpu_has_wsbh cpu_has_mips_r2
  293. #endif
  294. #ifndef cpu_has_dsp
  295. #define cpu_has_dsp (cpu_data[0].ases & MIPS_ASE_DSP)
  296. #endif
  297. #ifndef cpu_has_dsp2
  298. #define cpu_has_dsp2 (cpu_data[0].ases & MIPS_ASE_DSP2P)
  299. #endif
  300. #ifndef cpu_has_dsp3
  301. #define cpu_has_dsp3 (cpu_data[0].ases & MIPS_ASE_DSP3)
  302. #endif
  303. #ifndef cpu_has_mipsmt
  304. #define cpu_has_mipsmt (cpu_data[0].ases & MIPS_ASE_MIPSMT)
  305. #endif
  306. #ifndef cpu_has_vp
  307. #define cpu_has_vp (cpu_data[0].options & MIPS_CPU_VP)
  308. #endif
  309. #ifndef cpu_has_userlocal
  310. #define cpu_has_userlocal (cpu_data[0].options & MIPS_CPU_ULRI)
  311. #endif
  312. #ifdef CONFIG_32BIT
  313. # ifndef cpu_has_nofpuex
  314. # define cpu_has_nofpuex (cpu_data[0].options & MIPS_CPU_NOFPUEX)
  315. # endif
  316. # ifndef cpu_has_64bits
  317. # define cpu_has_64bits (cpu_data[0].isa_level & MIPS_CPU_ISA_64BIT)
  318. # endif
  319. # ifndef cpu_has_64bit_zero_reg
  320. # define cpu_has_64bit_zero_reg (cpu_data[0].isa_level & MIPS_CPU_ISA_64BIT)
  321. # endif
  322. # ifndef cpu_has_64bit_gp_regs
  323. # define cpu_has_64bit_gp_regs 0
  324. # endif
  325. # ifndef cpu_has_64bit_addresses
  326. # define cpu_has_64bit_addresses 0
  327. # endif
  328. # ifndef cpu_vmbits
  329. # define cpu_vmbits 31
  330. # endif
  331. #endif
  332. #ifdef CONFIG_64BIT
  333. # ifndef cpu_has_nofpuex
  334. # define cpu_has_nofpuex 0
  335. # endif
  336. # ifndef cpu_has_64bits
  337. # define cpu_has_64bits 1
  338. # endif
  339. # ifndef cpu_has_64bit_zero_reg
  340. # define cpu_has_64bit_zero_reg 1
  341. # endif
  342. # ifndef cpu_has_64bit_gp_regs
  343. # define cpu_has_64bit_gp_regs 1
  344. # endif
  345. # ifndef cpu_has_64bit_addresses
  346. # define cpu_has_64bit_addresses 1
  347. # endif
  348. # ifndef cpu_vmbits
  349. # define cpu_vmbits cpu_data[0].vmbits
  350. # define __NEED_VMBITS_PROBE
  351. # endif
  352. #endif
  353. #if defined(CONFIG_CPU_MIPSR2_IRQ_VI) && !defined(cpu_has_vint)
  354. # define cpu_has_vint (cpu_data[0].options & MIPS_CPU_VINT)
  355. #elif !defined(cpu_has_vint)
  356. # define cpu_has_vint 0
  357. #endif
  358. #if defined(CONFIG_CPU_MIPSR2_IRQ_EI) && !defined(cpu_has_veic)
  359. # define cpu_has_veic (cpu_data[0].options & MIPS_CPU_VEIC)
  360. #elif !defined(cpu_has_veic)
  361. # define cpu_has_veic 0
  362. #endif
  363. #ifndef cpu_has_inclusive_pcaches
  364. #define cpu_has_inclusive_pcaches (cpu_data[0].options & MIPS_CPU_INCLUSIVE_CACHES)
  365. #endif
  366. #ifndef cpu_dcache_line_size
  367. #define cpu_dcache_line_size() cpu_data[0].dcache.linesz
  368. #endif
  369. #ifndef cpu_icache_line_size
  370. #define cpu_icache_line_size() cpu_data[0].icache.linesz
  371. #endif
  372. #ifndef cpu_scache_line_size
  373. #define cpu_scache_line_size() cpu_data[0].scache.linesz
  374. #endif
  375. #ifndef cpu_hwrena_impl_bits
  376. #define cpu_hwrena_impl_bits 0
  377. #endif
  378. #ifndef cpu_has_perf_cntr_intr_bit
  379. #define cpu_has_perf_cntr_intr_bit (cpu_data[0].options & MIPS_CPU_PCI)
  380. #endif
  381. #ifndef cpu_has_vz
  382. #define cpu_has_vz (cpu_data[0].ases & MIPS_ASE_VZ)
  383. #endif
  384. #if defined(CONFIG_CPU_HAS_MSA) && !defined(cpu_has_msa)
  385. # define cpu_has_msa (cpu_data[0].ases & MIPS_ASE_MSA)
  386. #elif !defined(cpu_has_msa)
  387. # define cpu_has_msa 0
  388. #endif
  389. #ifndef cpu_has_fre
  390. # define cpu_has_fre (cpu_data[0].options & MIPS_CPU_FRE)
  391. #endif
  392. #ifndef cpu_has_cdmm
  393. # define cpu_has_cdmm (cpu_data[0].options & MIPS_CPU_CDMM)
  394. #endif
  395. #ifndef cpu_has_small_pages
  396. # define cpu_has_small_pages (cpu_data[0].options & MIPS_CPU_SP)
  397. #endif
  398. #ifndef cpu_has_nan_legacy
  399. #define cpu_has_nan_legacy (cpu_data[0].options & MIPS_CPU_NAN_LEGACY)
  400. #endif
  401. #ifndef cpu_has_nan_2008
  402. #define cpu_has_nan_2008 (cpu_data[0].options & MIPS_CPU_NAN_2008)
  403. #endif
  404. #ifndef cpu_has_ebase_wg
  405. # define cpu_has_ebase_wg (cpu_data[0].options & MIPS_CPU_EBASE_WG)
  406. #endif
  407. #endif /* __ASM_CPU_FEATURES_H */