PPC: Add FSL (e500) MMU emulation v5
cover PPC: Add FSL (e500) MMU emulation v5
In a global effort to get rid of KVM-only targets, this is the next important piece of the puzzle: e500 emulation :).
We had support for running an e500 KVM guest for a while now, but the code could not be tested without a real e500 machine, because it required KVM to work. This patchset adds emulation for the e500 MMU, enabling anyone to use the MPC8544DS emulation.
v1 -> v2:
- fix linux-user build
- optimize tlb invalidate & search
v2 -> v3:
- add qdev patch (enables -drive if=virtio)
- fix mpc initial tlb size comment
- enable cpu reset
v3 -> v4:
- remove tlb_nbs
- rename BOOKE_FSL to BOOKE206
- generalize implementation to be extensible for future MMUs
- check if tsize should be set
- check if iprot should be set
- set RPN on tlb miss
- implement tlb_invalidate_all
- use specific helper to set PIDs
- create generic booke206 tlb flushing function
- drop base_addr
- new patch: MPC7544DS: Use new TLB helper function
v4 -> v5:
- dont check iprot during tlb flush on reset (scott)
- model qdev conversion similar to versatilepb (pbrook)
Alexander Graf (7):
PPC: Make MPC8544DS obey -cpu switch
PPC: Make MPC8544DS emulation work w/o KVM
PPC: Add GS MSR definition
PPC: Add another 64 bits to instruction feature mask
PPC: Implement e500 (FSL) MMU
PPC MPC7544DS: Use new TLB helper function
PPC: Qdev'ify e500 pci
hw/ppce500.h | 22 --- hw/ppce500_mpc8544ds.c | 108 ++++++++++++---- hw/ppce500_pci.c | 122 ++++++++++-------- target-ppc/cpu.h | 307 ++++++++++++++++++++++++++++++++++++++++++- target-ppc/helper.c | 269 ++++++++++++++++++++++++++++++-------- target-ppc/helper.h | 6 + target-ppc/op_helper.c | 296 +++++++++++++++++++++++++++++++++++++++++ target-ppc/translate.c | 118 +++++++++++++++-- target-ppc/translate_init.c | 282 ++++++++++++++++++++++++++++----------- 9 files changed, 1280 insertions(+), 250 deletions(-) delete mode 100644 hw/ppce500.h
PATCH 1/7 PPC: Make MPC8544DS obey -cpu switch
The MPC8544DS board emulation code ignored the user defined -cpu switch. This patch enables it to only provide a sane default, not force an e500v2 CPU inside.
--- hw/ppce500_mpc8544ds.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
hw/ppce500_mpc8544ds.c +5 -1
@@ -178,7 +178,11 @@ static void mpc8544ds_init(ram_addr_t ram_size,qemu_irq *irqs, *mpic, *pci_irqs;/* Setup CPU */ - env =cpu_ppc_init ("e500v2_v30" ); +if (cpu_model ==NULL ) { + cpu_model ="e500v2_v30" ; + } + + env =cpu_ppc_init (cpu_model);if (!env) {fprintf (stderr,"Unable to initialize CPU!\n" );exit (1 );
Signature · 1 line
1.6.0.2
PATCH 2/7 PPC: Make MPC8544DS emulation work w/o KVM
In reply to Alexander GrafThe MPC8544DS board emulation was only used with KVM so far, so some parts of the code didn't provide proper values for non-KVM execution.
This patch makes the machine work without KVM enabled. To actually use this, you also need proper e500v2 MMU emulation.
---
v2 -> v3:
- fix mpc initial tlb size comment
- enable cpu reset
--- hw/ppce500_mpc8544ds.c | 86 +++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 71 insertions(+), 15 deletions(-)
hw/ppce500_mpc8544ds.c +71 -15
@@ -28,6 +28,7 @@#include "kvm_ppc.h" #include "device_tree.h" #include "openpic.h" +#include "ppc.h" #include "ppce500.h" #include "loader.h" #include "elf.h"
@@ -50,6 +51,12 @@#define MPC8544_PCI_IO 0xE1000000#define MPC8544_PCI_IOLEN 0x10000 +static struct boot_info +{ +uint32_t dt_base; +uint32_t entry; +} boot_info; +#ifdef CONFIG_FDT static int mpc8544_copy_soc_cell (void *fdt,const char *node,const char *prop) {
@@ -82,7 +89,7 @@ static int mpc8544_load_device_tree(target_phys_addr_t addr, {int ret =-1 ;#ifdef CONFIG_FDT -uint32_t mem_reg_property[] = {0 , ramsize}; +uint32_t mem_reg_property[] = {0 ,cpu_to_be32 (ramsize)};char *filename;int fdt_size;void *fdt;
@@ -103,15 +110,19 @@ static int mpc8544_load_device_tree(target_phys_addr_t addr,if (ret <0 )fprintf (stderr,"couldn't set /memory/reg\n" ); - ret =qemu_devtree_setprop_cell (fdt,"/chosen" ,"linux,initrd-start" , - initrd_base); -if (ret <0 ) -fprintf (stderr,"couldn't set /chosen/linux,initrd-start\n" ); +if (initrd_size) { + ret =qemu_devtree_setprop_cell (fdt,"/chosen" ,"linux,initrd-start" , + initrd_base); +if (ret <0 ) { +fprintf (stderr,"couldn't set /chosen/linux,initrd-start\n" ); + } - ret =qemu_devtree_setprop_cell (fdt,"/chosen" ,"linux,initrd-end" , - (initrd_base + initrd_size)); -if (ret <0 ) -fprintf (stderr,"couldn't set /chosen/linux,initrd-end\n" ); + ret =qemu_devtree_setprop_cell (fdt,"/chosen" ,"linux,initrd-end" , + (initrd_base + initrd_size)); +if (ret <0 ) { +fprintf (stderr,"couldn't set /chosen/linux,initrd-end\n" ); + } + } ret =qemu_devtree_setprop_string (fdt,"/chosen" ,"bootargs" , kernel_cmdline);
@@ -145,6 +156,13 @@ static int mpc8544_load_device_tree(target_phys_addr_t addr,mpc8544_copy_soc_cell (fdt, buf,"clock-frequency" );mpc8544_copy_soc_cell (fdt, buf,"timebase-frequency" ); + }else { +const uint32_t freq =400000000 ; + +qemu_devtree_setprop_cell (fdt,"/cpus/PowerPC,8544@0" , +"clock-frequency" , freq); +qemu_devtree_setprop_cell (fdt,"/cpus/PowerPC,8544@0" , +"timebase-frequency" , freq); } ret =rom_add_blob_fixed (BINARY_DEVICE_TREE_FILE , fdt, fdt_size, addr);
@@ -156,6 +174,35 @@ out:return ret; } +/* Create -kernel TLB entries for BookE, linearly spanning 256MB. */ +static void mmubooke_create_initial_mapping (CPUState *env, +target_ulong va, +target_phys_addr_t pa) +{ +ppcemb_tlb_t *tlb = &env->tlb[512 ].tlbe; + + tlb->attr =0 ; + tlb->prot =PAGE_VALID | ((PAGE_READ |PAGE_WRITE |PAGE_EXEC ) <<4 ); + tlb->size =256 *1024 *1024 ; + tlb->EPN = va &TARGET_PAGE_MASK ; + tlb->RPN = pa &TARGET_PAGE_MASK ; + tlb->PID =0 ; +} + +static void mpc8544ds_cpu_reset (void *opaque) +{ +CPUState *env = opaque; +struct boot_info *bi = env->load_info; + +cpu_reset (env); + +/* Set initial guest state. */ + env->gpr[1 ] = (16 <<20 ) -8 ; + env->gpr[3 ] = bi->dt_base; + env->nip = bi->entry; +mmubooke_create_initial_mapping (env,0 ,0 ); +} + static void mpc8544ds_init(ram_addr_t ram_size, const char *boot_device, const char *kernel_filename,
@@ -188,6 +235,13 @@ static void mpc8544ds_init(ram_addr_t ram_size,exit (1 ); } +/* XXX register timer? */ +ppc_emb_timers_init (env,400000000 ,PPC_INTERRUPT_DECR ); +ppc_dcr_init (env,NULL ,NULL ); + +/* Register reset handler */ +qemu_register_reset (mpc8544ds_cpu_reset, env); +/* Fixup Memory size on a alignment boundary */ ram_size &= ~(RAM_SIZES_ALIGN -1 );
@@ -265,6 +319,9 @@ static void mpc8544ds_init(ram_addr_t ram_size,/* If we're loading a kernel directly, we must load the device tree too. */ if (kernel_filename) { +#ifndef CONFIG_FDT +cpu_abort (env,"Compiled without FDT support - can't load kernel\n" ); +#endif dt_base = (kernel_size +DTC_LOAD_PAD ) & ~DTC_PAD_MASK ;if (mpc8544_load_device_tree (dt_base, ram_size, initrd_base, initrd_size, kernel_cmdline) <0 ) {
@@ -272,15 +329,14 @@ static void mpc8544ds_init(ram_addr_t ram_size,exit (1 ); } -/* Set initial guest state. */ - env->gpr[1 ] = (16 <<20 ) -8 ; - env->gpr[3 ] = dt_base; - env->nip = entry; -/* XXX we currently depend on KVM to create some initial TLB entries. */ + boot_info.entry = entry; + boot_info.dt_base = dt_base; } + env->load_info = &boot_info; -if (kvm_enabled ()) +if (kvm_enabled ()) {kvmppc_init (); + }return ; }
Signature · 1 line
1.6.0.2
Re: [Qemu-devel] [PATCH 2/7] PPC: Make MPC8544DS emulation work w/o KVM
Quoted 31 lines · Alexander Graf
The MPC8544DS board emulation was only used with KVM so far, so some parts of the code didn't provide proper values for non-KVM execution.
This patch makes the machine work without KVM enabled. To actually use this, you also need proper e500v2 MMU emulation.
Signed-off-by Alexander Graf <[email protected]>---
v2 -> v3:
- fix mpc initial tlb size comment
- enable cpu reset
---
hw/ppce500_mpc8544ds.c | 86 +++++++++++++++++++++++++++++++++++++++--------1 files changed, 71 insertions(+), 15 deletions(-)hw/ppce500_mpc8544ds.c +1
-0@@ -28,6 +28,7 @@ #include "kvm_ppc.h" #include "device_tree.h" #include "openpic.h" +#include "ppc.h" #include "ppce500.h" #include "loader.h" #include "elf.h"
hw/ppce500_mpc8544ds.c line 58
Quoted 8 lines
hw/ppce500_mpc8544ds.c +5
-0@@ -50,6 +51,12 @@ #define MPC8544_PCI_IO 0xE1000000 #define MPC8544_PCI_IOLEN 0x10000 +static struct boot_info +{ + uint32_t dt_base; + uint32_t entry; +} boot_info;
I don't think there is a need to use static state here.
Quoted 141 lines
hw/ppce500_mpc8544ds.c +65
-16+ #ifdef CONFIG_FDT static int mpc8544_copy_soc_cell(void *fdt, const char *node, const char *prop) {@@ -82,7 +89,7 @@ static int mpc8544_load_device_tree(target_phys_addr_t addr, { int ret = -1; #ifdef CONFIG_FDT - uint32_t mem_reg_property[] = {0, ramsize}; + uint32_t mem_reg_property[] = {0, cpu_to_be32(ramsize)}; char *filename; int fdt_size; void *fdt;@@ -103,15 +110,19 @@ static int mpc8544_load_device_tree(target_phys_addr_t addr, if (ret < 0) fprintf(stderr, "couldn't set /memory/reg\n"); - ret = qemu_devtree_setprop_cell(fdt, "/chosen", "linux,initrd-start", - initrd_base); - if (ret < 0) - fprintf(stderr, "couldn't set /chosen/linux,initrd-start\n"); + if (initrd_size) { + ret = qemu_devtree_setprop_cell(fdt, "/chosen", "linux,initrd-start", + initrd_base); + if (ret < 0) { + fprintf(stderr, "couldn't set /chosen/linux,initrd-start\n"); + } - ret = qemu_devtree_setprop_cell(fdt, "/chosen", "linux,initrd-end", - (initrd_base + initrd_size)); - if (ret < 0) - fprintf(stderr, "couldn't set /chosen/linux,initrd-end\n"); + ret = qemu_devtree_setprop_cell(fdt, "/chosen", "linux,initrd-end", + (initrd_base + initrd_size)); + if (ret < 0) { + fprintf(stderr, "couldn't set /chosen/linux,initrd-end\n"); + } + } ret = qemu_devtree_setprop_string(fdt, "/chosen", "bootargs", kernel_cmdline);@@ -145,6 +156,13 @@ static int mpc8544_load_device_tree(target_phys_addr_t addr, mpc8544_copy_soc_cell(fdt, buf, "clock-frequency"); mpc8544_copy_soc_cell(fdt, buf, "timebase-frequency"); + } else { + const uint32_t freq = 400000000; + + qemu_devtree_setprop_cell(fdt, "/cpus/PowerPC,8544@0", + "clock-frequency", freq); + qemu_devtree_setprop_cell(fdt, "/cpus/PowerPC,8544@0", + "timebase-frequency", freq); } ret = rom_add_blob_fixed(BINARY_DEVICE_TREE_FILE, fdt, fdt_size, addr);@@ -156,6 +174,35 @@ out: return ret; } +/* Create -kernel TLB entries for BookE, linearly spanning 256MB. */ +static void mmubooke_create_initial_mapping (CPUState *env, + target_ulong va, + target_phys_addr_t pa) +{ + ppcemb_tlb_t *tlb = &env->tlb[512].tlbe; + + tlb->attr = 0; + tlb->prot = PAGE_VALID | ((PAGE_READ | PAGE_WRITE | PAGE_EXEC) << 4); + tlb->size = 256 * 1024 * 1024; + tlb->EPN = va & TARGET_PAGE_MASK; + tlb->RPN = pa & TARGET_PAGE_MASK; + tlb->PID = 0; +} + +static void mpc8544ds_cpu_reset (void *opaque) +{ + CPUState *env = opaque; + struct boot_info *bi = env->load_info; + + cpu_reset(env); + + /* Set initial guest state. */ + env->gpr[1] = (16<<20) - 8; + env->gpr[3] = bi->dt_base; + env->nip = bi->entry; + mmubooke_create_initial_mapping(env, 0, 0); +} + static void mpc8544ds_init(ram_addr_t ram_size, const char *boot_device, const char *kernel_filename,@@ -188,6 +235,13 @@ static void mpc8544ds_init(ram_addr_t ram_size, exit(1); } + /* XXX register timer? */ + ppc_emb_timers_init(env, 400000000, PPC_INTERRUPT_DECR); + ppc_dcr_init(env, NULL, NULL); + + /* Register reset handler */ + qemu_register_reset(mpc8544ds_cpu_reset, env); + /* Fixup Memory size on a alignment boundary */ ram_size &= ~(RAM_SIZES_ALIGN - 1);@@ -265,6 +319,9 @@ static void mpc8544ds_init(ram_addr_t ram_size, /* If we're loading a kernel directly, we must load the device tree too. */ if (kernel_filename) { +#ifndef CONFIG_FDT + cpu_abort(env, "Compiled without FDT support - can't load kernel\n"); +#endif dt_base = (kernel_size + DTC_LOAD_PAD) & ~DTC_PAD_MASK; if (mpc8544_load_device_tree(dt_base, ram_size, initrd_base, initrd_size, kernel_cmdline) < 0) {@@ -272,15 +329,14 @@ static void mpc8544ds_init(ram_addr_t ram_size, exit(1); } - /* Set initial guest state. */ - env->gpr[1] = (16<<20) - 8; - env->gpr[3] = dt_base; - env->nip = entry; - /* XXX we currently depend on KVM to create some initial TLB entries. */ + boot_info.entry = entry; + boot_info.dt_base = dt_base; } + env->load_info = &boot_info; - if (kvm_enabled()) + if (kvm_enabled()) { kvmppc_init(); + } return; } --1.6.0.2
Re: [Qemu-devel] [PATCH 2/7] PPC: Make MPC8544DS emulation work w/o KVM
Am 08.05.2011 um 12:08 schrieb Blue Swirl <[email protected]>:
Quoted 35 lines · Alexander Graf
Quoted 34 lines
The MPC8544DS board emulation was only used with KVM so far, so some parts of the code didn't provide proper values for non-KVM execution.
This patch makes the machine work without KVM enabled. To actually use this, you also need proper e500v2 MMU emulation.
Signed-off-by Alexander Graf <[email protected]>---
v2 -> v3:
- fix mpc initial tlb size comment
- enable cpu reset--- hw/ppce500_mpc8544ds.c | 86 +++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 71 insertions(+), 15 deletions(-)hw/ppce500_mpc8544ds.c +1
-0@@ -28,6 +28,7 @@#include "kvm_ppc.h" #include "device_tree.h" #include "openpic.h" +#include "ppc.h" #include "ppce500.h" #include "loader.h" #include "elf.h" @@ -50,6 +51,12 @@#define MPC8544_PCI_IO 0xE1000000#define MPC8544_PCI_IOLEN 0x10000
Quoted 7 lines
hw/ppce500_mpc8544ds.c line 58
Quoted 5 lines
hw/ppce500_mpc8544ds.c +5
-0+static struct boot_info +{ +uint32_t dt_base; +uint32_t entry; +} boot_info;I don't think there is a need to use static state here.
I just modeled it the same as Edgar's code :)
Quoted 1 line
Alex
PATCH 3/7 PPC: Add GS MSR definition
In reply to Alexander GrafThe BookE specification defines MSR bit 28 as Guest State. Add it to the list of MSR macros.
--- target-ppc/cpu.h | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
target-ppc/cpu.h +2 -0
@@ -420,6 +420,7 @@ struct ppc_slb_t {#define MSR_CM 31/* Computation mode for BookE hflags */ #define MSR_ICM 30/* Interrupt computation mode for BookE */ #define MSR_THV 29/* hypervisor state for 32 bits PowerPC hflags */ +#define MSR_GS 28/* guest state for BookE */ #define MSR_UCLE 26/* User-mode cache lock enable for BookE */ #define MSR_VR 25/* altivec available x hflags */ #define MSR_SPE 25/* SPE enable for BookE x hflags */
@@ -457,6 +458,7 @@ struct ppc_slb_t {#define msr_cm ((env->msr >> MSR_CM) & 1)#define msr_icm ((env->msr >> MSR_ICM) & 1)#define msr_thv ((env->msr >> MSR_THV) & 1) +#define msr_gs ((env->msr >> MSR_GS) & 1)#define msr_ucle ((env->msr >> MSR_UCLE) & 1)#define msr_vr ((env->msr >> MSR_VR) & 1)#define msr_spe ((env->msr >> MSR_SPE) & 1)
Signature · 1 line
1.6.0.2
PATCH 4/7 PPC: Add another 64 bits to instruction feature mask
In reply to Alexander GrafTo enable quick runtime detection of instruction groups to the currently selected CPU emulation, we have a feature mask of what exactly the respective instruction supports.
This feature mask is 64 bits long and we just successfully exceeded those 64 bits. To add more features, we need to think of something.
The easiest solution that came to my mind was to simply add another 64 bits that we can also match on. Since the comparison is only done on start of the qemu process to generate an internal opcode calling table, we should be fine on any performance penalties here.
--- target-ppc/cpu.h | 1 + target-ppc/translate.c | 25 +++++++-- target-ppc/translate_init.c | 123 +++++++++++++++++++++++++++++++------------ 3 files changed, 110 insertions(+), 39 deletions(-)
target-ppc/cpu.h +1 -0
@@ -722,6 +722,7 @@ struct CPUPPCState {int bfd_mach;uint32_t flags;uint64_t insns_flags; +uint64_t insns_flags2;#if defined(TARGET_PPC64 ) && !defined(CONFIG_USER_ONLY )target_phys_addr_t vpa;
target-ppc/translate.c +19 -6
@@ -201,6 +201,8 @@ struct opc_handler_t {uint32_t inval;/* instruction type */ uint64_t type; +/* extended instruction type */ +uint64_t type2;/* handler */ void (*handler)(DisasContext *ctx);#if defined(DO_PPC_STATISTICS ) || defined(PPC_DUMP_CPU )
@@ -314,10 +316,16 @@ static inline void gen_sync_exception(DisasContext *ctx) }#define GEN_HANDLER (name, opc1, opc2, opc3, inval, type) \ -GEN_OPCODE(name, opc1, opc2, opc3, inval, type) +GEN_OPCODE(name, opc1, opc2, opc3, inval, type, PPC_NONE) + +#define GEN_HANDLER_E (name, opc1, opc2, opc3, inval, type, type2) \ +GEN_OPCODE(name, opc1, opc2, opc3, inval, type, type2)#define GEN_HANDLER2 (name, onam, opc1, opc2, opc3, inval, type) \ -GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type) +GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, PPC_NONE) + +#define GEN_HANDLER2_E (name, onam, opc1, opc2, opc3, inval, type, type2) \ +GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, type2) typedef struct opcode_t { unsigned char opc1, opc2, opc3;
@@ -457,7 +465,7 @@ static inline target_ulong MASK(uint32_t start, uint32_t end)/* PowerPC instructions table */ #if defined(DO_PPC_STATISTICS ) -#define GEN_OPCODE (name, op1, op2, op3, invl, _typ) \ +#define GEN_OPCODE (name, op1, op2, op3, invl, _typ, _typ2) \ { \ .opc1 = op1, \ .opc2 = op2, \
@@ -466,12 +474,13 @@ static inline target_ulong MASK(uint32_t start, uint32_t end) .handler = { \ .inval = invl, \ .type = _typ, \ + .type2 = _typ2, \ .handler = &gen_##name, \ .oname = stringify(name), \ }, \ .oname = stringify(name), \ } -#define GEN_OPCODE2 (name, onam, op1, op2, op3, invl, _typ) \ +#define GEN_OPCODE2 (name, onam, op1, op2, op3, invl, _typ, _typ2) \ { \ .opc1 = op1, \ .opc2 = op2, \
@@ -480,13 +489,14 @@ static inline target_ulong MASK(uint32_t start, uint32_t end) .handler = { \ .inval = invl, \ .type = _typ, \ + .type2 = _typ2, \ .handler = &gen_##name, \ .oname = onam, \ }, \ .oname = onam, \ }#else -#define GEN_OPCODE (name, op1, op2, op3, invl, _typ) \ +#define GEN_OPCODE (name, op1, op2, op3, invl, _typ, _typ2) \ { \ .opc1 = op1, \ .opc2 = op2, \
@@ -495,11 +505,12 @@ static inline target_ulong MASK(uint32_t start, uint32_t end) .handler = { \ .inval = invl, \ .type = _typ, \ + .type2 = _typ2, \ .handler = &gen_##name, \ }, \ .oname = stringify(name), \ } -#define GEN_OPCODE2 (name, onam, op1, op2, op3, invl, _typ) \ +#define GEN_OPCODE2 (name, onam, op1, op2, op3, invl, _typ, _typ2) \ { \ .opc1 = op1, \ .opc2 = op2, \
@@ -508,6 +519,7 @@ static inline target_ulong MASK(uint32_t start, uint32_t end) .handler = { \ .inval = invl, \ .type = _typ, \ + .type2 = _typ2, \ .handler = &gen_##name, \ }, \ .oname = onam, \
@@ -534,6 +546,7 @@ static void gen_invalid(DisasContext *ctx)static opc_handler_t invalid_handler = { .inval =0xFFFFFFFF , .type =PPC_NONE , + .type2 =PPC_NONE , .handler = gen_invalid, };
target-ppc/translate_init.c +90 -33
460 lines not on this page · raw message
Signature · 1 line
1.6.0.2
PATCH 5/7 PPC: Implement e500 (FSL) MMU
In reply to Alexander GrafMost of the code to support e500 style MMUs is already in place, but we're missing on some of the special TLB0-TLB1 handling code and slightly different TLB modification.
This patch adds support for the FSL style MMU.
---
v1 -> v2:
- fix linux-user build
- optimize tlb invalidate & search
v3 -> v4:
- remove tlb_nbs
- rename BOOKE_FSL to BOOKE206
- generalize implementation to be extensible for future MMUs
- check if tsize should be set
- check if iprot should be set
- set RPN on tlb miss
- implement tlb_invalidate_all
- use specific helper to set PIDs
- create generic booke206 tlb flushing function
- make e500 check more explicit
- rename functions to booke206
- rework page size finder
Special thanks go to Scott here for pointing out all the issues :)
v4 -> v5:
- dont check iprot during tlb flush on reset (scott)
--- target-ppc/cpu.h | 304 ++++++++++++++++++++++++++++++++++++++++++- target-ppc/helper.c | 269 ++++++++++++++++++++++++++++++-------- target-ppc/helper.h | 6 + target-ppc/op_helper.c | 296 +++++++++++++++++++++++++++++++++++++++++ target-ppc/translate.c | 93 +++++++++++++- target-ppc/translate_init.c | 163 ++++++++++++++++------- 6 files changed, 1018 insertions(+), 113 deletions(-)
target-ppc/cpu.h +301 -3
@@ -108,8 +108,8 @@ enum powerpc_mmu_t { POWERPC_MMU_MPC8xx =0x00000007 ,/* BookE MMU model */ POWERPC_MMU_BOOKE =0x00000008 , -/* BookE FSL MMU model */ -POWERPC_MMU_BOOKE_FSL =0x00000009 , +/* BookE 2.06 MMU model */ +POWERPC_MMU_BOOKE206 =0x00000009 ,/* PowerPC 601 MMU model (specific BATs format) */ POWERPC_MMU_601 =0x0000000A , #if defined(TARGET_PPC64)
@@ -608,6 +608,224 @@ enum {#define vscr_sat (((env->vscr) >> VSCR_SAT) & 0x1)/*****************************************************************************/ +/* BookE e500 MMU registers */ + +#define MAS0_NV_SHIFT 0 +#define MAS0_NV_MASK (0xfff << MAS0_NV_SHIFT) + +#define MAS0_WQ_SHIFT 12 +#define MAS0_WQ_MASK (3 << MAS0_WQ_SHIFT) +/* Write TLB entry regardless of reservation */ +#define MAS0_WQ_ALWAYS (0 << MAS0_WQ_SHIFT) +/* Write TLB entry only already in use */ +#define MAS0_WQ_COND (1 << MAS0_WQ_SHIFT) +/* Clear TLB entry */ +#define MAS0_WQ_CLR_RSRV (2 << MAS0_WQ_SHIFT) + +#define MAS0_HES_SHIFT 14 +#define MAS0_HES (1 << MAS0_HES_SHIFT) + +#define MAS0_ESEL_SHIFT 16 +#define MAS0_ESEL_MASK (0xfff << MAS0_ESEL_SHIFT) + +#define MAS0_TLBSEL_SHIFT 28 +#define MAS0_TLBSEL_MASK (3 << MAS0_TLBSEL_SHIFT) +#define MAS0_TLBSEL_TLB0 (0 << MAS0_TLBSEL_SHIFT) +#define MAS0_TLBSEL_TLB1 (1 << MAS0_TLBSEL_SHIFT) +#define MAS0_TLBSEL_TLB2 (2 << MAS0_TLBSEL_SHIFT) +#define MAS0_TLBSEL_TLB3 (3 << MAS0_TLBSEL_SHIFT) + +#define MAS0_ATSEL_SHIFT 31 +#define MAS0_ATSEL (1 << MAS0_ATSEL_SHIFT) +#define MAS0_ATSEL_TLB 0 +#define MAS0_ATSEL_LRAT MAS0_ATSEL + +#define MAS1_TSIZE_SHIFT 8 +#define MAS1_TSIZE_MASK (0xf << MAS1_TSIZE_SHIFT) + +#define MAS1_TS_SHIFT 12 +#define MAS1_TS (1 << MAS1_TS_SHIFT) + +#define MAS1_IND_SHIFT 13 +#define MAS1_IND (1 << MAS1_IND_SHIFT) + +#define MAS1_TID_SHIFT 16 +#define MAS1_TID_MASK (0x3fff << MAS1_TID_SHIFT) + +#define MAS1_IPROT_SHIFT 30 +#define MAS1_IPROT (1 << MAS1_IPROT_SHIFT) + +#define MAS1_VALID_SHIFT 31 +#define MAS1_VALID 0x80000000 + +#define MAS2_EPN_SHIFT 12 +#define MAS2_EPN_MASK (0xfffff << MAS2_EPN_SHIFT) + +#define MAS2_ACM_SHIFT 6 +#define MAS2_ACM (1 << MAS2_ACM_SHIFT) + +#define MAS2_VLE_SHIFT 5 +#define MAS2_VLE (1 << MAS2_VLE_SHIFT) + +#define MAS2_W_SHIFT 4 +#define MAS2_W (1 << MAS2_W_SHIFT) + +#define MAS2_I_SHIFT 3 +#define MAS2_I (1 << MAS2_I_SHIFT) + +#define MAS2_M_SHIFT 2 +#define MAS2_M (1 << MAS2_M_SHIFT) + +#define MAS2_G_SHIFT 1 +#define MAS2_G (1 << MAS2_G_SHIFT) + +#define MAS2_E_SHIFT 0 +#define MAS2_E (1 << MAS2_E_SHIFT) + +#define MAS3_RPN_SHIFT 12 +#define MAS3_RPN_MASK (0xfffff << MAS3_RPN_SHIFT) + +#define MAS3_U0 0x00000200 +#define MAS3_U1 0x00000100 +#define MAS3_U2 0x00000080 +#define MAS3_U3 0x00000040 +#define MAS3_UX 0x00000020 +#define MAS3_SX 0x00000010 +#define MAS3_UW 0x00000008 +#define MAS3_SW 0x00000004 +#define MAS3_UR 0x00000002 +#define MAS3_SR 0x00000001 +#define MAS3_SPSIZE_SHIFT 1 +#define MAS3_SPSIZE_MASK (0x3e << MAS3_SPSIZE_SHIFT) + +#define MAS4_TLBSELD_SHIFT MAS0_TLBSEL_SHIFT +#define MAS4_TLBSELD_MASK MAS0_TLBSEL_MASK +#define MAS4_TIDSELD_MASK 0x00030000 +#define MAS4_TIDSELD_PID0 0x00000000 +#define MAS4_TIDSELD_PID1 0x00010000 +#define MAS4_TIDSELD_PID2 0x00020000 +#define MAS4_TIDSELD_PIDZ 0x00030000 +#define MAS4_INDD 0x00008000/* Default IND */ +#define MAS4_TSIZED_SHIFT MAS1_TSIZE_SHIFT +#define MAS4_TSIZED_MASK MAS1_TSIZE_MASK +#define MAS4_ACMD 0x00000040 +#define MAS4_VLED 0x00000020 +#define MAS4_WD 0x00000010 +#define MAS4_ID 0x00000008 +#define MAS4_MD 0x00000004 +#define MAS4_GD 0x00000002 +#define MAS4_ED 0x00000001 +#define MAS4_WIMGED_MASK 0x0000001f/* Default WIMGE */ +#define MAS4_WIMGED_SHIFT 0 + +#define MAS5_SGS 0x80000000 +#define MAS5_SLPID_MASK 0x00000fff + +#define MAS6_SPID0 0x3fff0000 +#define MAS6_SPID1 0x00007ffe +#define MAS6_ISIZE (x) MAS1_TSIZE(x) +#define MAS6_SAS 0x00000001 +#define MAS6_SPID MAS6_SPID0 +#define MAS6_SIND 0x00000002/* Indirect page */ +#define MAS6_SIND_SHIFT 1 +#define MAS6_SPID_MASK 0x3fff0000 +#define MAS6_SPID_SHIFT 16 +#define MAS6_ISIZE_MASK 0x00000f80 +#define MAS6_ISIZE_SHIFT 7 + +#define MAS7_RPN 0xffffffff + +#define MAS8_TGS 0x80000000 +#define MAS8_VF 0x40000000 +#define MAS8_TLBPID 0x00000fff + +/* Bit definitions for MMUCFG */ +#define MMUCFG_MAVN 0x00000003/* MMU Architecture Version Number */ +#define MMUCFG_MAVN_V1 0x00000000/* v1.0 */ +#define MMUCFG_MAVN_V2 0x00000001/* v2.0 */ +#define MMUCFG_NTLBS 0x0000000c/* Number of TLBs */ +#define MMUCFG_PIDSIZE 0x000007c0/* PID Reg Size */ +#define MMUCFG_TWC 0x00008000/* TLB Write Conditional (v2.0) */ +#define MMUCFG_LRAT 0x00010000/* LRAT Supported (v2.0) */ +#define MMUCFG_RASIZE 0x00fe0000/* Real Addr Size */ +#define MMUCFG_LPIDSIZE 0x0f000000/* LPID Reg Size */ + +/* Bit definitions for MMUCSR0 */ +#define MMUCSR0_TLB1FI 0x00000002/* TLB1 Flash invalidate */ +#define MMUCSR0_TLB0FI 0x00000004/* TLB0 Flash invalidate */ +#define MMUCSR0_TLB2FI 0x00000040/* TLB2 Flash invalidate */ +#define MMUCSR0_TLB3FI 0x00000020/* TLB3 Flash invalidate */ +#define MMUCSR0_TLBFI (MMUCSR0_TLB0FI | MMUCSR0_TLB1FI | \ + MMUCSR0_TLB2FI | MMUCSR0_TLB3FI) +#define MMUCSR0_TLB0PS 0x00000780/* TLB0 Page Size */ +#define MMUCSR0_TLB1PS 0x00007800/* TLB1 Page Size */ +#define MMUCSR0_TLB2PS 0x00078000/* TLB2 Page Size */ +#define MMUCSR0_TLB3PS 0x00780000/* TLB3 Page Size */ + +/* TLBnCFG encoding */ +#define TLBnCFG_N_ENTRY 0x00000fff/* number of entries */ +#define TLBnCFG_HES 0x00002000/* HW select supported */ +#define TLBnCFG_AVAIL 0x00004000/* variable page size */ +#define TLBnCFG_IPROT 0x00008000/* IPROT supported */ +#define TLBnCFG_GTWE 0x00010000/* Guest can write */ +#define TLBnCFG_IND 0x00020000/* IND entries supported */ +#define TLBnCFG_PT 0x00040000/* Can load from page table */ +#define TLBnCFG_MINSIZE 0x00f00000/* Minimum Page Size (v1.0) */ +#define TLBnCFG_MINSIZE_SHIFT 20 +#define TLBnCFG_MAXSIZE 0x000f0000/* Maximum Page Size (v1.0) */ +#define TLBnCFG_MAXSIZE_SHIFT 16 +#define TLBnCFG_ASSOC 0xff000000/* Associativity */ +#define TLBnCFG_ASSOC_SHIFT 24 + +/* TLBnPS encoding */ +#define TLBnPS_4K 0x00000004 +#define TLBnPS_8K 0x00000008 +#define TLBnPS_16K 0x00000010 +#define TLBnPS_32K 0x00000020 +#define TLBnPS_64K 0x00000040 +#define TLBnPS_128K 0x00000080 +#define TLBnPS_256K 0x00000100 +#define TLBnPS_512K 0x00000200 +#define TLBnPS_1M 0x00000400 +#define TLBnPS_2M 0x00000800 +#define TLBnPS_4M 0x00001000 +#define TLBnPS_8M 0x00002000 +#define TLBnPS_16M 0x00004000 +#define TLBnPS_32M 0x00008000 +#define TLBnPS_64M 0x00010000 +#define TLBnPS_128M 0x00020000 +#define TLBnPS_256M 0x00040000 +#define TLBnPS_512M 0x00080000 +#define TLBnPS_1G 0x00100000 +#define TLBnPS_2G 0x00200000 +#define TLBnPS_4G 0x00400000 +#define TLBnPS_8G 0x00800000 +#define TLBnPS_16G 0x01000000 +#define TLBnPS_32G 0x02000000 +#define TLBnPS_64G 0x04000000 +#define TLBnPS_128G 0x08000000 +#define TLBnPS_256G 0x10000000 + +/* tlbilx action encoding */ +#define TLBILX_T_ALL 0 +#define TLBILX_T_TID 1 +#define TLBILX_T_FULLMATCH 3 +#define TLBILX_T_CLASS0 4 +#define TLBILX_T_CLASS1 5 +#define TLBILX_T_CLASS2 6 +#define TLBILX_T_CLASS3 7 + +/* BookE 2.06 helper defines */ + +#define BOOKE206_FLUSH_TLB0 (1 << 0) +#define BOOKE206_FLUSH_TLB1 (1 << 1) +#define BOOKE206_FLUSH_TLB2 (1 << 2) +#define BOOKE206_FLUSH_TLB3 (1 << 3) + +/* number of possible TLBs */ +#define BOOKE206_MAX_TLBN 4 + +/*****************************************************************************/ /* The whole PowerPC CPU context */ #define NB_MMU_MODES 3
@@ -678,7 +896,7 @@ struct CPUPPCState {int nb_BATs;target_ulong DBAT [2 ][8 ];target_ulong IBAT [2 ][8 ]; -/* PowerPC TLB registers (for 4xx and 60x software driven TLBs) */ +/* PowerPC TLB registers (for 4xx, e500 and 60x software driven TLBs) */ int nb_tlb;/* Total number of TLB */ int tlb_per_way;/* Speed-up helper: used to avoid divisions at run time */ int nb_ways;/* Number of ways in the TLB set */
@@ -856,6 +1074,10 @@ void store_40x_dbcr0 (CPUPPCState *env, uint32_t val);void store_40x_sler (CPUPPCState *env,uint32_t val);void store_booke_tcr (CPUPPCState *env,target_ulong val);void store_booke_tsr (CPUPPCState *env,target_ulong val); +void booke206_flush_tlb (CPUState *env,int flags,const int check_iprot); +int ppcemb_tlb_check (CPUState *env,ppcemb_tlb_t *tlb, +target_phys_addr_t *raddrp,target_ulong address, +uint32_t pid,int ext,int i);void ppc_tlb_invalidate_all (CPUPPCState *env);void ppc_tlb_invalidate_one (CPUPPCState *env,target_ulong addr);#if defined(TARGET_PPC64 )
@@ -1547,6 +1769,11 @@ enum {PPC_DCRUX =0x4000000000000000ULL ,/* popcntw and popcntd instructions */ PPC_POPCNTWD =0x8000000000000000ULL , + +/* extended type values */ + +/* BookE 2.06 PowerPC specification */ + PPC2_BOOKE206 = 0x0000000000000001ULL, };/*****************************************************************************/
@@ -1699,6 +1926,77 @@ static inline void cpu_set_tls(CPUState *env, target_ulong newtls)#endif } +#if !defined(CONFIG_USER_ONLY ) +static inline int booke206_tlbe_id (CPUState *env,ppcemb_tlb_t *tlbe) +{ +ulong tlbel = (ulong )tlbe; +ulong tlbl = (ulong )env->tlb; + +return (tlbel - tlbl) /sizeof (env->tlb[0 ]); +} + +static inline int booke206_tlb_size (CPUState *env,int tlbn) +{ +uint32_t tlbncfg = env->spr[SPR_BOOKE_TLB0CFG + tlbn]; +int r = tlbncfg & TLBnCFG_N_ENTRY; +return r; +} + +static inline int booke206_tlb_ways (CPUState *env,int tlbn) +{ +uint32_t tlbncfg = env->spr[SPR_BOOKE_TLB0CFG + tlbn]; +int r = tlbncfg >> TLBnCFG_ASSOC_SHIFT; +return r; +} + +static inline int booke206_tlbe_to_tlbn (CPUState *env,ppcemb_tlb_t *tlbe) +{ +int id =booke206_tlbe_id (env, tlbe); +int end =0 ; +int i; + +for (i =0 ; i <BOOKE206_MAX_TLBN ; i++) { + end +=booke206_tlb_size (env, i); +if (id < end) { +return i; + } + } + +cpu_abort (env,"Unknown TLBe: %d\n" , id); +return 0 ; +} + +static inline int booke206_tlbe_to_way (CPUState *env,ppcemb_tlb_t *tlb) +{ +int tlbn =booke206_tlbe_to_tlbn (env, tlb); +int tlbid =booke206_tlbe_id (env, tlb); +return tlbid & (booke206_tlb_ways (env, tlbn) -1 ); +} + +static inline ppcemb_tlb_t *booke206_get_tlbe (CPUState *env,const int tlbn, +target_ulong ea,int way) +{ +int r; +uint32_t ways =booke206_tlb_ways (env, tlbn); +int ways_bits =ffs (ways) -1 ; +int tlb_bits =ffs (booke206_tlb_size (env, tlbn)) -1 ; +int i; + + way &= ways -1 ; + ea >>=MAS2_EPN_SHIFT ; + ea &= (1 << (tlb_bits - ways_bits)) -1 ; + r = (ea << ways_bits) | way; + +/* bump up to tlbn index */ +for (i =0 ; i < tlbn; i++) { + r +=booke206_tlb_size (env, i); + } + +return &env->tlb[r].tlbe; +} + +#endif +extern void (*cpu_ppc_hypercall)(CPUState *);#endif /* !defined (__CPU_PPC_H__) */
target-ppc/helper.c +213 -56
385 lines not on this page · raw message
target-ppc/helper.h +6 -0
@@ -334,6 +334,12 @@ DEF_HELPER_1(4xx_tlbsx, tl, tl) DEF_HELPER_2(440_tlbre, tl, i32, tl) DEF_HELPER_3(440_tlbwe, void, i32, tl, tl) DEF_HELPER_1(440_tlbsx, tl, tl) +DEF_HELPER_0(booke206_tlbre, void) +DEF_HELPER_0(booke206_tlbwe, void) +DEF_HELPER_2(booke206_tlbsx, void, tl, tl) +DEF_HELPER_1(booke206_tlbivax, void, tl) +DEF_HELPER_1(booke206_tlbflush, void, i32) +DEF_HELPER_2(booke_setpid, void, i32, tl) DEF_HELPER_1(6xx_tlbd, void, tl) DEF_HELPER_1(6xx_tlbi, void, tl) DEF_HELPER_1(74xx_tlbd, void, tl)
target-ppc/op_helper.c +296 -0
300 lines not on this page · raw message
target-ppc/translate.c +88 -5
120 lines not on this page · raw message
target-ppc/translate_init.c +114 -49
312 lines not on this page · raw message
Signature · 1 line
1.6.0.2
PATCH 6/7 PPC MPC7544DS: Use new TLB helper function
In reply to Alexander GrafNow that we have some nice helpers that can find us a TLB entry, let's use that on the machine initialization code, so we don't need to know about the internals of the TLB array.
--- hw/ppce500_mpc8544ds.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
hw/ppce500_mpc8544ds.c +1 -1
@@ -179,7 +179,7 @@ static void mmubooke_create_initial_mapping(CPUState *env, target_ulong va, target_phys_addr_t pa) { -ppcemb_tlb_t *tlb = &env->tlb[512 ].tlbe; +ppcemb_tlb_t *tlb =booke206_get_tlbe (env,1 ,0 ,0 ); tlb->attr =0 ; tlb->prot =PAGE_VALID | ((PAGE_READ |PAGE_WRITE |PAGE_EXEC ) <<4 );
Signature · 1 line
1.6.0.2
PATCH 7/7 PPC: Qdev'ify e500 pci
In reply to Alexander GrafThe e500 PCI controller isn't qdev'ified yet. This leads to severe issues when running with -drive.
To be able to use a virtio disk with an e500 VM, let's convert the PCI controller over to qdev.
---
v2 -> v3:
- rebase to current code base
- fix endian issue
- use sysbus helpers
v3 -> v4:
- drop base_addr
v4 -> v5:
- model qdev conversion similar to versatilepb (pbrook)
--- hw/ppce500.h | 22 --------- hw/ppce500_mpc8544ds.c | 16 +++--- hw/ppce500_pci.c | 122 +++++++++++++++++++++++++++--------------------- 3 files changed, 76 insertions(+), 84 deletions(-) delete mode 100644 hw/ppce500.h
hw/ppce500.h deleted +0 -22
@@ -1,22 +0,0 @@ -/* -* QEMU PowerPC E500 emulation shared definitions -* -* Copyright (C) 2009 Freescale Semiconductor, Inc. All rights reserved. -* -* Author: Yu Liu, <[email protected]> -* -* This file is derived from hw/ppc440.h -* the copyright for that material belongs to the original owners. -* -* This is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -*/ - -#if !defined(PPC_E500_H ) -#define PPC_E500_H - -PCIBus *ppce500_pci_init (qemu_irq *pic,target_phys_addr_t registers); - -#endif /* !defined(PPC_E500_H) */
hw/ppce500_mpc8544ds.c +8 -8
@@ -29,9 +29,9 @@#include "device_tree.h" #include "openpic.h" #include "ppc.h" -#include "ppce500.h" #include "loader.h" #include "elf.h" +#include "sysbus.h" #define BINARY_DEVICE_TREE_FILE "mpc8544ds.dtb"#define UIMAGE_LOAD_BASE 0
@@ -222,7 +222,8 @@ static void mpc8544ds_init(ram_addr_t ram_size,target_long initrd_size=0 ;int i=0 ;unsigned int pci_irq_nrs[4 ] = {1 ,2 ,3 ,4 }; -qemu_irq *irqs, *mpic, *pci_irqs; +qemu_irq *irqs, *mpic; +DeviceState *dev;/* Setup CPU */ if (cpu_model ==NULL ) {
@@ -269,12 +270,11 @@ static void mpc8544ds_init(ram_addr_t ram_size, }/* PCI */ - pci_irqs =qemu_malloc (sizeof (qemu_irq) *4 ); - pci_irqs[0 ] = mpic[pci_irq_nrs[0 ]]; - pci_irqs[1 ] = mpic[pci_irq_nrs[1 ]]; - pci_irqs[2 ] = mpic[pci_irq_nrs[2 ]]; - pci_irqs[3 ] = mpic[pci_irq_nrs[3 ]]; - pci_bus =ppce500_pci_init (pci_irqs,MPC8544_PCI_REGS_BASE ); + dev =sysbus_create_varargs ("e500-pcihost" ,MPC8544_PCI_REGS_BASE , + mpic[pci_irq_nrs[0 ]], mpic[pci_irq_nrs[1 ]], + mpic[pci_irq_nrs[2 ]], mpic[pci_irq_nrs[3 ]], +NULL ); + pci_bus = (PCIBus *)qdev_get_child_bus (dev,"pci" );if (!pci_bus)printf ("couldn't create PCI controller!\n" );
hw/ppce500_pci.c +68 -54
160 lines not on this page · raw message
Signature · 1 line
1.6.0.2
Re: [Qemu-devel] [PATCH 7/7] PPC: Qdev'ify e500 pci
hw/ppce500_pci.c static const VMStateDescription vmstate_ppce500_pci = { · line 255
Quoted 7 lines
hw/ppce500_pci.c +0
-1@@ -250,7 +254,6 @@ static const VMStateDescription vmstate_ppce500_pci = { .minimum_version_id = 1, .minimum_version_id_old = 1, .fields = (VMStateField []) { -VMSTATE_PCI_DEVICE_POINTER (pci_dev, PPCE500PCIState),
Doesn't this require incrementing version_id?
Review static const VMStateDescription vmstate_ppce500_pci = { · line 259
Quoted 1 line
(quoted diff) +1
-0+ vmstate_register(&dev->qdev, ppce500_pci_id++, &vmstate_ppce500_pci,
ppce500_pci_id is bogus, and should be removed. You probably shouldn't be calling this at all. Instead use sysbus_register_withprop and qdev.vmsd.
Other than that, this patch looks ok.
Paul
Re: [Qemu-devel] [PATCH 7/7] PPC: Qdev'ify e500 pci
Quoted 9 lines · Paul Brook
hw/ppce500_pci.c static const VMStateDescription vmstate_ppce500_pci = { · line 255
Quoted 7 lines
hw/ppce500_pci.c +0
-1@@ -250,7 +254,6 @@ static const VMStateDescription vmstate_ppce500_pci = { .minimum_version_id = 1, .minimum_version_id_old = 1, .fields = (VMStateField []) { -VMSTATE_PCI_DEVICE_POINTER (pci_dev, PPCE500PCIState),Doesn't this require incrementing
version_id?
It's never worked before and there is no known good state - so I don't think there's any need to increment here whatsoever :). There won't be any old users.
Quoted 8 lines
Review static const VMStateDescription vmstate_ppce500_pci = { · line 259
Quoted 2 lines
(quoted diff) +1
-0+ vmstate_register(&dev->qdev, ppce500_pci_id++, &vmstate_ppce500_pci,
ppce500_pci_idis bogus, and should be removed. You probably shouldn't be calling this at all. Instead usesysbus_register_withpropand qdev.vmsd.Other than that, this patch looks ok.
Alrighty, new patch underway.
Alex