xref: /linux/drivers/acpi/riscv/irq.c (revision f8bba143dae10f824e2b4522f31d6e78781b8667)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (C) 2023-2024, Ventana Micro Systems Inc
4  *	Author: Sunil V L <sunilvl@ventanamicro.com>
5  */
6 
7 #include <linux/acpi.h>
8 #include <linux/sort.h>
9 
10 static int irqchip_cmp_func(const void *in0, const void *in1)
11 {
12 	struct acpi_probe_entry *elem0 = (struct acpi_probe_entry *)in0;
13 	struct acpi_probe_entry *elem1 = (struct acpi_probe_entry *)in1;
14 
15 	return (elem0->type > elem1->type) - (elem0->type < elem1->type);
16 }
17 
18 /*
19  * On RISC-V, RINTC structures in MADT should be probed before any other
20  * interrupt controller structures and IMSIC before APLIC. The interrupt
21  * controller subtypes in MADT of ACPI spec for RISC-V are defined in
22  * the incremental order like RINTC(24)->IMSIC(25)->APLIC(26)->PLIC(27).
23  * Hence, simply sorting the subtypes in incremental order will
24  * establish the required order.
25  */
26 void arch_sort_irqchip_probe(struct acpi_probe_entry *ap_head, int nr)
27 {
28 	struct acpi_probe_entry *ape = ap_head;
29 
30 	if (nr == 1 || !ACPI_COMPARE_NAMESEG(ACPI_SIG_MADT, ape->id))
31 		return;
32 	sort(ape, nr, sizeof(*ape), irqchip_cmp_func, NULL);
33 }
34