lib: sbi_domain: Allow adding memrange to a particular domain from drivers

Currently, memregions of non-root domain only populated at domain creation
time which not flexible for drivers which create domain specific resources
(such as MPXY channels). Add new sbi_domain_add_memrange() function which
allows adding memrange to any domain at boot time.

Signed-off-by: Anup Patel <anup.patel@oss.qualcomm.com>
Reviewed-by: Pawandeep Oza <pawandeep.oza@oss.qualcomm.com>
Tested-by: Pawandeep Oza <pawandeep.oza@oss.qualcomm.com>
Link: https://lore.kernel.org/r/20260923032359.4041876-9-anup.patel@oss.qualcomm.com
Signed-off-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
Anup Patel authored and Anup Patel committed 2026-10-25 14:30:46 +05:30
1 parent 145bd4ccc0
commit c4f098bfa3
2 files changed
+38 -18

No files matched your search

+21 -2
View File
@@ -345,6 +345,22 @@ void sbi_domain_dump_all(const char *suffix);
*/ */
int sbi_domain_register(struct sbi_domain *dom); int sbi_domain_register(struct sbi_domain *dom);
/**
* Add a memory range with its flags to a domain
* @param dom pointer to domain
* @param addr start physical address of memory range
* @param size physical size of memory range
* @param align alignment of memory region
* @param region_flags memory range flags
*
* @return 0 on success
* @return SBI_EALREADY if memory region conflicts with the existing one
* @return SBI_EINVAL otherwise
*/
int sbi_domain_add_memrange(struct sbi_domain *dom,
unsigned long addr, unsigned long size,
unsigned long align, unsigned long region_flags);
/** /**
* Add a memory range with its flags to the root domain * Add a memory range with its flags to the root domain
* @param addr start physical address of memory range * @param addr start physical address of memory range
@@ -356,8 +372,11 @@ int sbi_domain_register(struct sbi_domain *dom);
* @return SBI_EALREADY if memory region conflicts with the existing one * @return SBI_EALREADY if memory region conflicts with the existing one
* @return SBI_EINVAL otherwise * @return SBI_EINVAL otherwise
*/ */
int sbi_domain_root_add_memrange(unsigned long addr, unsigned long size, static inline int sbi_domain_root_add_memrange(unsigned long addr, unsigned long size,
unsigned long align, unsigned long region_flags); unsigned long align, unsigned long region_flags)
{
return sbi_domain_add_memrange(&root, addr, size, align, region_flags);
}
/** Startup non-root domains */ /** Startup non-root domains */
int sbi_domain_startup(struct sbi_scratch *scratch, u32 cold_hartid); int sbi_domain_startup(struct sbi_scratch *scratch, u32 cold_hartid);
+17 -16
View File
@@ -722,16 +722,16 @@ int sbi_domain_register(struct sbi_domain *dom)
return 0; return 0;
} }
static int root_add_memregion(const struct sbi_domain_memregion *reg) static int add_memregion(struct sbi_domain *dom, const struct sbi_domain_memregion *reg)
{ {
int rc; int rc;
bool reg_merged; bool reg_merged;
struct sbi_domain_memregion *nreg, *nreg1; struct sbi_domain_memregion *nreg, *nreg1;
int root_memregs_count = sbi_domain_used_memregions(&root); int memregs_count = sbi_domain_used_memregions(dom);
/* Sanity checks */ /* Sanity checks */
if (!reg || domain_finalized || if (!reg || domain_finalized ||
(SBI_DOMAIN_MEMREGION_MAX <= root_memregs_count)) (SBI_DOMAIN_MEMREGION_MAX <= memregs_count))
return SBI_EINVAL; return SBI_EINVAL;
/* Check whether compatible region exists for the new one */ /* Check whether compatible region exists for the new one */
@@ -741,25 +741,25 @@ static int root_add_memregion(const struct sbi_domain_memregion *reg)
} }
/* Append the memregion to root memregions */ /* Append the memregion to root memregions */
nreg = &root.regions[root_memregs_count]; nreg = &dom->regions[memregs_count];
sbi_memcpy(nreg, reg, sizeof(*reg)); sbi_memcpy(nreg, reg, sizeof(*reg));
root_memregs_count++; memregs_count++;
root.regions[root_memregs_count].order = 0; dom->regions[memregs_count].order = 0;
/* Sort and optimize root regions */ /* Sort and optimize regions */
do { do {
/* Sanitize the root domain so that memregions are sorted */ /* Sanitize the domain so that memregions are sorted */
rc = sanitize_domain(&root); rc = sanitize_domain(dom);
if (rc) { if (rc) {
sbi_printf("%s: sanity checks failed for" sbi_printf("%s: sanity checks failed for"
" %s (error %d)\n", __func__, " %s (error %d)\n", __func__,
root.name, rc); dom->name, rc);
return rc; return rc;
} }
/* Merge consecutive memregions with same order and flags */ /* Merge consecutive memregions with same order and flags */
reg_merged = false; reg_merged = false;
sbi_domain_for_each_memregion(&root, nreg) { sbi_domain_for_each_memregion(dom, nreg) {
nreg1 = nreg + 1; nreg1 = nreg + 1;
if (!nreg1->order) if (!nreg1->order)
continue; continue;
@@ -768,12 +768,12 @@ static int root_add_memregion(const struct sbi_domain_memregion *reg)
(nreg->base + BIT(nreg->order)) == nreg1->base && (nreg->base + BIT(nreg->order)) == nreg1->base &&
nreg->order == nreg1->order && nreg->order == nreg1->order &&
nreg->flags == nreg1->flags) { nreg->flags == nreg1->flags) {
int i1 = nreg1 - root.regions; int i1 = nreg1 - dom->regions;
nreg->order++; nreg->order++;
sbi_memmove(nreg1, nreg1 + 1, sbi_memmove(nreg1, nreg1 + 1,
sizeof(*nreg1) * (root_memregs_count - i1)); sizeof(*nreg1) * (memregs_count - i1));
reg_merged = true; reg_merged = true;
root_memregs_count--; memregs_count--;
} }
} }
} while (reg_merged); } while (reg_merged);
@@ -781,7 +781,8 @@ static int root_add_memregion(const struct sbi_domain_memregion *reg)
return 0; return 0;
} }
int sbi_domain_root_add_memrange(unsigned long addr, unsigned long size, int sbi_domain_add_memrange(struct sbi_domain *dom,
unsigned long addr, unsigned long size,
unsigned long align, unsigned long region_flags) unsigned long align, unsigned long region_flags)
{ {
int rc; int rc;
@@ -799,7 +800,7 @@ int sbi_domain_root_add_memrange(unsigned long addr, unsigned long size,
(end - pos) : align; (end - pos) : align;
sbi_domain_memregion_init(pos, rsize, region_flags, &reg); sbi_domain_memregion_init(pos, rsize, region_flags, &reg);
rc = root_add_memregion(&reg); rc = add_memregion(dom, &reg);
if (rc) if (rc)
return rc; return rc;
pos += rsize; pos += rsize;