From patchwork Mon Mar 25 13:32:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 782339 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e01:0:b0:33e:7753:30bd with SMTP id p1csp1176837wrt; Mon, 25 Mar 2024 06:35:38 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUkxJi7Zrw7fXlqb8yoF0gT8RppF0PVbz0IGqwgLIhIDoZUUsyR8nXx2fWdD4OJyXCv/SnBwm0Y/aCGW9PUmoma X-Google-Smtp-Source: AGHT+IE1wd7mIuJtA/qVFX4OxyklHKAQxqoNAFyNw0qsqWuBXHS8MxEzzg+AVEvf5cMilK8HVEEp X-Received: by 2002:a05:622a:1883:b0:431:2051:4798 with SMTP id v3-20020a05622a188300b0043120514798mr8858436qtc.14.1711373738246; Mon, 25 Mar 2024 06:35:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1711373738; cv=none; d=google.com; s=arc-20160816; b=eLSRVBGqMMrn71o+u0CM2a63ceIc3NRDP6lRgsvpwmIlyRf6pZ9Hxs+IwSSiX5iynd A9PuxR4J/AunddUO4P54H7DrQWzNsfENKkVJoFUyIpU6kHmbqABYblr5bjm2/kobZipC zwoCD3GIrD4GcvQvrsips9HxM36FsVH2f0OhfR2eunB34WS75ljAH5j9fP37jVCazK+T tqHvoBkrIeqw9ILjrGfSI3zatcWulxRYKgM4u+z7fi/ARU/FmNSqzQ3yO5I11YSQqH8h X0y0byca9CcvTHPOq6yyWgVyu7iXdtUXnmcbaLHVjo2GdlFyVG77vmORXJnqBEpGnueK qIPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=cC2Yz91nzGrohL4G/Awv0+dd4I3kt82iWAFcfxuwSZM=; fh=t3X8QBlUt8lTNNYLmXnvt7uYZqjf0Fo0hWn60R6P6ms=; b=EAywQ83/8/YyeIPCGg1HHkfmB4kbumpdN/u+DilcnstAe9c3kbdXwPmreobt7WRQBb ut9u4GdForsN7izvBNszoA4RDSF5Ba72CUizGqwN0jeCbT8+NOgj+fSk4fAMMRyvnLMZ /CiqBxeVW+TLiYC9lmUmwgxXTrAc7/i8B/nz793y19W1TYNpzeldRIt3b/yFq0LjsIDZ dNJtJtjlaHEahoCdkzn0BOEJF/PW81x61XnRxBNCmyNpRjs6SN2+2j5wL5XE22JVaWkS pHW7Uzooi+4cK0s6cnFHCGJwZlqGo0eRBrOze6avAgHFsat33NQidkou+OD/ycTPrTIy ClQQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=c4m9fmaT; 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=pass (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 f6-20020ac85d06000000b004315e3614c7si1113988qtx.373.2024.03.25.06.35.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 25 Mar 2024 06:35:38 -0700 (PDT) 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=pass header.i=@linaro.org header.s=google header.b=c4m9fmaT; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rokSb-0003ZB-Dm; Mon, 25 Mar 2024 09:33:57 -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 1rokSY-0003Y3-Sm for qemu-devel@nongnu.org; Mon, 25 Mar 2024 09:33:54 -0400 Received: from mail-ed1-x535.google.com ([2a00:1450:4864:20::535]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rokSX-0007TR-82 for qemu-devel@nongnu.org; Mon, 25 Mar 2024 09:33:54 -0400 Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-56c0613307cso1616439a12.0 for ; Mon, 25 Mar 2024 06:33:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1711373631; x=1711978431; 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=cC2Yz91nzGrohL4G/Awv0+dd4I3kt82iWAFcfxuwSZM=; b=c4m9fmaTqK/XPlEjig0UaahEDKAgnSNSNyONhgN2JpiiC+wfIcfy7dBlhYqNmpYUfC aCKRiUq70AOpnD71r4N54Woy78+uYREu5w6Rivg3xvEdeUeEP7eEBA9SXC5FUZ9maV0u OZhNWV5wOedNB9N6Xer7K1Wme8cPLzA6JjfNh8LSflmQ8vAYeKoaKITVEdiXZpezQjnN VKubYafax35ySvIIHThW+3884YE//pMREyfmwCXlBz5F8VvL9v3gv7QGdujosmr8Ol7g PcZeeAIWE9sie2oMFo/7pZgqB+p+KKYeUZuzUxBNSaF5Tsus606LtNvgyi53N8fDKqE/ 6y/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711373631; x=1711978431; 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=cC2Yz91nzGrohL4G/Awv0+dd4I3kt82iWAFcfxuwSZM=; b=kvFZbZwilgfFbe5+C1TSt9mEypqjcLFclLFsMQLvS8vBB0XsBCe2a+EHzaO/qJ9wd6 t2FdF8Aa7Qzd8oO4g7czeqaeu8fg1hrKUBE9ROAUAsnlf8fFbBMegz2NSicBfzlGWOaK 3bYYNvkNMIzRYIFdOH4RGF3RAvOSpPPL6BcT2+nLwPFOFURolhKnKWLGkzBDyOp/v9Hn RKIxDAItkJQH2NC6ID1nLDPkXHs0L73X6G8NDkNgy8BJcaoMRJw7eyztCUdVCU12Am0R QHVD1wn6BaWa6aSxXsi9C0ttVCWiFN+zCpaTvbqBLJGMS0NjgpjzSqnRacxjj1mGqgk0 /sMA== X-Gm-Message-State: AOJu0Yzzy1SPeLzUB+c+gyxtqKvXw4BpqRsHtMhDLwwKz1wkJffmUjEm 3QZGziwo5boyDlxrdB2eqQXm0m59z48ysx5QG+QVIsTf7JCgJ/TXX/E5kORQ16tG3s9y5XXZw2s 7MDk= X-Received: by 2002:a17:906:4e8d:b0:a46:cea6:a7f1 with SMTP id v13-20020a1709064e8d00b00a46cea6a7f1mr4793519eju.51.1711373630981; Mon, 25 Mar 2024 06:33:50 -0700 (PDT) Received: from m1x-phil.lan ([176.187.208.214]) by smtp.gmail.com with ESMTPSA id qy34-20020a17090768a200b00a4623030893sm3046795ejc.126.2024.03.25.06.33.49 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 25 Mar 2024 06:33:50 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?In=C3=A8s_Varhol?= , Arnaud Minier , Damien Hedde , qemu-arm@nongnu.org, Peter Maydell , Alistair Francis , Luc Michel , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , "Edgar E. Iglesias" Subject: [PATCH-for-9.1 v2 8/8] hw/misc/zynq_slcr: Only propagate clock changes when necessary Date: Mon, 25 Mar 2024 14:32:58 +0100 Message-ID: <20240325133259.57235-9-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240325133259.57235-1-philmd@linaro.org> References: <20240325133259.57235-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::535; envelope-from=philmd@linaro.org; helo=mail-ed1-x535.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Pass &bool to zynq_slcr_compute_clocks[_internal](), so we can pass it to the clock_set() calls which might update it. Then check it and only call zynq_slcr_propagate_clocks() and clock_propagate() when necessary. Signed-off-by: Philippe Mathieu-Daudé --- hw/misc/zynq_slcr.c | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/hw/misc/zynq_slcr.c b/hw/misc/zynq_slcr.c index e637798507..ad9c575137 100644 --- a/hw/misc/zynq_slcr.c +++ b/hw/misc/zynq_slcr.c @@ -269,7 +269,8 @@ static uint64_t zynq_slcr_compute_clock(const uint64_t periods[], zynq_slcr_compute_clock((plls), (state)->regs[reg], \ reg ## _ ## enable_field ## _SHIFT) -static void zynq_slcr_compute_clocks_internal(ZynqSLCRState *s, uint64_t ps_clk) +static void zynq_slcr_compute_clocks_internal(ZynqSLCRState *s, uint64_t ps_clk, + bool *changed) { uint64_t io_pll = zynq_slcr_compute_pll(ps_clk, s->regs[R_IO_PLL_CTRL]); uint64_t arm_pll = zynq_slcr_compute_pll(ps_clk, s->regs[R_ARM_PLL_CTRL]); @@ -279,9 +280,9 @@ static void zynq_slcr_compute_clocks_internal(ZynqSLCRState *s, uint64_t ps_clk) /* compute uartX reference clocks */ clock_set(s->uart0_ref_clk, - ZYNQ_COMPUTE_CLK(s, uart_mux, R_UART_CLK_CTRL, CLKACT0), NULL); + ZYNQ_COMPUTE_CLK(s, uart_mux, R_UART_CLK_CTRL, CLKACT0), changed); clock_set(s->uart1_ref_clk, - ZYNQ_COMPUTE_CLK(s, uart_mux, R_UART_CLK_CTRL, CLKACT1), NULL); + ZYNQ_COMPUTE_CLK(s, uart_mux, R_UART_CLK_CTRL, CLKACT1), changed); } /** @@ -289,7 +290,7 @@ static void zynq_slcr_compute_clocks_internal(ZynqSLCRState *s, uint64_t ps_clk) * But do not propagate them further. Connected clocks * will not receive any updates (See zynq_slcr_compute_clocks()) */ -static void zynq_slcr_compute_clocks(ZynqSLCRState *s) +static void zynq_slcr_compute_clocks(ZynqSLCRState *s, bool *changed) { uint64_t ps_clk = clock_get(s->ps_clk); @@ -298,7 +299,7 @@ static void zynq_slcr_compute_clocks(ZynqSLCRState *s) ps_clk = 0; } - zynq_slcr_compute_clocks_internal(s, ps_clk); + zynq_slcr_compute_clocks_internal(s, ps_clk, changed); } /** @@ -315,9 +316,12 @@ static void zynq_slcr_propagate_clocks(ZynqSLCRState *s) static void zynq_slcr_ps_clk_callback(void *opaque, ClockEvent event) { ZynqSLCRState *s = (ZynqSLCRState *) opaque; + bool propagate = false; - zynq_slcr_compute_clocks(s); - zynq_slcr_propagate_clocks(s); + zynq_slcr_compute_clocks(s, &propagate); + if (propagate) { + zynq_slcr_propagate_clocks(s); + } } static void zynq_slcr_reset_init(Object *obj, ResetType type) @@ -419,19 +423,25 @@ static void zynq_slcr_reset_init(Object *obj, ResetType type) static void zynq_slcr_reset_hold(Object *obj) { ZynqSLCRState *s = ZYNQ_SLCR(obj); + bool propagate = false; /* will disable all output clocks */ - zynq_slcr_compute_clocks_internal(s, 0); - zynq_slcr_propagate_clocks(s); + zynq_slcr_compute_clocks_internal(s, 0, &propagate); + if (propagate) { + zynq_slcr_propagate_clocks(s); + } } static void zynq_slcr_reset_exit(Object *obj) { ZynqSLCRState *s = ZYNQ_SLCR(obj); + bool propagate = false; /* will compute output clocks according to ps_clk and registers */ - zynq_slcr_compute_clocks_internal(s, clock_get(s->ps_clk)); - zynq_slcr_propagate_clocks(s); + zynq_slcr_compute_clocks_internal(s, clock_get(s->ps_clk), &propagate); + if (propagate) { + zynq_slcr_propagate_clocks(s); + } } static bool zynq_slcr_check_offset(hwaddr offset, bool rnw) @@ -516,6 +526,7 @@ static void zynq_slcr_write(void *opaque, hwaddr offset, uint64_t val, unsigned size) { ZynqSLCRState *s = (ZynqSLCRState *)opaque; + bool propagate = false; offset /= 4; DB_PRINT("addr: %08" HWADDR_PRIx " data: %08" PRIx64 "\n", offset * 4, val); @@ -569,8 +580,10 @@ static void zynq_slcr_write(void *opaque, hwaddr offset, case R_ARM_PLL_CTRL: case R_DDR_PLL_CTRL: case R_UART_CLK_CTRL: - zynq_slcr_compute_clocks(s); - zynq_slcr_propagate_clocks(s); + zynq_slcr_compute_clocks(s, &propagate); + if (propagate) { + zynq_slcr_propagate_clocks(s); + } break; } }