2017-09-19 12:14:52 +08:00
|
|
|
/*
|
2021-03-27 17:51:56 +08:00
|
|
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
2017-09-19 12:14:52 +08:00
|
|
|
*
|
2019-03-25 20:03:49 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2017-09-19 12:14:52 +08:00
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2013-07-20 Bernard first version
|
|
|
|
* 2014-04-03 Grissiom many enhancements
|
2018-11-22 14:40:43 +08:00
|
|
|
* 2018-11-22 Jesven add rt_hw_ipi_send()
|
|
|
|
* add rt_hw_ipi_handler_install()
|
2017-09-19 12:14:52 +08:00
|
|
|
*/
|
|
|
|
|
2018-11-22 14:40:43 +08:00
|
|
|
#include <rthw.h>
|
2017-09-19 12:14:52 +08:00
|
|
|
#include <rtthread.h>
|
|
|
|
|
|
|
|
#include "gic.h"
|
|
|
|
#include "cp15.h"
|
|
|
|
|
|
|
|
struct arm_gic
|
|
|
|
{
|
2019-03-25 20:03:49 +08:00
|
|
|
rt_uint32_t offset; /* the first interrupt index in the vector table */
|
2017-09-19 12:14:52 +08:00
|
|
|
|
2019-03-25 20:03:49 +08:00
|
|
|
rt_uint32_t dist_hw_base; /* the base address of the gic distributor */
|
|
|
|
rt_uint32_t cpu_hw_base; /* the base addrees of the gic cpu interface */
|
2017-09-19 12:14:52 +08:00
|
|
|
};
|
2019-03-25 20:03:49 +08:00
|
|
|
|
|
|
|
/* 'ARM_GIC_MAX_NR' is the number of cores */
|
2017-09-19 12:14:52 +08:00
|
|
|
static struct arm_gic _gic_table[ARM_GIC_MAX_NR];
|
|
|
|
|
2021-04-08 15:46:15 +08:00
|
|
|
/** Macro to access the Generic Interrupt Controller Interface (GICC)
|
|
|
|
*/
|
2021-04-09 11:07:58 +08:00
|
|
|
#define GIC_CPU_CTRL(hw_base) __REG32((hw_base) + 0x00U)
|
|
|
|
#define GIC_CPU_PRIMASK(hw_base) __REG32((hw_base) + 0x04U)
|
|
|
|
#define GIC_CPU_BINPOINT(hw_base) __REG32((hw_base) + 0x08U)
|
|
|
|
#define GIC_CPU_INTACK(hw_base) __REG32((hw_base) + 0x0cU)
|
|
|
|
#define GIC_CPU_EOI(hw_base) __REG32((hw_base) + 0x10U)
|
|
|
|
#define GIC_CPU_RUNNINGPRI(hw_base) __REG32((hw_base) + 0x14U)
|
|
|
|
#define GIC_CPU_HIGHPRI(hw_base) __REG32((hw_base) + 0x18U)
|
|
|
|
#define GIC_CPU_IIDR(hw_base) __REG32((hw_base) + 0xFCU)
|
2017-09-19 12:14:52 +08:00
|
|
|
|
2021-04-08 15:46:15 +08:00
|
|
|
/** Macro to access the Generic Interrupt Controller Distributor (GICD)
|
|
|
|
*/
|
2021-04-09 11:07:58 +08:00
|
|
|
#define GIC_DIST_CTRL(hw_base) __REG32((hw_base) + 0x000U)
|
|
|
|
#define GIC_DIST_TYPE(hw_base) __REG32((hw_base) + 0x004U)
|
|
|
|
#define GIC_DIST_IGROUP(hw_base, n) __REG32((hw_base) + 0x080U + ((n)/32U) * 4U)
|
|
|
|
#define GIC_DIST_ENABLE_SET(hw_base, n) __REG32((hw_base) + 0x100U + ((n)/32U) * 4U)
|
|
|
|
#define GIC_DIST_ENABLE_CLEAR(hw_base, n) __REG32((hw_base) + 0x180U + ((n)/32U) * 4U)
|
|
|
|
#define GIC_DIST_PENDING_SET(hw_base, n) __REG32((hw_base) + 0x200U + ((n)/32U) * 4U)
|
|
|
|
#define GIC_DIST_PENDING_CLEAR(hw_base, n) __REG32((hw_base) + 0x280U + ((n)/32U) * 4U)
|
|
|
|
#define GIC_DIST_ACTIVE_SET(hw_base, n) __REG32((hw_base) + 0x300U + ((n)/32U) * 4U)
|
|
|
|
#define GIC_DIST_ACTIVE_CLEAR(hw_base, n) __REG32((hw_base) + 0x380U + ((n)/32U) * 4U)
|
|
|
|
#define GIC_DIST_PRI(hw_base, n) __REG32((hw_base) + 0x400U + ((n)/4U) * 4U)
|
|
|
|
#define GIC_DIST_TARGET(hw_base, n) __REG32((hw_base) + 0x800U + ((n)/4U) * 4U)
|
|
|
|
#define GIC_DIST_CONFIG(hw_base, n) __REG32((hw_base) + 0xc00U + ((n)/16U) * 4U)
|
|
|
|
#define GIC_DIST_SOFTINT(hw_base) __REG32((hw_base) + 0xf00U)
|
|
|
|
#define GIC_DIST_CPENDSGI(hw_base, n) __REG32((hw_base) + 0xf10U + ((n)/4U) * 4U)
|
|
|
|
#define GIC_DIST_SPENDSGI(hw_base, n) __REG32((hw_base) + 0xf20U + ((n)/4U) * 4U)
|
|
|
|
#define GIC_DIST_ICPIDR2(hw_base) __REG32((hw_base) + 0xfe8U)
|
2017-09-19 12:14:52 +08:00
|
|
|
|
|
|
|
static unsigned int _gic_max_irq;
|
|
|
|
|
|
|
|
int arm_gic_get_active_irq(rt_uint32_t index)
|
|
|
|
{
|
|
|
|
int irq;
|
|
|
|
|
|
|
|
RT_ASSERT(index < ARM_GIC_MAX_NR);
|
|
|
|
|
|
|
|
irq = GIC_CPU_INTACK(_gic_table[index].cpu_hw_base);
|
|
|
|
irq += _gic_table[index].offset;
|
|
|
|
return irq;
|
|
|
|
}
|
|
|
|
|
|
|
|
void arm_gic_ack(rt_uint32_t index, int irq)
|
|
|
|
{
|
2021-04-09 11:07:58 +08:00
|
|
|
rt_uint32_t mask = 1U << (irq % 32U);
|
2017-09-19 12:14:52 +08:00
|
|
|
|
|
|
|
RT_ASSERT(index < ARM_GIC_MAX_NR);
|
|
|
|
|
|
|
|
irq = irq - _gic_table[index].offset;
|
2021-04-09 11:07:58 +08:00
|
|
|
RT_ASSERT(irq >= 0U);
|
2017-09-19 12:14:52 +08:00
|
|
|
|
2020-06-30 17:32:14 +08:00
|
|
|
GIC_DIST_PENDING_CLEAR(_gic_table[index].dist_hw_base, irq) = mask;
|
2017-09-19 12:14:52 +08:00
|
|
|
GIC_CPU_EOI(_gic_table[index].cpu_hw_base) = irq;
|
|
|
|
}
|
|
|
|
|
|
|
|
void arm_gic_mask(rt_uint32_t index, int irq)
|
|
|
|
{
|
2021-04-09 11:07:58 +08:00
|
|
|
rt_uint32_t mask = 1U << (irq % 32U);
|
2017-09-19 12:14:52 +08:00
|
|
|
|
|
|
|
RT_ASSERT(index < ARM_GIC_MAX_NR);
|
|
|
|
|
|
|
|
irq = irq - _gic_table[index].offset;
|
2021-04-09 11:07:58 +08:00
|
|
|
RT_ASSERT(irq >= 0U);
|
2017-09-19 12:14:52 +08:00
|
|
|
|
|
|
|
GIC_DIST_ENABLE_CLEAR(_gic_table[index].dist_hw_base, irq) = mask;
|
|
|
|
}
|
|
|
|
|
2021-04-08 15:46:15 +08:00
|
|
|
void arm_gic_umask(rt_uint32_t index, int irq)
|
2017-09-19 12:14:52 +08:00
|
|
|
{
|
2021-04-09 11:07:58 +08:00
|
|
|
rt_uint32_t mask = 1U << (irq % 32U);
|
2017-09-19 12:14:52 +08:00
|
|
|
|
|
|
|
RT_ASSERT(index < ARM_GIC_MAX_NR);
|
|
|
|
|
|
|
|
irq = irq - _gic_table[index].offset;
|
2021-04-09 11:07:58 +08:00
|
|
|
RT_ASSERT(irq >= 0U);
|
2017-09-19 12:14:52 +08:00
|
|
|
|
2021-04-08 15:46:15 +08:00
|
|
|
GIC_DIST_ENABLE_SET(_gic_table[index].dist_hw_base, irq) = mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
rt_uint32_t arm_gic_get_pending_irq(rt_uint32_t index, int irq)
|
|
|
|
{
|
|
|
|
rt_uint32_t pend;
|
|
|
|
|
|
|
|
RT_ASSERT(index < ARM_GIC_MAX_NR);
|
|
|
|
|
|
|
|
irq = irq - _gic_table[index].offset;
|
2021-04-09 11:07:58 +08:00
|
|
|
RT_ASSERT(irq >= 0U);
|
2021-04-08 15:46:15 +08:00
|
|
|
|
2021-04-09 11:07:58 +08:00
|
|
|
if (irq >= 16U)
|
2021-04-08 15:46:15 +08:00
|
|
|
{
|
2021-04-09 11:07:58 +08:00
|
|
|
pend = (GIC_DIST_PENDING_SET(_gic_table[index].dist_hw_base, irq) >> (irq % 32U)) & 0x1UL;
|
2021-04-08 15:46:15 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* INTID 0-15 Software Generated Interrupt */
|
2021-04-09 11:07:58 +08:00
|
|
|
pend = (GIC_DIST_SPENDSGI(_gic_table[index].dist_hw_base, irq) >> ((irq % 4U) * 8U)) & 0xFFUL;
|
2021-04-08 15:46:15 +08:00
|
|
|
/* No CPU identification offered */
|
2021-04-09 11:07:58 +08:00
|
|
|
if (pend != 0U)
|
2021-04-08 15:46:15 +08:00
|
|
|
{
|
2021-04-09 11:07:58 +08:00
|
|
|
pend = 1U;
|
2021-04-08 15:46:15 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-04-09 11:07:58 +08:00
|
|
|
pend = 0U;
|
2021-04-08 15:46:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (pend);
|
|
|
|
}
|
|
|
|
|
|
|
|
void arm_gic_set_pending_irq(rt_uint32_t index, int irq)
|
|
|
|
{
|
|
|
|
RT_ASSERT(index < ARM_GIC_MAX_NR);
|
|
|
|
|
|
|
|
irq = irq - _gic_table[index].offset;
|
2021-04-09 11:07:58 +08:00
|
|
|
RT_ASSERT(irq >= 0U);
|
2021-04-08 15:46:15 +08:00
|
|
|
|
2021-04-09 11:07:58 +08:00
|
|
|
if (irq >= 16U)
|
2021-04-08 15:46:15 +08:00
|
|
|
{
|
2021-04-09 11:07:58 +08:00
|
|
|
GIC_DIST_PENDING_SET(_gic_table[index].dist_hw_base, irq) = 1U << (irq % 32U);
|
2021-04-08 15:46:15 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* INTID 0-15 Software Generated Interrupt */
|
|
|
|
/* Forward the interrupt to the CPU interface that requested it */
|
2021-04-09 11:07:58 +08:00
|
|
|
GIC_DIST_SOFTINT(_gic_table[index].dist_hw_base) = (irq | 0x02000000U);
|
2021-04-08 15:46:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void arm_gic_clear_pending_irq(rt_uint32_t index, int irq)
|
|
|
|
{
|
|
|
|
rt_uint32_t mask;
|
|
|
|
|
|
|
|
RT_ASSERT(index < ARM_GIC_MAX_NR);
|
|
|
|
|
|
|
|
irq = irq - _gic_table[index].offset;
|
2021-04-09 11:07:58 +08:00
|
|
|
RT_ASSERT(irq >= 0U);
|
2021-04-08 15:46:15 +08:00
|
|
|
|
2021-04-09 11:07:58 +08:00
|
|
|
if (irq >= 16U)
|
2021-04-08 15:46:15 +08:00
|
|
|
{
|
2021-04-09 11:07:58 +08:00
|
|
|
mask = 1U << (irq % 32U);
|
2021-04-08 15:46:15 +08:00
|
|
|
GIC_DIST_PENDING_CLEAR(_gic_table[index].dist_hw_base, irq) = mask;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-04-09 11:07:58 +08:00
|
|
|
mask = 1U << ((irq % 4U) * 8U);
|
2021-04-08 15:46:15 +08:00
|
|
|
GIC_DIST_CPENDSGI(_gic_table[index].dist_hw_base, irq) = mask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-17 21:16:37 +08:00
|
|
|
void arm_gic_set_configuration(rt_uint32_t index, int irq, rt_uint32_t config)
|
2021-04-08 15:46:15 +08:00
|
|
|
{
|
|
|
|
rt_uint32_t icfgr;
|
|
|
|
rt_uint32_t shift;
|
|
|
|
|
|
|
|
RT_ASSERT(index < ARM_GIC_MAX_NR);
|
|
|
|
|
|
|
|
irq = irq - _gic_table[index].offset;
|
2021-04-09 11:07:58 +08:00
|
|
|
RT_ASSERT(irq >= 0U);
|
2021-04-08 15:46:15 +08:00
|
|
|
|
|
|
|
icfgr = GIC_DIST_CONFIG(_gic_table[index].dist_hw_base, irq);
|
2021-04-09 11:07:58 +08:00
|
|
|
shift = (irq % 16U) << 1U;
|
2021-04-08 15:46:15 +08:00
|
|
|
|
2021-04-09 11:07:58 +08:00
|
|
|
icfgr &= (~(3U << shift));
|
2021-04-08 15:46:15 +08:00
|
|
|
icfgr |= (config << shift);
|
|
|
|
|
|
|
|
GIC_DIST_CONFIG(_gic_table[index].dist_hw_base, irq) = icfgr;
|
|
|
|
}
|
|
|
|
|
|
|
|
rt_uint32_t arm_gic_get_configuration(rt_uint32_t index, int irq)
|
|
|
|
{
|
|
|
|
RT_ASSERT(index < ARM_GIC_MAX_NR);
|
|
|
|
|
|
|
|
irq = irq - _gic_table[index].offset;
|
2021-04-09 11:07:58 +08:00
|
|
|
RT_ASSERT(irq >= 0U);
|
2021-04-08 15:46:15 +08:00
|
|
|
|
2021-04-09 11:07:58 +08:00
|
|
|
return (GIC_DIST_CONFIG(_gic_table[index].dist_hw_base, irq) >> ((irq % 16U) >> 1U));
|
2017-09-19 12:14:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void arm_gic_clear_active(rt_uint32_t index, int irq)
|
|
|
|
{
|
2021-04-09 11:07:58 +08:00
|
|
|
rt_uint32_t mask = 1U << (irq % 32U);
|
2017-09-19 12:14:52 +08:00
|
|
|
|
|
|
|
RT_ASSERT(index < ARM_GIC_MAX_NR);
|
|
|
|
|
|
|
|
irq = irq - _gic_table[index].offset;
|
2021-04-09 11:07:58 +08:00
|
|
|
RT_ASSERT(irq >= 0U);
|
2017-09-19 12:14:52 +08:00
|
|
|
|
|
|
|
GIC_DIST_ACTIVE_CLEAR(_gic_table[index].dist_hw_base, irq) = mask;
|
|
|
|
}
|
|
|
|
|
2019-03-25 20:03:49 +08:00
|
|
|
/* Set up the cpu mask for the specific interrupt */
|
2017-09-19 12:14:52 +08:00
|
|
|
void arm_gic_set_cpu(rt_uint32_t index, int irq, unsigned int cpumask)
|
|
|
|
{
|
|
|
|
rt_uint32_t old_tgt;
|
|
|
|
|
|
|
|
RT_ASSERT(index < ARM_GIC_MAX_NR);
|
|
|
|
|
|
|
|
irq = irq - _gic_table[index].offset;
|
2021-04-09 11:07:58 +08:00
|
|
|
RT_ASSERT(irq >= 0U);
|
2017-09-19 12:14:52 +08:00
|
|
|
|
|
|
|
old_tgt = GIC_DIST_TARGET(_gic_table[index].dist_hw_base, irq);
|
|
|
|
|
2021-04-09 11:07:58 +08:00
|
|
|
old_tgt &= ~(0x0FFUL << ((irq % 4U)*8U));
|
|
|
|
old_tgt |= cpumask << ((irq % 4U)*8U);
|
2017-09-19 12:14:52 +08:00
|
|
|
|
|
|
|
GIC_DIST_TARGET(_gic_table[index].dist_hw_base, irq) = old_tgt;
|
|
|
|
}
|
|
|
|
|
2021-04-08 15:46:15 +08:00
|
|
|
rt_uint32_t arm_gic_get_target_cpu(rt_uint32_t index, int irq)
|
2017-09-19 12:14:52 +08:00
|
|
|
{
|
2021-04-08 15:46:15 +08:00
|
|
|
RT_ASSERT(index < ARM_GIC_MAX_NR);
|
|
|
|
|
|
|
|
irq = irq - _gic_table[index].offset;
|
2021-04-09 11:07:58 +08:00
|
|
|
RT_ASSERT(irq >= 0U);
|
2021-04-08 15:46:15 +08:00
|
|
|
|
2021-04-09 11:07:58 +08:00
|
|
|
return (GIC_DIST_TARGET(_gic_table[index].dist_hw_base, irq) >> ((irq % 4U) * 8U)) & 0xFFUL;
|
2021-04-08 15:46:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void arm_gic_set_priority(rt_uint32_t index, int irq, rt_uint32_t priority)
|
|
|
|
{
|
|
|
|
rt_uint32_t mask;
|
2017-09-19 12:14:52 +08:00
|
|
|
|
|
|
|
RT_ASSERT(index < ARM_GIC_MAX_NR);
|
|
|
|
|
|
|
|
irq = irq - _gic_table[index].offset;
|
2021-04-09 11:07:58 +08:00
|
|
|
RT_ASSERT(irq >= 0U);
|
2017-09-19 12:14:52 +08:00
|
|
|
|
2021-04-08 15:46:15 +08:00
|
|
|
mask = GIC_DIST_PRI(_gic_table[index].dist_hw_base, irq);
|
2021-04-09 11:07:58 +08:00
|
|
|
mask &= ~(0xFFUL << ((irq % 4U) * 8U));
|
|
|
|
mask |= ((priority & 0xFFUL) << ((irq % 4U) * 8U));
|
2021-04-08 15:46:15 +08:00
|
|
|
GIC_DIST_PRI(_gic_table[index].dist_hw_base, irq) = mask;
|
2017-09-19 12:14:52 +08:00
|
|
|
}
|
|
|
|
|
2021-04-08 15:46:15 +08:00
|
|
|
rt_uint32_t arm_gic_get_priority(rt_uint32_t index, int irq)
|
2017-09-19 12:14:52 +08:00
|
|
|
{
|
2021-04-08 15:46:15 +08:00
|
|
|
RT_ASSERT(index < ARM_GIC_MAX_NR);
|
2017-09-19 12:14:52 +08:00
|
|
|
|
2021-04-08 15:46:15 +08:00
|
|
|
irq = irq - _gic_table[index].offset;
|
2021-04-09 11:07:58 +08:00
|
|
|
RT_ASSERT(irq >= 0U);
|
2021-04-08 15:46:15 +08:00
|
|
|
|
2021-04-09 11:07:58 +08:00
|
|
|
return (GIC_DIST_PRI(_gic_table[index].dist_hw_base, irq) >> ((irq % 4U) * 8U)) & 0xFFUL;
|
2017-09-19 12:14:52 +08:00
|
|
|
}
|
|
|
|
|
2021-04-08 15:46:15 +08:00
|
|
|
void arm_gic_set_interface_prior_mask(rt_uint32_t index, rt_uint32_t priority)
|
2017-09-19 12:14:52 +08:00
|
|
|
{
|
2021-04-08 15:46:15 +08:00
|
|
|
RT_ASSERT(index < ARM_GIC_MAX_NR);
|
2017-09-19 12:14:52 +08:00
|
|
|
|
2021-04-08 15:46:15 +08:00
|
|
|
/* set priority mask */
|
2021-04-09 11:07:58 +08:00
|
|
|
GIC_CPU_PRIMASK(_gic_table[index].cpu_hw_base) = priority & 0xFFUL;
|
2021-04-08 15:46:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
rt_uint32_t arm_gic_get_interface_prior_mask(rt_uint32_t index)
|
|
|
|
{
|
|
|
|
RT_ASSERT(index < ARM_GIC_MAX_NR);
|
|
|
|
|
|
|
|
return GIC_CPU_PRIMASK(_gic_table[index].cpu_hw_base);
|
|
|
|
}
|
|
|
|
|
|
|
|
void arm_gic_set_binary_point(rt_uint32_t index, rt_uint32_t binary_point)
|
|
|
|
{
|
2021-04-09 11:07:58 +08:00
|
|
|
GIC_CPU_BINPOINT(_gic_table[index].cpu_hw_base) = binary_point & 0x7U;
|
2021-04-08 15:46:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
rt_uint32_t arm_gic_get_binary_point(rt_uint32_t index)
|
|
|
|
{
|
|
|
|
return GIC_CPU_BINPOINT(_gic_table[index].cpu_hw_base);
|
|
|
|
}
|
|
|
|
|
|
|
|
rt_uint32_t arm_gic_get_irq_status(rt_uint32_t index, int irq)
|
|
|
|
{
|
|
|
|
rt_uint32_t pending;
|
|
|
|
rt_uint32_t active;
|
|
|
|
|
|
|
|
RT_ASSERT(index < ARM_GIC_MAX_NR);
|
|
|
|
|
|
|
|
irq = irq - _gic_table[index].offset;
|
2021-04-09 11:07:58 +08:00
|
|
|
RT_ASSERT(irq >= 0U);
|
2021-04-08 15:46:15 +08:00
|
|
|
|
2021-04-09 11:07:58 +08:00
|
|
|
active = (GIC_DIST_ACTIVE_SET(_gic_table[index].dist_hw_base, irq) >> (irq % 32U)) & 0x1UL;
|
|
|
|
pending = (GIC_DIST_PENDING_SET(_gic_table[index].dist_hw_base, irq) >> (irq % 32U)) & 0x1UL;
|
2021-04-08 15:46:15 +08:00
|
|
|
|
2021-04-09 11:07:58 +08:00
|
|
|
return ((active << 1U) | pending);
|
2021-04-08 15:46:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void arm_gic_send_sgi(rt_uint32_t index, int irq, rt_uint32_t target_list, rt_uint32_t filter_list)
|
|
|
|
{
|
|
|
|
RT_ASSERT(index < ARM_GIC_MAX_NR);
|
|
|
|
|
|
|
|
irq = irq - _gic_table[index].offset;
|
2021-04-09 11:07:58 +08:00
|
|
|
RT_ASSERT(irq >= 0U);
|
2021-04-08 15:46:15 +08:00
|
|
|
|
2021-04-09 11:07:58 +08:00
|
|
|
GIC_DIST_SOFTINT(_gic_table[index].dist_hw_base) = ((filter_list & 0x3U) << 24U) | ((target_list & 0xFFUL) << 16U) | (irq & 0x0FUL);
|
2021-04-08 15:46:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
rt_uint32_t arm_gic_get_high_pending_irq(rt_uint32_t index)
|
|
|
|
{
|
|
|
|
RT_ASSERT(index < ARM_GIC_MAX_NR);
|
|
|
|
|
|
|
|
return GIC_CPU_HIGHPRI(_gic_table[index].cpu_hw_base);
|
|
|
|
}
|
|
|
|
|
|
|
|
rt_uint32_t arm_gic_get_interface_id(rt_uint32_t index)
|
|
|
|
{
|
|
|
|
RT_ASSERT(index < ARM_GIC_MAX_NR);
|
|
|
|
|
|
|
|
return GIC_CPU_IIDR(_gic_table[index].cpu_hw_base);
|
|
|
|
}
|
|
|
|
|
|
|
|
void arm_gic_set_group(rt_uint32_t index, int irq, rt_uint32_t group)
|
|
|
|
{
|
2022-04-17 21:16:37 +08:00
|
|
|
rt_uint32_t igroupr;
|
|
|
|
rt_uint32_t shift;
|
2021-04-08 15:46:15 +08:00
|
|
|
|
|
|
|
RT_ASSERT(index < ARM_GIC_MAX_NR);
|
2021-04-09 11:07:58 +08:00
|
|
|
RT_ASSERT(group <= 1U);
|
2021-04-08 15:46:15 +08:00
|
|
|
|
|
|
|
irq = irq - _gic_table[index].offset;
|
2021-04-09 11:07:58 +08:00
|
|
|
RT_ASSERT(irq >= 0U);
|
2021-04-08 15:46:15 +08:00
|
|
|
|
|
|
|
igroupr = GIC_DIST_IGROUP(_gic_table[index].dist_hw_base, irq);
|
2021-04-09 11:07:58 +08:00
|
|
|
shift = (irq % 32U);
|
|
|
|
igroupr &= (~(1U << shift));
|
|
|
|
igroupr |= ( (group & 0x1U) << shift);
|
2021-04-08 15:46:15 +08:00
|
|
|
|
|
|
|
GIC_DIST_IGROUP(_gic_table[index].dist_hw_base, irq) = igroupr;
|
|
|
|
}
|
|
|
|
|
|
|
|
rt_uint32_t arm_gic_get_group(rt_uint32_t index, int irq)
|
|
|
|
{
|
|
|
|
RT_ASSERT(index < ARM_GIC_MAX_NR);
|
|
|
|
|
|
|
|
irq = irq - _gic_table[index].offset;
|
2021-04-09 11:07:58 +08:00
|
|
|
RT_ASSERT(irq >= 0U);
|
2021-04-08 15:46:15 +08:00
|
|
|
|
2021-04-09 11:07:58 +08:00
|
|
|
return (GIC_DIST_IGROUP(_gic_table[index].dist_hw_base, irq) >> (irq % 32U)) & 0x1UL;
|
2017-09-19 12:14:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int arm_gic_dist_init(rt_uint32_t index, rt_uint32_t dist_base, int irq_start)
|
|
|
|
{
|
|
|
|
unsigned int gic_type, i;
|
2021-04-09 11:07:58 +08:00
|
|
|
rt_uint32_t cpumask = 1U << 0U;
|
2017-09-19 12:14:52 +08:00
|
|
|
|
|
|
|
RT_ASSERT(index < ARM_GIC_MAX_NR);
|
|
|
|
|
|
|
|
_gic_table[index].dist_hw_base = dist_base;
|
|
|
|
_gic_table[index].offset = irq_start;
|
|
|
|
|
|
|
|
/* Find out how many interrupts are supported. */
|
|
|
|
gic_type = GIC_DIST_TYPE(dist_base);
|
2021-04-09 11:07:58 +08:00
|
|
|
_gic_max_irq = ((gic_type & 0x1fU) + 1U) * 32U;
|
2017-09-19 12:14:52 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The GIC only supports up to 1020 interrupt sources.
|
|
|
|
* Limit this to either the architected maximum, or the
|
|
|
|
* platform maximum.
|
|
|
|
*/
|
2021-04-09 11:07:58 +08:00
|
|
|
if (_gic_max_irq > 1020U)
|
|
|
|
_gic_max_irq = 1020U;
|
2019-03-25 20:03:49 +08:00
|
|
|
if (_gic_max_irq > ARM_GIC_NR_IRQS) /* the platform maximum interrupts */
|
2017-09-19 12:14:52 +08:00
|
|
|
_gic_max_irq = ARM_GIC_NR_IRQS;
|
|
|
|
|
2021-04-09 11:07:58 +08:00
|
|
|
cpumask |= cpumask << 8U;
|
|
|
|
cpumask |= cpumask << 16U;
|
|
|
|
cpumask |= cpumask << 24U;
|
2017-09-19 12:14:52 +08:00
|
|
|
|
2021-04-09 11:07:58 +08:00
|
|
|
GIC_DIST_CTRL(dist_base) = 0x0U;
|
2017-09-19 12:14:52 +08:00
|
|
|
|
|
|
|
/* Set all global interrupts to be level triggered, active low. */
|
2021-04-09 11:07:58 +08:00
|
|
|
for (i = 32U; i < _gic_max_irq; i += 16U)
|
|
|
|
GIC_DIST_CONFIG(dist_base, i) = 0x0U;
|
2017-09-19 12:14:52 +08:00
|
|
|
|
|
|
|
/* Set all global interrupts to this CPU only. */
|
2021-04-09 11:07:58 +08:00
|
|
|
for (i = 32U; i < _gic_max_irq; i += 4U)
|
2017-09-19 12:14:52 +08:00
|
|
|
GIC_DIST_TARGET(dist_base, i) = cpumask;
|
|
|
|
|
|
|
|
/* Set priority on all interrupts. */
|
2021-04-09 11:07:58 +08:00
|
|
|
for (i = 0U; i < _gic_max_irq; i += 4U)
|
|
|
|
GIC_DIST_PRI(dist_base, i) = 0xa0a0a0a0U;
|
2017-09-19 12:14:52 +08:00
|
|
|
|
|
|
|
/* Disable all interrupts. */
|
2021-04-09 11:07:58 +08:00
|
|
|
for (i = 0U; i < _gic_max_irq; i += 32U)
|
|
|
|
GIC_DIST_ENABLE_CLEAR(dist_base, i) = 0xffffffffU;
|
2017-09-19 12:14:52 +08:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* All interrupts defaults to IGROUP1(IRQ). */
|
|
|
|
for (i = 0; i < _gic_max_irq; i += 32)
|
|
|
|
GIC_DIST_IGROUP(dist_base, i) = 0xffffffff;
|
|
|
|
#endif
|
2021-04-09 11:07:58 +08:00
|
|
|
for (i = 0U; i < _gic_max_irq; i += 32U)
|
|
|
|
GIC_DIST_IGROUP(dist_base, i) = 0U;
|
2017-09-19 12:14:52 +08:00
|
|
|
|
|
|
|
/* Enable group0 and group1 interrupt forwarding. */
|
2021-04-09 11:07:58 +08:00
|
|
|
GIC_DIST_CTRL(dist_base) = 0x01U;
|
2017-09-19 12:14:52 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int arm_gic_cpu_init(rt_uint32_t index, rt_uint32_t cpu_base)
|
|
|
|
{
|
|
|
|
RT_ASSERT(index < ARM_GIC_MAX_NR);
|
|
|
|
|
2022-12-03 12:07:44 +08:00
|
|
|
if (!_gic_table[index].cpu_hw_base)
|
|
|
|
{
|
|
|
|
_gic_table[index].cpu_hw_base = cpu_base;
|
|
|
|
}
|
|
|
|
cpu_base = _gic_table[index].cpu_hw_base;
|
2017-09-19 12:14:52 +08:00
|
|
|
|
2021-04-09 11:07:58 +08:00
|
|
|
GIC_CPU_PRIMASK(cpu_base) = 0xf0U;
|
|
|
|
GIC_CPU_BINPOINT(cpu_base) = 0x7U;
|
2017-09-19 12:14:52 +08:00
|
|
|
/* Enable CPU interrupt */
|
2021-04-09 11:07:58 +08:00
|
|
|
GIC_CPU_CTRL(cpu_base) = 0x01U;
|
2017-09-19 12:14:52 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-04-08 15:46:15 +08:00
|
|
|
void arm_gic_dump_type(rt_uint32_t index)
|
2017-09-19 12:14:52 +08:00
|
|
|
{
|
2021-04-08 15:46:15 +08:00
|
|
|
unsigned int gic_type;
|
|
|
|
|
|
|
|
gic_type = GIC_DIST_TYPE(_gic_table[index].dist_hw_base);
|
|
|
|
rt_kprintf("GICv%d on %p, max IRQs: %d, %s security extension(%08x)\n",
|
2021-04-09 11:07:58 +08:00
|
|
|
(GIC_DIST_ICPIDR2(_gic_table[index].dist_hw_base) >> 4U) & 0xfUL,
|
2021-04-08 15:46:15 +08:00
|
|
|
_gic_table[index].dist_hw_base,
|
|
|
|
_gic_max_irq,
|
2021-04-09 11:07:58 +08:00
|
|
|
gic_type & (1U << 10U) ? "has" : "no",
|
2021-04-08 15:46:15 +08:00
|
|
|
gic_type);
|
|
|
|
}
|
2017-09-19 12:14:52 +08:00
|
|
|
|
2021-04-08 15:46:15 +08:00
|
|
|
void arm_gic_dump(rt_uint32_t index)
|
|
|
|
{
|
|
|
|
unsigned int i, k;
|
|
|
|
|
|
|
|
k = GIC_CPU_HIGHPRI(_gic_table[index].cpu_hw_base);
|
|
|
|
rt_kprintf("--- high pending priority: %d(%08x)\n", k, k);
|
|
|
|
rt_kprintf("--- hw mask ---\n");
|
2021-04-09 11:07:58 +08:00
|
|
|
for (i = 0U; i < _gic_max_irq / 32U; i++)
|
2017-09-19 12:14:52 +08:00
|
|
|
{
|
2021-04-08 15:46:15 +08:00
|
|
|
rt_kprintf("0x%08x, ",
|
|
|
|
GIC_DIST_ENABLE_SET(_gic_table[index].dist_hw_base,
|
2021-04-09 11:07:58 +08:00
|
|
|
i * 32U));
|
2017-09-19 12:14:52 +08:00
|
|
|
}
|
2021-04-08 15:46:15 +08:00
|
|
|
rt_kprintf("\n--- hw pending ---\n");
|
2021-04-09 11:07:58 +08:00
|
|
|
for (i = 0U; i < _gic_max_irq / 32U; i++)
|
2017-09-19 12:14:52 +08:00
|
|
|
{
|
2021-04-08 15:46:15 +08:00
|
|
|
rt_kprintf("0x%08x, ",
|
|
|
|
GIC_DIST_PENDING_SET(_gic_table[index].dist_hw_base,
|
2021-04-09 11:07:58 +08:00
|
|
|
i * 32U));
|
2017-09-19 12:14:52 +08:00
|
|
|
}
|
2021-04-08 15:46:15 +08:00
|
|
|
rt_kprintf("\n--- hw active ---\n");
|
2021-04-09 11:07:58 +08:00
|
|
|
for (i = 0U; i < _gic_max_irq / 32U; i++)
|
2021-04-08 15:46:15 +08:00
|
|
|
{
|
|
|
|
rt_kprintf("0x%08x, ",
|
|
|
|
GIC_DIST_ACTIVE_SET(_gic_table[index].dist_hw_base,
|
2021-04-09 11:07:58 +08:00
|
|
|
i * 32U));
|
2021-04-08 15:46:15 +08:00
|
|
|
}
|
|
|
|
rt_kprintf("\n");
|
2017-09-19 12:14:52 +08:00
|
|
|
}
|
2018-11-22 14:40:43 +08:00
|
|
|
|
2021-04-09 11:07:58 +08:00
|
|
|
long gic_dump(void)
|
|
|
|
{
|
|
|
|
arm_gic_dump_type(0);
|
|
|
|
arm_gic_dump(0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
MSH_CMD_EXPORT(gic_dump, show gic status);
|
2018-11-22 14:40:43 +08:00
|
|
|
|