From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-002e3701.pphosted.com (mx0b-002e3701.pphosted.com [148.163.143.35]) by mx.groups.io with SMTP id smtpd.web08.10684.1633521442234151355 for ; Wed, 06 Oct 2021 04:57:26 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@hpe.com header.s=pps0720 header.b=jObWz84Q; spf=temperror, err=temporary DNS error (domain: hpe.com, ip: 148.163.143.35, mailfrom: prvs=0913d10296=daniel.schaefer@hpe.com) Received: from pps.filterd (m0134423.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 1969UVTi030312; Wed, 6 Oct 2021 11:57:21 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hpe.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=pps0720; bh=qM9OvLUW6Fl0c5HaUNUqvO03jT2pOIwfmz5xEXFJTn0=; b=jObWz84QqVp4kftsBf9AA7vbbhI9XIAHJNy3JVGSeFz7Rt5RX3M0n8oaVXG7PwXpndlu 9ZHK74tlUD9S5AD70AwnOAR5DbgXg1UnY+gpocdWr4Gs7NL8GQPRK8+DFW7e/cFVdedw ax+8ykSWNVd8xRA5yWTIeys6ZnUcrZrPm3ilMj9qYywE95eGznJ9O4Bfw7J/cYoDPuZ2 JiCkNDz8sW/82nceqqsXWRWRdpJ8/cWvaqnlfST8df/pVfJiEdPW7nEnjWRXp1gm4ENa MCeyFrfSIMH9wFWILAZ0GnpyfkUmFCcwzMVUq6U7w5T7578KzLY5XNv9DcDFuU2INR3b Lg== Received: from g9t5009.houston.hpe.com (g9t5009.houston.hpe.com [15.241.48.73]) by mx0b-002e3701.pphosted.com with ESMTP id 3bgyevdnju-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Oct 2021 11:57:21 +0000 Received: from G4W9120.americas.hpqcorp.net (exchangepmrr1.us.hpecorp.net [16.210.21.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by g9t5009.houston.hpe.com (Postfix) with ESMTPS id AC6FD6D; Wed, 6 Oct 2021 11:57:20 +0000 (UTC) Received: from G1W8107.americas.hpqcorp.net (2002:10c1:483b::10c1:483b) by G4W9120.americas.hpqcorp.net (2002:10d2:150f::10d2:150f) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Wed, 6 Oct 2021 11:57:20 +0000 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (15.241.52.11) by G1W8107.americas.hpqcorp.net (16.193.72.59) with Microsoft SMTP Server (TLS) id 15.0.1497.23 via Frontend Transport; Wed, 6 Oct 2021 11:57:20 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ht0iLVxC8LPza92pKZa4wLx030abtP/sDP2QFyTPbBPGvgIsa13EmCoqhjE5C/u7YD+Hguzh2Nrig0fmWQbpiGRE2oXHJfHI/ZYY8DlBWaHCIKkbFa+FiP6S+NTvKPB00OMi8tO9GmhiiaaARrqrmuqVphek7LVbi2qS3aU1KHYi4iLHHFN3fjmy+McrtG7YX+6TVMxddJ8wDRscd/z+VE0DmUPqs+i9eKdJLEu4qHAXfzEFd9ZNzP9D+IWhg/DgrUeDaPNb7cOBTCwDzxMT4BqlgHi2/fRgz2YbU3jp/3wdWGGoWF4nwHXi+zDCVEUW32pltGnfT6Xm6GLJIvLKOg== 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=qM9OvLUW6Fl0c5HaUNUqvO03jT2pOIwfmz5xEXFJTn0=; b=A1jBTjm/GLYiNinQYae2zbc7KUGr8cB6wk15yVd1WCiT5B1cA09Hws3vvfNORQ9i92hPCq1RwBccfaosoeyRD8K3dlk7VCRG0PLU9L7WZ+n9KFEp9TslgiMP2hNvMVG7f0YP5aMJwpjM94uXwRKUdi1Pme1jNFEB8IQT/6VJziNheUiVWB+zIpj49CR5ZkhjEgBW0n8WyLxoll2sRTY+Rg8suin9Da+Uvop/oPL6Ke9VJOmq/LNH7ImlQP4phSllT0f0miLLTW9AVc2b6wXQWx/bZRip86Q0u+vqT6A0XEsF/2CZQCqvM4cI/slCbXpJirNTIk7nH/ExECW1Hvcc6A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=hpe.com; dmarc=pass action=none header.from=hpe.com; dkim=pass header.d=hpe.com; arc=none Authentication-Results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=hpe.com; Received: from DF4PR8401MB0923.NAMPRD84.PROD.OUTLOOK.COM (2a01:111:e400:760f::13) by DF4PR8401MB0331.NAMPRD84.PROD.OUTLOOK.COM (2a01:111:e400:7606::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.15; Wed, 6 Oct 2021 11:57:18 +0000 Received: from DF4PR8401MB0923.NAMPRD84.PROD.OUTLOOK.COM ([fe80::597f:4786:f1d6:8469]) by DF4PR8401MB0923.NAMPRD84.PROD.OUTLOOK.COM ([fe80::597f:4786:f1d6:8469%3]) with mapi id 15.20.4566.023; Wed, 6 Oct 2021 11:57:18 +0000 From: "Daniel Schaefer" To: CC: Sunil V L Subject: [edk2-platforms][PATCH v2 04/14] Silicon/RISC-V: Introduce FirmwareContext library Date: Wed, 6 Oct 2021 19:56:42 +0800 Message-ID: <20211006115652.3635489-5-daniel.schaefer@hpe.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211006115652.3635489-1-daniel.schaefer@hpe.com> References: <20211006115652.3635489-1-daniel.schaefer@hpe.com> X-ClientProxiedBy: HK2PR0401CA0022.apcprd04.prod.outlook.com (2603:1096:202:2::32) To DF4PR8401MB0923.NAMPRD84.PROD.OUTLOOK.COM (2a01:111:e400:760f::13) MIME-Version: 1.0 Received: from localhost.localdomain (123.193.59.220) by HK2PR0401CA0022.apcprd04.prod.outlook.com (2603:1096:202:2::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.17 via Frontend Transport; Wed, 6 Oct 2021 11:57:16 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: bbb54957-4449-4894-b03d-08d988c07218 X-MS-TrafficTypeDiagnostic: DF4PR8401MB0331: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1824; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zx3mtEjqmo/4GLsI8+TpjLRd2WIogtNg7dvDJd1V/UisR+YyrAkWhAutLxixfKoQ+R8RVN+h3uhFsare9GV6QxxvAERgV8rYWfqiOFuvLWSWOPtYXGfEJjzwHHPoS2tcOAfPPzdBTDf2L3HvE7GdqK+1llrvU9cjXM9P2W4q1jlkZICVVwr1hscuvLPwyWIf7JoKaUM3KNJKzH1eJFROIdXUScA8RjaKR7r23z3Mc9c5NhPYs8XCIZid2nNK0hbaav84NN6fQXt0AX30QMe4EA7xF7uXTCYGKewATvqCx6BSYMNkgd23VlmBq9viDG4v9+qIVTSGezAnRIUwDU9QzjpyqMpQPa4Yii4mrIw58xoER6JRpu4ekgvqQMIdT59V5BZEMFzdl61BW9sobI4u/9O5nbmfXRGYXCCLvAFJsK6YZ+fHiSc+M9XTEQK+5/IGERDmfwvYmNbBZhc3mNGqMYdTffZ7m2+VnbdYZ5SNPcsTn8K40MAqXT9ejAfzpcqSJbAx94i11+Ra2dediWqu4wucvaurQi97XRnYpDT1V7ls7W8NRJKouEcPIma15jgwxU0js1tmYsv28chUKdLp+xRd80CeER1qW8uOiNTYsv9lvmnk0Zwl0ddtBGnvp5nhaMxAuaqBS/9Ywm28AEEJ32BokNoLsbviivFzRWuJxbZBNxhMu4bHbjtRPHg0A7U4WM+DgFs5JiMOlZD4mmF9Dw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DF4PR8401MB0923.NAMPRD84.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(366004)(2616005)(1076003)(8676002)(83380400001)(8936002)(38100700002)(44832011)(38350700002)(30864003)(6916009)(2906002)(36756003)(5660300002)(508600001)(956004)(86362001)(316002)(186003)(66556008)(6486002)(66476007)(52116002)(6506007)(26005)(66946007)(6512007)(4326008)(6666004);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?oYas88WuQePxKphsHZMUXZ+8bnW4vuqo164//jZGZZP8XAUrMu63iXtS2XQe?= =?us-ascii?Q?A0toJFFjTGGqSkRpZOzNlE262JBKQ5GvvD2yF4Iliebt0H5WbkVDnBDt5KWT?= =?us-ascii?Q?sSTRQXzkgnPgKJjXTIme8tFybiS/VQ6rpapZcjwrg72KAAOMxvbAXZxS8ozr?= =?us-ascii?Q?Si2m6X4eQQbB2NPt+60KiAAQAeefavv16yw5cYj2ddOToCRYL5WwU5WgR81Q?= =?us-ascii?Q?bngqTw2VVvfTsAvIQjImsvP8uy5Y8WSLmEHIZiu+oI8mJmgzsGMthgq8tjnZ?= =?us-ascii?Q?nITGeGXhHmGSIqYqyA+clmx9sZ+IGlKfAWPaTY64/5Oh/6jJod55fB0jLaTL?= =?us-ascii?Q?bzW8w8BHB57xqyAyCKuttX4czM+V/YxEIYAs86nR9vDHfWa1UUjrKbIfJZsv?= =?us-ascii?Q?Febaf3X3w7kjkJmAE4gwMUfeEVF5POmL4qVLzcQsV3q5jRUuHj7u0gxNTMP3?= =?us-ascii?Q?RSsxrY2XGt2+DaSyKBXd3VPBa0c8TfOIrvgOpLA6Xa4ybX2IJky0rdoH9qfR?= =?us-ascii?Q?fRfJ4t4JonUtSfbGnFyBK0nrWXpDanQZHebsxiwNcVMOPrg/kgbMtMTGc1Go?= =?us-ascii?Q?m+NEPLhG5YQf18SMAx2rZjKFBqrd0keBPR+IcF2dNaaq78K4Q62yA+bXyQlp?= =?us-ascii?Q?moU3ZrEmH8caCHO2ow5urcKfg/RhA7RDAvUZ2aYn+4g4cYi6QJQoAJ3sw0EY?= =?us-ascii?Q?gZdHHe6eMBiux2kWmPPMFHSLH92oB/W7DTZZcM26ASZb0WxHHl6RAc7WP/qc?= =?us-ascii?Q?Cuk8OICAvwSUzXaHhnfrMDyi1KQwOMXk4m4ZHdaGzkD9SSvWTIr45K9GATNW?= =?us-ascii?Q?jKoA6/A3PxsyjqyizWqCFuef4kTZFxpknCCqsSQ8F6Pk9rYxWceQ6E6VlAjd?= =?us-ascii?Q?Bx0QYhxfudy5O00L+3otLgh8nCyjfHQSiMiXlDBe7syFLh7kys4ETAwIAdEm?= =?us-ascii?Q?Bh2ECfJZyq6W+L+o9/0LUn6B6W5gYy3CF1gHkZB8QqREWRbFvCh/xVzo3KD7?= =?us-ascii?Q?Zps23F2xonmWScWnftzykUAbtRtQ9bzv3pa/0pM1fdFfCOLOB3xNngMnL4GE?= =?us-ascii?Q?YB425cVXQMyK8dUJxAk0eBxdQ90D8jdKBMWnJA9a+E8fUKL2RmsWGMc8LT0h?= =?us-ascii?Q?gU5yk4edWMV8AWosyc1MGkJ/HHGC+XMd9EmYsA27fKioTQIMtlxn/EIV9wOV?= =?us-ascii?Q?lugM52roTGhkN3qCHrIBnyc2l2bCqro26oqTtBDH2sxTss1Gvv/EiOPqoNCs?= =?us-ascii?Q?gefgyRezc3vTGZbJ3wpqWFs+x532S3FjdqWop8PGfkQelVafYV1/WHhzgvy8?= =?us-ascii?Q?1c79TrTz51/gEdKMoiYWJnWS?= X-MS-Exchange-CrossTenant-Network-Message-Id: bbb54957-4449-4894-b03d-08d988c07218 X-MS-Exchange-CrossTenant-AuthSource: DF4PR8401MB0923.NAMPRD84.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Oct 2021 11:57:18.2543 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 105b2061-b669-4b31-92ac-24d304d195dc X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 8iR9jK2vSNPrhCbKAiKTCK3kY16XWyufPxJ0wADsC3rmXvSWqL3zKJrF7Kt7Q1oOuSDPhB6o/ysSGKCPrNfmkA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DF4PR8401MB0331 X-OriginatorOrg: hpe.com X-Proofpoint-ORIG-GUID: 9c1Ag55ChcVppiIZMWTsraPZG7kYojlZ X-Proofpoint-GUID: 9c1Ag55ChcVppiIZMWTsraPZG7kYojlZ X-HPE-SCL: -1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.391,FMLib:17.0.607.475 definitions=2021-10-06_02,2021-10-06_01,2020-04-07_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 malwarescore=0 adultscore=0 bulkscore=0 clxscore=1015 mlxscore=0 lowpriorityscore=0 spamscore=0 mlxlogscore=999 impostorscore=0 priorityscore=1501 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2109230001 definitions=main-2110060075 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain From: Abner Chang Add RISC-V FirmwareContext library for different FirmwareContext implementations. This instance uses SBI firmware extension to get the pointer to FirmwareContext. Cc: Sunil V L Cc: Daniel Schaefer Signed-off-by: Abner Chang --- Silicon/RISC-V/ProcessorPkg/Include/IndustryStandard/RiscV.h = | 3 +- Silicon/RISC-V/ProcessorPkg/Include/Library/RiscVCpuLib.h = | 14 +++++- Silicon/RISC-V/ProcessorPkg/Include/Library/RiscVFirmwareContextLib.h = | 43 ++++++++++++++++ Silicon/RISC-V/ProcessorPkg/Library/RiscVCpuLib/Cpu.S = | 34 ++++++++++++- Silicon/RISC-V/ProcessorPkg/Library/RiscVFirmwareContextSbiLib/RiscVFirmwa= reContextSbiLib.c | 52 ++++++++++++++++++++ Silicon/RISC-V/ProcessorPkg/Library/RiscVFirmwareContextSbiLib/RiscVFirmwa= reContextSbiLib.inf | 34 +++++++++++++ Silicon/RISC-V/ProcessorPkg/Library/RiscVFirmwareContextSscratchLib/RiscVF= irmwareContextSscratchLib.c | 48 ++++++++++++++++++ Silicon/RISC-V/ProcessorPkg/Library/RiscVFirmwareContextSscratchLib/RiscVF= irmwareContextSscratchLib.inf | 33 +++++++++++++ Silicon/RISC-V/ProcessorPkg/Library/RiscVFirmwareContextStvecLib/RiscVFirm= wareContextStvecLib.c | 48 ++++++++++++++++++ Silicon/RISC-V/ProcessorPkg/Library/RiscVFirmwareContextStvecLib/RiscVFirm= wareContextStvecLib.inf | 34 +++++++++++++ Silicon/RISC-V/ProcessorPkg/RiscVProcessorPkg.dec = | 1 + Silicon/RISC-V/ProcessorPkg/RiscVProcessorPkg.dsc = | 4 +- 12 files changed, 344 insertions(+), 4 deletions(-) diff --git a/Silicon/RISC-V/ProcessorPkg/Include/IndustryStandard/RiscV.h b= /Silicon/RISC-V/ProcessorPkg/Include/IndustryStandard/RiscV.h index 2a992394ed..f6726bda24 100644 --- a/Silicon/RISC-V/ProcessorPkg/Include/IndustryStandard/RiscV.h +++ b/Silicon/RISC-V/ProcessorPkg/Include/IndustryStandard/RiscV.h @@ -1,7 +1,7 @@ /** @file=0D RISC-V package definitions.=0D =0D - Copyright (c) 2019, Hewlett Packard Enterprise Development LP. All right= s reserved.
=0D + Copyright (c) 2021, Hewlett Packard Enterprise Development LP. All right= s reserved.
=0D =0D SPDX-License-Identifier: BSD-2-Clause-Patent=0D =0D @@ -96,6 +96,7 @@ #define SSTATUS_SIE_BIT_POSITION 1=0D #define SSTATUS_SPP_BIT_POSITION 8=0D #define RISCV_CSR_SUPERVISOR_SIE 0x104=0D +#define RISCV_CSR_SUPERVISOR_STVEC 0x105=0D #define RISCV_CSR_SUPERVISOR_SSCRATCH 0x140=0D #define RISCV_CSR_SUPERVISOR_SEPC 0x141=0D #define RISCV_CSR_SUPERVISOR_SCAUSE 0x142=0D diff --git a/Silicon/RISC-V/ProcessorPkg/Include/Library/RiscVCpuLib.h b/Si= licon/RISC-V/ProcessorPkg/Include/Library/RiscVCpuLib.h index f37d4c20d0..f70723567e 100644 --- a/Silicon/RISC-V/ProcessorPkg/Include/Library/RiscVCpuLib.h +++ b/Silicon/RISC-V/ProcessorPkg/Include/Library/RiscVCpuLib.h @@ -1,7 +1,7 @@ /** @file=0D RISC-V CPU library definitions.=0D =0D - Copyright (c) 2016 - 2019, Hewlett Packard Enterprise Development LP. Al= l rights reserved.
=0D + Copyright (c) 2016 - 2021, Hewlett Packard Enterprise Development LP. Al= l rights reserved.
=0D =0D SPDX-License-Identifier: BSD-2-Clause-Patent=0D **/=0D @@ -68,4 +68,16 @@ RiscVReadMachineImplementId (VOID); VOID=0D RiscVSetSupervisorAddressTranslationRegister(UINT64);=0D =0D +VOID=0D +RiscVSetSupervisorScratch (UINT64);=0D +=0D +UINT64=0D +RiscVGetSupervisorScratch (VOID);=0D +=0D +VOID=0D +RiscVSetSupervisorStvec (UINT64);=0D +=0D +UINT64=0D +RiscVGetSupervisorStvec (VOID);=0D +=0D #endif=0D diff --git a/Silicon/RISC-V/ProcessorPkg/Include/Library/RiscVFirmwareConte= xtLib.h b/Silicon/RISC-V/ProcessorPkg/Include/Library/RiscVFirmwareContextL= ib.h new file mode 100644 index 0000000000..f35c4e0c51 --- /dev/null +++ b/Silicon/RISC-V/ProcessorPkg/Include/Library/RiscVFirmwareContextLib.h @@ -0,0 +1,43 @@ +/** @file=0D + Library to get/set Firmware Context.=0D +=0D + Copyright (c) 2021, Hewlett Packard Development LP. All rights reserved.=
=0D +=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#ifndef RISCV_FIRMWARE_CONTEXT_LIB_H_=0D +#define RISCV_FIRMWARE_CONTEXT_LIB_H_=0D +=0D +#include =0D +#include =0D +=0D +/**=0D + Get pointer to OpenSBI Firmware Context=0D +=0D + Get the pointer of firmware context.=0D +=0D + @param FirmwareContextPtr Pointer to retrieve pointer to the=0D + Firmware Context.=0D +**/=0D +VOID=0D +EFIAPI=0D +GetFirmwareContextPointer (=0D + IN OUT EFI_RISCV_OPENSBI_FIRMWARE_CONTEXT **FirmwareContextPtr=0D + );=0D +=0D +/**=0D + Set pointer to OpenSBI Firmware Context=0D +=0D + Set the pointer of firmware context.=0D +=0D + @param FirmwareContextPtr Pointer to Firmware Context.=0D +**/=0D +VOID=0D +EFIAPI=0D +SetFirmwareContextPointer (=0D + IN EFI_RISCV_OPENSBI_FIRMWARE_CONTEXT *FirmwareContextPtr=0D + );=0D +=0D +#endif=0D diff --git a/Silicon/RISC-V/ProcessorPkg/Library/RiscVCpuLib/Cpu.S b/Silico= n/RISC-V/ProcessorPkg/Library/RiscVCpuLib/Cpu.S index 06ba80cb5f..e242c9b866 100644 --- a/Silicon/RISC-V/ProcessorPkg/Library/RiscVCpuLib/Cpu.S +++ b/Silicon/RISC-V/ProcessorPkg/Library/RiscVCpuLib/Cpu.S @@ -2,7 +2,7 @@ //=0D // RISC-V CPU functions.=0D //=0D -// Copyright (c) 2016 - 2020, Hewlett Packard Enterprise Development LP. A= ll rights reserved.
=0D +// Copyright (c) 2016 - 2021, Hewlett Packard Enterprise Development LP. A= ll rights reserved.
=0D //=0D // SPDX-License-Identifier: BSD-2-Clause-Patent=0D //=0D @@ -101,6 +101,38 @@ ASM_FUNC (RiscVReadMachineImplementId) csrr a0, RISCV_CSR_MACHINE_MIMPID=0D ret=0D =0D +//=0D +// Set Supervisor mode scratch.=0D +// @param a0 : Value set to Supervisor mode scratch=0D +//=0D +ASM_FUNC (RiscVSetSupervisorScratch)=0D + csrrw a1, RISCV_CSR_SUPERVISOR_SSCRATCH, a0=0D + ret=0D +=0D +//=0D +// Get Supervisor mode scratch.=0D +// @retval a0 : Value in Supervisor mode scratch=0D +//=0D +ASM_FUNC (RiscVGetSupervisorScratch)=0D + csrr a0, RISCV_CSR_SUPERVISOR_SSCRATCH=0D + ret=0D +=0D +//=0D +// Set Supervisor mode trap vector.=0D +// @param a0 : Value set to Supervisor mode trap vector=0D +//=0D +ASM_FUNC (RiscVSetSupervisorStvec)=0D + csrrw a1, RISCV_CSR_SUPERVISOR_STVEC, a0=0D + ret=0D +=0D +//=0D +// Get Supervisor mode scratch.=0D +// @retval a0 : Value in Supervisor mode trap vector=0D +//=0D +ASM_FUNC (RiscVGetSupervisorStvec)=0D + csrr a0, RISCV_CSR_SUPERVISOR_STVEC=0D + ret=0D +=0D //=0D // Set Supervisor Address Translation and=0D // Protection Register.=0D diff --git a/Silicon/RISC-V/ProcessorPkg/Library/RiscVFirmwareContextSbiLib= /RiscVFirmwareContextSbiLib.c b/Silicon/RISC-V/ProcessorPkg/Library/RiscVFi= rmwareContextSbiLib/RiscVFirmwareContextSbiLib.c new file mode 100644 index 0000000000..6125618eaf --- /dev/null +++ b/Silicon/RISC-V/ProcessorPkg/Library/RiscVFirmwareContextSbiLib/RiscVF= irmwareContextSbiLib.c @@ -0,0 +1,52 @@ +/** @file=0D + This iinstance uses RISC-V OpenSBI Firmware Extension SBI to=0D + get the pointer of firmware context.=0D +=0D + Copyright (c) 2021 Hewlett Packard Enterprise Development LP. All rights= reserved.
=0D +=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +**/=0D +=0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +=0D +/**=0D + Get pointer to OpenSBI Firmware Context=0D +=0D + Get the pointer of firmware context through OpenSBI FW Extension SBI.=0D +=0D + @param FirmwareContextPtr Pointer to retrieve pointer to the=0D + Firmware Context.=0D +**/=0D +VOID=0D +EFIAPI=0D +GetFirmwareContextPointer (=0D + IN OUT EFI_RISCV_OPENSBI_FIRMWARE_CONTEXT **FirmwareContextPtr=0D + )=0D +{=0D + SbiGetFirmwareContext (FirmwareContextPtr);=0D +}=0D +=0D +/**=0D + Set the pointer to OpenSBI Firmware Context=0D +=0D + Set the pointer of firmware context through OpenSBI FW Extension SBI.=0D +=0D + @param FirmwareContextPtr Pointer to Firmware Context.=0D +**/=0D +VOID=0D +EFIAPI=0D +SetFirmwareContextPointer (=0D + IN EFI_RISCV_OPENSBI_FIRMWARE_CONTEXT *FirmwareContextPtr=0D + )=0D +{=0D + //=0D + // We don't have to set firmware context pointer using=0D + // OpenSBI FW Extension SBI.=0D + //=0D +}=0D +=0D diff --git a/Silicon/RISC-V/ProcessorPkg/Library/RiscVFirmwareContextSbiLib= /RiscVFirmwareContextSbiLib.inf b/Silicon/RISC-V/ProcessorPkg/Library/RiscV= FirmwareContextSbiLib/RiscVFirmwareContextSbiLib.inf new file mode 100644 index 0000000000..168b705453 --- /dev/null +++ b/Silicon/RISC-V/ProcessorPkg/Library/RiscVFirmwareContextSbiLib/RiscVF= irmwareContextSbiLib.inf @@ -0,0 +1,34 @@ +## @file=0D +# Instance of OpebSBI Firmware Conext Library=0D +#=0D +# This iinstance uses RISC-V OpenSBI Firmware Extension SBI.=0D +#=0D +# Copyright (c) 2021, Hewlett Packard Enterprise Development LP. All righ= ts reserved.
=0D +#=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +##=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x0001001b=0D + BASE_NAME =3D RiscVFirmwareContextSbiLib=0D + FILE_GUID =3D 3709E048-6794-427A-B728-BFE3FFD6D461= =0D + MODULE_TYPE =3D PEIM=0D + VERSION_STRING =3D 1.0=0D + LIBRARY_CLASS =3D RiscVFirmwareContextLib|PEIM PEI_CORE= =0D +=0D +#=0D +# VALID_ARCHITECTURES =3D RISCV64=0D +#=0D +[Sources]=0D + RiscVFirmwareContextSbiLib.c=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D + Silicon/RISC-V/ProcessorPkg/RiscVProcessorPkg.dec=0D +=0D +[LibraryClasses]=0D + DebugLib=0D + RiscVCpuLib=0D + RiscVEdk2SbiLib=0D +=0D diff --git a/Silicon/RISC-V/ProcessorPkg/Library/RiscVFirmwareContextSscrat= chLib/RiscVFirmwareContextSscratchLib.c b/Silicon/RISC-V/ProcessorPkg/Libra= ry/RiscVFirmwareContextSscratchLib/RiscVFirmwareContextSscratchLib.c new file mode 100644 index 0000000000..2504e17132 --- /dev/null +++ b/Silicon/RISC-V/ProcessorPkg/Library/RiscVFirmwareContextSscratchLib/R= iscVFirmwareContextSscratchLib.c @@ -0,0 +1,48 @@ +/** @file=0D + This instance uses Supervisor mode SCRATCH CSR to get/set the=0D + pointer of firmware context.=0D +=0D + Copyright (c) 2021 Hewlett Packard Enterprise Development LP. All rights= reserved.
=0D +=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +**/=0D +=0D +#include =0D +=0D +#include =0D +=0D +#include =0D +#include =0D +=0D +/**=0D + Get pointer to OpenSBI Firmware Context=0D +=0D + Get the pointer of firmware context through Supervisor mode SCRATCH CSR.= =0D +=0D + @param FirmwareContextPtr Pointer to retrieve pointer to the=0D + Firmware Context.=0D +**/=0D +VOID=0D +EFIAPI=0D +GetFirmwareContextPointer (=0D + IN OUT EFI_RISCV_OPENSBI_FIRMWARE_CONTEXT **FirmwareContextPtr=0D + )=0D +{=0D + *FirmwareContextPtr =3D (EFI_RISCV_OPENSBI_FIRMWARE_CONTEXT *)RiscVGetSu= pervisorScratch ();=0D +}=0D +=0D +/**=0D + Set the pointer to OpenSBI Firmware Context=0D +=0D + Set the pointer of firmware context through Supervisor mode SCRATCH CSR.= =0D +=0D + @param FirmwareContextPtr Pointer to Firmware Context.=0D +**/=0D +VOID=0D +EFIAPI=0D +SetFirmwareContextPointer (=0D + IN EFI_RISCV_OPENSBI_FIRMWARE_CONTEXT *FirmwareContextPtr=0D + )=0D +{=0D + RiscVSetSupervisorScratch ((UINT64)FirmwareContextPtr);=0D +}=0D diff --git a/Silicon/RISC-V/ProcessorPkg/Library/RiscVFirmwareContextSscrat= chLib/RiscVFirmwareContextSscratchLib.inf b/Silicon/RISC-V/ProcessorPkg/Lib= rary/RiscVFirmwareContextSscratchLib/RiscVFirmwareContextSscratchLib.inf new file mode 100644 index 0000000000..750c1cf51f --- /dev/null +++ b/Silicon/RISC-V/ProcessorPkg/Library/RiscVFirmwareContextSscratchLib/R= iscVFirmwareContextSscratchLib.inf @@ -0,0 +1,33 @@ +## @file=0D +# Instance of OpebSBI Firmware Conext Library=0D +#=0D +# This instance uses RISC-V Supervisor mode SCRATCH CSR=0D +#=0D +# Copyright (c) 2021, Hewlett Packard Enterprise Development LP. All righ= ts reserved.
=0D +#=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +##=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x0001001b=0D + BASE_NAME =3D RiscVFirmwareContextSscratchLib=0D + FILE_GUID =3D 3709E048-6794-427A-B728-BFE3FFD6D461= =0D + MODULE_TYPE =3D PEIM=0D + VERSION_STRING =3D 1.0=0D + LIBRARY_CLASS =3D RiscVFirmwareContextLib|PEIM PEI_CORE= =0D +=0D +#=0D +# VALID_ARCHITECTURES =3D RISCV64=0D +#=0D +[Sources]=0D + RiscVFirmwareContextSscratchLib.c=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D + Silicon/RISC-V/ProcessorPkg/RiscVProcessorPkg.dec=0D +=0D +[LibraryClasses]=0D + DebugLib=0D + RiscVCpuLib=0D +=0D diff --git a/Silicon/RISC-V/ProcessorPkg/Library/RiscVFirmwareContextStvecL= ib/RiscVFirmwareContextStvecLib.c b/Silicon/RISC-V/ProcessorPkg/Library/Ris= cVFirmwareContextStvecLib/RiscVFirmwareContextStvecLib.c new file mode 100644 index 0000000000..7d1675355a --- /dev/null +++ b/Silicon/RISC-V/ProcessorPkg/Library/RiscVFirmwareContextStvecLib/Risc= VFirmwareContextStvecLib.c @@ -0,0 +1,48 @@ +/** @file=0D + This instance uses This iinstance Supervisor mode STVEC CSR to=0D + get/set the pointer of firmware context.=0D +=0D + Copyright (c) 2021 Hewlett Packard Enterprise Development LP. All rights= reserved.
=0D +=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +**/=0D +=0D +#include =0D +=0D +#include =0D +=0D +#include =0D +#include =0D +=0D +/**=0D + Get pointer to OpenSBI Firmware Context=0D +=0D + Get the pointer of firmware context through Supervisor mode STVEC CSR.=0D +=0D + @param FirmwareContextPtr Pointer to retrieve pointer to the=0D + Firmware Context.=0D +**/=0D +VOID=0D +EFIAPI=0D +GetFirmwareContextPointer (=0D + IN OUT EFI_RISCV_OPENSBI_FIRMWARE_CONTEXT **FirmwareContextPtr=0D + )=0D +{=0D + *FirmwareContextPtr =3D (EFI_RISCV_OPENSBI_FIRMWARE_CONTEXT *)RiscVGetSu= pervisorStvec ();=0D +}=0D +=0D +/**=0D + Set pointer to OpenSBI Firmware Context=0D +=0D + Set the pointer of firmware context through Supervisor mode STVEC CSR=0D +=0D + @param FirmwareContextPtr Pointer to Firmware Context.=0D +**/=0D +VOID=0D +EFIAPI=0D +SetFirmwareContextPointer (=0D + IN EFI_RISCV_OPENSBI_FIRMWARE_CONTEXT *FirmwareContextPtr=0D + )=0D +{=0D + RiscVSetSupervisorStvec ((UINT64)FirmwareContextPtr);=0D +}=0D diff --git a/Silicon/RISC-V/ProcessorPkg/Library/RiscVFirmwareContextStvecL= ib/RiscVFirmwareContextStvecLib.inf b/Silicon/RISC-V/ProcessorPkg/Library/R= iscVFirmwareContextStvecLib/RiscVFirmwareContextStvecLib.inf new file mode 100644 index 0000000000..fa894cda91 --- /dev/null +++ b/Silicon/RISC-V/ProcessorPkg/Library/RiscVFirmwareContextStvecLib/Risc= VFirmwareContextStvecLib.inf @@ -0,0 +1,34 @@ +## @file=0D +# Instance of OpebSBI Firmware Conext Library=0D +#=0D +# This iinstance Supervisor mode STVEC CSR=0D +#=0D +# Copyright (c) 2021, Hewlett Packard Enterprise Development LP. All righ= ts reserved.
=0D +#=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +##=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x0001001b=0D + BASE_NAME =3D RiscVFirmwareContextStvecLib=0D + FILE_GUID =3D 42DCFFAC-1DBD-4264-80A3-85CC7167AC82= =0D + MODULE_TYPE =3D PEIM=0D + VERSION_STRING =3D 1.0=0D + LIBRARY_CLASS =3D RiscVFirmwareContextLib|PEIM PEI_CORE= =0D +=0D +#=0D +# VALID_ARCHITECTURES =3D RISCV64=0D +#=0D +[Sources]=0D + RiscVFirmwareContextStvecLib.c=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D + Silicon/RISC-V/ProcessorPkg/RiscVProcessorPkg.dec=0D +=0D +[LibraryClasses]=0D + DebugLib=0D + RiscVCpuLib=0D +=0D +=0D diff --git a/Silicon/RISC-V/ProcessorPkg/RiscVProcessorPkg.dec b/Silicon/RI= SC-V/ProcessorPkg/RiscVProcessorPkg.dec index 0b64b33f0f..08279a97b1 100644 --- a/Silicon/RISC-V/ProcessorPkg/RiscVProcessorPkg.dec +++ b/Silicon/RISC-V/ProcessorPkg/RiscVProcessorPkg.dec @@ -24,6 +24,7 @@ RiscVPlatformDxeIplLib|Include/Library/RiscVPlatformDxeIpl.h=0D RiscVCpuLib|Include/Library/RiscVCpuLib.h=0D RiscVEdk2SbiLib|Include/Library/RiscVEdk2SbiLib.h=0D + RiscVFirmwareContextLib|Include/Library/RiscVFirmwareContextLib.h=0D =0D [Guids]=0D gUefiRiscVPkgTokenSpaceGuid =3D { 0x4261e9c8, 0x52c0, 0x4b34, { 0x85, 0= x3d, 0x48, 0x46, 0xea, 0xd3, 0xb7, 0x2c}}=0D diff --git a/Silicon/RISC-V/ProcessorPkg/RiscVProcessorPkg.dsc b/Silicon/RI= SC-V/ProcessorPkg/RiscVProcessorPkg.dsc index 5c5cfcb525..1292ba1bea 100644 --- a/Silicon/RISC-V/ProcessorPkg/RiscVProcessorPkg.dsc +++ b/Silicon/RISC-V/ProcessorPkg/RiscVProcessorPkg.dsc @@ -65,13 +65,14 @@ UefiLib|MdePkg/Library/UefiLib/UefiLib.inf=0D DevicePathLib|MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDev= icePathLibDevicePathProtocol.inf=0D RiscVPlatformTimerLib|Silicon/RISC-V/ProcessorPkg/Library/RiscVPlatformT= imerLibNull/RiscVPlatformTimerLib.inf=0D - PeiServicesTablePointerLib|Silicon/RISC-V/ProcessorPkg/Library/PeiServic= esTablePointerLibOpenSbi/PeiServicesTablePointerLibOpenSbi.inf=0D =0D [LibraryClasses.common.PEI_CORE]=0D PeiServicesTablePointerLib|Silicon/RISC-V/ProcessorPkg/Library/PeiServic= esTablePointerLibOpenSbi/PeiServicesTablePointerLibOpenSbi.inf=0D + RiscVFirmwareContextLib|Silicon/RISC-V/ProcessorPkg/Library/RiscVFirmwar= eContextSbiLib/RiscVFirmwareContextSbiLib.inf=0D =0D [LibraryClasses.common.PEIM]=0D PeiServicesTablePointerLib|Silicon/RISC-V/ProcessorPkg/Library/PeiServic= esTablePointerLibOpenSbi/PeiServicesTablePointerLibOpenSbi.inf=0D + RiscVFirmwareContextLib|Silicon/RISC-V/ProcessorPkg/Library/RiscVFirmwar= eContextSbiLib/RiscVFirmwareContextSbiLib.inf=0D HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf=0D MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAlloc= ationLib.inf=0D PeimEntryPoint|MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf=0D @@ -92,6 +93,7 @@ [Components]=0D Silicon/RISC-V/ProcessorPkg/Library/RiscVTimerLib/BaseRiscVTimerLib.inf= =0D Silicon/RISC-V/ProcessorPkg/Library/RiscVExceptionLib/CpuExceptionHandle= rDxeLib.inf=0D + Silicon/RISC-V/ProcessorPkg/Library/RiscVFirmwareContextSbiLib/RiscVFirm= wareContextSbiLib.inf=0D Silicon/RISC-V/ProcessorPkg/Library/PeiServicesTablePointerLibOpenSbi/Pe= iServicesTablePointerLibOpenSbi.inf=0D Silicon/RISC-V/ProcessorPkg/Library/RiscVOpensbiLib/RiscVOpensbiLib.inf= =0D Silicon/RISC-V/ProcessorPkg/Library/RiscVPlatformTimerLibNull/RiscVPlatf= ormTimerLib.inf=0D --=20 2.33.0