From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by mx.groups.io with SMTP id smtpd.web11.7465.1675920104830280786 for ; Wed, 08 Feb 2023 21:21:44 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=feVXkLX+; spf=pass (domain: intel.com, ip: 134.134.136.126, mailfrom: ray.ni@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675920104; x=1707456104; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=loDNEF68RxjEPq22k1aSl5aRWRLGBWQ7z7SMETR0FeM=; b=feVXkLX+qu/McbZCDGbr7NzfOOtsJcPr2NGTpjqiCsAiSrwgn43XiI/q 37nrp77QetIFGJFVXkFK9p0X+fsqHyr83dOHXBA0olgjSmokeHYPKPwzX /r+lRV1Jy6PK5bx+ty01gqhaJsJzy4VRKRgtjsDmPEOyNPpiQBGALgM+T s0yxYozeA7q7lJjM3kEsgUZh0B1Mzyi900HiMuqwp5tB0EGEKsQiwxY+E Y5h9enBzsSwgwsVcOrpJeFz7B45KF4B4KQyRbxgqy4Iw97agIHizof9iU WWR46T/RQ3TrWBvEkd3cu5hojNbfj6C67hjeWCO9pOPDMpZgpKgAWhf5u w==; X-IronPort-AV: E=McAfee;i="6500,9779,10615"; a="313651384" X-IronPort-AV: E=Sophos;i="5.97,281,1669104000"; d="scan'208";a="313651384" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2023 21:21:43 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10615"; a="669458484" X-IronPort-AV: E=Sophos;i="5.97,281,1669104000"; d="scan'208";a="669458484" Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by fmsmga007.fm.intel.com with ESMTP; 08 Feb 2023 21:21:43 -0800 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Wed, 8 Feb 2023 21:21:43 -0800 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Wed, 8 Feb 2023 21:21:42 -0800 Received: from orsedg603.ED.cps.intel.com (10.7.248.4) by orsmsx610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16 via Frontend Transport; Wed, 8 Feb 2023 21:21:42 -0800 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (104.47.58.168) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.16; Wed, 8 Feb 2023 21:21:22 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Po8rbKDas4BqTMyC8yluT9BkMyO4loUXQEj6cMxtcdGwJ8CZ/3cNdrTfKWFyS0Qsyw6LmtI689q+I5vIUrfKLpYuVRy3Opvf4ayyeMzIhJcn4On1hiMriXQ5zdBvduNIW4JofvdapJOhZC4KDFkiz2LspMX9mRhaV2XON3nuIUM8OHdukaTst9ysvlBT4J80L7fmhutLc/p4PMwI/5oBvaK2O40n4kbdyNI3okQDxnL08KEb9HC6P477PlzmZ+V9sR7mNWuDlMwnQDm+rka0xQCOGy4XAWAS0d/essDAYMHkXVW4cHjiV6tCglY4mMFes0q06Sxoxo68T1LmSlBPxg== 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=X0c/Gb2vqCaBH63V0PI6YmX6mdVCgfRzNKZxD0qQO6g=; b=QJrZmt+rDoMzOPAGRTzaTLjGn7wZBOno8T5+j6OQU+Nz7jN5qgGOqsw5rGhKH32IrccpITDhTANh2mfOhglHLXJU/xZVTSlqmPKMol7dZJFDjWZWIEGcRjGY7/KmcWar3GWlM7GONTsrwBEKaNI5bO4FiK6cbw2R21SUvOK1tHtJVnwkGcuG/DS2X9nDu2WAzxPEm2TsgiMNloZFJaZqzPq04GsMP0Jhdc16/STihjIfE+Vy2p6PyH3hOhxwSQXH0YcOayfDDQUlvY9fSK58H1UndpWhAoV14f1cKomrBkjjKhLVeR1/c0VEnTHfbbfp9SB5zb2FxGq4wKM2KPrp6g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from MN6PR11MB8244.namprd11.prod.outlook.com (2603:10b6:208:470::14) by PH8PR11MB7141.namprd11.prod.outlook.com (2603:10b6:510:22f::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6064.25; Thu, 9 Feb 2023 05:21:19 +0000 Received: from MN6PR11MB8244.namprd11.prod.outlook.com ([fe80::f890:e4ec:e2d8:5831]) by MN6PR11MB8244.namprd11.prod.outlook.com ([fe80::f890:e4ec:e2d8:5831%3]) with mapi id 15.20.6086.017; Thu, 9 Feb 2023 05:21:19 +0000 From: "Ni, Ray" To: "devel@edk2.groups.io" , "sunilvl@ventanamicro.com" CC: "Dong, Eric" , "Kumar, Rahul R" , Daniel Schaefer , "Gerd Hoffmann" , Abner Chang Subject: Re: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V7 05/20] UefiCpuPkg: Add CpuTimerDxe module Thread-Topic: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V7 05/20] UefiCpuPkg: Add CpuTimerDxe module Thread-Index: AQHZM01ZvkFdsF7Z90SMhO7o0yNGPK7GJfww Date: Thu, 9 Feb 2023 05:21:19 +0000 Message-ID: References: <20230128191807.2080547-1-sunilvl@ventanamicro.com> <20230128191807.2080547-6-sunilvl@ventanamicro.com> In-Reply-To: <20230128191807.2080547-6-sunilvl@ventanamicro.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MN6PR11MB8244:EE_|PH8PR11MB7141:EE_ x-ms-office365-filtering-correlation-id: b9b3aa46-fc94-4bcd-1674-08db0a5d79e2 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: +xarSL5i6lrgIwE4gBszPDkP145GWZ+xF10/yyVGerKu0QEnG5OFfFAyKy6B6FmuY0zkXwUrnzVQ5LGTWepnHAphTFeViYd3JpLLGzKDwiphkPBYs//7PNbV9OvAkxS98OKFmAiqisbDJYmyCYNIAHM9HrCcX/5PyRHWIQbNKZ7Nz5uBmsu12QgaUTXJssXgU413Du+wpS2E7xcQtxCzbtT/q7vD71jjhECPC121CrOZ5hLQUuirMk+IEG9gqjJRrahAosKkFvZsoAQ47dovoivM7dqFq18cZcV7/XbMafiiIJHj0YVYoD1+Geb1H6rzCiBLbI3gy6DavjEIzGjLqjBhdGGLHgIzTir+3ydVdfixjNOr8P/ZTC6b1JhyhFKzb8q7QMGE9p5P5HrVqNafC7+WxybXsxZ6Ynr/B9fRCPMfIGrir37J1BXeekGHaexXqYfNaAyO0L2otgFkNutWOY0Xk+zgwVD+Fe1dOQRhlJhmknYFMM8p7mCdaD1XjEu2gU2EZ4iniqyCg0R+EzApBew3JXjL8brElP28NyWKLJ+g10fRYMRxxHCg+tI/juCwfAwgIwZilQuD38kYRHnqI00iB2tSBB0k5r/14kQWnforijz31g+Z6Eys+23e5ct92oWFIaaqSLDMWKq3MurhQSnhOetu+nFf2GwYJzFqFf03wZPiQT6WieQSGo0CrSVP8ASVj0w3aEDmoQf+3TAQSAlVYannAmCRw9jjvNSuh/Zv4peA/Xuu1Z0e6Zs8pIQfS9O1P6DArUVYk4aqUZurkg5A/hW+Z0qiNbqz7jg1wpc= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN6PR11MB8244.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(366004)(39860400002)(136003)(376002)(346002)(396003)(451199018)(30864003)(5660300002)(2906002)(66899018)(8936002)(86362001)(82960400001)(52536014)(122000001)(4326008)(38100700002)(41300700001)(66946007)(76116006)(66476007)(8676002)(66556008)(64756008)(66446008)(55016003)(966005)(7696005)(110136005)(71200400001)(26005)(54906003)(83380400001)(19627235002)(9686003)(38070700005)(316002)(186003)(53546011)(6506007)(478600001)(33656002)(579004)(44824005);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?yXvNywRdQrtpqCNuRgOBHtDvN4TtJqnu4N5urekIHT50c95bSfHD2RsX4xTH?= =?us-ascii?Q?89jYkrjf3La25Sqnmwg2XyUv/ZzVf3GnbM180ZGxLoQoE5XHdLd8KcZzs15y?= =?us-ascii?Q?nkL+0cgnchWDeL/3+AkJ/93dtQBUuUpZpT/A0i9o1oGw03cH0uverAFbRBBc?= =?us-ascii?Q?rd+aobQVPgNxQOb1joXIsA3H12DRBX57G7j/YbNipLfUt8PNWkeATHqfE2di?= =?us-ascii?Q?rOa4PWIoEg+uoKFmeHZ21wwKRABNNnW9ZzmwOSNdjgnBNOxh/yXnh5ITprMq?= =?us-ascii?Q?QGB09Jv6vKZHlAVZrrBhDm5X+f/tcAY130al8k5qsJu1FFqgVCKwjDw9vQFl?= =?us-ascii?Q?HChtPbRf6eoKMRyYyJk15WHEF99S7fm+v2PBdW7gWHrI0kQTCU9EwSQ8gH4L?= =?us-ascii?Q?e0DZMyeWs3XlDcXZEeFteBQ8pHwpOpCRFb4wAq+2r18YhuaWitBenQCKva3B?= =?us-ascii?Q?0wsXw/N8jPO/w03Mg6T5nGMX8nK5MHDbsyzQZHIzrSQhVlV1ribLCfy8jV1d?= =?us-ascii?Q?2exrrbEmpvgXhmEqFEQPKkMQG9USREgCMAld1Hc0c32mvkeFY/jHgeeQY0O/?= =?us-ascii?Q?5jm0/PNcbjugq8twManAuNpshgDkYIpGjPZ+l18qPArpnW9h+TwRpX6ha68d?= =?us-ascii?Q?la5Cz5+TNUotxdkV/xK/yN1VGXA/zxnZY5KOnEsr5ptRIzZGWnEckrqp+JTr?= =?us-ascii?Q?a2gQedYA6NuSIaA80V54Gq7qQsx7D50If4w3mP+6jArCPyiY6I1Of4g3mQlE?= =?us-ascii?Q?gvIqik14i3zQWqQa4FcYEhCLZCQxr0209jHkXL2pXMOQ7tCMU9XYMZfHBIWh?= =?us-ascii?Q?F5Ctx2PUTPl381zcJDisPf8Ubcy0n4eDjw9RYN8/gVC2gXFJnIB9c5rgONH2?= =?us-ascii?Q?9Pjfi/ZyXPHUufUJyjEI1AEnhpOe6tF7vvymNEIDKmNN+Xrq0G6a+DG1ePRg?= =?us-ascii?Q?zD5GgvNI5G+y/GZmfR014vObRWGoeDbvp5TcWZ+M5Q4bZDQKYNcdzup9hY00?= =?us-ascii?Q?Y0nfKB5n6PXfls1m2dv0NFtsFOMR0VDG9d8r+g1p0oV83hsjbVnxguOMXF4+?= =?us-ascii?Q?zvTGBB/k2sHVrJsRf2jobfNIJIjbRruuMaZ/5xxgNCFuTa6X3uiGb05P2WPj?= =?us-ascii?Q?1se0QXWIol4N0dchMDuMx5oCyn8JMZWu4naIdXqi90Y+OGyrUJyx0iqX4y1H?= =?us-ascii?Q?LIq3pGsBbOCj3IFusPNkQHh/sckRcd4f8jVzhCDoW3frOU9Ab+uzqjUtAz0Z?= =?us-ascii?Q?ZAmv4K1fM/MukdKIEcA4pd/R3IaL9cs+sP5Dk3J1JhRiiydzcpT3CJQVgN18?= =?us-ascii?Q?gKlU0sBdcaphD7+4tCsV12vQK9pI1F+G/Fw7JQbDAWudcVbGP/APvFE/GLVX?= =?us-ascii?Q?n2zO4Hlpdw1Dfus87W5Nq0uMwlmR1CpMQSoz7tSmu/Fk5R0sN3cqcQzd+Uc1?= =?us-ascii?Q?PAPNNBlYPyI8U+OynsBlEvr0GTVcOIgekc2U0LMamC6Yb+/CHKJqwhNqaPHb?= =?us-ascii?Q?+6X1bs4ZXnMJ0E8MFoB79qjLN10cqVwZXDNFUhB6ZggfkmjwzEl8qeBtvF3G?= =?us-ascii?Q?0WSQqvyYFKfD7Rm2s5XFEZEhAfKGykSVZvcDqDFi?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MN6PR11MB8244.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: b9b3aa46-fc94-4bcd-1674-08db0a5d79e2 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Feb 2023 05:21:19.5997 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: WYbF2Wl2bf3nCOkErD6Jnj20368WAQIjfQkTF6TNzAuZsWIv4eEtFYvYjGFKCmjp8j8wjmFmbJeCxa62JRXXcQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR11MB7141 Return-Path: ray.ni@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable I am curious if this module will support other arch as well? If it's RiscV = specific, there is no need for creating the RiscV64 folder. > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of Sunil V L > Sent: Sunday, January 29, 2023 3:18 AM > To: devel@edk2.groups.io > Cc: Dong, Eric ; Ni, Ray ; Kumar, > Rahul R ; Daniel Schaefer > ; Gerd Hoffmann ; Abner > Chang > Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V7 05/20] > UefiCpuPkg: Add CpuTimerDxe module >=20 > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4076 >=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 > Cc: Gerd Hoffmann > Signed-off-by: Sunil V L > Acked-by: Abner Chang > --- > 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 f9a46089d2c7..96f6770281fe 100644 > --- a/UefiCpuPkg/UefiCpuPkg.dsc > +++ b/UefiCpuPkg/UefiCpuPkg.dsc > @@ -195,5 +195,8 @@ [Components.IA32, Components.X64] > [Components.X64] >=20 > UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHan > dlerLibUnitTest.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 rig= hts > 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 th= e > 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 rig= hts > 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 spec= ified > + by TimerPeriod. If the timer period is updated, then the selected tim= er > + period is stored in EFI_TIMER.TimerPeriod, and EFI_SUCCESS is returned= . > If > + the timer hardware is not programmable, then EFI_UNSUPPORTED is > returned. > + If an error occurs while attempting to update the timer period, then t= he > + 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 CPU'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 spec= ified > + by TimerPeriod. If the timer period is updated, then the selected tim= er > + period is stored in EFI_TIMER.TimerPeriod, and EFI_SUCCESS is returned= . > If > + the timer hardware is not programmable, then EFI_UNSUPPORTED is > returned. > + If an error occurs while attempting to update the timer period, then t= he > + 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 CPU'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 n= ot > 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 i= nterrupt > 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-genera= ted > 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 rig= hts > reserved.
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#include > +#include > +#include "Timer.h" > + > +// > +// The handle onto which the Timer Architectural Protocol will be instal= led > +// > +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 eve= ry time > + the timer interrupt fires. It also passes the amount of time since th= e last > + handler call to the NotifyFunction. If NotifyFunction is NULL, then t= he > + handler is unregistered. If the handler is registered, then EFI_SUCCE= SS 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 > handler > + 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 spec= ified > + by TimerPeriod. If the timer period is updated, then the selected tim= er > + period is stored in EFI_TIMER.TimerPeriod, and EFI_SUCCESS is returned= . > If > + the timer hardware is not programmable, then EFI_UNSUPPORTED is > returned. > + If an error occurs while attempting to update the timer period, then t= he > + 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 CPU'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 n= ot > 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 i= nterrupt > 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-genera= ted > 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 ri= ghts > 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 ri= ghts > 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