From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-002e3701.pphosted.com (mx0a-002e3701.pphosted.com [148.163.147.86]) by mx.groups.io with SMTP id smtpd.web11.1477.1589217636069651951 for ; Mon, 11 May 2020 10:20:36 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: hpe.com, ip: 148.163.147.86, mailfrom: prvs=0400127891=daniel.schaefer@hpe.com) Received: from pps.filterd (m0134422.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 04BH70dH002375; Mon, 11 May 2020 17:20:35 GMT Received: from g9t5009.houston.hpe.com (g9t5009.houston.hpe.com [15.241.48.73]) by mx0b-002e3701.pphosted.com with ESMTP id 30x6nst9mj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 11 May 2020 17:20:35 +0000 Received: from G4W9120.americas.hpqcorp.net (g4w9120.houston.hp.com [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 ED1C165; Mon, 11 May 2020 17:20:34 +0000 (UTC) Received: from G2W6309.americas.hpqcorp.net (2002:10c5:4033::10c5:4033) by G4W9120.americas.hpqcorp.net (2002:10d2:150f::10d2:150f) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 11 May 2020 17:20:34 +0000 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (15.241.52.11) by G2W6309.americas.hpqcorp.net (16.197.64.51) with Microsoft SMTP Server (TLS) id 15.0.1497.2 via Frontend Transport; Mon, 11 May 2020 17:20:35 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FgN0h9bUs1eWubDnxFRKhvoB2llP+Li7b0CjKqayJeJsWXaOpV6WrqNzlAsMtMQTgZv8R8GLKHgJLKNo+zGHmxKINfIcCsMPPjmflIw5Hz+DinZainZ2tmJxyVrsIuTFtLWzTiVmJO3zKVxmjonW5BNazw1kjPar1fUZcv6GNwWiUDSQY6j2ozVbqVomVQVjXCrZvrd/cnbzOr1YMWz9j5nfDamDZzFpR5y4uEgWmtQPUO1tllxRYONJEyQILpVx1Y5jILDYPwCsDUBjDRNYmyFmvQSzBdfw7vEwrcKZxS0QnuAAslilF+2xRa49/s/MXIY8yaW/iaDhpfiFjndoUg== 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-SenderADCheck; bh=yNwypKydeoLJ9MHS5n5ZByln473VdzqcxuwEi9GyKNQ=; b=gd8wQqAPeK1YI5kITBPWwFSM4Fxi7rGw6yzuXePULXNKZuYBZWEUKgWJZZX0ahDZAHPcS05nm31qqW4H4t7U18f33SVSITMI59BcAHL9ulaScbl0VELQrr01TxdqQ1D8/uL2rHmgOhfDKqigKT1Zj4l17ZJE+wFLl4FApD4Bc1akNpr/oOjaH/9ZfGr4oqMqduwbkVmfbrxProLk1BlrNmkUP8bdFN9o9Q/p8csrHuD/KbZYMm3y0IQZUVC01hyFESEOe7pEga3f83672oz8QZE3/HjtLT1GRV8nEHLXirfN23aBuFDPOJBxPtq/Ay2QIX+EVjvr/m6KVbgySv1cWQ== 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 CS1PR8401MB0726.NAMPRD84.PROD.OUTLOOK.COM (2a01:111:e400:750c::23) by CS1PR8401MB1224.NAMPRD84.PROD.OUTLOOK.COM (2a01:111:e400:7507::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.28; Mon, 11 May 2020 17:20:33 +0000 Received: from CS1PR8401MB0726.NAMPRD84.PROD.OUTLOOK.COM ([fe80::940c:db10:af3c:c3f5]) by CS1PR8401MB0726.NAMPRD84.PROD.OUTLOOK.COM ([fe80::940c:db10:af3c:c3f5%4]) with mapi id 15.20.2979.033; Mon, 11 May 2020 17:20:33 +0000 From: "Daniel Schaefer" To: CC: Abner Chang , Gilbert Chen , Leif Lindholm , Leif Lindholm , Michael D Kinney Subject: [platform/devel-riscvplatforms PATCHv1 2/2] ProcessorPkg/Library: Add EDK2 RISC-V OpenSBI library. Date: Mon, 11 May 2020 19:20:15 +0200 Message-ID: <20200511172015.5139-3-daniel.schaefer@hpe.com> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200511172015.5139-1-daniel.schaefer@hpe.com> References: <20200511172015.5139-1-daniel.schaefer@hpe.com> X-ClientProxiedBy: AM0PR01CA0078.eurprd01.prod.exchangelabs.com (2603:10a6:208:10e::19) To CS1PR8401MB0726.NAMPRD84.PROD.OUTLOOK.COM (2a01:111:e400:750c::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from x360-nix.fritz.box (2001:16b8:5765:4200:25c4:7680:e129:dab4) by AM0PR01CA0078.eurprd01.prod.exchangelabs.com (2603:10a6:208:10e::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.28 via Frontend Transport; Mon, 11 May 2020 17:20:31 +0000 X-Mailer: git-send-email 2.26.1 X-Originating-IP: [2001:16b8:5765:4200:25c4:7680:e129:dab4] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 4467fe45-7226-4ff5-6993-08d7f5cf9c96 X-MS-TrafficTypeDiagnostic: CS1PR8401MB1224: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3276; X-Forefront-PRVS: 04004D94E2 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AIVED5ixfTGnbUUtYM4PiFRh2wE1XBD5Pct8V1XKXRH09iXagENxVGLcUyGWQJgBEoXvaJnW7Uu8n3Q1UK8S7rle6NIt242qAWza1qQXfez5KTf4xcr2hxXGCwjqmzeHfi5sAPOKXqR2I02lTC0LgZFZZw0kYEH9n0r0dBw7pX4vmzXY1r6QnOylCCDzjwLrH/oEjoXjkXkPRruWlgKka9tPmG6wUbIToLtcwa5fSspnh8NH5jxaq1bzXgMfiFlkdYFFoDmPnl97VEZufsftXQa11ux+3a1ten8gHotHD37ZMNnlMxAxaN6fO6lPGuWsuNA9pPsra+0YkKjuK2ZDgLllWPkqGyRk7ltKPo0/6qdvT3RLis6tMDfign4ClDJnMF/j1G7UmuPl4gLfmpyJ86hTER2OVdiBWQZRmiui8/Mi1zcKSfMT93FRhwDqH8J9MVVMKsDaCznHGPurSNUgfSZev0IXuJ3CgE2Qh0u0p7/xURnXLkrsJTTQ0Ao0+be3SFcd2vru/BhqswNMz4DsHw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CS1PR8401MB0726.NAMPRD84.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFTY:;SFS:(376002)(396003)(346002)(39860400002)(366004)(136003)(33430700001)(6512007)(2616005)(6486002)(478600001)(316002)(1076003)(4326008)(186003)(16526019)(86362001)(66946007)(8676002)(33440700001)(6666004)(6506007)(6916009)(66556008)(66476007)(2906002)(52116002)(36756003)(54906003)(44832011)(5660300002)(8936002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData: BulwcMwRBwl86CTZ5pCdBq5F1HWnPvw9yzx/R02bxxcgVUGxAjgx+teqzcFxseGK5WBMJuSto6o7QR5YYy42tJZhHtHBRSIqwWWujU+kEAt1NAqv57gzJEVDbse3S/QKrznXLHlzuLxHo9LDozatbkGOFYOh1XVgHSGvnKF1SFx34sBDzjQAII07WDJEoo1iBKDAKu/CVtNyzEuhLiqGN/vKxbbeuT2PezlEL3uqiKukCNCyICW7SdWQrm5vFVEF1Hi9JbmG1emA7BN42hN+FTfXdp0Y2+jfW+e36HAR5r+kF9CW0gHNqQMpCQsdjqzhiJJUXD2sy3ffXntEKs+9nR6kOPEQjVP6mTBiENCNPJruFtY7feSuikZQC0BbkIUrpFMS4K/23Scp6Wshaa84s04MtkSdhw35ngNWHzlnXi78A3bua1LZgUuAe8voHKoE0hpzdfy4zk06asyWQ8OK8+bFsEaTi6ZRlT41eJGa1OaK6+WqzjRldRBbFrPjTHSitXX5tYAl+UygbstOP5VNneQ1CffEsajymu0b/yoE8IYmxevFcsUC3dzzysL2NHSM X-MS-Exchange-CrossTenant-Network-Message-Id: 4467fe45-7226-4ff5-6993-08d7f5cf9c96 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 May 2020 17:20:33.3311 (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: QHPA0SyX19rtuODkBgZ9mSjcEaJZlRh+7puSyfDKio0zvG/gNyl7f66FoQ7Uyv+2ddnrMO5nLgjHenDbrTbF3A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CS1PR8401MB1224 X-OriginatorOrg: hpe.com X-HPE-SCL: -1 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216,18.0.676 definitions=2020-05-11_08:2020-05-11,2020-05-11 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 suspectscore=43 phishscore=0 mlxlogscore=999 spamscore=0 impostorscore=0 adultscore=0 priorityscore=1501 lowpriorityscore=0 mlxscore=0 bulkscore=0 clxscore=1011 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2005110135 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain EDK2 RISC-V OpenSBI library which pull in external source files under RISC-V/ProcessorPkg/Library/RiscVOpensbiLib/opensbi to the build process. Signed-off-by: Daniel Schaefer Co-authored-by: Abner Chang Co-authored-by: Gilbert Chen Reviewed-by: Leif Lindholm Cc: Leif Lindholm Cc: Gilbert Chen Cc: Michael D Kinney --- Silicon/RISC-V/ProcessorPkg/Library/RiscVOpensbiLib/RiscVOpensbiLib.inf | = 60 +++++++++++++++ Silicon/RISC-V/ProcessorPkg/Include/IndustryStandard/RiscVOpensbi.h | = 79 ++++++++++++++++++++ Silicon/RISC-V/ProcessorPkg/Include/OpensbiTypes.h | = 66 ++++++++++++++++ 3 files changed, 205 insertions(+) diff --git a/Silicon/RISC-V/ProcessorPkg/Library/RiscVOpensbiLib/RiscVOpens= biLib.inf b/Silicon/RISC-V/ProcessorPkg/Library/RiscVOpensbiLib/RiscVOpensb= iLib.inf new file mode 100644 index 000000000000..59dbd67d8e03 --- /dev/null +++ b/Silicon/RISC-V/ProcessorPkg/Library/RiscVOpensbiLib/RiscVOpensbiLib.i= nf @@ -0,0 +1,60 @@ +## @file=0D +# RISC-V Opensbi Library Instance.=0D +#=0D +# Copyright (c) 2020, 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 RiscVOpensbiLib=0D + FILE_GUID =3D 6EF0C812-66F6-11E9-93CE-3F5D5F0DF0A7=0D + MODULE_TYPE =3D BASE=0D + VERSION_STRING =3D 1.0=0D + LIBRARY_CLASS =3D RiscVOpensbiLib=0D +=0D +[Sources]=0D + opensbi/lib/sbi/riscv_asm.c=0D + opensbi/lib/sbi/riscv_atomic.c=0D + opensbi/lib/sbi/riscv_hardfp.S=0D + opensbi/lib/sbi/riscv_locks.c=0D + opensbi/lib/sbi/sbi_console.c=0D + opensbi/lib/sbi/sbi_ecall.c=0D + opensbi/lib/sbi/sbi_ecall_vendor.c=0D + opensbi/lib/sbi/sbi_ecall_replace.c=0D + opensbi/lib/sbi/sbi_ecall_legacy.c=0D + opensbi/lib/sbi/sbi_ecall_base.c=0D + opensbi/lib/sbi/sbi_emulate_csr.c=0D + opensbi/lib/sbi/sbi_fifo.c=0D + opensbi/lib/sbi/sbi_hart.c=0D + opensbi/lib/sbi/sbi_hfence.S=0D + opensbi/lib/sbi/sbi_illegal_insn.c=0D + opensbi/lib/sbi/sbi_init.c=0D + opensbi/lib/sbi/sbi_ipi.c=0D + opensbi/lib/sbi/sbi_misaligned_ldst.c=0D + opensbi/lib/sbi/sbi_scratch.c=0D + opensbi/lib/sbi/sbi_string.c=0D + opensbi/lib/sbi/sbi_system.c=0D + opensbi/lib/sbi/sbi_timer.c=0D + opensbi/lib/sbi/sbi_tlb.c=0D + opensbi/lib/sbi/sbi_trap.c=0D + opensbi/lib/sbi/sbi_unpriv.c=0D + opensbi/lib/utils/sys/clint.c=0D + opensbi/lib/utils/irqchip/plic.c=0D + opensbi/lib/utils/serial/sifive-uart.c=0D + opensbi/lib/utils/serial/uart8250.c=0D +=0D +[Packages]=0D + EmbeddedPkg/EmbeddedPkg.dec # For libfdt.=0D + MdePkg/MdePkg.dec=0D + Silicon/RISC-V/ProcessorPkg/RiscVProcessorPkg.dec=0D +=0D +[LibraryClasses]=0D + BaseLib=0D + PcdLib=0D + RiscVCpuLib=0D +=0D +=0D +=0D diff --git a/Silicon/RISC-V/ProcessorPkg/Include/IndustryStandard/RiscVOpen= sbi.h b/Silicon/RISC-V/ProcessorPkg/Include/IndustryStandard/RiscVOpensbi.h new file mode 100644 index 000000000000..c5c0bd6d9b01 --- /dev/null +++ b/Silicon/RISC-V/ProcessorPkg/Include/IndustryStandard/RiscVOpensbi.h @@ -0,0 +1,79 @@ +/** @file=0D + SBI inline function calls.=0D +=0D + Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All right= s reserved.
=0D +=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#ifndef EDK2_SBI_H_=0D +#define EDK2_SBI_H_=0D +=0D +#include // Reference to header file in opensbi= =0D +#include =0D +#include // Reference to header file wrapper=0D +=0D +#define SBI_SUCCESS 0=0D +#define SBI_ERR_FAILED -1=0D +#define SBI_ERR_NOT_SUPPORTED -2=0D +#define SBI_ERR_INVALID_PARAM -3=0D +#define SBI_ERR_DENIED -4=0D +#define SBI_ERR_INVALID_ADDRESS -5=0D +#define SBI_ERR_ALREADY_AVAILABLE -6=0D +=0D +#define SBI_BASE_EXT 0x10=0D +#define SBI_HSM_EXT 0x48534D=0D +#define SBI_TIME_EXT 0x54494D45=0D +#define SBI_IPI_EXT 0x735049=0D +#define SBI_RFNC_EXT 0x52464E43=0D +=0D +//=0D +// Below two definitions should be defined in OpenSBI.=0D +//=0D +#define SBI_EXT_FIRMWARE_CODE_BASE_START 0x0A000000=0D +#define SBI_EXT_FIRMWARE_CODE_BASE_END 0x0AFFFFFF=0D +=0D +#define SBI_GET_SPEC_VERSION_FUNC 0=0D +#define SBI_GET_IMPL_ID_FUNC 1=0D +#define SBI_GET_IMPL_VERSION_FUNC 2=0D +#define SBI_PROBE_EXTENSION_FUNC 3=0D +#define SBI_GET_MVENDORID_FUNC 4=0D +#define SBI_GET_MARCHID_FUNC 5=0D +#define SBI_GET_MIMPID_FUNC 6=0D +=0D +#define SBI_HART_START_FUNC 0=0D +#define SBI_HART_STOP_FUNC 1=0D +#define SBI_HART_GET_STATUS_FUNC 2=0D +=0D +#define RISC_V_MAX_HART_SUPPORTED 16=0D +=0D +typedef=0D +VOID=0D +(EFIAPI *RISCV_HART_SWITCH_MODE)(=0D + IN UINTN FuncArg0,=0D + IN UINTN FuncArg1,=0D + IN UINTN NextAddr,=0D + IN UINTN NextMode,=0D + IN BOOLEAN NextVirt=0D + );=0D +=0D +//=0D +// Keep the structure member in 64-bit alignment.=0D +//=0D +typedef struct {=0D + UINT64 IsaExtensionSupported; // The ISA extension th= is core supported.=0D + RISCV_UINT128 MachineVendorId; // Machine vendor ID=0D + RISCV_UINT128 MachineArchId; // Machine Architecture= ID=0D + RISCV_UINT128 MachineImplId; // Machine Implementati= on ID=0D + RISCV_HART_SWITCH_MODE HartSwitchMode; // OpenSBI's function t= o switch the mode of a hart=0D +} EFI_RISCV_FIRMWARE_CONTEXT_HART_SPECIFIC;=0D +#define FIRMWARE_CONTEXT_HART_SPECIFIC_SIZE (64 * 8) // This is the size = of EFI_RISCV_FIRMWARE_CONTEXT_HART_SPECIFIC=0D + // structure. Referr= ed by both C code and assembly code.=0D +=0D +typedef struct {=0D + VOID *PeiServiceTable; // PEI Service table=0D + EFI_RISCV_FIRMWARE_CONTEXT_HART_SPECIFIC *HartSpecific[RISC_V_MAX_HART_= SUPPORTED];=0D +} EFI_RISCV_OPENSBI_FIRMWARE_CONTEXT;=0D +=0D +#endif=0D diff --git a/Silicon/RISC-V/ProcessorPkg/Include/OpensbiTypes.h b/Silicon/R= ISC-V/ProcessorPkg/Include/OpensbiTypes.h new file mode 100644 index 000000000000..3964bf00ea88 --- /dev/null +++ b/Silicon/RISC-V/ProcessorPkg/Include/OpensbiTypes.h @@ -0,0 +1,66 @@ +/** @file=0D + RISC-V OpesbSBI header file reference.=0D +=0D + Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All right= s reserved.
=0D +=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +#ifndef EDK2_SBI_TYPES_H_=0D +#define EDK2_SBI_TYPES_H_=0D +=0D +typedef INT8 s8;=0D +typedef UINT8 u8;=0D +typedef UINT8 uint8_t;=0D +=0D +typedef INT16 s16;=0D +typedef UINT16 u16;=0D +typedef INT16 int16_t;=0D +typedef UINT16 uint16_t;=0D +=0D +typedef INT32 s32;=0D +typedef UINT32 u32;=0D +typedef INT32 int32_t;=0D +typedef UINT32 uint32_t;=0D +=0D +typedef INT64 s64;=0D +typedef UINT64 u64;=0D +typedef INT64 int64_t;=0D +typedef UINT64 uint64_t;=0D +=0D +#define PRILX "016lx"=0D +=0D +typedef BOOLEAN bool;=0D +typedef unsigned long ulong;=0D +typedef UINT64 uintptr_t;=0D +typedef UINT64 size_t;=0D +typedef INT64 ssize_t;=0D +typedef UINT64 virtual_addr_t;=0D +typedef UINT64 virtual_size_t;=0D +typedef UINT64 physical_addr_t;=0D +typedef UINT64 physical_size_t;=0D +=0D +#define __packed __attribute__((packed))=0D +#define __noreturn __attribute__((noreturn))=0D +=0D +#define likely(x) __builtin_expect((x), 1)=0D +#define unlikely(x) __builtin_expect((x), 0)=0D +=0D +#undef offsetof=0D +#ifdef __compiler_offsetof=0D +#define offsetof(TYPE, MEMBER) __compiler_offsetof(TYPE,MEMBER)=0D +#else=0D +#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)=0D +#endif=0D +=0D +#define container_of(ptr, type, member) ({ \=0D + const typeof(((type *)0)->member) * __mptr =3D (ptr); \=0D + (type *)((char *)__mptr - offsetof(type, member)); })=0D +=0D +#define CLAMP(a, lo, hi) MIN(MAX(a, lo), hi)=0D +#define ROUNDUP(a, b) ((((a)-1) / (b) + 1) * (b))=0D +#define ROUNDDOWN(a, b) ((a) / (b) * (b))=0D +=0D +/* clang-format on */=0D +=0D +#endif=0D --=20 2.26.1