2018-12-11 21:54:06 +08:00
|
|
|
/*
|
2019-01-24 14:11:10 +08:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*
|
|
|
|
* Copyright (c) 2019 Western Digital Corporation or its affiliates.
|
2018-12-11 21:54:06 +08:00
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Anup Patel <anup.patel@wdc.com>
|
2019-02-18 05:43:41 +08:00
|
|
|
* Nick Kossifidis <mick@ics.forth.gr>
|
2018-12-11 21:54:06 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sbi/riscv_asm.h>
|
|
|
|
#include <sbi/riscv_barrier.h>
|
2019-01-21 15:24:26 +08:00
|
|
|
#include <sbi/riscv_atomic.h>
|
2019-03-30 20:13:23 +08:00
|
|
|
#include <sbi/riscv_unpriv.h>
|
2018-12-11 21:54:06 +08:00
|
|
|
#include <sbi/sbi_hart.h>
|
2019-01-21 15:24:26 +08:00
|
|
|
#include <sbi/sbi_bitops.h>
|
|
|
|
#include <sbi/sbi_console.h>
|
2018-12-11 21:54:06 +08:00
|
|
|
#include <sbi/sbi_ipi.h>
|
|
|
|
#include <sbi/sbi_platform.h>
|
|
|
|
#include <sbi/sbi_timer.h>
|
|
|
|
|
2019-03-10 04:57:20 +08:00
|
|
|
static int sbi_ipi_send(struct sbi_scratch *scratch, u32 hartid,
|
|
|
|
u32 event, void *data)
|
2019-02-17 15:00:20 +08:00
|
|
|
{
|
|
|
|
struct sbi_scratch *remote_scratch = NULL;
|
2019-03-06 15:29:34 +08:00
|
|
|
const struct sbi_platform *plat = sbi_platform_ptr(scratch);
|
2019-03-10 04:57:20 +08:00
|
|
|
struct sbi_tlb_info *tlb_info = data;
|
|
|
|
struct sbi_tlb_info *ipi_tlb_data;
|
2019-02-17 15:00:20 +08:00
|
|
|
|
|
|
|
if (sbi_platform_hart_disabled(plat, hartid))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Set IPI type on remote hart's scratch area and
|
|
|
|
* trigger the interrupt
|
|
|
|
*/
|
|
|
|
remote_scratch = sbi_hart_id_to_scratch(scratch, hartid);
|
2019-03-10 04:57:20 +08:00
|
|
|
if (event == SBI_IPI_EVENT_SFENCE_VMA ||
|
|
|
|
event == SBI_IPI_EVENT_SFENCE_VMA_ASID) {
|
|
|
|
ipi_tlb_data = sbi_tlb_info_ptr(remote_scratch);
|
|
|
|
ipi_tlb_data->start = tlb_info->start;
|
|
|
|
ipi_tlb_data->size = tlb_info->size;
|
|
|
|
ipi_tlb_data->asid = tlb_info->asid;
|
|
|
|
}
|
2019-03-09 03:22:22 +08:00
|
|
|
atomic_raw_set_bit(event, &sbi_ipi_data_ptr(remote_scratch)->ipi_type);
|
2019-02-17 15:00:20 +08:00
|
|
|
mb();
|
|
|
|
sbi_platform_ipi_send(plat, hartid);
|
|
|
|
if (event != SBI_IPI_EVENT_SOFT)
|
|
|
|
sbi_platform_ipi_sync(plat, hartid);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-12-11 21:54:06 +08:00
|
|
|
int sbi_ipi_send_many(struct sbi_scratch *scratch,
|
2019-03-10 04:57:20 +08:00
|
|
|
ulong *pmask, u32 event, void *data)
|
2018-12-11 21:54:06 +08:00
|
|
|
{
|
|
|
|
ulong i, m;
|
|
|
|
ulong mask = sbi_hart_available_mask();
|
2019-02-17 15:00:20 +08:00
|
|
|
u32 hartid = sbi_current_hartid();
|
2018-12-11 21:54:06 +08:00
|
|
|
|
|
|
|
if (pmask)
|
2019-03-30 20:05:48 +08:00
|
|
|
mask &= load_ulong(pmask);
|
2018-12-11 21:54:06 +08:00
|
|
|
|
2019-02-17 15:00:20 +08:00
|
|
|
/* send IPIs to every other hart on the set */
|
2019-02-18 21:09:02 +08:00
|
|
|
for (i = 0, m = mask; m; i++, m >>= 1)
|
2019-02-17 15:00:20 +08:00
|
|
|
if ((m & 1UL) && (i != hartid))
|
2019-03-10 04:57:20 +08:00
|
|
|
sbi_ipi_send(scratch, i, event, data);
|
2019-02-17 15:00:20 +08:00
|
|
|
|
|
|
|
/* If the current hart is on the set, send an IPI
|
|
|
|
* to it as well
|
|
|
|
*/
|
|
|
|
if (mask & (1UL << hartid))
|
2019-03-10 04:57:20 +08:00
|
|
|
sbi_ipi_send(scratch, hartid, event, data);
|
2019-02-17 15:00:20 +08:00
|
|
|
|
2018-12-11 21:54:06 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-01-22 16:50:59 +08:00
|
|
|
void sbi_ipi_clear_smode(struct sbi_scratch *scratch)
|
2018-12-11 21:54:06 +08:00
|
|
|
{
|
2019-02-13 10:32:06 +08:00
|
|
|
csr_clear(CSR_MIP, MIP_SSIP);
|
2018-12-11 21:54:06 +08:00
|
|
|
}
|
|
|
|
|
2019-03-13 04:50:37 +08:00
|
|
|
static void sbi_ipi_tlb_flush_all()
|
2019-03-10 04:57:20 +08:00
|
|
|
{
|
2019-03-13 04:50:37 +08:00
|
|
|
__asm__ __volatile("sfence.vma");
|
2019-03-10 04:57:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sbi_ipi_sfence_vma(struct sbi_tlb_info *tinfo)
|
|
|
|
{
|
|
|
|
unsigned long start = tinfo->start;
|
|
|
|
unsigned long size = tinfo->size;
|
|
|
|
unsigned long i;
|
|
|
|
|
2019-03-13 04:50:37 +08:00
|
|
|
if ((start == 0 && size == 0) || (size == SBI_TLB_FLUSH_ALL)) {
|
|
|
|
sbi_ipi_tlb_flush_all();
|
|
|
|
return;
|
|
|
|
}
|
2019-03-10 04:57:20 +08:00
|
|
|
|
|
|
|
for (i = 0; i < size; i += PAGE_SIZE) {
|
|
|
|
__asm__ __volatile__ ("sfence.vma %0"
|
|
|
|
: : "r" (start + i)
|
|
|
|
: "memory");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sbi_ipi_sfence_vma_asid(struct sbi_tlb_info *tinfo)
|
|
|
|
{
|
|
|
|
unsigned long start = tinfo->start;
|
|
|
|
unsigned long size = tinfo->size;
|
|
|
|
unsigned long asid = tinfo->asid;
|
|
|
|
unsigned long i;
|
|
|
|
|
2019-03-13 04:50:37 +08:00
|
|
|
if (start == 0 && size == 0) {
|
|
|
|
sbi_ipi_tlb_flush_all();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Flush entire MM context for a given ASID */
|
2019-03-10 04:57:20 +08:00
|
|
|
if (size == SBI_TLB_FLUSH_ALL) {
|
2019-03-13 04:50:37 +08:00
|
|
|
__asm__ __volatile__ ("sfence.vma x0, %0"
|
|
|
|
: : "r" (asid)
|
|
|
|
: "memory");
|
2019-03-10 04:57:20 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < size; i += PAGE_SIZE) {
|
|
|
|
__asm__ __volatile__ ("sfence.vma %0, %1"
|
|
|
|
: : "r" (start + i), "r" (asid)
|
|
|
|
: "memory");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-22 16:50:59 +08:00
|
|
|
void sbi_ipi_process(struct sbi_scratch *scratch)
|
2018-12-11 21:54:06 +08:00
|
|
|
{
|
2019-03-06 15:29:34 +08:00
|
|
|
const struct sbi_platform *plat = sbi_platform_ptr(scratch);
|
2019-01-21 15:24:26 +08:00
|
|
|
volatile unsigned long ipi_type;
|
|
|
|
unsigned int ipi_event;
|
2019-01-22 16:50:59 +08:00
|
|
|
u32 hartid = sbi_current_hartid();
|
2018-12-11 21:54:06 +08:00
|
|
|
|
|
|
|
sbi_platform_ipi_clear(plat, hartid);
|
2019-01-21 15:24:26 +08:00
|
|
|
|
|
|
|
do {
|
2019-03-09 03:22:22 +08:00
|
|
|
ipi_type = sbi_ipi_data_ptr(scratch)->ipi_type;
|
2019-01-21 15:24:26 +08:00
|
|
|
rmb();
|
|
|
|
ipi_event = __ffs(ipi_type);
|
|
|
|
switch (ipi_event) {
|
|
|
|
case SBI_IPI_EVENT_SOFT:
|
2019-02-13 10:32:06 +08:00
|
|
|
csr_set(CSR_MIP, MIP_SSIP);
|
2019-01-21 15:24:26 +08:00
|
|
|
break;
|
|
|
|
case SBI_IPI_EVENT_FENCE_I:
|
|
|
|
__asm__ __volatile("fence.i");
|
|
|
|
break;
|
|
|
|
case SBI_IPI_EVENT_SFENCE_VMA:
|
2019-03-10 04:57:20 +08:00
|
|
|
sbi_ipi_sfence_vma(sbi_tlb_info_ptr(scratch));
|
|
|
|
break;
|
|
|
|
case SBI_IPI_EVENT_SFENCE_VMA_ASID:
|
|
|
|
sbi_ipi_sfence_vma_asid(sbi_tlb_info_ptr(scratch));
|
2019-01-21 15:24:26 +08:00
|
|
|
break;
|
|
|
|
case SBI_IPI_EVENT_HALT:
|
|
|
|
sbi_hart_hang();
|
|
|
|
break;
|
|
|
|
};
|
2019-03-09 03:22:22 +08:00
|
|
|
ipi_type = atomic_raw_clear_bit(ipi_event, &sbi_ipi_data_ptr(scratch)->ipi_type);
|
2019-01-21 15:24:26 +08:00
|
|
|
} while(ipi_type > 0);
|
2018-12-11 21:54:06 +08:00
|
|
|
}
|
|
|
|
|
2019-01-22 16:50:59 +08:00
|
|
|
int sbi_ipi_init(struct sbi_scratch *scratch, bool cold_boot)
|
2018-12-11 21:54:06 +08:00
|
|
|
{
|
2019-03-09 03:22:22 +08:00
|
|
|
sbi_ipi_data_ptr(scratch)->ipi_type = 0x00;
|
2019-03-10 04:57:20 +08:00
|
|
|
sbi_tlb_info_ptr(scratch)->start = 0x00;
|
|
|
|
sbi_tlb_info_ptr(scratch)->size = 0x00;
|
|
|
|
sbi_tlb_info_ptr(scratch)->asid = 0x00;
|
2019-03-09 03:22:22 +08:00
|
|
|
|
2018-12-11 21:54:06 +08:00
|
|
|
/* Enable software interrupts */
|
2019-02-13 10:32:06 +08:00
|
|
|
csr_set(CSR_MIE, MIP_MSIP);
|
2018-12-11 21:54:06 +08:00
|
|
|
|
2018-12-26 21:06:11 +08:00
|
|
|
return sbi_platform_ipi_init(sbi_platform_ptr(scratch),
|
2019-01-22 16:50:59 +08:00
|
|
|
cold_boot);
|
2018-12-11 21:54:06 +08:00
|
|
|
}
|