public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Leif Lindholm" <leif@nuviainc.com>
To: Daniel Schaefer <daniel.schaefer@hpe.com>
Cc: devel@edk2.groups.io, Abner Chang <abner.chang@hpe.com>,
	Gilbert Chen <gilbert.chen@hpe.com>,
	Michael D Kinney <michael.k.kinney@intel.com>
Subject: Re: [edk2-devel] [PATCH v2 3/3] ProcessorPkg/Library: Add RiscVEdk2SbiLib
Date: Fri, 29 May 2020 14:15:05 +0100	[thread overview]
Message-ID: <20200529131505.GM1923@vanye> (raw)
In-Reply-To: <492edaee-f3a1-9d36-0dc0-c70564912d2c@hpe.com>

On Fri, May 29, 2020 at 14:43:43 +0200, Daniel Schaefer wrote:
> Hi Leif,
> 
> thanks for this super careful review!
> Comments and one question inline.
> 
> - Daniel
> 
> On 5/20/20 8:27 PM, Leif Lindholm wrote:
> > On Fri, May 15, 2020 at 15:39:37 +0200, Daniel Schaefer wrote:
> > > Library provides interfaces to invoke SBI extensions.
> > > 
> > > Signed-off-by: Daniel Schaefer <daniel.schaefer@hpe.com>
> > > 
> > > Cc: Abner Chang <abner.chang@hpe.com>
> > > Cc: Gilbert Chen <gilbert.chen@hpe.com>
> > > Cc: Michael D Kinney <michael.k.kinney@intel.com>
> > > Cc: Leif Lindholm <leif@nuviainc.com>
> > > ---
> > >   Silicon/RISC-V/ProcessorPkg/Library/RiscVEdk2SbiLib/RiscVEdk2SbiLib.inf |  28 +
> > >   Silicon/RISC-V/ProcessorPkg/Include/IndustryStandard/RiscVOpensbi.h     |  43 +-
> > >   Silicon/RISC-V/ProcessorPkg/Include/Library/RiscVEdk2SbiLib.h           | 631 ++++++++++++++++
> > >   Silicon/RISC-V/ProcessorPkg/Library/RiscVEdk2SbiLib/RiscVEdk2SbiLib.c   | 789 ++++++++++++++++++++
> > >   4 files changed, 1466 insertions(+), 25 deletions(-)
> > > 

> > > diff --git a/Silicon/RISC-V/ProcessorPkg/Include/Library/RiscVEdk2SbiLib.h b/Silicon/RISC-V/ProcessorPkg/Include/Library/RiscVEdk2SbiLib.h
> > > new file mode 100644
> > > index 000000000000..cf77814e3bbc
> > > --- /dev/null
> > > +++ b/Silicon/RISC-V/ProcessorPkg/Include/Library/RiscVEdk2SbiLib.h
> > 

> > > +  long error;   ///< SBI status code
> > > +  long value;   ///< Value returned
> > 
> > This looks like a maintenance hazard (means different things to GCC
> > and VS for example). Can we use UINT32?
> 
> I'll use UINTN because it's bigger than 32bits on RISCV64

Oh, then definitely that, yes.

> > 
> > > +};
> > > +
> > > +#define SbiCall0(ext_id, func_id) \
> > > +  SbiCall(ext_id, func_id, 0, 0, 0, 0, 0, 0)
> > > +#define SbiCall1(ext_id, func_id, arg0) \
> > > +  SbiCall(ext_id, func_id, arg0, 0, 0, 0, 0, 0)
> > > +#define SbiCall2(ext_id, func_id, arg0, arg1) \
> > > +  SbiCall(ext_id, func_id, arg0, arg1, 0, 0, 0, 0)
> > > +#define SbiCall3(ext_id, func_id, arg0, arg1, arg2) \
> > > +  SbiCall(ext_id, func_id, arg0, arg1, arg2, 0, 0, 0)
> > > +#define SbiCall4(ext_id, func_id, arg0, arg1, arg2, arg3) \
> > > +  SbiCall(ext_id, func_id, arg0, arg1, arg2, arg3, 0, 0)
> > > +#define SbiCall5(ext_id, func_id, arg0, arg1, arg2, arg3, arg4) \
> > > +  SbiCall(ext_id, func_id, arg0, arg1, arg2, arg3, arg4, 0)
> > > +#define SbiCall6(ext_id, func_id, arg0, arg1, arg2, arg3, arg4, arg5) \
> > > +  SbiCall(ext_id, func_id, arg0, arg1, arg2, arg3, arg4, arg5)
> > 
> > Ugh. This looks way too much like pre-EFIAPI x86 code.
> > 
> > Is this a pattern used across multiple codebases?
> > If not, could we make this a simple argc/argv instead and do the
> > unpacking inside SbiCall()? Hmm, maybe that would make the call sites
> > even worse.
> > 
> > If we need to keep these, coding style says all macros should use
> > UPPERCASE_AND_UNDERSCORES.
> > 
> 
> Yeah, I think argc/argv is going to make the callsites worse. What about
> vararg, like I used in SbiVendorCall in
> Silicon/RISC-V/ProcessorPkg/Library/RiscVEdk2SbiLib/RiscVEdk2SbiLib.c
> ? Or does that have a performance impact? Maybe an architecture specific
> one?

It *might* have a performance impact, but I'd be astonished if it is
noticeable.

Yes please, if you don't mind, I think that would really improve the
readability.


> > > +/**
> > > +  Get the CPU's vendor ID
> > > +
> > > +  Reads the mvendorid CSR.
> > 
> > What is an MvendorId? MachineVendorId?
> > Even if an official register name, I would prefer function and
> > arguments to be given proper descriptive CamelCase names.
> 
> Yes, it's the official register name. Alright, will change it.

If it *is* the official register name, adding it to the glossary
section is also OK.

> > > +**/
> > > +VOID
> > > +EFIAPI
> > > +SbiGetMarchId (
> > > +  OUT UINTN                       *MarchId
> > > +  );
> > > +
> > > +/**
> > > +  Get the CPU's implementation ID
> > > +
> > > +  Reads the mimpid CSR.
> > > +
> > > +  @param[out] MimpId               The CPU's implementation ID.
> > 
> > Above "Impl" is used for "Impelentation". *Strictly* speaking, "Impl"
> > doesn't fall in the pretty small group of abbreviations permitted
> > without a glossary section in the source file, but it's clear enough
> > to me I'll let it slip.
> > The same cannot be said for "Imp".
> > MachineImplId?
> 
> Sounds good. Should it be added to the permitted abbreviations?
> If I spell it out fully here, it becomes quite long.

I'm OK with Impl. We should consider adding it to the list.

> > > +**/
> > > +EFI_STATUS
> > > +EFIAPI
> > > +SbiHartGetStatus (
> > > +  IN  UINTN                          HartId,
> > > +  OUT UINTN                         *HartStatus
> > > +  );
> > > +
> > > +///
> > > +/// Timer extension
> > > +///
> > > +
> > > +/**
> > > +  Clear pending timer interrupt bit and set timer for next event after StimeValue.
> > 
> > What does the S stand for in Stime?
> 
> That's what they call it in the spec: stime_value.
> I guess it stands for supervisor. Should we change it to just `Time`?

That would be a valid thing to do.
Another would be to add it to the glossary.

> > > +  if (!ret.error) {
> > > +    ScratchSpace = (struct sbi_scratch *) ret.value;
> > > +    SbiPlatform = (struct sbi_platform *) sbi_platform_ptr(ScratchSpace);
> > > +    SbiPlatform->firmware_context = (long unsigned int) FirmwareContext;
> > 
> > UINT64?
> 
> UINTN for compatibility with 32bits.

Of course.

Thanks!

/
    Leif

  reply	other threads:[~2020-05-29 13:15 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-15 13:39 [PATCH v2 0/3] New RISC-V Patches Daniel Schaefer
2020-05-15 13:39 ` [PATCH v2 1/3] ProcessorPkg/RiscVOpensbLib: Add opensbi submodule Daniel Schaefer
2020-05-20 11:51   ` Leif Lindholm
2020-05-15 13:39 ` [PATCH v2 2/3] ProcessorPkg/Library: Add RiscVOpensbiLib Daniel Schaefer
2020-05-20 12:00   ` Leif Lindholm
2020-05-20 14:44     ` Daniel Schaefer
2020-05-15 13:39 ` [PATCH v2 3/3] ProcessorPkg/Library: Add RiscVEdk2SbiLib Daniel Schaefer
2020-05-20 18:27   ` Leif Lindholm
2020-05-29 12:43     ` [edk2-devel] " Daniel Schaefer
2020-05-29 13:15       ` Leif Lindholm [this message]
2020-05-20 11:43 ` [edk2-devel] [PATCH v2 0/3] New RISC-V Patches Leif Lindholm
2020-05-20 16:03   ` [edk2-devel] [PATCH v2 0/3] New RISC-V Patches - Why in edk2-platforms Daniel Schaefer
2020-05-20 16:07     ` Daniel Schaefer
2020-05-20 16:17       ` Daniel Schaefer
2020-05-21  6:59         ` Abner Chang
2020-05-28 11:54           ` Leif Lindholm
2020-05-29 14:41             ` Abner Chang
     [not found]             ` <b55ee3ec-74de-532e-01f7-bd24a327d00b@hpe.com>
     [not found]               ` <CY4PR21MB0743421F39A05298FBCFBAA0EF8F0@CY4PR21MB0743.namprd21.prod.outlook.com>
     [not found]                 ` <MN2PR11MB4461D8666DE6DA1E7D4B5B9BD28F0@MN2PR11MB4461.namprd11.prod.outlook.com>
     [not found]                   ` <TU4PR8401MB1182F755F76709FF1D46D3F2FF8F0@TU4PR8401MB1182.NAMPRD84.PROD.OUTLOOK.COM>
     [not found]                     ` <MN2PR11MB4461442E7462457D6C20F6F2D28F0@MN2PR11MB4461.namprd11.prod.outlook.com>
     [not found]                       ` <MW2PR2101MB092494AB8318628E06B62089E18F0@MW2PR2101MB0924.namprd21.prod.outlook.com>
2020-06-03 11:57                         ` [edk2-devel] Where to put RISC-V packages Daniel Schaefer
2020-06-03 15:02                           ` Abner Chang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200529131505.GM1923@vanye \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox