From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web10.13678.1676033178941923131 for ; Fri, 10 Feb 2023 04:46:19 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=nB5MmKb6; spf=pass (domain: intel.com, ip: 134.134.136.24, 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=1676033178; x=1707569178; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=noyYg1Tp9SS2VgpHtLKMdi8gNQNGPtJp4kinxNTpzqE=; b=nB5MmKb60+fW6IRXf4+8JgbRDCpYmHzCcZlKIrNa910cbvjYvajR0624 H6roGpdyFMrjcpr6IhhM918hxZBsgdR0LEH+0MyxWeDD3F1luDDgD9RsA tdHakfy0HcyDWeJ7RVav7mWppq06M4qdrFWU9wnwuoxbP6AUTUdVkLscj rHSicamj2upnX7RuSwm+5doOZhgrgfd1pteaQQD7nmGplwdnRAg/PImCG jAisGK8IRcb5B/f6l7LbRKdUn7L5JMrjE85iPDZBM5zYtluI5dmiVKLMx lZlpzRXM6g/WHfxNviWzDWeoROVXtDZvBCldw+o2TmAJCVCB2D9xO28uX A==; X-IronPort-AV: E=McAfee;i="6500,9779,10616"; a="331715334" X-IronPort-AV: E=Sophos;i="5.97,287,1669104000"; d="scan'208";a="331715334" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Feb 2023 04:46:18 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10616"; a="698415662" X-IronPort-AV: E=Sophos;i="5.97,287,1669104000"; d="scan'208";a="698415662" Received: from orsmsx602.amr.corp.intel.com ([10.22.229.15]) by orsmga008.jf.intel.com with ESMTP; 10 Feb 2023 04:46:18 -0800 Received: from orsmsx611.amr.corp.intel.com (10.22.229.24) by ORSMSX602.amr.corp.intel.com (10.22.229.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Fri, 10 Feb 2023 04:46:18 -0800 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX611.amr.corp.intel.com (10.22.229.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Fri, 10 Feb 2023 04:46:17 -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; Fri, 10 Feb 2023 04:46:17 -0800 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (104.47.55.170) 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; Fri, 10 Feb 2023 04:46:17 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nONUkLOxXhhftfXidGDoBypaZLW4PAD/Oq6zwUvkgTEkBUX61Klz73KtYl0V7vWmo3dGGmjS0Rmivk7CTMf+gZXYRyP+uaCi+g9bTcT5b/v0GInYDFbvMdTLT7iTj3osL5PDMeENqy1GJ4nNhR1Buk/V5snyMCpd+u0Cr6Sdev64KZtYPEsEgb4FeK6UyLLNOSzabM6awzltjlmZJa1khqL2iVxas5kSldsua1PUaZHQcFcLO7559nAqtBP6/f2qNbvC3aX5o0UWkwKwoUHkEL8Ah0C0zwDvWsBUoeM3nk6cG0RdXk4b2EVLvnAecSHQjFhZr1LHbdsmmKkMj5ueQQ== 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=+Qgurd0PMIAPWqNTjz8Y2YHv4dnRVR00dwobgDL3d9o=; b=Hg9cuFlruyFr47ssS/q9WoWNBJ5bVhs8ohB5t+4tG0bGdUXGAK55eR9RcvHMABqrmGmQr1scRqpP+pPEYhjGOx+CLRnSHeZhAoAfmxj2eMPLKRcfgXMqffeK3CC5blo4/ZOs2KV608N6hb7U03BHBl33VFQHpeUF0KVMGdbn+w2cH3aTDU9LxUMQd4Nv039odvqURW1KJB7udthy7jhyQaIDxmDcU7Z7SSK4T2WU617mdFc8vwmrS4UYeH+mmX0MSQZnItr4xzzmsjgjph7eAJj8h26u08/Hoz38AVHfaAGILXkxhzMwa99hy4fL+XwrCSJboT6cL2SWr53qSx04AA== 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 CY8PR11MB7924.namprd11.prod.outlook.com (2603:10b6:930:7a::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6086.21; Fri, 10 Feb 2023 12:46:14 +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; Fri, 10 Feb 2023 12:46:14 +0000 From: "Ni, Ray" To: Sunil V L , "devel@edk2.groups.io" CC: "Dong, Eric" , "Kumar, Rahul R" , Daniel Schaefer , "Gerd Hoffmann" , Abner Chang , "Warkentin, Andrei" Subject: Re: [edk2-staging/RiscV64QemuVirt PATCH V8 07/19] UefiCpuPkg: Add CpuTimerDxeRiscV64 module Thread-Topic: [edk2-staging/RiscV64QemuVirt PATCH V8 07/19] UefiCpuPkg: Add CpuTimerDxeRiscV64 module Thread-Index: AQHZPUuThmfdNduaCU2NDrkjCyldlK7IIKmg Date: Fri, 10 Feb 2023 12:46:14 +0000 Message-ID: References: <20230210123041.1489506-1-sunilvl@ventanamicro.com> <20230210123041.1489506-8-sunilvl@ventanamicro.com> In-Reply-To: <20230210123041.1489506-8-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_|CY8PR11MB7924:EE_ x-ms-office365-filtering-correlation-id: 4776ee3f-2c83-475a-0602-08db0b64cbad x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: Zz7Rd4WlO92W6M1hm9QQLvhFs9XjV3rVCvlazlBtFAiTHL2y4rEDHfY0ulAc4ZuYwAmESIqBPXHmTtaht7PRBxcXFkzAgqgr3lDqK8hDEgNAYWE1L5psq/ecjg8YWvWXGZ9raAzgRvgku0FsHo9ojrW613mSNrt31t5qdiWENF4HDNc4wjcNO8A1FRolt+eFlxNeW9VYzxKUVN1m8Yjy8Ym4CFZcUmB/ZFaIyXYJJ4Y9j3V/JNKovpreL7VpvIXHFkORFo3k+1mHVw0gZEWcV4LQnbcfr3ttnntxNfuvZPYpeUtVyAIGlHP3XGSsiqwpuXzGbF0rfYRSwbw+wtz30IuE5vz9CRDMatcrd/OwQMsvR2J+LW/Rv4DynUSyZ/Tzw/xDN4jL+j035lTxzd3eoc/96Xbh6v10Rh50Y0g5gSiUNwIm0z2+kbwedYwa57+Md61ORjkJOBrRuPQARqATP5Owr+uk/fPiv1bH4HREFUCjO2jf9NLej9bUSK5rXEu+eSIACIO+ekHvtO9kbuagrPkWLxMGxuVsg6tOlPDzl10aUCRz5i/DBQKxGwt7B+7oYDfnuhrUwnfKQwk/s8b3ZV9dPs+mM9MybSRBL0KSYokB4cbRWnbl/wNzDwLkJLAGLbnjQ/WAjSs5eHva0EX4XQeDjFWX+johUq5uNT7RvVc2mMc5A6HjI5VEgfAGmet1zgnM8ixqoSJOEMw+u88bo1zBNi/svTjct0hKpEwywC4ht8WffZwMKMYpEsYXbgd21jhkDaijyCsRdRdPMXwt9Zfn8aSVPSN14q0rvTVFtcY= 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)(39860400002)(396003)(346002)(376002)(136003)(366004)(451199018)(83380400001)(66446008)(66476007)(66556008)(66946007)(76116006)(19627235002)(316002)(54906003)(8676002)(52536014)(5660300002)(8936002)(4326008)(110136005)(41300700001)(107886003)(64756008)(478600001)(6506007)(9686003)(186003)(26005)(53546011)(966005)(71200400001)(7696005)(38070700005)(33656002)(55016003)(86362001)(2906002)(30864003)(38100700002)(82960400001)(122000001)(579004)(44824005)(14943795004);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?E4MSQsbkpywOOQselr5Zbef0ZmztqWaNt7RBNOZmUPOoxAilLpXgS+pgckuu?= =?us-ascii?Q?+4vB7Dfjjsbgw3oQYq9KFsDxYGYzBEcrO7IDnAIgsUbSIZMAm35e9GXvSAFq?= =?us-ascii?Q?QlYVykRiis8jfxCRc5jhGtrPudXrI+6oVzQhZ5scNiq0gtfUQ6pb1Wdmqyk5?= =?us-ascii?Q?FlaZP8G/u+B0Xg+8WghQv9/XkmY1fC62pfQJLR6nYh7+D7vTVr3DAsAAjD7G?= =?us-ascii?Q?OD8WSBjjApQyyQDHDjFSrnJYRaYazME/G/5O5mU3tILjrCBXoaLc4GXdHaKy?= =?us-ascii?Q?GAUIR2t4Dp7B6j9BCa1Mw2FwLkvCeAielb8HhjpJAfy7B+2Am+AMMdSFWAJZ?= =?us-ascii?Q?pQoSZmA0TSbUJXF6nhfaxeuK26DxjzdEmm22Yd8ORkIloGE038cF566+D43q?= =?us-ascii?Q?Z1YflkycHoDMmic3gFtxv9So1mgeT88hqz/BKWO83ItU/foxknOhSQijNTvM?= =?us-ascii?Q?k8+aYFNoU6HVQnr6k4tLVmGGntZNszKfsUzoFUNPMKZ5lEJC9tss4kyWIOX7?= =?us-ascii?Q?A+NbERYBsILrKjafRBuM4DyHTQmuy2pWjnFeyS8//RfK/aHSY6CRx5SS7SFm?= =?us-ascii?Q?8HiYJlinjTw9j7OSNlsGuLzZ+HYPE851oe6Q900aJvB2NxO2TCCH5vj8kGH2?= =?us-ascii?Q?LFevO8aJmI/yVq/TGOaMFYyHdbIQszo4H0CMtE3jncDFZ5n8nFNKDCSWbt4N?= =?us-ascii?Q?C2A625KfkglgkgzOpka119+FmWybD5qerAjZFzD1IBZeJMNT7i+FtC4B8u5Z?= =?us-ascii?Q?qUPD5MKlms6mNkLHbRXZGjj3cJ4sz+EumRIa+CRpCzgd7MMsHoz6XBCmlAHk?= =?us-ascii?Q?RHCA8HaNj2m3b+Dn8nNUaKzRootFMD/bwxM+VUnFPvGQlVTBrUbaC0Zr/YS7?= =?us-ascii?Q?TzXa9CoXTuT9sHGaan96xhw0nQzgF3LEUqLYaFpHoc9IBe1xKJa4HLE1Bqt8?= =?us-ascii?Q?7eNoKjcz19EtValSwRPXHSOtfDsYUh0umMfzTZeW6PcaQ3N2hu51bQornq/1?= =?us-ascii?Q?9LBpmQeS+QOf3mGNXP9AE9MsJgjb2FI5h2Tnp6ejTxifwSPf0hjLVku1KqH0?= =?us-ascii?Q?5vr+nITLYShugfJCBlcW6tM1u/p6aaFh1QwlxWiI5CrYqmbvptRdXjPpAyUU?= =?us-ascii?Q?hbqUgwmfRkwhBkVDRDfPpwZ57DsdGDM+yLymXQBYkLutldEYEz5Eb9luQ23S?= =?us-ascii?Q?GhDGMVoRL5eDy1RSvLK6KqB/S9cssce0dcDxbv/0q8Lnb0Er/T0bsonAdv2k?= =?us-ascii?Q?A8kMxqVgmWpiMe+zub7aetEJnSfpMcgFHzjheOGMz13AtHSCWm55gK/8SbZO?= =?us-ascii?Q?mZ+AvBKP1av62PMr5yTebKWusQChnU0GRcs7a+a2tmfNYjoG2Af+CNlN+HwX?= =?us-ascii?Q?c20OQl8z8KiVcOLlkunZ2VliQO/ONCIjAO2zZBiOK9O/l1LslGTBqDcoGoyq?= =?us-ascii?Q?DQCH1gCdCoT+ucr1HiDTKR3rCH3rOARVdJNYlgQxnPnenuCPVoXXEuKeAsN1?= =?us-ascii?Q?d6e8T7wialAQbz1e9kkBUjN/fnBuTiEg9BZisC4kW79AjHSsZyxJR0t2bhUf?= =?us-ascii?Q?Ju8QUfpKN7XRz5bUDrORU6fgOT9AeCPr8zSt1xWQ?= 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: 4776ee3f-2c83-475a-0602-08db0b64cbad X-MS-Exchange-CrossTenant-originalarrivaltime: 10 Feb 2023 12:46:14.4181 (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: QdCuFba8F8GvlBcAr0qgaTv1DtMcrLv/ODWn29kXMyNueLM7ldZhmGFivBN+G7Yst6f8nFRcAKWSQXMwhXk2dw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR11MB7924 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 Acked-by: Ray Ni > -----Original Message----- > From: Sunil V L > Sent: Friday, February 10, 2023 8:30 PM > To: devel@edk2.groups.io > Cc: Dong, Eric ; Ni, Ray ; Kumar, > Rahul R ; Daniel Schaefer ; > Gerd Hoffmann ; Abner Chang ; > Warkentin, Andrei > Subject: [edk2-staging/RiscV64QemuVirt PATCH V8 07/19] UefiCpuPkg: Add > CpuTimerDxeRiscV64 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 > Reviewed-by: Andrei Warkentin > --- > UefiCpuPkg/UefiCpuPkg.dsc | 1 + > UefiCpuPkg/CpuTimerDxeRiscV64/CpuTimerDxeRiscV64.inf | 51 ++++ > UefiCpuPkg/CpuTimerDxeRiscV64/Timer.h | 177 ++++++++++++ > UefiCpuPkg/CpuTimerDxeRiscV64/Timer.c | 294 > ++++++++++++++++++++ > UefiCpuPkg/CpuTimerDxeRiscV64/CpuTimer.uni | 14 + > UefiCpuPkg/CpuTimerDxeRiscV64/CpuTimerExtra.uni | 12 + > 6 files changed, 549 insertions(+) >=20 > diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc > index c511403842b8..aba5ae927586 100644 > --- a/UefiCpuPkg/UefiCpuPkg.dsc > +++ b/UefiCpuPkg/UefiCpuPkg.dsc > @@ -198,6 +198,7 @@ [Components.X64] > [Components.RISCV64] >=20 > UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/BaseRiscV64CpuExce > ptionHandlerLib.inf > UefiCpuPkg/Library/BaseRiscV64CpuTimerLib/BaseRiscV64CpuTimerLib.inf > + UefiCpuPkg/CpuTimerDxeRiscV64/CpuTimerDxeRiscV64.inf >=20 > [BuildOptions] > *_*_*_CC_FLAGS =3D -D DISABLE_NEW_DEPRECATED_INTERFACES > diff --git a/UefiCpuPkg/CpuTimerDxeRiscV64/CpuTimerDxeRiscV64.inf > b/UefiCpuPkg/CpuTimerDxeRiscV64/CpuTimerDxeRiscV64.inf > new file mode 100644 > index 000000000000..2c1f9f10e165 > --- /dev/null > +++ b/UefiCpuPkg/CpuTimerDxeRiscV64/CpuTimerDxeRiscV64.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 RiscVTimerDxe > + MODULE_UNI_FILE =3D RiscVTimer.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] > + Timer.h > + Timer.c > + > +[Protocols] > + gEfiCpuArchProtocolGuid ## CONSUMES > + gEfiTimerArchProtocolGuid ## PRODUCES > + > +[Depex] > + gEfiCpuArchProtocolGuid > + > +[UserExtensions.TianoCore."ExtraFiles"] > + RiscVTimerExtra.uni > diff --git a/UefiCpuPkg/CpuTimerDxeRiscV64/Timer.h > b/UefiCpuPkg/CpuTimerDxeRiscV64/Timer.h > new file mode 100644 > index 000000000000..586eb0cfadb4 > --- /dev/null > +++ b/UefiCpuPkg/CpuTimerDxeRiscV64/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 in= itialize > 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 return= ed. > + 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 int= errupt > + 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 return= ed. > + 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 int= errupt > + 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 TimerP= eriod > + 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/CpuTimerDxeRiscV64/Timer.c > b/UefiCpuPkg/CpuTimerDxeRiscV64/Timer.c > new file mode 100644 > index 000000000000..db153f715e60 > --- /dev/null > +++ b/UefiCpuPkg/CpuTimerDxeRiscV64/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 inter= rupt > 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 h= andler, > + 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 retu= rned. > + If an attempt is made to unregister a handler when a handler is not re= gistered, > + 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 ha= ndler > was not > + previously registered. > + @retval EFI_DEVICE_ERROR The timer handler could not be r= egistered. > + > +**/ > +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 return= ed. > + 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 int= errupt > + 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 TimerP= eriod > + 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 in= itialize > 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_IN= T, > 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/CpuTimerDxeRiscV64/CpuTimer.uni > b/UefiCpuPkg/CpuTimerDxeRiscV64/CpuTimer.uni > new file mode 100644 > index 000000000000..76de1f3f352a > --- /dev/null > +++ b/UefiCpuPkg/CpuTimerDxeRiscV64/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 th= at > provides Timer Arch protocol." > diff --git a/UefiCpuPkg/CpuTimerDxeRiscV64/CpuTimerExtra.uni > b/UefiCpuPkg/CpuTimerDxeRiscV64/CpuTimerExtra.uni > new file mode 100644 > index 000000000000..ceb93a7ce82f > --- /dev/null > +++ b/UefiCpuPkg/CpuTimerDxeRiscV64/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.34.1