blob: a9ff80e51526785949ec5770f9eeefda85a0d0c6 [file] [log] [blame]
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -05001/*
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. 2007
16 *
17 * Authors: Hollis Blanchard <hollisb@us.ibm.com>
18 */
19
20#ifndef __KVM_POWERPC_TLB_H__
21#define __KVM_POWERPC_TLB_H__
22
23#include <linux/kvm_host.h>
24#include <asm/mmu-44x.h>
25
26extern int kvmppc_44x_tlb_index(struct kvm_vcpu *vcpu, gva_t eaddr,
27 unsigned int pid, unsigned int as);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050028
Hollis Blanchard75f74f02008-11-05 09:36:16 -060029extern int kvmppc_44x_emul_tlbsx(struct kvm_vcpu *vcpu, u8 rt, u8 ra, u8 rb,
30 u8 rc);
31extern int kvmppc_44x_emul_tlbwe(struct kvm_vcpu *vcpu, u8 ra, u8 rs, u8 ws);
32
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050033/* TLB helper functions */
Hollis Blanchard0f55dc42008-11-05 09:36:12 -060034static inline unsigned int get_tlb_size(const struct kvmppc_44x_tlbe *tlbe)
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050035{
36 return (tlbe->word0 >> 4) & 0xf;
37}
38
Hollis Blanchard0f55dc42008-11-05 09:36:12 -060039static inline gva_t get_tlb_eaddr(const struct kvmppc_44x_tlbe *tlbe)
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050040{
41 return tlbe->word0 & 0xfffffc00;
42}
43
Hollis Blanchard0f55dc42008-11-05 09:36:12 -060044static inline gva_t get_tlb_bytes(const struct kvmppc_44x_tlbe *tlbe)
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050045{
46 unsigned int pgsize = get_tlb_size(tlbe);
47 return 1 << 10 << (pgsize << 1);
48}
49
Hollis Blanchard0f55dc42008-11-05 09:36:12 -060050static inline gva_t get_tlb_end(const struct kvmppc_44x_tlbe *tlbe)
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050051{
52 return get_tlb_eaddr(tlbe) + get_tlb_bytes(tlbe) - 1;
53}
54
Hollis Blanchard0f55dc42008-11-05 09:36:12 -060055static inline u64 get_tlb_raddr(const struct kvmppc_44x_tlbe *tlbe)
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050056{
57 u64 word1 = tlbe->word1;
58 return ((word1 & 0xf) << 32) | (word1 & 0xfffffc00);
59}
60
Hollis Blanchard0f55dc42008-11-05 09:36:12 -060061static inline unsigned int get_tlb_tid(const struct kvmppc_44x_tlbe *tlbe)
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050062{
63 return tlbe->tid & 0xff;
64}
65
Hollis Blanchard0f55dc42008-11-05 09:36:12 -060066static inline unsigned int get_tlb_ts(const struct kvmppc_44x_tlbe *tlbe)
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050067{
68 return (tlbe->word0 >> 8) & 0x1;
69}
70
Hollis Blanchard0f55dc42008-11-05 09:36:12 -060071static inline unsigned int get_tlb_v(const struct kvmppc_44x_tlbe *tlbe)
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050072{
73 return (tlbe->word0 >> 9) & 0x1;
74}
75
76static inline unsigned int get_mmucr_stid(const struct kvm_vcpu *vcpu)
77{
78 return vcpu->arch.mmucr & 0xff;
79}
80
81static inline unsigned int get_mmucr_sts(const struct kvm_vcpu *vcpu)
82{
83 return (vcpu->arch.mmucr >> 16) & 0x1;
84}
85
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050086#endif /* __KVM_POWERPC_TLB_H__ */