forked from Mirrors/opensbi
lib: utils/irqchip: Move per-hart data from fdt_plic to plic
The per-hart PLIC pointer is not really specific to FDT platforms. Move it into the main driver and drop the extra wrapper functions. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
This commit is contained in:

committed by
Anup Patel

parent
c6c22f00f4
commit
56fddce83f
@@ -1,19 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
|
||||||
*
|
|
||||||
* Copyright (c) 2022 Samuel Holland <samuel@sholland.org>
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __IRQCHIP_FDT_IRQCHIP_PLIC_H__
|
|
||||||
#define __IRQCHIP_FDT_IRQCHIP_PLIC_H__
|
|
||||||
|
|
||||||
#include <sbi/sbi_types.h>
|
|
||||||
#include <sbi_utils/irqchip/plic.h>
|
|
||||||
|
|
||||||
struct plic_data *fdt_plic_get(void);
|
|
||||||
|
|
||||||
void fdt_plic_suspend(void);
|
|
||||||
|
|
||||||
void fdt_plic_resume(void);
|
|
||||||
|
|
||||||
#endif
|
|
@@ -36,11 +36,13 @@ struct plic_data {
|
|||||||
|
|
||||||
#define PLIC_IE_WORDS(__p) ((__p)->num_src / 32 + 1)
|
#define PLIC_IE_WORDS(__p) ((__p)->num_src / 32 + 1)
|
||||||
|
|
||||||
void plic_suspend(const struct plic_data *plic);
|
struct plic_data *plic_get(void);
|
||||||
|
|
||||||
void plic_resume(const struct plic_data *plic);
|
void plic_suspend(void);
|
||||||
|
|
||||||
int plic_warm_irqchip_init(const struct plic_data *plic);
|
void plic_resume(void);
|
||||||
|
|
||||||
|
int plic_warm_irqchip_init(void);
|
||||||
|
|
||||||
int plic_cold_irqchip_init(struct plic_data *plic);
|
int plic_cold_irqchip_init(struct plic_data *plic);
|
||||||
|
|
||||||
|
@@ -18,48 +18,11 @@
|
|||||||
#include <sbi_utils/irqchip/fdt_irqchip.h>
|
#include <sbi_utils/irqchip/fdt_irqchip.h>
|
||||||
#include <sbi_utils/irqchip/plic.h>
|
#include <sbi_utils/irqchip/plic.h>
|
||||||
|
|
||||||
static unsigned long plic_ptr_offset;
|
|
||||||
|
|
||||||
#define plic_get_hart_data_ptr(__scratch) \
|
|
||||||
sbi_scratch_read_type((__scratch), void *, plic_ptr_offset)
|
|
||||||
|
|
||||||
#define plic_set_hart_data_ptr(__scratch, __plic) \
|
|
||||||
sbi_scratch_write_type((__scratch), void *, plic_ptr_offset, (__plic))
|
|
||||||
|
|
||||||
struct plic_data *fdt_plic_get(void)
|
|
||||||
{
|
|
||||||
struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
|
|
||||||
|
|
||||||
return plic_get_hart_data_ptr(scratch);
|
|
||||||
}
|
|
||||||
|
|
||||||
void fdt_plic_suspend(void)
|
|
||||||
{
|
|
||||||
struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
|
|
||||||
|
|
||||||
plic_suspend(plic_get_hart_data_ptr(scratch));
|
|
||||||
}
|
|
||||||
|
|
||||||
void fdt_plic_resume(void)
|
|
||||||
{
|
|
||||||
struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
|
|
||||||
|
|
||||||
plic_resume(plic_get_hart_data_ptr(scratch));
|
|
||||||
}
|
|
||||||
|
|
||||||
static int irqchip_plic_warm_init(void)
|
|
||||||
{
|
|
||||||
struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
|
|
||||||
|
|
||||||
return plic_warm_irqchip_init(plic_get_hart_data_ptr(scratch));
|
|
||||||
}
|
|
||||||
|
|
||||||
static int irqchip_plic_update_context_map(const void *fdt, int nodeoff,
|
static int irqchip_plic_update_context_map(const void *fdt, int nodeoff,
|
||||||
struct plic_data *pd)
|
struct plic_data *pd)
|
||||||
{
|
{
|
||||||
const fdt32_t *val;
|
const fdt32_t *val;
|
||||||
u32 phandle, hwirq, hartid, hartindex;
|
u32 phandle, hwirq, hartid, hartindex;
|
||||||
struct sbi_scratch *scratch;
|
|
||||||
int i, err, count, cpu_offset, cpu_intc_offset;
|
int i, err, count, cpu_offset, cpu_intc_offset;
|
||||||
|
|
||||||
val = fdt_getprop(fdt, nodeoff, "interrupts-extended", &count);
|
val = fdt_getprop(fdt, nodeoff, "interrupts-extended", &count);
|
||||||
@@ -84,11 +47,9 @@ static int irqchip_plic_update_context_map(const void *fdt, int nodeoff,
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
hartindex = sbi_hartid_to_hartindex(hartid);
|
hartindex = sbi_hartid_to_hartindex(hartid);
|
||||||
scratch = sbi_hartindex_to_scratch(hartindex);
|
if (hartindex == -1U)
|
||||||
if (!scratch)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
plic_set_hart_data_ptr(scratch, pd);
|
|
||||||
switch (hwirq) {
|
switch (hwirq) {
|
||||||
case IRQ_M_EXT:
|
case IRQ_M_EXT:
|
||||||
pd->context_map[hartindex][PLIC_M_CONTEXT] = i / 2;
|
pd->context_map[hartindex][PLIC_M_CONTEXT] = i / 2;
|
||||||
@@ -110,12 +71,6 @@ static int irqchip_plic_cold_init(const void *fdt, int nodeoff,
|
|||||||
int rc;
|
int rc;
|
||||||
struct plic_data *pd;
|
struct plic_data *pd;
|
||||||
|
|
||||||
if (!plic_ptr_offset) {
|
|
||||||
plic_ptr_offset = sbi_scratch_alloc_type_offset(void *);
|
|
||||||
if (!plic_ptr_offset)
|
|
||||||
return SBI_ENOMEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
pd = sbi_zalloc(PLIC_DATA_SIZE(plat->hart_count));
|
pd = sbi_zalloc(PLIC_DATA_SIZE(plat->hart_count));
|
||||||
if (!pd)
|
if (!pd)
|
||||||
return SBI_ENOMEM;
|
return SBI_ENOMEM;
|
||||||
@@ -153,6 +108,6 @@ static const struct fdt_match irqchip_plic_match[] = {
|
|||||||
struct fdt_irqchip fdt_irqchip_plic = {
|
struct fdt_irqchip fdt_irqchip_plic = {
|
||||||
.match_table = irqchip_plic_match,
|
.match_table = irqchip_plic_match,
|
||||||
.cold_init = irqchip_plic_cold_init,
|
.cold_init = irqchip_plic_cold_init,
|
||||||
.warm_init = irqchip_plic_warm_init,
|
.warm_init = plic_warm_irqchip_init,
|
||||||
.exit = NULL,
|
.exit = NULL,
|
||||||
};
|
};
|
||||||
|
@@ -27,6 +27,21 @@
|
|||||||
|
|
||||||
#define THEAD_PLIC_CTRL_REG 0x1ffffc
|
#define THEAD_PLIC_CTRL_REG 0x1ffffc
|
||||||
|
|
||||||
|
static unsigned long plic_ptr_offset;
|
||||||
|
|
||||||
|
#define plic_get_hart_data_ptr(__scratch) \
|
||||||
|
sbi_scratch_read_type((__scratch), void *, plic_ptr_offset)
|
||||||
|
|
||||||
|
#define plic_set_hart_data_ptr(__scratch, __plic) \
|
||||||
|
sbi_scratch_write_type((__scratch), void *, plic_ptr_offset, (__plic))
|
||||||
|
|
||||||
|
struct plic_data *plic_get(void)
|
||||||
|
{
|
||||||
|
struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
|
||||||
|
|
||||||
|
return plic_get_hart_data_ptr(scratch);
|
||||||
|
}
|
||||||
|
|
||||||
static u32 plic_get_priority(const struct plic_data *plic, u32 source)
|
static u32 plic_get_priority(const struct plic_data *plic, u32 source)
|
||||||
{
|
{
|
||||||
volatile void *plic_priority = (char *)plic->addr +
|
volatile void *plic_priority = (char *)plic->addr +
|
||||||
@@ -109,8 +124,10 @@ static int plic_context_init(const struct plic_data *plic, int context_id,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void plic_suspend(const struct plic_data *plic)
|
void plic_suspend(void)
|
||||||
{
|
{
|
||||||
|
struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
|
||||||
|
const struct plic_data *plic = plic_get_hart_data_ptr(scratch);
|
||||||
u32 ie_words = PLIC_IE_WORDS(plic);
|
u32 ie_words = PLIC_IE_WORDS(plic);
|
||||||
u32 *data_word = plic->pm_data;
|
u32 *data_word = plic->pm_data;
|
||||||
u8 *data_byte;
|
u8 *data_byte;
|
||||||
@@ -138,8 +155,10 @@ void plic_suspend(const struct plic_data *plic)
|
|||||||
*data_byte++ = plic_get_priority(plic, i);
|
*data_byte++ = plic_get_priority(plic, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
void plic_resume(const struct plic_data *plic)
|
void plic_resume(void)
|
||||||
{
|
{
|
||||||
|
struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
|
||||||
|
const struct plic_data *plic = plic_get_hart_data_ptr(scratch);
|
||||||
u32 ie_words = PLIC_IE_WORDS(plic);
|
u32 ie_words = PLIC_IE_WORDS(plic);
|
||||||
u32 *data_word = plic->pm_data;
|
u32 *data_word = plic->pm_data;
|
||||||
u8 *data_byte;
|
u8 *data_byte;
|
||||||
@@ -170,8 +189,10 @@ void plic_resume(const struct plic_data *plic)
|
|||||||
plic_delegate(plic);
|
plic_delegate(plic);
|
||||||
}
|
}
|
||||||
|
|
||||||
int plic_warm_irqchip_init(const struct plic_data *plic)
|
int plic_warm_irqchip_init(void)
|
||||||
{
|
{
|
||||||
|
struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
|
||||||
|
const struct plic_data *plic = plic_get_hart_data_ptr(scratch);
|
||||||
u32 hartindex = current_hartindex();
|
u32 hartindex = current_hartindex();
|
||||||
s16 m_cntx_id = plic->context_map[hartindex][PLIC_M_CONTEXT];
|
s16 m_cntx_id = plic->context_map[hartindex][PLIC_M_CONTEXT];
|
||||||
s16 s_cntx_id = plic->context_map[hartindex][PLIC_S_CONTEXT];
|
s16 s_cntx_id = plic->context_map[hartindex][PLIC_S_CONTEXT];
|
||||||
@@ -201,11 +222,17 @@ int plic_warm_irqchip_init(const struct plic_data *plic)
|
|||||||
|
|
||||||
int plic_cold_irqchip_init(struct plic_data *plic)
|
int plic_cold_irqchip_init(struct plic_data *plic)
|
||||||
{
|
{
|
||||||
int i;
|
int i, ret;
|
||||||
|
|
||||||
if (!plic)
|
if (!plic)
|
||||||
return SBI_EINVAL;
|
return SBI_EINVAL;
|
||||||
|
|
||||||
|
if (!plic_ptr_offset) {
|
||||||
|
plic_ptr_offset = sbi_scratch_alloc_type_offset(void *);
|
||||||
|
if (!plic_ptr_offset)
|
||||||
|
return SBI_ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
if (plic->flags & PLIC_FLAG_ENABLE_PM) {
|
if (plic->flags & PLIC_FLAG_ENABLE_PM) {
|
||||||
unsigned long data_size = 0;
|
unsigned long data_size = 0;
|
||||||
|
|
||||||
@@ -237,7 +264,19 @@ int plic_cold_irqchip_init(struct plic_data *plic)
|
|||||||
|
|
||||||
plic_delegate(plic);
|
plic_delegate(plic);
|
||||||
|
|
||||||
return sbi_domain_root_add_memrange(plic->addr, plic->size, BIT(20),
|
ret = sbi_domain_root_add_memrange(plic->addr, plic->size, BIT(20),
|
||||||
(SBI_DOMAIN_MEMREGION_MMIO |
|
(SBI_DOMAIN_MEMREGION_MMIO |
|
||||||
SBI_DOMAIN_MEMREGION_SHARED_SURW_MRW));
|
SBI_DOMAIN_MEMREGION_SHARED_SURW_MRW));
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
for (u32 i = 0; i <= sbi_scratch_last_hartindex(); i++) {
|
||||||
|
if (plic->context_map[i][PLIC_M_CONTEXT] < 0 &&
|
||||||
|
plic->context_map[i][PLIC_S_CONTEXT] < 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
plic_set_hart_data_ptr(sbi_hartindex_to_scratch(i), plic);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -110,7 +110,7 @@ static int ariane_irqchip_init(bool cold_boot)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
return plic_warm_irqchip_init(&plic);
|
return plic_warm_irqchip_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -143,7 +143,7 @@ static int openpiton_irqchip_init(bool cold_boot)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
return plic_warm_irqchip_init(&plic);
|
return plic_warm_irqchip_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -17,7 +17,7 @@
|
|||||||
#include <sbi/sbi_scratch.h>
|
#include <sbi/sbi_scratch.h>
|
||||||
#include <sbi_utils/fdt/fdt_fixup.h>
|
#include <sbi_utils/fdt/fdt_fixup.h>
|
||||||
#include <sbi_utils/fdt/fdt_helper.h>
|
#include <sbi_utils/fdt/fdt_helper.h>
|
||||||
#include <sbi_utils/irqchip/fdt_irqchip_plic.h>
|
#include <sbi_utils/irqchip/plic.h>
|
||||||
|
|
||||||
#define SUN20I_D1_CCU_BASE ((void *)0x02001000)
|
#define SUN20I_D1_CCU_BASE ((void *)0x02001000)
|
||||||
#define SUN20I_D1_RISCV_CFG_BASE ((void *)0x06010000)
|
#define SUN20I_D1_RISCV_CFG_BASE ((void *)0x06010000)
|
||||||
@@ -92,7 +92,7 @@ static void sun20i_d1_ppu_restore(void)
|
|||||||
|
|
||||||
static void sun20i_d1_riscv_cfg_save(void)
|
static void sun20i_d1_riscv_cfg_save(void)
|
||||||
{
|
{
|
||||||
struct plic_data *plic = fdt_plic_get();
|
struct plic_data *plic = plic_get();
|
||||||
u32 *plic_sie = plic->pm_data;
|
u32 *plic_sie = plic->pm_data;
|
||||||
|
|
||||||
/* Enable MMIO access. Do not assume S-mode leaves the clock enabled. */
|
/* Enable MMIO access. Do not assume S-mode leaves the clock enabled. */
|
||||||
@@ -136,7 +136,7 @@ static int sun20i_d1_hart_suspend(u32 suspend_type)
|
|||||||
if (!(suspend_type & SBI_HSM_SUSP_NON_RET_BIT))
|
if (!(suspend_type & SBI_HSM_SUSP_NON_RET_BIT))
|
||||||
return SBI_ENOTSUPP;
|
return SBI_ENOTSUPP;
|
||||||
|
|
||||||
fdt_plic_suspend();
|
plic_suspend();
|
||||||
sun20i_d1_ppu_save();
|
sun20i_d1_ppu_save();
|
||||||
sun20i_d1_riscv_cfg_save();
|
sun20i_d1_riscv_cfg_save();
|
||||||
sun20i_d1_csr_save();
|
sun20i_d1_csr_save();
|
||||||
@@ -156,7 +156,7 @@ static void sun20i_d1_hart_resume(void)
|
|||||||
sun20i_d1_csr_restore();
|
sun20i_d1_csr_restore();
|
||||||
sun20i_d1_riscv_cfg_restore();
|
sun20i_d1_riscv_cfg_restore();
|
||||||
sun20i_d1_ppu_restore();
|
sun20i_d1_ppu_restore();
|
||||||
fdt_plic_resume();
|
plic_resume();
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct sbi_hsm_device sun20i_d1_ppu = {
|
static const struct sbi_hsm_device sun20i_d1_ppu = {
|
||||||
|
@@ -146,7 +146,7 @@ static int k210_irqchip_init(bool cold_boot)
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
return plic_warm_irqchip_init(&plic);
|
return plic_warm_irqchip_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int k210_ipi_init(void)
|
static int k210_ipi_init(void)
|
||||||
|
@@ -200,7 +200,7 @@ static int ux600_irqchip_init(bool cold_boot)
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
return plic_warm_irqchip_init(&plic);
|
return plic_warm_irqchip_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ux600_ipi_init(void)
|
static int ux600_ipi_init(void)
|
||||||
|
@@ -100,7 +100,7 @@ static int platform_irqchip_init(bool cold_boot)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
return plic_warm_irqchip_init(&plic);
|
return plic_warm_irqchip_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Reference in New Issue
Block a user