Skip to content

Commit 0858ed0

Browse files
chenhuacaiMarc Zyngier
authored andcommitted
irqchip/loongson-liointc: Add ACPI init support
LIOINTC stands for "Legacy I/O Interrupts" that described in Section 11.1 of "Loongson 3A5000 Processor Reference Manual". For more information please refer Documentation/loongarch/irq-chip-model.rst. Co-developed-by: Jianmin Lv <lvjianmin@loongson.cn> Signed-off-by: Jianmin Lv <lvjianmin@loongson.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn> Signed-off-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/1658314292-35346-11-git-send-email-lvjianmin@loongson.cn
1 parent 0230873 commit 0858ed0

File tree

4 files changed

+131
-78
lines changed

4 files changed

+131
-78
lines changed

arch/loongarch/include/asm/irq.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ struct acpi_madt_lpc_pic;
105105

106106
struct irq_domain *loongarch_cpu_irq_init(void);
107107

108-
struct irq_domain *liointc_acpi_init(struct irq_domain *parent,
108+
int liointc_acpi_init(struct irq_domain *parent,
109109
struct acpi_madt_lio_pic *acpi_liointc);
110110
struct irq_domain *eiointc_acpi_init(struct irq_domain *parent,
111111
struct acpi_madt_eio_pic *acpi_eiointc);
@@ -138,7 +138,7 @@ extern struct acpi_madt_msi_pic *acpi_pchmsi[MAX_IO_PICS];
138138
extern struct acpi_madt_bio_pic *acpi_pchpic[MAX_IO_PICS];
139139

140140
extern struct irq_domain *cpu_domain;
141-
extern struct irq_domain *liointc_domain;
141+
extern struct fwnode_handle *liointc_handle;
142142
extern struct fwnode_handle *pch_lpc_handle;
143143
extern struct fwnode_handle *pch_pic_handle[MAX_IO_PICS];
144144

arch/loongarch/kernel/irq.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ DEFINE_PER_CPU_SHARED_ALIGNED(irq_cpustat_t, irq_stat);
2626
EXPORT_PER_CPU_SYMBOL(irq_stat);
2727

2828
struct irq_domain *cpu_domain;
29-
struct irq_domain *liointc_domain;
3029

3130
struct acpi_vector_group pch_group[MAX_IO_PICS];
3231
struct acpi_vector_group msi_group[MAX_IO_PICS];

arch/mips/include/asm/mach-loongson64/irq.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#define NR_IRQS (NR_IRQS_LEGACY + NR_MIPS_CPU_IRQS + NR_MAX_CHAINED_IRQS + 256)
1010
#define MAX_IO_PICS 1
1111
#define MIPS_CPU_IRQ_BASE NR_IRQS_LEGACY
12+
#define GSI_MIN_CPU_IRQ 0
1213

1314
#include <asm/mach-generic/irq.h>
1415

drivers/irqchip/irq-loongson-liointc.c

Lines changed: 128 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#endif
2424

2525
#define LIOINTC_CHIP_IRQ 32
26-
#define LIOINTC_NUM_PARENT 4
26+
#define LIOINTC_NUM_PARENT 4
2727
#define LIOINTC_NUM_CORES 4
2828

2929
#define LIOINTC_INTC_CHIP_START 0x20
@@ -58,6 +58,8 @@ struct liointc_priv {
5858
bool has_lpc_irq_errata;
5959
};
6060

61+
struct fwnode_handle *liointc_handle;
62+
6163
static void liointc_chained_handle_irq(struct irq_desc *desc)
6264
{
6365
struct liointc_handler_data *handler = irq_desc_get_handler_data(desc);
@@ -153,97 +155,79 @@ static void liointc_resume(struct irq_chip_generic *gc)
153155
irq_gc_unlock_irqrestore(gc, flags);
154156
}
155157

156-
static const char * const parent_names[] = {"int0", "int1", "int2", "int3"};
157-
static const char * const core_reg_names[] = {"isr0", "isr1", "isr2", "isr3"};
158+
static int parent_irq[LIOINTC_NUM_PARENT];
159+
static u32 parent_int_map[LIOINTC_NUM_PARENT];
160+
static const char *const parent_names[] = {"int0", "int1", "int2", "int3"};
161+
static const char *const core_reg_names[] = {"isr0", "isr1", "isr2", "isr3"};
158162

159-
static void __iomem *liointc_get_reg_byname(struct device_node *node,
160-
const char *name)
163+
static int liointc_domain_xlate(struct irq_domain *d, struct device_node *ctrlr,
164+
const u32 *intspec, unsigned int intsize,
165+
unsigned long *out_hwirq, unsigned int *out_type)
161166
{
162-
int index = of_property_match_string(node, "reg-names", name);
163-
164-
if (index < 0)
165-
return NULL;
166-
167-
return of_iomap(node, index);
167+
if (WARN_ON(intsize < 1))
168+
return -EINVAL;
169+
*out_hwirq = intspec[0] - GSI_MIN_CPU_IRQ;
170+
*out_type = IRQ_TYPE_NONE;
171+
return 0;
168172
}
169173

170-
static int __init liointc_of_init(struct device_node *node,
171-
struct device_node *parent)
174+
static const struct irq_domain_ops acpi_irq_gc_ops = {
175+
.map = irq_map_generic_chip,
176+
.unmap = irq_unmap_generic_chip,
177+
.xlate = liointc_domain_xlate,
178+
};
179+
180+
static int liointc_init(phys_addr_t addr, unsigned long size, int revision,
181+
struct fwnode_handle *domain_handle, struct device_node *node)
172182
{
183+
int i, err;
184+
void __iomem *base;
185+
struct irq_chip_type *ct;
173186
struct irq_chip_generic *gc;
174187
struct irq_domain *domain;
175-
struct irq_chip_type *ct;
176188
struct liointc_priv *priv;
177-
void __iomem *base;
178-
u32 of_parent_int_map[LIOINTC_NUM_PARENT];
179-
int parent_irq[LIOINTC_NUM_PARENT];
180-
bool have_parent = FALSE;
181-
int sz, i, err = 0;
182189

183190
priv = kzalloc(sizeof(*priv), GFP_KERNEL);
184191
if (!priv)
185192
return -ENOMEM;
186193

187-
if (of_device_is_compatible(node, "loongson,liointc-2.0")) {
188-
base = liointc_get_reg_byname(node, "main");
189-
if (!base) {
190-
err = -ENODEV;
191-
goto out_free_priv;
192-
}
194+
base = ioremap(addr, size);
195+
if (!base)
196+
goto out_free_priv;
193197

194-
for (i = 0; i < LIOINTC_NUM_CORES; i++)
195-
priv->core_isr[i] = liointc_get_reg_byname(node, core_reg_names[i]);
196-
if (!priv->core_isr[0]) {
197-
err = -ENODEV;
198-
goto out_iounmap_base;
199-
}
200-
} else {
201-
base = of_iomap(node, 0);
202-
if (!base) {
203-
err = -ENODEV;
204-
goto out_free_priv;
205-
}
198+
for (i = 0; i < LIOINTC_NUM_CORES; i++)
199+
priv->core_isr[i] = base + LIOINTC_REG_INTC_STATUS;
206200

207-
for (i = 0; i < LIOINTC_NUM_CORES; i++)
208-
priv->core_isr[i] = base + LIOINTC_REG_INTC_STATUS;
209-
}
201+
for (i = 0; i < LIOINTC_NUM_PARENT; i++)
202+
priv->handler[i].parent_int_map = parent_int_map[i];
210203

211-
for (i = 0; i < LIOINTC_NUM_PARENT; i++) {
212-
parent_irq[i] = of_irq_get_byname(node, parent_names[i]);
213-
if (parent_irq[i] > 0)
214-
have_parent = TRUE;
215-
}
216-
if (!have_parent) {
217-
err = -ENODEV;
218-
goto out_iounmap_isr;
219-
}
204+
if (revision > 1) {
205+
for (i = 0; i < LIOINTC_NUM_CORES; i++) {
206+
int index = of_property_match_string(node,
207+
"reg-names", core_reg_names[i]);
220208

221-
sz = of_property_read_variable_u32_array(node,
222-
"loongson,parent_int_map",
223-
&of_parent_int_map[0],
224-
LIOINTC_NUM_PARENT,
225-
LIOINTC_NUM_PARENT);
226-
if (sz < 4) {
227-
pr_err("loongson-liointc: No parent_int_map\n");
228-
err = -ENODEV;
229-
goto out_iounmap_isr;
230-
}
209+
if (index < 0)
210+
return -EINVAL;
231211

232-
for (i = 0; i < LIOINTC_NUM_PARENT; i++)
233-
priv->handler[i].parent_int_map = of_parent_int_map[i];
212+
priv->core_isr[i] = of_iomap(node, index);
213+
}
214+
}
234215

235216
/* Setup IRQ domain */
236-
domain = irq_domain_add_linear(node, 32,
217+
if (!acpi_disabled)
218+
domain = irq_domain_create_linear(domain_handle, LIOINTC_CHIP_IRQ,
219+
&acpi_irq_gc_ops, priv);
220+
else
221+
domain = irq_domain_create_linear(domain_handle, LIOINTC_CHIP_IRQ,
237222
&irq_generic_chip_ops, priv);
238223
if (!domain) {
239224
pr_err("loongson-liointc: cannot add IRQ domain\n");
240-
err = -EINVAL;
241-
goto out_iounmap_isr;
225+
goto out_iounmap;
242226
}
243227

244-
err = irq_alloc_domain_generic_chips(domain, 32, 1,
245-
node->full_name, handle_level_irq,
246-
IRQ_NOPROBE, 0, 0);
228+
err = irq_alloc_domain_generic_chips(domain, LIOINTC_CHIP_IRQ, 1,
229+
(node ? node->full_name : "LIOINTC"),
230+
handle_level_irq, 0, IRQ_NOPROBE, 0);
247231
if (err) {
248232
pr_err("loongson-liointc: unable to register IRQ domain\n");
249233
goto out_free_domain;
@@ -299,24 +283,93 @@ static int __init liointc_of_init(struct device_node *node,
299283
liointc_chained_handle_irq, &priv->handler[i]);
300284
}
301285

286+
liointc_handle = domain_handle;
302287
return 0;
303288

304289
out_free_domain:
305290
irq_domain_remove(domain);
306-
out_iounmap_isr:
307-
for (i = 0; i < LIOINTC_NUM_CORES; i++) {
308-
if (!priv->core_isr[i])
309-
continue;
310-
iounmap(priv->core_isr[i]);
311-
}
312-
out_iounmap_base:
291+
out_iounmap:
313292
iounmap(base);
314293
out_free_priv:
315294
kfree(priv);
316295

317-
return err;
296+
return -EINVAL;
297+
}
298+
299+
#ifdef CONFIG_OF
300+
301+
static int __init liointc_of_init(struct device_node *node,
302+
struct device_node *parent)
303+
{
304+
bool have_parent = FALSE;
305+
int sz, i, index, revision, err = 0;
306+
struct resource res;
307+
308+
if (!of_device_is_compatible(node, "loongson,liointc-2.0")) {
309+
index = 0;
310+
revision = 1;
311+
} else {
312+
index = of_property_match_string(node, "reg-names", "main");
313+
revision = 2;
314+
}
315+
316+
if (of_address_to_resource(node, index, &res))
317+
return -EINVAL;
318+
319+
for (i = 0; i < LIOINTC_NUM_PARENT; i++) {
320+
parent_irq[i] = of_irq_get_byname(node, parent_names[i]);
321+
if (parent_irq[i] > 0)
322+
have_parent = TRUE;
323+
}
324+
if (!have_parent)
325+
return -ENODEV;
326+
327+
sz = of_property_read_variable_u32_array(node,
328+
"loongson,parent_int_map",
329+
&parent_int_map[0],
330+
LIOINTC_NUM_PARENT,
331+
LIOINTC_NUM_PARENT);
332+
if (sz < 4) {
333+
pr_err("loongson-liointc: No parent_int_map\n");
334+
return -ENODEV;
335+
}
336+
337+
err = liointc_init(res.start, resource_size(&res),
338+
revision, of_node_to_fwnode(node), node);
339+
if (err < 0)
340+
return err;
341+
342+
return 0;
318343
}
319344

320345
IRQCHIP_DECLARE(loongson_liointc_1_0, "loongson,liointc-1.0", liointc_of_init);
321346
IRQCHIP_DECLARE(loongson_liointc_1_0a, "loongson,liointc-1.0a", liointc_of_init);
322347
IRQCHIP_DECLARE(loongson_liointc_2_0, "loongson,liointc-2.0", liointc_of_init);
348+
349+
#endif
350+
351+
#ifdef CONFIG_ACPI
352+
int __init liointc_acpi_init(struct irq_domain *parent, struct acpi_madt_lio_pic *acpi_liointc)
353+
{
354+
int ret;
355+
struct fwnode_handle *domain_handle;
356+
357+
parent_int_map[0] = acpi_liointc->cascade_map[0];
358+
parent_int_map[1] = acpi_liointc->cascade_map[1];
359+
360+
parent_irq[0] = irq_create_mapping(parent, acpi_liointc->cascade[0]);
361+
parent_irq[1] = irq_create_mapping(parent, acpi_liointc->cascade[1]);
362+
363+
domain_handle = irq_domain_alloc_fwnode((phys_addr_t *)acpi_liointc);
364+
if (!domain_handle) {
365+
pr_err("Unable to allocate domain handle\n");
366+
return -ENOMEM;
367+
}
368+
ret = liointc_init(acpi_liointc->address, acpi_liointc->size,
369+
1, domain_handle, NULL);
370+
if (ret)
371+
irq_domain_free_fwnode(domain_handle);
372+
373+
return ret;
374+
}
375+
#endif

0 commit comments

Comments
 (0)