alpha: Decouple the CPU and Typhoon
cover alpha: Decouple the CPU and Typhoon
From: Yodel Eldar <[email protected]>
Hi,
This series is intended as a leg of a re-spin of the "QOMify Clipper and Typhoon" series [1]. There, thanks to a suggestion by Philippe, we decided to decouple the Alpha CPU from the Typhoon chipset to improve the machine model.
Currently, the CPU owns a QEMUTimer and its state owns the alarm expiration of that alarm timer. Modification of the timer is triggered via a QEMU-specific synthetic processor register in PALcode by changing the expiration value through the side effect invocation of a TCG helper function, helper_set_alarm(). Meanwhile, the timer alarm callback is defined in the Typhoon chipset, so the creation of the timer occurs during the realization of the chipset; thus, the typhoon must have access to CPU internals in violation of encapsulation and architectural accuracy. Instead, as Philippe pointed out, the chipset should just communicate with the CPU through an IRQ line wired by the board.
This series does that by removing the timer out of the CPU and into the chipset. The alarm expiration now resides in an QEMU-specific (non-standard) Cchip MMIO register at offset 0x7c0 as implemented in the PALcode binary. The logic as to what happens when alarm expiration is modified remains the same as before, but now we don't need the TCG helper function or the magic process register that triggers its invocation.
I'm submitting this series primarily to get feedback on the third and fourth patches, because it blurs the line of a refactor and a functional change; moreover, it necessitates a change in an external dependency (qemu-palcode), so I'm particularly interested in Richard's (its owner) opinion on the shift from a synthetic processor register to a vendor-specific MMIO register.
If we agree to take this route, as mentioned earlier, this series will be folded into the QOMification series that motivated it.
Patch 4 contains the modified palcode-clipper binary so that testers would not need to build it themselves, but my intent is to submit a PR to the qemu-palcode repo. The diff of the source changes to palcode-clipper are in the notes of Patch 4.
Patch 3 depends on Patch 4, so they'd need to be squashed together to avoid breaking bisect.
Patch 2 is much more straightforward: the Typhoon needs access to the CPU index for its read of the Cchip's MISC register; right now, we use current_cpu to get the index, but this is an antipattern, because it violates encapsulation. Instead, we designate the requester_id attribute in MemTxAttrs for the CPU index.
Patch 1 defines the instance_init for the Typhoon, so that we can instantiate the Typhoon in clipper_init() and connect the IRQ lines between the CPU and Typhoon there in Patch 3.
I look forward to your feedback.
Thanks,
Yodel
[1] https://lore.kernel.org/qemu-devel/[email protected]/
Yodel Eldar (4):
alpha: Define Typhoon instance_init
alpha: Propagate CPU index via MemTxAttrs
alpha: Replace helper_set_alarm with Typhoon Cchip MMIO register pc-bios/palcode-clipper: Replace qemu_alarm with Cchip register
hw/alpha/alpha_sys.h | 4 ++- hw/alpha/dp264.c | 12 ++++++- hw/alpha/typhoon.c | 69 ++++++++++++++++++++++++++------------ pc-bios/palcode-clipper | Bin 153728 -> 154432 bytes target/alpha/cpu.c | 17 ++++++++++ target/alpha/cpu.h | 6 ---- target/alpha/helper.c | 15 +++++++-- target/alpha/helper.h | 1 - target/alpha/sys_helper.c | 12 ------- target/alpha/translate.c | 11 ------ 10 files changed, 91 insertions(+), 56 deletions(-)
Signature · 1 line
2.53.0
RFC PATCH 1/4 alpha: Define Typhoon instance_init
From: Yodel Eldar <[email protected]>
--- hw/alpha/alpha_sys.h | 4 +++- hw/alpha/dp264.c | 8 +++++++- hw/alpha/typhoon.c | 24 ++++++++++++------------ 3 files changed, 22 insertions(+), 14 deletions(-)
hw/alpha/alpha_sys.h +3 -1
@@ -8,9 +8,11 @@#include "hw/core/boards.h" #include "hw/intc/i8259.h" +#define TYPE_TYPHOON_PCI_HOST_BRIDGE "typhoon-pcihost" +OBJECT_DECLARE_SIMPLE_TYPE(TyphoonState, TYPHOON_PCI_HOST_BRIDGE)PCIBus *typhoon_init (MemoryRegion *,qemu_irq *,qemu_irq *,AlphaCPU *[4 ], -pci_map_irq_fn ,uint8_t devfn_min); +pci_map_irq_fn ,uint8_t devfn_min,TyphoonState *);/* alpha_pci.c. */ extern const MemoryRegionOps alpha_pci_ignore_ops;
hw/alpha/dp264.c +7 -1
@@ -49,6 +49,7 @@ static void clipper_init(MachineState *machine)const char *kernel_cmdline = machine->kernel_cmdline;const char *initrd_filename = machine->initrd_filename;MachineClass *mc =MACHINE_GET_CLASS (machine); +Object *typhoon_obj;AlphaCPU *cpus[4 ];PCIBus *pci_bus;PCIDevice *pci_dev;
@@ -62,6 +63,10 @@ static void clipper_init(MachineState *machine)uint64_t kernel_entry, kernel_low;unsigned int smp_cpus = machine->smp.cpus; + typhoon_obj =object_new_with_props (TYPE_TYPHOON_PCI_HOST_BRIDGE , +OBJECT (machine),"typhoon" , + &error_fatal,NULL ); +/* Create up to 4 cpus. */ memset (cpus,0 ,sizeof (cpus));for (i =0 ; i < smp_cpus; ++i) {
@@ -87,7 +92,8 @@ static void clipper_init(MachineState *machine)* the minimum PCI device IdSel is 1. */ pci_bus =typhoon_init (machine->ram, &isa_irq, &rtc_irq, cpus, - clipper_pci_map_irq,PCI_DEVFN (1 ,0 )); + clipper_pci_map_irq,PCI_DEVFN (1 ,0 ), +TYPHOON_PCI_HOST_BRIDGE (typhoon_obj));/* * Init the PCI -> ISA bridge.
hw/alpha/typhoon.c +12 -12
@@ -17,7 +17,6 @@#include "alpha_sys.h" -#define TYPE_TYPHOON_PCI_HOST_BRIDGE "typhoon-pcihost"#define TYPE_TYPHOON_IOMMU_MEMORY_REGION "typhoon-iommu-memory-region" typedef struct TyphoonCchip {
@@ -49,8 +48,6 @@ typedef struct TyphoonPchip {TyphoonWindow win[4 ]; } TyphoonPchip; -OBJECT_DECLARE_SIMPLE_TYPE(TyphoonState, TYPHOON_PCI_HOST_BRIDGE) -struct TyphoonState {PCIHostState parent_obj;
@@ -819,25 +816,27 @@ static void typhoon_alarm_timer(void *opaque)cpu_interrupt (CPU (s->cchip.cpu[cpu]),CPU_INTERRUPT_TIMER ); } +static void typhoon_pcihost_instance_init (Object *obj) +{ +TyphoonState *s =TYPHOON_PCI_HOST_BRIDGE (obj); + + s->cchip.misc =0x800000000ull ;/* Revision: Typhoon. */ + s->pchip.win[3 ].wba =2 ;/* Window 3 SG always enabled. */ +} +PCIBus *typhoon_init (MemoryRegion *ram,qemu_irq *p_isa_irq,qemu_irq *p_rtc_irq,AlphaCPU *cpus[4 ], -pci_map_irq_fn sys_map_irq,uint8_t devfn_min) +pci_map_irq_fn sys_map_irq,uint8_t devfn_min, +TyphoonState *s) {MemoryRegion *addr_space =get_system_memory (); -DeviceState *dev; -TyphoonState *s; +DeviceState *dev =DEVICE (s);PCIHostState *phb;PCIBus *b;int i; - dev =qdev_new (TYPE_TYPHOON_PCI_HOST_BRIDGE ); - - s =TYPHOON_PCI_HOST_BRIDGE (dev); phb =PCI_HOST_BRIDGE (dev); - s->cchip.misc =0x800000000ull ;/* Revision: Typhoon. */ - s->pchip.win[3 ].wba =2 ;/* Window 3 SG always enabled. */ -/* Remember the CPUs so that we can deliver interrupts to them. */ for (i =0 ; i <4 ; i++) {AlphaCPU *cpu = cpus[i];
@@ -931,6 +930,7 @@ PCIBus *typhoon_init(MemoryRegion *ram, qemu_irq *p_isa_irq,static const TypeInfo typhoon_pcihost_info = { .name =TYPE_TYPHOON_PCI_HOST_BRIDGE , .parent =TYPE_PCI_HOST_BRIDGE , + .instance_init = typhoon_pcihost_instance_init, .instance_size =sizeof (TyphoonState), };
Signature · 1 line
2.53.0
Re: [RFC PATCH 1/4] alpha: Define Typhoon instance_init
Quoted 8 lines · Yodel Eldar
From: Yodel Eldar <[email protected]>
Signed-off-by Yodel Eldar <[email protected]>--- hw/alpha/alpha_sys.h | 4 +++- hw/alpha/dp264.c | 8 +++++++- hw/alpha/typhoon.c | 24 ++++++++++++------------ 3 files changed, 22 insertions(+), 14 deletions(-)
This is doing more than one thing.
The subject says adding typhoon_pcihost_instance_init, but that would just be moving two lines out of typhoon_init.
Creating the typhoon object in clipper_init is a different change, and I don't see how that's even helpful at this stage, since typhoon_obj is not used in clipper_init.
r~
Re: [RFC PATCH 1/4] alpha: Define Typhoon instance_init
Quoted 10 lines · Richard Henderson
Quoted 8 lines · Yodel Eldar
From: Yodel Eldar <[email protected]>
Signed-off-by Yodel Eldar <[email protected]>---
hw/alpha/alpha_sys.h| 4 +++- hw/alpha/dp264.c | 8 +++++++- hw/alpha/typhoon.c | 24 ++++++++++++------------3 files changed, 22 insertions(+), 14 deletions(-)
Quoted 6 lines
This is doing more than one thing.
The subject says adding
typhoon_pcihost_instance_init, but that would just be moving two lines out oftyphoon_init.Creating the typhoon object in
clipper_initis a different change, and I don't see how that's even helpful at this stage, sincetyphoon_objis not used inclipper_init.
Like Patch 3, I'll split this one, too. Thanks for being specific.
Yodel
Quoted 3 lines
r~
RFC PATCH 2/4 alpha: Propagate CPU index via MemTxAttrs
In reply to Yodel EldarFrom: Yodel Eldar <[email protected]>
Currently, a read of the Typhoon Cchip's MISC register dereferences current_cpu for the CPU index. To decouple Typhoon from the CPU, let's instead pass the CPU index through the requester_id attribute of the memory transaction.
--- hw/alpha/typhoon.c | 7 ++++--- target/alpha/helper.c | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-)
hw/alpha/typhoon.c +4 -3
@@ -74,7 +74,6 @@ static MemTxResult cchip_read(void *opaque, hwaddr addr, uint64_t *data, unsigned size, MemTxAttrs attrs) { - CPUState *cpu = current_cpu; TyphoonState *s = opaque;uint64_t ret =0 ;
@@ -90,10 +89,12 @@ static MemTxResult cchip_read(void *opaque, hwaddr addr,/* All sorts of stuff related to real DRAM. */ break ; -case 0x0080 : +case 0x0080 : {/* MISC: Miscellaneous Register. */ - ret = s->cchip.misc | (cpu->cpu_index &3 ); +uint64_t cpu_index = attrs.requester_id &3 ; + ret = s->cchip.misc | cpu_index;break ; + }case 0x00c0 :/* MPD: Memory Presence Detect Register. */
target/alpha/helper.c +12 -3
@@ -164,13 +164,19 @@ void alpha_cpu_record_sigsegv(CPUState *cs, vaddr address, env->trap_arg2 = cause; }#else +static inline QEMU_ALWAYS_INLINE +MemTxAttrs alpha_cpu_get_mem_attrs(const CPUState *cs) +{ +return (MemTxAttrs ){ .requester_id = cs->cpu_index }; +} +/* Returns the OSF/1 entMM failure indication, or -1 on success. */ static int get_physical_address (CPUAlphaState *env,vaddr addr,int prot_need,int mmu_idx,hwaddr *pphys,int *pprot) { -const MemTxAttrs attrs =MEMTXATTRS_UNSPECIFIED ;CPUState *cs =env_cpu (env); +const MemTxAttrs attrs =alpha_cpu_get_mem_attrs (cs);target_long saddr = addr;hwaddr phys =0 ;uint64_t L1pte, L2pte, L3pte;
@@ -327,8 +333,11 @@ bool alpha_cpu_tlb_fill(CPUState *cs, vaddr addr, int size,cpu_loop_exit_restore (cs, retaddr); } -tlb_set_page (cs, addr &TARGET_PAGE_MASK , phys &TARGET_PAGE_MASK , - prot, mmu_idx,TARGET_PAGE_SIZE ); +tlb_set_page_with_attrs (cs, addr &TARGET_PAGE_MASK , + phys &TARGET_PAGE_MASK , +alpha_cpu_get_mem_attrs (cs), + prot, mmu_idx,TARGET_PAGE_SIZE ); +return true; }
Signature · 1 line
2.53.0
Re: [RFC PATCH 2/4] alpha: Propagate CPU index via MemTxAttrs
Quoted 13 lines · Yodel Eldar
From: Yodel Eldar <[email protected]>
Currently, a read of the Typhoon Cchip's MISC register dereferences
current_cpufor the CPU index. To decouple Typhoon from the CPU, let's instead pass the CPU index through therequester_idattribute of the memory transaction.Signed-off-by Yodel Eldar <[email protected]>--- hw/alpha/typhoon.c | 7 ++++--- target/alpha/helper.c | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-)
target/alpha/helper.c void alpha_cpu_record_sigsegv(CPUState *cs, vaddr address, · line 171
Quoted 5 lines
target/alpha/helper.c +5
-0+static inline QEMU_ALWAYS_INLINE +MemTxAttrs alpha_cpu_get_mem_attrs(const CPUState *cs) +{ +return (MemTxAttrs ){ .requester_id = cs->cpu_index }; +}
No need for QEMU_ALWAYS_INLINE.
Otherwise,
r~
Re: [RFC PATCH 2/4] alpha: Propagate CPU index via MemTxAttrs
Quoted 14 lines · Richard Henderson
Quoted 12 lines · Yodel Eldar
From: Yodel Eldar <[email protected]>
Currently, a read of the Typhoon Cchip's MISC register dereferences
current_cpufor the CPU index. To decouple Typhoon from the CPU, let's instead pass the CPU index through therequester_idattribute of the memory transaction.Signed-off-by Yodel Eldar <[email protected]>---
hw/alpha/typhoon.c | 7 ++++---target/alpha/helper.c| 15 ++++++++++++---2 files changed, 16 insertions(+), 6 deletions(-)
Quoted 8 lines
target/alpha/helper.c void alpha_cpu_record_sigsegv(CPUState *cs, vaddr address, · line 171
Quoted 5 lines
target/alpha/helper.c +5
-0+static inline QEMU_ALWAYS_INLINE +MemTxAttrs alpha_cpu_get_mem_attrs(const CPUState *cs) +{ + return (MemTxAttrs){ .requester_id = cs->cpu_index }; +}No need for
QEMU_ALWAYS_INLINE.
Consider it gone.
Quoted 3 lines
Otherwise,
Reviewed-by Richard Henderson <[email protected]>
Thanks for the R-b.
Yodel
Quoted 3 lines
r~
RFC PATCH 3/4 alpha: Replace helper_set_alarm with Typhoon Cchip MMIO register
In reply to Yodel EldarFrom: Yodel Eldar <[email protected]>
This commit creates a QEMU-specific (non-standard) MMIO register in Typhoon's Cchip to replace helper_set_alarm() and to move the QEMUTimer pointer, alarm_timer, out of the Alpha CPU and into the chipset code.
Currently, PALcode writes to the QEMU-specific, synthetic Processor Register (index 251) and triggers the invocation of helper_set_alarm() as a side effect in QEMU, thereby setting the timer alarm expiration value.
This works, because the AlphaCPU contains the QEMUTimer and CPUAlphaState stores the alarm expiration value; however, the timer alarm callback resides in and is specific to the Typhoon chipset, thus the CPU and the chipset are entangled.
By designating the currently unused offset (0x7c0) of Cchip as the location of the timer alarm expiration, we can disentangle and better encapsulate both.
---
Notes:
The patch to the palcode-clipper binary that follows this one is necessary for this patch to work; I've left the diff to the source in the notes of it for reproduction.
Philippe:
Thanks, again, for the suggestion of decoupling the CPU from the Typhoon using IRQ lines. In my response, I guessed that getting the CPU index would be trickier than moving the timer into TyphoonState; perhaps you'll find it amusing (as I do) that it appears I had that backwards (due to the PALcode peculiarity)!
The remaining CPU interrupts will be refactored in v2 of that series.
hw/alpha/dp264.c | 4 ++++ hw/alpha/typhoon.c | 38 ++++++++++++++++++++++++++++++++------ target/alpha/cpu.c | 17 +++++++++++++++++ target/alpha/cpu.h | 6 ------ target/alpha/helper.h | 1 - target/alpha/sys_helper.c | 12 ------------ target/alpha/translate.c | 11 ----------- 7 files changed, 53 insertions(+), 36 deletions(-)
hw/alpha/dp264.c +4 -0
@@ -71,6 +71,10 @@ static void clipper_init(MachineState *machine)memset (cpus,0 ,sizeof (cpus));for (i =0 ; i < smp_cpus; ++i) { cpus[i] =ALPHA_CPU (cpu_create (machine->cpu_type)); + +qdev_connect_gpio_out_named (DEVICE (typhoon_obj),"cpu-irq" , i, +qdev_get_gpio_in_named (DEVICE (cpus[i]), +"timer-irq" ,0 )); }/*
hw/alpha/typhoon.c +32 -6
@@ -26,6 +26,9 @@ typedef struct TyphoonCchip {uint64_t dim[4 ];uint32_t iic[4 ];AlphaCPU *cpu[4 ]; +qemu_irq cpu_irq[4 ]; +QEMUTimer *alarm_timer[4 ]; +uint64_t alarm_expire[4 ]; } TyphoonCchip; typedef struct TyphoonWindow {
@@ -187,6 +190,14 @@ static MemTxResult cchip_read(void *opaque, hwaddr addr,/* PWR: Power Management Control. */ break ; +case 0x07c0 : { +/* ALRM: QEMU-specific Timer Alarm Register */ +uint64_t cpu_index = attrs.requester_id &3 ; + + ret = s->cchip.alarm_expire[cpu_index]; + +break ; + }case 0x0c00 :/* CMONCTLA */ case 0x0c40 :/* CMONCTLB */ case 0x0c80 :/* CMONCNT01 */
@@ -352,7 +363,7 @@ static MemTxResult cchip_write(void *opaque, hwaddr addr,/* ITI can only be cleared by the write. */ if ((newval & (1 << (i +4 ))) ==0 ) { -cpu_reset_interrupt (cs,CPU_INTERRUPT_TIMER ); +qemu_set_irq (s->cchip.cpu_irq[i],0 ); } } }
@@ -439,6 +450,19 @@ static MemTxResult cchip_write(void *opaque, hwaddr addr,/* PWR: Power Management Control. */ break ; +case 0x07c0 : { +/* ALRM: QEMU-specific Timer Alarm Register */ +uint64_t cpu_index = attrs.requester_id &3 ; +QEMUTimer *alarm_timer = s->cchip.alarm_timer[cpu_index]; + +if (val) { + s->cchip.alarm_expire[cpu_index] = val; +timer_mod (alarm_timer, val); + }else { +timer_del (alarm_timer); + } +break ; + }case 0x0c00 :/* CMONCTLA */ case 0x0c40 :/* CMONCTLB */ case 0x0c80 :/* CMONCNT01 */
@@ -801,7 +825,7 @@ static void typhoon_set_timer_irq(void *opaque, int irq, int level)/* Set the ITI bit for this cpu. */ s->cchip.misc |=1 << (i +4 );/* And signal the interrupt. */ -cpu_interrupt (CPU (cpu),CPU_INTERRUPT_TIMER ); +qemu_set_irq (s->cchip.cpu_irq[i],1 ); } } }
@@ -814,7 +838,7 @@ static void typhoon_alarm_timer(void *opaque)/* Set the ITI bit for this cpu. */ s->cchip.misc |=1 << (cpu +4 ); -cpu_interrupt (CPU (s->cchip.cpu[cpu]),CPU_INTERRUPT_TIMER ); +qemu_set_irq (s->cchip.cpu_irq[cpu],1 ); }static void typhoon_pcihost_instance_init (Object *obj)
@@ -823,6 +847,8 @@ static void typhoon_pcihost_instance_init(Object *obj) s->cchip.misc =0x800000000ull ;/* Revision: Typhoon. */ s->pchip.win[3 ].wba =2 ;/* Window 3 SG always enabled. */ + +qdev_init_gpio_out_named (DEVICE (s), s->cchip.cpu_irq,"cpu-irq" ,4 ); } PCIBus *typhoon_init(MemoryRegion *ram, qemu_irq *p_isa_irq,
@@ -843,9 +869,9 @@ PCIBus *typhoon_init(MemoryRegion *ram, qemu_irq *p_isa_irq,AlphaCPU *cpu = cpus[i]; s->cchip.cpu[i] = cpu;if (cpu !=NULL ) { - cpu->alarm_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , - typhoon_alarm_timer, - (void *)((uintptr_t )s + i)); + s->cchip.alarm_timer[i] =timer_new_ns (QEMU_CLOCK_VIRTUAL , + typhoon_alarm_timer, + (void *)((uintptr_t )s + i)); } }
target/alpha/cpu.c +17 -0
@@ -27,6 +27,7 @@#include "exec/target_page.h" #include "accel/tcg/cpu-ops.h" #include "fpu/softfloat.h" +#include "hw/core/cpu.h" static void alpha_cpu_set_pc (CPUState *cs,vaddr value)
@@ -203,10 +204,26 @@ static void ev67_cpu_initfn(Object *obj)cpu_env (CPU (obj))->amask |=AMASK_CIX |AMASK_PREFETCH ; } +#ifndef CONFIG_USER_ONLY +static void alpha_cpu_irq_handler (void *opaque,int irq,int level) +{ +CPUState *cs =CPU (opaque); + +if (level) { +cpu_interrupt (cs,CPU_INTERRUPT_TIMER ); + }else { +cpu_reset_interrupt (cs,CPU_INTERRUPT_TIMER ); + } +} +#endif +static void alpha_cpu_initfn (Object *obj) {CPUAlphaState *env =cpu_env (CPU (obj)); +#ifndef CONFIG_USER_ONLY +qdev_init_gpio_in_named (DEVICE (obj), alpha_cpu_irq_handler,"timer-irq" ,1 ); +#endif /* TODO all this should be done in reset, not init */ env->lock_addr =-1 ;
target/alpha/cpu.h +0 -6
@@ -241,9 +241,6 @@ typedef struct CPUArchState {uint64_t scratch[24 ];#endif -/* This alarm doesn't exist in real hardware; we wish it did. */ -uint64_t alarm_expire; -int error_code;uint32_t features;
@@ -261,9 +258,6 @@ struct ArchCPU {CPUState parent_obj;CPUAlphaState env; - -/* This alarm doesn't exist in real hardware; we wish it did. */ -QEMUTimer *alarm_timer; };/**
target/alpha/helper.h +0 -1
@@ -96,5 +96,4 @@ DEF_HELPER_1(whami, i64, env) DEF_HELPER_FLAGS_0(get_vmtime, TCG_CALL_NO_RWG, i64) DEF_HELPER_FLAGS_0(get_walltime, TCG_CALL_NO_RWG, i64) -DEF_HELPER_FLAGS_2(set_alarm, TCG_CALL_NO_RWG, void, env, i64)#endif
target/alpha/sys_helper.c +0 -12
@@ -56,18 +56,6 @@ uint64_t helper_get_walltime(void)return qemu_clock_get_ns (rtc_clock); } -void helper_set_alarm (CPUAlphaState *env,uint64_t expire) -{ -AlphaCPU *cpu =env_archcpu (env); - -if (expire) { - env->alarm_expire = expire; -timer_mod (cpu->alarm_timer, expire); - }else { -timer_del (cpu->alarm_timer); - } -} -uint64_t HELPER (whami )(CPUAlphaState *env) {return env_cpu (env)->cpu_index;
target/alpha/translate.c +0 -11
@@ -1196,9 +1196,6 @@ static int cpu_pr_data(int pr) case 40 ... 63: return offsetof(CPUAlphaState, scratch[pr - 40]); - -case 251 : -return offsetof(CPUAlphaState , alarm_expire); }return 0 ; }
@@ -1280,14 +1277,6 @@ static DisasJumpType gen_mtpr(DisasContext *ctx, TCGv_i64 vb, int regno)gen_helper_halt (vb);return DISAS_PC_STALE ; -case 251 : -/* ALARM */ -if (translator_io_start (&ctx->base)) { - ret =DISAS_PC_STALE ; - } -gen_helper_set_alarm (tcg_env, vb); -break ; -case 7 :/* PALBR */ tcg_gen_st_i64 (vb, tcg_env, offsetof(CPUAlphaState , palbr));
Signature · 1 line
2.53.0
Re: [RFC PATCH 3/4] alpha: Replace helper_set_alarm with Typhoon Cchip MMIO register
Quoted 38 lines · Yodel Eldar
From: Yodel Eldar <[email protected]>
This commit creates a QEMU-specific (non-standard) MMIO register in Typhoon's Cchip to replace
helper_set_alarm()and to move the QEMUTimer pointer,alarm_timer, out of the Alpha CPU and into the chipset code.Currently, PALcode writes to the QEMU-specific, synthetic Processor Register (index 251) and triggers the invocation of
helper_set_alarm()as a side effect in QEMU, thereby setting the timer alarm expiration value.This works, because the AlphaCPU contains the QEMUTimer and CPUAlphaState stores the alarm expiration value; however, the timer alarm callback resides in and is specific to the Typhoon chipset, thus the CPU and the chipset are entangled.
By designating the currently unused offset (
0x7c0) of Cchip as the location of the timer alarm expiration, we can disentangle and better encapsulate both.Suggested-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Yodel Eldar <[email protected]>---
Notes:
The patch to the palcode-clipper binary that follows this one is necessary for this patch to work; I've left the diff to the source in the notes of it for reproduction.Philippe:
Thanks, again, for the suggestion of decoupling the CPU from the Typhoon using IRQ lines. In my response, I guessed that getting the CPU index would be trickier than moving the timer into TyphoonState; perhaps you'll find it amusing (as I do) that it appears I had that backwards (due to the PALcode peculiarity)!
Quoted 2 lines
The remaining CPU interrupts will be refactored in v2 of that series.
I'm not keen on this. I would much rather keep the synthetic processor register than add a synthetic CChip mmio.
In any case, this is also doing more than one thing at a time. For instance, Connecting the irq on typhoon to the irq on the cpu does not depend on anything else.
r~
Re: [RFC PATCH 3/4] alpha: Replace helper_set_alarm with Typhoon Cchip MMIO register
Quoted 40 lines · Richard Henderson
Quoted 25 lines · Yodel Eldar
From: Yodel Eldar <[email protected]>
This commit creates a QEMU-specific (non-standard) MMIO register in Typhoon's Cchip to replace
helper_set_alarm()and to move the QEMUTimer pointer,alarm_timer, out of the Alpha CPU and into the chipset code.Currently, PALcode writes to the QEMU-specific, synthetic Processor Register (index 251) and triggers the invocation of
helper_set_alarm()as a side effect in QEMU, thereby setting the timer alarm expiration value.This works, because the AlphaCPU contains the QEMUTimer and CPUAlphaState stores the alarm expiration value; however, the timer alarm callback resides in and is specific to the Typhoon chipset, thus the CPU and the chipset are entangled.
By designating the currently unused offset (
0x7c0) of Cchip as the location of the timer alarm expiration, we can disentangle and better encapsulate both.Suggested-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Yodel Eldar <[email protected]>---
Quoted 13 lines
Notes:
The patch to the palcode-clipper binary that follows this one is necessary for this patch to work; I've left the diff to the source in the notes of it for reproduction. Philippe:
Thanks, again, for the suggestion of decoupling the CPU from the Typhoon using IRQ lines. In my response, I guessed that getting the CPU index would be trickier than moving the timer into TyphoonState; perhaps you'll find it amusing (as I do) that it appears I had that backwards (due to the PALcode peculiarity)!
The remaining CPU interrupts will be refactored in v2 of that series.
Quoted 2 lines
I'm not keen on this. I would much rather keep the synthetic processor register than add a synthetic CChip mmio.
No problem... Are we okay with exposing a typhoon timer helper and TyphoonState to target/alpha/sys_helper.c via the inclusion of hw/alpha/alpha_sys.h?
If so, we can add an opaque pointer parameter to helper_set_alarm carrying the TyphoonState and invoke the typhoon timer helper; e.g.:
/* Inside target/alpha/sys_helper.c */
#include "hw/alpha/alpha_sys.h"
void helper_set_alarm(CPUAlphaState *env, uint64_t expire, void *opaque)
{
CPUState *cs = env_cpu(env);
TyphoonState *s = TYPHOON_PCI_HOST_BRIDGE(opaque);
int cpu_index = cs->cpu_index & 3;
if (expire) {
env->alarm_expire = expire;
typhoon_timer_mod(s, cpu_index, expire);
} else {
typhoon_timer_del(s, cpu_index);
}}
We'd have to keep alarm_expire in CPUAlphaState, because palcode-clipper would still expect it, but alarm timers would be moved into the typhoon as an array indexed by cpu_index.
WDYT?
Quoted 2 lines
In any case, this is also doing more than one thing at a time. For instance, Connecting the irq on typhoon to the irq on the cpu does not depend on anything else.
Thanks for the example; I'll split it next time.
Thanks again,
Yodel
Quoted 3 lines
r~
Re: [RFC PATCH 3/4] alpha: Replace helper_set_alarm with Typhoon Cchip MMIO register
Quoted 68 lines · Yodel Eldar
Quoted 40 lines · Richard Henderson
Quoted 25 lines · Yodel Eldar
From: Yodel Eldar <[email protected]>
This commit creates a QEMU-specific (non-standard) MMIO register in Typhoon's Cchip to replace
helper_set_alarm()and to move the QEMUTimer pointer,alarm_timer, out of the Alpha CPU and into the chipset code.Currently, PALcode writes to the QEMU-specific, synthetic Processor Register (index 251) and triggers the invocation of
helper_set_alarm()as a side effect in QEMU, thereby setting the timer alarm expiration value.This works, because the AlphaCPU contains the QEMUTimer and CPUAlphaState stores the alarm expiration value; however, the timer alarm callback resides in and is specific to the Typhoon chipset, thus the CPU and the chipset are entangled.
By designating the currently unused offset (
0x7c0) of Cchip as the location of the timer alarm expiration, we can disentangle and better encapsulate both.Suggested-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Yodel Eldar <[email protected]>---
Quoted 13 lines
Notes:
The patch to the palcode-clipper binary that follows this one is necessary for this patch to work; I've left the diff to the source in the notes of it for reproduction. Philippe:
Thanks, again, for the suggestion of decoupling the CPU from the Typhoon using IRQ lines. In my response, I guessed that getting the CPU index would be trickier than moving the timer into TyphoonState; perhaps you'll find it amusing (as I do) that it appears I had that backwards (due to the PALcode peculiarity)!
The remaining CPU interrupts will be refactored in v2 of that series.Quoted 2 lines
I'm not keen on this. I would much rather keep the synthetic processor register than add a synthetic CChip mmio.
No problem... Are we okay with exposing a typhoon timer helper and TyphoonState to
target/alpha/sys_helper.cvia the inclusion ofhw/alpha/alpha_sys.h?If so, we can add an opaque pointer parameter to
helper_set_alarmcarrying the TyphoonState and invoke the typhoon timer helper; e.g.:/* Inside
target/alpha/sys_helper.c*/
#include "hw/alpha/alpha_sys.h"void
helper_set_alarm(CPUAlphaState *env, uint64_t expire, void *opaque){
CPUState *cs =env_cpu(env);
TyphoonState *s =TYPHOON_PCI_HOST_BRIDGE(opaque);
intcpu_index=cs->cpu_index& 3;if (expire) {
env->alarm_expire= expire;
typhoon_timer_mod(s, cpu_index, expire);
} else {
typhoon_timer_del(s, cpu_index);
}
Quoted 7 lines
}
We'd have to keep
alarm_expirein CPUAlphaState, because palcode-clipper would still expect it, but alarm timers would be moved into the typhoon as an array indexed bycpu_index.WDYT?
I don't understand why you want to move the QEMUTimer. What do we gain by preventing the cpu from accessing the QEMUTimer?
r~
Re: [RFC PATCH 3/4] alpha: Replace helper_set_alarm with Typhoon Cchip MMIO register
Hi, Richard!
Quoted 71 lines · Richard Henderson
Quoted 70 lines · Yodel Eldar
Quoted 40 lines · Richard Henderson
Quoted 25 lines · Yodel Eldar
From: Yodel Eldar <[email protected]>
This commit creates a QEMU-specific (non-standard) MMIO register in Typhoon's Cchip to replace
helper_set_alarm()and to move the QEMUTimer pointer,alarm_timer, out of the Alpha CPU and into the chipset code.Currently, PALcode writes to the QEMU-specific, synthetic Processor Register (index 251) and triggers the invocation of
helper_set_alarm()as a side effect in QEMU, thereby setting the timer alarm expiration value.This works, because the AlphaCPU contains the QEMUTimer and CPUAlphaState stores the alarm expiration value; however, the timer alarm callback resides in and is specific to the Typhoon chipset, thus the CPU and the chipset are entangled.
By designating the currently unused offset (
0x7c0) of Cchip as the location of the timer alarm expiration, we can disentangle and better encapsulate both.Suggested-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Yodel Eldar <[email protected]>---
Quoted 13 lines
Notes:
The patch to the palcode-clipper binary that follows this one is necessary for this patch to work; I've left the diff to the source in the notes of it for reproduction. Philippe:
Thanks, again, for the suggestion of decoupling the CPU from the Typhoon using IRQ lines. In my response, I guessed that getting the CPU index would be trickier than moving the timer into TyphoonState; perhaps you'll find it amusing (as I do) that it appears I had that backwards (due to the PALcode peculiarity)!
The remaining CPU interrupts will be refactored in v2 of that series.Quoted 2 lines
I'm not keen on this. I would much rather keep the synthetic processor register than add a synthetic CChip mmio.
No problem... Are we okay with exposing a typhoon timer helper and TyphoonState to
target/alpha/sys_helper.cvia the inclusion ofhw/alpha/alpha_sys.h?If so, we can add an opaque pointer parameter to
helper_set_alarmcarrying the TyphoonState and invoke the typhoon timer helper; e.g.:/* Inside
target/alpha/sys_helper.c*/
#include "hw/alpha/alpha_sys.h"void
helper_set_alarm(CPUAlphaState *env, uint64_t expire, void *opaque){
CPUState *cs =env_cpu(env);
TyphoonState *s =TYPHOON_PCI_HOST_BRIDGE(opaque);
intcpu_index=cs->cpu_index& 3;if (expire) {
env->alarm_expire= expire;
typhoon_timer_mod(s, cpu_index, expire);
} else {
typhoon_timer_del(s, cpu_index);
}}
Quoted 8 lines
Quoted 5 lines
We'd have to keep
alarm_expirein CPUAlphaState, because palcode-clipper would still expect it, but alarm timers would be moved into the typhoon as an array indexed bycpu_index.WDYT?
I don't understand why you want to move the QEMUTimer. What do we gain by preventing the cpu from accessing the QEMUTimer?
For architectural accuracy and separation of concerns, I wanted to eliminate the references to the CPUs in Typhoon's Cchip, but as I mentioned in the email I just sent before I saw your reply, I understand the MMIO approach is probably too heavy-handed.
I'll drop the MMIO patch and am setting aside alternative approaches to focus on the rest of the QOMify series.
Thanks a lot for your comments and time.
Yodel
Quoted 3 lines
r~
Re: [RFC PATCH 3/4] alpha: Replace helper_set_alarm with Typhoon Cchip MMIO register
In reply to Yodel EldarQuoted 61 lines · Yodel Eldar
Quoted 40 lines · Richard Henderson
Quoted 25 lines · Yodel Eldar
From: Yodel Eldar <[email protected]>
This commit creates a QEMU-specific (non-standard) MMIO register in Typhoon's Cchip to replace
helper_set_alarm()and to move the QEMUTimer pointer,alarm_timer, out of the Alpha CPU and into the chipset code.Currently, PALcode writes to the QEMU-specific, synthetic Processor Register (index 251) and triggers the invocation of
helper_set_alarm()as a side effect in QEMU, thereby setting the timer alarm expiration value.This works, because the AlphaCPU contains the QEMUTimer and CPUAlphaState stores the alarm expiration value; however, the timer alarm callback resides in and is specific to the Typhoon chipset, thus the CPU and the chipset are entangled.
By designating the currently unused offset (
0x7c0) of Cchip as the location of the timer alarm expiration, we can disentangle and better encapsulate both.Suggested-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Yodel Eldar <[email protected]>---
Quoted 13 lines
Notes:
The patch to the palcode-clipper binary that follows this one is necessary for this patch to work; I've left the diff to the source in the notes of it for reproduction. Philippe:
Thanks, again, for the suggestion of decoupling the CPU from the Typhoon using IRQ lines. In my response, I guessed that getting the CPU index would be trickier than moving the timer into TyphoonState; perhaps you'll find it amusing (as I do) that it appears I had that backwards (due to the PALcode peculiarity)!
The remaining CPU interrupts will be refactored in v2 of that series.Quoted 2 lines
I'm not keen on this. I would much rather keep the synthetic processor register than add a synthetic CChip mmio.
No problem... Are we okay with exposing a typhoon timer helper and TyphoonState to
target/alpha/sys_helper.cvia the inclusion ofhw/alpha/alpha_sys.h?If so, we can add an opaque pointer parameter to
helper_set_alarmcarrying the TyphoonState and invoke the typhoon timer helper; e.g.:/* Inside
target/alpha/sys_helper.c*/
#include "hw/alpha/alpha_sys.h"void
helper_set_alarm(CPUAlphaState *env, uint64_t expire, void *opaque){
CPUState *cs =env_cpu(env);
TyphoonState *s =TYPHOON_PCI_HOST_BRIDGE(opaque);
intcpu_index=cs->cpu_index& 3;
Quoted 9 lines
if (expire) {
env->alarm_expire= expire;
typhoon_timer_mod(s, cpu_index, expire);
} else {
typhoon_timer_del(s, cpu_index);
}}
Hmm, on second thought, I'm not sure this is doable without setting a link property between CPU and Typhoon, and if we're relegated to that than adding the link property in Typhoon's instance_init (as in in Patch 8 of "QOMify Clipper and Typhoon" [1]) to use them in Typhoon's realize to create the timers is preferable over using them in TCG helper/translate.
The MMIO approach may be the only way to achieve encapsulation here, but it adds complexity and is probably not as performant than using a process register, so I understand the pushback against it.
Let's set aside the MMIO patch; I'll integrate the MemTxAttrs patch (to eliminate current_cpu from the MISC register read) into the larger QOMify series and replace all occurrences of cpu_{,reset_}interrupt with IRQ lines, but leave the alarm timers in the CPU. Since the callback for the timer alarm belongs to Typhoon, the Cchip will for the time being continue to have a reference to the CPUs (though, I'll continue to think about gentler ways of eliminating them).
Philippe: I hope two out of three nexuses will be enough for now?
Richard: Thanks for taking the time to check this out and for the feedback; I'll incorporate it into v2.
[1] <[email protected]>
Thanks,
Yodel
Quoted 19 lines
We'd have to keep
alarm_expirein CPUAlphaState, because palcode-clipper would still expect it, but alarm timers would be moved into the typhoon as an array indexed bycpu_index.WDYT?
Quoted 2 lines
In any case, this is also doing more than one thing at a time. For instance, Connecting the irq on typhoon to the irq on the cpu does not depend on anything else.
Thanks for the example; I'll split it next time.
Thanks again,
YodelQuoted 3 lines
r~
RFC 4/4 pc-bios/palcode-clipper: Replace qemu_alarm with Cchip register
In reply to Yodel EldarFrom: Yodel Eldar <[email protected]>
This commit removes the qemu_alarm function call in favor of a QEMU-specific, non-standard Cchip MMIO register at offset 0x7c0 to facilitate the move of the timer alarm from the CPU to the Typhoon chipset in QEMU.
Prior to this commit, modifying/stopping the timer required calling a QEMU TCG helper function (helper_set_alarm) via mtpr of qemu_alarm in PALcode; now, writing the absolute alarm expiration value in nanoseconds to Cchip+0x7c0 replaces that functionality.
Likewise, reads of Cchip+0x7c0 return the alarm expiration value, as mfpr of qemu_alarm did in Cserve_Get_Alarm().
Also, CallPal_Ndelay() now stores the delay value in the MMIO register, instead of moving to the qemu_alarm processor register and triggering helper_set_alarm() in QEMU.
---
Notes:
This binary diff patch is not intended for direct merging;
the previous patch needs this change in palcode-clipper to
function. The source diff in the notes below are the
changes made to the qemu-palcode repo [1] that resulted in
the binary provided here for convenience.
Richard:
If it's alright with you, I'll submit the diff below as a
PR to your qemu-palcode repo so that the resultant binary can
be squashed with the preceding QEMU patch that requires it.
Suppose the patches are approved, does that work for you?
As mentioned in the cover letter, I intend to fold this RFC
series into the "QOMify Clipper and Typhoon" [2] series as
part of its v2 re-spin, so any comments/suggestions on this
and the patch before it would be much appreciated. WDYT
about replacing the synthetic processor register that
triggers the helper_set_alarm() TCG helper with an MMIO
register in the Control chip of the Typhoon?
Instead of creating a register for each CPU, I went with
a single banked register at Cchip+0x7c0, because we get
the CPU index for free with the MemTxAttrs patch.
Would we rather go with ALRM{0,1,2,3} instead?
[1] https://github.com/rth7680/qemu-palcode.git
[2] <[email protected]>
diff --git a/core-typhoon.h b/core-typhoon.h
index 96a0a90..f4f4414 100644
--- a/core-typhoon.h
+++ b/core-typhoon.h
@@ -58,6 +58,8 @@
#define TYPHOON_CCHIP_IIC2 0x0700
#define TYPHOON_CCHIP_IIC3 0x0740
#define TYPHOON_CCHIP_PWR 0x0780
+/* QEMU-specific CPU timer alarm expiration */
+#define TYPHOON_CCHIP_ALRM 0x07c0
#define TYPHOON_CCHIP_CMONCTLA 0x0c00
#define TYPHOON_CCHIP_CMONCTLB 0x0c40
#define TYPHOON_CCHIP_CMONCNT01 0x0c80
diff --git a/pal.S b/pal.S
index 8d55a0a..7ea4080 100644
--- a/pal.S
+++ b/pal.S
@@ -422,9 +422,16 @@ ENDFN CallPal_Draina
*/
ORG_CALL_PAL_PRIV(0x03)
CallPal_Ndelay:
+ br CallPal_Ndelay_Cont
+ENDFN CallPal_Ndelay
+
+ .text 1
+ .align 3
+CallPal_Ndelay_Cont:
mfpr p0, qemu_vmtime
addq p0, a0, p0
- mtpr p0, qemu_alarm
+ LOAD_PHYS_CCHIP t0
+ stq_p p0, TYPHOON_CCHIP_ALRM(t0)
mtpr $31, qemu_wait
@@ -433,7 +440,8 @@ CallPal_Ndelay:
mfpr v0, qemu_vmtime
subq p0, v0, v0
hw_rei
-ENDFN CallPal_Ndelay
+ENDFN CallPal_Ndelay_Cont
+ .previous
ORG_CALL_PAL_PRIV(0x04)
CallPal_OpcDec04:
@@ -505,8 +513,8 @@ Cserve_Get_Wall_Time:
hw_rei
ENDFN Cserve_Get_Wall_Time
Cserve_Get_Alarm:
- mfpr v0, qemu_alarm
- hw_rei
+ br Cserve_Get_Alarm_Cont
+ nop
ENDFN Cserve_Get_Alarm
Cserve_Set_Alarm_Rel:
// Cheating here: create the absolute time and fall thru.
@@ -514,8 +522,8 @@ Cserve_Set_Alarm_Rel:
addq p0, a1, a1
ENDFN Cserve_Set_Alarm_Rel
Cserve_Set_Alarm_Abs:
- mtpr a1, qemu_alarm
- hw_rei
+ br Cserve_Set_Alarm_Abs_Cont
+ nop
ENDFN Cserve_Set_Alarm_Abs
Cserve_Get_VM_Time:
mfpr v0, qemu_vmtime
@@ -534,6 +542,18 @@ CallPal_Cserve_Cont:
bne v0, Cserve_Dis
hw_rei
ENDFN CallPal_Cserve_Cont
+
+Cserve_Get_Alarm_Cont:
+ LOAD_PHYS_CCHIP t0
+ ldq_p v0, TYPHOON_CCHIP_ALRM(t0)
+ hw_rei
+ENDFN Cserve_Get_Alarm_Cont
+
+Cserve_Set_Alarm_Abs_Cont:
+ LOAD_PHYS_CCHIP t0
+ stq_p a1, TYPHOON_CCHIP_ALRM(t0)
+ hw_rei
+ENDFN Cserve_Set_Alarm_Abs_Cont
.previous
/*
diff --git a/pal.h b/pal.h
index c89a18c..c37a85e 100644
--- a/pal.h
+++ b/pal.h
@@ -107,7 +107,6 @@
#define qemu_tbis 254
#define qemu_wait 253
#define qemu_halt 252
-#define qemu_alarm 251
#define qemu_walltime 250
#define qemu_vmtime 249pc-bios/palcode-clipper | Bin 153728 -> 154432 bytes 1 file changed, 0 insertions(+), 0 deletions(-)
pc-bios/palcode-clipper binary +0 -0
Signature · 1 line
2.53.0
Re: [RFC NOTFORMERGE 4/4] pc-bios/palcode-clipper: Replace qemu_alarm with Cchip register
Quoted 44 lines · Yodel Eldar
From: Yodel Eldar <[email protected]>
This commit removes the
qemu_alarmfunction call in favor of a QEMU-specific, non-standard Cchip MMIO register at offset0x7c0to facilitate the move of the timer alarm from the CPU to the Typhoon chipset in QEMU.Prior to this commit, modifying/stopping the timer required calling a QEMU TCG helper function (
helper_set_alarm) via mtpr ofqemu_alarmin PALcode; now, writing the absolute alarm expiration value in nanoseconds toCchip+0x7c0replaces that functionality.Likewise, reads of
Cchip+0x7c0return the alarm expiration value, as mfpr ofqemu_alarmdid inCserve_Get_Alarm().Also,
CallPal_Ndelay()now stores the delay value in the MMIO register, instead of moving to theqemu_alarmprocessor register and triggeringhelper_set_alarm()in QEMU.Signed-off-by Yodel Eldar <[email protected]>---
Notes:
This binary diff patch is not intended for direct merging; the previous patch needs this change in palcode-clipper to function. The source diff in the notes below are the changes made to the qemu-palcode repo [1] that resulted in the binary provided here for convenience.Richard:
If it's alright with you, I'll submit the diff below as a PR to your qemu-palcode repo so that the resultant binary can be squashed with the preceding QEMU patch that requires it. Suppose the patches are approved, does that work for you?As mentioned in the cover letter, I intend to fold this RFC series into the "QOMify Clipper and Typhoon" [2] series as part of its v2 re-spin, so any comments/suggestions on this and the patch before it would be much appreciated. WDYT about replacing the synthetic processor register that triggers the
helper_set_alarm()TCG helper with an MMIO register in the Control chip of the Typhoon?
Quoted 8 lines
Instead of creating a register for each CPU, I went with a single banked register at
Cchip+0x7c0, because we get the CPU index for free with the MemTxAttrs patch. Would we rather go with ALRM{0,1,2,3} instead?[1] https://github.com/rth7680/qemu-palcode.git
[2] <[email protected]>
Here's the fork containing the commit:
https://github.com/yodel/qemu-palcode/tree/timer-alarm
Thanks,
Yodel