162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Copyright IBM Corp. 2008
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci * Authors: Hollis Blanchard <hollisb@us.ibm.com>
762306a36Sopenharmony_ci */
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#ifndef __POWERPC_KVM_ASM_H__
1062306a36Sopenharmony_ci#define __POWERPC_KVM_ASM_H__
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci#ifdef __ASSEMBLY__
1362306a36Sopenharmony_ci#ifdef CONFIG_64BIT
1462306a36Sopenharmony_ci#define PPC_STD(sreg, offset, areg)  std sreg, (offset)(areg)
1562306a36Sopenharmony_ci#define PPC_LD(treg, offset, areg)   ld treg, (offset)(areg)
1662306a36Sopenharmony_ci#else
1762306a36Sopenharmony_ci#define PPC_STD(sreg, offset, areg)  stw sreg, (offset+4)(areg)
1862306a36Sopenharmony_ci#define PPC_LD(treg, offset, areg)   lwz treg, (offset+4)(areg)
1962306a36Sopenharmony_ci#endif
2062306a36Sopenharmony_ci#endif
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci/* IVPR must be 64KiB-aligned. */
2362306a36Sopenharmony_ci#define VCPU_SIZE_ORDER 4
2462306a36Sopenharmony_ci#define VCPU_SIZE_LOG   (VCPU_SIZE_ORDER + 12)
2562306a36Sopenharmony_ci#define VCPU_SIZE_BYTES (1<<VCPU_SIZE_LOG)
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ci#define BOOKE_INTERRUPT_CRITICAL 0
2862306a36Sopenharmony_ci#define BOOKE_INTERRUPT_MACHINE_CHECK 1
2962306a36Sopenharmony_ci#define BOOKE_INTERRUPT_DATA_STORAGE 2
3062306a36Sopenharmony_ci#define BOOKE_INTERRUPT_INST_STORAGE 3
3162306a36Sopenharmony_ci#define BOOKE_INTERRUPT_EXTERNAL 4
3262306a36Sopenharmony_ci#define BOOKE_INTERRUPT_ALIGNMENT 5
3362306a36Sopenharmony_ci#define BOOKE_INTERRUPT_PROGRAM 6
3462306a36Sopenharmony_ci#define BOOKE_INTERRUPT_FP_UNAVAIL 7
3562306a36Sopenharmony_ci#define BOOKE_INTERRUPT_SYSCALL 8
3662306a36Sopenharmony_ci#define BOOKE_INTERRUPT_AP_UNAVAIL 9
3762306a36Sopenharmony_ci#define BOOKE_INTERRUPT_DECREMENTER 10
3862306a36Sopenharmony_ci#define BOOKE_INTERRUPT_FIT 11
3962306a36Sopenharmony_ci#define BOOKE_INTERRUPT_WATCHDOG 12
4062306a36Sopenharmony_ci#define BOOKE_INTERRUPT_DTLB_MISS 13
4162306a36Sopenharmony_ci#define BOOKE_INTERRUPT_ITLB_MISS 14
4262306a36Sopenharmony_ci#define BOOKE_INTERRUPT_DEBUG 15
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ci/* E500 */
4562306a36Sopenharmony_ci#ifdef CONFIG_SPE_POSSIBLE
4662306a36Sopenharmony_ci#define BOOKE_INTERRUPT_SPE_UNAVAIL 32
4762306a36Sopenharmony_ci#define BOOKE_INTERRUPT_SPE_FP_DATA 33
4862306a36Sopenharmony_ci#define BOOKE_INTERRUPT_SPE_FP_ROUND 34
4962306a36Sopenharmony_ci#endif
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ci#ifdef CONFIG_PPC_E500MC
5262306a36Sopenharmony_ci#define BOOKE_INTERRUPT_ALTIVEC_UNAVAIL 32
5362306a36Sopenharmony_ci#define BOOKE_INTERRUPT_ALTIVEC_ASSIST 33
5462306a36Sopenharmony_ci#endif
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_ci#define BOOKE_INTERRUPT_PERFORMANCE_MONITOR 35
5762306a36Sopenharmony_ci#define BOOKE_INTERRUPT_DOORBELL 36
5862306a36Sopenharmony_ci#define BOOKE_INTERRUPT_DOORBELL_CRITICAL 37
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ci/* booke_hv */
6162306a36Sopenharmony_ci#define BOOKE_INTERRUPT_GUEST_DBELL 38
6262306a36Sopenharmony_ci#define BOOKE_INTERRUPT_GUEST_DBELL_CRIT 39
6362306a36Sopenharmony_ci#define BOOKE_INTERRUPT_HV_SYSCALL 40
6462306a36Sopenharmony_ci#define BOOKE_INTERRUPT_HV_PRIV 41
6562306a36Sopenharmony_ci#define BOOKE_INTERRUPT_LRAT_ERROR 42
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ci/* book3s */
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ci#define BOOK3S_INTERRUPT_SYSTEM_RESET	0x100
7062306a36Sopenharmony_ci#define BOOK3S_INTERRUPT_MACHINE_CHECK	0x200
7162306a36Sopenharmony_ci#define BOOK3S_INTERRUPT_DATA_STORAGE	0x300
7262306a36Sopenharmony_ci#define BOOK3S_INTERRUPT_DATA_SEGMENT	0x380
7362306a36Sopenharmony_ci#define BOOK3S_INTERRUPT_INST_STORAGE	0x400
7462306a36Sopenharmony_ci#define BOOK3S_INTERRUPT_INST_SEGMENT	0x480
7562306a36Sopenharmony_ci#define BOOK3S_INTERRUPT_EXTERNAL	0x500
7662306a36Sopenharmony_ci#define BOOK3S_INTERRUPT_EXTERNAL_HV	0x502
7762306a36Sopenharmony_ci#define BOOK3S_INTERRUPT_ALIGNMENT	0x600
7862306a36Sopenharmony_ci#define BOOK3S_INTERRUPT_PROGRAM	0x700
7962306a36Sopenharmony_ci#define BOOK3S_INTERRUPT_FP_UNAVAIL	0x800
8062306a36Sopenharmony_ci#define BOOK3S_INTERRUPT_DECREMENTER	0x900
8162306a36Sopenharmony_ci#define BOOK3S_INTERRUPT_HV_DECREMENTER	0x980
8262306a36Sopenharmony_ci#define BOOK3S_INTERRUPT_NESTED_HV_DECREMENTER	0x1980
8362306a36Sopenharmony_ci#define BOOK3S_INTERRUPT_DOORBELL	0xa00
8462306a36Sopenharmony_ci#define BOOK3S_INTERRUPT_SYSCALL	0xc00
8562306a36Sopenharmony_ci#define BOOK3S_INTERRUPT_TRACE		0xd00
8662306a36Sopenharmony_ci#define BOOK3S_INTERRUPT_H_DATA_STORAGE	0xe00
8762306a36Sopenharmony_ci#define BOOK3S_INTERRUPT_H_INST_STORAGE	0xe20
8862306a36Sopenharmony_ci#define BOOK3S_INTERRUPT_H_EMUL_ASSIST	0xe40
8962306a36Sopenharmony_ci#define BOOK3S_INTERRUPT_HMI		0xe60
9062306a36Sopenharmony_ci#define BOOK3S_INTERRUPT_H_DOORBELL	0xe80
9162306a36Sopenharmony_ci#define BOOK3S_INTERRUPT_H_VIRT		0xea0
9262306a36Sopenharmony_ci#define BOOK3S_INTERRUPT_PERFMON	0xf00
9362306a36Sopenharmony_ci#define BOOK3S_INTERRUPT_ALTIVEC	0xf20
9462306a36Sopenharmony_ci#define BOOK3S_INTERRUPT_VSX		0xf40
9562306a36Sopenharmony_ci#define BOOK3S_INTERRUPT_FAC_UNAVAIL	0xf60
9662306a36Sopenharmony_ci#define BOOK3S_INTERRUPT_H_FAC_UNAVAIL	0xf80
9762306a36Sopenharmony_ci
9862306a36Sopenharmony_ci/* book3s_hv */
9962306a36Sopenharmony_ci
10062306a36Sopenharmony_ci#define BOOK3S_INTERRUPT_HV_SOFTPATCH	0x1500
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_ci/*
10362306a36Sopenharmony_ci * Special trap used to indicate to host that this is a
10462306a36Sopenharmony_ci * passthrough interrupt that could not be handled
10562306a36Sopenharmony_ci * completely in the guest.
10662306a36Sopenharmony_ci */
10762306a36Sopenharmony_ci#define BOOK3S_INTERRUPT_HV_RM_HARD	0x5555
10862306a36Sopenharmony_ci
10962306a36Sopenharmony_ci#define BOOK3S_IRQPRIO_SYSTEM_RESET		0
11062306a36Sopenharmony_ci#define BOOK3S_IRQPRIO_DATA_SEGMENT		1
11162306a36Sopenharmony_ci#define BOOK3S_IRQPRIO_INST_SEGMENT		2
11262306a36Sopenharmony_ci#define BOOK3S_IRQPRIO_DATA_STORAGE		3
11362306a36Sopenharmony_ci#define BOOK3S_IRQPRIO_INST_STORAGE		4
11462306a36Sopenharmony_ci#define BOOK3S_IRQPRIO_ALIGNMENT		5
11562306a36Sopenharmony_ci#define BOOK3S_IRQPRIO_PROGRAM			6
11662306a36Sopenharmony_ci#define BOOK3S_IRQPRIO_FP_UNAVAIL		7
11762306a36Sopenharmony_ci#define BOOK3S_IRQPRIO_ALTIVEC			8
11862306a36Sopenharmony_ci#define BOOK3S_IRQPRIO_VSX			9
11962306a36Sopenharmony_ci#define BOOK3S_IRQPRIO_FAC_UNAVAIL		10
12062306a36Sopenharmony_ci#define BOOK3S_IRQPRIO_SYSCALL			11
12162306a36Sopenharmony_ci#define BOOK3S_IRQPRIO_MACHINE_CHECK		12
12262306a36Sopenharmony_ci#define BOOK3S_IRQPRIO_DEBUG			13
12362306a36Sopenharmony_ci#define BOOK3S_IRQPRIO_EXTERNAL			14
12462306a36Sopenharmony_ci#define BOOK3S_IRQPRIO_DECREMENTER		15
12562306a36Sopenharmony_ci#define BOOK3S_IRQPRIO_PERFORMANCE_MONITOR	16
12662306a36Sopenharmony_ci#define BOOK3S_IRQPRIO_MAX			17
12762306a36Sopenharmony_ci
12862306a36Sopenharmony_ci#define BOOK3S_HFLAG_DCBZ32			0x1
12962306a36Sopenharmony_ci#define BOOK3S_HFLAG_SLB			0x2
13062306a36Sopenharmony_ci#define BOOK3S_HFLAG_PAIRED_SINGLE		0x4
13162306a36Sopenharmony_ci#define BOOK3S_HFLAG_NATIVE_PS			0x8
13262306a36Sopenharmony_ci#define BOOK3S_HFLAG_MULTI_PGSIZE		0x10
13362306a36Sopenharmony_ci#define BOOK3S_HFLAG_NEW_TLBIE			0x20
13462306a36Sopenharmony_ci#define BOOK3S_HFLAG_SPLIT_HACK			0x40
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_ci#define RESUME_FLAG_NV          (1<<0)  /* Reload guest nonvolatile state? */
13762306a36Sopenharmony_ci#define RESUME_FLAG_HOST        (1<<1)  /* Resume host? */
13862306a36Sopenharmony_ci#define RESUME_FLAG_ARCH1	(1<<2)
13962306a36Sopenharmony_ci#define RESUME_FLAG_ARCH2	(1<<3)
14062306a36Sopenharmony_ci
14162306a36Sopenharmony_ci#define RESUME_GUEST            0
14262306a36Sopenharmony_ci#define RESUME_GUEST_NV         RESUME_FLAG_NV
14362306a36Sopenharmony_ci#define RESUME_HOST             RESUME_FLAG_HOST
14462306a36Sopenharmony_ci#define RESUME_HOST_NV          (RESUME_FLAG_HOST|RESUME_FLAG_NV)
14562306a36Sopenharmony_ci
14662306a36Sopenharmony_ci#define KVM_GUEST_MODE_NONE	0
14762306a36Sopenharmony_ci#define KVM_GUEST_MODE_GUEST	1
14862306a36Sopenharmony_ci#define KVM_GUEST_MODE_SKIP	2
14962306a36Sopenharmony_ci#define KVM_GUEST_MODE_GUEST_HV	3
15062306a36Sopenharmony_ci#define KVM_GUEST_MODE_HOST_HV	4
15162306a36Sopenharmony_ci#define KVM_GUEST_MODE_HV_P9	5 /* ISA >= v3.0 path */
15262306a36Sopenharmony_ci
15362306a36Sopenharmony_ci#define KVM_INST_FETCH_FAILED	-1
15462306a36Sopenharmony_ci
15562306a36Sopenharmony_ci/* Extract PO and XOP opcode fields */
15662306a36Sopenharmony_ci#define PO_XOP_OPCODE_MASK 0xfc0007fe
15762306a36Sopenharmony_ci
15862306a36Sopenharmony_ci#endif /* __POWERPC_KVM_ASM_H__ */
159