Skip to content

Commit 3f2401f

Browse files
avpatelbonzini
authored andcommitted
RISC-V: Add hypervisor extension related CSR defines
This patch adds asm/kvm_csr.h for RISC-V hypervisor extension related defines. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Paolo Bonzini <[email protected]> Reviewed-by: Alexander Graf <[email protected]> Message-Id: <[email protected]> Acked-by: Palmer Dabbelt <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 2353e59 commit 3f2401f

File tree

1 file changed

+87
-0
lines changed
  • arch/riscv/include/asm

1 file changed

+87
-0
lines changed

arch/riscv/include/asm/csr.h

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,32 @@
5858

5959
/* Interrupt causes (minus the high bit) */
6060
#define IRQ_S_SOFT 1
61+
#define IRQ_VS_SOFT 2
6162
#define IRQ_M_SOFT 3
6263
#define IRQ_S_TIMER 5
64+
#define IRQ_VS_TIMER 6
6365
#define IRQ_M_TIMER 7
6466
#define IRQ_S_EXT 9
67+
#define IRQ_VS_EXT 10
6568
#define IRQ_M_EXT 11
6669

6770
/* Exception causes */
6871
#define EXC_INST_MISALIGNED 0
6972
#define EXC_INST_ACCESS 1
73+
#define EXC_INST_ILLEGAL 2
7074
#define EXC_BREAKPOINT 3
7175
#define EXC_LOAD_ACCESS 5
7276
#define EXC_STORE_ACCESS 7
7377
#define EXC_SYSCALL 8
78+
#define EXC_HYPERVISOR_SYSCALL 9
79+
#define EXC_SUPERVISOR_SYSCALL 10
7480
#define EXC_INST_PAGE_FAULT 12
7581
#define EXC_LOAD_PAGE_FAULT 13
7682
#define EXC_STORE_PAGE_FAULT 15
83+
#define EXC_INST_GUEST_PAGE_FAULT 20
84+
#define EXC_LOAD_GUEST_PAGE_FAULT 21
85+
#define EXC_VIRTUAL_INST_FAULT 22
86+
#define EXC_STORE_GUEST_PAGE_FAULT 23
7787

7888
/* PMP configuration */
7989
#define PMP_R 0x01
@@ -85,6 +95,58 @@
8595
#define PMP_A_NAPOT 0x18
8696
#define PMP_L 0x80
8797

98+
/* HSTATUS flags */
99+
#ifdef CONFIG_64BIT
100+
#define HSTATUS_VSXL _AC(0x300000000, UL)
101+
#define HSTATUS_VSXL_SHIFT 32
102+
#endif
103+
#define HSTATUS_VTSR _AC(0x00400000, UL)
104+
#define HSTATUS_VTW _AC(0x00200000, UL)
105+
#define HSTATUS_VTVM _AC(0x00100000, UL)
106+
#define HSTATUS_VGEIN _AC(0x0003f000, UL)
107+
#define HSTATUS_VGEIN_SHIFT 12
108+
#define HSTATUS_HU _AC(0x00000200, UL)
109+
#define HSTATUS_SPVP _AC(0x00000100, UL)
110+
#define HSTATUS_SPV _AC(0x00000080, UL)
111+
#define HSTATUS_GVA _AC(0x00000040, UL)
112+
#define HSTATUS_VSBE _AC(0x00000020, UL)
113+
114+
/* HGATP flags */
115+
#define HGATP_MODE_OFF _AC(0, UL)
116+
#define HGATP_MODE_SV32X4 _AC(1, UL)
117+
#define HGATP_MODE_SV39X4 _AC(8, UL)
118+
#define HGATP_MODE_SV48X4 _AC(9, UL)
119+
120+
#define HGATP32_MODE_SHIFT 31
121+
#define HGATP32_VMID_SHIFT 22
122+
#define HGATP32_VMID_MASK _AC(0x1FC00000, UL)
123+
#define HGATP32_PPN _AC(0x003FFFFF, UL)
124+
125+
#define HGATP64_MODE_SHIFT 60
126+
#define HGATP64_VMID_SHIFT 44
127+
#define HGATP64_VMID_MASK _AC(0x03FFF00000000000, UL)
128+
#define HGATP64_PPN _AC(0x00000FFFFFFFFFFF, UL)
129+
130+
#define HGATP_PAGE_SHIFT 12
131+
132+
#ifdef CONFIG_64BIT
133+
#define HGATP_PPN HGATP64_PPN
134+
#define HGATP_VMID_SHIFT HGATP64_VMID_SHIFT
135+
#define HGATP_VMID_MASK HGATP64_VMID_MASK
136+
#define HGATP_MODE_SHIFT HGATP64_MODE_SHIFT
137+
#else
138+
#define HGATP_PPN HGATP32_PPN
139+
#define HGATP_VMID_SHIFT HGATP32_VMID_SHIFT
140+
#define HGATP_VMID_MASK HGATP32_VMID_MASK
141+
#define HGATP_MODE_SHIFT HGATP32_MODE_SHIFT
142+
#endif
143+
144+
/* VSIP & HVIP relation */
145+
#define VSIP_TO_HVIP_SHIFT (IRQ_VS_SOFT - IRQ_S_SOFT)
146+
#define VSIP_VALID_MASK ((_AC(1, UL) << IRQ_S_SOFT) | \
147+
(_AC(1, UL) << IRQ_S_TIMER) | \
148+
(_AC(1, UL) << IRQ_S_EXT))
149+
88150
/* symbolic CSR names: */
89151
#define CSR_CYCLE 0xc00
90152
#define CSR_TIME 0xc01
@@ -104,6 +166,31 @@
104166
#define CSR_SIP 0x144
105167
#define CSR_SATP 0x180
106168

169+
#define CSR_VSSTATUS 0x200
170+
#define CSR_VSIE 0x204
171+
#define CSR_VSTVEC 0x205
172+
#define CSR_VSSCRATCH 0x240
173+
#define CSR_VSEPC 0x241
174+
#define CSR_VSCAUSE 0x242
175+
#define CSR_VSTVAL 0x243
176+
#define CSR_VSIP 0x244
177+
#define CSR_VSATP 0x280
178+
179+
#define CSR_HSTATUS 0x600
180+
#define CSR_HEDELEG 0x602
181+
#define CSR_HIDELEG 0x603
182+
#define CSR_HIE 0x604
183+
#define CSR_HTIMEDELTA 0x605
184+
#define CSR_HCOUNTEREN 0x606
185+
#define CSR_HGEIE 0x607
186+
#define CSR_HTIMEDELTAH 0x615
187+
#define CSR_HTVAL 0x643
188+
#define CSR_HIP 0x644
189+
#define CSR_HVIP 0x645
190+
#define CSR_HTINST 0x64a
191+
#define CSR_HGATP 0x680
192+
#define CSR_HGEIP 0xe12
193+
107194
#define CSR_MSTATUS 0x300
108195
#define CSR_MISA 0x301
109196
#define CSR_MIE 0x304

0 commit comments

Comments
 (0)