xref: /kvmtool/mips/include/asm/kvm.h (revision 1bbe92f568513662589b1a159be01fd27f8bf27d)
1*1bbe92f5SDave Martin /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
260021220SAndre Przywara /*
360021220SAndre Przywara  * This file is subject to the terms and conditions of the GNU General Public
460021220SAndre Przywara  * License.  See the file "COPYING" in the main directory of this archive
560021220SAndre Przywara  * for more details.
660021220SAndre Przywara  *
760021220SAndre Przywara  * Copyright (C) 2012  MIPS Technologies, Inc.  All rights reserved.
860021220SAndre Przywara  * Copyright (C) 2013 Cavium, Inc.
960021220SAndre Przywara  * Authors: Sanjay Lal <sanjayl@kymasys.com>
1060021220SAndre Przywara  */
1160021220SAndre Przywara 
1260021220SAndre Przywara #ifndef __LINUX_KVM_MIPS_H
1360021220SAndre Przywara #define __LINUX_KVM_MIPS_H
1460021220SAndre Przywara 
1560021220SAndre Przywara #include <linux/types.h>
1660021220SAndre Przywara 
1760021220SAndre Przywara /*
1860021220SAndre Przywara  * KVM MIPS specific structures and definitions.
1960021220SAndre Przywara  *
2060021220SAndre Przywara  * Some parts derived from the x86 version of this file.
2160021220SAndre Przywara  */
2260021220SAndre Przywara 
23764dfba1SAndre Przywara #define __KVM_HAVE_READONLY_MEM
24764dfba1SAndre Przywara 
25*1bbe92f5SDave Martin #define KVM_COALESCED_MMIO_PAGE_OFFSET 1
26*1bbe92f5SDave Martin 
2760021220SAndre Przywara /*
2860021220SAndre Przywara  * for KVM_GET_REGS and KVM_SET_REGS
2960021220SAndre Przywara  *
3060021220SAndre Przywara  * If Config[AT] is zero (32-bit CPU), the register contents are
3160021220SAndre Przywara  * stored in the lower 32-bits of the struct kvm_regs fields and sign
3260021220SAndre Przywara  * extended to 64-bits.
3360021220SAndre Przywara  */
3460021220SAndre Przywara struct kvm_regs {
3560021220SAndre Przywara 	/* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
3660021220SAndre Przywara 	__u64 gpr[32];
3760021220SAndre Przywara 	__u64 hi;
3860021220SAndre Przywara 	__u64 lo;
3960021220SAndre Przywara 	__u64 pc;
4060021220SAndre Przywara };
4160021220SAndre Przywara 
4260021220SAndre Przywara /*
4360021220SAndre Przywara  * for KVM_GET_FPU and KVM_SET_FPU
4460021220SAndre Przywara  */
4560021220SAndre Przywara struct kvm_fpu {
4660021220SAndre Przywara };
4760021220SAndre Przywara 
4860021220SAndre Przywara 
4960021220SAndre Przywara /*
5060021220SAndre Przywara  * For MIPS, we use KVM_SET_ONE_REG and KVM_GET_ONE_REG to access various
5160021220SAndre Przywara  * registers.  The id field is broken down as follows:
5260021220SAndre Przywara  *
5360021220SAndre Przywara  *  bits[63..52] - As per linux/kvm.h
5460021220SAndre Przywara  *  bits[51..32] - Must be zero.
5560021220SAndre Przywara  *  bits[31..16] - Register set.
5660021220SAndre Przywara  *
5760021220SAndre Przywara  * Register set = 0: GP registers from kvm_regs (see definitions below).
5860021220SAndre Przywara  *
5960021220SAndre Przywara  * Register set = 1: CP0 registers.
60*1bbe92f5SDave Martin  *  bits[15..8]  - COP0 register set.
61*1bbe92f5SDave Martin  *
62*1bbe92f5SDave Martin  *  COP0 register set = 0: Main CP0 registers.
6360021220SAndre Przywara  *   bits[7..3]   - Register 'rd'  index.
6460021220SAndre Przywara  *   bits[2..0]   - Register 'sel' index.
6560021220SAndre Przywara  *
66*1bbe92f5SDave Martin  *  COP0 register set = 1: MAARs.
67*1bbe92f5SDave Martin  *   bits[7..0]   - MAAR index.
68*1bbe92f5SDave Martin  *
6960021220SAndre Przywara  * Register set = 2: KVM specific registers (see definitions below).
7060021220SAndre Przywara  *
7160021220SAndre Przywara  * Register set = 3: FPU / MSA registers (see definitions below).
7260021220SAndre Przywara  *
7360021220SAndre Przywara  * Other sets registers may be added in the future.  Each set would
7460021220SAndre Przywara  * have its own identifier in bits[31..16].
7560021220SAndre Przywara  */
7660021220SAndre Przywara 
7760021220SAndre Przywara #define KVM_REG_MIPS_GP		(KVM_REG_MIPS | 0x0000000000000000ULL)
7860021220SAndre Przywara #define KVM_REG_MIPS_CP0	(KVM_REG_MIPS | 0x0000000000010000ULL)
7960021220SAndre Przywara #define KVM_REG_MIPS_KVM	(KVM_REG_MIPS | 0x0000000000020000ULL)
8060021220SAndre Przywara #define KVM_REG_MIPS_FPU	(KVM_REG_MIPS | 0x0000000000030000ULL)
8160021220SAndre Przywara 
8260021220SAndre Przywara 
8360021220SAndre Przywara /*
8460021220SAndre Przywara  * KVM_REG_MIPS_GP - General purpose registers from kvm_regs.
8560021220SAndre Przywara  */
8660021220SAndre Przywara 
8760021220SAndre Przywara #define KVM_REG_MIPS_R0		(KVM_REG_MIPS_GP | KVM_REG_SIZE_U64 |  0)
8860021220SAndre Przywara #define KVM_REG_MIPS_R1		(KVM_REG_MIPS_GP | KVM_REG_SIZE_U64 |  1)
8960021220SAndre Przywara #define KVM_REG_MIPS_R2		(KVM_REG_MIPS_GP | KVM_REG_SIZE_U64 |  2)
9060021220SAndre Przywara #define KVM_REG_MIPS_R3		(KVM_REG_MIPS_GP | KVM_REG_SIZE_U64 |  3)
9160021220SAndre Przywara #define KVM_REG_MIPS_R4		(KVM_REG_MIPS_GP | KVM_REG_SIZE_U64 |  4)
9260021220SAndre Przywara #define KVM_REG_MIPS_R5		(KVM_REG_MIPS_GP | KVM_REG_SIZE_U64 |  5)
9360021220SAndre Przywara #define KVM_REG_MIPS_R6		(KVM_REG_MIPS_GP | KVM_REG_SIZE_U64 |  6)
9460021220SAndre Przywara #define KVM_REG_MIPS_R7		(KVM_REG_MIPS_GP | KVM_REG_SIZE_U64 |  7)
9560021220SAndre Przywara #define KVM_REG_MIPS_R8		(KVM_REG_MIPS_GP | KVM_REG_SIZE_U64 |  8)
9660021220SAndre Przywara #define KVM_REG_MIPS_R9		(KVM_REG_MIPS_GP | KVM_REG_SIZE_U64 |  9)
9760021220SAndre Przywara #define KVM_REG_MIPS_R10	(KVM_REG_MIPS_GP | KVM_REG_SIZE_U64 | 10)
9860021220SAndre Przywara #define KVM_REG_MIPS_R11	(KVM_REG_MIPS_GP | KVM_REG_SIZE_U64 | 11)
9960021220SAndre Przywara #define KVM_REG_MIPS_R12	(KVM_REG_MIPS_GP | KVM_REG_SIZE_U64 | 12)
10060021220SAndre Przywara #define KVM_REG_MIPS_R13	(KVM_REG_MIPS_GP | KVM_REG_SIZE_U64 | 13)
10160021220SAndre Przywara #define KVM_REG_MIPS_R14	(KVM_REG_MIPS_GP | KVM_REG_SIZE_U64 | 14)
10260021220SAndre Przywara #define KVM_REG_MIPS_R15	(KVM_REG_MIPS_GP | KVM_REG_SIZE_U64 | 15)
10360021220SAndre Przywara #define KVM_REG_MIPS_R16	(KVM_REG_MIPS_GP | KVM_REG_SIZE_U64 | 16)
10460021220SAndre Przywara #define KVM_REG_MIPS_R17	(KVM_REG_MIPS_GP | KVM_REG_SIZE_U64 | 17)
10560021220SAndre Przywara #define KVM_REG_MIPS_R18	(KVM_REG_MIPS_GP | KVM_REG_SIZE_U64 | 18)
10660021220SAndre Przywara #define KVM_REG_MIPS_R19	(KVM_REG_MIPS_GP | KVM_REG_SIZE_U64 | 19)
10760021220SAndre Przywara #define KVM_REG_MIPS_R20	(KVM_REG_MIPS_GP | KVM_REG_SIZE_U64 | 20)
10860021220SAndre Przywara #define KVM_REG_MIPS_R21	(KVM_REG_MIPS_GP | KVM_REG_SIZE_U64 | 21)
10960021220SAndre Przywara #define KVM_REG_MIPS_R22	(KVM_REG_MIPS_GP | KVM_REG_SIZE_U64 | 22)
11060021220SAndre Przywara #define KVM_REG_MIPS_R23	(KVM_REG_MIPS_GP | KVM_REG_SIZE_U64 | 23)
11160021220SAndre Przywara #define KVM_REG_MIPS_R24	(KVM_REG_MIPS_GP | KVM_REG_SIZE_U64 | 24)
11260021220SAndre Przywara #define KVM_REG_MIPS_R25	(KVM_REG_MIPS_GP | KVM_REG_SIZE_U64 | 25)
11360021220SAndre Przywara #define KVM_REG_MIPS_R26	(KVM_REG_MIPS_GP | KVM_REG_SIZE_U64 | 26)
11460021220SAndre Przywara #define KVM_REG_MIPS_R27	(KVM_REG_MIPS_GP | KVM_REG_SIZE_U64 | 27)
11560021220SAndre Przywara #define KVM_REG_MIPS_R28	(KVM_REG_MIPS_GP | KVM_REG_SIZE_U64 | 28)
11660021220SAndre Przywara #define KVM_REG_MIPS_R29	(KVM_REG_MIPS_GP | KVM_REG_SIZE_U64 | 29)
11760021220SAndre Przywara #define KVM_REG_MIPS_R30	(KVM_REG_MIPS_GP | KVM_REG_SIZE_U64 | 30)
11860021220SAndre Przywara #define KVM_REG_MIPS_R31	(KVM_REG_MIPS_GP | KVM_REG_SIZE_U64 | 31)
11960021220SAndre Przywara 
12060021220SAndre Przywara #define KVM_REG_MIPS_HI		(KVM_REG_MIPS_GP | KVM_REG_SIZE_U64 | 32)
12160021220SAndre Przywara #define KVM_REG_MIPS_LO		(KVM_REG_MIPS_GP | KVM_REG_SIZE_U64 | 33)
12260021220SAndre Przywara #define KVM_REG_MIPS_PC		(KVM_REG_MIPS_GP | KVM_REG_SIZE_U64 | 34)
12360021220SAndre Przywara 
12460021220SAndre Przywara 
12560021220SAndre Przywara /*
126*1bbe92f5SDave Martin  * KVM_REG_MIPS_CP0 - Coprocessor 0 registers.
127*1bbe92f5SDave Martin  */
128*1bbe92f5SDave Martin 
129*1bbe92f5SDave Martin #define KVM_REG_MIPS_MAAR	(KVM_REG_MIPS_CP0 | (1 << 8))
130*1bbe92f5SDave Martin #define KVM_REG_MIPS_CP0_MAAR(n)	(KVM_REG_MIPS_MAAR | \
131*1bbe92f5SDave Martin 					 KVM_REG_SIZE_U64 | (n))
132*1bbe92f5SDave Martin 
133*1bbe92f5SDave Martin 
134*1bbe92f5SDave Martin /*
13560021220SAndre Przywara  * KVM_REG_MIPS_KVM - KVM specific control registers.
13660021220SAndre Przywara  */
13760021220SAndre Przywara 
13860021220SAndre Przywara /*
13960021220SAndre Przywara  * CP0_Count control
14060021220SAndre Przywara  * DC:    Set 0: Master disable CP0_Count and set COUNT_RESUME to now
14160021220SAndre Przywara  *        Set 1: Master re-enable CP0_Count with unchanged bias, handling timer
14260021220SAndre Przywara  *               interrupts since COUNT_RESUME
14360021220SAndre Przywara  *        This can be used to freeze the timer to get a consistent snapshot of
14460021220SAndre Przywara  *        the CP0_Count and timer interrupt pending state, while also resuming
14560021220SAndre Przywara  *        safely without losing time or guest timer interrupts.
14660021220SAndre Przywara  * Other: Reserved, do not change.
14760021220SAndre Przywara  */
14860021220SAndre Przywara #define KVM_REG_MIPS_COUNT_CTL	    (KVM_REG_MIPS_KVM | KVM_REG_SIZE_U64 | 0)
14960021220SAndre Przywara #define KVM_REG_MIPS_COUNT_CTL_DC	0x00000001
15060021220SAndre Przywara 
15160021220SAndre Przywara /*
15260021220SAndre Przywara  * CP0_Count resume monotonic nanoseconds
15360021220SAndre Przywara  * The monotonic nanosecond time of the last set of COUNT_CTL.DC (master
15460021220SAndre Przywara  * disable). Any reads and writes of Count related registers while
15560021220SAndre Przywara  * COUNT_CTL.DC=1 will appear to occur at this time. When COUNT_CTL.DC is
15660021220SAndre Przywara  * cleared again (master enable) any timer interrupts since this time will be
15760021220SAndre Przywara  * emulated.
15860021220SAndre Przywara  * Modifications to times in the future are rejected.
15960021220SAndre Przywara  */
16060021220SAndre Przywara #define KVM_REG_MIPS_COUNT_RESUME   (KVM_REG_MIPS_KVM | KVM_REG_SIZE_U64 | 1)
16160021220SAndre Przywara /*
16260021220SAndre Przywara  * CP0_Count rate in Hz
16360021220SAndre Przywara  * Specifies the rate of the CP0_Count timer in Hz. Modifications occur without
16460021220SAndre Przywara  * discontinuities in CP0_Count.
16560021220SAndre Przywara  */
16660021220SAndre Przywara #define KVM_REG_MIPS_COUNT_HZ	    (KVM_REG_MIPS_KVM | KVM_REG_SIZE_U64 | 2)
16760021220SAndre Przywara 
16860021220SAndre Przywara 
16960021220SAndre Przywara /*
17060021220SAndre Przywara  * KVM_REG_MIPS_FPU - Floating Point and MIPS SIMD Architecture (MSA) registers.
17160021220SAndre Przywara  *
17260021220SAndre Przywara  *  bits[15..8]  - Register subset (see definitions below).
17360021220SAndre Przywara  *  bits[7..5]   - Must be zero.
17460021220SAndre Przywara  *  bits[4..0]   - Register number within register subset.
17560021220SAndre Przywara  */
17660021220SAndre Przywara 
17760021220SAndre Przywara #define KVM_REG_MIPS_FPR	(KVM_REG_MIPS_FPU | 0x0000000000000000ULL)
17860021220SAndre Przywara #define KVM_REG_MIPS_FCR	(KVM_REG_MIPS_FPU | 0x0000000000000100ULL)
17960021220SAndre Przywara #define KVM_REG_MIPS_MSACR	(KVM_REG_MIPS_FPU | 0x0000000000000200ULL)
18060021220SAndre Przywara 
18160021220SAndre Przywara /*
18260021220SAndre Przywara  * KVM_REG_MIPS_FPR - Floating point / Vector registers.
18360021220SAndre Przywara  */
18460021220SAndre Przywara #define KVM_REG_MIPS_FPR_32(n)	(KVM_REG_MIPS_FPR | KVM_REG_SIZE_U32  | (n))
18560021220SAndre Przywara #define KVM_REG_MIPS_FPR_64(n)	(KVM_REG_MIPS_FPR | KVM_REG_SIZE_U64  | (n))
18660021220SAndre Przywara #define KVM_REG_MIPS_VEC_128(n)	(KVM_REG_MIPS_FPR | KVM_REG_SIZE_U128 | (n))
18760021220SAndre Przywara 
18860021220SAndre Przywara /*
18960021220SAndre Przywara  * KVM_REG_MIPS_FCR - Floating point control registers.
19060021220SAndre Przywara  */
19160021220SAndre Przywara #define KVM_REG_MIPS_FCR_IR	(KVM_REG_MIPS_FCR | KVM_REG_SIZE_U32 |  0)
19260021220SAndre Przywara #define KVM_REG_MIPS_FCR_CSR	(KVM_REG_MIPS_FCR | KVM_REG_SIZE_U32 | 31)
19360021220SAndre Przywara 
19460021220SAndre Przywara /*
19560021220SAndre Przywara  * KVM_REG_MIPS_MSACR - MIPS SIMD Architecture (MSA) control registers.
19660021220SAndre Przywara  */
19760021220SAndre Przywara #define KVM_REG_MIPS_MSA_IR	 (KVM_REG_MIPS_MSACR | KVM_REG_SIZE_U32 |  0)
19860021220SAndre Przywara #define KVM_REG_MIPS_MSA_CSR	 (KVM_REG_MIPS_MSACR | KVM_REG_SIZE_U32 |  1)
19960021220SAndre Przywara 
20060021220SAndre Przywara 
20160021220SAndre Przywara /*
20260021220SAndre Przywara  * KVM MIPS specific structures and definitions
20360021220SAndre Przywara  *
20460021220SAndre Przywara  */
20560021220SAndre Przywara struct kvm_debug_exit_arch {
20660021220SAndre Przywara 	__u64 epc;
20760021220SAndre Przywara };
20860021220SAndre Przywara 
20960021220SAndre Przywara /* for KVM_SET_GUEST_DEBUG */
21060021220SAndre Przywara struct kvm_guest_debug_arch {
21160021220SAndre Przywara };
21260021220SAndre Przywara 
21360021220SAndre Przywara /* definition of registers in kvm_run */
21460021220SAndre Przywara struct kvm_sync_regs {
21560021220SAndre Przywara };
21660021220SAndre Przywara 
21760021220SAndre Przywara /* dummy definition */
21860021220SAndre Przywara struct kvm_sregs {
21960021220SAndre Przywara };
22060021220SAndre Przywara 
22160021220SAndre Przywara struct kvm_mips_interrupt {
22260021220SAndre Przywara 	/* in */
22360021220SAndre Przywara 	__u32 cpu;
22460021220SAndre Przywara 	__u32 irq;
22560021220SAndre Przywara };
22660021220SAndre Przywara 
22760021220SAndre Przywara #endif /* __LINUX_KVM_MIPS_H */
228