18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * cpu.h: Values of the PRID register used to match up 48c2ecf20Sopenharmony_ci * various LoongArch cpu types. 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Copyright (C) 2020 Loongson Technology Corporation Limited 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci#ifndef _ASM_CPU_H 98c2ecf20Sopenharmony_ci#define _ASM_CPU_H 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci/* 128c2ecf20Sopenharmony_ci * As described in LoongArch specs from Loongson Technology, the PRID register 138c2ecf20Sopenharmony_ci * (CPUCFG.00) has the following layout: 148c2ecf20Sopenharmony_ci * 158c2ecf20Sopenharmony_ci * +---------------+----------------+------------+--------------------+ 168c2ecf20Sopenharmony_ci * | Reserved | Company ID | Series ID | Product ID | 178c2ecf20Sopenharmony_ci * +---------------+----------------+------------+--------------------+ 188c2ecf20Sopenharmony_ci * 31 24 23 16 15 12 11 0 198c2ecf20Sopenharmony_ci */ 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci/* 228c2ecf20Sopenharmony_ci * Assigned Company values for bits 23:16 of the PRID register. 238c2ecf20Sopenharmony_ci */ 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci#define PRID_COMP_MASK 0xff0000 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci#define PRID_COMP_LOONGSON 0x140000 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci/* 308c2ecf20Sopenharmony_ci * Assigned Series ID values for bits 15:12 of the PRID register. In order 318c2ecf20Sopenharmony_ci * to detect a certain CPU type exactly eventually additional registers may 328c2ecf20Sopenharmony_ci * need to be examined. 338c2ecf20Sopenharmony_ci */ 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci#define PRID_SERIES_MASK 0xf000 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci#define PRID_SERIES_LA132 0x8000 /* Loongson 32bit */ 388c2ecf20Sopenharmony_ci#define PRID_SERIES_LA264 0xa000 /* Loongson 64bit, 2-issue */ 398c2ecf20Sopenharmony_ci#define PRID_SERIES_LA364 0xb000 /* Loongson 64bit, 3-issue */ 408c2ecf20Sopenharmony_ci#define PRID_SERIES_LA464 0xc000 /* Loongson 64bit, 4-issue */ 418c2ecf20Sopenharmony_ci#define PRID_SERIES_LA664 0xd000 /* Loongson 64bit, 6-issue */ 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci/* 448c2ecf20Sopenharmony_ci * Particular Product ID values for bits 11:0 of the PRID register. 458c2ecf20Sopenharmony_ci */ 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci#define PRID_PRODUCT_MASK 0x0fff 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci#if !defined(__ASSEMBLY__) 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_cienum cpu_type_enum { 528c2ecf20Sopenharmony_ci CPU_UNKNOWN, 538c2ecf20Sopenharmony_ci CPU_LOONGSON32, 548c2ecf20Sopenharmony_ci CPU_LOONGSON64, 558c2ecf20Sopenharmony_ci CPU_LAST 568c2ecf20Sopenharmony_ci}; 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci#endif /* !__ASSEMBLY */ 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci/* 618c2ecf20Sopenharmony_ci * ISA Level encodings 628c2ecf20Sopenharmony_ci * 638c2ecf20Sopenharmony_ci */ 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci#define LOONGARCH_CPU_ISA_LA32R 0x00000001 668c2ecf20Sopenharmony_ci#define LOONGARCH_CPU_ISA_LA32S 0x00000002 678c2ecf20Sopenharmony_ci#define LOONGARCH_CPU_ISA_LA64 0x00000004 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci#define LOONGARCH_CPU_ISA_32BIT (LOONGARCH_CPU_ISA_LA32R | LOONGARCH_CPU_ISA_LA32S) 708c2ecf20Sopenharmony_ci#define LOONGARCH_CPU_ISA_64BIT LOONGARCH_CPU_ISA_LA64 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci/* 738c2ecf20Sopenharmony_ci * CPU Option encodings 748c2ecf20Sopenharmony_ci */ 758c2ecf20Sopenharmony_ci#define CPU_FEATURE_CPUCFG 0 /* CPU has CPUCFG */ 768c2ecf20Sopenharmony_ci#define CPU_FEATURE_LAM 1 /* CPU has Atomic instructions */ 778c2ecf20Sopenharmony_ci#define CPU_FEATURE_UAL 2 /* CPU supports unaligned access */ 788c2ecf20Sopenharmony_ci#define CPU_FEATURE_FPU 3 /* CPU has FPU */ 798c2ecf20Sopenharmony_ci#define CPU_FEATURE_LSX 4 /* CPU has LSX (128-bit SIMD) */ 808c2ecf20Sopenharmony_ci#define CPU_FEATURE_LASX 5 /* CPU has LASX (256-bit SIMD) */ 818c2ecf20Sopenharmony_ci#define CPU_FEATURE_CRC32 6 /* CPU has CRC32 instructions */ 828c2ecf20Sopenharmony_ci#define CPU_FEATURE_COMPLEX 7 /* CPU has Complex instructions */ 838c2ecf20Sopenharmony_ci#define CPU_FEATURE_CRYPTO 8 /* CPU has Crypto instructions */ 848c2ecf20Sopenharmony_ci#define CPU_FEATURE_LVZ 9 /* CPU has Virtualization extension */ 858c2ecf20Sopenharmony_ci#define CPU_FEATURE_LBT_X86 10 /* CPU has X86 Binary Translation */ 868c2ecf20Sopenharmony_ci#define CPU_FEATURE_LBT_ARM 11 /* CPU has ARM Binary Translation */ 878c2ecf20Sopenharmony_ci#define CPU_FEATURE_LBT_MIPS 12 /* CPU has MIPS Binary Translation */ 888c2ecf20Sopenharmony_ci#define CPU_FEATURE_TLB 13 /* CPU has TLB */ 898c2ecf20Sopenharmony_ci#define CPU_FEATURE_CSR 14 /* CPU has CSR */ 908c2ecf20Sopenharmony_ci#define CPU_FEATURE_WATCH 15 /* CPU has watchpoint registers */ 918c2ecf20Sopenharmony_ci#define CPU_FEATURE_VINT 16 /* CPU has vectored interrupts */ 928c2ecf20Sopenharmony_ci#define CPU_FEATURE_CSRIPI 17 /* CPU has CSR-IPI */ 938c2ecf20Sopenharmony_ci#define CPU_FEATURE_EXTIOI 18 /* CPU has EXT-IOI */ 948c2ecf20Sopenharmony_ci#define CPU_FEATURE_PREFETCH 19 /* CPU has prefetch instructions */ 958c2ecf20Sopenharmony_ci#define CPU_FEATURE_PMP 20 /* CPU has perfermance counter */ 968c2ecf20Sopenharmony_ci#define CPU_FEATURE_SCALEFREQ 21 /* CPU supports cpufreq scaling */ 978c2ecf20Sopenharmony_ci#define CPU_FEATURE_FLATMODE 22 /* CPU has flat mode */ 988c2ecf20Sopenharmony_ci#define CPU_FEATURE_EIODECODE 23 /* CPU has EXTIOI interrupt pin decode mode */ 998c2ecf20Sopenharmony_ci#define CPU_FEATURE_GUESTID 24 /* CPU has GuestID feature */ 1008c2ecf20Sopenharmony_ci#define CPU_FEATURE_HYPERVISOR 25 /* CPU has hypervisor (running in VM) */ 1018c2ecf20Sopenharmony_ci#define CPU_FEATURE_PTW 26 /* CPU has hardware page table walker */ 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci#define LOONGARCH_CPU_CPUCFG BIT_ULL(CPU_FEATURE_CPUCFG) 1048c2ecf20Sopenharmony_ci#define LOONGARCH_CPU_LAM BIT_ULL(CPU_FEATURE_LAM) 1058c2ecf20Sopenharmony_ci#define LOONGARCH_CPU_UAL BIT_ULL(CPU_FEATURE_UAL) 1068c2ecf20Sopenharmony_ci#define LOONGARCH_CPU_FPU BIT_ULL(CPU_FEATURE_FPU) 1078c2ecf20Sopenharmony_ci#define LOONGARCH_CPU_LSX BIT_ULL(CPU_FEATURE_LSX) 1088c2ecf20Sopenharmony_ci#define LOONGARCH_CPU_LASX BIT_ULL(CPU_FEATURE_LASX) 1098c2ecf20Sopenharmony_ci#define LOONGARCH_CPU_CRC32 BIT_ULL(CPU_FEATURE_CRC32) 1108c2ecf20Sopenharmony_ci#define LOONGARCH_CPU_COMPLEX BIT_ULL(CPU_FEATURE_COMPLEX) 1118c2ecf20Sopenharmony_ci#define LOONGARCH_CPU_CRYPTO BIT_ULL(CPU_FEATURE_CRYPTO) 1128c2ecf20Sopenharmony_ci#define LOONGARCH_CPU_LVZ BIT_ULL(CPU_FEATURE_LVZ) 1138c2ecf20Sopenharmony_ci#define LOONGARCH_CPU_LBT_X86 BIT_ULL(CPU_FEATURE_LBT_X86) 1148c2ecf20Sopenharmony_ci#define LOONGARCH_CPU_LBT_ARM BIT_ULL(CPU_FEATURE_LBT_ARM) 1158c2ecf20Sopenharmony_ci#define LOONGARCH_CPU_LBT_MIPS BIT_ULL(CPU_FEATURE_LBT_MIPS) 1168c2ecf20Sopenharmony_ci#define LOONGARCH_CPU_TLB BIT_ULL(CPU_FEATURE_TLB) 1178c2ecf20Sopenharmony_ci#define LOONGARCH_CPU_CSR BIT_ULL(CPU_FEATURE_CSR) 1188c2ecf20Sopenharmony_ci#define LOONGARCH_CPU_WATCH BIT_ULL(CPU_FEATURE_WATCH) 1198c2ecf20Sopenharmony_ci#define LOONGARCH_CPU_VINT BIT_ULL(CPU_FEATURE_VINT) 1208c2ecf20Sopenharmony_ci#define LOONGARCH_CPU_CSRIPI BIT_ULL(CPU_FEATURE_CSRIPI) 1218c2ecf20Sopenharmony_ci#define LOONGARCH_CPU_EXTIOI BIT_ULL(CPU_FEATURE_EXTIOI) 1228c2ecf20Sopenharmony_ci#define LOONGARCH_CPU_PREFETCH BIT_ULL(CPU_FEATURE_PREFETCH) 1238c2ecf20Sopenharmony_ci#define LOONGARCH_CPU_PMP BIT_ULL(CPU_FEATURE_PMP) 1248c2ecf20Sopenharmony_ci#define LOONGARCH_CPU_SCALEFREQ BIT_ULL(CPU_FEATURE_SCALEFREQ) 1258c2ecf20Sopenharmony_ci#define LOONGARCH_CPU_FLATMODE BIT_ULL(CPU_FEATURE_FLATMODE) 1268c2ecf20Sopenharmony_ci#define LOONGARCH_CPU_EIODECODE BIT_ULL(CPU_FEATURE_EIODECODE) 1278c2ecf20Sopenharmony_ci#define LOONGARCH_CPU_GUESTID BIT_ULL(CPU_FEATURE_GUESTID) 1288c2ecf20Sopenharmony_ci#define LOONGARCH_CPU_HYPERVISOR BIT_ULL(CPU_FEATURE_HYPERVISOR) 1298c2ecf20Sopenharmony_ci#define LOONGARCH_CPU_PTW BIT_ULL(CPU_FEATURE_PTW) 1308c2ecf20Sopenharmony_ci#endif /* _ASM_CPU_H */ 131