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.web12.2453.1648192614417752907 for ; Fri, 25 Mar 2022 00:16:54 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@hpe.com header.s=pps0720 header.b=V76jlrXk; spf=permerror, err=parse error for token &{10 18 %{ir}.%{v}.%{d}.spf.has.pphosted.com}: invalid domain name (domain: hpe.com, ip: 148.163.143.35, mailfrom: prvs=0083f32eee=abner.chang@hpe.com) Received: from pps.filterd (m0134424.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 22P6R8Ur000646; Fri, 25 Mar 2022 07:16:53 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 : mime-version; s=pps0720; bh=EZ+C92lYSxGwTr+gB7mK8NFZMMsaP78+DvUMjkRbCW4=; b=V76jlrXk4LInUi4rAXXg/BIDCuTMar8P09KtysEU0yKh3eR1MwYcY8huvs1ztYLEEmIb VH2db8QqTeB52ivdMTPhK5XifGaxvfNiMtFyb2jj7jYsrsGKkPqwmI5fFGXyqflwD6My Aw1gogfP1fdQkq9QNLBzdarX3CmX5/bxmOpEy201uIDCzweSbicJ2v+hcvP6BUyzkhBv MtsvcvagzJJRFnmrhWCz2Icd+JadQDbKa4jYYVkrMWa1PQUgHW7PpTVk0nAIO6j5oA2Y OxFhTXsLFDaw6YFcb8V6CF35TNZ7F/0/8iM/epHTGia9MaeRxaARaigyQXyijLifUzTR Ng== Received: from g4t3425.houston.hpe.com (g4t3425.houston.hpe.com [15.241.140.78]) by mx0b-002e3701.pphosted.com (PPS) with ESMTPS id 3f18fqrgaa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 25 Mar 2022 07:16:53 +0000 Received: from g4t3433.houston.hpecorp.net (g4t3433.houston.hpecorp.net [16.208.49.245]) by g4t3425.houston.hpe.com (Postfix) with ESMTP id 02A7CA1; Fri, 25 Mar 2022 07:16:53 +0000 (UTC) Received: from UB16Abner.asiapacific.hpqcorp.net (ub16abner.asiapacific.hpqcorp.net [15.119.209.229]) by g4t3433.houston.hpecorp.net (Postfix) with ESMTP id 751F146; Fri, 25 Mar 2022 07:16:51 +0000 (UTC) From: "Abner Chang" To: devel@edk2.groups.io Cc: abner.chang@hpe.com, Daniel Schaefer , Sunil V L , Leif Lindholm , Michael D Kinney , Chao Li Subject: [PATCH V2 5/8] [RFC] MdePkg/Include: Add RISC-V OpenSBI header files Date: Fri, 25 Mar 2022 14:12:46 +0800 Message-Id: <20220325061249.30626-6-abner.chang@hpe.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220325061249.30626-1-abner.chang@hpe.com> References: <20220325061249.30626-1-abner.chang@hpe.com> X-Proofpoint-GUID: TuEu2Nu9uY2khqa5P9KIm4lIYcG6x9Ul X-Proofpoint-ORIG-GUID: TuEu2Nu9uY2khqa5P9KIm4lIYcG6x9Ul X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-HPE-SCL: -1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.850,Hydra:6.0.425,FMLib:17.11.64.514 definitions=2022-03-25_02,2022-03-24_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 mlxlogscore=999 clxscore=1015 phishscore=0 impostorscore=0 bulkscore=0 adultscore=0 suspectscore=0 mlxscore=0 lowpriorityscore=0 spamscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203250039 Content-Transfer-Encoding: quoted-printable https://bugzilla.tianocore.org/show_bug.cgi?id=3D3860 RiscVOpensbiTypes.h: The header file for building RISC-V OpenSBI library. RiscVOpenSBI.h: The header file of using OpenSBI library. Signed-off-by: Abner Chang Co-authored-by: Daniel Schaefer M: Liming Gao [lgao4] R: Zhiguang Liu [LiuZhiguang001] Cc: Sunil V L Cc: Leif Lindholm Cc: Michael D Kinney Cc: Chao Li --- .../Include/IndustryStandard/RiscVOpensbi.h | 62 ++++++++++++++ .../IndustryStandard/RiscVOpensbiTypes.h | 82 +++++++++++++++++++ MdePkg/MdePkg.ci.yaml | 2 + 3 files changed, 146 insertions(+) create mode 100644 MdePkg/Include/IndustryStandard/RiscVOpensbi.h create mode 100644 MdePkg/Include/IndustryStandard/RiscVOpensbiTypes.h diff --git a/MdePkg/Include/IndustryStandard/RiscVOpensbi.h b/MdePkg/Includ= e/IndustryStandard/RiscVOpensbi.h new file mode 100644 index 0000000000..4c9186f212 --- /dev/null +++ b/MdePkg/Include/IndustryStandard/RiscVOpensbi.h @@ -0,0 +1,62 @@ +/** @file=0D + SBI inline function calls.=0D +=0D + Copyright (c) 2022, Hewlett Packard Enterprise Development LP. All right= s reserved.
=0D +=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#ifndef EDK2_RISC_V_SBI_H_=0D +#define EDK2_RISC_V_SBI_H_=0D +=0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +=0D +#define RISC_V_MAX_HART_SUPPORTED SBI_HARTMASK_MAX_BITS=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 + UINT64 BootHartId;=0D + VOID *PeiServiceTable; // PEI = Service table=0D + UINT64 FlattenedDeviceTree; // Poin= ter to Flattened Device tree=0D + UINT64 SecPeiHandOffData; // This= is EFI_SEC_PEI_HAND_OFF passed to PEI Core.=0D + EFI_RISCV_FIRMWARE_CONTEXT_HART_SPECIFIC *HartSpecific[RISC_V_MAX_HAR= T_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/MdePkg/Include/IndustryStandard/RiscVOpensbiTypes.h b/MdePkg/I= nclude/IndustryStandard/RiscVOpensbiTypes.h new file mode 100644 index 0000000000..6a6a1f532d --- /dev/null +++ b/MdePkg/Include/IndustryStandard/RiscVOpensbiTypes.h @@ -0,0 +1,82 @@ +/** @file=0D + RISC-V OpenSBI header file reference.=0D +=0D + Copyright (c) 2022, Hewlett Packard Enterprise Development LP. All right= s reserved.
=0D +=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#ifndef EDK2_RISC_V_SBI_TYPES_H_=0D +#define EDK2_RISC_V_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 true TRUE=0D +#define false FALSE=0D +=0D +#define __packed __attribute__((packed))=0D +#define __noreturn __attribute__((noreturn))=0D +#define __aligned(x) __attribute__((aligned(x)))=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 array_size(x) (sizeof(x) / sizeof((x)[0]))=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 diff --git a/MdePkg/MdePkg.ci.yaml b/MdePkg/MdePkg.ci.yaml index 054233ebc7..7c05fb913f 100644 --- a/MdePkg/MdePkg.ci.yaml +++ b/MdePkg/MdePkg.ci.yaml @@ -50,6 +50,8 @@ "Include/IndustryStandard/Tpm20.h",=0D "Include/IndustryStandard/IoRemappingTable.h",=0D "Include/IndustryStandard/UefiTcgPlatform.h",=0D + "Include/IndustryStandard/RiscVOpensbi.h",=0D + "Include/IndustryStandard/RiscVOpensbiTypes.h",=0D "Include/Library/PcdLib.h",=0D "Include/Library/SafeIntLib.h",=0D "Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c"=0D --=20 2.31.1