OpenSBI Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Alistair Francis <Alistair.Francis@wdc.com>
To: opensbi@lists.infradead.org
Subject: [PATCH 2/7] lib: sbi: Add sbi_domain_memregion_init() API
Date: Sun, 11 Apr 2021 21:22:39 +0000	[thread overview]
Message-ID: <7c2d319d2e8fd5b27ef18e68f5a67051ebbc73e7.camel@wdc.com> (raw)
In-Reply-To: <20210410071808.759856-3-anup.patel@wdc.com>

On Sat, 2021-04-10 at 12:48 +0530, Anup Patel wrote:
> This patch adds sbi_domain_memregion_init() helper API which can
> be used by platform support to initialize a domain memory region
> before adding it to the root domain.
> 
> Signed-off-by: Anup Patel <anup.patel@wdc.com>

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

> ---
> ?include/sbi/sbi_domain.h | 14 +++++++++++++
> ?lib/sbi/sbi_domain.c???? | 45 ++++++++++++++++++++++++++++++++--------
> ?2 files changed, 50 insertions(+), 9 deletions(-)
> 
> diff --git a/include/sbi/sbi_domain.h b/include/sbi/sbi_domain.h
> index 1f8b942..f9f4f7d 100644
> --- a/include/sbi/sbi_domain.h
> +++ b/include/sbi/sbi_domain.h
> @@ -127,6 +127,20 @@ ulong sbi_domain_get_assigned_hartmask(const
> struct sbi_domain *dom,
> ?/** Initialize a domain memory region as firmware region */
> ?void sbi_domain_memregion_initfw(struct sbi_domain_memregion *reg);
> ?
> +/**
> + * Initialize a domain memory region based on it's physical
> + * address and size.
> + *
> + * @param addr start physical address of memory region
> + * @param size physical size of memory region
> + * @param flags memory region flags
> + * @param reg pointer to memory region being initialized
> + */
> +void sbi_domain_memregion_init(unsigned long addr,
> +???????????????????????????????unsigned long size,
> +???????????????????????????????unsigned long flags,
> +???????????????????????????????struct sbi_domain_memregion *reg);
> +
> ?/**
> ? * Check whether we can access specified address for given mode and
> ? * memory region flags under a domain
> diff --git a/lib/sbi/sbi_domain.c b/lib/sbi/sbi_domain.c
> index 2849241..164f35c 100644
> --- a/lib/sbi/sbi_domain.c
> +++ b/lib/sbi/sbi_domain.c
> @@ -72,6 +72,35 @@ void sbi_domain_memregion_initfw(struct
> sbi_domain_memregion *reg)
> ????????sbi_memcpy(reg, &root_memregs[ROOT_FW_REGION], sizeof(*reg));
> ?}
> ?
> +void sbi_domain_memregion_init(unsigned long addr,
> +???????????????????????????????unsigned long size,
> +???????????????????????????????unsigned long flags,
> +???????????????????????????????struct sbi_domain_memregion *reg)
> +{
> +???????unsigned long base = 0, order;
> +
> +???????for (order = log2roundup(size) ; order <= __riscv_xlen;
> order++) {
> +???????????????if (order < __riscv_xlen) {
> +???????????????????????base = addr & ~((1UL << order) - 1UL);
> +???????????????????????if ((base <= addr) &&
> +?????????????????????????? (addr < (base + (1UL << order))) &&
> +?????????????????????????? (base <= (addr + size - 1UL)) &&
> +?????????????????????????? ((addr + size - 1UL) < (base + (1UL <<
> order))))
> +???????????????????????????????break;
> +???????????????} else {
> +???????????????????????base = 0;
> +???????????????????????break;
> +???????????????}
> +
> +???????}
> +
> +???????if (reg) {
> +???????????????reg->base = base;
> +???????????????reg->order = order;
> +???????????????reg->flags = flags;
> +???????}
> +}
> +
> ?bool sbi_domain_check_addr(const struct sbi_domain *dom,
> ?????????????????????????? unsigned long addr, unsigned long mode,
> ?????????????????????????? unsigned long access_flags)
> @@ -507,17 +536,15 @@ int sbi_domain_init(struct sbi_scratch *scratch,
> u32 cold_hartid)
> ????????const struct sbi_platform *plat = sbi_platform_ptr(scratch);
> ?
> ????????/* Root domain firmware memory region */
> -???????root_memregs[ROOT_FW_REGION].order = log2roundup(scratch-
> >fw_size);
> -???????root_memregs[ROOT_FW_REGION].base = scratch->fw_start &
> -???????????????????????????????~((1UL << root_memregs[0].order) -
> 1UL);
> -???????root_memregs[ROOT_FW_REGION].flags = 0;
> +???????sbi_domain_memregion_init(scratch->fw_start, scratch->fw_size,
> 0,
> +???????????????????????????????? &root_memregs[ROOT_FW_REGION]);
> ?
> ????????/* Root domain allow everything memory region */
> -???????root_memregs[ROOT_ALL_REGION].order = __riscv_xlen;
> -???????root_memregs[ROOT_ALL_REGION].base = 0;
> -???????root_memregs[ROOT_ALL_REGION].flags =
> (SBI_DOMAIN_MEMREGION_READABLE |
> -
> ???????????????????????????????????????????????SBI_DOMAIN_MEMREGION_WRIT
> EABLE |
> -
> ???????????????????????????????????????????????SBI_DOMAIN_MEMREGION_EXEC
> UTABLE);
> +???????sbi_domain_memregion_init(0, ~0UL,
> +???????????????????????????????? (SBI_DOMAIN_MEMREGION_READABLE |
> +????????????????????????????????? SBI_DOMAIN_MEMREGION_WRITEABLE |
> +????????????????????????????????? SBI_DOMAIN_MEMREGION_EXECUTABLE),
> +???????????????????????????????? &root_memregs[ROOT_ALL_REGION]);
> ?
> ????????/* Root domain memory region end */
> ????????root_memregs[ROOT_END_REGION].order = 0;


  parent reply	other threads:[~2021-04-11 21:22 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 [this message]
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
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=7c2d319d2e8fd5b27ef18e68f5a67051ebbc73e7.camel@wdc.com \
    --to=alistair.francis@wdc.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