From nobody Mon Feb 9 01:16:23 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+82336+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+82336+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=hpe.com ARC-Seal: i=1; a=rsa-sha256; t=1634634531; cv=none; d=zohomail.com; s=zohoarc; b=n7cm/bAOoTMxOmY2Iae3Bfs43pc740eilsOXucqLVDU+e4iDaxmh70x1J8vhBYUaxM+ZWl023lTRBR6oDLWVoBFXh+gbHDp0uacC3GXTiNVHE2MqtxcdHU7u8P+zPqtQVePRt5AjOb22E5rqK7TWyBSLUerKbMOKs+lwOOEBYN8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1634634531; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=MnmKxIvk5wSSd64bVLKQ1PQK2/BayYFjGpOshqgiOtw=; b=hsKoZ6mf4Eot5Xgsl5aeG37o5cOIBd6MU62FKOthiw9wI9Z1ACoP8mHzdxMB+BAeGqXi1ovBRLGv/dHXIBrq5MiKaq63Q9KKj22czFgTfSVBFUlqZR/2S/8ocSzMbZ5KHXg98QrHYchBCyz9vBDovKOFc1HSdckryHCAXZzhu9U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+82336+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1634634531028656.8217542467396; Tue, 19 Oct 2021 02:08:51 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 5mbxYY1788612xApYwFsViJJ; Tue, 19 Oct 2021 02:08:50 -0700 X-Received: from mx0a-002e3701.pphosted.com (mx0a-002e3701.pphosted.com [148.163.147.86]) by mx.groups.io with SMTP id smtpd.web12.7281.1634634528484674495 for ; Tue, 19 Oct 2021 02:08:49 -0700 X-Received: from pps.filterd (m0150241.ppops.net [127.0.0.1]) by mx0a-002e3701.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 19J81swW005268; Tue, 19 Oct 2021 09:08:48 GMT X-Received: from g4t3425.houston.hpe.com (g4t3425.houston.hpe.com [15.241.140.78]) by mx0a-002e3701.pphosted.com with ESMTP id 3bs9b3qs0g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 19 Oct 2021 09:08:48 +0000 X-Received: from g9t2301.houston.hpecorp.net (g9t2301.houston.hpecorp.net [16.220.97.129]) by g4t3425.houston.hpe.com (Postfix) with ESMTP id 4569EB4; Tue, 19 Oct 2021 09:08:47 +0000 (UTC) X-Received: from UB16Abner.asiapacific.hpqcorp.net (ub16abner.asiapacific.hpqcorp.net [15.119.209.229]) by g9t2301.houston.hpecorp.net (Postfix) with ESMTP id 33C0248; Tue, 19 Oct 2021 09:08:46 +0000 (UTC) From: "Abner Chang" To: devel@edk2.groups.io Cc: abner.chang@hpe.com, Sunil V L , Daniel Schaefer Subject: [edk2-devel] [edk2-platforms][PATCH 25/30] Silicon/SiFive: Use mtime CSR library Date: Tue, 19 Oct 2021 16:10:02 +0800 Message-Id: <20211019081007.31165-26-abner.chang@hpe.com> In-Reply-To: <20211019081007.31165-1-abner.chang@hpe.com> References: <20211019081007.31165-1-abner.chang@hpe.com> MIME-Version: 1.0 X-Proofpoint-GUID: pArvweNFQOkZj9pTZJ8yJlAJKH0lnTc8 X-Proofpoint-ORIG-GUID: pArvweNFQOkZj9pTZJ8yJlAJKH0lnTc8 X-HPE-SCL: -1 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,abner.chang@hpe.com X-Gm-Message-State: ALyBYFx2wUIm4qLSjWdTA1cyx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634634530; bh=slXfSt0GyIqpBN9v8lx8YuI4QXzarKD1vrIL9kl0J6E=; h=Cc:Date:From:Reply-To:Subject:To; b=F14txi/aHZSW9o9wvK1B4Ln3a3BcytkWNF4b5KJTOjP/S1vCaQAu0xz75Btf1+0+72B aW3ZIR2iiz6LigBwhHYksIqX5ycwmFqHUDs3XuIvErLy4GdxljSc8+8/i7CWNJd4EEGVH SiXmx8wLg6dMpdKNbsgBxwy4nkSZyW10hUg= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634634531669100003 Content-Type: text/plain; charset="utf-8" Use mtime CSR library interface to access mtime CSR in Timer DXE driver. Cc: Sunil V L Cc: Daniel Schaefer Signed-off-by: Abner Chang --- .../FreedomU540HiFiveUnleashedBoard/U540.dsc | 2 ++ .../Universal/Dxe/TimerDxe/TimerDxe.inf | 1 + .../U5SeriesPkg/Universal/Dxe/TimerDxe/Timer.c | 14 +++++--------- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/U5= 40.dsc b/Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/U540.d= sc index 4d16adfc82..c29b36e9bb 100644 --- a/Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/U540.dsc +++ b/Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/U540.dsc @@ -148,6 +148,8 @@ RiscVCpuLib|Silicon/RISC-V/ProcessorPkg/Library/RiscVCpuLib/RiscVCpuLib.= inf RiscVEdk2SbiLib|Silicon/RISC-V/ProcessorPkg/Library/RiscVEdk2SbiLib/Risc= VEdk2SbiLib.inf RiscVPlatformTimerLib|Platform/SiFive/U5SeriesPkg/Library/RiscVPlatformT= imerLib/RiscVPlatformTimerLib.inf + #MachineModeTimerLib|Silicon/RISC-V/ProcessorPkg/Library/RiscVReadMachin= eModeTimer/MachineModeTimerLib/MachineModeTimerLib.inf + MachineModeTimerLib|Silicon/RISC-V/ProcessorPkg/Library/RiscVReadMachine= ModeTimer/EmulatedMachineModeTimerLib/EmulatedMachineModeTimerLib.inf CpuExceptionHandlerLib|Silicon/RISC-V/ProcessorPkg/Library/RiscVExceptio= nLib/CpuExceptionHandlerDxeLib.inf =20 =20 diff --git a/Platform/SiFive/U5SeriesPkg/Universal/Dxe/TimerDxe/TimerDxe.in= f b/Platform/SiFive/U5SeriesPkg/Universal/Dxe/TimerDxe/TimerDxe.inf index 25cb3bb8b4..4571621a2e 100644 --- a/Platform/SiFive/U5SeriesPkg/Universal/Dxe/TimerDxe/TimerDxe.inf +++ b/Platform/SiFive/U5SeriesPkg/Universal/Dxe/TimerDxe/TimerDxe.inf @@ -30,6 +30,7 @@ BaseLib DebugLib IoLib + MachineModeTimerLib RiscVCpuLib RiscVEdk2SbiLib UefiBootServicesTableLib diff --git a/Platform/SiFive/U5SeriesPkg/Universal/Dxe/TimerDxe/Timer.c b/P= latform/SiFive/U5SeriesPkg/Universal/Dxe/TimerDxe/Timer.c index 065ecdda86..deb5799277 100644 --- a/Platform/SiFive/U5SeriesPkg/Universal/Dxe/TimerDxe/Timer.c +++ b/Platform/SiFive/U5SeriesPkg/Universal/Dxe/TimerDxe/Timer.c @@ -15,9 +15,6 @@ #include #include =20 -STATIC volatile VOID * const p_mtime =3D (VOID *)CLINT_REG_MTIME; -#define MTIME (*p_mtime) -#define MTIMECMP(i) (p_mtimecmp[i]) BOOLEAN TimerHandlerReentry =3D FALSE; =20 // @@ -73,7 +70,7 @@ TimerInterruptHandler ( // MMode timer occurred when processing // SMode timer handler. // - RiscvTimer =3D readq_relaxed(p_mtime); + RiscvTimer =3D RiscVReadMachineTimerInterface(); SbiSetTimer (RiscvTimer +=3D mTimerPeriod); csr_clear(CSR_SIP, MIP_STIP); return; @@ -91,7 +88,7 @@ TimerInterruptHandler ( if (mTimerNotifyFunction !=3D NULL) { mTimerNotifyFunction (mTimerPeriod); } - RiscvTimer =3D readq_relaxed(p_mtime); + RiscvTimer =3D RiscVReadMachineTimerInterface(); SbiSetTimer (RiscvTimer +=3D mTimerPeriod); gBS->RestoreTPL (OriginalTPL); csr_set(CSR_SIE, MIP_STIP); // enable SMode timer int @@ -185,10 +182,9 @@ TimerDriverSetTimerPeriod ( return EFI_SUCCESS; } =20 - mTimerPeriod =3D TimerPeriod / 10; // convert unit from 100ns to 1us - - RiscvTimer =3D readq_relaxed(p_mtime); - SbiSetTimer(RiscvTimer + mTimerPeriod); + mTimerPeriod =3D TimerPeriod; // convert unit from 100ns to 1us + RiscvTimer =3D RiscVReadMachineTimerInterface(); + SbiSetTimer(RiscvTimer + mTimerPeriod / 10); =20 mCpu->EnableInterrupt(mCpu); csr_set(CSR_SIE, MIP_STIP); // enable timer int --=20 2.31.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#82336): https://edk2.groups.io/g/devel/message/82336 Mute This Topic: https://groups.io/mt/86435689/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-