Skip to contentSkip to conversation

Add per guest pvr (userspace)

PATCH In review [email protected] 1 participant 2 messages Jan 30, 2008 – Jan 31, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 2/4 Add per guest pvr (userspace)

Subject: [PATCH] [2/4] Add per guest pvr (userspace)
From: Christian Ehrhardt <[email protected]>

This adds a per VM variable called pvr in imitation of the hardware spr. It also adds a interface to get/set this variable to the vm ioctl. Atm it uses non-real pvr values to allow us to differ on runtime e.g. between ppc440 and e500 guests.

---

 libkvm/libkvm-powerpc.c |   21 ++++++++++++++++++++-
 libkvm/libkvm.h         |    4 ++++
 qemu/vl.c               |    7 +++++++
 3 files changed, 31 insertions(+), 1 deletion(-)
libkvm/libkvm-powerpc.c +20 -1
@@ -25,6 +25,10 @@
 #include "kvm-powerpc.h"
 #include <errno.h>
 #include <stdio.h>
+#include <sys/ioctl.h>
+
+/* need to be available prior to kvm_arch_create and prior to qemu env setup */
+static struct kvm_pvr kvm_guest_pvr;
 
 int handle_dcr(struct kvm_run *run,  kvm_context_t kvm, int vcpu)
 {
@@ -85,10 +89,25 @@ void kvm_show_regs(kvm_context_t kvm, in
 	fflush(stdout);
 }
 
+void kvm_init_guest_pvr(uint32_t guest_pvr)
+{
+	kvm_guest_pvr.pvr = guest_pvr;
+}
+
 int kvm_arch_create(kvm_context_t kvm, unsigned long phys_mem_bytes,
 			 void **vm_mem)
 {
-	return 0;
+	int r = 0;
+
+	if (kvm_guest_pvr.pvr = 0)
+		/* we might want to set a useful default here */
+		fprintf(stderr, "%s warning - pvr not set\n", __func__);
+
+	r = ioctl(kvm->vm_fd, KVM_SET_GUEST_PVR, &kvm_guest_pvr);
+	if (r)
+		fprintf(stderr, "%s failed (r='%d')\n", __func__, r);
+
+	return r;
 }
 
 int kvm_arch_create_default_phys_mem(kvm_context_t kvm,
libkvm/libkvm.h +4 -0
@@ -556,4 +556,8 @@ int kvm_enable_vapic(kvm_context_t kvm, 
 
 #endif
 
+#if defined(__powerpc__)
+void kvm_init_guest_pvr(uint32_t guest_pvr);
 #endif
+
+#endif
qemu/vl.c +7 -0
@@ -9319,6 +9319,13 @@ int main(int argc, char **argv)
 #else
 #define KVM_EXTRA_PAGES 0
 #endif
+
+#ifdef TARGET_PPC
+/* initialize wanted pvr in libkvm prior to first create call */
+if (machine = &bamboo_machine)
+	kvm_init_guest_pvr(KVM_PPC_PVR_PPC44X);
+#endif
+
     if (kvm_allowed) {
 	    phys_ram_size += KVM_EXTRA_PAGES * TARGET_PAGE_SIZE;
 	    if (kvm_qemu_create_context() < 0) {

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
kvm-ppc-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-ppc-devel

#1 lore raw

PATCH 2/4 Add per guest pvr (userspace)

From: Christian Ehrhardt <[email protected]>

This adds a per vcpu interface to get/set the the pvr.
The current patch sets the pvr for a PPC440EP when the selected guest type is a bamboo machine.

---

 libkvm/libkvm-powerpc.c |   21 +++++++++++++++++++++
 libkvm/libkvm.h         |    4 ++++
 qemu/hw/ppc440_bamboo.c |    1 +
 qemu/qemu-kvm-powerpc.c |    5 +++++
 qemu/qemu-kvm.h         |    1 +
 qemu/vl.c               |    1 +
 6 files changed, 33 insertions(+)
libkvm/libkvm-powerpc.c +25 -0
@@ -25,6 +25,7 @@
 #include "kvm-powerpc.h"
 #include <errno.h>
 #include <stdio.h>
+#include <sys/ioctl.h>
 
 int handle_dcr(struct kvm_run *run,  kvm_context_t kvm, int vcpu)
 {
@@ -85,6 +86,30 @@ void kvm_show_regs(kvm_context_t kvm, in
 	fflush(stdout);
 }
 
+int kvm_get_guest_pvr(kvm_context_t kvm, int vcpu)
+{
+	int r = 0;
+	struct kvm_pvr kvm_guest_pvr;
+
+	r = ioctl(kvm->vcpu_fd[vcpu], KVM_GET_GUEST_PVR, &kvm_guest_pvr);
+	if (r)
+		fprintf(stderr, "%s failed (r='%d')\n", __func__, r);
+
+
+	return kvm_guest_pvr.pvr;
+}
+
+void kvm_set_guest_pvr(kvm_context_t kvm, uint32_t guest_pvr, int vcpu)
+{
+	int r = 0;
+	struct kvm_pvr kvm_guest_pvr;
+	kvm_guest_pvr.pvr = guest_pvr;
+
+	r = ioctl(kvm->vcpu_fd[vcpu], KVM_SET_GUEST_PVR, &kvm_guest_pvr);
+	if (r)
+		fprintf(stderr, "%s failed (r='%d')\n", __func__, r);
+}
+
 int kvm_arch_create(kvm_context_t kvm, unsigned long phys_mem_bytes,
 			 void **vm_mem)
 {
libkvm/libkvm.h +4 -0
@@ -556,4 +556,8 @@ int kvm_enable_vapic(kvm_context_t kvm, 
 
 #endif
 
+#if defined(__powerpc__)
+void kvm_set_guest_pvr(kvm_context_t kvm, uint32_t guest_pvr, int vcpu);
 #endif
+
+#endif
qemu/hw/ppc440_bamboo.c +1 -0
@@ -102,6 +102,7 @@ void bamboo_init(ram_addr_t ram_size, in
 	}
 
 #if USE_KVM
+	set_guest_pvr(KVM_PPC_PVR_PPC440EP, env);
 	/* XXX insert TLB entries */
 	env->gpr[1] = (16<<20) - 8;
 	env->gpr[4] = initrd_base;
qemu/qemu-kvm-powerpc.c +5 -0
@@ -194,4 +194,9 @@ int handle_powerpc_dcr_write(int vcpu, u
     return 0; /* XXX ignore failed DCR ops */
 }
 
+void set_guest_pvr(uint32_t guest_pvr, CPUState *env)
+{
+	kvm_set_guest_pvr(kvm_context, guest_pvr, env->cpu_index);
+}
+
 #endif
qemu/qemu-kvm.h +1 -0
@@ -57,6 +57,7 @@ int handle_tpr_access(void *opaque, int 
 #ifdef TARGET_PPC
 int handle_powerpc_dcr_read(int vcpu, uint32_t dcrn, uint32_t *data);
 int handle_powerpc_dcr_write(int vcpu,uint32_t dcrn, uint32_t data);
+void set_guest_pvr(uint32_t guest_pvr, CPUState *env);
 #endif
 
 #define ALIGN(x, y)  (((x)+(y)-1) & ~((y)-1))

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
kvm-ppc-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-ppc-devel