From nobody Sat Apr 5 17:31:56 2025 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1737971101; cv=none; d=zohomail.com; s=zohoarc; b=e5joHuhIz6w8bXmrtqrino8C/DvVFx7mRlNX0ie9Vm00JYj05UKyOdiEPyvbJQiO/EsP7CoB/5FZIiwMgze0ZWhL1D5ZAuqfm2dqtKAImdV2EodpiCNynqoA0M2A4Ba0qClT6cHv0PMjkOlMT4aX/qTE2TCIK0I5kPxWKzqRTLo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1737971101; 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=xNPwhTpaz34u5lSlNxX/kXU9REYVHuHQVuZhmQvf+KY=; b=KvX28s6886CsZGWAM/QMNdbeB8+IRAbIxC+dCkK1Tfc7MmnJ4qhnu7iWZXHvYhfetIQsUNOmj6/nymaYGE+3/2ipRJrmfvOyfAlfRPxcob/3InacxUmqr8Rb29aylSffHQTPgMfW11JpKVDEkRpbWRbV8Wo8ajOEmGCoyKZtNxs= 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 1737971101230639.3457683749251; Mon, 27 Jan 2025 01:45:01 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tcLe8-0006Cx-Hu; Mon, 27 Jan 2025 04:43:08 -0500 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 1tcLe6-0006Cd-M9 for qemu-devel@nongnu.org; Mon, 27 Jan 2025 04:43:06 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tcLe4-0005Qh-QP for qemu-devel@nongnu.org; Mon, 27 Jan 2025 04:43:06 -0500 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-182-YYplK-hdOruu0ImGiSMU9w-1; Mon, 27 Jan 2025 04:42:59 -0500 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2DA771800378; Mon, 27 Jan 2025 09:42:58 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.63]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 666161800365; Mon, 27 Jan 2025 09:42:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737970983; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xNPwhTpaz34u5lSlNxX/kXU9REYVHuHQVuZhmQvf+KY=; b=hruUGe4GhdzkkSEAz/9QfN9Q1eXIZp/+lkf4kc4clCl2247fgTxB/QtgijMXCEwbUu36Uk ZENSVSzBZtkyMgvmixu0xcbMaEicQ4jfT8FYPxE1YDjEWkuODE02kV9vgGGpkAC62EqeGL HVXuKfgqCyHoj1RE8mWBHyh5QJbAncM= X-MC-Unique: YYplK-hdOruu0ImGiSMU9w-1 X-Mimecast-MFC-AGG-ID: YYplK-hdOruu0ImGiSMU9w From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: Jamin Lin , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 04/12] hw/timer/aspeed: Refactor Timer Callbacks for SoC-Specific Implementations Date: Mon, 27 Jan 2025 10:42:31 +0100 Message-ID: <20250127094239.636526-5-clg@redhat.com> In-Reply-To: <20250127094239.636526-1-clg@redhat.com> References: <20250127094239.636526-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 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=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.299, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.01, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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 @redhat.com) X-ZM-MESSAGEID: 1737971102438019000 From: Jamin Lin The register set have a significant change in AST2700. The TMC00-TMC3C are used for TIMER0 and TMC40-TMC7C are used for TIMER1. In additional, TMC20-TMC3C and TMC60-TMC7C are reserved registers for TIMER0 and TIMER1, respectively. Besides, each TIMER has their own control and interrupt status register. In other words, users are able to set control and interrupt status for TIME= R0 in one register. Both aspeed_timer_read and aspeed_timer_write callback functions are not compatible AST2700. Introduce common read and write functions for ASPEED timers. Modify the aspeed_timer_read and aspeed_timer_write functions to delegate to SoC-specific callbacks first. Update the AST2400, AST2500, AST2600 and AST1030 specific read and write functions to call the common implementations for common register accesses. This refactoring improves the organization of call delegation and prepares = the codebase for future SoC-specific specializations, such as the AST2700. Signed-off-by: Jamin Lin Reviewed-by: C=C3=A9dric Le Goater Link: https://lore.kernel.org/r/20250113064455.1660564-2-jamin_lin@aspeedte= ch.com Signed-off-by: C=C3=A9dric Le Goater --- hw/timer/aspeed_timer.c | 55 ++++++++++++++++++++++++++++++----------- hw/timer/trace-events | 2 +- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/hw/timer/aspeed_timer.c b/hw/timer/aspeed_timer.c index 4868651ad489..24ba40cbe9b4 100644 --- a/hw/timer/aspeed_timer.c +++ b/hw/timer/aspeed_timer.c @@ -239,9 +239,8 @@ static uint64_t aspeed_timer_get_value(AspeedTimer *t, = int reg) return value; } =20 -static uint64_t aspeed_timer_read(void *opaque, hwaddr offset, unsigned si= ze) +static uint64_t aspeed_timer_read_common(AspeedTimerCtrlState *s, hwaddr o= ffset) { - AspeedTimerCtrlState *s =3D opaque; const int reg =3D (offset & 0xf) / 4; uint64_t value; =20 @@ -256,10 +255,11 @@ static uint64_t aspeed_timer_read(void *opaque, hwadd= r offset, unsigned size) value =3D aspeed_timer_get_value(&s->timers[(offset >> 4) - 1], re= g); break; default: - value =3D ASPEED_TIMER_GET_CLASS(s)->read(s, offset); + qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%" HWADDR_PRIx "\= n", + __func__, offset); + value =3D 0; break; } - trace_aspeed_timer_read(offset, size, value); return value; } =20 @@ -431,12 +431,11 @@ static void aspeed_timer_set_ctrl2(AspeedTimerCtrlSta= te *s, uint32_t value) trace_aspeed_timer_set_ctrl2(value); } =20 -static void aspeed_timer_write(void *opaque, hwaddr offset, uint64_t value, - unsigned size) +static void aspeed_timer_write_common(AspeedTimerCtrlState *s, hwaddr offs= et, + uint64_t value) { const uint32_t tv =3D (uint32_t)(value & 0xFFFFFFFF); const int reg =3D (offset & 0xf) / 4; - AspeedTimerCtrlState *s =3D opaque; =20 switch (offset) { /* Control Registers */ @@ -451,11 +450,25 @@ static void aspeed_timer_write(void *opaque, hwaddr o= ffset, uint64_t value, aspeed_timer_set_value(s, (offset >> TIMER_NR_REGS) - 1, reg, tv); break; default: - ASPEED_TIMER_GET_CLASS(s)->write(s, offset, value); + qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%" HWADDR_PRIx "\= n", + __func__, offset); break; } } =20 +static uint64_t aspeed_timer_read(void *opaque, hwaddr offset, unsigned si= ze) +{ + AspeedTimerCtrlState *s =3D ASPEED_TIMER(opaque); + return ASPEED_TIMER_GET_CLASS(s)->read(s, offset); +} + +static void aspeed_timer_write(void *opaque, hwaddr offset, uint64_t value, + unsigned size) +{ + AspeedTimerCtrlState *s =3D ASPEED_TIMER(opaque); + ASPEED_TIMER_GET_CLASS(s)->write(s, offset, value); +} + static const MemoryRegionOps aspeed_timer_ops =3D { .read =3D aspeed_timer_read, .write =3D aspeed_timer_write, @@ -475,12 +488,15 @@ static uint64_t aspeed_2400_timer_read(AspeedTimerCtr= lState *s, hwaddr offset) break; case 0x38: case 0x3C: - default: qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%" HWADDR_PRIx "\= n", __func__, offset); value =3D 0; break; + default: + value =3D aspeed_timer_read_common(s, offset); + break; } + trace_aspeed_timer_read(offset, value); return value; } =20 @@ -495,10 +511,12 @@ static void aspeed_2400_timer_write(AspeedTimerCtrlSt= ate *s, hwaddr offset, break; case 0x38: case 0x3C: - default: qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%" HWADDR_PRIx "\= n", __func__, offset); break; + default: + aspeed_timer_write_common(s, offset, value); + break; } } =20 @@ -514,12 +532,15 @@ static uint64_t aspeed_2500_timer_read(AspeedTimerCtr= lState *s, hwaddr offset) value =3D s->ctrl3 & BIT(0); break; case 0x3C: - default: qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%" HWADDR_PRIx "\= n", __func__, offset); value =3D 0; break; + default: + value =3D aspeed_timer_read_common(s, offset); + break; } + trace_aspeed_timer_read(offset, value); return value; } =20 @@ -548,8 +569,7 @@ static void aspeed_2500_timer_write(AspeedTimerCtrlStat= e *s, hwaddr offset, break; =20 default: - qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%" HWADDR_PRIx "\= n", - __func__, offset); + aspeed_timer_write_common(s, offset, value); break; } } @@ -564,12 +584,15 @@ static uint64_t aspeed_2600_timer_read(AspeedTimerCtr= lState *s, hwaddr offset) break; case 0x38: case 0x3C: - default: qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%" HWADDR_PRIx "\= n", __func__, offset); value =3D 0; break; + default: + value =3D aspeed_timer_read_common(s, offset); + break; } + trace_aspeed_timer_read(offset, value); return value; } =20 @@ -586,10 +609,12 @@ static void aspeed_2600_timer_write(AspeedTimerCtrlSt= ate *s, hwaddr offset, aspeed_timer_set_ctrl(s, s->ctrl & ~tv); break; case 0x38: - default: qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%" HWADDR_PRIx "\= n", __func__, offset); break; + default: + aspeed_timer_write_common(s, offset, value); + break; } } =20 diff --git a/hw/timer/trace-events b/hw/timer/trace-events index 5cfc369fba46..c5b6db49f587 100644 --- a/hw/timer/trace-events +++ b/hw/timer/trace-events @@ -31,7 +31,7 @@ aspeed_timer_ctrl_overflow_interrupt(uint8_t i, bool enab= le) "Timer %" PRIu8 ": aspeed_timer_ctrl_pulse_enable(uint8_t i, bool enable) "Timer %" PRIu8 ": = %d" aspeed_timer_set_ctrl2(uint32_t value) "Value: 0x%" PRIx32 aspeed_timer_set_value(int timer, int reg, uint32_t value) "Timer %d regis= ter %d: 0x%" PRIx32 -aspeed_timer_read(uint64_t offset, unsigned size, uint64_t value) "From 0x= %" PRIx64 ": of size %u: 0x%" PRIx64 +aspeed_timer_read(uint64_t offset, uint64_t value) "From 0x%" PRIx64 ": 0x= %" PRIx64 =20 # armv7m_systick.c systick_reload(void) "systick reload" --=20 2.48.1