Xilinx Versal CFI support
v3 cover Xilinx Versal CFI support
Hi,
This series adds support for the Configuration Frame Unit (CFU) and the Configuration Frame controllers (CFRAME) to the Xilinx Versal machine ([1], chapter 21) for emulaing bitstream loading and readback.
The series starts by introducing the Xilinx CFI interface that is thereafter used by the Xilinx CFU components, the Xilinx CFRAME and Xilinx CFRAME broadcast models for transfering CFI packets between each other. Thereafter a model of the CFU_APB, CFU_FDRO and CFU_SFR are introduced and also models of the CFRAME controller and CFRAME broadcast controller.
The series thereafter ends with connecting the models to Xilinx Versal machine.
Best regards,
Francisco Iglesias
References:
[1] https://docs.xilinx.com/r/en-US/am011-versal-acap-trm/PSM-Local-Registers
Changelog:v2->v3:
[PATCH 5]
* Swap to store the CFrames in a GTree instead of GArray
* Rename new_f to new_f_data and also add it to the vmstate
* Removed unnecessary 'switch' braces in cframe_reg_cfi_transfer_packet
* Correct the reset of new_f_data and the cframes GTree
v1->v2:
[PATCH 2]
* Use KiB when defining KEYHOLE_STREAM_4K/KEYHOLE_STREAM_256K
* Updated to be able to share wfifo code
[PATCH 3]
* Swap to use Fifo32 instead of GArray in the CFU_FDRO model
* Add device reset to the CFU_FDRO model
[PATCH 4]
* Add device reset to the CFU_SFR model
[PATCH 5]
* Use KiB when defining KEYHOLE_STREAM_4K
* Add comma after CFRAME_CMD_DLPARK
* Remove backwards compatibility comment (and the 'cfu' alias propname for cfg.cfu_fdro)
* Use Fifo32 inside the XlnxCFrame structure
* Reworked cframes_reg_pre_save / cframes_reg_post_load
[PATCH 6]
* Add device reset to the CFrame broadcast reg model
[PATCH 8]
* Switch to use g_autofree instead of explicit g_free
Francisco Iglesias (8):
hw/misc: Introduce the Xilinx CFI interface
hw/misc: Introduce a model of Xilinx Versal's CFU_APB hw/misc/xlnx-versal-cfu: Introduce a model of Xilinx Versal CFU_FDRO hw/misc/xlnx-versal-cfu: Introduce a model of Xilinx Versal's CFU_SFR hw/misc: Introduce a model of Xilinx Versal's CFRAME_REG hw/misc: Introduce a model of Xilinx Versal's CFRAME_BCAST_REG hw/arm/xlnx-versal: Connect the CFU_APB, CFU_FDRO and CFU_SFR hw/arm/versal: Connect the CFRAME_REG and CFRAME_BCAST_REG
MAINTAINERS | 10 + hw/arm/xlnx-versal.c | 155 ++++- hw/misc/meson.build | 3 + hw/misc/xlnx-cfi-if.c | 34 + hw/misc/xlnx-versal-cframe-reg.c | 846 +++++++++++++++++++++++ hw/misc/xlnx-versal-cfu.c | 563 +++++++++++++++ include/hw/arm/xlnx-versal.h | 85 +++ include/hw/misc/xlnx-cfi-if.h | 59 ++ include/hw/misc/xlnx-versal-cframe-reg.h | 303 ++++++++ include/hw/misc/xlnx-versal-cfu.h | 258 +++++++ 10 files changed, 2315 insertions(+), 1 deletion(-) create mode 100644 hw/misc/xlnx-cfi-if.c create mode 100644 hw/misc/xlnx-versal-cframe-reg.c create mode 100644 hw/misc/xlnx-versal-cfu.c create mode 100644 include/hw/misc/xlnx-cfi-if.h create mode 100644 include/hw/misc/xlnx-versal-cframe-reg.h create mode 100644 include/hw/misc/xlnx-versal-cfu.h
Signature · 1 line
2.34.1
PATCH v3 1/8 hw/misc: Introduce the Xilinx CFI interface
Introduce the Xilinx Configuration Frame Interface (CFI) for transmitting CFI data packets between the Xilinx Configuration Frame Unit models (CFU_APB, CFU_FDRO and CFU_SFR), the Xilinx CFRAME controller (CFRAME_REG) and the Xilinx CFRAME broadcast controller (CFRAME_BCAST_REG) models (when emulating bitstream programming and readback).
--- MAINTAINERS | 6 ++++ hw/misc/meson.build | 1 + hw/misc/xlnx-cfi-if.c | 34 ++++++++++++++++++++ include/hw/misc/xlnx-cfi-if.h | 59 +++++++++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+) create mode 100644 hw/misc/xlnx-cfi-if.c create mode 100644 include/hw/misc/xlnx-cfi-if.h
MAINTAINERS +6 -0
@@ -1034,6 +1034,12 @@ S: Maintained F: hw/ssi/xlnx-versal-ospi.c F: include/hw/ssi/xlnx-versal-ospi.h +Xilinx Versal CFI +M: Francisco Iglesias <[email protected]> +S: Maintained +F: hw/misc/xlnx-cfi-if.c +F: include/hw/misc/xlnx-cfi-if.h + STM32F100 M: Alexandre Iooss <[email protected]> L: [email protected]
hw/misc/meson.build +1 -0
@@ -97,6 +97,7 @@ specific_ss.add(when: 'CONFIG_XLNX_VERSAL', if_true: files('xlnx-versal-crl.c')) system_ss.add(when: 'CONFIG_XLNX_VERSAL', if_true: files( 'xlnx-versal-xramc.c', 'xlnx-versal-pmc-iou-slcr.c', + 'xlnx-cfi-if.c', )) system_ss.add(when: 'CONFIG_STM32F2XX_SYSCFG', if_true: files('stm32f2xx_syscfg.c')) system_ss.add(when: 'CONFIG_STM32F4XX_SYSCFG', if_true: files('stm32f4xx_syscfg.c'))
hw/misc/xlnx-cfi-if.c new file +34 -0
@@ -0,0 +1,34 @@ +/* +* Xilinx CFI interface +* +* Copyright (C) 2023, Advanced Micro Devices, Inc. +* +* Written by Francisco Iglesias <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ +#include "qemu/osdep.h" +#include "hw/misc/xlnx-cfi-if.h" + +void xlnx_cfi_transfer_packet (XlnxCfiIf *cfi_if,XlnxCfiPacket *pkt) +{ +XlnxCfiIfClass *xcic =XLNX_CFI_IF_GET_CLASS (cfi_if); + +if (xcic->cfi_transfer_packet) { + xcic->cfi_transfer_packet (cfi_if, pkt); + } +} + +static const TypeInfo xlnx_cfi_if_info = { + .name =TYPE_XLNX_CFI_IF , + .parent =TYPE_INTERFACE , + .class_size =sizeof (XlnxCfiIfClass), +}; + +static void xlnx_cfi_if_register_types (void ) +{ +type_register_static (&xlnx_cfi_if_info); +} + +type_init (xlnx_cfi_if_register_types) +
include/hw/misc/xlnx-cfi-if.h new file +59 -0
59 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v3 2/8 hw/misc: Introduce a model of Xilinx Versal's CFU_APB
In reply to Francisco IglesiasIntroduce a model of the software programming interface (CFU_APB) of Xilinx Versal's Configuration Frame Unit.
--- MAINTAINERS | 2 + hw/misc/meson.build | 1 + hw/misc/xlnx-versal-cfu.c | 380 ++++++++++++++++++++++++++++++ include/hw/misc/xlnx-versal-cfu.h | 231 ++++++++++++++++++ 4 files changed, 614 insertions(+) create mode 100644 hw/misc/xlnx-versal-cfu.c create mode 100644 include/hw/misc/xlnx-versal-cfu.h
MAINTAINERS +2 -0
@@ -1039,6 +1039,8 @@ M: Francisco Iglesias <[email protected]> S: Maintained F: hw/misc/xlnx-cfi-if.c F: include/hw/misc/xlnx-cfi-if.h +F: hw/misc/xlnx-versal-cfu.c +F: include/hw/misc/xlnx-versal-cfu.h STM32F100 M: Alexandre Iooss <[email protected]>
hw/misc/meson.build +1 -0
@@ -97,6 +97,7 @@ specific_ss.add(when: 'CONFIG_XLNX_VERSAL', if_true: files('xlnx-versal-crl.c')) system_ss.add(when: 'CONFIG_XLNX_VERSAL', if_true: files( 'xlnx-versal-xramc.c', 'xlnx-versal-pmc-iou-slcr.c', + 'xlnx-versal-cfu.c', 'xlnx-cfi-if.c', )) system_ss.add(when: 'CONFIG_STM32F2XX_SYSCFG', if_true: files('stm32f2xx_syscfg.c'))
hw/misc/xlnx-versal-cfu.c new file +380 -0
380 lines not on this page · raw message
include/hw/misc/xlnx-versal-cfu.h new file +231 -0
231 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v3 3/8 hw/misc/xlnx-versal-cfu: Introduce a model of Xilinx Versal CFU_FDRO
In reply to Francisco IglesiasIntroduce a model of Xilinx Versal's Configuration Frame Unit's data out port (CFU_FDRO).
--- hw/misc/xlnx-versal-cfu.c | 96 +++++++++++++++++++++++++++++++ include/hw/misc/xlnx-versal-cfu.h | 12 ++++ 2 files changed, 108 insertions(+)
hw/misc/xlnx-versal-cfu.c +96 -0
@@ -264,6 +264,25 @@ static void cfu_stream_write(void *opaque, hwaddr addr, uint64_t value, } } +static uint64_t cfu_fdro_read (void *opaque,hwaddr addr,unsigned size) +{ +XlnxVersalCFUFDRO *s =XLNX_VERSAL_CFU_FDRO (opaque); +uint64_t ret =0 ; + +if (!fifo32_is_empty (&s->fdro_data)) { + ret =fifo32_pop (&s->fdro_data); + } + +return ret; +} + +static void cfu_fdro_write (void *opaque,hwaddr addr,uint64_t value, +unsigned size) +{ +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Unsupported write from addr=%" + HWADDR_PRIx"\n" , __func__, addr); +} +static const MemoryRegionOps cfu_stream_ops = { .read = cfu_stream_read, .write = cfu_stream_write,
@@ -274,6 +293,16 @@ static const MemoryRegionOps cfu_stream_ops = { }, }; +static const MemoryRegionOps cfu_fdro_ops = { + .read = cfu_fdro_read, + .write = cfu_fdro_write, + .endianness =DEVICE_LITTLE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 , + }, +}; +static void cfu_apb_init (Object *obj) {XlnxVersalCFUAPB *s =XLNX_VERSAL_CFU_APB (obj);
@@ -305,6 +334,39 @@ static void cfu_apb_init(Object *obj)sysbus_init_irq (sbd, &s->irq_cfu_imr); } +static void cfu_fdro_init (Object *obj) +{ +XlnxVersalCFUFDRO *s =XLNX_VERSAL_CFU_FDRO (obj); +SysBusDevice *sbd =SYS_BUS_DEVICE (obj); + +memory_region_init_io (&s->iomem_fdro, obj, &cfu_fdro_ops, s, +TYPE_XLNX_VERSAL_CFU_FDRO ,KEYHOLE_STREAM_4K ); +sysbus_init_mmio (sbd, &s->iomem_fdro); +fifo32_create (&s->fdro_data,8 * KiB /sizeof (uint32_t )); +} + +static void cfu_fdro_reset_enter (Object *obj,ResetType type) +{ +XlnxVersalCFUFDRO *s =XLNX_VERSAL_CFU_FDRO (obj); + +fifo32_reset (&s->fdro_data); +} + +static void cfu_fdro_cfi_transfer_packet (XlnxCfiIf *cfi_if,XlnxCfiPacket *pkt) +{ +XlnxVersalCFUFDRO *s =XLNX_VERSAL_CFU_FDRO (cfi_if); + +if (fifo32_num_free (&s->fdro_data) >=ARRAY_SIZE (pkt->data)) { +for (int i =0 ; i <ARRAY_SIZE (pkt->data); i++) { +fifo32_push (&s->fdro_data, pkt->data[i]); + } + }else { +/* It is a programming error to fill the fifo. */ +qemu_log_mask (LOG_GUEST_ERROR , +"CFU_FDRO: CFI data dropped due to full read fifo\n" ); + } +} +static Property cfu_props[] = {DEFINE_PROP_LINK ("cframe0" , XlnxVersalCFUAPB, cfg.cframe[0 ], TYPE_XLNX_CFI_IF, XlnxCfiIf *),
@@ -351,6 +413,16 @@ static const VMStateDescription vmstate_cfu_apb = { } }; +static const VMStateDescription vmstate_cfu_fdro = { + .name =TYPE_XLNX_VERSAL_CFU_FDRO , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_FIFO32 (fdro_data, XlnxVersalCFUFDRO), +VMSTATE_END_OF_LIST (), + } +}; +static void cfu_apb_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);
@@ -360,6 +432,17 @@ static void cfu_apb_class_init(ObjectClass *klass, void *data)device_class_set_props (dc, cfu_props); } +static void cfu_fdro_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +ResettableClass *rc =RESETTABLE_CLASS (klass); +XlnxCfiIfClass *xcic =XLNX_CFI_IF_CLASS (klass); + + dc->vmsd = &vmstate_cfu_fdro; + xcic->cfi_transfer_packet = cfu_fdro_cfi_transfer_packet; + rc->phases.enter = cfu_fdro_reset_enter; +} +static const TypeInfo cfu_apb_info = { .name =TYPE_XLNX_VERSAL_CFU_APB , .parent =TYPE_SYS_BUS_DEVICE ,
@@ -372,9 +455,22 @@ static const TypeInfo cfu_apb_info = { } }; +static const TypeInfo cfu_fdro_info = { + .name =TYPE_XLNX_VERSAL_CFU_FDRO , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (XlnxVersalCFUFDRO), + .class_init = cfu_fdro_class_init, + .instance_init = cfu_fdro_init, + .interfaces = (InterfaceInfo []) { + {TYPE_XLNX_CFI_IF }, + { } + } +}; +static void cfu_apb_register_types (void ) {type_register_static (&cfu_apb_info); +type_register_static (&cfu_fdro_info); }type_init (cfu_apb_register_types)
include/hw/misc/xlnx-versal-cfu.h +12 -0
@@ -20,10 +20,14 @@#include "hw/sysbus.h" #include "hw/register.h" #include "hw/misc/xlnx-cfi-if.h" +#include "qemu/fifo32.h" #define TYPE_XLNX_VERSAL_CFU_APB "xlnx,versal-cfu-apb" OBJECT_DECLARE_SIMPLE_TYPE(XlnxVersalCFUAPB, XLNX_VERSAL_CFU_APB) +#define TYPE_XLNX_VERSAL_CFU_FDRO "xlnx,versal-cfu-fdro" +OBJECT_DECLARE_SIMPLE_TYPE(XlnxVersalCFUFDRO, XLNX_VERSAL_CFU_FDRO) + REG32(CFU_ISR, 0x0) FIELD(CFU_ISR, USR_GTS_EVENT, 9, 1)FIELD (CFU_ISR ,USR_GSR_EVENT ,8 ,1 )
@@ -210,6 +214,14 @@ struct XlnxVersalCFUAPB { } cfg; }; + +struct XlnxVersalCFUFDRO { +SysBusDevice parent_obj; +MemoryRegion iomem_fdro; + +Fifo32 fdro_data; +}; +/** * This is a helper function for updating a CFI data write fifo, an array of 4 * uint32_t and 128 bits of data that are allowed to be written through 4
Signature · 1 line
2.34.1
PATCH v3 4/8 hw/misc/xlnx-versal-cfu: Introduce a model of Xilinx Versal's CFU_SFR
In reply to Francisco IglesiasIntroduce a model of Xilinx Versal's Configuration Frame Unit's Single Frame Read port (CFU_SFR).
--- hw/misc/xlnx-versal-cfu.c | 87 +++++++++++++++++++++++++++++++ include/hw/misc/xlnx-versal-cfu.h | 15 ++++++ 2 files changed, 102 insertions(+)
hw/misc/xlnx-versal-cfu.c +87 -0
@@ -264,6 +264,31 @@ static void cfu_stream_write(void *opaque, hwaddr addr, uint64_t value, } } +static uint64_t cfu_sfr_read (void *opaque,hwaddr addr,unsigned size) +{ +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Unsupported read from addr=%" + HWADDR_PRIx"\n" , __func__, addr); +return 0 ; +} + +static void cfu_sfr_write (void *opaque,hwaddr addr,uint64_t value, +unsigned size) +{ +XlnxVersalCFUSFR *s =XLNX_VERSAL_CFU_SFR (opaque); +uint32_t wfifo[WFIFO_SZ ]; + +if (update_wfifo (addr, value, s->wfifo, wfifo)) { +uint8_t row_addr =extract32 (wfifo[0 ],23 ,5 ); +uint32_t frame_addr =extract32 (wfifo[0 ],0 ,23 ); +XlnxCfiPacket pkt = { .reg_addr =CFRAME_SFR , + .data[0 ] = frame_addr }; + +if (s->cfg.cfu) { +cfu_transfer_cfi_packet (s->cfg.cfu, row_addr, &pkt); + } + } +} +static uint64_t cfu_fdro_read (void *opaque,hwaddr addr,unsigned size) {XlnxVersalCFUFDRO *s =XLNX_VERSAL_CFU_FDRO (opaque);
@@ -293,6 +318,16 @@ static const MemoryRegionOps cfu_stream_ops = { }, }; +static const MemoryRegionOps cfu_sfr_ops = { + .read = cfu_sfr_read, + .write = cfu_sfr_write, + .endianness =DEVICE_LITTLE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 , + }, +}; +static const MemoryRegionOps cfu_fdro_ops = { .read = cfu_fdro_read, .write = cfu_fdro_write,
@@ -334,6 +369,23 @@ static void cfu_apb_init(Object *obj)sysbus_init_irq (sbd, &s->irq_cfu_imr); } +static void cfu_sfr_init (Object *obj) +{ +XlnxVersalCFUSFR *s =XLNX_VERSAL_CFU_SFR (obj); +SysBusDevice *sbd =SYS_BUS_DEVICE (obj); + +memory_region_init_io (&s->iomem_sfr, obj, &cfu_sfr_ops, s, +TYPE_XLNX_VERSAL_CFU_SFR ,KEYHOLE_STREAM_4K ); +sysbus_init_mmio (sbd, &s->iomem_sfr); +} + +static void cfu_sfr_reset_enter (Object *obj,ResetType type) +{ +XlnxVersalCFUSFR *s =XLNX_VERSAL_CFU_SFR (obj); + +memset (s->wfifo,0 ,WFIFO_SZ *sizeof (uint32_t )); +} +static void cfu_fdro_init (Object *obj) {XlnxVersalCFUFDRO *s =XLNX_VERSAL_CFU_FDRO (obj);
@@ -401,6 +453,12 @@ static Property cfu_props[] = { DEFINE_PROP_END_OF_LIST(), }; +static Property cfu_sfr_props[] = { +DEFINE_PROP_LINK ("cfu" , XlnxVersalCFUSFR, cfg.cfu, + TYPE_XLNX_VERSAL_CFU_APB, XlnxVersalCFUAPB *), +DEFINE_PROP_END_OF_LIST (), +}; +static const VMStateDescription vmstate_cfu_apb = { .name =TYPE_XLNX_VERSAL_CFU_APB , .version_id =1 ,
@@ -423,6 +481,16 @@ static const VMStateDescription vmstate_cfu_fdro = { } }; +static const VMStateDescription vmstate_cfu_sfr = { + .name =TYPE_XLNX_VERSAL_CFU_SFR , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT32_ARRAY (wfifo, XlnxVersalCFUSFR,4 ), +VMSTATE_END_OF_LIST (), + } +}; +static void cfu_apb_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);
@@ -443,6 +511,16 @@ static void cfu_fdro_class_init(ObjectClass *klass, void *data) rc->phases.enter = cfu_fdro_reset_enter; } +static void cfu_sfr_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +ResettableClass *rc =RESETTABLE_CLASS (klass); + +device_class_set_props (dc, cfu_sfr_props); + dc->vmsd = &vmstate_cfu_sfr; + rc->phases.enter = cfu_sfr_reset_enter; +} +static const TypeInfo cfu_apb_info = { .name =TYPE_XLNX_VERSAL_CFU_APB , .parent =TYPE_SYS_BUS_DEVICE ,
@@ -467,10 +545,19 @@ static const TypeInfo cfu_fdro_info = { } }; +static const TypeInfo cfu_sfr_info = { + .name =TYPE_XLNX_VERSAL_CFU_SFR , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (XlnxVersalCFUSFR), + .class_init = cfu_sfr_class_init, + .instance_init = cfu_sfr_init, +}; +static void cfu_apb_register_types (void ) {type_register_static (&cfu_apb_info);type_register_static (&cfu_fdro_info); +type_register_static (&cfu_sfr_info); }type_init (cfu_apb_register_types)
include/hw/misc/xlnx-versal-cfu.h +15 -0
@@ -28,6 +28,9 @@ OBJECT_DECLARE_SIMPLE_TYPE(XlnxVersalCFUAPB, XLNX_VERSAL_CFU_APB)#define TYPE_XLNX_VERSAL_CFU_FDRO "xlnx,versal-cfu-fdro" OBJECT_DECLARE_SIMPLE_TYPE(XlnxVersalCFUFDRO, XLNX_VERSAL_CFU_FDRO) +#define TYPE_XLNX_VERSAL_CFU_SFR "xlnx,versal-cfu-sfr" +OBJECT_DECLARE_SIMPLE_TYPE(XlnxVersalCFUSFR, XLNX_VERSAL_CFU_SFR) + REG32(CFU_ISR, 0x0) FIELD(CFU_ISR, USR_GTS_EVENT, 9, 1)FIELD (CFU_ISR ,USR_GSR_EVENT ,8 ,1 )
@@ -222,6 +225,18 @@ struct XlnxVersalCFUFDRO {Fifo32 fdro_data; }; +struct XlnxVersalCFUSFR { +SysBusDevice parent_obj; +MemoryRegion iomem_sfr; + +/* 128-bit wfifo. */ +uint32_t wfifo[WFIFO_SZ ]; + +struct { +XlnxVersalCFUAPB *cfu; + } cfg; +}; +/** * This is a helper function for updating a CFI data write fifo, an array of 4 * uint32_t and 128 bits of data that are allowed to be written through 4
Signature · 1 line
2.34.1
PATCH v3 5/8 hw/misc: Introduce a model of Xilinx Versal's CFRAME_REG
In reply to Francisco IglesiasIntroduce a model of Xilinx Versal's Configuration Frame controller (CFRAME_REG).
--- MAINTAINERS | 2 + hw/misc/meson.build | 1 + hw/misc/xlnx-versal-cframe-reg.c | 685 +++++++++++++++++++++++ include/hw/misc/xlnx-versal-cframe-reg.h | 286 ++++++++++ 4 files changed, 974 insertions(+) create mode 100644 hw/misc/xlnx-versal-cframe-reg.c create mode 100644 include/hw/misc/xlnx-versal-cframe-reg.h
MAINTAINERS +2 -0
@@ -1041,6 +1041,8 @@ F: hw/misc/xlnx-cfi-if.c F: include/hw/misc/xlnx-cfi-if.h F: hw/misc/xlnx-versal-cfu.c F: include/hw/misc/xlnx-versal-cfu.h +F: hw/misc/xlnx-versal-cframe-reg.c +F: include/hw/misc/xlnx-versal-cframe-reg.h STM32F100 M: Alexandre Iooss <[email protected]>
hw/misc/meson.build +1 -0
@@ -99,6 +99,7 @@ system_ss.add(when: 'CONFIG_XLNX_VERSAL', if_true: files( 'xlnx-versal-pmc-iou-slcr.c', 'xlnx-versal-cfu.c', 'xlnx-cfi-if.c', + 'xlnx-versal-cframe-reg.c', )) system_ss.add(when: 'CONFIG_STM32F2XX_SYSCFG', if_true: files('stm32f2xx_syscfg.c')) system_ss.add(when: 'CONFIG_STM32F4XX_SYSCFG', if_true: files('stm32f4xx_syscfg.c'))
hw/misc/xlnx-versal-cframe-reg.c new file +685 -0
685 lines not on this page · raw message
include/hw/misc/xlnx-versal-cframe-reg.h new file +286 -0
286 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v3 5/8] hw/misc: Introduce a model of Xilinx Versal's CFRAME_REG
Quoted 14 lines · Francisco Iglesias
Introduce a model of Xilinx Versal's Configuration Frame controller (
CFRAME_REG).Signed-off-by Francisco Iglesias <[email protected]>hw/misc/xlnx-versal-cframe-reg.c new file +8
-0+static void cfrm_fdri_post_write (RegisterInfo *reg,uint64_t val) +{ +XlnxVersalCFrameReg *s =XLNX_VERSAL_CFRAME_REG (reg->opaque); + +if (s->row_configured && s->rowon && s->wcfg) { + +if (fifo32_num_free (&s->new_f_data) >=N_WORDS_128BIT ) { +fifo32_push (&s->new_f_data, s->regs[R_FDRI0 ]);
hw/misc/xlnx-versal-cframe-reg.c line 129
Quoted 10 lines
hw/misc/xlnx-versal-cframe-reg.c new file +10
-0+fifo32_push (&s->new_f_data, s->regs[R_FDRI1 ]); +fifo32_push (&s->new_f_data, s->regs[R_FDRI2 ]); +fifo32_push (&s->new_f_data, s->regs[R_FDRI3 ]); + } + +if (fifo32_is_full (&s->new_f_data)) { +uint32_t addr =extract32 (s->regs[R_FAR0 ],0 ,23 ); +XlnxCFrame *f =g_new (XlnxCFrame,1 ); + +memcpy (f->data, s->new_f_data.fifo.data,sizeof (f->data));
This works, but it's going under the hood of the Fifo32 abstraction and makes the assumptions that (a) if you only push to the fifo and never pop then the data is going to be contiguous from the start of the fifo internal buffer and (b) that fifo32_push() pushes the bytes of the 32 bit value in little endian order. Those are both true at the moment, but fifo32 doesn't explicitly guarantee either of them...
Quoted 5 lines
hw/misc/xlnx-versal-cframe-reg.c new file +5
-0+ +g_tree_replace (s->cframes,GUINT_TO_POINTER (addr), f); + +cframe_incr_far (s); +
hw/misc/xlnx-versal-cframe-reg.c line 144
Quoted 10 lines
hw/misc/xlnx-versal-cframe-reg.c new file +10
-0+fifo32_reset (&s->new_f_data); + } + } +} + +static void cfrm_readout_frames (XlnxVersalCFrameReg *s,uint32_t start_addr, +uint32_t end_addr) +{ +for (uint32_t addr = start_addr; addr < end_addr; addr++) { +XlnxCFrame *f =g_tree_lookup (s->cframes,GUINT_TO_POINTER (addr));
You don't need to g_tree_lookup() for every address. If you use g_tree_lookup_node() you get a GTreeNode* back, and you can then iterate through the tree from that point using g_tree_node_next(), something like this:
for (node = g_tree_lookup_node(s->cframes, GUINT_TO_POINTER(addr));
node && GPOINTER_TO_UINT(g_tree_node_key(node)) < end_addr;
node = g_tree_node_next(node)) {
XlnxCFrame *f = g_tree_node_value(node); // definitely not NULL
/* Transmit the data */
for (int i = 0; i < FRAME_NUM_WORDS; i += 4) {
... etc ...
}
}Quoted 22 lines
hw/misc/xlnx-versal-cframe-reg.c new file +20
-0+ +/* Transmit the data if a frame was found */ +if (f) { +for (int i =0 ; i <FRAME_NUM_WORDS ; i +=4 ) { +XlnxCfiPacket pkt = {}; + + pkt.data[0 ] = f->data[i]; + pkt.data[1 ] = f->data[i +1 ]; + pkt.data[2 ] = f->data[i +2 ]; + pkt.data[3 ] = f->data[i +3 ]; + +if (s->cfg.cfu_fdro) { +xlnx_cfi_transfer_packet (s->cfg.cfu_fdro, &pkt); + } + } + } + } +} +static void cframe_reg_reset_enter (Object *obj,ResetType type) +{
hw/misc/xlnx-versal-cframe-reg.c
Quoted 10 lines
hw/misc/xlnx-versal-cframe-reg.c new file +10
-0+XlnxVersalCFrameReg *s =XLNX_VERSAL_CFRAME_REG (obj); +unsigned int i; + +for (i =0 ; i <ARRAY_SIZE (s->regs_info); ++i) { +register_reset (&s->regs_info[i]); + } +memset (s->wfifo,0 ,WFIFO_SZ *sizeof (uint32_t )); +fifo32_reset (&s->new_f_data); + +if (g_tree_height (s->cframes)) {
Calculating g_tree_height() requires walking the tree. Using g_tree_nnodes() is faster because that's just a field in the GTree struct.
hw/misc/xlnx-versal-cframe-reg.c line 529
Quoted 3 lines
hw/misc/xlnx-versal-cframe-reg.c new file +3
-0+g_tree_destroy (s->cframes); + s->cframes =g_tree_new_full ((GCompareDataFunc )int_cmp,NULL , +NULL , (GDestroyNotify ) g_free);
Faster to do
/*
* Take a reference so when g_tree_destroy() unrefs it we keep the
* GTree and only destroy its contents. NB: when our minimum
* glib version is at least 2.70 we could use g_tree_remove_all().
*/
g_tree_ref(s->cframes);
g_tree_destroy(s->cframes);Quoted 21 lines
hw/misc/xlnx-versal-cframe-reg.c new file +20
-0+ } +} + +static void cframe_reg_init (Object *obj) +{ +XlnxVersalCFrameReg *s =XLNX_VERSAL_CFRAME_REG (obj); +SysBusDevice *sbd =SYS_BUS_DEVICE (obj); +RegisterInfoArray *reg_array; + +memory_region_init (&s->iomem, obj,TYPE_XLNX_VERSAL_CFRAME_REG , +CFRAME_REG_R_MAX *4 ); + reg_array = +register_init_block32 (DEVICE (obj), cframe_reg_regs_info, +ARRAY_SIZE (cframe_reg_regs_info), + s->regs_info, s->regs, + &cframe_reg_ops, +XLNX_VERSAL_CFRAME_REG_ERR_DEBUG , +CFRAME_REG_R_MAX *4 ); + memory_region_add_subregion(&s->iomem, + 0x0,
hw/misc/xlnx-versal-cframe-reg.c line 603
Quoted 10 lines
hw/misc/xlnx-versal-cframe-reg.c new file +10
-0+ ®_array->mem); +sysbus_init_mmio (sbd, &s->iomem); +memory_region_init_io (&s->iomem_fdri, obj, &cframe_reg_fdri_ops, s, +TYPE_XLNX_VERSAL_CFRAME_REG "-fdri" , +KEYHOLE_STREAM_4K ); +sysbus_init_mmio (sbd, &s->iomem_fdri); +sysbus_init_irq (sbd, &s->irq_cfrm_imr); + + s->cframes =g_tree_new_full ((GCompareDataFunc )int_cmp,NULL , +NULL , (GDestroyNotify ) g_free);
Stray space before 'g_free'.
hw/misc/xlnx-versal-cframe-reg.c line 605
Quoted 2 lines
hw/misc/xlnx-versal-cframe-reg.c new file +2
-0+fifo32_create (&s->new_f_data,FRAME_NUM_WORDS ); +}
thanks
-- PMM
Re: [PATCH v3 5/8] hw/misc: Introduce a model of Xilinx Versal's CFRAME_REG
Hi Peter,
Quoted 27 lines · Peter Maydell
Quoted 14 lines · Francisco Iglesias
Introduce a model of Xilinx Versal's Configuration Frame controller (
CFRAME_REG).Signed-off-by Francisco Iglesias <[email protected]>hw/misc/xlnx-versal-cframe-reg.c new file +8
-0+static void cfrm_fdri_post_write (RegisterInfo *reg,uint64_t val) +{ +XlnxVersalCFrameReg *s =XLNX_VERSAL_CFRAME_REG (reg->opaque); + +if (s->row_configured && s->rowon && s->wcfg) { + +if (fifo32_num_free (&s->new_f_data) >=N_WORDS_128BIT ) { +fifo32_push (&s->new_f_data, s->regs[R_FDRI0 ]);hw/misc/xlnx-versal-cframe-reg.c line 129
Quoted 10 lines
hw/misc/xlnx-versal-cframe-reg.c new file +10
-0+fifo32_push (&s->new_f_data, s->regs[R_FDRI1 ]); +fifo32_push (&s->new_f_data, s->regs[R_FDRI2 ]); +fifo32_push (&s->new_f_data, s->regs[R_FDRI3 ]); + } + +if (fifo32_is_full (&s->new_f_data)) { +uint32_t addr =extract32 (s->regs[R_FAR0 ],0 ,23 ); +XlnxCFrame *f =g_new (XlnxCFrame,1 ); + +memcpy (f->data, s->new_f_data.fifo.data,sizeof (f->data));
Quoted 8 lines
This works, but it's going under the hood of the Fifo32 abstraction and makes the assumptions that (a) if you only push to the fifo and never pop then the data is going to be contiguous from the start of the fifo internal buffer and (b) that
fifo32_push()pushes the bytes of the 32 bit value in little endian order. Those are both true at the moment, but fifo32 doesn't explicitly guarantee either of them...
Undestood, to be safe I changed to pop the values from the fifo instead of using memcpy.
Quoted 21 lines
Quoted 5 lines
hw/misc/xlnx-versal-cframe-reg.c new file +5
-0+ +g_tree_replace (s->cframes,GUINT_TO_POINTER (addr), f); + +cframe_incr_far (s); +hw/misc/xlnx-versal-cframe-reg.c line 144
Quoted 10 lines
hw/misc/xlnx-versal-cframe-reg.c new file +10
-0+fifo32_reset (&s->new_f_data); + } + } +} + +static void cfrm_readout_frames (XlnxVersalCFrameReg *s,uint32_t start_addr, +uint32_t end_addr) +{ +for (uint32_t addr = start_addr; addr < end_addr; addr++) { +XlnxCFrame *f =g_tree_lookup (s->cframes,GUINT_TO_POINTER (addr));You don't need to
g_tree_lookup()for every address. If you useg_tree_lookup_node()you get a GTreeNode* back, and you can then iterate through the tree from that point usingg_tree_node_next(), something like this:
Quoted 10 lines
for (node = g_tree_lookup_node(s->cframes, GUINT_TO_POINTER(addr));
node && GPOINTER_TO_UINT(g_tree_node_key(node)) < end_addr;
node = g_tree_node_next(node)) {
XlnxCFrame *f = g_tree_node_value(node); // definitely not NULL
/* Transmit the data */
for (int i = 0; i < FRAME_NUM_WORDS; i += 4) {
... etc ...
}
}I tried above but it looks to require glib 2.68 so added a comment instead (didn't compile on my machine with glib-2.64 :/, if I understand meson.build correctly the min glib version supported is 2.56). Let me know if some other solution would be preferred.
/*
* NB: when our minimum glib version is at least 2.68 we can improve the
* performance of the cframe traversal by using g_tree_lookup_node and
* g_tree_node_next (instead of calling g_tree_lookup for finding each
* cframe).
*/
I also added in the other improvements and correction below!
Thank you for the help again!
Best regards,
Francisco
Quoted 22 lines
Quoted 20 lines
hw/misc/xlnx-versal-cframe-reg.c new file +18
-0+ +/* Transmit the data if a frame was found */ +if (f) { +for (int i =0 ; i <FRAME_NUM_WORDS ; i +=4 ) { +XlnxCfiPacket pkt = {}; + + pkt.data[0 ] = f->data[i]; + pkt.data[1 ] = f->data[i +1 ]; + pkt.data[2 ] = f->data[i +2 ]; + pkt.data[3 ] = f->data[i +3 ]; + +if (s->cfg.cfu_fdro) { +xlnx_cfi_transfer_packet (s->cfg.cfu_fdro, &pkt); + } + } + } + } +}
Quoted 5 lines
hw/misc/xlnx-versal-cframe-reg.c line 519
Quoted 5 lines
hw/misc/xlnx-versal-cframe-reg.c new file +5
-0+static void cframe_reg_reset_enter (Object *obj,ResetType type) +{ +XlnxVersalCFrameReg *s =XLNX_VERSAL_CFRAME_REG (obj); +unsigned int i; +
j>> + for (i = 0; i < ARRAY_SIZE(s->regs_info); ++i) {
Quoted 63 lines
hw/misc/xlnx-versal-cframe-reg.c line 526
Quoted 6 lines
hw/misc/xlnx-versal-cframe-reg.c new file +6
-0+register_reset (&s->regs_info[i]); + } +memset (s->wfifo,0 ,WFIFO_SZ *sizeof (uint32_t )); +fifo32_reset (&s->new_f_data); + +if (g_tree_height (s->cframes)) {Calculating
g_tree_height()requires walking the tree. Usingg_tree_nnodes()is faster because that's just a field in the GTree struct.hw/misc/xlnx-versal-cframe-reg.c line 529
Quoted 3 lines
hw/misc/xlnx-versal-cframe-reg.c new file +3
-0+g_tree_destroy (s->cframes); + s->cframes =g_tree_new_full ((GCompareDataFunc )int_cmp,NULL , +NULL , (GDestroyNotify ) g_free);Faster to do
/* * Take a reference so when g_tree_destroy() unrefs it we keep the * GTree and only destroy its contents. NB: when our minimum * glib version is at least 2.70 we could use g_tree_remove_all(). */ g_tree_ref(s->cframes); g_tree_destroy(s->cframes);Quoted 21 lines
hw/misc/xlnx-versal-cframe-reg.c new file +20
-0+ } +} + +static void cframe_reg_init (Object *obj) +{ +XlnxVersalCFrameReg *s =XLNX_VERSAL_CFRAME_REG (obj); +SysBusDevice *sbd =SYS_BUS_DEVICE (obj); +RegisterInfoArray *reg_array; + +memory_region_init (&s->iomem, obj,TYPE_XLNX_VERSAL_CFRAME_REG , +CFRAME_REG_R_MAX *4 ); + reg_array = +register_init_block32 (DEVICE (obj), cframe_reg_regs_info, +ARRAY_SIZE (cframe_reg_regs_info), + s->regs_info, s->regs, + &cframe_reg_ops, +XLNX_VERSAL_CFRAME_REG_ERR_DEBUG , +CFRAME_REG_R_MAX *4 ); + memory_region_add_subregion(&s->iomem, + 0x0,hw/misc/xlnx-versal-cframe-reg.c line 603
Quoted 10 lines
hw/misc/xlnx-versal-cframe-reg.c new file +10
-0+ ®_array->mem); +sysbus_init_mmio (sbd, &s->iomem); +memory_region_init_io (&s->iomem_fdri, obj, &cframe_reg_fdri_ops, s, +TYPE_XLNX_VERSAL_CFRAME_REG "-fdri" , +KEYHOLE_STREAM_4K ); +sysbus_init_mmio (sbd, &s->iomem_fdri); +sysbus_init_irq (sbd, &s->irq_cfrm_imr); + + s->cframes =g_tree_new_full ((GCompareDataFunc )int_cmp,NULL , +NULL , (GDestroyNotify ) g_free);Stray space before '
g_free'.hw/misc/xlnx-versal-cframe-reg.c line 605
Quoted 2 lines
hw/misc/xlnx-versal-cframe-reg.c new file +2
-0+fifo32_create (&s->new_f_data,FRAME_NUM_WORDS ); +}thanks
-- PMM
Re: [PATCH v3 5/8] hw/misc: Introduce a model of Xilinx Versal's CFRAME_REG
Quoted 20 lines · Francisco Iglesias
Hi Peter,
Quoted 5 lines · Peter Maydell
You don't need to
g_tree_lookup()for every address. If you useg_tree_lookup_node()you get a GTreeNode* back, and you can then iterate through the tree from that point usingg_tree_node_next(), something like this:Quoted 10 lines
for (node = g_tree_lookup_node(s->cframes, GUINT_TO_POINTER(addr)); node && GPOINTER_TO_UINT(g_tree_node_key(node)) < end_addr; node = g_tree_node_next(node)) { XlnxCFrame *f = g_tree_node_value(node); // definitely not NULL /* Transmit the data */ for (int i = 0; i < FRAME_NUM_WORDS; i += 4) { ... etc ... } }
Quoted 4 lines
I tried above but it looks to require glib 2.68 so added a comment instead (didn't compile on my machine with glib-2.64 :/, if I understand meson.build correctly the min glib version supported is 2.56). Let me know if some other solution would be preferred.
Whoops, yes, I didn't notice the version-statement on g_tree_lookup_node(). Yeah, keep what you have.
thanks
-- PMM
PATCH v3 6/8 hw/misc: Introduce a model of Xilinx Versal's CFRAME_BCAST_REG
In reply to Francisco IglesiasIntroduce a model of Xilinx Versal's Configuration Frame broadcast controller (CFRAME_BCAST_REG).
--- hw/misc/xlnx-versal-cframe-reg.c | 161 +++++++++++++++++++++++ include/hw/misc/xlnx-versal-cframe-reg.h | 17 +++ 2 files changed, 178 insertions(+)
hw/misc/xlnx-versal-cframe-reg.c +161 -0
@@ -557,6 +557,83 @@ static const MemoryRegionOps cframe_reg_fdri_ops = { }, }; +static uint64_t cframes_bcast_reg_read (void *opaque,hwaddr addr,unsigned size) +{ +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Unsupported read from addr=%" + HWADDR_PRIx"\n" , __func__, addr); +return 0 ; +} + +static void cframes_bcast_write (XlnxVersalCFrameBcastReg *s,uint8_t reg_addr, +uint32_t *wfifo) +{ +XlnxCfiPacket pkt = { + .reg_addr = reg_addr, + .data[0 ] = wfifo[0 ], + .data[1 ] = wfifo[1 ], + .data[2 ] = wfifo[2 ], + .data[3 ] = wfifo[3 ] + }; + +for (int i =0 ; i <ARRAY_SIZE (s->cfg.cframe); i++) { +if (s->cfg.cframe[i]) { +xlnx_cfi_transfer_packet (s->cfg.cframe[i], &pkt); + } + } +} + +static void cframes_bcast_reg_write (void *opaque,hwaddr addr,uint64_t value, +unsigned size) +{ +XlnxVersalCFrameBcastReg *s =XLNX_VERSAL_CFRAME_BCAST_REG (opaque); +uint32_t wfifo[WFIFO_SZ ]; + +if (update_wfifo (addr, value, s->wfifo, wfifo)) { +uint8_t reg_addr =extract32 (addr,4 ,6 ); + +cframes_bcast_write (s, reg_addr, wfifo); + } +} + +static uint64_t cframes_bcast_fdri_read (void *opaque,hwaddr addr, +unsigned size) +{ +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Unsupported read from addr=%" + HWADDR_PRIx"\n" , __func__, addr); +return 0 ; +} + +static void cframes_bcast_fdri_write (void *opaque,hwaddr addr,uint64_t value, +unsigned size) +{ +XlnxVersalCFrameBcastReg *s =XLNX_VERSAL_CFRAME_BCAST_REG (opaque); +uint32_t wfifo[WFIFO_SZ ]; + +if (update_wfifo (addr, value, s->wfifo, wfifo)) { +cframes_bcast_write (s,CFRAME_FDRI , wfifo); + } +} + +static const MemoryRegionOps cframes_bcast_reg_reg_ops = { + .read = cframes_bcast_reg_read, + .write = cframes_bcast_reg_write, + .endianness =DEVICE_LITTLE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 , + }, +}; + +static const MemoryRegionOps cframes_bcast_reg_fdri_ops = { + .read = cframes_bcast_fdri_read, + .write = cframes_bcast_fdri_write, + .endianness =DEVICE_LITTLE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 , + }, +}; +static void cframe_reg_realize (DeviceState *dev,Error **errp) {XlnxVersalCFrameReg *s =XLNX_VERSAL_CFRAME_REG (dev);
@@ -651,6 +728,71 @@ static Property cframe_regs_props[] = { DEFINE_PROP_END_OF_LIST(), }; +static void cframe_bcast_reg_init (Object *obj) +{ +XlnxVersalCFrameBcastReg *s =XLNX_VERSAL_CFRAME_BCAST_REG (obj); +SysBusDevice *sbd =SYS_BUS_DEVICE (obj); + +memory_region_init_io (&s->iomem_reg, obj, &cframes_bcast_reg_reg_ops, s, +TYPE_XLNX_VERSAL_CFRAME_BCAST_REG ,KEYHOLE_STREAM_4K ); +memory_region_init_io (&s->iomem_fdri, obj, &cframes_bcast_reg_fdri_ops, s, +TYPE_XLNX_VERSAL_CFRAME_BCAST_REG "-fdri" , +KEYHOLE_STREAM_4K ); +sysbus_init_mmio (sbd, &s->iomem_reg); +sysbus_init_mmio (sbd, &s->iomem_fdri); +} + +static void cframe_bcast_reg_reset_enter (Object *obj,ResetType type) +{ +XlnxVersalCFrameBcastReg *s =XLNX_VERSAL_CFRAME_BCAST_REG (obj); + +memset (s->wfifo,0 ,WFIFO_SZ *sizeof (uint32_t )); +} + +static const VMStateDescription vmstate_cframe_bcast_reg = { + .name =TYPE_XLNX_VERSAL_CFRAME_BCAST_REG , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT32_ARRAY (wfifo, XlnxVersalCFrameBcastReg,4 ), +VMSTATE_END_OF_LIST (), + } +}; + +static Property cframe_bcast_regs_props[] = { +DEFINE_PROP_LINK ("cframe0" , XlnxVersalCFrameBcastReg, cfg.cframe[0 ], + TYPE_XLNX_CFI_IF, XlnxCfiIf *), +DEFINE_PROP_LINK ("cframe1" , XlnxVersalCFrameBcastReg, cfg.cframe[1 ], + TYPE_XLNX_CFI_IF, XlnxCfiIf *), +DEFINE_PROP_LINK ("cframe2" , XlnxVersalCFrameBcastReg, cfg.cframe[2 ], + TYPE_XLNX_CFI_IF, XlnxCfiIf *), +DEFINE_PROP_LINK ("cframe3" , XlnxVersalCFrameBcastReg, cfg.cframe[3 ], + TYPE_XLNX_CFI_IF, XlnxCfiIf *), +DEFINE_PROP_LINK ("cframe4" , XlnxVersalCFrameBcastReg, cfg.cframe[4 ], + TYPE_XLNX_CFI_IF, XlnxCfiIf *), +DEFINE_PROP_LINK ("cframe5" , XlnxVersalCFrameBcastReg, cfg.cframe[5 ], + TYPE_XLNX_CFI_IF, XlnxCfiIf *), +DEFINE_PROP_LINK ("cframe6" , XlnxVersalCFrameBcastReg, cfg.cframe[6 ], + TYPE_XLNX_CFI_IF, XlnxCfiIf *), +DEFINE_PROP_LINK ("cframe7" , XlnxVersalCFrameBcastReg, cfg.cframe[7 ], + TYPE_XLNX_CFI_IF, XlnxCfiIf *), +DEFINE_PROP_LINK ("cframe8" , XlnxVersalCFrameBcastReg, cfg.cframe[8 ], + TYPE_XLNX_CFI_IF, XlnxCfiIf *), +DEFINE_PROP_LINK ("cframe9" , XlnxVersalCFrameBcastReg, cfg.cframe[9 ], + TYPE_XLNX_CFI_IF, XlnxCfiIf *), +DEFINE_PROP_LINK ("cframe10" , XlnxVersalCFrameBcastReg, cfg.cframe[10 ], + TYPE_XLNX_CFI_IF, XlnxCfiIf *), +DEFINE_PROP_LINK ("cframe11" , XlnxVersalCFrameBcastReg, cfg.cframe[11 ], + TYPE_XLNX_CFI_IF, XlnxCfiIf *), +DEFINE_PROP_LINK ("cframe12" , XlnxVersalCFrameBcastReg, cfg.cframe[12 ], + TYPE_XLNX_CFI_IF, XlnxCfiIf *), +DEFINE_PROP_LINK ("cframe13" , XlnxVersalCFrameBcastReg, cfg.cframe[13 ], + TYPE_XLNX_CFI_IF, XlnxCfiIf *), +DEFINE_PROP_LINK ("cframe14" , XlnxVersalCFrameBcastReg, cfg.cframe[14 ], + TYPE_XLNX_CFI_IF, XlnxCfiIf *), +DEFINE_PROP_END_OF_LIST (), +}; +static void cframe_reg_class_init (ObjectClass *klass,void *data) {ResettableClass *rc =RESETTABLE_CLASS (klass);
@@ -665,6 +807,16 @@ static void cframe_reg_class_init(ObjectClass *klass, void *data) xcic->cfi_transfer_packet = cframe_reg_cfi_transfer_packet; } +static void cframe_bcast_reg_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +ResettableClass *rc =RESETTABLE_CLASS (klass); + + dc->vmsd = &vmstate_cframe_bcast_reg; +device_class_set_props (dc, cframe_bcast_regs_props); + rc->phases.enter = cframe_bcast_reg_reset_enter; +} +static const TypeInfo cframe_reg_info = { .name =TYPE_XLNX_VERSAL_CFRAME_REG , .parent =TYPE_SYS_BUS_DEVICE ,
@@ -677,9 +829,18 @@ static const TypeInfo cframe_reg_info = { } }; +static const TypeInfo cframe_bcast_reg_info = { + .name =TYPE_XLNX_VERSAL_CFRAME_BCAST_REG , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (XlnxVersalCFrameBcastReg), + .class_init = cframe_bcast_reg_class_init, + .instance_init = cframe_bcast_reg_init, +}; +static void cframe_reg_register_types (void ) {type_register_static (&cframe_reg_info); +type_register_static (&cframe_bcast_reg_info); }type_init (cframe_reg_register_types)
include/hw/misc/xlnx-versal-cframe-reg.h +17 -0
@@ -26,6 +26,10 @@#define TYPE_XLNX_VERSAL_CFRAME_REG "xlnx,cframe-reg" OBJECT_DECLARE_SIMPLE_TYPE(XlnxVersalCFrameReg, XLNX_VERSAL_CFRAME_REG) +#define TYPE_XLNX_VERSAL_CFRAME_BCAST_REG "xlnx.cframe-bcast-reg" +OBJECT_DECLARE_SIMPLE_TYPE (XlnxVersalCFrameBcastReg, +XLNX_VERSAL_CFRAME_BCAST_REG ) +/* * The registers in this module are 128 bits wide but it is ok to write * and read them through 4 sequential 32 bit accesses (address[3:2] = 0,
@@ -283,4 +287,17 @@ struct XlnxVersalCFrameReg { bool row_configured; }; +struct XlnxVersalCFrameBcastReg { +SysBusDevice parent_obj; +MemoryRegion iomem_reg; +MemoryRegion iomem_fdri; + +/* 128-bit wfifo. */ +uint32_t wfifo[WFIFO_SZ ]; + +struct { +XlnxCfiIf *cframe[15 ]; + } cfg; +}; +#endif
Signature · 1 line
2.34.1
PATCH v3 7/8 hw/arm/xlnx-versal: Connect the CFU_APB, CFU_FDRO and CFU_SFR
In reply to Francisco IglesiasConnect the Configuration Frame Unit (CFU_APB, CFU_FDRO and CFU_SFR) to the Versal machine.
--- hw/arm/xlnx-versal.c | 42 ++++++++++++++++++++++++++++++++++++ include/hw/arm/xlnx-versal.h | 16 ++++++++++++++ 2 files changed, 58 insertions(+)
hw/arm/xlnx-versal.c +42 -0
@@ -570,6 +570,47 @@ static void versal_create_ospi(Versal *s, qemu_irq *pic)qdev_connect_gpio_out (orgate,0 , pic[VERSAL_OSPI_IRQ ]); } +static void versal_create_cfu (Versal *s,qemu_irq *pic) +{ +SysBusDevice *sbd; + +/* CFU FDRO */ +object_initialize_child (OBJECT (s),"cfu-fdro" , &s->pmc.cfu_fdro, +TYPE_XLNX_VERSAL_CFU_FDRO ); + sbd =SYS_BUS_DEVICE (&s->pmc.cfu_fdro); + +sysbus_realize (sbd, &error_fatal); +memory_region_add_subregion (&s->mr_ps,MM_PMC_CFU_FDRO , +sysbus_mmio_get_region (sbd,0 )); + +/* CFU APB */ +object_initialize_child (OBJECT (s),"cfu-apb" , &s->pmc.cfu_apb, +TYPE_XLNX_VERSAL_CFU_APB ); + sbd =SYS_BUS_DEVICE (&s->pmc.cfu_apb); + +sysbus_realize (sbd, &error_fatal); +memory_region_add_subregion (&s->mr_ps,MM_PMC_CFU_APB , +sysbus_mmio_get_region (sbd,0 )); +memory_region_add_subregion (&s->mr_ps,MM_PMC_CFU_STREAM , +sysbus_mmio_get_region (sbd,1 )); +memory_region_add_subregion (&s->mr_ps,MM_PMC_CFU_STREAM_2 , +sysbus_mmio_get_region (sbd,2 )); +sysbus_connect_irq (sbd,0 , pic[VERSAL_CFU_IRQ_0 ]); + +/* CFU SFR */ +object_initialize_child (OBJECT (s),"cfu-sfr" , &s->pmc.cfu_sfr, +TYPE_XLNX_VERSAL_CFU_SFR ); + + sbd =SYS_BUS_DEVICE (&s->pmc.cfu_sfr); + +object_property_set_link (OBJECT (&s->pmc.cfu_sfr), +"cfu" ,OBJECT (&s->pmc.cfu_apb), &error_abort); + +sysbus_realize (sbd, &error_fatal); +memory_region_add_subregion (&s->mr_ps,MM_PMC_CFU_SFR , +sysbus_mmio_get_region (sbd,0 )); +} +static void versal_create_crl (Versal *s,qemu_irq *pic) {SysBusDevice *sbd;
@@ -763,6 +804,7 @@ static void versal_realize(DeviceState *dev, Error **errp)versal_create_pmc_iou_slcr (s, pic);versal_create_ospi (s, pic);versal_create_crl (s, pic); +versal_create_cfu (s, pic);versal_map_ddr (s);versal_unimp (s);
include/hw/arm/xlnx-versal.h +16 -0
@@ -32,6 +32,7 @@#include "hw/misc/xlnx-versal-crl.h" #include "hw/misc/xlnx-versal-pmc-iou-slcr.h" #include "hw/net/xlnx-versal-canfd.h" +#include "hw/misc/xlnx-versal-cfu.h" #define TYPE_XLNX_VERSAL "xlnx-versal"OBJECT_DECLARE_SIMPLE_TYPE (Versal,XLNX_VERSAL )
@@ -117,6 +118,9 @@ struct Versal {XlnxEFuse efuse;XlnxVersalEFuseCtrl efuse_ctrl;XlnxVersalEFuseCache efuse_cache; +XlnxVersalCFUAPB cfu_apb; +XlnxVersalCFUFDRO cfu_fdro; +XlnxVersalCFUSFR cfu_sfr;OrIRQState apb_irq_orgate; } pmc;
@@ -147,6 +151,7 @@ struct Versal {#define VERSAL_GEM1_WAKE_IRQ_0 59#define VERSAL_ADMA_IRQ_0 60#define VERSAL_XRAM_IRQ_0 79 +#define VERSAL_CFU_IRQ_0 120#define VERSAL_PMC_APB_IRQ 121#define VERSAL_OSPI_IRQ 124#define VERSAL_SD0_IRQ_0 126
@@ -240,6 +245,17 @@ struct Versal {#define MM_PMC_EFUSE_CACHE 0xf1250000#define MM_PMC_EFUSE_CACHE_SIZE 0x00C00 +#define MM_PMC_CFU_APB 0xf12b0000 +#define MM_PMC_CFU_APB_SIZE 0x10000 +#define MM_PMC_CFU_STREAM 0xf12c0000 +#define MM_PMC_CFU_STREAM_SIZE 0x1000 +#define MM_PMC_CFU_SFR 0xf12c1000 +#define MM_PMC_CFU_SFR_SIZE 0x1000 +#define MM_PMC_CFU_FDRO 0xf12c2000 +#define MM_PMC_CFU_FDRO_SIZE 0x1000 +#define MM_PMC_CFU_STREAM_2 0xf1f80000 +#define MM_PMC_CFU_STREAM_2_SIZE 0x40000 +#define MM_PMC_CRP 0xf1260000U#define MM_PMC_CRP_SIZE 0x10000#define MM_PMC_RTC 0xf12a0000
Signature · 1 line
2.34.1
PATCH v3 8/8 hw/arm/versal: Connect the CFRAME_REG and CFRAME_BCAST_REG
In reply to Francisco IglesiasConnect the Configuration Frame controller (CFRAME_REG) and the Configuration Frame broadcast controller (CFRAME_BCAST_REG) to the Versal machine.
--- hw/arm/xlnx-versal.c | 113 ++++++++++++++++++++++++++++++++++- include/hw/arm/xlnx-versal.h | 69 +++++++++++++++++++++ 2 files changed, 181 insertions(+), 1 deletion(-)
hw/arm/xlnx-versal.c +112 -1
@@ -27,7 +27,7 @@#define XLNX_VERSAL_RCPU_TYPE ARM_CPU_TYPE_NAME("cortex-r5f")#define GEM_REVISION 0x40070106 -#define VERSAL_NUM_PMC_APB_IRQS 3 +#define VERSAL_NUM_PMC_APB_IRQS 18#define NUM_OSPI_IRQ_LINES 3static void versal_create_apu_cpus (Versal *s)
@@ -341,6 +341,7 @@ static void versal_create_pmc_apb_irq_orgate(Versal *s, qemu_irq *pic)* - RTC * - BBRAM * - PMC SLCR +* - CFRAME regs (input 3 - 17 to the orgate) */ object_initialize_child (OBJECT (s),"pmc-apb-irq-orgate" , &s->pmc.apb_irq_orgate,TYPE_OR_IRQ );
@@ -573,6 +574,42 @@ static void versal_create_ospi(Versal *s, qemu_irq *pic)static void versal_create_cfu (Versal *s,qemu_irq *pic) {SysBusDevice *sbd; +DeviceState *dev; +int i; +const struct { +uint64_t reg_base; +uint64_t fdri_base; + } cframe_addr[] = { + {MM_PMC_CFRAME0_REG ,MM_PMC_CFRAME0_FDRI }, + {MM_PMC_CFRAME1_REG ,MM_PMC_CFRAME1_FDRI }, + {MM_PMC_CFRAME2_REG ,MM_PMC_CFRAME2_FDRI }, + {MM_PMC_CFRAME3_REG ,MM_PMC_CFRAME3_FDRI }, + {MM_PMC_CFRAME4_REG ,MM_PMC_CFRAME4_FDRI }, + {MM_PMC_CFRAME5_REG ,MM_PMC_CFRAME5_FDRI }, + {MM_PMC_CFRAME6_REG ,MM_PMC_CFRAME6_FDRI }, + {MM_PMC_CFRAME7_REG ,MM_PMC_CFRAME7_FDRI }, + {MM_PMC_CFRAME8_REG ,MM_PMC_CFRAME8_FDRI }, + {MM_PMC_CFRAME9_REG ,MM_PMC_CFRAME9_FDRI }, + {MM_PMC_CFRAME10_REG ,MM_PMC_CFRAME10_FDRI }, + {MM_PMC_CFRAME11_REG ,MM_PMC_CFRAME11_FDRI }, + {MM_PMC_CFRAME12_REG ,MM_PMC_CFRAME12_FDRI }, + {MM_PMC_CFRAME13_REG ,MM_PMC_CFRAME13_FDRI }, + {MM_PMC_CFRAME14_REG ,MM_PMC_CFRAME14_FDRI }, + }; +const struct { +uint32_t blktype0_frames; +uint32_t blktype1_frames; +uint32_t blktype2_frames; +uint32_t blktype3_frames; +uint32_t blktype4_frames; +uint32_t blktype5_frames; +uint32_t blktype6_frames; + } cframe_cfg[] = { + [0 ] = {34111 ,3528 ,12800 ,11 ,5 ,1 ,1 }, + [1 ] = {38498 ,3841 ,15361 ,13 ,7 ,3 ,1 }, + [2 ] = {38498 ,3841 ,15361 ,13 ,7 ,3 ,1 }, + [3 ] = {38498 ,3841 ,15361 ,13 ,7 ,3 ,1 }, + };/* CFU FDRO */ object_initialize_child(OBJECT(s), "cfu-fdro", &s->pmc.cfu_fdro,
@@ -583,10 +620,84 @@ static void versal_create_cfu(Versal *s, qemu_irq *pic)memory_region_add_subregion (&s->mr_ps,MM_PMC_CFU_FDRO ,sysbus_mmio_get_region (sbd,0 )); +/* CFRAME REG */ +for (i =0 ; i <ARRAY_SIZE (s->pmc.cframe); i++) { + g_autofree char *name = g_strdup_printf("cframe%d", i); + +object_initialize_child (OBJECT (s), name, &s->pmc.cframe[i], +TYPE_XLNX_VERSAL_CFRAME_REG ); + + sbd =SYS_BUS_DEVICE (&s->pmc.cframe[i]); + dev =DEVICE (&s->pmc.cframe[i]); + +if (i <ARRAY_SIZE (cframe_cfg)) { +object_property_set_int (OBJECT (dev),"blktype0-frames" , + cframe_cfg[i].blktype0_frames, + &error_abort); +object_property_set_int (OBJECT (dev),"blktype1-frames" , + cframe_cfg[i].blktype1_frames, + &error_abort); +object_property_set_int (OBJECT (dev),"blktype2-frames" , + cframe_cfg[i].blktype2_frames, + &error_abort); +object_property_set_int (OBJECT (dev),"blktype3-frames" , + cframe_cfg[i].blktype3_frames, + &error_abort); +object_property_set_int (OBJECT (dev),"blktype4-frames" , + cframe_cfg[i].blktype4_frames, + &error_abort); +object_property_set_int (OBJECT (dev),"blktype5-frames" , + cframe_cfg[i].blktype5_frames, + &error_abort); +object_property_set_int (OBJECT (dev),"blktype6-frames" , + cframe_cfg[i].blktype6_frames, + &error_abort); + } +object_property_set_link (OBJECT (dev),"cfu-fdro" , +OBJECT (&s->pmc.cfu_fdro), &error_fatal); + +sysbus_realize (SYS_BUS_DEVICE (dev), &error_fatal); + +memory_region_add_subregion (&s->mr_ps, cframe_addr[i].reg_base, +sysbus_mmio_get_region (sbd,0 )); +memory_region_add_subregion (&s->mr_ps, cframe_addr[i].fdri_base, +sysbus_mmio_get_region (sbd,1 )); +sysbus_connect_irq (sbd,0 , +qdev_get_gpio_in (DEVICE (&s->pmc.apb_irq_orgate), +3 + i)); + } + +/* CFRAME BCAST */ +object_initialize_child (OBJECT (s),"cframe_bcast" , &s->pmc.cframe_bcast, +TYPE_XLNX_VERSAL_CFRAME_BCAST_REG ); + + sbd =SYS_BUS_DEVICE (&s->pmc.cframe_bcast); + dev =DEVICE (&s->pmc.cframe_bcast); + +for (i =0 ; i <ARRAY_SIZE (s->pmc.cframe); i++) { + g_autofree char *propname = g_strdup_printf("cframe%d", i); +object_property_set_link (OBJECT (dev), propname, +OBJECT (&s->pmc.cframe[i]), &error_fatal); + } + +sysbus_realize (sbd, &error_fatal); + +memory_region_add_subregion (&s->mr_ps,MM_PMC_CFRAME_BCAST_REG , +sysbus_mmio_get_region (sbd,0 )); +memory_region_add_subregion (&s->mr_ps,MM_PMC_CFRAME_BCAST_FDRI , +sysbus_mmio_get_region (sbd,1 )); +/* CFU APB */ object_initialize_child (OBJECT (s),"cfu-apb" , &s->pmc.cfu_apb,TYPE_XLNX_VERSAL_CFU_APB ); sbd =SYS_BUS_DEVICE (&s->pmc.cfu_apb); + dev =DEVICE (&s->pmc.cfu_apb); + +for (i =0 ; i <ARRAY_SIZE (s->pmc.cframe); i++) { + g_autofree char *propname = g_strdup_printf("cframe%d", i); +object_property_set_link (OBJECT (dev), propname, +OBJECT (&s->pmc.cframe[i]), &error_fatal); + }sysbus_realize (sbd, &error_fatal); memory_region_add_subregion(&s->mr_ps, MM_PMC_CFU_APB,
include/hw/arm/xlnx-versal.h +69 -0
93 lines not on this page · raw message
Signature · 1 line
2.34.1