public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Cc: kvm-ppc-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Subject: [PATCH 6 of 7] Add powerpc KVM support to qemu
Date: Sun, 27 Jan 2008 21:16:29 -0600	[thread overview]
Message-ID: <bf22e220977099e60b57.1201490189@thinkpad> (raw)
In-Reply-To: <patchbomb.1201490183@thinkpad>

# HG changeset patch
# User Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
# Date 1201490017 21600
# Node ID bf22e220977099e60b57be9e16d7d96487defdc1
# Parent  391b6488213008a4502b1753c26e8bd5200bd3c6
Add powerpc KVM support to qemu.

This patch adds needed files and other modifications for supporting  of powerpc KVM within qemu.

Signed-off-by: Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
Signed-off-by: Christian Ehrhardt <ehrhardt-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>

diff --git a/qemu/qemu-kvm-powerpc.c b/qemu/qemu-kvm-powerpc.c
new file mode 100644
--- /dev/null
+++ b/qemu/qemu-kvm-powerpc.c
@@ -0,0 +1,198 @@
+
+#include "config.h"
+#include "config-host.h"
+
+extern int kvm_allowed;
+extern int kvm_irqchip;
+
+#ifdef USE_KVM
+
+#include <string.h>
+#include "hw/hw.h"
+#include "sysemu.h"
+#include "cpu.h"
+#include "helper_regs.h"
+
+#include "qemu-kvm.h"
+#include <libkvm.h>
+#include <pthread.h>
+#include <sys/utsname.h>
+
+extern kvm_context_t kvm_context;
+extern __thread CPUState *vcpu_env;
+
+void cpu_reset(CPUState *env)
+{
+	cpu_ppc_reset(env);
+}
+
+
+int kvm_arch_qemu_create_context(void)
+{
+	return 0;
+}
+
+void kvm_arch_load_regs(CPUState *env)
+{
+    struct kvm_regs regs;
+    int rc,i;
+
+    rc = kvm_get_regs(kvm_context, env->cpu_index, &regs);
+    if (rc == -1)
+        perror("kvm_get_regs FAILED");
+
+    /* cr is untouched in qemu and not existant in CPUState fr ppr */
+    /* hflags is a morphed to MSR on ppc, no need to sync that down to kvm */
+
+    regs.pc = env->nip;
+
+    regs.ctr = env->ctr;
+    regs.lr  = env->lr;
+    regs.xer = ppc_load_xer(env);
+    regs.msr = env->msr; 
+
+    regs.srr0 = env->spr[SPR_SRR0];
+    regs.srr1 = env->spr[SPR_SRR1];
+
+    regs.sprg0 = env->spr[SPR_SPRG0];
+    regs.sprg1 = env->spr[SPR_SPRG1];
+    regs.sprg2 = env->spr[SPR_SPRG2];
+    regs.sprg3 = env->spr[SPR_SPRG3];
+    regs.sprg4 = env->spr[SPR_SPRG4];
+    regs.sprg5 = env->spr[SPR_SPRG5];
+    regs.sprg6 = env->spr[SPR_SPRG6];
+    regs.sprg7 = env->spr[SPR_SPRG7];
+
+    for (i = 0;i < 32; i++){
+        regs.gpr[i] = env->gpr[i];
+        regs.fpr[i] = env->fpr[i];
+    }
+
+    rc = kvm_set_regs(kvm_context, env->cpu_index, &regs);
+    if (rc == -1)
+        perror("kvm_set_regs FAILED");
+}
+
+
+void kvm_arch_save_regs(CPUState *env)
+{
+    struct kvm_regs regs;
+    uint32_t i, rc;
+
+    rc = kvm_get_regs(kvm_context, env->cpu_index, &regs);
+    if (rc == -1)
+        perror("kvm_get_regs FAILED");
+
+    env->ctr =regs.ctr;
+    env->lr = regs.lr;
+    ppc_store_xer(env,regs.xer);
+    env->msr = regs.msr;
+    /* calculate hflags based on the current msr using the ppc qemu helper */
+    hreg_compute_hflags(env);
+
+    env->nip = regs.pc;
+
+    env->spr[SPR_SRR0] = regs.srr0;
+    env->spr[SPR_SRR1] = regs.srr1;
+
+    env->spr[SPR_SPRG0] = regs.sprg0;
+    env->spr[SPR_SPRG1] = regs.sprg1;
+    env->spr[SPR_SPRG2] = regs.sprg2;
+    env->spr[SPR_SPRG3] = regs.sprg3;
+    env->spr[SPR_SPRG4] = regs.sprg4;
+    env->spr[SPR_SPRG5] = regs.sprg5;
+    env->spr[SPR_SPRG6] = regs.sprg6;
+    env->spr[SPR_SPRG7] = regs.sprg7;
+
+    for (i = 0;i < 32; i++){
+        env->gpr[i] = regs.gpr[i];
+        env->fpr[i] = regs.fpr[i];
+    }
+
+}
+
+int kvm_arch_qemu_init_env(CPUState *cenv)
+{
+    return 0;
+}
+
+int kvm_arch_halt(void *opaque, int vcpu)
+{
+    CPUState *env = cpu_single_env;
+
+    if (!(env->interrupt_request & CPU_INTERRUPT_HARD) 
+	&& (msr_ee))
+    {
+            env->halted = 1;
+	    env->exception_index = EXCP_HLT;
+    }
+    return 1;
+}
+
+void kvm_arch_pre_kvm_run(void *opaque, int vcpu)
+{
+	return;
+}
+
+void kvm_arch_post_kvm_run(void *opaque, int vcpu)
+{  
+    CPUState *env = qemu_kvm_cpu_env(vcpu);
+    cpu_single_env = env;
+    env->ready_for_interrupt_injection = \
+	kvm_is_ready_for_interrupt_injection(kvm_context, vcpu);
+}
+
+int kvm_arch_has_work(CPUState *env)
+{
+    if ((env->interrupt_request & (CPU_INTERRUPT_HARD | CPU_INTERRUPT_EXIT)) &&
+	(msr_ee))
+	return 1;
+    return 0;
+}
+
+int kvm_arch_try_push_interrupts(void *opaque)
+{
+    CPUState *env = cpu_single_env;
+    int r;
+    unsigned irq;
+
+    if (env->ready_for_interrupt_injection &&
+        (env->interrupt_request & CPU_INTERRUPT_HARD))
+       { 
+            env->interrupt_request &= ~CPU_INTERRUPT_HARD;
+
+            /* For now KVM disregards the 'irq' argument. However, in the
+             * future KVM could cache it in-kernel to avoid a heavyweight exit
+             * when reading the UIC. 
+             */
+            irq = -1U;
+
+            r = kvm_inject_irq(kvm_context, env->cpu_index, irq);
+            if (r < 0)
+                printf("cpu %d fail inject %x\n", env->cpu_index, irq);
+    }
+
+    return (env->interrupt_request & CPU_INTERRUPT_HARD) != 0;
+}
+
+void kvm_arch_update_regs_for_sipi(CPUState *env)
+{
+    printf("%s: no kvm-powerpc multi processor support yet!\n", __func__);
+}
+
+/* map dcr access to existing qemu dcr emulation */
+int handle_powerpc_dcr_read(int vcpu, uint32_t dcrn, uint32_t *data)
+{
+    CPUState *env = qemu_kvm_cpu_env(vcpu);
+    ppc_dcr_read(env->dcr_env, dcrn, data);
+    return 0; /* XXX ignore failed DCR ops */
+}
+
+int handle_powerpc_dcr_write(int vcpu, uint32_t dcrn, uint32_t data)
+{
+    CPUState *env = qemu_kvm_cpu_env(vcpu);
+    ppc_dcr_write(env->dcr_env, dcrn, data);
+    return 0; /* XXX ignore failed DCR ops */
+}
+
+#endif
diff --git a/qemu/qemu-kvm.h b/qemu/qemu-kvm.h
--- a/qemu/qemu-kvm.h
+++ b/qemu/qemu-kvm.h
@@ -55,8 +55,8 @@ int handle_tpr_access(void *opaque, int 
 			     uint64_t rip, int is_write);
 
 #ifdef TARGET_PPC
-int handle_powerpc_dcr_read(uint32_t dcrn, uint32_t *data);
-int handle_powerpc_dcr_write(uint32_t dcrn, uint32_t data);
+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);
 #endif
 
 #define ALIGN(x, y)  (((x)+(y)-1) & ~((y)-1))
diff --git a/qemu/target-ppc/cpu.h b/qemu/target-ppc/cpu.h
--- a/qemu/target-ppc/cpu.h
+++ b/qemu/target-ppc/cpu.h
@@ -573,6 +573,10 @@ struct CPUPPCState {
     target_ulong msr;
     /* temporary general purpose registers */
     ppc_gpr_t tgpr[4]; /* Used to speed-up TLB assist handlers */
+	
+#ifdef USE_KVM
+    uint8_t ready_for_interrupt_injection;
+#endif
 
     /* Floating point execution context */
     /* temporary float registers */
@@ -1421,4 +1425,11 @@ enum {
 
 /*****************************************************************************/
 
+/* hidden flags (hflags) - used internally by qemu to represent additional
+ * cpu states.
+ */
+#define HF_HALTED_SHIFT 1
+
+#define HF_HALTED_MASK 1<<HF_HALTED_SHIFT
+
 #endif /* !defined (__CPU_PPC_H__) */

-------------------------------------------------------------------------
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/

  parent reply	other threads:[~2008-01-28  3:16 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-28  3:16 [PATCH 0 of 7] PowerPC Embedded KVM qemu enablement patches Jerone Young
2008-01-28  3:16 ` [PATCH 1 of 7] Enhnace kvm-userspace configure script for powerpc Jerone Young
2008-01-28  3:16 ` [PATCH 2 of 7] Ensure 4kB page alignment for embedded powerpc when using kvm Jerone Young
2008-01-28  3:16 ` [PATCH 3 of 7] Chnage so that Powerpc & IA64 do not have KVM_EXTRA_PAGES set Jerone Young
2008-01-28  3:16 ` [PATCH 4 of 7] Add vcpu to arguments of powerpc libkvm callbacks Jerone Young
2008-01-28  3:16 ` [PATCH 5 of 7] Add qemu powerpc build support Jerone Young
2008-01-28  3:16 ` Jerone Young [this message]
2008-01-28  3:16 ` [PATCH 7 of 7] Add Powerpc 440 board model "bamboo" to take advantage of Powerpc KVM Jerone Young
2008-01-28  3:46 ` [PATCH 0 of 7] PowerPC Embedded KVM qemu enablement patches Anthony Liguori
     [not found]   ` <479D5032.6050807-rdkfGonbjUSkNkDKm+mE6A@public.gmane.org>
2008-01-28 16:01     ` Jerone Young
2008-01-28 16:17       ` Anthony Liguori
     [not found]         ` <479E0029.3090906-rdkfGonbjUSkNkDKm+mE6A@public.gmane.org>
2008-01-28 16:20           ` Jerone Young
2008-01-28 16:48           ` [kvm-ppc-devel] " Hollis Blanchard
2008-01-28 11:03 ` Avi Kivity

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bf22e220977099e60b57.1201490189@thinkpad \
    --to=jyoung5-r/jw6+rmf7hqt0dzr+alfa@public.gmane.org \
    --cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    --cc=kvm-ppc-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox