2017-03-14 22:16:30 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017 Jean-Paul Etienne <fractalclone@gmail.com>
|
2018-06-10 19:02:14 +02:00
|
|
|
* Contributors: 2018 Antmicro <www.antmicro.com>
|
2017-03-14 22:16:30 +01:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Platform Level Interrupt Controller (PLIC) driver
|
2018-06-10 19:02:14 +02:00
|
|
|
* for RISC-V processors
|
2017-03-14 22:16:30 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <kernel.h>
|
|
|
|
#include <arch/cpu.h>
|
|
|
|
#include <init.h>
|
2018-06-10 19:02:14 +02:00
|
|
|
#include "plic.h"
|
2017-03-14 22:16:30 +01:00
|
|
|
#include <sw_isr_table.h>
|
|
|
|
|
|
|
|
|
2018-06-10 19:02:14 +02:00
|
|
|
struct plic_regs_t {
|
2017-04-21 10:03:20 -05:00
|
|
|
u32_t threshold_prio;
|
|
|
|
u32_t claim_complete;
|
2017-03-14 22:16:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static int save_irq;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @brief Enable a riscv PLIC-specific interrupt line
|
|
|
|
*
|
|
|
|
* This routine enables a RISCV PLIC-specific interrupt line.
|
|
|
|
* riscv_plic_irq_enable is called by SOC_FAMILY_RISCV_PRIVILEGE
|
2019-03-08 14:19:05 -07:00
|
|
|
* z_arch_irq_enable function to enable external interrupts for
|
2017-03-14 22:16:30 +01:00
|
|
|
* IRQS > RISCV_MAX_GENERIC_IRQ, whenever CONFIG_RISCV_HAS_PLIC
|
|
|
|
* variable is set.
|
|
|
|
* @param irq IRQ number to enable
|
|
|
|
*
|
|
|
|
* @return N/A
|
|
|
|
*/
|
2017-04-21 10:03:20 -05:00
|
|
|
void riscv_plic_irq_enable(u32_t irq)
|
2017-03-14 22:16:30 +01:00
|
|
|
{
|
2017-04-21 10:03:20 -05:00
|
|
|
u32_t key;
|
2018-06-10 19:02:14 +02:00
|
|
|
u32_t plic_irq = irq - RISCV_MAX_GENERIC_IRQ;
|
2017-04-21 10:03:20 -05:00
|
|
|
volatile u32_t *en =
|
dts: riscv: Add sifive,plic-1.0.0 binding and fix riscv,ndev values
Add a new sifive,plic-1.0.0 binding that inherits from the riscv,plic0
binding. The new binding adds a required riscv,ndev property, which
gives the number of external interrupts supported.
Use the new binding for microsemi-miv.dtsi (with a value of 31 for
riscv,ndev, from http://www.actel.com/ipdocs/MiV_RV32IMAF_L1_AHB_HB.pdf)
and riscv32-fe310.dtsi (which already assigns riscv,ndev).
Also remove a spurious riscv,ndev assignment from
riscv32-litex-vexriscv.dtsi.
Also make edtlib and the old scripts/dts/ scripts replace '.' in
compatible strings with '_' when generating identifiers.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-08-01 18:14:52 +02:00
|
|
|
(volatile u32_t *)DT_INST_0_SIFIVE_PLIC_1_0_0_IRQ_EN_BASE_ADDRESS;
|
2017-03-14 22:16:30 +01:00
|
|
|
|
|
|
|
key = irq_lock();
|
2018-06-10 19:02:14 +02:00
|
|
|
en += (plic_irq >> 5);
|
|
|
|
*en |= (1 << (plic_irq & 31));
|
2017-03-14 22:16:30 +01:00
|
|
|
irq_unlock(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @brief Disable a riscv PLIC-specific interrupt line
|
|
|
|
*
|
|
|
|
* This routine disables a RISCV PLIC-specific interrupt line.
|
|
|
|
* riscv_plic_irq_disable is called by SOC_FAMILY_RISCV_PRIVILEGE
|
2019-03-08 14:19:05 -07:00
|
|
|
* z_arch_irq_disable function to disable external interrupts, for
|
2017-03-14 22:16:30 +01:00
|
|
|
* IRQS > RISCV_MAX_GENERIC_IRQ, whenever CONFIG_RISCV_HAS_PLIC
|
|
|
|
* variable is set.
|
|
|
|
* @param irq IRQ number to disable
|
|
|
|
*
|
|
|
|
* @return N/A
|
|
|
|
*/
|
2017-04-21 10:03:20 -05:00
|
|
|
void riscv_plic_irq_disable(u32_t irq)
|
2017-03-14 22:16:30 +01:00
|
|
|
{
|
2017-04-21 10:03:20 -05:00
|
|
|
u32_t key;
|
2018-06-10 19:02:14 +02:00
|
|
|
u32_t plic_irq = irq - RISCV_MAX_GENERIC_IRQ;
|
2017-04-21 10:03:20 -05:00
|
|
|
volatile u32_t *en =
|
dts: riscv: Add sifive,plic-1.0.0 binding and fix riscv,ndev values
Add a new sifive,plic-1.0.0 binding that inherits from the riscv,plic0
binding. The new binding adds a required riscv,ndev property, which
gives the number of external interrupts supported.
Use the new binding for microsemi-miv.dtsi (with a value of 31 for
riscv,ndev, from http://www.actel.com/ipdocs/MiV_RV32IMAF_L1_AHB_HB.pdf)
and riscv32-fe310.dtsi (which already assigns riscv,ndev).
Also remove a spurious riscv,ndev assignment from
riscv32-litex-vexriscv.dtsi.
Also make edtlib and the old scripts/dts/ scripts replace '.' in
compatible strings with '_' when generating identifiers.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-08-01 18:14:52 +02:00
|
|
|
(volatile u32_t *)DT_INST_0_SIFIVE_PLIC_1_0_0_IRQ_EN_BASE_ADDRESS;
|
2017-03-14 22:16:30 +01:00
|
|
|
|
|
|
|
key = irq_lock();
|
2018-06-10 19:02:14 +02:00
|
|
|
en += (plic_irq >> 5);
|
|
|
|
*en &= ~(1 << (plic_irq & 31));
|
2017-03-14 22:16:30 +01:00
|
|
|
irq_unlock(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @brief Check if a riscv PLIC-specific interrupt line is enabled
|
|
|
|
*
|
|
|
|
* This routine checks if a RISCV PLIC-specific interrupt line is enabled.
|
|
|
|
* @param irq IRQ number to check
|
|
|
|
*
|
|
|
|
* @return 1 or 0
|
|
|
|
*/
|
2017-04-21 10:03:20 -05:00
|
|
|
int riscv_plic_irq_is_enabled(u32_t irq)
|
2017-03-14 22:16:30 +01:00
|
|
|
{
|
2017-04-21 10:03:20 -05:00
|
|
|
volatile u32_t *en =
|
dts: riscv: Add sifive,plic-1.0.0 binding and fix riscv,ndev values
Add a new sifive,plic-1.0.0 binding that inherits from the riscv,plic0
binding. The new binding adds a required riscv,ndev property, which
gives the number of external interrupts supported.
Use the new binding for microsemi-miv.dtsi (with a value of 31 for
riscv,ndev, from http://www.actel.com/ipdocs/MiV_RV32IMAF_L1_AHB_HB.pdf)
and riscv32-fe310.dtsi (which already assigns riscv,ndev).
Also remove a spurious riscv,ndev assignment from
riscv32-litex-vexriscv.dtsi.
Also make edtlib and the old scripts/dts/ scripts replace '.' in
compatible strings with '_' when generating identifiers.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-08-01 18:14:52 +02:00
|
|
|
(volatile u32_t *)DT_INST_0_SIFIVE_PLIC_1_0_0_IRQ_EN_BASE_ADDRESS;
|
2018-06-10 19:02:14 +02:00
|
|
|
u32_t plic_irq = irq - RISCV_MAX_GENERIC_IRQ;
|
2017-03-14 22:16:30 +01:00
|
|
|
|
2018-06-10 19:02:14 +02:00
|
|
|
en += (plic_irq >> 5);
|
|
|
|
return !!(*en & (1 << (plic_irq & 31)));
|
2017-03-14 22:16:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @brief Set priority of a riscv PLIC-specific interrupt line
|
|
|
|
*
|
|
|
|
* This routine set the priority of a RISCV PLIC-specific interrupt line.
|
2019-07-17 13:17:05 -04:00
|
|
|
* riscv_plic_irq_set_prio is called by riscv Z_ARCH_IRQ_CONNECT to set
|
2017-03-14 22:16:30 +01:00
|
|
|
* the priority of an interrupt whenever CONFIG_RISCV_HAS_PLIC variable is set.
|
|
|
|
* @param irq IRQ number for which to set priority
|
|
|
|
*
|
|
|
|
* @return N/A
|
|
|
|
*/
|
2017-04-21 10:03:20 -05:00
|
|
|
void riscv_plic_set_priority(u32_t irq, u32_t priority)
|
2017-03-14 22:16:30 +01:00
|
|
|
{
|
2017-04-21 10:03:20 -05:00
|
|
|
volatile u32_t *prio =
|
dts: riscv: Add sifive,plic-1.0.0 binding and fix riscv,ndev values
Add a new sifive,plic-1.0.0 binding that inherits from the riscv,plic0
binding. The new binding adds a required riscv,ndev property, which
gives the number of external interrupts supported.
Use the new binding for microsemi-miv.dtsi (with a value of 31 for
riscv,ndev, from http://www.actel.com/ipdocs/MiV_RV32IMAF_L1_AHB_HB.pdf)
and riscv32-fe310.dtsi (which already assigns riscv,ndev).
Also remove a spurious riscv,ndev assignment from
riscv32-litex-vexriscv.dtsi.
Also make edtlib and the old scripts/dts/ scripts replace '.' in
compatible strings with '_' when generating identifiers.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-08-01 18:14:52 +02:00
|
|
|
(volatile u32_t *)DT_INST_0_SIFIVE_PLIC_1_0_0_PRIO_BASE_ADDRESS;
|
2017-03-14 22:16:30 +01:00
|
|
|
|
|
|
|
/* Can set priority only for PLIC-specific interrupt line */
|
|
|
|
if (irq <= RISCV_MAX_GENERIC_IRQ)
|
|
|
|
return;
|
|
|
|
|
dts: riscv: Add sifive,plic-1.0.0 binding and fix riscv,ndev values
Add a new sifive,plic-1.0.0 binding that inherits from the riscv,plic0
binding. The new binding adds a required riscv,ndev property, which
gives the number of external interrupts supported.
Use the new binding for microsemi-miv.dtsi (with a value of 31 for
riscv,ndev, from http://www.actel.com/ipdocs/MiV_RV32IMAF_L1_AHB_HB.pdf)
and riscv32-fe310.dtsi (which already assigns riscv,ndev).
Also remove a spurious riscv,ndev assignment from
riscv32-litex-vexriscv.dtsi.
Also make edtlib and the old scripts/dts/ scripts replace '.' in
compatible strings with '_' when generating identifiers.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-08-01 18:14:52 +02:00
|
|
|
if (priority > DT_INST_0_SIFIVE_PLIC_1_0_0_RISCV_MAX_PRIORITY)
|
|
|
|
priority = DT_INST_0_SIFIVE_PLIC_1_0_0_RISCV_MAX_PRIORITY;
|
2017-03-14 22:16:30 +01:00
|
|
|
|
|
|
|
prio += (irq - RISCV_MAX_GENERIC_IRQ);
|
|
|
|
*prio = priority;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @brief Get riscv PLIC-specific interrupt line causing an interrupt
|
|
|
|
*
|
|
|
|
* This routine returns the RISCV PLIC-specific interrupt line causing an
|
|
|
|
* interrupt.
|
|
|
|
* @param irq IRQ number for which to set priority
|
|
|
|
*
|
|
|
|
* @return N/A
|
|
|
|
*/
|
|
|
|
int riscv_plic_get_irq(void)
|
|
|
|
{
|
|
|
|
return save_irq;
|
|
|
|
}
|
|
|
|
|
2018-06-10 19:02:14 +02:00
|
|
|
static void plic_irq_handler(void *arg)
|
2017-03-14 22:16:30 +01:00
|
|
|
{
|
2018-06-10 19:02:14 +02:00
|
|
|
volatile struct plic_regs_t *regs =
|
dts: riscv: Add sifive,plic-1.0.0 binding and fix riscv,ndev values
Add a new sifive,plic-1.0.0 binding that inherits from the riscv,plic0
binding. The new binding adds a required riscv,ndev property, which
gives the number of external interrupts supported.
Use the new binding for microsemi-miv.dtsi (with a value of 31 for
riscv,ndev, from http://www.actel.com/ipdocs/MiV_RV32IMAF_L1_AHB_HB.pdf)
and riscv32-fe310.dtsi (which already assigns riscv,ndev).
Also remove a spurious riscv,ndev assignment from
riscv32-litex-vexriscv.dtsi.
Also make edtlib and the old scripts/dts/ scripts replace '.' in
compatible strings with '_' when generating identifiers.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-08-01 18:14:52 +02:00
|
|
|
(volatile struct plic_regs_t *) DT_INST_0_SIFIVE_PLIC_1_0_0_REG_BASE_ADDRESS;
|
2017-03-14 22:16:30 +01:00
|
|
|
|
2017-04-21 10:03:20 -05:00
|
|
|
u32_t irq;
|
2017-03-14 22:16:30 +01:00
|
|
|
struct _isr_table_entry *ite;
|
|
|
|
|
|
|
|
/* Get the IRQ number generating the interrupt */
|
|
|
|
irq = regs->claim_complete;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Save IRQ in save_irq. To be used, if need be, by
|
|
|
|
* subsequent handlers registered in the _sw_isr_table table,
|
|
|
|
* as IRQ number held by the claim_complete register is
|
|
|
|
* cleared upon read.
|
|
|
|
*/
|
|
|
|
save_irq = irq;
|
|
|
|
|
|
|
|
/*
|
2019-03-08 14:19:05 -07:00
|
|
|
* If the IRQ is out of range, call z_irq_spurious.
|
|
|
|
* A call to z_irq_spurious will not return.
|
2017-03-14 22:16:30 +01:00
|
|
|
*/
|
2019-03-26 19:57:45 -06:00
|
|
|
if (irq == 0U || irq >= PLIC_IRQS)
|
2019-03-08 14:19:05 -07:00
|
|
|
z_irq_spurious(NULL);
|
2017-03-14 22:16:30 +01:00
|
|
|
|
|
|
|
irq += RISCV_MAX_GENERIC_IRQ;
|
|
|
|
|
|
|
|
/* Call the corresponding IRQ handler in _sw_isr_table */
|
|
|
|
ite = (struct _isr_table_entry *)&_sw_isr_table[irq];
|
|
|
|
ite->isr(ite->arg);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write to claim_complete register to indicate to
|
|
|
|
* PLIC controller that the IRQ has been handled.
|
|
|
|
*/
|
|
|
|
regs->claim_complete = save_irq;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
2018-06-10 19:02:14 +02:00
|
|
|
* @brief Initialize the Platform Level Interrupt Controller
|
2017-03-14 22:16:30 +01:00
|
|
|
* @return N/A
|
|
|
|
*/
|
2018-06-10 19:02:14 +02:00
|
|
|
static int plic_init(struct device *dev)
|
2017-03-14 22:16:30 +01:00
|
|
|
{
|
|
|
|
ARG_UNUSED(dev);
|
|
|
|
|
2017-04-21 10:03:20 -05:00
|
|
|
volatile u32_t *en =
|
dts: riscv: Add sifive,plic-1.0.0 binding and fix riscv,ndev values
Add a new sifive,plic-1.0.0 binding that inherits from the riscv,plic0
binding. The new binding adds a required riscv,ndev property, which
gives the number of external interrupts supported.
Use the new binding for microsemi-miv.dtsi (with a value of 31 for
riscv,ndev, from http://www.actel.com/ipdocs/MiV_RV32IMAF_L1_AHB_HB.pdf)
and riscv32-fe310.dtsi (which already assigns riscv,ndev).
Also remove a spurious riscv,ndev assignment from
riscv32-litex-vexriscv.dtsi.
Also make edtlib and the old scripts/dts/ scripts replace '.' in
compatible strings with '_' when generating identifiers.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-08-01 18:14:52 +02:00
|
|
|
(volatile u32_t *)DT_INST_0_SIFIVE_PLIC_1_0_0_IRQ_EN_BASE_ADDRESS;
|
2017-04-21 10:03:20 -05:00
|
|
|
volatile u32_t *prio =
|
dts: riscv: Add sifive,plic-1.0.0 binding and fix riscv,ndev values
Add a new sifive,plic-1.0.0 binding that inherits from the riscv,plic0
binding. The new binding adds a required riscv,ndev property, which
gives the number of external interrupts supported.
Use the new binding for microsemi-miv.dtsi (with a value of 31 for
riscv,ndev, from http://www.actel.com/ipdocs/MiV_RV32IMAF_L1_AHB_HB.pdf)
and riscv32-fe310.dtsi (which already assigns riscv,ndev).
Also remove a spurious riscv,ndev assignment from
riscv32-litex-vexriscv.dtsi.
Also make edtlib and the old scripts/dts/ scripts replace '.' in
compatible strings with '_' when generating identifiers.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-08-01 18:14:52 +02:00
|
|
|
(volatile u32_t *)DT_INST_0_SIFIVE_PLIC_1_0_0_PRIO_BASE_ADDRESS;
|
2018-06-10 19:02:14 +02:00
|
|
|
volatile struct plic_regs_t *regs =
|
dts: riscv: Add sifive,plic-1.0.0 binding and fix riscv,ndev values
Add a new sifive,plic-1.0.0 binding that inherits from the riscv,plic0
binding. The new binding adds a required riscv,ndev property, which
gives the number of external interrupts supported.
Use the new binding for microsemi-miv.dtsi (with a value of 31 for
riscv,ndev, from http://www.actel.com/ipdocs/MiV_RV32IMAF_L1_AHB_HB.pdf)
and riscv32-fe310.dtsi (which already assigns riscv,ndev).
Also remove a spurious riscv,ndev assignment from
riscv32-litex-vexriscv.dtsi.
Also make edtlib and the old scripts/dts/ scripts replace '.' in
compatible strings with '_' when generating identifiers.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-08-01 18:14:52 +02:00
|
|
|
(volatile struct plic_regs_t *)DT_INST_0_SIFIVE_PLIC_1_0_0_REG_BASE_ADDRESS;
|
2017-03-14 22:16:30 +01:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Ensure that all interrupts are disabled initially */
|
2018-06-10 19:02:14 +02:00
|
|
|
for (i = 0; i < PLIC_EN_SIZE; i++) {
|
2018-11-29 11:12:22 -08:00
|
|
|
*en = 0U;
|
2017-03-14 22:16:30 +01:00
|
|
|
en++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set priority of each interrupt line to 0 initially */
|
2018-06-10 19:02:14 +02:00
|
|
|
for (i = 0; i < PLIC_IRQS; i++) {
|
2018-11-29 11:12:22 -08:00
|
|
|
*prio = 0U;
|
2017-03-14 22:16:30 +01:00
|
|
|
prio++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set threshold priority to 0 */
|
2018-11-29 11:12:22 -08:00
|
|
|
regs->threshold_prio = 0U;
|
2017-03-14 22:16:30 +01:00
|
|
|
|
|
|
|
/* Setup IRQ handler for PLIC driver */
|
|
|
|
IRQ_CONNECT(RISCV_MACHINE_EXT_IRQ,
|
|
|
|
0,
|
2018-06-10 19:02:14 +02:00
|
|
|
plic_irq_handler,
|
2017-03-14 22:16:30 +01:00
|
|
|
NULL,
|
|
|
|
0);
|
|
|
|
|
|
|
|
/* Enable IRQ for PLIC driver */
|
|
|
|
irq_enable(RISCV_MACHINE_EXT_IRQ);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-06-10 19:02:14 +02:00
|
|
|
SYS_INIT(plic_init, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
|