From nobody Sun May 19 14:14:27 2024 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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1714134615; cv=none; d=zohomail.com; s=zohoarc; b=dYirU3ezdLsCUaWzUO2wZopzsucvkT8HL0Pt5klCRkf3fjoFRR3QIBQZQWuVkU2yo7c0BNygZTmNXB0DpBD3mUe3NYi3X5CHtmpJCtUN/cWe1AJ1CpNuUcz39kYEB+XBj7WA4mWtwkWZ4IqjBBIA0gGqRcI2jSTCPjNkSQqufBI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1714134615; 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=DB0/7Uqp2qUB8AIDdwjge4FwiUAyUxwuYK0G2iKn4ik=; b=atpBwbik3rRcXeC8M5Y4CspDWAdTNrgYXVUEtw5VXN46gxA5tWkBkosHGV35aXTItsbaEh8qIkgoC547uRB6YfcXHqPDMA+/F2bGdiqD4Z+jh/SjjXyFR7P2OMeN3iJbwNhlTOFHbXlyB+Xi1iZNUwI4aSBg8o/s3hqUeYsurbc= 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 1714134614855382.3733958293201; Fri, 26 Apr 2024 05:30:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s0Khf-00039z-1v; Fri, 26 Apr 2024 08:29:23 -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 1s0Khc-00039d-Am for qemu-devel@nongnu.org; Fri, 26 Apr 2024 08:29:20 -0400 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s0KhZ-00064f-NS for qemu-devel@nongnu.org; Fri, 26 Apr 2024 08:29:20 -0400 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-41ba1ba5591so2421165e9.1 for ; Fri, 26 Apr 2024 05:29:17 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id m15-20020a05600c460f00b0041a964b55ddsm1397134wmo.1.2024.04.26.05.29.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Apr 2024 05:29:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1714134556; x=1714739356; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DB0/7Uqp2qUB8AIDdwjge4FwiUAyUxwuYK0G2iKn4ik=; b=qDLbAyKdbgASlqXkTww1ViH8YU6hVgUh7iGxletNdXqOq1+tyAHtnPlzQ81U7GX4Op GylbqcURjpA0NiGVJZM5m34VYjO0IH9hXxxaGauj2p1kct9GxQ6vgkJenOM8j2PBHlZy wyYz5bxNTTBF0k+5ZwlF+lO0xXpYesy1H+2s8nKRHj/N9YYPgc4igBJmQG4RsxtwuHz8 L+FL0L8tUlgbQ/KBM5aNn8go6qD64MPobA5ZFuMmgahHCDv0s5umKGz8OYlQSPDbMHjT 2nCza2jAHHo6h8ax+A3avW1UwEP2CruGMbGSB1aP1V1VBS+w2CxVMJHXJo1XPyJHFXj9 Ifbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714134556; x=1714739356; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DB0/7Uqp2qUB8AIDdwjge4FwiUAyUxwuYK0G2iKn4ik=; b=Jl+13V7BmmOCX1VZVn299noZJ7KxNm9GZC03nDcLebalWjZa47HIjDL8GdUB8hdFML AA3Gnp6YkvB9LdvjLKrJaqVYLNdDxl70DdtTAGvnBnqDTrK1zxjgSAgKTsVKa5PlgtIt oW9A53Xi6zvoK5qOfFn7oYvdDEyYfPT6Nk2/GMS5LstOm89dWnsKXCGcu0u2uYYjjr7P /m0lKwLqFmtzKj0mbbE+Wl/u+0MKaMUJStPYeW2Mhm2PXGQG9saBRUOJPv3kmB148jz3 GZHrmoEFaBYmVjylOCdsUhGfxPAxrmeCdqV308EDpjX9TNuD5yqmtqtSu91036HUYxZu KBcw== X-Forwarded-Encrypted: i=1; AJvYcCWjtgPrdTinwnhwvIoRaJDT9EGmJhGfpjPeB+FN7S/e9k2YGGt2Ksi3jGbP9tWmz/EhGUqeroRAHQVJq0I+jKLlXLLTzHM= X-Gm-Message-State: AOJu0YzrT86kzXvlvaInB20EpOplMaOZzJrXzZuKF+QzLnLTGm0Hy74T 2dBylO+tVGYcsQYpChYB1QlNJ5ubPCNxneO2klCnoGmrCssDJlUHs6LpcfiogBc= X-Google-Smtp-Source: AGHT+IHCAP5IkNiPFnFpcNNCL7txGdygEj/htN3jHc4CxfhejruZd2+PvvxeDgIwV/1AihzOFSco1A== X-Received: by 2002:a05:600c:470f:b0:41a:8374:7eae with SMTP id v15-20020a05600c470f00b0041a83747eaemr1980934wmo.31.1714134555834; Fri, 26 Apr 2024 05:29:15 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: Radoslaw Biernacki , Leif Lindholm , Marcin Juszkiewicz Subject: [PATCH v2 1/4] target/arm: Refactor default generic timer frequency handling Date: Fri, 26 Apr 2024 13:29:10 +0100 Message-Id: <20240426122913.3427983-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240426122913.3427983-1-peter.maydell@linaro.org> References: <20240426122913.3427983-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=2a00:1450:4864:20::32c; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32c.google.com 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, RCVD_IN_DNSWL_NONE=-0.0001, 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 @linaro.org) X-ZM-MESSAGEID: 1714134616631100003 The generic timer frequency is settable by board code via a QOM property "cntfrq", but otherwise defaults to 62.5MHz. The way this is done includes some complication resulting from how this was originally a fixed value with no QOM property. Clean it up: * always set cpu->gt_cntfrq_hz to some sensible value, whether the CPU has the generic timer or not, and whether it's system or user-only emulation * this means we can always use gt_cntfrq_hz, and never need the old GTIMER_SCALE define * set the default value in exactly one place, in the realize fn The aim here is to pave the way for handling the ARMv8.6 requirement that the generic timer frequency is always 1GHz. We're going to do that by having old CPU types keep their legacy-in-QEMU behaviour and having the default for any new CPU types be a 1GHz rather han 62.5MHz cntfrq, so we want the point where the default is decided to be in one place, and in code, not in a DEFINE_PROP_UINT64() initializer. This commit should have no behavioural changes. Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson --- target/arm/internals.h | 7 ++++--- target/arm/cpu.c | 31 +++++++++++++++++-------------- target/arm/helper.c | 16 ++++++++-------- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/target/arm/internals.h b/target/arm/internals.h index b53f5e8ff2a..a1509a3a58e 100644 --- a/target/arm/internals.h +++ b/target/arm/internals.h @@ -59,10 +59,11 @@ static inline bool excp_is_internal(int excp) || excp =3D=3D EXCP_SEMIHOST; } =20 -/* Scale factor for generic timers, ie number of ns per tick. - * This gives a 62.5MHz timer. +/* + * Default frequency for the generic timer, in Hz. + * This is 62.5MHz, which gives a 16 ns tick period. */ -#define GTIMER_SCALE 16 +#define GTIMER_DEFAULT_HZ 62500000 =20 /* Bit definitions for the v7M CONTROL register */ FIELD(V7M_CONTROL, NPRIV, 0, 1) diff --git a/target/arm/cpu.c b/target/arm/cpu.c index a152def2413..9f2ca6633a1 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -1506,9 +1506,12 @@ static void arm_cpu_initfn(Object *obj) } } =20 +/* + * 0 means "unset, use the default value". That default might vary dependi= ng + * on the CPU type, and is set in the realize fn. + */ static Property arm_cpu_gt_cntfrq_property =3D - DEFINE_PROP_UINT64("cntfrq", ARMCPU, gt_cntfrq_hz, - NANOSECONDS_PER_SECOND / GTIMER_SCALE); + DEFINE_PROP_UINT64("cntfrq", ARMCPU, gt_cntfrq_hz, 0); =20 static Property arm_cpu_reset_cbar_property =3D DEFINE_PROP_UINT64("reset-cbar", ARMCPU, reset_cbar, 0); @@ -1954,6 +1957,17 @@ static void arm_cpu_realizefn(DeviceState *dev, Erro= r **errp) return; } =20 + if (!cpu->gt_cntfrq_hz) { + /* + * 0 means "the board didn't set a value, use the default". + * The default value of the generic timer frequency (as seen in + * CNTFRQ_EL0) is 62.5MHz, which corresponds to a period of 16ns. + * This is what you get (a) for a CONFIG_USER_ONLY CPU (b) if the + * board doesn't set it. + */ + cpu->gt_cntfrq_hz =3D GTIMER_DEFAULT_HZ; + } + #ifndef CONFIG_USER_ONLY /* The NVIC and M-profile CPU are two halves of a single piece of * hardware; trying to use one without the other is a command line @@ -2002,18 +2016,7 @@ static void arm_cpu_realizefn(DeviceState *dev, Erro= r **errp) } =20 { - uint64_t scale; - - if (arm_feature(env, ARM_FEATURE_GENERIC_TIMER)) { - if (!cpu->gt_cntfrq_hz) { - error_setg(errp, "Invalid CNTFRQ: %"PRId64"Hz", - cpu->gt_cntfrq_hz); - return; - } - scale =3D gt_cntfrq_period_ns(cpu); - } else { - scale =3D GTIMER_SCALE; - } + uint64_t scale =3D gt_cntfrq_period_ns(cpu); =20 cpu->gt_timer[GTIMER_PHYS] =3D timer_new(QEMU_CLOCK_VIRTUAL, scale, arm_gt_ptimer_cb, cpu); diff --git a/target/arm/helper.c b/target/arm/helper.c index 6b224826fbb..1e3002f9947 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -2474,6 +2474,13 @@ static const ARMCPRegInfo v6k_cp_reginfo[] =3D { .resetvalue =3D 0 }, }; =20 +static void arm_gt_cntfrq_reset(CPUARMState *env, const ARMCPRegInfo *opaq= ue) +{ + ARMCPU *cpu =3D env_archcpu(env); + + cpu->env.cp15.c14_cntfrq =3D cpu->gt_cntfrq_hz; +} + #ifndef CONFIG_USER_ONLY =20 static CPAccessResult gt_cntfrq_access(CPUARMState *env, const ARMCPRegInf= o *ri, @@ -3228,13 +3235,6 @@ void arm_gt_hvtimer_cb(void *opaque) gt_recalc_timer(cpu, GTIMER_HYPVIRT); } =20 -static void arm_gt_cntfrq_reset(CPUARMState *env, const ARMCPRegInfo *opaq= ue) -{ - ARMCPU *cpu =3D env_archcpu(env); - - cpu->env.cp15.c14_cntfrq =3D cpu->gt_cntfrq_hz; -} - static const ARMCPRegInfo generic_timer_cp_reginfo[] =3D { /* * Note that CNTFRQ is purely reads-as-written for the benefit @@ -3514,7 +3514,7 @@ static const ARMCPRegInfo generic_timer_cp_reginfo[] = =3D { .opc0 =3D 3, .opc1 =3D 3, .crn =3D 14, .crm =3D 0, .opc2 =3D 0, .type =3D ARM_CP_CONST, .access =3D PL0_R /* no PL1_RW in linux-user= */, .fieldoffset =3D offsetof(CPUARMState, cp15.c14_cntfrq), - .resetvalue =3D NANOSECONDS_PER_SECOND / GTIMER_SCALE, + .resetfn =3D arm_gt_cntfrq_reset, }, { .name =3D "CNTVCT_EL0", .state =3D ARM_CP_STATE_AA64, .opc0 =3D 3, .opc1 =3D 3, .crn =3D 14, .crm =3D 0, .opc2 =3D 2, --=20 2.34.1 From nobody Sun May 19 14:14:27 2024 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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1714134614; cv=none; d=zohomail.com; s=zohoarc; b=Tdt1dt82xJATAOSZyaqPoXmMBd1haXJ/+EcdHcE/YfJYVJeUByq29Nmx3z6JONk/N9ML36HjQGHMQXAHbK1EWvd3QuykpLsrsGtfsfkHYZLJNXoGtqjP9tCU4YNaDbhHj4ouTp+Yk/VahTOP66HUpGbRKRUMZvPDXFlHb8BKIlw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1714134614; h=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=N0nd37JbIqFWOk7TVvpZsBjDnU/+rTPYGOgPUq3SDrY=; b=CaA1PCztj2XFvwKC85ROYv32ncC+fa7GA9eNGUTTmolK8CRAiP1iiqSyi0k9JISigSPO5/7rSknQyrkF/1db1UZJLxtLYWTR3tI4fxfqC2q2N1US0hb6gi7hxbHWIVbN1P//4ws2T+bdHUKEPSb7hCLXi8oayZJ8wa4+WKG2kEg= 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 171413461455587.16693034278114; Fri, 26 Apr 2024 05:30:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s0Khg-0003Bz-T0; Fri, 26 Apr 2024 08:29: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 1s0Khd-0003A2-Uq for qemu-devel@nongnu.org; Fri, 26 Apr 2024 08:29:21 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s0Khb-00064m-33 for qemu-devel@nongnu.org; Fri, 26 Apr 2024 08:29:21 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-41b79451145so6704185e9.3 for ; Fri, 26 Apr 2024 05:29:17 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id m15-20020a05600c460f00b0041a964b55ddsm1397134wmo.1.2024.04.26.05.29.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Apr 2024 05:29:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1714134556; x=1714739356; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=N0nd37JbIqFWOk7TVvpZsBjDnU/+rTPYGOgPUq3SDrY=; b=AXqnKx4FbHeeJXfIuj3UCBTL1pLdXSthtg832dHJ9ggZerQCNOUDreXyKJEUulqhRg oecRk88yZNhLXtPdJ7vdjTgNsA4w1Rsxt5rtaT/OTgWJCTsIqP+TlsPQO/j3/KoOqrz5 BHsct3d8bFj1vxYOxVjj02EZS94M3Jjkw6iKAcIEIZA9PJq1lZ4RZRendNhSX7XZ30qy REj9BZkzeQhkjgM4KJlCAuOf8mAcwYJDRteFgQBYoEaVjXSNuul2zc6P8SDUMCgIvDI6 gg3efamYVpL5agODwePI6+r1rvOzucEg58cVlDpWUnk/T/AGX1xHikUl5iUmrQVgzQz/ sgSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714134556; x=1714739356; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=N0nd37JbIqFWOk7TVvpZsBjDnU/+rTPYGOgPUq3SDrY=; b=jBBRgQfYB98mFrFYmSpnoqdeRKTprhVd9bDdQUJw+KybMh2OPK50hPfEgms7MK+IDi kSPdolwkcagZ2LeoefPIhOZD02eOVNFgFb7QxxfnKsyitq5YgiW9SSiqPg5QQaZnUj7B 9KqxAPLbOu5gbtAcmWIazlM70BCz1OyRkS8nxFT3Vb7CY1gk3Ke3alYxSOyztbJWxCda zJzoolocqZJWLp20DKd5n7eJxn1XTZEFVzO+YMPHAS4MnldTx16QaBg1/DWqy8+qXqw1 nzcSDa6dHW26fN7cOb5CKL4dC7pct8jVWmVB7hqRDqaQtmp39G0V7pUYZs5Q57EUmBZy O17Q== X-Forwarded-Encrypted: i=1; AJvYcCXT0vGLBjFQhGm3wkyLuTvo1tzVKJPr7pRHyKiwMm1PU+J4lTADNumPX2obZtR3dg72GOpqGvSolEy1rNLzpnz5XGjWa7Y= X-Gm-Message-State: AOJu0YytrmFTeU6Z4F+/rmpHKCReRAJkOAY8qBGae72iY0xint+XNIsW /8azTRRQZeVq2/thTwXw4Am5AwhTVdJPFPWmb5Kx1kmPlBUMkFEx8vy7wwXGnu8= X-Google-Smtp-Source: AGHT+IG8SvxrQNIjmW4bPYl1czbbKbVwvl1QZZJle5Gy+D+sJo8gvacM9RYndo/t2J7f0GdTWFnMtA== X-Received: by 2002:a05:600c:4e47:b0:41a:e995:b924 with SMTP id e7-20020a05600c4e4700b0041ae995b924mr1758805wmq.33.1714134556360; Fri, 26 Apr 2024 05:29:16 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: Radoslaw Biernacki , Leif Lindholm , Marcin Juszkiewicz Subject: [PATCH v2 2/4] hw/arm/sbsa-ref: Force CPU generic timer to 62.5MHz Date: Fri, 26 Apr 2024 13:29:11 +0100 Message-Id: <20240426122913.3427983-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240426122913.3427983-1-peter.maydell@linaro.org> References: <20240426122913.3427983-1-peter.maydell@linaro.org> 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=2a00:1450:4864:20::32d; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32d.google.com 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, RCVD_IN_DNSWL_NONE=-0.0001, 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 @linaro.org) X-ZM-MESSAGEID: 1714134616601100001 Content-Type: text/plain; charset="utf-8" Currently QEMU CPUs always run with a generic timer counter frequency of 62.5MHz, but ARMv8.6 CPUs will run at 1GHz. For older versions of the TF-A firmware that sbsa-ref runs, the frequency of the generic timer is hardcoded into the firmware, and so if the CPU actually has a different frequency then timers in the guest will be set incorrectly. The default frequency used by the 'max' CPU is about to change, so make the sbsa-ref board force the CPU frequency to the value which the firmware expects. Newer versions of TF-A will read the frequency from the CPU's CNTFRQ_EL0 register: https://github.com/ARM-software/arm-trusted-firmware/commit/4c77fac98dac0b= ebc63798aae9101ac865b87148 so in the longer term we could make this board use the 1GHz frequency. We will need to make sure we update the binaries used by our avocado test Aarch64SbsarefMachine.test_sbsaref_alpine_linux_max_pauth_impdef before we can do that. Signed-off-by: Peter Maydell Reviewed-by: Marcin Juszkiewicz Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- I leave it up to the sbsa-ref maintainers exactly when they want to shift to 1GHz (probably after a TF-A release with the fix?) --- hw/arm/sbsa-ref.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c index f5709d6c141..36f6f717b4b 100644 --- a/hw/arm/sbsa-ref.c +++ b/hw/arm/sbsa-ref.c @@ -60,6 +60,19 @@ #define NUM_SMMU_IRQS 4 #define NUM_SATA_PORTS 6 =20 +/* + * Generic timer frequency in Hz (which drives both the CPU generic timers + * and the SBSA watchdog-timer). Older versions of the TF-A firmware + * typically used with sbsa-ref (including the binaries in our Avocado test + * Aarch64SbsarefMachine.test_sbsaref_alpine_linux_max_pauth_impdef + * assume it is this value. + * + * TODO: this value is not architecturally correct for an Armv8.6 or + * better CPU, so we should move to 1GHz once the TF-A fix above has + * made it into a release and into our Avocado test. + */ +#define SBSA_GTIMER_HZ 62500000 + enum { SBSA_FLASH, SBSA_MEM, @@ -767,6 +780,8 @@ static void sbsa_ref_init(MachineState *machine) &error_abort); } =20 + object_property_set_int(cpuobj, "cntfrq", SBSA_GTIMER_HZ, &error_a= bort); + object_property_set_link(cpuobj, "memory", OBJECT(sysmem), &error_abort); =20 --=20 2.34.1 From nobody Sun May 19 14:14:27 2024 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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1714134634; cv=none; d=zohomail.com; s=zohoarc; b=dUXqgSi7QevvccKdv7amMqlQoTC+YGooI/a+ioLnsFp4KVel4b6ORnDEtqYu0QwgTJf40NRnX8iDvMUjsE8r9qAVpsvUd+HZGZhviyeGZC7H3b1/L0nGK+0EAhXuM0VwCI52G7B6/3I7ANIqx6aeqOx4Cp+KXZyOwlPeSUDOaQo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1714134634; h=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=WS9SzNWMMODXM/MCi5WitYJBrcmDnkYWEhDYB5gmtic=; b=lB6NvSvtk48amKGidOz2QmMLTkuVME9xr2YfmkQ+sE9WPhKjVNzSDPhtroqExVTNb9OH3xPrm7ueJTTr1v93LawoFraeSVuPdvi1M7BAAEQGhpMVJh8bp88xLXAsnOHSmmmAbwtrGNXr3ucZa0BuvTZsZkKnGx1QRoW13ms1suk= 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 1714134634224173.75195981437082; Fri, 26 Apr 2024 05:30:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s0Khh-0003CK-Hs; Fri, 26 Apr 2024 08:29: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 1s0Khg-0003Bn-4E for qemu-devel@nongnu.org; Fri, 26 Apr 2024 08:29:24 -0400 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s0Khb-00064u-BV for qemu-devel@nongnu.org; Fri, 26 Apr 2024 08:29:23 -0400 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-41bab13ca4eso1241605e9.1 for ; Fri, 26 Apr 2024 05:29:18 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id m15-20020a05600c460f00b0041a964b55ddsm1397134wmo.1.2024.04.26.05.29.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Apr 2024 05:29:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1714134557; x=1714739357; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=WS9SzNWMMODXM/MCi5WitYJBrcmDnkYWEhDYB5gmtic=; b=H2z+ryAfa1GmC2U5USp1dWHx+58KAfKPfOnLU6LVLP+uodx9C+6ACc6sC3YPcKAnF+ Ukl5Ciata/UbApgbJ8rRwFQN799taAFDes2GNp3Got0LSoomNFtbcFoPSBGFIkDFklrb FMfbvarAxG+l+FiMsvSJm9mpm6kSNKhbcxTAuKMCKwmt4+MX3X+Ox5GImXsI7g2A/mql JNQFjng03J4lFaZHhZ0qWaq4jqLgLB6zDC8HHCpbxBYKFPKtJ2DxRPfzjZ2VhScTPXtT Sun77dJ+w2RI7kokldURUW4sHXGc9FuDjhpg1hbE1gNvWdtINEfOd/0ejIUoIv4W6sXJ xOYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714134557; x=1714739357; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WS9SzNWMMODXM/MCi5WitYJBrcmDnkYWEhDYB5gmtic=; b=Q2Sw702V3GN4nDPRZAwfYgjjcTRnfRs1S8tnSXNbl1iqqDCr39jOm8nvO300wirF8F cs4r+C055BDE54lDXH8efBMEVpEPa9uIrDUnZyhZPC+wXD9e1kCatFUR094W20l0pMX/ axbkeSLuTmAtI+Itzy2iRt6D29NzhnWzs0ZiWuqzgv5EfXp7A56sZRym0XcWm9tgddSc 0LDBSkzmN3rKrI6YrQ8zCTJfss+1IzDjpv09zgMpgcUcwBimJEHuVVh0+mKRilI3PZTY prUdIIOFI4Z/mhe+8xp6UyT/LOwiuu2YGVTF1PrCeK46f7LeoSjrBzYK3XnBiYee5tMz OUhQ== X-Forwarded-Encrypted: i=1; AJvYcCWh5kuQJp/8wHYPMY449+2RAjqVnuScZ9j4ESUxrbLxn6mmG/t0Zs7verXbToVQT+Xa0xMeeKZmO2UK96FBE9iY8fv5W7U= X-Gm-Message-State: AOJu0YwflXl2sNtaMJLmfencZRR8hSif3ywe08mvMnk+Rfr2odUIWdpZ LpWhu1CRlfODmV2a2Nes6SqngdxJoR5zsjyw9AQlnPsgvoTgHn1lmXkPKUa7/SU= X-Google-Smtp-Source: AGHT+IFraGiaPWygrlDarrqP90vgN/sfZK93sIMurUjsbEhQeZpwH4rNYWW0kKHbh2dy5bV0f0U4lw== X-Received: by 2002:a05:600c:45cd:b0:41a:a521:9699 with SMTP id s13-20020a05600c45cd00b0041aa5219699mr1970436wmo.4.1714134556905; Fri, 26 Apr 2024 05:29:16 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: Radoslaw Biernacki , Leif Lindholm , Marcin Juszkiewicz Subject: [PATCH v2 3/4] hw/watchdog/sbsa_gwdt: Make watchdog timer frequency a QOM property Date: Fri, 26 Apr 2024 13:29:12 +0100 Message-Id: <20240426122913.3427983-4-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240426122913.3427983-1-peter.maydell@linaro.org> References: <20240426122913.3427983-1-peter.maydell@linaro.org> 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=2a00:1450:4864:20::332; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x332.google.com 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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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 @linaro.org) X-ZM-MESSAGEID: 1714134636081100005 Content-Type: text/plain; charset="utf-8" Currently the sbsa_gdwt watchdog device hardcodes its frequency at 62.5MHz. In real hardware, this watchdog is supposed to be driven from the system counter, which also drives the CPU generic timers. Newer CPU types (in particular from Armv8.6) should have a CPU generic timer frequency of 1GHz, so we can't leave the watchdog on the old QEMU default of 62.5GHz. Make the frequency a QOM property so it can be set by the board, and have our only board that uses this device set that frequency to the same value it sets the CPU frequency. Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/hw/watchdog/sbsa_gwdt.h | 3 +-- hw/arm/sbsa-ref.c | 1 + hw/watchdog/sbsa_gwdt.c | 15 ++++++++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/include/hw/watchdog/sbsa_gwdt.h b/include/hw/watchdog/sbsa_gwd= t.h index 70b137de301..4bdc6c6fdb6 100644 --- a/include/hw/watchdog/sbsa_gwdt.h +++ b/include/hw/watchdog/sbsa_gwdt.h @@ -55,8 +55,6 @@ #define SBSA_GWDT_RMMIO_SIZE 0x1000 #define SBSA_GWDT_CMMIO_SIZE 0x1000 =20 -#define SBSA_TIMER_FREQ 62500000 /* Hz */ - typedef struct SBSA_GWDTState { /* */ SysBusDevice parent_obj; @@ -67,6 +65,7 @@ typedef struct SBSA_GWDTState { qemu_irq irq; =20 QEMUTimer *timer; + uint64_t freq; =20 uint32_t id; uint32_t wcs; diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c index 36f6f717b4b..57c337fd92a 100644 --- a/hw/arm/sbsa-ref.c +++ b/hw/arm/sbsa-ref.c @@ -543,6 +543,7 @@ static void create_wdt(const SBSAMachineState *sms) SysBusDevice *s =3D SYS_BUS_DEVICE(dev); int irq =3D sbsa_ref_irqmap[SBSA_GWDT_WS0]; =20 + qdev_prop_set_uint64(dev, "clock-frequency", SBSA_GTIMER_HZ); sysbus_realize_and_unref(s, &error_fatal); sysbus_mmio_map(s, 0, rbase); sysbus_mmio_map(s, 1, cbase); diff --git a/hw/watchdog/sbsa_gwdt.c b/hw/watchdog/sbsa_gwdt.c index 96895d76369..d437535cc66 100644 --- a/hw/watchdog/sbsa_gwdt.c +++ b/hw/watchdog/sbsa_gwdt.c @@ -18,6 +18,7 @@ #include "qemu/osdep.h" #include "sysemu/reset.h" #include "sysemu/watchdog.h" +#include "hw/qdev-properties.h" #include "hw/watchdog/sbsa_gwdt.h" #include "qemu/timer.h" #include "migration/vmstate.h" @@ -109,7 +110,7 @@ static void sbsa_gwdt_update_timer(SBSA_GWDTState *s, W= dtRefreshType rtype) timeout =3D s->woru; timeout <<=3D 32; timeout |=3D s->worl; - timeout =3D muldiv64(timeout, NANOSECONDS_PER_SECOND, SBSA_TIMER_F= REQ); + timeout =3D muldiv64(timeout, NANOSECONDS_PER_SECOND, s->freq); timeout +=3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); =20 if ((rtype =3D=3D EXPLICIT_REFRESH) || ((rtype =3D=3D TIMEOUT_REFR= ESH) && @@ -261,6 +262,17 @@ static void wdt_sbsa_gwdt_realize(DeviceState *dev, Er= ror **errp) dev); } =20 +static Property wdt_sbsa_gwdt_props[] =3D { + /* + * Timer frequency in Hz. This must match the frequency used by + * the CPU's generic timer. Default 62.5Hz matches QEMU's legacy + * CPU timer frequency default. + */ + DEFINE_PROP_UINT64("clock-frequency", struct SBSA_GWDTState, freq, + 62500000), + DEFINE_PROP_END_OF_LIST(), +}; + static void wdt_sbsa_gwdt_class_init(ObjectClass *klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); @@ -271,6 +283,7 @@ static void wdt_sbsa_gwdt_class_init(ObjectClass *klass= , void *data) set_bit(DEVICE_CATEGORY_WATCHDOG, dc->categories); dc->vmsd =3D &vmstate_sbsa_gwdt; dc->desc =3D "SBSA-compliant generic watchdog device"; + device_class_set_props(dc, wdt_sbsa_gwdt_props); } =20 static const TypeInfo wdt_sbsa_gwdt_info =3D { --=20 2.34.1 From nobody Sun May 19 14:14:27 2024 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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1714134633; cv=none; d=zohomail.com; s=zohoarc; b=JXxL6Dua+Q5hUM6hgvmy+qpH9Lgl3tbEV8nl7OcFhgLjRGUuET/PExjgMLqFDL9aO8ElspgXpEdNZe9+QGWcwThhisqpHid3kQd1sD2UvmLIzILp3HOxMjLzQ201hocWxbH+M5VJxPB6Uvro2lqUoQbUXVJdpHGIk+Ybl55b+Wg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1714134633; 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=q3y0R1vsfiLr1WCIZ1FebY/60oHcB7hAtVgV1KQkX9c=; b=n+k/jxFc9WFX6tNql9hKoDZObLhSG9v/vhuMZ32M47f1Mf1iovjl2L2zIJYom03p5t6Ws1FoqdcQOeZrAqaRq66aqVOZgU//fCrXtoKL1qX0m7ASe2liKSd4tlNmpO58lsUbp9Bzte+/5AIKFE9eyVUJdn6N/UjGansgsfMA1xA= 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 1714134633987499.23893465822914; Fri, 26 Apr 2024 05:30:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s0Khm-0003Ed-Dz; Fri, 26 Apr 2024 08:29:30 -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 1s0Khi-0003D6-M0 for qemu-devel@nongnu.org; Fri, 26 Apr 2024 08:29:27 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s0Khb-000655-QT for qemu-devel@nongnu.org; Fri, 26 Apr 2024 08:29:26 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-4155819f710so15711345e9.2 for ; Fri, 26 Apr 2024 05:29:19 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id m15-20020a05600c460f00b0041a964b55ddsm1397134wmo.1.2024.04.26.05.29.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Apr 2024 05:29:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1714134557; x=1714739357; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=q3y0R1vsfiLr1WCIZ1FebY/60oHcB7hAtVgV1KQkX9c=; b=ERtohyW60QZtwC+FgdOTYxMhihCh3BEN8zoCN0v6fBlSRd4uzlBsPFqBJzK15/x09u MZJQhDA1BeZ+7MLPIvZRPCCaE0gshHQjcwaayNIzcD9WLYXDS3mxfZxI8WD+sEham6ML C78iK5+hYqjhZ8J3aryem/Rxfx3uktNZJg8FR6YfLeBlnM2zmMlihKwaFROoNQqKPzZc iGw7v1hsZLU0aHV6+qN/a7B9zxYOFBAeuakIRAvQTRq0EuwLiQDxqOF/c5Odove9ITqr 57qmiwpeAbP89V7S3iMal60fwEO/im4rFIpnCpt+/MIcEUhRPj1UrRzQJhkQ7AKdlm6b e9Yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714134557; x=1714739357; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=q3y0R1vsfiLr1WCIZ1FebY/60oHcB7hAtVgV1KQkX9c=; b=B65Gs7jFIKjdkLTaZCHIyJB2w3dxV9U28MOj1cX19/bc01UvhB+1yUowIx/My0CcYN t9X+AOOkexq4lLi70tI1MovQoTyTF9TBfWmjHtHtU8mWXhpkjadcZcH9i3nZed8Z0YAZ 6lo7Z2gmbNE8Kz0HSrqWp/t711QQ0PFrfN3bGF+cCqcKZw+Vmto0kYFf0m5HxAhSBaJh qw5BNfFdhN5KbNF/EGPCIID73aGibAQv+zPST7CqWxR0pFt5R6xX36RLqx8Kgs3tKwb+ VNq+vLgSIO4OmIcwi6BTmK9g+4eFF8/BJj3XsQzVmi1woxJApwhmvOQR8ugdQ636LREI yUtg== X-Forwarded-Encrypted: i=1; AJvYcCX7nnJ0MeN62lvVawSH2kNJGW08X89OmzHa8lUT2Ri9WkVJRbITa2urzb+ihHmN8VjG0R/QwNtcg+dLna2vfbnAKEA3lH8= X-Gm-Message-State: AOJu0Yxsy2mPIgywuGZLP3EZnu1fpkBXTSX41r/bBDPozTbsdo6bXKGQ A0fs9+k+HE6ebVGbCbKva+OG4Sq2KxV9pNMTiN6vGZ0bkXcJ3DkWa0rlFAZn/dA= X-Google-Smtp-Source: AGHT+IEJ7Ry1kCRsS2eWiLzWfjTyRO3qj5sh7kd9FaGpxOI69dSmOMqLgIv5p99W8kLD0xwvKd9yQg== X-Received: by 2002:a05:600c:a43:b0:41b:9828:f4c2 with SMTP id c3-20020a05600c0a4300b0041b9828f4c2mr1107159wmq.3.1714134557463; Fri, 26 Apr 2024 05:29:17 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: Radoslaw Biernacki , Leif Lindholm , Marcin Juszkiewicz Subject: [PATCH v2 4/4] target/arm: Default to 1GHz cntfrq for 'max' and new CPUs Date: Fri, 26 Apr 2024 13:29:13 +0100 Message-Id: <20240426122913.3427983-5-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240426122913.3427983-1-peter.maydell@linaro.org> References: <20240426122913.3427983-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=2a00:1450:4864:20::32d; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32d.google.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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 @linaro.org) X-ZM-MESSAGEID: 1714134636090100006 In previous versions of the Arm architecture, the frequency of the generic timers as reported in CNTFRQ_EL0 could be any IMPDEF value, and for QEMU we picked 62.5MHz, giving a timer tick period of 16ns. In Armv8.6, the architecture standardized this frequency to 1GHz. Because there is no ID register feature field that indicates whether a CPU is v8.6 or that it ought to have this counter frequency, we implement this by changing our default CNTFRQ value for all CPUs, with exceptions for backwards compatibility: * CPU types which we already implement will retain the old default value. None of these are v8.6 CPUs, so this is architecturally OK. * CPUs used in versioned machine types with a version of 9.0 or earlier will retain the old default value. The upshot is that the only CPU type that changes is 'max'; but any new type we add in future (whether v8.6 or not) will also get the new 1GHz default. It remains the case that the machine model can override the default value via the 'cntfrq' QOM property (regardless of the CPU type). Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- v1->v2: use DEFINE_PROP_BOOL in arm_cpu_properties[] instead of qdev_property_add_static() to define backcompat-cntfrq property --- target/arm/cpu.h | 11 +++++++++++ target/arm/internals.h | 12 ++++++++++-- hw/core/machine.c | 4 +++- target/arm/cpu.c | 23 +++++++++++++++++------ target/arm/cpu64.c | 2 ++ target/arm/tcg/cpu32.c | 4 ++++ target/arm/tcg/cpu64.c | 18 ++++++++++++++++++ 7 files changed, 65 insertions(+), 9 deletions(-) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 97997dbd087..b614bc5d139 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -959,6 +959,9 @@ struct ArchCPU { */ bool host_cpu_probe_failed; =20 + /* QOM property to indicate we should use the back-compat CNTFRQ defau= lt */ + bool backcompat_cntfrq; + /* Specify the number of cores in this CPU cluster. Used for the L2CTLR * register. */ @@ -2359,6 +2362,14 @@ enum arm_features { ARM_FEATURE_M_SECURITY, /* M profile Security Extension */ ARM_FEATURE_M_MAIN, /* M profile Main Extension */ ARM_FEATURE_V8_1M, /* M profile extras only in v8.1M and later */ + /* + * ARM_FEATURE_BACKCOMPAT_CNTFRQ makes the CPU default cntfrq be 62.5M= Hz + * if the board doesn't set a value, instead of 1GHz. It is for backwa= rds + * compatibility and used only with CPU definitions that were already + * in QEMU before we changed the default. It should not be set on any + * CPU types added in future. + */ + ARM_FEATURE_BACKCOMPAT_CNTFRQ, /* 62.5MHz timer default */ }; =20 static inline int arm_feature(CPUARMState *env, int feature) diff --git a/target/arm/internals.h b/target/arm/internals.h index a1509a3a58e..5a5be347c67 100644 --- a/target/arm/internals.h +++ b/target/arm/internals.h @@ -61,9 +61,17 @@ static inline bool excp_is_internal(int excp) =20 /* * Default frequency for the generic timer, in Hz. - * This is 62.5MHz, which gives a 16 ns tick period. + * ARMv8.6 and later CPUs architecturally must use a 1GHz timer; before + * that it was an IMPDEF choice, and QEMU initially picked 62.5MHz, + * which gives a 16ns tick period. + * + * We will use the back-compat value: + * - for QEMU CPU types added before we standardized on 1GHz + * - for versioned machine types with a version of 9.0 or earlier + * In any case, the machine model may override via the cntfrq property. */ -#define GTIMER_DEFAULT_HZ 62500000 +#define GTIMER_DEFAULT_HZ 1000000000 +#define GTIMER_BACKCOMPAT_HZ 62500000 =20 /* Bit definitions for the v7M CONTROL register */ FIELD(V7M_CONTROL, NPRIV, 0, 1) diff --git a/hw/core/machine.c b/hw/core/machine.c index 0dec48e8021..4ff60911e74 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -33,7 +33,9 @@ #include "hw/virtio/virtio-iommu.h" #include "audio/audio.h" =20 -GlobalProperty hw_compat_9_0[] =3D {}; +GlobalProperty hw_compat_9_0[] =3D { + {"arm-cpu", "backcompat-cntfrq", "true" }, +}; const size_t hw_compat_9_0_len =3D G_N_ELEMENTS(hw_compat_9_0); =20 GlobalProperty hw_compat_8_2[] =3D { diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 9f2ca6633a1..fdc3eda318a 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -1959,13 +1959,22 @@ static void arm_cpu_realizefn(DeviceState *dev, Err= or **errp) =20 if (!cpu->gt_cntfrq_hz) { /* - * 0 means "the board didn't set a value, use the default". - * The default value of the generic timer frequency (as seen in - * CNTFRQ_EL0) is 62.5MHz, which corresponds to a period of 16ns. - * This is what you get (a) for a CONFIG_USER_ONLY CPU (b) if the - * board doesn't set it. + * 0 means "the board didn't set a value, use the default". (We al= so + * get here for the CONFIG_USER_ONLY case.) + * ARMv8.6 and later CPUs architecturally must use a 1GHz timer; b= efore + * that it was an IMPDEF choice, and QEMU initially picked 62.5MHz, + * which gives a 16ns tick period. + * + * We will use the back-compat value: + * - for QEMU CPU types added before we standardized on 1GHz + * - for versioned machine types with a version of 9.0 or earlier */ - cpu->gt_cntfrq_hz =3D GTIMER_DEFAULT_HZ; + if (arm_feature(env, ARM_FEATURE_BACKCOMPAT_CNTFRQ) || + cpu->backcompat_cntfrq) { + cpu->gt_cntfrq_hz =3D GTIMER_BACKCOMPAT_HZ; + } else { + cpu->gt_cntfrq_hz =3D GTIMER_DEFAULT_HZ; + } } =20 #ifndef CONFIG_USER_ONLY @@ -2574,6 +2583,8 @@ static Property arm_cpu_properties[] =3D { mp_affinity, ARM64_AFFINITY_INVALID), DEFINE_PROP_INT32("node-id", ARMCPU, node_id, CPU_UNSET_NUMA_NODE_ID), DEFINE_PROP_INT32("core-count", ARMCPU, core_count, -1), + /* True to default to the backward-compat old CNTFRQ rather than 1Ghz = */ + DEFINE_PROP_BOOL("backcompat-cntfrq", ARMCPU, backcompat_cntfrq, false= ), DEFINE_PROP_END_OF_LIST() }; =20 diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index 985b1efe160..c15d086049f 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -599,6 +599,7 @@ static void aarch64_a57_initfn(Object *obj) set_feature(&cpu->env, ARM_FEATURE_V8); set_feature(&cpu->env, ARM_FEATURE_NEON); set_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER); + set_feature(&cpu->env, ARM_FEATURE_BACKCOMPAT_CNTFRQ); set_feature(&cpu->env, ARM_FEATURE_AARCH64); set_feature(&cpu->env, ARM_FEATURE_CBAR_RO); set_feature(&cpu->env, ARM_FEATURE_EL2); @@ -656,6 +657,7 @@ static void aarch64_a53_initfn(Object *obj) set_feature(&cpu->env, ARM_FEATURE_V8); set_feature(&cpu->env, ARM_FEATURE_NEON); set_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER); + set_feature(&cpu->env, ARM_FEATURE_BACKCOMPAT_CNTFRQ); set_feature(&cpu->env, ARM_FEATURE_AARCH64); set_feature(&cpu->env, ARM_FEATURE_CBAR_RO); set_feature(&cpu->env, ARM_FEATURE_EL2); diff --git a/target/arm/tcg/cpu32.c b/target/arm/tcg/cpu32.c index de8f2be9416..e4f983bcdc1 100644 --- a/target/arm/tcg/cpu32.c +++ b/target/arm/tcg/cpu32.c @@ -457,6 +457,7 @@ static void cortex_a7_initfn(Object *obj) set_feature(&cpu->env, ARM_FEATURE_NEON); set_feature(&cpu->env, ARM_FEATURE_THUMB2EE); set_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER); + set_feature(&cpu->env, ARM_FEATURE_BACKCOMPAT_CNTFRQ); set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS); set_feature(&cpu->env, ARM_FEATURE_CBAR_RO); set_feature(&cpu->env, ARM_FEATURE_EL2); @@ -505,6 +506,7 @@ static void cortex_a15_initfn(Object *obj) set_feature(&cpu->env, ARM_FEATURE_NEON); set_feature(&cpu->env, ARM_FEATURE_THUMB2EE); set_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER); + set_feature(&cpu->env, ARM_FEATURE_BACKCOMPAT_CNTFRQ); set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS); set_feature(&cpu->env, ARM_FEATURE_CBAR_RO); set_feature(&cpu->env, ARM_FEATURE_EL2); @@ -696,6 +698,7 @@ static void cortex_r52_initfn(Object *obj) set_feature(&cpu->env, ARM_FEATURE_PMSA); set_feature(&cpu->env, ARM_FEATURE_NEON); set_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER); + set_feature(&cpu->env, ARM_FEATURE_BACKCOMPAT_CNTFRQ); set_feature(&cpu->env, ARM_FEATURE_CBAR_RO); set_feature(&cpu->env, ARM_FEATURE_AUXCR); cpu->midr =3D 0x411fd133; /* r1p3 */ @@ -924,6 +927,7 @@ static void arm_max_initfn(Object *obj) set_feature(&cpu->env, ARM_FEATURE_V8); set_feature(&cpu->env, ARM_FEATURE_NEON); set_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER); + set_feature(&cpu->env, ARM_FEATURE_BACKCOMPAT_CNTFRQ); set_feature(&cpu->env, ARM_FEATURE_CBAR_RO); set_feature(&cpu->env, ARM_FEATURE_EL2); set_feature(&cpu->env, ARM_FEATURE_EL3); diff --git a/target/arm/tcg/cpu64.c b/target/arm/tcg/cpu64.c index 62c4663512b..b235bd22979 100644 --- a/target/arm/tcg/cpu64.c +++ b/target/arm/tcg/cpu64.c @@ -63,6 +63,7 @@ static void aarch64_a35_initfn(Object *obj) set_feature(&cpu->env, ARM_FEATURE_V8); set_feature(&cpu->env, ARM_FEATURE_NEON); set_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER); + set_feature(&cpu->env, ARM_FEATURE_BACKCOMPAT_CNTFRQ); set_feature(&cpu->env, ARM_FEATURE_AARCH64); set_feature(&cpu->env, ARM_FEATURE_CBAR_RO); set_feature(&cpu->env, ARM_FEATURE_EL2); @@ -231,6 +232,7 @@ static void aarch64_a55_initfn(Object *obj) set_feature(&cpu->env, ARM_FEATURE_V8); set_feature(&cpu->env, ARM_FEATURE_NEON); set_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER); + set_feature(&cpu->env, ARM_FEATURE_BACKCOMPAT_CNTFRQ); set_feature(&cpu->env, ARM_FEATURE_AARCH64); set_feature(&cpu->env, ARM_FEATURE_CBAR_RO); set_feature(&cpu->env, ARM_FEATURE_EL2); @@ -299,6 +301,7 @@ static void aarch64_a72_initfn(Object *obj) set_feature(&cpu->env, ARM_FEATURE_V8); set_feature(&cpu->env, ARM_FEATURE_NEON); set_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER); + set_feature(&cpu->env, ARM_FEATURE_BACKCOMPAT_CNTFRQ); set_feature(&cpu->env, ARM_FEATURE_AARCH64); set_feature(&cpu->env, ARM_FEATURE_CBAR_RO); set_feature(&cpu->env, ARM_FEATURE_EL2); @@ -354,6 +357,7 @@ static void aarch64_a76_initfn(Object *obj) set_feature(&cpu->env, ARM_FEATURE_V8); set_feature(&cpu->env, ARM_FEATURE_NEON); set_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER); + set_feature(&cpu->env, ARM_FEATURE_BACKCOMPAT_CNTFRQ); set_feature(&cpu->env, ARM_FEATURE_AARCH64); set_feature(&cpu->env, ARM_FEATURE_CBAR_RO); set_feature(&cpu->env, ARM_FEATURE_EL2); @@ -423,6 +427,7 @@ static void aarch64_a64fx_initfn(Object *obj) set_feature(&cpu->env, ARM_FEATURE_V8); set_feature(&cpu->env, ARM_FEATURE_NEON); set_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER); + set_feature(&cpu->env, ARM_FEATURE_BACKCOMPAT_CNTFRQ); set_feature(&cpu->env, ARM_FEATURE_AARCH64); set_feature(&cpu->env, ARM_FEATURE_EL2); set_feature(&cpu->env, ARM_FEATURE_EL3); @@ -592,6 +597,7 @@ static void aarch64_neoverse_n1_initfn(Object *obj) set_feature(&cpu->env, ARM_FEATURE_V8); set_feature(&cpu->env, ARM_FEATURE_NEON); set_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER); + set_feature(&cpu->env, ARM_FEATURE_BACKCOMPAT_CNTFRQ); set_feature(&cpu->env, ARM_FEATURE_AARCH64); set_feature(&cpu->env, ARM_FEATURE_CBAR_RO); set_feature(&cpu->env, ARM_FEATURE_EL2); @@ -663,6 +669,7 @@ static void aarch64_neoverse_v1_initfn(Object *obj) set_feature(&cpu->env, ARM_FEATURE_V8); set_feature(&cpu->env, ARM_FEATURE_NEON); set_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER); + set_feature(&cpu->env, ARM_FEATURE_BACKCOMPAT_CNTFRQ); set_feature(&cpu->env, ARM_FEATURE_AARCH64); set_feature(&cpu->env, ARM_FEATURE_CBAR_RO); set_feature(&cpu->env, ARM_FEATURE_EL2); @@ -885,6 +892,7 @@ static void aarch64_a710_initfn(Object *obj) set_feature(&cpu->env, ARM_FEATURE_V8); set_feature(&cpu->env, ARM_FEATURE_NEON); set_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER); + set_feature(&cpu->env, ARM_FEATURE_BACKCOMPAT_CNTFRQ); set_feature(&cpu->env, ARM_FEATURE_AARCH64); set_feature(&cpu->env, ARM_FEATURE_CBAR_RO); set_feature(&cpu->env, ARM_FEATURE_EL2); @@ -982,6 +990,7 @@ static void aarch64_neoverse_n2_initfn(Object *obj) set_feature(&cpu->env, ARM_FEATURE_V8); set_feature(&cpu->env, ARM_FEATURE_NEON); set_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER); + set_feature(&cpu->env, ARM_FEATURE_BACKCOMPAT_CNTFRQ); set_feature(&cpu->env, ARM_FEATURE_AARCH64); set_feature(&cpu->env, ARM_FEATURE_CBAR_RO); set_feature(&cpu->env, ARM_FEATURE_EL2); @@ -1077,6 +1086,15 @@ void aarch64_max_tcg_initfn(Object *obj) uint64_t t; uint32_t u; =20 + /* + * Unset ARM_FEATURE_BACKCOMPAT_CNTFRQ, which we would otherwise defau= lt + * to because we started with aarch64_a57_initfn(). A 'max' CPU might + * be a v8.6-or-later one, in which case the cntfrq must be 1GHz; and + * because it is our "may change" CPU type we are OK with it not being + * backwards-compatible with how it worked in old QEMU. + */ + unset_feature(&cpu->env, ARM_FEATURE_BACKCOMPAT_CNTFRQ); + /* * Reset MIDR so the guest doesn't mistake our 'max' CPU type for a re= al * one and try to apply errata workarounds or use impdef features we --=20 2.34.1