From patchwork Tue Feb 8 17:16:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 540802 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp762493imo; Tue, 8 Feb 2022 11:44:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJy/0Jrzz3lQ0jEOslLy5pyRiOGFtKLQ7VNt/1QZrwvD0d+FfaoBrzBGD/Eet92mRO+n3Nc8 X-Received: by 2002:a25:870c:: with SMTP id a12mr6261538ybl.682.1644349448609; Tue, 08 Feb 2022 11:44:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644349448; cv=none; d=google.com; s=arc-20160816; b=Tj4EF31677GaN/4pLVEWYOTQy0VkHVWooiVvxSrj9vl+y1Ozl3ymi0rhxNrR/Tdq+e FKvpclqW3RGh4pFgkLh3b1pcW7KG8hfO7iM55A9pZJjE/y8vZoJbI/RbbbaOXqy1xupw O+96DhGq0mwv51BRDb8nobUk1NvsdhhgsynQG8BQwfaqumPJZlh+kGEVWAaODbK/Fpbn 1FvFjvRP/+2E+LXb/x1N/OcCl0Eox0wlVdA7ZYAfg7LrySYtlAEhDBmA/7U3V3Zw9dVu C2+E8IM6LaO6XdswlrGDhqdPsxWET8Z+WeZlRsO0hyOu7ZEU+E2z5/plE2dTGVIqdIE8 zeTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature; bh=X+5q8Q245RMXKO+FXIQP2z10d5lBl/C2tAq9zh99WDw=; b=WGpCtQMYoCRfHCQYbOEBesUkEdKC4B+myMJG1RX1GLLDRbG7EjlJL43xKqtGpJiQfw xItHtdozc4o+EyNb50Ima/4Q0rOm4BYxeolmUxpoIq1POSI1YQzc9/Lo0OmyFWAIP5dh +UqOdQJinIwzObss3pTHARuYL48dRjzs+SmH7xt+qGSNtGn4sNLMNeUwbVAFqiR1kPRj 5YGBIplvvY/jSKvfhP+GmgjkIOcU0T2KmKt/xoopY1b+PSabHDb8nxy4uXJdlbIrvNLO 8+rHTrtRQO8Ern9jCVcrxHnPh1jPUhM6ovoRnGQHMCUyd9znTkmqsxTA05LiKKMXLNax 2Snw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=IClUJYyQ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id h3si10142222ybc.425.2022.02.08.11.44.08 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Feb 2022 11:44:08 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=IClUJYyQ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:47278 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHWPI-0007zE-36 for patch@linaro.org; Tue, 08 Feb 2022 14:44:08 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48522) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHU6m-0003jf-Cb for qemu-devel@nongnu.org; Tue, 08 Feb 2022 12:16:52 -0500 Received: from [2a00:1450:4864:20::430] (port=38526 helo=mail-wr1-x430.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHU6h-0002NT-VM for qemu-devel@nongnu.org; Tue, 08 Feb 2022 12:16:51 -0500 Received: by mail-wr1-x430.google.com with SMTP id s10so29436607wra.5 for ; Tue, 08 Feb 2022 09:16:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=X+5q8Q245RMXKO+FXIQP2z10d5lBl/C2tAq9zh99WDw=; b=IClUJYyQkhtkPpKMZmFwxgEZnJBygzTsZLIKirMwPUI2NacdoEtEgkdIDA9AzNB50e KUJrEQAi1I2euB9pBYGW5IpPbeWrsvpXFaQ2Y3/NHWItXjpCMwO1Q2OEKly/TVFkR8iH WTKOnWJuHpXK7uj0agXsJPgaExzGkdp5FNkBZSSovjmy7xQ/OsDuYU4rd7PHHv603lQh p8vQ7sNK/CfvLSzQ1DTu7f/6Pw7vk8KGtKoDAU8rY8fZqsRCShHa6nehwyTxtNaIpjU+ Du0LyeKOw3ipugoWJDQcWWnBrXfO2rJBOvil4ZAd0BCVhCq/GdSoBkt96GnA77VhH0um h6Ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=X+5q8Q245RMXKO+FXIQP2z10d5lBl/C2tAq9zh99WDw=; b=IuqcCh6kNEP/d2PUOL/hHSbRi57SjfJ6Jo93oKQtsHuE5BYRzqE7Oa+O/zMoVTV4+y 6HLh2r2FA+yq/opqILQOijNtJ1eqiitD+a1KQopor15e75gJFMjLVzmSbre/2sdXgDVJ OcnvGgkxe6BY0O5ZVwMtc2hGW5K7jT160afRtrLyPsDW4yy3EUZQwGxZQUGDXYmWqA/w btDawIoKUhMATigBGsDdtPmNksFL6bKbEiQd/ByTYuVOkAMWhtFxEhdbdMOjBqnT0qSW wShC9tsDGpKH1D/0Bs09b5Gh9yS08zauYFkIAK17MDataJjczAozbs9fL1fKAfsX2V5I 5+LA== X-Gm-Message-State: AOAM531KHhQWXFfNJRYgXaqFCPPG+EzrALGrg1jVTJr37J8A1V/VLlPI cqgt8KQ9gkqeEKpTM87rXyWVnPko/YvqQQ== X-Received: by 2002:a5d:4089:: with SMTP id o9mr2689911wrp.634.1644340605938; Tue, 08 Feb 2022 09:16:45 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id t14sm2718680wmq.43.2022.02.08.09.16.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 09:16:45 -0800 (PST) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH] hw/arm/armv7m: Handle disconnected clock inputs Date: Tue, 8 Feb 2022 17:16:43 +0000 Message-Id: <20220208171643.3486277-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::430 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::430; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x430.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Cc: qemu-stable@nongnu.org, Richard Petri Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" In the armv7m object, handle clock inputs that aren't connected. This is always an error for 'cpuclk'. For 'refclk' it is OK for this to be disconnected, but we need to handle it by not trying to connect a sourceless-clock to the systick device. This fixes a bug where on the mps2-an521 and similar boards (which do not have a refclk) the systick device incorrectly reset with SYST_CSR.CLKSOURCE 0 ("use refclk") rather than 1 ("use CPU clock"). Cc: qemu-stable@nongnu.org Reported-by: Richard Petri Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson --- The other option would be to have clock_has_source() look not just at clk->source but somehow walk up the clock tree to see if it can find something that looks like a "root". That seems overcomplicated... --- hw/arm/armv7m.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/hw/arm/armv7m.c b/hw/arm/armv7m.c index ceb76df3cd4..41cfca0f223 100644 --- a/hw/arm/armv7m.c +++ b/hw/arm/armv7m.c @@ -284,6 +284,12 @@ static void armv7m_realize(DeviceState *dev, Error **errp) return; } + /* cpuclk must be connected; refclk is optional */ + if (!clock_has_source(s->cpuclk)) { + error_setg(errp, "armv7m: cpuclk must be connected"); + return; + } + memory_region_add_subregion_overlap(&s->container, 0, s->board_memory, -1); s->cpu = ARM_CPU(object_new_with_props(s->cpu_type, OBJECT(s), "cpu", @@ -420,8 +426,18 @@ static void armv7m_realize(DeviceState *dev, Error **errp) &s->sysreg_ns_mem); } - /* Create and map the systick devices */ - qdev_connect_clock_in(DEVICE(&s->systick[M_REG_NS]), "refclk", s->refclk); + /* + * Create and map the systick devices. Note that we only connect + * refclk if it has been connected to us; otherwise the systick + * device gets the wrong answer for clock_has_source(refclk), because + * it has an immediate source (the ARMv7M's clock object) but not + * an ultimate source, and then it won't correctly auto-select the + * CPU clock as its only possible clock source. + */ + if (clock_has_source(s->refclk)) { + qdev_connect_clock_in(DEVICE(&s->systick[M_REG_NS]), "refclk", + s->refclk); + } qdev_connect_clock_in(DEVICE(&s->systick[M_REG_NS]), "cpuclk", s->cpuclk); if (!sysbus_realize(SYS_BUS_DEVICE(&s->systick[M_REG_NS]), errp)) { return; @@ -438,8 +454,10 @@ static void armv7m_realize(DeviceState *dev, Error **errp) */ object_initialize_child(OBJECT(dev), "systick-reg-s", &s->systick[M_REG_S], TYPE_SYSTICK); - qdev_connect_clock_in(DEVICE(&s->systick[M_REG_S]), "refclk", - s->refclk); + if (clock_has_source(s->refclk)) { + qdev_connect_clock_in(DEVICE(&s->systick[M_REG_S]), "refclk", + s->refclk); + } qdev_connect_clock_in(DEVICE(&s->systick[M_REG_S]), "cpuclk", s->cpuclk);