blob: e1b441cce416a29d1599af65c2ea59ea57b49fa4 [file] [log] [blame]
Alexander Graf4e3420252009-10-30 05:47:05 +00001/*
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 SUSE Linux Products GmbH 2009
16 *
17 * Authors: Alexander Graf <agraf@suse.de>
18 */
19
20#ifndef __ASM_KVM_BOOK3S_H__
21#define __ASM_KVM_BOOK3S_H__
22
23#include <linux/types.h>
24#include <linux/kvm_host.h>
25#include <asm/kvm_ppc.h>
Alexander Graf7e57cba2010-01-08 02:58:03 +010026#include <asm/kvm_book3s_64_asm.h>
Alexander Graf4e3420252009-10-30 05:47:05 +000027
28struct kvmppc_slb {
29 u64 esid;
30 u64 vsid;
31 u64 orige;
32 u64 origv;
33 bool valid;
34 bool Ks;
35 bool Kp;
36 bool nx;
Alexander Graf4b5c9b72010-01-10 03:27:47 +010037 bool large; /* PTEs are 16MB */
38 bool tb; /* 1TB segment */
Alexander Graf4e3420252009-10-30 05:47:05 +000039 bool class;
40};
41
42struct kvmppc_sr {
43 u32 raw;
44 u32 vsid;
45 bool Ks;
46 bool Kp;
47 bool nx;
48};
49
50struct kvmppc_bat {
Alexander Grafe15a1132009-11-30 03:02:02 +000051 u64 raw;
Alexander Graf4e3420252009-10-30 05:47:05 +000052 u32 bepi;
53 u32 bepi_mask;
54 bool vs;
55 bool vp;
56 u32 brpn;
57 u8 wimg;
58 u8 pp;
59};
60
61struct kvmppc_sid_map {
62 u64 guest_vsid;
63 u64 guest_esid;
64 u64 host_vsid;
65 bool valid;
66};
67
68#define SID_MAP_BITS 9
69#define SID_MAP_NUM (1 << SID_MAP_BITS)
70#define SID_MAP_MASK (SID_MAP_NUM - 1)
71
72struct kvmppc_vcpu_book3s {
73 struct kvm_vcpu vcpu;
Alexander Graf7e57cba2010-01-08 02:58:03 +010074 struct kvmppc_book3s_shadow_vcpu shadow_vcpu;
Alexander Graf4e3420252009-10-30 05:47:05 +000075 struct kvmppc_sid_map sid_map[SID_MAP_NUM];
76 struct kvmppc_slb slb[64];
77 struct {
78 u64 esid;
79 u64 vsid;
80 } slb_shadow[64];
81 u8 slb_shadow_max;
82 struct kvmppc_sr sr[16];
83 struct kvmppc_bat ibat[8];
84 struct kvmppc_bat dbat[8];
85 u64 hid[6];
86 int slb_nr;
87 u64 sdr1;
88 u64 dsisr;
89 u64 hior;
90 u64 msr_mask;
91 u64 vsid_first;
92 u64 vsid_next;
93 u64 vsid_max;
94 int context_id;
Alexander Graf25a8a022010-01-08 02:58:07 +010095 ulong prog_flags; /* flags to inject when giving a 700 trap */
Alexander Graf4e3420252009-10-30 05:47:05 +000096};
97
98#define CONTEXT_HOST 0
99#define CONTEXT_GUEST 1
100#define CONTEXT_GUEST_END 2
101
102#define VSID_REAL 0xfffffffffff00000
103#define VSID_REAL_DR 0xffffffffffe00000
104#define VSID_REAL_IR 0xffffffffffd00000
105#define VSID_BAT 0xffffffffffc00000
106#define VSID_PR 0x8000000000000000
107
108extern void kvmppc_mmu_pte_flush(struct kvm_vcpu *vcpu, u64 ea, u64 ea_mask);
109extern void kvmppc_mmu_pte_vflush(struct kvm_vcpu *vcpu, u64 vp, u64 vp_mask);
110extern void kvmppc_mmu_pte_pflush(struct kvm_vcpu *vcpu, u64 pa_start, u64 pa_end);
111extern void kvmppc_set_msr(struct kvm_vcpu *vcpu, u64 new_msr);
112extern void kvmppc_mmu_book3s_64_init(struct kvm_vcpu *vcpu);
113extern void kvmppc_mmu_book3s_32_init(struct kvm_vcpu *vcpu);
114extern int kvmppc_mmu_map_page(struct kvm_vcpu *vcpu, struct kvmppc_pte *pte);
115extern int kvmppc_mmu_map_segment(struct kvm_vcpu *vcpu, ulong eaddr);
116extern void kvmppc_mmu_flush_segments(struct kvm_vcpu *vcpu);
117extern struct kvmppc_pte *kvmppc_mmu_find_pte(struct kvm_vcpu *vcpu, u64 ea, bool data);
118extern int kvmppc_ld(struct kvm_vcpu *vcpu, ulong eaddr, int size, void *ptr, bool data);
119extern int kvmppc_st(struct kvm_vcpu *vcpu, ulong eaddr, int size, void *ptr);
120extern void kvmppc_book3s_queue_irqprio(struct kvm_vcpu *vcpu, unsigned int vec);
Alexander Grafe15a1132009-11-30 03:02:02 +0000121extern void kvmppc_set_bat(struct kvm_vcpu *vcpu, struct kvmppc_bat *bat,
122 bool upper, u32 val);
Alexander Graf4e3420252009-10-30 05:47:05 +0000123
124extern u32 kvmppc_trampoline_lowmem;
125extern u32 kvmppc_trampoline_enter;
Alexander Graf021ec9c2010-01-08 02:58:06 +0100126extern void kvmppc_rmcall(ulong srr0, ulong srr1);
Alexander Grafd5e52812010-01-15 14:49:10 +0100127extern void kvmppc_load_up_fpu(void);
128extern void kvmppc_load_up_altivec(void);
129extern void kvmppc_load_up_vsx(void);
Alexander Graf4e3420252009-10-30 05:47:05 +0000130
131static inline struct kvmppc_vcpu_book3s *to_book3s(struct kvm_vcpu *vcpu)
132{
133 return container_of(vcpu, struct kvmppc_vcpu_book3s, vcpu);
134}
135
136static inline ulong dsisr(void)
137{
138 ulong r;
139 asm ( "mfdsisr %0 " : "=r" (r) );
140 return r;
141}
142
143extern void kvm_return_point(void);
144
145#define INS_DCBZ 0x7c0007ec
146
147#endif /* __ASM_KVM_BOOK3S_H__ */