kvm_ppc.h revision b104d06632d08957f384ff7403f609fb5dfb9cbd
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License, version 2, as
4 * published by the Free Software Foundation.
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9 * GNU General Public License for more details.
10 *
11 * You should have received a copy of the GNU General Public License
12 * along with this program; if not, write to the Free Software
13 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
14 *
15 * Copyright IBM Corp. 2008
16 *
17 * Authors: Hollis Blanchard <hollisb@us.ibm.com>
18 */
19
20#ifndef __POWERPC_KVM_PPC_H__
21#define __POWERPC_KVM_PPC_H__
22
23/* This file exists just so we can dereference kvm_vcpu, avoiding nested header
24 * dependencies. */
25
26#include <linux/mutex.h>
27#include <linux/timer.h>
28#include <linux/types.h>
29#include <linux/kvm_types.h>
30#include <linux/kvm_host.h>
31#ifdef CONFIG_PPC_BOOK3S
32#include <asm/kvm_book3s.h>
33#endif
34
35enum emulation_result {
36	EMULATE_DONE,         /* no further processing */
37	EMULATE_DO_MMIO,      /* kvm_run filled with MMIO request */
38	EMULATE_DO_DCR,       /* kvm_run filled with DCR request */
39	EMULATE_FAIL,         /* can't emulate this instruction */
40};
41
42extern int __kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu);
43extern char kvmppc_handlers_start[];
44extern unsigned long kvmppc_handler_len;
45extern void kvmppc_handler_highmem(void);
46
47extern void kvmppc_dump_vcpu(struct kvm_vcpu *vcpu);
48extern int kvmppc_handle_load(struct kvm_run *run, struct kvm_vcpu *vcpu,
49                              unsigned int rt, unsigned int bytes,
50                              int is_bigendian);
51extern int kvmppc_handle_store(struct kvm_run *run, struct kvm_vcpu *vcpu,
52                               u64 val, unsigned int bytes, int is_bigendian);
53
54extern int kvmppc_emulate_instruction(struct kvm_run *run,
55                                      struct kvm_vcpu *vcpu);
56extern int kvmppc_emulate_mmio(struct kvm_run *run, struct kvm_vcpu *vcpu);
57extern void kvmppc_emulate_dec(struct kvm_vcpu *vcpu);
58
59/* Core-specific hooks */
60
61extern void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 gvaddr, gpa_t gpaddr,
62                           unsigned int gtlb_idx);
63extern void kvmppc_mmu_priv_switch(struct kvm_vcpu *vcpu, int usermode);
64extern void kvmppc_mmu_switch_pid(struct kvm_vcpu *vcpu, u32 pid);
65extern void kvmppc_mmu_destroy(struct kvm_vcpu *vcpu);
66extern int kvmppc_mmu_dtlb_index(struct kvm_vcpu *vcpu, gva_t eaddr);
67extern int kvmppc_mmu_itlb_index(struct kvm_vcpu *vcpu, gva_t eaddr);
68extern gpa_t kvmppc_mmu_xlate(struct kvm_vcpu *vcpu, unsigned int gtlb_index,
69                              gva_t eaddr);
70extern void kvmppc_mmu_dtlb_miss(struct kvm_vcpu *vcpu);
71extern void kvmppc_mmu_itlb_miss(struct kvm_vcpu *vcpu);
72
73extern struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm,
74                                                unsigned int id);
75extern void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu);
76extern int kvmppc_core_vcpu_setup(struct kvm_vcpu *vcpu);
77extern int kvmppc_core_check_processor_compat(void);
78extern int kvmppc_core_vcpu_translate(struct kvm_vcpu *vcpu,
79                                      struct kvm_translation *tr);
80
81extern void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu);
82extern void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu);
83
84extern void kvmppc_core_deliver_interrupts(struct kvm_vcpu *vcpu);
85extern int kvmppc_core_pending_dec(struct kvm_vcpu *vcpu);
86extern void kvmppc_core_queue_program(struct kvm_vcpu *vcpu, ulong flags);
87extern void kvmppc_core_queue_dec(struct kvm_vcpu *vcpu);
88extern void kvmppc_core_dequeue_dec(struct kvm_vcpu *vcpu);
89extern void kvmppc_core_queue_external(struct kvm_vcpu *vcpu,
90                                       struct kvm_interrupt *irq);
91
92extern int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,
93                                  unsigned int op, int *advance);
94extern int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs);
95extern int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt);
96
97extern int kvmppc_booke_init(void);
98extern void kvmppc_booke_exit(void);
99
100extern void kvmppc_core_destroy_mmu(struct kvm_vcpu *vcpu);
101
102#ifdef CONFIG_PPC_BOOK3S
103
104/* We assume we're always acting on the current vcpu */
105
106static inline void kvmppc_set_gpr(struct kvm_vcpu *vcpu, int num, ulong val)
107{
108	if ( num < 14 ) {
109		get_paca()->shadow_vcpu.gpr[num] = val;
110		to_book3s(vcpu)->shadow_vcpu.gpr[num] = val;
111	} else
112		vcpu->arch.gpr[num] = val;
113}
114
115static inline ulong kvmppc_get_gpr(struct kvm_vcpu *vcpu, int num)
116{
117	if ( num < 14 )
118		return get_paca()->shadow_vcpu.gpr[num];
119	else
120		return vcpu->arch.gpr[num];
121}
122
123static inline void kvmppc_set_cr(struct kvm_vcpu *vcpu, u32 val)
124{
125	get_paca()->shadow_vcpu.cr = val;
126	to_book3s(vcpu)->shadow_vcpu.cr = val;
127}
128
129static inline u32 kvmppc_get_cr(struct kvm_vcpu *vcpu)
130{
131	return get_paca()->shadow_vcpu.cr;
132}
133
134static inline void kvmppc_set_xer(struct kvm_vcpu *vcpu, u32 val)
135{
136	get_paca()->shadow_vcpu.xer = val;
137	to_book3s(vcpu)->shadow_vcpu.xer = val;
138}
139
140static inline u32 kvmppc_get_xer(struct kvm_vcpu *vcpu)
141{
142	return get_paca()->shadow_vcpu.xer;
143}
144
145#else
146
147static inline void kvmppc_set_gpr(struct kvm_vcpu *vcpu, int num, ulong val)
148{
149	vcpu->arch.gpr[num] = val;
150}
151
152static inline ulong kvmppc_get_gpr(struct kvm_vcpu *vcpu, int num)
153{
154	return vcpu->arch.gpr[num];
155}
156
157static inline void kvmppc_set_cr(struct kvm_vcpu *vcpu, u32 val)
158{
159	vcpu->arch.cr = val;
160}
161
162static inline u32 kvmppc_get_cr(struct kvm_vcpu *vcpu)
163{
164	return vcpu->arch.cr;
165}
166
167static inline void kvmppc_set_xer(struct kvm_vcpu *vcpu, u32 val)
168{
169	vcpu->arch.xer = val;
170}
171
172static inline u32 kvmppc_get_xer(struct kvm_vcpu *vcpu)
173{
174	return vcpu->arch.xer;
175}
176
177#endif
178
179#endif /* __POWERPC_KVM_PPC_H__ */
180