162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
462306a36Sopenharmony_ci */
562306a36Sopenharmony_ci#ifndef _ASM_IRQ_H
662306a36Sopenharmony_ci#define _ASM_IRQ_H
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#include <linux/irqdomain.h>
962306a36Sopenharmony_ci#include <linux/irqreturn.h>
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#define IRQ_STACK_SIZE			THREAD_SIZE
1262306a36Sopenharmony_ci#define IRQ_STACK_START			(IRQ_STACK_SIZE - 16)
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ciDECLARE_PER_CPU(unsigned long, irq_stack);
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci/*
1762306a36Sopenharmony_ci * The highest address on the IRQ stack contains a dummy frame which is
1862306a36Sopenharmony_ci * structured as follows:
1962306a36Sopenharmony_ci *
2062306a36Sopenharmony_ci *   top ------------
2162306a36Sopenharmony_ci *       | task sp  | <- irq_stack[cpu] + IRQ_STACK_START
2262306a36Sopenharmony_ci *       ------------
2362306a36Sopenharmony_ci *       |          | <- First frame of IRQ context
2462306a36Sopenharmony_ci *       ------------
2562306a36Sopenharmony_ci *
2662306a36Sopenharmony_ci * task sp holds a copy of the task stack pointer where the struct pt_regs
2762306a36Sopenharmony_ci * from exception entry can be found.
2862306a36Sopenharmony_ci */
2962306a36Sopenharmony_ci
3062306a36Sopenharmony_cistatic inline bool on_irq_stack(int cpu, unsigned long sp)
3162306a36Sopenharmony_ci{
3262306a36Sopenharmony_ci	unsigned long low = per_cpu(irq_stack, cpu);
3362306a36Sopenharmony_ci	unsigned long high = low + IRQ_STACK_SIZE;
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci	return (low <= sp && sp <= high);
3662306a36Sopenharmony_ci}
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_civoid spurious_interrupt(void);
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_ci#define NR_IRQS_LEGACY 16
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci#define arch_trigger_cpumask_backtrace arch_trigger_cpumask_backtrace
4362306a36Sopenharmony_civoid arch_trigger_cpumask_backtrace(const struct cpumask *mask, int exclude_cpu);
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ci#define MAX_IO_PICS 2
4662306a36Sopenharmony_ci#define NR_IRQS	(64 + (256 * MAX_IO_PICS))
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_cistruct acpi_vector_group {
4962306a36Sopenharmony_ci	int node;
5062306a36Sopenharmony_ci	int pci_segment;
5162306a36Sopenharmony_ci	struct irq_domain *parent;
5262306a36Sopenharmony_ci};
5362306a36Sopenharmony_ciextern struct acpi_vector_group pch_group[MAX_IO_PICS];
5462306a36Sopenharmony_ciextern struct acpi_vector_group msi_group[MAX_IO_PICS];
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_ci#define CORES_PER_EIO_NODE	4
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci#define LOONGSON_CPU_UART0_VEC		10 /* CPU UART0 */
5962306a36Sopenharmony_ci#define LOONGSON_CPU_THSENS_VEC		14 /* CPU Thsens */
6062306a36Sopenharmony_ci#define LOONGSON_CPU_HT0_VEC		16 /* CPU HT0 irq vector base number */
6162306a36Sopenharmony_ci#define LOONGSON_CPU_HT1_VEC		24 /* CPU HT1 irq vector base number */
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ci/* IRQ number definitions */
6462306a36Sopenharmony_ci#define LOONGSON_LPC_IRQ_BASE		0
6562306a36Sopenharmony_ci#define LOONGSON_LPC_LAST_IRQ		(LOONGSON_LPC_IRQ_BASE + 15)
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ci#define LOONGSON_CPU_IRQ_BASE		16
6862306a36Sopenharmony_ci#define LOONGSON_CPU_LAST_IRQ		(LOONGSON_CPU_IRQ_BASE + 14)
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_ci#define LOONGSON_PCH_IRQ_BASE		64
7162306a36Sopenharmony_ci#define LOONGSON_PCH_ACPI_IRQ		(LOONGSON_PCH_IRQ_BASE + 47)
7262306a36Sopenharmony_ci#define LOONGSON_PCH_LAST_IRQ		(LOONGSON_PCH_IRQ_BASE + 64 - 1)
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ci#define LOONGSON_MSI_IRQ_BASE		(LOONGSON_PCH_IRQ_BASE + 64)
7562306a36Sopenharmony_ci#define LOONGSON_MSI_LAST_IRQ		(LOONGSON_PCH_IRQ_BASE + 256 - 1)
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_ci#define GSI_MIN_LPC_IRQ		LOONGSON_LPC_IRQ_BASE
7862306a36Sopenharmony_ci#define GSI_MAX_LPC_IRQ		(LOONGSON_LPC_IRQ_BASE + 16 - 1)
7962306a36Sopenharmony_ci#define GSI_MIN_CPU_IRQ		LOONGSON_CPU_IRQ_BASE
8062306a36Sopenharmony_ci#define GSI_MAX_CPU_IRQ		(LOONGSON_CPU_IRQ_BASE + 48 - 1)
8162306a36Sopenharmony_ci#define GSI_MIN_PCH_IRQ		LOONGSON_PCH_IRQ_BASE
8262306a36Sopenharmony_ci#define GSI_MAX_PCH_IRQ		(LOONGSON_PCH_IRQ_BASE + 256 - 1)
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_cistruct acpi_madt_lio_pic;
8562306a36Sopenharmony_cistruct acpi_madt_eio_pic;
8662306a36Sopenharmony_cistruct acpi_madt_ht_pic;
8762306a36Sopenharmony_cistruct acpi_madt_bio_pic;
8862306a36Sopenharmony_cistruct acpi_madt_msi_pic;
8962306a36Sopenharmony_cistruct acpi_madt_lpc_pic;
9062306a36Sopenharmony_ci
9162306a36Sopenharmony_ciint liointc_acpi_init(struct irq_domain *parent,
9262306a36Sopenharmony_ci					struct acpi_madt_lio_pic *acpi_liointc);
9362306a36Sopenharmony_ciint eiointc_acpi_init(struct irq_domain *parent,
9462306a36Sopenharmony_ci					struct acpi_madt_eio_pic *acpi_eiointc);
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_ciint htvec_acpi_init(struct irq_domain *parent,
9762306a36Sopenharmony_ci					struct acpi_madt_ht_pic *acpi_htvec);
9862306a36Sopenharmony_ciint pch_lpc_acpi_init(struct irq_domain *parent,
9962306a36Sopenharmony_ci					struct acpi_madt_lpc_pic *acpi_pchlpc);
10062306a36Sopenharmony_ciint pch_msi_acpi_init(struct irq_domain *parent,
10162306a36Sopenharmony_ci					struct acpi_madt_msi_pic *acpi_pchmsi);
10262306a36Sopenharmony_ciint pch_pic_acpi_init(struct irq_domain *parent,
10362306a36Sopenharmony_ci					struct acpi_madt_bio_pic *acpi_pchpic);
10462306a36Sopenharmony_ciint find_pch_pic(u32 gsi);
10562306a36Sopenharmony_cistruct fwnode_handle *get_pch_msi_handle(int pci_segment);
10662306a36Sopenharmony_ci
10762306a36Sopenharmony_ciextern struct acpi_madt_lio_pic *acpi_liointc;
10862306a36Sopenharmony_ciextern struct acpi_madt_eio_pic *acpi_eiointc[MAX_IO_PICS];
10962306a36Sopenharmony_ci
11062306a36Sopenharmony_ciextern struct acpi_madt_ht_pic *acpi_htintc;
11162306a36Sopenharmony_ciextern struct acpi_madt_lpc_pic *acpi_pchlpc;
11262306a36Sopenharmony_ciextern struct acpi_madt_msi_pic *acpi_pchmsi[MAX_IO_PICS];
11362306a36Sopenharmony_ciextern struct acpi_madt_bio_pic *acpi_pchpic[MAX_IO_PICS];
11462306a36Sopenharmony_ci
11562306a36Sopenharmony_ciextern struct fwnode_handle *cpuintc_handle;
11662306a36Sopenharmony_ciextern struct fwnode_handle *liointc_handle;
11762306a36Sopenharmony_ciextern struct fwnode_handle *pch_lpc_handle;
11862306a36Sopenharmony_ciextern struct fwnode_handle *pch_pic_handle[MAX_IO_PICS];
11962306a36Sopenharmony_ci
12062306a36Sopenharmony_ciextern irqreturn_t loongson_ipi_interrupt(int irq, void *dev);
12162306a36Sopenharmony_ci
12262306a36Sopenharmony_ci#include <asm-generic/irq.h>
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_ci#endif /* _ASM_IRQ_H */
125