44x_tlb.h 2.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License, version 2, as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 * Copyright IBM Corp. 2007
 *
 * Authors: Hollis Blanchard <hollisb@us.ibm.com>
 */

#ifndef __KVM_POWERPC_TLB_H__
#define __KVM_POWERPC_TLB_H__

#include <linux/kvm_host.h>
#include <asm/mmu-44x.h>

extern int kvmppc_44x_tlb_index(struct kvm_vcpu *vcpu, gva_t eaddr,
                                unsigned int pid, unsigned int as);
28 29 30 31
extern struct kvmppc_44x_tlbe *kvmppc_44x_dtlb_search(struct kvm_vcpu *vcpu,
                                                      gva_t eaddr);
extern struct kvmppc_44x_tlbe *kvmppc_44x_itlb_search(struct kvm_vcpu *vcpu,
                                                      gva_t eaddr);
32 33

/* TLB helper functions */
34
static inline unsigned int get_tlb_size(const struct kvmppc_44x_tlbe *tlbe)
35 36 37 38
{
	return (tlbe->word0 >> 4) & 0xf;
}

39
static inline gva_t get_tlb_eaddr(const struct kvmppc_44x_tlbe *tlbe)
40 41 42 43
{
	return tlbe->word0 & 0xfffffc00;
}

44
static inline gva_t get_tlb_bytes(const struct kvmppc_44x_tlbe *tlbe)
45 46 47 48 49
{
	unsigned int pgsize = get_tlb_size(tlbe);
	return 1 << 10 << (pgsize << 1);
}

50
static inline gva_t get_tlb_end(const struct kvmppc_44x_tlbe *tlbe)
51 52 53 54
{
	return get_tlb_eaddr(tlbe) + get_tlb_bytes(tlbe) - 1;
}

55
static inline u64 get_tlb_raddr(const struct kvmppc_44x_tlbe *tlbe)
56 57 58 59 60
{
	u64 word1 = tlbe->word1;
	return ((word1 & 0xf) << 32) | (word1 & 0xfffffc00);
}

61
static inline unsigned int get_tlb_tid(const struct kvmppc_44x_tlbe *tlbe)
62 63 64 65
{
	return tlbe->tid & 0xff;
}

66
static inline unsigned int get_tlb_ts(const struct kvmppc_44x_tlbe *tlbe)
67 68 69 70
{
	return (tlbe->word0 >> 8) & 0x1;
}

71
static inline unsigned int get_tlb_v(const struct kvmppc_44x_tlbe *tlbe)
72 73 74 75 76 77 78 79 80 81 82 83 84 85
{
	return (tlbe->word0 >> 9) & 0x1;
}

static inline unsigned int get_mmucr_stid(const struct kvm_vcpu *vcpu)
{
	return vcpu->arch.mmucr & 0xff;
}

static inline unsigned int get_mmucr_sts(const struct kvm_vcpu *vcpu)
{
	return (vcpu->arch.mmucr >> 16) & 0x1;
}

86
static inline gpa_t tlb_xlate(struct kvmppc_44x_tlbe *tlbe, gva_t eaddr)
87 88 89 90 91 92 93
{
	unsigned int pgmask = get_tlb_bytes(tlbe) - 1;

	return get_tlb_raddr(tlbe) | (eaddr & pgmask);
}

#endif /* __KVM_POWERPC_TLB_H__ */