hw/arm: add Beckhoff CX7200 board
Subsystems (2)
PATCH v8 2/7 hw/arm/xilinx_zynq: Add flash type as machine class property
In reply to Corvin KöhneFrom: YannickV <[email protected]>
Introduce ZynqMachineClass with qspi_flash_type field to allow different Zynq-based machines to specify their flash device type. The base Zynq machine defaults to n25q128.
--- hw/arm/xilinx_zynq.c | 19 ++++++++++++++----- include/hw/arm/xilinx_zynq.h | 8 +++++++- 2 files changed, 21 insertions(+), 6 deletions(-)
hw/arm/xilinx_zynq.c +14 -5
@@ -117,7 +117,8 @@ static void gem_init(uint32_t base, qemu_irq irq) }static inline int zynq_init_spi_flashes (uint32_t base_addr,qemu_irq irq, -bool is_qspi,int unit0) +bool is_qspi,int unit0, +const char *flash_type) {int unit = unit0;DeviceState *dev;
@@ -149,7 +150,8 @@ static inline int zynq_init_spi_flashes(uint32_t base_addr, qemu_irq irq,for (j =0 ; j < num_ss; ++j) {DriveInfo *dinfo =drive_get (IF_MTD ,0 , unit++); - flash_dev =qdev_new ("n25q128" ); + + flash_dev =qdev_new (flash_type);if (dinfo) { qdev_prop_set_drive_err(flash_dev, "drive", blk_by_legacy_dinfo(dinfo),
@@ -201,6 +203,7 @@ static void ddr_ctrl_init(uint32_t base)static void zynq_init (MachineState *machine) {ZynqMachineState *zynq_machine =ZYNQ_MACHINE (machine); +ZynqMachineClass *zmc =ZYNQ_MACHINE_GET_CLASS (machine);MemoryRegion *address_space_mem =get_system_memory ();MemoryRegion *ocm_ram =g_new (MemoryRegion,1 );DeviceState *dev, *slcr;
@@ -280,9 +283,12 @@ static void zynq_init(MachineState *machine) pic[n] =qdev_get_gpio_in (dev, n); } - n =zynq_init_spi_flashes (0xE0006000 , pic[58 -GIC_INTERNAL ], false,0 ); - n =zynq_init_spi_flashes (0xE0007000 , pic[81 -GIC_INTERNAL ], false, n); - n =zynq_init_spi_flashes (0xE000D000 , pic[51 -GIC_INTERNAL ], true, n); + n =zynq_init_spi_flashes (0xE0006000 , pic[58 -GIC_INTERNAL ], false,0 , + zmc->qspi_flash_type); + n =zynq_init_spi_flashes (0xE0007000 , pic[81 -GIC_INTERNAL ], false, n, + zmc->qspi_flash_type); + n =zynq_init_spi_flashes (0xE000D000 , pic[51 -GIC_INTERNAL ], true, n, + zmc->qspi_flash_type);sysbus_create_simple (TYPE_CHIPIDEA ,0xE0002000 , pic[53 -GIC_INTERNAL ]);sysbus_create_simple (TYPE_CHIPIDEA ,0xE0003000 , pic[76 -GIC_INTERNAL ]);
@@ -458,6 +464,7 @@ static void zynq_machine_class_init(ObjectClass *oc, const void *data) NULL };MachineClass *mc =MACHINE_CLASS (oc); +ZynqMachineClass *zmc =ZYNQ_MACHINE_CLASS (oc);ObjectProperty *prop; mc->desc ="Xilinx Zynq 7000 Platform Baseboard for Cortex-A9" ; mc->init = zynq_init;
@@ -471,11 +478,13 @@ static void zynq_machine_class_init(ObjectClass *oc, const void *data)"Supported boot modes:" " jtag qspi sd nor");object_property_set_default_str (prop,"qspi" ); + zmc->qspi_flash_type ="n25q128" ; }static const TypeInfo zynq_machine_type = { .name =TYPE_ZYNQ_MACHINE , .parent =TYPE_MACHINE , + .class_size =sizeof (ZynqMachineClass), .class_init = zynq_machine_class_init, .instance_size =sizeof (ZynqMachineState), };
include/hw/arm/xilinx_zynq.h +7 -1
@@ -12,12 +12,13 @@#ifndef QEMU_ARM_ZYNQ_H #define QEMU_ARM_ZYNQ_H +#include "hw/core/boards.h" #include "target/arm/cpu-qom.h" #include "hw/core/qdev-clock.h" #include "hw/arm/boot.h" #define TYPE_ZYNQ_MACHINE MACHINE_TYPE_NAME("xilinx-zynq-a9") -OBJECT_DECLARE_SIMPLE_TYPE(ZynqMachineState, ZYNQ_MACHINE) +OBJECT_DECLARE_TYPE(ZynqMachineState, ZynqMachineClass, ZYNQ_MACHINE)#define ZYNQ_MAX_CPUS 2
@@ -29,4 +30,9 @@ struct ZynqMachineState { struct arm_boot_info bootinfo; }; +struct ZynqMachineClass { +MachineClass parent_class; +const char *qspi_flash_type; +}; +#endif /* QEMU_ARM_ZYNQ_H */
Signature · 1 line
2.47.3
v8 cover hw/arm: add Beckhoff CX7200 board
From: Corvin Köhne <[email protected]>
Hi,
Beckhoff has build a board, called CX7200, based on the Xilinx Zynq A9 platform. This commit series adds the Beckhoff CX7200 as new board variant to QEMU.
The emulation is able to successfully boot an CX7200 image. The image includes some self tests executed on every boot. Only the cache self test fails due to QEMU emulating the cache as always being coherent. The self tests include f.e.:
* Network
* Flash
* CCAT DMA + EEPROM [1]
* TwinCAT (Beckhoff's automation control software [2])
[1] https://github.com/beckhoff/ccat
[2] https://www.beckhoff.com/en-us/products/automation/
YannickV (7):
hw/misc: Add Beckhoff CCAT device
hw/arm/xilinx_zynq: Add flash type as machine class property hw/misc/zynq_slcr: Add CPU clock outputs and ratios hw/timer,cpu: Add Clock API support to A9MPCore timers hw/arm/xilinx_zynq: Make PS frequency configurable hw/arm: Add new machine based on xilinx-zynq-a9 for Beckhoff CX7200 docs/system/arm: Add support for Beckhoff CX7200
MAINTAINERS | 9 + docs/system/arm/beckhoff-cx7200.rst | 68 ++++++ docs/system/target-arm.rst | 1 + hw/arm/Kconfig | 7 + hw/arm/beckhoff_CX7200.c | 79 +++++++ hw/arm/meson.build | 1 + hw/arm/xilinx_zynq.c | 23 +- hw/cpu/a9mpcore.c | 12 + hw/misc/Kconfig | 2 + hw/misc/beckhoff_ccat.c | 347 ++++++++++++++++++++++++++++ hw/misc/meson.build | 1 + hw/misc/zynq_slcr.c | 37 +++ hw/timer/a9gtimer.c | 42 +++- hw/timer/arm_mptimer.c | 19 +- include/hw/arm/xilinx_zynq.h | 9 +- include/hw/cpu/a9mpcore.h | 1 + include/hw/timer/a9gtimer.h | 1 + include/hw/timer/arm_mptimer.h | 2 + 18 files changed, 643 insertions(+), 18 deletions(-) create mode 100644 docs/system/arm/beckhoff-cx7200.rst create mode 100644 hw/arm/beckhoff_CX7200.c create mode 100644 hw/misc/beckhoff_ccat.c
Signature · 1 line
2.47.3
PATCH v8 7/7 docs/system/arm: Add support for Beckhoff CX7200
From: YannickV <[email protected]>
This commit offers some documentation on the Beckhoff CX7200 qemu emulation.
--- docs/system/arm/beckhoff-cx7200.rst | 68 +++++++++++++++++++++++++++++ docs/system/target-arm.rst | 1 + 2 files changed, 69 insertions(+) create mode 100644 docs/system/arm/beckhoff-cx7200.rst
docs/system/arm/beckhoff-cx7200.rst new file +68 -0
@@ -0,0 +1,68 @@ +.. SPDX-License-Identifier: GPL-2.0-or-later + +Beckhoff CX7200 (``beckhoff-cx7200``) +===================================== +The Beckhoff CX7200 is based on the same architecture as the Xilinx Zynq A9. +The Zynq 7000 family is based on the AMD SoC architecture. These products +integrate a feature-rich dual or single-core Arm Cortex-A9 MPCore based +processing system (PS) and AMD programmable logic (PL) in a single device. +The Beckhoff Communication Controller (CCAT) can be found in the PL of Zynq. + +You can find more detail about this board on +`the manufacturer's product page <https://www.beckhoff.com/en-en/products/ipc/embedded-pcs/cx7000-arm-r-cortex-r/cx7293.html?>`__. +The SoC is documented in the +`Zynq 7000 Technical Reference manual <https://docs.amd.com/r/en-US/ug585-zynq-7000-SoC-TRM>`__. + +The CX7200 supports the following: + +- Arm Cortex-A9 MPCore CPU + + - Cortex-A9 CPUs + - GIC v1 interrupt controller + - Generic timer + - Watchdog timer + +- OCM 256KB +- SMC SRAM 64MB +- Zynq SLCR +- SPI x2 +- QSPI +- UART +- TTC x2 +- Gigabit Ethernet Controller x2 +- SD Controller x2 +- XADC +- Arm PrimeCell DMA Controller +- DDR Memory +- USB 2.0 x2 +- DDR Controller +- Beckhoff Communication Controller (CCAT) + + - EEPROM Interface + - DMA Controller + +The following is not supported: + +- I2C + +Running +""""""" +Directly loading an ELF file to the CPU of the CX7200 to run TC/RTOS +(based on FreeRTOS): + +.. code-block:: bash + + $ qemu-system-arm -M beckhoff-cx7200 \ + -device loader,file=CX7200_Zynq_Fsbl.elf \ + -display none + + +For setting the EEPROM content of the CCAT provide the following on the +command line: + +.. code-block:: bash + + -drive file=eeprom.bin,format=raw,id=ccat-eeprom + +The size of eeprom.bin must be aligned to a power of 2 and bigger than +256 bytes.
docs/system/target-arm.rst +1 -0
@@ -82,6 +82,7 @@ Board-specific documentation arm/aspeed arm/bananapi_m2u.rst arm/b-l475e-iot01a.rst + arm/beckhoff-cx7200 arm/sabrelite arm/digic arm/cubieboard
Signature · 1 line
2.47.3
PATCH v8 1/7 hw/misc: Add Beckhoff CCAT device
In reply to Corvin KöhneFrom: YannickV <[email protected]>
This adds the Beckhoff Communication Controller (CCAT). The information block, EEPROM interface and DMA controller are currently implemented.
The EEPROM provides production information for Beckhoff Devices. An EEPORM binary must therefor be handed over. It should be aligned to a power of two. If no EEPROM binary is handed over an empty EEPROM of size 4096 is initialized.
This device is needed for the Beckhoff CX7200 board emulation.
--- hw/misc/Kconfig | 2 + hw/misc/beckhoff_ccat.c | 347 ++++++++++++++++++++++++++++++++++++++++ hw/misc/meson.build | 1 + 3 files changed, 350 insertions(+) create mode 100644 hw/misc/beckhoff_ccat.c
hw/misc/Kconfig +2 -0
@@ -261,6 +261,8 @@ config AXIADO_CLK bool config K230_DECOMP_GZIP + +config BECKHOFF_CCAT bool source macio/Kconfig
hw/misc/beckhoff_ccat.c new file +347 -0
347 lines not on this page · raw message
hw/misc/meson.build +1 -0
@@ -16,6 +16,7 @@ system_ss.add(when: 'CONFIG_PL310', if_true: files('arm_l2x0.c')) system_ss.add(when: 'CONFIG_INTEGRATOR_DEBUG', if_true: files('arm_integrator_debug.c')) system_ss.add(when: 'CONFIG_A9SCU', if_true: files('a9scu.c')) system_ss.add(when: 'CONFIG_ARM11SCU', if_true: files('arm11scu.c')) +system_ss.add(when: 'CONFIG_BECKHOFF_CCAT', if_true: files('beckhoff_ccat.c')) system_ss.add(when: 'CONFIG_ARM_V7M', if_true: files('armv7m_ras.c'))
Signature · 1 line
2.47.3
PATCH v8 5/7 hw/arm/xilinx_zynq: Make PS frequency configurable
In reply to Corvin KöhneFrom: YannickV <[email protected]>
Add ps_clk_freq to ZynqMachineClass so derived machine types can set their own PS clock frequency instead of using the hardcoded default.
--- hw/arm/xilinx_zynq.c | 3 ++- include/hw/arm/xilinx_zynq.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-)
hw/arm/xilinx_zynq.c +2 -1
@@ -253,7 +253,7 @@ static void zynq_init(MachineState *machine)object_property_add_child (OBJECT (zynq_machine),"ps_clk" ,OBJECT (zynq_machine->ps_clk));object_unref (OBJECT (zynq_machine->ps_clk)); -clock_set_hz (zynq_machine->ps_clk,PS_CLK_FREQUENCY ); +clock_set_hz (zynq_machine->ps_clk, zmc->ps_clk_freq);/* Create slcr, keep a pointer to connect clocks */ slcr =qdev_new ("xilinx-zynq_slcr" );
@@ -480,6 +480,7 @@ static void zynq_machine_class_init(ObjectClass *oc, const void *data) " jtag qspi sd nor");object_property_set_default_str (prop,"qspi" ); zmc->qspi_flash_type ="n25q128" ; + zmc->ps_clk_freq =PS_CLK_FREQUENCY ; }static const TypeInfo zynq_machine_type = {
include/hw/arm/xilinx_zynq.h +1 -0
@@ -33,6 +33,7 @@ struct ZynqMachineState {struct ZynqMachineClass {MachineClass parent_class;const char *qspi_flash_type; +uint64_t ps_clk_freq; };#endif /* QEMU_ARM_ZYNQ_H */
Signature · 1 line
2.47.3
PATCH v8 6/7 hw/arm: Add new machine based on xilinx-zynq-a9 for Beckhoff CX7200
In reply to Corvin KöhneFrom: YannickV <[email protected]>
Introduce a new machine type 'beckhoff-cx7200' that inherits from the xilinx-zynq-a9 machine. The CX7200 is an industrial PC based on the Xilinx Zynq-7000 SoC.
The machine preserves all standard Zynq features (boot-mode selection, SPI, UART, Ethernet, etc.) while adding CX7200-specific hardware components.
--- MAINTAINERS | 9 +++++ hw/arm/Kconfig | 7 ++++ hw/arm/beckhoff_CX7200.c | 79 ++++++++++++++++++++++++++++++++++++++++ hw/arm/meson.build | 1 + 4 files changed, 96 insertions(+) create mode 100644 hw/arm/beckhoff_CX7200.c
MAINTAINERS +9 -0
@@ -1153,6 +1153,15 @@ F: include/hw/adc/zynq-xadc.h X: hw/ssi/xilinx_* F: docs/system/arm/xlnx-zynq.rst +Beckhoff CX7200 +M: Yannick Vossen <[email protected]> +M: Corvin Koehne <[email protected]> +L: [email protected] +S: Maintained +F: hw/arm/beckhoff_CX7200.c +F: hw/misc/beckhoff_ccat.c +F: include/hw/misc/beckhoff_ccat.h + Xilinx ZynqMP and Versal M: Alistair Francis <[email protected]> M: Edgar E. Iglesias <[email protected]>
hw/arm/Kconfig +7 -0
@@ -277,6 +277,13 @@ config ZYNQ select XLNX_ZYNQ_DDRC select ZYNQ_DEVCFG +config BECKHOFF_CX7200 + bool + default y + depends on TCG && ARM + select ZYNQ + select BECKHOFF_CCAT + config ARM_V7M bool # currently v7M must be included in a TCG build due to translate.c
hw/arm/beckhoff_CX7200.c new file +79 -0
79 lines not on this page · raw message
hw/arm/meson.build +1 -0
@@ -1,6 +1,7 @@ arm_common_ss = ss.source_set() arm_common_ss.add(when: 'CONFIG_ARM_VIRT', if_true: files('virt.c')) arm_common_ss.add(when: 'CONFIG_ACPI', if_true: files('virt-acpi-build.c')) +arm_common_ss.add(when: 'CONFIG_BECKHOFF_CX7200', if_true: files('beckhoff_CX7200.c')) arm_common_ss.add(when: 'CONFIG_DIGIC', if_true: files('digic_boards.c')) arm_common_ss.add(when: 'CONFIG_EMCRAFT_SF2', if_true: files('msf2-som.c')) arm_common_ss.add(when: 'CONFIG_INTEGRATOR', if_true: files('integratorcp.c'))
Signature · 1 line
2.47.3
PATCH v8 4/7 hw/timer, cpu: Add Clock API support to A9MPCore timers
In reply to Corvin KöhneFrom: YannickV <[email protected]>
Add a clock input to a9gtimer, arm_mptimer and a9mpcore. a9mpcore distributes the clock to the other timers. If no clock is connected, falls back to 100 MHz for backward compatibility with existing machine types.
Frequency calculation now uses the input clock and prescaler values according to ARM Cortex-A9 MPCore Technical Reference Manual.
More information about the A9MPCore timers can be found here:
https://developer.arm.com/documentation/ddi0407/c/timers-and-watchdog-registers?lang=en
--- hw/arm/xilinx_zynq.c | 1 + hw/cpu/a9mpcore.c | 12 ++++++++++ hw/timer/a9gtimer.c | 42 +++++++++++++++++++++++++++++----- hw/timer/arm_mptimer.c | 19 +++++++++++---- include/hw/cpu/a9mpcore.h | 1 + include/hw/timer/a9gtimer.h | 1 + include/hw/timer/arm_mptimer.h | 2 ++ 7 files changed, 67 insertions(+), 11 deletions(-)
hw/arm/xilinx_zynq.c +1 -0
@@ -265,6 +265,7 @@ static void zynq_init(MachineState *machine) dev =qdev_new (TYPE_A9MPCORE_PRIV );qdev_prop_set_uint32 (dev,"num-cpu" , smp_cpus);qdev_prop_set_uint32 (dev,"num-irq" ,GIC_EXT_IRQS +GIC_INTERNAL ); +qdev_connect_clock_in (dev,"clk" ,qdev_get_clock_out (slcr,"cpu_3x2x" )); busdev =SYS_BUS_DEVICE (dev);sysbus_realize_and_unref (busdev, &error_fatal);sysbus_mmio_map (busdev,0 ,MPCORE_PERIPHBASE );
hw/cpu/a9mpcore.c +12 -0
@@ -14,6 +14,8 @@#include "hw/cpu/a9mpcore.h" #include "hw/core/irq.h" #include "hw/core/qdev-properties.h" +#include "hw/core/qdev-clock.h" +#include "hw/core/clock.h" #include "hw/core/cpu.h" #include "target/arm/cpu-qom.h"
@@ -42,6 +44,13 @@ static void a9mp_priv_initfn(Object *obj)object_initialize_child (obj,"mptimer" , &s->mptimer,TYPE_ARM_MPTIMER );object_initialize_child (obj,"wdt" , &s->wdt,TYPE_ARM_MPTIMER ); + +/* +* Register a clock input. If no clock is connected the +* frequency falls back to 100 MHz for backward compatibility. +*/ + s->clk =qdev_init_clock_in (DEVICE (obj),"clk" ,NULL ,NULL ,0 ); +clock_set_ns (s->clk,10 ); }static void a9mp_priv_realize (DeviceState *dev,Error **errp)
@@ -103,6 +112,7 @@ static void a9mp_priv_realize(DeviceState *dev, Error **errp) gtimerdev =DEVICE (&s->gtimer);qdev_prop_set_uint32 (gtimerdev,"num-cpu" , s->num_cpu); +qdev_connect_clock_in (gtimerdev,"clk" , s->clk);if (!sysbus_realize (SYS_BUS_DEVICE (&s->gtimer), errp)) {return ; }
@@ -110,6 +120,7 @@ static void a9mp_priv_realize(DeviceState *dev, Error **errp) mptimerdev =DEVICE (&s->mptimer);qdev_prop_set_uint32 (mptimerdev,"num-cpu" , s->num_cpu); +qdev_connect_clock_in (mptimerdev,"clk" , s->clk);if (!sysbus_realize (SYS_BUS_DEVICE (&s->mptimer), errp)) {return ; }
@@ -117,6 +128,7 @@ static void a9mp_priv_realize(DeviceState *dev, Error **errp) wdtdev =DEVICE (&s->wdt);qdev_prop_set_uint32 (wdtdev,"num-cpu" , s->num_cpu); +qdev_connect_clock_in (wdtdev,"clk" , s->clk);if (!sysbus_realize (SYS_BUS_DEVICE (&s->wdt), errp)) {return ; }
hw/timer/a9gtimer.c +36 -6
80 lines not on this page · raw message
hw/timer/arm_mptimer.c +14 -5
@@ -24,9 +24,13 @@#include "hw/core/irq.h" #include "hw/core/ptimer.h" #include "hw/core/qdev-properties.h" +#include "hw/core/qdev-properties-system.h" +#include "hw/core/qdev-clock.h" +#include "hw/core/clock.h" #include "hw/timer/arm_mptimer.h" #include "migration/vmstate.h" #include "qapi/error.h" +#include "qemu/error-report.h" #include "qemu/module.h" #include "hw/core/cpu.h"
@@ -58,10 +62,12 @@ static inline void timerblock_update_irq(TimerBlock *tb)qemu_set_irq (tb->irq, tb->status && (tb->control &4 )); } -/* Return conversion factor from mpcore timer ticks to qemu timer ticks. */ -static inline uint32_t timerblock_scale (uint32_t control) +static inline void timerblock_set_period (TimerBlock *tb,uint32_t control) { -return (((control >>8 ) &0xff ) +1 ) *10 ; +uint32_t prescale = (((control >>8 ) &0xff ) +1 ); + +assert ((control &1 ) ==0 ||clock_get (tb->clk) !=0 ); +ptimer_set_period_from_clock (tb->timer, tb->clk, prescale); }/* Must be called within a ptimer transaction block */
@@ -155,7 +161,7 @@ static void timerblock_write(void *opaque, hwaddr addr,ptimer_stop (tb->timer); }if ((control &0xff00 ) != (value &0xff00 )) { -ptimer_set_period (tb->timer,timerblock_scale (value)); +timerblock_set_period (tb, value); }if (value &1 ) {uint64_t count =ptimer_get_count (tb->timer);
@@ -222,7 +228,7 @@ static void timerblock_reset(TimerBlock *tb)ptimer_transaction_begin (tb->timer);ptimer_stop (tb->timer);ptimer_set_limit (tb->timer,0 ,1 ); -ptimer_set_period (tb->timer,timerblock_scale (0 )); +timerblock_set_period (tb,0 );ptimer_transaction_commit (tb->timer); } }
@@ -244,6 +250,8 @@ static void arm_mptimer_init(Object *obj)memory_region_init_io (&s->iomem, obj, &arm_thistimer_ops, s,"arm_mptimer_timer" ,0x20 );sysbus_init_mmio (SYS_BUS_DEVICE (obj), &s->iomem); + + s->clk =qdev_init_clock_in (DEVICE (obj),"clk" ,NULL ,NULL ,0 ); }static void arm_mptimer_realize (DeviceState *dev,Error **errp)
@@ -269,6 +277,7 @@ static void arm_mptimer_realize(DeviceState *dev, Error **errp)*/ for (i =0 ; i < s->num_cpu; i++) {TimerBlock *tb = &s->timerblock[i]; + tb->clk = s->clk; tb->timer =ptimer_init (timerblock_tick, tb,PTIMER_POLICY );sysbus_init_irq (sbd, &tb->irq); memory_region_init_io(&tb->iomem, OBJECT(s), &timerblock_ops, tb,
include/hw/cpu/a9mpcore.h +1 -0
@@ -34,6 +34,7 @@ struct A9MPPrivState {A9GTimerState gtimer;ARMMPTimerState mptimer;ARMMPTimerState wdt; + Clock *clk; };#endif
include/hw/timer/a9gtimer.h +1 -0
@@ -87,6 +87,7 @@ struct A9GTimerState {uint32_t control;/* only non per cpu banked bits valid */ A9GTimerPerCPU per_cpu[A9_GTIMER_MAX_CPUS ]; +Clock *clk; }; typedef struct A9GTimerUpdate {
include/hw/timer/arm_mptimer.h +2 -0
@@ -33,6 +33,7 @@ typedef struct {struct ptimer_state *timer;qemu_irq irq;MemoryRegion iomem; +Clock *clk; } TimerBlock;#define TYPE_ARM_MPTIMER "arm_mptimer"
@@ -44,6 +45,7 @@ struct ARMMPTimerState {/*< public >*/ uint32_t num_cpu; +Clock *clk;TimerBlock timerblock[ARM_MPTIMER_MAX_CPUS ];MemoryRegion iomem; };
Signature · 1 line
2.47.3
PATCH v8 3/7 hw/misc/zynq_slcr: Add CPU clock outputs and ratios
In reply to Corvin KöhneFrom: YannickV <[email protected]>
Add CPU clock outputs and derive the related domains from the base CPU clock ratio. This makes the CPU clock domains visible and keeps their ratios consistent with the hardware clock tree.
--- hw/misc/zynq_slcr.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
hw/misc/zynq_slcr.c +37 -0
@@ -61,6 +61,13 @@ REG32(DDR_PLL_CFG, 0x114) REG32(IO_PLL_CFG, 0x118) REG32(ARM_CLK_CTRL, 0x120) +FIELD (ARM_CLK_CTRL ,CPU_PERI_CLKACT ,28 ,1 ); +FIELD (ARM_CLK_CTRL ,CPU_1XCLKACT ,27 ,1 ); +FIELD (ARM_CLK_CTRL ,CPU_2XCLKACT ,26 ,1 ); +FIELD (ARM_CLK_CTRL ,CPU_3OR2XCLKACT ,25 ,1 ); +FIELD (ARM_CLK_CTRL ,CPU_6OR4XCLKACT ,24 ,1 ); +FIELD (ARM_CLK_CTRL ,DIVISOR ,8 ,6 ); +FIELD (ARM_CLK_CTRL ,SRCSEL ,4 ,2 ); REG32(DDR_CLK_CTRL, 0x124) REG32(DCI_CLK_CTRL, 0x128)REG32 (APER_CLK_CTRL ,0x12c )
@@ -98,6 +105,7 @@ FPGA_CTRL_REGS(3, 0x1a0) REG32(BANDGAP_TRIP, 0x1b8) REG32(PLL_PREDIVISOR, 0x1c0) REG32(CLK_621_TRUE, 0x1c4) + FIELD(CLK_621_TRUE, CLK_621_TRUE, 0, 1) REG32(PSS_RST_CTRL, 0x200)FIELD (PSS_RST_CTRL ,SOFT_RST ,0 ,1 )
@@ -206,6 +214,10 @@ struct ZynqSLCRState {Clock *ps_clk;Clock *uart0_ref_clk;Clock *uart1_ref_clk; +Clock *cpu_1x; +Clock *cpu_2x; +Clock *cpu_3x2x; +Clock *cpu_6x4x;uint8_t boot_mode; };
@@ -286,14 +298,31 @@ static void zynq_slcr_compute_clocks_internal(ZynqSLCRState *s, uint64_t ps_clk)uint64_t io_pll =zynq_slcr_compute_pll (ps_clk, s->regs[R_IO_PLL_CTRL ]);uint64_t arm_pll =zynq_slcr_compute_pll (ps_clk, s->regs[R_ARM_PLL_CTRL ]);uint64_t ddr_pll =zynq_slcr_compute_pll (ps_clk, s->regs[R_DDR_PLL_CTRL ]); +uint64_t cpu_base;uint64_t uart_mux[4 ] = {io_pll, io_pll, arm_pll, ddr_pll}; +uint64_t cpu_mux[4 ] = {arm_pll, arm_pll, ddr_pll, io_pll}; + +bool use_621 =FIELD_EX32 (s->regs[R_CLK_621_TRUE ],CLK_621_TRUE , +CLK_621_TRUE ); +/* Select 6:2:1 (true) or 4:2:1 (false) CPU clock ratios. */ +uint32_t ratio_6x4x = use_621 ?6 :4 ; +uint32_t ratio_3x2x = use_621 ?3 :2 ; +/* compute uartX reference clocks */ clock_set (s->uart0_ref_clk,ZYNQ_COMPUTE_CLK (s, uart_mux,R_UART_CLK_CTRL ,CLKACT0 ));clock_set (s->uart1_ref_clk,ZYNQ_COMPUTE_CLK (s, uart_mux,R_UART_CLK_CTRL ,CLKACT1 )); + +/* Base is CPU clock (6x/4x domain). Derive other CPU domains via ratios. */ + cpu_base =ZYNQ_COMPUTE_CLK (s, cpu_mux,R_ARM_CLK_CTRL ,CPU_6OR4XCLKACT ); + +clock_set (s->cpu_6x4x, cpu_base); +clock_set (s->cpu_3x2x, cpu_base * ratio_6x4x / ratio_3x2x); +clock_set (s->cpu_2x, cpu_base * ratio_6x4x /2 ); +clock_set (s->cpu_1x, cpu_base * ratio_6x4x); }/**
@@ -322,6 +351,10 @@ static void zynq_slcr_propagate_clocks(ZynqSLCRState *s) {clock_propagate (s->uart0_ref_clk);clock_propagate (s->uart1_ref_clk); +clock_propagate (s->cpu_1x); +clock_propagate (s->cpu_2x); +clock_propagate (s->cpu_3x2x); +clock_propagate (s->cpu_6x4x); }static void zynq_slcr_ps_clk_callback (void *opaque,ClockEvent event)
@@ -619,6 +652,10 @@ static const ClockPortInitArray zynq_slcr_clocks = {QDEV_CLOCK_IN (ZynqSLCRState, ps_clk, zynq_slcr_ps_clk_callback, ClockUpdate),QDEV_CLOCK_OUT (ZynqSLCRState, uart0_ref_clk),QDEV_CLOCK_OUT (ZynqSLCRState, uart1_ref_clk), +QDEV_CLOCK_OUT (ZynqSLCRState, cpu_1x), +QDEV_CLOCK_OUT (ZynqSLCRState, cpu_2x), +QDEV_CLOCK_OUT (ZynqSLCRState, cpu_3x2x), +QDEV_CLOCK_OUT (ZynqSLCRState, cpu_6x4x), QDEV_CLOCK_END };
Signature · 1 line
2.47.3
Re: [PATCH v8 4/7] hw/timer, cpu: Add Clock API support to A9MPCore timers
In reply to Corvin KöhneQuoted 15 lines · Corvin Köhne
From: YannickV <[email protected]>
Add a clock input to a9gtimer,
arm_mptimerand a9mpcore. a9mpcore distributes the clock to the other timers. If no clock is connected, falls back to 100 MHz for backward compatibility with existing machine types.Frequency calculation now uses the input clock and prescaler values according to ARM Cortex-A9 MPCore Technical Reference Manual.
More information about the A9MPCore timers can be found here:
https://developer.arm.com/documentation/ddi0407/c/timers-and-watchdog-registers?lang=enSigned-off-by YannickV <[email protected]>
Quoted 9 lines
--- hw/arm/xilinx_zynq.c | 1 + hw/cpu/a9mpcore.c | 12 ++++++++++ hw/timer/a9gtimer.c | 42 +++++++++++++++++++++++++++++----- hw/timer/arm_mptimer.c | 19 +++++++++++---- include/hw/cpu/a9mpcore.h | 1 + include/hw/timer/a9gtimer.h | 1 + include/hw/timer/arm_mptimer.h | 2 ++ 7 files changed, 67 insertions(+), 11 deletions(-)
Where you add an input Clock to a device, you need to do something to handle migration -- see the section docs/devel/clocks.rst. For these devices, care will be required, as I think we would rather not break migration compatibility.
This patch is also adding Clock handling in multiple places at once:
* a9gtimer
* arm_mptimer
* the wrapper a9mpcore object
* the zynq board
I think these would be clearer done separately.
hw/timer/a9gtimer.c static inline int a9_gtimer_get_current_cpu(A9GTimerState *s) · line 74
Quoted 3 lines
hw/timer/a9gtimer.c +3
-0+static inline uint64_t a9_gtimer_ns_to_ticks (A9GTimerState *s,uint64_t ns) +{ +assert (!(s->control &R_CONTROL_TIMER_ENABLE ) ||clock_get (s->clk) !=0 );
It's not clear to me why you can assert this, or why it's an interesting thing to assert. Similarly below and with the equivalent-looking assert in a9mptimer.
hw/timer/a9gtimer.c static inline int a9_gtimer_get_current_cpu(A9GTimerState *s) · line 78
Quoted 4 lines
hw/timer/a9gtimer.c +4
-0+ +return clock_ns_to_ticks (s->clk, ns) / +a9_gtimer_get_prescale (s); +}
-- PMM
Re: [PATCH v8 5/7] hw/arm/xilinx_zynq: Make PS frequency configurable
In reply to Corvin KöhneQuoted 12 lines · Corvin Köhne
From: YannickV <[email protected]>
Add
ps_clk_freqto ZynqMachineClass so derived machine types can set their own PS clock frequency instead of using the hardcoded default.Signed-off-by YannickV <[email protected]>--- hw/arm/xilinx_zynq.c | 3 ++- include/hw/arm/xilinx_zynq.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-)
thanks
-- PMM
Re: [PATCH v8 3/7] hw/misc/zynq_slcr: Add CPU clock outputs and ratios
In reply to Corvin KöhneQuoted 8 lines · Corvin Köhne
From: YannickV <[email protected]>
Add CPU clock outputs and derive the related domains from the base CPU clock ratio. This makes the CPU clock domains visible and keeps their ratios consistent with the hardware clock tree.
Signed-off-by YannickV <[email protected]>
thanks
-- PMM
Re: [PATCH v8 2/7] hw/arm/xilinx_zynq: Add flash type as machine class property
In reply to Corvin KöhneQuoted 8 lines · Corvin Köhne
From: YannickV <[email protected]>
Introduce ZynqMachineClass with
qspi_flash_typefield to allow different Zynq-based machines to specify their flash device type. The base Zynq machine defaults to n25q128.Signed-off-by YannickV <[email protected]>
The commit message subject needs updating, because this isn't a machine class property. Otherwise
thanks
-- PMM
Re: [PATCH v8 1/7] hw/misc: Add Beckhoff CCAT device
In reply to Corvin KöhneQuoted 8 lines · Corvin Köhne
From: YannickV <[email protected]>
This adds the Beckhoff Communication Controller (CCAT). The information block, EEPROM interface and DMA controller are currently implemented.
The EEPROM provides production information for Beckhoff Devices. An EEPORM binary must therefor be handed over. It should be aligned to
"EEPROM"
Quoted 6 lines
a power of two. If no EEPROM binary is handed over an empty EEPROM of size 4096 is initialized.
This device is needed for the Beckhoff CX7200 board emulation.
Signed-off-by YannickV <[email protected]>
Any progress on availability of a manual/datasheet for this device?
hw/misc/beckhoff_ccat.c line 165
Quoted 13 lines
hw/misc/beckhoff_ccat.c new file +13
-0+static void beckhoff_ccat_dma_write (void *opaque,hwaddr addr,uint64_t val, +unsigned size) +{ +BeckhoffCcat *s = opaque; +dma_addr_t dma_addr; +uint8_t len; +uint8_t *mem_buf; + +switch (addr) { +case DMA_TRANSFER_OFFSET : + len = s->mem[DMA_TRANSFER_LENGTH_OFFSET ]; + mem_buf = &s->mem[DMA_BUFFER_OFFSET ]; + dma_addr =ldl_le_p (&s->mem[DMA_HOST_ADR_OFFSET ]);
If I'm reading the code correctly, the dma_memory_read/write accesses to mem_buf can't overflow the s->mem array because len is at most 255 and mem_buf isn't close enough to the end of s->mem for a 255 * 8 transfer to be able to overrun. But I think it would be helpful to add an assert() here for the benefit of readers and static analysers alike, e.g:
/*
* The DMA buffer is placed such that the worst case transfer
* cannot run off the end of the mem buffer.
*/
assert((mem_buf + len * 8) <= (s->mem + sizeof(s->mem));Quoted 6 lines
hw/misc/beckhoff_ccat.c new file +6
-0+if (s->mem[DMA_DIRECTION_OFFSET ] &DMA_DIRECTION_MASK ) { +dma_memory_read (&address_space_memory, dma_addr, + mem_buf, len *8 ,MEMTXATTRS_UNSPECIFIED ); + }else { +/* +* The write transfer uses Host DMA Address + 8 as the target
hw/misc/beckhoff_ccat.c line 181
Quoted 10 lines
hw/misc/beckhoff_ccat.c new file +10
-0+* offset, as described in the CCAT manual Version 0.0.41 +* section 20.2. +*/ +dma_memory_write (&address_space_memory, dma_addr +8 , + mem_buf, len *8 ,MEMTXATTRS_UNSPECIFIED ); + } +break ; + } +stn_le_p (&s->mem[addr], size, val); +}
Otherwise
thanks
-- PMM
Re: [PATCH v8 4/7] hw/timer, cpu: Add Clock API support to A9MPCore timers
In reply to Corvin KöhneQuoted 8 lines · Corvin Köhne
From: YannickV <[email protected]>
Add a clock input to a9gtimer,
arm_mptimerand a9mpcore. a9mpcore distributes the clock to the other timers. If no clock is connected, falls back to 100 MHz for backward compatibility with existing machine types.
Quoted 7 lines
Frequency calculation now uses the input clock and prescaler values according to ARM Cortex-A9 MPCore Technical Reference Manual.
More information about the A9MPCore timers can be found here:
https://developer.arm.com/documentation/ddi0407/c/timers-and-watchdog-registers?lang=enSigned-off-by YannickV <[email protected]>
Also, something in this commit has broken the functional test for the realview board, so "make check-functional" fails because the boot of that board hangs with no output. You can run the individual test with QEMU_TEST_QEMU_BINARY=qemu-system-arm $BUILDDIR/run tests/functional/arm/test_realview.py
(it won't have a timeout applied like that, so it just hangs).
thanks
-- PMM