Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1 | /* |
| 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 | |
| 26 | extern int kvmppc_44x_tlb_index(struct kvm_vcpu *vcpu, gva_t eaddr, |
| 27 | unsigned int pid, unsigned int as); |
Hollis Blanchard | 0f55dc4 | 2008-11-05 09:36:12 -0600 | [diff] [blame] | 28 | extern struct kvmppc_44x_tlbe *kvmppc_44x_dtlb_search(struct kvm_vcpu *vcpu, |
| 29 | gva_t eaddr); |
| 30 | extern struct kvmppc_44x_tlbe *kvmppc_44x_itlb_search(struct kvm_vcpu *vcpu, |
| 31 | gva_t eaddr); |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 32 | extern void kvmppc_tlbe_set_modified(struct kvm_vcpu *vcpu, unsigned int i); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 33 | |
Hollis Blanchard | 75f74f0 | 2008-11-05 09:36:16 -0600 | [diff] [blame] | 34 | extern int kvmppc_44x_emul_tlbsx(struct kvm_vcpu *vcpu, u8 rt, u8 ra, u8 rb, |
| 35 | u8 rc); |
| 36 | extern int kvmppc_44x_emul_tlbwe(struct kvm_vcpu *vcpu, u8 ra, u8 rs, u8 ws); |
| 37 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 38 | /* TLB helper functions */ |
Hollis Blanchard | 0f55dc4 | 2008-11-05 09:36:12 -0600 | [diff] [blame] | 39 | static inline unsigned int get_tlb_size(const struct kvmppc_44x_tlbe *tlbe) |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 40 | { |
| 41 | return (tlbe->word0 >> 4) & 0xf; |
| 42 | } |
| 43 | |
Hollis Blanchard | 0f55dc4 | 2008-11-05 09:36:12 -0600 | [diff] [blame] | 44 | static inline gva_t get_tlb_eaddr(const struct kvmppc_44x_tlbe *tlbe) |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 45 | { |
| 46 | return tlbe->word0 & 0xfffffc00; |
| 47 | } |
| 48 | |
Hollis Blanchard | 0f55dc4 | 2008-11-05 09:36:12 -0600 | [diff] [blame] | 49 | static inline gva_t get_tlb_bytes(const struct kvmppc_44x_tlbe *tlbe) |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 50 | { |
| 51 | unsigned int pgsize = get_tlb_size(tlbe); |
| 52 | return 1 << 10 << (pgsize << 1); |
| 53 | } |
| 54 | |
Hollis Blanchard | 0f55dc4 | 2008-11-05 09:36:12 -0600 | [diff] [blame] | 55 | static inline gva_t get_tlb_end(const struct kvmppc_44x_tlbe *tlbe) |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 56 | { |
| 57 | return get_tlb_eaddr(tlbe) + get_tlb_bytes(tlbe) - 1; |
| 58 | } |
| 59 | |
Hollis Blanchard | 0f55dc4 | 2008-11-05 09:36:12 -0600 | [diff] [blame] | 60 | static inline u64 get_tlb_raddr(const struct kvmppc_44x_tlbe *tlbe) |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 61 | { |
| 62 | u64 word1 = tlbe->word1; |
| 63 | return ((word1 & 0xf) << 32) | (word1 & 0xfffffc00); |
| 64 | } |
| 65 | |
Hollis Blanchard | 0f55dc4 | 2008-11-05 09:36:12 -0600 | [diff] [blame] | 66 | static inline unsigned int get_tlb_tid(const struct kvmppc_44x_tlbe *tlbe) |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 67 | { |
| 68 | return tlbe->tid & 0xff; |
| 69 | } |
| 70 | |
Hollis Blanchard | 0f55dc4 | 2008-11-05 09:36:12 -0600 | [diff] [blame] | 71 | static inline unsigned int get_tlb_ts(const struct kvmppc_44x_tlbe *tlbe) |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 72 | { |
| 73 | return (tlbe->word0 >> 8) & 0x1; |
| 74 | } |
| 75 | |
Hollis Blanchard | 0f55dc4 | 2008-11-05 09:36:12 -0600 | [diff] [blame] | 76 | static inline unsigned int get_tlb_v(const struct kvmppc_44x_tlbe *tlbe) |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 77 | { |
| 78 | return (tlbe->word0 >> 9) & 0x1; |
| 79 | } |
| 80 | |
| 81 | static inline unsigned int get_mmucr_stid(const struct kvm_vcpu *vcpu) |
| 82 | { |
| 83 | return vcpu->arch.mmucr & 0xff; |
| 84 | } |
| 85 | |
| 86 | static inline unsigned int get_mmucr_sts(const struct kvm_vcpu *vcpu) |
| 87 | { |
| 88 | return (vcpu->arch.mmucr >> 16) & 0x1; |
| 89 | } |
| 90 | |
Hollis Blanchard | 0f55dc4 | 2008-11-05 09:36:12 -0600 | [diff] [blame] | 91 | static inline gpa_t tlb_xlate(struct kvmppc_44x_tlbe *tlbe, gva_t eaddr) |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 92 | { |
| 93 | unsigned int pgmask = get_tlb_bytes(tlbe) - 1; |
| 94 | |
| 95 | return get_tlb_raddr(tlbe) | (eaddr & pgmask); |
| 96 | } |
| 97 | |
| 98 | #endif /* __KVM_POWERPC_TLB_H__ */ |