From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=pass header.i=@linaro.org header.s=google header.b=kx0W345C; spf=pass (domain: linaro.org, ip: 209.85.128.66, mailfrom: leif.lindholm@linaro.org) Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by groups.io with SMTP; Mon, 30 Sep 2019 11:31:17 -0700 Received: by mail-wm1-f66.google.com with SMTP id y21so554609wmi.0 for ; Mon, 30 Sep 2019 11:31:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=sqQDtDH5sKq5fidhORkpoxllW+LBd3T80/xpTkzGBoo=; b=kx0W345C6UZunSjRU+ZiICrC4KYJUihhuLuzB4yzqQLtJKMzagSKY/O0AZyBr2Ocnw fSwqz/cfR8/0yEDBSZAiXlLzT0SB3aet+hYCoat73xWCvrhOGOWfnPzMAESjSwo9Twpl uwUk7sEfkM4fpV6e+ff+8OYVvUnFDyR2U17Dxh6a449uzcLpTwSONP5AzWfVLaM6KUhd ayPnMESS0TUg4EQhoBr0zERT0vNcsBb7wzOOWnjdG8A1pgxBWAniZTlhwjEeQlNupvny /qVhF7KfW4gviFw+wxOxfIBUhLnxElbfNcLSa17bdaNCL96fmjw7YPtC+YpoAKLYKIPO 35dQ== 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:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=sqQDtDH5sKq5fidhORkpoxllW+LBd3T80/xpTkzGBoo=; b=nEAvMkfyKpbN0BYQo/GT6ozjk8fB1/fs5vNq2HWjZXodTW5hPgrWRBw4k9FaRLNEHN j4sIndQsgm6RI1PDAXtcQCECKu3g2bTKiNLHaOEqWMP3SWTtFmBuwtayYPfQCIXcjfSJ wuKUMrVELlMVnT0VUdKQVidaMeZ3JoYaj8sGCZQcyVvr9XE30xk6u3xtvZJ9VStRlgGV PMoQQmKTAefxJA2ujcvVAV284i3tqck67O6rFEPmmvUOIDJ/k0N0gvwmEVfo4knFU9Nm 5R19Iy1sWX2pbI3dRvmxIDu5sogsjruxLSIhyzsJuiDjPg69TkyuMjwuqnPcgsDVE9UO /Q6w== X-Gm-Message-State: APjAAAWAtppv03DdIi3bipmpYxvXGYb580aJnI3SGAta303oaS1CrACM MaGgEk5X0JxqqlF56JbLBimntvag1l8= X-Google-Smtp-Source: APXvYqz3k6V4Lhximic8VwN2xCyGwN4w0LGjoDjFco4IAmKxsF6QY/pdM9yKqsJMs0fYqlqZ8I8V7w== X-Received: by 2002:a1c:d188:: with SMTP id i130mr430440wmg.101.1569868275374; Mon, 30 Sep 2019 11:31:15 -0700 (PDT) Return-Path: Received: from bivouac.eciton.net (bivouac.eciton.net. [2a00:1098:0:86:1000:23:0:2]) by smtp.gmail.com with ESMTPSA id q124sm601684wma.5.2019.09.30.11.31.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2019 11:31:14 -0700 (PDT) Date: Mon, 30 Sep 2019 19:31:12 +0100 From: "Leif Lindholm" To: devel@edk2.groups.io, abner.chang@hpe.com Subject: Re: [edk2-devel] [edk2-staging/RISC-V-V2 PATCH v2 15/29] RiscVPkg/Library: RISC-V CPU library Message-ID: <20190930183112.GZ25504@bivouac.eciton.net> References: <1569198715-31552-1-git-send-email-abner.chang@hpe.com> <1569198715-31552-17-git-send-email-abner.chang@hpe.com> MIME-Version: 1.0 In-Reply-To: <1569198715-31552-17-git-send-email-abner.chang@hpe.com> User-Agent: Mutt/1.10.1 (2018-07-13) Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon, Sep 23, 2019 at 08:31:41AM +0800, Abner Chang wrote: > This library provides CSR assembly functions to read/write RISC-V > specific Control and Status registers. > > Signed-off-by: Abner Chang > --- > RiscVPkg/Include/Library/RiscVCpuLib.h | 68 ++++++++++++++++ > RiscVPkg/Library/RiscVCpuLib/Cpu.S | 115 +++++++++++++++++++++++++++ > RiscVPkg/Library/RiscVCpuLib/RiscVCpuLib.inf | 34 ++++++++ Please ensure you have set up an orderfile, as described on https://github.com/tianocore/tianocore.github.io/wiki/Laszlo%27s-unkempt-git-guide-for-edk2-contributors-and-maintainers or by executing BaseTools/Scripts/SetupGit.py inside each repository. > 3 files changed, 217 insertions(+) > create mode 100644 RiscVPkg/Include/Library/RiscVCpuLib.h > create mode 100644 RiscVPkg/Library/RiscVCpuLib/Cpu.S > create mode 100644 RiscVPkg/Library/RiscVCpuLib/RiscVCpuLib.inf > > diff --git a/RiscVPkg/Include/Library/RiscVCpuLib.h b/RiscVPkg/Include/Library/RiscVCpuLib.h > new file mode 100644 > index 0000000..c84d599 > --- /dev/null > +++ b/RiscVPkg/Include/Library/RiscVCpuLib.h > @@ -0,0 +1,68 @@ > +/** @file > + RISC-V CPU library definitions. > + > + Copyright (c) 2016 - 2019, Hewlett Packard Enterprise Development LP. All rights reserved.
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent > +**/ > + > +#ifndef _RISCV_CPU_LIB_H_ > +#define _RISCV_CPU_LIB_H_ Please drop leading _. > + > +#include "RiscV.h" Hmm. This raises two concerns. First - style-wise, "" should not be used for anything but local (same directory) include files. Secondly, there are two separate files called RiscV.h introduced by this patch series: RiscVPkg/Include/IndustryStandard/RiscV.h RiscVPkg/Include/RiscV.h Have these been split solely in order to have one directly includable in assembler? If so, please merge them (in the IndustryStandard one), and put the C-specific bits inside an #ifndef __ASSEMBLY__ statement. If not, please provide a description of their logical split, and rename one of them. > + > +/** > + RISCV_TRAP_HANDLER > +**/ > +typedef > +VOID > +(EFIAPI *RISCV_TRAP_HANDLER)( > + VOID > + ); > + > +VOID > +RiscVSetScratch (RISCV_MACHINE_MODE_CONTEXT *RiscvContext); Please keep all names referring to architectural registers identifiable. A quick Internet search suggests this may mean Machine Scratch Register? > + > +UINT32 > +RiscVGetScratch (VOID); > + > +UINT32 > +RiscVGetTrapCause (VOID); > + > +UINT64 > +RiscVReadMachineTimer (VOID); > + > +VOID > +RiscVSetMachineTimerCmp (UINT64); Cmp neds expanding to its full name. > + > +UINT64 > +RiscVReadMachineTimerCmp(VOID); > + > +UINT64 > +RiscVReadMachineIE(VOID); > + > +UINT64 > +RiscVReadMachineIP(VOID); IE/IP needs expanding, unless these are the names used in the architecture reference. If it is, this file needs those terms introduced in a glossary section at the start of this file. > + > +UINT64 > +RiscVReadMachineStatus(VOID); > + > +VOID > +RiscVWriteMachineStatus(UINT64); > + > +UINT64 > +RiscVReadMachineTvec(VOID); > + > +UINT64 > +RiscVReadMisa (VOID); Tvec/Misa need the same treatment as IE/IP. If the M stands for Machine, it should be written out fully, and likely isa should be Isa. > + > +UINT64 > +RiscVReadMVendorId (VOID); > + > +UINT64 > +RiscVReadMArchId (VOID); > + > +UINT64 > +RiscVReadMImplId (VOID); Impl needs expanding - I can't tell whether that means Implementation or Implmenter. For all 3 above, is that M only an abbreviated Machine? If so, please write it out fully. > + > +#endif > diff --git a/RiscVPkg/Library/RiscVCpuLib/Cpu.S b/RiscVPkg/Library/RiscVCpuLib/Cpu.S > new file mode 100644 > index 0000000..f372397 > --- /dev/null > +++ b/RiscVPkg/Library/RiscVCpuLib/Cpu.S > @@ -0,0 +1,115 @@ > +//------------------------------------------------------------------------------ > +// > +// RISC-V CPU functions. > +// > +// Copyright (c) 2016 - 2019, Hewlett Packard Enterprise Development LP. All rights reserved.
> +// > +// SPDX-License-Identifier: BSD-2-Clause-Patent > +// > +//------------------------------------------------------------------------------ > +#include > +#include > + > +.data > + > +.text > +.align 3 > + > +.global ASM_PFX(RiscVSetScratch) > +.global ASM_PFX(RiscVGetScratch) > +.global ASM_PFX(RiscVGetMachineTrapCause) > +.global ASM_PFX(RiscVReadMachineIE) > +.global ASM_PFX(RiscVReadMachineIP) > +.global ASM_PFX(RiscVReadMachineStatus) > +.global ASM_PFX(RiscVWriteMachineStatus) > +.global ASM_PFX(RiscVReadMachineTvec) > +.global ASM_PFX(RiscVReadMisa) > +.global ASM_PFX(RiscVReadMVendorId) > +.global ASM_PFX(RiscVReadMArchId) > +.global ASM_PFX(RiscVReadMImplId) This could get a lot neater if you replicate what we have for the ARM/AARCH64 ports and implement an ASM_FUNC macro that does both the global, and the prefix (and some more stuff that is less imortant now we use lto anyway). Have a look in ArmPkg/Include/AsmMacroIoLib*.h > +// > +// Set machine mode scratch. > +// @param a0 : Pointer to RISCV_MACHINE_MODE_CONTEXT. > +// > +ASM_PFX (RiscVSetScratch): > + csrrw a1, RISCV_CSR_MACHINE_MSCRATCH, a0 > + ret > + > +// > +// Get machine mode scratch. > +// @retval a0 : Pointer to RISCV_MACHINE_MODE_CONTEXT. > +// > +ASM_PFX (RiscVGetScratch): > + csrrs a0, RISCV_CSR_MACHINE_MSCRATCH, 0 > + ret > + > +// > +// Get machine trap cause CSR. > +// > +ASM_PFX (RiscVGetMachineTrapCause): > + csrrs a0, RISCV_CSR_MACHINE_MCAUSE, 0 > + ret > + > +// > +// Get machine interrupt enable > +// > +ASM_PFX (RiscVReadMachineIE): > + csrr a0, RISCV_CSR_MACHINE_MIE > + ret > + > +// > +// Get machine interrupt pending > +// > +ASM_PFX (RiscVReadMachineIP): > + csrr a0, RISCV_CSR_MACHINE_MIP > + ret > + > +// > +// Get machine status > +// > +ASM_PFX(RiscVReadMachineStatus): > + csrr a0, RISCV_CSR_MACHINE_MSTATUS > + ret > + > +// > +// Set machine status > +// > +ASM_PFX(RiscVWriteMachineStatus): > + csrw RISCV_CSR_MACHINE_MSTATUS, a0 > + ret > + > +// > +// Get machine trap vector > +// > +ASM_PFX(RiscVReadMachineTvec): > + csrr a0, RISCV_CSR_MACHINE_MTVEC > + ret > + > +// > +// Read machine ISA > +// > +ASM_PFX(RiscVReadMisa): > + csrr a0, RISCV_CSR_MACHINE_MISA > + ret > + > +// > +// Read machine vendor ID > +// > +ASM_PFX(RiscVReadMVendorId): > + csrr a0, RISCV_CSR_MACHINE_MVENDORID > + ret > + > +// > +// Read machine architecture ID > +// > +ASM_PFX(RiscVReadMArchId): > + csrr a0, RISCV_CSR_MACHINE_MARCHID > + ret > + > +// > +// Read machine implementation ID > +// > +ASM_PFX(RiscVReadMImplId): > + csrr a0, RISCV_CSR_MACHINE_MIMPID > + ret > + > diff --git a/RiscVPkg/Library/RiscVCpuLib/RiscVCpuLib.inf b/RiscVPkg/Library/RiscVCpuLib/RiscVCpuLib.inf > new file mode 100644 > index 0000000..fc9131b > --- /dev/null > +++ b/RiscVPkg/Library/RiscVCpuLib/RiscVCpuLib.inf > @@ -0,0 +1,34 @@ > +## @file > +# RISC-V RV64 CPU library > +# > +# Copyright (c) 2016 - 2019, Hewlett Packard Enterprise Development LP. All rights reserved.
> +# > +# SPDX-License-Identifier: BSD-2-Clause-Patent > +# > +## > + > +[Defines] > + INF_VERSION = 0x0001001b > + BASE_NAME = RiscVCpuLib > + FILE_GUID = 8C6CFB0D-A0EE-40D5-90DA-2E51EAE0583F > + MODULE_TYPE = BASE > + VERSION_STRING = 1.0 > + LIBRARY_CLASS = RiscVCpuLib > + > +# > +# The following information is for reference only and not required by the build tools. > +# > +# VALID_ARCHITECTURES = RISCV64 > +# > + > +[Sources] > + > +[Sources.RISCV64] > + Cpu.S > + > +[Packages] > + MdePkg/MdePkg.dec > + MdeModulePkg/MdeModulePkg.dec Please sort the above two alphabetically. / Leif > + RiscVPkg/RiscVPkg.dec > + > + > -- > 2.7.4 > > > >