aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/kvm/e500_tlb.h
diff options
context:
space:
mode:
authorHollis Blanchard <hollisb@us.ibm.com>2009-01-03 17:23:10 -0500
committerAvi Kivity <avi@redhat.com>2009-03-24 05:02:58 -0400
commitbc8080cbcc8870178f0910edd537d0cb5706d703 (patch)
tree7e929e8585a32c3d93a373553d3179e182c7eb5f /arch/powerpc/kvm/e500_tlb.h
parent17c885eb5c38f39a2bb3143a67687bd905dcd0fa (diff)
KVM: ppc: E500 core-specific code
Signed-off-by: Liu Yu <yu.liu@freescale.com> Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com> Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'arch/powerpc/kvm/e500_tlb.h')
-rw-r--r--arch/powerpc/kvm/e500_tlb.h184
1 files changed, 184 insertions, 0 deletions
diff --git a/arch/powerpc/kvm/e500_tlb.h b/arch/powerpc/kvm/e500_tlb.h
new file mode 100644
index 000000000000..d8833f955163
--- /dev/null
+++ b/arch/powerpc/kvm/e500_tlb.h
@@ -0,0 +1,184 @@
1/*
2 * Copyright (C) 2008 Freescale Semiconductor, Inc. All rights reserved.
3 *
4 * Author: Yu Liu, yu.liu@freescale.com
5 *
6 * Description:
7 * This file is based on arch/powerpc/kvm/44x_tlb.h,
8 * by Hollis Blanchard <hollisb@us.ibm.com>.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License, version 2, as
12 * published by the Free Software Foundation.
13 */
14
15#ifndef __KVM_E500_TLB_H__
16#define __KVM_E500_TLB_H__
17
18#include <linux/kvm_host.h>
19#include <asm/mmu-fsl-booke.h>
20#include <asm/tlb.h>
21#include <asm/kvm_e500.h>
22
23#define KVM_E500_TLB0_WAY_SIZE_BIT 7 /* Fixed */
24#define KVM_E500_TLB0_WAY_SIZE (1UL << KVM_E500_TLB0_WAY_SIZE_BIT)
25#define KVM_E500_TLB0_WAY_SIZE_MASK (KVM_E500_TLB0_WAY_SIZE - 1)
26
27#define KVM_E500_TLB0_WAY_NUM_BIT 1 /* No greater than 7 */
28#define KVM_E500_TLB0_WAY_NUM (1UL << KVM_E500_TLB0_WAY_NUM_BIT)
29#define KVM_E500_TLB0_WAY_NUM_MASK (KVM_E500_TLB0_WAY_NUM - 1)
30
31#define KVM_E500_TLB0_SIZE (KVM_E500_TLB0_WAY_SIZE * KVM_E500_TLB0_WAY_NUM)
32#define KVM_E500_TLB1_SIZE 16
33
34#define index_of(tlbsel, esel) (((tlbsel) << 16) | ((esel) & 0xFFFF))
35#define tlbsel_of(index) ((index) >> 16)
36#define esel_of(index) ((index) & 0xFFFF)
37
38#define E500_TLB_USER_PERM_MASK (MAS3_UX|MAS3_UR|MAS3_UW)
39#define E500_TLB_SUPER_PERM_MASK (MAS3_SX|MAS3_SR|MAS3_SW)
40#define MAS2_ATTRIB_MASK \
41 (MAS2_X0 | MAS2_X1 | MAS2_W | MAS2_I | MAS2_M | MAS2_G | MAS2_E)
42#define MAS3_ATTRIB_MASK \
43 (MAS3_U0 | MAS3_U1 | MAS3_U2 | MAS3_U3 \
44 | E500_TLB_USER_PERM_MASK | E500_TLB_SUPER_PERM_MASK)
45
46extern void kvmppc_dump_tlbs(struct kvm_vcpu *);
47extern int kvmppc_e500_emul_tlbwe(struct kvm_vcpu *);
48extern int kvmppc_e500_emul_tlbre(struct kvm_vcpu *);
49extern int kvmppc_e500_emul_tlbivax(struct kvm_vcpu *, int, int);
50extern int kvmppc_e500_emul_tlbsx(struct kvm_vcpu *, int);
51extern int kvmppc_e500_tlb_search(struct kvm_vcpu *, gva_t, unsigned int, int);
52extern void kvmppc_e500_tlb_put(struct kvm_vcpu *);
53extern void kvmppc_e500_tlb_load(struct kvm_vcpu *, int);
54extern int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *);
55extern void kvmppc_e500_tlb_uninit(struct kvmppc_vcpu_e500 *);
56extern void kvmppc_e500_tlb_setup(struct kvmppc_vcpu_e500 *);
57
58/* TLB helper functions */
59static inline unsigned int get_tlb_size(const struct tlbe *tlbe)
60{
61 return (tlbe->mas1 >> 8) & 0xf;
62}
63
64static inline gva_t get_tlb_eaddr(const struct tlbe *tlbe)
65{
66 return tlbe->mas2 & 0xfffff000;
67}
68
69static inline u64 get_tlb_bytes(const struct tlbe *tlbe)
70{
71 unsigned int pgsize = get_tlb_size(tlbe);
72 return 1ULL << 10 << (pgsize << 1);
73}
74
75static inline gva_t get_tlb_end(const struct tlbe *tlbe)
76{
77 u64 bytes = get_tlb_bytes(tlbe);
78 return get_tlb_eaddr(tlbe) + bytes - 1;
79}
80
81static inline u64 get_tlb_raddr(const struct tlbe *tlbe)
82{
83 u64 rpn = tlbe->mas7;
84 return (rpn << 32) | (tlbe->mas3 & 0xfffff000);
85}
86
87static inline unsigned int get_tlb_tid(const struct tlbe *tlbe)
88{
89 return (tlbe->mas1 >> 16) & 0xff;
90}
91
92static inline unsigned int get_tlb_ts(const struct tlbe *tlbe)
93{
94 return (tlbe->mas1 >> 12) & 0x1;
95}
96
97static inline unsigned int get_tlb_v(const struct tlbe *tlbe)
98{
99 return (tlbe->mas1 >> 31) & 0x1;
100}
101
102static inline unsigned int get_tlb_iprot(const struct tlbe *tlbe)
103{
104 return (tlbe->mas1 >> 30) & 0x1;
105}
106
107static inline unsigned int get_cur_pid(struct kvm_vcpu *vcpu)
108{
109 return vcpu->arch.pid & 0xff;
110}
111
112static inline unsigned int get_cur_spid(
113 const struct kvmppc_vcpu_e500 *vcpu_e500)
114{
115 return (vcpu_e500->mas6 >> 16) & 0xff;
116}
117
118static inline unsigned int get_cur_sas(
119 const struct kvmppc_vcpu_e500 *vcpu_e500)
120{
121 return vcpu_e500->mas6 & 0x1;
122}
123
124static inline unsigned int get_tlb_tlbsel(
125 const struct kvmppc_vcpu_e500 *vcpu_e500)
126{
127 /*
128 * Manual says that tlbsel has 2 bits wide.
129 * Since we only have tow TLBs, only lower bit is used.
130 */
131 return (vcpu_e500->mas0 >> 28) & 0x1;
132}
133
134static inline unsigned int get_tlb_nv_bit(
135 const struct kvmppc_vcpu_e500 *vcpu_e500)
136{
137 return vcpu_e500->mas0 & 0xfff;
138}
139
140static inline unsigned int get_tlb_esel_bit(
141 const struct kvmppc_vcpu_e500 *vcpu_e500)
142{
143 return (vcpu_e500->mas0 >> 16) & 0xfff;
144}
145
146static inline unsigned int get_tlb_esel(
147 const struct kvmppc_vcpu_e500 *vcpu_e500,
148 int tlbsel)
149{
150 unsigned int esel = get_tlb_esel_bit(vcpu_e500);
151
152 if (tlbsel == 0) {
153 esel &= KVM_E500_TLB0_WAY_NUM_MASK;
154 esel |= ((vcpu_e500->mas2 >> 12) & KVM_E500_TLB0_WAY_SIZE_MASK)
155 << KVM_E500_TLB0_WAY_NUM_BIT;
156 } else {
157 esel &= KVM_E500_TLB1_SIZE - 1;
158 }
159
160 return esel;
161}
162
163static inline int tlbe_is_host_safe(const struct kvm_vcpu *vcpu,
164 const struct tlbe *tlbe)
165{
166 gpa_t gpa;
167
168 if (!get_tlb_v(tlbe))
169 return 0;
170
171 /* Does it match current guest AS? */
172 /* XXX what about IS != DS? */
173 if (get_tlb_ts(tlbe) != !!(vcpu->arch.msr & MSR_IS))
174 return 0;
175
176 gpa = get_tlb_raddr(tlbe);
177 if (!gfn_to_memslot(vcpu->kvm, gpa >> PAGE_SHIFT))
178 /* Mapping is not for RAM. */
179 return 0;
180
181 return 1;
182}
183
184#endif /* __KVM_E500_TLB_H__ */