Xilinx Versal CFI support
v4 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:v3->v4:
[PATCH 5]
* Swap to pop out the fifo32 data instead of using memcpy
* Use g_tree_nnodes instead of g_tree_height
* Take reference before g_tree_destroy (for keeping the GTree around)
* Remove stray whitespace (in cframe_reg_init before g_free)
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 GTreev1->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 | 858 +++++++++++++++++++++++ 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, 2327 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 v4 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 v4 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 v4 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 v4 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