booke timers
RFC PATCH v3 1/1 booke timers
While working on the emulation of the freescale p2010 (e500v2) I realized that there's no implementation of booke's timers features. Currently mpc8544 uses ppc_emb (ppc_emb_timers_init) which is close but not exactly like booke (for example booke uses different SPR).
This is a first attempt for a distinct and clean implementation of booke's timers.
Please feel free to comment.
V2:
- Fix fixed timer, now trigger each time the selected bit switch from 0 to 1.
- Fix e500 criterion.
- Trigger an interrupt when user set DIE/FIE/WIE while DIS/FIS/WIS is already set.
- Minor fixes (mask definition, variable name...).
- Rename ppc_emb to ppc_40x
V3:
- Fix bit selection for e500 fixed timers (fp == 000000 selects msb)
- Improved formula to compute the next event of a fixed timer
--- Makefile.target | 2 +- hw/ppc.c | 133 ++++++++-------------- hw/ppc.h | 25 ++++- hw/ppc4xx_devs.c | 2 +- hw/ppc_booke.c | 262 +++++++++++++++++++++++++++++++++++++++++++ hw/ppce500_mpc8544ds.c | 4 +- hw/virtex_ml507.c | 11 +-- target-ppc/cpu.h | 25 ++++ target-ppc/helper.c | 12 ++- target-ppc/translate_init.c | 43 +++++++- 10 files changed, 416 insertions(+), 103 deletions(-) create mode 100644 hw/ppc_booke.c
Makefile.target +1 -1
@@ -242,7 +242,7 @@ obj-i386-$(CONFIG_KVM) += kvmclock.o obj-i386-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.o # shared objects -obj-ppc-y = ppc.o +obj-ppc-y = ppc.o ppc_booke.o obj-ppc-y += vga.o # PREP target obj-ppc-y += i8259.o mc146818rtc.o
hw/ppc.c +50 -83
279 lines not on this page · raw message
hw/ppc.h +24 -1
@@ -1,3 +1,5 @@ +void ppc_set_irq (CPUState *env,int n_IRQ,int level); +/* PowerPC hardware exceptions management helpers */ typedef void (*clk_setup_cb )(void *opaque,uint32_t freq);typedef struct clk_setup_t clk_setup_t ;
@@ -11,6 +13,24 @@ static inline void clk_setup (clk_setup_t *clk, uint32_t freq) (*clk->cb)(clk->opaque, freq); } +struct ppc_tb_t { +/* Time base management */ +int64_t tb_offset;/* Compensation */ +int64_t atb_offset;/* Compensation */ +uint32_t tb_freq;/* TB frequency */ +/* Decrementer management */ +uint64_t decr_next;/* Tick for next decr interrupt */ +uint32_t decr_freq;/* decrementer frequency */ +struct QEMUTimer *decr_timer; +/* Hypervisor decrementer management */ +uint64_t hdecr_next;/* Tick for next hdecr interrupt */ +struct QEMUTimer *hdecr_timer; +uint64_t purr_load; +uint64_t purr_start; +void *opaque; +}; + +uint64_t cpu_ppc_get_tb (ppc_tb_t *tb_env,uint64_t vmclk,int64_t tb_offset);clk_setup_cb cpu_ppc_tb_init (CPUState *env,uint32_t freq);/* Embedded PowerPC DCR management */ typedef uint32_t (*dcr_read_cb )(void *opaque,int dcrn);
@@ -19,7 +39,7 @@ int ppc_dcr_init (CPUState *env, int (*dcr_read_error)(int dcrn), int (*dcr_write_error)(int dcrn));int ppc_dcr_register (CPUState *env,int dcrn,void *opaque,dcr_read_cb drc_read,dcr_write_cb dcr_write); -clk_setup_cb ppc_emb_timers_init (CPUState *env,uint32_t freq, +clk_setup_cb ppc_40x_timers_init (CPUState *env,uint32_t freq,unsigned int decr_excp);/* Embedded PowerPC reset */
@@ -55,3 +75,6 @@ enum {#define FW_CFG_PPC_KVM_PID (FW_CFG_ARCH_LOCAL + 0x07)#define PPC_SERIAL_MM_BAUDBASE 399193 + +/* ppc_booke.c */ +void ppc_booke_timers_init (CPUState *env,uint32_t freq);
hw/ppc4xx_devs.c +1 -1
@@ -55,7 +55,7 @@ CPUState *ppc4xx_init (const char *cpu_model, cpu_clk->cb =NULL ;/* We don't care about CPU clock frequency changes */ cpu_clk->opaque = env;/* Set time-base frequency to sysclk */ - tb_clk->cb =ppc_emb_timers_init (env, sysclk,PPC_INTERRUPT_PIT ); + tb_clk->cb =ppc_40x_timers_init (env, sysclk,PPC_INTERRUPT_PIT ); tb_clk->opaque = env;ppc_dcr_init (env,NULL ,NULL );/* Register qemu callbacks */
hw/ppc_booke.c new file +262 -0
262 lines not on this page · raw message
hw/ppce500_mpc8544ds.c +1 -3
@@ -252,9 +252,7 @@ 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 ); +ppc_booke_timers_init (env,400000000 );/* Register reset handler */ qemu_register_reset (mpc8544ds_cpu_reset, env);
hw/virtex_ml507.c +2 -9
@@ -81,7 +81,6 @@ static void mmubooke_create_initial_mapping(CPUState *env,static CPUState *ppc440_init_xilinx (ram_addr_t *ram_size,int do_init,const char *cpu_model, -clk_setup_t *cpu_clk,clk_setup_t *tb_clk,uint32_t sysclk) {CPUState *env;
@@ -93,11 +92,7 @@ static CPUState *ppc440_init_xilinx(ram_addr_t *ram_size,exit (1 ); } - cpu_clk->cb =NULL ;/* We don't care about CPU clock frequency changes */ - cpu_clk->opaque = env; -/* Set time-base frequency to sysclk */ - tb_clk->cb =ppc_emb_timers_init (env, sysclk,PPC_INTERRUPT_DECR ); - tb_clk->opaque = env; +ppc_booke_timers_init (env, sysclk);ppc_dcr_init (env,NULL ,NULL );
@@ -198,7 +193,6 @@ static void virtex_init(ram_addr_t ram_size,ram_addr_t phys_ram;ram_addr_t phys_flash;qemu_irq irq[32 ], *cpu_irq; -clk_setup_t clk_setup[7 ];int kernel_size;int i;
@@ -208,8 +202,7 @@ static void virtex_init(ram_addr_t ram_size, }memset (clk_setup,0 ,sizeof (clk_setup)); - env =ppc440_init_xilinx (&ram_size,1 , cpu_model, &clk_setup[0 ], - &clk_setup[1 ],400000000 ); + env =ppc440_init_xilinx (&ram_size,1 , cpu_model,400000000 );qemu_register_reset (main_cpu_reset, env); phys_ram =qemu_ram_alloc (NULL ,"ram" , ram_size);
target-ppc/cpu.h +25 -0
@@ -997,8 +997,31 @@ struct CPUPPCState {#if !defined(CONFIG_USER_ONLY )void *load_info;/* Holds boot loading state. */ #endif + +/* booke timers */ + +/* Specifies bit locations of the Time Base used to signal a fixed timer +* exception on a transition from 0 to 1. (watchdog or fixed-interval timer) +* +* 0 selects the least significant bit. +* 63 selects the most significant bit. +*/ +uint8_t fit_period[4 ]; +uint8_t wdt_period[4 ]; }; +#define SET_FIT_PERIOD (a_, b_, c_, d_) \ +env->fit_period[0] = (a_); \ + env->fit_period[1] = (b_); \ + env->fit_period[2] = (c_); \ + env->fit_period[3] = (d_); \ + +#define SET_WDT_PERIOD (a_, b_, c_, d_) \ +env->wdt_period[0] = (a_); \ + env->wdt_period[1] = (b_); \ + env->wdt_period[2] = (c_); \ + env->wdt_period[3] = (d_); \ +#if !defined(CONFIG_USER_ONLY )/* Context used internally during MMU translations */ typedef struct mmu_ctx_t mmu_ctx_t ;
@@ -1793,6 +1816,8 @@ enum {/* BookE 2.06 PowerPC specification */ PPC2_BOOKE206 =0x0000000000000001ULL , +/* e500 support */ + PPC2_E500 = 0x0000000000000002ULL, };/*****************************************************************************/
target-ppc/helper.c +9 -3
@@ -2968,7 +2968,9 @@ void ppc_hw_interrupt (CPUPPCState *env)if (msr_ee !=0 ) {/* Watchdog timer on embedded PowerPC */ if (env->pending_interrupts & (1 <<PPC_INTERRUPT_WDT )) { - env->pending_interrupts &= ~(1 <<PPC_INTERRUPT_WDT ); +if (env->excp_model !=POWERPC_EXCP_BOOKE ) { + env->pending_interrupts &= ~(1 <<PPC_INTERRUPT_WDT ); + }powerpc_excp (env, env->excp_model,POWERPC_EXCP_WDT );return ; }
@@ -2979,7 +2981,9 @@ void ppc_hw_interrupt (CPUPPCState *env) }/* Fixed interval timer on embedded PowerPC */ if (env->pending_interrupts & (1 <<PPC_INTERRUPT_FIT )) { - env->pending_interrupts &= ~(1 <<PPC_INTERRUPT_FIT ); +if (env->excp_model !=POWERPC_EXCP_BOOKE ) { + env->pending_interrupts &= ~(1 <<PPC_INTERRUPT_FIT ); + }powerpc_excp (env, env->excp_model,POWERPC_EXCP_FIT );return ; }
@@ -2991,7 +2995,9 @@ void ppc_hw_interrupt (CPUPPCState *env) }/* Decrementer exception */ if (env->pending_interrupts & (1 <<PPC_INTERRUPT_DECR )) { - env->pending_interrupts &= ~(1 <<PPC_INTERRUPT_DECR ); +if (env->excp_model !=POWERPC_EXCP_BOOKE ) { + env->pending_interrupts &= ~(1 <<PPC_INTERRUPT_DECR ); + }powerpc_excp (env, env->excp_model,POWERPC_EXCP_DECR );return ; }
target-ppc/translate_init.c +41 -2
133 lines not on this page · raw message
Signature · 1 line
1.7.4.1