1 /*
2  * Copyright (C) 2008-2011 Freescale Semiconductor, Inc. All rights reserved.
3  *
4  * Author: Yu Liu, <yu.liu@freescale.com>
5  *
6  * Description:
7  * This file is derived from arch/powerpc/include/asm/kvm_44x.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 __ASM_KVM_E500_H__
16 #define __ASM_KVM_E500_H__
17 
18 #include <linux/kvm_host.h>
19 
20 #define BOOKE_INTERRUPT_SIZE 36
21 
22 #define E500_PID_NUM   3
23 #define E500_TLB_NUM   2
24 
25 #define E500_TLB_VALID 1
26 #define E500_TLB_DIRTY 2
27 
28 struct tlbe_ref {
29 	pfn_t pfn;
30 	unsigned int flags; /* E500_TLB_* */
31 };
32 
33 struct tlbe_priv {
34 	struct tlbe_ref ref; /* TLB0 only -- TLB1 uses tlb_refs */
35 };
36 
37 struct vcpu_id_table;
38 
39 struct kvmppc_e500_tlb_params {
40 	int entries, ways, sets;
41 };
42 
43 struct kvmppc_vcpu_e500 {
44 	/* Unmodified copy of the guest's TLB -- shared with host userspace. */
45 	struct kvm_book3e_206_tlb_entry *gtlb_arch;
46 
47 	/* Starting entry number in gtlb_arch[] */
48 	int gtlb_offset[E500_TLB_NUM];
49 
50 	/* KVM internal information associated with each guest TLB entry */
51 	struct tlbe_priv *gtlb_priv[E500_TLB_NUM];
52 
53 	struct kvmppc_e500_tlb_params gtlb_params[E500_TLB_NUM];
54 
55 	unsigned int gtlb_nv[E500_TLB_NUM];
56 
57 	/*
58 	 * information associated with each host TLB entry --
59 	 * TLB1 only for now.  If/when guest TLB1 entries can be
60 	 * mapped with host TLB0, this will be used for that too.
61 	 *
62 	 * We don't want to use this for guest TLB0 because then we'd
63 	 * have the overhead of doing the translation again even if
64 	 * the entry is still in the guest TLB (e.g. we swapped out
65 	 * and back, and our host TLB entries got evicted).
66 	 */
67 	struct tlbe_ref *tlb_refs[E500_TLB_NUM];
68 	unsigned int host_tlb1_nv;
69 
70 	u32 host_pid[E500_PID_NUM];
71 	u32 pid[E500_PID_NUM];
72 	u32 svr;
73 
74 	/* vcpu id table */
75 	struct vcpu_id_table *idt;
76 
77 	u32 l1csr0;
78 	u32 l1csr1;
79 	u32 hid0;
80 	u32 hid1;
81 	u32 tlb0cfg;
82 	u32 tlb1cfg;
83 	u64 mcar;
84 
85 	struct page **shared_tlb_pages;
86 	int num_shared_tlb_pages;
87 
88 	struct kvm_vcpu vcpu;
89 };
90 
to_e500(struct kvm_vcpu * vcpu)91 static inline struct kvmppc_vcpu_e500 *to_e500(struct kvm_vcpu *vcpu)
92 {
93 	return container_of(vcpu, struct kvmppc_vcpu_e500, vcpu);
94 }
95 
96 #endif /* __ASM_KVM_E500_H__ */
97