2013-04-26 15:06:32 +02:00
|
|
|
/*
|
2019-02-27 15:10:53 +01:00
|
|
|
* Copyright (c) 2013, 2019 embedded brains GmbH. All rights reserved.
|
2013-04-26 15:06:32 +02:00
|
|
|
*
|
|
|
|
|
* embedded brains GmbH
|
|
|
|
|
* Dornierstr. 4
|
|
|
|
|
* 82178 Puchheim
|
|
|
|
|
* Germany
|
|
|
|
|
* <info@embedded-brains.de>
|
|
|
|
|
*
|
|
|
|
|
* The license and distribution terms for this file may be
|
|
|
|
|
* found in the file LICENSE in this distribution or at
|
2014-03-21 08:10:47 +11:00
|
|
|
* http://www.rtems.org/license/LICENSE.
|
2013-04-26 15:06:32 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <bsp/arm-gic.h>
|
|
|
|
|
|
|
|
|
|
#include <rtems/score/armv4.h>
|
|
|
|
|
|
|
|
|
|
#include <libcpu/arm-cp15.h>
|
|
|
|
|
|
|
|
|
|
#include <bsp/irq.h>
|
|
|
|
|
#include <bsp/irq-generic.h>
|
2013-05-31 13:59:47 +02:00
|
|
|
#include <bsp/start.h>
|
2013-04-26 15:06:32 +02:00
|
|
|
|
|
|
|
|
#define GIC_CPUIF ((volatile gic_cpuif *) BSP_ARM_GIC_CPUIF_BASE)
|
|
|
|
|
|
2013-08-13 14:43:54 +02:00
|
|
|
#define PRIORITY_DEFAULT 127
|
2013-04-26 15:06:32 +02:00
|
|
|
|
|
|
|
|
void bsp_interrupt_dispatch(void)
|
|
|
|
|
{
|
|
|
|
|
volatile gic_cpuif *cpuif = GIC_CPUIF;
|
|
|
|
|
uint32_t icciar = cpuif->icciar;
|
|
|
|
|
rtems_vector_number vector = GIC_CPUIF_ICCIAR_ACKINTID_GET(icciar);
|
|
|
|
|
rtems_vector_number spurious = 1023;
|
|
|
|
|
|
|
|
|
|
if (vector != spurious) {
|
|
|
|
|
uint32_t psr = _ARMV4_Status_irq_enable();
|
|
|
|
|
|
|
|
|
|
bsp_interrupt_handler_dispatch(vector);
|
|
|
|
|
|
|
|
|
|
_ARMV4_Status_restore(psr);
|
|
|
|
|
|
|
|
|
|
cpuif->icceoir = icciar;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-19 14:09:28 +02:00
|
|
|
void bsp_interrupt_vector_enable(rtems_vector_number vector)
|
2013-04-26 15:06:32 +02:00
|
|
|
{
|
2017-06-19 14:09:28 +02:00
|
|
|
volatile gic_dist *dist = ARM_GIC_DIST;
|
2013-04-26 15:06:32 +02:00
|
|
|
|
2017-06-19 14:09:28 +02:00
|
|
|
bsp_interrupt_assert(bsp_interrupt_is_valid_vector(vector));
|
2013-04-26 15:06:32 +02:00
|
|
|
|
2017-06-19 14:09:28 +02:00
|
|
|
gic_id_enable(dist, vector);
|
2013-04-26 15:06:32 +02:00
|
|
|
}
|
|
|
|
|
|
2017-06-19 14:09:28 +02:00
|
|
|
void bsp_interrupt_vector_disable(rtems_vector_number vector)
|
2013-04-26 15:06:32 +02:00
|
|
|
{
|
2017-06-19 14:09:28 +02:00
|
|
|
volatile gic_dist *dist = ARM_GIC_DIST;
|
2013-04-26 15:06:32 +02:00
|
|
|
|
2017-06-19 14:09:28 +02:00
|
|
|
bsp_interrupt_assert(bsp_interrupt_is_valid_vector(vector));
|
2013-04-26 15:06:32 +02:00
|
|
|
|
2017-06-19 14:09:28 +02:00
|
|
|
gic_id_disable(dist, vector);
|
2013-04-26 15:06:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline uint32_t get_id_count(volatile gic_dist *dist)
|
|
|
|
|
{
|
|
|
|
|
uint32_t id_count = GIC_DIST_ICDICTR_IT_LINES_NUMBER_GET(dist->icdictr);
|
|
|
|
|
|
|
|
|
|
id_count = 32 * (id_count + 1);
|
|
|
|
|
id_count = id_count <= 1020 ? id_count : 1020;
|
|
|
|
|
|
|
|
|
|
return id_count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rtems_status_code bsp_interrupt_facility_initialize(void)
|
|
|
|
|
{
|
|
|
|
|
volatile gic_cpuif *cpuif = GIC_CPUIF;
|
2013-05-31 13:59:47 +02:00
|
|
|
volatile gic_dist *dist = ARM_GIC_DIST;
|
2013-04-26 15:06:32 +02:00
|
|
|
uint32_t id_count = get_id_count(dist);
|
|
|
|
|
uint32_t id;
|
|
|
|
|
|
2013-05-31 13:59:47 +02:00
|
|
|
arm_cp15_set_exception_handler(
|
|
|
|
|
ARM_EXCEPTION_IRQ,
|
|
|
|
|
_ARMV4_Exception_interrupt
|
|
|
|
|
);
|
|
|
|
|
|
2017-10-12 07:12:12 +02:00
|
|
|
for (id = 0; id < id_count; id += 32) {
|
|
|
|
|
dist->icdicer[id / 32] = 0xffffffff;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-26 15:06:32 +02:00
|
|
|
for (id = 0; id < id_count; ++id) {
|
|
|
|
|
gic_id_set_priority(dist, id, PRIORITY_DEFAULT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (id = 32; id < id_count; ++id) {
|
|
|
|
|
gic_id_set_targets(dist, id, 0x01);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cpuif->iccpmr = GIC_CPUIF_ICCPMR_PRIORITY(0xff);
|
|
|
|
|
cpuif->iccbpr = GIC_CPUIF_ICCBPR_BINARY_POINT(0x0);
|
|
|
|
|
cpuif->iccicr = GIC_CPUIF_ICCICR_ENABLE;
|
|
|
|
|
|
|
|
|
|
dist->icddcr = GIC_DIST_ICDDCR_ENABLE;
|
|
|
|
|
|
|
|
|
|
return RTEMS_SUCCESSFUL;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-31 13:59:47 +02:00
|
|
|
#ifdef RTEMS_SMP
|
|
|
|
|
BSP_START_TEXT_SECTION void arm_gic_irq_initialize_secondary_cpu(void)
|
|
|
|
|
{
|
|
|
|
|
volatile gic_cpuif *cpuif = GIC_CPUIF;
|
|
|
|
|
volatile gic_dist *dist = ARM_GIC_DIST;
|
|
|
|
|
|
|
|
|
|
while ((dist->icddcr & GIC_DIST_ICDDCR_ENABLE) == 0) {
|
|
|
|
|
/* Wait */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cpuif->iccpmr = GIC_CPUIF_ICCPMR_PRIORITY(0xff);
|
|
|
|
|
cpuif->iccbpr = GIC_CPUIF_ICCBPR_BINARY_POINT(0x0);
|
|
|
|
|
cpuif->iccicr = GIC_CPUIF_ICCICR_ENABLE;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2013-04-26 15:06:32 +02:00
|
|
|
rtems_status_code arm_gic_irq_set_priority(
|
|
|
|
|
rtems_vector_number vector,
|
|
|
|
|
uint8_t priority
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
rtems_status_code sc = RTEMS_SUCCESSFUL;
|
|
|
|
|
|
|
|
|
|
if (bsp_interrupt_is_valid_vector(vector)) {
|
2013-05-31 13:59:47 +02:00
|
|
|
volatile gic_dist *dist = ARM_GIC_DIST;
|
2013-04-26 15:06:32 +02:00
|
|
|
|
|
|
|
|
gic_id_set_priority(dist, vector, priority);
|
|
|
|
|
} else {
|
|
|
|
|
sc = RTEMS_INVALID_ID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rtems_status_code arm_gic_irq_get_priority(
|
|
|
|
|
rtems_vector_number vector,
|
|
|
|
|
uint8_t *priority
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
rtems_status_code sc = RTEMS_SUCCESSFUL;
|
|
|
|
|
|
|
|
|
|
if (bsp_interrupt_is_valid_vector(vector)) {
|
2013-05-31 13:59:47 +02:00
|
|
|
volatile gic_dist *dist = ARM_GIC_DIST;
|
2013-04-26 15:06:32 +02:00
|
|
|
|
|
|
|
|
*priority = gic_id_get_priority(dist, vector);
|
|
|
|
|
} else {
|
|
|
|
|
sc = RTEMS_INVALID_ID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sc;
|
|
|
|
|
}
|
2016-02-18 08:36:16 +01:00
|
|
|
|
2019-02-27 15:10:53 +01:00
|
|
|
rtems_status_code arm_gic_irq_set_group(
|
|
|
|
|
rtems_vector_number vector,
|
|
|
|
|
gic_group group
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
rtems_status_code sc = RTEMS_SUCCESSFUL;
|
|
|
|
|
|
|
|
|
|
if (bsp_interrupt_is_valid_vector(vector)) {
|
|
|
|
|
volatile gic_dist *dist = ARM_GIC_DIST;
|
|
|
|
|
|
|
|
|
|
gic_id_set_group(dist, vector, group);
|
|
|
|
|
} else {
|
|
|
|
|
sc = RTEMS_INVALID_ID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rtems_status_code arm_gic_irq_get_group(
|
|
|
|
|
rtems_vector_number vector,
|
|
|
|
|
gic_group *group
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
rtems_status_code sc = RTEMS_SUCCESSFUL;
|
|
|
|
|
|
|
|
|
|
if (bsp_interrupt_is_valid_vector(vector)) {
|
|
|
|
|
volatile gic_dist *dist = ARM_GIC_DIST;
|
|
|
|
|
|
|
|
|
|
*group = gic_id_get_group(dist, vector);
|
|
|
|
|
} else {
|
|
|
|
|
sc = RTEMS_INVALID_ID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sc;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-11 11:54:30 +02:00
|
|
|
void bsp_interrupt_set_affinity(
|
2016-02-18 08:36:16 +01:00
|
|
|
rtems_vector_number vector,
|
2017-07-11 11:54:30 +02:00
|
|
|
const Processor_mask *affinity
|
2016-02-18 08:36:16 +01:00
|
|
|
)
|
|
|
|
|
{
|
2017-07-11 11:54:30 +02:00
|
|
|
volatile gic_dist *dist = ARM_GIC_DIST;
|
|
|
|
|
uint8_t targets = (uint8_t) _Processor_mask_To_uint32_t(affinity, 0);
|
2016-02-18 08:36:16 +01:00
|
|
|
|
2017-07-11 11:54:30 +02:00
|
|
|
gic_id_set_targets(dist, vector, targets);
|
|
|
|
|
}
|
2016-02-18 08:36:16 +01:00
|
|
|
|
2017-07-11 11:54:30 +02:00
|
|
|
void bsp_interrupt_get_affinity(
|
|
|
|
|
rtems_vector_number vector,
|
|
|
|
|
Processor_mask *affinity
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
volatile gic_dist *dist = ARM_GIC_DIST;
|
|
|
|
|
uint8_t targets = gic_id_get_targets(dist, vector);
|
2016-02-18 08:36:16 +01:00
|
|
|
|
2017-07-11 11:54:30 +02:00
|
|
|
_Processor_mask_From_uint32_t(affinity, targets, 0);
|
2016-02-18 08:36:16 +01:00
|
|
|
}
|