qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/4] Check clock connection between STM32L4x5 RCC and peripherals
@ 2024-05-23 19:41 Inès Varhol
  2024-05-23 19:41 ` [PATCH v3 1/4] hw/misc: Create STM32L4x5 SYSCFG clock Inès Varhol
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Inès Varhol @ 2024-05-23 19:41 UTC (permalink / raw)
  To: qemu-devel
  Cc: Inès Varhol, Laurent Vivier, qemu-arm,
	Marc-André Lureau, Peter Maydell, Damien Hedde,
	Paolo Bonzini, Luc Michel, Arnaud Minier,
	Philippe Mathieu-Daudé, Thomas Huth

Among implemented STM32L4x5 devices, USART, GPIO and SYSCFG
have a clock source, but none has a corresponding test in QEMU.

This patch makes sure that all 3 devices create a clock correctly,
adds a QOM property to access clocks' periods from QTests,
and adds QTests checking that clock enable in RCC has the
expected results for all 3 devices.

Thank you for the reviews.

Changes from "v1" to v3:
- adding a commit to expose `qtest-clock-period`, a QOM property for
all clocks, only accessible from QTests, and mention it in clock.rst
- adapt QTests so that they use clock period instead of clock frequency
- remove `clock-freq-hz` QOM property in STM32L4x5 USART and SYSCFG
- dropping the commit migrating GPIO clocks as it's already upstream

Changes from v1 to an unfortunate second "v1":
- upgrading `VMStateDescription` to version 2 to account for
`VMSTATE_CLOCK()`
- QTests : consolidating `get_clock_freq_hz()` in a header
and making appropriate changes in stm32l4x5q_*-test.c

Signed-off-by: Inès Varhol <ines.varhol@telecom-paris.fr>

Inès Varhol (4):
  hw/misc: Create STM32L4x5 SYSCFG clock
  hw/char: Use v2 VMStateDescription for STM32L4x5 USART
  hw/clock: Expose 'qtest-clock-period' QOM property for QTests
  tests/qtest: Check STM32L4x5 clock connections

 docs/devel/clocks.rst               |  3 ++
 include/hw/misc/stm32l4x5_syscfg.h  |  1 +
 tests/qtest/stm32l4x5.h             | 43 +++++++++++++++++++++++++++++
 hw/arm/stm32l4x5_soc.c              |  2 ++
 hw/char/stm32l4x5_usart.c           |  4 +--
 hw/core/clock.c                     | 16 +++++++++++
 hw/misc/stm32l4x5_syscfg.c          | 19 +++++++++++--
 tests/qtest/stm32l4x5_gpio-test.c   | 23 +++++++++++++++
 tests/qtest/stm32l4x5_syscfg-test.c | 20 ++++++++++++--
 tests/qtest/stm32l4x5_usart-test.c  | 26 +++++++++++++++++
 10 files changed, 151 insertions(+), 6 deletions(-)
 create mode 100644 tests/qtest/stm32l4x5.h

-- 
2.43.2



^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v3 1/4] hw/misc: Create STM32L4x5 SYSCFG clock
  2024-05-23 19:41 [PATCH v3 0/4] Check clock connection between STM32L4x5 RCC and peripherals Inès Varhol
@ 2024-05-23 19:41 ` Inès Varhol
  2024-05-28 14:40   ` Peter Maydell
  2024-05-29  6:27   ` Philippe Mathieu-Daudé
  2024-05-23 19:41 ` [PATCH v3 2/4] hw/char: Use v2 VMStateDescription for STM32L4x5 USART Inès Varhol
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 12+ messages in thread
From: Inès Varhol @ 2024-05-23 19:41 UTC (permalink / raw)
  To: qemu-devel
  Cc: Inès Varhol, Laurent Vivier, qemu-arm,
	Marc-André Lureau, Peter Maydell, Damien Hedde,
	Paolo Bonzini, Luc Michel, Arnaud Minier,
	Philippe Mathieu-Daudé, Thomas Huth

This commit creates a clock in STM32L4x5 SYSCFG and wires it up to the
corresponding clock from STM32L4x5 RCC.

Signed-off-by: Inès Varhol <ines.varhol@telecom-paris.fr>
---
 include/hw/misc/stm32l4x5_syscfg.h |  1 +
 hw/arm/stm32l4x5_soc.c             |  2 ++
 hw/misc/stm32l4x5_syscfg.c         | 19 +++++++++++++++++--
 3 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/include/hw/misc/stm32l4x5_syscfg.h b/include/hw/misc/stm32l4x5_syscfg.h
index 23bb564150..c450df2b9e 100644
--- a/include/hw/misc/stm32l4x5_syscfg.h
+++ b/include/hw/misc/stm32l4x5_syscfg.h
@@ -48,6 +48,7 @@ struct Stm32l4x5SyscfgState {
     uint32_t swpr2;
 
     qemu_irq gpio_out[GPIO_NUM_PINS];
+    Clock *clk;
 };
 
 #endif
diff --git a/hw/arm/stm32l4x5_soc.c b/hw/arm/stm32l4x5_soc.c
index 38f7a2d5d9..fb2afa6cfe 100644
--- a/hw/arm/stm32l4x5_soc.c
+++ b/hw/arm/stm32l4x5_soc.c
@@ -236,6 +236,8 @@ static void stm32l4x5_soc_realize(DeviceState *dev_soc, Error **errp)
 
     /* System configuration controller */
     busdev = SYS_BUS_DEVICE(&s->syscfg);
+    qdev_connect_clock_in(DEVICE(&s->syscfg), "clk",
+        qdev_get_clock_out(DEVICE(&(s->rcc)), "syscfg-out"));
     if (!sysbus_realize(busdev, errp)) {
         return;
     }
diff --git a/hw/misc/stm32l4x5_syscfg.c b/hw/misc/stm32l4x5_syscfg.c
index a5a1ce2680..a947a9e036 100644
--- a/hw/misc/stm32l4x5_syscfg.c
+++ b/hw/misc/stm32l4x5_syscfg.c
@@ -26,6 +26,9 @@
 #include "trace.h"
 #include "hw/irq.h"
 #include "migration/vmstate.h"
+#include "hw/clock.h"
+#include "hw/qdev-clock.h"
+#include "qapi/error.h"
 #include "hw/misc/stm32l4x5_syscfg.h"
 #include "hw/gpio/stm32l4x5_gpio.h"
 
@@ -225,12 +228,22 @@ static void stm32l4x5_syscfg_init(Object *obj)
     qdev_init_gpio_in(DEVICE(obj), stm32l4x5_syscfg_set_irq,
                       GPIO_NUM_PINS * NUM_GPIOS);
     qdev_init_gpio_out(DEVICE(obj), s->gpio_out, GPIO_NUM_PINS);
+    s->clk = qdev_init_clock_in(DEVICE(s), "clk", NULL, s, 0);
+}
+
+static void stm32l4x5_syscfg_realize(DeviceState *dev, Error **errp)
+{
+    Stm32l4x5SyscfgState *s = STM32L4X5_SYSCFG(dev);
+    if (!clock_has_source(s->clk)) {
+        error_setg(errp, "SYSCFG: clk input must be connected");
+        return;
+    }
 }
 
 static const VMStateDescription vmstate_stm32l4x5_syscfg = {
     .name = TYPE_STM32L4X5_SYSCFG,
-    .version_id = 1,
-    .minimum_version_id = 1,
+    .version_id = 2,
+    .minimum_version_id = 2,
     .fields = (VMStateField[]) {
         VMSTATE_UINT32(memrmp, Stm32l4x5SyscfgState),
         VMSTATE_UINT32(cfgr1, Stm32l4x5SyscfgState),
@@ -241,6 +254,7 @@ static const VMStateDescription vmstate_stm32l4x5_syscfg = {
         VMSTATE_UINT32(swpr, Stm32l4x5SyscfgState),
         VMSTATE_UINT32(skr, Stm32l4x5SyscfgState),
         VMSTATE_UINT32(swpr2, Stm32l4x5SyscfgState),
+        VMSTATE_CLOCK(clk, Stm32l4x5SyscfgState),
         VMSTATE_END_OF_LIST()
     }
 };
@@ -251,6 +265,7 @@ static void stm32l4x5_syscfg_class_init(ObjectClass *klass, void *data)
     ResettableClass *rc = RESETTABLE_CLASS(klass);
 
     dc->vmsd = &vmstate_stm32l4x5_syscfg;
+    dc->realize = stm32l4x5_syscfg_realize;
     rc->phases.hold = stm32l4x5_syscfg_hold_reset;
 }
 
-- 
2.43.2



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v3 2/4] hw/char: Use v2 VMStateDescription for STM32L4x5 USART
  2024-05-23 19:41 [PATCH v3 0/4] Check clock connection between STM32L4x5 RCC and peripherals Inès Varhol
  2024-05-23 19:41 ` [PATCH v3 1/4] hw/misc: Create STM32L4x5 SYSCFG clock Inès Varhol
@ 2024-05-23 19:41 ` Inès Varhol
  2024-05-28 14:39   ` Peter Maydell
  2024-05-23 19:41 ` [PATCH v3 3/4] hw/clock: Expose 'qtest-clock-period' QOM property for QTests Inès Varhol
  2024-05-23 19:41 ` [PATCH v3 4/4] tests/qtest: Check STM32L4x5 clock connections Inès Varhol
  3 siblings, 1 reply; 12+ messages in thread
From: Inès Varhol @ 2024-05-23 19:41 UTC (permalink / raw)
  To: qemu-devel
  Cc: Inès Varhol, Laurent Vivier, qemu-arm,
	Marc-André Lureau, Peter Maydell, Damien Hedde,
	Paolo Bonzini, Luc Michel, Arnaud Minier,
	Philippe Mathieu-Daudé, Thomas Huth

`vmstate_stm32l4x5_usart_base` namely uses `VMSTATE_CLOCK` so
version needs to be 2.

Signed-off-by: Inès Varhol <ines.varhol@telecom-paris.fr>
---
 hw/char/stm32l4x5_usart.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/char/stm32l4x5_usart.c b/hw/char/stm32l4x5_usart.c
index 02f666308c..0f16f0917a 100644
--- a/hw/char/stm32l4x5_usart.c
+++ b/hw/char/stm32l4x5_usart.c
@@ -546,8 +546,8 @@ static int stm32l4x5_usart_base_post_load(void *opaque, int version_id)
 
 static const VMStateDescription vmstate_stm32l4x5_usart_base = {
     .name = TYPE_STM32L4X5_USART_BASE,
-    .version_id = 1,
-    .minimum_version_id = 1,
+    .version_id = 2,
+    .minimum_version_id = 2,
     .post_load = stm32l4x5_usart_base_post_load,
     .fields = (VMStateField[]) {
         VMSTATE_UINT32(cr1, Stm32l4x5UsartBaseState),
-- 
2.43.2



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v3 3/4] hw/clock: Expose 'qtest-clock-period' QOM property for QTests
  2024-05-23 19:41 [PATCH v3 0/4] Check clock connection between STM32L4x5 RCC and peripherals Inès Varhol
  2024-05-23 19:41 ` [PATCH v3 1/4] hw/misc: Create STM32L4x5 SYSCFG clock Inès Varhol
  2024-05-23 19:41 ` [PATCH v3 2/4] hw/char: Use v2 VMStateDescription for STM32L4x5 USART Inès Varhol
@ 2024-05-23 19:41 ` Inès Varhol
  2024-05-27  7:04   ` Luc Michel
                     ` (2 more replies)
  2024-05-23 19:41 ` [PATCH v3 4/4] tests/qtest: Check STM32L4x5 clock connections Inès Varhol
  3 siblings, 3 replies; 12+ messages in thread
From: Inès Varhol @ 2024-05-23 19:41 UTC (permalink / raw)
  To: qemu-devel
  Cc: Inès Varhol, Laurent Vivier, qemu-arm,
	Marc-André Lureau, Peter Maydell, Damien Hedde,
	Paolo Bonzini, Luc Michel, Arnaud Minier,
	Philippe Mathieu-Daudé, Thomas Huth

Expose the clock period via the QOM 'qtest-clock-period' property so it
can be used in QTests. This property is only accessible in QTests (not
via HMP).

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Inès Varhol <ines.varhol@telecom-paris.fr>
---
 docs/devel/clocks.rst |  3 +++
 hw/core/clock.c       | 16 ++++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/docs/devel/clocks.rst b/docs/devel/clocks.rst
index 177ee1c90d..19e67601ec 100644
--- a/docs/devel/clocks.rst
+++ b/docs/devel/clocks.rst
@@ -358,6 +358,9 @@ humans (for instance in debugging), use ``clock_display_freq()``,
 which returns a prettified string-representation, e.g. "33.3 MHz".
 The caller must free the string with g_free() after use.
 
+It's also possible to retrieve the clock period from a QTest by
+accessing QOM property ``qtest-clock-period`` using a QMP command.
+
 Calculating expiry deadlines
 ----------------------------
 
diff --git a/hw/core/clock.c b/hw/core/clock.c
index e212865307..216b54b8df 100644
--- a/hw/core/clock.c
+++ b/hw/core/clock.c
@@ -13,6 +13,8 @@
 
 #include "qemu/osdep.h"
 #include "qemu/cutils.h"
+#include "qapi/visitor.h"
+#include "sysemu/qtest.h"
 #include "hw/clock.h"
 #include "trace.h"
 
@@ -158,6 +160,15 @@ bool clock_set_mul_div(Clock *clk, uint32_t multiplier, uint32_t divider)
     return true;
 }
 
+static void clock_period_prop_get(Object *obj, Visitor *v, const char *name,
+                                void *opaque, Error **errp)
+{
+    Clock *clk = CLOCK(obj);
+    uint64_t freq_hz = clock_get(clk);
+    visit_type_uint64(v, name, &freq_hz, errp);
+}
+
+
 static void clock_initfn(Object *obj)
 {
     Clock *clk = CLOCK(obj);
@@ -166,6 +177,11 @@ static void clock_initfn(Object *obj)
     clk->divider = 1;
 
     QLIST_INIT(&clk->children);
+
+    if (qtest_enabled()) {
+        object_property_add(obj, "qtest-clock-period", "uint64",
+                            clock_period_prop_get, NULL, NULL, NULL);
+    }
 }
 
 static void clock_finalizefn(Object *obj)
-- 
2.43.2



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v3 4/4] tests/qtest: Check STM32L4x5 clock connections
  2024-05-23 19:41 [PATCH v3 0/4] Check clock connection between STM32L4x5 RCC and peripherals Inès Varhol
                   ` (2 preceding siblings ...)
  2024-05-23 19:41 ` [PATCH v3 3/4] hw/clock: Expose 'qtest-clock-period' QOM property for QTests Inès Varhol
@ 2024-05-23 19:41 ` Inès Varhol
  2024-05-28 14:49   ` Peter Maydell
  3 siblings, 1 reply; 12+ messages in thread
From: Inès Varhol @ 2024-05-23 19:41 UTC (permalink / raw)
  To: qemu-devel
  Cc: Inès Varhol, Laurent Vivier, qemu-arm,
	Marc-André Lureau, Peter Maydell, Damien Hedde,
	Paolo Bonzini, Luc Michel, Arnaud Minier,
	Philippe Mathieu-Daudé, Thomas Huth

For USART, GPIO and SYSCFG devices, check that clock frequency before
and after enabling the peripheral clock in RCC is correct.

Signed-off-by: Inès Varhol <ines.varhol@telecom-paris.fr>
---
 tests/qtest/stm32l4x5.h             | 43 +++++++++++++++++++++++++++++
 tests/qtest/stm32l4x5_gpio-test.c   | 23 +++++++++++++++
 tests/qtest/stm32l4x5_syscfg-test.c | 20 ++++++++++++--
 tests/qtest/stm32l4x5_usart-test.c  | 26 +++++++++++++++++
 4 files changed, 110 insertions(+), 2 deletions(-)
 create mode 100644 tests/qtest/stm32l4x5.h

diff --git a/tests/qtest/stm32l4x5.h b/tests/qtest/stm32l4x5.h
new file mode 100644
index 0000000000..cf59aeb019
--- /dev/null
+++ b/tests/qtest/stm32l4x5.h
@@ -0,0 +1,43 @@
+/*
+ * QTest testcase header for STM32L4X5 :
+ * used for consolidating common objects in stm32l4x5_*-test.c
+ *
+ * Copyright (c) 2024 Arnaud Minier <arnaud.minier@telecom-paris.fr>
+ * Copyright (c) 2024 Inès Varhol <ines.varhol@telecom-paris.fr>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include "libqtest.h"
+
+/*
+ * MSI (4 MHz) is used as system clock source after startup
+ * from Reset.
+ * AHB, APB1 and APB2 prescalers are set to 1 at reset.
+ *
+ * A clock period is stored in units of 2^-32 ns :
+ * 10^9 * 2^32 / 4000000 = 1073741824000
+ */
+#define SYSCLK_PERIOD 1073741824000UL
+#define RCC_AHB2ENR 0x4002104C
+#define RCC_APB1ENR1 0x40021058
+#define RCC_APB1ENR2 0x4002105C
+#define RCC_APB2ENR 0x40021060
+
+
+static inline uint64_t get_clock_period(QTestState *qts, const char *path)
+{
+    uint64_t clock_period = 0;
+    QDict *r;
+
+    r = qtest_qmp(qts, "{ 'execute': 'qom-get', 'arguments':"
+        " { 'path': %s, 'property': 'qtest-clock-period'} }", path);
+    g_assert_false(qdict_haskey(r, "error"));
+    clock_period = qdict_get_int(r, "return");
+    qobject_unref(r);
+    return clock_period;
+}
+
+
diff --git a/tests/qtest/stm32l4x5_gpio-test.c b/tests/qtest/stm32l4x5_gpio-test.c
index 72a7823406..c0686c7b30 100644
--- a/tests/qtest/stm32l4x5_gpio-test.c
+++ b/tests/qtest/stm32l4x5_gpio-test.c
@@ -10,6 +10,7 @@
 
 #include "qemu/osdep.h"
 #include "libqtest-single.h"
+#include "stm32l4x5.h"
 
 #define GPIO_BASE_ADDR 0x48000000
 #define GPIO_SIZE      0x400
@@ -505,6 +506,26 @@ static void test_bsrr_brr(const void *data)
     gpio_writel(gpio, ODR, reset(gpio, ODR));
 }
 
+static void test_clock_enable(void)
+{
+    /*
+     * For each GPIO, enable its clock in RCC
+     * and check that its clock period changes to SYSCLK_PERIOD
+     */
+    unsigned int gpio_id;
+
+    for (uint32_t gpio = GPIO_A; gpio <= GPIO_H; gpio += GPIO_B - GPIO_A) {
+        gpio_id = get_gpio_id(gpio);
+        g_autofree char *path = g_strdup_printf("/machine/soc/gpio%c/clk",
+                                                gpio_id + 'a');
+        g_assert_cmpuint(get_clock_period(global_qtest, path), ==, 0);
+        /* Enable the gpio clock */
+        writel(RCC_AHB2ENR, readl(RCC_AHB2ENR) | (0x1 << gpio_id));
+        g_assert_cmpuint(get_clock_period(global_qtest, path), ==,
+                         SYSCLK_PERIOD);
+    }
+}
+
 int main(int argc, char **argv)
 {
     int ret;
@@ -556,6 +577,8 @@ int main(int argc, char **argv)
     qtest_add_data_func("stm32l4x5/gpio/test_bsrr_brr2",
                         test_data(GPIO_D, 0),
                         test_bsrr_brr);
+    qtest_add_func("stm32l4x5/gpio/test_clock_enable",
+                   test_clock_enable);
 
     qtest_start("-machine b-l475e-iot01a");
     ret = g_test_run();
diff --git a/tests/qtest/stm32l4x5_syscfg-test.c b/tests/qtest/stm32l4x5_syscfg-test.c
index 506ca08bc2..8eaffe43ea 100644
--- a/tests/qtest/stm32l4x5_syscfg-test.c
+++ b/tests/qtest/stm32l4x5_syscfg-test.c
@@ -10,6 +10,7 @@
 
 #include "qemu/osdep.h"
 #include "libqtest-single.h"
+#include "stm32l4x5.h"
 
 #define SYSCFG_BASE_ADDR 0x40010000
 #define SYSCFG_MEMRMP 0x00
@@ -26,7 +27,9 @@
 #define INVALID_ADDR 0x2C
 
 /* SoC forwards GPIOs to SysCfg */
-#define SYSCFG "/machine/soc"
+#define SOC "/machine/soc"
+#define SYSCFG "/machine/soc/syscfg"
+#define SYSCFG_CLK "/machine/soc/syscfg/clk"
 #define EXTI "/machine/soc/exti"
 
 static void syscfg_writel(unsigned int offset, uint32_t value)
@@ -41,7 +44,7 @@ static uint32_t syscfg_readl(unsigned int offset)
 
 static void syscfg_set_irq(int num, int level)
 {
-   qtest_set_irq_in(global_qtest, SYSCFG, NULL, num, level);
+   qtest_set_irq_in(global_qtest, SOC, NULL, num, level);
 }
 
 static void system_reset(void)
@@ -301,6 +304,17 @@ static void test_irq_gpio_multiplexer(void)
     syscfg_writel(SYSCFG_EXTICR1, 0x00000000);
 }
 
+static void test_clock_enable(void)
+{
+    g_assert_cmpuint(get_clock_period(global_qtest, SYSCFG_CLK), ==, 0);
+
+    /* Enable SYSCFG clock */
+    writel(RCC_APB2ENR, readl(RCC_APB2ENR) | (0x1 << 0));
+
+    g_assert_cmpuint(get_clock_period(global_qtest, SYSCFG_CLK), ==,
+                                       SYSCLK_PERIOD);
+}
+
 int main(int argc, char **argv)
 {
     int ret;
@@ -325,6 +339,8 @@ int main(int argc, char **argv)
                    test_irq_pin_multiplexer);
     qtest_add_func("stm32l4x5/syscfg/test_irq_gpio_multiplexer",
                    test_irq_gpio_multiplexer);
+    qtest_add_func("stm32l4x5/syscfg/test_clock_enable",
+                   test_clock_enable);
 
     qtest_start("-machine b-l475e-iot01a");
     ret = g_test_run();
diff --git a/tests/qtest/stm32l4x5_usart-test.c b/tests/qtest/stm32l4x5_usart-test.c
index 8902518233..4bad3603e8 100644
--- a/tests/qtest/stm32l4x5_usart-test.c
+++ b/tests/qtest/stm32l4x5_usart-test.c
@@ -12,6 +12,7 @@
 #include "libqtest.h"
 #include "hw/misc/stm32l4x5_rcc_internals.h"
 #include "hw/registerfields.h"
+#include "stm32l4x5.h"
 
 #define RCC_BASE_ADDR 0x40021000
 /* Use USART 1 ADDR, assume the others work the same */
@@ -296,6 +297,30 @@ static void test_send_str(void)
     qtest_quit(qts);
 }
 
+static void check_clock(QTestState *qts, const char *path, uint32_t rcc_reg,
+                        uint32_t reg_offset)
+{
+    g_assert_cmpuint(get_clock_period(qts, path), ==, 0);
+    qtest_writel(qts, rcc_reg, qtest_readl(qts, rcc_reg) | (0x1 << reg_offset));
+    g_assert_cmpuint(get_clock_period(qts, path), ==, SYSCLK_PERIOD);
+}
+
+static void test_clock_enable(void)
+{
+    /*
+     * For each USART device, enable its clock in RCC
+     * and check that its clock frequency is SYSCLK_PERIOD
+     */
+    QTestState *qts = qtest_init("-M b-l475e-iot01a");
+
+    check_clock(qts, "machine/soc/usart[0]/clk", RCC_APB2ENR, 14);
+    check_clock(qts, "machine/soc/usart[1]/clk", RCC_APB1ENR1, 17);
+    check_clock(qts, "machine/soc/usart[2]/clk", RCC_APB1ENR1, 18);
+    check_clock(qts, "machine/soc/uart[0]/clk", RCC_APB1ENR1, 19);
+    check_clock(qts, "machine/soc/uart[1]/clk", RCC_APB1ENR1, 20);
+    check_clock(qts, "machine/soc/lpuart1/clk", RCC_APB1ENR2, 0);
+}
+
 int main(int argc, char **argv)
 {
     int ret;
@@ -308,6 +333,7 @@ int main(int argc, char **argv)
     qtest_add_func("stm32l4x5/usart/send_char", test_send_char);
     qtest_add_func("stm32l4x5/usart/receive_str", test_receive_str);
     qtest_add_func("stm32l4x5/usart/send_str", test_send_str);
+    qtest_add_func("stm32l4x5/usart/clock_enable", test_clock_enable);
     ret = g_test_run();
 
     return ret;
-- 
2.43.2



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 3/4] hw/clock: Expose 'qtest-clock-period' QOM property for QTests
  2024-05-23 19:41 ` [PATCH v3 3/4] hw/clock: Expose 'qtest-clock-period' QOM property for QTests Inès Varhol
@ 2024-05-27  7:04   ` Luc Michel
  2024-05-28 14:51   ` Peter Maydell
  2024-05-28 15:17   ` Philippe Mathieu-Daudé
  2 siblings, 0 replies; 12+ messages in thread
From: Luc Michel @ 2024-05-27  7:04 UTC (permalink / raw)
  To: Inès Varhol
  Cc: qemu-devel, Laurent Vivier, qemu-arm, Marc-André Lureau,
	Peter Maydell, Damien Hedde, Paolo Bonzini, Arnaud Minier,
	Philippe Mathieu-Daudé, Thomas Huth

On 21:41 Thu 23 May     , Inès Varhol wrote:
> Expose the clock period via the QOM 'qtest-clock-period' property so it
> can be used in QTests. This property is only accessible in QTests (not
> via HMP).
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> Signed-off-by: Inès Varhol <ines.varhol@telecom-paris.fr>
> ---
>  docs/devel/clocks.rst |  3 +++
>  hw/core/clock.c       | 16 ++++++++++++++++
>  2 files changed, 19 insertions(+)
> 
> diff --git a/docs/devel/clocks.rst b/docs/devel/clocks.rst
> index 177ee1c90d..19e67601ec 100644
> --- a/docs/devel/clocks.rst
> +++ b/docs/devel/clocks.rst
> @@ -358,6 +358,9 @@ humans (for instance in debugging), use ``clock_display_freq()``,
>  which returns a prettified string-representation, e.g. "33.3 MHz".
>  The caller must free the string with g_free() after use.
>  
> +It's also possible to retrieve the clock period from a QTest by
> +accessing QOM property ``qtest-clock-period`` using a QMP command.
> +
>  Calculating expiry deadlines
>  ----------------------------
>  
> diff --git a/hw/core/clock.c b/hw/core/clock.c
> index e212865307..216b54b8df 100644
> --- a/hw/core/clock.c
> +++ b/hw/core/clock.c
> @@ -13,6 +13,8 @@
>  
>  #include "qemu/osdep.h"
>  #include "qemu/cutils.h"
> +#include "qapi/visitor.h"
> +#include "sysemu/qtest.h"
>  #include "hw/clock.h"
>  #include "trace.h"
>  
> @@ -158,6 +160,15 @@ bool clock_set_mul_div(Clock *clk, uint32_t multiplier, uint32_t divider)
>      return true;
>  }
>  
> +static void clock_period_prop_get(Object *obj, Visitor *v, const char *name,
> +                                void *opaque, Error **errp)
> +{
> +    Clock *clk = CLOCK(obj);
> +    uint64_t freq_hz = clock_get(clk);
> +    visit_type_uint64(v, name, &freq_hz, errp);
s/freq_hz/period

Otherwise:

Reviewed-by: Luc Michel <luc@lmichel.fr>

> +}
> +
> +
>  static void clock_initfn(Object *obj)
>  {
>      Clock *clk = CLOCK(obj);
> @@ -166,6 +177,11 @@ static void clock_initfn(Object *obj)
>      clk->divider = 1;
>  
>      QLIST_INIT(&clk->children);
> +
> +    if (qtest_enabled()) {
> +        object_property_add(obj, "qtest-clock-period", "uint64",
> +                            clock_period_prop_get, NULL, NULL, NULL);
> +    }
>  }
>  
>  static void clock_finalizefn(Object *obj)
> -- 
> 2.43.2
> 

-- 


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 2/4] hw/char: Use v2 VMStateDescription for STM32L4x5 USART
  2024-05-23 19:41 ` [PATCH v3 2/4] hw/char: Use v2 VMStateDescription for STM32L4x5 USART Inès Varhol
@ 2024-05-28 14:39   ` Peter Maydell
  0 siblings, 0 replies; 12+ messages in thread
From: Peter Maydell @ 2024-05-28 14:39 UTC (permalink / raw)
  To: Inès Varhol
  Cc: qemu-devel, Laurent Vivier, qemu-arm, Marc-André Lureau,
	Damien Hedde, Paolo Bonzini, Luc Michel, Arnaud Minier,
	Philippe Mathieu-Daudé, Thomas Huth

On Thu, 23 May 2024 at 20:44, Inès Varhol <ines.varhol@telecom-paris.fr> wrote:
>
> `vmstate_stm32l4x5_usart_base` namely uses `VMSTATE_CLOCK` so
> version needs to be 2.
>
> Signed-off-by: Inès Varhol <ines.varhol@telecom-paris.fr>
> ---
>  hw/char/stm32l4x5_usart.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/hw/char/stm32l4x5_usart.c b/hw/char/stm32l4x5_usart.c
> index 02f666308c..0f16f0917a 100644
> --- a/hw/char/stm32l4x5_usart.c
> +++ b/hw/char/stm32l4x5_usart.c
> @@ -546,8 +546,8 @@ static int stm32l4x5_usart_base_post_load(void *opaque, int version_id)
>
>  static const VMStateDescription vmstate_stm32l4x5_usart_base = {
>      .name = TYPE_STM32L4X5_USART_BASE,
> -    .version_id = 1,
> -    .minimum_version_id = 1,
> +    .version_id = 2,
> +    .minimum_version_id = 2,

I don't understand why we are bumping the version number here;
can you explain? Usually we bump the version number when we
add a new vmstate field to the vmstate, but this commit doesn't
do that.

thanks
-- PMM


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 1/4] hw/misc: Create STM32L4x5 SYSCFG clock
  2024-05-23 19:41 ` [PATCH v3 1/4] hw/misc: Create STM32L4x5 SYSCFG clock Inès Varhol
@ 2024-05-28 14:40   ` Peter Maydell
  2024-05-29  6:27   ` Philippe Mathieu-Daudé
  1 sibling, 0 replies; 12+ messages in thread
From: Peter Maydell @ 2024-05-28 14:40 UTC (permalink / raw)
  To: Inès Varhol
  Cc: qemu-devel, Laurent Vivier, qemu-arm, Marc-André Lureau,
	Damien Hedde, Paolo Bonzini, Luc Michel, Arnaud Minier,
	Philippe Mathieu-Daudé, Thomas Huth

On Thu, 23 May 2024 at 20:44, Inès Varhol <ines.varhol@telecom-paris.fr> wrote:
>
> This commit creates a clock in STM32L4x5 SYSCFG and wires it up to the
> corresponding clock from STM32L4x5 RCC.
>
> Signed-off-by: Inès Varhol <ines.varhol@telecom-paris.fr>
> ---

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 4/4] tests/qtest: Check STM32L4x5 clock connections
  2024-05-23 19:41 ` [PATCH v3 4/4] tests/qtest: Check STM32L4x5 clock connections Inès Varhol
@ 2024-05-28 14:49   ` Peter Maydell
  0 siblings, 0 replies; 12+ messages in thread
From: Peter Maydell @ 2024-05-28 14:49 UTC (permalink / raw)
  To: Inès Varhol
  Cc: qemu-devel, Laurent Vivier, qemu-arm, Marc-André Lureau,
	Damien Hedde, Paolo Bonzini, Luc Michel, Arnaud Minier,
	Philippe Mathieu-Daudé, Thomas Huth

On Thu, 23 May 2024 at 20:44, Inès Varhol <ines.varhol@telecom-paris.fr> wrote:
>
> For USART, GPIO and SYSCFG devices, check that clock frequency before
> and after enabling the peripheral clock in RCC is correct.
>
> Signed-off-by: Inès Varhol <ines.varhol@telecom-paris.fr>
> ---
>  tests/qtest/stm32l4x5.h             | 43 +++++++++++++++++++++++++++++
>  tests/qtest/stm32l4x5_gpio-test.c   | 23 +++++++++++++++
>  tests/qtest/stm32l4x5_syscfg-test.c | 20 ++++++++++++--
>  tests/qtest/stm32l4x5_usart-test.c  | 26 +++++++++++++++++
>  4 files changed, 110 insertions(+), 2 deletions(-)
>  create mode 100644 tests/qtest/stm32l4x5.h
>
> diff --git a/tests/qtest/stm32l4x5.h b/tests/qtest/stm32l4x5.h
> new file mode 100644
> index 0000000000..cf59aeb019
> --- /dev/null
> +++ b/tests/qtest/stm32l4x5.h
> @@ -0,0 +1,43 @@
> +/*
> + * QTest testcase header for STM32L4X5 :
> + * used for consolidating common objects in stm32l4x5_*-test.c
> + *
> + * Copyright (c) 2024 Arnaud Minier <arnaud.minier@telecom-paris.fr>
> + * Copyright (c) 2024 Inès Varhol <ines.varhol@telecom-paris.fr>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or later.
> + * See the COPYING file in the top-level directory.
> + */
> +
> +#include "qemu/osdep.h"

Header files must never include osdep.h. The rules for
osdep.h are:
 * never included in a .h file
 * always included as the first include in every .c file

> +#include "libqtest.h"
> +
> +/*
> + * MSI (4 MHz) is used as system clock source after startup
> + * from Reset.
> + * AHB, APB1 and APB2 prescalers are set to 1 at reset.
> + *
> + * A clock period is stored in units of 2^-32 ns :
> + * 10^9 * 2^32 / 4000000 = 1073741824000
> + */
> +#define SYSCLK_PERIOD 1073741824000UL

Rather than doing the calculation by hand, it would be
clearer to use the CLOCK_PERIOD_FROM_HZ() macro from hw/clock.h.
(If #including clock.h from the test C file doesn't work for
some reason, you can copy the macro definition; it's a one-liner).

#define SYSCLK_PERIOD CLOCK_PERIOD_FROM_HZ(4000000)

Otherwise
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 3/4] hw/clock: Expose 'qtest-clock-period' QOM property for QTests
  2024-05-23 19:41 ` [PATCH v3 3/4] hw/clock: Expose 'qtest-clock-period' QOM property for QTests Inès Varhol
  2024-05-27  7:04   ` Luc Michel
@ 2024-05-28 14:51   ` Peter Maydell
  2024-05-28 15:17   ` Philippe Mathieu-Daudé
  2 siblings, 0 replies; 12+ messages in thread
From: Peter Maydell @ 2024-05-28 14:51 UTC (permalink / raw)
  To: Inès Varhol
  Cc: qemu-devel, Laurent Vivier, qemu-arm, Marc-André Lureau,
	Damien Hedde, Paolo Bonzini, Luc Michel, Arnaud Minier,
	Philippe Mathieu-Daudé, Thomas Huth

On Thu, 23 May 2024 at 20:44, Inès Varhol <ines.varhol@telecom-paris.fr> wrote:
>
> Expose the clock period via the QOM 'qtest-clock-period' property so it
> can be used in QTests. This property is only accessible in QTests (not
> via HMP).
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> Signed-off-by: Inès Varhol <ines.varhol@telecom-paris.fr>
> ---
>  docs/devel/clocks.rst |  3 +++
>  hw/core/clock.c       | 16 ++++++++++++++++
>  2 files changed, 19 insertions(+)
>
> diff --git a/docs/devel/clocks.rst b/docs/devel/clocks.rst
> index 177ee1c90d..19e67601ec 100644
> --- a/docs/devel/clocks.rst
> +++ b/docs/devel/clocks.rst
> @@ -358,6 +358,9 @@ humans (for instance in debugging), use ``clock_display_freq()``,
>  which returns a prettified string-representation, e.g. "33.3 MHz".
>  The caller must free the string with g_free() after use.
>
> +It's also possible to retrieve the clock period from a QTest by
> +accessing QOM property ``qtest-clock-period`` using a QMP command.

We should add:

  This property is only present when the device is being run under
  the ``qtest`` accelerator; it is not available when QEMU is
  being run normally.

thanks
-- PMM


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 3/4] hw/clock: Expose 'qtest-clock-period' QOM property for QTests
  2024-05-23 19:41 ` [PATCH v3 3/4] hw/clock: Expose 'qtest-clock-period' QOM property for QTests Inès Varhol
  2024-05-27  7:04   ` Luc Michel
  2024-05-28 14:51   ` Peter Maydell
@ 2024-05-28 15:17   ` Philippe Mathieu-Daudé
  2 siblings, 0 replies; 12+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-05-28 15:17 UTC (permalink / raw)
  To: Inès Varhol, qemu-devel
  Cc: Laurent Vivier, qemu-arm, Marc-André Lureau, Peter Maydell,
	Damien Hedde, Paolo Bonzini, Luc Michel, Arnaud Minier,
	Thomas Huth

On 23/5/24 21:41, Inès Varhol wrote:
> Expose the clock period via the QOM 'qtest-clock-period' property so it
> can be used in QTests. This property is only accessible in QTests (not
> via HMP).
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Addressing Luc and Peter comments, you can replace that line by:

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Thanks!

> Signed-off-by: Inès Varhol <ines.varhol@telecom-paris.fr>
> ---
>   docs/devel/clocks.rst |  3 +++
>   hw/core/clock.c       | 16 ++++++++++++++++
>   2 files changed, 19 insertions(+)



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 1/4] hw/misc: Create STM32L4x5 SYSCFG clock
  2024-05-23 19:41 ` [PATCH v3 1/4] hw/misc: Create STM32L4x5 SYSCFG clock Inès Varhol
  2024-05-28 14:40   ` Peter Maydell
@ 2024-05-29  6:27   ` Philippe Mathieu-Daudé
  1 sibling, 0 replies; 12+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-05-29  6:27 UTC (permalink / raw)
  To: Inès Varhol, qemu-devel
  Cc: Laurent Vivier, qemu-arm, Marc-André Lureau, Peter Maydell,
	Damien Hedde, Paolo Bonzini, Luc Michel, Arnaud Minier,
	Thomas Huth

On 23/5/24 21:41, Inès Varhol wrote:
> This commit creates a clock in STM32L4x5 SYSCFG and wires it up to the
> corresponding clock from STM32L4x5 RCC.
> 
> Signed-off-by: Inès Varhol <ines.varhol@telecom-paris.fr>
> ---
>   include/hw/misc/stm32l4x5_syscfg.h |  1 +
>   hw/arm/stm32l4x5_soc.c             |  2 ++
>   hw/misc/stm32l4x5_syscfg.c         | 19 +++++++++++++++++--
>   3 files changed, 20 insertions(+), 2 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2024-05-29  6:27 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-23 19:41 [PATCH v3 0/4] Check clock connection between STM32L4x5 RCC and peripherals Inès Varhol
2024-05-23 19:41 ` [PATCH v3 1/4] hw/misc: Create STM32L4x5 SYSCFG clock Inès Varhol
2024-05-28 14:40   ` Peter Maydell
2024-05-29  6:27   ` Philippe Mathieu-Daudé
2024-05-23 19:41 ` [PATCH v3 2/4] hw/char: Use v2 VMStateDescription for STM32L4x5 USART Inès Varhol
2024-05-28 14:39   ` Peter Maydell
2024-05-23 19:41 ` [PATCH v3 3/4] hw/clock: Expose 'qtest-clock-period' QOM property for QTests Inès Varhol
2024-05-27  7:04   ` Luc Michel
2024-05-28 14:51   ` Peter Maydell
2024-05-28 15:17   ` Philippe Mathieu-Daudé
2024-05-23 19:41 ` [PATCH v3 4/4] tests/qtest: Check STM32L4x5 clock connections Inès Varhol
2024-05-28 14:49   ` Peter Maydell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).