From: Xiang W <wxjstz@126.com>
To: opensbi@lists.infradead.org
Subject: [PATCH 4/7] lib: utils/sys: Add CLINT memregion in the root domain
Date: Mon, 12 Apr 2021 13:42:23 +0800 [thread overview]
Message-ID: <3e0812e732394a3f39bd678332edd2cbc7478014.camel@126.com> (raw)
In-Reply-To: <CAAhSdy3RXmSTH78zMLtOPuLQqTzQRkFHmMcPWtOhN-jRBO7Sqg@mail.gmail.com>
? 2021-04-12?? 10:53 +0530?Anup Patel???
> On Sun, Apr 11, 2021 at 2:35 PM Xiang W <wxjstz@126.com> wrote:
> > ? 2021-04-10?? 12:48 +0530?Anup Patel???
> > > The CLINT memory should not be accessed by the supervisor-mode
> > > software so let's protect it by adding CLINT memregion to the
> > > root domain.
> > >
> > > Signed-off-by: Anup Patel <anup.patel@wdc.com>
> > clint_cold_timer_init and clint_cold_ipi_init may use the same
> > clint,
> > which will call clint_add_root_memregion twice and generate an
> > error.
> > I suggest to separate
> >
> > In clint_cold_timer_init execute
> > sbi_domain_memregion_init(clint->addr, 0x4000,
> > SBI_DOMAIN_MEMREGION_MMIO, ®);
> >
> > In clint_cold_ipi_init execute
> > sbi_domain_memregion_init(clint->addr + 0x4000, 0x8000,
> > SBI_DOMAIN_MEMREGION_MMIO, ®);
>
> I had though about this but the only issue in having two
> separate memregions for CLINT is that it will take-up more
> PMP CSRs. The "skip_conflt" flag was added as parameter
> to sbi_domain_root_add_memregion() so that CLINT driver
> can call it multiple time.
>
> I think we can have a better implementation of the
> sbi_domain_root_add_memregion() which will merge
> consecutive regions with matching flags. This will allow
> use to add separate regions for CLINT driver but
> sbi_domain_root_add_memregion() will merge them
> into single region.
Merge regions is a good idea. I think the merger can be performed by
default. So we can separate this side first, and then modify
sbi_domain_root_add_memregion to add the merge function.
Regards,
Xiang W
>
> Regards,
> Anup
>
> > Regards,
> > Xiang W
> > > ---
> > > lib/utils/sys/clint.c | 17 +++++++++++++++--
> > > 1 file changed, 15 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/lib/utils/sys/clint.c b/lib/utils/sys/clint.c
> > > index 7a392aa..fe98cc4 100644
> > > --- a/lib/utils/sys/clint.c
> > > +++ b/lib/utils/sys/clint.c
> > > @@ -10,6 +10,7 @@
> > > #include <sbi/riscv_asm.h>
> > > #include <sbi/riscv_atomic.h>
> > > #include <sbi/riscv_io.h>
> > > +#include <sbi/sbi_domain.h>
> > > #include <sbi/sbi_error.h>
> > > #include <sbi/sbi_hartmask.h>
> > > #include <sbi_utils/sys/clint.h>
> > > @@ -17,9 +18,19 @@
> > > #define CLINT_IPI_OFF 0
> > > #define CLINT_TIME_CMP_OFF 0x4000
> > > #define CLINT_TIME_VAL_OFF 0xbff8
> > > +#define CLINT_SIZE 0xc000
> > >
> > > static struct clint_data
> > > *clint_ipi_hartid2data[SBI_HARTMASK_MAX_BITS];
> > >
> > > +static int clint_add_root_memregion(struct clint_data *clint)
> > > +{
> > > + struct sbi_domain_memregion reg;
> > > +
> > > + sbi_domain_memregion_init(clint->addr, CLINT_SIZE,
> > > + SBI_DOMAIN_MEMREGION_MMIO, ®);
> > > + return sbi_domain_root_add_memregion(®, true);
> > > +}
> > > +
> > > void clint_ipi_send(u32 target_hart)
> > > {
> > > struct clint_data *clint;
> > > @@ -70,7 +81,8 @@ int clint_cold_ipi_init(struct clint_data
> > > *clint)
> > > for (i = 0; i < clint->hart_count; i++)
> > > clint_ipi_hartid2data[clint->first_hartid + i] =
> > > clint;
> > >
> > > - return 0;
> > > + /* Add CLINT region to the root domain */
> > > + return clint_add_root_memregion(clint);
> > > }
> > >
> > > static struct clint_data
> > > *clint_timer_hartid2data[SBI_HARTMASK_MAX_BITS];
> > > @@ -199,5 +211,6 @@ int clint_cold_timer_init(struct clint_data
> > > *clint,
> > > for (i = 0; i < clint->hart_count; i++)
> > > clint_timer_hartid2data[clint->first_hartid + i] =
> > > clint;
> > >
> > > - return 0;
> > > + /* Add CLINT region to the root domain */
> > > + return clint_add_root_memregion(clint);
> > > }
> > > --
> > > 2.25.1
> > >
> > >
next prev parent reply other threads:[~2021-04-12 5:42 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-10 7:18 [PATCH 0/7] Protect M-mode only MMIO devices Anup Patel
2021-04-10 7:18 ` [PATCH 1/7] lib: sbi: Domains can be registered only before finalizing domains Anup Patel
2021-04-11 7:49 ` Xiang W
2021-04-11 21:19 ` Alistair Francis
2021-04-10 7:18 ` [PATCH 2/7] lib: sbi: Add sbi_domain_memregion_init() API Anup Patel
2021-04-11 7:50 ` Xiang W
2021-04-11 21:22 ` Alistair Francis
2021-04-10 7:18 ` [PATCH 3/7] lib: sbi: Add sbi_domain_root_add_memregion() API Anup Patel
2021-04-11 8:43 ` Xiang W
2021-04-11 21:27 ` Alistair Francis
2021-04-10 7:18 ` [PATCH 4/7] lib: utils/sys: Add CLINT memregion in the root domain Anup Patel
2021-04-11 9:05 ` Xiang W
2021-04-12 5:23 ` Anup Patel
2021-04-12 5:42 ` Xiang W [this message]
2021-04-12 6:24 ` Anup Patel
2021-04-10 7:18 ` [PATCH 5/7] lib: sbi: Make the root domain instance global variable Anup Patel
2021-04-11 10:07 ` Xiang W
2021-04-11 21:29 ` Alistair Francis
2021-04-10 7:18 ` [PATCH 6/7] lib: utils: Copy over restricted root domain memregions to FDT domains Anup Patel
2021-04-11 10:07 ` Xiang W
2021-04-11 21:30 ` Alistair Francis
2021-04-10 7:18 ` [PATCH 7/7] lib: sbi: Make sbi_domain_memregion_initfw() a local function Anup Patel
2021-04-11 10:07 ` Xiang W
2021-04-11 21:32 ` Alistair Francis
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=3e0812e732394a3f39bd678332edd2cbc7478014.camel@126.com \
--to=wxjstz@126.com \
--cc=opensbi@lists.infradead.org \
/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