From nobody Tue Feb 10 19:49:01 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=telecom-paris.fr ARC-Seal: i=1; a=rsa-sha256; t=1714918094; cv=none; d=zohomail.com; s=zohoarc; b=APF7M/2MF2VNAmJdruQ5QtZ3NUn3DxQof6K1DUlmxzv66OdjXv76SIagpNoF9MSoko2PvCxMcTRC63xiH8ZqhvomqWQyLUQxLHIOlHpPswAM8uh2UcYNhNH0vJ+Efox91ME0lCEeoBjoFQgJ19+F7iu/y4N1HrAfaSfrOZ1y6Vg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1714918094; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=PQrO98JAVg+dMsiZ3wMPO7MlqpV4mBVU/7/oZd0u37c=; b=McRnUmMG2QrFmL/UQBUd+kSi7aINOrNYu6yLvUAOJYjV0EED99jbCLxG4gzIvAl3qv3dlcukD3mspREJ90WD4RsNNZWVMKtd8rLa54gshuKVB5avZXeba80hsrdV2ou5DSUDoybmu93Wu0QgauoP3JkDqAzBtVVIJcCIzCmxiTo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1714918094050559.6217577213719; Sun, 5 May 2024 07:08:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s3cVV-0005wR-DS; Sun, 05 May 2024 10:06:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s3cVK-0005su-Jj; Sun, 05 May 2024 10:06:14 -0400 Received: from zproxy3.enst.fr ([2001:660:330f:2::de]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s3cVH-00085q-2m; Sun, 05 May 2024 10:06:14 -0400 Received: from localhost (localhost [IPv6:::1]) by zproxy3.enst.fr (Postfix) with ESMTP id 33FCAA0748; Sun, 5 May 2024 16:06:05 +0200 (CEST) Received: from zproxy3.enst.fr ([IPv6:::1]) by localhost (zproxy3.enst.fr [IPv6:::1]) (amavis, port 10032) with ESMTP id B88WY9VTXHwk; Sun, 5 May 2024 16:06:04 +0200 (CEST) Received: from localhost (localhost [IPv6:::1]) by zproxy3.enst.fr (Postfix) with ESMTP id 9A729A072C; Sun, 5 May 2024 16:06:04 +0200 (CEST) Received: from zproxy3.enst.fr ([IPv6:::1]) by localhost (zproxy3.enst.fr [IPv6:::1]) (amavis, port 10026) with ESMTP id 9zqfmn7Q7a1F; Sun, 5 May 2024 16:06:04 +0200 (CEST) Received: from inesv-Inspiron-3501.enst.fr (unknown [IPv6:2a04:8ec0:0:124::190c]) by zproxy3.enst.fr (Postfix) with ESMTPSA id A03CFA06D1; Sun, 5 May 2024 16:06:03 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.10.3 zproxy3.enst.fr 9A729A072C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telecom-paris.fr; s=A35C7578-1106-11E5-A17F-C303FDDA8F2E; t=1714917964; bh=PQrO98JAVg+dMsiZ3wMPO7MlqpV4mBVU/7/oZd0u37c=; h=From:To:Date:Message-ID:MIME-Version; b=Cy/QkrCWmo7xJnmER4B4hRj5UYp+n87UKywEUEQYl4prGvWV2HYWD7ECyKXkNL1Wu VHhK8njZldQE9mJ8+vTBP5xQLD/4bmVa2LLtqY2SqHLqe7BW/eIdCDT92gutL7/wQf Z6oPACW110gRSQkoWCd0BHprhwLl4QpV8FzZz2Hs= X-Virus-Scanned: amavis at enst.fr From: =?UTF-8?q?In=C3=A8s=20Varhol?= To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Thomas Huth , Arnaud Minier , Laurent Vivier , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?In=C3=A8s=20Varhol?= , Peter Maydell , Alistair Francis , Samuel Tardieu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paolo Bonzini Subject: [PATCH 1/4] hw/misc: Create STM32L4x5 SYSCFG clock Date: Sun, 5 May 2024 16:05:03 +0200 Message-ID: <20240505140556.373711-2-ines.varhol@telecom-paris.fr> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240505140556.373711-1-ines.varhol@telecom-paris.fr> References: <20240505140556.373711-1-ines.varhol@telecom-paris.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2001:660:330f:2::de; envelope-from=ines.varhol@telecom-paris.fr; helo=zproxy3.enst.fr X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @telecom-paris.fr) X-ZM-MESSAGEID: 1714918094453100004 Content-Type: text/plain; charset="utf-8" Signed-off-by: In=C3=A8s Varhol --- include/hw/misc/stm32l4x5_syscfg.h | 1 + hw/arm/stm32l4x5_soc.c | 2 ++ hw/misc/stm32l4x5_syscfg.c | 26 ++++++++++++++++++++++++++ 3 files changed, 29 insertions(+) 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; =20 qemu_irq gpio_out[GPIO_NUM_PINS]; + Clock *clk; }; =20 #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) =20 /* System configuration controller */ busdev =3D 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..a82864c33d 100644 --- a/hw/misc/stm32l4x5_syscfg.c +++ b/hw/misc/stm32l4x5_syscfg.c @@ -26,6 +26,10 @@ #include "trace.h" #include "hw/irq.h" #include "migration/vmstate.h" +#include "hw/clock.h" +#include "hw/qdev-clock.h" +#include "qapi/visitor.h" +#include "qapi/error.h" #include "hw/misc/stm32l4x5_syscfg.h" #include "hw/gpio/stm32l4x5_gpio.h" =20 @@ -202,6 +206,14 @@ static void stm32l4x5_syscfg_write(void *opaque, hwadd= r addr, } } =20 +static void clock_freq_get(Object *obj, Visitor *v, + const char *name, void *opaque, Error **errp) +{ + Stm32l4x5SyscfgState *s =3D STM32L4X5_SYSCFG(obj); + uint32_t clock_freq_hz =3D clock_get_hz(s->clk); + visit_type_uint32(v, name, &clock_freq_hz, errp); +} + static const MemoryRegionOps stm32l4x5_syscfg_ops =3D { .read =3D stm32l4x5_syscfg_read, .write =3D stm32l4x5_syscfg_write, @@ -225,6 +237,18 @@ 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 =3D qdev_init_clock_in(DEVICE(s), "clk", NULL, s, 0); + object_property_add(obj, "clock-freq-hz", "uint32", clock_freq_get, NU= LL, + NULL, NULL); +} + +static void stm32l4x5_syscfg_realize(DeviceState *dev, Error **errp) +{ + Stm32l4x5SyscfgState *s =3D STM32L4X5_SYSCFG(dev); + if (!clock_has_source(s->clk)) { + error_setg(errp, "SYSCFG: clk input must be connected"); + return; + } } =20 static const VMStateDescription vmstate_stm32l4x5_syscfg =3D { @@ -241,6 +265,7 @@ static const VMStateDescription vmstate_stm32l4x5_syscf= g =3D { VMSTATE_UINT32(swpr, Stm32l4x5SyscfgState), VMSTATE_UINT32(skr, Stm32l4x5SyscfgState), VMSTATE_UINT32(swpr2, Stm32l4x5SyscfgState), + VMSTATE_CLOCK(clk, Stm32l4x5SyscfgState), VMSTATE_END_OF_LIST() } }; @@ -251,6 +276,7 @@ static void stm32l4x5_syscfg_class_init(ObjectClass *kl= ass, void *data) ResettableClass *rc =3D RESETTABLE_CLASS(klass); =20 dc->vmsd =3D &vmstate_stm32l4x5_syscfg; + dc->realize =3D stm32l4x5_syscfg_realize; rc->phases.hold =3D stm32l4x5_syscfg_hold_reset; } =20 --=20 2.43.2 From nobody Tue Feb 10 19:49:01 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=telecom-paris.fr ARC-Seal: i=1; a=rsa-sha256; t=1714918059; cv=none; d=zohomail.com; s=zohoarc; b=T4DpD8uljFqfXur5ZvTE7UaNTFOaQSQgu/kN5blLNQ2E+y+zhJcwg8vJrLeBM+xKbsjH1bIQkrTp43Cu/qgNvSj3rNXFIX26ERhsISrxa6chPl9iKy8jfopwFCU1sYoQWh5gLASxLWJoqK3WzQ7yFn+Wj8A936N1Scc23JMfgr4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1714918059; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=s6kUahatkuNBmbNzGf064R0ZxKZ/IMkQiTFLKObIBno=; b=TaFLp9iwJwm0YzltXPVox4mDs0GZjJh+AlvuEm5loEKqVIeGYReTqblmBtTZht1FWvs8AOxQldEVN1IadVg2OhRZzvgAG/CLX8GKZN4bvgypD+9i0ymBjJVeoCDDZjKiwd/iIZa/smiaNEp9OEJuuMIc9+Nc1b5FI471UStk9lw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1714918059511451.0483613364303; Sun, 5 May 2024 07:07:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s3cVN-0005tq-6d; Sun, 05 May 2024 10:06:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s3cVK-0005ss-Ix; Sun, 05 May 2024 10:06:14 -0400 Received: from zproxy3.enst.fr ([137.194.2.222]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s3cVH-00085s-AP; Sun, 05 May 2024 10:06:12 -0400 Received: from localhost (localhost [IPv6:::1]) by zproxy3.enst.fr (Postfix) with ESMTP id D291FA06B6; Sun, 5 May 2024 16:06:05 +0200 (CEST) Received: from zproxy3.enst.fr ([IPv6:::1]) by localhost (zproxy3.enst.fr [IPv6:::1]) (amavis, port 10032) with ESMTP id qkhgwEMOKexZ; Sun, 5 May 2024 16:06:05 +0200 (CEST) Received: from localhost (localhost [IPv6:::1]) by zproxy3.enst.fr (Postfix) with ESMTP id 93747A071D; Sun, 5 May 2024 16:06:05 +0200 (CEST) Received: from zproxy3.enst.fr ([IPv6:::1]) by localhost (zproxy3.enst.fr [IPv6:::1]) (amavis, port 10026) with ESMTP id Q2In-kAoXJH5; Sun, 5 May 2024 16:06:05 +0200 (CEST) Received: from inesv-Inspiron-3501.enst.fr (unknown [IPv6:2a04:8ec0:0:124::190c]) by zproxy3.enst.fr (Postfix) with ESMTPSA id 9A5D4A06B6; Sun, 5 May 2024 16:06:04 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.10.3 zproxy3.enst.fr 93747A071D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telecom-paris.fr; s=A35C7578-1106-11E5-A17F-C303FDDA8F2E; t=1714917965; bh=s6kUahatkuNBmbNzGf064R0ZxKZ/IMkQiTFLKObIBno=; h=From:To:Date:Message-ID:MIME-Version; b=xe+B40NwoX++V3nQmKa2VCqSBg3OxO/yKIporHAVlUN2X0odXWlwd7l+y7gcE42uk Jk5DQ9H+PmlR1kpp4eyaC87JKHc2TyyL767Br2d7Eb2aYVKzXVb0dvFl43wPhiq7YI 2jf/swhFnL2ruokxMqBlbJp1JB+zOCsrThSTD4PE= X-Virus-Scanned: amavis at enst.fr From: =?UTF-8?q?In=C3=A8s=20Varhol?= To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Thomas Huth , Arnaud Minier , Laurent Vivier , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?In=C3=A8s=20Varhol?= , Peter Maydell , Alistair Francis , Samuel Tardieu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paolo Bonzini Subject: [PATCH 2/4] hw/gpio: Handle clock migration in STM32L4x5 gpios Date: Sun, 5 May 2024 16:05:04 +0200 Message-ID: <20240505140556.373711-3-ines.varhol@telecom-paris.fr> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240505140556.373711-1-ines.varhol@telecom-paris.fr> References: <20240505140556.373711-1-ines.varhol@telecom-paris.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=137.194.2.222; envelope-from=ines.varhol@telecom-paris.fr; helo=zproxy3.enst.fr X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @telecom-paris.fr) X-ZM-MESSAGEID: 1714918060672100003 Content-Type: text/plain; charset="utf-8" Signed-off-by: In=C3=A8s Varhol --- hw/gpio/stm32l4x5_gpio.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hw/gpio/stm32l4x5_gpio.c b/hw/gpio/stm32l4x5_gpio.c index 71bf5fddb2..14e6618d30 100644 --- a/hw/gpio/stm32l4x5_gpio.c +++ b/hw/gpio/stm32l4x5_gpio.c @@ -20,6 +20,7 @@ #include "qemu/log.h" #include "hw/gpio/stm32l4x5_gpio.h" #include "hw/irq.h" +#include "hw/clock.h" #include "hw/qdev-clock.h" #include "hw/qdev-properties.h" #include "qapi/visitor.h" @@ -441,6 +442,7 @@ static const VMStateDescription vmstate_stm32l4x5_gpio = =3D { VMSTATE_UINT32(ascr, Stm32l4x5GpioState), VMSTATE_UINT16(disconnected_pins, Stm32l4x5GpioState), VMSTATE_UINT16(pins_connected_high, Stm32l4x5GpioState), + VMSTATE_CLOCK(clk, Stm32l4x5GpioState), VMSTATE_END_OF_LIST() } }; --=20 2.43.2 From nobody Tue Feb 10 19:49:01 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=telecom-paris.fr ARC-Seal: i=1; a=rsa-sha256; t=1714918092; cv=none; d=zohomail.com; s=zohoarc; b=ncxgKEVVmaCzGnwbQeIK6xgZvgtzhFPFKO9RWT+wQXpn1EdTvDUY0pmvCPg05q6TumztjRWdccYN/+8CBzZqlbFzUnY1tNIsob2gleRNORfozG3myqoqfRTa46rx0gVI8LhMh5GTuA2hCqY87ws/PT9nlmiM1KJIPB4mLgG8Oo8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1714918092; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=zMFeulWVkOYx/BzjKpb4Lr6JnGmx5OooPNZDwt3CYjs=; b=CP5a1pxP4l2ACZRTXWvxvHAU3YSM8mQZuop/mFuktopkt2RN3ai3fZ0pyIsW9mDlfwBmSIwtell3nW54qhl5hKX3hNaMj/e1yy/1fjB80kkAcWrXf9L8M/7An4iLUoCOa768wo291/8xL/E6TBwlhocp0Pje4sBCxKYeXPqYWDY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1714918092711858.3629335315169; Sun, 5 May 2024 07:08:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s3cVU-0005vz-Op; Sun, 05 May 2024 10:06:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s3cVK-0005sr-II; Sun, 05 May 2024 10:06:14 -0400 Received: from zproxy3.enst.fr ([137.194.2.222]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s3cVH-00086E-2r; Sun, 05 May 2024 10:06:12 -0400 Received: from localhost (localhost [IPv6:::1]) by zproxy3.enst.fr (Postfix) with ESMTP id D7A63A071D; Sun, 5 May 2024 16:06:06 +0200 (CEST) Received: from zproxy3.enst.fr ([IPv6:::1]) by localhost (zproxy3.enst.fr [IPv6:::1]) (amavis, port 10032) with ESMTP id wrd_UPYNM3jm; Sun, 5 May 2024 16:06:06 +0200 (CEST) Received: from localhost (localhost [IPv6:::1]) by zproxy3.enst.fr (Postfix) with ESMTP id 9182FA06FC; Sun, 5 May 2024 16:06:06 +0200 (CEST) Received: from zproxy3.enst.fr ([IPv6:::1]) by localhost (zproxy3.enst.fr [IPv6:::1]) (amavis, port 10026) with ESMTP id gRja93ZjF1SQ; Sun, 5 May 2024 16:06:06 +0200 (CEST) Received: from inesv-Inspiron-3501.enst.fr (unknown [IPv6:2a04:8ec0:0:124::190c]) by zproxy3.enst.fr (Postfix) with ESMTPSA id A96F1A072C; Sun, 5 May 2024 16:06:05 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.10.3 zproxy3.enst.fr 9182FA06FC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telecom-paris.fr; s=A35C7578-1106-11E5-A17F-C303FDDA8F2E; t=1714917966; bh=zMFeulWVkOYx/BzjKpb4Lr6JnGmx5OooPNZDwt3CYjs=; h=From:To:Date:Message-ID:MIME-Version; b=8CxpRlC/Au55lrun1lofuvo9ge8gNCIRdDrY2zTeZfi3nwM8hnDSIyXPlTBWdIFiX cu6zwiEDuKdNedjYVbfDsi4nnt+RRxHVy2Ak4Hkc99HGxha1T4vWeabvMZZVYTJ2cB HdUv72iaamRA+HnzKjXEoTiNbXAOoW82Pt3plzHw= X-Virus-Scanned: amavis at enst.fr From: =?UTF-8?q?In=C3=A8s=20Varhol?= To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Thomas Huth , Arnaud Minier , Laurent Vivier , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?In=C3=A8s=20Varhol?= , Peter Maydell , Alistair Francis , Samuel Tardieu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paolo Bonzini Subject: [PATCH 3/4] hw/char: Add QOM property for STM32L4x5 USART clock frequency Date: Sun, 5 May 2024 16:05:05 +0200 Message-ID: <20240505140556.373711-4-ines.varhol@telecom-paris.fr> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240505140556.373711-1-ines.varhol@telecom-paris.fr> References: <20240505140556.373711-1-ines.varhol@telecom-paris.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=137.194.2.222; envelope-from=ines.varhol@telecom-paris.fr; helo=zproxy3.enst.fr X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @telecom-paris.fr) X-ZM-MESSAGEID: 1714918094443100003 Content-Type: text/plain; charset="utf-8" Signed-off-by: In=C3=A8s Varhol --- hw/char/stm32l4x5_usart.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/hw/char/stm32l4x5_usart.c b/hw/char/stm32l4x5_usart.c index fc5dcac0c4..ee7727481c 100644 --- a/hw/char/stm32l4x5_usart.c +++ b/hw/char/stm32l4x5_usart.c @@ -26,6 +26,7 @@ #include "hw/clock.h" #include "hw/irq.h" #include "hw/qdev-clock.h" +#include "qapi/visitor.h" #include "hw/qdev-properties.h" #include "hw/qdev-properties-system.h" #include "hw/registerfields.h" @@ -523,6 +524,14 @@ static Property stm32l4x5_usart_base_properties[] =3D { DEFINE_PROP_END_OF_LIST(), }; =20 +static void clock_freq_get(Object *obj, Visitor *v, + const char *name, void *opaque, Error **errp) +{ + Stm32l4x5UsartBaseState *s =3D STM32L4X5_USART_BASE(obj); + uint32_t clock_freq_hz =3D clock_get_hz(s->clk); + visit_type_uint32(v, name, &clock_freq_hz, errp); +} + static void stm32l4x5_usart_base_init(Object *obj) { Stm32l4x5UsartBaseState *s =3D STM32L4X5_USART_BASE(obj); @@ -534,6 +543,9 @@ static void stm32l4x5_usart_base_init(Object *obj) sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mmio); =20 s->clk =3D qdev_init_clock_in(DEVICE(s), "clk", NULL, s, 0); + + object_property_add(obj, "clock-freq-hz", "uint32", + clock_freq_get, NULL, NULL, NULL); } =20 static int stm32l4x5_usart_base_post_load(void *opaque, int version_id) --=20 2.43.2 From nobody Tue Feb 10 19:49:01 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=telecom-paris.fr ARC-Seal: i=1; a=rsa-sha256; t=1714918099; cv=none; d=zohomail.com; s=zohoarc; b=E1ObptHBVFQJ5uOtFKNBxgphxt/OiWLWpKTDV+75aDM0i8Pf7e+nITIYZRCkVF6roIhSL2lBqQvr6enmweOv9BeC87W2stuSCBA7AlmiEtYNERnLMM/6kgCbzZhVnyZgjHRqsnt5CCNyBIbho9DFMEk9TWVLov4K2w8/y5LPXB0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1714918099; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=a0JcXUYEaTT4impeQLCUpEzujhW/Bb2lou9Ofz38O+4=; b=DZDdJ8ilQkwUC6QSaDaI3Do5VBKdcVSS+kI3pnKnlCektxWyDTb9Wx55XT6vF/XLI+6J5GH2AYUePUx/NLBS3PwfpWkhSdnVDt9nFBB1gIGeIJAB7Lm35K8su/LbVv0Cg5SPiZB9YFP/oMxlHHzEKXAP2fJxk1l5T5QSi/s/6hs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1714918099074866.5842677509249; Sun, 5 May 2024 07:08:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s3cVW-0005wt-FL; Sun, 05 May 2024 10:06:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s3cVK-0005sy-Vl; Sun, 05 May 2024 10:06:15 -0400 Received: from zproxy3.enst.fr ([2001:660:330f:2::de]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s3cVH-00086V-CT; Sun, 05 May 2024 10:06:14 -0400 Received: from localhost (localhost [IPv6:::1]) by zproxy3.enst.fr (Postfix) with ESMTP id EC5E8A0721; Sun, 5 May 2024 16:06:07 +0200 (CEST) Received: from zproxy3.enst.fr ([IPv6:::1]) by localhost (zproxy3.enst.fr [IPv6:::1]) (amavis, port 10032) with ESMTP id il71TNKqggR8; Sun, 5 May 2024 16:06:07 +0200 (CEST) Received: from localhost (localhost [IPv6:::1]) by zproxy3.enst.fr (Postfix) with ESMTP id 8861AA06FC; Sun, 5 May 2024 16:06:07 +0200 (CEST) Received: from zproxy3.enst.fr ([IPv6:::1]) by localhost (zproxy3.enst.fr [IPv6:::1]) (amavis, port 10026) with ESMTP id 8EElalwT4_uj; Sun, 5 May 2024 16:06:07 +0200 (CEST) Received: from inesv-Inspiron-3501.enst.fr (unknown [IPv6:2a04:8ec0:0:124::190c]) by zproxy3.enst.fr (Postfix) with ESMTPSA id 9D408A0721; Sun, 5 May 2024 16:06:06 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.10.3 zproxy3.enst.fr 8861AA06FC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telecom-paris.fr; s=A35C7578-1106-11E5-A17F-C303FDDA8F2E; t=1714917967; bh=a0JcXUYEaTT4impeQLCUpEzujhW/Bb2lou9Ofz38O+4=; h=From:To:Date:Message-ID:MIME-Version; b=tUD+oOQ+XMpd6j03y3uUdrkl+m0a2vVEDhEJarbXAPnJQRPrqMak0vJstA+h46beU 3/BykhmFnBYR41FdQT2BKZoedUx36bq412Q/TDDMIGN30ElawVxdPM/jCd3l0dvCDL eTb5zMkM1y8LsZnCwjZyw2+szs4qS7XwNVbV74H4= X-Virus-Scanned: amavis at enst.fr From: =?UTF-8?q?In=C3=A8s=20Varhol?= To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Thomas Huth , Arnaud Minier , Laurent Vivier , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?In=C3=A8s=20Varhol?= , Peter Maydell , Alistair Francis , Samuel Tardieu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paolo Bonzini Subject: [PATCH 4/4] tests/qtest: Check STM32L4x5 clock connections Date: Sun, 5 May 2024 16:05:06 +0200 Message-ID: <20240505140556.373711-5-ines.varhol@telecom-paris.fr> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240505140556.373711-1-ines.varhol@telecom-paris.fr> References: <20240505140556.373711-1-ines.varhol@telecom-paris.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2001:660:330f:2::de; envelope-from=ines.varhol@telecom-paris.fr; helo=zproxy3.enst.fr X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @telecom-paris.fr) X-ZM-MESSAGEID: 1714918100479100003 Content-Type: text/plain; charset="utf-8" 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=C3=A8s Varhol --- Hello, Should these tests be regrouped in stm32l4x5_rcc-test.c ? Best regards, In=C3=A8s Varhol tests/qtest/stm32l4x5_gpio-test.c | 39 +++++++++++++++++++++++ tests/qtest/stm32l4x5_syscfg-test.c | 38 +++++++++++++++++++++-- tests/qtest/stm32l4x5_usart-test.c | 48 +++++++++++++++++++++++++++++ 3 files changed, 123 insertions(+), 2 deletions(-) diff --git a/tests/qtest/stm32l4x5_gpio-test.c b/tests/qtest/stm32l4x5_gpio= -test.c index 72a7823406..896c16ad59 100644 --- a/tests/qtest/stm32l4x5_gpio-test.c +++ b/tests/qtest/stm32l4x5_gpio-test.c @@ -25,6 +25,14 @@ #define GPIO_G 0x48001800 #define GPIO_H 0x48001C00 =20 +/* + * MSI (4 MHz) is used as system clock source after startup + * from Reset. + * AHB prescaler is set to 1 at reset. + */ +#define SYSCLK_FREQ_HZ 4000000 +#define RCC_AHB2ENR 0x4002104C + #define MODER 0x00 #define OTYPER 0x04 #define PUPDR 0x0C @@ -168,6 +176,21 @@ static uint32_t reset(uint32_t gpio, unsigned int offs= et) return 0x0; } =20 +static uint32_t get_clock_freq_hz(unsigned int gpio) +{ + g_autofree char *path =3D g_strdup_printf("/machine/soc/gpio%c", + get_gpio_id(gpio) + 'a'); + uint32_t clock_freq_hz =3D 0; + QDict *r; + + r =3D qtest_qmp(global_qtest, "{ 'execute': 'qom-get', 'arguments':" + " { 'path': %s, 'property': 'clock-freq-hz'} }", path); + g_assert_false(qdict_haskey(r, "error")); + clock_freq_hz =3D qdict_get_int(r, "return"); + qobject_unref(r); + return clock_freq_hz; +} + static void system_reset(void) { QDict *r; @@ -505,6 +528,20 @@ static void test_bsrr_brr(const void *data) gpio_writel(gpio, ODR, reset(gpio, ODR)); } =20 +static void test_clock_enable(void) +{ + /* + * For each GPIO, enable its clock in RCC + * and check that its clock frequency changes to SYSCLK_FREQ_HZ + */ + for (uint32_t gpio =3D GPIO_A; gpio <=3D GPIO_H; gpio +=3D GPIO_B - GP= IO_A) { + g_assert_cmpuint(get_clock_freq_hz(gpio), =3D=3D, 0); + /* Enable the gpio clock */ + writel(RCC_AHB2ENR, readl(RCC_AHB2ENR) | (0x1 << get_gpio_id(gpio)= )); + g_assert_cmpuint(get_clock_freq_hz(gpio), =3D=3D, SYSCLK_FREQ_HZ); + } +} + int main(int argc, char **argv) { int ret; @@ -556,6 +593,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); =20 qtest_start("-machine b-l475e-iot01a"); ret =3D g_test_run(); diff --git a/tests/qtest/stm32l4x5_syscfg-test.c b/tests/qtest/stm32l4x5_sy= scfg-test.c index 506ca08bc2..616106460d 100644 --- a/tests/qtest/stm32l4x5_syscfg-test.c +++ b/tests/qtest/stm32l4x5_syscfg-test.c @@ -26,9 +26,18 @@ #define INVALID_ADDR 0x2C =20 /* SoC forwards GPIOs to SysCfg */ -#define SYSCFG "/machine/soc" +#define SOC "/machine/soc" +#define SYSCFG "/machine/soc/syscfg" #define EXTI "/machine/soc/exti" =20 +/* + * MSI (4 MHz) is used as system clock source after startup + * from Reset. + * AHB and APB2 prescalers are set to 1 at reset. + */ +#define SYSCLK_FREQ_HZ 4000000 +#define RCC_APB2ENR 0x40021060 + static void syscfg_writel(unsigned int offset, uint32_t value) { writel(SYSCFG_BASE_ADDR + offset, value); @@ -41,7 +50,7 @@ static uint32_t syscfg_readl(unsigned int offset) =20 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); } =20 static void system_reset(void) @@ -52,6 +61,19 @@ static void system_reset(void) qobject_unref(response); } =20 +static uint32_t get_clock_freq_hz() +{ + uint32_t clock_freq_hz =3D 0; + QDict *r; + + r =3D qtest_qmp(global_qtest, "{ 'execute': 'qom-get', 'arguments':" + " { 'path': %s, 'property': 'clock-freq-hz'} }", SYSCFG); + g_assert_false(qdict_haskey(r, "error")); + clock_freq_hz =3D qdict_get_int(r, "return"); + qobject_unref(r); + return clock_freq_hz; +} + static void test_reset(void) { /* @@ -301,6 +323,16 @@ static void test_irq_gpio_multiplexer(void) syscfg_writel(SYSCFG_EXTICR1, 0x00000000); } =20 +static void test_clock_enable(void) +{ + g_assert_cmpuint(get_clock_freq_hz(), =3D=3D, 0); + + /* Enable SYSCFG clock */ + writel(RCC_APB2ENR, readl(RCC_APB2ENR) | (0x1 << 0)); + + g_assert_cmpuint(get_clock_freq_hz(), =3D=3D, SYSCLK_FREQ_HZ); +} + int main(int argc, char **argv) { int ret; @@ -325,6 +357,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); =20 qtest_start("-machine b-l475e-iot01a"); ret =3D g_test_run(); diff --git a/tests/qtest/stm32l4x5_usart-test.c b/tests/qtest/stm32l4x5_usa= rt-test.c index 8902518233..6e6e66b6ab 100644 --- a/tests/qtest/stm32l4x5_usart-test.c +++ b/tests/qtest/stm32l4x5_usart-test.c @@ -17,6 +17,16 @@ /* Use USART 1 ADDR, assume the others work the same */ #define USART1_BASE_ADDR 0x40013800 =20 +/* + * MSI (4 MHz) is used as system clock source after startup + * from Reset. + * AHB, APB1 and APB2 prescaler are set to 1 at reset. + */ +#define SYSCLK_FREQ_HZ 4000000 +#define RCC_APB1ENR1 0x40021058 +#define RCC_APB1ENR2 0x4002105C +#define RCC_APB2ENR 0x40021060 + /* See stm32l4x5_usart for definitions */ REG32(CR1, 0x00) FIELD(CR1, M1, 28, 1) @@ -64,6 +74,19 @@ static bool clear_nvic_pending(QTestState *qts, unsigned= int n) return true; } =20 +static uint32_t get_clock_freq_hz(QTestState *qts, const char *path) +{ + uint32_t clock_freq_hz =3D 0; + QDict *r; + + r =3D qtest_qmp(qts, "{ 'execute': 'qom-get', 'arguments':" + " { 'path': %s, 'property': 'clock-freq-hz'} }", path); + g_assert_false(qdict_haskey(r, "error")); + clock_freq_hz =3D qdict_get_int(r, "return"); + qobject_unref(r); + return clock_freq_hz; +} + /* * Wait indefinitely for the flag to be updated. * If this is run on a slow CI runner, @@ -296,6 +319,30 @@ static void test_send_str(void) qtest_quit(qts); } =20 +static void check_clock(QTestState *qts, const char *path, uint32_t rcc_re= g, + uint32_t reg_offset) +{ + g_assert_cmpuint(get_clock_freq_hz(qts, path), =3D=3D, 0); + qtest_writel(qts, rcc_reg, qtest_readl(qts, rcc_reg) | (0x1 << reg_off= set)); + g_assert_cmpuint(get_clock_freq_hz(qts, path), =3D=3D, SYSCLK_FREQ_HZ); +} + +static void test_clock_enable(void) +{ + /* + * For each USART device, enable its clock in RCC + * and check that its clock frequency is SYSCLK_FREQ_HZ + */ + QTestState *qts =3D qtest_init("-M b-l475e-iot01a"); + + check_clock(qts, "machine/soc/usart[0]", RCC_APB2ENR, 14); + check_clock(qts, "machine/soc/usart[1]", RCC_APB1ENR1, 17); + check_clock(qts, "machine/soc/usart[2]", RCC_APB1ENR1, 18); + check_clock(qts, "machine/soc/uart[0]", RCC_APB1ENR1, 19); + check_clock(qts, "machine/soc/uart[1]", RCC_APB1ENR1, 20); + check_clock(qts, "machine/soc/lpuart1", RCC_APB1ENR2, 0); +} + int main(int argc, char **argv) { int ret; @@ -308,6 +355,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 =3D g_test_run(); =20 return ret; --=20 2.43.2