All of lore.kernel.org
 help / color / mirror / Atom feed
From: Auer, Lukas <lukas.auer@aisec.fraunhofer.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [RESEND PATCH v2 08/15] riscv: Add a helper routine to print CPU information
Date: Tue, 18 Sep 2018 10:53:05 +0000	[thread overview]
Message-ID: <bcbdd768c60c5f0debc2926d807fb5194aee2708.camel@aisec.fraunhofer.de> (raw)
In-Reply-To: <CAEUhbmUmBmea+GeA0Oy8DeAdyJwArA=iuvP8NZzqxSqfNcoUYw@mail.gmail.com>

Hi Bin,

On Tue, 2018-09-18 at 16:53 +0800, Bin Meng wrote:
> Hi Lukas,
> 
> On Tue, Sep 18, 2018 at 5:59 AM Auer, Lukas
> <lukas.auer@aisec.fraunhofer.de> wrote:
> > 
> > Hi Bin,
> > 
> > On Mon, 2018-09-17 at 12:55 +0800, Bin Meng wrote:
> > > Hi Lukas,
> > > 
> > > On Mon, Sep 17, 2018 at 4:54 AM Auer, Lukas
> > > <lukas.auer@aisec.fraunhofer.de> wrote:
> > > > 
> > > > Hi Bin,
> > > > 
> > > > On Mon, 2018-09-10 at 21:54 -0700, Bin Meng wrote:
> > > > > This adds a helper routine to print CPU information.
> > > > > Currently
> > > > > it prints all the instruction set extensions that the
> > > > > processor
> > > > > core supports.
> > > > > 
> > > > > Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
> > > > > ---
> > > > > 
> > > > > Changes in v2: None
> > > > > 
> > > > >  arch/riscv/Makefile          |   1 +
> > > > >  arch/riscv/cpu/Makefile      |   5 ++
> > > > >  arch/riscv/cpu/cpu.c         |  49 +++++++++++++++++
> > > > >  arch/riscv/include/asm/csr.h | 124
> > > > > +++++++++++++++++++++++++++++++++++++++++++
> > > > >  4 files changed, 179 insertions(+)
> > > > >  create mode 100644 arch/riscv/cpu/Makefile
> > > > >  create mode 100644 arch/riscv/cpu/cpu.c
> > > > >  create mode 100644 arch/riscv/include/asm/csr.h
> > > > > 
> > > > > diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile
> > > > > index 084888a..af432e1 100644
> > > > > --- a/arch/riscv/Makefile
> > > > > +++ b/arch/riscv/Makefile
> > > > > @@ -5,5 +5,6 @@
> > > > > 
> > > > >  head-y := arch/riscv/cpu/$(CPU)/start.o
> > > > > 
> > > > > +libs-y += arch/riscv/cpu/
> > > > >  libs-y += arch/riscv/cpu/$(CPU)/
> > > > >  libs-y += arch/riscv/lib/
> > > > > diff --git a/arch/riscv/cpu/Makefile
> > > > > b/arch/riscv/cpu/Makefile
> > > > > new file mode 100644
> > > > > index 0000000..63de163
> > > > > --- /dev/null
> > > > > +++ b/arch/riscv/cpu/Makefile
> > > > > @@ -0,0 +1,5 @@
> > > > > +# SPDX-License-Identifier: GPL-2.0+
> > > > > +#
> > > > > +# Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
> > > > > +
> > > > > +obj-y += cpu.o
> > > > > diff --git a/arch/riscv/cpu/cpu.c b/arch/riscv/cpu/cpu.c
> > > > > new file mode 100644
> > > > > index 0000000..ae57fb8
> > > > > --- /dev/null
> > > > > +++ b/arch/riscv/cpu/cpu.c
> > > > > @@ -0,0 +1,49 @@
> > > > > +// SPDX-License-Identifier: GPL-2.0+
> > > > > +/*
> > > > > + * Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
> > > > > + */
> > > > > +
> > > > > +#include <common.h>
> > > > > +#include <asm/csr.h>
> > > > > +
> > > > > +enum {
> > > > > +     ISA_INVALID = 0,
> > > > > +     ISA_32BIT,
> > > > > +     ISA_64BIT,
> > > > > +     ISA_128BIT
> > > > > +};
> > > > > +
> > > > > +static const char * const isa_bits[] = {
> > > > > +     [ISA_INVALID] = NULL,
> > > > > +     [ISA_32BIT]   = "32",
> > > > > +     [ISA_64BIT]   = "64",
> > > > > +     [ISA_128BIT]  = "128"
> > > > > +};
> > > > > +
> > > > > +static inline bool supports_extension(char ext)
> > > > > +{
> > > > > +     return csr_read(misa) & (1 << (ext - 'a'));
> > > > > +}
> > > > > +
> > > > > +int print_cpuinfo(void)
> > > > > +{
> > > > > +     char name[32];
> > > > > +     char *s = name;
> > > > > +     int bit;
> > > > > +
> > > > > +     s += sprintf(name, "rv");
> > > > > +     bit = csr_read(misa) >> (sizeof(long) * 8 - 2);
> > > > > +     s += sprintf(s, isa_bits[bit]);
> > > > > +
> > > > > +     supports_extension('i') ? *s++ = 'i' : 'r';
> > > > > +     supports_extension('m') ? *s++ = 'm' : 'i';
> > > > > +     supports_extension('a') ? *s++ = 'a' : 's';
> > > > > +     supports_extension('f') ? *s++ = 'f' : 'c';
> > > > > +     supports_extension('d') ? *s++ = 'd' : '-';
> > > > > +     supports_extension('c') ? *s++ = 'c' : 'v';
> > > > > +     *s++ = '\0';
> > > > 
> > > > Why are you not using the ISA string "riscv,isa" from the
> > > > device
> > > > tree?
> > > > This way, the code is not limited to machine mode and we do not
> > > > have
> > > > update it if the set of extensions to check for changes.
> > > 
> > > I wanted to use hardware provided information whenever possible.
> > > Reading from DT can be a last resort. I think we wanted to have
> > > U-
> > > Boot
> > > running in machine mode, no?
> > > 
> > > Regards,
> > > Bin
> > > 
> > 
> > Ok, I see. I don't entirely like that this has to be updated if we
> > want
> > to display new extensions and it's currently actually missing the
> > 'u'
> > (user) and 's' (supervisor) extensions, which are present in the
> > misa
> > of RISC-V QEMU. It is fine for now, I think.
> > 
> 
> Yes, let's leave this for now. Currently it seems only prints "GC"
> extension is enough (IMAFDC).
> 

That makes sense.

> > Yes, we want to run u-boot in machine mode for now, especially if
> > we
> > want to add an SBI implementation to u-boot. Not much is needed to
> > run
> > it in supervisor mode though, which is why I mentioned this. It
> > also
> > allows us to use an SBI implementation external to u-boot, should
> > we
> > want / need that.
> > 
> 
> Let's see how things go. My personal preference would be only using
> U-Boot though :)
> 
> Regards,
> Bin

Yes that certainly is the best solution, at least for now. :) I think a
separate SBI implementation only starts to make sense, if it becomes a
lot more complicated / feature-rich than it is now.

Thanks,
Lukas

  reply	other threads:[~2018-09-18 10:53 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-11  4:54 [U-Boot] [RESEND PATCH v2 00/15] riscv: Add QEMU virt board support Bin Meng
2018-09-11  4:54 ` [U-Boot] [RESEND PATCH v2 01/15] riscv: kconfig: Normalize architecture name spelling Bin Meng
2018-09-16 20:43   ` Auer, Lukas
     [not found]   ` <752D002CFF5D0F4FA35C0100F1D73F3FA2F93D39@ATCPCS16.andestech.com>
2018-09-20  3:15     ` Rick Chen
2018-09-11  4:54 ` [U-Boot] [RESEND PATCH v2 02/15] riscv: Remove setup.h Bin Meng
2018-09-16 20:44   ` Auer, Lukas
2018-09-11  4:54 ` [U-Boot] [RESEND PATCH v2 03/15] riscv: bootm: Correct the 1st kernel argument to hart id Bin Meng
2018-09-16 20:45   ` Auer, Lukas
     [not found]   ` <752D002CFF5D0F4FA35C0100F1D73F3FA2F93D4E@ATCPCS16.andestech.com>
2018-09-20  3:17     ` Rick Chen
2018-09-11  4:54 ` [U-Boot] [RESEND PATCH v2 04/15] riscv: Remove mach type Bin Meng
2018-09-16 20:46   ` Auer, Lukas
2018-09-11  4:54 ` [U-Boot] [RESEND PATCH v2 05/15] riscv: Move the linker script to the CPU root directory Bin Meng
2018-09-16 20:47   ` Auer, Lukas
2018-09-11  4:54 ` [U-Boot] [RESEND PATCH v2 06/15] riscv: Fix coding style issues in the linker script Bin Meng
2018-09-16 20:49   ` Auer, Lukas
2018-09-11  4:54 ` [U-Boot] [RESEND PATCH v2 07/15] riscv: Explicitly pass -march and -mabi to the compiler Bin Meng
2018-09-16 20:51   ` Auer, Lukas
2018-09-11  4:54 ` [U-Boot] [RESEND PATCH v2 08/15] riscv: Add a helper routine to print CPU information Bin Meng
2018-09-16 20:54   ` Auer, Lukas
2018-09-17  4:55     ` Bin Meng
2018-09-17 21:59       ` Auer, Lukas
2018-09-18  8:53         ` Bin Meng
2018-09-18 10:53           ` Auer, Lukas [this message]
2018-09-11  4:54 ` [U-Boot] [RESEND PATCH v2 09/15] riscv: Remove CSR read/write defines in encoding.h Bin Meng
2018-09-16 20:55   ` Auer, Lukas
     [not found]   ` <752D002CFF5D0F4FA35C0100F1D73F3FA2F93D8B@ATCPCS16.andestech.com>
2018-09-20  3:20     ` Rick Chen
2018-09-11  4:54 ` [U-Boot] [RESEND PATCH v2 10/15] riscv: bootm: Pass mhartid CSR value to kernel Bin Meng
2018-09-16 20:55   ` Auer, Lukas
     [not found]   ` <752D002CFF5D0F4FA35C0100F1D73F3FA2F93D92@ATCPCS16.andestech.com>
2018-09-20  3:22     ` Rick Chen
2018-09-11  4:54 ` [U-Boot] [RESEND PATCH v2 11/15] riscv: Make start.S available for all targets Bin Meng
2018-09-16 20:56   ` Auer, Lukas
2018-09-11  4:54 ` [U-Boot] [RESEND PATCH v2 12/15] riscv: ae350: Clean up mixed tabs and spaces in the dts Bin Meng
2018-09-16 20:57   ` Auer, Lukas
2018-09-11  4:54 ` [U-Boot] [RESEND PATCH v2 13/15] riscv: kconfig: Select DM and OF_CONTROL Bin Meng
2018-09-16 20:58   ` Auer, Lukas
2018-09-11  4:54 ` [U-Boot] [RESEND PATCH v2 14/15] riscv: Add QEMU virt board support Bin Meng
2018-09-16 21:02   ` Auer, Lukas
2018-09-17  5:18     ` Bin Meng
2018-09-17 21:54       ` Auer, Lukas
2018-09-11  4:54 ` [U-Boot] [RESEND PATCH v2 15/15] riscv: Move do_reset() to a common place Bin Meng
2018-09-16 21:09   ` Auer, Lukas
2018-09-17  5:02     ` Bin Meng
2018-09-17 22:01       ` Auer, Lukas
2018-09-18  8:50         ` Bin Meng
2018-09-18 10:54           ` Auer, Lukas
     [not found]   ` <752D002CFF5D0F4FA35C0100F1D73F3FA2F93DD7@ATCPCS16.andestech.com>
2018-09-20  3:26     ` Rick Chen
2018-09-16 10:57 ` [U-Boot] [RESEND PATCH v2 00/15] riscv: Add QEMU virt board support Bin Meng
     [not found]   ` <752D002CFF5D0F4FA35C0100F1D73F3FA2F93D22@ATCPCS16.andestech.com>
2018-09-20  3:00     ` Rick Chen
2018-09-20  3:21       ` Bin Meng

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-all 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=bcbdd768c60c5f0debc2926d807fb5194aee2708.camel@aisec.fraunhofer.de \
    --to=lukas.auer@aisec.fraunhofer.de \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.