[PATCH 1/3] lib: sbi: Introduce IPI device rating
Anup Patel
apatel at ventanamicro.com
Tue Sep 2 23:49:53 PDT 2025
On Wed, Sep 3, 2025 at 5:11 AM Samuel Holland <samuel.holland at sifive.com> wrote:
>
> Hi Anup,
>
> On 2025-09-02 7:17 AM, Anup Patel wrote:
> > A platform can have multiple IPI devices (such as ACLINT MSWI,
> > AIA IMSIC, etc). Currently, OpenSBI rely on platform calling
> > the sbi_ipi_set_device() function in correct order and prefer
> > the first avaiable IPI device which is fragile.
> >
> > Instead of the above, introdcue IPI device rating and prefer
> > the highest rated IPI device. This further allows extending
> > the sbi_ipi_raw_clear() to clear all available IPI devices.
> >
> > Signed-off-by: Anup Patel <apatel at ventanamicro.com>
> > ---
> > include/sbi/sbi_ipi.h | 6 +++++-
> > lib/sbi/sbi_init.c | 2 +-
> > lib/sbi/sbi_ipi.c | 28 ++++++++++++++++++++--------
> > lib/utils/ipi/aclint_mswi.c | 1 +
> > lib/utils/ipi/andes_plicsw.c | 1 +
> > lib/utils/irqchip/imsic.c | 1 +
> > 6 files changed, 29 insertions(+), 10 deletions(-)
> >
> > diff --git a/include/sbi/sbi_ipi.h b/include/sbi/sbi_ipi.h
> > index 62d61304..0a9ae03d 100644
> > --- a/include/sbi/sbi_ipi.h
> > +++ b/include/sbi/sbi_ipi.h
> > @@ -14,6 +14,7 @@
> >
> > /* clang-format off */
> >
> > +#define SBI_IPI_DEVICE_MAX (4)
> > #define SBI_IPI_EVENT_MAX (8 * __SIZEOF_LONG__)
> >
> > /* clang-format on */
> > @@ -23,6 +24,9 @@ struct sbi_ipi_device {
> > /** Name of the IPI device */
> > char name[32];
> >
> > + /** Ratings of the IPI device (higher is better) */
> > + unsigned long rating;
> > +
> > /** Send IPI to a target HART index */
> > void (*ipi_send)(u32 hart_index);
> >
> > @@ -87,7 +91,7 @@ void sbi_ipi_process(void);
> >
> > int sbi_ipi_raw_send(u32 hartindex);
> >
> > -void sbi_ipi_raw_clear(void);
> > +void sbi_ipi_raw_clear(bool all_devices);
> >
> > const struct sbi_ipi_device *sbi_ipi_get_device(void);
> >
> > diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c
> > index 84a63748..663b486b 100644
> > --- a/lib/sbi/sbi_init.c
> > +++ b/lib/sbi/sbi_init.c
> > @@ -507,7 +507,7 @@ static void __noreturn init_warmboot(struct sbi_scratch *scratch, u32 hartid)
> > if (hstate == SBI_HSM_STATE_SUSPENDED) {
> > init_warm_resume(scratch, hartid);
> > } else {
> > - sbi_ipi_raw_clear();
> > + sbi_ipi_raw_clear(true);
> > init_warm_startup(scratch, hartid);
> > }
> > }
> > diff --git a/lib/sbi/sbi_ipi.c b/lib/sbi/sbi_ipi.c
> > index 2de459b0..b57ec652 100644
> > --- a/lib/sbi/sbi_ipi.c
> > +++ b/lib/sbi/sbi_ipi.c
> > @@ -32,8 +32,9 @@ _Static_assert(
> > "type of sbi_ipi_data.ipi_type has changed, please redefine SBI_IPI_EVENT_MAX"
> > );
> >
> > -static unsigned long ipi_data_off;
> > +static unsigned long ipi_data_off, ipi_dev_count;
> > static const struct sbi_ipi_device *ipi_dev = NULL;
> > +static const struct sbi_ipi_device *ipi_dev_array[SBI_IPI_DEVICE_MAX];
>
> Since the only things we do with the array are append to it and iterate over it,
> can we use a linked list here so there is no arbitrary limit?
Sure, I will use linked list in v2.
Regards,
Anup
More information about the opensbi
mailing list