lib: sbi: Introduce per-domain MPXY state
v2 cover lib: sbi: Introduce per-domain MPXY state
When multiple supervisor domains need to communicate with OpenSBI through MPXY channel, they will allocate shared memory from their own memory region, thus the MPXY state need to be per-domain and per-hart data.
Changes since v1:
- Addressed conflict with master branch
Alvin Chang (4):
lib: sbi_mpxy: Export MPXY data structures
lib: sbi_domain: Introduce per-domain MPXY state data
lib: sbi_mpxy: Convert MPXY state to per-domain data
lib: sbi: sbi_init: Allocate MPXY state for each domain
include/sbi/sbi_domain.h | 1 + include/sbi/sbi_domain_mpxy_state.h | 50 ++++++++++++++++++++ include/sbi/sbi_mpxy.h | 15 ++++++ lib/sbi/objects.mk | 1 + lib/sbi/sbi_domain.c | 9 +++- lib/sbi/sbi_domain_mpxy_state.c | 47 +++++++++++++++++++ lib/sbi/sbi_init.c | 16 ++++--- lib/sbi/sbi_mpxy.c | 72 +++++++++++++---------------- 8 files changed, 164 insertions(+), 47 deletions(-) create mode 100644 include/sbi/sbi_domain_mpxy_state.h create mode 100644 lib/sbi/sbi_domain_mpxy_state.c
Signature · 1 line
2.34.1
PATCH v2 1/4 lib: sbi_mpxy: Export MPXY data structures
Move MPXY data structures from private C source file to public header so that other modules can reference them.
--- include/sbi/sbi_mpxy.h | 15 +++++++++++++++ lib/sbi/sbi_mpxy.c | 15 --------------- 2 files changed, 15 insertions(+), 15 deletions(-)
include/sbi/sbi_mpxy.h +15 -0
@@ -14,6 +14,21 @@struct sbi_scratch ; +/** Per hart shared memory */ +struct mpxy_shmem { +unsigned long shmem_addr_lo; +unsigned long shmem_addr_hi; +}; + +struct mpxy_state { +/* MSI support in MPXY */ +bool msi_avail; +/* SSE support in MPXY */ +bool sse_avail; +/* MPXY Shared memory details */ +struct mpxy_shmem shmem; +}; +#define SBI_MPXY_MSGPROTO_VERSION (Major, Minor) ((Major << 16) | Minor)enum sbi_mpxy_attr_id {
lib/sbi/sbi_mpxy.c +0 -15
@@ -74,21 +74,6 @@ static SBI_LIST_HEAD(mpxy_channel_list);#error "Undefined XLEN"#endif -/** Per hart shared memory */ -struct mpxy_shmem { -unsigned long shmem_addr_lo; -unsigned long shmem_addr_hi; -}; - -struct mpxy_state { -/* MSI support in MPXY */ -bool msi_avail; -/* SSE support in MPXY */ -bool sse_avail; -/* MPXY Shared memory details */ -struct mpxy_shmem shmem; -}; -/** Disable hart shared memory */ static inline void sbi_mpxy_shmem_disable (struct mpxy_state *ms) {
Signature · 1 line
2.34.1
PATCH v2 1/4 lib: sbi_mpxy: Export MPXY data structures
Quoted 6 lines · On Tue, Feb 25, 2025 at 6:47?AM Alvin Chang <[email protected]> wrote:
Move MPXY data structures from private C source file to public header so that other modules can reference them.
Signed-off-by Alvin Chang <[email protected]>Reviewed-by Yu-Chien Peter Lin <[email protected]>
No need for this patch.
Regards,
Anup
Quoted 65 lines
--- include/sbi/sbi_mpxy.h | 15 +++++++++++++++ lib/sbi/sbi_mpxy.c | 15 --------------- 2 files changed, 15 insertions(+), 15 deletions(-)include/sbi/sbi_mpxy.h +15
-0@@ -14,6 +14,21 @@struct sbi_scratch ; +/** Per hart shared memory */ +struct mpxy_shmem { +unsigned long shmem_addr_lo; +unsigned long shmem_addr_hi; +}; + +struct mpxy_state { +/* MSI support in MPXY */ +bool msi_avail; +/* SSE support in MPXY */ +bool sse_avail; +/* MPXY Shared memory details */ +struct mpxy_shmem shmem; +}; +#define SBI_MPXY_MSGPROTO_VERSION (Major, Minor) ((Major << 16) | Minor)enum sbi_mpxy_attr_id {lib/sbi/sbi_mpxy.c +0
-16@@ -74,21 +74,6 @@ static SBI_LIST_HEAD(mpxy_channel_list);#error "Undefined XLEN"#endif -/** Per hart shared memory */ -struct mpxy_shmem { -unsigned long shmem_addr_lo; -unsigned long shmem_addr_hi; -}; - -struct mpxy_state { -/* MSI support in MPXY */ -bool msi_avail; -/* SSE support in MPXY */ -bool sse_avail; -/* MPXY Shared memory details */ -struct mpxy_shmem shmem; -}; -/** Disable hart shared memory */ static inline void sbi_mpxy_shmem_disable (struct mpxy_state *ms) { --2.34.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
PATCH v2 2/4 lib: sbi_domain: Introduce per-domain MPXY state data
In reply to Alvin ChangWhen multiple supervisor domains need to communicate with OpenSBI through MPXY channel, they will allocate shared memory from their own memory region (e.g. using alloc_pages() in Linux; memalign() in OP-TEE OS), thus the MPXY state need to be per-domain and per-hart data.
--- include/sbi/sbi_domain.h | 1 + include/sbi/sbi_domain_mpxy_state.h | 50 +++++++++++++++++++++++++++++ lib/sbi/objects.mk | 1 + lib/sbi/sbi_domain.c | 9 +++++- lib/sbi/sbi_domain_mpxy_state.c | 47 +++++++++++++++++++++++++++ 5 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 include/sbi/sbi_domain_mpxy_state.h create mode 100644 lib/sbi/sbi_domain_mpxy_state.c
include/sbi/sbi_domain.h +1 -0
@@ -16,6 +16,7 @@#include <sbi/sbi_hartmask.h> #include <sbi/sbi_domain_context.h> #include <sbi/sbi_domain_data.h> +#include <sbi/sbi_domain_mpxy_state.h> struct sbi_scratch ;
include/sbi/sbi_domain_mpxy_state.h new file +50 -0
50 lines not on this page · raw message
lib/sbi/objects.mk +1 -0
@@ -69,6 +69,7 @@ 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_mpxy_state.o libsbi-objs-y += sbi_domain.o libsbi-objs-y += sbi_double_trap.o libsbi-objs-y += sbi_emulate_csr.o
lib/sbi/sbi_domain.c +8 -1
@@ -800,11 +800,16 @@ int sbi_domain_init(struct sbi_scratch *scratch, u32 cold_hartid)if (rc) goto fail_free_domain_hart_ptr_offset; +/* Initialize domain MPXY state support */ + rc =sbi_domain_mpxy_state_init (); +if (rc) + goto fail_deinit_context; + 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_deinit_context; + goto fail_deinit_mpxy_state; } root.regions = root_memregs;
@@ -869,6 +874,8 @@ fail_free_root_hmask:sbi_free (root_hmask); fail_free_root_memregs:sbi_free (root_memregs); +fail_deinit_mpxy_state: +sbi_domain_mpxy_state_deinit (); fail_deinit_context:sbi_domain_context_deinit (); fail_free_domain_hart_ptr_offset:
lib/sbi/sbi_domain_mpxy_state.c new file +47 -0
47 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v2 2/4 lib: sbi_domain: Introduce per-domain MPXY state data
Quoted 11 lines · On Tue, Feb 25, 2025 at 6:47?AM Alvin Chang <[email protected]> wrote:
When multiple supervisor domains need to communicate with OpenSBI through MPXY channel, they will allocate shared memory from their own memory region (e.g. using
alloc_pages()in Linux;memalign()in OP-TEE OS), thus the MPXY state need to be per-domain and per-hart data.Signed-off-by Yu-Chien Peter Lin <[email protected]>Co-developed-by Yong Li <[email protected]>Signed-off-by Yong Li <[email protected]>Reviewed-by Alvin Chang <[email protected]>
Quoted 6 lines
--- include/sbi/sbi_domain.h | 1 + include/sbi/sbi_domain_mpxy_state.h | 50 +++++++++++++++++++++++++++++ lib/sbi/objects.mk | 1 + lib/sbi/sbi_domain.c | 9 +++++- lib/sbi/sbi_domain_mpxy_state.c | 47 +++++++++++++++++++++++++++
No need for a separate sbi_domain_mpxy_state.c and sbi_domain_mpxy_state.h
The sbi_mpxy_init() can do sbi_domain_register_data() instead of doing it very early in sbi_domain_init. This means we can squash this change into your PATCH3 and drop PATCH1.
Regards,
Anup
Quoted 176 lines
5 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 include/sbi/sbi_domain_mpxy_state.h create mode 100644 lib/sbi/sbi_domain_mpxy_state.cinclude/sbi/sbi_domain.h +1
-0@@ -16,6 +16,7 @@#include <sbi/sbi_hartmask.h> #include <sbi/sbi_domain_context.h> #include <sbi/sbi_domain_data.h> +#include <sbi/sbi_domain_mpxy_state.h> struct sbi_scratch ;include/sbi/sbi_domain_mpxy_state.h new file +50
-0@@ -0,0 +1,50 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2024 Intel Corporation. +* Copyright (c) 2024-2025 Andes Technology Corporation. +*/ + +#ifndef __SBI_DOMAIN_MPXY_STATE_H__ +#define __SBI_DOMAIN_MPXY_STATE_H__ + +#include <sbi/sbi_types.h> + +struct sbi_domain ; +struct mpxy_state ; + +/** +* Get per-domain MPXY state pointer for a given domain and HART index +* @param dom pointer to domain +* @param hartindex the HART index +* +* @return per-domain MPXY state pointer for given HART index +*/ +struct mpxy_state *sbi_domain_get_mpxy_state (struct sbi_domain *dom, +u32 hartindex); + +/** +* Set per-domain MPXY state pointer for a given domain and HART index +* @param dom pointer to domain +* @param hartindex the HART index +* @param ms pointer to MPXY state +*/ +void sbi_domain_set_mpxy_state (struct sbi_domain *dom,u32 hartindex, +struct mpxy_state *ms); + +/** Macro to obtain the current hart's MPXY state pointer */ +#define sbi_domain_mpxy_state_thishart_ptr () \ + sbi_domain_get_mpxy_state(sbi_domain_thishart_ptr(), \ + current_hartindex()) + +/** +* Initialize domain MPXY state support +* +* @return 0 on success and negative error code on failure +*/ +int sbi_domain_mpxy_state_init (void ); + +/* Deinitialize domain MPXY state support */ +void sbi_domain_mpxy_state_deinit (void ); + +#endif lib/sbi/objects.mk +1
-0@@ -69,6 +69,7 @@ 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_mpxy_state.o libsbi-objs-y += sbi_domain.o libsbi-objs-y += sbi_double_trap.o libsbi-objs-y += sbi_emulate_csr.olib/sbi/sbi_domain.c +8
-1@@ -800,11 +800,16 @@ int sbi_domain_init(struct sbi_scratch *scratch, u32 cold_hartid)if (rc) goto fail_free_domain_hart_ptr_offset; +/* Initialize domain MPXY state support */ + rc =sbi_domain_mpxy_state_init (); +if (rc) + goto fail_deinit_context; + 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_deinit_context; + goto fail_deinit_mpxy_state; } root.regions = root_memregs;@@ -869,6 +874,8 @@ fail_free_root_hmask:sbi_free (root_hmask); fail_free_root_memregs:sbi_free (root_memregs); +fail_deinit_mpxy_state: +sbi_domain_mpxy_state_deinit (); fail_deinit_context:sbi_domain_context_deinit (); fail_free_domain_hart_ptr_offset:lib/sbi/sbi_domain_mpxy_state.c new file +47
-1@@ -0,0 +1,47 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2024 Intel Corporation. +* Copyright (c) 2024-2025 Andes Technology Corporation. +*/ + +#include <sbi/sbi_domain.h> + +struct domain_mpxy_state_priv { +/** MPXY state for possible HARTs indexed by hartindex */ +struct mpxy_state *hartindex_to_mpxy_state_table[SBI_HARTMASK_MAX_BITS ]; +}; + +static struct sbi_domain_data dmspriv = { + .data_size =sizeof (struct domain_mpxy_state_priv ), +}; + +struct mpxy_state *sbi_domain_get_mpxy_state (struct sbi_domain *dom, +u32 hartindex) +{ +struct domain_mpxy_state_priv *dmsp = +sbi_domain_data_ptr (dom, &dmspriv); + +return (dmsp && hartindex <SBI_HARTMASK_MAX_BITS ) ? + dmsp->hartindex_to_mpxy_state_table[hartindex] :NULL ; +} + +void sbi_domain_set_mpxy_state (struct sbi_domain *dom,u32 hartindex, +struct mpxy_state *ms) +{ +struct domain_mpxy_state_priv *dmsp = +sbi_domain_data_ptr (dom, &dmspriv); + +if (dmsp && hartindex <SBI_HARTMASK_MAX_BITS ) + dmsp->hartindex_to_mpxy_state_table[hartindex] = ms; +} + +int sbi_domain_mpxy_state_init (void ) +{ +return sbi_domain_register_data (&dmspriv); +} + +void sbi_domain_mpxy_state_deinit (void ) +{ +sbi_domain_unregister_data (&dmspriv); +} --2.34.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
PATCH v2 2/4 lib: sbi_domain: Introduce per-domain MPXY state data
Hi Anup,
Quoted 30 lines
-----Original Message-----
From: Anup Patel <[email protected]>
Sent: Sunday, March 23, 2025 12:18 PM
To: Alvin Che-Chia Chang(???) <[email protected]>
Cc: opensbi at lists.infradead.org; Yu-Chien Peter Lin <[email protected]>; Yong Li <[email protected]>
Subject: Re: [PATCH v2 2/4] lib:sbi_domain: Introduce per-domain MPXY state data[EXTERNAL MAIL]
Quoted 6 lines · On Tue, Feb 25, 2025 at 6:47?AM Alvin Chang <[email protected]> wrote:
When multiple supervisor domains need to communicate with OpenSBI through MPXY channel, they will allocate shared memory from their own memory region (e.g. using
alloc_pages()in Linux;memalign()in OP-TEE OS), thus the MPXY state need to be per-domain and per-hart data.Quoted 7 lines
Signed-off-by Yu-Chien Peter Lin <[email protected]>Co-developed-by Yong Li <[email protected]>Signed-off-by Yong Li <[email protected]>Reviewed-by Alvin Chang <[email protected]>--- include/sbi/sbi_domain.h | 1 + include/sbi/sbi_domain_mpxy_state.h | 50+++++++++++++++++++++++++++++
Quoted 3 lines
lib/sbi/objects.mk | 1 + lib/sbi/sbi_domain.c | 9 +++++- lib/sbi/sbi_domain_mpxy_state.c | 47
Quoted 8 lines
+++++++++++++++++++++++++++
No need for a separate
sbi_domain_mpxy_state.candsbi_domain_mpxy_state.hThe
sbi_mpxy_init()can dosbi_domain_register_data()instead of doing it very early insbi_domain_init. This means we can squash this change into your PATCH3 and drop PATCH1.
Good idea! It makes sense.
I will test it and send PR v3 soon.
Regards,
Alvin
Quoted 181 lines
Regards,
Anuplib/sbi/sbi_domain.c int sbi_domain_init(struct sbi_scratch *scratch,
Quoted 89 lines
5 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 include/sbi/sbi_domain_mpxy_state.h create mode 100644 lib/sbi/sbi_domain_mpxy_state.cinclude/sbi/sbi_domain.h index renamed from include/sbi/sbi_domain.h +0
-0e9cff0b..9d88234 100644
include/sbi/sbi_domain.h +1
-0@@ -16,6 +16,7 @@#include <sbi/sbi_hartmask.h> #include <sbi/sbi_domain_context.h> #include <sbi/sbi_domain_data.h> +#include <sbi/sbi_domain_mpxy_state.h> struct sbi_scratch ;include/sbi/sbi_domain_mpxy_state.h new file +50
-0@@ -0,0 +1,50 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2024 Intel Corporation. +* Copyright (c) 2024-2025 Andes Technology Corporation. +*/ + +#ifndef __SBI_DOMAIN_MPXY_STATE_H__ +#define __SBI_DOMAIN_MPXY_STATE_H__ + +#include <sbi/sbi_types.h> + +struct sbi_domain ; +struct mpxy_state ; + +/** +* Get per-domain MPXY state pointer for a given domain and HART +index +* @param dom pointer to domain +* @param hartindex the HART index +* +* @return per-domain MPXY state pointer for given HART index */ +struct mpxy_state *sbi_domain_get_mpxy_state (struct sbi_domain *dom, +u32 hartindex); + +/** +* Set per-domain MPXY state pointer for a given domain and HART +index +* @param dom pointer to domain +* @param hartindex the HART index +* @param ms pointer to MPXY state +*/ +void sbi_domain_set_mpxy_state (struct sbi_domain *dom,u32 hartindex, +struct mpxy_state *ms); + +/** Macro to obtain the current hart's MPXY state pointer */ +#define sbi_domain_mpxy_state_thishart_ptr () \ + sbi_domain_get_mpxy_state(sbi_domain_thishart_ptr(), \ + current_hartindex()) + +/** +* Initialize domain MPXY state support +* +* @return 0 on success and negative error code on failure */ int +sbi_domain_mpxy_state_init (void ); + +/* Deinitialize domain MPXY state support */ void +sbi_domain_mpxy_state_deinit (void ); + +#endif lib/sbi/objects.mk index renamed from lib/sbi/objects.mk +0
-09cb2842..a728e9b 100644
lib/sbi/objects.mk +0
-0@@ -69,6 +69,7 @@ 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
lib/sbi/objects.mk +1
-0+libsbi-objs-y += sbi_domain_mpxy_state.o libsbi-objs-y += sbi_domain.o libsbi-objs-y += sbi_double_trap.o libsbi-objs-y += sbi_emulate_csr.olib/sbi/sbi_domain.c index renamed from lib/sbi/sbi_domain.c +0
-051c82a7..bd5d0ef 100644
lib/sbi/sbi_domain.c +0
-0@@ -800,11 +800,16 @@ int sbi_domain_init(struct sbi_scratch *scratch,u32
cold_hartid)lib/sbi/sbi_domain.c int sbi_domain_init(struct sbi_scratch *scratch, u32 cold_hartid)
Quoted 9 lines
lib/sbi/sbi_domain.c +5
-0if (rc) goto fail_free_domain_hart_ptr_offset; +/* Initialize domain MPXY state support */ + rc =sbi_domain_mpxy_state_init (); +if (rc) + goto fail_deinit_context; + root_memregs = sbi_calloc(sizeof(*root_memregs),
ROOT_REGION_MAX+ 1);lib/sbi/sbi_domain.c int sbi_domain_init(struct sbi_scratch *scratch, · line 810
Quoted 2 lines
lib/sbi/sbi_domain.c +0
-0if (!root_memregs) { sbi_printf("%s: no memory for root regions\n",
__func__);Quoted 36 lines
lib/sbi/sbi_domain.c +3
-1rc =SBI_ENOMEM ; - goto fail_deinit_context; + goto fail_deinit_mpxy_state; } root.regions = root_memregs;@@ -869,6 +874,8 @@ fail_free_root_hmask:sbi_free (root_hmask); fail_free_root_memregs:sbi_free (root_memregs); +fail_deinit_mpxy_state: +sbi_domain_mpxy_state_deinit (); fail_deinit_context:sbi_domain_context_deinit (); fail_free_domain_hart_ptr_offset:(quoted diff) +0
-0
b/lib/sbi/sbi_domain_mpxy_state.cnew file mode 100644 index 0000000..45f63a9lib/sbi/sbi_domain_mpxy_state.c new file +15
-0@@ -0,0 +1,47 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2024 Intel Corporation. +* Copyright (c) 2024-2025 Andes Technology Corporation. +*/ + +#include <sbi/sbi_domain.h> + +struct domain_mpxy_state_priv { +/** MPXY state for possible HARTs indexed by hartindex */ +struct mpxy_state +*hartindex_to_mpxy_state_table[SBI_HARTMASK_MAX_BITS ]; +}; +lib/sbi/sbi_domain_mpxy_state.c line 25
Quoted 10 lines
lib/sbi/sbi_domain_mpxy_state.c new file +10
-0+static struct sbi_domain_data dmspriv = { + .data_size =sizeof (struct domain_mpxy_state_priv ), }; + +struct mpxy_state *sbi_domain_get_mpxy_state (struct sbi_domain *dom, +u32 hartindex) { +struct domain_mpxy_state_priv *dmsp = +sbi_domain_data_ptr (dom, &dmspriv); + +return (dmsp && hartindex <SBI_HARTMASK_MAX_BITS ) ? + dmsp->hartindex_to_mpxy_state_table[hartindex] :NULL;
lib/sbi/sbi_domain_mpxy_state.c
Quoted 9 lines
lib/sbi/sbi_domain_mpxy_state.c new file +9
-0+} + +void sbi_domain_set_mpxy_state (struct sbi_domain *dom,u32 hartindex, +struct mpxy_state *ms) { +struct domain_mpxy_state_priv *dmsp = +sbi_domain_data_ptr (dom, &dmspriv); + +if (dmsp && hartindex <SBI_HARTMASK_MAX_BITS ) + dmsp->hartindex_to_mpxy_state_table[hartindex] =ms; }
Quoted 14 lines
lib/sbi/sbi_domain_mpxy_state.c new file +10
-1+ +int sbi_domain_mpxy_state_init (void ) +{ +return sbi_domain_register_data (&dmspriv); +} + +void sbi_domain_mpxy_state_deinit (void ) +{ +sbi_domain_unregister_data (&dmspriv); +} --2.34.1
Quoted 4 lines
Quoted 4 lines
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
CONFIDENTIALITY NOTICE:
This e-mail (and its attachments) may contain confidential and legally privileged information or information protected from disclosure. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein is strictly prohibited. In this case, please immediately notify the sender by return e-mail, delete the message (and any accompanying documents) and destroy all printed hard copies. Thank you for your cooperation.
Copyright ANDES TECHNOLOGY CORPORATION - All Rights Reserved.
PATCH v2 3/4 lib: sbi_mpxy: Convert MPXY state to per-domain data
In reply to Alvin ChangNow MPXY state is per-domain data. Allocate per-domain and per-hart MPXY state in sbi_mpxy_init(). Use sbi_domain_mpxy_state_thishart_ptr() to get pointer to MPXY state of current hart in current domain.
--- lib/sbi/sbi_mpxy.c | 57 ++++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 25 deletions(-)
lib/sbi/sbi_mpxy.c +32 -25
@@ -11,6 +11,7 @@#include <sbi/sbi_domain.h> #include <sbi/sbi_error.h> #include <sbi/sbi_hart.h> +#include <sbi/sbi_heap.h> #include <sbi/sbi_platform.h> #include <sbi/sbi_mpxy.h> #include <sbi/sbi_scratch.h>
@@ -22,9 +23,6 @@/** Shared memory size across all harts */ static unsigned long mpxy_shmem_size =PAGE_SIZE ; -/** Offset of pointer to MPXY state in scratch space */ -static unsigned long mpxy_state_offset; -/** List of MPXY proxy channels */ static SBI_LIST_HEAD (mpxy_channel_list);
@@ -156,7 +154,7 @@ bool sbi_mpxy_channel_available(void)static void mpxy_std_attrs_init (struct sbi_mpxy_channel *channel) { -struct mpxy_state *ms =sbi_scratch_thishart_offset_ptr (mpxy_state_offset); +struct mpxy_state *ms =sbi_domain_mpxy_state_thishart_ptr ();u32 capability =0 ;/* Reset values */
@@ -227,21 +225,30 @@ int sbi_mpxy_register_channel(struct sbi_mpxy_channel *channel)int sbi_mpxy_init (struct sbi_scratch *scratch) { +struct sbi_domain *dom;struct mpxy_state *ms; - - mpxy_state_offset = sbi_scratch_alloc_type_offset(struct mpxy_state); -if (!mpxy_state_offset) -return SBI_ENOMEM ; - -/** -* TODO: Proper support for checking msi support from platform. -* Currently disable msi and sse and use polling -*/ - ms =sbi_scratch_thishart_offset_ptr (mpxy_state_offset); - ms->msi_avail = false; - ms->sse_avail = false; - -sbi_mpxy_shmem_disable (ms); +u32 i; + +/* Loop through each domain to configure its MPXY state */ +sbi_domain_for_each (dom) { +sbi_hartmask_for_each_hartindex (i, dom->possible_harts) { + ms =sbi_zalloc (sizeof (*ms)); +if (!ms) +return SBI_ENOMEM ; + +/* +* TODO: Proper support for checking msi support from +* platform. Currently disable msi and sse and use +* polling +*/ + ms->msi_avail = false; + ms->sse_avail = false; + +sbi_mpxy_shmem_disable (ms); + +sbi_domain_set_mpxy_state (dom, i, ms); + } + }return sbi_platform_mpxy_init (sbi_platform_ptr (scratch)); }
@@ -255,7 +262,7 @@ int sbi_mpxy_set_shmem(unsigned long shmem_phys_lo, unsigned long shmem_phys_hi, unsigned long flags) { -struct mpxy_state *ms =sbi_scratch_thishart_offset_ptr (mpxy_state_offset); +struct mpxy_state *ms =sbi_domain_mpxy_state_thishart_ptr ();unsigned long *ret_buf;/** Disable shared memory if both hi and lo have all bit 1s */
@@ -297,7 +304,7 @@ int sbi_mpxy_set_shmem(unsigned long shmem_phys_lo,int sbi_mpxy_get_channel_ids (u32 start_index) { -struct mpxy_state *ms =sbi_scratch_thishart_offset_ptr (mpxy_state_offset); +struct mpxy_state *ms =sbi_domain_mpxy_state_thishart_ptr ();u32 remaining, returned, max_channelids;u32 node_index =0 , node_ret =0 ;struct sbi_mpxy_channel *channel;
@@ -348,7 +355,7 @@ int sbi_mpxy_get_channel_ids(u32 start_index)int sbi_mpxy_read_attrs (u32 channel_id,u32 base_attr_id,u32 attr_count) { -struct mpxy_state *ms =sbi_scratch_thishart_offset_ptr (mpxy_state_offset); +struct mpxy_state *ms =sbi_domain_mpxy_state_thishart_ptr ();int ret =SBI_SUCCESS ;u32 *attr_ptr, end_id;void *shmem_base;
@@ -464,7 +471,7 @@ static int mpxy_check_write_std_attr(struct sbi_mpxy_channel *channel,static void mpxy_write_std_attr (struct sbi_mpxy_channel *channel,u32 attr_id,u32 attr_val) { -struct mpxy_state *ms =sbi_scratch_thishart_offset_ptr (mpxy_state_offset); +struct mpxy_state *ms =sbi_domain_mpxy_state_thishart_ptr ();struct sbi_mpxy_channel_attrs *attrs = &channel->attrs;switch (attr_id) {
@@ -498,7 +505,7 @@ static void mpxy_write_std_attr(struct sbi_mpxy_channel *channel, u32 attr_id,int sbi_mpxy_write_attrs (u32 channel_id,u32 base_attr_id,u32 attr_count) { -struct mpxy_state *ms =sbi_scratch_thishart_offset_ptr (mpxy_state_offset); +struct mpxy_state *ms =sbi_domain_mpxy_state_thishart_ptr ();u32 *mem_ptr, attr_id, end_id, attr_val;struct sbi_mpxy_channel *channel;int ret, mem_idx;
@@ -588,7 +595,7 @@ int sbi_mpxy_send_message(u32 channel_id, u8 msg_id,unsigned long msg_data_len, unsigned long *resp_data_len) { - struct mpxy_state *ms = sbi_scratch_thishart_offset_ptr(mpxy_state_offset); + struct mpxy_state *ms = sbi_domain_mpxy_state_thishart_ptr();struct sbi_mpxy_channel *channel;void *shmem_base, *resp_buf;u32 resp_bufsize;
@@ -646,7 +653,7 @@ int sbi_mpxy_send_message(u32 channel_id, u8 msg_id,int sbi_mpxy_get_notification_events (u32 channel_id,unsigned long *events_len) { -struct mpxy_state *ms =sbi_scratch_thishart_offset_ptr (mpxy_state_offset); +struct mpxy_state *ms =sbi_domain_mpxy_state_thishart_ptr ();struct sbi_mpxy_channel *channel;void *eventsbuf, *shmem_base;int ret;
Signature · 1 line
2.34.1
PATCH v2 4/4 lib: sbi: sbi_init: Allocate MPXY state for each domain
In reply to Alvin ChangEach domain need its own shared memory region. Adjust the sbi_mpxy_init() after sbi_domain_finalize() so OpenSBI can populate domains from device-tree and allocate their own MPXY state.
--- lib/sbi/sbi_init.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
lib/sbi/sbi_init.c +10 -6
@@ -313,12 +313,6 @@ static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid)sbi_hart_hang (); } - rc =sbi_mpxy_init (scratch); -if (rc) { -sbi_printf ("%s: mpxy init failed (error %d)\n" , __func__, rc); -sbi_hart_hang (); - } -/* * Note: Finalize domains after HSM initialization * Note: Finalize domains before HART PMP configuration so
@@ -331,6 +325,16 @@ static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid)sbi_hart_hang (); } +/* +* Note: Each domain needs its own MPXY shared memory region. +* Note: Initialize the MPXY after sbi_domain_finalize(). +*/ + rc =sbi_mpxy_init (scratch); +if (rc) { +sbi_printf ("%s: mpxy init failed (error %d)\n" , __func__, rc); +sbi_hart_hang (); + } +/* * Note: Platform final initialization should be after finalizing * domains so that it sees correct domain assignment and PMP
Signature · 1 line
2.34.1
PATCH v2 4/4 lib: sbi: sbi_init: Allocate MPXY state for each domain
Quoted 5 lines · On Tue, Feb 25, 2025 at 6:47?AM Alvin Chang <[email protected]> wrote:
Each domain need its own shared memory region. Adjust the
sbi_mpxy_init()aftersbi_domain_finalize()so OpenSBI can populate domains from device-tree and allocate their own MPXY state.
Even if MXPY shared memory is per-domain, it is the supervisor software running inside the domain that will set up the MPXY shared memory and there is no role of OpenSBI here.
This patch is not needed.
Regards,
Anup
Quoted 52 lines
Signed-off-by Yong Li <[email protected]>Tested-by Yu-Chien Peter Lin <[email protected]>Reviewed-by Yu-Chien Peter Lin <[email protected]>Tested-by Alvin Chang <[email protected]>Reviewed-by Alvin Chang <[email protected]>--- lib/sbi/sbi_init.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)lib/sbi/sbi_init.c +10
-7@@ -313,12 +313,6 @@ static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid)sbi_hart_hang (); } - rc =sbi_mpxy_init (scratch); -if (rc) { -sbi_printf ("%s: mpxy init failed (error %d)\n" , __func__, rc); -sbi_hart_hang (); - } -/* * Note: Finalize domains after HSM initialization * Note: Finalize domains before HART PMP configuration so @@ -331,6 +325,16 @@ static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid)sbi_hart_hang (); } +/* +* Note: Each domain needs its own MPXY shared memory region. +* Note: Initialize the MPXY after sbi_domain_finalize(). +*/ + rc =sbi_mpxy_init (scratch); +if (rc) { +sbi_printf ("%s: mpxy init failed (error %d)\n" , __func__, rc); +sbi_hart_hang (); + } +/* * Note: Platform final initialization should be after finalizing * domains so that it sees correct domain assignment and PMP -- 2.34.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi