From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 1205AAC0B63 for ; Mon, 8 Jan 2024 11:37:10 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=fKMyyM/XLyQlh76lZ7JYOUbhkVnAkdO3JqwYsGszPXE=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1704713829; v=1; b=v8XAbNfxF9HHvPYYXko2ZqNUOLsEVG0jwPOQgWnasvcm7wJgs+aydnb4jUzG+6r9xnS6xLr/ TCPvuSZeVupGs6ILm2fyZIOqivIdnvjvsw01zp2kovnx/PGGzLRkEIOxr9P/Jb3RLrcJn6n6FlC fd6yP77GqndcnSUVKtmiewR4= X-Received: by 127.0.0.2 with SMTP id pdZVYY7687511xJ1upXWkDNn; Mon, 08 Jan 2024 03:37:09 -0800 X-Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by mx.groups.io with SMTP id smtpd.web11.4721.1704713829189811893 for ; Mon, 08 Jan 2024 03:37:09 -0800 X-Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-6d9a79a1ad4so388393b3a.2 for ; Mon, 08 Jan 2024 03:37:09 -0800 (PST) X-Gm-Message-State: PdM1uTJCvs6kfYSJkF7HQflCx7686176AA= X-Google-Smtp-Source: AGHT+IFk+Q5znJ+dj6ar9vO3AVdFCDPBia1MKXSOgWQnFc6o1DO6g7Q26j/QGa+NfWM4dDJCduqEVg== X-Received: by 2002:a05:6a00:2e25:b0:6da:c21e:40c0 with SMTP id fc37-20020a056a002e2500b006dac21e40c0mr1054599pfb.18.1704713827874; Mon, 08 Jan 2024 03:37:07 -0800 (PST) X-Received: from localhost.localdomain ([106.51.188.200]) by smtp.gmail.com with ESMTPSA id i12-20020aa787cc000000b006d9af59eecesm5846618pfo.20.2024.01.08.03.37.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 03:37:07 -0800 (PST) From: "Sunil V L" To: devel@edk2.groups.io Cc: Sunil V L , Gerd Hoffmann , Rahul Kumar , Laszlo Ersek , Ray Ni , Andrei Warkentin Subject: [edk2-devel] [PATCH v2 3/4] UefiCpuPkg/CpuTimerDxeRiscV64: Add support for Sstc Date: Mon, 8 Jan 2024 17:06:49 +0530 Message-Id: <20240108113650.454940-4-sunilvl@ventanamicro.com> In-Reply-To: <20240108113650.454940-1-sunilvl@ventanamicro.com> References: <20240108113650.454940-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk 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,sunilvl@ventanamicro.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Transfer-Encoding: 8bit X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=v8XAbNfx; dmarc=none; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io Sstc extension allows to program the timer and receive the interrupt without using an SBI call. This reduces the latency to generate the timer interrupt. So, detect whether Sstc extension is supported and use the stimecmp register directly to program the timer interrupt. Cc: Gerd Hoffmann Cc: Rahul Kumar Cc: Laszlo Ersek Cc: Ray Ni Cc: Andrei Warkentin Signed-off-by: Sunil V L --- .../CpuTimerDxeRiscV64/CpuTimerDxeRiscV64.inf | 1 + UefiCpuPkg/CpuTimerDxeRiscV64/Timer.h | 2 + UefiCpuPkg/CpuTimerDxeRiscV64/Timer.c | 49 +++++++++++++++++-- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/UefiCpuPkg/CpuTimerDxeRiscV64/CpuTimerDxeRiscV64.inf b/UefiCpuPkg/CpuTimerDxeRiscV64/CpuTimerDxeRiscV64.inf index aba660186dc0..f2a2cf12caef 100644 --- a/UefiCpuPkg/CpuTimerDxeRiscV64/CpuTimerDxeRiscV64.inf +++ b/UefiCpuPkg/CpuTimerDxeRiscV64/CpuTimerDxeRiscV64.inf @@ -41,6 +41,7 @@ [Sources.RISCV64] Timer.c [Pcd] + gEfiMdePkgTokenSpaceGuid.PcdRiscVFeatureOverride ## CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuCoreCrystalClockFrequency ## CONSUMES [Protocols] diff --git a/UefiCpuPkg/CpuTimerDxeRiscV64/Timer.h b/UefiCpuPkg/CpuTimerDxeRiscV64/Timer.h index 9b3542230cb5..067bbd29f377 100644 --- a/UefiCpuPkg/CpuTimerDxeRiscV64/Timer.h +++ b/UefiCpuPkg/CpuTimerDxeRiscV64/Timer.h @@ -26,6 +26,8 @@ // #define DEFAULT_TIMER_TICK_DURATION 100000 +#define RISCV_CPU_FEATURE_SSTC_BITMASK BIT1 + extern VOID RiscvSetTimerPeriod ( UINT32 TimerPeriod diff --git a/UefiCpuPkg/CpuTimerDxeRiscV64/Timer.c b/UefiCpuPkg/CpuTimerDxeRiscV64/Timer.c index 30e48061cd06..216f48a52931 100644 --- a/UefiCpuPkg/CpuTimerDxeRiscV64/Timer.c +++ b/UefiCpuPkg/CpuTimerDxeRiscV64/Timer.c @@ -44,6 +44,45 @@ STATIC EFI_TIMER_NOTIFY mTimerNotifyFunction; STATIC UINT64 mTimerPeriod = 0; STATIC UINT64 mLastPeriodStart = 0; +// +// Sstc support +// +STATIC BOOLEAN mSstcEnabled = FALSE; + +/** + Program the timer. + + Program either using stimecmp (when Sstc extension is enabled) or using SBI + TIME call. + + @param NextValue Core tick value the timer should expire. +**/ +STATIC +VOID +RiscVProgramTimer ( + UINT64 NextValue + ) +{ + if (mSstcEnabled) { + RiscVSetSupervisorTimeCompareRegister (NextValue); + } else { + SbiSetTimer (NextValue); + } +} + +/** + Check whether Sstc is enabled in PCD. + +**/ +STATIC +BOOLEAN +RiscVIsSstcEnabled ( + VOID + ) +{ + return ((PcdGet64 (PcdRiscVFeatureOverride) & RISCV_CPU_FEATURE_SSTC_BITMASK) != 0); +} + /** Timer Interrupt Handler. @@ -94,7 +133,7 @@ TimerInterruptHandler ( ), 1000000u ); // convert to tick - SbiSetTimer (PeriodStart); + RiscVProgramTimer (PeriodStart); RiscVEnableTimerInterrupt (); // enable SMode timer int gBS->RestoreTPL (OriginalTPL); } @@ -197,8 +236,7 @@ TimerDriverSetTimerPeriod ( ), 1000000u ); // convert to tick - SbiSetTimer (PeriodStart); - + RiscVProgramTimer (PeriodStart); mCpu->EnableInterrupt (mCpu); RiscVEnableTimerInterrupt (); // enable SMode timer int return EFI_SUCCESS; @@ -282,6 +320,11 @@ TimerDriverInitialize ( // mTimerNotifyFunction = NULL; + if (RiscVIsSstcEnabled ()) { + mSstcEnabled = TRUE; + DEBUG ((DEBUG_INFO, "TimerDriverInitialize: Timer interrupt is via Sstc extension\n")); + } + // // Make sure the Timer Architectural Protocol is not already installed in the system // -- 2.34.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#113384): https://edk2.groups.io/g/devel/message/113384 Mute This Topic: https://groups.io/mt/103595210/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-