1d94d71cbSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
275f74f0dSHollis Blanchard /*
375f74f0dSHollis Blanchard *
475f74f0dSHollis Blanchard * Copyright IBM Corp. 2008
575f74f0dSHollis Blanchard *
675f74f0dSHollis Blanchard * Authors: Hollis Blanchard <hollisb@us.ibm.com>
775f74f0dSHollis Blanchard */
875f74f0dSHollis Blanchard
975f74f0dSHollis Blanchard #ifndef __KVM_BOOKE_H__
1075f74f0dSHollis Blanchard #define __KVM_BOOKE_H__
1175f74f0dSHollis Blanchard
1275f74f0dSHollis Blanchard #include <linux/types.h>
1375f74f0dSHollis Blanchard #include <linux/kvm_host.h>
14d0c7dc03SHollis Blanchard #include <asm/kvm_ppc.h>
158fae845fSScott Wood #include <asm/switch_to.h>
1673e75b41SHollis Blanchard #include "timing.h"
1775f74f0dSHollis Blanchard
18d4cf3892SHollis Blanchard /* interrupt priortity ordering */
19d4cf3892SHollis Blanchard #define BOOKE_IRQPRIO_DATA_STORAGE 0
20d4cf3892SHollis Blanchard #define BOOKE_IRQPRIO_INST_STORAGE 1
21d4cf3892SHollis Blanchard #define BOOKE_IRQPRIO_ALIGNMENT 2
22d4cf3892SHollis Blanchard #define BOOKE_IRQPRIO_PROGRAM 3
23d4cf3892SHollis Blanchard #define BOOKE_IRQPRIO_FP_UNAVAIL 4
2495d80a29SMihai Caraman #ifdef CONFIG_SPE_POSSIBLE
25bb3a8a17SHollis Blanchard #define BOOKE_IRQPRIO_SPE_UNAVAIL 5
26bb3a8a17SHollis Blanchard #define BOOKE_IRQPRIO_SPE_FP_DATA 6
27bb3a8a17SHollis Blanchard #define BOOKE_IRQPRIO_SPE_FP_ROUND 7
2895d80a29SMihai Caraman #endif
2995d80a29SMihai Caraman #ifdef CONFIG_PPC_E500MC
3095d80a29SMihai Caraman #define BOOKE_IRQPRIO_ALTIVEC_UNAVAIL 5
3195d80a29SMihai Caraman #define BOOKE_IRQPRIO_ALTIVEC_ASSIST 6
3295d80a29SMihai Caraman #endif
33bb3a8a17SHollis Blanchard #define BOOKE_IRQPRIO_SYSCALL 8
34bb3a8a17SHollis Blanchard #define BOOKE_IRQPRIO_AP_UNAVAIL 9
35bb3a8a17SHollis Blanchard #define BOOKE_IRQPRIO_DTLB_MISS 10
36bb3a8a17SHollis Blanchard #define BOOKE_IRQPRIO_ITLB_MISS 11
37bb3a8a17SHollis Blanchard #define BOOKE_IRQPRIO_MACHINE_CHECK 12
38bb3a8a17SHollis Blanchard #define BOOKE_IRQPRIO_DEBUG 13
39bb3a8a17SHollis Blanchard #define BOOKE_IRQPRIO_CRITICAL 14
40bb3a8a17SHollis Blanchard #define BOOKE_IRQPRIO_WATCHDOG 15
41bb3a8a17SHollis Blanchard #define BOOKE_IRQPRIO_EXTERNAL 16
42bb3a8a17SHollis Blanchard #define BOOKE_IRQPRIO_FIT 17
43bb3a8a17SHollis Blanchard #define BOOKE_IRQPRIO_DECREMENTER 18
44bb3a8a17SHollis Blanchard #define BOOKE_IRQPRIO_PERFORMANCE_MONITOR 19
45c5335f17SAlexander Graf /* Internal pseudo-irqprio for level triggered externals */
46c5335f17SAlexander Graf #define BOOKE_IRQPRIO_EXTERNAL_LEVEL 20
47d30f6e48SScott Wood #define BOOKE_IRQPRIO_DBELL 21
48d30f6e48SScott Wood #define BOOKE_IRQPRIO_DBELL_CRIT 22
49d30f6e48SScott Wood #define BOOKE_IRQPRIO_MAX 23
50d30f6e48SScott Wood
51d30f6e48SScott Wood #define BOOKE_IRQMASK_EE ((1 << BOOKE_IRQPRIO_EXTERNAL_LEVEL) | \
52d30f6e48SScott Wood (1 << BOOKE_IRQPRIO_PERFORMANCE_MONITOR) | \
53d30f6e48SScott Wood (1 << BOOKE_IRQPRIO_DBELL) | \
54d30f6e48SScott Wood (1 << BOOKE_IRQPRIO_DECREMENTER) | \
55d30f6e48SScott Wood (1 << BOOKE_IRQPRIO_FIT) | \
56d30f6e48SScott Wood (1 << BOOKE_IRQPRIO_EXTERNAL))
57d30f6e48SScott Wood
58d30f6e48SScott Wood #define BOOKE_IRQMASK_CE ((1 << BOOKE_IRQPRIO_DBELL_CRIT) | \
59d30f6e48SScott Wood (1 << BOOKE_IRQPRIO_WATCHDOG) | \
60d30f6e48SScott Wood (1 << BOOKE_IRQPRIO_CRITICAL))
61bb3a8a17SHollis Blanchard
62bb3a8a17SHollis Blanchard extern unsigned long kvmppc_booke_handlers;
631d542d9cSBharat Bhushan extern unsigned long kvmppc_booke_handler_addr[];
64d4cf3892SHollis Blanchard
654cd35f67SScott Wood void kvmppc_set_msr(struct kvm_vcpu *vcpu, u32 new_msr);
66dd9ebf1fSLiu Yu void kvmppc_mmu_msr_notify(struct kvm_vcpu *vcpu, u32 old_msr);
6775f74f0dSHollis Blanchard
6838f98824SMihai Caraman void kvmppc_set_epcr(struct kvm_vcpu *vcpu, u32 new_epcr);
69dfd4d47eSScott Wood void kvmppc_set_tcr(struct kvm_vcpu *vcpu, u32 new_tcr);
70dfd4d47eSScott Wood void kvmppc_set_tsr_bits(struct kvm_vcpu *vcpu, u32 tsr_bits);
71dfd4d47eSScott Wood void kvmppc_clr_tsr_bits(struct kvm_vcpu *vcpu, u32 tsr_bits);
72dfd4d47eSScott Wood
738c99d345STianjia Zhang int kvmppc_booke_emulate_op(struct kvm_vcpu *vcpu,
74d0c7dc03SHollis Blanchard unsigned int inst, int *advance);
7554771e62SAlexander Graf int kvmppc_booke_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val);
7654771e62SAlexander Graf int kvmppc_booke_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val);
77d0c7dc03SHollis Blanchard
784cd35f67SScott Wood /* low-level asm code to transfer guest state */
794cd35f67SScott Wood void kvmppc_load_guest_spe(struct kvm_vcpu *vcpu);
804cd35f67SScott Wood void kvmppc_save_guest_spe(struct kvm_vcpu *vcpu);
814cd35f67SScott Wood
824cd35f67SScott Wood /* high-level function, manages flags, host state */
834cd35f67SScott Wood void kvmppc_vcpu_disable_spe(struct kvm_vcpu *vcpu);
844cd35f67SScott Wood
8594fa9d99SScott Wood void kvmppc_booke_vcpu_load(struct kvm_vcpu *vcpu, int cpu);
8694fa9d99SScott Wood void kvmppc_booke_vcpu_put(struct kvm_vcpu *vcpu);
8794fa9d99SScott Wood
88d30f6e48SScott Wood enum int_class {
89d30f6e48SScott Wood INT_CLASS_NONCRIT,
90d30f6e48SScott Wood INT_CLASS_CRIT,
91d30f6e48SScott Wood INT_CLASS_MC,
92d30f6e48SScott Wood INT_CLASS_DBG,
93d30f6e48SScott Wood };
94d30f6e48SScott Wood
95d30f6e48SScott Wood void kvmppc_set_pending_interrupt(struct kvm_vcpu *vcpu, enum int_class type);
96d30f6e48SScott Wood
978c99d345STianjia Zhang extern int kvmppc_core_emulate_op_e500(struct kvm_vcpu *vcpu,
983a167beaSAneesh Kumar K.V unsigned int inst, int *advance);
993a167beaSAneesh Kumar K.V extern int kvmppc_core_emulate_mtspr_e500(struct kvm_vcpu *vcpu, int sprn,
1003a167beaSAneesh Kumar K.V ulong spr_val);
1013a167beaSAneesh Kumar K.V extern int kvmppc_core_emulate_mfspr_e500(struct kvm_vcpu *vcpu, int sprn,
1023a167beaSAneesh Kumar K.V ulong *spr_val);
1033a167beaSAneesh Kumar K.V extern int kvmppc_core_emulate_mtspr_e500(struct kvm_vcpu *vcpu, int sprn,
1043a167beaSAneesh Kumar K.V ulong spr_val);
1053a167beaSAneesh Kumar K.V extern int kvmppc_core_emulate_mfspr_e500(struct kvm_vcpu *vcpu, int sprn,
1063a167beaSAneesh Kumar K.V ulong *spr_val);
1073a167beaSAneesh Kumar K.V
kvmppc_clear_dbsr(void)108ce11e48bSBharat Bhushan static inline void kvmppc_clear_dbsr(void)
109ce11e48bSBharat Bhushan {
110ce11e48bSBharat Bhushan mtspr(SPRN_DBSR, mfspr(SPRN_DBSR));
111ce11e48bSBharat Bhushan }
112*43d05c61SMichael Ellerman
113*43d05c61SMichael Ellerman int kvmppc_handle_exit(struct kvm_vcpu *vcpu, unsigned int exit_nr);
114*43d05c61SMichael Ellerman
11575f74f0dSHollis Blanchard #endif /* __KVM_BOOKE_H__ */
116