From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (NAM04-DM6-obe.outbound.protection.outlook.com [40.107.102.41]) by mx.groups.io with SMTP id smtpd.web08.30523.1665932026932895596 for ; Sun, 16 Oct 2022 07:53:47 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amd.com header.s=selector1 header.b=XglH4pcc; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: amd.com, ip: 40.107.102.41, mailfrom: abner.chang@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lo7JOkBD8hC2h2F0Dl70jiHPbqRYBYGUTuXlSgd+UUd1yO6t9akscCGAofEHQKb36MSHylPgfb+m/WUgi4LsPjGE2SCETc2Lw6mlBVKW9v0gn+xmlML/SK8SbHYU5ReIi2T84ifvhBKltOA054fHUIPqu8J/t9xkhJ+/cKiLC3+yJWj0LSEwG0zuk3TcK2ysIGPQa/0aDml5r8lu7xXH3qV5pGsrSVvRWHoRWEXz6wn8J+/R87g9FFfghh6QX5PbVwPc+tknMvYH/ALgAaifs2dE1oLRm/3Vr8/E7fY6OoS1mG2NX/MVyaR5pniEqCIFujVUR1Csr+o3whUVEOVbyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=owzxPUEZaPMu20yStDUiETpDIm9R14r1DwIXzzv7/VE=; b=lk31pizcAIaCcshkeDIcaVBoKItlR3ZBnJjLYBPJgWYPmP0QAKFQxYRfGITX9Cfm0yGvVdpckc9JPrl8XLCe8cj5B02E1GvExQKQH+PXINLYsiq+U1i0e2+7q15ExGpbqiYp1gHtKKpxBblTRchFgIMiM0ShueG5M5hO7rHxmKA03D2nl5uygEIAl2RlDCvjXgjKf6NZzQT0BgQ2/LjmsDNnM8ahJpXFcAPaegDoOatEBiB8i7urTk57wvjdq0kPnS64xNV8NcbaEB2Dom86MaUjaU8F/VPzkxpYFQWwncZpT/OXb9jwYET6vm1/Qrq+vrpxt0c6LThlbpn7XHJKBw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=owzxPUEZaPMu20yStDUiETpDIm9R14r1DwIXzzv7/VE=; b=XglH4pcc98CAcnWFBm8xDFWkKFaO9QmzezPIp2wefN+YKJKesP5NWQ6GD6mxJOONYFPRacKerLRX5lRILE0i5nHNAWiQo146PDx4ze6R0jtp/htpuGRdqRXpINwBvwTBhD81ubtUgW03qeapbchH7UOdpod+b43kihpDT5uJh+g= Received: from MN2PR12MB3966.namprd12.prod.outlook.com (2603:10b6:208:165::18) by DS7PR12MB6285.namprd12.prod.outlook.com (2603:10b6:8:96::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.32; Sun, 16 Oct 2022 14:53:41 +0000 Received: from MN2PR12MB3966.namprd12.prod.outlook.com ([fe80::2eab:b851:827c:1d88]) by MN2PR12MB3966.namprd12.prod.outlook.com ([fe80::2eab:b851:827c:1d88%3]) with mapi id 15.20.5723.032; Sun, 16 Oct 2022 14:53:41 +0000 From: "Chang, Abner" To: "devel@edk2.groups.io" , "sunilvl@ventanamicro.com" CC: Eric Dong , Ray Ni , Rahul Kumar , Daniel Schaefer Subject: Re: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V4 20/34] UefiCpuPkg: Add CpuTimerDxe module Thread-Topic: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V4 20/34] UefiCpuPkg: Add CpuTimerDxe module Thread-Index: AQHY3+00inRbr2fJl0mb+V2zcns5Rq4RHe7A Date: Sun, 16 Oct 2022 14:53:41 +0000 Message-ID: References: <20221014164836.1513036-1-sunilvl@ventanamicro.com> <20221014164836.1513036-21-sunilvl@ventanamicro.com> In-Reply-To: <20221014164836.1513036-21-sunilvl@ventanamicro.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_Enabled=true; MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_SetDate=2022-10-16T14:53:39Z; MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_Method=Standard; MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_Name=General; MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_SiteId=3dd8961f-e488-4e60-8e11-a82d994e183d; MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_ActionId=1c701c5a-37f2-4d70-8c98-5e8f8eb9f660; MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_ContentBits=1 authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MN2PR12MB3966:EE_|DS7PR12MB6285:EE_ x-ms-office365-filtering-correlation-id: a2fb9af9-eeec-49a0-126a-08daaf863769 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: lVyO4OMsS/yiMGWSQYUa9seXWW7kOEAdIGwaDrz30fRgb2OEYscDojBotnnW3QYlZrDGGnBsIBG9pBaYncF9ER30b12lY015FJZky8uNl60VlYu6SOyia22KkqAgCPghIdsoil2vtNWomAoyX5ZOv+B8EW1z3aqkSPujCJIEk97+EV00pa4bDiZ0A8zYBi8y8Ja5VF/KT5g3SZqHWv6ks1b6qVe7ScZ71EBgz3gSGRhEvWcAqgt/uZP2cVH0pJq5foHHZQT5SVD/hANlHKJoPFHQTH28SIWRxJjAucGtLRBgfezk2ugV2R6UZc4QyaASGR69HmqUSWgyS46hSwswyn4vvDoYOgrdMmcoRShHRbyrP8OGo+I4RbmGL8Ckif1dcyu0QMdKUyJLqgYHyq/wglEZKbDj2E+H5CL9kBv2JgAFbiuPPdMgDJCLw+MkeI/bs8+47EDni+jTIEVtk2pKC1TfRQeKU6QSqsjwG22olLH4TpSKxwMG2+QO+V9f99EzQ4E8GFBrl/YctEnVtHTWIGUmJFAYv987sN4jQG5NYaJ3rVfhh5TBf3aqRBB8BiqhAeT7dttqm4o+z32fbdhJl/Ny1eDGRew2Aa5rzhWmjlXVDfsLXSNgSSC2W5Gn3Los+bKoHXUmN1eViQbRqn7pQNvKR+WDW/rf2RjM2omn04lLkTt9etFhzp5YjqLJ3h2PeaVfAsBuccPqImuOJFfrcNh1CZ5sBUS0HSDpcyDLy6k7fnOwklWpxm1WR8R5fPqiGvVZFzTtBG1wi72q3rA23YlYpjKZRa2z0C0HwGd+z9JMuXNy7tKiU/QGpoyighpHQOKDU449CNFESXLG4EA3KWcCTg/rdL66pA0QAH70sxU= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN2PR12MB3966.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(376002)(396003)(346002)(136003)(366004)(39860400002)(451199015)(33656002)(55016003)(122000001)(38070700005)(38100700002)(86362001)(66946007)(66556008)(66476007)(66446008)(64756008)(4326008)(76116006)(8676002)(45080400002)(110136005)(54906003)(19627235002)(2906002)(52536014)(316002)(41300700001)(8936002)(30864003)(5660300002)(186003)(83380400001)(478600001)(53546011)(966005)(71200400001)(26005)(9686003)(7696005)(6506007)(66899015)(559001)(579004)(44824005);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?6krYy40h+KuEU/BXntuNoMhVa8YcgXNf4CtxD9cjkjfQrMhpv+FboRKrUfu/?= =?us-ascii?Q?6KLlrWLUN4BIYzbItQPqmwo/JrTDp2x3WFYwqzfYAjLOvs7ZDen1BB4Waj0n?= =?us-ascii?Q?uq2/dTvp4KOAVRJ0dyDGBspJIFJIV2ekhWdMweGZdeNFcEIRKn+R6rQ47P8v?= =?us-ascii?Q?dD7zLLsU8cWpE2RQJsAHMk0PDjcHMKlXIYD44ip4j0eoZtJPWuBjE7XpsYB1?= =?us-ascii?Q?f56gYn8EAckUS2Fw5sLEZuvpa6/6Ff9ZyxrtQtThOZlNWvAYNg0cOD3lQ4nL?= =?us-ascii?Q?PukKSfnXUYxSayNEBDPpdo3TL4t5GDSUMhasBLU3pAfskg1hR71Ht4NMyVfu?= =?us-ascii?Q?N+Qi2vekiTI9/S+19zwEdgqY22aD0nhZzdGgd04wQh4Lf8M0rzhFWL0e2EHo?= =?us-ascii?Q?AsTadH6Iaf8WR6Q5CrzBMC6P25sxHgeEr0fYaRlvAqgSloVvugFE68bpYcTU?= =?us-ascii?Q?Bo3JeltDYqLsLzB/jwOortrDknB1XSmOOFnElbcaU+eT8dXtbs5I2VH/iuL8?= =?us-ascii?Q?I6bGX5Y3K+NvjBDYB2jToOOzD67ihynRovSOdaBpXBjK337Znz2zd0jLclYk?= =?us-ascii?Q?HMaNHsI6wa0JHz1uX/r3Ji3sQWR9AvM8fyB2M+1u5M1129MaRzJpsGwVZa7s?= =?us-ascii?Q?pUuq+MTflAOj/rSwGJKGKdvQH5Z22mqR2RYL0mvQvZsg/sJAg90HvC/8ANnW?= =?us-ascii?Q?dCtMY3WhURqGsZbmf65e4A3YUVa8hWatk5lGzpJLveahQKgFCv5yrg4kmzWy?= =?us-ascii?Q?0KmsXqFpZnfFMjuRGwkfpt+AT/lrKTeUjMsv0p7rIB0ao5/rrhKdt6xobDGt?= =?us-ascii?Q?uWeCeLCd7TyWTbWPzBeTB5ImCJUD90rUpS9t8o9uHXNaW0A0OAiLZSgDq/4Q?= =?us-ascii?Q?u2MFo74qowU1K7RtjI3aUGtWzJMKeWc92sG0PNtt/mglcv9jIr+7D6bc5KvL?= =?us-ascii?Q?5Qbz6qrF/fDlQupNc74OALRo6lR+3jm7H/Aosp8AbirQfr6kDMtZLNYOmHCz?= =?us-ascii?Q?V2WdUEADhQntw2nyUvcEQzWpfaxvApGJQqovf+dbrY8mBvd5fxaoEaV8lo6r?= =?us-ascii?Q?ODBbVrY3dOpbiqwfToBILOYxLSMPE+i8C2jbZThHo5dE9enJANptxK0jIziZ?= =?us-ascii?Q?v6JJqxIQFYVOgn56BF/olMw2R6z8khwIlKVZb7X27PVNCLGczzCSWvdGg5/1?= =?us-ascii?Q?MsGHv3vYsKRBWFP2F1GHL6Nbsk2UMkBpPM4Dj1giwOqsGUrKiMt6dOySE2Ho?= =?us-ascii?Q?NPDT5Pvj07z5egs/qXVdza9svb17KIG9uSNL1FXiRBmryhCoOQMn+Dfx4dOl?= =?us-ascii?Q?WTJ46HCe3DeYAYP80at6CVP9ty5jjyWPpaw8qynYW8anTOLyqS7Jc6uyA6jT?= =?us-ascii?Q?Qr59b4yeUlqnaWKdhiSFyYu8GefDMyQufP7MNRkyO1m1bu2ByQfdXXQ2Havt?= =?us-ascii?Q?Erx8HaVQniRmIbrCZBw4ni/nRRrZRoGQkbb2o9CzwGNw5VPfXyIQn3dohkCH?= =?us-ascii?Q?5NQkPJDlUGmtLKQnDvnh5hbn7wwZxXourjUtDc5BFXd6nZuNuWUPtN9/HTQj?= =?us-ascii?Q?us3OFq3abcRf758q5E61aGA8Si3X00S5QP9fWnGK?= MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MN2PR12MB3966.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: a2fb9af9-eeec-49a0-126a-08daaf863769 X-MS-Exchange-CrossTenant-originalarrivaltime: 16 Oct 2022 14:53:41.5989 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: mcstfeVMFMrHakhsrP2pvyeV1vsIVt8XOcaif8tzmVPQ4VbTD7cuuBsrQMfPc1KbGM/LeZ+4Y275ntGuZD2zpA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB6285 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable [AMD Official Use Only - General] Acked-by: Abner Chang Need maintainer's agreement. Abner > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of Sunil V L > via groups.io > Sent: Saturday, October 15, 2022 12:48 AM > To: devel@edk2.groups.io > Cc: Eric Dong ; Ray Ni ; Rahul > Kumar ; Daniel Schaefer > > Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V4 20/34] > UefiCpuPkg: Add CpuTimerDxe module >=20 > Caution: This message originated from an External Source. Use proper > caution when opening attachments, clicking links, or responding. >=20 >=20 > REF: > https://nam11.safelinks.protection.outlook.com/?url=3Dhttps%3A%2F%2Fbugz > illa.tianocore.org%2Fshow_bug.cgi%3Fid%3D4076&data=3D05%7C01%7Ca > bner.chang%40amd.com%7Cb8b27a5b30864359da3408daae045448%7C3dd89 > 61fe4884e608e11a82d994e183d%7C0%7C0%7C638013630881288660%7CUnkn > own%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik > 1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=3DTuh%2BRGCWd > YvjFXMWH%2FfEYRBoND5OhLWWk2VHINqUhb4%3D&reserved=3D0 >=20 > This DXE module initializes the timer interrupt handler and installs the = Arch > Timer protocol. >=20 > Cc: Eric Dong > Cc: Ray Ni > Cc: Rahul Kumar > Cc: Daniel Schaefer > Signed-off-by: Sunil V L > --- > UefiCpuPkg/UefiCpuPkg.dsc | 3 + > UefiCpuPkg/CpuTimerDxe/CpuTimerDxe.inf | 51 ++++ > UefiCpuPkg/CpuTimerDxe/RiscV64/Timer.h | 177 ++++++++++++ > UefiCpuPkg/CpuTimerDxe/RiscV64/Timer.c | 294 ++++++++++++++++++++ > UefiCpuPkg/CpuTimerDxe/CpuTimer.uni | 14 + > UefiCpuPkg/CpuTimerDxe/CpuTimerExtra.uni | 12 + > 6 files changed, 551 insertions(+) >=20 > diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc index > 6ea90507e36f..54ef5edd6eae 100644 > --- a/UefiCpuPkg/UefiCpuPkg.dsc > +++ b/UefiCpuPkg/UefiCpuPkg.dsc > @@ -178,5 +178,8 @@ [Components.IA32, Components.X64] > UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf > UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableLib.inf >=20 > +[Components.RISCV64] > + UefiCpuPkg/CpuTimerDxe/CpuTimerDxe.inf > + > [BuildOptions] > *_*_*_CC_FLAGS =3D -D DISABLE_NEW_DEPRECATED_INTERFACES diff --git > a/UefiCpuPkg/CpuTimerDxe/CpuTimerDxe.inf > b/UefiCpuPkg/CpuTimerDxe/CpuTimerDxe.inf > new file mode 100644 > index 000000000000..d7706328b591 > --- /dev/null > +++ b/UefiCpuPkg/CpuTimerDxe/CpuTimerDxe.inf > @@ -0,0 +1,51 @@ > +## @file > +# Timer Arch protocol module > +# > +# Copyright (c) 2019, Hewlett Packard Enterprise Development LP. All > +rights reserved.
# # SPDX-License-Identifier: BSD-2-Clause-Patent # > +## > + > +[Defines] > + INF_VERSION =3D 0x0001001b > + BASE_NAME =3D CpuTimerDxe > + MODULE_UNI_FILE =3D CpuTimer.uni > + FILE_GUID =3D 055DDAC6-9142-4013-BF20-FC2E5BC325C= 9 > + MODULE_TYPE =3D DXE_DRIVER > + VERSION_STRING =3D 1.0 > + ENTRY_POINT =3D TimerDriverInitialize > +# > +# The following information is for reference only and not required by > +the build # tools. > +# > +# VALID_ARCHITECTURES =3D RISCV64 > +# > +[Packages] > + MdePkg/MdePkg.dec > + UefiCpuPkg/UefiCpuPkg.dec > + > +[LibraryClasses] > + BaseLib > + DebugLib > + IoLib > + CpuLib > + UefiBootServicesTableLib > + UefiDriverEntryPoint > + > +[LibraryClasses.RISCV64] > + RiscVSbiLib > + > +[Sources.RISCV64] > + RiscV64/Timer.h > + RiscV64/Timer.c > + > +[Protocols] > + gEfiCpuArchProtocolGuid ## CONSUMES > + gEfiTimerArchProtocolGuid ## PRODUCES > + > +[Depex] > + gEfiCpuArchProtocolGuid > + > +[UserExtensions.TianoCore."ExtraFiles"] > + CpuTimerExtra.uni > diff --git a/UefiCpuPkg/CpuTimerDxe/RiscV64/Timer.h > b/UefiCpuPkg/CpuTimerDxe/RiscV64/Timer.h > new file mode 100644 > index 000000000000..586eb0cfadb4 > --- /dev/null > +++ b/UefiCpuPkg/CpuTimerDxe/RiscV64/Timer.h > @@ -0,0 +1,177 @@ > +/** @file > + RISC-V Timer Architectural Protocol definitions > + > + Copyright (c) 2019, Hewlett Packard Enterprise Development LP. All > + rights reserved.
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#ifndef TIMER_H_ > +#define TIMER_H_ > + > +#include > + > +#include > +#include > + > +#include > +#include > +#include > +#include > + > +// > +// RISC-V use 100us timer. > +// The default timer tick duration is set to 10 ms =3D 10 * 1000 * 10 10= 0 > +ns units // #define DEFAULT_TIMER_TICK_DURATION 100000 > + > +extern VOID > +RiscvSetTimerPeriod ( > + UINT32 TimerPeriod > + ); > + > +// > +// Function Prototypes > +// > + > +/** > + Initialize the Timer Architectural Protocol driver > + > + @param ImageHandle ImageHandle of the loaded driver > + @param SystemTable Pointer to the System Table > + > + @retval EFI_SUCCESS Timer Architectural Protocol created > + @retval EFI_OUT_OF_RESOURCES Not enough resources available to > initialize driver. > + @retval EFI_DEVICE_ERROR A device error occured attempting to > initialize the driver. > + > +**/ > +EFI_STATUS > +EFIAPI > +TimerDriverInitialize ( > + IN EFI_HANDLE ImageHandle, > + IN EFI_SYSTEM_TABLE *SystemTable > + ) > +; > + > +/** > + > + This function adjusts the period of timer interrupts to the value > + specified by TimerPeriod. If the timer period is updated, then the > + selected timer period is stored in EFI_TIMER.TimerPeriod, and > + EFI_SUCCESS is returned. If the timer hardware is not programmable, t= hen > EFI_UNSUPPORTED is returned. > + If an error occurs while attempting to update the timer period, then > + the timer hardware will be put back in its state prior to this call, > + and EFI_DEVICE_ERROR is returned. If TimerPeriod is 0, then the > + timer interrupt is disabled. This is not the same as disabling the CP= U's > interrupts. > + Instead, it must either turn off the timer hardware, or it must > + adjust the interrupt controller so that a CPU interrupt is not > + generated when the timer interrupt fires. > + > + > + @param This The EFI_TIMER_ARCH_PROTOCOL instance. > + @param NotifyFunction The rate to program the timer interrupt in 100 = nS > units. If > + the timer hardware is not programmable, then > EFI_UNSUPPORTED is > + returned. If the timer is programmable, then t= he timer period > + will be rounded up to the nearest timer period = that is > supported > + by the timer hardware. If TimerPeriod is set t= o 0, then the > + timer interrupts will be disabled. > + > + @retval EFI_SUCCESS The timer period was changed. > + @retval EFI_UNSUPPORTED The platform cannot change the period= of > the timer interrupt. > + @retval EFI_DEVICE_ERROR The timer period could not be changed > due to a device error. > + > +**/ > +EFI_STATUS > +EFIAPI > +TimerDriverRegisterHandler ( > + IN EFI_TIMER_ARCH_PROTOCOL *This, > + IN EFI_TIMER_NOTIFY NotifyFunction > + ) > +; > + > +/** > + > + This function adjusts the period of timer interrupts to the value > + specified by TimerPeriod. If the timer period is updated, then the > + selected timer period is stored in EFI_TIMER.TimerPeriod, and > + EFI_SUCCESS is returned. If the timer hardware is not programmable, t= hen > EFI_UNSUPPORTED is returned. > + If an error occurs while attempting to update the timer period, then > + the timer hardware will be put back in its state prior to this call, > + and EFI_DEVICE_ERROR is returned. If TimerPeriod is 0, then the > + timer interrupt is disabled. This is not the same as disabling the CP= U's > interrupts. > + Instead, it must either turn off the timer hardware, or it must > + adjust the interrupt controller so that a CPU interrupt is not > + generated when the timer interrupt fires. > + > + > + @param This The EFI_TIMER_ARCH_PROTOCOL instance. > + @param TimerPeriod The rate to program the timer interrupt in 100 = nS > units. If > + the timer hardware is not programmable, then > EFI_UNSUPPORTED is > + returned. If the timer is programmable, then t= he timer period > + will be rounded up to the nearest timer period = that is > supported > + by the timer hardware. If TimerPeriod is set t= o 0, then the > + timer interrupts will be disabled. > + > + @retval EFI_SUCCESS The timer period was changed. > + @retval EFI_UNSUPPORTED The platform cannot change the period= of > the timer interrupt. > + @retval EFI_DEVICE_ERROR The timer period could not be changed > due to a device error. > + > +**/ > +EFI_STATUS > +EFIAPI > +TimerDriverSetTimerPeriod ( > + IN EFI_TIMER_ARCH_PROTOCOL *This, > + IN UINT64 TimerPeriod > + ) > +; > + > +/** > + > + This function retrieves the period of timer interrupts in 100 ns > + units, returns that value in TimerPeriod, and returns EFI_SUCCESS. > + If TimerPeriod is NULL, then EFI_INVALID_PARAMETER is returned. If a > + TimerPeriod of 0 is returned, then the timer is currently disabled. > + > + > + @param This The EFI_TIMER_ARCH_PROTOCOL instance. > + @param TimerPeriod A pointer to the timer period to retrieve in 10= 0 ns > units. If > + 0 is returned, then the timer is currently disa= bled. > + > + @retval EFI_SUCCESS The timer period was returned in TimerP= eriod. > + @retval EFI_INVALID_PARAMETER TimerPeriod is NULL. > + > +**/ > +EFI_STATUS > +EFIAPI > +TimerDriverGetTimerPeriod ( > + IN EFI_TIMER_ARCH_PROTOCOL *This, > + OUT UINT64 *TimerPeriod > + ) > +; > + > +/** > + > + This function generates a soft timer interrupt. If the platform does > + not support soft timer interrupts, then EFI_UNSUPPORTED is returned. > Otherwise, EFI_SUCCESS is returned. > + If a handler has been registered through the > + EFI_TIMER_ARCH_PROTOCOL.RegisterHandler() > + service, then a soft timer interrupt will be generated. If the timer > + interrupt is enabled when this service is called, then the registered > + handler will be invoked. The registered handler should not be able to > + distinguish a hardware-generated timer interrupt from a software- > generated timer interrupt. > + > + > + @param This The EFI_TIMER_ARCH_PROTOCOL instance. > + > + @retval EFI_SUCCESS The soft timer interrupt was generated. > + @retval EFI_UNSUPPORTEDT The platform does not support the > generation of soft timer interrupts. > + > +**/ > +EFI_STATUS > +EFIAPI > +TimerDriverGenerateSoftInterrupt ( > + IN EFI_TIMER_ARCH_PROTOCOL *This > + ) > +; > + > +#endif > diff --git a/UefiCpuPkg/CpuTimerDxe/RiscV64/Timer.c > b/UefiCpuPkg/CpuTimerDxe/RiscV64/Timer.c > new file mode 100644 > index 000000000000..db153f715e60 > --- /dev/null > +++ b/UefiCpuPkg/CpuTimerDxe/RiscV64/Timer.c > @@ -0,0 +1,294 @@ > +/** @file > + RISC-V Timer Architectural Protocol > + > + Copyright (c) 2019, Hewlett Packard Enterprise Development LP. All > + rights reserved.
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#include > +#include > +#include "Timer.h" > + > +// > +// The handle onto which the Timer Architectural Protocol will be > +installed // STATIC EFI_HANDLE mTimerHandle =3D NULL; > + > +// > +// The Timer Architectural Protocol that this driver produces // > +EFI_TIMER_ARCH_PROTOCOL mTimer =3D { > + TimerDriverRegisterHandler, > + TimerDriverSetTimerPeriod, > + TimerDriverGetTimerPeriod, > + TimerDriverGenerateSoftInterrupt > +}; > + > +// > +// Pointer to the CPU Architectural Protocol instance // > +EFI_CPU_ARCH_PROTOCOL *mCpu; > + > +// > +// The notification function to call on every timer interrupt. > +// A bug in the compiler prevents us from initializing this here. > +// > +STATIC EFI_TIMER_NOTIFY mTimerNotifyFunction; > + > +// > +// The current period of the timer interrupt // STATIC UINT64 > +mTimerPeriod =3D 0; > + > +/** > + Timer Interrupt Handler. > + > + @param InterruptType The type of interrupt that occured > + @param SystemContext A pointer to the system context when the > interrupt occured > +**/ > +VOID > +EFIAPI > +TimerInterruptHandler ( > + IN EFI_EXCEPTION_TYPE InterruptType, > + IN EFI_SYSTEM_CONTEXT SystemContext > + ) > +{ > + EFI_TPL OriginalTPL; > + UINT64 RiscvTimer; > + > + OriginalTPL =3D gBS->RaiseTPL (TPL_HIGH_LEVEL); if > + (mTimerNotifyFunction !=3D NULL) { > + mTimerNotifyFunction (mTimerPeriod); } > + > + RiscVDisableTimerInterrupt (); // Disable SMode timer int > + RiscVClearPendingTimerInterrupt (); if (mTimerPeriod =3D=3D 0) { > + gBS->RestoreTPL (OriginalTPL); > + RiscVDisableTimerInterrupt (); // Disable SMode timer int > + return; > + } > + > + RiscvTimer =3D RiscVReadTimer (); > + SbiSetTimer (RiscvTimer +=3D mTimerPeriod); > + gBS->RestoreTPL (OriginalTPL); > + RiscVEnableTimerInterrupt (); // enable SMode timer int } > + > +/** > + > + This function registers the handler NotifyFunction so it is called > + every time the timer interrupt fires. It also passes the amount of > + time since the last handler call to the NotifyFunction. If > + NotifyFunction is NULL, then the handler is unregistered. If the > + handler is registered, then EFI_SUCCESS is returned. If the CPU does > + not support registering a timer interrupt handler, then > + EFI_UNSUPPORTED is returned. If an attempt is made to register a handl= er > when a handler is already registered, then EFI_ALREADY_STARTED is > returned. > + If an attempt is made to unregister a handler when a handler is not > + registered, then EFI_INVALID_PARAMETER is returned. If an error > + occurs attempting to register the NotifyFunction with the timer > + interrupt, then EFI_DEVICE_ERROR is returned. > + > + @param This The EFI_TIMER_ARCH_PROTOCOL instance. > + @param NotifyFunction The function to call when a timer interrupt fi= res. > This > + function executes at TPL_HIGH_LEVEL. The DXE = Core will > + register a handler for the timer interrupt, so= it can know > + how much time has passed. This information is= used to > + signal timer based events. NULL will unregist= er the handler. > + > + @retval EFI_SUCCESS The timer handler was registered= . > + @retval EFI_UNSUPPORTED The platform does not support ti= mer > interrupts. > + @retval EFI_ALREADY_STARTED NotifyFunction is not NULL, and = a > handler is already > + registered. > + @retval EFI_INVALID_PARAMETER NotifyFunction is NULL, and a > handler was not > + previously registered. > + @retval EFI_DEVICE_ERROR The timer handler could not be > registered. > + > +**/ > +EFI_STATUS > +EFIAPI > +TimerDriverRegisterHandler ( > + IN EFI_TIMER_ARCH_PROTOCOL *This, > + IN EFI_TIMER_NOTIFY NotifyFunction > + ) > +{ > + DEBUG ((DEBUG_INFO, "TimerDriverRegisterHandler(0x%lx) called\n", > +NotifyFunction)); > + mTimerNotifyFunction =3D NotifyFunction; > + return EFI_SUCCESS; > +} > + > +/** > + > + This function adjusts the period of timer interrupts to the value > + specified by TimerPeriod. If the timer period is updated, then the > + selected timer period is stored in EFI_TIMER.TimerPeriod, and > + EFI_SUCCESS is returned. If the timer hardware is not programmable, t= hen > EFI_UNSUPPORTED is returned. > + If an error occurs while attempting to update the timer period, then > + the timer hardware will be put back in its state prior to this call, > + and EFI_DEVICE_ERROR is returned. If TimerPeriod is 0, then the > + timer interrupt is disabled. This is not the same as disabling the CP= U's > interrupts. > + Instead, it must either turn off the timer hardware, or it must > + adjust the interrupt controller so that a CPU interrupt is not > + generated when the timer interrupt fires. > + > + > + @param This The EFI_TIMER_ARCH_PROTOCOL instance. > + @param TimerPeriod The rate to program the timer interrupt in 100 = nS > units. If > + the timer hardware is not programmable, then > EFI_UNSUPPORTED is > + returned. If the timer is programmable, then t= he timer period > + will be rounded up to the nearest timer period = that is > supported > + by the timer hardware. If TimerPeriod is set t= o 0, then the > + timer interrupts will be disabled. > + > + @retval EFI_SUCCESS The timer period was changed. > + @retval EFI_UNSUPPORTED The platform cannot change the period= of > the timer interrupt. > + @retval EFI_DEVICE_ERROR The timer period could not be changed > due to a device error. > + > +**/ > +EFI_STATUS > +EFIAPI > +TimerDriverSetTimerPeriod ( > + IN EFI_TIMER_ARCH_PROTOCOL *This, > + IN UINT64 TimerPeriod > + ) > +{ > + UINT64 RiscvTimer; > + > + DEBUG ((DEBUG_INFO, "TimerDriverSetTimerPeriod(0x%lx)\n", > + TimerPeriod)); > + > + if (TimerPeriod =3D=3D 0) { > + mTimerPeriod =3D 0; > + RiscVDisableTimerInterrupt (); // Disable SMode timer int > + return EFI_SUCCESS; > + } > + > + mTimerPeriod =3D TimerPeriod / 10; // convert unit from 100ns to 1us > + RiscvTimer =3D RiscVReadTimer (); > + SbiSetTimer (RiscvTimer + mTimerPeriod); > + > + mCpu->EnableInterrupt (mCpu); > + RiscVEnableTimerInterrupt (); // enable SMode timer int > + return EFI_SUCCESS; > +} > + > +/** > + > + This function retrieves the period of timer interrupts in 100 ns > + units, returns that value in TimerPeriod, and returns EFI_SUCCESS. > + If TimerPeriod is NULL, then EFI_INVALID_PARAMETER is returned. If a > + TimerPeriod of 0 is returned, then the timer is currently disabled. > + > + > + @param This The EFI_TIMER_ARCH_PROTOCOL instance. > + @param TimerPeriod A pointer to the timer period to retrieve in 10= 0 ns > units. If > + 0 is returned, then the timer is currently disa= bled. > + > + @retval EFI_SUCCESS The timer period was returned in TimerP= eriod. > + @retval EFI_INVALID_PARAMETER TimerPeriod is NULL. > + > +**/ > +EFI_STATUS > +EFIAPI > +TimerDriverGetTimerPeriod ( > + IN EFI_TIMER_ARCH_PROTOCOL *This, > + OUT UINT64 *TimerPeriod > + ) > +{ > + *TimerPeriod =3D mTimerPeriod; > + return EFI_SUCCESS; > +} > + > +/** > + > + This function generates a soft timer interrupt. If the platform does > + not support soft timer interrupts, then EFI_UNSUPPORTED is returned. > Otherwise, EFI_SUCCESS is returned. > + If a handler has been registered through the > + EFI_TIMER_ARCH_PROTOCOL.RegisterHandler() > + service, then a soft timer interrupt will be generated. If the timer > + interrupt is enabled when this service is called, then the registered > + handler will be invoked. The registered handler should not be able to > + distinguish a hardware-generated timer interrupt from a software- > generated timer interrupt. > + > + > + @param This The EFI_TIMER_ARCH_PROTOCOL instance. > + > + @retval EFI_SUCCESS The soft timer interrupt was generated. > + @retval EFI_UNSUPPORTEDT The platform does not support the > generation of soft timer interrupts. > + > +**/ > +EFI_STATUS > +EFIAPI > +TimerDriverGenerateSoftInterrupt ( > + IN EFI_TIMER_ARCH_PROTOCOL *This > + ) > +{ > + return EFI_SUCCESS; > +} > + > +/** > + Initialize the Timer Architectural Protocol driver > + > + @param ImageHandle ImageHandle of the loaded driver > + @param SystemTable Pointer to the System Table > + > + @retval EFI_SUCCESS Timer Architectural Protocol created > + @retval EFI_OUT_OF_RESOURCES Not enough resources available to > initialize driver. > + @retval EFI_DEVICE_ERROR A device error occured attempting to > initialize the driver. > + > +**/ > +EFI_STATUS > +EFIAPI > +TimerDriverInitialize ( > + IN EFI_HANDLE ImageHandle, > + IN EFI_SYSTEM_TABLE *SystemTable > + ) > +{ > + EFI_STATUS Status; > + > + // > + // Initialize the pointer to our notify function. > + // > + mTimerNotifyFunction =3D NULL; > + > + // > + // Make sure the Timer Architectural Protocol is not already > + installed in the system // ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, > + &gEfiTimerArchProtocolGuid); > + > + // > + // Find the CPU architectural protocol. > + // > + Status =3D gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID > + **)&mCpu); ASSERT_EFI_ERROR (Status); > + > + // > + // Force the timer to be disabled > + // > + Status =3D TimerDriverSetTimerPeriod (&mTimer, 0); ASSERT_EFI_ERROR > + (Status); > + > + // > + // Install interrupt handler for RISC-V Timer. > + // > + Status =3D mCpu->RegisterInterruptHandler (mCpu, > + EXCEPT_RISCV_TIMER_INT, TimerInterruptHandler); ASSERT_EFI_ERROR > + (Status); > + > + // > + // Force the timer to be enabled at its default period // Status =3D > + TimerDriverSetTimerPeriod (&mTimer, DEFAULT_TIMER_TICK_DURATION); > + ASSERT_EFI_ERROR (Status); > + > + // > + // Install the Timer Architectural Protocol onto a new handle > + // > + Status =3D gBS->InstallMultipleProtocolInterfaces ( > + &mTimerHandle, > + &gEfiTimerArchProtocolGuid, > + &mTimer, > + NULL > + ); > + ASSERT_EFI_ERROR (Status); > + return Status; > +} > diff --git a/UefiCpuPkg/CpuTimerDxe/CpuTimer.uni > b/UefiCpuPkg/CpuTimerDxe/CpuTimer.uni > new file mode 100644 > index 000000000000..76de1f3f352a > --- /dev/null > +++ b/UefiCpuPkg/CpuTimerDxe/CpuTimer.uni > @@ -0,0 +1,14 @@ > +// /** @file > +// > +// Timer Arch protocol strings. > +// > +// Copyright (c) 2016, Hewlett Packard Enterprise Development LP. All > +rights reserved.
// // SPDX-License-Identifier: BSD-2-Clause-Patent > +// // **/ > + > + > +#string STR_MODULE_ABSTRACT #language en-US "Timer driver th= at > provides Timer Arch protocol" > + > +#string STR_MODULE_DESCRIPTION #language en-US "Timer driver > that provides Timer Arch protocol." > diff --git a/UefiCpuPkg/CpuTimerDxe/CpuTimerExtra.uni > b/UefiCpuPkg/CpuTimerDxe/CpuTimerExtra.uni > new file mode 100644 > index 000000000000..ceb93a7ce82f > --- /dev/null > +++ b/UefiCpuPkg/CpuTimerDxe/CpuTimerExtra.uni > @@ -0,0 +1,12 @@ > +// /** @file > +// Timer Localized Strings and Content > +// > +// Copyright (c) 2016, Hewlett Packard Enterprise Development LP. All > +rights reserved.
// // SPDX-License-Identifier: BSD-2-Clause-Patent > +// // **/ > + > +#string STR_PROPERTIES_MODULE_NAME > +#language en-US > +"Timer DXE Driver" > -- > 2.38.0 >=20 >=20 >=20 >=20 >=20