From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by mx.groups.io with SMTP id smtpd.web10.57011.1675699098242808205 for ; Mon, 06 Feb 2023 07:58:18 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=X2qROXYT; spf=pass (domain: intel.com, ip: 192.55.52.120, mailfrom: andrei.warkentin@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675699098; x=1707235098; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=o4oQgt4Hzwx2zQi462XWZ+onzWM1I3MOqG0y1pXrNOA=; b=X2qROXYT03Mxxd5AMa6wCmg1xr3kDyQdk3FKuEoaOCmnmq6x8FlTykuC O3t86nGi8Q5pU/ltsLSjLG+0WSqF1RsZDl1Yz+u6eAjKsESo6sFniyzmS xYEYhPfIsQRcxUJbbMLiWgZQlzzcoCSP0rcKju/bUD2rDh9xvU5KYowQK bAEUgabUcjh9ssukqkcotfyjiOTwrLcgnGDVBv9fhTW++HNeUGAaKUH3K Sf0DJz6Tz6QwkjYwLRIxvLB+/yENJwz8hnClj6eNnkY4piW8mGAW7L2KA VC9XOFZVkFhUL1o8QnFO4vI1Pmafzt4d9n92FXUOZSKH89/9iGFzKNw3p A==; X-IronPort-AV: E=McAfee;i="6500,9779,10613"; a="327872416" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="327872416" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Feb 2023 07:58:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10613"; a="644081029" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="644081029" Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by orsmga006.jf.intel.com with ESMTP; 06 Feb 2023 07:58:16 -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; Mon, 6 Feb 2023 07:58:16 -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; Mon, 6 Feb 2023 07:58:16 -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; Mon, 6 Feb 2023 07:58:16 -0800 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (104.47.57.177) 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; Mon, 6 Feb 2023 07:58:15 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iqaGSUQahynxHi+W2Eu+z2LgT8WfOwriaD3/VsUK6kAwVZ8Y8Z8amyhwYmoueReG3tfURNLqBU6h9wVLOfP7FKq54RxExXpR0rAooguSZ+BawTOG48MYVmZenbx2/XIt/FCXYBv7Umfu/oVpna7ZprXOeSy9uZoPOxXPS09tKaChelWK1dGF/12e+26OxIt3OWrfduWbxuD4qqeCeE5/aaflxqJVJ4TWye0y8rdT8EgSTv59uZkxMhQnFFjsc8M5RVjx+P73UhX2rxbgdaxIH3DyjgLQhbcsyB6K27PSUP/0dQdVUwx/xmT7bwnFBkiAwja9pj3Ksczvki0SeCHXjQ== 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=VyjszV3kiz/A89NsGHkgx8m8Q/isrL75I/vjY4ELnwk=; b=DJ3BEeCFgLqxShxOAzZvCNUytcjOXPcBhMatXge7Tw6/VtD0bYDeyqGAUQuswgM5+UkIXr/DPCiw11KUDL25aOFroTXfaS7Kl+hacCoF6m42D+zXAJppuIApVxZN6UJmzYVFBFIlVNSoO41QCc6lBojZqvr8eZycM6cjjjydPRk06oCLmItGLRQRdHCmQ8evgd+IvWhy8XaicIiJ9OFWU2BiMhT7GiFTuRRK+spe64A3U6OsgLCqN3SWRXvCeyWSOseHwqB7FpayhaAUMVNZn6kWsoN8nKvR6/W8mgE+aEpFcGhrFb82KwuDyzl7u3odfCaAtyrQlr3tE2mab+VNCw== 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 PH8PR11MB6856.namprd11.prod.outlook.com (2603:10b6:510:22b::7) by PH0PR11MB5128.namprd11.prod.outlook.com (2603:10b6:510:39::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6064.34; Mon, 6 Feb 2023 15:58:14 +0000 Received: from PH8PR11MB6856.namprd11.prod.outlook.com ([fe80::9dba:633a:320c:87b]) by PH8PR11MB6856.namprd11.prod.outlook.com ([fe80::9dba:633a:320c:87b%5]) with mapi id 15.20.6064.032; Mon, 6 Feb 2023 15:58:14 +0000 From: "Andrei Warkentin" To: "devel@edk2.groups.io" , "sunilvl@ventanamicro.com" CC: "Dong, Eric" , "Ni, Ray" , "Kumar, Rahul R" , Daniel Schaefer , Gerd Hoffmann , Abner Chang Subject: Re: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V7 07/20] UefiCpuPkg/CpuDxe: Add RISC-V instance Thread-Topic: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V7 07/20] UefiCpuPkg/CpuDxe: Add RISC-V instance Thread-Index: AQHZM01i3FhMHBzCj0+xj7LNgDlNc67CINVg Date: Mon, 6 Feb 2023 15:58:13 +0000 Message-ID: References: <20230128191807.2080547-1-sunilvl@ventanamicro.com> <20230128191807.2080547-8-sunilvl@ventanamicro.com> In-Reply-To: <20230128191807.2080547-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: PH8PR11MB6856:EE_|PH0PR11MB5128:EE_ x-ms-office365-filtering-correlation-id: 4d363b75-2b08-40c7-ef68-08db085af40a x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: qW+XZAAI/+dsQxcxCpTdHQXtdADiuqJe97VuG31sN70kt4qbPgq7PwDXgSLQOQX8TWx6h+eNXih6wkCNgu++abTvxvgsBrqZZsE5AdelOpYQ7z7W3mfmzTN3iDD+axHpV5F0MBSAeMUKzXB1GoIevln6NRW6PTQaHuMM8rsw1NWMNeQwGQ2e1j+p0MOaGbU4mAqYQcvLdiF22yQYDoIBLtgBnmbvx8B+i9z7vvaeE6VCGQ6pL4qXAcYnFrimSj5VDbdaah8Ailf0FZcR1LDzuW2EhsdQ8oIHbKqxRZbfyLapIpwRGEUECHTGSd1yEaJKlm0y3qXgGv+slyGuoAJN4WcDdhyVpbOuXgCQkxmYGIj4fmmWxaKMLN7TDaEHi+1MLS/wYHIEdM7Gm/ELjcTVHgbCE+4HeHnZ3PLZcjJDuWplfBQNE2/6WxtrmwAIVxy2VcnE0zd1PxceYGwP/ZEx9+XX6ZpWiY/n4HBqAr6AYlX1YYeJ0DLBcs94es0R+RMxApcCEeAAkhpJdXqctYND4AYW5ZjBDRXGDIGGlDmgPhewqEnRoqTpQbidcQaJDkvVlVdFVOTTdQmEPdMNiM6sEYhnwzcdnWSUVfKfeyWh+SaC9oN4aY7Lh0l8Tvj5HVP5mdSxl8d5KXzgcUvBeodeJE/OypflR8JBQ8aU/JzAwKQw9rIZhfDOAawRRsfuBhQHswoIzDn+8QjWVigr3cH0Sd1NHKzM2BS4vroI+Q0a05+Tw9COBnlyM9xjJhsjQZVEKybwSbg1mB6PN38r08N4/DDRrdcPRV6FldxELMGuEpI= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH8PR11MB6856.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(396003)(39860400002)(346002)(136003)(366004)(376002)(451199018)(33656002)(38070700005)(86362001)(82960400001)(38100700002)(122000001)(19627235002)(64756008)(66556008)(66446008)(52536014)(8676002)(41300700001)(5660300002)(66476007)(4326008)(8936002)(110136005)(54906003)(76116006)(66946007)(316002)(2906002)(55016003)(30864003)(83380400001)(478600001)(966005)(186003)(7696005)(26005)(53546011)(9686003)(6506007)(71200400001)(66899018)(579004)(44824005);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?nJYiBBW19klCHw+4w8WOWQLUaY0Llk0rg6GcscNKI5e8KWdFnbFw+Xgxu5Lf?= =?us-ascii?Q?Btz3/aiUFZ7tOO6194xO/lddguwRMmxKAl70RWvwWZ2KbfYDD7gqi0AkQ5uM?= =?us-ascii?Q?uSrXGmicDayGlKI/6CP3NYUkjvedXoMtZV/5+ze7RS1d+fpmAMZPJKVRh40D?= =?us-ascii?Q?S9wo/ry6qcAl6nQoVX/JlNwzbmkdfCtN4c6z4qwFPexpDYn7NPBNiZaVde77?= =?us-ascii?Q?LlogCDij+uuadbxotKv4h4dd2OsKrK39UPW5Jgqme7mXA7P4DKra5+xpiXco?= =?us-ascii?Q?xHM8L5mNVYnHZ397O8ZDXxTBdU50rdm3D37EFf5eaV3d64aE5B8zd1MdC08V?= =?us-ascii?Q?hA1/x7wkYmm6Dd35IvVZeRLjtqJB5x97Y+CzbWe3TJUOGpnvSRR4gsfPe0MP?= =?us-ascii?Q?iQgJin1oUXUzZE9rTCYQ4xplSZE5C2KQBP6sd09ttc9nx9yAyBIC9ZPlZkFp?= =?us-ascii?Q?WCT/w2VsFgN5Gf6dfeOUs7KXSejGGqHyCuBj8kN62OocnJpPm0jnxB//dktQ?= =?us-ascii?Q?f232h8PMKFTVFz/N4A3PQ79MJXCU9VQtRG9U70A5C29FQsgpJHL7CtxLrYZl?= =?us-ascii?Q?n6OcJi9lTz3mkqZcP1s6T14P0CMzcqBKsLUvQUPIm+ufdr4FJ4IQ+hdu3cmv?= =?us-ascii?Q?So2zqXv12uE7UxttA9L3zPS1XpTMEaEyRc7L2ATlwbrkIRlZHe7GrszMa4CQ?= =?us-ascii?Q?64WlaY/F4Ns/Pn0nNQKgSNXhHemvLeuLYyrNez68wSYte6zMK2Br1D35mDYX?= =?us-ascii?Q?nYJRx5lFur0r7n/LeLIe7Wap5l33boIoYHz759HBBKu9EEUkm4cyMbanX2On?= =?us-ascii?Q?4TpQymdQe99yUyrJVctp4MOf3ltQ7Z8fYHwJ6opPKlbDKh+D4NgdbxklW04I?= =?us-ascii?Q?gbQACDBQEKMiyxJfdr2UkSTvTWCrWcVFgpxVizWgN8BgF8MMZNY1NndBxA8e?= =?us-ascii?Q?547at43LWRsLQs3GWh4dZQJwLdrwfUhfRZyvYEBgUOeaP3VGtrFnzY3BzDw0?= =?us-ascii?Q?ydotK3r8lDPEdV1q+ZGxdOYLe9jqucVEwNoSVhpcPRFWrESeSOaMjozZw1O0?= =?us-ascii?Q?HZCNcW/pgjzJIzZtYhqgpaK+3+oSt6MtoPQTQyXwg0G5Lu4QG2nGUWhXnb2g?= =?us-ascii?Q?ngqGgFmV8ttl4sygX3tuUQJMY+MssNJmMCmwQc5bdulbV2GzWhxIG2XCBrvp?= =?us-ascii?Q?QXBxqXyZxbaoVPY9nlQGehUc6fkxje64txPPlQXK+UjEX24OoWJPZMXX2wCs?= =?us-ascii?Q?2jStntaNvEXVl9Je/Wwg5IMaQryF5FpULGFGrRv/OmahHIOyeTMnRQTJrWUE?= =?us-ascii?Q?rIiEYT8ptv+VCUz1WT6gS1IxVuFaRApYyzNEbTVPAesLc5xt5AX1o3cG9wsq?= =?us-ascii?Q?15HvXxF0haM26qLwJIUq05ahgwA1QzWR945ZF8d25Yok+mvyPwh6xKl7uejv?= =?us-ascii?Q?P+fZHUqhxfmykXwQSws5W8h8jEzM8P4JjXR6SEOyv/78kuaRlRQL9T8d4l9l?= =?us-ascii?Q?wua5W2kxplWCIel/FTSd9fK1ww/YYbONXyn/Q/AKutZcgJzgPcdcddX0MsTJ?= =?us-ascii?Q?v87FM2NVHPOYmxJB+FycfQnpB2S3oaedQHzX4j4v22hOh52uyKFWSmMHKXKX?= =?us-ascii?Q?6Q=3D=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PH8PR11MB6856.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4d363b75-2b08-40c7-ef68-08db085af40a X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Feb 2023 15:58:13.7180 (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: NxTbaYxJoqyfcihe+guguWvHClTtAeF1eduiZCwUxHHQxhcPoj2SyNYI+DWZNK4PEWVpo8gk3744bM1W6drmPbjjNHUSQvoSHQ7+ZXgFodM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR11MB5128 Return-Path: andrei.warkentin@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Andrei Warkentin -----Original Message----- From: devel@edk2.groups.io On Behalf Of Sunil V L Sent: Saturday, January 28, 2023 1:18 PM To: devel@edk2.groups.io Cc: Dong, Eric ; Ni, Ray ; Kumar, Ra= hul R ; Daniel Schaefer ; G= erd Hoffmann ; Abner Chang Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V7 07/20] UefiCpu= Pkg/CpuDxe: Add RISC-V instance REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4076 This is copied from edk2-platforms/Silicon/RISC-V/ProcessorPkg/Universal/CpuDxe 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 | 1 + UefiCpuPkg/CpuDxe/CpuDxeRiscV64.inf | 68 ++++ UefiCpuPkg/CpuDxe/RiscV64/= CpuDxe.h | 199 +++++++++++ UefiCpuPkg/CpuDxe/RiscV64/CpuDxe.c | 365 ++++= ++++++++++++++++ 4 files changed, 633 insertions(+) diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc index 25= 1a8213f022..8f2be6cd1b05 100644 --- a/UefiCpuPkg/UefiCpuPkg.dsc +++ b/UefiCpuPkg/UefiCpuPkg.dsc @@ -198,6 +198,7 @@ [Components.X64] [Components.RISCV64] UefiCpuPkg/CpuTimerDxe/CpuTimerDxe.inf UefiCpuPkg/Library/CpuExceptionHandlerLib/BaseRiscV64CpuExceptionHandler= Lib.inf + UefiCpuPkg/CpuDxe/CpuDxeRiscV64.inf =20 [BuildOptions] *_*_*_CC_FLAGS =3D -D DISABLE_NEW_DEPRECATED_INTERFACES diff --git a/Uef= iCpuPkg/CpuDxe/CpuDxeRiscV64.inf b/UefiCpuPkg/CpuDxe/CpuDxeRiscV64.inf new file mode 100644 index 000000000000..5e590d03754f --- /dev/null +++ b/UefiCpuPkg/CpuDxe/CpuDxeRiscV64.inf @@ -0,0 +1,68 @@ +## @file +# RISC-V CPU DXE module. +# +# Copyright (c) 2022, Ventana Micro Systems Inc. All rights=20 +reserved.
# # SPDX-License-Identifier: BSD-2-Clause-Patent # ## + +[Defines] + INF_VERSION =3D 0x0001001B + BASE_NAME =3D CpuDxeRiscV64 + MODULE_UNI_FILE =3D CpuDxe.uni + FILE_GUID =3D BDEA19E2-778F-473C-BF82-5E38D6A27765 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D InitializeCpu + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + CpuLib + DebugLib + DxeServicesTableLib + MemoryAllocationLib + UefiBootServicesTableLib + UefiDriverEntryPoint + UefiLib + CpuExceptionHandlerLib + HobLib + ReportStatusCodeLib + TimerLib + PeCoffGetEntryPointLib + RiscVSbiLib + +[Sources] + RiscV64/CpuDxe.c + RiscV64/CpuDxe.h + +[Protocols] + gEfiCpuArchProtocolGuid ## PRODUCES + gRiscVEfiBootProtocolGuid ## PRODUCES + +[Guids] + gIdleLoopEventGuid ## CONSUMES ## E= vent + +[Ppis] + gEfiSecPlatformInformation2PpiGuid ## UNDEFINED # HOB + gEfiSecPlatformInformationPpiGuid ## UNDEFINED # HOB + +[Pcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard ##= CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdHeapGuardPropertyMask ##= CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdNullPointerDetectionPropertyMask ##= CONSUMES + gUefiCpuPkgTokenSpaceGuid.PcdCpuStackSwitchExceptionList ##= CONSUMES + gUefiCpuPkgTokenSpaceGuid.PcdCpuKnownGoodStackSize ##= CONSUMES + gUefiCpuPkgTokenSpaceGuid.PcdCpuCoreCrystalClockFrequency ##= CONSUMES + +[Depex] + TRUE + +[UserExtensions.TianoCore."ExtraFiles"] + CpuDxeExtra.uni diff --git a/UefiCpuPkg/CpuDxe/RiscV64/CpuDxe.h b/UefiCpuPkg/CpuDxe/RiscV64= /CpuDxe.h new file mode 100644 index 000000000000..49f4e119665a --- /dev/null +++ b/UefiCpuPkg/CpuDxe/RiscV64/CpuDxe.h @@ -0,0 +1,199 @@ +/** @file + RISC-V CPU DXE module header file. + + Copyright (c) 2016 - 2022, Hewlett Packard Enterprise Development LP.=20 + All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef CPU_DXE_H_ +#define CPU_DXE_H_ + +#include + +#include +#include #include=20 + #include #include=20 + +#include +#include +#include + +/** + Flush CPU data cache. If the instruction cache is fully coherent + with all DMA operations then function can just return EFI_SUCCESS. + + @param This Protocol instance structure + @param Start Physical address to start flushing from. + @param Length Number of bytes to flush. Round up to chipset + granularity. + @param FlushType Specifies the type of flush operation to perfo= rm. + + @retval EFI_SUCCESS If cache was flushed + @retval EFI_UNSUPPORTED If flush type is not supported. + @retval EFI_DEVICE_ERROR If requested range could not be flushed. + +**/ +EFI_STATUS +EFIAPI +CpuFlushCpuDataCache ( + IN EFI_CPU_ARCH_PROTOCOL *This, + IN EFI_PHYSICAL_ADDRESS Start, + IN UINT64 Length, + IN EFI_CPU_FLUSH_TYPE FlushType + ); + +/** + Enables CPU interrupts. + + @param This Protocol instance structure + + @retval EFI_SUCCESS If interrupts were enabled in the CPU + @retval EFI_DEVICE_ERROR If interrupts could not be enabled on the CPU. + +**/ +EFI_STATUS +EFIAPI +CpuEnableInterrupt ( + IN EFI_CPU_ARCH_PROTOCOL *This + ); + +/** + Disables CPU interrupts. + + @param This Protocol instance structure + + @retval EFI_SUCCESS If interrupts were disabled in the CPU. + @retval EFI_DEVICE_ERROR If interrupts could not be disabled on the CPU= . + +**/ +EFI_STATUS +EFIAPI +CpuDisableInterrupt ( + IN EFI_CPU_ARCH_PROTOCOL *This + ); + +/** + Return the state of interrupts. + + @param This Protocol instance structure + @param State Pointer to the CPU's current interrupt st= ate + + @retval EFI_SUCCESS If interrupts were disabled in the CPU. + @retval EFI_INVALID_PARAMETER State is NULL. + +**/ +EFI_STATUS +EFIAPI +CpuGetInterruptState ( + IN EFI_CPU_ARCH_PROTOCOL *This, + OUT BOOLEAN *State + ); + +/** + Generates an INIT to the CPU. + + @param This Protocol instance structure + @param InitType Type of CPU INIT to perform + + @retval EFI_SUCCESS If CPU INIT occurred. This value should never = be + seen. + @retval EFI_DEVICE_ERROR If CPU INIT failed. + @retval EFI_UNSUPPORTED Requested type of CPU INIT not supported. + +**/ +EFI_STATUS +EFIAPI +CpuInit ( + IN EFI_CPU_ARCH_PROTOCOL *This, + IN EFI_CPU_INIT_TYPE InitType + ); + +/** + Registers a function to be called from the CPU interrupt handler. + + @param This Protocol instance structure + @param InterruptType Defines which interrupt to hook. IA-32 + valid range is 0x00 through 0xFF + @param InterruptHandler A pointer to a function of type + EFI_CPU_INTERRUPT_HANDLER that is called + when a processor interrupt occurs. A nul= l + pointer is an error condition. + + @retval EFI_SUCCESS If handler installed or uninstalled. + @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handl= er + for InterruptType was previously installe= d. + @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler f= or + InterruptType was not previously installe= d. + @retval EFI_UNSUPPORTED The interrupt specified by InterruptType + is not supported. + +**/ +EFI_STATUS +EFIAPI +CpuRegisterInterruptHandler ( + IN EFI_CPU_ARCH_PROTOCOL *This, + IN EFI_EXCEPTION_TYPE InterruptType, + IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler + ); + +/** + Returns a timer value from one of the CPU's internal timers. There is=20 +no + inherent time interval between ticks but is a function of the CPU freque= ncy. + + @param This - Protocol instance structure. + @param TimerIndex - Specifies which CPU timer is requested. + @param TimerValue - Pointer to the returned timer value. + @param TimerPeriod - A pointer to the amount of time that passe= s + in femtoseconds (10-15) for each increment + of TimerValue. If TimerValue does not + increment at a predictable rate, then 0 is + returned. The amount of time that has + passed between two calls to GetTimerValue(= ) + can be calculated with the formula + (TimerValue2 - TimerValue1) * TimerPeriod. + This parameter is optional and may be NULL= . + + @retval EFI_SUCCESS - If the CPU timer count was returned. + @retval EFI_UNSUPPORTED - If the CPU does not have any readable ti= mers. + @retval EFI_DEVICE_ERROR - If an error occurred while reading the t= imer. + @retval EFI_INVALID_PARAMETER - TimerIndex is not valid or TimerValue is= NULL. + +**/ +EFI_STATUS +EFIAPI +CpuGetTimerValue ( + IN EFI_CPU_ARCH_PROTOCOL *This, + IN UINT32 TimerIndex, + OUT UINT64 *TimerValue, + OUT UINT64 *TimerPeriod OPTIONAL + ); + +/** + Set memory cacheability attributes for given range of memeory. + + @param This Protocol instance structure + @param BaseAddress Specifies the start address of the + memory range + @param Length Specifies the length of the memory range + @param Attributes The memory cacheability for the memory ra= nge + + @retval EFI_SUCCESS If the cacheability of that memory range = is + set successfully + @retval EFI_UNSUPPORTED If the desired operation cannot be done + @retval EFI_INVALID_PARAMETER The input parameter is not correct, + such as Length =3D 0 + +**/ +EFI_STATUS +EFIAPI +CpuSetMemoryAttributes ( + IN EFI_CPU_ARCH_PROTOCOL *This, + IN EFI_PHYSICAL_ADDRESS BaseAddress, + IN UINT64 Length, + IN UINT64 Attributes + ); + +#endif diff --git a/UefiCpuPkg/CpuDxe/RiscV64/CpuDxe.c b/UefiCpuPkg/CpuDxe/RiscV64= /CpuDxe.c new file mode 100644 index 000000000000..7551e0653603 --- /dev/null +++ b/UefiCpuPkg/CpuDxe/RiscV64/CpuDxe.c @@ -0,0 +1,365 @@ +/** @file + RISC-V CPU DXE driver. + + Copyright (c) 2016 - 2022, Hewlett Packard Enterprise Development LP.=20 + All rights reserved.
Copyright (c) 2022, Ventana Micro Systems=20 + Inc. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "CpuDxe.h" + +// +// Global Variables +// +STATIC BOOLEAN mInterruptState =3D FALSE; +STATIC EFI_HANDLE mCpuHandle =3D NULL; +STATIC UINTN mBootHartId; +RISCV_EFI_BOOT_PROTOCOL gRiscvBootProtocol; + +/** + Get the boot hartid + + @param This Protocol instance structure + @param BootHartId Pointer to the Boot Hart ID variable + + @retval EFI_SUCCESS If BootHartId is returned + @retval EFI_INVALID_PARAMETER Either "BootHartId" is NULL or "This" is = not + a valid RISCV_EFI_BOOT_PROTOCOL instance. + +**/ +EFI_STATUS +EFIAPI +RiscvGetBootHartId ( + IN RISCV_EFI_BOOT_PROTOCOL *This, + OUT UINTN *BootHartId + ) +{ + if ((This !=3D &gRiscvBootProtocol) || (BootHartId =3D=3D NULL)) { + return EFI_INVALID_PARAMETER; + } + + *BootHartId =3D mBootHartId; + return EFI_SUCCESS; +} + +RISCV_EFI_BOOT_PROTOCOL gRiscvBootProtocol =3D { + RISCV_EFI_BOOT_PROTOCOL_LATEST_VERSION, + RiscvGetBootHartId +}; + +EFI_CPU_ARCH_PROTOCOL gCpu =3D { + CpuFlushCpuDataCache, + CpuEnableInterrupt, + CpuDisableInterrupt, + CpuGetInterruptState, + CpuInit, + CpuRegisterInterruptHandler, + CpuGetTimerValue, + CpuSetMemoryAttributes, + 1, // NumberOfTimers + 4 // DmaBufferAlignment +}; + +// +// CPU Arch Protocol Functions +// + +/** + Flush CPU data cache. If the instruction cache is fully coherent + with all DMA operations then function can just return EFI_SUCCESS. + + @param This Protocol instance structure + @param Start Physical address to start flushing from. + @param Length Number of bytes to flush. Round up to chipset + granularity. + @param FlushType Specifies the type of flush operation to perfo= rm. + + @retval EFI_SUCCESS If cache was flushed + @retval EFI_UNSUPPORTED If flush type is not supported. + @retval EFI_DEVICE_ERROR If requested range could not be flushed. + +**/ +EFI_STATUS +EFIAPI +CpuFlushCpuDataCache ( + IN EFI_CPU_ARCH_PROTOCOL *This, + IN EFI_PHYSICAL_ADDRESS Start, + IN UINT64 Length, + IN EFI_CPU_FLUSH_TYPE FlushType + ) +{ + return EFI_SUCCESS; +} + +/** + Enables CPU interrupts. + + @param This Protocol instance structure + + @retval EFI_SUCCESS If interrupts were enabled in the CPU + @retval EFI_DEVICE_ERROR If interrupts could not be enabled on the CPU. + +**/ +EFI_STATUS +EFIAPI +CpuEnableInterrupt ( + IN EFI_CPU_ARCH_PROTOCOL *This + ) +{ + EnableInterrupts (); + mInterruptState =3D TRUE; + return EFI_SUCCESS; +} + +/** + Disables CPU interrupts. + + @param This Protocol instance structure + + @retval EFI_SUCCESS If interrupts were disabled in the CPU. + @retval EFI_DEVICE_ERROR If interrupts could not be disabled on the CPU= . + +**/ +EFI_STATUS +EFIAPI +CpuDisableInterrupt ( + IN EFI_CPU_ARCH_PROTOCOL *This + ) +{ + DisableInterrupts (); + mInterruptState =3D FALSE; + return EFI_SUCCESS; +} + +/** + Return the state of interrupts. + + @param This Protocol instance structure + @param State Pointer to the CPU's current interrupt st= ate + + @retval EFI_SUCCESS If interrupts were disabled in the CPU. + @retval EFI_INVALID_PARAMETER State is NULL. + +**/ +EFI_STATUS +EFIAPI +CpuGetInterruptState ( + IN EFI_CPU_ARCH_PROTOCOL *This, + OUT BOOLEAN *State + ) +{ + if (State =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + *State =3D mInterruptState; + return EFI_SUCCESS; +} + +/** + Generates an INIT to the CPU. + + @param This Protocol instance structure + @param InitType Type of CPU INIT to perform + + @retval EFI_SUCCESS If CPU INIT occurred. This value should never = be + seen. + @retval EFI_DEVICE_ERROR If CPU INIT failed. + @retval EFI_UNSUPPORTED Requested type of CPU INIT not supported. + +**/ +EFI_STATUS +EFIAPI +CpuInit ( + IN EFI_CPU_ARCH_PROTOCOL *This, + IN EFI_CPU_INIT_TYPE InitType + ) +{ + return EFI_UNSUPPORTED; +} + +/** + Registers a function to be called from the CPU interrupt handler. + + @param This Protocol instance structure + @param InterruptType Defines which interrupt to hook. IA-32 + valid range is 0x00 through 0xFF + @param InterruptHandler A pointer to a function of type + EFI_CPU_INTERRUPT_HANDLER that is called + when a processor interrupt occurs. A nul= l + pointer is an error condition. + + @retval EFI_SUCCESS If handler installed or uninstalled. + @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handl= er + for InterruptType was previously installe= d. + @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler f= or + InterruptType was not previously installe= d. + @retval EFI_UNSUPPORTED The interrupt specified by InterruptType + is not supported. + +**/ +EFI_STATUS +EFIAPI +CpuRegisterInterruptHandler ( + IN EFI_CPU_ARCH_PROTOCOL *This, + IN EFI_EXCEPTION_TYPE InterruptType, + IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler + ) +{ + return RegisterCpuInterruptHandler (InterruptType, InterruptHandler);=20 +} + +/** + Returns a timer value from one of the CPU's internal timers. There is=20 +no + inherent time interval between ticks but is a function of the CPU freque= ncy. + + @param This - Protocol instance structure. + @param TimerIndex - Specifies which CPU timer is requested. + @param TimerValue - Pointer to the returned timer value. + @param TimerPeriod - A pointer to the amount of time that passe= s + in femtoseconds (10-15) for each increment + of TimerValue. If TimerValue does not + increment at a predictable rate, then 0 is + returned. The amount of time that has + passed between two calls to GetTimerValue(= ) + can be calculated with the formula + (TimerValue2 - TimerValue1) * TimerPeriod. + This parameter is optional and may be NULL= . + + @retval EFI_SUCCESS - If the CPU timer count was returned. + @retval EFI_UNSUPPORTED - If the CPU does not have any readable ti= mers. + @retval EFI_DEVICE_ERROR - If an error occurred while reading the t= imer. + @retval EFI_INVALID_PARAMETER - TimerIndex is not valid or TimerValue is= NULL. + +**/ +EFI_STATUS +EFIAPI +CpuGetTimerValue ( + IN EFI_CPU_ARCH_PROTOCOL *This, + IN UINT32 TimerIndex, + OUT UINT64 *TimerValue, + OUT UINT64 *TimerPeriod OPTIONAL + ) +{ + if (TimerValue =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + if (TimerIndex !=3D 0) { + return EFI_INVALID_PARAMETER; + } + + *TimerValue =3D (UINT64)RiscVReadTimer (); if (TimerPeriod !=3D NULL) { + *TimerPeriod =3D DivU64x32 ( + 1000000000000000u, + PcdGet64 (PcdCpuCoreCrystalClockFrequency) + ); + } + + return EFI_SUCCESS; +} + +/** + Implementation of SetMemoryAttributes() service of CPU Architecture Prot= ocol. + + This function modifies the attributes for the memory region specified=20 + by BaseAddress and Length from their current attributes to the attribute= s specified by Attributes. + + @param This The EFI_CPU_ARCH_PROTOCOL instance. + @param BaseAddress The physical address that is the start address = of a memory region. + @param Length The size in bytes of the memory region. + @param Attributes The bit mask of attributes to set for the memor= y region. + + @retval EFI_SUCCESS The attributes were set for the memory reg= ion. + @retval EFI_ACCESS_DENIED The attributes for the memory resource ran= ge specified by + BaseAddress and Length cannot be modified. + @retval EFI_INVALID_PARAMETER Length is zero. + Attributes specified an illegal combinatio= n of attributes that + cannot be set together. + @retval EFI_OUT_OF_RESOURCES There are not enough system resources to m= odify the attributes of + the memory resource range. + @retval EFI_UNSUPPORTED The processor does not support one or more= bytes of the memory + resource range specified by BaseAddress an= d Length. + The bit mask of attributes is not support = for the memory resource + range specified by BaseAddress and Length. + +**/ +EFI_STATUS +EFIAPI +CpuSetMemoryAttributes ( + IN EFI_CPU_ARCH_PROTOCOL *This, + IN EFI_PHYSICAL_ADDRESS BaseAddress, + IN UINT64 Length, + IN UINT64 Attributes + ) +{ + DEBUG ((DEBUG_INFO, "%a: Set memory attributes not supported yet\n",=20 +__FUNCTION__)); + return EFI_SUCCESS; +} + +/** + Initialize the state information for the CPU Architectural Protocol. + + @param ImageHandle Image handle this driver. + @param SystemTable Pointer to the System Table. + + @retval EFI_SUCCESS Thread can be successfully created + @retval EFI_OUT_OF_RESOURCES Cannot allocate protocol data structure + @retval EFI_DEVICE_ERROR Cannot create the thread + +**/ +EFI_STATUS +EFIAPI +InitializeCpu ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + EFI_RISCV_FIRMWARE_CONTEXT *FirmwareContext; + + GetFirmwareContextPointer (&FirmwareContext); ASSERT=20 + (FirmwareContext !=3D NULL); if (FirmwareContext =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "Failed to get the pointer of EFI_RISCV_FIRMWARE_= CONTEXT\n")); + return EFI_NOT_FOUND; + } + + DEBUG ((DEBUG_INFO, " %a: Firmware Context is at 0x%x.\n",=20 + __FUNCTION__, FirmwareContext)); + + mBootHartId =3D FirmwareContext->BootHartId; DEBUG ((DEBUG_INFO, " %a:= =20 + mBootHartId =3D 0x%x.\n", __FUNCTION__, mBootHartId)); + + InitializeCpuExceptionHandlers (NULL); + + // + // Make sure interrupts are disabled + // + DisableInterrupts (); + + // + // Install Boot protocol + // + Status =3D gBS->InstallProtocolInterface ( + &ImageHandle, + &gRiscVEfiBootProtocolGuid, + EFI_NATIVE_INTERFACE, + &gRiscvBootProtocol + ); + ASSERT_EFI_ERROR (Status); + + // + // Install CPU Architectural Protocol + // + Status =3D gBS->InstallMultipleProtocolInterfaces ( + &mCpuHandle, + &gEfiCpuArchProtocolGuid, + &gCpu, + NULL + ); + ASSERT_EFI_ERROR (Status); + return Status; +} -- 2.38.0