From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mx.groups.io with SMTP id smtpd.web11.7609.1675921070584382414 for ; Wed, 08 Feb 2023 21:37:50 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=K2YsXU3L; spf=pass (domain: intel.com, ip: 192.55.52.115, 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=1675921070; x=1707457070; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=+ZKJ3FRMtI4tHh1EiNLIrBihi5ccEWJ+LCDnH+t8NYs=; b=K2YsXU3Lds9bNfB+xUt30Pv2qjM/U/XtGNa/fqjKXzwHspMVBmO23v7P Eg0r2MhtplElD0p6x6ITvMwDgj5a8IljhGeKfqetXtHAuGH27W9aMOyV+ oHAH4f2abPqpV/1WqAOMxsRYe5pZgBHs0+KxUjouANA+tJvRNMofBFmpp ClH+cRpdmLikRtRbyJdAaTOnT37T0c97EEHLlPdv8/Beg8qti93nOxJth WmvMwpV8lU2qIoIOmiZjWrNuDhYxTPmKY/0yjDYSixewBYqSIdVUwDY63 5ApeY1vQec3sEmuUx2qy3reiwQTRF35LIEV66WI8rd3TDWQNVro7oPE+l Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10615"; a="330043790" X-IronPort-AV: E=Sophos;i="5.97,281,1669104000"; d="scan'208";a="330043790" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2023 21:37:33 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10615"; a="996405409" X-IronPort-AV: E=Sophos;i="5.97,281,1669104000"; d="scan'208";a="996405409" Received: from fmsmsx602.amr.corp.intel.com ([10.18.126.82]) by fmsmga005.fm.intel.com with ESMTP; 08 Feb 2023 21:37:33 -0800 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx602.amr.corp.intel.com (10.18.126.82) 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:37:32 -0800 Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) by fmsmsx610.amr.corp.intel.com (10.18.126.90) 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:37:32 -0800 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (104.47.55.174) by edgegateway.intel.com (192.55.55.68) 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:37:32 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VhpebqyCiPJ2ESii8xlUjkPNO5J0CtxRwdBEVBfjIX9qNtYhftKq1gqTq7ydEJd7pzkKfJITQ+i2b6Uz18HAQ5dJX2nrzhK+cmBWsRVxV81DNVAuaP8TCa+N4VtXxDXJHfend2FKVubQQJI9ESkSSJhWWJx4DSHuDiYYlar9qZIkfFd1MhkLcudm3DEpVUUjhGP1sAZ7zKgEYEoRTIBCPu5vJxAWd8s6eh7B8CBTy1z1/nF6+SkRTqTw1M8HxjWzhVp9WAoBY1Ts/eXf/anTmdfkzvf3m65gtdBnobTh/vabZd86zekL4GHQ5SU0C+ABmO6+j2MQ7+zQPqqdU0caJg== 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=+vUyU5uCW0usmujrOBTq0OLYVXvQAXbzu5mC/PZCeeI=; b=C0BTfnvOWHLuJ9QIfYXS+1xsmLGdCfTgGB2MQHKagPPR804hJC6pSEDmdu+dfeeyuWqTIDa+8XRZIQU0r5D/5ToXRUHMjSvw86qxfY7UU41bZ4gL2GbcadSeRt9VeCRpDlhNQvLV5gmDB+6uJdDWtGVptntMFa5uYFLWTUKFhs6GdQAOl/aN2HS7GzLmEXml3LHyEVFT+xO+ZpPVx9mzIGzW2+SE/dk9udjXCPKNMmNwgWfCza1K5aeP/FzJGud2Ahy2ngO0ijrvP4p8d/MZRL3EXMfOV+5mSsJW55VuY/Ft3NN9wFPb2ECNqofdif9lNnPu9JosA1XgbvdZCSCmhg== 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 SJ1PR11MB6204.namprd11.prod.outlook.com (2603:10b6:a03:459::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6086.17; Thu, 9 Feb 2023 05:37:29 +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:37:29 +0000 From: "Ni, Ray" To: Sunil V L , "devel@edk2.groups.io" CC: "Dong, Eric" , "Kumar, Rahul R" , Daniel Schaefer , "Abner Chang" , Gerd Hoffmann Subject: Re: [edk2-staging/RiscV64QemuVirt PATCH V7 08/20] UefiCpuPkg/CpuTimerLib: Add RISC-V instance Thread-Topic: [edk2-staging/RiscV64QemuVirt PATCH V7 08/20] UefiCpuPkg/CpuTimerLib: Add RISC-V instance Thread-Index: AQHZM01Yur9mPHn2qUeRr8gq5BXXn67GKnhA Date: Thu, 9 Feb 2023 05:37:29 +0000 Message-ID: References: <20230128191807.2080547-1-sunilvl@ventanamicro.com> <20230128191807.2080547-9-sunilvl@ventanamicro.com> In-Reply-To: <20230128191807.2080547-9-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_|SJ1PR11MB6204:EE_ x-ms-office365-filtering-correlation-id: 0ce022bb-0cf6-4382-8662-08db0a5fbc05 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 3ItKY0xU33RYI8UHvoSVnWPc6SGGGDhrocHXRqYyTCEp9xU4JRqfTmBxMeC/PDknW5YcNwQlcFsmxzNVUMl+2CXFsnuYiX3UkDz1MnunKScwxeTBHNN0J6YAwGGOKRtofB9WdLPvKt5HmEti1gzffTGFt37KvpBuRnmVnYS42OnzxuPrrKHZk+Or6YS9FPyv8oULNwLfim7bqtdRnWftV+V0w3xPeqCGowJsVBmY1eTuVdz72ARn+gqvgPPNGcC6ar0NprGKStfsyXqSc4USVgv9nuhRziOGtEiyaPXTPv7lFbkWCXobmk/EzcsIuiOy1ihx33RVfIE6aoMw1UQvz8mjdVEQf5QzWZSkCK0lmes7HXb8bj/bmIj9lvOSIZ0geQnam2Ns4wJMx5Pk8eCELmPjDLj2rgwTcQfQsPcmNra84+JC224QWLe1lZDfXG+FX4xHSomrJmwJoT6OhCOYp6bHkEP++6WWTWg0iqicgxbkBdFe9kpHlH2s8jUeWdUkjOUcW8Epleje4gmPTy6/Cn5OaPrlGi/cMGRtDZnOKuMafWTTy2hC09R5vLmHt9l9YynEcOkbQUKyNUdFiBHE//xQorJJ9XeXh6LF3qw1W8FQOuM7Rjyc9mtzPhDrBGkdJAUaSqm3ydsJOXfBPM3eebSj84xFqEaGsuIGo1V1yL/+erapBgMDlhtkyTJkeBfPvtElqfLmHzPvqHeRnHhpb6rh/yaEzhUwUi/FlI/YGYE= 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)(376002)(346002)(366004)(136003)(396003)(451199018)(2906002)(86362001)(38100700002)(82960400001)(122000001)(966005)(71200400001)(7696005)(26005)(186003)(76116006)(9686003)(6506007)(53546011)(110136005)(33656002)(38070700005)(55016003)(66556008)(64756008)(54906003)(83380400001)(66476007)(316002)(66446008)(66946007)(19627235002)(4326008)(478600001)(41300700001)(8676002)(52536014)(5660300002)(8936002);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?vB/s8leIWn/JDU/c/eRHHSR+wen8gH3uY5f/pNwKJNjDAEx/ENBd6Mb4k9vb?= =?us-ascii?Q?0USaTU0uLHL4Xmjv9GuVlhZH7S/3Df3GavNTEOXFYwxp4L21LJC7mkgSMhM9?= =?us-ascii?Q?DUlDQqvi+M7n8a4kMiEkIPeO8EQWHAkEqTa9B94O56MMhL3V+68foVRgL0V+?= =?us-ascii?Q?wkRlHSurE/RPcCWm95KvWrI99UpJItNC5v26jd8hcxukpCg3Jp/cvMBD4L8a?= =?us-ascii?Q?yTBSkGes26mxPOm1URgU66KESw/LBwu3c2yrysS1btlxzVi5a1H1+be18Wkw?= =?us-ascii?Q?DeoyuCSAgQPRcjEGL5KmaRCH8bYICb2cKBQEpYPlMxo5bl0C9RaMOfZ/7llb?= =?us-ascii?Q?YgVV2xhX6iJpnmMv/X4t1VAV1UF6xmz1gkX0qRjgQl8//eKDKUODo0YDJhnW?= =?us-ascii?Q?U1UMrnCZfsXzjGh9XNJkbpv3zXNzjouD5th8aUvtybEwpoU5dvtqqFILbC7t?= =?us-ascii?Q?hN1dbA/ETixjhL45WgEVkB9OYDF6oCQn4x1gQ4KeMeQPZ8FgxTtW1PGtcrhC?= =?us-ascii?Q?CDGpF+PTJQfQuHvEIbIFOGRj76xwzUZxSJRrkfpndoj1WpK/wv2KgR+hHlMa?= =?us-ascii?Q?/bZelfOc7TfhEl2lcoZUV3bWh6j4YR532G7OIUO78M7iVpJL1xieYTC8FTLt?= =?us-ascii?Q?+iCxYweUJ5YnPff4wGXJAy1Okduw0BT9R88fyVjFALgneATi51BoItk2yRpm?= =?us-ascii?Q?31MctIjU+y5DKIblcl/QYADuLrIuZGIPbHSD9di2vSww4JhwAi7J+NQTZ2Gn?= =?us-ascii?Q?01dewpBlyuBi7aQOeRFmuN3fGkjUcgIqP2zyG5HQVi72gLvpwLSzRLJeNYnz?= =?us-ascii?Q?ufmj9Z+5ElscICKIT0rWqeN2BksFbtj8CrRI49AP+WQ2+dREUWg53cCLybqm?= =?us-ascii?Q?UCVGjvDB2Q3016CEmc1gB6nVNR3rbzEuZx33mLf5PQ2h8cK5AekRHDviRAIT?= =?us-ascii?Q?IOIfO7AGQcvyAMeYQp9Oocm7dRxj/JB689RNzhs1ddIWebjB+SrLrAWJ4xiz?= =?us-ascii?Q?egF5wNg/QZQ1OCgR6dGUJLceKfAmuigTvl+r4ROabIk0xc8mqK89lgJW4aJz?= =?us-ascii?Q?iX/CZ2CqzqpKe1B3RGDMPuBhNinRFkE3VKdBTgTYVK/2qukE4HLdeH5m2T47?= =?us-ascii?Q?e9Jxiobfdfv7MuTKy/7JzjfiksMdxMNquZwvjLmspI5FycrHRCrQkIMk0m3W?= =?us-ascii?Q?5vxn7juTYX3rXhbSilWjdh4vXZNz5FVQ6pDlNQHhor8IcWU9ZSGTFzgtABmV?= =?us-ascii?Q?kvvtz4l+AvtTBQJRYXJouzIUetFBXbGwtVk+0r45Z2ZLpV0KRubioBvCjKrf?= =?us-ascii?Q?BvjcKOkHIC2QvgRNN39SmMWqW3duvMBtfbx/h28ElBWo7HCX9wPkk7fYuvBl?= =?us-ascii?Q?R/NPYuzX0YiV2yHrlXr4pNAjSEXDLusUhg83ww64u6WAoXQTD5C/esIcAbp0?= =?us-ascii?Q?4N3DZC0606TvPDeI/zyLVUN6OIkbyf1eBGy4oif+6IqkWT/9D2M8xBkrYdOB?= =?us-ascii?Q?+UxA9jpL7vT8U/fBezdBNnxw72/fJ/d41b1gPhl3R16BPtkx6VBM576m6dpo?= =?us-ascii?Q?8bE048E8Z0SZ3uMRkclW2Sc8K0qygAKoxS43zylt?= 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: 0ce022bb-0cf6-4382-8662-08db0a5fbc05 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Feb 2023 05:37:29.5081 (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: nhR12rwVzznF57kMj/nE3rVm83hDDe/1W2HG2sbKkAVKKYCjLGL7ayQqYrVcsA3WwIeVN7LHwYFxd1Ofi0BmiA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR11MB6204 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 Can you rename CpuTimerLib to RiscVTimerLib or something else that's more s= pecific? RiscV64 sub-directory might not be necessary. > -----Original Message----- > From: 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 > ; Abner Chang ; Gerd > Hoffmann > Subject: [edk2-staging/RiscV64QemuVirt PATCH V7 08/20] > UefiCpuPkg/CpuTimerLib: Add RISC-V instance >=20 > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4076 >=20 > This is mostly copied from > edk2-platforms/Silicon/RISC-V/ProcessorPkg/Library/RiscVTimerLib >=20 > Cc: Eric Dong > Cc: Ray Ni > Cc: Rahul Kumar > Cc: Daniel Schaefer > Cc: Abner Chang > Cc: Gerd Hoffmann > Signed-off-by: Sunil V L > Acked-by: Abner Chang > --- > UefiCpuPkg/UefiCpuPkg.dsc | 1 + > UefiCpuPkg/Library/CpuTimerLib/BaseRiscV64CpuTimerLib.inf | 32 ++++ > UefiCpuPkg/Library/CpuTimerLib/RiscV64/CpuTimerLib.c | 199 > ++++++++++++++++++++ > 3 files changed, 232 insertions(+) >=20 > diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc > index 8f2be6cd1b05..2df02bf75a35 100644 > --- a/UefiCpuPkg/UefiCpuPkg.dsc > +++ b/UefiCpuPkg/UefiCpuPkg.dsc > @@ -199,6 +199,7 @@ [Components.RISCV64] > UefiCpuPkg/CpuTimerDxe/CpuTimerDxe.inf >=20 > UefiCpuPkg/Library/CpuExceptionHandlerLib/BaseRiscV64CpuExceptionHan > dlerLib.inf > UefiCpuPkg/CpuDxe/CpuDxeRiscV64.inf > + UefiCpuPkg/Library/CpuTimerLib/BaseRiscV64CpuTimerLib.inf >=20 > [BuildOptions] > *_*_*_CC_FLAGS =3D -D DISABLE_NEW_DEPRECATED_INTERFACES > diff --git a/UefiCpuPkg/Library/CpuTimerLib/BaseRiscV64CpuTimerLib.inf > b/UefiCpuPkg/Library/CpuTimerLib/BaseRiscV64CpuTimerLib.inf > new file mode 100644 > index 000000000000..c920e8e098b5 > --- /dev/null > +++ b/UefiCpuPkg/Library/CpuTimerLib/BaseRiscV64CpuTimerLib.inf > @@ -0,0 +1,32 @@ > +## @file > +# RISC-V Base CPU Timer Library Instance > +# > +# Copyright (c) 2016 - 2019, Hewlett Packard Enterprise Development LP.= All > rights reserved.
> +# Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved. > +# > +# SPDX-License-Identifier: BSD-2-Clause-Patent > +# > +## > + > +[Defines] > + INF_VERSION =3D 0x0001001B > + BASE_NAME =3D BaseRisV64CpuTimerLib > + FILE_GUID =3D B635A600-EA24-4199-88E8-5761EEA96A5= 1 > + MODULE_TYPE =3D BASE > + VERSION_STRING =3D 1.0 > + LIBRARY_CLASS =3D TimerLib > + > +[Sources] > + RiscV64/CpuTimerLib.c > + > +[Packages] > + MdePkg/MdePkg.dec > + UefiCpuPkg/UefiCpuPkg.dec > + > +[LibraryClasses] > + BaseLib > + PcdLib > + DebugLib > + > +[Pcd] > + gUefiCpuPkgTokenSpaceGuid.PcdCpuCoreCrystalClockFrequency ## > CONSUMES > diff --git a/UefiCpuPkg/Library/CpuTimerLib/RiscV64/CpuTimerLib.c > b/UefiCpuPkg/Library/CpuTimerLib/RiscV64/CpuTimerLib.c > new file mode 100644 > index 000000000000..9c8efc0f3530 > --- /dev/null > +++ b/UefiCpuPkg/Library/CpuTimerLib/RiscV64/CpuTimerLib.c > @@ -0,0 +1,199 @@ > +/** @file > + RISC-V instance of Timer Library. > + > + Copyright (c) 2016 - 2022, Hewlett Packard Enterprise Development LP. = All > rights reserved.
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#include > +#include > +#include > +#include > +#include > + > +/** > + Stalls the CPU for at least the given number of ticks. > + > + Stalls the CPU for at least the given number of ticks. It's invoked by > + MicroSecondDelay() and NanoSecondDelay(). > + > + @param Delay A period of time to delay in ticks. > + > +**/ > +VOID > +InternalRiscVTimerDelay ( > + IN UINT32 Delay > + ) > +{ > + UINT32 Ticks; > + UINT32 Times; > + > + Times =3D Delay >> (RISCV_TIMER_COMPARE_BITS - 2); > + Delay &=3D ((1 << (RISCV_TIMER_COMPARE_BITS - 2)) - 1); > + do { > + // > + // The target timer count is calculated here > + // > + Ticks =3D RiscVReadTimer () + Delay; > + Delay =3D 1 << (RISCV_TIMER_COMPARE_BITS - 2); > + while (((Ticks - RiscVReadTimer ()) & (1 << (RISCV_TIMER_COMPARE_BIT= S > - 1))) =3D=3D 0) { > + CpuPause (); > + } > + } while (Times-- > 0); > +} > + > +/** > + Stalls the CPU for at least the given number of microseconds. > + > + Stalls the CPU for the number of microseconds specified by MicroSecond= s. > + > + @param MicroSeconds The minimum number of microseconds to delay. > + > + @return MicroSeconds > + > +**/ > +UINTN > +EFIAPI > +MicroSecondDelay ( > + IN UINTN MicroSeconds > + ) > +{ > + InternalRiscVTimerDelay ( > + (UINT32)DivU64x32 ( > + MultU64x32 ( > + MicroSeconds, > + PcdGet64 (PcdCpuCoreCrystalClockFrequency) > + ), > + 1000000u > + ) > + ); > + return MicroSeconds; > +} > + > +/** > + Stalls the CPU for at least the given number of nanoseconds. > + > + Stalls the CPU for the number of nanoseconds specified by NanoSeconds. > + > + @param NanoSeconds The minimum number of nanoseconds to delay. > + > + @return NanoSeconds > + > +**/ > +UINTN > +EFIAPI > +NanoSecondDelay ( > + IN UINTN NanoSeconds > + ) > +{ > + InternalRiscVTimerDelay ( > + (UINT32)DivU64x32 ( > + MultU64x32 ( > + NanoSeconds, > + PcdGet64 (PcdCpuCoreCrystalClockFrequency) > + ), > + 1000000000u > + ) > + ); > + return NanoSeconds; > +} > + > +/** > + Retrieves the current value of a 64-bit free running performance count= er. > + > + Retrieves the current value of a 64-bit free running performance count= er. > The > + counter can either count up by 1 or count down by 1. If the physical > + performance counter counts by a larger increment, then the counter > values > + must be translated. The properties of the counter can be retrieved fro= m > + GetPerformanceCounterProperties(). > + > + @return The current value of the free running performance counter. > + > +**/ > +UINT64 > +EFIAPI > +GetPerformanceCounter ( > + VOID > + ) > +{ > + return (UINT64)RiscVReadTimer (); > +} > + > +/**return > + Retrieves the 64-bit frequency in Hz and the range of performance coun= ter > + values. > + > + If StartValue is not NULL, then the value that the performance counter > starts > + with immediately after is it rolls over is returned in StartValue. If > + EndValue is not NULL, then the value that the performance counter end > with > + immediately before it rolls over is returned in EndValue. The 64-bit > + frequency of the performance counter in Hz is always returned. If > StartValue > + is less than EndValue, then the performance counter counts up. If > StartValue > + is greater than EndValue, then the performance counter counts down. Fo= r > + example, a 64-bit free running counter that counts up would have a > StartValue > + of 0 and an EndValue of 0xFFFFFFFFFFFFFFFF. A 24-bit free running > counter > + that counts down would have a StartValue of 0xFFFFFF and an EndValue o= f > 0. > + > + @param StartValue The value the performance counter starts with when > it > + rolls over. > + @param EndValue The value that the performance counter ends with > before > + it rolls over. > + > + @return The frequency in Hz. > + > +**/ > +UINT64 > +EFIAPI > +GetPerformanceCounterProperties ( > + OUT UINT64 *StartValue, OPTIONAL > + OUT UINT64 *EndValue OPTIONAL > + ) > +{ > + if (StartValue !=3D NULL) { > + *StartValue =3D 0; > + } > + > + if (EndValue !=3D NULL) { > + *EndValue =3D 32 - 1; > + } > + > + return PcdGet64 (PcdCpuCoreCrystalClockFrequency); > +} > + > +/** > + Converts elapsed ticks of performance counter to time in nanoseconds. > + > + This function converts the elapsed ticks of running performance counte= r to > + time value in unit of nanoseconds. > + > + @param Ticks The number of elapsed ticks of running performance > counter. > + > + @return The elapsed time in nanoseconds. > + > +**/ > +UINT64 > +EFIAPI > +GetTimeInNanoSecond ( > + IN UINT64 Ticks > + ) > +{ > + UINT64 NanoSeconds; > + UINT32 Remainder; > + > + // > + // Ticks > + // Time =3D --------- x 1,000,000,000 > + // Frequency > + // > + NanoSeconds =3D MultU64x32 (DivU64x32Remainder (Ticks, PcdGet64 > (PcdCpuCoreCrystalClockFrequency), &Remainder), 1000000000u); > + > + // > + // Frequency < 0x100000000, so Remainder < 0x100000000, then > (Remainder * 1,000,000,000) > + // will not overflow 64-bit. > + // > + NanoSeconds +=3D DivU64x32 (MultU64x32 ((UINT64)Remainder, > 1000000000u), PcdGet64 (PcdCpuCoreCrystalClockFrequency)); > + > + return NanoSeconds; > +} > -- > 2.38.0