Fix CPU spinlock lockups on secondary CPU bringup
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / powerpc / kvm / e500.c
blobe3768ee9b59537bf92eceb853fa9edf56d7d5b6c
1 /*
2 * Copyright (C) 2008 Freescale Semiconductor, Inc. All rights reserved.
4 * Author: Yu Liu, <yu.liu@freescale.com>
6 * Description:
7 * This file is derived from arch/powerpc/kvm/44x.c,
8 * by Hollis Blanchard <hollisb@us.ibm.com>.
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.
15 #include <linux/kvm_host.h>
16 #include <linux/slab.h>
17 #include <linux/err.h>
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>
25 #include "booke.h"
26 #include "e500_tlb.h"
28 void kvmppc_core_load_host_debugstate(struct kvm_vcpu *vcpu)
32 void kvmppc_core_load_guest_debugstate(struct kvm_vcpu *vcpu)
36 void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
38 kvmppc_e500_tlb_load(vcpu, cpu);
41 void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu)
43 kvmppc_e500_tlb_put(vcpu);
46 int kvmppc_core_check_processor_compat(void)
48 int r;
50 if (strcmp(cur_cpu_spec->cpu_name, "e500v2") == 0)
51 r = 0;
52 else
53 r = -ENOTSUPP;
55 return r;
58 int kvmppc_core_vcpu_setup(struct kvm_vcpu *vcpu)
60 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
62 kvmppc_e500_tlb_setup(vcpu_e500);
64 /* Registers init */
65 vcpu->arch.pvr = mfspr(SPRN_PVR);
67 /* Since booke kvm only support one core, update all vcpus' PIR to 0 */
68 vcpu->vcpu_id = 0;
70 return 0;
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)
77 int index;
78 gva_t eaddr;
79 u8 pid;
80 u8 as;
82 eaddr = tr->linear_address;
83 pid = (tr->linear_address >> 32) & 0xff;
84 as = (tr->linear_address >> 40) & 0x1;
86 index = kvmppc_e500_tlb_search(vcpu, eaddr, pid, as);
87 if (index < 0) {
88 tr->valid = 0;
89 return 0;
92 tr->physical_address = kvmppc_mmu_xlate(vcpu, index, eaddr);
93 /* XXX what does "writeable" and "usermode" even mean? */
94 tr->valid = 1;
96 return 0;
99 struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id)
101 struct kvmppc_vcpu_e500 *vcpu_e500;
102 struct kvm_vcpu *vcpu;
103 int err;
105 vcpu_e500 = kmem_cache_zalloc(kvm_vcpu_cache, GFP_KERNEL);
106 if (!vcpu_e500) {
107 err = -ENOMEM;
108 goto out;
111 vcpu = &vcpu_e500->vcpu;
112 err = kvm_vcpu_init(vcpu, kvm, id);
113 if (err)
114 goto free_vcpu;
116 err = kvmppc_e500_tlb_init(vcpu_e500);
117 if (err)
118 goto uninit_vcpu;
120 vcpu->arch.shared = (void*)__get_free_page(GFP_KERNEL|__GFP_ZERO);
121 if (!vcpu->arch.shared)
122 goto uninit_tlb;
124 return vcpu;
126 uninit_tlb:
127 kvmppc_e500_tlb_uninit(vcpu_e500);
128 uninit_vcpu:
129 kvm_vcpu_uninit(vcpu);
130 free_vcpu:
131 kmem_cache_free(kvm_vcpu_cache, vcpu_e500);
132 out:
133 return ERR_PTR(err);
136 void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu)
138 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
140 free_page((unsigned long)vcpu->arch.shared);
141 kvm_vcpu_uninit(vcpu);
142 kvmppc_e500_tlb_uninit(vcpu_e500);
143 kmem_cache_free(kvm_vcpu_cache, vcpu_e500);
146 static int __init kvmppc_e500_init(void)
148 int r, i;
149 unsigned long ivor[3];
150 unsigned long max_ivor = 0;
152 r = kvmppc_booke_init();
153 if (r)
154 return r;
156 /* copy extra E500 exception handlers */
157 ivor[0] = mfspr(SPRN_IVOR32);
158 ivor[1] = mfspr(SPRN_IVOR33);
159 ivor[2] = mfspr(SPRN_IVOR34);
160 for (i = 0; i < 3; i++) {
161 if (ivor[i] > max_ivor)
162 max_ivor = ivor[i];
164 memcpy((void *)kvmppc_booke_handlers + ivor[i],
165 kvmppc_handlers_start + (i + 16) * kvmppc_handler_len,
166 kvmppc_handler_len);
168 flush_icache_range(kvmppc_booke_handlers,
169 kvmppc_booke_handlers + max_ivor + kvmppc_handler_len);
171 return kvm_init(NULL, sizeof(struct kvmppc_vcpu_e500), 0, THIS_MODULE);
174 static void __exit kvmppc_e500_exit(void)
176 kvmppc_booke_exit();
179 module_init(kvmppc_e500_init);
180 module_exit(kvmppc_e500_exit);