"[PATCH] Fix leaks on /proc/{*/sched,sched_debug,timer_list,timer_stats}" and
[mmotm.git] / arch / powerpc / kvm / e500.c
blob64949eef43f12994f9d75ee7eb86eb11d03b2d5b
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/err.h>
18 #include <asm/reg.h>
19 #include <asm/cputable.h>
20 #include <asm/tlbflush.h>
21 #include <asm/kvm_e500.h>
22 #include <asm/kvm_ppc.h>
24 #include "booke.h"
25 #include "e500_tlb.h"
27 void kvmppc_core_load_host_debugstate(struct kvm_vcpu *vcpu)
31 void kvmppc_core_load_guest_debugstate(struct kvm_vcpu *vcpu)
35 void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
37 kvmppc_e500_tlb_load(vcpu, cpu);
40 void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu)
42 kvmppc_e500_tlb_put(vcpu);
45 int kvmppc_core_check_processor_compat(void)
47 int r;
49 if (strcmp(cur_cpu_spec->cpu_name, "e500v2") == 0)
50 r = 0;
51 else
52 r = -ENOTSUPP;
54 return r;
57 int kvmppc_core_vcpu_setup(struct kvm_vcpu *vcpu)
59 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
61 kvmppc_e500_tlb_setup(vcpu_e500);
63 return 0;
66 /* 'linear_address' is actually an encoding of AS|PID|EADDR . */
67 int kvmppc_core_vcpu_translate(struct kvm_vcpu *vcpu,
68 struct kvm_translation *tr)
70 int index;
71 gva_t eaddr;
72 u8 pid;
73 u8 as;
75 eaddr = tr->linear_address;
76 pid = (tr->linear_address >> 32) & 0xff;
77 as = (tr->linear_address >> 40) & 0x1;
79 index = kvmppc_e500_tlb_search(vcpu, eaddr, pid, as);
80 if (index < 0) {
81 tr->valid = 0;
82 return 0;
85 tr->physical_address = kvmppc_mmu_xlate(vcpu, index, eaddr);
86 /* XXX what does "writeable" and "usermode" even mean? */
87 tr->valid = 1;
89 return 0;
92 struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id)
94 struct kvmppc_vcpu_e500 *vcpu_e500;
95 struct kvm_vcpu *vcpu;
96 int err;
98 vcpu_e500 = kmem_cache_zalloc(kvm_vcpu_cache, GFP_KERNEL);
99 if (!vcpu_e500) {
100 err = -ENOMEM;
101 goto out;
104 vcpu = &vcpu_e500->vcpu;
105 err = kvm_vcpu_init(vcpu, kvm, id);
106 if (err)
107 goto free_vcpu;
109 err = kvmppc_e500_tlb_init(vcpu_e500);
110 if (err)
111 goto uninit_vcpu;
113 return vcpu;
115 uninit_vcpu:
116 kvm_vcpu_uninit(vcpu);
117 free_vcpu:
118 kmem_cache_free(kvm_vcpu_cache, vcpu_e500);
119 out:
120 return ERR_PTR(err);
123 void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu)
125 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
127 kvmppc_e500_tlb_uninit(vcpu_e500);
128 kvm_vcpu_uninit(vcpu);
129 kmem_cache_free(kvm_vcpu_cache, vcpu_e500);
132 static int __init kvmppc_e500_init(void)
134 int r, i;
135 unsigned long ivor[3];
136 unsigned long max_ivor = 0;
138 r = kvmppc_booke_init();
139 if (r)
140 return r;
142 /* copy extra E500 exception handlers */
143 ivor[0] = mfspr(SPRN_IVOR32);
144 ivor[1] = mfspr(SPRN_IVOR33);
145 ivor[2] = mfspr(SPRN_IVOR34);
146 for (i = 0; i < 3; i++) {
147 if (ivor[i] > max_ivor)
148 max_ivor = ivor[i];
150 memcpy((void *)kvmppc_booke_handlers + ivor[i],
151 kvmppc_handlers_start + (i + 16) * kvmppc_handler_len,
152 kvmppc_handler_len);
154 flush_icache_range(kvmppc_booke_handlers,
155 kvmppc_booke_handlers + max_ivor + kvmppc_handler_len);
157 return kvm_init(NULL, sizeof(struct kvmppc_vcpu_e500), THIS_MODULE);
160 static void __init kvmppc_e500_exit(void)
162 kvmppc_booke_exit();
165 module_init(kvmppc_e500_init);
166 module_exit(kvmppc_e500_exit);