OpenSBI domain data support
v2 cover OpenSBI domain data support
This series extends the OpenSBI domain support to allow per-domain data from different parts of OpenSBI. Also extend OpenSBI domain context as the first user of OpenSBI domain data support.
The first 6 patches of this series are miscellaneous improvements which were pending for quite some time.
These patches can also be found in the sbi_domain_imp_v2 branch at:
https://github.com/avpatel/opensbi.git
Changes since v1:
- Typo fixes in PATCH1 to PATCH4
- Use current_hartindex() wherever applicable in PATCH8
Anup Patel (9):
lib: utils/ipi: Use sbi_domain_root_add_memrange() for ACLINT mswi
lib: utils/irqchip: Use sbi_domain_root_add_memrange() for IMSIC
lib: utils/irqchip: Use sbi_domain_root_add_memrange() for APLIC
lib: sbi_domain: Make sbi_domain_root_add_memregion() as local
function
lib: utils/fdt: Use sbi_domain_memregion_init() when parsing domains
include: sbi: Remove cyclic include in sbi_domain_context.h
lib: sbi: Introduce domain data
lib: sbi_domain: Use domain data support for per-domain hart context
docs: Remove hartindex_to_context_table from domain_support.md
docs/domain_support.md | 2 - include/sbi/sbi_domain.h | 15 +--- include/sbi/sbi_domain_context.h | 57 +++---------- include/sbi/sbi_domain_data.h | 93 +++++++++++++++++++++ lib/sbi/objects.mk | 1 + lib/sbi/sbi_domain.c | 24 +++++- lib/sbi/sbi_domain_context.c | 105 ++++++++++++++++++++--- lib/sbi/sbi_domain_data.c | 138 +++++++++++++++++++++++++++++++ lib/utils/fdt/fdt_domain.c | 14 ++-- lib/utils/ipi/aclint_mswi.c | 20 ++--- lib/utils/irqchip/aplic.c | 11 +-- lib/utils/irqchip/imsic.c | 14 ++-- 12 files changed, 383 insertions(+), 111 deletions(-) create mode 100644 include/sbi/sbi_domain_data.h create mode 100644 lib/sbi/sbi_domain_data.c
Signature · 1 line
2.43.0
PATCH v2 1/9 lib: utils/ipi: Use sbi_domain_root_add_memrange() for ACLINT mswi
The sbi_domain_root_add_memrange() should be preferred for creating multiple memregions over a range. Update ACLINT mswi driver to use sbi_domain_root_add_memrange() instead of explicitly registering memregions.
--- lib/utils/ipi/aclint_mswi.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-)
lib/utils/ipi/aclint_mswi.c +6 -14
@@ -84,8 +84,6 @@ int aclint_mswi_cold_init(struct aclint_mswi_data *mswi)u32 i;int rc;struct sbi_scratch *scratch; -unsigned long pos, region_size; -struct sbi_domain_memregion reg;/* Sanity checks */ if (!mswi || (mswi->addr & (ACLINT_MSWI_ALIGN - 1)) ||
@@ -114,18 +112,12 @@ int aclint_mswi_cold_init(struct aclint_mswi_data *mswi) }/* Add MSWI regions to the root domain */ -for (pos =0 ; pos < mswi->size; pos +=ACLINT_MSWI_ALIGN ) { - region_size = ((mswi->size - pos) <ACLINT_MSWI_ALIGN ) ? - (mswi->size - pos) :ACLINT_MSWI_ALIGN ; -sbi_domain_memregion_init (mswi->addr + pos, region_size, - (SBI_DOMAIN_MEMREGION_MMIO | -SBI_DOMAIN_MEMREGION_M_READABLE | -SBI_DOMAIN_MEMREGION_M_WRITABLE ), - ®); - rc =sbi_domain_root_add_memregion (®); -if (rc) -return rc; - } + rc =sbi_domain_root_add_memrange (mswi->addr, mswi->size,ACLINT_MSWI_ALIGN , +SBI_DOMAIN_MEMREGION_MMIO | +SBI_DOMAIN_MEMREGION_M_READABLE | +SBI_DOMAIN_MEMREGION_M_WRITABLE ); +if (rc) +return rc;sbi_ipi_set_device (&aclint_mswi);
Signature · 1 line
2.43.0
PATCH v2 2/9 lib: utils/irqchip: Use sbi_domain_root_add_memrange() for IMSIC
In reply to Anup PatelThe sbi_domain_root_add_memrange() should be preferred for creating multiple memregions over a range. Update IMSIC driver to use sbi_domain_root_add_memrange() instead of explicitly registering memregions.
--- lib/utils/irqchip/imsic.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
lib/utils/irqchip/imsic.c +6 -8
@@ -348,7 +348,6 @@ int imsic_data_check(struct imsic_data *imsic)int imsic_cold_irqchip_init (struct imsic_data *imsic) {int i, rc; -struct sbi_domain_memregion reg;/* Sanity checks */ rc =imsic_data_check (imsic);
@@ -378,13 +377,12 @@ int imsic_cold_irqchip_init(struct imsic_data *imsic)/* Add IMSIC regions to the root domain */ for (i =0 ; i <IMSIC_MAX_REGS && imsic->regs[i].size; i++) { -sbi_domain_memregion_init (imsic->regs[i].addr, - imsic->regs[i].size, - (SBI_DOMAIN_MEMREGION_MMIO | -SBI_DOMAIN_MEMREGION_M_READABLE | -SBI_DOMAIN_MEMREGION_M_WRITABLE ), - ®); - rc =sbi_domain_root_add_memregion (®); + rc =sbi_domain_root_add_memrange (imsic->regs[i].addr, + imsic->regs[i].size, +IMSIC_MMIO_PAGE_SZ , +SBI_DOMAIN_MEMREGION_MMIO | +SBI_DOMAIN_MEMREGION_M_READABLE | +SBI_DOMAIN_MEMREGION_M_WRITABLE );if (rc)return rc; }
Signature · 1 line
2.43.0
PATCH v2 3/9 lib: utils/irqchip: Use sbi_domain_root_add_memrange() for APLIC
In reply to Anup PatelThe sbi_domain_root_add_memrange() should be preferred for creating multiple memregions over a range. Update APLIC driver to use sbi_domain_root_add_memrange() instead of explicitly registering memregions.
--- lib/utils/irqchip/aplic.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
lib/utils/irqchip/aplic.c +4 -7
@@ -169,7 +169,6 @@ int aplic_cold_irqchip_init(struct aplic_data *aplic) {int rc;u32 i, j, tmp; -struct sbi_domain_memregion reg;struct aplic_delegate_data *deleg;u32 first_deleg_irq, last_deleg_irq;
@@ -268,12 +267,10 @@ int aplic_cold_irqchip_init(struct aplic_data *aplic) ((first_deleg_irq < last_deleg_irq) && (last_deleg_irq == aplic->num_source) && (first_deleg_irq == 1))) { -sbi_domain_memregion_init (aplic->addr, aplic->size, - (SBI_DOMAIN_MEMREGION_MMIO | -SBI_DOMAIN_MEMREGION_M_READABLE | -SBI_DOMAIN_MEMREGION_M_WRITABLE ), - ®); - rc =sbi_domain_root_add_memregion (®); + rc =sbi_domain_root_add_memrange (aplic->addr, aplic->size,PAGE_SIZE , +SBI_DOMAIN_MEMREGION_MMIO | +SBI_DOMAIN_MEMREGION_M_READABLE | +SBI_DOMAIN_MEMREGION_M_WRITABLE );if (rc)return rc; }
Signature · 1 line
2.43.0
PATCH v2 4/9 lib: sbi_domain: Make sbi_domain_root_add_memregion() as local function
In reply to Anup PatelThe sbi_domain_root_add_memregion() is only used within sbi_domain implementation so rename and make it a local function.
--- include/sbi/sbi_domain.h | 10 ---------- lib/sbi/sbi_domain.c | 4 ++-- 2 files changed, 2 insertions(+), 12 deletions(-)
include/sbi/sbi_domain.h +0 -10
@@ -292,16 +292,6 @@ void sbi_domain_dump_all(const char *suffix);int sbi_domain_register (struct sbi_domain *dom,const struct sbi_hartmask *assign_mask); -/** -* Add a memory region to the root domain -* @param reg pointer to the memory region to be added -* -* @return 0 on success -* @return SBI_EALREADY if memory region conflicts with the existing one -* @return SBI_EINVAL otherwise -*/ -int sbi_domain_root_add_memregion (const struct sbi_domain_memregion *reg); -/** * Add a memory range with its flags to the root domain * @param addr start physical address of memory range
lib/sbi/sbi_domain.c +2 -2
@@ -589,7 +589,7 @@ int sbi_domain_register(struct sbi_domain *dom,return 0 ; } -int sbi_domain_root_add_memregion (const struct sbi_domain_memregion *reg) +static int root_add_memregion (const struct sbi_domain_memregion *reg) {int rc;bool reg_merged;
@@ -667,7 +667,7 @@ int sbi_domain_root_add_memrange(unsigned long addr, unsigned long size, (end - pos) : align;sbi_domain_memregion_init (pos, rsize, region_flags, ®); - rc =sbi_domain_root_add_memregion (®); + rc =root_add_memregion (®);if (rc)return rc; pos += rsize;
Signature · 1 line
2.43.0
PATCH v2 5/9 lib: utils/fdt: Use sbi_domain_memregion_init() when parsing domains
In reply to Anup PatelUse sbi_domain_memregion_init() at the time of parsing domains from FDT so that sbi_domain_memregion_init() is always used for setting up all memregions.
--- lib/utils/fdt/fdt_domain.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
lib/utils/fdt/fdt_domain.c +8 -6
@@ -253,8 +253,8 @@ static int __fdt_parse_region(const void *fdt, int domain_offset,u32 val32;u64 val64;const u32 *val; +unsigned long base, order, flags;struct parse_region_data *preg = opaque; -struct sbi_domain_memregion *region;/* * Non-root domains cannot add a region with only M-mode
@@ -271,7 +271,6 @@ static int __fdt_parse_region(const void *fdt, int domain_offset,/* Find next region of the domain */ if (preg->max_regions <= preg->region_count)return SBI_ENOSPC ; - region = &preg->dom->regions[preg->region_count];/* Read "base" DT property */ val =fdt_getprop (fdt, region_offset,"base" , &len);
@@ -279,7 +278,7 @@ static int __fdt_parse_region(const void *fdt, int domain_offset,return SBI_EINVAL ; val64 =fdt32_to_cpu (val[0 ]); val64 = (val64 <<32 ) |fdt32_to_cpu (val[1 ]); - region->base = val64; + base = val64;/* Read "order" DT property */ val =fdt_getprop (fdt, region_offset,"order" , &len);
@@ -288,12 +287,15 @@ static int __fdt_parse_region(const void *fdt, int domain_offset, val32 =fdt32_to_cpu (*val);if (val32 <3 || __riscv_xlen < val32)return SBI_EINVAL ; - region->order = val32; + order = val32;/* Read "mmio" DT property */ - region->flags = region_access &SBI_DOMAIN_MEMREGION_ACCESS_MASK ; + flags = region_access &SBI_DOMAIN_MEMREGION_ACCESS_MASK ;if (fdt_get_property (fdt, region_offset,"mmio" ,NULL )) - region->flags |=SBI_DOMAIN_MEMREGION_MMIO ; + flags |=SBI_DOMAIN_MEMREGION_MMIO ; + +sbi_domain_memregion_init (base, (order == __riscv_xlen) ? ~0UL :BIT (order), + flags, &preg->dom->regions[preg->region_count]); preg->region_count++;
Signature · 1 line
2.43.0
PATCH v2 6/9 include: sbi: Remove cyclic include in sbi_domain_context.h
In reply to Anup PatelThe sbi_domain_context.h includes sbi_domain.h and the sbi_domain.h also includes sbi_domain_context.h. Remove this cyclic include in sbi_domain_context.h.
--- include/sbi/sbi_domain_context.h | 3 ++- lib/sbi/sbi_domain_context.c | 1 + 2 files changed, 3 insertions(+), 1 deletion(-)
include/sbi/sbi_domain_context.h +2 -1
@@ -9,7 +9,8 @@#include <sbi/sbi_types.h> #include <sbi/sbi_trap.h> -#include <sbi/sbi_domain.h> + +struct sbi_domain ;/** Context representation for a hart within a domain */ struct sbi_context {
lib/sbi/sbi_domain_context.c +1 -0
@@ -13,6 +13,7 @@#include <sbi/sbi_heap.h> #include <sbi/sbi_scratch.h> #include <sbi/sbi_string.h> +#include <sbi/sbi_domain.h> #include <sbi/sbi_domain_context.h> /**
Signature · 1 line
2.43.0
PATCH v2 7/9 lib: sbi: Introduce domain data
In reply to Anup PatelDifferent parts of OpenSBI require their own per-domain data so introduce domain data (or sbi_domain_data) which can be registered by any part of OpenSBI. Using the domain data, the domain framework will create a data pointer for every domain which can be used to maintain some per-domain state.
--- include/sbi/sbi_domain.h | 3 + include/sbi/sbi_domain_data.h | 93 +++++++++++++++++++++++ lib/sbi/objects.mk | 1 + lib/sbi/sbi_domain.c | 11 +++ lib/sbi/sbi_domain_data.c | 138 ++++++++++++++++++++++++++++++++++ 5 files changed, 246 insertions(+) create mode 100644 include/sbi/sbi_domain_data.h create mode 100644 lib/sbi/sbi_domain_data.c
include/sbi/sbi_domain.h +3 -0
@@ -15,6 +15,7 @@#include <sbi/sbi_types.h> #include <sbi/sbi_hartmask.h> #include <sbi/sbi_domain_context.h> +#include <sbi/sbi_domain_data.h> struct sbi_scratch ;
@@ -163,6 +164,8 @@ struct sbi_domain_memregion {struct sbi_domain {/** Node in linked list of domains */ struct sbi_dlist node; +/** Internal state of per-domain data */ +struct sbi_domain_data_priv data_priv;/** Logical index of this domain */ u32 index;/** HARTs assigned to this domain */
include/sbi/sbi_domain_data.h new file +93 -0
93 lines not on this page · raw message
lib/sbi/objects.mk +1 -0
@@ -65,6 +65,7 @@ libsbi-objs-y += sbi_bitmap.o libsbi-objs-y += sbi_bitops.o libsbi-objs-y += sbi_console.o libsbi-objs-y += sbi_domain_context.o +libsbi-objs-y += sbi_domain_data.o libsbi-objs-y += sbi_domain.o libsbi-objs-y += sbi_emulate_csr.o libsbi-objs-y += sbi_fifo.o
lib/sbi/sbi_domain.c +11 -0
@@ -586,6 +586,15 @@ int sbi_domain_register(struct sbi_domain *dom, } } +/* Setup data for the discovered domain */ + rc =sbi_domain_setup_data (dom); +if (rc) { +sbi_printf ("%s: domain data setup failed for %s (error %d)\n" , + __func__, dom->name, rc); +sbi_list_del (&dom->node); +return rc; + } +return 0 ; }
@@ -752,6 +761,8 @@ int sbi_domain_init(struct sbi_scratch *scratch, u32 cold_hartid)struct sbi_domain_memregion *root_memregs;const struct sbi_platform *plat =sbi_platform_ptr (scratch); +SBI_INIT_LIST_HEAD (&domain_list); +if (scratch->fw_rw_offset ==0 || (scratch->fw_rw_offset & (scratch->fw_rw_offset -1 )) !=0 ) { sbi_printf("%s: fw_rw_offset is not a power of 2 (0x%lx)\n",
lib/sbi/sbi_domain_data.c new file +138 -0
138 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v2 8/9 lib: sbi_domain: Use domain data support for per-domain hart context
In reply to Anup PatelThe per-domain hartindex_to_context_table[] is yet another per-domain data required for implementing hart entry into (or exit from) domain.
Use the recently added domain data support for per-domain hart context so that a dedicated hartindex_to_context_table[] in struct sbi_domain is not needed.
--- include/sbi/sbi_domain.h | 2 - include/sbi/sbi_domain_context.h | 56 +++-------------- lib/sbi/sbi_domain.c | 9 ++- lib/sbi/sbi_domain_context.c | 104 +++++++++++++++++++++++++++---- 4 files changed, 109 insertions(+), 62 deletions(-)
include/sbi/sbi_domain.h +0 -2
@@ -176,8 +176,6 @@ struct sbi_domain {char name[64 ];/** Possible HARTs in this domain */ const struct sbi_hartmask *possible_harts; -/** Contexts for possible HARTs indexed by hartindex */ -struct sbi_context *hartindex_to_context_table[SBI_HARTMASK_MAX_BITS ];/** Array of memory regions terminated by a region with order zero */ struct sbi_domain_memregion *regions;/** HART id of the HART booting this domain */
include/sbi/sbi_domain_context.h +10 -46
69 lines not on this page · raw message
lib/sbi/sbi_domain.c +8 -1
@@ -780,11 +780,16 @@ int sbi_domain_init(struct sbi_scratch *scratch, u32 cold_hartid)if (!domain_hart_ptr_offset)return SBI_ENOMEM ; +/* Initialize domain context support */ + rc =sbi_domain_context_init (); +if (rc) + goto fail_free_domain_hart_ptr_offset; + root_memregs =sbi_calloc (sizeof (*root_memregs),ROOT_REGION_MAX +1 );if (!root_memregs) {sbi_printf ("%s: no memory for root regions\n" , __func__); rc =SBI_ENOMEM ; - goto fail_free_domain_hart_ptr_offset; + goto fail_deinit_context; } root.regions = root_memregs;
@@ -849,6 +854,8 @@ fail_free_root_hmask:sbi_free (root_hmask); fail_free_root_memregs:sbi_free (root_memregs); +fail_deinit_context: +sbi_domain_context_deinit (); fail_free_domain_hart_ptr_offset:sbi_scratch_free_offset (domain_hart_ptr_offset);return rc;
lib/sbi/sbi_domain_context.c +91 -13
154 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v2 9/9 docs: Remove hartindex_to_context_table from domain_support.md
In reply to Anup PatelThe hartindex_to_context_table field is no longer part of sbi_domain so remove related documentation from domain_support.md.
--- docs/domain_support.md | 2 -- 1 file changed, 2 deletions(-)
docs/domain_support.md +0 -2
@@ -41,7 +41,6 @@ has following details: * **name** - Name of this domain * **assigned_harts** - HARTs assigned to this domain * **possible_harts** - HARTs possible in this domain -* **hartindex_to_context_table** - Contexts corresponding to possible HARTs * **regions** - Array of memory regions terminated by a memory region with order zero * **boot_hartid** - HART id of the HART booting this domain. The domain
@@ -81,7 +80,6 @@ following manner: platform support * **possible_harts** - All valid HARTs of a RISC-V platform are possible HARTs of the ROOT domain -* **hartindex_to_context_table** - Contexts corresponding to ROOT domain's possible HARTs * **regions** - Two memory regions available to the ROOT domain: **A)** A memory region to protect OpenSBI firmware from S-mode and U-mode **B)** A memory region of **order=__riscv_xlen** allowing S-mode and
Signature · 1 line
2.43.0
Anup Patel
Appliedv2 cover OpenSBI domain data support
In reply to Anup PatelQuoted 15 lines · On Thu, Oct 10, 2024 at 2:31?PM Anup Patel <[email protected]> wrote:
This series extends the OpenSBI domain support to allow per-domain data from different parts of OpenSBI. Also extend OpenSBI domain context as the first user of OpenSBI domain data support.
The first 6 patches of this series are miscellaneous improvements which were pending for quite some time.
These patches can also be found in the
sbi_domain_imp_v2branch at:
https://github.com/avpatel/opensbi.gitChanges since v1:
- Typo fixes in PATCH1 to PATCH4
- Usecurrent_hartindex()wherever applicable in PATCH8
Quoted 11 lines
Anup Patel (9):
lib: utils/ipi: Usesbi_domain_root_add_memrange()for ACLINT mswi
lib: utils/irqchip: Usesbi_domain_root_add_memrange()for IMSIC
lib: utils/irqchip: Usesbi_domain_root_add_memrange()for APLIC
lib:sbi_domain: Makesbi_domain_root_add_memregion()as local
function
lib: utils/fdt: Usesbi_domain_memregion_init()when parsing domains
include: sbi: Remove cyclic include insbi_domain_context.h
lib: sbi: Introduce domain data
lib:sbi_domain: Use domain data support for per-domain hart context
docs: Removehartindex_to_context_tablefrom domain_support.md
Applied this series to the riscv/opensbi repo.
Regards,
Anup
Quoted 20 lines
docs/domain_support.md | 2 - include/sbi/sbi_domain.h | 15 +--- include/sbi/sbi_domain_context.h | 57 +++---------- include/sbi/sbi_domain_data.h | 93 +++++++++++++++++++++ lib/sbi/objects.mk | 1 + lib/sbi/sbi_domain.c | 24 +++++- lib/sbi/sbi_domain_context.c | 105 ++++++++++++++++++++--- lib/sbi/sbi_domain_data.c | 138 +++++++++++++++++++++++++++++++ lib/utils/fdt/fdt_domain.c | 14 ++-- lib/utils/ipi/aclint_mswi.c | 20 ++--- lib/utils/irqchip/aplic.c | 11 +-- lib/utils/irqchip/imsic.c | 14 ++-- 12 files changed, 383 insertions(+), 111 deletions(-) create mode 100644 include/sbi/sbi_domain_data.h create mode 100644 lib/sbi/sbi_domain_data.c--
2.43.0