From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) by mx.groups.io with SMTP id smtpd.web11.6328.1662549196457548227 for ; Wed, 07 Sep 2022 04:13:16 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@ventanamicro.com header.s=google header.b=CNfCNHUj; spf=pass (domain: ventanamicro.com, ip: 209.85.216.50, mailfrom: sunilvl@ventanamicro.com) Received: by mail-pj1-f50.google.com with SMTP id x1-20020a17090ab00100b001fda21bbc90so17922239pjq.3 for ; Wed, 07 Sep 2022 04:13:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=ilm3+J2YIHpgadgsdRwBSgteBW68NpM4ciVhyuuVeF0=; b=CNfCNHUjuQRR6Y35e6mJJ8MuyBml196I1DVPR3AnnvIRNYvL33hz7LpNC58it2Dwsv s6iQ4wmc/61A+kfd6+c/95LEQm3z/qk8cMZE7rfUz6G+x9smcyCz1LcRA6hyWi+IICA3 y1RfyN5AcWO2vgftnMqQUDn6XOpnuyEBG3B1a87EF7pLYgodPLu1AWBlBMQjnjCy89kk AUum1Dx4D/aIb/HijzW4OCVCYbBACgZfNByJxMwIVV+VGnbweCES0tatgiRM5tZrLSNM M5bg4JNk3OJV4ZLyLjotCd5R8rAw5+qQs/0ImLqe+t4h95/AzsbfQn5UxLDrwMbxdHiG Q7xQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=ilm3+J2YIHpgadgsdRwBSgteBW68NpM4ciVhyuuVeF0=; b=DfvX2XMb+g36YPaTGQZSW6wC6zfuHQNFhuKHTUHbgwDc81A2weAp6DzO8HzXER9GPh jwLULojxCeCVqTJu/ShVVnWpqgxMj8/HpaSw8cbSM8ZLFr1BHQwRK2Mm4bm7n3o36SeW jEGj8NgHeItNwGhfvrZHeOe+1VTE1x+Gt8gg+R6F1Z779y8HwGzRdSFxDSD0AF64eizb Z4JhCYZnnrer2XRnhBSk0mnKz0xZmuv5LAS6d54/RMuc0eTct/fjZrt/vMR3ZZHPRjUc 6caFGcq4py8vOb6IN4x4L4pq111PuKdfKYv9ojbZuTu7CEDa0EL8qtNiGVh/eH7EfiJ6 EyeQ== X-Gm-Message-State: ACgBeo1A53drJuX4Lm5VyqPUTA6vlEpjg4WrkxA4hv3tmhI4gijRCw7L 2u9JpVAXwmnl5fc9vgcmXBO935r/p9ByOiK/ X-Google-Smtp-Source: AA6agR4taTfvPQtx44JHrP4w/6K8fkkRIf/RJe3dthFunjbIglVWk+1qtAWuQ/Ht3vAxL8m6/8WL1A== X-Received: by 2002:a17:902:db11:b0:175:4cdc:f32 with SMTP id m17-20020a170902db1100b001754cdc0f32mr3062118plx.58.1662549195416; Wed, 07 Sep 2022 04:13:15 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([49.206.11.92]) by smtp.gmail.com with ESMTPSA id y5-20020aa79ae5000000b0052b84ca900csm12208518pfp.62.2022.09.07.04.13.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Sep 2022 04:13:15 -0700 (PDT) From: "Sunil V L" To: devel@edk2.groups.io Cc: Jian J Wang , Liming Gao , Eric Dong , Ray Ni , Rahul Kumar , Debkumar De , Catharine West , Daniel Schaefer , Abner Chang , Leif Lindholm , Andrew Fish , Ard Biesheuvel , Heinrich Schuchardt , Anup Patel , Sunil V L Subject: [RFC PATCH V2 17/19] MdeModulePkg/Universal: Add TimerDxe module Date: Wed, 7 Sep 2022 16:41:23 +0530 Message-Id: <20220907111125.539698-18-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220907111125.539698-1-sunilvl@ventanamicro.com> References: <20220907111125.539698-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable This DXE module initializes the timer interrupt handler and installs the Arch Timer protocol. Signed-off-by: Sunil V L --- MdeModulePkg/Universal/TimerDxe/TimerDxe.inf | 52 ++++ MdeModulePkg/Universal/TimerDxe/RiscV64/Timer.h | 174 ++++++++++++ MdeModulePkg/Universal/TimerDxe/RiscV64/Timer.c | 293 ++++++++++++++++++++ MdeModulePkg/Universal/TimerDxe/Timer.uni | 15 + MdeModulePkg/Universal/TimerDxe/TimerExtra.uni | 13 + 5 files changed, 547 insertions(+) diff --git a/MdeModulePkg/Universal/TimerDxe/TimerDxe.inf b/MdeModulePkg/Un= iversal/TimerDxe/TimerDxe.inf new file mode 100644 index 000000000000..b291a1fcecb2 --- /dev/null +++ b/MdeModulePkg/Universal/TimerDxe/TimerDxe.inf @@ -0,0 +1,52 @@ +## @file=0D +# Timer Arch protocol module=0D +#=0D +# Copyright (c) 2019, Hewlett Packard Enterprise Development LP. All right= s reserved.
=0D +# Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
= =0D +#=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +##=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x0001001b=0D + BASE_NAME =3D Timer=0D + MODULE_UNI_FILE =3D Timer.uni=0D + FILE_GUID =3D 055DDAC6-9142-4013-BF20-FC2E5BC325C9= =0D + MODULE_TYPE =3D DXE_DRIVER=0D + VERSION_STRING =3D 1.0=0D + ENTRY_POINT =3D TimerDriverInitialize=0D +#=0D +# The following information is for reference only and not required by the = build=0D +# tools.=0D +#=0D +# VALID_ARCHITECTURES =3D RISCV64=0D +#=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D + UefiCpuPkg/UefiCpuPkg.dec=0D +=0D +[LibraryClasses]=0D + BaseLib=0D + DebugLib=0D + IoLib=0D + CpuLib=0D + UefiBootServicesTableLib=0D + UefiDriverEntryPoint=0D +=0D +[LibraryClasses.RISCV64]=0D + RiscVSbiLib=0D +=0D +[Sources.RISCV64]=0D + RiscV64/Timer.h=0D + RiscV64/Timer.c=0D +=0D +[Protocols]=0D + gEfiCpuArchProtocolGuid ## CONSUMES=0D + gEfiTimerArchProtocolGuid ## PRODUCES=0D +=0D +[Depex]=0D + gEfiCpuArchProtocolGuid=0D +=0D +[UserExtensions.TianoCore."ExtraFiles"]=0D + TimerExtra.uni=0D diff --git a/MdeModulePkg/Universal/TimerDxe/RiscV64/Timer.h b/MdeModulePkg= /Universal/TimerDxe/RiscV64/Timer.h new file mode 100644 index 000000000000..32f56f8fe1ca --- /dev/null +++ b/MdeModulePkg/Universal/TimerDxe/RiscV64/Timer.h @@ -0,0 +1,174 @@ +/** @file=0D + RISC-V Timer Architectural Protocol definitions=0D +=0D + Copyright (c) 2019, Hewlett Packard Enterprise Development LP. All right= s reserved.
=0D + Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
= =0D +=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#ifndef _TIMER_H_=0D +#define _TIMER_H_=0D +=0D +#include =0D +=0D +#include =0D +#include =0D +=0D +#include =0D +#include =0D +#include =0D +#include =0D +=0D +//=0D +// RISC-V use 100us 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 +=0D +extern VOID RiscvSetTimerPeriod (UINT32 TimerPeriod);=0D +=0D +//=0D +// Function Prototypes=0D +//=0D +/**=0D + Initialize the Timer Architectural Protocol driver=0D +=0D + @param ImageHandle ImageHandle of the loaded driver=0D + @param SystemTable Pointer to the System Table=0D +=0D + @retval EFI_SUCCESS Timer Architectural Protocol created=0D + @retval EFI_OUT_OF_RESOURCES Not enough resources available to initial= ize driver.=0D + @retval EFI_DEVICE_ERROR A device error occured attempting to init= ialize the driver.=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +TimerDriverInitialize (=0D + IN EFI_HANDLE ImageHandle,=0D + IN EFI_SYSTEM_TABLE *SystemTable=0D + )=0D +;=0D +=0D +/**=0D +=0D + This function adjusts the period of timer interrupts to the value specif= ied=0D + by TimerPeriod. If the timer period is updated, then the selected timer= =0D + period is stored in EFI_TIMER.TimerPeriod, and EFI_SUCCESS is returned. = If=0D + the timer hardware is not programmable, then EFI_UNSUPPORTED is returned= .=0D + If an error occurs while attempting to update the timer period, then the= =0D + timer hardware will be put back in its state prior to this call, and=0D + EFI_DEVICE_ERROR is returned. If TimerPeriod is 0, then the timer inter= rupt=0D + is disabled. This is not the same as disabling the CPU's interrupts.=0D + Instead, it must either turn off the timer hardware, or it must adjust t= he=0D + interrupt controller so that a CPU interrupt is not generated when the t= imer=0D + interrupt fires.=0D +=0D +=0D + @param This The EFI_TIMER_ARCH_PROTOCOL instance.=0D + @param NotifyFunction The rate to program the timer interrupt in 100 nS= units. If=0D + the timer hardware is not programmable, then EFI_= UNSUPPORTED is=0D + returned. If the timer is programmable, then the= timer period=0D + will be rounded up to the nearest timer period th= at is supported=0D + by the timer hardware. If TimerPeriod is set to = 0, then the=0D + timer interrupts will be disabled.=0D +=0D + @retval EFI_SUCCESS The timer period was changed.=0D + @retval EFI_UNSUPPORTED The platform cannot change the period o= f the timer interrupt.=0D + @retval EFI_DEVICE_ERROR The timer period could not be changed d= ue to a device error.=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +TimerDriverRegisterHandler (=0D + IN EFI_TIMER_ARCH_PROTOCOL *This,=0D + IN EFI_TIMER_NOTIFY NotifyFunction=0D + )=0D +;=0D +=0D +/**=0D +=0D + This function adjusts the period of timer interrupts to the value specif= ied=0D + by TimerPeriod. If the timer period is updated, then the selected timer= =0D + period is stored in EFI_TIMER.TimerPeriod, and EFI_SUCCESS is returned. = If=0D + the timer hardware is not programmable, then EFI_UNSUPPORTED is returned= .=0D + If an error occurs while attempting to update the timer period, then the= =0D + timer hardware will be put back in its state prior to this call, and=0D + EFI_DEVICE_ERROR is returned. If TimerPeriod is 0, then the timer inter= rupt=0D + is disabled. This is not the same as disabling the CPU's interrupts.=0D + Instead, it must either turn off the timer hardware, or it must adjust t= he=0D + interrupt controller so that a CPU interrupt is not generated when the t= imer=0D + interrupt fires.=0D +=0D +=0D + @param This The EFI_TIMER_ARCH_PROTOCOL instance.=0D + @param TimerPeriod The rate to program the timer interrupt in 100 nS= units. If=0D + the timer hardware is not programmable, then EFI_= UNSUPPORTED is=0D + returned. If the timer is programmable, then the= timer period=0D + will be rounded up to the nearest timer period th= at is supported=0D + by the timer hardware. If TimerPeriod is set to = 0, then the=0D + timer interrupts will be disabled.=0D +=0D + @retval EFI_SUCCESS The timer period was changed.=0D + @retval EFI_UNSUPPORTED The platform cannot change the period o= f the timer interrupt.=0D + @retval EFI_DEVICE_ERROR The timer period could not be changed d= ue to a device error.=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +TimerDriverSetTimerPeriod (=0D + IN EFI_TIMER_ARCH_PROTOCOL *This,=0D + IN UINT64 TimerPeriod=0D + )=0D +;=0D +=0D +/**=0D +=0D + This function retrieves the period of timer interrupts in 100 ns units,= =0D + returns that value in TimerPeriod, and returns EFI_SUCCESS. If TimerPer= iod=0D + is NULL, then EFI_INVALID_PARAMETER is returned. If a TimerPeriod of 0 = is=0D + returned, then the timer is currently disabled.=0D +=0D +=0D + @param This The EFI_TIMER_ARCH_PROTOCOL instance.=0D + @param TimerPeriod A pointer to the timer period to retrieve in 100 = ns units. If=0D + 0 is returned, then the timer is currently disabl= ed.=0D +=0D + @retval EFI_SUCCESS The timer period was returned in TimerPer= iod.=0D + @retval EFI_INVALID_PARAMETER TimerPeriod is NULL.=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +TimerDriverGetTimerPeriod (=0D + IN EFI_TIMER_ARCH_PROTOCOL *This,=0D + OUT UINT64 *TimerPeriod=0D + )=0D +;=0D +=0D +/**=0D +=0D + This function generates a soft timer interrupt. If the platform does not= support soft=0D + timer interrupts, then EFI_UNSUPPORTED is returned. Otherwise, EFI_SUCCE= SS is returned.=0D + If a handler has been registered through the EFI_TIMER_ARCH_PROTOCOL.Reg= isterHandler()=0D + service, then a soft timer interrupt will be generated. If the timer int= errupt is=0D + enabled when this service is called, then the registered handler will be= invoked. The=0D + registered handler should not be able to distinguish a hardware-generate= d timer=0D + interrupt from a software-generated timer interrupt.=0D +=0D +=0D + @param This The EFI_TIMER_ARCH_PROTOCOL instance.=0D +=0D + @retval EFI_SUCCESS The soft timer interrupt was generated.=0D + @retval EFI_UNSUPPORTEDT The platform does not support the generation o= f soft timer interrupts.=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +TimerDriverGenerateSoftInterrupt (=0D + IN EFI_TIMER_ARCH_PROTOCOL *This=0D + )=0D +;=0D +=0D +#endif=0D diff --git a/MdeModulePkg/Universal/TimerDxe/RiscV64/Timer.c b/MdeModulePkg= /Universal/TimerDxe/RiscV64/Timer.c new file mode 100644 index 000000000000..4deb91766d17 --- /dev/null +++ b/MdeModulePkg/Universal/TimerDxe/RiscV64/Timer.c @@ -0,0 +1,293 @@ +/** @file=0D + RISC-V Timer Architectural Protocol=0D +=0D + Copyright (c) 2019, Hewlett Packard Enterprise Development LP. All right= s reserved.
=0D + Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
= =0D +=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#include "Timer.h"=0D +#include =0D +#include =0D +=0D +//=0D +// The handle onto which the Timer Architectural Protocol will be installe= d=0D +//=0D +STATIC EFI_HANDLE mTimerHandle =3D NULL;=0D +=0D +//=0D +// The Timer Architectural Protocol that this driver produces=0D +//=0D +EFI_TIMER_ARCH_PROTOCOL mTimer =3D {=0D + TimerDriverRegisterHandler,=0D + TimerDriverSetTimerPeriod,=0D + TimerDriverGetTimerPeriod,=0D + TimerDriverGenerateSoftInterrupt=0D +};=0D +=0D +//=0D +// Pointer to the CPU Architectural Protocol instance=0D +//=0D +EFI_CPU_ARCH_PROTOCOL *mCpu;=0D +=0D +//=0D +// The notification function to call on every timer interrupt.=0D +// A bug in the compiler prevents us from initializing this here.=0D +//=0D +STATIC EFI_TIMER_NOTIFY mTimerNotifyFunction;=0D +=0D +//=0D +// The current period of the timer interrupt=0D +//=0D +STATIC UINT64 mTimerPeriod =3D 0;=0D +=0D +/**=0D + Timer Interrupt Handler.=0D +=0D + @param InterruptType The type of interrupt that occured=0D + @param SystemContext A pointer to the system context when the interru= pt occured=0D +**/=0D +=0D +VOID=0D +EFIAPI=0D +TimerInterruptHandler (=0D + IN EFI_EXCEPTION_TYPE InterruptType,=0D + IN EFI_SYSTEM_CONTEXT SystemContext=0D + )=0D +{=0D + EFI_TPL OriginalTPL;=0D + UINT64 RiscvTimer;=0D +=0D + OriginalTPL =3D gBS->RaiseTPL (TPL_HIGH_LEVEL);=0D + if (mTimerNotifyFunction !=3D NULL) {=0D + mTimerNotifyFunction (mTimerPeriod);=0D + }=0D + csr_clear(CSR_SIE, SIP_STIP); // Disable SMode timer int=0D + csr_clear(CSR_SIP, SIP_STIP);=0D + if (mTimerPeriod =3D=3D 0) {=0D + gBS->RestoreTPL (OriginalTPL);=0D + csr_clear(CSR_SIE, SIP_STIP); // Disable SMode timer int=0D + return;=0D + }=0D + RiscvTimer =3D csr_read(CSR_TIME);=0D + SbiSetTimer (RiscvTimer +=3D mTimerPeriod);=0D + gBS->RestoreTPL (OriginalTPL);=0D + csr_set(CSR_SIE, SIP_STIP); // enable SMode timer int=0D +}=0D +=0D +/**=0D +=0D + This function registers the handler NotifyFunction so it is called every= time=0D + the timer interrupt fires. It also passes the amount of time since the = last=0D + handler call to the NotifyFunction. If NotifyFunction is NULL, then the= =0D + handler is unregistered. If the handler is registered, then EFI_SUCCESS= is=0D + returned. If the CPU does not support registering a timer interrupt han= dler,=0D + then EFI_UNSUPPORTED is returned. If an attempt is made to register a h= andler=0D + when a handler is already registered, then EFI_ALREADY_STARTED is return= ed.=0D + If an attempt is made to unregister a handler when a handler is not regi= stered,=0D + then EFI_INVALID_PARAMETER is returned. If an error occurs attempting t= o=0D + register the NotifyFunction with the timer interrupt, then EFI_DEVICE_ER= ROR=0D + is returned.=0D +=0D + @param This The EFI_TIMER_ARCH_PROTOCOL instance.=0D + @param NotifyFunction The function to call when a timer interrupt fire= s. This=0D + function executes at TPL_HIGH_LEVEL. The DXE Co= re will=0D + register a handler for the timer interrupt, so i= t can know=0D + how much time has passed. This information is u= sed to=0D + signal timer based events. NULL will unregister= the handler.=0D +=0D + @retval EFI_SUCCESS The timer handler was registered.= =0D + @retval EFI_UNSUPPORTED The platform does not support time= r interrupts.=0D + @retval EFI_ALREADY_STARTED NotifyFunction is not NULL, and a = handler is already=0D + registered.=0D + @retval EFI_INVALID_PARAMETER NotifyFunction is NULL, and a hand= ler was not=0D + previously registered.=0D + @retval EFI_DEVICE_ERROR The timer handler could not be reg= istered.=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +TimerDriverRegisterHandler (=0D + IN EFI_TIMER_ARCH_PROTOCOL *This,=0D + IN EFI_TIMER_NOTIFY NotifyFunction=0D + )=0D +{=0D + DEBUG ((DEBUG_INFO, "TimerDriverRegisterHandler(0x%lx) called\n", Notify= Function));=0D + mTimerNotifyFunction =3D NotifyFunction;=0D + return EFI_SUCCESS;=0D +}=0D +=0D +/**=0D +=0D + This function adjusts the period of timer interrupts to the value specif= ied=0D + by TimerPeriod. If the timer period is updated, then the selected timer= =0D + period is stored in EFI_TIMER.TimerPeriod, and EFI_SUCCESS is returned. = If=0D + the timer hardware is not programmable, then EFI_UNSUPPORTED is returned= .=0D + If an error occurs while attempting to update the timer period, then the= =0D + timer hardware will be put back in its state prior to this call, and=0D + EFI_DEVICE_ERROR is returned. If TimerPeriod is 0, then the timer inter= rupt=0D + is disabled. This is not the same as disabling the CPU's interrupts.=0D + Instead, it must either turn off the timer hardware, or it must adjust t= he=0D + interrupt controller so that a CPU interrupt is not generated when the t= imer=0D + interrupt fires.=0D +=0D +=0D + @param This The EFI_TIMER_ARCH_PROTOCOL instance.=0D + @param TimerPeriod The rate to program the timer interrupt in 100 nS= units. If=0D + the timer hardware is not programmable, then EFI_= UNSUPPORTED is=0D + returned. If the timer is programmable, then the= timer period=0D + will be rounded up to the nearest timer period th= at is supported=0D + by the timer hardware. If TimerPeriod is set to = 0, then the=0D + timer interrupts will be disabled.=0D +=0D + @retval EFI_SUCCESS The timer period was changed.=0D + @retval EFI_UNSUPPORTED The platform cannot change the period o= f the timer interrupt.=0D + @retval EFI_DEVICE_ERROR The timer period could not be changed d= ue to a device error.=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +TimerDriverSetTimerPeriod (=0D + IN EFI_TIMER_ARCH_PROTOCOL *This,=0D + IN UINT64 TimerPeriod=0D + )=0D +{=0D + UINT64 RiscvTimer;=0D +=0D + DEBUG ((DEBUG_INFO, "TimerDriverSetTimerPeriod(0x%lx)\n", TimerPeriod));= =0D +=0D + if (TimerPeriod =3D=3D 0) {=0D + mTimerPeriod =3D 0;=0D + csr_clear(CSR_SIE, SIP_STIP); // disable timer int=0D + return EFI_SUCCESS;=0D + }=0D +=0D + mTimerPeriod =3D TimerPeriod / 10; // convert unit from 100ns to 1us=0D + RiscvTimer =3D csr_read(CSR_TIME);=0D + SbiSetTimer(RiscvTimer + mTimerPeriod);=0D +=0D + mCpu->EnableInterrupt(mCpu);=0D + csr_set(CSR_SIE, SIP_STIP); // enable timer int=0D + return EFI_SUCCESS;=0D +}=0D +=0D +/**=0D +=0D + This function retrieves the period of timer interrupts in 100 ns units,= =0D + returns that value in TimerPeriod, and returns EFI_SUCCESS. If TimerPer= iod=0D + is NULL, then EFI_INVALID_PARAMETER is returned. If a TimerPeriod of 0 = is=0D + returned, then the timer is currently disabled.=0D +=0D +=0D + @param This The EFI_TIMER_ARCH_PROTOCOL instance.=0D + @param TimerPeriod A pointer to the timer period to retrieve in 100 = ns units. If=0D + 0 is returned, then the timer is currently disabl= ed.=0D +=0D + @retval EFI_SUCCESS The timer period was returned in TimerPer= iod.=0D + @retval EFI_INVALID_PARAMETER TimerPeriod is NULL.=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +TimerDriverGetTimerPeriod (=0D + IN EFI_TIMER_ARCH_PROTOCOL *This,=0D + OUT UINT64 *TimerPeriod=0D + )=0D +{=0D + *TimerPeriod =3D mTimerPeriod;=0D + return EFI_SUCCESS;=0D +}=0D +=0D +/**=0D +=0D + This function generates a soft timer interrupt. If the platform does not= support soft=0D + timer interrupts, then EFI_UNSUPPORTED is returned. Otherwise, EFI_SUCCE= SS is returned.=0D + If a handler has been registered through the EFI_TIMER_ARCH_PROTOCOL.Reg= isterHandler()=0D + service, then a soft timer interrupt will be generated. If the timer int= errupt is=0D + enabled when this service is called, then the registered handler will be= invoked. The=0D + registered handler should not be able to distinguish a hardware-generate= d timer=0D + interrupt from a software-generated timer interrupt.=0D +=0D +=0D + @param This The EFI_TIMER_ARCH_PROTOCOL instance.=0D +=0D + @retval EFI_SUCCESS The soft timer interrupt was generated.=0D + @retval EFI_UNSUPPORTEDT The platform does not support the generation o= f soft timer interrupts.=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +TimerDriverGenerateSoftInterrupt (=0D + IN EFI_TIMER_ARCH_PROTOCOL *This=0D + )=0D +{=0D + return EFI_SUCCESS;=0D +}=0D +=0D +/**=0D + Initialize the Timer Architectural Protocol driver=0D +=0D + @param ImageHandle ImageHandle of the loaded driver=0D + @param SystemTable Pointer to the System Table=0D +=0D + @retval EFI_SUCCESS Timer Architectural Protocol created=0D + @retval EFI_OUT_OF_RESOURCES Not enough resources available to initial= ize driver.=0D + @retval EFI_DEVICE_ERROR A device error occured attempting to init= ialize the driver.=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +TimerDriverInitialize (=0D + IN EFI_HANDLE ImageHandle,=0D + IN EFI_SYSTEM_TABLE *SystemTable=0D + )=0D +{=0D + EFI_STATUS Status;=0D +=0D + //=0D + // Initialize the pointer to our notify function.=0D + //=0D + mTimerNotifyFunction =3D NULL;=0D +=0D + //=0D + // Make sure the Timer Architectural Protocol is not already installed i= n the system=0D + //=0D + ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiTimerArchProtocolGuid);=0D +=0D + //=0D + // Find the CPU architectural protocol.=0D + //=0D + Status =3D gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **= ) &mCpu);=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + //=0D + // Force the timer to be disabled=0D + //=0D + Status =3D TimerDriverSetTimerPeriod (&mTimer, 0);=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + //=0D + // Install interrupt handler for RISC-V Timer.=0D + //=0D + Status =3D mCpu->RegisterInterruptHandler (mCpu, EXCEPT_RISCV_TIMER_INT,= TimerInterruptHandler);=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + //=0D + // Force the timer to be enabled at its default period=0D + //=0D + Status =3D TimerDriverSetTimerPeriod (&mTimer, DEFAULT_TIMER_TICK_DURATI= ON);=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + //=0D + // Install the Timer Architectural Protocol onto a new handle=0D + //=0D + Status =3D gBS->InstallMultipleProtocolInterfaces (=0D + &mTimerHandle,=0D + &gEfiTimerArchProtocolGuid, &mTimer,=0D + NULL=0D + );=0D + ASSERT_EFI_ERROR (Status);=0D + return Status;=0D +}=0D diff --git a/MdeModulePkg/Universal/TimerDxe/Timer.uni b/MdeModulePkg/Unive= rsal/TimerDxe/Timer.uni new file mode 100644 index 000000000000..07272a8a787b --- /dev/null +++ b/MdeModulePkg/Universal/TimerDxe/Timer.uni @@ -0,0 +1,15 @@ +// /** @file=0D +//=0D +// Timer Arch protocol strings.=0D +//=0D +// Copyright (c) 2016, Hewlett Packard Enterprise Development LP. All righ= ts reserved.
=0D +// Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
= =0D +//=0D +// SPDX-License-Identifier: BSD-2-Clause-Patent=0D +//=0D +// **/=0D +=0D +=0D +#string STR_MODULE_ABSTRACT #language en-US "Timer driver that= provides Timer Arch protocol"=0D +=0D +#string STR_MODULE_DESCRIPTION #language en-US "Timer driver that= provides Timer Arch protocol."=0D diff --git a/MdeModulePkg/Universal/TimerDxe/TimerExtra.uni b/MdeModulePkg/= Universal/TimerDxe/TimerExtra.uni new file mode 100644 index 000000000000..ad80afe2674c --- /dev/null +++ b/MdeModulePkg/Universal/TimerDxe/TimerExtra.uni @@ -0,0 +1,13 @@ +// /** @file=0D +// Timer Localized Strings and Content=0D +//=0D +// Copyright (c) 2016, Hewlett Packard Enterprise Development LP. All righ= ts reserved.
=0D +// Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
= =0D +//=0D +// SPDX-License-Identifier: BSD-2-Clause-Patent=0D +//=0D +// **/=0D +=0D +#string STR_PROPERTIES_MODULE_NAME=0D +#language en-US=0D +"Timer DXE Driver"=0D --=20 2.25.1