Skip to content

Commit f4cc33e

Browse files
lyctwKAGA-KOKO
authored andcommitted
irqchip/riscv-intc: Introduce Andes hart-level interrupt controller
Add support for the Andes hart-level interrupt controller. This controller provides interrupt mask/unmask functions to access the custom register (SLIE) where the non-standard S-mode local interrupt enable bits are located. The base of custom interrupt number is set to 256. To share the riscv_intc_domain_map() with the generic RISC-V INTC and ACPI, add a chip parameter to riscv_intc_init_common(), so it can be passed to the irq_domain_set_info() as a private data. Andes hart-level interrupt controller requires the "andestech,cpu-intc" compatible string to be present in interrupt-controller of cpu node to enable the use of custom local interrupt source. e.g., cpu0: cpu@0 { compatible = "andestech,ax45mp", "riscv"; ... cpu0-intc: interrupt-controller { #interrupt-cells = <0x01>; compatible = "andestech,cpu-intc", "riscv,cpu-intc"; interrupt-controller; }; }; Signed-off-by: Yu Chien Peter Lin <peterlin@andestech.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Randolph <randolph@andestech.com> Reviewed-by: Anup Patel <anup@brainfault.org> Link: https://lore.kernel.org/r/20240222083946.3977135-4-peterlin@andestech.com
1 parent 96303bc commit f4cc33e

File tree

2 files changed

+69
-7
lines changed

2 files changed

+69
-7
lines changed

drivers/irqchip/irq-riscv-intc.c

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/module.h>
1818
#include <linux/of.h>
1919
#include <linux/smp.h>
20+
#include <linux/soc/andes/irq.h>
2021

2122
static struct irq_domain *intc_domain;
2223
static unsigned int riscv_intc_nr_irqs __ro_after_init = BITS_PER_LONG;
@@ -48,6 +49,31 @@ static void riscv_intc_irq_unmask(struct irq_data *d)
4849
csr_set(CSR_IE, BIT(d->hwirq));
4950
}
5051

52+
static void andes_intc_irq_mask(struct irq_data *d)
53+
{
54+
/*
55+
* Andes specific S-mode local interrupt causes (hwirq)
56+
* are defined as (256 + n) and controlled by n-th bit
57+
* of SLIE.
58+
*/
59+
unsigned int mask = BIT(d->hwirq % BITS_PER_LONG);
60+
61+
if (d->hwirq < ANDES_SLI_CAUSE_BASE)
62+
csr_clear(CSR_IE, mask);
63+
else
64+
csr_clear(ANDES_CSR_SLIE, mask);
65+
}
66+
67+
static void andes_intc_irq_unmask(struct irq_data *d)
68+
{
69+
unsigned int mask = BIT(d->hwirq % BITS_PER_LONG);
70+
71+
if (d->hwirq < ANDES_SLI_CAUSE_BASE)
72+
csr_set(CSR_IE, mask);
73+
else
74+
csr_set(ANDES_CSR_SLIE, mask);
75+
}
76+
5177
static void riscv_intc_irq_eoi(struct irq_data *d)
5278
{
5379
/*
@@ -71,12 +97,21 @@ static struct irq_chip riscv_intc_chip = {
7197
.irq_eoi = riscv_intc_irq_eoi,
7298
};
7399

100+
static struct irq_chip andes_intc_chip = {
101+
.name = "RISC-V INTC",
102+
.irq_mask = andes_intc_irq_mask,
103+
.irq_unmask = andes_intc_irq_unmask,
104+
.irq_eoi = riscv_intc_irq_eoi,
105+
};
106+
74107
static int riscv_intc_domain_map(struct irq_domain *d, unsigned int irq,
75108
irq_hw_number_t hwirq)
76109
{
110+
struct irq_chip *chip = d->host_data;
111+
77112
irq_set_percpu_devid(irq);
78-
irq_domain_set_info(d, irq, hwirq, &riscv_intc_chip, d->host_data,
79-
handle_percpu_devid_irq, NULL, NULL);
113+
irq_domain_set_info(d, irq, hwirq, chip, NULL, handle_percpu_devid_irq,
114+
NULL, NULL);
80115

81116
return 0;
82117
}
@@ -122,11 +157,12 @@ static struct fwnode_handle *riscv_intc_hwnode(void)
122157
return intc_domain->fwnode;
123158
}
124159

125-
static int __init riscv_intc_init_common(struct fwnode_handle *fn)
160+
static int __init riscv_intc_init_common(struct fwnode_handle *fn,
161+
struct irq_chip *chip)
126162
{
127163
int rc;
128164

129-
intc_domain = irq_domain_create_tree(fn, &riscv_intc_domain_ops, NULL);
165+
intc_domain = irq_domain_create_tree(fn, &riscv_intc_domain_ops, chip);
130166
if (!intc_domain) {
131167
pr_err("unable to add IRQ domain\n");
132168
return -ENXIO;
@@ -152,8 +188,9 @@ static int __init riscv_intc_init_common(struct fwnode_handle *fn)
152188
static int __init riscv_intc_init(struct device_node *node,
153189
struct device_node *parent)
154190
{
155-
int rc;
191+
struct irq_chip *chip = &riscv_intc_chip;
156192
unsigned long hartid;
193+
int rc;
157194

158195
rc = riscv_of_parent_hartid(node, &hartid);
159196
if (rc < 0) {
@@ -178,10 +215,17 @@ static int __init riscv_intc_init(struct device_node *node,
178215
return 0;
179216
}
180217

181-
return riscv_intc_init_common(of_node_to_fwnode(node));
218+
if (of_device_is_compatible(node, "andestech,cpu-intc")) {
219+
riscv_intc_custom_base = ANDES_SLI_CAUSE_BASE;
220+
riscv_intc_custom_nr_irqs = ANDES_RV_IRQ_LAST;
221+
chip = &andes_intc_chip;
222+
}
223+
224+
return riscv_intc_init_common(of_node_to_fwnode(node), chip);
182225
}
183226

184227
IRQCHIP_DECLARE(riscv, "riscv,cpu-intc", riscv_intc_init);
228+
IRQCHIP_DECLARE(andes, "andestech,cpu-intc", riscv_intc_init);
185229

186230
#ifdef CONFIG_ACPI
187231

@@ -208,7 +252,7 @@ static int __init riscv_intc_acpi_init(union acpi_subtable_headers *header,
208252
return -ENOMEM;
209253
}
210254

211-
return riscv_intc_init_common(fn);
255+
return riscv_intc_init_common(fn, &riscv_intc_chip);
212256
}
213257

214258
IRQCHIP_ACPI_DECLARE(riscv_intc, ACPI_MADT_TYPE_RINTC, NULL,

include/linux/soc/andes/irq.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/*
3+
* Copyright (C) 2023 Andes Technology Corporation
4+
*/
5+
#ifndef __ANDES_IRQ_H
6+
#define __ANDES_IRQ_H
7+
8+
/* Andes PMU irq number */
9+
#define ANDES_RV_IRQ_PMOVI 18
10+
#define ANDES_RV_IRQ_LAST ANDES_RV_IRQ_PMOVI
11+
#define ANDES_SLI_CAUSE_BASE 256
12+
13+
/* Andes PMU related registers */
14+
#define ANDES_CSR_SLIE 0x9c4
15+
#define ANDES_CSR_SLIP 0x9c5
16+
#define ANDES_CSR_SCOUNTEROF 0x9d4
17+
18+
#endif /* __ANDES_IRQ_H */

0 commit comments

Comments
 (0)