mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2025-08-25 07:41:42 +01:00
lib: Handle failure of sbi_hartid_to_scratch() API
The sbi_hartid_to_scratch() API can fail for non-existent HARTs so all uses of sbi_hartid_to_scratch() API should check return value. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
#define SBI_HART_STOPPING 1
|
#define SBI_HART_STOPPING 1
|
||||||
#define SBI_HART_STARTING 2
|
#define SBI_HART_STARTING 2
|
||||||
#define SBI_HART_STARTED 3
|
#define SBI_HART_STARTED 3
|
||||||
|
#define SBI_HART_UNKNOWN 4
|
||||||
|
|
||||||
int sbi_hsm_init(struct sbi_scratch *scratch, u32 hartid, bool cold_boot);
|
int sbi_hsm_init(struct sbi_scratch *scratch, u32 hartid, bool cold_boot);
|
||||||
void __noreturn sbi_hsm_exit(struct sbi_scratch *scratch);
|
void __noreturn sbi_hsm_exit(struct sbi_scratch *scratch);
|
||||||
|
@@ -61,6 +61,9 @@ int sbi_hsm_hart_get_state(u32 hartid)
|
|||||||
struct sbi_scratch *scratch;
|
struct sbi_scratch *scratch;
|
||||||
|
|
||||||
scratch = sbi_hartid_to_scratch(hartid);
|
scratch = sbi_hartid_to_scratch(hartid);
|
||||||
|
if (!scratch)
|
||||||
|
return SBI_HART_UNKNOWN;
|
||||||
|
|
||||||
hdata = sbi_scratch_offset_ptr(scratch, hart_data_offset);
|
hdata = sbi_scratch_offset_ptr(scratch, hart_data_offset);
|
||||||
|
|
||||||
return atomic_read(&hdata->state);
|
return atomic_read(&hdata->state);
|
||||||
@@ -165,6 +168,9 @@ int sbi_hsm_init(struct sbi_scratch *scratch, u32 hartid, bool cold_boot)
|
|||||||
/* Initialize hart state data for every hart */
|
/* Initialize hart state data for every hart */
|
||||||
for (i = 0; i < hart_count; i++) {
|
for (i = 0; i < hart_count; i++) {
|
||||||
rscratch = sbi_hartid_to_scratch(i);
|
rscratch = sbi_hartid_to_scratch(i);
|
||||||
|
if (!rscratch)
|
||||||
|
continue;
|
||||||
|
|
||||||
hdata = sbi_scratch_offset_ptr(rscratch,
|
hdata = sbi_scratch_offset_ptr(rscratch,
|
||||||
hart_data_offset);
|
hart_data_offset);
|
||||||
ATOMIC_INIT(&hdata->state,
|
ATOMIC_INIT(&hdata->state,
|
||||||
@@ -212,14 +218,17 @@ fail_exit:
|
|||||||
int sbi_hsm_hart_start(struct sbi_scratch *scratch, u32 hartid,
|
int sbi_hsm_hart_start(struct sbi_scratch *scratch, u32 hartid,
|
||||||
ulong saddr, ulong priv)
|
ulong saddr, ulong priv)
|
||||||
{
|
{
|
||||||
|
int rc;
|
||||||
unsigned long init_count;
|
unsigned long init_count;
|
||||||
unsigned int hstate;
|
unsigned int hstate;
|
||||||
int rc;
|
struct sbi_scratch *rscratch;
|
||||||
|
struct sbi_hsm_data *hdata;
|
||||||
const struct sbi_platform *plat = sbi_platform_ptr(scratch);
|
const struct sbi_platform *plat = sbi_platform_ptr(scratch);
|
||||||
struct sbi_scratch *rscratch = sbi_hartid_to_scratch(hartid);
|
|
||||||
struct sbi_hsm_data *hdata = sbi_scratch_offset_ptr(rscratch,
|
|
||||||
hart_data_offset);
|
|
||||||
|
|
||||||
|
rscratch = sbi_hartid_to_scratch(hartid);
|
||||||
|
if (!rscratch)
|
||||||
|
return SBI_EINVAL;
|
||||||
|
hdata = sbi_scratch_offset_ptr(rscratch, hart_data_offset);
|
||||||
if (sbi_platform_hart_disabled(plat, hartid))
|
if (sbi_platform_hart_disabled(plat, hartid))
|
||||||
return SBI_EINVAL;
|
return SBI_EINVAL;
|
||||||
hstate = arch_atomic_cmpxchg(&hdata->state, SBI_HART_STOPPED,
|
hstate = arch_atomic_cmpxchg(&hdata->state, SBI_HART_STOPPED,
|
||||||
|
@@ -305,6 +305,9 @@ unsigned long sbi_init_count(u32 hartid)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
scratch = sbi_hartid_to_scratch(hartid);
|
scratch = sbi_hartid_to_scratch(hartid);
|
||||||
|
if (!scratch)
|
||||||
|
return 0;
|
||||||
|
|
||||||
init_count = sbi_scratch_offset_ptr(scratch, init_count_offset);
|
init_count = sbi_scratch_offset_ptr(scratch, init_count_offset);
|
||||||
|
|
||||||
return *init_count;
|
return *init_count;
|
||||||
|
@@ -41,11 +41,10 @@ static int sbi_ipi_send(struct sbi_scratch *scratch, u32 remote_hartid,
|
|||||||
return SBI_EINVAL;
|
return SBI_EINVAL;
|
||||||
ipi_ops = ipi_ops_array[event];
|
ipi_ops = ipi_ops_array[event];
|
||||||
|
|
||||||
/*
|
|
||||||
* Set IPI type on remote hart's scratch area and
|
|
||||||
* trigger the interrupt
|
|
||||||
*/
|
|
||||||
remote_scratch = sbi_hartid_to_scratch(remote_hartid);
|
remote_scratch = sbi_hartid_to_scratch(remote_hartid);
|
||||||
|
if (!remote_scratch)
|
||||||
|
return SBI_EINVAL;
|
||||||
|
|
||||||
ipi_data = sbi_scratch_offset_ptr(remote_scratch, ipi_data_off);
|
ipi_data = sbi_scratch_offset_ptr(remote_scratch, ipi_data_off);
|
||||||
|
|
||||||
if (ipi_ops->update) {
|
if (ipi_ops->update) {
|
||||||
@@ -55,6 +54,10 @@ static int sbi_ipi_send(struct sbi_scratch *scratch, u32 remote_hartid,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set IPI type on remote hart's scratch area and
|
||||||
|
* trigger the interrupt
|
||||||
|
*/
|
||||||
atomic_raw_set_bit(event, &ipi_data->ipi_type);
|
atomic_raw_set_bit(event, &ipi_data->ipi_type);
|
||||||
smp_wmb();
|
smp_wmb();
|
||||||
sbi_platform_ipi_send(plat, remote_hartid);
|
sbi_platform_ipi_send(plat, remote_hartid);
|
||||||
|
@@ -72,6 +72,8 @@ done:
|
|||||||
plat = sbi_platform_ptr(scratch);
|
plat = sbi_platform_ptr(scratch);
|
||||||
for (i = 0; i < sbi_platform_hart_count(plat); i++) {
|
for (i = 0; i < sbi_platform_hart_count(plat); i++) {
|
||||||
rscratch = sbi_hartid_to_scratch(i);
|
rscratch = sbi_hartid_to_scratch(i);
|
||||||
|
if (!rscratch)
|
||||||
|
continue;
|
||||||
ptr = sbi_scratch_offset_ptr(rscratch, ret);
|
ptr = sbi_scratch_offset_ptr(rscratch, ret);
|
||||||
sbi_memset(ptr, 0, size);
|
sbi_memset(ptr, 0, size);
|
||||||
}
|
}
|
||||||
|
@@ -197,6 +197,9 @@ static void sbi_tlb_entry_process(struct sbi_tlb_info *tinfo)
|
|||||||
|
|
||||||
sbi_hartmask_for_each_hart(rhartid, &tinfo->smask) {
|
sbi_hartmask_for_each_hart(rhartid, &tinfo->smask) {
|
||||||
rscratch = sbi_hartid_to_scratch(rhartid);
|
rscratch = sbi_hartid_to_scratch(rhartid);
|
||||||
|
if (!rscratch)
|
||||||
|
continue;
|
||||||
|
|
||||||
rtlb_sync = sbi_scratch_offset_ptr(rscratch, tlb_sync_off);
|
rtlb_sync = sbi_scratch_offset_ptr(rscratch, tlb_sync_off);
|
||||||
while (atomic_raw_xchg_ulong(rtlb_sync, 1)) ;
|
while (atomic_raw_xchg_ulong(rtlb_sync, 1)) ;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user