blob: c6011336371e506829a54ed18a225d559c1e3b41 [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>
26
27struct kvmppc_slb {
28 u64 esid;
29 u64 vsid;
30 u64 orige;
31 u64 origv;
32 bool valid;
33 bool Ks;
34 bool Kp;
35 bool nx;
36 bool large;
37 bool class;
38};
39
40struct kvmppc_sr {
41 u32 raw;
42 u32 vsid;
43 bool Ks;
44 bool Kp;
45 bool nx;
46};
47
48struct kvmppc_bat {
49 u32 bepi;
50 u32 bepi_mask;
51 bool vs;
52 bool vp;
53 u32 brpn;
54 u8 wimg;
55 u8 pp;
56};
57
58struct kvmppc_sid_map {
59 u64 guest_vsid;
60 u64 guest_esid;
61 u64 host_vsid;
62 bool valid;
63};
64
65#define SID_MAP_BITS 9
66#define SID_MAP_NUM (1 << SID_MAP_BITS)
67#define SID_MAP_MASK (SID_MAP_NUM - 1)
68
69struct kvmppc_vcpu_book3s {
70 struct kvm_vcpu vcpu;
71 struct kvmppc_sid_map sid_map[SID_MAP_NUM];
72 struct kvmppc_slb slb[64];
73 struct {
74 u64 esid;
75 u64 vsid;
76 } slb_shadow[64];
77 u8 slb_shadow_max;
78 struct kvmppc_sr sr[16];
79 struct kvmppc_bat ibat[8];
80 struct kvmppc_bat dbat[8];
81 u64 hid[6];
82 int slb_nr;
83 u64 sdr1;
84 u64 dsisr;
85 u64 hior;
86 u64 msr_mask;
87 u64 vsid_first;
88 u64 vsid_next;
89 u64 vsid_max;
90 int context_id;
91};
92
93#define CONTEXT_HOST 0
94#define CONTEXT_GUEST 1
95#define CONTEXT_GUEST_END 2
96
97#define VSID_REAL 0xfffffffffff00000
98#define VSID_REAL_DR 0xffffffffffe00000
99#define VSID_REAL_IR 0xffffffffffd00000
100#define VSID_BAT 0xffffffffffc00000
101#define VSID_PR 0x8000000000000000
102
103extern void kvmppc_mmu_pte_flush(struct kvm_vcpu *vcpu, u64 ea, u64 ea_mask);
104extern void kvmppc_mmu_pte_vflush(struct kvm_vcpu *vcpu, u64 vp, u64 vp_mask);
105extern void kvmppc_mmu_pte_pflush(struct kvm_vcpu *vcpu, u64 pa_start, u64 pa_end);
106extern void kvmppc_set_msr(struct kvm_vcpu *vcpu, u64 new_msr);
107extern void kvmppc_mmu_book3s_64_init(struct kvm_vcpu *vcpu);
108extern void kvmppc_mmu_book3s_32_init(struct kvm_vcpu *vcpu);
109extern int kvmppc_mmu_map_page(struct kvm_vcpu *vcpu, struct kvmppc_pte *pte);
110extern int kvmppc_mmu_map_segment(struct kvm_vcpu *vcpu, ulong eaddr);
111extern void kvmppc_mmu_flush_segments(struct kvm_vcpu *vcpu);
112extern struct kvmppc_pte *kvmppc_mmu_find_pte(struct kvm_vcpu *vcpu, u64 ea, bool data);
113extern int kvmppc_ld(struct kvm_vcpu *vcpu, ulong eaddr, int size, void *ptr, bool data);
114extern int kvmppc_st(struct kvm_vcpu *vcpu, ulong eaddr, int size, void *ptr);
115extern void kvmppc_book3s_queue_irqprio(struct kvm_vcpu *vcpu, unsigned int vec);
116
117extern u32 kvmppc_trampoline_lowmem;
118extern u32 kvmppc_trampoline_enter;
119
120static inline struct kvmppc_vcpu_book3s *to_book3s(struct kvm_vcpu *vcpu)
121{
122 return container_of(vcpu, struct kvmppc_vcpu_book3s, vcpu);
123}
124
125static inline ulong dsisr(void)
126{
127 ulong r;
128 asm ( "mfdsisr %0 " : "=r" (r) );
129 return r;
130}
131
132extern void kvm_return_point(void);
133
134#define INS_DCBZ 0x7c0007ec
135
136#endif /* __ASM_KVM_BOOK3S_H__ */