From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ot1-f43.google.com (mail-ot1-f43.google.com [209.85.210.43]) by mx.groups.io with SMTP id smtpd.web10.4450.1686159043170203110 for ; Wed, 07 Jun 2023 10:30:43 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="signature has expired" header.i=@ventanamicro.com header.s=google header.b=Wrv7149S; spf=pass (domain: ventanamicro.com, ip: 209.85.210.43, mailfrom: tphan@ventanamicro.com) Received: by mail-ot1-f43.google.com with SMTP id 46e09a7af769-6b2a4cb5776so629076a34.0 for ; Wed, 07 Jun 2023 10:30:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1686159041; x=1688751041; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=djW/Lb1O4guindCW6K+su+Gs2Cqa0CToWkSH8ToRD58=; b=Wrv7149SBlRAqOllV2hVYOdPgomAQH6p/siEBbGw7ygwHWLjngd+6PcQOU1lUnoSx9 BgY5Jmz/jLLUaxPmZuaoO+h1R6pCHDfZiSW5P5x12NiX8niowRilaQnyOo9w/genqsAy ng71H46aULGwVFbFIVQKu8l6ujCqQKmfNAQs50vvw6SwBfLUiA8e2VaG+YqEOqqyGkEi LhBIpWwF/hKx8kUWtv6U0aaj0UcjHP+mzZhpNavM44/Zhc8rIEKl49mav7493GlJGnUg PpM0Bx02Jhj/Bikg8BF2IEJI2mlDq4jgr+Q/Begjoh3WolZpoxOR1Y72KNZYNNmuW6A+ vQ4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686159041; x=1688751041; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=djW/Lb1O4guindCW6K+su+Gs2Cqa0CToWkSH8ToRD58=; b=FFMKGfEeDVYObG+356KR1+WRjeaAOPuRdzbyD/9DfmFSG7gp0jqyxM3zJ73DlLOBvI pJ3lG5hKKpnmX6kTLqpe16KxP69tSndUTGgAszb1fMLntK+xg9GJbMDZIFCaQw9Znlf/ yCi70KjzXUvI2LVy+rd3SiZWFmf0z6VAGrkB1FEMfbpHWoAx1c9RNU69dE66qojUloqG qyn96LVTkvPXejy6GxqXJ3woPZONCGwsn36M9ktyiH8+Z8aktbuuyOhF2sEtSXC6bFSj /K3LzB8j3G5p4NwkvNW6gIax1EdFaj2wOe2YrDv6wrRHVYWtmrd6LAwrgH5tfuOWt52r I36w== X-Gm-Message-State: AC+VfDws1y+2cu+fC/k+Pu/jxhCLRYn8FPqWPSohXWwGIBdAzo+iBTyq F3WLaQj+sJPDbVrLPZjmDq03RElB9QLxc63qb6BVCQ== X-Google-Smtp-Source: ACHHUZ5bxnNZGO2t6uk/jJ1p+1104Q0qW1QwOvglFlckTyDQ1X7Bdg79h1GujZ+ZyMzYEDieIn3KMg== X-Received: by 2002:a05:6830:1bc8:b0:6b2:6ba0:5340 with SMTP id v8-20020a0568301bc800b006b26ba05340mr3346235ota.27.1686159041186; Wed, 07 Jun 2023 10:30:41 -0700 (PDT) Return-Path: Received: from DESKTOP-I1ETA6N.dc1.ventanamicro.com (c-174-50-177-95.hsd1.ca.comcast.net. [174.50.177.95]) by smtp.gmail.com with ESMTPSA id n13-20020a9d6f0d000000b006af814436f4sm5650951otq.25.2023.06.07.10.30.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jun 2023 10:30:40 -0700 (PDT) From: "Tuan Phan" To: devel@edk2.groups.io Cc: eric.dong@intel.com, ray.ni@intel.com, andrei.warkentin@intel.com, sunilvl@ventanamicro.com, Tuan Phan Subject: [PATCH v2 1/2] UefiCpuPkg: CpuTimerDxeRiscV64: Fix incorrect value sent to SbiSetTimer Date: Wed, 7 Jun 2023 10:30:20 -0700 Message-Id: <20230607173021.3566-1-tphan@ventanamicro.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable SbiSetTimer expects core tick value. Cc: Andrei Warkentin Signed-off-by: Tuan Phan Reviewed-by: Sunil V L --- V2: Fixed format issue with uncrustify. .../CpuTimerDxeRiscV64/CpuTimerDxeRiscV64.inf | 3 +++ UefiCpuPkg/CpuTimerDxeRiscV64/Timer.c | 26 ++++++++++++++++--- UefiCpuPkg/CpuTimerDxeRiscV64/Timer.h | 2 +- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/UefiCpuPkg/CpuTimerDxeRiscV64/CpuTimerDxeRiscV64.inf b/UefiCpu= Pkg/CpuTimerDxeRiscV64/CpuTimerDxeRiscV64.inf index c76bd9648373..aba660186dc0 100644 --- a/UefiCpuPkg/CpuTimerDxeRiscV64/CpuTimerDxeRiscV64.inf +++ b/UefiCpuPkg/CpuTimerDxeRiscV64/CpuTimerDxeRiscV64.inf @@ -40,6 +40,9 @@ Timer.h=0D Timer.c=0D =0D +[Pcd]=0D + gUefiCpuPkgTokenSpaceGuid.PcdCpuCoreCrystalClockFrequency ## CONSUMES=0D +=0D [Protocols]=0D gEfiCpuArchProtocolGuid ## CONSUMES=0D gEfiTimerArchProtocolGuid ## PRODUCES=0D diff --git a/UefiCpuPkg/CpuTimerDxeRiscV64/Timer.c b/UefiCpuPkg/CpuTimerDxe= RiscV64/Timer.c index fa957ba5e3e9..358057e7c6a4 100644 --- a/UefiCpuPkg/CpuTimerDxeRiscV64/Timer.c +++ b/UefiCpuPkg/CpuTimerDxeRiscV64/Timer.c @@ -80,8 +80,15 @@ TimerInterruptHandler ( return;=0D }=0D =0D - mLastPeriodStart =3D PeriodStart;=0D - SbiSetTimer (PeriodStart +=3D mTimerPeriod);=0D + mLastPeriodStart =3D PeriodStart;=0D + PeriodStart +=3D DivU64x32 (=0D + MultU64x32 (=0D + mTimerPeriod,=0D + PcdGet64 (PcdCpuCoreCrystalClockFrequency)=0D + ),=0D + 1000000u=0D + ); // convert to tick=0D + SbiSetTimer (PeriodStart);=0D RiscVEnableTimerInterrupt (); // enable SMode timer int=0D gBS->RestoreTPL (OriginalTPL);=0D }=0D @@ -163,6 +170,8 @@ TimerDriverSetTimerPeriod ( IN UINT64 TimerPeriod=0D )=0D {=0D + UINT64 PeriodStart;=0D +=0D DEBUG ((DEBUG_INFO, "TimerDriverSetTimerPeriod(0x%lx)\n", TimerPeriod));= =0D =0D if (TimerPeriod =3D=3D 0) {=0D @@ -171,9 +180,18 @@ TimerDriverSetTimerPeriod ( return EFI_SUCCESS;=0D }=0D =0D - mTimerPeriod =3D TimerPeriod / 10; // convert unit from 100ns to 1us= =0D + mTimerPeriod =3D TimerPeriod / 10; // convert unit from 100ns to 1us= =0D +=0D mLastPeriodStart =3D RiscVReadTimer ();=0D - SbiSetTimer (mLastPeriodStart + mTimerPeriod);=0D + PeriodStart =3D mLastPeriodStart;=0D + PeriodStart +=3D DivU64x32 (=0D + MultU64x32 (=0D + mTimerPeriod,=0D + PcdGet64 (PcdCpuCoreCrystalClockFrequency)=0D + ),=0D + 1000000u=0D + ); // convert to tick=0D + SbiSetTimer (PeriodStart);=0D =0D mCpu->EnableInterrupt (mCpu);=0D RiscVEnableTimerInterrupt (); // enable SMode timer int=0D diff --git a/UefiCpuPkg/CpuTimerDxeRiscV64/Timer.h b/UefiCpuPkg/CpuTimerDxe= RiscV64/Timer.h index 586eb0cfadb4..9b3542230cb5 100644 --- a/UefiCpuPkg/CpuTimerDxeRiscV64/Timer.h +++ b/UefiCpuPkg/CpuTimerDxeRiscV64/Timer.h @@ -21,7 +21,7 @@ #include =0D =0D //=0D -// RISC-V use 100us timer.=0D +// RISC-V use 100ns timer.=0D // The default timer tick duration is set to 10 ms =3D 10 * 1000 * 10 100 = ns units=0D //=0D #define DEFAULT_TIMER_TICK_DURATION 100000=0D --=20 2.25.1