0001
0002
0003
0004
0005 #ifndef _LOONGSON_REGS_H_
0006 #define _LOONGSON_REGS_H_
0007
0008 #include <linux/types.h>
0009 #include <linux/bits.h>
0010
0011 #include <asm/mipsregs.h>
0012 #include <asm/cpu.h>
0013
0014 static inline bool cpu_has_cfg(void)
0015 {
0016 return ((read_c0_prid() & PRID_IMP_MASK) == PRID_IMP_LOONGSON_64G);
0017 }
0018
0019 static inline u32 read_cpucfg(u32 reg)
0020 {
0021 u32 __res;
0022
0023 __asm__ __volatile__(
0024 _ASM_SET_PARSE_R
0025 "parse_r __res,%0\n\t"
0026 "parse_r reg,%1\n\t"
0027 _ASM_UNSET_PARSE_R
0028 ".insn \n\t"
0029 ".word (0xc8080118 | (reg << 21) | (__res << 11))\n\t"
0030 :"=r"(__res)
0031 :"r"(reg)
0032 :
0033 );
0034 return __res;
0035 }
0036
0037
0038 #define LOONGSON_CFG0 0x0
0039 #define LOONGSON_CFG0_PRID GENMASK(31, 0)
0040
0041 #define LOONGSON_CFG1 0x1
0042 #define LOONGSON_CFG1_FP BIT(0)
0043 #define LOONGSON_CFG1_FPREV GENMASK(3, 1)
0044 #define LOONGSON_CFG1_MMI BIT(4)
0045 #define LOONGSON_CFG1_MSA1 BIT(5)
0046 #define LOONGSON_CFG1_MSA2 BIT(6)
0047 #define LOONGSON_CFG1_CGP BIT(7)
0048 #define LOONGSON_CFG1_WRP BIT(8)
0049 #define LOONGSON_CFG1_LSX1 BIT(9)
0050 #define LOONGSON_CFG1_LSX2 BIT(10)
0051 #define LOONGSON_CFG1_LASX BIT(11)
0052 #define LOONGSON_CFG1_R6FXP BIT(12)
0053 #define LOONGSON_CFG1_R6CRCP BIT(13)
0054 #define LOONGSON_CFG1_R6FPP BIT(14)
0055 #define LOONGSON_CFG1_CNT64 BIT(15)
0056 #define LOONGSON_CFG1_LSLDR0 BIT(16)
0057 #define LOONGSON_CFG1_LSPREF BIT(17)
0058 #define LOONGSON_CFG1_LSPREFX BIT(18)
0059 #define LOONGSON_CFG1_LSSYNCI BIT(19)
0060 #define LOONGSON_CFG1_LSUCA BIT(20)
0061 #define LOONGSON_CFG1_LLSYNC BIT(21)
0062 #define LOONGSON_CFG1_TGTSYNC BIT(22)
0063 #define LOONGSON_CFG1_LLEXC BIT(23)
0064 #define LOONGSON_CFG1_SCRAND BIT(24)
0065 #define LOONGSON_CFG1_MUALP BIT(25)
0066 #define LOONGSON_CFG1_KMUALEN BIT(26)
0067 #define LOONGSON_CFG1_ITLBT BIT(27)
0068 #define LOONGSON_CFG1_LSUPERF BIT(28)
0069 #define LOONGSON_CFG1_SFBP BIT(29)
0070 #define LOONGSON_CFG1_CDMAP BIT(30)
0071
0072 #define LOONGSON_CFG1_FPREV_OFFSET 1
0073
0074 #define LOONGSON_CFG2 0x2
0075 #define LOONGSON_CFG2_LEXT1 BIT(0)
0076 #define LOONGSON_CFG2_LEXT2 BIT(1)
0077 #define LOONGSON_CFG2_LEXT3 BIT(2)
0078 #define LOONGSON_CFG2_LSPW BIT(3)
0079 #define LOONGSON_CFG2_LBT1 BIT(4)
0080 #define LOONGSON_CFG2_LBT2 BIT(5)
0081 #define LOONGSON_CFG2_LBT3 BIT(6)
0082 #define LOONGSON_CFG2_LBTMMU BIT(7)
0083 #define LOONGSON_CFG2_LPMP BIT(8)
0084 #define LOONGSON_CFG2_LPMREV GENMASK(11, 9)
0085 #define LOONGSON_CFG2_LAMO BIT(12)
0086 #define LOONGSON_CFG2_LPIXU BIT(13)
0087 #define LOONGSON_CFG2_LPIXNU BIT(14)
0088 #define LOONGSON_CFG2_LVZP BIT(15)
0089 #define LOONGSON_CFG2_LVZREV GENMASK(18, 16)
0090 #define LOONGSON_CFG2_LGFTP BIT(19)
0091 #define LOONGSON_CFG2_LGFTPREV GENMASK(22, 20)
0092 #define LOONGSON_CFG2_LLFTP BIT(23)
0093 #define LOONGSON_CFG2_LLFTPREV GENMASK(26, 24)
0094 #define LOONGSON_CFG2_LCSRP BIT(27)
0095 #define LOONGSON_CFG2_LDISBLIKELY BIT(28)
0096
0097 #define LOONGSON_CFG2_LPMREV_OFFSET 9
0098 #define LOONGSON_CFG2_LPM_REV1 (1 << LOONGSON_CFG2_LPMREV_OFFSET)
0099 #define LOONGSON_CFG2_LPM_REV2 (2 << LOONGSON_CFG2_LPMREV_OFFSET)
0100 #define LOONGSON_CFG2_LVZREV_OFFSET 16
0101 #define LOONGSON_CFG2_LVZ_REV1 (1 << LOONGSON_CFG2_LVZREV_OFFSET)
0102 #define LOONGSON_CFG2_LVZ_REV2 (2 << LOONGSON_CFG2_LVZREV_OFFSET)
0103
0104 #define LOONGSON_CFG3 0x3
0105 #define LOONGSON_CFG3_LCAMP BIT(0)
0106 #define LOONGSON_CFG3_LCAMREV GENMASK(3, 1)
0107 #define LOONGSON_CFG3_LCAMNUM GENMASK(11, 4)
0108 #define LOONGSON_CFG3_LCAMKW GENMASK(19, 12)
0109 #define LOONGSON_CFG3_LCAMVW GENMASK(27, 20)
0110
0111 #define LOONGSON_CFG3_LCAMREV_OFFSET 1
0112 #define LOONGSON_CFG3_LCAM_REV1 (1 << LOONGSON_CFG3_LCAMREV_OFFSET)
0113 #define LOONGSON_CFG3_LCAM_REV2 (2 << LOONGSON_CFG3_LCAMREV_OFFSET)
0114 #define LOONGSON_CFG3_LCAMNUM_OFFSET 4
0115 #define LOONGSON_CFG3_LCAMNUM_REV1 (0x3f << LOONGSON_CFG3_LCAMNUM_OFFSET)
0116 #define LOONGSON_CFG3_LCAMKW_OFFSET 12
0117 #define LOONGSON_CFG3_LCAMKW_REV1 (0x27 << LOONGSON_CFG3_LCAMKW_OFFSET)
0118 #define LOONGSON_CFG3_LCAMVW_OFFSET 20
0119 #define LOONGSON_CFG3_LCAMVW_REV1 (0x3f << LOONGSON_CFG3_LCAMVW_OFFSET)
0120
0121 #define LOONGSON_CFG4 0x4
0122 #define LOONGSON_CFG4_CCFREQ GENMASK(31, 0)
0123
0124 #define LOONGSON_CFG5 0x5
0125 #define LOONGSON_CFG5_CFM GENMASK(15, 0)
0126 #define LOONGSON_CFG5_CFD GENMASK(31, 16)
0127
0128 #define LOONGSON_CFG6 0x6
0129
0130 #define LOONGSON_CFG7 0x7
0131 #define LOONGSON_CFG7_GCCAEQRP BIT(0)
0132 #define LOONGSON_CFG7_UCAWINP BIT(1)
0133
0134 static inline bool cpu_has_csr(void)
0135 {
0136 if (cpu_has_cfg())
0137 return (read_cpucfg(LOONGSON_CFG2) & LOONGSON_CFG2_LCSRP);
0138
0139 return false;
0140 }
0141
0142 static inline u32 csr_readl(u32 reg)
0143 {
0144 u32 __res;
0145
0146
0147 __asm__ __volatile__(
0148 _ASM_SET_PARSE_R
0149 "parse_r __res,%0\n\t"
0150 "parse_r reg,%1\n\t"
0151 _ASM_UNSET_PARSE_R
0152 ".insn \n\t"
0153 ".word (0xc8000118 | (reg << 21) | (__res << 11))\n\t"
0154 :"=r"(__res)
0155 :"r"(reg)
0156 :
0157 );
0158 return __res;
0159 }
0160
0161 static inline u64 csr_readq(u32 reg)
0162 {
0163 u64 __res;
0164
0165
0166 __asm__ __volatile__(
0167 _ASM_SET_PARSE_R
0168 "parse_r __res,%0\n\t"
0169 "parse_r reg,%1\n\t"
0170 _ASM_UNSET_PARSE_R
0171 ".insn \n\t"
0172 ".word (0xc8020118 | (reg << 21) | (__res << 11))\n\t"
0173 :"=r"(__res)
0174 :"r"(reg)
0175 :
0176 );
0177 return __res;
0178 }
0179
0180 static inline void csr_writel(u32 val, u32 reg)
0181 {
0182
0183 __asm__ __volatile__(
0184 _ASM_SET_PARSE_R
0185 "parse_r reg,%0\n\t"
0186 "parse_r val,%1\n\t"
0187 _ASM_UNSET_PARSE_R
0188 ".insn \n\t"
0189 ".word (0xc8010118 | (reg << 21) | (val << 11))\n\t"
0190 :
0191 :"r"(reg),"r"(val)
0192 :
0193 );
0194 }
0195
0196 static inline void csr_writeq(u64 val, u32 reg)
0197 {
0198
0199 __asm__ __volatile__(
0200 _ASM_SET_PARSE_R
0201 "parse_r reg,%0\n\t"
0202 "parse_r val,%1\n\t"
0203 _ASM_UNSET_PARSE_R
0204 ".insn \n\t"
0205 ".word (0xc8030118 | (reg << 21) | (val << 11))\n\t"
0206 :
0207 :"r"(reg),"r"(val)
0208 :
0209 );
0210 }
0211
0212
0213 #define CSR_PUBLIC_MMIO_BASE 0x1fe00000
0214
0215 #define MMIO_CSR(x) (void *)TO_UNCAC(CSR_PUBLIC_MMIO_BASE + x)
0216
0217 #define LOONGSON_CSR_FEATURES 0x8
0218 #define LOONGSON_CSRF_TEMP BIT(0)
0219 #define LOONGSON_CSRF_NODECNT BIT(1)
0220 #define LOONGSON_CSRF_MSI BIT(2)
0221 #define LOONGSON_CSRF_EXTIOI BIT(3)
0222 #define LOONGSON_CSRF_IPI BIT(4)
0223 #define LOONGSON_CSRF_FREQ BIT(5)
0224
0225 #define LOONGSON_CSR_VENDOR 0x10
0226 #define LOONGSON_CSR_CPUNAME 0x20
0227 #define LOONGSON_CSR_NODECNT 0x408
0228 #define LOONGSON_CSR_CPUTEMP 0x428
0229
0230
0231 #define LOONGSON_CSR_IPI_STATUS 0x1000
0232 #define LOONGSON_CSR_IPI_EN 0x1004
0233 #define LOONGSON_CSR_IPI_SET 0x1008
0234 #define LOONGSON_CSR_IPI_CLEAR 0x100c
0235 #define LOONGSON_CSR_IPI_SEND 0x1040
0236 #define CSR_IPI_SEND_IP_SHIFT 0
0237 #define CSR_IPI_SEND_CPU_SHIFT 16
0238 #define CSR_IPI_SEND_BLOCK BIT(31)
0239
0240 #define LOONGSON_CSR_MAIL_BUF0 0x1020
0241 #define LOONGSON_CSR_MAIL_SEND 0x1048
0242 #define CSR_MAIL_SEND_BLOCK BIT_ULL(31)
0243 #define CSR_MAIL_SEND_BOX_LOW(box) (box << 1)
0244 #define CSR_MAIL_SEND_BOX_HIGH(box) ((box << 1) + 1)
0245 #define CSR_MAIL_SEND_BOX_SHIFT 2
0246 #define CSR_MAIL_SEND_CPU_SHIFT 16
0247 #define CSR_MAIL_SEND_BUF_SHIFT 32
0248 #define CSR_MAIL_SEND_H32_MASK 0xFFFFFFFF00000000ULL
0249
0250 static inline u64 drdtime(void)
0251 {
0252 int rID = 0;
0253 u64 val = 0;
0254
0255 __asm__ __volatile__(
0256 _ASM_SET_PARSE_R
0257 "parse_r rID,%0\n\t"
0258 "parse_r val,%1\n\t"
0259 _ASM_UNSET_PARSE_R
0260 ".insn \n\t"
0261 ".word (0xc8090118 | (rID << 21) | (val << 11))\n\t"
0262 :"=r"(rID),"=r"(val)
0263 :
0264 );
0265 return val;
0266 }
0267
0268 #endif