From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ot1-f45.google.com (mail-ot1-f45.google.com [209.85.210.45]) by mx.groups.io with SMTP id smtpd.web11.4553.1686159052266374037 for ; Wed, 07 Jun 2023 10:30:52 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="signature has expired" header.i=@ventanamicro.com header.s=google header.b=TVDxpp2L; spf=pass (domain: ventanamicro.com, ip: 209.85.210.45, mailfrom: tphan@ventanamicro.com) Received: by mail-ot1-f45.google.com with SMTP id 46e09a7af769-6b280319df5so2699500a34.3 for ; Wed, 07 Jun 2023 10:30:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1686159051; x=1688751051; 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=Ecq/dDPiBvtIYzD1yAfJh6LlaFVrwotgc3g8d006n00=; b=TVDxpp2LdOR4g5F+nyi1xXUYfHHldUn/5NFKCV/SXp22pZUhTzpQK6KWI45byoYpVc hTEjAn7J3LvSpQKLlR8JUfqwb3XgcZODI9+Gr5koPe//DfO9KwXPtF+tsKbua92I3wxo UYtBVMbc3jrpg1aAI4x8T0k2KvSeAvuSzk53rWM7FcyZ/sMHvsznjYA/WM+eF7+P7aAF zHQ8BR3oYUt7xKxvfnhwWUHVwIXsklAXTvMkCC6HLuHrtMhMx5wxhbu1kNMJPHdmKZxA RAl9k/jOSo7RqyeS2iEd1o5Qoo6jLAePLwNbmLaCicpTQyh53zFFBPBqaBrhfcEIDw7j fkgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686159051; x=1688751051; 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=Ecq/dDPiBvtIYzD1yAfJh6LlaFVrwotgc3g8d006n00=; b=Z4yERHYS+UCBQckWrMZ30G8tSxEWVqRBYiXXXug2XRG6CGluPZI9TcZ/aN520wVGIt Fo8iEe6EIRyPCZCezuXosdBzL9tnFUZWfcQX2C2QWgkRkPx6xrl2CaH7wXaiarNr4K/p 6/EQ0j+ESxvY9PuKmb6hTl7orHedHW6vZfZ0p00WVaPEYDQw5YYlaWAjRHJx3i2V5FET AhGacKZxTPFO/fV6yw5ftXzTXpHeMUFXib82zzez6WDOSiv9fpjrL6jJJ2LwBwg2CsZr H/dQv8TiaPiEsKDDXQERZxY/ooDnZ4aEXeGrREy39H1gPqWhOe6/JMnAVrePcUDNduVn ANhA== X-Gm-Message-State: AC+VfDzlfO1SumzJn/GjF42vRQoQRmuWW33vsLgkM9vPJ3tuKm20zvjE Nk9QQO4c2Za9YygYt82Z7MOBG4VkE1sxX9QMeaZn8A== X-Google-Smtp-Source: ACHHUZ5YHY2gdkjwcGNBOasceadBLPcjJgJ+kRhemb6LnCXDkyu4UyA0MZsKfHwVXHBWBXFk+tTB5Q== X-Received: by 2002:a9d:750f:0:b0:6b1:c635:b0fd with SMTP id r15-20020a9d750f000000b006b1c635b0fdmr6582407otk.32.1686159051160; Wed, 07 Jun 2023 10:30:51 -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.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jun 2023 10:30:50 -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 2/2] UefiCpuPkg: RISC-V: TimerLib: Fix delay function to use 64-bit Date: Wed, 7 Jun 2023 10:30:21 -0700 Message-Id: <20230607173021.3566-2-tphan@ventanamicro.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230607173021.3566-1-tphan@ventanamicro.com> References: <20230607173021.3566-1-tphan@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable The timer compare register is 64-bit so simplifying the delay function. Cc: Andrei Warkentin Signed-off-by: Tuan Phan Reviewed-by: Sunil V L --- V2: Fix format issue with uncrustify. MdePkg/Include/Register/RiscV64/RiscVImpl.h | 1 - .../BaseRiscV64CpuTimerLib/CpuTimerLib.c | 53 ++++++++----------- 2 files changed, 23 insertions(+), 31 deletions(-) diff --git a/MdePkg/Include/Register/RiscV64/RiscVImpl.h b/MdePkg/Include/R= egister/RiscV64/RiscVImpl.h index ee5c2ba60377..6997de6cc001 100644 --- a/MdePkg/Include/Register/RiscV64/RiscVImpl.h +++ b/MdePkg/Include/Register/RiscV64/RiscVImpl.h @@ -20,6 +20,5 @@ Name:=0D =0D #define ASM_FUNC(Name) _ASM_FUNC(ASM_PFX(Name), .text. ## Name)=0D -#define RISCV_TIMER_COMPARE_BITS 32=0D =0D #endif=0D diff --git a/UefiCpuPkg/Library/BaseRiscV64CpuTimerLib/CpuTimerLib.c b/Uefi= CpuPkg/Library/BaseRiscV64CpuTimerLib/CpuTimerLib.c index 9c8efc0f3530..27d7276aaa8a 100644 --- a/UefiCpuPkg/Library/BaseRiscV64CpuTimerLib/CpuTimerLib.c +++ b/UefiCpuPkg/Library/BaseRiscV64CpuTimerLib/CpuTimerLib.c @@ -22,26 +22,19 @@ @param Delay A period of time to delay in ticks.=0D =0D **/=0D +STATIC=0D VOID=0D InternalRiscVTimerDelay (=0D - IN UINT32 Delay=0D + IN UINT64 Delay=0D )=0D {=0D - UINT32 Ticks;=0D - UINT32 Times;=0D -=0D - Times =3D Delay >> (RISCV_TIMER_COMPARE_BITS - 2);=0D - Delay &=3D ((1 << (RISCV_TIMER_COMPARE_BITS - 2)) - 1);=0D - do {=0D - //=0D - // The target timer count is calculated here=0D - //=0D - Ticks =3D RiscVReadTimer () + Delay;=0D - Delay =3D 1 << (RISCV_TIMER_COMPARE_BITS - 2);=0D - while (((Ticks - RiscVReadTimer ()) & (1 << (RISCV_TIMER_COMPARE_BITS = - 1))) =3D=3D 0) {=0D - CpuPause ();=0D - }=0D - } while (Times-- > 0);=0D + UINT64 Ticks;=0D +=0D + Ticks =3D RiscVReadTimer () + Delay;=0D +=0D + while (RiscVReadTimer () <=3D Ticks) {=0D + CpuPause ();=0D + }=0D }=0D =0D /**=0D @@ -61,13 +54,13 @@ MicroSecondDelay ( )=0D {=0D InternalRiscVTimerDelay (=0D - (UINT32)DivU64x32 (=0D - MultU64x32 (=0D - MicroSeconds,=0D - PcdGet64 (PcdCpuCoreCrystalClockFrequency)=0D - ),=0D - 1000000u=0D - )=0D + DivU64x32 (=0D + MultU64x32 (=0D + MicroSeconds,=0D + PcdGet64 (PcdCpuCoreCrystalClockFrequency)=0D + ),=0D + 1000000u=0D + )=0D );=0D return MicroSeconds;=0D }=0D @@ -89,13 +82,13 @@ NanoSecondDelay ( )=0D {=0D InternalRiscVTimerDelay (=0D - (UINT32)DivU64x32 (=0D - MultU64x32 (=0D - NanoSeconds,=0D - PcdGet64 (PcdCpuCoreCrystalClockFrequency)=0D - ),=0D - 1000000000u=0D - )=0D + DivU64x32 (=0D + MultU64x32 (=0D + NanoSeconds,=0D + PcdGet64 (PcdCpuCoreCrystalClockFrequency)=0D + ),=0D + 1000000000u=0D + )=0D );=0D return NanoSeconds;=0D }=0D --=20 2.25.1