Skip to contentSkip to conversation

hw/arm: add Beckhoff CX7200 board

PATCH Superseded Corvin Köhne 4 participants 31 messages Aug 15, 2025 – Oct 15, 2025

Subsystems (2)

v2 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v2 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 (14):
hw/timer: Make frequency configurable
hw/timer: Make PERIPHCLK period configurable hw/dma/zynq-devcfg: Handle bitstream loading via DMA to 0xffffffff hw/arm/zynq-devcfg: Prevent unintended unlock during initialization hw/dma/zynq: Ensure PCFG_DONE bit remains set to indicate PL is in
user mode
hw/dma/zynq-devcfg: Simulate dummy PL reset hw/dma/zynq-devcfg: Indicate power-up status of PL hw/dma/zynq-devcfg: Fix register memory
hw/misc: Add dummy ZYNQ DDR controller hw/misc/zynq_slcr: Add logic for DCI configuration hw/misc: Add Beckhoff CCAT device
hw/block/m25p80: Add HAS_SR_TB flag for is25lp016d hw/arm: Add new machine based on xilinx-zynq-a9 for Beckhoff CX7200 docs/system/arm: Add support for Beckhoff CX7200

 docs/system/arm/beckhoff-cx7200.rst |  57 ++++
 docs/system/target-arm.rst          |   1 +
 hw/arm/Kconfig                      |  18 ++
 hw/arm/beckhoff_CX7200.c            | 440 ++++++++++++++++++++++++++++
 hw/arm/meson.build                  |   1 +
 hw/block/m25p80.c                   |   3 +-
 hw/dma/xlnx-zynq-devcfg.c           |  29 +-
 hw/misc/Kconfig                     |   6 +
 hw/misc/beckhoff_ccat.c             | 365 +++++++++++++++++++++++
 hw/misc/meson.build                 |   2 +
 hw/misc/xlnx-zynq-ddrc.c            | 393 +++++++++++++++++++++++++
 hw/misc/zynq_slcr.c                 |  31 ++
 hw/timer/a9gtimer.c                 |  25 +-
 hw/timer/arm_mptimer.c              |  33 ++-
 include/hw/misc/xlnx-zynq-ddrc.h    | 140 +++++++++
 include/hw/timer/a9gtimer.h         |   2 +
 include/hw/timer/arm_mptimer.h      |   4 +
 17 files changed, 1538 insertions(+), 12 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
 create mode 100644 hw/misc/xlnx-zynq-ddrc.c
 create mode 100644 include/hw/misc/xlnx-zynq-ddrc.h
Signature · 1 line
2.50.1
#1 lore raw

PATCH v2 1/14 hw/timer: Make frequency configurable

From: YannickV <[email protected]>

The a9 global timer and arm mp timers rely on the PERIPHCLK as their clock source. The current implementation does not take that into account. That causes problems for applications assuming other frequencies than 1 GHz.

We can now configure frequencies for the a9 global timer and arm mp timer. By allowing these values to be set according to the application's needs, we ensure that the timers behave consistently with the expected system configuration.

The frequency can also be set via the command line, for example for the a9 global timer:
-global driver=arm.cortex-a9-global-timer,

	property=cpu-freq,value=1000000000

Information can be found in the Zynq 7000 SoC Technical Reference Manual under Timers.
https://docs.amd.com/r/en-US/ug585-zynq-7000-SoC-TRM

---
 hw/timer/a9gtimer.c            |  8 +++++---
 hw/timer/arm_mptimer.c         | 15 +++++++++++----
 include/hw/timer/a9gtimer.h    |  1 +
 include/hw/timer/arm_mptimer.h |  2 ++
 4 files changed, 19 insertions(+), 7 deletions(-)
hw/timer/a9gtimer.c +5 -3
index 9835c35483..a1f5540e75 100644
@@ -63,9 +63,9 @@ static inline int a9_gtimer_get_current_cpu(A9GTimerState *s)
 static inline uint64_t a9_gtimer_get_conv(A9GTimerState *s)
 {
     uint64_t prescale = extract32(s->control, R_CONTROL_PRESCALER_SHIFT,
-                                  R_CONTROL_PRESCALER_LEN);
-
-    return (prescale + 1) * 10;
+                                  R_CONTROL_PRESCALER_LEN) + 1;
+    uint64_t ret = NANOSECONDS_PER_SECOND * prescale * 10;
+    return (uint32_t) (ret / s->cpu_clk_freq_hz);
 }
 
 static A9GTimerUpdate a9_gtimer_get_update(A9GTimerState *s)
@@ -374,6 +374,8 @@ static const VMStateDescription vmstate_a9_gtimer = {
 };
 
 static const Property a9_gtimer_properties[] = {
+    DEFINE_PROP_UINT64("cpu-freq", A9GTimerState, cpu_clk_freq_hz,
+                       NANOSECONDS_PER_SECOND),
     DEFINE_PROP_UINT32("num-cpu", A9GTimerState, num_cpu, 0),
 };
 
hw/timer/arm_mptimer.c +11 -4
index 803dad1e8a..a748b6ab1a 100644
@@ -59,9 +59,11 @@ static inline void timerblock_update_irq(TimerBlock *tb)
 }
 
 /* Return conversion factor from mpcore timer ticks to qemu timer ticks.  */
-static inline uint32_t timerblock_scale(uint32_t control)
+static inline uint32_t timerblock_scale(TimerBlock *tb, uint32_t control)
 {
-    return (((control >> 8) & 0xff) + 1) * 10;
+    uint64_t prescale = (((control >> 8) & 0xff) + 1);
+    uint64_t ret = NANOSECONDS_PER_SECOND * prescale * 10;
+    return (uint32_t) (ret / tb->freq_hz);
 }
 
 /* Must be called within a ptimer transaction block */
@@ -155,7 +157,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));
+            ptimer_set_period(tb->timer, timerblock_scale(tb, value));
         }
         if (value & 1) {
             uint64_t count = ptimer_get_count(tb->timer);
@@ -222,7 +224,8 @@ 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));
+        ptimer_set_period(tb->timer,
+            timerblock_scale(tb, tb->control));
         ptimer_transaction_commit(tb->timer);
     }
 }
@@ -269,6 +272,7 @@ static void arm_mptimer_realize(DeviceState *dev, Error **errp)
      */
     for (i = 0; i < s->num_cpu; i++) {
         TimerBlock *tb = &s->timerblock[i];
+        tb->freq_hz = s->clk_freq_hz;
         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,
@@ -283,6 +287,7 @@ static const VMStateDescription vmstate_timerblock = {
     .minimum_version_id = 3,
     .fields = (const VMStateField[]) {
         VMSTATE_UINT32(control, TimerBlock),
+        VMSTATE_UINT64(freq_hz, TimerBlock),
         VMSTATE_UINT32(status, TimerBlock),
         VMSTATE_PTIMER(timer, TimerBlock),
         VMSTATE_END_OF_LIST()
@@ -301,6 +306,8 @@ static const VMStateDescription vmstate_arm_mptimer = {
 };
 
 static const Property arm_mptimer_properties[] = {
+    DEFINE_PROP_UINT64("clk-freq", ARMMPTimerState, clk_freq_hz,
+                       NANOSECONDS_PER_SECOND),
     DEFINE_PROP_UINT32("num-cpu", ARMMPTimerState, num_cpu, 0),
 };
 
include/hw/timer/a9gtimer.h +1 -0
index 6ae9122e4b..8ce507a793 100644
@@ -76,6 +76,7 @@ struct A9GTimerState {
 
     MemoryRegion iomem;
     /* static props */
+    uint64_t cpu_clk_freq_hz;
     uint32_t num_cpu;
 
     QEMUTimer *timer;
include/hw/timer/arm_mptimer.h +2 -0
index 65a96e2a0d..8b936cceac 100644
@@ -31,6 +31,7 @@ typedef struct {
     uint32_t control;
     uint32_t status;
     struct ptimer_state *timer;
+    uint64_t freq_hz;
     qemu_irq irq;
     MemoryRegion iomem;
 } TimerBlock;
@@ -43,6 +44,7 @@ struct ARMMPTimerState {
     SysBusDevice parent_obj;
     /*< public >*/
 
+    uint64_t clk_freq_hz;
     uint32_t num_cpu;
     TimerBlock timerblock[ARM_MPTIMER_MAX_CPUS];
     MemoryRegion iomem;
Signature · 1 line
2.50.1
#2 lore raw

Re: [PATCH v2 01/14] hw/timer: Make frequency configurable

Quoted 13 lines · Corvin Köhne

From: YannickV <[email protected]>

The a9 global timer and arm mp timers rely on the PERIPHCLK as their clock source. The current implementation does not take that into account. That causes problems for applications assuming other frequencies than 1 GHz.

We can now configure frequencies for the a9 global timer and arm mp timer. By allowing these values to be set according to the application's needs, we ensure that the timers behave consistently with the expected system configuration.

Quoted 4 lines

The frequency can also be set via the command line, for example for the a9 global timer:
-global driver=arm.cortex-a9-global-timer,

        property=cpu-freq,value=1000000000

-global is a rare thing for special cases, you don't need to mention it here. The standard case should be "the SoC configures the device correctly".

Quoted 17 lines

Information can be found in the Zynq 7000 SoC Technical Reference Manual under Timers.
https://docs.amd.com/r/en-US/ug585-zynq-7000-SoC-TRM

---
 hw/timer/a9gtimer.c            |  8 +++++---
 hw/timer/arm_mptimer.c         | 15 +++++++++++----
 include/hw/timer/a9gtimer.h    |  1 +
 include/hw/timer/arm_mptimer.h |  2 ++
 4 files changed, 19 insertions(+), 7 deletions(-)
hw/timer/a9gtimer.c +0 -0
index 9835c35483..a1f5540e75 100644

hw/timer/a9gtimer.c static inline int a9_gtimer_get_current_cpu(A9GTimerState *s) · line 68

Quoted 9 lines
hw/timer/a9gtimer.c +3 -3
@@ -63,9 +63,9 @@ static inline int a9_gtimer_get_current_cpu(A9GTimerState *s)
 static inline uint64_t a9_gtimer_get_conv(A9GTimerState *s)
 {
     uint64_t prescale = extract32(s->control, R_CONTROL_PRESCALER_SHIFT,
-                                  R_CONTROL_PRESCALER_LEN);
-
-    return (prescale + 1) * 10;
+                                  R_CONTROL_PRESCALER_LEN) + 1;
+    uint64_t ret = NANOSECONDS_PER_SECOND * prescale * 10;
+    return (uint32_t) (ret / s->cpu_clk_freq_hz);

Why the cast to uint32_t here ?

If you are doing an "x * NANOSECONDS_PER_SECOND / frequency" calculation, use muldiv64(). (This does the calculation with a 96 bit intermediate result.)

hw/timer/a9gtimer.c static const VMStateDescription vmstate_a9_gtimer = { · line 378

Quoted 9 lines
hw/timer/a9gtimer.c +2 -0
 }
 
 static A9GTimerUpdate a9_gtimer_get_update(A9GTimerState *s)
@@ -374,6 +374,8 @@ static const VMStateDescription vmstate_a9_gtimer = {
 };
 
 static const Property a9_gtimer_properties[] = {
+    DEFINE_PROP_UINT64("cpu-freq", A9GTimerState, cpu_clk_freq_hz,
+                       NANOSECONDS_PER_SECOND),

You could have a comment mentioning that this default is 1GHz.

The modern way to do this is to have a Clock property, but we have enough existing timer devices that take an integer frequency that I don't object to another one.

Quoted 49 lines
hw/timer/a9gtimer.c +0 -0
     DEFINE_PROP_UINT32("num-cpu", A9GTimerState, num_cpu, 0),
 };
 
hw/timer/arm_mptimer.c +8 -4
index 803dad1e8a..a748b6ab1a 100644
@@ -59,9 +59,11 @@ static inline void timerblock_update_irq(TimerBlock *tb)
 }
 
 /* Return conversion factor from mpcore timer ticks to qemu timer ticks.  */
-static inline uint32_t timerblock_scale(uint32_t control)
+static inline uint32_t timerblock_scale(TimerBlock *tb, uint32_t control)
 {
-    return (((control >> 8) & 0xff) + 1) * 10;
+    uint64_t prescale = (((control >> 8) & 0xff) + 1);
+    uint64_t ret = NANOSECONDS_PER_SECOND * prescale * 10;
+    return (uint32_t) (ret / tb->freq_hz);
 }
 
 /* Must be called within a ptimer transaction block */
@@ -155,7 +157,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));
+            ptimer_set_period(tb->timer, timerblock_scale(tb, value));
         }
         if (value & 1) {
             uint64_t count = ptimer_get_count(tb->timer);
@@ -222,7 +224,8 @@ 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));
+        ptimer_set_period(tb->timer,
+            timerblock_scale(tb, tb->control));
         ptimer_transaction_commit(tb->timer);
     }
 }
@@ -269,6 +272,7 @@ static void arm_mptimer_realize(DeviceState *dev, Error **errp)
      */
     for (i = 0; i < s->num_cpu; i++) {
         TimerBlock *tb = &s->timerblock[i];
+        tb->freq_hz = s->clk_freq_hz;
         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,

hw/timer/arm_mptimer.c static const VMStateDescription vmstate_timerblock = { · line 293

Quoted 7 lines
hw/timer/arm_mptimer.c +1 -0
@@ -283,6 +287,7 @@ static const VMStateDescription vmstate_timerblock = {
     .minimum_version_id = 3,
     .fields = (const VMStateField[]) {
         VMSTATE_UINT32(control, TimerBlock),
+        VMSTATE_UINT64(freq_hz, TimerBlock),
         VMSTATE_UINT32(status, TimerBlock),
         VMSTATE_PTIMER(timer, TimerBlock),
         VMSTATE_END_OF_LIST()

You cannot add fields to a VMStateDescription without doing something to handle migration compatibility. Fortunately, in this case you don't need to add the field at all -- freq_hz is a property value that cannot be updated by the guest at runtime, so it doesn't need to be saved for migration.

hw/timer/arm_mptimer.c static const VMStateDescription vmstate_arm_mptimer = { · line 310

Quoted 6 lines
hw/timer/arm_mptimer.c +2 -0
@@ -301,6 +306,8 @@ static const VMStateDescription vmstate_arm_mptimer = {
 };
 
 static const Property arm_mptimer_properties[] = {
+    DEFINE_PROP_UINT64("clk-freq", ARMMPTimerState, clk_freq_hz,
+                       NANOSECONDS_PER_SECOND),

Can we be consistent about the property name and state struct field that we use, please?

The one that seems to be most used in hw/timer/ is a property name "clock-frequency" and a field name freq_hz.

thanks
-- PMM

#4 lore raw

PATCH v2 2/14 hw/timer: Make PERIPHCLK period configurable

In reply to Corvin Köhne

From: YannickV <[email protected]>

The a9 global timer and arm mp timer rely on the PERIPHCLK as their clock source. The period of PERIPHCLK (denoted as N) must be a multiple of the core CLK period, with N being equal to or greater than two. However, the current implementation does not take the PERIPHCLK period into account, leading to unexpected behavior in systems where the application assumes PERIPHCLK is clocked differently.

The property periphclk-period represents the period N, the CLK is devided by to get the peripheral clock PERIPHCLK. We can now configure clock properties for the a9 global timer and arm mp timer. That ensures timers can behave according to the applications needs.

The PERIPHCLK period can also be set via the command line, for example for the a9 global timer:
-global driver=arm.cortex-a9-global-timer,
property=periphclk-period,value=2

Information can be found in the Zynq 7000 Soc Technical Reference Manual under Timers.
https://docs.amd.com/r/en-US/ug585-zynq-7000-SoC-TRM

---
 hw/timer/a9gtimer.c            | 19 ++++++++++++++++++-
 hw/timer/arm_mptimer.c         | 20 +++++++++++++++++++-
 include/hw/timer/a9gtimer.h    |  1 +
 include/hw/timer/arm_mptimer.h |  2 ++
 4 files changed, 40 insertions(+), 2 deletions(-)
hw/timer/a9gtimer.c +18 -1
index a1f5540e75..83aa75889e 100644
@@ -27,6 +27,7 @@
 #include "hw/timer/a9gtimer.h"
 #include "migration/vmstate.h"
 #include "qapi/error.h"
+#include "qemu/error-report.h"
 #include "qemu/timer.h"
 #include "qemu/bitops.h"
 #include "qemu/log.h"
@@ -62,9 +63,17 @@ static inline int a9_gtimer_get_current_cpu(A9GTimerState *s)
 
 static inline uint64_t a9_gtimer_get_conv(A9GTimerState *s)
 {
+    /*
+     * Referring to the ARM-Cortex-A9 MPCore TRM
+     * 
+     * The a9 global timer relies on the PERIPHCLK as its clock source.
+     * The PERIPHCLK clock period must be configured as a multiple of the
+     * main clock CLK. The conversion from the qemu clock (1GHz) to a9
+     * gtimer ticks can be calculated like this:
+     */
     uint64_t prescale = extract32(s->control, R_CONTROL_PRESCALER_SHIFT,
                                   R_CONTROL_PRESCALER_LEN) + 1;
-    uint64_t ret = NANOSECONDS_PER_SECOND * prescale * 10;
+    uint64_t ret = NANOSECONDS_PER_SECOND * prescale * s->periphclk_period;
     return (uint32_t) (ret / s->cpu_clk_freq_hz);
 }
 
@@ -312,6 +321,12 @@ static void a9_gtimer_realize(DeviceState *dev, Error **errp)
     sysbus_init_mmio(sbd, &s->iomem);
     s->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, a9_gtimer_update_no_sync, s);
 
+    if (s->periphclk_period < 2) {
+        error_report("Invalid periphclk-period (%lu), must be >= 2",
+                     s->periphclk_period);
+        exit(1);
+    }
+
     for (i = 0; i < s->num_cpu; i++) {
         A9GTimerPerCPU *gtb = &s->per_cpu[i];
 
@@ -377,6 +392,8 @@ static const Property a9_gtimer_properties[] = {
     DEFINE_PROP_UINT64("cpu-freq", A9GTimerState, cpu_clk_freq_hz,
                        NANOSECONDS_PER_SECOND),
     DEFINE_PROP_UINT32("num-cpu", A9GTimerState, num_cpu, 0),
+    DEFINE_PROP_UINT64("periphclk-period", A9GTimerState,
+                       periphclk_period, 10),
 };
 
 static void a9_gtimer_class_init(ObjectClass *klass, void *data)
hw/timer/arm_mptimer.c +19 -1
index a748b6ab1a..767413c77a 100644
@@ -27,6 +27,7 @@
 #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"
 
@@ -61,8 +62,16 @@ static inline void timerblock_update_irq(TimerBlock *tb)
 /* Return conversion factor from mpcore timer ticks to qemu timer ticks.  */
 static inline uint32_t timerblock_scale(TimerBlock *tb, uint32_t control)
 {
+    /*
+     * Referring to the ARM-Cortex-A9 MPCore TRM
+     * 
+     * The arm mp timer relies on the PERIPHCLK as its clock source.
+     * The PERIPHCLK clock period must be configured as a multiple of the
+     * main clock CLK. The conversion from the qemu clock (1GHz) to arm mp
+     * timer ticks can be calculated like this:
+     */
     uint64_t prescale = (((control >> 8) & 0xff) + 1);
-    uint64_t ret = NANOSECONDS_PER_SECOND * prescale * 10;
+    uint64_t ret = NANOSECONDS_PER_SECOND * prescale * tb->periphclk_period;
     return (uint32_t) (ret / tb->freq_hz);
 }
 
@@ -273,6 +282,12 @@ static void arm_mptimer_realize(DeviceState *dev, Error **errp)
     for (i = 0; i < s->num_cpu; i++) {
         TimerBlock *tb = &s->timerblock[i];
         tb->freq_hz = s->clk_freq_hz;
+        if (s->periphclk_period < 2) {
+            error_report("Invalid periphclk-period (%lu), must be >= 2",
+                         s->periphclk_period);
+            exit(1);
+        }
+        tb->periphclk_period = s->periphclk_period;
         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,
@@ -288,6 +303,7 @@ static const VMStateDescription vmstate_timerblock = {
     .fields = (const VMStateField[]) {
         VMSTATE_UINT32(control, TimerBlock),
         VMSTATE_UINT64(freq_hz, TimerBlock),
+        VMSTATE_UINT64(periphclk_period, TimerBlock),
         VMSTATE_UINT32(status, TimerBlock),
         VMSTATE_PTIMER(timer, TimerBlock),
         VMSTATE_END_OF_LIST()
@@ -309,6 +325,8 @@ static const Property arm_mptimer_properties[] = {
     DEFINE_PROP_UINT64("clk-freq", ARMMPTimerState, clk_freq_hz,
                        NANOSECONDS_PER_SECOND),
     DEFINE_PROP_UINT32("num-cpu", ARMMPTimerState, num_cpu, 0),
+    DEFINE_PROP_UINT64("periphclk-period", ARMMPTimerState,
+                       periphclk_period, 10),
 };
 
 static void arm_mptimer_class_init(ObjectClass *klass, void *data)
include/hw/timer/a9gtimer.h +1 -0
index 8ce507a793..edb51f91e3 100644
@@ -77,6 +77,7 @@ struct A9GTimerState {
     MemoryRegion iomem;
     /* static props */
     uint64_t cpu_clk_freq_hz;
+    uint64_t periphclk_period;
     uint32_t num_cpu;
 
     QEMUTimer *timer;
include/hw/timer/arm_mptimer.h +2 -0
index 8b936cceac..2c4cb5c1c3 100644
@@ -32,6 +32,7 @@ typedef struct {
     uint32_t status;
     struct ptimer_state *timer;
     uint64_t freq_hz;
+    uint64_t periphclk_period;
     qemu_irq irq;
     MemoryRegion iomem;
 } TimerBlock;
@@ -45,6 +46,7 @@ struct ARMMPTimerState {
     /*< public >*/
 
     uint64_t clk_freq_hz;
+    uint64_t periphclk_period;
     uint32_t num_cpu;
     TimerBlock timerblock[ARM_MPTIMER_MAX_CPUS];
     MemoryRegion iomem;
Signature · 1 line
2.50.1
#5 lore raw

Re: [PATCH v2 02/14] hw/timer: Make PERIPHCLK period configurable

Quoted 17 lines · Corvin Köhne

From: YannickV <[email protected]>

The a9 global timer and arm mp timer rely on the PERIPHCLK as their clock source. The period of PERIPHCLK (denoted as N) must be a multiple of the core CLK period, with N being equal to or greater than two. However, the current implementation does not take the PERIPHCLK period into account, leading to unexpected behavior in systems where the application assumes PERIPHCLK is clocked differently.

The property periphclk-period represents the period N, the CLK is devided by to get the peripheral clock PERIPHCLK. We can now configure clock properties for the a9 global timer and arm mp timer. That ensures timers can behave according to the applications needs.

Quoted 4 lines

The PERIPHCLK period can also be set via the command line, for example for the a9 global timer:
-global driver=arm.cortex-a9-global-timer,
property=periphclk-period,value=2

Why is the property for the main clock frequency a value in Hz but the PERIPHCLK takes a period ?

thanks
-- PMM

#6 lore raw

PATCH v2 3/14 hw/dma/zynq-devcfg: Handle bitstream loading via DMA to 0xffffffff

In reply to Corvin Köhne

From: YannickV <[email protected]>

A DMA transfer to destination address 0xffffffff should trigger a bitstream load via the PCAP interface. Currently, this case is not intercepted, causing loaders to enter an infinite loop when polling the status register.

This commit adds a check for 0xffffffff as the destination address. If detected, the relevant status register bits (DMA_DONE, DMA_P_DONE, and PCFG_DONE) are set to indicate a successful bitstream load. If the address is different, the DMA transfer proceeds as usual. A successful load is indicated but nothing is actually done. Guests relying on FPGA functions are still known to fail.

This feature is required for the integration of the Beckhoff CX7200 model.

---
 hw/dma/xlnx-zynq-devcfg.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
hw/dma/xlnx-zynq-devcfg.c +8 -1
index 0fd0d23f57..b838c1c0d0 100644
@@ -247,7 +247,14 @@ static uint64_t r_lock_pre_write(RegisterInfo *reg, uint64_t val)
 static void r_dma_dst_len_post_write(RegisterInfo *reg, uint64_t val)
 {
     XlnxZynqDevcfg *s = XLNX_ZYNQ_DEVCFG(reg->opaque);
-
+    if ((s->regs[R_DMA_DST_ADDR]) == 0xffffffff) {
+        DB_PRINT("bitstream loading detected\n");
+        s->regs[R_INT_STS] |= R_INT_STS_DMA_DONE_MASK |
+                                R_INT_STS_DMA_P_DONE_MASK |
+                                R_INT_STS_PCFG_DONE_MASK;
+        xlnx_zynq_devcfg_update_ixr(s);
+        return;
+    }
     s->dma_cmd_fifo[s->dma_cmd_fifo_num] = (XlnxZynqDevcfgDMACmd) {
             .src_addr = s->regs[R_DMA_SRC_ADDR] & ~0x3UL,
             .dest_addr = s->regs[R_DMA_DST_ADDR] & ~0x3UL,
Signature · 1 line
2.50.1
#7 lore raw

PATCH v2 4/14 hw/arm/zynq-devcfg: Prevent unintended unlock during initialization

In reply to Corvin Köhne

From: YannickV <[email protected]>

During the emulation startup, all registers are reset, which triggers the r_unlock_post_write function with a value of 0. This led to an unintended memory access disable, making the devcfg unusable.

During startup, the memory space no longer gets locked.

---
 hw/dma/xlnx-zynq-devcfg.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/dma/xlnx-zynq-devcfg.c +3 -1
index b838c1c0d0..f28d0015e6 100644
@@ -221,7 +221,9 @@ static void r_unlock_post_write(RegisterInfo *reg, uint64_t val)
 {
     XlnxZynqDevcfg *s = XLNX_ZYNQ_DEVCFG(reg->opaque);
     const char *device_prefix = object_get_typename(OBJECT(s));
-
+    if (device_is_in_reset(DEVICE(s))) {
+        return;
+    }
     if (val == R_UNLOCK_MAGIC) {
         DB_PRINT("successful unlock\n");
         s->regs[R_CTRL] |= R_CTRL_PCAP_PR_MASK;
Signature · 1 line
2.50.1
Reviewed-by on v2 4/14
#8 lore raw

Re: [PATCH v2 04/14] hw/arm/zynq-devcfg: Prevent unintended unlock during initialization

Quoted 9 lines · Corvin Köhne

From: YannickV <[email protected]>

During the emulation startup, all registers are reset, which triggers the r_unlock_post_write function with a value of 0. This led to an unintended memory access disable, making the devcfg unusable.

During startup, the memory space no longer gets locked.

Quoted 22 lines
---
 hw/dma/xlnx-zynq-devcfg.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/dma/xlnx-zynq-devcfg.c +3 -1
index b838c1c0d0..f28d0015e6 100644
@@ -221,7 +221,9 @@ static void r_unlock_post_write(RegisterInfo *reg, uint64_t val)
 {
     XlnxZynqDevcfg *s = XLNX_ZYNQ_DEVCFG(reg->opaque);
     const char *device_prefix = object_get_typename(OBJECT(s));
-
+    if (device_is_in_reset(DEVICE(s))) {
+        return;
+    }
     if (val == R_UNLOCK_MAGIC) {
         DB_PRINT("successful unlock\n");
         s->regs[R_CTRL] |= R_CTRL_PCAP_PR_MASK;
Signature · 1 line
2.50.1
#9 lore raw

PATCH v2 5/14 hw/dma/zynq: Ensure PCFG_DONE bit remains set to indicate PL is in user mode

In reply to Corvin Köhne

From: YannickV <[email protected]>

All register bits are clear on write by writing 1s to those bits, however the register bits will only be cleared if the condition that sets the interrupt flag is no longer true. Since we can assume that programming is always done, the PCFG_DONE flag is always set to 1, so it will not never be cleared.

---
 hw/dma/xlnx-zynq-devcfg.c | 2 ++
 1 file changed, 2 insertions(+)
hw/dma/xlnx-zynq-devcfg.c +2 -0
index f28d0015e6..60ea351494 100644
@@ -188,6 +188,8 @@ static void r_ixr_post_write(RegisterInfo *reg, uint64_t val)
 {
     XlnxZynqDevcfg *s = XLNX_ZYNQ_DEVCFG(reg->opaque);
 
+    s->regs[R_INT_STS] |= R_INT_STS_PCFG_DONE_MASK;
+    
     xlnx_zynq_devcfg_update_ixr(s);
 }
 
Signature · 1 line
2.50.1
Reviewed-by on v2 5/14
#10 lore raw

Re: [PATCH v2 05/14] hw/dma/zynq: Ensure PCFG_DONE bit remains set to indicate PL is in user mode

Quoted 18 lines · Corvin Köhne

From: YannickV <[email protected]>

All register bits are clear on write by writing 1s to those bits, however the register bits will only be cleared if the condition that sets the interrupt flag is no longer true. Since we can assume that programming is always done, the PCFG_DONE flag is always set to 1, so it will not never be cleared.

---
 hw/dma/xlnx-zynq-devcfg.c | 2 ++
 1 file changed, 2 insertions(+)
hw/dma/xlnx-zynq-devcfg.c +0 -0
index f28d0015e6..60ea351494 100644

hw/dma/xlnx-zynq-devcfg.c static void r_ixr_post_write(RegisterInfo *reg, uint64_t val) · line 192

Quoted 5 lines
hw/dma/xlnx-zynq-devcfg.c +2 -0
@@ -188,6 +188,8 @@ static void r_ixr_post_write(RegisterInfo *reg, uint64_t val)
 {
     XlnxZynqDevcfg *s = XLNX_ZYNQ_DEVCFG(reg->opaque);
 
+    s->regs[R_INT_STS] |= R_INT_STS_PCFG_DONE_MASK;
+    

Looks like you've got some stray spaces in the empty line.

I'm fine with this but another way to handle PCFG_DONE could be to have some state that goes true after the first programming. e.g:

s->regs[R_INT_STS] |= s->pcfg_done ? R_INT_STS_PCFG_DONE_MASK : 0;

On the other hand, for direct Linux boots we may want this to be always one...

Anyway, with the whitespace fixes:

Quoted 6 lines
hw/dma/xlnx-zynq-devcfg.c +0 -0
     xlnx_zynq_devcfg_update_ixr(s);
 }
 
Signature · 1 line
2.50.1
#11 lore raw

PATCH v2 6/14 hw/dma/zynq-devcfg: Simulate dummy PL reset

In reply to Corvin Köhne

From: YannickV <[email protected]>

Setting PCFG_PROG_B should reset the PL. After a reset PCFG_INIT should indicate that the reset is finished successfully.

In order to add a MMIO-Device as part of the PL in the Zynq, the reset logic must succeed. The PCFG_INIT flag is now set when the PL reset is triggered by PCFG_PROG_B. Indicating the reset was successful.

---
 hw/dma/xlnx-zynq-devcfg.c | 9 +++++++++
 1 file changed, 9 insertions(+)
hw/dma/xlnx-zynq-devcfg.c +9 -0
index 60ea351494..c699df6ad4 100644
@@ -49,6 +49,7 @@
 
 REG32(CTRL, 0x00)
     FIELD(CTRL,     FORCE_RST,          31,  1) /* Not supported, wr ignored */
+    FIELD(CTRL,     PCFG_PROG_B,        30,  1)
     FIELD(CTRL,     PCAP_PR,            27,  1) /* Forced to 0 on bad unlock */
     FIELD(CTRL,     PCAP_MODE,          26,  1)
     FIELD(CTRL,     MULTIBOOT_EN,       24,  1)
@@ -116,6 +117,7 @@ REG32(STATUS, 0x14)
     FIELD(STATUS,   PSS_GTS_USR_B,      11,  1)
     FIELD(STATUS,   PSS_FST_CFG_B,      10,  1)
     FIELD(STATUS,   PSS_CFG_RESET_B,     5,  1)
+    FIELD(STATUS,   PCFG_INIT,           4,  1)
 
 REG32(DMA_SRC_ADDR, 0x18)
 REG32(DMA_DST_ADDR, 0x1C)
@@ -204,6 +206,13 @@ static uint64_t r_ctrl_pre_write(RegisterInfo *reg, uint64_t val)
             val |= lock_ctrl_map[i] & s->regs[R_CTRL];
         }
     }
+
+    if (FIELD_EX32(val, CTRL, PCFG_PROG_B)) {
+        s->regs[R_STATUS] |= R_STATUS_PCFG_INIT_MASK;
+    } else {
+        s->regs[R_STATUS] &= ~R_STATUS_PCFG_INIT_MASK;
+    }
+
     return val;
 }
 
Signature · 1 line
2.50.1
Reviewed-by on v2 6/14
#12 lore raw

Re: [PATCH v2 06/14] hw/dma/zynq-devcfg: Simulate dummy PL reset

Quoted 11 lines · Corvin Köhne

From: YannickV <[email protected]>

Setting PCFG_PROG_B should reset the PL. After a reset PCFG_INIT should indicate that the reset is finished successfully.

In order to add a MMIO-Device as part of the PL in the Zynq, the reset logic must succeed. The PCFG_INIT flag is now set when the PL reset is triggered by PCFG_PROG_B. Indicating the reset was successful.

Quoted 41 lines
---
 hw/dma/xlnx-zynq-devcfg.c | 9 +++++++++
 1 file changed, 9 insertions(+)
hw/dma/xlnx-zynq-devcfg.c +9 -0
index 60ea351494..c699df6ad4 100644
@@ -49,6 +49,7 @@
 
 REG32(CTRL, 0x00)
     FIELD(CTRL,     FORCE_RST,          31,  1) /* Not supported, wr ignored */
+    FIELD(CTRL,     PCFG_PROG_B,        30,  1)
     FIELD(CTRL,     PCAP_PR,            27,  1) /* Forced to 0 on bad unlock */
     FIELD(CTRL,     PCAP_MODE,          26,  1)
     FIELD(CTRL,     MULTIBOOT_EN,       24,  1)
@@ -116,6 +117,7 @@ REG32(STATUS, 0x14)
     FIELD(STATUS,   PSS_GTS_USR_B,      11,  1)
     FIELD(STATUS,   PSS_FST_CFG_B,      10,  1)
     FIELD(STATUS,   PSS_CFG_RESET_B,     5,  1)
+    FIELD(STATUS,   PCFG_INIT,           4,  1)
 
 REG32(DMA_SRC_ADDR, 0x18)
 REG32(DMA_DST_ADDR, 0x1C)
@@ -204,6 +206,13 @@ static uint64_t r_ctrl_pre_write(RegisterInfo *reg, uint64_t val)
             val |= lock_ctrl_map[i] & s->regs[R_CTRL];
         }
     }
+
+    if (FIELD_EX32(val, CTRL, PCFG_PROG_B)) {
+        s->regs[R_STATUS] |= R_STATUS_PCFG_INIT_MASK;
+    } else {
+        s->regs[R_STATUS] &= ~R_STATUS_PCFG_INIT_MASK;
+    }
+
     return val;
 }
 
Signature · 1 line
2.50.1
#13 lore raw

PATCH v2 7/14 hw/dma/zynq-devcfg: Indicate power-up status of PL

In reply to Corvin Köhne

From: YannickV <[email protected]>

It is assumed, that the programmable logic (PL) is always powered during emulation. Therefor the PCFG_POR_B bit in the MCTRL register is set.

---
 hw/dma/xlnx-zynq-devcfg.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/dma/xlnx-zynq-devcfg.c +2 -1
index c699df6ad4..064955a0f8 100644
@@ -333,7 +333,8 @@ static const RegisterAccessInfo xlnx_zynq_devcfg_regs_info[] = {
        /* Silicon 3.0 for version field, the mysterious reserved bit 23
         * and QEMU platform identifier.
         */
-       .reset = 0x2 << R_MCTRL_PS_VERSION_SHIFT | 1 << 23 | R_MCTRL_QEMU_MASK,
+       .reset = 0x2 << R_MCTRL_PS_VERSION_SHIFT | 1 << 23 |
+                R_MCTRL_PCFG_POR_B_MASK | R_MCTRL_QEMU_MASK,
        .ro = ~R_MCTRL_INT_PCAP_LPBK_MASK,
        .rsvd = 0x00f00303,
     },
Signature · 1 line
2.50.1
Reviewed-by on v2 7/14
#14 lore raw

Re: [PATCH v2 07/14] hw/dma/zynq-devcfg: Indicate power-up status of PL

Quoted 7 lines · Corvin Köhne

From: YannickV <[email protected]>

It is assumed, that the programmable logic (PL) is always powered during emulation. Therefor the PCFG_POR_B bit in the MCTRL register is set.

Quoted 21 lines
---
 hw/dma/xlnx-zynq-devcfg.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/dma/xlnx-zynq-devcfg.c +2 -1
index c699df6ad4..064955a0f8 100644
@@ -333,7 +333,8 @@ static const RegisterAccessInfo xlnx_zynq_devcfg_regs_info[] = {
        /* Silicon 3.0 for version field, the mysterious reserved bit 23
         * and QEMU platform identifier.
         */
-       .reset = 0x2 << R_MCTRL_PS_VERSION_SHIFT | 1 << 23 | R_MCTRL_QEMU_MASK,
+       .reset = 0x2 << R_MCTRL_PS_VERSION_SHIFT | 1 << 23 |
+                R_MCTRL_PCFG_POR_B_MASK | R_MCTRL_QEMU_MASK,
        .ro = ~R_MCTRL_INT_PCAP_LPBK_MASK,
        .rsvd = 0x00f00303,
     },
Signature · 1 line
2.50.1
#15 lore raw

PATCH v2 8/14 hw/dma/zynq-devcfg: Fix register memory

In reply to Corvin Köhne

From: YannickV <[email protected]>

Registers are always 32 bit aligned. R_MAX is not the maximum register address, it is the maximum register number. The memory size can be determined by 4 * R_MAX.

Currently every register with an offset bigger than 0x40 will be ignored, because the memory size is set wrong. This effects the MCTRL register and makes it useless. This commit restores the correct behaviour.

---
 hw/dma/xlnx-zynq-devcfg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/dma/xlnx-zynq-devcfg.c +1 -1
index 064955a0f8..83570ccfaa 100644
@@ -393,7 +393,7 @@ static void xlnx_zynq_devcfg_init(Object *obj)
                               s->regs_info, s->regs,
                               &xlnx_zynq_devcfg_reg_ops,
                               XLNX_ZYNQ_DEVCFG_ERR_DEBUG,
-                              XLNX_ZYNQ_DEVCFG_R_MAX);
+                              XLNX_ZYNQ_DEVCFG_R_MAX * 4);
     memory_region_add_subregion(&s->iomem,
                                 A_CTRL,
                                 &reg_array->mem);
Signature · 1 line
2.50.1
#16 lore raw

PATCH v2 9/14 hw/misc: Add dummy ZYNQ DDR controller

In reply to Corvin Köhne

From: YannickV <[email protected]>

A dummy DDR controller for ZYNQ has been added. While all registers are present, not all are functional. Read and write access is validated, and the user mode can be set. This provides a basic DDR controller initialization, preventing system hangs due to endless polling or similar issues.

---
 hw/misc/Kconfig                  |   3 +
 hw/misc/meson.build              |   1 +
 hw/misc/xlnx-zynq-ddrc.c         | 393 +++++++++++++++++++++++++++++++
 include/hw/misc/xlnx-zynq-ddrc.h | 140 +++++++++++
 4 files changed, 537 insertions(+)
 create mode 100644 hw/misc/xlnx-zynq-ddrc.c
 create mode 100644 include/hw/misc/xlnx-zynq-ddrc.h
hw/misc/Kconfig +3 -0
index 8f9ce2f68c..99548e146f 100644
@@ -220,4 +220,7 @@ config IOSB
 config XLNX_VERSAL_TRNG
     bool
 
+config XLNX_ZYNQ_DDRC
+    bool
+
 source macio/Kconfig
hw/misc/meson.build +1 -0
index 55f493521b..6ee7b6c71d 100644
@@ -89,6 +89,7 @@ system_ss.add(when: 'CONFIG_RASPI', if_true: files(
 ))
 system_ss.add(when: 'CONFIG_SLAVIO', if_true: files('slavio_misc.c'))
 system_ss.add(when: 'CONFIG_ZYNQ', if_true: files('zynq_slcr.c'))
+system_ss.add(when: 'CONFIG_ZYNQ', if_true: files('xlnx-zynq-ddrc.c'))
 system_ss.add(when: 'CONFIG_XLNX_ZYNQMP_ARM', if_true: files('xlnx-zynqmp-crf.c'))
 system_ss.add(when: 'CONFIG_XLNX_ZYNQMP_ARM', if_true: files('xlnx-zynqmp-apu-ctrl.c'))
 system_ss.add(when: 'CONFIG_XLNX_VERSAL', if_true: files(
hw/misc/xlnx-zynq-ddrc.c new file +393 -0

393 lines not on this page · raw message

include/hw/misc/xlnx-zynq-ddrc.h new file +140 -0

140 lines not on this page · raw message

Signature · 1 line
2.50.1
#17 lore raw

Re: [PATCH v2 09/14] hw/misc: Add dummy ZYNQ DDR controller

hw/misc/xlnx-zynq-ddrc.c

Quoted 47 lines · Corvin Köhne

From: YannickV <[email protected]>

A dummy DDR controller for ZYNQ has been added. While all registers are present, not all are functional. Read and write access is validated, and the user mode can be set. This provides a basic DDR controller initialization, preventing system hangs due to endless polling or similar issues.

---
 hw/misc/Kconfig                  |   3 +
 hw/misc/meson.build              |   1 +
 hw/misc/xlnx-zynq-ddrc.c         | 393 +++++++++++++++++++++++++++++++
 include/hw/misc/xlnx-zynq-ddrc.h | 140 +++++++++++
 4 files changed, 537 insertions(+)
 create mode 100644 hw/misc/xlnx-zynq-ddrc.c
 create mode 100644 include/hw/misc/xlnx-zynq-ddrc.h
hw/misc/Kconfig +3 -0
index 8f9ce2f68c..99548e146f 100644
@@ -220,4 +220,7 @@ config IOSB
 config XLNX_VERSAL_TRNG
     bool
 
+config XLNX_ZYNQ_DDRC
+    bool
+
 source macio/Kconfig
hw/misc/meson.build +1 -0
index 55f493521b..6ee7b6c71d 100644
@@ -89,6 +89,7 @@ system_ss.add(when: 'CONFIG_RASPI', if_true: files(
 ))
 system_ss.add(when: 'CONFIG_SLAVIO', if_true: files('slavio_misc.c'))
 system_ss.add(when: 'CONFIG_ZYNQ', if_true: files('zynq_slcr.c'))
+system_ss.add(when: 'CONFIG_ZYNQ', if_true: files('xlnx-zynq-ddrc.c'))
 system_ss.add(when: 'CONFIG_XLNX_ZYNQMP_ARM', if_true: files('xlnx-zynqmp-crf.c'))
 system_ss.add(when: 'CONFIG_XLNX_ZYNQMP_ARM', if_true: files('xlnx-zynqmp-apu-ctrl.c'))
 system_ss.add(when: 'CONFIG_XLNX_VERSAL', if_true: files(
hw/misc/xlnx-zynq-ddrc.c new file +0 -0
new file mode 100644
index 0000000000..8151a0e3ee

All new files must start with a comment which at least
(a) says what the file is for and (b) has the SPDX license indicator. You can optionally also add an authorship or copyright line here if you/your employer need that.

Same applies to the .h file.

hw/misc/xlnx-zynq-ddrc.c line 378

Quoted 6 lines
hw/misc/xlnx-zynq-ddrc.c new file +6 -0
+static void zynq_ddrctrl_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    device_class_set_legacy_reset(dc, zynq_ddrctrl_reset);
+}

This looks like it's missing registration of a vmstate struct for state save/load.

thanks
-- PMM

#18 lore raw

Re: [PATCH v2 09/14] hw/misc: Add dummy ZYNQ DDR controller

Quoted 72 lines · Peter Maydell
Quoted 4 lines · Corvin Köhne

From: YannickV <[email protected]>

A dummy DDR controller for ZYNQ has been added. While all registers are

present,

Quoted 1 line

not all are functional. Read and write access is validated, and the user

mode

Quoted 1 line

can be set. This provides a basic DDR controller initialization,

preventing

Quoted 29 lines

system hangs due to endless polling or similar issues.

---
 hw/misc/Kconfig                  |   3 +
 hw/misc/meson.build              |   1 +
 hw/misc/xlnx-zynq-ddrc.c         | 393 +++++++++++++++++++++++++++++++
 include/hw/misc/xlnx-zynq-ddrc.h | 140 +++++++++++
 4 files changed, 537 insertions(+)
 create mode 100644 hw/misc/xlnx-zynq-ddrc.c
 create mode 100644 include/hw/misc/xlnx-zynq-ddrc.h
hw/misc/Kconfig +3 -0
index 8f9ce2f68c..99548e146f 100644
@@ -220,4 +220,7 @@ config IOSB
 config XLNX_VERSAL_TRNG
     bool
 
+config XLNX_ZYNQ_DDRC
+    bool
+
 source macio/Kconfig
hw/misc/meson.build +0 -0
index 55f493521b..6ee7b6c71d 100644

hw/misc/meson.build system_ss.add(when: 'CONFIG_RASPI', if_true: files( · line 93

Quoted 5 lines
hw/misc/meson.build +1 -0
@@ -89,6 +89,7 @@ system_ss.add(when: 'CONFIG_RASPI', if_true: files(
 ))
 system_ss.add(when: 'CONFIG_SLAVIO', if_true: files('slavio_misc.c'))
 system_ss.add(when: 'CONFIG_ZYNQ', if_true: files('zynq_slcr.c'))
+system_ss.add(when: 'CONFIG_ZYNQ', if_true: files('xlnx-zynq-ddrc.c'))
 system_ss.add(when: 'CONFIG_XLNX_ZYNQMP_ARM', if_true:

files('xlnx-zynqmp-crf.c'))

hw/misc/meson.build system_ss.add(when: 'CONFIG_RASPI', if_true: files( · line 94

Quoted 1 line
hw/misc/meson.build +0 -0
 system_ss.add(when: 'CONFIG_XLNX_ZYNQMP_ARM', if_true:

files('xlnx-zynqmp-apu-ctrl.c'))

hw/misc/xlnx-zynq-ddrc.c

Quoted 6 lines
hw/misc/meson.build +0 -0
 system_ss.add(when: 'CONFIG_XLNX_VERSAL', if_true: files(
hw/misc/xlnx-zynq-ddrc.c new file +0 -0
new file mode 100644
index 0000000000..8151a0e3ee

All new files must start with a comment which at least
(a) says what the file is for and (b) has the SPDX license indicator. You can optionally also add an authorship or copyright line here if you/your employer need that.

Same applies to the .h file.

hw/misc/xlnx-zynq-ddrc.c line 378

Quoted 6 lines
hw/misc/xlnx-zynq-ddrc.c new file +6 -0
+static void zynq_ddrctrl_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    device_class_set_legacy_reset(dc, zynq_ddrctrl_reset);
+}

This looks like it's missing registration of a vmstate struct for state save/load.

Quoted 3 lines

thanks
-- PMM

Except for the stuff that Peter mentions, the rest looks good to me!

Cheers,
Edgar

#19 lore raw

PATCH v2 10/14 hw/misc/zynq_slcr: Add logic for DCI configuration

In reply to Corvin Köhne

From: YannickV <[email protected]>

The registers for the digitally controlled impedance (DCI) clock are part of the system level control registers (SLCR). The DONE bit in the status register indicates a successfull DCI calibration. An description of the calibration process can be found here:
https://docs.amd.com/r/en-US/ug585-zynq-7000-SoC-TRM/DDR-IOB-Impedance-Calibration

The DCI control register and status register have been added. As soon as the ENABLE and RESET bit are set, the RESET bit has also been toggled to 0 before and the UPDATE_CONTROL is not set, the DONE bit in the status register is set. If these bits change the DONE bit is reset. Note that the option bits are not taken into consideration.

---
 hw/misc/zynq_slcr.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
hw/misc/zynq_slcr.c +31 -0
index a766bab182..8d15f0cc66 100644
@@ -180,6 +180,12 @@ REG32(GPIOB_CFG_HSTL, 0xb14)
 REG32(GPIOB_DRVR_BIAS_CTRL, 0xb18)
 
 REG32(DDRIOB, 0xb40)
+REG32(DDRIOB_DCI_CTRL, 0xb70)
+    FIELD(DDRIOB_DCI_CTRL, RESET, 0, 1)
+    FIELD(DDRIOB_DCI_CTRL, ENABLE, 1, 1)
+    FIELD(DDRIOB_DCI_CTRL, UPDATE_CONTROL, 20, 1)
+REG32(DDRIOB_DCI_STATUS, 0xb74)
+    FIELD(DDRIOB_DCI_STATUS, DONE, 13, 1)
 #define DDRIOB_LENGTH 14
 
 #define ZYNQ_SLCR_MMIO_SIZE     0x1000
@@ -193,6 +199,8 @@ struct ZynqSLCRState {
 
     MemoryRegion iomem;
 
+    bool ddriob_dci_ctrl_reset_toggled;
+
     uint32_t regs[ZYNQ_SLCR_NUM_REGS];
 
     Clock *ps_clk;
@@ -331,6 +339,8 @@ static void zynq_slcr_reset_init(Object *obj, ResetType type)
 
     DB_PRINT("RESET\n");
 
+    s->ddriob_dci_ctrl_reset_toggled = false;
+
     s->regs[R_LOCKSTA] = 1;
     /* 0x100 - 0x11C */
     s->regs[R_ARM_PLL_CTRL]   = 0x0001A008;
@@ -418,6 +428,8 @@ static void zynq_slcr_reset_init(Object *obj, ResetType type)
     s->regs[R_DDRIOB + 4] = s->regs[R_DDRIOB + 5] = s->regs[R_DDRIOB + 6]
                           = 0x00000e00;
     s->regs[R_DDRIOB + 12] = 0x00000021;
+
+    s->regs[R_DDRIOB_DCI_CTRL] = 0x00000020;
 }
 
 static void zynq_slcr_reset_hold(Object *obj, ResetType type)
@@ -554,6 +566,25 @@ static void zynq_slcr_write(void *opaque, hwaddr offset,
                 (int)offset, (unsigned)val & 0xFFFF);
         }
         return;
+
+    case R_DDRIOB_DCI_CTRL:
+        if (!FIELD_EX32(val, DDRIOB_DCI_CTRL, RESET) && 
+            FIELD_EX32(s->regs[R_DDRIOB_DCI_CTRL], DDRIOB_DCI_CTRL, RESET)) {
+
+            s->ddriob_dci_ctrl_reset_toggled = true;
+            DB_PRINT("DDRIOB DCI CTRL RESET was toggled\n");
+        }
+
+        if (FIELD_EX32(val, DDRIOB_DCI_CTRL, ENABLE) &&
+            FIELD_EX32(val, DDRIOB_DCI_CTRL, RESET) &&
+            !FIELD_EX32(val, DDRIOB_DCI_CTRL, UPDATE_CONTROL) &&
+            s->ddriob_dci_ctrl_reset_toggled) {
+
+            s->regs[R_DDRIOB_DCI_STATUS] |= R_DDRIOB_DCI_STATUS_DONE_MASK;
+        } else {
+            s->regs[R_DDRIOB_DCI_STATUS] &= ~R_DDRIOB_DCI_STATUS_DONE_MASK;
+        }
+        break;
     }
 
     if (s->regs[R_LOCKSTA]) {
Signature · 1 line
2.50.1
#20 lore raw

Re: [PATCH v2 10/14] hw/misc/zynq_slcr: Add logic for DCI configuration

Quoted 8 lines · Corvin Köhne

From: YannickV <[email protected]>

The registers for the digitally controlled impedance (DCI) clock are part of the system level control registers (SLCR). The DONE bit in the status register indicates a successfull DCI calibration. An description of the calibration process can be found here:
https://docs.amd.com/r/en-US/ug585-zynq-7000-SoC-TRM/DDR-IOB-Impedance-Calibration

Quoted 8 lines

The DCI control register and status register have been added. As soon as the ENABLE and RESET bit are set, the RESET bit has also been toggled to 0 before and the UPDATE_CONTROL is not set, the DONE bit in the status register is set. If these bits change the DONE bit is reset. Note that the option bits are not taken into consideration.

BTW, I just noticed that this patch has style problems:

e8874ea66c (HEAD, beckhoff) hw/misc/zynq_slcr: Add logic for DCI configuration

ERROR: trailing whitespace
#72: FILE: hw/misc/zynq_slcr.c:571:
+ if (!FIELD_EX32(val, DDRIOB_DCI_CTRL, RESET) && $

total: 1 errors, 0 warnings, 61 lines checked

Quoted 77 lines
---
 hw/misc/zynq_slcr.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
hw/misc/zynq_slcr.c +31 -0
index a766bab182..8d15f0cc66 100644
@@ -180,6 +180,12 @@ REG32(GPIOB_CFG_HSTL, 0xb14)
 REG32(GPIOB_DRVR_BIAS_CTRL, 0xb18)
 
 REG32(DDRIOB, 0xb40)
+REG32(DDRIOB_DCI_CTRL, 0xb70)
+    FIELD(DDRIOB_DCI_CTRL, RESET, 0, 1)
+    FIELD(DDRIOB_DCI_CTRL, ENABLE, 1, 1)
+    FIELD(DDRIOB_DCI_CTRL, UPDATE_CONTROL, 20, 1)
+REG32(DDRIOB_DCI_STATUS, 0xb74)
+    FIELD(DDRIOB_DCI_STATUS, DONE, 13, 1)
 #define DDRIOB_LENGTH 14
 
 #define ZYNQ_SLCR_MMIO_SIZE     0x1000
@@ -193,6 +199,8 @@ struct ZynqSLCRState {
 
     MemoryRegion iomem;
 
+    bool ddriob_dci_ctrl_reset_toggled;
+
     uint32_t regs[ZYNQ_SLCR_NUM_REGS];
 
     Clock *ps_clk;
@@ -331,6 +339,8 @@ static void zynq_slcr_reset_init(Object *obj, ResetType type)
 
     DB_PRINT("RESET\n");
 
+    s->ddriob_dci_ctrl_reset_toggled = false;
+
     s->regs[R_LOCKSTA] = 1;
     /* 0x100 - 0x11C */
     s->regs[R_ARM_PLL_CTRL]   = 0x0001A008;
@@ -418,6 +428,8 @@ static void zynq_slcr_reset_init(Object *obj, ResetType type)
     s->regs[R_DDRIOB + 4] = s->regs[R_DDRIOB + 5] = s->regs[R_DDRIOB + 6]
                           = 0x00000e00;
     s->regs[R_DDRIOB + 12] = 0x00000021;
+
+    s->regs[R_DDRIOB_DCI_CTRL] = 0x00000020;
 }
 
 static void zynq_slcr_reset_hold(Object *obj, ResetType type)
@@ -554,6 +566,25 @@ static void zynq_slcr_write(void *opaque, hwaddr offset,
                 (int)offset, (unsigned)val & 0xFFFF);
         }
         return;
+
+    case R_DDRIOB_DCI_CTRL:
+        if (!FIELD_EX32(val, DDRIOB_DCI_CTRL, RESET) && 
+            FIELD_EX32(s->regs[R_DDRIOB_DCI_CTRL], DDRIOB_DCI_CTRL, RESET)) {
+
+            s->ddriob_dci_ctrl_reset_toggled = true;
+            DB_PRINT("DDRIOB DCI CTRL RESET was toggled\n");
+        }
+
+        if (FIELD_EX32(val, DDRIOB_DCI_CTRL, ENABLE) &&
+            FIELD_EX32(val, DDRIOB_DCI_CTRL, RESET) &&
+            !FIELD_EX32(val, DDRIOB_DCI_CTRL, UPDATE_CONTROL) &&
+            s->ddriob_dci_ctrl_reset_toggled) {
+
+            s->regs[R_DDRIOB_DCI_STATUS] |= R_DDRIOB_DCI_STATUS_DONE_MASK;
+        } else {
+            s->regs[R_DDRIOB_DCI_STATUS] &= ~R_DDRIOB_DCI_STATUS_DONE_MASK;
+        }
+        break;
     }
 
     if (s->regs[R_LOCKSTA]) {
Signature · 1 line
2.50.1
#21 lore raw

PATCH v2 11/14 hw/misc: Add Beckhoff CCAT device

In reply to 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 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         |   3 +
 hw/misc/beckhoff_ccat.c | 365 ++++++++++++++++++++++++++++++++++++++++
 hw/misc/meson.build     |   1 +
 3 files changed, 369 insertions(+)
 create mode 100644 hw/misc/beckhoff_ccat.c
hw/misc/Kconfig +3 -0
index 99548e146f..f3a2efa350 100644
@@ -223,4 +223,7 @@ config XLNX_VERSAL_TRNG
 config XLNX_ZYNQ_DDRC
     bool
 
+config BECKHOFF_CCAT
+    bool
+
 source macio/Kconfig
hw/misc/beckhoff_ccat.c new file +365 -0

365 lines not on this page · raw message

hw/misc/meson.build +1 -0
index 6ee7b6c71d..1fc1468464 100644
@@ -14,6 +14,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.50.1
#22 lore raw

Re: [PATCH v2 11/14] hw/misc: Add Beckhoff CCAT device

Quoted 46 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 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         |   3 +
 hw/misc/beckhoff_ccat.c | 365 ++++++++++++++++++++++++++++++++++++++++
 hw/misc/meson.build     |   1 +
 3 files changed, 369 insertions(+)
 create mode 100644 hw/misc/beckhoff_ccat.c
hw/misc/Kconfig +3 -0
index 99548e146f..f3a2efa350 100644
@@ -223,4 +223,7 @@ config XLNX_VERSAL_TRNG
 config XLNX_ZYNQ_DDRC
     bool
 
+config BECKHOFF_CCAT
+    bool
+
 source macio/Kconfig
hw/misc/beckhoff_ccat.c new file +7 -0
new file mode 100644
index 0000000000..0e21962a98
@@ -0,0 +1,365 @@
+/*
+ * Beckhoff Communication Controller Emulation
+ *
+ * Copyright (c) Beckhoff Automation GmbH. & Co. KG
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the

hw/misc/beckhoff_ccat.c line 17

Quoted 10 lines
hw/misc/beckhoff_ccat.c new file +10 -0
+ * Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see <http://www.gnu.org/licenses/>.

This needs an SPDX license identifier line. If you have that, then you don't need the human-readable license blurb.

Is there a datasheet/manual for this device? The comment at the top of the file is a good place to put the URL to it.

Quoted 18 lines
hw/misc/beckhoff_ccat.c new file +18 -0
+ */
+
+#include "qemu/osdep.h"
+#include "hw/sysbus.h"
+#include "hw/register.h"
+#include "qemu/bitops.h"
+#include "qemu/log.h"
+#include "qapi/error.h"
+#include "system/block-backend.h"
+#include "exec/address-spaces.h"
+#include "exec/memory.h"
+#include "system/dma.h"
+#include "qemu/error-report.h"
+#include "block/block.h"
+#include "block/block_int.h"
+#include "block/qdict.h"
+#include "hw/block/block.h"
+

hw/misc/beckhoff_ccat.c line 45

Quoted 10 lines
hw/misc/beckhoff_ccat.c new file +10 -0
+#ifndef CCAT_ERR_DEBUG
+#define CCAT_ERR_DEBUG 0
+#endif
+
+#define DB_PRINT_L(level, ...) do { \
+    if (CCAT_ERR_DEBUG > (level)) { \
+        fprintf(stderr,  ": %s: ", __func__); \
+        fprintf(stderr, ## __VA_ARGS__); \
+    } \
+} while (0)

No debug printf macros in new code, please. Use either:
* tracepoints, for "this is information that might be interesting for somebody debugging the device or code that runs on the device"
* qemu_log_mask(LOG_UNIMP, ...), for "the guest tried to use a feature that we don't implement"
* qemu_log_mask(LOG_GUEST_ERROR, ...), for "the guest tried to do something that the datasheet says is undefined behaviour/reserved/unpredictable"

hw/misc/beckhoff_ccat.c line 51

Quoted 6 lines
hw/misc/beckhoff_ccat.c new file +6 -0
+
+#define DB_PRINT(...) DB_PRINT_L(0, ## __VA_ARGS__)
+
+#define TYPE_BECKHOFF_CCAT "beckhoff-ccat"
+#define BECKHOFF_CCAT(obj) \
+    OBJECT_CHECK(BeckhoffCcat, (obj), TYPE_BECKHOFF_CCAT)

Prefer the new-style OBJECT_DECLARE_SIMPLE_TYPE etc macros, rather than defining the cast macro yourself.

Quoted 49 lines
hw/misc/beckhoff_ccat.c new file +49 -0
+
+#define MAX_NUM_SLOTS 32
+
+#define CCAT_EEPROM_OFFSET 0x100
+#define CCAT_DMA_OFFSET 0x8000
+
+#define CCAT_MEM_SIZE 0xFFFF
+#define CCAT_DMA_SIZE 0x800
+#define CCAT_EEPROM_SIZE 0x20
+
+#define EEPROM_MEMORY_SIZE 0x1000
+
+#define EEPROM_CMD_OFFSET (CCAT_EEPROM_OFFSET + 0x00)
+    #define EEPROM_CMD_WRITE_MASK 0x2
+    #define EEPROM_CMD_READ_MASK 0x1
+#define EEPROM_ADR_OFFSET (CCAT_EEPROM_OFFSET + 0x04)
+#define EEPROM_DATA_OFFSET (CCAT_EEPROM_OFFSET + 0x08)
+
+#define DMA_BUFFER_OFFSET (CCAT_DMA_OFFSET + 0x00)
+#define DMA_DIRECTION_OFFSET (CCAT_DMA_OFFSET + 0x7c0)
+    #define DMA_DIRECTION_MASK 1
+#define DMA_TRANSFER_OFFSET (CCAT_DMA_OFFSET + 0x7c4)
+#define DMA_HOST_ADR_OFFSET (CCAT_DMA_OFFSET + 0x7c8)
+#define DMA_TRANSFER_LENGTH_OFFSET (CCAT_DMA_OFFSET + 0x7cc)
+
+/*
+ * The informationblock  is always located at address 0x0.
+ * Address and size are therefor replaced by two identifiers.
+ * The Parameter give information about the maximal number of
+ * function slots and the creation date (in this case 01.01.2001)
+ */
+#define CCAT_ID_1 0x88a4
+#define CCAT_ID_2 0x54414343
+#define CCAT_INFO_BLOCK_PARAMS (MAX_NUM_SLOTS << 0) | (0x1 << 8) | \
+                              (0x1 << 16) | (0x1 << 24)
+
+#define CCAT_FUN_TYPE_ENTRY 0x0001
+#define CCAT_FUN_TYPE_EEPROM 0x0012
+#define CCAT_FUN_TYPE_DMA 0x0013
+
+typedef struct BeckhoffCcat {
+    SysBusDevice parent_obj;
+
+    MemoryRegion iomem;
+
+    uint8_t mem[CCAT_MEM_SIZE];
+
+    BlockBackend *eeprom_blk;
+    uint8_t *eeprom_storage;

hw/misc/beckhoff_ccat.c line 110

Quoted 10 lines
hw/misc/beckhoff_ccat.c new file +10 -0
+    int64_t eeprom_size;
+} BeckhoffCcat;
+
+typedef struct __attribute__((packed)) CcatFunctionBlock {
+    uint16_t type;
+    uint16_t revision;
+    uint32_t parameter;
+    uint32_t address_offset;
+    uint32_t size;
+} CcatFunctionBlock;

"attribute((packed))" is a bit of a red flag of doing something wrong. In this case, you use this in beckhoff_ccat_reset() to set up a host C structure that you memcpy() into s->mem[]. That is not portable to big-endian systems.

Quoted 5 lines
hw/misc/beckhoff_ccat.c new file +5 -0
+
+static void sync_eeprom(BeckhoffCcat *s)
+{
+    if (!s->eeprom_blk) {
+        return;

hw/misc/beckhoff_ccat.c line 125

Quoted 10 lines
hw/misc/beckhoff_ccat.c new file +10 -0
+    }
+    blk_pwrite(s->eeprom_blk, 0, s->eeprom_size, s->eeprom_storage, 0);
+}
+
+static uint64_t beckhoff_ccat_eeprom_read(void *opaque, hwaddr addr,
+                                          unsigned size)
+{
+    BeckhoffCcat *s = opaque;
+    uint64_t val = 0;
+    memcpy(&val, &s->mem[addr], size);

What is this trying to do ? If you want to read N bytes of data in little endian order from a host address, use ldn_le_p(). (Also available in "big endian" and "host endianness" flavours.)

Quoted 10 lines
hw/misc/beckhoff_ccat.c new file +10 -0
+    return val;
+}
+
+static void beckhoff_ccat_eeprom_write(void *opaque, hwaddr addr, uint64_t val,
+                              unsigned size)
+{
+    BeckhoffCcat *s = opaque;
+    uint64_t eeprom_adr;
+    switch (addr) {
+    case EEPROM_CMD_OFFSET:

hw/misc/beckhoff_ccat.c line 145

Quoted 10 lines
hw/misc/beckhoff_ccat.c new file +10 -0
+        eeprom_adr = *(uint32_t *)&s->mem[EEPROM_ADR_OFFSET];
+        eeprom_adr = (eeprom_adr * 2) % s->eeprom_size;
+        if (val & EEPROM_CMD_READ_MASK) {
+            uint64_t buf = 0;
+            uint32_t bytes_to_read = 8;
+            if (eeprom_adr > s->eeprom_size - 8) {
+                bytes_to_read = s->eeprom_size - eeprom_adr;
+            }
+            memcpy(&buf, s->eeprom_storage + eeprom_adr, bytes_to_read);
+            *(uint64_t *)&s->mem[EEPROM_DATA_OFFSET] = buf;

All this code with casting to different pointer types and using memcpy() looks very suspicious. Use the relevant ld*_*_p() functions to load the right sized values at the right endianness. (Casting from one pointer type to another is usually an indication that you're going down a wrong path.)

Quoted 30 lines
hw/misc/beckhoff_ccat.c new file +30 -0
+
+        } else if (val & EEPROM_CMD_WRITE_MASK) {
+            uint32_t buf = *(uint32_t *)&s->mem[EEPROM_DATA_OFFSET];
+            memcpy(s->eeprom_storage + eeprom_adr, &buf, 2);
+            sync_eeprom(s);
+        }
+        break;
+    default:
+            memcpy(&s->mem[addr], &val, size);
+    }
+}
+
+static uint64_t beckhoff_ccat_dma_read(void *opaque, hwaddr addr, unsigned size)
+{
+    BeckhoffCcat *s = opaque;
+    uint64_t val = 0;
+
+    switch (addr) {
+    case DMA_TRANSFER_OFFSET:
+        if (s->mem[DMA_TRANSFER_OFFSET] & 0x1) {
+            DB_PRINT("DMA transfer finished\n");
+            s->mem[DMA_TRANSFER_OFFSET] = 0;
+        }
+        break;
+    }
+    memcpy(&val, &s->mem[addr], size);
+    return val;
+}
+
+static void beckhoff_ccat_dma_write(void *opaque, hwaddr addr, uint64_t val,

hw/misc/beckhoff_ccat.c line 185

Quoted 10 lines
hw/misc/beckhoff_ccat.c new file +10 -0
+                           unsigned size)
+{
+    BeckhoffCcat *s = opaque;
+    switch (addr) {
+    case DMA_TRANSFER_OFFSET:
+        uint8_t len = s->mem[DMA_TRANSFER_LENGTH_OFFSET];
+        uint8_t *mem_buf = &s->mem[DMA_BUFFER_OFFSET];
+
+        if (s->mem[DMA_DIRECTION_OFFSET] & DMA_DIRECTION_MASK) {
+            dma_addr_t dmaAddr = *(uint32_t *)&s->mem[DMA_HOST_ADR_OFFSET];

Should probably be ldl_le_p().

hw/misc/beckhoff_ccat.c line 191

Quoted 6 lines
hw/misc/beckhoff_ccat.c new file +6 -0
+            dma_memory_read(&address_space_memory, dmaAddr,
+                            mem_buf, len * 8, MEMTXATTRS_UNSPECIFIED);
+        } else {
+            dma_addr_t dmaAddr = *(uint32_t *)&s->mem[DMA_HOST_ADR_OFFSET];
+            dma_memory_write(&address_space_memory, dmaAddr + 8,
+                                mem_buf, len * 8, MEMTXATTRS_UNSPECIFIED);

Does this really use addr for reads and addr + 8 for writes ?

Quoted 5 lines
hw/misc/beckhoff_ccat.c new file +5 -0
+        }
+        break;
+    }
+    memcpy(&s->mem[addr], &val, size);
+}

hw/misc/beckhoff_ccat.c line 206

Quoted 10 lines
hw/misc/beckhoff_ccat.c new file +10 -0
+static uint64_t beckhoff_ccat_read(void *opaque, hwaddr addr, unsigned size)
+{
+    DB_PRINT("CCAT_READ addr=0x%lx size=%u\n", addr, size);
+
+    BeckhoffCcat *s = opaque;
+    uint64_t val = 0;
+
+    if (addr > CCAT_MEM_SIZE - size) {
+        error_report("Overflow. Address or size is too large.\n");
+        exit(1);

Don't error_report() and exit for things like this. Either:
(a) this is not possible unless there's a bug in QEMU:
in that case, use assert()
(b) this is possible if the guest does something silly:
in that case use qemu_log_mask(LOG_GUEST_ERROR, ...)

In this case it looks like an assert() is appropriate, because the memory_region_init_io() size argument should ensure that you can't get here with an addr + size that is beyond the end of the block.

Quoted 76 lines
hw/misc/beckhoff_ccat.c new file +76 -0
+    }
+
+    if (addr >= CCAT_EEPROM_OFFSET &&
+                        addr <= CCAT_EEPROM_OFFSET + s->eeprom_size) {
+        return beckhoff_ccat_eeprom_read(opaque, addr, size);
+    } else if (addr >= CCAT_DMA_OFFSET &&
+                        addr <= CCAT_DMA_OFFSET + CCAT_DMA_SIZE) {
+        return beckhoff_ccat_dma_read(opaque, addr, size);
+    } else {
+        memcpy(&val, &s->mem[addr], size);
+    }
+
+    return val;
+}
+
+static void beckhoff_ccat_write(void *opaque, hwaddr addr, uint64_t val,
+                                unsigned size)
+{
+    DB_PRINT("CCAT_WRITE addr=0x%lx size=%u val=0x%lx\n", addr, size, val);
+
+    BeckhoffCcat *s = opaque;
+
+    if (addr > CCAT_MEM_SIZE - size) {
+        error_report("Overflow. Address or size is too large.\n");
+        exit(1);
+    }
+
+    if (addr >= CCAT_EEPROM_OFFSET &&
+                        addr <= CCAT_EEPROM_OFFSET + s->eeprom_size) {
+        beckhoff_ccat_eeprom_write(opaque, addr, val, size);
+    } else if (addr >= CCAT_DMA_OFFSET &&
+                        addr <= CCAT_DMA_OFFSET + CCAT_DMA_SIZE) {
+        beckhoff_ccat_dma_write(opaque, addr, val, size);
+    } else {
+        memcpy(&s->mem[addr], &val, size);
+    }
+}
+
+static const MemoryRegionOps beckhoff_ccat_ops = {
+    .read = beckhoff_ccat_read,
+    .write = beckhoff_ccat_write,
+    .endianness = DEVICE_LITTLE_ENDIAN,
+    .valid = {
+        .min_access_size = 1,
+        .max_access_size = 8,
+    },
+};
+
+
+static void beckhoff_ccat_reset(DeviceState *dev)
+{
+    BeckhoffCcat *s = BECKHOFF_CCAT(dev);
+
+    CcatFunctionBlock function_blocks[MAX_NUM_SLOTS] = {0};
+
+    CcatFunctionBlock info_block = {
+        .type = CCAT_FUN_TYPE_ENTRY,
+        .revision = 0x0001,
+        .parameter = CCAT_INFO_BLOCK_PARAMS,
+        .address_offset = CCAT_ID_1,
+        .size = CCAT_ID_2
+    };
+    CcatFunctionBlock eeprom_block = {
+        .type = CCAT_FUN_TYPE_EEPROM,
+        .revision = 0x0001,
+        .parameter = 0,
+        .address_offset = CCAT_EEPROM_OFFSET,
+        .size = CCAT_EEPROM_SIZE
+    };
+    CcatFunctionBlock dma_block = {
+        .type = CCAT_FUN_TYPE_DMA,
+        .revision = 0x0000,
+        .parameter = 0,
+        .address_offset = CCAT_DMA_OFFSET,
+        .size = CCAT_DMA_SIZE
+    };

hw/misc/beckhoff_ccat.c line 292

Quoted 10 lines
hw/misc/beckhoff_ccat.c new file +10 -0
+
+    /*
+     * The EEPROM interface is usually at function slot 11.
+     * The DMA controller is usually at function slot 15.
+     */
+    function_blocks[0] = info_block;
+    function_blocks[11] = eeprom_block;
+    function_blocks[15] = dma_block;
+
+    memcpy(&s->mem[0], function_blocks, sizeof(function_blocks));

This isn't going to work on big-endian hosts, as noted above.

hw/misc/beckhoff_ccat.c line 300

Quoted 8 lines
hw/misc/beckhoff_ccat.c new file +8 -0
+}
+
+static void beckhoff_ccat_realize(DeviceState *dev, Error **errp)
+{
+    BeckhoffCcat *s = BECKHOFF_CCAT(dev);
+    BlockBackend *blk;
+
+    blk = blk_by_name("ccat-eeprom");

No other device calls blk_by_name() to get its block backend:
you should not do so either. Use a qdev property and have the SoC/board model set it.

hw/misc/beckhoff_ccat.c line 305

Quoted 5 lines
hw/misc/beckhoff_ccat.c new file +5 -0
+
+    if (blk) {
+        uint64_t blk_size = blk_getlength(blk);
+        if (!is_power_of_2(blk_size)) {
+            error_report("Blockend size is not a power of two.");

In a realize function you have an Error** argument, so you should report errors via error_setg() + return.

hw/misc/beckhoff_ccat.c line 312

Quoted 7 lines
hw/misc/beckhoff_ccat.c new file +7 -0
+        }
+
+        if (blk_size < 512) {
+            error_report("Blockend size is too small. Using backup.");
+            s->eeprom_size = EEPROM_MEMORY_SIZE;
+            s->eeprom_storage = blk_blockalign(NULL, s->eeprom_size);
+            memset(s->eeprom_storage, 0x00, s->eeprom_size);

We don't try to fix things up like this in other block-backed devices, I think, so we shouldn't do it here either.

hw/misc/beckhoff_ccat.c line 324

Quoted 12 lines
hw/misc/beckhoff_ccat.c new file +12 -0
+        } else {
+            DB_PRINT("EEPROM block backend found\n");
+            blk_set_perm(blk, BLK_PERM_WRITE, BLK_PERM_ALL, errp);
+
+            s->eeprom_size = blk_size;
+            s->eeprom_blk = blk;
+            s->eeprom_storage = blk_blockalign(s->eeprom_blk, s->eeprom_size);
+
+            if (!blk_check_size_and_read_all(s->eeprom_blk, DEVICE(s),
+                                             s->eeprom_storage, s->eeprom_size,
+                                             errp)) {
+                exit(1);

Don't silently exit(): use 'return', to report the error to your caller.

Quoted 15 lines
hw/misc/beckhoff_ccat.c new file +15 -0
+            }
+        }
+    } else {
+        s->eeprom_size = EEPROM_MEMORY_SIZE;
+        s->eeprom_storage = blk_blockalign(NULL, s->eeprom_size);
+        memset(s->eeprom_storage, 0x00, s->eeprom_size);
+    }
+
+    beckhoff_ccat_reset(dev);
+}
+
+static void beckhoff_ccat_init(Object *obj)
+{
+    BeckhoffCcat *s = BECKHOFF_CCAT(obj);
+    SysBusDevice *sbd = SYS_BUS_DEVICE(obj);

hw/misc/beckhoff_ccat.c line 349

Quoted 10 lines
hw/misc/beckhoff_ccat.c new file +10 -0
+
+    memory_region_init_io(&s->iomem, obj, &beckhoff_ccat_ops, s,
+                          TYPE_BECKHOFF_CCAT, CCAT_MEM_SIZE);
+    sysbus_init_mmio(sbd, &s->iomem);
+}
+
+static void beckhoff_ccat_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    dc->realize = beckhoff_ccat_realize;

The guest can read and write mem[], so I think you need a reset handler, and also a VMState for migration.

hw/misc/beckhoff_ccat.c line 350

Quoted 1 line
hw/misc/beckhoff_ccat.c new file +1 -0
+}

thanks
-- PMM

#23 lore raw

Re: [PATCH v2 11/14] hw/misc: Add Beckhoff CCAT device

Quoted 2 lines · Peter Maydell

Is there a datasheet/manual for this device? The comment at the top of the file is a good place to put the URL to it.

Unfortunately, there's no publicly available manual so far. We're currently trying to convince people to publish one. We're going to add the URL to the comment when on is available.

Best regards,
Corvin

#24 lore raw

PATCH v2 12/14 hw/block/m25p80: Add HAS_SR_TB flag for is25lp016d

In reply to Corvin Köhne

From: YannickV <[email protected]>

The is25lp016d has 4 Block Write Protect Bits. BP3 specifies whether the upper or lower range should be protected. Therefore, we add the HAS_SR_TB flag to the is25lp016d flags.

---
 hw/block/m25p80.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/block/m25p80.c +2 -1
index b84c6afb32..4c9d79ec44 100644
@@ -217,7 +217,8 @@ static const FlashPartInfo known_devices[] = {
     /* ISSI */
     { INFO("is25lq040b",  0x9d4013,      0,  64 << 10,   8, ER_4K) },
     { INFO("is25lp080d",  0x9d6014,      0,  64 << 10,  16, ER_4K) },
-    { INFO("is25lp016d",  0x9d6015,      0,  64 << 10,  32, ER_4K) },
+    { INFO("is25lp016d",  0x9d6015,      0,  64 << 10,  32,
+           ER_4K | HAS_SR_TB) },
     { INFO("is25lp032",   0x9d6016,      0,  64 << 10,  64, ER_4K) },
     { INFO("is25lp064",   0x9d6017,      0,  64 << 10, 128, ER_4K) },
     { INFO("is25lp128",   0x9d6018,      0,  64 << 10, 256, ER_4K) },
Signature · 1 line
2.50.1
#25 lore raw

PATCH v2 13/14 hw/arm: Add new machine based on xilinx-zynq-a9 for Beckhoff CX7200

In reply to Corvin Köhne

From: YannickV <[email protected]>

This commit introduces a new machine, derived from xilinx-zynq-a9. While retaining the foundational architecture, unnecessary peripherals have been removed and the remaining peripherals have been adapted to match the CX7200's hardware layout and behavior.

---
 hw/arm/Kconfig           |  18 ++
 hw/arm/beckhoff_CX7200.c | 440 +++++++++++++++++++++++++++++++++++++++
 hw/arm/meson.build       |   1 +
 3 files changed, 459 insertions(+)
 create mode 100644 hw/arm/beckhoff_CX7200.c
hw/arm/Kconfig +18 -0
index 256013ca80..66af990da9 100644
@@ -310,6 +310,24 @@ config ZYNQ
     select XILINX_SPIPS
     select ZYNQ_DEVCFG
 
+config BECKHOFF_CX7200
+    bool
+    default y
+    depends on TCG && ARM
+    select A9MPCORE
+    select CADENCE # UART
+    select PFLASH_CFI02
+    select PL310 # cache controller
+    select PL330
+    select SDHCI
+    select SSI_M25P80
+    select XILINX # UART
+    select XILINX_AXI
+    select XILINX_SPI
+    select XILINX_SPIPS
+    select ZYNQ_DEVCFG
+    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 +440 -0

440 lines not on this page · raw message

hw/arm/meson.build +1 -0
index 490234b3b8..b774b066dd 100644
@@ -17,6 +17,7 @@ arm_ss.add(when: 'CONFIG_SBSA_REF', if_true: files('sbsa-ref.c'))
 arm_ss.add(when: 'CONFIG_STELLARIS', if_true: files('stellaris.c'))
 arm_ss.add(when: 'CONFIG_STM32VLDISCOVERY', if_true: files('stm32vldiscovery.c'))
 arm_ss.add(when: 'CONFIG_ZYNQ', if_true: files('xilinx_zynq.c'))
+arm_ss.add(when: 'CONFIG_BECKHOFF_CX7200', if_true: files('beckhoff_CX7200.c'))
 arm_ss.add(when: 'CONFIG_SABRELITE', if_true: files('sabrelite.c'))
 
 arm_ss.add(when: 'CONFIG_ARM_V7M', if_true: files('armv7m.c'))
Signature · 1 line
2.50.1
#26 lore raw

PATCH v2 14/14 docs/system/arm: Add support for Beckhoff CX7200

In reply to Corvin Köhne

From: YannickV <[email protected]>

This commit offers some documentation on the Beckhoff CX7200 qemu emulation.

---
 docs/system/arm/beckhoff-cx7200.rst | 57 +++++++++++++++++++++++++++++
 docs/system/target-arm.rst          |  1 +
 2 files changed, 58 insertions(+)
 create mode 100644 docs/system/arm/beckhoff-cx7200.rst
docs/system/arm/beckhoff-cx7200.rst new file +57 -0
new file mode 100644
index 0000000000..f060319b0f
@@ -0,0 +1,57 @@
+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.
+
+More details here:
+https://docs.amd.com/r/en-US/ug585-zynq-7000-SoC-TRM/Zynq-7000-SoC-Technical-Reference-Manual
+https://www.beckhoff.com/de-de/produkte/ipc/embedded-pcs/cx7000-arm-r-cortex-r/cx7293.html
+
+The CX7200 supports following devices:
+    - A9 MPCORE
+        - cortex-a9
+        - GIC v1
+        - Generic timer
+        - wdt
+    - OCM 256KB
+    - SMC SRAM@0xe2000000 64MB
+    - Zynq SLCR
+    - SPI x2
+    - QSPI
+    - UART
+    - TTC x2
+    - Gigabit Ethernet Controller
+    - SD Controller
+    - XADC
+    - Arm PrimeCell DMA Controller
+    - DDR Memory
+    - DDR Controller
+    - Beckhoff Communication Controller (CCAT)
+        - EEPROM Interface
+        - DMA Controller
+
+Following devices are not supported:
+    - I2C
+
+Running
+"""""""
+Directly loading an ELF file to the CPU of the CX7200 to run f.e. TC/RTOS (based on FreeRTOS):
+
+.. code-block:: bash
+
+  $ qemu-system-arm -M beckhoff-cx7200 \
+        -device loader,file=CX7200_Zynq_Fsbl.elf \
+        -display none \
+        -icount shift=auto \
+
+
+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
index 9aaa9c414c..db7707725d 100644
@@ -106,6 +106,7 @@ Board-specific documentation
    arm/xlnx-versal-virt
    arm/xlnx-zynq
    arm/xlnx-zcu102
+   arm/beckhoff-cx7200
 
 Emulated CPU architecture support
 =================================
Signature · 1 line
2.50.1
#27 lore raw
In reply to Corvin Köhne
Quoted 21 lines · Corvin Köhne

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/

Quoted 16 lines

YannickV (14):
hw/timer: Make frequency configurable
hw/timer: Make PERIPHCLK period configurable hw/dma/zynq-devcfg: Handle bitstream loading via DMA to 0xffffffff hw/arm/zynq-devcfg: Prevent unintended unlock during initialization hw/dma/zynq: Ensure PCFG_DONE bit remains set to indicate PL is in
user mode
hw/dma/zynq-devcfg: Simulate dummy PL reset hw/dma/zynq-devcfg: Indicate power-up status of PL hw/dma/zynq-devcfg: Fix register memory
hw/misc: Add dummy ZYNQ DDR controller hw/misc/zynq_slcr: Add logic for DCI configuration hw/misc: Add Beckhoff CCAT device
hw/block/m25p80: Add HAS_SR_TB flag for is25lp016d hw/arm: Add new machine based on xilinx-zynq-a9 for Beckhoff CX7200 docs/system/arm: Add support for Beckhoff CX7200

This patchset is on my list to review. As an initial request, for a new board could we have a test in tests/functional/ please? This is basically a simple test that downloads a guest image from some public stable URL, runs it on QEMU, and checks for some output on the UART that indicates that it succeeded. (You can do more complex things like sending commands to the guest if you want/need to, but "does it basically boot" is the minimum bar here.) The other files in tests/functional/ should hopefully serve as examples you can pattern your test on.

thanks
-- PMM

#28 lore raw
Quoted 40 lines · Peter Maydell
Quoted 21 lines · Corvin Köhne

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/

Quoted 16 lines

YannickV (14):
hw/timer: Make frequency configurable
hw/timer: Make PERIPHCLK period configurable hw/dma/zynq-devcfg: Handle bitstream loading via DMA to 0xffffffff hw/arm/zynq-devcfg: Prevent unintended unlock during initialization hw/dma/zynq: Ensure PCFG_DONE bit remains set to indicate PL is in
user mode
hw/dma/zynq-devcfg: Simulate dummy PL reset hw/dma/zynq-devcfg: Indicate power-up status of PL hw/dma/zynq-devcfg: Fix register memory
hw/misc: Add dummy ZYNQ DDR controller hw/misc/zynq_slcr: Add logic for DCI configuration hw/misc: Add Beckhoff CCAT device
hw/block/m25p80: Add HAS_SR_TB flag for is25lp016d hw/arm: Add new machine based on xilinx-zynq-a9 for Beckhoff CX7200 docs/system/arm: Add support for Beckhoff CX7200

Quoted 3 lines

This patchset is on my list to review. As an initial request, for a new board could we have a test in tests/functional/ please?

I've also now reviewed the two initial generic-arm patches and the ones where you add new device models. I had a quick scan through the bug fix patches to the existing zynq devices but I'd appreciate it if the Xilinx folks could review those ones.

thanks
-- PMM

#29 lore raw
Quoted 45 lines · Peter Maydell
Quoted 40 lines · Peter Maydell
Quoted 21 lines · Corvin Köhne

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/

Quoted 16 lines

YannickV (14):
hw/timer: Make frequency configurable
hw/timer: Make PERIPHCLK period configurable hw/dma/zynq-devcfg: Handle bitstream loading via DMA to 0xffffffff hw/arm/zynq-devcfg: Prevent unintended unlock during initialization hw/dma/zynq: Ensure PCFG_DONE bit remains set to indicate PL is in
user mode
hw/dma/zynq-devcfg: Simulate dummy PL reset hw/dma/zynq-devcfg: Indicate power-up status of PL hw/dma/zynq-devcfg: Fix register memory
hw/misc: Add dummy ZYNQ DDR controller hw/misc/zynq_slcr: Add logic for DCI configuration hw/misc: Add Beckhoff CCAT device
hw/block/m25p80: Add HAS_SR_TB flag for is25lp016d hw/arm: Add new machine based on xilinx-zynq-a9 for Beckhoff CX7200 docs/system/arm: Add support for Beckhoff CX7200

Quoted 3 lines

This patchset is on my list to review. As an initial request, for a new board could we have a test in tests/functional/ please?

Quoted 6 lines

I've also now reviewed the two initial generic-arm patches and the ones where you add new device models. I had a quick scan through the bug fix patches to the existing zynq devices but I'd appreciate it if the Xilinx folks could review those ones.

Thanks Peter,

I reviewed patches 3 - 8 and 10.

Patch 5 and 10 have some minor whitespace issues, perhaps we could fix on commit...

f5badc6fe5 (HEAD) hw/dma/zynq: Ensure PCFG_DONE bit remains set to indicate PL is in user mode 3: ../check.sh

ERROR: trailing whitespace
#24: FILE: hw/dma/xlnx-zynq-devcfg.c:192:
+ $

total: 1 errors, 0 warnings, 8 lines checked

e8874ea66c (HEAD, beckhoff) hw/misc/zynq_slcr: Add logic for DCI configuration 7: ../check.sh

ERROR: trailing whitespace
#72: FILE: hw/misc/zynq_slcr.c:571:
+ if (!FIELD_EX32(val, DDRIOB_DCI_CTRL, RESET) && $

total: 1 errors, 0 warnings, 61 lines checked

Cheers,
Edgar

#30 lore raw
In reply to Peter Maydell
Quoted 11 lines · Peter Maydell

This patchset is on my list to review. As an initial request, for a new board could we have a test in tests/functional/ please? This is basically a simple test that downloads a guest image from some public stable URL, runs it on QEMU, and checks for some output on the UART that indicates that it succeeded. (You can do more complex things like sending commands to the guest if you want/need to, but "does it basically boot" is the minimum bar here.) The other files in tests/functional/ should hopefully serve as examples you can pattern your test on.

Quoted 2 lines

thanks
-- PMM

At the moment, there's no image for this device publicly available. However, we're working on it. We're going to add such a patch when there's a public stable URL.

Best regards,
Corvin