2 * Read/Write Loongson Extension Registers
5 #ifndef _LOONGSON_REGS_H_
6 #define _LOONGSON_REGS_H_
8 #include <linux/types.h>
9 #include <linux/bits.h>
11 #include <asm/mipsregs.h>
14 static inline bool cpu_has_cfg(void)
16 return ((read_c0_prid() & PRID_IMP_MASK
) == PRID_IMP_LOONGSON_64G
);
19 static inline u32
read_cpucfg(u32 reg
)
24 "parse_r __res,%0\n\t"
27 ".word (0xc8080118 | (reg << 21) | (__res << 11))\n\t"
35 /* Bit Domains for CFG registers */
36 #define LOONGSON_CFG0 0x0
37 #define LOONGSON_CFG0_PRID GENMASK(31, 0)
39 #define LOONGSON_CFG1 0x1
40 #define LOONGSON_CFG1_FP BIT(0)
41 #define LOONGSON_CFG1_FPREV GENMASK(3, 1)
42 #define LOONGSON_CFG1_MMI BIT(4)
43 #define LOONGSON_CFG1_MSA1 BIT(5)
44 #define LOONGSON_CFG1_MSA2 BIT(6)
45 #define LOONGSON_CFG1_CGP BIT(7)
46 #define LOONGSON_CFG1_WRP BIT(8)
47 #define LOONGSON_CFG1_LSX1 BIT(9)
48 #define LOONGSON_CFG1_LSX2 BIT(10)
49 #define LOONGSON_CFG1_LASX BIT(11)
50 #define LOONGSON_CFG1_R6FXP BIT(12)
51 #define LOONGSON_CFG1_R6CRCP BIT(13)
52 #define LOONGSON_CFG1_R6FPP BIT(14)
53 #define LOONGSON_CFG1_CNT64 BIT(15)
54 #define LOONGSON_CFG1_LSLDR0 BIT(16)
55 #define LOONGSON_CFG1_LSPREF BIT(17)
56 #define LOONGSON_CFG1_LSPREFX BIT(18)
57 #define LOONGSON_CFG1_LSSYNCI BIT(19)
58 #define LOONGSON_CFG1_LSUCA BIT(20)
59 #define LOONGSON_CFG1_LLSYNC BIT(21)
60 #define LOONGSON_CFG1_TGTSYNC BIT(22)
61 #define LOONGSON_CFG1_LLEXC BIT(23)
62 #define LOONGSON_CFG1_SCRAND BIT(24)
63 #define LOONGSON_CFG1_MUALP BIT(25)
64 #define LOONGSON_CFG1_KMUALEN BIT(26)
65 #define LOONGSON_CFG1_ITLBT BIT(27)
66 #define LOONGSON_CFG1_LSUPERF BIT(28)
67 #define LOONGSON_CFG1_SFBP BIT(29)
68 #define LOONGSON_CFG1_CDMAP BIT(30)
70 #define LOONGSON_CFG1_FPREV_OFFSET 1
72 #define LOONGSON_CFG2 0x2
73 #define LOONGSON_CFG2_LEXT1 BIT(0)
74 #define LOONGSON_CFG2_LEXT2 BIT(1)
75 #define LOONGSON_CFG2_LEXT3 BIT(2)
76 #define LOONGSON_CFG2_LSPW BIT(3)
77 #define LOONGSON_CFG2_LBT1 BIT(4)
78 #define LOONGSON_CFG2_LBT2 BIT(5)
79 #define LOONGSON_CFG2_LBT3 BIT(6)
80 #define LOONGSON_CFG2_LBTMMU BIT(7)
81 #define LOONGSON_CFG2_LPMP BIT(8)
82 #define LOONGSON_CFG2_LPMREV GENMASK(11, 9)
83 #define LOONGSON_CFG2_LAMO BIT(12)
84 #define LOONGSON_CFG2_LPIXU BIT(13)
85 #define LOONGSON_CFG2_LPIXNU BIT(14)
86 #define LOONGSON_CFG2_LVZP BIT(15)
87 #define LOONGSON_CFG2_LVZREV GENMASK(18, 16)
88 #define LOONGSON_CFG2_LGFTP BIT(19)
89 #define LOONGSON_CFG2_LGFTPREV GENMASK(22, 20)
90 #define LOONGSON_CFG2_LLFTP BIT(23)
91 #define LOONGSON_CFG2_LLFTPREV GENMASK(26, 24)
92 #define LOONGSON_CFG2_LCSRP BIT(27)
93 #define LOONGSON_CFG2_LDISBLIKELY BIT(28)
95 #define LOONGSON_CFG2_LPMREV_OFFSET 9
96 #define LOONGSON_CFG2_LPM_REV1 (1 << LOONGSON_CFG2_LPMREV_OFFSET)
97 #define LOONGSON_CFG2_LPM_REV2 (2 << LOONGSON_CFG2_LPMREV_OFFSET)
98 #define LOONGSON_CFG2_LVZREV_OFFSET 16
99 #define LOONGSON_CFG2_LVZ_REV1 (1 << LOONGSON_CFG2_LVZREV_OFFSET)
100 #define LOONGSON_CFG2_LVZ_REV2 (2 << LOONGSON_CFG2_LVZREV_OFFSET)
102 #define LOONGSON_CFG3 0x3
103 #define LOONGSON_CFG3_LCAMP BIT(0)
104 #define LOONGSON_CFG3_LCAMREV GENMASK(3, 1)
105 #define LOONGSON_CFG3_LCAMNUM GENMASK(11, 4)
106 #define LOONGSON_CFG3_LCAMKW GENMASK(19, 12)
107 #define LOONGSON_CFG3_LCAMVW GENMASK(27, 20)
109 #define LOONGSON_CFG3_LCAMREV_OFFSET 1
110 #define LOONGSON_CFG3_LCAM_REV1 (1 << LOONGSON_CFG3_LCAMREV_OFFSET)
111 #define LOONGSON_CFG3_LCAM_REV2 (2 << LOONGSON_CFG3_LCAMREV_OFFSET)
112 #define LOONGSON_CFG3_LCAMNUM_OFFSET 4
113 #define LOONGSON_CFG3_LCAMNUM_REV1 (0x3f << LOONGSON_CFG3_LCAMNUM_OFFSET)
114 #define LOONGSON_CFG3_LCAMKW_OFFSET 12
115 #define LOONGSON_CFG3_LCAMKW_REV1 (0x27 << LOONGSON_CFG3_LCAMKW_OFFSET)
116 #define LOONGSON_CFG3_LCAMVW_OFFSET 20
117 #define LOONGSON_CFG3_LCAMVW_REV1 (0x3f << LOONGSON_CFG3_LCAMVW_OFFSET)
119 #define LOONGSON_CFG4 0x4
120 #define LOONGSON_CFG4_CCFREQ GENMASK(31, 0)
122 #define LOONGSON_CFG5 0x5
123 #define LOONGSON_CFG5_CFM GENMASK(15, 0)
124 #define LOONGSON_CFG5_CFD GENMASK(31, 16)
126 #define LOONGSON_CFG6 0x6
128 #define LOONGSON_CFG7 0x7
129 #define LOONGSON_CFG7_GCCAEQRP BIT(0)
130 #define LOONGSON_CFG7_UCAWINP BIT(1)
132 static inline bool cpu_has_csr(void)
135 return (read_cpucfg(LOONGSON_CFG2
) & LOONGSON_CFG2_LCSRP
);
140 static inline u32
csr_readl(u32 reg
)
145 __asm__
__volatile__(
146 "parse_r __res,%0\n\t"
149 ".word (0xc8000118 | (reg << 21) | (__res << 11))\n\t"
157 static inline u64
csr_readq(u32 reg
)
161 /* DRDCSR reg, val */
162 __asm__
__volatile__(
163 "parse_r __res,%0\n\t"
166 ".word (0xc8020118 | (reg << 21) | (__res << 11))\n\t"
174 static inline void csr_writel(u32 val
, u32 reg
)
177 __asm__
__volatile__(
181 ".word (0xc8010118 | (reg << 21) | (val << 11))\n\t"
188 static inline void csr_writeq(u64 val
, u32 reg
)
190 /* DWRCSR reg, val */
191 __asm__
__volatile__(
195 ".word (0xc8030118 | (reg << 21) | (val << 11))\n\t"
202 /* Public CSR Register can also be accessed with regular addresses */
203 #define CSR_PUBLIC_MMIO_BASE 0x1fe00000
205 #define MMIO_CSR(x) (void *)TO_UNCAC(CSR_PUBLIC_MMIO_BASE + x)
207 #define LOONGSON_CSR_FEATURES 0x8
208 #define LOONGSON_CSRF_TEMP BIT(0)
209 #define LOONGSON_CSRF_NODECNT BIT(1)
210 #define LOONGSON_CSRF_MSI BIT(2)
211 #define LOONGSON_CSRF_EXTIOI BIT(3)
212 #define LOONGSON_CSRF_IPI BIT(4)
213 #define LOONGSON_CSRF_FREQ BIT(5)
215 #define LOONGSON_CSR_VENDOR 0x10 /* Vendor name string, should be "Loongson" */
216 #define LOONGSON_CSR_CPUNAME 0x20 /* Processor name string */
217 #define LOONGSON_CSR_NODECNT 0x408
218 #define LOONGSON_CSR_CPUTEMP 0x428
220 /* PerCore CSR, only accessable by local cores */
221 #define LOONGSON_CSR_IPI_STATUS 0x1000
222 #define LOONGSON_CSR_IPI_EN 0x1004
223 #define LOONGSON_CSR_IPI_SET 0x1008
224 #define LOONGSON_CSR_IPI_CLEAR 0x100c
225 #define LOONGSON_CSR_IPI_SEND 0x1040
226 #define CSR_IPI_SEND_IP_SHIFT 0
227 #define CSR_IPI_SEND_CPU_SHIFT 16
228 #define CSR_IPI_SEND_BLOCK BIT(31)
230 #define LOONGSON_CSR_MAIL_BUF0 0x1020
231 #define LOONGSON_CSR_MAIL_SEND 0x1048
232 #define CSR_MAIL_SEND_BLOCK BIT_ULL(31)
233 #define CSR_MAIL_SEND_BOX_LOW(box) (box << 1)
234 #define CSR_MAIL_SEND_BOX_HIGH(box) ((box << 1) + 1)
235 #define CSR_MAIL_SEND_BOX_SHIFT 2
236 #define CSR_MAIL_SEND_CPU_SHIFT 16
237 #define CSR_MAIL_SEND_BUF_SHIFT 32
238 #define CSR_MAIL_SEND_H32_MASK 0xFFFFFFFF00000000ULL
240 static inline u64
drdtime(void)
245 __asm__
__volatile__(
249 ".word (0xc8090118 | (rID << 21) | (val << 11))\n\t"