blob: fa3dc79af7026cfd640c0a9396e2700dcd18abc8 [file] [log] [blame]
Alexander Graf3ae07892010-04-16 00:11:37 +02001/*
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 2010
16 *
17 * Authors: Alexander Graf <agraf@suse.de>
18 */
19
20#ifndef __ASM_KVM_BOOK3S_64_H__
21#define __ASM_KVM_BOOK3S_64_H__
22
Paul Mackerrasde56a942011-06-29 00:21:34 +000023#ifdef CONFIG_KVM_BOOK3S_PR
Alexander Graf468a12c2011-12-09 14:44:13 +010024static inline struct kvmppc_book3s_shadow_vcpu *svcpu_get(struct kvm_vcpu *vcpu)
Alexander Graf3ae07892010-04-16 00:11:37 +020025{
Alexander Graf468a12c2011-12-09 14:44:13 +010026 preempt_disable();
Alexander Graf3ae07892010-04-16 00:11:37 +020027 return &get_paca()->shadow_vcpu;
28}
Alexander Graf468a12c2011-12-09 14:44:13 +010029
30static inline void svcpu_put(struct kvmppc_book3s_shadow_vcpu *svcpu)
31{
32 preempt_enable();
33}
Paul Mackerrasde56a942011-06-29 00:21:34 +000034#endif
Alexander Graf3ae07892010-04-16 00:11:37 +020035
David Gibson54738c02011-06-29 00:22:41 +000036#define SPAPR_TCE_SHIFT 12
37
Paul Mackerras8936dda2011-12-12 12:27:39 +000038#ifdef CONFIG_KVM_BOOK3S_64_HV
39/* For now use fixed-size 16MB page table */
40#define HPT_ORDER 24
41#define HPT_NPTEG (1ul << (HPT_ORDER - 7)) /* 128B per pteg */
42#define HPT_NPTE (HPT_NPTEG << 3) /* 8 PTEs per PTEG */
43#define HPT_HASH_MASK (HPT_NPTEG - 1)
44#endif
45
Andreas Schwab36cc66d2011-11-08 07:08:52 +000046static inline unsigned long compute_tlbie_rb(unsigned long v, unsigned long r,
47 unsigned long pte_index)
48{
49 unsigned long rb, va_low;
50
51 rb = (v & ~0x7fUL) << 16; /* AVA field */
52 va_low = pte_index >> 3;
53 if (v & HPTE_V_SECONDARY)
54 va_low = ~va_low;
55 /* xor vsid from AVA */
56 if (!(v & HPTE_V_1TB_SEG))
57 va_low ^= v >> 12;
58 else
59 va_low ^= v >> 24;
60 va_low &= 0x7ff;
61 if (v & HPTE_V_LARGE) {
62 rb |= 1; /* L field */
63 if (cpu_has_feature(CPU_FTR_ARCH_206) &&
64 (r & 0xff000)) {
65 /* non-16MB large page, must be 64k */
66 /* (masks depend on page size) */
67 rb |= 0x1000; /* page encoding in LP field */
68 rb |= (va_low & 0x7f) << 16; /* 7b of VA in AVA/LP field */
69 rb |= (va_low & 0xfe); /* AVAL field (P7 doesn't seem to care) */
70 }
71 } else {
72 /* 4kB page */
73 rb |= (va_low & 0x7ff) << 12; /* remaining 11b of VA */
74 }
75 rb |= (v >> 54) & 0x300; /* B field */
76 return rb;
77}
78
Alexander Graf3ae07892010-04-16 00:11:37 +020079#endif /* __ASM_KVM_BOOK3S_64_H__ */