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_CFG2 0x2
71 #define LOONGSON_CFG2_LEXT1 BIT(0)
72 #define LOONGSON_CFG2_LEXT2 BIT(1)
73 #define LOONGSON_CFG2_LEXT3 BIT(2)
74 #define LOONGSON_CFG2_LSPW BIT(3)
75 #define LOONGSON_CFG2_LBT1 BIT(4)
76 #define LOONGSON_CFG2_LBT2 BIT(5)
77 #define LOONGSON_CFG2_LBT3 BIT(6)
78 #define LOONGSON_CFG2_LBTMMU BIT(7)
79 #define LOONGSON_CFG2_LPMP BIT(8)
80 #define LOONGSON_CFG2_LPMPREV GENMASK(11, 9)
81 #define LOONGSON_CFG2_LAMO BIT(12)
82 #define LOONGSON_CFG2_LPIXU BIT(13)
83 #define LOONGSON_CFG2_LPIXUN BIT(14)
84 #define LOONGSON_CFG2_LZVP BIT(15)
85 #define LOONGSON_CFG2_LZVREV GENMASK(18, 16)
86 #define LOONGSON_CFG2_LGFTP BIT(19)
87 #define LOONGSON_CFG2_LGFTPREV GENMASK(22, 20)
88 #define LOONGSON_CFG2_LLFTP BIT(23)
89 #define LOONGSON_CFG2_LLFTPREV GENMASK(26, 24)
90 #define LOONGSON_CFG2_LCSRP BIT(27)
91 #define LOONGSON_CFG2_LDISBLIKELY BIT(28)
93 #define LOONGSON_CFG3 0x3
94 #define LOONGSON_CFG3_LCAMP BIT(0)
95 #define LOONGSON_CFG3_LCAMREV GENMASK(3, 1)
96 #define LOONGSON_CFG3_LCAMNUM GENMASK(11, 4)
97 #define LOONGSON_CFG3_LCAMKW GENMASK(19, 12)
98 #define LOONGSON_CFG3_LCAMVW GENMASK(27, 20)
100 #define LOONGSON_CFG4 0x4
101 #define LOONGSON_CFG4_CCFREQ GENMASK(31, 0)
103 #define LOONGSON_CFG5 0x5
104 #define LOONGSON_CFG5_CFM GENMASK(15, 0)
105 #define LOONGSON_CFG5_CFD GENMASK(31, 16)
107 #define LOONGSON_CFG6 0x6
109 #define LOONGSON_CFG7 0x7
110 #define LOONGSON_CFG7_GCCAEQRP BIT(0)
111 #define LOONGSON_CFG7_UCAWINP BIT(1)
113 static inline bool cpu_has_csr(void)
116 return (read_cpucfg(LOONGSON_CFG2
) & LOONGSON_CFG2_LCSRP
);
121 static inline u32
csr_readl(u32 reg
)
126 __asm__
__volatile__(
127 "parse_r __res,%0\n\t"
130 ".word (0xc8000118 | (reg << 21) | (__res << 11))\n\t"
138 static inline u64
csr_readq(u32 reg
)
142 /* DWRCSR reg, val */
143 __asm__
__volatile__(
144 "parse_r __res,%0\n\t"
147 ".word (0xc8020118 | (reg << 21) | (__res << 11))\n\t"
155 static inline void csr_writel(u32 val
, u32 reg
)
158 __asm__
__volatile__(
162 ".word (0xc8010118 | (reg << 21) | (val << 11))\n\t"
169 static inline void csr_writeq(u64 val
, u32 reg
)
171 /* DWRCSR reg, val */
172 __asm__
__volatile__(
176 ".word (0xc8030118 | (reg << 21) | (val << 11))\n\t"
183 /* Public CSR Register can also be accessed with regular addresses */
184 #define CSR_PUBLIC_MMIO_BASE 0x1fe00000
186 #define MMIO_CSR(x) (void *)TO_UNCAC(CSR_PUBLIC_MMIO_BASE + x)
188 #define LOONGSON_CSR_FEATURES 0x8
189 #define LOONGSON_CSRF_TEMP BIT(0)
190 #define LOONGSON_CSRF_NODECNT BIT(1)
191 #define LOONGSON_CSRF_MSI BIT(2)
192 #define LOONGSON_CSRF_EXTIOI BIT(3)
193 #define LOONGSON_CSRF_IPI BIT(4)
194 #define LOONGSON_CSRF_FREQ BIT(5)
196 #define LOONGSON_CSR_VENDOR 0x10 /* Vendor name string, should be "Loongson" */
197 #define LOONGSON_CSR_CPUNAME 0x20 /* Processor name string */
198 #define LOONGSON_CSR_NODECNT 0x408
199 #define LOONGSON_CSR_CPUTEMP 0x428
201 /* PerCore CSR, only accessable by local cores */
202 #define LOONGSON_CSR_IPI_STATUS 0x1000
203 #define LOONGSON_CSR_IPI_EN 0x1004
204 #define LOONGSON_CSR_IPI_SET 0x1008
205 #define LOONGSON_CSR_IPI_CLEAR 0x100c
206 #define LOONGSON_CSR_IPI_SEND 0x1040
207 #define CSR_IPI_SEND_IP_SHIFT 0
208 #define CSR_IPI_SEND_CPU_SHIFT 16
209 #define CSR_IPI_SEND_BLOCK BIT(31)
211 static inline u64
drdtime(void)
216 __asm__
__volatile__(
220 ".word (0xc8090118 | (rID << 21) | (val << 11))\n\t"