Skip to contentSkip to conversation

Add KVM PowerPC support to qemu's

PATCH New Hollis Blanchard 1 participant 1 message Feb 20, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add KVM PowerPC support to qemu's

# HG changeset patch
# User Hollis Blanchard <[email protected]> # Date 1203483763 21600
# Node ID 909a36f1e755302e3f091e05044dd19d7a833110 # Parent 10d75ce97a3fe28a45f0d97f15f42a488fb0a012

qemu/gdbstub.c +8 -0
@@ -898,6 +898,8 @@ static int gdb_handle_packet(GDBState *s
 		kvm_load_registers(env);
 #elif defined (TARGET_PPC)
             env->nip = addr;
+            if (kvm_enabled())
+                kvm_load_registers(env);
 #elif defined (TARGET_SPARC)
             env->pc = addr;
             env->npc = addr + 4;
@@ -926,6 +928,8 @@ static int gdb_handle_packet(GDBState *s
 		kvm_load_registers(env);
 #elif defined (TARGET_PPC)
             env->nip = addr;
+            if (kvm_enabled())
+                kvm_load_registers(env);
 #elif defined (TARGET_SPARC)
             env->pc = addr;
             env->npc = addr + 4;
@@ -995,6 +999,8 @@ static int gdb_handle_packet(GDBState *s
         if (*p = ',')
             p++;
         len = strtoull(p, NULL, 16);
+        if (kvm_enabled())
+            kvm_save_registers(env);
         if (cpu_memory_rw_debug(env, addr, mem_buf, len, 0) != 0) {
             put_packet (s, "E14");
         } else {
@@ -1010,6 +1016,8 @@ static int gdb_handle_packet(GDBState *s
         if (*p = ':')
             p++;
         hextomem(mem_buf, p, len);
+        if (kvm_enabled())
+            kvm_save_registers(env);
         if (cpu_memory_rw_debug(env, addr, mem_buf, len, 1) != 0)
             put_packet(s, "E14");
         else
qemu/hw/ppc440_bamboo.c +1 -0
@@ -75,6 +75,7 @@ void bamboo_init(ram_addr_t ram_size, in
 		fprintf(stderr, "Unable to initilize CPU!\n");
 		exit(1);
 	}
+	env->mmu_model = POWERPC_MMU_KVM;
 
 	/* call init */
 	printf("Calling function ppc440_init\n");
qemu/qemu-kvm-powerpc.c +28 -0
@@ -101,6 +101,7 @@ void kvm_arch_save_regs(CPUState *env)
 
     env->spr[SPR_SRR0] = regs.srr0;
     env->spr[SPR_SRR1] = regs.srr1;
+    env->spr[SPR_BOOKE_PID] = regs.pid;
 
     env->spr[SPR_SPRG0] = regs.sprg0;
     env->spr[SPR_SPRG1] = regs.sprg1;
@@ -205,3 +206,30 @@ int handle_powerpc_dcr_write(int vcpu, u
 
     return 0; /* XXX ignore failed DCR ops */
 }
+
+int mmukvm_get_physical_address(CPUState *env, mmu_ctx_t *ctx,
+                                target_ulong eaddr, int rw, int access_type)
+{
+    struct kvm_translation tr;
+    uint64_t pid;
+    uint64_t as;
+    int r;
+
+    pid = env->spr[SPR_BOOKE_PID];
+
+    if (access_type = ACCESS_CODE)
+        as = env->msr & msr_ir;
+    else
+        as = env->msr & msr_dr;
+
+    tr.linear_address = as << 40 | pid << 32 | eaddr;
+    r = kvm_translate(kvm_context, env->cpu_index, &tr);
+    if (r = -1)
+        return r;
+
+    if (!tr.valid)
+        return -EFAULT;
+
+    ctx->raddr = tr.physical_address;
+    return 0;
+}
qemu/target-ppc/cpu.h +2 -0
@@ -110,6 +110,8 @@ enum powerpc_mmu_t {
     POWERPC_MMU_BOOKE_FSL  = 0x00000009,
     /* PowerPC 601 MMU model (specific BATs format)            */
     POWERPC_MMU_601        = 0x0000000A,
+    /* KVM managing the MMU state                              */
+    POWERPC_MMU_KVM        = 0x0000000B,
 #if defined(TARGET_PPC64)
 #define POWERPC_MMU_64       0x00010000
     /* 64 bits PowerPC MMU                                     */
qemu/target-ppc/helper.c +4 -0
@@ -1408,6 +1408,10 @@ int get_physical_address (CPUState *env,
         fprintf(logfile, "%s\n", __func__);
     }
 #endif
+
+    if (env->mmu_model = POWERPC_MMU_KVM)
+        return mmukvm_get_physical_address(env, ctx, eaddr, rw, access_type);
+
     if ((access_type = ACCESS_CODE && msr_ir = 0) ||
         (access_type != ACCESS_CODE && msr_dr = 0)) {
         /* No address translation */
qemu/target-ppc/translate_init.c +5 -0
@@ -9275,6 +9275,11 @@ int cpu_ppc_register_internal (CPUPPCSta
         case POWERPC_MMU_601:
             mmu_model = "PowerPC 601";
             break;
+#ifdef KVM
+        case POWERPC_MMU_KVM:
+            mmu_model = "PowerPC KVM";
+            break;
+#endif
 #if defined (TARGET_PPC64)
         case POWERPC_MMU_64B:
             mmu_model = "PowerPC 64";

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