booke timers
RFC PATCH 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.
--- Makefile.target | 2 +- hw/ppc.c | 45 +-------- hw/ppc.h | 23 +++++ hw/ppc_booke.c | 254 ++++++++++++++++++++++++++++++++++++++++++++++++ hw/ppce500_mpc8544ds.c | 4 +- 5 files changed, 281 insertions(+), 47 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 +2 -43
64 lines not on this page · raw message
hw/ppc.h +23 -0
@@ -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);
@@ -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/ppc_booke.c new file +254 -0
254 lines not on this page · raw message
hw/ppce500_mpc8544ds.c +1 -3
@@ -237,9 +237,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);
Signature · 1 line
1.7.4.1
Quoted 4 lines · On Mon, 27 Jun 2011 18:14:06 +0200 Fabien Chouteau <[email protected]> wrote:
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).
ppc_emb_timers_init should be renamed something less generic, then.
hw/ppc_booke.c line 38
Quoted 6 lines
hw/ppc_booke.c new file +6
-0+/* Timer Control Register */ + +#define TCR_WP_MASK 0x3/* Watchdog Timer Period */ +#define TCR_WP_SHIFT 30 +#define TCR_WRC_MASK 0x3/* Watchdog Timer Reset Control */ +#define TCR_WRC_SHIFT 28
Usually such MASK defines are before shifting right:
#define TCR_WP_MASK 0xc0000000 #define TCR_WP_SHIFT 30 #define TCR_WRC_MASK 0x30000000
#define TCR_WRC_SHIFT 28
That way you can do things like
if (tcr & TCR_WRC_MASK) {
...
}hw/ppc_booke.c line 85
Quoted 11 lines
hw/ppc_booke.c new file +11
-0+/* Return the time base value at which the FIT will raise an interrupt */ +static uint64_t booke_get_fit_target (CPUState *env) +{ +uint32_t fp = (env->spr[SPR_BOOKE_TCR ] >>TCR_FP_SHIFT ) &TCR_FP_MASK ; + +/* Only for e500 */ +if (env->insns_flags2 &PPC2_BOOKE206 ) { +uint32_t fpext = (env->spr[SPR_BOOKE_TCR ] >>TCR_E500_FPEXT_SHIFT ) + &TCR_E500_FPEXT_MASK ; + fp |= fpext <<2 ; + }
BOOKE206 does not mean e500. FPEXT does not exist in Power ISA V2.06 Book III-E.
hw/ppc_booke.c line 88
Quoted 3 lines
hw/ppc_booke.c new file +3
-0+ +return 1 << fp; +}
The particular bits selected by the possible values of FP are implementation-dependent. e500 uses fpext to make all values possible, but on 440 the four values of fp select from 2^13, 2^17, 2^21, and 2^25.
Quoted 4 lines
hw/ppc_booke.c new file +4
-0+/* Return the time base value at which the WDT will raise an interrupt */ +static uint64_t booke_get_wdt_target (CPUState *env) +{ +uint32_t fp = (env->spr[SPR_BOOKE_TCR ] >>TCR_WP_SHIFT ) &TCR_WP_MASK ;
hw/ppc_booke.c line 103
Quoted 10 lines
hw/ppc_booke.c new file +10
-0+ +/* Only for e500 */ +if (env->insns_flags2 &PPC2_BOOKE206 ) { +uint32_t fpext = (env->spr[SPR_BOOKE_TCR ] >>TCR_E500_WPEXT_SHIFT ) + &TCR_E500_WPEXT_MASK ; + fp |= fpext <<2 ; + } + +return 1 << fp; +}
s/fp/wp/
Avoiding the confusion is especially important on 440, since a different interval is selected by a given value in FP versus WP.
Quoted 5 lines
hw/ppc_booke.c new file +5
-0+static void booke_update_fixed_timer (CPUState *env, +uint64_t tb_target, +uint64_t *next, +struct QEMUTimer *timer) +{
hw/ppc_booke.c line 119
Quoted 10 lines
hw/ppc_booke.c new file +10
-0+ppc_tb_t *tb_env = env->tb_env; +uint64_t lapse; +uint64_t tb; +uint64_t now; + + now =qemu_get_clock_ns (vm_clock); + tb =cpu_ppc_get_tb (tb_env, now, tb_env->tb_offset); + +if (tb_target < tb) { +qemu_del_timer (timer);
You're treating the target as the timebase value that has only the selected bit and nothing else -- you want to expire the next time that bit transitions from zero to one, regardless of the other bits.
The timer should never be outright disabled.
Quoted 9 lines
hw/ppc_booke.c new file +9
-0+static void booke_decr_cb (void *opaque) +{ +CPUState *env; +ppc_tb_t *tb_env; +booke_timer_t *booke_timer; + + env = opaque; + tb_env = env->tb_env; + booke_timer = tb_env->opaque;
hw/ppc_booke.c line 149
Quoted 10 lines
hw/ppc_booke.c new file +10
-0+ env->spr[SPR_BOOKE_TSR ] |=TSR_DIS ; +if (env->spr[SPR_BOOKE_TCR ] &TCR_DIE ) { +ppc_set_irq (env, booke_timer->decr_excp,1 ); + } + +if (env->spr[SPR_BOOKE_TCR ] &TCR_ARE ) { +/* Auto Reload */ +cpu_ppc_store_decr (env, env->spr[SPR_BOOKE_DECAR ]); + } +}
I think some changes in the decrementer code are needed to provide booke semantics -- no raising the interrupt based on the high bit of decr, and stop counting when reach zero.
Quoted 8 lines
hw/ppc_booke.c new file +8
-0+static void booke_wdt_cb (void *opaque) +{ +CPUState *env; +ppc_tb_t *tb_env; +booke_timer_t *booke_timer; + + env = opaque; + tb_env = env->tb_env;
hw/ppc_booke.c line 188
Quoted 10 lines
hw/ppc_booke.c new file +10
-0+ booke_timer = tb_env->opaque; + +/* TODO: There's lots of complicated stuff to do here */ +abort (); + +booke_update_fixed_timer (env, +booke_get_wdt_target (env), + &booke_timer->wdt_next, + booke_timer->wdt_timer); +}
Might want to avoid arming this one until that abort() is fixed...
hw/ppc_booke.c line 197
Quoted 9 lines
hw/ppc_booke.c new file +9
-0+ +void store_booke_tsr (CPUState *env,target_ulong val) +{ +ppc_tb_t *tb_env = env->tb_env; +booke_timer_t *booke_timer; + + booke_timer = tb_env->opaque; + + env->spr[SPR_BOOKE_TSR ] &= ~(val &0xFC000000 );
Do we really need the "& 0xFC000000"? Likewise in TCR.
hw/ppc_booke.c line 210
Quoted 13 lines
hw/ppc_booke.c new file +13
-0+ +if (val &TSR_DIS ) { +ppc_set_irq (env, booke_timer->decr_excp,0 ); + } + +if (val &TSR_FIS ) { +ppc_set_irq (env, booke_timer->fit_excp,0 ); + } + +if (val &TSR_WIS ) { +ppc_set_irq (env, booke_timer->wdt_excp,0 ); + } +}
It looks like ppc_hw_interrupt() is currently treating these as edge-triggered, deasserting upon delivery. It should be level for booke.
Quoted 8 lines
hw/ppc_booke.c new file +8
-0+void store_booke_tcr (CPUState *env,target_ulong val) +{ +ppc_tb_t *tb_env = env->tb_env; +booke_timer_t *booke_timer = tb_env->opaque; + + tb_env = env->tb_env; + env->spr[SPR_BOOKE_TCR ] = val &0xFFC00000 ; +
hw/ppc_booke.c line 229
Quoted 10 lines
hw/ppc_booke.c new file +10
-0+booke_update_fixed_timer (env, +booke_get_fit_target (env), + &booke_timer->fit_next, + booke_timer->fit_timer); + +booke_update_fixed_timer (env, +booke_get_wdt_target (env), + &booke_timer->wdt_next, + booke_timer->wdt_timer); +}
Check for FIS/DIS/WIS -- the corresponding enable bit might have just been set.
hw/ppc_booke.c line 248
Quoted 3 lines
hw/ppc_booke.c new file +3
-0+ booke_timer->decr_excp =PPC_INTERRUPT_DECR ; + booke_timer->fit_excp =PPC_INTERRUPT_FIT ; + booke_timer->wdt_excp =PPC_INTERRUPT_WDT ;
What do we gain by using this instead of PPC_INTERRUPT_foo directly?
-SCott
Subject: Re: [Qemu-devel] [PATCH] [PowerPC][RFC] booke timers To: Scott Wood <[email protected]>
Cc: [email protected]
Bcc:
-=-=-=-=-=-=-=-=-=# Don't remove this line #=-=-=-=-=-=-=-=-=-w
Quoted 9 lines · Scott Wood
Quoted 4 lines · On Mon, 27 Jun 2011 18:14:06 +0200 Fabien Chouteau <[email protected]> wrote:
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).
ppc_emb_timers_initshould be renamed something less generic, then.
Agreed, can you help me to find a better name?
Quoted 13 lines
hw/ppc_booke.c line 38
Quoted 7 lines
hw/ppc_booke.c new file +6
-0+/* Timer Control Register */ + +#define TCR_WP_MASK 0x3/* Watchdog Timer Period */ +#define TCR_WP_SHIFT 30 +#define TCR_WRC_MASK 0x3/* Watchdog Timer Reset Control */ +#define TCR_WRC_SHIFT 28Usually such MASK defines are before shifting right:
#define TCR_WP_MASK 0xc0000000 #define TCR_WP_SHIFT 30 #define TCR_WRC_MASK 0x30000000
Quoted 7 lines
#define
TCR_WRC_SHIFT28That way you can do things like
if (tcr & TCR_WRC_MASK) { ... }
OK, I will use this kind of declaration:
#define TCR_WP_SHIFT 30 /* Watchdog Timer Period */
#define TCR_WP_MASK (0x3 << TCR_WP_SHIFT)
Quoted 15 lines
hw/ppc_booke.c line 85
Quoted 12 lines
hw/ppc_booke.c new file +11
-0+/* Return the time base value at which the FIT will raise an interrupt */ +static uint64_t booke_get_fit_target (CPUState *env) +{ +uint32_t fp = (env->spr[SPR_BOOKE_TCR ] >>TCR_FP_SHIFT ) &TCR_FP_MASK ; + +/* Only for e500 */ +if (env->insns_flags2 &PPC2_BOOKE206 ) { +uint32_t fpext = (env->spr[SPR_BOOKE_TCR ] >>TCR_E500_FPEXT_SHIFT ) + &TCR_E500_FPEXT_MASK ; + fp |= fpext <<2 ; + }BOOKE206 does not mean e500. FPEXT does not exist in Power ISA V2.06 Book III-E.
I will try to fix this for v2.
Quoted 9 lines
hw/ppc_booke.c line 88
Quoted 4 lines
hw/ppc_booke.c new file +3
-0+ +return 1 << fp; +}The particular bits selected by the possible values of FP are implementation-dependent. e500 uses fpext to make all values possible, but on 440 the four values of fp select from 2^13, 2^17, 2^21, and 2^25.
Maybe I can do something like:
static uint64_t booke_get_fit_target(CPUState *env)
{
uint32_t fp = (env->spr[SPR_BOOKE_TCR] & TCR_FP_MASK) >> TCR_FP_SHIFT;
/* Only for e500 */
if (/* CPU is e500 */) {
uint32_t fpext = (env->spr[SPR_BOOKE_TCR] & TCR_E500_FPEXT_MASK)
>> TCR_E500_FPEXT_SHIFT;
fp |= fpext << 2;
} else {
fp = env->fit_period[fp];
}
return 1 << fp;
}Quoted 17 lines
Quoted 4 lines
hw/ppc_booke.c new file +4
-0+/* Return the time base value at which the WDT will raise an interrupt */ +static uint64_t booke_get_wdt_target (CPUState *env) +{ +uint32_t fp = (env->spr[SPR_BOOKE_TCR ] >>TCR_WP_SHIFT ) &TCR_WP_MASK ;hw/ppc_booke.c line 103
Quoted 10 lines
hw/ppc_booke.c new file +10
-0+ +/* Only for e500 */ +if (env->insns_flags2 &PPC2_BOOKE206 ) { +uint32_t fpext = (env->spr[SPR_BOOKE_TCR ] >>TCR_E500_WPEXT_SHIFT ) + &TCR_E500_WPEXT_MASK ; + fp |= fpext <<2 ; + } + +return 1 << fp; +}s/fp/wp/
Quoted 2 lines
Avoiding the confusion is especially important on 440, since a different interval is selected by a given value in FP versus WP.
Fixed.
Quoted 21 lines
Quoted 6 lines
hw/ppc_booke.c new file +5
-0+static void booke_update_fixed_timer (CPUState *env, +uint64_t tb_target, +uint64_t *next, +struct QEMUTimer *timer) +{hw/ppc_booke.c line 119
Quoted 10 lines
hw/ppc_booke.c new file +10
-0+ppc_tb_t *tb_env = env->tb_env; +uint64_t lapse; +uint64_t tb; +uint64_t now; + + now =qemu_get_clock_ns (vm_clock); + tb =cpu_ppc_get_tb (tb_env, now, tb_env->tb_offset); + +if (tb_target < tb) { +qemu_del_timer (timer);You're treating the target as the timebase value that has only the selected bit and nothing else -- you want to expire the next time that bit transitions from zero to one, regardless of the other bits.
Quoted 1 line
The timer should never be outright disabled.
That's right, I will fix this for v2.
Quoted 16 lines
Quoted 16 lines
hw/ppc_booke.c new file +15
-0+static void booke_decr_cb (void *opaque) +{ +CPUState *env; +ppc_tb_t *tb_env; +booke_timer_t *booke_timer; + + env = opaque; + tb_env = env->tb_env; + booke_timer = tb_env->opaque; + env->spr[SPR_BOOKE_TSR ] |=TSR_DIS ; +if (env->spr[SPR_BOOKE_TCR ] &TCR_DIE ) { +ppc_set_irq (env, booke_timer->decr_excp,1 ); + } + +if (env->spr[SPR_BOOKE_TCR ] &TCR_ARE ) {
Quoted 8 lines
hw/ppc_booke.c line 149
Quoted 4 lines
hw/ppc_booke.c new file +4
-0+/* Auto Reload */ +cpu_ppc_store_decr (env, env->spr[SPR_BOOKE_DECAR ]); + } +}I think some changes in the decrementer code are needed to provide booke semantics -- no raising the interrupt based on the high bit of decr, and stop counting when reach zero.
Can you please explain, I don't see where I'm not compliant with booke's decrementer.
Quoted 22 lines
Quoted 9 lines
hw/ppc_booke.c new file +8
-0+static void booke_wdt_cb (void *opaque) +{ +CPUState *env; +ppc_tb_t *tb_env; +booke_timer_t *booke_timer; + + env = opaque; + tb_env = env->tb_env;hw/ppc_booke.c line 188
Quoted 10 lines
hw/ppc_booke.c new file +10
-0+ booke_timer = tb_env->opaque; + +/* TODO: There's lots of complicated stuff to do here */ +abort (); + +booke_update_fixed_timer (env, +booke_get_wdt_target (env), + &booke_timer->wdt_next, + booke_timer->wdt_timer); +}Might want to avoid arming this one until that
abort()is fixed...
Quoted 11 lines
hw/ppc_booke.c line 197
Quoted 9 lines
hw/ppc_booke.c new file +9
-0+ +void store_booke_tsr (CPUState *env,target_ulong val) +{ +ppc_tb_t *tb_env = env->tb_env; +booke_timer_t *booke_timer; + + booke_timer = tb_env->opaque; + + env->spr[SPR_BOOKE_TSR ] &= ~(val &0xFC000000 );Do we really need the "&
0xFC000000"? Likewise in TCR.
It's just a mask to keep only the defined bits.
Quoted 17 lines
Quoted 4 lines
hw/ppc_booke.c new file +3
-0+ +if (val &TSR_DIS ) { +ppc_set_irq (env, booke_timer->decr_excp,0 );hw/ppc_booke.c line 210
Quoted 10 lines
hw/ppc_booke.c new file +10
-0+ } + +if (val &TSR_FIS ) { +ppc_set_irq (env, booke_timer->fit_excp,0 ); + } + +if (val &TSR_WIS ) { +ppc_set_irq (env, booke_timer->wdt_excp,0 ); + } +}It looks like
ppc_hw_interrupt()is currently treating these as edge-triggered, deasserting upon delivery. It should be level for booke.
This is beyond the scope of this patch.
Quoted 14 lines
Quoted 14 lines
hw/ppc_booke.c new file +13
-0+void store_booke_tcr (CPUState *env,target_ulong val) +{ +ppc_tb_t *tb_env = env->tb_env; +booke_timer_t *booke_timer = tb_env->opaque; + + tb_env = env->tb_env; + env->spr[SPR_BOOKE_TCR ] = val &0xFFC00000 ; + +booke_update_fixed_timer (env, +booke_get_fit_target (env), + &booke_timer->fit_next, + booke_timer->fit_timer); +
Quoted 8 lines
hw/ppc_booke.c line 188
Quoted 5 lines
hw/ppc_booke.c new file +5
-0+booke_update_fixed_timer (env, +booke_get_wdt_target (env), + &booke_timer->wdt_next, + booke_timer->wdt_timer); +}Check for FIS/DIS/WIS -- the corresponding enable bit might have just been set.
Can you explain, I don't see the problem.
Quoted 6 lines
hw/ppc_booke.c line 248
Quoted 4 lines
hw/ppc_booke.c new file +3
-0+ booke_timer->decr_excp =PPC_INTERRUPT_DECR ; + booke_timer->fit_excp =PPC_INTERRUPT_FIT ; + booke_timer->wdt_excp =PPC_INTERRUPT_WDT ;What do we gain by using this instead of
PPC_INTERRUPT_foodirectly?
Nothing...
Thanks for your review.
Signature · 1 line
Fabien Chouteau
Quoted 9 lines · On Tue, 28 Jun 2011 15:35:00 +0200 Fabien Chouteau <[email protected]> wrote:
Subject: Re: [Qemu-devel] [PATCH] [PowerPC][RFC] booke timers To: Scott Wood <[email protected]>Cc: [email protected]
Bcc:
-=-=-=-=-=-=-=-=-=# Don't remove this line #=-=-=-=-=-=-=-=-=-wQuoted 3 lines · Scott Wood
On Mon, 27 Jun 2011 18:14:06 +0200
Fabien Chouteau <[email protected]> wrote:
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
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).
ppc_emb_timers_initshould be renamed something less generic, then.Agreed, can you help me to find a better name?
What chips are covered by it? 40x?
Quoted 17 lines
Maybe I can do something like:
static
uint64_tbooke_get_fit_target(CPUState *env){ uint32_t fp = (env->spr[SPR_BOOKE_TCR] & TCR_FP_MASK) >> TCR_FP_SHIFT; /* Only for e500 */ if (/* CPU is e500 */) { uint32_t fpext = (env->spr[SPR_BOOKE_TCR] & TCR_E500_FPEXT_MASK) >> TCR_E500_FPEXT_SHIFT; fp |= fpext << 2; } else { fp = env->fit_period[fp]; } return 1 << fp; }
Looks good -- or just have a CPU-specific function pointer that extracts the period from TCR.
Quoted 6 lines
Quoted 3 lines
I think some changes in the decrementer code are needed to provide booke semantics -- no raising the interrupt based on the high bit of decr, and stop counting when reach zero.
Can you please explain, I don't see where I'm not compliant with booke's decrementer.
It's not an issue with this code specifically, but existing behavior in the decrementer code that isn't appropriate for booke.
On classic/server powerpc, when decrementer hits zero, it wraps around, and the upper bit of DECR is used to signal the interrupt. On booke, when decrementer hits zero, it stops, and the upper bit of DECR is not special.
Quoted 11 lines
Quoted 10 lines
hw/ppc_booke.c line 197
Quoted 8 lines
hw/ppc_booke.c new file +8
-0+void store_booke_tsr (CPUState *env,target_ulong val) +{ +ppc_tb_t *tb_env = env->tb_env; +booke_timer_t *booke_timer; + + booke_timer = tb_env->opaque; + + env->spr[SPR_BOOKE_TSR ] &= ~(val &0xFC000000 );Do we really need the "&
0xFC000000"? Likewise in TCR.
Quoted 1 line
It's just a mask to keep only the defined bits.
Just seems unnecessary, and potentially harmful if CPU-specific code wants to interpret implementation-defined bits, or if new bits are architected in the future.
Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
hw/ppc_booke.c new file +7
-0+if (val &TSR_DIS ) { +ppc_set_irq (env, booke_timer->decr_excp,0 ); + } + +if (val &TSR_FIS ) { +ppc_set_irq (env, booke_timer->fit_excp,0 ); + }Quoted 8 lines
hw/ppc_booke.c line 210
Quoted 5 lines
hw/ppc_booke.c new file +5
-0+ +if (val &TSR_WIS ) { +ppc_set_irq (env, booke_timer->wdt_excp,0 ); + } +}It looks like
ppc_hw_interrupt()is currently treating these as edge-triggered, deasserting upon delivery. It should be level for booke.
Quoted 1 line
This is beyond the scope of this patch.
It's part of correctly implementing booke timers.
Quoted 22 lines
Quoted 13 lines
Quoted 13 lines
hw/ppc_booke.c new file +13
-0+void store_booke_tcr (CPUState *env,target_ulong val) +{ +ppc_tb_t *tb_env = env->tb_env; +booke_timer_t *booke_timer = tb_env->opaque; + + tb_env = env->tb_env; + env->spr[SPR_BOOKE_TCR ] = val &0xFFC00000 ; + +booke_update_fixed_timer (env, +booke_get_fit_target (env), + &booke_timer->fit_next, + booke_timer->fit_timer); +Quoted 8 lines
hw/ppc_booke.c line 188
Quoted 5 lines
hw/ppc_booke.c new file +5
-0+booke_update_fixed_timer (env, +booke_get_wdt_target (env), + &booke_timer->wdt_next, + booke_timer->wdt_timer); +}Check for FIS/DIS/WIS -- the corresponding enable bit might have just been set.
Quoted 1 line
Can you explain, I don't see the problem.
If a decrementer fires with TCR[DIE] unset, it won't be delivered, but TSR[DIS] will be set.
If a guest subsequenly sets TCR[DIE], without having first cleared TSR[DIS], the interrupt should fire immediately -- but that will only happen if you check for it here.
-Scott
Quoted 12 lines · Scott Wood
Quoted 9 lines · On Tue, 28 Jun 2011 15:35:00 +0200 Fabien Chouteau <[email protected]> wrote:
Quoted 8 lines · Scott Wood
Quoted 4 lines · On Mon, 27 Jun 2011 18:14:06 +0200 Fabien Chouteau <[email protected]> wrote:
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).
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
ppc_emb_timers_initshould be renamed something less generic, then.Agreed, can you help me to find a better name?
What chips are covered by it? 40x?
The function is used by ppc4xx_init (ppc4xx_devs.c) and ppc440_init_xilinx (virtex_ml507.c), so I guess ppc_4xx_timers_int will be fine...
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
I think some changes in the decrementer code are needed to provide booke semantics -- no raising the interrupt based on the high bit of decr, and stop counting when reach zero.
Can you please explain, I don't see where I'm not compliant with booke's decrementer.
Quoted 7 lines
It's not an issue with this code specifically, but existing behavior in the decrementer code that isn't appropriate for booke.
On classic/server powerpc, when decrementer hits zero, it wraps around, and the upper bit of DECR is used to signal the interrupt. On booke, when decrementer hits zero, it stops, and the upper bit of DECR is not special.
And that's why I implemented the booke_decr_cb function that will emulate this behavior.
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
hw/ppc_booke.c line 197
Quoted 8 lines
hw/ppc_booke.c new file +8
-0+void store_booke_tsr (CPUState *env,target_ulong val) +{ +ppc_tb_t *tb_env = env->tb_env; +booke_timer_t *booke_timer; + + booke_timer = tb_env->opaque; + + env->spr[SPR_BOOKE_TSR ] &= ~(val &0xFC000000 );Do we really need the "&
0xFC000000"? Likewise in TCR.
Quoted 6 lines
Quoted 1 line
It's just a mask to keep only the defined bits.
Just seems unnecessary, and potentially harmful if CPU-specific code wants to interpret implementation-defined bits, or if new bits are architected in the future.
On the other hand, undefined bit should always be read as zeros.
Quoted 22 lines
Quoted 22 lines
Quoted 21 lines
Quoted 8 lines
hw/ppc_booke.c new file +8
-0+void store_booke_tcr (CPUState *env,target_ulong val) +{ +ppc_tb_t *tb_env = env->tb_env; +booke_timer_t *booke_timer = tb_env->opaque; + + tb_env = env->tb_env; + env->spr[SPR_BOOKE_TCR ] = val &0xFFC00000 ; +hw/ppc_booke.c line 229
Quoted 10 lines
hw/ppc_booke.c new file +10
-0+booke_update_fixed_timer (env, +booke_get_fit_target (env), + &booke_timer->fit_next, + booke_timer->fit_timer); + +booke_update_fixed_timer (env, +booke_get_wdt_target (env), + &booke_timer->wdt_next, + booke_timer->wdt_timer); +}Check for FIS/DIS/WIS -- the corresponding enable bit might have just been set.
Quoted 8 lines
Quoted 1 line
Can you explain, I don't see the problem.
If a decrementer fires with TCR[DIE] unset, it won't be delivered, but TSR[DIS] will be set.
If a guest subsequenly sets TCR[DIE], without having first cleared TSR[DIS], the interrupt should fire immediately -- but that will only happen if you check for it here.
I see, I will fix this.
Signature · 1 line
Fabien Chouteau
Quoted 13 lines · On Thu, 30 Jun 2011 17:51:10 +0200 Fabien Chouteau <[email protected]> wrote:
Quoted 12 lines · Scott Wood
Quoted 9 lines · On Tue, 28 Jun 2011 15:35:00 +0200 Fabien Chouteau <[email protected]> wrote:
Quoted 8 lines · Scott Wood
Quoted 4 lines · On Mon, 27 Jun 2011 18:14:06 +0200 Fabien Chouteau <[email protected]> wrote:
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).
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
ppc_emb_timers_initshould be renamed something less generic, then.Agreed, can you help me to find a better name?
What chips are covered by it? 40x?
The function is used by
ppc4xx_init(ppc4xx_devs.c) andppc440_init_xilinx(virtex_ml507.c), so I guessppc_4xx_timers_intwill be fine...
Doesn't 440 have normal booke timers?
Quoted 10 lines
Quoted 10 lines
Quoted 6 lines
Quoted 3 lines
I think some changes in the decrementer code are needed to provide booke semantics -- no raising the interrupt based on the high bit of decr, and stop counting when reach zero.
Can you please explain, I don't see where I'm not compliant with booke's decrementer.
It's not an issue with this code specifically, but existing behavior in the decrementer code that isn't appropriate for booke.
Quoted 7 lines
Quoted 4 lines
On classic/server powerpc, when decrementer hits zero, it wraps around, and the upper bit of DECR is used to signal the interrupt. On booke, when decrementer hits zero, it stops, and the upper bit of DECR is not special.
And that's why I implemented the
booke_decr_cbfunction that will emulate this behavior.
booke_decr_cb() doesn't control what happens when DECR is read after an expiration, nor does it control whether an interrupt is raised if software writes DECR with the high bit set.
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
It's just a mask to keep only the defined bits.
Just seems unnecessary, and potentially harmful if CPU-specific code wants to interpret implementation-defined bits, or if new bits are architected in the future.
On the other hand, undefined bit should always be read as zeros.
I don't think there's any such requirement.
-Scott
Quoted 18 lines · Scott Wood
Quoted 15 lines · On Thu, 30 Jun 2011 17:51:10 +0200 Fabien Chouteau <[email protected]> wrote:
Quoted 14 lines · Scott Wood
Quoted 11 lines · On Tue, 28 Jun 2011 15:35:00 +0200 Fabien Chouteau <[email protected]> wrote:
Quoted 9 lines · Scott Wood
Quoted 4 lines · On Mon, 27 Jun 2011 18:14:06 +0200 Fabien Chouteau <[email protected]> wrote:
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).
ppc_emb_timers_initshould be renamed something less generic, then.
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Agreed, can you help me to find a better name?
What chips are covered by it? 40x?
The function is used by
ppc4xx_init(ppc4xx_devs.c) andppc440_init_xilinx(virtex_ml507.c), so I guessppc_4xx_timers_intwill be fine...Doesn't 440 have normal booke timers?
Actually ppc_emb_timers_init should be renamed ppc40x_timers_init, and Xilinx's ppc440 should use the new implementation of booke timers.
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
Quoted 6 lines
Quoted 3 lines
I think some changes in the decrementer code are needed to provide booke semantics -- no raising the interrupt based on the high bit of decr, and stop counting when reach zero.
Can you please explain, I don't see where I'm not compliant with booke's decrementer.
It's not an issue with this code specifically, but existing behavior in the decrementer code that isn't appropriate for booke.
On classic/server powerpc, when decrementer hits zero, it wraps around, and the upper bit of DECR is used to signal the interrupt. On booke, when decrementer hits zero, it stops, and the upper bit of DECR is not special.
Quoted 7 lines
Quoted 2 lines
And that's why I implemented the
booke_decr_cbfunction that will emulate this behavior.
booke_decr_cb()doesn't control what happens when DECR is read after an expiration, nor does it control whether an interrupt is raised if software writes DECR with the high bit set.
OK, I will add a condition to avoid this on booke processors.
Quoted 10 lines
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
It's just a mask to keep only the defined bits.
Just seems unnecessary, and potentially harmful if CPU-specific code wants to interpret implementation-defined bits, or if new bits are architected in the future.
On the other hand, undefined bit should always be read as zeros.
I don't think there's any such requirement.
My bad ;)
"The handling of reserved bits in System Registers (e.g. Integer Exception Register, Floating-Point Status and Control Register) is implementation-dependent. Software is permitted to write any value to such a bit with no visible effect on processors that implement this version of Book E. A subsequent reading of the bit returns a 0 if the last value written to the bit was 0 and returns an undefined value (0 or 1) otherwise."
Signature · 1 line
Fabien Chouteau