Unlike last version, I don't refactor any property from kvm_vcpu_arch this time.
Just change necessary interfaces to make it easy for other cores' refactoring.
And this make the patch shorter and easier to read.
Signed-off-by: Liu Yu <[EMAIL PROTECTED]>
---
arch/powerpc/include/asm/kvm_host.h | 5 +++
arch/powerpc/kvm/44x.c | 49 +++++++++++++++++++++++++++++++++++
arch/powerpc/kvm/44x.h | 14 ++++++++++
arch/powerpc/kvm/booke_host.c | 12 +++-----
arch/powerpc/kvm/powerpc.c | 26 +++---------------
5 files changed, 77 insertions(+), 29 deletions(-)
create mode 100644 arch/powerpc/kvm/44x.c
create mode 100644 arch/powerpc/kvm/44x.h
diff --git a/arch/powerpc/include/asm/kvm_host.h
b/arch/powerpc/include/asm/kvm_host.h
index df73351..c61e295 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -156,6 +156,11 @@ struct kvm_vcpu_arch {
unsigned long pending_exceptions;
};
+struct kvm_powerpc_ops {
+ struct kvm_vcpu *(*vcpu_create)(struct kvm *kvm, unsigned id);
+ void (*vcpu_free)(struct kvm_vcpu *vcpu);
+}
+
struct kvm_guest_debug {
int enabled;
unsigned long bp[4];
diff --git a/arch/powerpc/kvm/44x.c b/arch/powerpc/kvm/44x.c
new file mode 100644
index 0000000..e03f2df
--- /dev/null
+++ b/arch/powerpc/kvm/44x.c
@@ -0,0 +1,49 @@
+
+#include <linux/kvm_host.h>
+#include <linux/module.h>
+
+#include "44x.h"
+
+static struct kvm_vcpu *44x_create_vcpu(struct kvm *kvm, unsigned int id)
+{
+ struct vcpu_44x *44x = kmem_cache_zalloc(kvm_vcpu_cache, GFP_KERNEL);
+ int err;
+ if (!44x)
+ return ERR_PTR(-ENOMEM);
+
+ err = kvm_vcpu_init(vcpu, kvm, id);
+ if (err)
+ goto free_vcpu;
+
+ return &44x->vcpu;
+
+free_vcpu:
+ kmem_cache_free(kvm_vcpu_cache, vcpu);
+ return ERR_PTR(err);
+}
+
+static void 44x_free_vcpu(struct kvm_vcpu *vcpu)
+{
+ kvm_vcpu_uninit(vcpu);
+ kmem_cache_free(kvm_vcpu_cache, vcpu);
+}
+
+static struct kvm_powerpc_ops 44x_powerpc_ops = {
+ .vcpu_create = 44x_create_vcpu,
+ .vcpu_free = 44x_free_vcpu
+};
+
+static void booke_44x_init(void)
+{
+ kvmppc_booke_init();
+ return kvm_init(44x_powerpc_ops, sizeof(struct vcpu_44x), THIS_MODULE);
+}
+
+static void __exit booke_44x_exit(void)
+{
+ kvmppc_booke_exit();
+ kvm_exit();
+}
+
+module_init(booke_44x_init)
+module_exit(booke_44x_exit)
diff --git a/arch/powerpc/kvm/44x.h b/arch/powerpc/kvm/44x.h
new file mode 100644
index 0000000..543754a
--- /dev/null
+++ b/arch/powerpc/kvm/44x.h
@@ -0,0 +1,14 @@
+#ifndef __KVM_POWERPC_44X_H__
+#define __KVM_POWERPC_44X_H__
+
+struct vcpu_44x {
+ struct kvm_vcpu vcpu;
+ /* define special things below */
+};
+
+static inline struct vcpu_44x *to_44x(struct kvm_vcpu *vcpu)
+{
+ return container_of(vcpu, struct vcpu_44x, vcpu);
+}
+
+#endif /* __KVM_POWERPC_44X_H__ */
diff --git a/arch/powerpc/kvm/booke_host.c b/arch/powerpc/kvm/booke_host.c
index b480341..6d45e7d 100644
--- a/arch/powerpc/kvm/booke_host.c
+++ b/arch/powerpc/kvm/booke_host.c
@@ -19,13 +19,12 @@
#include <linux/errno.h>
#include <linux/kvm_host.h>
-#include <linux/module.h>
#include <asm/cacheflush.h>
#include <asm/kvm_ppc.h>
unsigned long kvmppc_booke_handlers;
-static int kvmppc_booke_init(void)
+void kvmppc_booke_init(void)
{
unsigned long ivor[16];
unsigned long max_ivor = 0;
@@ -69,15 +68,12 @@ static int kvmppc_booke_init(void)
}
flush_icache_range(kvmppc_booke_handlers,
kvmppc_booke_handlers + max_ivor +
kvmppc_handler_len);
-
- return kvm_init(NULL, sizeof(struct kvm_vcpu), THIS_MODULE);
}
+EXPORT_SYMBOL_GPL(kvmppc_booke_init);
-static void __exit kvmppc_booke_exit(void)
+void __exit kvmppc_booke_exit(void)
{
free_pages(kvmppc_booke_handlers, VCPU_SIZE_ORDER);
- kvm_exit();
}
+EXPORT_SYMBOL_GPL(kvmppc_booke_exit);
-module_init(kvmppc_booke_init)
-module_exit(kvmppc_booke_exit)
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 90a6fc4..6d0e6c5 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -29,6 +29,8 @@
#include <asm/kvm_ppc.h>
#include <asm/tlbflush.h>
+struct kvm_powerpc_ops *kvm_powerpc_ops;
+EXPORT_SYMBOL_GPL(kvm_powerpc_ops);
gfn_t unalias_gfn(struct kvm *kvm, gfn_t gfn)
{
@@ -177,31 +179,12 @@ void kvm_arch_flush_shadow(struct kvm *kvm)
struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id)
{
- struct kvm_vcpu *vcpu;
- int err;
-
- vcpu = kmem_cache_zalloc(kvm_vcpu_cache, GFP_KERNEL);
- if (!vcpu) {
- err = -ENOMEM;
- goto out;
- }
-
- err = kvm_vcpu_init(vcpu, kvm, id);
- if (err)
- goto free_vcpu;
-
- return vcpu;
-
-free_vcpu:
- kmem_cache_free(kvm_vcpu_cache, vcpu);
-out:
- return ERR_PTR(err);
+ return kvm_powerpc_ops->vcpu_create(kvm, id);
}
void kvm_arch_vcpu_free(struct kvm_vcpu *vcpu)
{
- kvm_vcpu_uninit(vcpu);
- kmem_cache_free(kvm_vcpu_cache, vcpu);
+ kvm_powerpc_ops->vcpu_free(vcpu);
}
void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)
@@ -542,6 +525,7 @@ long kvm_arch_vm_ioctl(struct file *filp,
int kvm_arch_init(void *opaque)
{
+ kvm_powerpc_ops = (struct kvm_powerpc_ops *)opaque;
return 0;
}
--
1.5.4
--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at http://vger.kernel.org/majordomo-info.html