]>
Commit | Line | Data |
---|---|---|
bc8080cb HB |
1 | /* |
2 | * Copyright (C) 2008 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/kvm/44x.c, | |
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 | #include <linux/kvm_host.h> | |
5a0e3ad6 | 16 | #include <linux/slab.h> |
bc8080cb HB |
17 | #include <linux/err.h> |
18 | ||
19 | #include <asm/reg.h> | |
20 | #include <asm/cputable.h> | |
21 | #include <asm/tlbflush.h> | |
22 | #include <asm/kvm_e500.h> | |
23 | #include <asm/kvm_ppc.h> | |
24 | ||
bb3a8a17 | 25 | #include "booke.h" |
bc8080cb HB |
26 | #include "e500_tlb.h" |
27 | ||
28 | void kvmppc_core_load_host_debugstate(struct kvm_vcpu *vcpu) | |
29 | { | |
30 | } | |
31 | ||
32 | void kvmppc_core_load_guest_debugstate(struct kvm_vcpu *vcpu) | |
33 | { | |
34 | } | |
35 | ||
36 | void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu) | |
37 | { | |
38 | kvmppc_e500_tlb_load(vcpu, cpu); | |
39 | } | |
40 | ||
41 | void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu) | |
42 | { | |
43 | kvmppc_e500_tlb_put(vcpu); | |
44 | } | |
45 | ||
46 | int kvmppc_core_check_processor_compat(void) | |
47 | { | |
48 | int r; | |
49 | ||
50 | if (strcmp(cur_cpu_spec->cpu_name, "e500v2") == 0) | |
51 | r = 0; | |
52 | else | |
53 | r = -ENOTSUPP; | |
54 | ||
55 | return r; | |
56 | } | |
57 | ||
58 | int kvmppc_core_vcpu_setup(struct kvm_vcpu *vcpu) | |
59 | { | |
60 | struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu); | |
61 | ||
62 | kvmppc_e500_tlb_setup(vcpu_e500); | |
63 | ||
a9040f27 LY |
64 | /* Registers init */ |
65 | vcpu->arch.pvr = mfspr(SPRN_PVR); | |
66 | ||
67 | /* Since booke kvm only support one core, update all vcpus' PIR to 0 */ | |
68 | vcpu->vcpu_id = 0; | |
69 | ||
bc8080cb HB |
70 | return 0; |
71 | } | |
72 | ||
73 | /* 'linear_address' is actually an encoding of AS|PID|EADDR . */ | |
74 | int kvmppc_core_vcpu_translate(struct kvm_vcpu *vcpu, | |
75 | struct kvm_translation *tr) | |
76 | { | |
77 | int index; | |
78 | gva_t eaddr; | |
79 | u8 pid; | |
80 | u8 as; | |
81 | ||
82 | eaddr = tr->linear_address; | |
83 | pid = (tr->linear_address >> 32) & 0xff; | |
84 | as = (tr->linear_address >> 40) & 0x1; | |
85 | ||
86 | index = kvmppc_e500_tlb_search(vcpu, eaddr, pid, as); | |
87 | if (index < 0) { | |
88 | tr->valid = 0; | |
89 | return 0; | |
90 | } | |
91 | ||
92 | tr->physical_address = kvmppc_mmu_xlate(vcpu, index, eaddr); | |
93 | /* XXX what does "writeable" and "usermode" even mean? */ | |
94 | tr->valid = 1; | |
95 | ||
96 | return 0; | |
97 | } | |
98 | ||
99 | struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id) | |
100 | { | |
101 | struct kvmppc_vcpu_e500 *vcpu_e500; | |
102 | struct kvm_vcpu *vcpu; | |
103 | int err; | |
104 | ||
105 | vcpu_e500 = kmem_cache_zalloc(kvm_vcpu_cache, GFP_KERNEL); | |
106 | if (!vcpu_e500) { | |
107 | err = -ENOMEM; | |
108 | goto out; | |
109 | } | |
110 | ||
111 | vcpu = &vcpu_e500->vcpu; | |
112 | err = kvm_vcpu_init(vcpu, kvm, id); | |
113 | if (err) | |
114 | goto free_vcpu; | |
115 | ||
116 | err = kvmppc_e500_tlb_init(vcpu_e500); | |
117 | if (err) | |
118 | goto uninit_vcpu; | |
119 | ||
120 | return vcpu; | |
121 | ||
122 | uninit_vcpu: | |
123 | kvm_vcpu_uninit(vcpu); | |
124 | free_vcpu: | |
125 | kmem_cache_free(kvm_vcpu_cache, vcpu_e500); | |
126 | out: | |
127 | return ERR_PTR(err); | |
128 | } | |
129 | ||
130 | void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu) | |
131 | { | |
132 | struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu); | |
133 | ||
134 | kvmppc_e500_tlb_uninit(vcpu_e500); | |
135 | kvm_vcpu_uninit(vcpu); | |
136 | kmem_cache_free(kvm_vcpu_cache, vcpu_e500); | |
137 | } | |
138 | ||
2986b8c7 | 139 | static int __init kvmppc_e500_init(void) |
bc8080cb | 140 | { |
bb3a8a17 HB |
141 | int r, i; |
142 | unsigned long ivor[3]; | |
143 | unsigned long max_ivor = 0; | |
bc8080cb HB |
144 | |
145 | r = kvmppc_booke_init(); | |
146 | if (r) | |
147 | return r; | |
148 | ||
bb3a8a17 HB |
149 | /* copy extra E500 exception handlers */ |
150 | ivor[0] = mfspr(SPRN_IVOR32); | |
151 | ivor[1] = mfspr(SPRN_IVOR33); | |
152 | ivor[2] = mfspr(SPRN_IVOR34); | |
153 | for (i = 0; i < 3; i++) { | |
154 | if (ivor[i] > max_ivor) | |
155 | max_ivor = ivor[i]; | |
156 | ||
157 | memcpy((void *)kvmppc_booke_handlers + ivor[i], | |
158 | kvmppc_handlers_start + (i + 16) * kvmppc_handler_len, | |
159 | kvmppc_handler_len); | |
160 | } | |
161 | flush_icache_range(kvmppc_booke_handlers, | |
162 | kvmppc_booke_handlers + max_ivor + kvmppc_handler_len); | |
163 | ||
bc8080cb HB |
164 | return kvm_init(NULL, sizeof(struct kvmppc_vcpu_e500), THIS_MODULE); |
165 | } | |
166 | ||
2986b8c7 | 167 | static void __init kvmppc_e500_exit(void) |
bc8080cb HB |
168 | { |
169 | kvmppc_booke_exit(); | |
170 | } | |
171 | ||
172 | module_init(kvmppc_e500_init); | |
173 | module_exit(kvmppc_e500_exit); |