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.web10.1226.1590771999701679761 for ; Fri, 29 May 2020 10:06:39 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: hpe.com, ip: 148.163.147.86, mailfrom: prvs=041837a23b=daniel.schaefer@hpe.com) Received: from pps.filterd (m0150242.ppops.net [127.0.0.1]) by mx0a-002e3701.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 04TH3T7f011341; Fri, 29 May 2020 17:06:39 GMT Received: from g9t5008.houston.hpe.com (g9t5008.houston.hpe.com [15.241.48.72]) by mx0a-002e3701.pphosted.com with ESMTP id 31arnjetes-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 29 May 2020 17:06:39 +0000 Received: from G9W8456.americas.hpqcorp.net (exchangepmrr1.us.hpecorp.net [16.216.161.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by g9t5008.houston.hpe.com (Postfix) with ESMTPS id BBD7756; Fri, 29 May 2020 17:06:38 +0000 (UTC) Received: from G4W9119.americas.hpqcorp.net (2002:10d2:14d6::10d2:14d6) by G9W8456.americas.hpqcorp.net (2002:10d8:a15f::10d8:a15f) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 29 May 2020 17:06:38 +0000 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (15.241.52.13) by G4W9119.americas.hpqcorp.net (16.210.20.214) with Microsoft SMTP Server (TLS) id 15.0.1497.2 via Frontend Transport; Fri, 29 May 2020 17:06:38 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Zz6GdwGhakwTADpCS4bgp0vhdez5CY9MuOZyZ5LrNBFLRifsIINnsVuoWAgeJZgJSQEdlPPmsrA3bXrhFsevaEuBh+IrmnFqUnDVQ9ocqBTJX/VtPkCYKmIr6ayFmXBppSCiQ+me3KmUGv3R/0Nnqgztbb1H9DQOgW5Qiv9YsUtEPcTop5FP8KcZ36g2y+MiZaFNt/hGb9aqk/CaVEenH4CQrpWDYTt8Qmah87Zu5ztX6gdss41x206Nd3OHkOb1zkvM5EyMwaLaDienFTMZ9uI4o5m1UzQ70nHJAFOhN4Ws5pxXmGf+HhRGFHKbc3/Gf5EVsajTSbFADBfrinhZvw== 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=IoKHwfpxVuFMWrDxoP5P8iOwJoDRlnm26lQeS6Uikg8=; b=HYiwoEOhmnK0wId2zm7KX/PzBB7KEalDQTpT5KGHWB336DySFc9tpe+FIbloOjarrgKDNUpK83/Hx3PlzBrAC74y83Q54n4S/6D4KRci8zGZoC/2WlWxfxlRkNN6e+q5gy7KmVltwszxcmQgrxiCcgD1yBwFtTzgP5k4aEu0CTEVSUk/INP/z9WINhpdJp597hBn0c40QkTY27wy87t3uYMPTh5gbZTJEk3EQrwMejaBWfoFKMVCp+D3YHQQ9SKUnV32qj068RYbLa14t3LEGTOlLQYgbnE/AgrUg9ZjIbmU8U4KN/8en7NJuCChOstDZlaXZ9C8KZYAjWf+zGkFWQ== 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 DF4PR8401MB0474.NAMPRD84.PROD.OUTLOOK.COM (2a01:111:e400:7607::10) by DF4PR8401MB0441.NAMPRD84.PROD.OUTLOOK.COM (2a01:111:e400:7607::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3045.19; Fri, 29 May 2020 17:06:37 +0000 Received: from DF4PR8401MB0474.NAMPRD84.PROD.OUTLOOK.COM ([fe80::c4c5:a5a7:6deb:da30]) by DF4PR8401MB0474.NAMPRD84.PROD.OUTLOOK.COM ([fe80::c4c5:a5a7:6deb:da30%9]) with mapi id 15.20.3021.030; Fri, 29 May 2020 17:06:37 +0000 From: "Daniel Schaefer" To: CC: Gilbert Chen , Leif Lindholm , Abner Chang , Michael D Kinney Subject: [PATCH v3 2/3] ProcessorPkg/Library: Add RiscVOpensbiLib Date: Fri, 29 May 2020 19:06:21 +0200 Message-ID: <20200529170622.32610-3-daniel.schaefer@hpe.com> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200529170622.32610-1-daniel.schaefer@hpe.com> References: <20200529170622.32610-1-daniel.schaefer@hpe.com> X-ClientProxiedBy: AM0PR10CA0057.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::37) To DF4PR8401MB0474.NAMPRD84.PROD.OUTLOOK.COM (2a01:111:e400:7607::10) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from x360-nix.fritz.box (93.215.216.32) by AM0PR10CA0057.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3045.17 via Frontend Transport; Fri, 29 May 2020 17:06:35 +0000 X-Mailer: git-send-email 2.26.1 X-Originating-IP: [93.215.216.32] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 1abdf59d-5c1e-47ec-460f-08d803f2a577 X-MS-TrafficTypeDiagnostic: DF4PR8401MB0441: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-Forefront-PRVS: 04180B6720 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: J3Ijb/MZFKZydISS1kx/1PSjgIEH9UsjNfNn/vleGP/KRZcyumbzZ8IARp3GkbOYCuq+4B2sojA9TMkGoGzCRepkJ70EB4U4EZCMWDMQ83LFmhZ6UfPhnsNl+AvcgZ8lkHQ9W7CgML7hmAI5tIHiMBgjj0lsOl07WEbRAhx9aKeDr3M8tPxRdLHOri2h7ZcRdqnsSLbD/e4FtmQNH4bBudPO/KfIxNRZRlrI24FQaRSOwEeseCANsKzBba/prijlncj+DnDI3U8EYT2a390UItxaNEhYTCgJGp0pFvY+WDxC7u8Z9vSnicuY+sptqOqm5foJs6zlwRy+jzdO4tFQ8TXhVzHpz+ufhUefX8eSl0PRmBHtyLVb7q5pgW8dYR1E X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DF4PR8401MB0474.NAMPRD84.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFTY:;SFS:(346002)(136003)(39860400002)(376002)(396003)(366004)(52116002)(186003)(16526019)(316002)(54906003)(6916009)(478600001)(5660300002)(83380400001)(2906002)(956004)(2616005)(6486002)(44832011)(8936002)(6666004)(1076003)(36756003)(4326008)(6512007)(86362001)(6506007)(8676002)(26005)(66556008)(66476007)(66946007)(145603002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData: OxeGcAC+2W8dX05+xXpL3yx4SHNxLjJO17Wi8CPwfj4cS+5VwzjNDFiivKO++BNC2Z6Vojyb2o9B6Az9oJmgFAloHX3QInyNo2MTc+AOojwVqx1LS6DBDpgBew8ZsQ0LLLEastHMwZK6KSCYTYchn+ot5X6cWk1o9KtG4Vm2e4E1kgn92rhqyfKcHqEwII5EVeghjb/GrRGgTtovoATPT7jSLf05yOgPRTKGSo7mfG1vNN8GDay4iSDGznB+DQmNtpIpKczcYkAHRMLf48+Ay7loPQvNvwnUoQZapddBRgRMGxVTzPKChIgtXDTZCqkGaA+TUTssES5PskjhK+9W5XydOmPgGtu5adhJGQwPQlZksKEH/d3g691DHHfQH9qpce15svjUWkz5JBQ2tzC79Q4Lxk+YzvT5ugPks6xr1jKN4QyD+5bsgmCAOcARr9/TEgVJgc1v7iYdwN4SDxsjRoqMdUPMXnmBd6h3KVa4kIwMf/4NUZeyonuHmaUNGZuF X-MS-Exchange-CrossTenant-Network-Message-Id: 1abdf59d-5c1e-47ec-460f-08d803f2a577 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 May 2020 17:06:36.9210 (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: sJ1E9xh0bhGsHTWjvrPPbC9hFOiIlXR0dW8gDUG0lvm1/AZHXtDHNm0SgOlQ0qWdRtlyw1G7AgWqRJwwQBS7aw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DF4PR8401MB0441 X-OriginatorOrg: hpe.com X-HPE-SCL: -1 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216,18.0.687 definitions=2020-05-29_08:2020-05-28,2020-05-29 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxlogscore=999 spamscore=0 clxscore=1015 mlxscore=0 suspectscore=4 impostorscore=0 adultscore=0 priorityscore=1501 bulkscore=0 malwarescore=0 lowpriorityscore=0 cotscore=-2147483648 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2005290130 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: Abner Chang Co-authored-by: Daniel Schaefer Co-authored-by: Gilbert Chen Reviewed-by: Leif Lindholm Cc: Leif Lindholm Cc: Gilbert Chen Cc: Abner Chang Cc: Daniel Schaefer Cc: Michael D Kinney --- Silicon/RISC-V/ProcessorPkg/Library/RiscVOpensbiLib/RiscVOpensbiLib.inf | = 52 +++++++++++++ Silicon/RISC-V/ProcessorPkg/Include/IndustryStandard/RiscVOpensbi.h | = 81 ++++++++++++++++++++ Silicon/RISC-V/ProcessorPkg/Include/OpensbiTypes.h | = 75 ++++++++++++++++++ 3 files changed, 208 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..14e29dc0aa62 --- /dev/null +++ b/Silicon/RISC-V/ProcessorPkg/Library/RiscVOpensbiLib/RiscVOpensbiLib.i= nf @@ -0,0 +1,52 @@ +## @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 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..7d3b4a371c2d --- /dev/null +++ b/Silicon/RISC-V/ProcessorPkg/Include/IndustryStandard/RiscVOpensbi.h @@ -0,0 +1,81 @@ +/** @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 =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +=0D +// Translation from OpenSBI constants to SBI names=0D +#define SBI_SUCCESS SBI_OK=0D +#define SBI_ERR_FAILED SBI_EFAIL=0D +#define SBI_ERR_NOT_SUPPORTED SBI_ENOTSUPP=0D +#define SBI_ERR_INVALID_PARAM SBI_EINVAL=0D +#define SBI_ERR_DENIED SBI_DENIED=0D +#define SBI_ERR_INVALID_ADDRESS SBI_INVALID_ADDR=0D +// Currently improperly defined in upstream OpenSBI=0D +#define SBI_ERR_ALREADY_AVAILABLE -6=0D +=0D +// Included in OpenSBI 0.7=0D +// Can be removed, once we upgrade=0D +#define SBI_EXT_HSM 0x48534D=0D +#define SBI_EXT_HSM_HART_START 0x0=0D +#define SBI_EXT_HSM_HART_STOP 0x1=0D +#define SBI_EXT_HSM_HART_GET_STATUS 0x2=0D +=0D +//=0D +// Below two definitions should be defined in OpenSBI.=0D +// Submitted to upstream, waiting for merge and release.=0D +//=0D +#define SBI_EXT_FIRMWARE_CODE_BASE_START 0x0A000000=0D +#define SBI_EXT_FIRMWARE_CODE_BASE_END 0x0AFFFFFF=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 +//=0D +// Typedefs of OpenSBI type to make them conform to EDK2 coding guidelines= =0D +//=0D +typedef struct sbi_scratch SBI_SCRATCH;=0D +typedef struct sbi_platform SBI_PLATFORM;=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..7f85d28193e1 --- /dev/null +++ b/Silicon/RISC-V/ProcessorPkg/Include/OpensbiTypes.h @@ -0,0 +1,75 @@ +/** @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 +#include =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 +// PRILX is not used in EDK2 but we need to define it here because when=0D +// defining our own types, this constant is not defined but used by OpenSB= I.=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 +#if defined(__GNUC__) || defined(__clang__)=0D + #define likely(x) __builtin_expect((x), 1)=0D + #define unlikely(x) __builtin_expect((x), 0)=0D +#else=0D + #define likely(x) (x)=0D + #define unlikely(x) (x)=0D +#endif=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