From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) by mx.groups.io with SMTP id smtpd.web12.4219.1589239044143719089 for ; Mon, 11 May 2020 16:17:24 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@nuviainc-com.20150623.gappssmtp.com header.s=20150623 header.b=XVgrEH9n; spf=pass (domain: nuviainc.com, ip: 209.85.221.47, mailfrom: leif@nuviainc.com) Received: by mail-wr1-f47.google.com with SMTP id l18so13047597wrn.6 for ; Mon, 11 May 2020 16:17:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nuviainc-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=aXR90ibTegE6IzP48RCUTtt/H281gHVRJ1k4zPa6mD8=; b=XVgrEH9nlApCetAKL4MRRK6Y9p9PL9iUztns0D0XESVJJPXqNi5j05YMOaqISyRZ+w 2cSrkKIY7J2qdO3rdOnMDe0tbkrGrcNN4OPftz9T9tJ8V5KqS+rfAZHn7HL1IpPhGbgl dka1+W9yosC0RgBtY6a9mmZ7bFSIYXFlVMCu8N3IJqB3DVXrpD2cyy40y0jStqo4rSvP BiuT6TjEjL6t+tQT5niTU7Y8hEE70vgXp9EOxdMU/8PlJfGv0N4pliRtP6MwCpishMH5 7Qf/jsPSYzCtGYz7CGFeva67ojyPY1S8QYy7fSU2mT6d1EHk6NLSKQBej4/ETvpvtqIU gvQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=aXR90ibTegE6IzP48RCUTtt/H281gHVRJ1k4zPa6mD8=; b=OFfdSIZhXJwiQVeUjKV/4ANoarI3VXZFj/B4bEi6qOj1fB3/hWSN7WOufT/nk+OGvd X3u1+En5uU21cdXm19iS+fIxy0FOcEguNQmCeVWBXTtklyP2tgsc5xd6p+qaGkw/HURd LDXuTAoMmNQ1ZrEduxk8RMz7eol65iZNigYw5N4P6gCAReIxFOgKcZev8BPimMusE/7d WFwkfp+Aghnk68RE0ZJ/oO7Xsc5+RjTTHgaH08smyEECkiO9bBjoUQ3ZLSt1RR+oVSVg 8CmYMkdRpM0eWlLZxe9n4uO/gwEsuwDmbgANOaJPTuVR52lHOtuhHsFzxITu9cQlFUdm B1nw== X-Gm-Message-State: AGi0PuYOoDl71P+JGLUEb8DUz06BAYxtfAMr3w5hctnQZBeUNX9d1sUG cIdSDQ0Zv7b/rsSJUox7cV7b+iupwOv13GLFE1PBZIaT1lU1s1vb4/WS3N2rGaJpIZ+pfqVxdAx RMr9cHDP2Zh0IWIHCqY6AvlBSy8xgKwYP23wcMemUFeIyxaKd+ozsmbNnEh1l3RehFQ== X-Google-Smtp-Source: APiQypIgrM1hx6t9jvYHc7R1P+coNjE1d3bw6NxMAh99IsDdss3ERx7YOZhsf7oqONX4+yffinpa0Q== X-Received: by 2002:a5d:4801:: with SMTP id l1mr20711991wrq.235.1589239042351; Mon, 11 May 2020 16:17:22 -0700 (PDT) Return-Path: Received: from vanye ([2001:470:1f09:12f0:b26e:bfff:fea9:f1b8]) by smtp.gmail.com with ESMTPSA id j1sm8627589wrm.40.2020.05.11.16.17.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2020 16:17:21 -0700 (PDT) Date: Tue, 12 May 2020 00:17:19 +0100 From: "Leif Lindholm" To: devel@edk2.groups.io, daniel.schaefer@hpe.com Cc: Abner Chang , Gilbert Chen , Leif Lindholm , Michael D Kinney Subject: Re: [edk2-devel] [platform/devel-riscvplatforms PATCHv1 2/2] ProcessorPkg/Library: Add EDK2 RISC-V OpenSBI library. Message-ID: <20200511231719.GW21486@vanye> References: <20200511172015.5139-1-daniel.schaefer@hpe.com> <20200511172015.5139-3-daniel.schaefer@hpe.com> MIME-Version: 1.0 In-Reply-To: <20200511172015.5139-3-daniel.schaefer@hpe.com> User-Agent: Mutt/1.10.1 (2018-07-13) Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon, May 11, 2020 at 19:20:15 +0200, Daniel Schaefer wrote: > 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/RiscVOpensbiLib.inf b/Silicon/RISC-V/ProcessorPkg/Library/RiscVOpensbiLib/RiscVOpensbiLib.inf > new file mode 100644 > index 000000000000..59dbd67d8e03 > --- /dev/null > +++ b/Silicon/RISC-V/ProcessorPkg/Library/RiscVOpensbiLib/RiscVOpensbiLib.inf > @@ -0,0 +1,60 @@ > +## @file > +# RISC-V Opensbi Library Instance. > +# > +# Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.
> +# > +# SPDX-License-Identifier: BSD-2-Clause-Patent > +# > +## > + > +[Defines] > + INF_VERSION = 0x0001001b > + BASE_NAME = RiscVOpensbiLib > + FILE_GUID = 6EF0C812-66F6-11E9-93CE-3F5D5F0DF0A7 > + MODULE_TYPE = BASE > + VERSION_STRING = 1.0 > + LIBRARY_CLASS = RiscVOpensbiLib > + > +[Sources] > + opensbi/lib/sbi/riscv_asm.c > + opensbi/lib/sbi/riscv_atomic.c > + opensbi/lib/sbi/riscv_hardfp.S > + opensbi/lib/sbi/riscv_locks.c > + opensbi/lib/sbi/sbi_console.c > + opensbi/lib/sbi/sbi_ecall.c > + opensbi/lib/sbi/sbi_ecall_vendor.c > + opensbi/lib/sbi/sbi_ecall_replace.c > + opensbi/lib/sbi/sbi_ecall_legacy.c > + opensbi/lib/sbi/sbi_ecall_base.c > + opensbi/lib/sbi/sbi_emulate_csr.c > + opensbi/lib/sbi/sbi_fifo.c > + opensbi/lib/sbi/sbi_hart.c > + opensbi/lib/sbi/sbi_hfence.S > + opensbi/lib/sbi/sbi_illegal_insn.c > + opensbi/lib/sbi/sbi_init.c > + opensbi/lib/sbi/sbi_ipi.c > + opensbi/lib/sbi/sbi_misaligned_ldst.c > + opensbi/lib/sbi/sbi_scratch.c > + opensbi/lib/sbi/sbi_string.c > + opensbi/lib/sbi/sbi_system.c > + opensbi/lib/sbi/sbi_timer.c > + opensbi/lib/sbi/sbi_tlb.c > + opensbi/lib/sbi/sbi_trap.c > + opensbi/lib/sbi/sbi_unpriv.c > + opensbi/lib/utils/sys/clint.c > + opensbi/lib/utils/irqchip/plic.c > + opensbi/lib/utils/serial/sifive-uart.c > + opensbi/lib/utils/serial/uart8250.c > + > +[Packages] > + EmbeddedPkg/EmbeddedPkg.dec # For libfdt. > + MdePkg/MdePkg.dec > + Silicon/RISC-V/ProcessorPkg/RiscVProcessorPkg.dec > + > +[LibraryClasses] > + BaseLib > + PcdLib > + RiscVCpuLib > + > + > + > diff --git a/Silicon/RISC-V/ProcessorPkg/Include/IndustryStandard/RiscVOpensbi.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 > + SBI inline function calls. > + > + Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#ifndef EDK2_SBI_H_ > +#define EDK2_SBI_H_ > + > +#include // Reference to header file in opensbi > +#include > +#include // Reference to header file wrapper > + > +#define SBI_SUCCESS 0 > +#define SBI_ERR_FAILED -1 > +#define SBI_ERR_NOT_SUPPORTED -2 > +#define SBI_ERR_INVALID_PARAM -3 > +#define SBI_ERR_DENIED -4 > +#define SBI_ERR_INVALID_ADDRESS -5 > +#define SBI_ERR_ALREADY_AVAILABLE -6 These #defines are translations of what exists in opensbi/include/sbi/sbi_error.h - can we use the definitions there directly (redefining them here)? > + > +#define SBI_BASE_EXT 0x10 > +#define SBI_HSM_EXT 0x48534D > +#define SBI_TIME_EXT 0x54494D45 > +#define SBI_IPI_EXT 0x735049 > +#define SBI_RFNC_EXT 0x52464E43 > + > +// > +// Below two definitions should be defined in OpenSBI. > +// > +#define SBI_EXT_FIRMWARE_CODE_BASE_START 0x0A000000 > +#define SBI_EXT_FIRMWARE_CODE_BASE_END 0x0AFFFFFF > + > +#define SBI_GET_SPEC_VERSION_FUNC 0 > +#define SBI_GET_IMPL_ID_FUNC 1 > +#define SBI_GET_IMPL_VERSION_FUNC 2 > +#define SBI_PROBE_EXTENSION_FUNC 3 > +#define SBI_GET_MVENDORID_FUNC 4 > +#define SBI_GET_MARCHID_FUNC 5 > +#define SBI_GET_MIMPID_FUNC 6 > + > +#define SBI_HART_START_FUNC 0 > +#define SBI_HART_STOP_FUNC 1 > +#define SBI_HART_GET_STATUS_FUNC 2 > + > +#define RISC_V_MAX_HART_SUPPORTED 16 > + > +typedef > +VOID > +(EFIAPI *RISCV_HART_SWITCH_MODE)( > + IN UINTN FuncArg0, > + IN UINTN FuncArg1, > + IN UINTN NextAddr, > + IN UINTN NextMode, > + IN BOOLEAN NextVirt > + ); > + > +// > +// Keep the structure member in 64-bit alignment. > +// > +typedef struct { > + UINT64 IsaExtensionSupported; // The ISA extension this core supported. > + RISCV_UINT128 MachineVendorId; // Machine vendor ID > + RISCV_UINT128 MachineArchId; // Machine Architecture ID > + RISCV_UINT128 MachineImplId; // Machine Implementation ID > + RISCV_HART_SWITCH_MODE HartSwitchMode; // OpenSBI's function to switch the mode of a hart > +} EFI_RISCV_FIRMWARE_CONTEXT_HART_SPECIFIC; > +#define FIRMWARE_CONTEXT_HART_SPECIFIC_SIZE (64 * 8) // This is the size of EFI_RISCV_FIRMWARE_CONTEXT_HART_SPECIFIC > + // structure. Referred by both C code and assembly code. > + > +typedef struct { > + VOID *PeiServiceTable; // PEI Service table > + EFI_RISCV_FIRMWARE_CONTEXT_HART_SPECIFIC *HartSpecific[RISC_V_MAX_HART_SUPPORTED]; > +} EFI_RISCV_OPENSBI_FIRMWARE_CONTEXT; > + > +#endif > diff --git a/Silicon/RISC-V/ProcessorPkg/Include/OpensbiTypes.h b/Silicon/RISC-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 > + RISC-V OpesbSBI header file reference. > + > + Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > +#ifndef EDK2_SBI_TYPES_H_ > +#define EDK2_SBI_TYPES_H_ > + I think this header needs to include either Base.h or ProcessorBind.h? I am also somewhat confused by this file existing both here and in edk2-staging RISC-V-V2. Am I on the wrong timeline? > +typedef INT8 s8; > +typedef UINT8 u8; > +typedef UINT8 uint8_t; > + > +typedef INT16 s16; > +typedef UINT16 u16; > +typedef INT16 int16_t; > +typedef UINT16 uint16_t; > + > +typedef INT32 s32; > +typedef UINT32 u32; > +typedef INT32 int32_t; > +typedef UINT32 uint32_t; > + > +typedef INT64 s64; > +typedef UINT64 u64; > +typedef INT64 int64_t; > +typedef UINT64 uint64_t; > + > +#define PRILX "016lx" Please add a comment about what PRILX is for, given this isn't something I can even grep for in this repo. Maybe consider also moving it after all the typedefs, so it isn't as undexpected? > + > +typedef BOOLEAN bool; > +typedef unsigned long ulong; > +typedef UINT64 uintptr_t; > +typedef UINT64 size_t; > +typedef INT64 ssize_t; > +typedef UINT64 virtual_addr_t; > +typedef UINT64 virtual_size_t; > +typedef UINT64 physical_addr_t; > +typedef UINT64 physical_size_t; > + > +#define __packed __attribute__((packed)) > +#define __noreturn __attribute__((noreturn)) > + > +#define likely(x) __builtin_expect((x), 1) > +#define unlikely(x) __builtin_expect((x), 0) It may be premature to start worrying about support in non-gcc-like toolchains, but if that *does* happen, it might be nicer if it fails with a clear error message about "unsupported toolchain" (Base.h uses #if defined(__GNUC__) || defined(__clang__) ). / Leif > + > +#undef offsetof > +#ifdef __compiler_offsetof > +#define offsetof(TYPE, MEMBER) __compiler_offsetof(TYPE,MEMBER) > +#else > +#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) > +#endif > + > +#define container_of(ptr, type, member) ({ \ > + const typeof(((type *)0)->member) * __mptr = (ptr); \ > + (type *)((char *)__mptr - offsetof(type, member)); }) > + > +#define CLAMP(a, lo, hi) MIN(MAX(a, lo), hi) > +#define ROUNDUP(a, b) ((((a)-1) / (b) + 1) * (b)) > +#define ROUNDDOWN(a, b) ((a) / (b) * (b)) > + > +/* clang-format on */ > + > +#endif > -- > 2.26.1 > > > >