blob: 83a3212b956d5bce117ffdfa425383aefcb06c54 [file] [log] [blame]
Sanjay Lal740765c2012-11-21 18:34:00 -08001/*
2* This file is subject to the terms and conditions of the GNU General Public
3* License. See the file "COPYING" in the main directory of this archive
4* for more details.
5*
6* Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved.
7* Authors: Sanjay Lal <sanjayl@kymasys.com>
8*/
9
10#ifndef __MIPS_KVM_HOST_H__
11#define __MIPS_KVM_HOST_H__
12
13#include <linux/mutex.h>
14#include <linux/hrtimer.h>
15#include <linux/interrupt.h>
16#include <linux/types.h>
17#include <linux/kvm.h>
18#include <linux/kvm_types.h>
19#include <linux/threads.h>
20#include <linux/spinlock.h>
21
James Hogan48a3c4e2014-05-29 10:16:28 +010022/* MIPS KVM register ids */
23#define MIPS_CP0_32(_R, _S) \
James Hogan7bd4ace2014-12-02 15:47:04 +000024 (KVM_REG_MIPS_CP0 | KVM_REG_SIZE_U32 | (8 * (_R) + (_S)))
James Hogan48a3c4e2014-05-29 10:16:28 +010025
26#define MIPS_CP0_64(_R, _S) \
James Hogan7bd4ace2014-12-02 15:47:04 +000027 (KVM_REG_MIPS_CP0 | KVM_REG_SIZE_U64 | (8 * (_R) + (_S)))
James Hogan48a3c4e2014-05-29 10:16:28 +010028
29#define KVM_REG_MIPS_CP0_INDEX MIPS_CP0_32(0, 0)
30#define KVM_REG_MIPS_CP0_ENTRYLO0 MIPS_CP0_64(2, 0)
31#define KVM_REG_MIPS_CP0_ENTRYLO1 MIPS_CP0_64(3, 0)
32#define KVM_REG_MIPS_CP0_CONTEXT MIPS_CP0_64(4, 0)
33#define KVM_REG_MIPS_CP0_USERLOCAL MIPS_CP0_64(4, 2)
34#define KVM_REG_MIPS_CP0_PAGEMASK MIPS_CP0_32(5, 0)
35#define KVM_REG_MIPS_CP0_PAGEGRAIN MIPS_CP0_32(5, 1)
36#define KVM_REG_MIPS_CP0_WIRED MIPS_CP0_32(6, 0)
37#define KVM_REG_MIPS_CP0_HWRENA MIPS_CP0_32(7, 0)
38#define KVM_REG_MIPS_CP0_BADVADDR MIPS_CP0_64(8, 0)
39#define KVM_REG_MIPS_CP0_COUNT MIPS_CP0_32(9, 0)
40#define KVM_REG_MIPS_CP0_ENTRYHI MIPS_CP0_64(10, 0)
41#define KVM_REG_MIPS_CP0_COMPARE MIPS_CP0_32(11, 0)
42#define KVM_REG_MIPS_CP0_STATUS MIPS_CP0_32(12, 0)
43#define KVM_REG_MIPS_CP0_CAUSE MIPS_CP0_32(13, 0)
44#define KVM_REG_MIPS_CP0_EPC MIPS_CP0_64(14, 0)
James Hogan1068eaa2014-06-26 13:56:52 +010045#define KVM_REG_MIPS_CP0_PRID MIPS_CP0_32(15, 0)
James Hogan48a3c4e2014-05-29 10:16:28 +010046#define KVM_REG_MIPS_CP0_EBASE MIPS_CP0_64(15, 1)
47#define KVM_REG_MIPS_CP0_CONFIG MIPS_CP0_32(16, 0)
48#define KVM_REG_MIPS_CP0_CONFIG1 MIPS_CP0_32(16, 1)
49#define KVM_REG_MIPS_CP0_CONFIG2 MIPS_CP0_32(16, 2)
50#define KVM_REG_MIPS_CP0_CONFIG3 MIPS_CP0_32(16, 3)
James Hoganc7716072014-06-26 15:11:29 +010051#define KVM_REG_MIPS_CP0_CONFIG4 MIPS_CP0_32(16, 4)
52#define KVM_REG_MIPS_CP0_CONFIG5 MIPS_CP0_32(16, 5)
James Hogan48a3c4e2014-05-29 10:16:28 +010053#define KVM_REG_MIPS_CP0_CONFIG7 MIPS_CP0_32(16, 7)
54#define KVM_REG_MIPS_CP0_XCONTEXT MIPS_CP0_64(20, 0)
55#define KVM_REG_MIPS_CP0_ERROREPC MIPS_CP0_64(30, 0)
56
Sanjay Lal740765c2012-11-21 18:34:00 -080057
58#define KVM_MAX_VCPUS 1
59#define KVM_USER_MEM_SLOTS 8
60/* memory slots that does not exposed to userspace */
James Hogancaa1faa2015-12-16 23:49:26 +000061#define KVM_PRIVATE_MEM_SLOTS 0
Sanjay Lal740765c2012-11-21 18:34:00 -080062
63#define KVM_COALESCED_MMIO_PAGE_OFFSET 1
David Hildenbrand920552b2015-09-18 12:34:53 +020064#define KVM_HALT_POLL_NS_DEFAULT 500000
Sanjay Lal740765c2012-11-21 18:34:00 -080065
Sanjay Lal740765c2012-11-21 18:34:00 -080066
67
68/* Special address that contains the comm page, used for reducing # of traps */
James Hogan22027942014-03-14 13:06:08 +000069#define KVM_GUEST_COMMPAGE_ADDR 0x0
Sanjay Lal740765c2012-11-21 18:34:00 -080070
71#define KVM_GUEST_KERNEL_MODE(vcpu) ((kvm_read_c0_guest_status(vcpu->arch.cop0) & (ST0_EXL | ST0_ERL)) || \
72 ((kvm_read_c0_guest_status(vcpu->arch.cop0) & KSU_USER) == 0))
73
James Hogan22027942014-03-14 13:06:08 +000074#define KVM_GUEST_KUSEG 0x00000000UL
75#define KVM_GUEST_KSEG0 0x40000000UL
76#define KVM_GUEST_KSEG23 0x60000000UL
James Hogan7f5a1dd2016-06-09 10:50:44 +010077#define KVM_GUEST_KSEGX(a) ((_ACAST32_(a)) & 0xe0000000)
James Hogan22027942014-03-14 13:06:08 +000078#define KVM_GUEST_CPHYSADDR(a) ((_ACAST32_(a)) & 0x1fffffff)
Sanjay Lal740765c2012-11-21 18:34:00 -080079
80#define KVM_GUEST_CKSEG0ADDR(a) (KVM_GUEST_CPHYSADDR(a) | KVM_GUEST_KSEG0)
81#define KVM_GUEST_CKSEG1ADDR(a) (KVM_GUEST_CPHYSADDR(a) | KVM_GUEST_KSEG1)
82#define KVM_GUEST_CKSEG23ADDR(a) (KVM_GUEST_CPHYSADDR(a) | KVM_GUEST_KSEG23)
83
84/*
85 * Map an address to a certain kernel segment
86 */
87#define KVM_GUEST_KSEG0ADDR(a) (KVM_GUEST_CPHYSADDR(a) | KVM_GUEST_KSEG0)
88#define KVM_GUEST_KSEG1ADDR(a) (KVM_GUEST_CPHYSADDR(a) | KVM_GUEST_KSEG1)
89#define KVM_GUEST_KSEG23ADDR(a) (KVM_GUEST_CPHYSADDR(a) | KVM_GUEST_KSEG23)
90
James Hogan22027942014-03-14 13:06:08 +000091#define KVM_INVALID_PAGE 0xdeadbeef
92#define KVM_INVALID_INST 0xdeadbeef
93#define KVM_INVALID_ADDR 0xdeadbeef
Sanjay Lal740765c2012-11-21 18:34:00 -080094
Sanjay Lal740765c2012-11-21 18:34:00 -080095extern atomic_t kvm_mips_instance;
Sanjay Lal740765c2012-11-21 18:34:00 -080096
97struct kvm_vm_stat {
98 u32 remote_tlb_flush;
99};
100
101struct kvm_vcpu_stat {
102 u32 wait_exits;
103 u32 cache_exits;
104 u32 signal_exits;
105 u32 int_exits;
106 u32 cop_unusable_exits;
107 u32 tlbmod_exits;
108 u32 tlbmiss_ld_exits;
109 u32 tlbmiss_st_exits;
110 u32 addrerr_st_exits;
111 u32 addrerr_ld_exits;
112 u32 syscall_exits;
113 u32 resvd_inst_exits;
114 u32 break_inst_exits;
James Hogan0a560422015-02-06 16:03:57 +0000115 u32 trap_inst_exits;
James Hoganc2537ed2015-02-06 10:56:27 +0000116 u32 msa_fpe_exits;
James Hogan1c0cd662015-02-06 10:56:27 +0000117 u32 fpe_exits;
James Hoganc2537ed2015-02-06 10:56:27 +0000118 u32 msa_disabled_exits;
Sanjay Lal740765c2012-11-21 18:34:00 -0800119 u32 flush_dcache_exits;
Paolo Bonzinif7819512015-02-04 18:20:58 +0100120 u32 halt_successful_poll;
Paolo Bonzini62bea5b2015-09-15 18:27:57 +0200121 u32 halt_attempted_poll;
Christian Borntraeger3491caf2016-05-13 12:16:35 +0200122 u32 halt_poll_invalid;
Sanjay Lal740765c2012-11-21 18:34:00 -0800123 u32 halt_wakeup;
124};
125
126enum kvm_mips_exit_types {
127 WAIT_EXITS,
128 CACHE_EXITS,
129 SIGNAL_EXITS,
130 INT_EXITS,
131 COP_UNUSABLE_EXITS,
132 TLBMOD_EXITS,
133 TLBMISS_LD_EXITS,
134 TLBMISS_ST_EXITS,
135 ADDRERR_ST_EXITS,
136 ADDRERR_LD_EXITS,
137 SYSCALL_EXITS,
138 RESVD_INST_EXITS,
139 BREAK_INST_EXITS,
James Hogan0a560422015-02-06 16:03:57 +0000140 TRAP_INST_EXITS,
James Hoganc2537ed2015-02-06 10:56:27 +0000141 MSA_FPE_EXITS,
James Hogan1c0cd662015-02-06 10:56:27 +0000142 FPE_EXITS,
James Hoganc2537ed2015-02-06 10:56:27 +0000143 MSA_DISABLED_EXITS,
Sanjay Lal740765c2012-11-21 18:34:00 -0800144 FLUSH_DCACHE_EXITS,
145 MAX_KVM_MIPS_EXIT_TYPES
146};
147
148struct kvm_arch_memory_slot {
149};
150
151struct kvm_arch {
152 /* Guest GVA->HPA page table */
153 unsigned long *guest_pmap;
154 unsigned long guest_pmap_npages;
155
156 /* Wired host TLB used for the commpage */
157 int commpage_tlb;
158};
159
James Hogan22027942014-03-14 13:06:08 +0000160#define N_MIPS_COPROC_REGS 32
161#define N_MIPS_COPROC_SEL 8
Sanjay Lal740765c2012-11-21 18:34:00 -0800162
163struct mips_coproc {
164 unsigned long reg[N_MIPS_COPROC_REGS][N_MIPS_COPROC_SEL];
165#ifdef CONFIG_KVM_MIPS_DEBUG_COP0_COUNTERS
166 unsigned long stat[N_MIPS_COPROC_REGS][N_MIPS_COPROC_SEL];
167#endif
168};
169
170/*
171 * Coprocessor 0 register names
172 */
James Hogan22027942014-03-14 13:06:08 +0000173#define MIPS_CP0_TLB_INDEX 0
174#define MIPS_CP0_TLB_RANDOM 1
175#define MIPS_CP0_TLB_LOW 2
176#define MIPS_CP0_TLB_LO0 2
177#define MIPS_CP0_TLB_LO1 3
178#define MIPS_CP0_TLB_CONTEXT 4
179#define MIPS_CP0_TLB_PG_MASK 5
180#define MIPS_CP0_TLB_WIRED 6
181#define MIPS_CP0_HWRENA 7
182#define MIPS_CP0_BAD_VADDR 8
183#define MIPS_CP0_COUNT 9
184#define MIPS_CP0_TLB_HI 10
185#define MIPS_CP0_COMPARE 11
186#define MIPS_CP0_STATUS 12
187#define MIPS_CP0_CAUSE 13
188#define MIPS_CP0_EXC_PC 14
189#define MIPS_CP0_PRID 15
190#define MIPS_CP0_CONFIG 16
191#define MIPS_CP0_LLADDR 17
192#define MIPS_CP0_WATCH_LO 18
193#define MIPS_CP0_WATCH_HI 19
194#define MIPS_CP0_TLB_XCONTEXT 20
195#define MIPS_CP0_ECC 26
196#define MIPS_CP0_CACHE_ERR 27
197#define MIPS_CP0_TAG_LO 28
198#define MIPS_CP0_TAG_HI 29
199#define MIPS_CP0_ERROR_PC 30
200#define MIPS_CP0_DEBUG 23
201#define MIPS_CP0_DEPC 24
202#define MIPS_CP0_PERFCNT 25
203#define MIPS_CP0_ERRCTL 26
204#define MIPS_CP0_DATA_LO 28
205#define MIPS_CP0_DATA_HI 29
206#define MIPS_CP0_DESAVE 31
Sanjay Lal740765c2012-11-21 18:34:00 -0800207
James Hogan22027942014-03-14 13:06:08 +0000208#define MIPS_CP0_CONFIG_SEL 0
209#define MIPS_CP0_CONFIG1_SEL 1
210#define MIPS_CP0_CONFIG2_SEL 2
211#define MIPS_CP0_CONFIG3_SEL 3
James Hoganc7716072014-06-26 15:11:29 +0100212#define MIPS_CP0_CONFIG4_SEL 4
213#define MIPS_CP0_CONFIG5_SEL 5
Sanjay Lal740765c2012-11-21 18:34:00 -0800214
215/* Config0 register bits */
James Hogan22027942014-03-14 13:06:08 +0000216#define CP0C0_M 31
217#define CP0C0_K23 28
218#define CP0C0_KU 25
219#define CP0C0_MDU 20
220#define CP0C0_MM 17
221#define CP0C0_BM 16
222#define CP0C0_BE 15
223#define CP0C0_AT 13
224#define CP0C0_AR 10
225#define CP0C0_MT 7
226#define CP0C0_VI 3
227#define CP0C0_K0 0
Sanjay Lal740765c2012-11-21 18:34:00 -0800228
229/* Config1 register bits */
James Hogan22027942014-03-14 13:06:08 +0000230#define CP0C1_M 31
231#define CP0C1_MMU 25
232#define CP0C1_IS 22
233#define CP0C1_IL 19
234#define CP0C1_IA 16
235#define CP0C1_DS 13
236#define CP0C1_DL 10
237#define CP0C1_DA 7
238#define CP0C1_C2 6
239#define CP0C1_MD 5
240#define CP0C1_PC 4
241#define CP0C1_WR 3
242#define CP0C1_CA 2
243#define CP0C1_EP 1
244#define CP0C1_FP 0
Sanjay Lal740765c2012-11-21 18:34:00 -0800245
246/* Config2 Register bits */
James Hogan22027942014-03-14 13:06:08 +0000247#define CP0C2_M 31
248#define CP0C2_TU 28
249#define CP0C2_TS 24
250#define CP0C2_TL 20
251#define CP0C2_TA 16
252#define CP0C2_SU 12
253#define CP0C2_SS 8
254#define CP0C2_SL 4
255#define CP0C2_SA 0
Sanjay Lal740765c2012-11-21 18:34:00 -0800256
257/* Config3 Register bits */
James Hogan22027942014-03-14 13:06:08 +0000258#define CP0C3_M 31
259#define CP0C3_ISA_ON_EXC 16
260#define CP0C3_ULRI 13
261#define CP0C3_DSPP 10
262#define CP0C3_LPA 7
263#define CP0C3_VEIC 6
264#define CP0C3_VInt 5
265#define CP0C3_SP 4
266#define CP0C3_MT 2
267#define CP0C3_SM 1
268#define CP0C3_TL 0
Sanjay Lal740765c2012-11-21 18:34:00 -0800269
Sanjay Lal740765c2012-11-21 18:34:00 -0800270/* MMU types, the first four entries have the same layout as the
271 CP0C0_MT field. */
272enum mips_mmu_types {
273 MMU_TYPE_NONE,
274 MMU_TYPE_R4000,
275 MMU_TYPE_RESERVED,
276 MMU_TYPE_FMT,
277 MMU_TYPE_R3000,
278 MMU_TYPE_R6000,
279 MMU_TYPE_R8000
280};
281
Sanjay Lal740765c2012-11-21 18:34:00 -0800282/* Resume Flags */
James Hogan22027942014-03-14 13:06:08 +0000283#define RESUME_FLAG_DR (1<<0) /* Reload guest nonvolatile state? */
284#define RESUME_FLAG_HOST (1<<1) /* Resume host? */
Sanjay Lal740765c2012-11-21 18:34:00 -0800285
James Hogan22027942014-03-14 13:06:08 +0000286#define RESUME_GUEST 0
287#define RESUME_GUEST_DR RESUME_FLAG_DR
288#define RESUME_HOST RESUME_FLAG_HOST
Sanjay Lal740765c2012-11-21 18:34:00 -0800289
290enum emulation_result {
291 EMULATE_DONE, /* no further processing */
292 EMULATE_DO_MMIO, /* kvm_run filled with MMIO request */
293 EMULATE_FAIL, /* can't emulate this instruction */
294 EMULATE_WAIT, /* WAIT instruction */
295 EMULATE_PRIV_FAIL,
296};
297
James Hogan22027942014-03-14 13:06:08 +0000298#define MIPS3_PG_G 0x00000001 /* Global; ignore ASID if in lo0 & lo1 */
299#define MIPS3_PG_V 0x00000002 /* Valid */
300#define MIPS3_PG_NV 0x00000000
301#define MIPS3_PG_D 0x00000004 /* Dirty */
Sanjay Lal740765c2012-11-21 18:34:00 -0800302
303#define mips3_paddr_to_tlbpfn(x) \
James Hogan22027942014-03-14 13:06:08 +0000304 (((unsigned long)(x) >> MIPS3_PG_SHIFT) & MIPS3_PG_FRAME)
Sanjay Lal740765c2012-11-21 18:34:00 -0800305#define mips3_tlbpfn_to_paddr(x) \
James Hogan22027942014-03-14 13:06:08 +0000306 ((unsigned long)((x) & MIPS3_PG_FRAME) << MIPS3_PG_SHIFT)
Sanjay Lal740765c2012-11-21 18:34:00 -0800307
James Hogan22027942014-03-14 13:06:08 +0000308#define MIPS3_PG_SHIFT 6
309#define MIPS3_PG_FRAME 0x3fffffc0
Sanjay Lal740765c2012-11-21 18:34:00 -0800310
James Hogan22027942014-03-14 13:06:08 +0000311#define VPN2_MASK 0xffffe000
Paul Burtonca64c2b2016-05-06 14:36:20 +0100312#define KVM_ENTRYHI_ASID MIPS_ENTRYHI_ASID
James Hogan19d194c2016-06-09 14:19:18 +0100313#define TLB_IS_GLOBAL(x) ((x).tlb_lo[0] & (x).tlb_lo[1] & MIPS3_PG_G)
James Hogan22027942014-03-14 13:06:08 +0000314#define TLB_VPN2(x) ((x).tlb_hi & VPN2_MASK)
Paul Burtonca64c2b2016-05-06 14:36:20 +0100315#define TLB_ASID(x) ((x).tlb_hi & KVM_ENTRYHI_ASID)
James Hogan19d194c2016-06-09 14:19:18 +0100316#define TLB_LO_IDX(x, va) (((va) >> PAGE_SHIFT) & 1)
317#define TLB_IS_VALID(x, va) ((x).tlb_lo[TLB_LO_IDX(x, va)] & MIPS3_PG_V)
Deng-Cheng Zhud116e812014-06-26 12:11:34 -0700318#define TLB_HI_VPN2_HIT(x, y) ((TLB_VPN2(x) & ~(x).tlb_mask) == \
319 ((y) & VPN2_MASK & ~(x).tlb_mask))
320#define TLB_HI_ASID_HIT(x, y) (TLB_IS_GLOBAL(x) || \
Paul Burtonca64c2b2016-05-06 14:36:20 +0100321 TLB_ASID(x) == ((y) & KVM_ENTRYHI_ASID))
Sanjay Lal740765c2012-11-21 18:34:00 -0800322
323struct kvm_mips_tlb {
324 long tlb_mask;
325 long tlb_hi;
James Hogan9fbfb062016-06-09 14:19:17 +0100326 long tlb_lo[2];
Sanjay Lal740765c2012-11-21 18:34:00 -0800327};
328
James Hogan98e91b82014-11-18 14:09:12 +0000329#define KVM_MIPS_FPU_FPU 0x1
James Hogan539cb89fb2015-03-05 11:43:36 +0000330#define KVM_MIPS_FPU_MSA 0x2
James Hogan98e91b82014-11-18 14:09:12 +0000331
James Hogan22027942014-03-14 13:06:08 +0000332#define KVM_MIPS_GUEST_TLB_SIZE 64
Sanjay Lal740765c2012-11-21 18:34:00 -0800333struct kvm_vcpu_arch {
James Hogan878edf02016-06-09 14:19:14 +0100334 void *guest_ebase;
James Hogan797179b2016-06-09 10:50:43 +0100335 int (*vcpu_run)(struct kvm_run *run, struct kvm_vcpu *vcpu);
Sanjay Lal740765c2012-11-21 18:34:00 -0800336 unsigned long host_stack;
337 unsigned long host_gp;
338
339 /* Host CP0 registers used when handling exits from guest */
340 unsigned long host_cp0_badvaddr;
Sanjay Lal740765c2012-11-21 18:34:00 -0800341 unsigned long host_cp0_epc;
James Hogan31cf7492016-06-09 14:19:09 +0100342 u32 host_cp0_cause;
Sanjay Lal740765c2012-11-21 18:34:00 -0800343
344 /* GPRS */
345 unsigned long gprs[32];
346 unsigned long hi;
347 unsigned long lo;
348 unsigned long pc;
349
350 /* FPU State */
351 struct mips_fpu_struct fpu;
James Hogan98e91b82014-11-18 14:09:12 +0000352 /* Which FPU state is loaded (KVM_MIPS_FPU_*) */
353 unsigned int fpu_inuse;
Sanjay Lal740765c2012-11-21 18:34:00 -0800354
355 /* COP0 State */
356 struct mips_coproc *cop0;
357
358 /* Host KSEG0 address of the EI/DI offset */
359 void *kseg0_commpage;
360
361 u32 io_gpr; /* GPR used as IO source/target */
362
James Hogane30492b2014-05-29 10:16:35 +0100363 struct hrtimer comparecount_timer;
James Hoganf8239342014-05-29 10:16:37 +0100364 /* Count timer control KVM register */
James Hoganbdb7ed82016-06-09 14:19:07 +0100365 u32 count_ctl;
James Hogane30492b2014-05-29 10:16:35 +0100366 /* Count bias from the raw time */
James Hoganbdb7ed82016-06-09 14:19:07 +0100367 u32 count_bias;
James Hogane30492b2014-05-29 10:16:35 +0100368 /* Frequency of timer in Hz */
James Hoganbdb7ed82016-06-09 14:19:07 +0100369 u32 count_hz;
James Hogane30492b2014-05-29 10:16:35 +0100370 /* Dynamic nanosecond bias (multiple of count_period) to avoid overflow */
371 s64 count_dyn_bias;
James Hoganf8239342014-05-29 10:16:37 +0100372 /* Resume time */
373 ktime_t count_resume;
James Hogane30492b2014-05-29 10:16:35 +0100374 /* Period of timer tick in ns */
375 u64 count_period;
Sanjay Lal740765c2012-11-21 18:34:00 -0800376
377 /* Bitmask of exceptions that are pending */
378 unsigned long pending_exceptions;
379
380 /* Bitmask of pending exceptions to be cleared */
381 unsigned long pending_exceptions_clr;
382
James Hogan31cf7492016-06-09 14:19:09 +0100383 u32 pending_load_cause;
Sanjay Lal740765c2012-11-21 18:34:00 -0800384
385 /* Save/Restore the entryhi register when are are preempted/scheduled back in */
386 unsigned long preempt_entryhi;
387
388 /* S/W Based TLB for guest */
389 struct kvm_mips_tlb guest_tlb[KVM_MIPS_GUEST_TLB_SIZE];
390
391 /* Cached guest kernel/user ASIDs */
James Hoganbdb7ed82016-06-09 14:19:07 +0100392 u32 guest_user_asid[NR_CPUS];
393 u32 guest_kernel_asid[NR_CPUS];
Sanjay Lal740765c2012-11-21 18:34:00 -0800394 struct mm_struct guest_kernel_mm, guest_user_mm;
395
Sanjay Lal740765c2012-11-21 18:34:00 -0800396 int last_sched_cpu;
397
398 /* WAIT executed */
399 int wait;
James Hogan98e91b82014-11-18 14:09:12 +0000400
401 u8 fpu_enabled;
James Hogan539cb89fb2015-03-05 11:43:36 +0000402 u8 msa_enabled;
Sanjay Lal740765c2012-11-21 18:34:00 -0800403};
404
405
James Hogan22027942014-03-14 13:06:08 +0000406#define kvm_read_c0_guest_index(cop0) (cop0->reg[MIPS_CP0_TLB_INDEX][0])
407#define kvm_write_c0_guest_index(cop0, val) (cop0->reg[MIPS_CP0_TLB_INDEX][0] = val)
408#define kvm_read_c0_guest_entrylo0(cop0) (cop0->reg[MIPS_CP0_TLB_LO0][0])
409#define kvm_read_c0_guest_entrylo1(cop0) (cop0->reg[MIPS_CP0_TLB_LO1][0])
410#define kvm_read_c0_guest_context(cop0) (cop0->reg[MIPS_CP0_TLB_CONTEXT][0])
411#define kvm_write_c0_guest_context(cop0, val) (cop0->reg[MIPS_CP0_TLB_CONTEXT][0] = (val))
412#define kvm_read_c0_guest_userlocal(cop0) (cop0->reg[MIPS_CP0_TLB_CONTEXT][2])
James Hogan7767b7d2014-05-29 10:16:30 +0100413#define kvm_write_c0_guest_userlocal(cop0, val) (cop0->reg[MIPS_CP0_TLB_CONTEXT][2] = (val))
James Hogan22027942014-03-14 13:06:08 +0000414#define kvm_read_c0_guest_pagemask(cop0) (cop0->reg[MIPS_CP0_TLB_PG_MASK][0])
415#define kvm_write_c0_guest_pagemask(cop0, val) (cop0->reg[MIPS_CP0_TLB_PG_MASK][0] = (val))
416#define kvm_read_c0_guest_wired(cop0) (cop0->reg[MIPS_CP0_TLB_WIRED][0])
417#define kvm_write_c0_guest_wired(cop0, val) (cop0->reg[MIPS_CP0_TLB_WIRED][0] = (val))
James Hogan26f4f3b2014-03-14 13:06:09 +0000418#define kvm_read_c0_guest_hwrena(cop0) (cop0->reg[MIPS_CP0_HWRENA][0])
419#define kvm_write_c0_guest_hwrena(cop0, val) (cop0->reg[MIPS_CP0_HWRENA][0] = (val))
James Hogan22027942014-03-14 13:06:08 +0000420#define kvm_read_c0_guest_badvaddr(cop0) (cop0->reg[MIPS_CP0_BAD_VADDR][0])
421#define kvm_write_c0_guest_badvaddr(cop0, val) (cop0->reg[MIPS_CP0_BAD_VADDR][0] = (val))
422#define kvm_read_c0_guest_count(cop0) (cop0->reg[MIPS_CP0_COUNT][0])
423#define kvm_write_c0_guest_count(cop0, val) (cop0->reg[MIPS_CP0_COUNT][0] = (val))
424#define kvm_read_c0_guest_entryhi(cop0) (cop0->reg[MIPS_CP0_TLB_HI][0])
425#define kvm_write_c0_guest_entryhi(cop0, val) (cop0->reg[MIPS_CP0_TLB_HI][0] = (val))
426#define kvm_read_c0_guest_compare(cop0) (cop0->reg[MIPS_CP0_COMPARE][0])
427#define kvm_write_c0_guest_compare(cop0, val) (cop0->reg[MIPS_CP0_COMPARE][0] = (val))
428#define kvm_read_c0_guest_status(cop0) (cop0->reg[MIPS_CP0_STATUS][0])
429#define kvm_write_c0_guest_status(cop0, val) (cop0->reg[MIPS_CP0_STATUS][0] = (val))
430#define kvm_read_c0_guest_intctl(cop0) (cop0->reg[MIPS_CP0_STATUS][1])
431#define kvm_write_c0_guest_intctl(cop0, val) (cop0->reg[MIPS_CP0_STATUS][1] = (val))
432#define kvm_read_c0_guest_cause(cop0) (cop0->reg[MIPS_CP0_CAUSE][0])
433#define kvm_write_c0_guest_cause(cop0, val) (cop0->reg[MIPS_CP0_CAUSE][0] = (val))
434#define kvm_read_c0_guest_epc(cop0) (cop0->reg[MIPS_CP0_EXC_PC][0])
435#define kvm_write_c0_guest_epc(cop0, val) (cop0->reg[MIPS_CP0_EXC_PC][0] = (val))
436#define kvm_read_c0_guest_prid(cop0) (cop0->reg[MIPS_CP0_PRID][0])
437#define kvm_write_c0_guest_prid(cop0, val) (cop0->reg[MIPS_CP0_PRID][0] = (val))
438#define kvm_read_c0_guest_ebase(cop0) (cop0->reg[MIPS_CP0_PRID][1])
439#define kvm_write_c0_guest_ebase(cop0, val) (cop0->reg[MIPS_CP0_PRID][1] = (val))
440#define kvm_read_c0_guest_config(cop0) (cop0->reg[MIPS_CP0_CONFIG][0])
441#define kvm_read_c0_guest_config1(cop0) (cop0->reg[MIPS_CP0_CONFIG][1])
442#define kvm_read_c0_guest_config2(cop0) (cop0->reg[MIPS_CP0_CONFIG][2])
443#define kvm_read_c0_guest_config3(cop0) (cop0->reg[MIPS_CP0_CONFIG][3])
James Hoganc7716072014-06-26 15:11:29 +0100444#define kvm_read_c0_guest_config4(cop0) (cop0->reg[MIPS_CP0_CONFIG][4])
445#define kvm_read_c0_guest_config5(cop0) (cop0->reg[MIPS_CP0_CONFIG][5])
James Hogan22027942014-03-14 13:06:08 +0000446#define kvm_read_c0_guest_config7(cop0) (cop0->reg[MIPS_CP0_CONFIG][7])
447#define kvm_write_c0_guest_config(cop0, val) (cop0->reg[MIPS_CP0_CONFIG][0] = (val))
448#define kvm_write_c0_guest_config1(cop0, val) (cop0->reg[MIPS_CP0_CONFIG][1] = (val))
449#define kvm_write_c0_guest_config2(cop0, val) (cop0->reg[MIPS_CP0_CONFIG][2] = (val))
450#define kvm_write_c0_guest_config3(cop0, val) (cop0->reg[MIPS_CP0_CONFIG][3] = (val))
James Hoganc7716072014-06-26 15:11:29 +0100451#define kvm_write_c0_guest_config4(cop0, val) (cop0->reg[MIPS_CP0_CONFIG][4] = (val))
452#define kvm_write_c0_guest_config5(cop0, val) (cop0->reg[MIPS_CP0_CONFIG][5] = (val))
James Hogan22027942014-03-14 13:06:08 +0000453#define kvm_write_c0_guest_config7(cop0, val) (cop0->reg[MIPS_CP0_CONFIG][7] = (val))
454#define kvm_read_c0_guest_errorepc(cop0) (cop0->reg[MIPS_CP0_ERROR_PC][0])
455#define kvm_write_c0_guest_errorepc(cop0, val) (cop0->reg[MIPS_CP0_ERROR_PC][0] = (val))
Sanjay Lal740765c2012-11-21 18:34:00 -0800456
James Hoganc73c99b2014-05-29 10:16:33 +0100457/*
458 * Some of the guest registers may be modified asynchronously (e.g. from a
459 * hrtimer callback in hard irq context) and therefore need stronger atomicity
460 * guarantees than other registers.
461 */
462
463static inline void _kvm_atomic_set_c0_guest_reg(unsigned long *reg,
464 unsigned long val)
465{
466 unsigned long temp;
467 do {
468 __asm__ __volatile__(
469 " .set mips3 \n"
470 " " __LL "%0, %1 \n"
471 " or %0, %2 \n"
472 " " __SC "%0, %1 \n"
473 " .set mips0 \n"
474 : "=&r" (temp), "+m" (*reg)
475 : "r" (val));
476 } while (unlikely(!temp));
477}
478
479static inline void _kvm_atomic_clear_c0_guest_reg(unsigned long *reg,
480 unsigned long val)
481{
482 unsigned long temp;
483 do {
484 __asm__ __volatile__(
485 " .set mips3 \n"
486 " " __LL "%0, %1 \n"
487 " and %0, %2 \n"
488 " " __SC "%0, %1 \n"
489 " .set mips0 \n"
490 : "=&r" (temp), "+m" (*reg)
491 : "r" (~val));
492 } while (unlikely(!temp));
493}
494
495static inline void _kvm_atomic_change_c0_guest_reg(unsigned long *reg,
496 unsigned long change,
497 unsigned long val)
498{
499 unsigned long temp;
500 do {
501 __asm__ __volatile__(
502 " .set mips3 \n"
503 " " __LL "%0, %1 \n"
504 " and %0, %2 \n"
505 " or %0, %3 \n"
506 " " __SC "%0, %1 \n"
507 " .set mips0 \n"
508 : "=&r" (temp), "+m" (*reg)
509 : "r" (~change), "r" (val & change));
510 } while (unlikely(!temp));
511}
512
James Hogan22027942014-03-14 13:06:08 +0000513#define kvm_set_c0_guest_status(cop0, val) (cop0->reg[MIPS_CP0_STATUS][0] |= (val))
514#define kvm_clear_c0_guest_status(cop0, val) (cop0->reg[MIPS_CP0_STATUS][0] &= ~(val))
James Hoganc73c99b2014-05-29 10:16:33 +0100515
516/* Cause can be modified asynchronously from hardirq hrtimer callback */
517#define kvm_set_c0_guest_cause(cop0, val) \
518 _kvm_atomic_set_c0_guest_reg(&cop0->reg[MIPS_CP0_CAUSE][0], val)
519#define kvm_clear_c0_guest_cause(cop0, val) \
520 _kvm_atomic_clear_c0_guest_reg(&cop0->reg[MIPS_CP0_CAUSE][0], val)
James Hogan22027942014-03-14 13:06:08 +0000521#define kvm_change_c0_guest_cause(cop0, change, val) \
James Hoganc73c99b2014-05-29 10:16:33 +0100522 _kvm_atomic_change_c0_guest_reg(&cop0->reg[MIPS_CP0_CAUSE][0], \
523 change, val)
524
James Hogan22027942014-03-14 13:06:08 +0000525#define kvm_set_c0_guest_ebase(cop0, val) (cop0->reg[MIPS_CP0_PRID][1] |= (val))
526#define kvm_clear_c0_guest_ebase(cop0, val) (cop0->reg[MIPS_CP0_PRID][1] &= ~(val))
527#define kvm_change_c0_guest_ebase(cop0, change, val) \
528{ \
529 kvm_clear_c0_guest_ebase(cop0, change); \
530 kvm_set_c0_guest_ebase(cop0, ((val) & (change))); \
Sanjay Lal740765c2012-11-21 18:34:00 -0800531}
532
James Hogan98e91b82014-11-18 14:09:12 +0000533/* Helpers */
534
535static inline bool kvm_mips_guest_can_have_fpu(struct kvm_vcpu_arch *vcpu)
536{
537 return (!__builtin_constant_p(cpu_has_fpu) || cpu_has_fpu) &&
538 vcpu->fpu_enabled;
539}
540
541static inline bool kvm_mips_guest_has_fpu(struct kvm_vcpu_arch *vcpu)
542{
543 return kvm_mips_guest_can_have_fpu(vcpu) &&
544 kvm_read_c0_guest_config1(vcpu->cop0) & MIPS_CONF1_FP;
545}
Sanjay Lal740765c2012-11-21 18:34:00 -0800546
James Hogan539cb89fb2015-03-05 11:43:36 +0000547static inline bool kvm_mips_guest_can_have_msa(struct kvm_vcpu_arch *vcpu)
548{
549 return (!__builtin_constant_p(cpu_has_msa) || cpu_has_msa) &&
550 vcpu->msa_enabled;
551}
552
553static inline bool kvm_mips_guest_has_msa(struct kvm_vcpu_arch *vcpu)
554{
555 return kvm_mips_guest_can_have_msa(vcpu) &&
556 kvm_read_c0_guest_config3(vcpu->cop0) & MIPS_CONF3_MSA;
557}
558
Sanjay Lal740765c2012-11-21 18:34:00 -0800559struct kvm_mips_callbacks {
James Hogan2dca3722014-05-29 10:16:40 +0100560 int (*handle_cop_unusable)(struct kvm_vcpu *vcpu);
561 int (*handle_tlb_mod)(struct kvm_vcpu *vcpu);
562 int (*handle_tlb_ld_miss)(struct kvm_vcpu *vcpu);
563 int (*handle_tlb_st_miss)(struct kvm_vcpu *vcpu);
564 int (*handle_addr_err_st)(struct kvm_vcpu *vcpu);
565 int (*handle_addr_err_ld)(struct kvm_vcpu *vcpu);
566 int (*handle_syscall)(struct kvm_vcpu *vcpu);
567 int (*handle_res_inst)(struct kvm_vcpu *vcpu);
568 int (*handle_break)(struct kvm_vcpu *vcpu);
James Hogan0a560422015-02-06 16:03:57 +0000569 int (*handle_trap)(struct kvm_vcpu *vcpu);
James Hoganc2537ed2015-02-06 10:56:27 +0000570 int (*handle_msa_fpe)(struct kvm_vcpu *vcpu);
James Hogan1c0cd662015-02-06 10:56:27 +0000571 int (*handle_fpe)(struct kvm_vcpu *vcpu);
James Hogan98119ad2015-02-06 11:11:56 +0000572 int (*handle_msa_disabled)(struct kvm_vcpu *vcpu);
James Hogan2dca3722014-05-29 10:16:40 +0100573 int (*vm_init)(struct kvm *kvm);
574 int (*vcpu_init)(struct kvm_vcpu *vcpu);
575 int (*vcpu_setup)(struct kvm_vcpu *vcpu);
576 gpa_t (*gva_to_gpa)(gva_t gva);
577 void (*queue_timer_int)(struct kvm_vcpu *vcpu);
578 void (*dequeue_timer_int)(struct kvm_vcpu *vcpu);
579 void (*queue_io_int)(struct kvm_vcpu *vcpu,
580 struct kvm_mips_interrupt *irq);
581 void (*dequeue_io_int)(struct kvm_vcpu *vcpu,
582 struct kvm_mips_interrupt *irq);
583 int (*irq_deliver)(struct kvm_vcpu *vcpu, unsigned int priority,
James Hoganbdb7ed82016-06-09 14:19:07 +0100584 u32 cause);
James Hogan2dca3722014-05-29 10:16:40 +0100585 int (*irq_clear)(struct kvm_vcpu *vcpu, unsigned int priority,
James Hoganbdb7ed82016-06-09 14:19:07 +0100586 u32 cause);
James Hoganf8be02d2014-05-29 10:16:29 +0100587 int (*get_one_reg)(struct kvm_vcpu *vcpu,
588 const struct kvm_one_reg *reg, s64 *v);
589 int (*set_one_reg)(struct kvm_vcpu *vcpu,
590 const struct kvm_one_reg *reg, s64 v);
James Hoganb86ecb32015-02-09 16:35:20 +0000591 int (*vcpu_get_regs)(struct kvm_vcpu *vcpu);
592 int (*vcpu_set_regs)(struct kvm_vcpu *vcpu);
Sanjay Lal740765c2012-11-21 18:34:00 -0800593};
594extern struct kvm_mips_callbacks *kvm_mips_callbacks;
595int kvm_mips_emulation_init(struct kvm_mips_callbacks **install_callbacks);
596
597/* Debug: dump vcpu state */
598int kvm_arch_vcpu_dump_regs(struct kvm_vcpu *vcpu);
599
600/* Trampoline ASM routine to start running in "Guest" context */
601extern int __kvm_mips_vcpu_run(struct kvm_run *run, struct kvm_vcpu *vcpu);
602
James Hogan539cb89fb2015-03-05 11:43:36 +0000603/* FPU/MSA context management */
James Hogan98e91b82014-11-18 14:09:12 +0000604void __kvm_save_fpu(struct kvm_vcpu_arch *vcpu);
605void __kvm_restore_fpu(struct kvm_vcpu_arch *vcpu);
606void __kvm_restore_fcsr(struct kvm_vcpu_arch *vcpu);
James Hogan539cb89fb2015-03-05 11:43:36 +0000607void __kvm_save_msa(struct kvm_vcpu_arch *vcpu);
608void __kvm_restore_msa(struct kvm_vcpu_arch *vcpu);
609void __kvm_restore_msa_upper(struct kvm_vcpu_arch *vcpu);
610void __kvm_restore_msacsr(struct kvm_vcpu_arch *vcpu);
James Hogan98e91b82014-11-18 14:09:12 +0000611void kvm_own_fpu(struct kvm_vcpu *vcpu);
James Hogan539cb89fb2015-03-05 11:43:36 +0000612void kvm_own_msa(struct kvm_vcpu *vcpu);
James Hogan98e91b82014-11-18 14:09:12 +0000613void kvm_drop_fpu(struct kvm_vcpu *vcpu);
614void kvm_lose_fpu(struct kvm_vcpu *vcpu);
615
Sanjay Lal740765c2012-11-21 18:34:00 -0800616/* TLB handling */
James Hoganbdb7ed82016-06-09 14:19:07 +0100617u32 kvm_get_kernel_asid(struct kvm_vcpu *vcpu);
Sanjay Lal740765c2012-11-21 18:34:00 -0800618
James Hoganbdb7ed82016-06-09 14:19:07 +0100619u32 kvm_get_user_asid(struct kvm_vcpu *vcpu);
Sanjay Lal740765c2012-11-21 18:34:00 -0800620
James Hoganbdb7ed82016-06-09 14:19:07 +0100621u32 kvm_get_commpage_asid (struct kvm_vcpu *vcpu);
Sanjay Lal740765c2012-11-21 18:34:00 -0800622
623extern int kvm_mips_handle_kseg0_tlb_fault(unsigned long badbaddr,
624 struct kvm_vcpu *vcpu);
625
626extern int kvm_mips_handle_commpage_tlb_fault(unsigned long badvaddr,
627 struct kvm_vcpu *vcpu);
628
629extern int kvm_mips_handle_mapped_seg_tlb_fault(struct kvm_vcpu *vcpu,
James Hogan26ee17f2016-06-09 14:19:13 +0100630 struct kvm_mips_tlb *tlb);
Sanjay Lal740765c2012-11-21 18:34:00 -0800631
James Hogan31cf7492016-06-09 14:19:09 +0100632extern enum emulation_result kvm_mips_handle_tlbmiss(u32 cause,
James Hoganbdb7ed82016-06-09 14:19:07 +0100633 u32 *opc,
Sanjay Lal740765c2012-11-21 18:34:00 -0800634 struct kvm_run *run,
635 struct kvm_vcpu *vcpu);
636
James Hogan31cf7492016-06-09 14:19:09 +0100637extern enum emulation_result kvm_mips_handle_tlbmod(u32 cause,
James Hoganbdb7ed82016-06-09 14:19:07 +0100638 u32 *opc,
Sanjay Lal740765c2012-11-21 18:34:00 -0800639 struct kvm_run *run,
640 struct kvm_vcpu *vcpu);
641
642extern void kvm_mips_dump_host_tlbs(void);
643extern void kvm_mips_dump_guest_tlbs(struct kvm_vcpu *vcpu);
James Hogan403015b2016-06-09 14:19:10 +0100644extern int kvm_mips_host_tlb_write(struct kvm_vcpu *vcpu, unsigned long entryhi,
645 unsigned long entrylo0,
646 unsigned long entrylo1,
647 int flush_dcache_mask);
Sanjay Lal740765c2012-11-21 18:34:00 -0800648extern void kvm_mips_flush_host_tlb(int skip_kseg0);
649extern int kvm_mips_host_tlb_inv(struct kvm_vcpu *vcpu, unsigned long entryhi);
Sanjay Lal740765c2012-11-21 18:34:00 -0800650
651extern int kvm_mips_guest_tlb_lookup(struct kvm_vcpu *vcpu,
652 unsigned long entryhi);
653extern int kvm_mips_host_tlb_lookup(struct kvm_vcpu *vcpu, unsigned long vaddr);
654extern unsigned long kvm_mips_translate_guest_kseg0_to_hpa(struct kvm_vcpu *vcpu,
655 unsigned long gva);
656extern void kvm_get_new_mmu_context(struct mm_struct *mm, unsigned long cpu,
657 struct kvm_vcpu *vcpu);
Sanjay Lal740765c2012-11-21 18:34:00 -0800658extern void kvm_local_flush_tlb_all(void);
Sanjay Lal740765c2012-11-21 18:34:00 -0800659extern void kvm_mips_alloc_new_mmu_context(struct kvm_vcpu *vcpu);
660extern void kvm_mips_vcpu_load(struct kvm_vcpu *vcpu, int cpu);
661extern void kvm_mips_vcpu_put(struct kvm_vcpu *vcpu);
662
663/* Emulation */
James Hoganbdb7ed82016-06-09 14:19:07 +0100664u32 kvm_get_inst(u32 *opc, struct kvm_vcpu *vcpu);
665enum emulation_result update_pc(struct kvm_vcpu *vcpu, u32 cause);
Sanjay Lal740765c2012-11-21 18:34:00 -0800666
James Hogan31cf7492016-06-09 14:19:09 +0100667extern enum emulation_result kvm_mips_emulate_inst(u32 cause,
James Hoganbdb7ed82016-06-09 14:19:07 +0100668 u32 *opc,
Sanjay Lal740765c2012-11-21 18:34:00 -0800669 struct kvm_run *run,
670 struct kvm_vcpu *vcpu);
671
James Hogan31cf7492016-06-09 14:19:09 +0100672extern enum emulation_result kvm_mips_emulate_syscall(u32 cause,
James Hoganbdb7ed82016-06-09 14:19:07 +0100673 u32 *opc,
Sanjay Lal740765c2012-11-21 18:34:00 -0800674 struct kvm_run *run,
675 struct kvm_vcpu *vcpu);
676
James Hogan31cf7492016-06-09 14:19:09 +0100677extern enum emulation_result kvm_mips_emulate_tlbmiss_ld(u32 cause,
James Hoganbdb7ed82016-06-09 14:19:07 +0100678 u32 *opc,
Sanjay Lal740765c2012-11-21 18:34:00 -0800679 struct kvm_run *run,
680 struct kvm_vcpu *vcpu);
681
James Hogan31cf7492016-06-09 14:19:09 +0100682extern enum emulation_result kvm_mips_emulate_tlbinv_ld(u32 cause,
James Hoganbdb7ed82016-06-09 14:19:07 +0100683 u32 *opc,
Sanjay Lal740765c2012-11-21 18:34:00 -0800684 struct kvm_run *run,
685 struct kvm_vcpu *vcpu);
686
James Hogan31cf7492016-06-09 14:19:09 +0100687extern enum emulation_result kvm_mips_emulate_tlbmiss_st(u32 cause,
James Hoganbdb7ed82016-06-09 14:19:07 +0100688 u32 *opc,
Sanjay Lal740765c2012-11-21 18:34:00 -0800689 struct kvm_run *run,
690 struct kvm_vcpu *vcpu);
691
James Hogan31cf7492016-06-09 14:19:09 +0100692extern enum emulation_result kvm_mips_emulate_tlbinv_st(u32 cause,
James Hoganbdb7ed82016-06-09 14:19:07 +0100693 u32 *opc,
Sanjay Lal740765c2012-11-21 18:34:00 -0800694 struct kvm_run *run,
695 struct kvm_vcpu *vcpu);
696
James Hogan31cf7492016-06-09 14:19:09 +0100697extern enum emulation_result kvm_mips_emulate_tlbmod(u32 cause,
James Hoganbdb7ed82016-06-09 14:19:07 +0100698 u32 *opc,
Sanjay Lal740765c2012-11-21 18:34:00 -0800699 struct kvm_run *run,
700 struct kvm_vcpu *vcpu);
701
James Hogan31cf7492016-06-09 14:19:09 +0100702extern enum emulation_result kvm_mips_emulate_fpu_exc(u32 cause,
James Hoganbdb7ed82016-06-09 14:19:07 +0100703 u32 *opc,
Sanjay Lal740765c2012-11-21 18:34:00 -0800704 struct kvm_run *run,
705 struct kvm_vcpu *vcpu);
706
James Hogan31cf7492016-06-09 14:19:09 +0100707extern enum emulation_result kvm_mips_handle_ri(u32 cause,
James Hoganbdb7ed82016-06-09 14:19:07 +0100708 u32 *opc,
Sanjay Lal740765c2012-11-21 18:34:00 -0800709 struct kvm_run *run,
710 struct kvm_vcpu *vcpu);
711
James Hogan31cf7492016-06-09 14:19:09 +0100712extern enum emulation_result kvm_mips_emulate_ri_exc(u32 cause,
James Hoganbdb7ed82016-06-09 14:19:07 +0100713 u32 *opc,
Sanjay Lal740765c2012-11-21 18:34:00 -0800714 struct kvm_run *run,
715 struct kvm_vcpu *vcpu);
716
James Hogan31cf7492016-06-09 14:19:09 +0100717extern enum emulation_result kvm_mips_emulate_bp_exc(u32 cause,
James Hoganbdb7ed82016-06-09 14:19:07 +0100718 u32 *opc,
Sanjay Lal740765c2012-11-21 18:34:00 -0800719 struct kvm_run *run,
720 struct kvm_vcpu *vcpu);
721
James Hogan31cf7492016-06-09 14:19:09 +0100722extern enum emulation_result kvm_mips_emulate_trap_exc(u32 cause,
James Hoganbdb7ed82016-06-09 14:19:07 +0100723 u32 *opc,
James Hogan0a560422015-02-06 16:03:57 +0000724 struct kvm_run *run,
725 struct kvm_vcpu *vcpu);
726
James Hogan31cf7492016-06-09 14:19:09 +0100727extern enum emulation_result kvm_mips_emulate_msafpe_exc(u32 cause,
James Hoganbdb7ed82016-06-09 14:19:07 +0100728 u32 *opc,
James Hoganc2537ed2015-02-06 10:56:27 +0000729 struct kvm_run *run,
730 struct kvm_vcpu *vcpu);
731
James Hogan31cf7492016-06-09 14:19:09 +0100732extern enum emulation_result kvm_mips_emulate_fpe_exc(u32 cause,
James Hoganbdb7ed82016-06-09 14:19:07 +0100733 u32 *opc,
James Hogan1c0cd662015-02-06 10:56:27 +0000734 struct kvm_run *run,
735 struct kvm_vcpu *vcpu);
736
James Hogan31cf7492016-06-09 14:19:09 +0100737extern enum emulation_result kvm_mips_emulate_msadis_exc(u32 cause,
James Hoganbdb7ed82016-06-09 14:19:07 +0100738 u32 *opc,
James Hoganc2537ed2015-02-06 10:56:27 +0000739 struct kvm_run *run,
740 struct kvm_vcpu *vcpu);
741
Sanjay Lal740765c2012-11-21 18:34:00 -0800742extern enum emulation_result kvm_mips_complete_mmio_load(struct kvm_vcpu *vcpu,
743 struct kvm_run *run);
744
James Hoganbdb7ed82016-06-09 14:19:07 +0100745u32 kvm_mips_read_count(struct kvm_vcpu *vcpu);
746void kvm_mips_write_count(struct kvm_vcpu *vcpu, u32 count);
747void kvm_mips_write_compare(struct kvm_vcpu *vcpu, u32 compare, bool ack);
James Hogane30492b2014-05-29 10:16:35 +0100748void kvm_mips_init_count(struct kvm_vcpu *vcpu);
James Hoganf8239342014-05-29 10:16:37 +0100749int kvm_mips_set_count_ctl(struct kvm_vcpu *vcpu, s64 count_ctl);
750int kvm_mips_set_count_resume(struct kvm_vcpu *vcpu, s64 count_resume);
James Hoganf74a8e22014-05-29 10:16:38 +0100751int kvm_mips_set_count_hz(struct kvm_vcpu *vcpu, s64 count_hz);
James Hogane30492b2014-05-29 10:16:35 +0100752void kvm_mips_count_enable_cause(struct kvm_vcpu *vcpu);
753void kvm_mips_count_disable_cause(struct kvm_vcpu *vcpu);
754enum hrtimer_restart kvm_mips_count_timeout(struct kvm_vcpu *vcpu);
Sanjay Lal740765c2012-11-21 18:34:00 -0800755
James Hogan31cf7492016-06-09 14:19:09 +0100756enum emulation_result kvm_mips_check_privilege(u32 cause,
James Hoganbdb7ed82016-06-09 14:19:07 +0100757 u32 *opc,
Sanjay Lal740765c2012-11-21 18:34:00 -0800758 struct kvm_run *run,
759 struct kvm_vcpu *vcpu);
760
James Hoganbdb7ed82016-06-09 14:19:07 +0100761enum emulation_result kvm_mips_emulate_cache(u32 inst,
762 u32 *opc,
763 u32 cause,
Sanjay Lal740765c2012-11-21 18:34:00 -0800764 struct kvm_run *run,
765 struct kvm_vcpu *vcpu);
James Hoganbdb7ed82016-06-09 14:19:07 +0100766enum emulation_result kvm_mips_emulate_CP0(u32 inst,
767 u32 *opc,
768 u32 cause,
Sanjay Lal740765c2012-11-21 18:34:00 -0800769 struct kvm_run *run,
770 struct kvm_vcpu *vcpu);
James Hoganbdb7ed82016-06-09 14:19:07 +0100771enum emulation_result kvm_mips_emulate_store(u32 inst,
772 u32 cause,
Sanjay Lal740765c2012-11-21 18:34:00 -0800773 struct kvm_run *run,
774 struct kvm_vcpu *vcpu);
James Hoganbdb7ed82016-06-09 14:19:07 +0100775enum emulation_result kvm_mips_emulate_load(u32 inst,
776 u32 cause,
Sanjay Lal740765c2012-11-21 18:34:00 -0800777 struct kvm_run *run,
778 struct kvm_vcpu *vcpu);
779
James Hoganc7716072014-06-26 15:11:29 +0100780unsigned int kvm_mips_config1_wrmask(struct kvm_vcpu *vcpu);
781unsigned int kvm_mips_config3_wrmask(struct kvm_vcpu *vcpu);
782unsigned int kvm_mips_config4_wrmask(struct kvm_vcpu *vcpu);
783unsigned int kvm_mips_config5_wrmask(struct kvm_vcpu *vcpu);
784
Sanjay Lal740765c2012-11-21 18:34:00 -0800785/* Dynamic binary translation */
James Hoganbdb7ed82016-06-09 14:19:07 +0100786extern int kvm_mips_trans_cache_index(u32 inst, u32 *opc,
Sanjay Lal740765c2012-11-21 18:34:00 -0800787 struct kvm_vcpu *vcpu);
James Hoganbdb7ed82016-06-09 14:19:07 +0100788extern int kvm_mips_trans_cache_va(u32 inst, u32 *opc, struct kvm_vcpu *vcpu);
789extern int kvm_mips_trans_mfc0(u32 inst, u32 *opc, struct kvm_vcpu *vcpu);
790extern int kvm_mips_trans_mtc0(u32 inst, u32 *opc, struct kvm_vcpu *vcpu);
Sanjay Lal740765c2012-11-21 18:34:00 -0800791
792/* Misc */
Deng-Cheng Zhud98403a2014-06-26 12:11:36 -0700793extern void kvm_mips_dump_stats(struct kvm_vcpu *vcpu);
Sanjay Lal740765c2012-11-21 18:34:00 -0800794extern unsigned long kvm_mips_get_ramsize(struct kvm *kvm);
795
Radim Krčmář13a34e02014-08-28 15:13:03 +0200796static inline void kvm_arch_hardware_disable(void) {}
Radim Krčmář0865e632014-08-28 15:13:02 +0200797static inline void kvm_arch_hardware_unsetup(void) {}
798static inline void kvm_arch_sync_events(struct kvm *kvm) {}
799static inline void kvm_arch_free_memslot(struct kvm *kvm,
800 struct kvm_memory_slot *free, struct kvm_memory_slot *dont) {}
Paolo Bonzini15f46012015-05-17 21:26:08 +0200801static inline void kvm_arch_memslots_updated(struct kvm *kvm, struct kvm_memslots *slots) {}
Radim Krčmář0865e632014-08-28 15:13:02 +0200802static inline void kvm_arch_flush_shadow_all(struct kvm *kvm) {}
803static inline void kvm_arch_flush_shadow_memslot(struct kvm *kvm,
804 struct kvm_memory_slot *slot) {}
805static inline void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu) {}
806static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {}
Christoffer Dall3217f7c2015-08-27 16:41:15 +0200807static inline void kvm_arch_vcpu_blocking(struct kvm_vcpu *vcpu) {}
808static inline void kvm_arch_vcpu_unblocking(struct kvm_vcpu *vcpu) {}
Christian Borntraeger3491caf2016-05-13 12:16:35 +0200809static inline void kvm_arch_vcpu_block_finish(struct kvm_vcpu *vcpu) {}
Sanjay Lal740765c2012-11-21 18:34:00 -0800810
811#endif /* __MIPS_KVM_HOST_H__ */