18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2020 Loongson Technology Corporation Limited
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci#ifndef _ASM_IRQ_H
68c2ecf20Sopenharmony_ci#define _ASM_IRQ_H
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#include <linux/irqdomain.h>
98c2ecf20Sopenharmony_ci#include <irq.h>
108c2ecf20Sopenharmony_ci#include <asm-generic/irq.h>
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#define IRQ_STACK_SIZE			THREAD_SIZE
138c2ecf20Sopenharmony_ci#define IRQ_STACK_START			(IRQ_STACK_SIZE - 16)
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ciDECLARE_PER_CPU(unsigned long, irq_stack);
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci/*
188c2ecf20Sopenharmony_ci * The highest address on the IRQ stack contains a dummy frame put down in
198c2ecf20Sopenharmony_ci * genex.S (except_vec_vi_handler) which is structured as follows:
208c2ecf20Sopenharmony_ci *
218c2ecf20Sopenharmony_ci *   top ------------
228c2ecf20Sopenharmony_ci *       | task sp  | <- irq_stack[cpu] + IRQ_STACK_START
238c2ecf20Sopenharmony_ci *       ------------
248c2ecf20Sopenharmony_ci *       |          | <- First frame of IRQ context
258c2ecf20Sopenharmony_ci *       ------------
268c2ecf20Sopenharmony_ci *
278c2ecf20Sopenharmony_ci * task sp holds a copy of the task stack pointer where the struct pt_regs
288c2ecf20Sopenharmony_ci * from exception entry can be found.
298c2ecf20Sopenharmony_ci */
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_cistatic inline bool on_irq_stack(int cpu, unsigned long sp)
328c2ecf20Sopenharmony_ci{
338c2ecf20Sopenharmony_ci	unsigned long low = per_cpu(irq_stack, cpu);
348c2ecf20Sopenharmony_ci	unsigned long high = low + IRQ_STACK_SIZE;
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci	return (low <= sp && sp <= high);
378c2ecf20Sopenharmony_ci}
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_cistruct irq_data;
408c2ecf20Sopenharmony_cistruct device_node;
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ciint get_ipi_irq(void);
438c2ecf20Sopenharmony_ciint get_pmc_irq(void);
448c2ecf20Sopenharmony_ciint get_timer_irq(void);
458c2ecf20Sopenharmony_civoid arch_init_irq(void);
468c2ecf20Sopenharmony_civoid spurious_interrupt(void);
478c2ecf20Sopenharmony_cistruct irq_domain *loongarch_cpu_irq_init(void);
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci#define NR_IRQS_LEGACY 16
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_civoid arch_trigger_cpumask_backtrace(const struct cpumask *mask,
528c2ecf20Sopenharmony_ci					bool exclude_self);
538c2ecf20Sopenharmony_ci#define arch_trigger_cpumask_backtrace arch_trigger_cpumask_backtrace
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci#endif /* _ASM_IRQ_H */
56