1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Copyright (C) 2020 Loongson Technology Corporation Limited 4 */ 5 #ifndef __ASM_CPU_FEATURES_H 6 #define __ASM_CPU_FEATURES_H 7 8 #include <asm/cpu.h> 9 #include <asm/cpu-info.h> 10 11 #define cpu_opt(opt) (cpu_data[0].options & (opt)) 12 #define cpu_has(feat) (cpu_data[0].options & BIT_ULL(feat)) 13 14 #define cpu_has_loongarch (cpu_has_loongarch32 | cpu_has_loongarch64) 15 #define cpu_has_loongarch32 (cpu_data[0].isa_level & LOONGARCH_CPU_ISA_32BIT) 16 #define cpu_has_loongarch64 (cpu_data[0].isa_level & LOONGARCH_CPU_ISA_64BIT) 17 18 #ifdef CONFIG_32BIT 19 # define cpu_has_64bits (cpu_data[0].isa_level & LOONGARCH_CPU_ISA_64BIT) 20 # define cpu_vabits 31 21 # define cpu_pabits 31 22 #endif 23 24 #ifdef CONFIG_64BIT 25 # define cpu_has_64bits 1 26 # define cpu_vabits cpu_data[0].vabits 27 # define cpu_pabits cpu_data[0].pabits 28 # define __NEED_ADDRBITS_PROBE 29 #endif 30 31 /* 32 * SMP assumption: Options of CPU 0 are a superset of all processors. 33 * This is true for all known LoongArch systems. 34 */ 35 #define cpu_has_cpucfg cpu_opt(LOONGARCH_CPU_CPUCFG) 36 #define cpu_has_lam cpu_opt(LOONGARCH_CPU_LAM) 37 #define cpu_has_ual cpu_opt(LOONGARCH_CPU_UAL) 38 #define cpu_has_fpu cpu_opt(LOONGARCH_CPU_FPU) 39 #define cpu_has_lsx cpu_opt(LOONGARCH_CPU_LSX) 40 #define cpu_has_lasx cpu_opt(LOONGARCH_CPU_LASX) 41 #define cpu_has_crc32 cpu_opt(LOONGARCH_CPU_CRC32) 42 #define cpu_has_complex cpu_opt(LOONGARCH_CPU_COMPLEX) 43 #define cpu_has_crypto cpu_opt(LOONGARCH_CPU_CRYPTO) 44 #define cpu_has_lvz cpu_opt(LOONGARCH_CPU_LVZ) 45 #define cpu_has_lbt_x86 cpu_opt(LOONGARCH_CPU_LBT_X86) 46 #define cpu_has_lbt_arm cpu_opt(LOONGARCH_CPU_LBT_ARM) 47 #define cpu_has_lbt_mips cpu_opt(LOONGARCH_CPU_LBT_MIPS) 48 #define cpu_has_lbt (cpu_has_lbt_x86|cpu_has_lbt_arm|cpu_has_lbt_mips) 49 #define cpu_has_csr cpu_opt(LOONGARCH_CPU_CSR) 50 #define cpu_has_tlb cpu_opt(LOONGARCH_CPU_TLB) 51 #define cpu_has_watch cpu_opt(LOONGARCH_CPU_WATCH) 52 #define cpu_has_vint cpu_opt(LOONGARCH_CPU_VINT) 53 #define cpu_has_csripi cpu_opt(LOONGARCH_CPU_CSRIPI) 54 #define cpu_has_extioi cpu_opt(LOONGARCH_CPU_EXTIOI) 55 #define cpu_has_prefetch cpu_opt(LOONGARCH_CPU_PREFETCH) 56 #define cpu_has_pmp cpu_opt(LOONGARCH_CPU_PMP) 57 #define cpu_has_perf cpu_opt(LOONGARCH_CPU_PMP) 58 #define cpu_has_scalefreq cpu_opt(LOONGARCH_CPU_SCALEFREQ) 59 #define cpu_has_flatmode cpu_opt(LOONGARCH_CPU_FLATMODE) 60 #define cpu_has_eiodecode cpu_opt(LOONGARCH_CPU_EIODECODE) 61 #define cpu_has_guestid cpu_opt(LOONGARCH_CPU_GUESTID) 62 #define cpu_has_hypervisor cpu_opt(LOONGARCH_CPU_HYPERVISOR) 63 #define cpu_has_ptw cpu_opt(LOONGARCH_CPU_PTW) 64 65 #define cpu_has_matc_guest (cpu_data[0].guest_cfg & (1 << 0)) 66 #define cpu_has_matc_root (cpu_data[0].guest_cfg & (1 << 1)) 67 #define cpu_has_matc_nest (cpu_data[0].guest_cfg & (1 << 2)) 68 #define cpu_has_sitp (cpu_data[0].guest_cfg & (1 << 6)) 69 #define cpu_has_titp (cpu_data[0].guest_cfg & (1 << 8)) 70 #define cpu_has_toep (cpu_data[0].guest_cfg & (1 << 10)) 71 #define cpu_has_topp (cpu_data[0].guest_cfg & (1 << 12)) 72 #define cpu_has_torup (cpu_data[0].guest_cfg & (1 << 14)) 73 #define cpu_has_gcip_all (cpu_data[0].guest_cfg & (1 << 16)) 74 #define cpu_has_gcip_hit (cpu_data[0].guest_cfg & (1 << 17)) 75 #define cpu_has_gcip_secure (cpu_data[0].guest_cfg & (1 << 18)) 76 77 /* 78 * Guest capabilities 79 */ 80 #define cpu_guest_has_conf1 (cpu_data[0].guest.conf & (1 << 1)) 81 #define cpu_guest_has_conf2 (cpu_data[0].guest.conf & (1 << 2)) 82 #define cpu_guest_has_conf3 (cpu_data[0].guest.conf & (1 << 3)) 83 #define cpu_guest_has_fpu (cpu_data[0].guest.options & LOONGARCH_CPU_FPU) 84 #define cpu_guest_has_perf (cpu_data[0].guest.options & LOONGARCH_CPU_PMP) 85 #define cpu_guest_has_watch (cpu_data[0].guest.options & LOONGARCH_CPU_WATCH) 86 #define cpu_guest_has_lsx (cpu_data[0].guest.ases & LOONGARCH_ASE_LSX) 87 #define cpu_guest_has_kscr(n) (cpu_data[0].guest.kscratch_mask & (1u << (n))) 88 89 /* 90 * Guest dynamic capabilities 91 */ 92 #define cpu_guest_has_dyn_fpu (cpu_data[0].guest.options_dyn & LOONGARCH_CPU_FPU) 93 #define cpu_guest_has_dyn_perf (cpu_data[0].guest.options_dyn & LOONGARCH_CPU_PMP) 94 #define cpu_guest_has_dyn_lsx (cpu_data[0].guest.ases_dyn & LOONGARCH_ASE_LSX) 95 96 #endif /* __ASM_CPU_FEATURES_H */ 97