2015-04-10 16:44:37 -07:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014 Wind River Systems, Inc.
|
2022-11-19 13:36:24 +04:00
|
|
|
* Copyright (c) 2020-2022 Synopsys.
|
2015-04-10 16:44:37 -07:00
|
|
|
*
|
2017-01-18 17:01:01 -08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2015-04-10 16:44:37 -07:00
|
|
|
*/
|
|
|
|
|
2015-12-04 10:09:39 -05:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief ARCv2 Interrupt Unit device driver
|
|
|
|
*
|
2015-04-10 16:44:37 -07:00
|
|
|
* The ARCv2 interrupt unit has 16 allocated exceptions associated with
|
|
|
|
* vectors 0 to 15 and 240 interrupts associated with vectors 16 to 255.
|
|
|
|
* The interrupt unit is optional in the ARCv2-based processors. When
|
|
|
|
* building a processor, you can configure the processor to include an
|
|
|
|
* interrupt unit. The ARCv2 interrupt unit is highly programmable.
|
|
|
|
*/
|
|
|
|
|
2022-05-06 10:25:46 +02:00
|
|
|
#include <zephyr/kernel.h>
|
|
|
|
#include <zephyr/arch/cpu.h>
|
|
|
|
#include <zephyr/device.h>
|
2023-09-15 10:03:40 +00:00
|
|
|
#include <zephyr/device.h>
|
|
|
|
|
|
|
|
#define DT_DRV_COMPAT snps_arcv2_intc
|
2016-12-04 14:59:37 -06:00
|
|
|
|
2022-11-19 13:36:24 +04:00
|
|
|
#ifdef CONFIG_ARC_CONNECT
|
|
|
|
static void arc_shared_intc_init(void)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Initialize all IDU interrupts:
|
|
|
|
* - select round-robbin
|
|
|
|
* - disable all lines
|
|
|
|
*/
|
|
|
|
BUILD_ASSERT(CONFIG_NUM_IRQS > ARC_CONNECT_IDU_IRQ_START);
|
|
|
|
__ASSERT(z_arc_v2_core_id() == ARC_MP_PRIMARY_CPU_ID,
|
|
|
|
"idu interrupts must be inited from primary core");
|
|
|
|
|
|
|
|
z_arc_connect_idu_disable();
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < (CONFIG_NUM_IRQS - ARC_CONNECT_IDU_IRQ_START); i++) {
|
|
|
|
/*
|
|
|
|
* TODO: don't use z_arc_connect_idu* functions to avoid
|
|
|
|
* locking/unlocking every time.
|
|
|
|
*/
|
2023-01-24 17:36:12 +00:00
|
|
|
|
|
|
|
/* Disable (mask) line */
|
|
|
|
z_arc_connect_idu_set_mask(i, 0x1);
|
2022-11-19 13:36:24 +04:00
|
|
|
z_arc_connect_idu_set_mode(i, ARC_CONNECT_INTRPT_TRIGGER_LEVEL,
|
|
|
|
ARC_CONNECT_DISTRI_MODE_ROUND_ROBIN);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fake round-robin: we allow to distribute interrupts only to primary core as
|
|
|
|
* secondary cores may be not initialized yet.
|
|
|
|
*/
|
|
|
|
z_arc_connect_idu_set_dest(i, BIT(ARC_MP_PRIMARY_CPU_ID));
|
|
|
|
}
|
|
|
|
|
|
|
|
z_arc_connect_idu_enable();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allow to schedule IRQ to all cores after we bring up all secondary cores */
|
init: remove the need for a dummy device pointer in SYS_INIT functions
The init infrastructure, found in `init.h`, is currently used by:
- `SYS_INIT`: to call functions before `main`
- `DEVICE_*`: to initialize devices
They are all sorted according to an initialization level + a priority.
`SYS_INIT` calls are really orthogonal to devices, however, the required
function signature requires a `const struct device *dev` as a first
argument. The only reason for that is because the same init machinery is
used by devices, so we have something like:
```c
struct init_entry {
int (*init)(const struct device *dev);
/* only set by DEVICE_*, otherwise NULL */
const struct device *dev;
}
```
As a result, we end up with such weird/ugly pattern:
```c
static int my_init(const struct device *dev)
{
/* always NULL! add ARG_UNUSED to avoid compiler warning */
ARG_UNUSED(dev);
...
}
```
This is really a result of poor internals isolation. This patch proposes
a to make init entries more flexible so that they can accept sytem
initialization calls like this:
```c
static int my_init(void)
{
...
}
```
This is achieved using a union:
```c
union init_function {
/* for SYS_INIT, used when init_entry.dev == NULL */
int (*sys)(void);
/* for DEVICE*, used when init_entry.dev != NULL */
int (*dev)(const struct device *dev);
};
struct init_entry {
/* stores init function (either for SYS_INIT or DEVICE*)
union init_function init_fn;
/* stores device pointer for DEVICE*, NULL for SYS_INIT. Allows
* to know which union entry to call.
*/
const struct device *dev;
}
```
This solution **does not increase ROM usage**, and allows to offer clean
public APIs for both SYS_INIT and DEVICE*. Note that however, init
machinery keeps a coupling with devices.
**NOTE**: This is a breaking change! All `SYS_INIT` functions will need
to be converted to the new signature. See the script offered in the
following commit.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
init: convert SYS_INIT functions to the new signature
Conversion scripted using scripts/utils/migrate_sys_init.py.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
manifest: update projects for SYS_INIT changes
Update modules with updated SYS_INIT calls:
- hal_ti
- lvgl
- sof
- TraceRecorderSource
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
tests: devicetree: devices: adjust test
Adjust test according to the recently introduced SYS_INIT
infrastructure.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
tests: kernel: threads: adjust SYS_INIT call
Adjust to the new signature: int (*init_fn)(void);
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-10-19 09:33:44 +02:00
|
|
|
static int arc_shared_intc_update_post_smp(void)
|
2022-11-19 13:36:24 +04:00
|
|
|
{
|
|
|
|
__ASSERT(z_arc_v2_core_id() == ARC_MP_PRIMARY_CPU_ID,
|
|
|
|
"idu interrupts must be updated from primary core");
|
|
|
|
|
|
|
|
z_arc_connect_idu_disable();
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < (CONFIG_NUM_IRQS - ARC_CONNECT_IDU_IRQ_START); i++) {
|
|
|
|
/* TODO: take arc_connect_spinlock one time to avoid locking/unlocking every time */
|
2023-03-20 19:57:56 +00:00
|
|
|
z_arc_connect_idu_set_dest(i, BIT_MASK(arch_num_cpus()));
|
2022-11-19 13:36:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
z_arc_connect_idu_enable();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
SYS_INIT(arc_shared_intc_update_post_smp, SMP, 0);
|
|
|
|
#endif /* CONFIG_ARC_CONNECT */
|
|
|
|
|
|
|
|
|
|
|
|
/* lowest IRQ priority */
|
|
|
|
#ifdef CONFIG_ARC_SECURE_FIRMWARE
|
|
|
|
#define ARC_IRQ_DEFAULT_PRIORITY ((CONFIG_NUM_IRQ_PRIO_LEVELS - 1) | _ARC_V2_IRQ_PRIORITY_SECURE)
|
|
|
|
#else
|
|
|
|
#define ARC_IRQ_DEFAULT_PRIORITY (CONFIG_NUM_IRQ_PRIO_LEVELS - 1)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static inline void arc_core_intc_init_nolock(uint32_t irq, uint32_t state)
|
|
|
|
{
|
|
|
|
z_arc_v2_aux_reg_write(_ARC_V2_IRQ_SELECT, irq);
|
|
|
|
z_arc_v2_aux_reg_write(_ARC_V2_IRQ_PRIORITY, ARC_IRQ_DEFAULT_PRIORITY);
|
|
|
|
z_arc_v2_aux_reg_write(_ARC_V2_IRQ_TRIGGER, _ARC_V2_INT_LEVEL);
|
|
|
|
z_arc_v2_aux_reg_write(_ARC_V2_IRQ_ENABLE, state);
|
|
|
|
}
|
|
|
|
|
2016-11-15 15:19:00 +00:00
|
|
|
/*
|
2022-11-19 13:36:24 +04:00
|
|
|
* Initialize the core private interrupt controller.
|
2016-11-15 15:19:00 +00:00
|
|
|
*
|
2022-11-19 13:36:24 +04:00
|
|
|
* This function must be called on each CPU in case of SMP system.
|
2016-11-15 15:19:00 +00:00
|
|
|
*
|
2022-11-19 13:36:24 +04:00
|
|
|
* NOTE: core interrupts are still globally disabled at this point (STATUS32.IE = 0), so there is
|
|
|
|
* no need to protect the window between a write to IRQ_SELECT and subsequent writes to the
|
|
|
|
* selected IRQ's registers with locks.
|
2016-11-15 15:19:00 +00:00
|
|
|
*/
|
2022-11-19 13:36:24 +04:00
|
|
|
void arc_core_private_intc_init(void)
|
2015-04-10 16:44:37 -07:00
|
|
|
{
|
2022-11-19 13:36:24 +04:00
|
|
|
/*
|
|
|
|
* Interrupts from 0 to 15 are exceptions and they are ignored by IRQ auxiliary registers.
|
|
|
|
* We skip those interrupt lines while setting up core private interrupt controller.
|
|
|
|
*/
|
|
|
|
BUILD_ASSERT(CONFIG_GEN_IRQ_START_VECTOR == 16);
|
2015-04-10 16:44:37 -07:00
|
|
|
|
2022-11-19 13:36:24 +04:00
|
|
|
/*
|
|
|
|
* System with IDU case (most likely multi-core system):
|
|
|
|
* - disable private IRQs: they will be enabled with irq_enable before usage
|
|
|
|
* - enable shared (IDU) IRQs: their enabling / disabling is controlled via IDU, so we
|
|
|
|
* always pass them via core private interrupt controller.
|
|
|
|
* System without IDU case (single-core system):
|
|
|
|
* - disable all IRQs: they will be enabled with irq_enable before usage
|
2016-11-03 10:45:33 +00:00
|
|
|
*/
|
2022-11-19 13:36:24 +04:00
|
|
|
#ifdef CONFIG_ARC_CONNECT
|
|
|
|
for (uint32_t irq = CONFIG_GEN_IRQ_START_VECTOR; irq < ARC_CONNECT_IDU_IRQ_START; irq++) {
|
|
|
|
arc_core_intc_init_nolock(irq, _ARC_V2_INT_DISABLE);
|
|
|
|
}
|
2019-08-01 12:39:35 +08:00
|
|
|
|
2022-11-19 13:36:24 +04:00
|
|
|
for (uint32_t irq = ARC_CONNECT_IDU_IRQ_START; irq < CONFIG_NUM_IRQS; irq++) {
|
|
|
|
arc_core_intc_init_nolock(irq, _ARC_V2_INT_ENABLE);
|
|
|
|
}
|
2017-11-29 17:24:09 +08:00
|
|
|
#else
|
2022-11-19 13:36:24 +04:00
|
|
|
for (uint32_t irq = CONFIG_GEN_IRQ_START_VECTOR; irq < CONFIG_NUM_IRQS; irq++) {
|
|
|
|
arc_core_intc_init_nolock(irq, _ARC_V2_INT_DISABLE);
|
2015-04-10 16:44:37 -07:00
|
|
|
}
|
2022-11-19 13:36:24 +04:00
|
|
|
#endif /* CONFIG_ARC_CONNECT */
|
|
|
|
}
|
|
|
|
|
2023-09-15 10:03:40 +00:00
|
|
|
static int arc_irq_init(const struct device *dev)
|
2022-11-19 13:36:24 +04:00
|
|
|
{
|
|
|
|
#ifdef CONFIG_ARC_CONNECT
|
|
|
|
arc_shared_intc_init();
|
|
|
|
#endif /* CONFIG_ARC_CONNECT */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We initialize per-core part for core 0 here,
|
|
|
|
* for rest cores it will be initialized in slave_start.
|
|
|
|
*/
|
|
|
|
arc_core_private_intc_init();
|
2016-11-15 15:19:00 +00:00
|
|
|
|
|
|
|
return 0;
|
2015-04-10 16:44:37 -07:00
|
|
|
}
|
|
|
|
|
2023-09-15 10:03:40 +00:00
|
|
|
DEVICE_DT_INST_DEFINE(0, arc_irq_init, NULL, NULL, NULL,
|
|
|
|
PRE_KERNEL_1, 0, NULL);
|