mirror of
https://github.com/zephyrproject-rtos/zephyr
synced 2025-08-10 07:16:14 +00:00
The goal of this patch is to replace the 'void *' parameter by 'struct device *' if they use such variable or just 'const void *' on all relevant ISRs This will avoid not-so-nice const qualifier tweaks when device instances will be constant. Note that only the ISR passed to IRQ_CONNECT are of interest here. In order to do so, the script fix_isr.py below is necessary: from pathlib import Path import subprocess import pickle import mmap import sys import re import os cocci_template = """ @r_fix_isr_0 @ type ret_type; identifier P; identifier D; @@ -ret_type <!fn!>(void *P) +ret_type <!fn!>(const struct device *P) { ... ( const struct device *D = (const struct device *)P; | const struct device *D = P; ) ... } @r_fix_isr_1 @ type ret_type; identifier P; identifier D; @@ -ret_type <!fn!>(void *P) +ret_type <!fn!>(const struct device *P) { ... const struct device *D; ... ( D = (const struct device *)P; | D = P; ) ... } @r_fix_isr_2 @ type ret_type; identifier A; @@ -ret_type <!fn!>(void *A) +ret_type <!fn!>(const void *A) { ... } @r_fix_isr_3 @ const struct device *D; @@ -<!fn!>((void *)D); +<!fn!>(D); @r_fix_isr_4 @ type ret_type; identifier D; identifier P; @@ -ret_type <!fn!>(const struct device *P) +ret_type <!fn!>(const struct device *D) { ... ( -const struct device *D = (const struct device *)P; | -const struct device *D = P; ) ... } @r_fix_isr_5 @ type ret_type; identifier D; identifier P; @@ -ret_type <!fn!>(const struct device *P) +ret_type <!fn!>(const struct device *D) { ... -const struct device *D; ... ( -D = (const struct device *)P; | -D = P; ) ... } """ def find_isr(fn): db = [] data = None start = 0 try: with open(fn, 'r+') as f: data = str(mmap.mmap(f.fileno(), 0).read()) except Exception as e: return db while True: isr = "" irq = data.find('IRQ_CONNECT', start) while irq > -1: p = 1 arg = 1 p_o = data.find('(', irq) if p_o < 0: irq = -1 break; pos = p_o + 1 while p > 0: if data[pos] == ')': p -= 1 elif data[pos] == '(': p += 1 elif data[pos] == ',' and p == 1: arg += 1 if arg == 3: isr += data[pos] pos += 1 isr = isr.strip(',\\n\\t ') if isr not in db and len(isr) > 0: db.append(isr) start = pos break if irq < 0: break return db def patch_isr(fn, isr_list): if len(isr_list) <= 0: return for isr in isr_list: tmplt = cocci_template.replace('<!fn!>', isr) with open('/tmp/isr_fix.cocci', 'w') as f: f.write(tmplt) cmd = ['spatch', '--sp-file', '/tmp/isr_fix.cocci', '--in-place', fn] subprocess.run(cmd) def process_files(path): if path.is_file() and path.suffix in ['.h', '.c']: p = str(path.parent) + '/' + path.name isr_list = find_isr(p) patch_isr(p, isr_list) elif path.is_dir(): for p in path.iterdir(): process_files(p) if len(sys.argv) < 2: print("You need to provide a dir/file path") sys.exit(1) process_files(Path(sys.argv[1])) And is run: ./fix_isr.py <zephyr root directory> Finally, some files needed manual fixes such. Fixes #27399 Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
131 lines
2.9 KiB
C
131 lines
2.9 KiB
C
/*
|
|
* Copyright (c) 2018 - 2019 Antmicro <www.antmicro.com>
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
#define DT_DRV_COMPAT litex_eth0
|
|
|
|
#include <kernel.h>
|
|
#include <arch/cpu.h>
|
|
#include <init.h>
|
|
#include <irq.h>
|
|
#include <device.h>
|
|
#include <zephyr.h>
|
|
#include <zephyr/types.h>
|
|
|
|
#define IRQ_MASK DT_REG_ADDR_BY_NAME(DT_INST(0, vexriscv_intc0), irq_mask)
|
|
#define IRQ_PENDING DT_REG_ADDR_BY_NAME(DT_INST(0, vexriscv_intc0), irq_pending)
|
|
|
|
#define TIMER0_IRQ DT_IRQN(DT_INST(0, litex_timer0))
|
|
#define UART0_IRQ DT_IRQN(DT_INST(0, litex_uart0))
|
|
|
|
#define ETH0_IRQ DT_IRQN(DT_INST(0, litex_eth0))
|
|
|
|
#define I2S_RX_IRQ DT_IRQN(DT_NODELABEL(i2s_rx))
|
|
#define I2S_TX_IRQ DT_IRQN(DT_NODELABEL(i2s_tx))
|
|
static inline void vexriscv_litex_irq_setmask(uint32_t mask)
|
|
{
|
|
__asm__ volatile ("csrw %0, %1" :: "i"(IRQ_MASK), "r"(mask));
|
|
}
|
|
|
|
static inline uint32_t vexriscv_litex_irq_getmask(void)
|
|
{
|
|
uint32_t mask;
|
|
|
|
__asm__ volatile ("csrr %0, %1" : "=r"(mask) : "i"(IRQ_MASK));
|
|
return mask;
|
|
}
|
|
|
|
static inline uint32_t vexriscv_litex_irq_pending(void)
|
|
{
|
|
uint32_t pending;
|
|
|
|
__asm__ volatile ("csrr %0, %1" : "=r"(pending) : "i"(IRQ_PENDING));
|
|
return pending;
|
|
}
|
|
|
|
static inline void vexriscv_litex_irq_setie(uint32_t ie)
|
|
{
|
|
if (ie) {
|
|
__asm__ volatile ("csrrs x0, mstatus, %0"
|
|
:: "r"(MSTATUS_IEN));
|
|
} else {
|
|
__asm__ volatile ("csrrc x0, mstatus, %0"
|
|
:: "r"(MSTATUS_IEN));
|
|
}
|
|
}
|
|
|
|
static void vexriscv_litex_irq_handler(const void *device)
|
|
{
|
|
struct _isr_table_entry *ite;
|
|
uint32_t pending, mask, irqs;
|
|
|
|
pending = vexriscv_litex_irq_pending();
|
|
mask = vexriscv_litex_irq_getmask();
|
|
irqs = pending & mask;
|
|
|
|
#ifdef CONFIG_LITEX_TIMER
|
|
if (irqs & (1 << TIMER0_IRQ)) {
|
|
ite = &_sw_isr_table[TIMER0_IRQ];
|
|
ite->isr(ite->arg);
|
|
}
|
|
#endif
|
|
|
|
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
|
if (irqs & (1 << UART0_IRQ)) {
|
|
ite = &_sw_isr_table[UART0_IRQ];
|
|
ite->isr(ite->arg);
|
|
}
|
|
#endif
|
|
|
|
#ifdef CONFIG_ETH_LITEETH
|
|
if (irqs & (1 << ETH0_IRQ)) {
|
|
ite = &_sw_isr_table[ETH0_IRQ];
|
|
ite->isr(ite->arg);
|
|
}
|
|
#endif
|
|
|
|
#ifdef CONFIG_I2S
|
|
if (irqs & (1 << I2S_RX_IRQ)) {
|
|
ite = &_sw_isr_table[I2S_RX_IRQ];
|
|
ite->isr(ite->arg);
|
|
}
|
|
if (irqs & (1 << I2S_TX_IRQ)) {
|
|
ite = &_sw_isr_table[I2S_TX_IRQ];
|
|
ite->isr(ite->arg);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
void arch_irq_enable(unsigned int irq)
|
|
{
|
|
vexriscv_litex_irq_setmask(vexriscv_litex_irq_getmask() | (1 << irq));
|
|
}
|
|
|
|
void arch_irq_disable(unsigned int irq)
|
|
{
|
|
vexriscv_litex_irq_setmask(vexriscv_litex_irq_getmask() & ~(1 << irq));
|
|
}
|
|
|
|
int arch_irq_is_enabled(unsigned int irq)
|
|
{
|
|
return vexriscv_litex_irq_getmask() & (1 << irq);
|
|
}
|
|
|
|
static int vexriscv_litex_irq_init(const struct device *dev)
|
|
{
|
|
ARG_UNUSED(dev);
|
|
__asm__ volatile ("csrrs x0, mie, %0"
|
|
:: "r"((1 << RISCV_MACHINE_TIMER_IRQ)
|
|
| (1 << RISCV_MACHINE_EXT_IRQ)));
|
|
vexriscv_litex_irq_setie(1);
|
|
IRQ_CONNECT(RISCV_MACHINE_EXT_IRQ, 0, vexriscv_litex_irq_handler,
|
|
NULL, 0);
|
|
|
|
return 0;
|
|
}
|
|
|
|
SYS_INIT(vexriscv_litex_irq_init, PRE_KERNEL_2,
|
|
CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
|