hw/nvram: hw/arm: Introduce Xilinx eFUSE and BBRAM
Subsystems (2)
v3 cover hw/nvram: hw/arm: Introduce Xilinx eFUSE and BBRAM
This series implements the Xilinx eFUSE and BBRAM devices for the Versal and ZynqMP product families.
Furthermore, both new devices are connected to the xlnx-versal-virt board and the xlnx-zcu102 board.
See changes in docs/system/arm/xlnx-versal-virt.rst for detail.
---
Changelogs:
v2->v3:
* Move drive-backend attaching to board models
* Use OBJECT_DECLARE_SIMPLE_TYPE instead of OBJECT_CHECK
* Use reg_array->mem directly instead of an extra mr-container
* Add doc comments for .h file API
* Remove "qemu/osdep.h" from .h files
* Remove ad-hoc endianess detection
* Remove error_abort from device models
* Remove empty vmstate and mininum_version_id_old
* Remove unused #define macros
* Remove unavailable references from comments
* Kconfig & meson.build:
- Add CONFIG_XLNX_EFUSE_CRC in patch 1
- Select bbram and efuse devices from boards' Kconfig
- Remove 'if' from meson.build
* Fix spelling and wording in comments and docs
v1->v2:
* Move doc change from 1st to last of this series
* Remove outdated comment of 'autogenerated by xregqemu.py' from all affected files.
---
Tong Ho (9):
hw/nvram: Introduce Xilinx eFuse QOM
hw/nvram: Introduce Xilinx Versal eFuse device hw/nvram: Introduce Xilinx ZynqMP eFuse device hw/nvram: Introduce Xilinx battery-backed ram hw/arm: xlnx-versal-virt: Add Xilinx BBRAM device hw/arm: xlnx-versal-virt: Add Xilinx eFUSE device hw/arm: xlnx-zcu102: Add Xilinx BBRAM device hw/arm: xlnx-zcu102: Add Xilinx eFUSE device docs/system/arm: xlnx-versal-virt: BBRAM and eFUSE Usage
docs/system/arm/xlnx-versal-virt.rst | 49 ++ hw/Kconfig | 2 + hw/arm/Kconfig | 2 + hw/arm/xlnx-versal-virt.c | 88 +++ hw/arm/xlnx-versal.c | 57 ++ hw/arm/xlnx-zcu102.c | 30 + hw/arm/xlnx-zynqmp.c | 49 ++ hw/nvram/Kconfig | 19 + hw/nvram/meson.build | 8 + hw/nvram/xlnx-bbram.c | 545 +++++++++++++++++ hw/nvram/xlnx-efuse-crc.c | 119 ++++ hw/nvram/xlnx-efuse.c | 280 +++++++++ hw/nvram/xlnx-versal-efuse-cache.c | 114 ++++ hw/nvram/xlnx-versal-efuse-ctrl.c | 783 ++++++++++++++++++++++++ hw/nvram/xlnx-zynqmp-efuse.c | 855 +++++++++++++++++++++++++++ include/hw/arm/xlnx-versal.h | 15 + include/hw/arm/xlnx-zynqmp.h | 5 + include/hw/nvram/xlnx-bbram.h | 54 ++ include/hw/nvram/xlnx-efuse.h | 132 +++++ include/hw/nvram/xlnx-versal-efuse.h | 68 +++ include/hw/nvram/xlnx-zynqmp-efuse.h | 44 ++ 21 files changed, 3318 insertions(+) create mode 100644 hw/nvram/xlnx-bbram.c create mode 100644 hw/nvram/xlnx-efuse-crc.c create mode 100644 hw/nvram/xlnx-efuse.c create mode 100644 hw/nvram/xlnx-versal-efuse-cache.c create mode 100644 hw/nvram/xlnx-versal-efuse-ctrl.c create mode 100644 hw/nvram/xlnx-zynqmp-efuse.c create mode 100644 include/hw/nvram/xlnx-bbram.h create mode 100644 include/hw/nvram/xlnx-efuse.h create mode 100644 include/hw/nvram/xlnx-versal-efuse.h create mode 100644 include/hw/nvram/xlnx-zynqmp-efuse.h
Signature · 1 line
2.25.1
PATCH v3 1/9 hw/nvram: Introduce Xilinx eFuse QOM
This introduces the QOM for Xilinx eFuse, an one-time field-programmable storage bit array.
The actual mmio interface to the array varies by device families and will be provided in different change-sets.
--- hw/nvram/Kconfig | 7 + hw/nvram/meson.build | 2 + hw/nvram/xlnx-efuse-crc.c | 119 +++++++++++++++ hw/nvram/xlnx-efuse.c | 280 ++++++++++++++++++++++++++++++++++ include/hw/nvram/xlnx-efuse.h | 132 ++++++++++++++++ 5 files changed, 540 insertions(+) create mode 100644 hw/nvram/xlnx-efuse-crc.c create mode 100644 hw/nvram/xlnx-efuse.c create mode 100644 include/hw/nvram/xlnx-efuse.h
hw/nvram/Kconfig +7 -0
@@ -15,3 +15,10 @@ config NMC93XX_EEPROM config CHRP_NVRAM bool + +config XLNX_EFUSE_CRC + bool + +config XLNX_EFUSE + bool + select XLNX_EFUSE_CRC
hw/nvram/meson.build +2 -0
@@ -9,5 +9,7 @@ softmmu_ss.add(when: 'CONFIG_AT24C', if_true: files('eeprom_at24c.c')) softmmu_ss.add(when: 'CONFIG_MAC_NVRAM', if_true: files('mac_nvram.c')) softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_otp.c')) softmmu_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('nrf51_nvm.c')) +softmmu_ss.add(when: 'CONFIG_XLNX_EFUSE_CRC', if_true: files('xlnx-efuse-crc.c')) +softmmu_ss.add(when: 'CONFIG_XLNX_EFUSE', if_true: files('xlnx-efuse.c')) specific_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr_nvram.c'))
hw/nvram/xlnx-efuse-crc.c new file +119 -0
119 lines not on this page · raw message
hw/nvram/xlnx-efuse.c new file +280 -0
280 lines not on this page · raw message
include/hw/nvram/xlnx-efuse.h new file +132 -0
132 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v3 2/9 hw/nvram: Introduce Xilinx Versal eFuse device
In reply to Tong HoThis implements the Xilinx Versal eFuse, an one-time field-programmable non-volatile storage device. There is only one such device in the Xilinx Versal product family.
This device has two separate mmio interfaces, a controller and a flatten readback.
The controller provides interfaces for field-programming, configuration, control, and status.
The flatten readback is a cache to provide a byte-accessible read-only interface to efficiently read efuse array.
--- hw/nvram/Kconfig | 4 + hw/nvram/meson.build | 3 + hw/nvram/xlnx-versal-efuse-cache.c | 114 ++++ hw/nvram/xlnx-versal-efuse-ctrl.c | 783 +++++++++++++++++++++++++++ include/hw/nvram/xlnx-versal-efuse.h | 68 +++ 5 files changed, 972 insertions(+) create mode 100644 hw/nvram/xlnx-versal-efuse-cache.c create mode 100644 hw/nvram/xlnx-versal-efuse-ctrl.c create mode 100644 include/hw/nvram/xlnx-versal-efuse.h
hw/nvram/Kconfig +4 -0
@@ -22,3 +22,7 @@ config XLNX_EFUSE_CRC config XLNX_EFUSE bool select XLNX_EFUSE_CRC + +config XLNX_EFUSE_VERSAL + bool + select XLNX_EFUSE
hw/nvram/meson.build +3 -0
@@ -11,5 +11,8 @@ softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_otp.c')) softmmu_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('nrf51_nvm.c')) softmmu_ss.add(when: 'CONFIG_XLNX_EFUSE_CRC', if_true: files('xlnx-efuse-crc.c')) softmmu_ss.add(when: 'CONFIG_XLNX_EFUSE', if_true: files('xlnx-efuse.c')) +softmmu_ss.add(when: 'CONFIG_XLNX_EFUSE_VERSAL', if_true: files( + 'xlnx-versal-efuse-cache.c', + 'xlnx-versal-efuse-ctrl.c')) specific_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr_nvram.c'))
hw/nvram/xlnx-versal-efuse-cache.c new file +114 -0
114 lines not on this page · raw message
hw/nvram/xlnx-versal-efuse-ctrl.c new file +783 -0
783 lines not on this page · raw message
include/hw/nvram/xlnx-versal-efuse.h new file +68 -0
68 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v3 3/9 hw/nvram: Introduce Xilinx ZynqMP eFuse device
In reply to Tong HoThis implements the Xilinx ZynqMP eFuse, an one-time field-programmable non-volatile storage device. There is only one such device in the Xilinx ZynqMP product family.
--- hw/nvram/Kconfig | 4 + hw/nvram/meson.build | 2 + hw/nvram/xlnx-zynqmp-efuse.c | 855 +++++++++++++++++++++++++++ include/hw/nvram/xlnx-zynqmp-efuse.h | 44 ++ 4 files changed, 905 insertions(+) create mode 100644 hw/nvram/xlnx-zynqmp-efuse.c create mode 100644 include/hw/nvram/xlnx-zynqmp-efuse.h
hw/nvram/Kconfig +4 -0
@@ -26,3 +26,7 @@ config XLNX_EFUSE config XLNX_EFUSE_VERSAL bool select XLNX_EFUSE + +config XLNX_EFUSE_ZYNQMP + bool + select XLNX_EFUSE
hw/nvram/meson.build +2 -0
@@ -14,5 +14,7 @@ softmmu_ss.add(when: 'CONFIG_XLNX_EFUSE', if_true: files('xlnx-efuse.c')) softmmu_ss.add(when: 'CONFIG_XLNX_EFUSE_VERSAL', if_true: files( 'xlnx-versal-efuse-cache.c', 'xlnx-versal-efuse-ctrl.c')) +softmmu_ss.add(when: 'CONFIG_XLNX_EFUSE_ZYNQMP', if_true: files( + 'xlnx-zynqmp-efuse.c')) specific_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr_nvram.c'))
hw/nvram/xlnx-zynqmp-efuse.c new file +855 -0
855 lines not on this page · raw message
include/hw/nvram/xlnx-zynqmp-efuse.h new file +44 -0
44 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v3 4/9 hw/nvram: Introduce Xilinx battery-backed ram
In reply to Tong HoThis device is present in Versal and ZynqMP product families to store a 256-bit encryption key.
--- hw/nvram/Kconfig | 4 + hw/nvram/meson.build | 1 + hw/nvram/xlnx-bbram.c | 545 ++++++++++++++++++++++++++++++++++ include/hw/nvram/xlnx-bbram.h | 54 ++++ 4 files changed, 604 insertions(+) create mode 100644 hw/nvram/xlnx-bbram.c create mode 100644 include/hw/nvram/xlnx-bbram.h
hw/nvram/Kconfig +4 -0
@@ -30,3 +30,7 @@ config XLNX_EFUSE_VERSAL config XLNX_EFUSE_ZYNQMP bool select XLNX_EFUSE + +config XLNX_BBRAM + bool + select XLNX_EFUSE_CRC
hw/nvram/meson.build +1 -0
@@ -16,5 +16,6 @@ softmmu_ss.add(when: 'CONFIG_XLNX_EFUSE_VERSAL', if_true: files( 'xlnx-versal-efuse-ctrl.c')) softmmu_ss.add(when: 'CONFIG_XLNX_EFUSE_ZYNQMP', if_true: files( 'xlnx-zynqmp-efuse.c')) +softmmu_ss.add(when: 'CONFIG_XLNX_BBRAM', if_true: files('xlnx-bbram.c')) specific_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr_nvram.c'))
hw/nvram/xlnx-bbram.c new file +545 -0
545 lines not on this page · raw message
include/hw/nvram/xlnx-bbram.h new file +54 -0
54 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v3 5/9 hw/arm: xlnx-versal-virt: Add Xilinx BBRAM device
In reply to Tong HoConnect the support for Versal Battery-Backed RAM (BBRAM)
The command argument:
-drive if=pflash,index=0,...
Can be used to optionally connect the bbram to a backend storage, such that field-programmed values in one invocation can be made available to next invocation.
The backend storage must be a seekable binary file, and its size must be 36 bytes or larger. A file with all binary 0's is a 'blank'.
--- hw/arm/Kconfig | 1 + hw/arm/xlnx-versal-virt.c | 36 ++++++++++++++++++++++++++++++++++++ hw/arm/xlnx-versal.c | 18 ++++++++++++++++++ include/hw/arm/xlnx-versal.h | 5 +++++ 4 files changed, 60 insertions(+)
hw/arm/Kconfig +1 -0
@@ -381,6 +381,7 @@ config XLNX_VERSAL select XLNX_ZDMA select XLNX_ZYNQMP select OR_IRQ + select XLNX_BBRAM config NPCM7XX bool
hw/arm/xlnx-versal-virt.c +36 -0
@@ -356,6 +356,26 @@ static void fdt_add_rtc_node(VersalVirt *s)g_free (name); } +static void fdt_add_bbram_node (VersalVirt *s) +{ +const char compat[] =TYPE_XLNX_BBRAM ; +const char interrupt_names[] ="bbram-error" ; +char *name =g_strdup_printf ("/bbram@%x" ,MM_PMC_BBRAM_CTRL ); + +qemu_fdt_add_subnode (s->fdt, name); + +qemu_fdt_setprop_cells (s->fdt, name,"interrupts" , +GIC_FDT_IRQ_TYPE_SPI ,VERSAL_BBRAM_APB_IRQ_0 , +GIC_FDT_IRQ_FLAGS_LEVEL_HI ); +qemu_fdt_setprop (s->fdt, name,"interrupt-names" , + interrupt_names,sizeof (interrupt_names)); +qemu_fdt_setprop_sized_cells (s->fdt, name,"reg" , +2 ,MM_PMC_BBRAM_CTRL , +2 ,MM_PMC_BBRAM_CTRL_SIZE ); +qemu_fdt_setprop (s->fdt, name,"compatible" , compat,sizeof (compat)); +g_free (name); +} +static void fdt_nop_memory_nodes (void *fdt,Error **errp) {Error *err =NULL ;
@@ -510,6 +530,18 @@ static void create_virtio_regions(VersalVirt *s) } } +static void bbram_attach_drive (XlnxBBRam *dev) +{ +DriveInfo *dinfo; +BlockBackend *blk; + + dinfo =drive_get_by_index (IF_PFLASH ,0 ); + blk = dinfo ?blk_by_legacy_dinfo (dinfo) :NULL ; +if (blk) { +qdev_prop_set_drive (DEVICE (dev),"drive" , blk); + } +} +static void sd_plugin_card (SDHCIState *sd,DriveInfo *di) {BlockBackend *blk = di ?blk_by_legacy_dinfo (di) :NULL ;
@@ -570,6 +602,7 @@ static void versal_virt_init(MachineState *machine)fdt_add_usb_xhci_nodes (s);fdt_add_sd_nodes (s);fdt_add_rtc_node (s); +fdt_add_bbram_node (s);fdt_add_cpu_nodes (s, psci_conduit);fdt_add_clk_node (s,"/clk125" ,125000000 , s->phandle.clk_125Mhz);fdt_add_clk_node (s,"/clk25" ,25000000 , s->phandle.clk_25Mhz);
@@ -579,6 +612,9 @@ static void versal_virt_init(MachineState *machine)memory_region_add_subregion_overlap (get_system_memory (),0 , &s->soc.fpd.apu.mr,0 ); +/* Attach bbram backend, if given */ +bbram_attach_drive (&s->soc.pmc.bbram); +/* Plugin SD cards. */ for (i =0 ; i <ARRAY_SIZE (s->soc.pmc.iou.sd); i++) {sd_plugin_card (&s->soc.pmc.iou.sd[i],drive_get_next (IF_SD ));
hw/arm/xlnx-versal.c +18 -0
@@ -314,6 +314,23 @@ static void versal_create_xrams(Versal *s, qemu_irq *pic) } } +static void versal_create_bbram (Versal *s,qemu_irq *pic) +{ +SysBusDevice *sbd; + +object_initialize_child_with_props (OBJECT (s),"bbram" , &s->pmc.bbram, +sizeof (s->pmc.bbram),TYPE_XLNX_BBRAM , + &error_fatal, +"crc-zpads" ,"0" , +NULL ); + sbd =SYS_BUS_DEVICE (&s->pmc.bbram); + +sysbus_realize (sbd, &error_fatal); +memory_region_add_subregion (&s->mr_ps,MM_PMC_BBRAM_CTRL , +sysbus_mmio_get_region (sbd,0 )); +sysbus_connect_irq (sbd,0 , pic[VERSAL_BBRAM_APB_IRQ_0 ]); +} +/* This takes the board allocated linear DDR memory and creates aliases * for each split DDR range/aperture on the Versal address map. */
@@ -402,6 +419,7 @@ static void versal_realize(DeviceState *dev, Error **errp)versal_create_sds (s, pic);versal_create_rtc (s, pic);versal_create_xrams (s, pic); +versal_create_bbram (s, pic);versal_map_ddr (s);versal_unimp (s);
include/hw/arm/xlnx-versal.h +5 -0
@@ -24,6 +24,7 @@#include "qom/object.h" #include "hw/usb/xlnx-usb-subsystem.h" #include "hw/misc/xlnx-versal-xramc.h" +#include "hw/nvram/xlnx-bbram.h" #define TYPE_XLNX_VERSAL "xlnx-versal"OBJECT_DECLARE_SIMPLE_TYPE (Versal,XLNX_VERSAL )
@@ -79,6 +80,7 @@ struct Versal { } iou;XlnxZynqMPRTC rtc; +XlnxBBRam bbram; } pmc;struct {
@@ -105,6 +107,7 @@ struct Versal {#define VERSAL_GEM1_WAKE_IRQ_0 59#define VERSAL_ADMA_IRQ_0 60#define VERSAL_XRAM_IRQ_0 79 +#define VERSAL_BBRAM_APB_IRQ_0 121#define VERSAL_RTC_APB_ERR_IRQ 121#define VERSAL_SD0_IRQ_0 126#define VERSAL_RTC_ALARM_IRQ 142
@@ -172,6 +175,8 @@ struct Versal {#define MM_PMC_SD0 0xf1040000U#define MM_PMC_SD0_SIZE 0x10000 +#define MM_PMC_BBRAM_CTRL 0xf11f0000 +#define MM_PMC_BBRAM_CTRL_SIZE 0x00050#define MM_PMC_CRP 0xf1260000U#define MM_PMC_CRP_SIZE 0x10000#define MM_PMC_RTC 0xf12a0000
Signature · 1 line
2.25.1
PATCH v3 6/9 hw/arm: xlnx-versal-virt: Add Xilinx eFUSE device
In reply to Tong HoConnect the support for Versal eFUSE one-time field-programmable bit array.
The command argument:
-drive if=pflash,index=1,...
Can be used to optionally connect the bit array to a backend storage, such that field-programmed values in one invocation can be made available to next invocation.
The backend storage must be a seekable binary file, and its size must be 3072 bytes or larger. A file with all binary 0's is a 'blank'.
--- hw/arm/Kconfig | 1 + hw/arm/xlnx-versal-virt.c | 52 ++++++++++++++++++++++++++++++++++++ hw/arm/xlnx-versal.c | 39 +++++++++++++++++++++++++++ include/hw/arm/xlnx-versal.h | 10 +++++++ 4 files changed, 102 insertions(+)
hw/arm/Kconfig +1 -0
@@ -382,6 +382,7 @@ config XLNX_VERSAL select XLNX_ZYNQMP select OR_IRQ select XLNX_BBRAM + select XLNX_EFUSE_VERSAL config NPCM7XX bool
hw/arm/xlnx-versal-virt.c +52 -0
76 lines not on this page · raw message
hw/arm/xlnx-versal.c +39 -0
@@ -331,6 +331,44 @@ static void versal_create_bbram(Versal *s, qemu_irq *pic)sysbus_connect_irq (sbd,0 , pic[VERSAL_BBRAM_APB_IRQ_0 ]); } +static void versal_realize_efuse_part (Versal *s,Object *dev,hwaddr base) +{ +SysBusDevice *part =SYS_BUS_DEVICE (dev); + +object_property_set_link (OBJECT (part),"efuse" , +OBJECT (&s->pmc.efuse), &error_abort); + +sysbus_realize (part, &error_abort); +memory_region_add_subregion (&s->mr_ps, base, +sysbus_mmio_get_region (part,0 )); +} + +static void versal_create_efuse (Versal *s,qemu_irq *pic) +{ +Object *bits =OBJECT (&s->pmc.efuse); +Object *ctrl =OBJECT (&s->pmc.efuse_ctrl); +Object *cache =OBJECT (&s->pmc.efuse_cache); + +object_initialize_child (OBJECT (s),"efuse-ctrl" , &s->pmc.efuse_ctrl, +TYPE_XLNX_VERSAL_EFUSE_CTRL ); + +object_initialize_child (OBJECT (s),"efuse-cache" , &s->pmc.efuse_cache, +TYPE_XLNX_VERSAL_EFUSE_CACHE ); + +object_initialize_child_with_props (ctrl,"xlnx-efuse@0" , bits, +sizeof (s->pmc.efuse), +TYPE_XLNX_EFUSE , &error_abort, +"efuse-nr" ,"3" , +"efuse-size" ,"8192" , +NULL ); + +qdev_realize (DEVICE (bits),NULL , &error_abort); +versal_realize_efuse_part (s, ctrl,MM_PMC_EFUSE_CTRL ); +versal_realize_efuse_part (s, cache,MM_PMC_EFUSE_CACHE ); + +sysbus_connect_irq (SYS_BUS_DEVICE (ctrl),0 , pic[VERSAL_EFUSE_IRQ ]); +} +/* This takes the board allocated linear DDR memory and creates aliases * for each split DDR range/aperture on the Versal address map. */
@@ -420,6 +458,7 @@ static void versal_realize(DeviceState *dev, Error **errp)versal_create_rtc (s, pic);versal_create_xrams (s, pic);versal_create_bbram (s, pic); +versal_create_efuse (s, pic);versal_map_ddr (s);versal_unimp (s);
include/hw/arm/xlnx-versal.h +10 -0
@@ -25,6 +25,7 @@#include "hw/usb/xlnx-usb-subsystem.h" #include "hw/misc/xlnx-versal-xramc.h" #include "hw/nvram/xlnx-bbram.h" +#include "hw/nvram/xlnx-versal-efuse.h" #define TYPE_XLNX_VERSAL "xlnx-versal"OBJECT_DECLARE_SIMPLE_TYPE (Versal,XLNX_VERSAL )
@@ -81,6 +82,9 @@ struct Versal {XlnxZynqMPRTC rtc;XlnxBBRam bbram; +XlnxEFuse efuse; +XlnxVersalEFuseCtrl efuse_ctrl; +XlnxVersalEFuseCache efuse_cache; } pmc;struct {
@@ -110,6 +114,7 @@ struct Versal {#define VERSAL_BBRAM_APB_IRQ_0 121#define VERSAL_RTC_APB_ERR_IRQ 121#define VERSAL_SD0_IRQ_0 126 +#define VERSAL_EFUSE_IRQ 139#define VERSAL_RTC_ALARM_IRQ 142#define VERSAL_RTC_SECONDS_IRQ 143
@@ -177,6 +182,11 @@ struct Versal {#define MM_PMC_SD0_SIZE 0x10000#define MM_PMC_BBRAM_CTRL 0xf11f0000#define MM_PMC_BBRAM_CTRL_SIZE 0x00050 +#define MM_PMC_EFUSE_CTRL 0xf1240000 +#define MM_PMC_EFUSE_CTRL_SIZE 0x00104 +#define MM_PMC_EFUSE_CACHE 0xf1250000 +#define MM_PMC_EFUSE_CACHE_SIZE 0x00C00 +#define MM_PMC_CRP 0xf1260000U#define MM_PMC_CRP_SIZE 0x10000#define MM_PMC_RTC 0xf12a0000
Signature · 1 line
2.25.1
PATCH v3 7/9 hw/arm: xlnx-zcu102: Add Xilinx BBRAM device
In reply to Tong HoConnect the support for Xilinx ZynqMP Battery-Backed RAM (BBRAM)
The command argument:
-drive if=pflash,index=2,...
Can be used to optionally connect the bbram to a backend storage, such that field-programmed values in one invocation can be made available to next invocation.
The backend storage must be a seekable binary file, and its size must be 36 bytes or larger. A file with all binary 0's is a 'blank'.
--- hw/Kconfig | 1 + hw/arm/xlnx-zcu102.c | 15 +++++++++++++++ hw/arm/xlnx-zynqmp.c | 20 ++++++++++++++++++++ include/hw/arm/xlnx-zynqmp.h | 2 ++ 4 files changed, 38 insertions(+)
hw/Kconfig +1 -0
@@ -81,3 +81,4 @@ config XLNX_ZYNQMP select REGISTER select CAN_BUS select PTIMER + select XLNX_BBRAM
hw/arm/xlnx-zcu102.c +15 -0
@@ -98,6 +98,18 @@ static void zcu102_modify_dtb(const struct arm_boot_info *binfo, void *fdt) } } +static void bbram_attach_drive (XlnxBBRam *dev) +{ +DriveInfo *dinfo; +BlockBackend *blk; + + dinfo =drive_get_by_index (IF_PFLASH ,2 ); + blk = dinfo ?blk_by_legacy_dinfo (dinfo) :NULL ; +if (blk) { +qdev_prop_set_drive (DEVICE (dev),"drive" , blk); + } +} +static void xlnx_zcu102_init (MachineState *machine) {XlnxZCU102 *s =ZCU102_MACHINE (machine);
@@ -136,6 +148,9 @@ static void xlnx_zcu102_init(MachineState *machine)qdev_realize (DEVICE (&s->soc),NULL , &error_fatal); +/* Attach bbram backend, if given */ +bbram_attach_drive (&s->soc.bbram); +/* Create and plug in the SD cards */ for (i =0 ; i <XLNX_ZYNQMP_NUM_SDHCI ; i++) {BusState *bus;
hw/arm/xlnx-zynqmp.c +20 -0
@@ -66,6 +66,9 @@#define RTC_ADDR 0xffa60000#define RTC_IRQ 26 +#define BBRAM_ADDR 0xffcd0000 +#define BBRAM_IRQ 11 +#define SDHCI_CAPABILITIES 0x280737ec6481/* Datasheet: UG1085 (v1.7) */ static const uint64_t gem_addr[XLNX_ZYNQMP_NUM_GEMS ] = {
@@ -226,6 +229,22 @@ static void xlnx_zynqmp_create_rpu(MachineState *ms, XlnxZynqMPState *s,qdev_realize (DEVICE (&s->rpu_cluster),NULL , &error_fatal); } +static void xlnx_zynqmp_create_bbram (XlnxZynqMPState *s,qemu_irq *gic) +{ +SysBusDevice *sbd; + +object_initialize_child_with_props (OBJECT (s),"bbram" , &s->bbram, +sizeof (s->bbram),TYPE_XLNX_BBRAM , + &error_fatal, +"crc-zpads" ,"1" , +NULL ); + sbd =SYS_BUS_DEVICE (&s->bbram); + +sysbus_realize (sbd, &error_fatal); +sysbus_mmio_map (sbd,0 ,BBRAM_ADDR ); +sysbus_connect_irq (sbd,0 , gic[BBRAM_IRQ ]); +} +static void xlnx_zynqmp_create_unimp_mmio (XlnxZynqMPState *s) { static const struct UnimpInfo {
@@ -626,6 +645,7 @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp)sysbus_mmio_map (SYS_BUS_DEVICE (&s->rtc),0 ,RTC_ADDR );sysbus_connect_irq (SYS_BUS_DEVICE (&s->rtc),0 , gic_spi[RTC_IRQ ]); +xlnx_zynqmp_create_bbram (s, gic_spi);xlnx_zynqmp_create_unimp_mmio (s);for (i =0 ; i <XLNX_ZYNQMP_NUM_GDMA_CH ; i++) {
include/hw/arm/xlnx-zynqmp.h +2 -0
@@ -36,6 +36,7 @@#include "qom/object.h" #include "net/can_emu.h" #include "hw/dma/xlnx_csu_dma.h" +#include "hw/nvram/xlnx-bbram.h" #define TYPE_XLNX_ZYNQMP "xlnx-zynqmp"OBJECT_DECLARE_SIMPLE_TYPE (XlnxZynqMPState,XLNX_ZYNQMP )
@@ -100,6 +101,7 @@ struct XlnxZynqMPState {MemoryRegion *ddr_ram;MemoryRegion ddr_ram_low, ddr_ram_high; +XlnxBBRam bbram;MemoryRegion mr_unimp[XLNX_ZYNQMP_NUM_UNIMP_AREAS ];
Signature · 1 line
2.25.1
PATCH v3 8/9 hw/arm: xlnx-zcu102: Add Xilinx eFUSE device
In reply to Tong HoConnect the support for ZynqMP eFUSE one-time field-programmable bit array.
The command argument:
-drive if=pflash,index=3,...
Can be used to optionally connect the bit array to a backend storage, such that field-programmed values in one invocation can be made available to next invocation.
The backend storage must be a seekable binary file, and its size must be 768 bytes or larger. A file with all binary 0's is a 'blank'.
--- hw/Kconfig | 1 + hw/arm/xlnx-zcu102.c | 15 +++++++++++++++ hw/arm/xlnx-zynqmp.c | 29 +++++++++++++++++++++++++++++ include/hw/arm/xlnx-zynqmp.h | 3 +++ 4 files changed, 48 insertions(+)
hw/Kconfig +1 -0
@@ -82,3 +82,4 @@ config XLNX_ZYNQMP select CAN_BUS select PTIMER select XLNX_BBRAM + select XLNX_EFUSE_ZYNQMP
hw/arm/xlnx-zcu102.c +15 -0
@@ -110,6 +110,18 @@ static void bbram_attach_drive(XlnxBBRam *dev) } } +static void efuse_attach_drive (XlnxEFuse *dev) +{ +DriveInfo *dinfo; +BlockBackend *blk; + + dinfo =drive_get_by_index (IF_PFLASH ,3 ); + blk = dinfo ?blk_by_legacy_dinfo (dinfo) :NULL ; +if (blk) { +qdev_prop_set_drive (DEVICE (dev),"drive" , blk); + } +} +static void xlnx_zcu102_init (MachineState *machine) {XlnxZCU102 *s =ZCU102_MACHINE (machine);
@@ -151,6 +163,9 @@ static void xlnx_zcu102_init(MachineState *machine)/* Attach bbram backend, if given */ bbram_attach_drive (&s->soc.bbram); +/* Attach efuse backend, if given */ +efuse_attach_drive (&s->soc.efuse); +/* Create and plug in the SD cards */ for (i =0 ; i <XLNX_ZYNQMP_NUM_SDHCI ; i++) {BusState *bus;
hw/arm/xlnx-zynqmp.c +29 -0
@@ -69,6 +69,9 @@#define BBRAM_ADDR 0xffcd0000#define BBRAM_IRQ 11 +#define EFUSE_ADDR 0xffcc0000 +#define EFUSE_IRQ 87 +#define SDHCI_CAPABILITIES 0x280737ec6481/* Datasheet: UG1085 (v1.7) */ static const uint64_t gem_addr[XLNX_ZYNQMP_NUM_GEMS ] = {
@@ -245,6 +248,31 @@ static void xlnx_zynqmp_create_bbram(XlnxZynqMPState *s, qemu_irq *gic)sysbus_connect_irq (sbd,0 , gic[BBRAM_IRQ ]); } +static void xlnx_zynqmp_create_efuse (XlnxZynqMPState *s,qemu_irq *gic) +{ +Object *bits =OBJECT (&s->efuse); +Object *ctrl =OBJECT (&s->efuse_ctrl); +SysBusDevice *sbd; + +object_initialize_child (OBJECT (s),"efuse-ctrl" , &s->efuse_ctrl, +TYPE_XLNX_ZYNQMP_EFUSE ); + +object_initialize_child_with_props (ctrl,"xlnx-efuse@0" , bits, +sizeof (s->efuse), +TYPE_XLNX_EFUSE , &error_abort, +"efuse-nr" ,"3" , +"efuse-size" ,"2048" , +NULL ); + +qdev_realize (DEVICE (bits),NULL , &error_abort); +object_property_set_link (ctrl,"efuse" , bits, &error_abort); + + sbd =SYS_BUS_DEVICE (ctrl); +sysbus_realize (sbd, &error_abort); +sysbus_mmio_map (sbd,0 ,EFUSE_ADDR ); +sysbus_connect_irq (sbd,0 , gic[EFUSE_IRQ ]); +} +static void xlnx_zynqmp_create_unimp_mmio (XlnxZynqMPState *s) { static const struct UnimpInfo {
@@ -646,6 +674,7 @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp)sysbus_connect_irq (SYS_BUS_DEVICE (&s->rtc),0 , gic_spi[RTC_IRQ ]);xlnx_zynqmp_create_bbram (s, gic_spi); +xlnx_zynqmp_create_efuse (s, gic_spi);xlnx_zynqmp_create_unimp_mmio (s);for (i =0 ; i <XLNX_ZYNQMP_NUM_GDMA_CH ; i++) {
include/hw/arm/xlnx-zynqmp.h +3 -0
@@ -37,6 +37,7 @@#include "net/can_emu.h" #include "hw/dma/xlnx_csu_dma.h" #include "hw/nvram/xlnx-bbram.h" +#include "hw/nvram/xlnx-zynqmp-efuse.h" #define TYPE_XLNX_ZYNQMP "xlnx-zynqmp"OBJECT_DECLARE_SIMPLE_TYPE (XlnxZynqMPState,XLNX_ZYNQMP )
@@ -102,6 +103,8 @@ struct XlnxZynqMPState {MemoryRegion *ddr_ram;MemoryRegion ddr_ram_low, ddr_ram_high;XlnxBBRam bbram; +XlnxEFuse efuse; +XlnxZynqMPEFuse efuse_ctrl;MemoryRegion mr_unimp[XLNX_ZYNQMP_NUM_UNIMP_AREAS ];
Signature · 1 line
2.25.1
PATCH v3 9/9 docs/system/arm: xlnx-versal-virt: BBRAM and eFUSE Usage
In reply to Tong HoAdd BBRAM and eFUSE usage to the Xilinx Versal Virt board document.
--- docs/system/arm/xlnx-versal-virt.rst | 49 ++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+)
docs/system/arm/xlnx-versal-virt.rst +49 -0
@@ -32,6 +32,8 @@ Implemented devices: - OCM (256KB of On Chip Memory) - XRAM (4MB of on chip Accelerator RAM) - DDR memory +- BBRAM (36 bytes of Battery-backed RAM) +- eFUSE (3072 bytes of one-time field-programmable bit array) QEMU does not yet model any other devices, including the PL and the AI Engine.
@@ -175,3 +177,50 @@ Run the following at the U-Boot prompt: fdt set /chosen/dom0 reg <0x00000000 0x40000000 0x0 0x03100000> booti 30000000 - 20000000 +BBRAM File Backend +"""""""""""""""""" +BBRAM can have an optional file backend, which must be a seekable +binary file with a size of 36 bytes or larger. A file with all +binary 0s is a 'blank'. + +To add a file-backend for the BBRAM: + +.. code-block:: bash + + -drive if=pflash,index=0,file=versal-bbram.bin,format=raw + +To use a different index value, N, from default of 0, add: + +.. code-block:: bash + + -global xlnx,bbram-ctrl.drive-index=N + +eFUSE File Backend +"""""""""""""""""" +eFUSE can have an optional file backend, which must be a seekable +binary file with a size of 3072 bytes or larger. A file with all +binary 0s is a 'blank'. + +To add a file-backend for the eFUSE: + +.. code-block:: bash + + -drive if=pflash,index=1,file=versal-efuse.bin,format=raw + +To use a different index value, N, from default of 1, add: + +.. code-block:: bash + + -global xlnx,efuse.drive-index=N + +.. warning:: + In actual physical Versal, BBRAM and eFUSE contain sensitive data. + The QEMU device models do **not** encrypt nor obfuscate any data + when holding them in models' memory or when writing them to their + file backends. + + Thus, a file backend should be used with caution, and 'format=luks' + is highly recommended (albeit with usage complexity). + + Better yet, do not use actual product data when running guest image + on this Xilinx Versal Virt board.
Signature · 1 line
2.25.1
Peter Maydell
AppliedQuoted 10 lines · Tong Ho
This series implements the Xilinx eFUSE and BBRAM devices for the Versal and ZynqMP product families.
Furthermore, both new devices are connected to the xlnx-versal-virt board and the xlnx-zcu102 board.
See changes in
docs/system/arm/xlnx-versal-virt.rstfor detail.---
Applied to target-arm.next, thanks.
-- PMM
Quoted 8 lines · Tong Ho
This series implements the Xilinx eFUSE and BBRAM devices for the Versal and ZynqMP product families.
Furthermore, both new devices are connected to the xlnx-versal-virt board and the xlnx-zcu102 board.
See changes in
docs/system/arm/xlnx-versal-virt.rstfor detail.
Hi -- now this has landed upstream, Coverity points out a lot of memory leaks on error or logging paths, where the code does things like:
*** CID 1464071: Resource leaks (RESOURCE_LEAK) /qemu/hw/nvram/xlnx-versal-efuse-ctrl.c: 628 in efuse_ctrl_reg_write()
622 dev = reg_array->mem.owner;
623 assert(dev);
624
625 s = XLNX_VERSAL_EFUSE_CTRL(dev);
626
627 if (addr != A_WR_LOCK && s->regs[R_WR_LOCK]) {
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
CID 1464071: Resource leaks (
RESOURCE_LEAK)
Failing to save or free storage allocated by "object_get_canonical_path((Object *)s)" leaks it.
628 qemu_log_mask(LOG_GUEST_ERROR,
629 "%s[reg_0x%02lx]: Attempt to write
locked register.\n",
630 object_get_canonical_path(OBJECT(s)), (long)addr);
631 } else {
632 register_write_memory(opaque, addr, data, size);
633 }
You need to free the memory here. A good pattern is how it's done in xlnx-zynqmp-can.c with g_autofree:
if (ARRAY_FIELD_EX32(s->regs, SOFTWARE_RESET_REGISTER, SRST)) {
g_autofree char *path = object_get_canonical_path(OBJECT(s));
qemu_log_mask(LOG_GUEST_ERROR, "%s: Attempting to transfer data while"
" data while controller is in reset mode.\n",
path);
return false;
}Could somebody send some followup patches that fix all of these, please? (There are 10 coverity issues, covering probably all of the places where object_get_canonical_path() is used in this series.)
thanks
-- PMM
Hi Peter,
I will follow up with patches to fix the memory leaks.
Where can I get a copy of the Coverity reports that have the 10 issues you indicated?
Thanks,
Tong
-----Original Message-----
From: Peter Maydell <[email protected]>
Sent: Saturday, October 2, 2021 3:28 AM
To: Tong Ho <[email protected]>
Cc: qemu-arm <[email protected]>; QEMU Developers <[email protected]>; Alistair Francis <[email protected]>; Edgar E. Iglesias <[email protected]>
Subject: Re: [PATCH v3 0/9] hw/nvram: hw/arm: Introduce Xilinx eFUSE and BBRAM
Quoted 8 lines · Tong Ho
This series implements the Xilinx eFUSE and BBRAM devices for the Versal and ZynqMP product families.
Furthermore, both new devices are connected to the xlnx-versal-virt board and the xlnx-zcu102 board.
See changes in
docs/system/arm/xlnx-versal-virt.rstfor detail.
Hi -- now this has landed upstream, Coverity points out a lot of memory leaks on error or logging paths, where the code does things like:
*** CID 1464071: Resource leaks (RESOURCE_LEAK) /qemu/hw/nvram/xlnx-versal-efuse-ctrl.c: 628 in efuse_ctrl_reg_write()
622 dev = reg_array->mem.owner;
623 assert(dev);
624
625 s = XLNX_VERSAL_EFUSE_CTRL(dev);
626
627 if (addr != A_WR_LOCK && s->regs[R_WR_LOCK]) {
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
CID 1464071: Resource leaks (
RESOURCE_LEAK)
Failing to save or free storage allocated by "object_get_canonical_path((Object *)s)" leaks it.
628 qemu_log_mask(LOG_GUEST_ERROR,
629 "%s[reg_0x%02lx]: Attempt to write
locked register.\n",
630 object_get_canonical_path(OBJECT(s)), (long)addr);
631 } else {
632 register_write_memory(opaque, addr, data, size);
633 }
You need to free the memory here. A good pattern is how it's done in xlnx-zynqmp-can.c with g_autofree:
if (ARRAY_FIELD_EX32(s->regs, SOFTWARE_RESET_REGISTER, SRST)) {
g_autofree char *path = object_get_canonical_path(OBJECT(s));
qemu_log_mask(LOG_GUEST_ERROR, "%s: Attempting to transfer data while"
" data while controller is in reset mode.\n",
path);
return false;
}Could somebody send some followup patches that fix all of these, please? (There are 10 coverity issues, covering probably all of the places where object_get_canonical_path() is used in this series.)
thanks
-- PMM
Quoted 6 lines · Tong Ho
Hi Peter,
I will follow up with patches to fix the memory leaks.
Where can I get a copy of the Coverity reports that have the 10 issues you indicated?
They're on https://scan.coverity.com/projects/qemu?tab=overview
You'll need to create an account and request access there.
-- PMM