ppc: pnv ChipTOD and various timebase fixes
v3 cover ppc: pnv ChipTOD and various timebase fixes
This accumulated a few changes and review comment fixes since v2:
- Remove the now unnecessary class xscom ops.
- Split the introduction of the chiptod model from wiring it to machines.
- Fix chiptod model patch changelog.
- Wrap chiptod/tb state machine variables in CPUArchState in a struct.
Will put this in the next merge window if no objections. Thanks to Cedric for all the review and help.
Thanks,
Nick
Nicholas Piggin (8):
target/ppc: Rename TBL to TB on 64-bit
target/ppc: Improve timebase register defines naming target/ppc: Fix move-to timebase SPR access permissions pnv/chiptod: Add POWER9/10 chiptod model
ppc/pnv: Wire ChipTOD model to powernv9 and powernv10 machines pnv/chiptod: Implement the ChipTOD to Core transfer target/ppc: Implement core timebase state machine and TFMR target/ppc: Add SMT support to time facilities
include/hw/ppc/pnv.h | 2 + include/hw/ppc/pnv_chip.h | 3 + include/hw/ppc/pnv_chiptod.h | 53 ++++ include/hw/ppc/pnv_xscom.h | 9 + target/ppc/cpu.h | 57 +++- hw/ppc/pnv.c | 45 +++ hw/ppc/pnv_chiptod.c | 586 +++++++++++++++++++++++++++++++++++ target/ppc/helper_regs.c | 39 ++- target/ppc/ppc-qmp-cmds.c | 4 + target/ppc/timebase_helper.c | 309 +++++++++++++++++- target/ppc/translate.c | 42 ++- hw/ppc/meson.build | 1 + hw/ppc/trace-events | 4 + 13 files changed, 1129 insertions(+), 25 deletions(-) create mode 100644 include/hw/ppc/pnv_chiptod.h create mode 100644 hw/ppc/pnv_chiptod.c
Signature · 1 line
2.42.0
PATCH v3 1/8 target/ppc: Rename TBL to TB on 64-bit
From the earliest PowerPC ISA, TBR (later SPR) 268 has been called TB and accessed with mftb instruction. The problem is that TB is the name of the 64-bit register, and 32-bit implementations can only read the lower half with one instruction, so 268 has also been called TBL and it does only read TBL on 32-bit.
Change SPR 268 to be called TB on 64-bit implementations.
--- target/ppc/helper_regs.c | 4 ++++ target/ppc/ppc-qmp-cmds.c | 4 ++++ 2 files changed, 8 insertions(+)
target/ppc/helper_regs.c +4 -0
@@ -460,7 +460,11 @@ void register_generic_sprs(PowerPCCPU *cpu) }/* Time base */ +#if defined(TARGET_PPC64 ) +spr_register (env,SPR_VTBL ,"TB" , +#elsespr_register (env,SPR_VTBL ,"TBL" , +#endif &spr_read_tbl,SPR_NOACCESS , &spr_read_tbl,SPR_NOACCESS , 0x00000000);
target/ppc/ppc-qmp-cmds.c +4 -0
@@ -103,7 +103,11 @@ const MonitorDef monitor_defs[] = { { "xer", 0, &monitor_get_xer }, { "msr", offsetof(CPUPPCState, msr) }, { "tbu", 0, &monitor_get_tbu, }, +#if defined(TARGET_PPC64) + { "tb", 0, &monitor_get_tbl, }, +#else { "tbl", 0, &monitor_get_tbl, }, +#endif { NULL }, };
Signature · 1 line
2.42.0
PATCH v3 2/8 target/ppc: Improve timebase register defines naming
In reply to Nicholas PigginThe timebase in ppc started out with the mftb instruction which is like mfspr but addressed timebase registers (TBRs) rather than SPRs. These instructions could be used to read TB and TBU at 268 and 269. Timebase could be written via the TBL and TBU SPRs at 284 and 285.
The ISA changed around v2.03 to bring TB and TBU reads into the SPR space at 268 and 269 (access via mftb TBR-space is still supported but will be phased out). Later, VTB was added which is an entirely different register.
The SPR number defines in QEMU are understandably inconsistently named. Change SPR 268, 269, 284, 285 to TBL, TBU, WR_TBL, WR_TBU, respectively.
--- target/ppc/cpu.h | 8 ++++---- target/ppc/helper_regs.c | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-)
target/ppc/cpu.h +4 -4
@@ -1750,8 +1750,8 @@ void ppc_compat_add_property(Object *obj, const char *name,#define SPR_USPRG5 (0x105)#define SPR_USPRG6 (0x106)#define SPR_USPRG7 (0x107) -#define SPR_VTBL (0x10C) -#define SPR_VTBU (0x10D) +#define SPR_TBL (0x10C) +#define SPR_TBU (0x10D)#define SPR_SPRG0 (0x110)#define SPR_SPRG1 (0x111)#define SPR_SPRG2 (0x112)
@@ -1764,8 +1764,8 @@ void ppc_compat_add_property(Object *obj, const char *name,#define SPR_SPRG7 (0x117)#define SPR_ASR (0x118)#define SPR_EAR (0x11A) -#define SPR_TBL (0x11C) -#define SPR_TBU (0x11D) +#define SPR_WR_TBL (0x11C) +#define SPR_WR_TBU (0x11D)#define SPR_TBU40 (0x11E)#define SPR_SVR (0x11E)#define SPR_BOOKE_PIR (0x11E)
target/ppc/helper_regs.c +5 -5
@@ -461,22 +461,22 @@ void register_generic_sprs(PowerPCCPU *cpu)/* Time base */ #if defined(TARGET_PPC64 ) -spr_register (env,SPR_VTBL ,"TB" , +spr_register (env,SPR_TBL ,"TB" , #else - spr_register(env, SPR_VTBL, "TBL", + spr_register(env, SPR_TBL, "TBL", #endif &spr_read_tbl, SPR_NOACCESS, &spr_read_tbl, SPR_NOACCESS, 0x00000000); - spr_register(env, SPR_TBL, "TBL", + spr_register(env, SPR_WR_TBL, "TBL", &spr_read_tbl, SPR_NOACCESS, &spr_read_tbl, &spr_write_tbl, 0x00000000); - spr_register(env, SPR_VTBU, "TBU", + spr_register(env, SPR_TBU, "TBU", &spr_read_tbu, SPR_NOACCESS, &spr_read_tbu, SPR_NOACCESS, 0x00000000); -spr_register (env,SPR_TBU ,"TBU" , +spr_register (env,SPR_WR_TBU ,"TBU" , &spr_read_tbu,SPR_NOACCESS , &spr_read_tbu, &spr_write_tbu, 0x00000000);
Signature · 1 line
2.42.0
PATCH v3 3/8 target/ppc: Fix move-to timebase SPR access permissions
In reply to Nicholas PigginThe move-to timebase registers TBU and TBL can not be read, and they can not be written in supervisor mode on hypervisor-capable CPUs.
--- target/ppc/helper_regs.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-)
target/ppc/helper_regs.c +23 -8
@@ -468,18 +468,33 @@ void register_generic_sprs(PowerPCCPU *cpu) &spr_read_tbl,SPR_NOACCESS , &spr_read_tbl,SPR_NOACCESS , 0x00000000); -spr_register (env,SPR_WR_TBL ,"TBL" , - &spr_read_tbl,SPR_NOACCESS , - &spr_read_tbl, &spr_write_tbl, -0x00000000 );spr_register (env,SPR_TBU ,"TBU" , &spr_read_tbu,SPR_NOACCESS , &spr_read_tbu,SPR_NOACCESS ,0x00000000 ); -spr_register (env,SPR_WR_TBU ,"TBU" , - &spr_read_tbu,SPR_NOACCESS , - &spr_read_tbu, &spr_write_tbu, -0x00000000 ); +#ifndef CONFIG_USER_ONLY +if (env->has_hv_mode) { +spr_register_hv (env,SPR_WR_TBL ,"TBL" , +SPR_NOACCESS ,SPR_NOACCESS , +SPR_NOACCESS ,SPR_NOACCESS , +SPR_NOACCESS , &spr_write_tbl, +0x00000000 ); +spr_register_hv (env,SPR_WR_TBU ,"TBU" , +SPR_NOACCESS ,SPR_NOACCESS , +SPR_NOACCESS ,SPR_NOACCESS , +SPR_NOACCESS , &spr_write_tbu, +0x00000000 ); + }else { +spr_register (env,SPR_WR_TBL ,"TBL" , +SPR_NOACCESS ,SPR_NOACCESS , +SPR_NOACCESS , &spr_write_tbl, +0x00000000 ); +spr_register (env,SPR_WR_TBU ,"TBU" , +SPR_NOACCESS ,SPR_NOACCESS , +SPR_NOACCESS , &spr_write_tbu, +0x00000000 ); + } +#endif }void register_non_embedded_sprs (CPUPPCState *env)
Signature · 1 line
2.42.0
PATCH v3 4/8 pnv/chiptod: Add POWER9/10 chiptod model
In reply to Nicholas PigginThe ChipTOD (for Time-Of-Day) is a chip pervasive facility in IBM POWER (powernv) processors that keeps a time of day clock.
In particular for this model are facilities that initialise and start the time of day clock, and that synchronise that clock to cores on the chip, and to other chips. In this way, all cores on all chips can synchronise timebase (TB).
This model implements functionality sufficient to run the skiboot chiptod synchronisation procedure (with the following core timebase state machine implementation). It does not modify the TB in the cores where the real hardware would, because the QEMU ppc timebase implementation is always synchronised acros all cores.
--- include/hw/ppc/pnv_chiptod.h | 49 ++++ include/hw/ppc/pnv_xscom.h | 9 + hw/ppc/pnv_chiptod.c | 454 +++++++++++++++++++++++++++++++++++ hw/ppc/meson.build | 1 + hw/ppc/trace-events | 4 + 5 files changed, 517 insertions(+) create mode 100644 include/hw/ppc/pnv_chiptod.h create mode 100644 hw/ppc/pnv_chiptod.c
include/hw/ppc/pnv_chiptod.h new file +49 -0
@@ -0,0 +1,49 @@ +/* +* QEMU PowerPC PowerNV Emulation of some CHIPTOD behaviour +* +* Copyright (c) 2022-2023, IBM Corporation. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef PPC_PNV_CHIPTOD_H +#define PPC_PNV_CHIPTOD_H + +#include "qom/object.h" + +#define TYPE_PNV_CHIPTOD "pnv-chiptod" +OBJECT_DECLARE_TYPE(PnvChipTOD, PnvChipTODClass, PNV_CHIPTOD) +#define TYPE_PNV9_CHIPTOD TYPE_PNV_CHIPTOD "-POWER9" +DECLARE_INSTANCE_CHECKER(PnvChipTOD, PNV9_CHIPTOD, TYPE_PNV9_CHIPTOD) +#define TYPE_PNV10_CHIPTOD TYPE_PNV_CHIPTOD "-POWER10" +DECLARE_INSTANCE_CHECKER(PnvChipTOD, PNV10_CHIPTOD, TYPE_PNV10_CHIPTOD) + +enum tod_state { + tod_error =0 , + tod_not_set =7 , + tod_running =2 , + tod_stopped =1 , +}; + +struct PnvChipTOD { +DeviceState xd; + +PnvChip *chip; +MemoryRegion xscom_regs; + +bool primary; +bool secondary; +enum tod_state tod_state; +uint64_t tod_error; +uint64_t pss_mss_ctrl_reg; +}; + +struct PnvChipTODClass { +DeviceClass parent_class; + +void (*broadcast_ttype)(PnvChipTOD *sender,uint32_t trigger); + +int xscom_size; +}; + +#endif /* PPC_PNV_CHIPTOD_H */
include/hw/ppc/pnv_xscom.h +9 -0
@@ -64,6 +64,9 @@ struct PnvXScomInterfaceClass {#define PNV_XSCOM_PSIHB_BASE 0x2010900#define PNV_XSCOM_PSIHB_SIZE 0x20 +#define PNV_XSCOM_CHIPTOD_BASE 0x0040000 +#define PNV_XSCOM_CHIPTOD_SIZE 0x31 +#define PNV_XSCOM_OCC_BASE 0x0066000#define PNV_XSCOM_OCC_SIZE 0x6000
@@ -93,6 +96,9 @@ struct PnvXScomInterfaceClass {#define PNV9_XSCOM_I2CM_BASE 0xa0000#define PNV9_XSCOM_I2CM_SIZE 0x1000 +#define PNV9_XSCOM_CHIPTOD_BASE PNV_XSCOM_CHIPTOD_BASE +#define PNV9_XSCOM_CHIPTOD_SIZE PNV_XSCOM_CHIPTOD_SIZE +#define PNV9_XSCOM_OCC_BASE PNV_XSCOM_OCC_BASE#define PNV9_XSCOM_OCC_SIZE 0x8000
@@ -155,6 +161,9 @@ struct PnvXScomInterfaceClass {#define PNV10_XSCOM_I2CM_BASE PNV9_XSCOM_I2CM_BASE#define PNV10_XSCOM_I2CM_SIZE PNV9_XSCOM_I2CM_SIZE +#define PNV10_XSCOM_CHIPTOD_BASE PNV9_XSCOM_CHIPTOD_BASE +#define PNV10_XSCOM_CHIPTOD_SIZE PNV9_XSCOM_CHIPTOD_SIZE +#define PNV10_XSCOM_OCC_BASE PNV9_XSCOM_OCC_BASE#define PNV10_XSCOM_OCC_SIZE PNV9_XSCOM_OCC_SIZE
hw/ppc/pnv_chiptod.c new file +454 -0
454 lines not on this page · raw message
hw/ppc/meson.build +1 -0
@@ -46,6 +46,7 @@ ppc_ss.add(when: 'CONFIG_POWERNV', if_true: files( 'pnv_i2c.c', 'pnv_lpc.c', 'pnv_psi.c', + 'pnv_chiptod.c', 'pnv_occ.c', 'pnv_sbe.c', 'pnv_bmc.c',
hw/ppc/trace-events +4 -0
@@ -95,6 +95,10 @@ vof_write(uint32_t ih, unsigned cb, const char *msg) "ih=0x%x [%u] \"%s\"" vof_avail(uint64_t start, uint64_t end, uint64_t size) "0x%"PRIx64"..0x%"PRIx64" size=0x%"PRIx64 vof_claimed(uint64_t start, uint64_t end, uint64_t size) "0x%"PRIx64"..0x%"PRIx64" size=0x%"PRIx64 +# pnv_chiptod.c +pnv_chiptod_xscom_read(uint64_t addr, uint64_t val) "addr 0x%" PRIx64 " val 0x%" PRIx64 +pnv_chiptod_xscom_write(uint64_t addr, uint64_t val) "addr 0x%" PRIx64 " val 0x%" PRIx64 + # pnv_sbe.c pnv_sbe_xscom_ctrl_read(uint64_t addr, uint64_t val) "addr 0x%" PRIx64 " val 0x%" PRIx64 pnv_sbe_xscom_ctrl_write(uint64_t addr, uint64_t val) "addr 0x%" PRIx64 " val 0x%" PRIx64
Signature · 1 line
2.42.0
PATCH v3 5/8 ppc/pnv: Wire ChipTOD model to powernv9 and powernv10 machines
In reply to Nicholas PigginWire the ChipTOD model to powernv9 and powernv10 machines.
--- include/hw/ppc/pnv_chip.h | 3 +++ hw/ppc/pnv.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+)
include/hw/ppc/pnv_chip.h +3 -0
@@ -2,6 +2,7 @@#define PPC_PNV_CHIP_H #include "hw/pci-host/pnv_phb4.h" +#include "hw/ppc/pnv_chiptod.h" #include "hw/ppc/pnv_core.h" #include "hw/ppc/pnv_homer.h" #include "hw/ppc/pnv_lpc.h"
@@ -78,6 +79,7 @@ struct Pnv9Chip {PnvXive xive;Pnv9Psi psi;PnvLpcController lpc; +PnvChipTOD chiptod;PnvOCC occ;PnvSBE sbe;PnvHomer homer;
@@ -110,6 +112,7 @@ struct Pnv10Chip {PnvXive2 xive;Pnv9Psi psi;PnvLpcController lpc; +PnvChipTOD chiptod;PnvOCC occ;PnvSBE sbe;PnvHomer homer;
hw/ppc/pnv.c +30 -0
@@ -1419,6 +1419,8 @@ static void pnv_chip_power9_instance_init(Object *obj)object_initialize_child (obj,"lpc" , &chip9->lpc,TYPE_PNV9_LPC ); +object_initialize_child (obj,"chiptod" , &chip9->chiptod,TYPE_PNV9_CHIPTOD ); +object_initialize_child (obj,"occ" , &chip9->occ,TYPE_PNV9_OCC );object_initialize_child (obj,"sbe" , &chip9->sbe,TYPE_PNV9_SBE );
@@ -1565,6 +1567,19 @@ static void pnv_chip_power9_realize(DeviceState *dev, Error **errp) chip->dt_isa_nodename =g_strdup_printf ("/lpcm-opb@%" PRIx64"/lpc@0" , (uint64_t )PNV9_LPCM_BASE (chip)); +/* ChipTOD */ +object_property_set_bool (OBJECT (&chip9->chiptod),"primary" , + chip->chip_id ==0 , &error_abort); +object_property_set_bool (OBJECT (&chip9->chiptod),"secondary" , + chip->chip_id ==1 , &error_abort); +object_property_set_link (OBJECT (&chip9->chiptod),"chip" ,OBJECT (chip), + &error_abort); +if (!qdev_realize (DEVICE (&chip9->chiptod),NULL , errp)) { +return ; + } +pnv_xscom_add_subregion (chip,PNV9_XSCOM_CHIPTOD_BASE , + &chip9->chiptod.xscom_regs); +/* Create the simplified OCC model */ if (!qdev_realize (DEVICE (&chip9->occ),NULL , errp)) {return ;
@@ -1677,6 +1692,8 @@ static void pnv_chip_power10_instance_init(Object *obj) "xive-fabric");object_initialize_child (obj,"psi" , &chip10->psi,TYPE_PNV10_PSI );object_initialize_child (obj,"lpc" , &chip10->lpc,TYPE_PNV10_LPC ); +object_initialize_child (obj,"chiptod" , &chip10->chiptod, +TYPE_PNV10_CHIPTOD );object_initialize_child (obj,"occ" , &chip10->occ,TYPE_PNV10_OCC );object_initialize_child (obj,"sbe" , &chip10->sbe,TYPE_PNV10_SBE );object_initialize_child (obj,"homer" , &chip10->homer,TYPE_PNV10_HOMER );
@@ -1810,6 +1827,19 @@ static void pnv_chip_power10_realize(DeviceState *dev, Error **errp) chip->dt_isa_nodename =g_strdup_printf ("/lpcm-opb@%" PRIx64"/lpc@0" , (uint64_t )PNV10_LPCM_BASE (chip)); +/* ChipTOD */ +object_property_set_bool (OBJECT (&chip10->chiptod),"primary" , + chip->chip_id ==0 , &error_abort); +object_property_set_bool (OBJECT (&chip10->chiptod),"secondary" , + chip->chip_id ==1 , &error_abort); +object_property_set_link (OBJECT (&chip10->chiptod),"chip" ,OBJECT (chip), + &error_abort); +if (!qdev_realize (DEVICE (&chip10->chiptod),NULL , errp)) { +return ; + } +pnv_xscom_add_subregion (chip,PNV10_XSCOM_CHIPTOD_BASE , + &chip10->chiptod.xscom_regs); +/* Create the simplified OCC model */ if (!qdev_realize (DEVICE (&chip10->occ),NULL , errp)) {return ;
Signature · 1 line
2.42.0
Re: [PATCH v3 5/8] ppc/pnv: Wire ChipTOD model to powernv9 and powernv10 machines
Quoted 4 lines · Nicholas Piggin
Wire the ChipTOD model to powernv9 and powernv10 machines.
Suggested-by-by Cédric Le Goater <[email protected]>Signed-off-by Nicholas Piggin <[email protected]>
Thanks,
C.
Quoted 95 lines
--- include/hw/ppc/pnv_chip.h | 3 +++ hw/ppc/pnv.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+)include/hw/ppc/pnv_chip.h +3
-0@@ -2,6 +2,7 @@#define PPC_PNV_CHIP_H #include "hw/pci-host/pnv_phb4.h" +#include "hw/ppc/pnv_chiptod.h" #include "hw/ppc/pnv_core.h" #include "hw/ppc/pnv_homer.h" #include "hw/ppc/pnv_lpc.h" @@ -78,6 +79,7 @@ struct Pnv9Chip {PnvXive xive;Pnv9Psi psi;PnvLpcController lpc; +PnvChipTOD chiptod;PnvOCC occ;PnvSBE sbe;PnvHomer homer;@@ -110,6 +112,7 @@ struct Pnv10Chip {PnvXive2 xive;Pnv9Psi psi;PnvLpcController lpc; +PnvChipTOD chiptod;PnvOCC occ;PnvSBE sbe;PnvHomer homer;hw/ppc/pnv.c +30
-0@@ -1419,6 +1419,8 @@ static void pnv_chip_power9_instance_init(Object *obj)object_initialize_child (obj,"lpc" , &chip9->lpc,TYPE_PNV9_LPC ); +object_initialize_child (obj,"chiptod" , &chip9->chiptod,TYPE_PNV9_CHIPTOD ); +object_initialize_child (obj,"occ" , &chip9->occ,TYPE_PNV9_OCC );object_initialize_child (obj,"sbe" , &chip9->sbe,TYPE_PNV9_SBE );@@ -1565,6 +1567,19 @@ static void pnv_chip_power9_realize(DeviceState *dev, Error **errp) chip->dt_isa_nodename =g_strdup_printf ("/lpcm-opb@%" PRIx64"/lpc@0" , (uint64_t )PNV9_LPCM_BASE (chip)); +/* ChipTOD */ +object_property_set_bool (OBJECT (&chip9->chiptod),"primary" , + chip->chip_id ==0 , &error_abort); +object_property_set_bool (OBJECT (&chip9->chiptod),"secondary" , + chip->chip_id ==1 , &error_abort); +object_property_set_link (OBJECT (&chip9->chiptod),"chip" ,OBJECT (chip), + &error_abort); +if (!qdev_realize (DEVICE (&chip9->chiptod),NULL , errp)) { +return ; + } +pnv_xscom_add_subregion (chip,PNV9_XSCOM_CHIPTOD_BASE , + &chip9->chiptod.xscom_regs); +/* Create the simplified OCC model */ if (!qdev_realize (DEVICE (&chip9->occ),NULL , errp)) {return ;@@ -1677,6 +1692,8 @@ static void pnv_chip_power10_instance_init(Object *obj) "xive-fabric");object_initialize_child (obj,"psi" , &chip10->psi,TYPE_PNV10_PSI );object_initialize_child (obj,"lpc" , &chip10->lpc,TYPE_PNV10_LPC ); +object_initialize_child (obj,"chiptod" , &chip10->chiptod, +TYPE_PNV10_CHIPTOD );object_initialize_child (obj,"occ" , &chip10->occ,TYPE_PNV10_OCC );object_initialize_child (obj,"sbe" , &chip10->sbe,TYPE_PNV10_SBE );object_initialize_child (obj,"homer" , &chip10->homer,TYPE_PNV10_HOMER );@@ -1810,6 +1827,19 @@ static void pnv_chip_power10_realize(DeviceState *dev, Error **errp) chip->dt_isa_nodename =g_strdup_printf ("/lpcm-opb@%" PRIx64"/lpc@0" , (uint64_t )PNV10_LPCM_BASE (chip)); +/* ChipTOD */ +object_property_set_bool (OBJECT (&chip10->chiptod),"primary" , + chip->chip_id ==0 , &error_abort); +object_property_set_bool (OBJECT (&chip10->chiptod),"secondary" , + chip->chip_id ==1 , &error_abort); +object_property_set_link (OBJECT (&chip10->chiptod),"chip" ,OBJECT (chip), + &error_abort); +if (!qdev_realize (DEVICE (&chip10->chiptod),NULL , errp)) { +return ; + } +pnv_xscom_add_subregion (chip,PNV10_XSCOM_CHIPTOD_BASE , + &chip10->chiptod.xscom_regs); +/* Create the simplified OCC model */ if (!qdev_realize (DEVICE (&chip10->occ),NULL , errp)) {return ;
PATCH v3 6/8 pnv/chiptod: Implement the ChipTOD to Core transfer
In reply to Nicholas PigginOne of the functions of the ChipTOD is to transfer TOD to the Core (aka PC - Pervasive Core) timebase facility.
The ChipTOD can be programmed with a target address to send the TOD value to. The hardware implementation seems to perform this by sending the TOD value to a SCOM address.
This implementation grabs the core directly and manipulates the timebase facility state in the core. This is a hack, but it works enough for now. A better implementation would implement the transfer to the PnvCore xscom register and drive the timebase state machine from there.
--- include/hw/ppc/pnv.h | 2 + include/hw/ppc/pnv_chiptod.h | 4 ++ target/ppc/cpu.h | 13 ++++ hw/ppc/pnv.c | 15 ++++ hw/ppc/pnv_chiptod.c | 132 +++++++++++++++++++++++++++++++++++ 5 files changed, 166 insertions(+)
include/hw/ppc/pnv.h +2 -0
@@ -28,6 +28,7 @@#define TYPE_PNV_CHIP "pnv-chip" +typedef struct PnvCore PnvCore ;typedef struct PnvChip PnvChip ;typedef struct Pnv8Chip Pnv8Chip ;typedef struct Pnv9Chip Pnv9Chip ;
@@ -56,6 +57,7 @@ DECLARE_INSTANCE_CHECKER(PnvChip, PNV_CHIP_POWER9,DECLARE_INSTANCE_CHECKER (PnvChip,PNV_CHIP_POWER10 , TYPE_PNV_CHIP_POWER10) +PnvCore *pnv_chip_find_core (PnvChip *chip,uint32_t core_id);PowerPCCPU *pnv_chip_find_cpu (PnvChip *chip,uint32_t pir);typedef struct PnvPHB PnvPHB ;
include/hw/ppc/pnv_chiptod.h +4 -0
@@ -25,6 +25,8 @@ enum tod_state { tod_stopped = 1, }; +typedef struct PnvCore PnvCore ; +struct PnvChipTOD {DeviceState xd;
@@ -36,12 +38,14 @@ struct PnvChipTOD {enum tod_state tod_state;uint64_t tod_error;uint64_t pss_mss_ctrl_reg; +PnvCore *slave_pc_target; };struct PnvChipTODClass {DeviceClass parent_class;void (*broadcast_ttype)(PnvChipTOD *sender,uint32_t trigger); +PnvCore *(*tx_ttype_target)(PnvChipTOD *chiptod,uint64_t val);int xscom_size; };
target/ppc/cpu.h +13 -0
@@ -1183,6 +1183,13 @@ DEXCR_ASPECT(SRAPD, 4) DEXCR_ASPECT(NPHIE, 5)DEXCR_ASPECT (PHIE ,6 ) +/*****************************************************************************/ +/* PowerNV ChipTOD and TimeBase State Machine */ +struct pnv_tod_tbst { +int tb_ready_for_tod;/* core TB ready to receive TOD from chiptod */ +int tod_sent_to_tb;/* chiptod sent TOD to the core TB */ +}; +/*****************************************************************************/ /* The whole PowerPC CPU context */
@@ -1258,6 +1265,12 @@ struct CPUArchState {uint32_t tlb_need_flush;/* Delayed flush needed */ #define TLB_NEED_LOCAL_FLUSH 0x1#define TLB_NEED_GLOBAL_FLUSH 0x2 + +#if defined (TARGET_PPC64 ) +/* PowerNV chiptod / timebase facility state. */ +/* Would be nice to put these into PnvCore */ +struct pnv_tod_tbst pnv_tod_tbst; +#endif #endif /* Other registers */
hw/ppc/pnv.c +15 -0
@@ -2065,6 +2065,21 @@ static void pnv_chip_class_init(ObjectClass *klass, void *data) dc->desc ="PowerNV Chip" ; } +PnvCore *pnv_chip_find_core (PnvChip *chip,uint32_t core_id) +{ +int i; + +for (i =0 ; i < chip->nr_cores; i++) { +PnvCore *pc = chip->cores[i]; +CPUCore *cc =CPU_CORE (pc); + +if (cc->core_id == core_id) { +return pc; + } + } +return NULL ; +} +PowerPCCPU *pnv_chip_find_cpu (PnvChip *chip,uint32_t pir) {int i, j;
hw/ppc/pnv_chiptod.c +132 -0
162 lines not on this page · raw message
Signature · 1 line
2.42.0
PATCH v3 7/8 target/ppc: Implement core timebase state machine and TFMR
In reply to Nicholas PigginThis implements the core timebase state machine, which is the core side of the time-of-day system in POWER processors. This facility is operated by control fields in the TFMR register, which also contains status fields.
The core timebase interacts with the chiptod hardware, primarily to receive TOD updates, to synchronise timebase with other cores. This model does not actually update TB values with TOD or updates received from the chiptod, as timebases are always synchronised. It does step through the states required to perform the update.
There are several asynchronous state transitions. These are modelled using using mfTFMR to drive state changes, because it is expected that firmware poll the register to wait for those states. This is good enough to test basic firmware behaviour without adding real timers. The values chosen are arbitrary.
--- target/ppc/cpu.h | 36 ++++++ target/ppc/timebase_helper.c | 210 ++++++++++++++++++++++++++++++++++- 2 files changed, 243 insertions(+), 3 deletions(-)
target/ppc/cpu.h +36 -0
@@ -1188,6 +1188,14 @@ DEXCR_ASPECT(PHIE, 6)struct pnv_tod_tbst {int tb_ready_for_tod;/* core TB ready to receive TOD from chiptod */ int tod_sent_to_tb;/* chiptod sent TOD to the core TB */ + +/* +* "Timers" for async TBST events are simulated by mfTFAC because TFAC +* is polled for such events. These are just used to ensure firmware +* performs the polling at least a few times. +*/ +int tb_state_timer; +int tb_sync_pulse_timer; };/*****************************************************************************/
@@ -2661,6 +2669,34 @@ enum { HMER_XSCOM_STATUS_MASK = PPC_BITMASK(21, 23), }; +/* TFMR */ +enum { +TFMR_CONTROL_MASK =PPC_BITMASK (0 ,24 ), +TFMR_MASK_HMI =PPC_BIT (10 ), +TFMR_TB_ECLIPZ =PPC_BIT (14 ), +TFMR_LOAD_TOD_MOD =PPC_BIT (16 ), +TFMR_MOVE_CHIP_TOD_TO_TB =PPC_BIT (18 ), +TFMR_CLEAR_TB_ERRORS =PPC_BIT (24 ), +TFMR_STATUS_MASK =PPC_BITMASK (25 ,63 ), +TFMR_TBST_ENCODED =PPC_BITMASK (28 ,31 ),/* TBST = TB State */ +TFMR_TBST_LAST =PPC_BITMASK (32 ,35 ),/* Previous TBST */ +TFMR_TB_ENABLED =PPC_BIT (40 ), +TFMR_TB_VALID =PPC_BIT (41 ), +TFMR_TB_SYNC_OCCURED =PPC_BIT (42 ), +TFMR_FIRMWARE_CONTROL_ERROR =PPC_BIT (46 ), +}; + +/* TFMR TBST (Time Base State Machine). */ +enum { +TBST_RESET =0x0 , +TBST_SEND_TOD_MOD =0x1 , +TBST_NOT_SET =0x2 , +TBST_SYNC_WAIT =0x6 , +TBST_GET_TOD =0x7 , +TBST_TB_RUNNING =0x8 , +TBST_TB_ERROR =0x9 , +}; +/*****************************************************************************/ #define is_isa300 (ctx) (!!(ctx->insns_flags2 & PPC2_ISA300))
target/ppc/timebase_helper.c +207 -3
228 lines not on this page · raw message
Signature · 1 line
2.42.0
PATCH v3 8/8 target/ppc: Add SMT support to time facilities
In reply to Nicholas PigginThe TB, VTB, PURR, HDEC SPRs are per-LPAR registers, and the TFMR is a per-core register. Add the necessary SMT synchronisation and value sharing.
The TFMR can only drive the timebase state machine via thread 0 of the core, which is almost certainly not right, but it is enough for skiboot and certain other proprietary firmware.
--- target/ppc/timebase_helper.c | 105 ++++++++++++++++++++++++++++++++--- target/ppc/translate.c | 42 +++++++++++++- 2 files changed, 136 insertions(+), 11 deletions(-)
target/ppc/timebase_helper.c +96 -9
@@ -60,19 +60,55 @@ target_ulong helper_load_purr(CPUPPCState *env)void helper_store_purr (CPUPPCState *env,target_ulong val) { -cpu_ppc_store_purr (env, val); +CPUState *cs =env_cpu (env); +CPUState *ccs; +uint32_t nr_threads = cs->nr_threads; + +if (nr_threads ==1 || !(env->flags &POWERPC_FLAG_SMT_1LPAR )) { +cpu_ppc_store_purr (env, val); +return ; + } + + THREAD_SIBLING_FOREACH(cs, ccs) { +CPUPPCState *cenv = &POWERPC_CPU (ccs)->env; +cpu_ppc_store_purr (cenv, val); + } }#endif #if !defined(CONFIG_USER_ONLY )void helper_store_tbl (CPUPPCState *env,target_ulong val) { -cpu_ppc_store_tbl (env, val); +CPUState *cs =env_cpu (env); +CPUState *ccs; +uint32_t nr_threads = cs->nr_threads; + +if (nr_threads ==1 || !(env->flags &POWERPC_FLAG_SMT_1LPAR )) { +cpu_ppc_store_tbl (env, val); +return ; + } + + THREAD_SIBLING_FOREACH(cs, ccs) { +CPUPPCState *cenv = &POWERPC_CPU (ccs)->env; +cpu_ppc_store_tbl (cenv, val); + } }void helper_store_tbu (CPUPPCState *env,target_ulong val) { -cpu_ppc_store_tbu (env, val); +CPUState *cs =env_cpu (env); +CPUState *ccs; +uint32_t nr_threads = cs->nr_threads; + +if (nr_threads ==1 || !(env->flags &POWERPC_FLAG_SMT_1LPAR )) { +cpu_ppc_store_tbu (env, val); +return ; + } + + THREAD_SIBLING_FOREACH(cs, ccs) { +CPUPPCState *cenv = &POWERPC_CPU (ccs)->env; +cpu_ppc_store_tbu (cenv, val); + } }void helper_store_atbl (CPUPPCState *env,target_ulong val)
@@ -102,17 +138,53 @@ target_ulong helper_load_hdecr(CPUPPCState *env)void helper_store_hdecr (CPUPPCState *env,target_ulong val) { -cpu_ppc_store_hdecr (env, val); +CPUState *cs =env_cpu (env); +CPUState *ccs; +uint32_t nr_threads = cs->nr_threads; + +if (nr_threads ==1 || !(env->flags &POWERPC_FLAG_SMT_1LPAR )) { +cpu_ppc_store_hdecr (env, val); +return ; + } + + THREAD_SIBLING_FOREACH(cs, ccs) { +CPUPPCState *cenv = &POWERPC_CPU (ccs)->env; +cpu_ppc_store_hdecr (cenv, val); + } }void helper_store_vtb (CPUPPCState *env,target_ulong val) { -cpu_ppc_store_vtb (env, val); +CPUState *cs =env_cpu (env); +CPUState *ccs; +uint32_t nr_threads = cs->nr_threads; + +if (nr_threads ==1 || !(env->flags &POWERPC_FLAG_SMT_1LPAR )) { +cpu_ppc_store_vtb (env, val); +return ; + } + + THREAD_SIBLING_FOREACH(cs, ccs) { +CPUPPCState *cenv = &POWERPC_CPU (ccs)->env; +cpu_ppc_store_vtb (cenv, val); + } }void helper_store_tbu40 (CPUPPCState *env,target_ulong val) { -cpu_ppc_store_tbu40 (env, val); +CPUState *cs =env_cpu (env); +CPUState *ccs; +uint32_t nr_threads = cs->nr_threads; + +if (nr_threads ==1 || !(env->flags &POWERPC_FLAG_SMT_1LPAR )) { +cpu_ppc_store_tbu40 (env, val); +return ; + } + + THREAD_SIBLING_FOREACH(cs, ccs) { +CPUPPCState *cenv = &POWERPC_CPU (ccs)->env; +cpu_ppc_store_tbu40 (cenv, val); + } }target_ulong helper_load_40x_pit (CPUPPCState *env)
@@ -211,6 +283,21 @@ static uint64_t tfmr_new_tb_state(uint64_t tfmr, unsigned int tbst)return tfmr; } +static void write_tfmr (CPUPPCState *env,target_ulong val) +{ +CPUState *cs =env_cpu (env); + +if (cs->nr_threads ==1 ) { + env->spr[SPR_TFMR ] = val; + }else { +CPUState *ccs; + THREAD_SIBLING_FOREACH(cs, ccs) { +CPUPPCState *cenv = &POWERPC_CPU (ccs)->env; + cenv->spr[SPR_TFMR ] = val; + } + } +} +static void tb_state_machine_step (CPUPPCState *env) {uint64_t tfmr = env->spr[SPR_TFMR ];
@@ -224,7 +311,7 @@ static void tb_state_machine_step(CPUPPCState *env) env->pnv_tod_tbst.tb_sync_pulse_timer--; }else { tfmr |=TFMR_TB_SYNC_OCCURED ; - env->spr[SPR_TFMR ] = tfmr; +write_tfmr (env, tfmr); }if (env->pnv_tod_tbst.tb_state_timer) {
@@ -262,7 +349,7 @@ static void tb_state_machine_step(CPUPPCState *env) } } - env->spr[SPR_TFMR ] = tfmr; +write_tfmr (env, tfmr); }target_ulong helper_load_tfmr (CPUPPCState *env)
@@ -357,7 +444,7 @@ void helper_store_tfmr(CPUPPCState *env, target_ulong val) } out: - env->spr[SPR_TFMR ] = tfmr; +write_tfmr (env, tfmr); }#endif
target/ppc/translate.c +40 -2
100 lines not on this page · raw message
Signature · 1 line
2.42.0
Re: [PATCH v3 8/8] target/ppc: Add SMT support to time facilities
Quoted 9 lines · Nicholas Piggin
The TB, VTB, PURR, HDEC SPRs are per-LPAR registers, and the TFMR is a per-core register. Add the necessary SMT synchronisation and value sharing.
The TFMR can only drive the timebase state machine via thread 0 of the core, which is almost certainly not right, but it is enough for skiboot and certain other proprietary firmware.
Signed-off-by Nicholas Piggin <[email protected]>
Thanks,
C.
Quoted 284 lines
--- target/ppc/timebase_helper.c | 105 ++++++++++++++++++++++++++++++++--- target/ppc/translate.c | 42 +++++++++++++- 2 files changed, 136 insertions(+), 11 deletions(-)target/ppc/timebase_helper.c +96
-9@@ -60,19 +60,55 @@ target_ulong helper_load_purr(CPUPPCState *env)void helper_store_purr (CPUPPCState *env,target_ulong val) { -cpu_ppc_store_purr (env, val); +CPUState *cs =env_cpu (env); +CPUState *ccs; +uint32_t nr_threads = cs->nr_threads; + +if (nr_threads ==1 || !(env->flags &POWERPC_FLAG_SMT_1LPAR )) { +cpu_ppc_store_purr (env, val); +return ; + } + + THREAD_SIBLING_FOREACH(cs, ccs) { +CPUPPCState *cenv = &POWERPC_CPU (ccs)->env; +cpu_ppc_store_purr (cenv, val); + } }#endif #if !defined(CONFIG_USER_ONLY )void helper_store_tbl (CPUPPCState *env,target_ulong val) { -cpu_ppc_store_tbl (env, val); +CPUState *cs =env_cpu (env); +CPUState *ccs; +uint32_t nr_threads = cs->nr_threads; + +if (nr_threads ==1 || !(env->flags &POWERPC_FLAG_SMT_1LPAR )) { +cpu_ppc_store_tbl (env, val); +return ; + } + + THREAD_SIBLING_FOREACH(cs, ccs) { +CPUPPCState *cenv = &POWERPC_CPU (ccs)->env; +cpu_ppc_store_tbl (cenv, val); + } }void helper_store_tbu (CPUPPCState *env,target_ulong val) { -cpu_ppc_store_tbu (env, val); +CPUState *cs =env_cpu (env); +CPUState *ccs; +uint32_t nr_threads = cs->nr_threads; + +if (nr_threads ==1 || !(env->flags &POWERPC_FLAG_SMT_1LPAR )) { +cpu_ppc_store_tbu (env, val); +return ; + } + + THREAD_SIBLING_FOREACH(cs, ccs) { +CPUPPCState *cenv = &POWERPC_CPU (ccs)->env; +cpu_ppc_store_tbu (cenv, val); + } }void helper_store_atbl (CPUPPCState *env,target_ulong val)@@ -102,17 +138,53 @@ target_ulong helper_load_hdecr(CPUPPCState *env)void helper_store_hdecr (CPUPPCState *env,target_ulong val) { -cpu_ppc_store_hdecr (env, val); +CPUState *cs =env_cpu (env); +CPUState *ccs; +uint32_t nr_threads = cs->nr_threads; + +if (nr_threads ==1 || !(env->flags &POWERPC_FLAG_SMT_1LPAR )) { +cpu_ppc_store_hdecr (env, val); +return ; + } + + THREAD_SIBLING_FOREACH(cs, ccs) { +CPUPPCState *cenv = &POWERPC_CPU (ccs)->env; +cpu_ppc_store_hdecr (cenv, val); + } }void helper_store_vtb (CPUPPCState *env,target_ulong val) { -cpu_ppc_store_vtb (env, val); +CPUState *cs =env_cpu (env); +CPUState *ccs; +uint32_t nr_threads = cs->nr_threads; + +if (nr_threads ==1 || !(env->flags &POWERPC_FLAG_SMT_1LPAR )) { +cpu_ppc_store_vtb (env, val); +return ; + } + + THREAD_SIBLING_FOREACH(cs, ccs) { +CPUPPCState *cenv = &POWERPC_CPU (ccs)->env; +cpu_ppc_store_vtb (cenv, val); + } }void helper_store_tbu40 (CPUPPCState *env,target_ulong val) { -cpu_ppc_store_tbu40 (env, val); +CPUState *cs =env_cpu (env); +CPUState *ccs; +uint32_t nr_threads = cs->nr_threads; + +if (nr_threads ==1 || !(env->flags &POWERPC_FLAG_SMT_1LPAR )) { +cpu_ppc_store_tbu40 (env, val); +return ; + } + + THREAD_SIBLING_FOREACH(cs, ccs) { +CPUPPCState *cenv = &POWERPC_CPU (ccs)->env; +cpu_ppc_store_tbu40 (cenv, val); + } }target_ulong helper_load_40x_pit (CPUPPCState *env)@@ -211,6 +283,21 @@ static uint64_t tfmr_new_tb_state(uint64_t tfmr, unsigned int tbst)return tfmr; } +static void write_tfmr (CPUPPCState *env,target_ulong val) +{ +CPUState *cs =env_cpu (env); + +if (cs->nr_threads ==1 ) { + env->spr[SPR_TFMR ] = val; + }else { +CPUState *ccs; + THREAD_SIBLING_FOREACH(cs, ccs) { +CPUPPCState *cenv = &POWERPC_CPU (ccs)->env; + cenv->spr[SPR_TFMR ] = val; + } + } +} +static void tb_state_machine_step (CPUPPCState *env) {uint64_t tfmr = env->spr[SPR_TFMR ];@@ -224,7 +311,7 @@ static void tb_state_machine_step(CPUPPCState *env) env->pnv_tod_tbst.tb_sync_pulse_timer--; }else { tfmr |=TFMR_TB_SYNC_OCCURED ; - env->spr[SPR_TFMR ] = tfmr; +write_tfmr (env, tfmr); }if (env->pnv_tod_tbst.tb_state_timer) {@@ -262,7 +349,7 @@ static void tb_state_machine_step(CPUPPCState *env) } } - env->spr[SPR_TFMR ] = tfmr; +write_tfmr (env, tfmr); }target_ulong helper_load_tfmr (CPUPPCState *env)@@ -357,7 +444,7 @@ void helper_store_tfmr(CPUPPCState *env, target_ulong val) } out: - env->spr[SPR_TFMR ] = tfmr; +write_tfmr (env, tfmr); }#endif target/ppc/translate.c +40
-2@@ -247,13 +247,24 @@ static inline bool gen_serialize(DisasContext *ctx)return true; } -#if defined(TARGET_PPC64 ) && !defined(CONFIG_USER_ONLY ) +#if !defined(CONFIG_USER_ONLY ) +#if defined(TARGET_PPC64 ) +static inline bool gen_serialize_core (DisasContext *ctx) +{ +if (ctx->flags &POWERPC_FLAG_SMT ) { +return gen_serialize (ctx); + } +return true; +} +#endif +static inline bool gen_serialize_core_lpar (DisasContext *ctx) { +#if defined(TARGET_PPC64 )if (ctx->flags &POWERPC_FLAG_SMT_1LPAR ) {return gen_serialize (ctx); } - +#endif return true; }#endif @@ -667,12 +678,20 @@ void spr_read_atbu(DisasContext *ctx, int gprn, int sprn)#if !defined(CONFIG_USER_ONLY )void spr_write_tbl (DisasContext *ctx,int sprn,int gprn) { +if (!gen_serialize_core_lpar (ctx)) { +return ; + } +translator_io_start (&ctx->base);gen_helper_store_tbl (tcg_env, cpu_gpr[gprn]); }void spr_write_tbu (DisasContext *ctx,int sprn,int gprn) { +if (!gen_serialize_core_lpar (ctx)) { +return ; + } +translator_io_start (&ctx->base);gen_helper_store_tbu (tcg_env, cpu_gpr[gprn]); }@@ -696,6 +715,9 @@ void spr_read_purr(DisasContext *ctx, int gprn, int sprn)void spr_write_purr (DisasContext *ctx,int sprn,int gprn) { +if (!gen_serialize_core_lpar (ctx)) { +return ; + }translator_io_start (&ctx->base);gen_helper_store_purr (tcg_env, cpu_gpr[gprn]); }@@ -709,6 +731,9 @@ void spr_read_hdecr(DisasContext *ctx, int gprn, int sprn)void spr_write_hdecr (DisasContext *ctx,int sprn,int gprn) { +if (!gen_serialize_core_lpar (ctx)) { +return ; + }translator_io_start (&ctx->base);gen_helper_store_hdecr (tcg_env, cpu_gpr[gprn]); }@@ -721,12 +746,18 @@ void spr_read_vtb(DisasContext *ctx, int gprn, int sprn)void spr_write_vtb (DisasContext *ctx,int sprn,int gprn) { +if (!gen_serialize_core_lpar (ctx)) { +return ; + }translator_io_start (&ctx->base);gen_helper_store_vtb (tcg_env, cpu_gpr[gprn]); }void spr_write_tbu40 (DisasContext *ctx,int sprn,int gprn) { +if (!gen_serialize_core_lpar (ctx)) { +return ; + }translator_io_start (&ctx->base);gen_helper_store_tbu40 (tcg_env, cpu_gpr[gprn]); }@@ -1220,11 +1251,18 @@ void spr_write_hmer(DisasContext *ctx, int sprn, int gprn)void spr_read_tfmr (DisasContext *ctx,int gprn,int sprn) { +/* Reading TFMR can cause it to be updated, so serialize threads here too */ +if (!gen_serialize_core (ctx)) { +return ; + }gen_helper_load_tfmr (cpu_gpr[gprn], tcg_env); }void spr_write_tfmr (DisasContext *ctx,int sprn,int gprn) { +if (!gen_serialize_core (ctx)) { +return ; + }gen_helper_store_tfmr (tcg_env, cpu_gpr[gprn]); }