From: Bjorn Helgaas <helgaas@kernel.org>
To: Sunil V L <sunilvl@ventanamicro.com>
Cc: linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org,
linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org,
acpica-devel@lists.linux.dev,
"Catalin Marinas" <catalin.marinas@arm.com>,
"Will Deacon" <will@kernel.org>,
"Paul Walmsley" <paul.walmsley@sifive.com>,
"Palmer Dabbelt" <palmer@dabbelt.com>,
"Albert Ou" <aou@eecs.berkeley.edu>,
"Rafael J . Wysocki" <rafael@kernel.org>,
"Len Brown" <lenb@kernel.org>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Anup Patel" <anup@brainfault.org>,
"Thomas Gleixner" <tglx@linutronix.de>,
"Samuel Holland" <samuel.holland@sifive.com>,
"Robert Moore" <robert.moore@intel.com>,
"Conor Dooley" <conor.dooley@microchip.com>,
"Andrew Jones" <ajones@ventanamicro.com>,
"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
"Marc Zyngier" <maz@kernel.org>,
"Atish Kumar Patra" <atishp@rivosinc.com>,
"Haibo1 Xu" <haibo1.xu@intel.com>,
"Björn Töpel" <bjorn@kernel.org>
Subject: Re: [PATCH v6 11/17] ACPI: RISC-V: Initialize GSI mapping structures
Date: Thu, 6 Jun 2024 17:32:59 -0500 [thread overview]
Message-ID: <20240606223259.GA822964@bhelgaas> (raw)
In-Reply-To: <20240601150411.1929783-12-sunilvl@ventanamicro.com>
On Sat, Jun 01, 2024 at 08:34:05PM +0530, Sunil V L wrote:
> RISC-V has PLIC and APLIC in MADT as well as namespace devices.
> Initialize the list of those structures using MADT and namespace devices
> to create mapping between the ACPI handle and the GSI ranges. This will
> be used later to add dependencies.
From a long ways away, this looks like "map a GSI to an interrupt
controller described either via MADT or namespace" plus a little bit
of RISC-V stuff.
That first part, mapping GSI to interrupt controller, is generic and
other arches need to do the same thing. It would be nice if every
arch didn't have to roll their own list of (handle, gsi_base, nr_irqs)
tuples. And it might clarify the whole concept of GSI, which is
conceptually very simple but gets muddied by all the magic stuff
around it.
This is probably just wishful thinking and not actionable feedback.
> Signed-off-by: Sunil V L <sunilvl@ventanamicro.com>
> ---
> arch/riscv/include/asm/irq.h | 22 ++++++
> drivers/acpi/riscv/init.c | 2 +
> drivers/acpi/riscv/init.h | 4 +
> drivers/acpi/riscv/irq.c | 142 +++++++++++++++++++++++++++++++++++
> 4 files changed, 170 insertions(+)
> create mode 100644 drivers/acpi/riscv/init.h
>
> diff --git a/arch/riscv/include/asm/irq.h b/arch/riscv/include/asm/irq.h
> index 8e10a94430a2..44a0b128c602 100644
> --- a/arch/riscv/include/asm/irq.h
> +++ b/arch/riscv/include/asm/irq.h
> @@ -16,4 +16,26 @@ void riscv_set_intc_hwnode_fn(struct fwnode_handle *(*fn)(void));
>
> struct fwnode_handle *riscv_get_intc_hwnode(void);
>
> +#ifdef CONFIG_ACPI
> +
> +enum riscv_irqchip_type {
> + ACPI_RISCV_IRQCHIP_INTC = 0x00,
> + ACPI_RISCV_IRQCHIP_IMSIC = 0x01,
> + ACPI_RISCV_IRQCHIP_PLIC = 0x02,
> + ACPI_RISCV_IRQCHIP_APLIC = 0x03,
> +};
> +
> +int riscv_acpi_get_gsi_info(struct fwnode_handle *fwnode, u32 *gsi_base,
> + u32 *id, u32 *nr_irqs, u32 *nr_idcs);
> +struct fwnode_handle *riscv_acpi_get_gsi_domain_id(u32 gsi);
> +
> +#else
> +static inline int riscv_acpi_get_gsi_info(struct fwnode_handle *fwnode, u32 *gsi_base,
> + u32 *id, u32 *nr_irqs, u32 *nr_idcs)
> +{
> + return 0;
> +}
> +
> +#endif /* CONFIG_ACPI */
> +
> #endif /* _ASM_RISCV_IRQ_H */
> diff --git a/drivers/acpi/riscv/init.c b/drivers/acpi/riscv/init.c
> index 5f7571143245..22db97f7a772 100644
> --- a/drivers/acpi/riscv/init.c
> +++ b/drivers/acpi/riscv/init.c
> @@ -6,7 +6,9 @@
> */
>
> #include <linux/acpi.h>
> +#include "init.h"
>
> void __init acpi_riscv_init(void)
> {
> + riscv_acpi_init_gsi_mapping();
> }
> diff --git a/drivers/acpi/riscv/init.h b/drivers/acpi/riscv/init.h
> new file mode 100644
> index 000000000000..0b9a07e4031f
> --- /dev/null
> +++ b/drivers/acpi/riscv/init.h
> @@ -0,0 +1,4 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +#include <linux/init.h>
> +
> +void __init riscv_acpi_init_gsi_mapping(void);
> diff --git a/drivers/acpi/riscv/irq.c b/drivers/acpi/riscv/irq.c
> index f56e103a501f..0473428e8d1e 100644
> --- a/drivers/acpi/riscv/irq.c
> +++ b/drivers/acpi/riscv/irq.c
> @@ -7,6 +7,21 @@
>
> #include <linux/acpi.h>
> #include <linux/sort.h>
> +#include <linux/irq.h>
> +
> +#include "init.h"
> +
> +struct riscv_ext_intc_list {
> + acpi_handle handle;
> + u32 gsi_base;
> + u32 nr_irqs;
> + u32 nr_idcs;
> + u32 id;
> + u32 type;
> + struct list_head list;
> +};
> +
> +LIST_HEAD(ext_intc_list);
>
> static int irqchip_cmp_func(const void *in0, const void *in1)
> {
> @@ -30,3 +45,130 @@ void arch_sort_irqchip_probe(struct acpi_probe_entry *ap_head, int nr)
> return;
> sort(ape, nr, sizeof(*ape), irqchip_cmp_func, NULL);
> }
> +
> +static void riscv_acpi_update_gsi_handle(u32 gsi_base, acpi_handle handle)
> +{
> + struct riscv_ext_intc_list *ext_intc_element;
> + struct list_head *i, *tmp;
> +
> + list_for_each_safe(i, tmp, &ext_intc_list) {
> + ext_intc_element = list_entry(i, struct riscv_ext_intc_list, list);
> + if (gsi_base == ext_intc_element->gsi_base) {
> + ext_intc_element->handle = handle;
> + return;
> + }
> + }
> +
> + acpi_handle_err(handle, "failed to find the GSI mapping entry\n");
> +}
> +
> +int riscv_acpi_get_gsi_info(struct fwnode_handle *fwnode, u32 *gsi_base,
> + u32 *id, u32 *nr_irqs, u32 *nr_idcs)
> +{
> + struct riscv_ext_intc_list *ext_intc_element;
> + struct list_head *i, *tmp;
> +
> + list_for_each_safe(i, tmp, &ext_intc_list) {
> + ext_intc_element = list_entry(i, struct riscv_ext_intc_list, list);
> + if (ext_intc_element->handle == ACPI_HANDLE_FWNODE(fwnode)) {
> + *gsi_base = ext_intc_element->gsi_base;
> + *id = ext_intc_element->id;
> + *nr_irqs = ext_intc_element->nr_irqs;
> + if (nr_idcs)
> + *nr_idcs = ext_intc_element->nr_idcs;
> +
> + return 0;
> + }
> + }
> +
> + return -ENODEV;
> +}
> +
> +struct fwnode_handle *riscv_acpi_get_gsi_domain_id(u32 gsi)
> +{
> + struct riscv_ext_intc_list *ext_intc_element;
> + struct acpi_device *adev;
> + struct list_head *i, *tmp;
> +
> + list_for_each_safe(i, tmp, &ext_intc_list) {
> + ext_intc_element = list_entry(i, struct riscv_ext_intc_list, list);
> + if (gsi >= ext_intc_element->gsi_base &&
> + gsi < (ext_intc_element->gsi_base + ext_intc_element->nr_irqs)) {
> + adev = acpi_fetch_acpi_dev(ext_intc_element->handle);
> + if (!adev)
> + return NULL;
> +
> + return acpi_fwnode_handle(adev);
> + }
> + }
> +
> + return NULL;
> +}
> +
> +static int __init riscv_acpi_register_ext_intc(u32 gsi_base, u32 nr_irqs, u32 nr_idcs,
> + u32 id, u32 type)
> +{
> + struct riscv_ext_intc_list *ext_intc_element;
> +
> + ext_intc_element = kzalloc(sizeof(*ext_intc_element), GFP_KERNEL);
> + if (!ext_intc_element)
> + return -ENOMEM;
> +
> + ext_intc_element->gsi_base = gsi_base;
> + ext_intc_element->nr_irqs = nr_irqs;
> + ext_intc_element->nr_idcs = nr_idcs;
> + ext_intc_element->id = id;
> + list_add_tail(&ext_intc_element->list, &ext_intc_list);
> + return 0;
> +}
> +
> +static acpi_status __init riscv_acpi_create_gsi_map(acpi_handle handle, u32 level,
> + void *context, void **return_value)
> +{
> + acpi_status status;
> + u64 gbase;
> +
> + if (!acpi_has_method(handle, "_GSB")) {
> + acpi_handle_err(handle, "_GSB method not found\n");
> + return AE_OK;
> + }
> +
> + status = acpi_evaluate_integer(handle, "_GSB", NULL, &gbase);
> + if (ACPI_FAILURE(status)) {
> + acpi_handle_err(handle, "failed to evaluate _GSB method\n");
> + return AE_OK;
> + }
> +
> + riscv_acpi_update_gsi_handle((u32)gbase, handle);
> + return AE_OK;
> +}
> +
> +static int __init riscv_acpi_aplic_parse_madt(union acpi_subtable_headers *header,
> + const unsigned long end)
> +{
> + struct acpi_madt_aplic *aplic = (struct acpi_madt_aplic *)header;
> +
> + return riscv_acpi_register_ext_intc(aplic->gsi_base, aplic->num_sources, aplic->num_idcs,
> + aplic->id, ACPI_RISCV_IRQCHIP_APLIC);
> +}
> +
> +static int __init riscv_acpi_plic_parse_madt(union acpi_subtable_headers *header,
> + const unsigned long end)
> +{
> + struct acpi_madt_plic *plic = (struct acpi_madt_plic *)header;
> +
> + return riscv_acpi_register_ext_intc(plic->gsi_base, plic->num_irqs, 0,
> + plic->id, ACPI_RISCV_IRQCHIP_PLIC);
> +}
> +
> +void __init riscv_acpi_init_gsi_mapping(void)
> +{
> + /* There can be either PLIC or APLIC */
> + if (acpi_table_parse_madt(ACPI_MADT_TYPE_PLIC, riscv_acpi_plic_parse_madt, 0) > 0) {
> + acpi_get_devices("RSCV0001", riscv_acpi_create_gsi_map, NULL, NULL);
> + return;
> + }
> +
> + if (acpi_table_parse_madt(ACPI_MADT_TYPE_APLIC, riscv_acpi_aplic_parse_madt, 0) > 0)
> + acpi_get_devices("RSCV0002", riscv_acpi_create_gsi_map, NULL, NULL);
> +}
> --
> 2.40.1
>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2024-06-06 22:33 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-01 15:03 [PATCH v6 00/17] RISC-V: ACPI: Add external interrupt controller support Sunil V L
2024-06-01 15:03 ` [PATCH v6 01/17] arm64: PCI: Migrate ACPI related functions to pci-acpi.c Sunil V L
2024-06-01 15:03 ` [PATCH v6 02/17] ACPI: scan: Add a weak function to reorder the IRQCHIP probe Sunil V L
2024-06-01 15:03 ` [PATCH v6 03/17] ACPI: bus: Add acpi_riscv_init function Sunil V L
2024-06-01 15:03 ` [PATCH v6 04/17] ACPI: scan: Refactor dependency creation Sunil V L
2024-06-01 15:03 ` [PATCH v6 05/17] ACPI: scan: Add RISC-V interrupt controllers to honor list Sunil V L
2024-06-01 15:04 ` [PATCH v6 06/17] ACPI: scan: Define weak function to populate dependencies Sunil V L
2024-06-01 15:04 ` [PATCH v6 07/17] ACPI: bus: Add RINTC IRQ model for RISC-V Sunil V L
2024-06-01 15:04 ` [PATCH v6 08/17] ACPI: pci_link: Clear the dependencies after probe Sunil V L
2024-06-01 15:04 ` [PATCH v6 09/17] ACPI: RISC-V: Implement PCI related functionality Sunil V L
2024-06-01 15:04 ` [PATCH v6 10/17] ACPI: RISC-V: Implement function to reorder irqchip probe entries Sunil V L
2024-06-06 22:07 ` Bjorn Helgaas
2024-07-10 13:55 ` Sunil V L
2024-06-01 15:04 ` [PATCH v6 11/17] ACPI: RISC-V: Initialize GSI mapping structures Sunil V L
2024-06-06 22:32 ` Bjorn Helgaas [this message]
2024-07-10 10:45 ` Lorenzo Pieralisi
2024-07-10 13:42 ` Sunil V L
2024-06-01 15:04 ` [PATCH v6 12/17] ACPI: RISC-V: Implement function to add implicit dependencies Sunil V L
2024-06-01 15:04 ` [PATCH v6 13/17] irqchip/riscv-intc: Add ACPI support for AIA Sunil V L
2024-06-01 15:04 ` [PATCH v6 14/17] irqchip/riscv-imsic-state: Create separate function for DT Sunil V L
2024-06-01 15:04 ` [PATCH v6 15/17] irqchip/riscv-imsic: Add ACPI support Sunil V L
2024-06-01 15:04 ` [PATCH v6 16/17] irqchip/riscv-aplic: " Sunil V L
2024-06-01 15:04 ` [PATCH v6 17/17] irqchip/sifive-plic: " Sunil V L
2024-06-25 7:25 ` [PATCH v6 00/17] RISC-V: ACPI: Add external interrupt controller support Thomas Gleixner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240606223259.GA822964@bhelgaas \
--to=helgaas@kernel.org \
--cc=acpica-devel@lists.linux.dev \
--cc=ajones@ventanamicro.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=anup@brainfault.org \
--cc=aou@eecs.berkeley.edu \
--cc=atishp@rivosinc.com \
--cc=bhelgaas@google.com \
--cc=bjorn@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=conor.dooley@microchip.com \
--cc=haibo1.xu@intel.com \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=maz@kernel.org \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=rafael@kernel.org \
--cc=robert.moore@intel.com \
--cc=samuel.holland@sifive.com \
--cc=sunilvl@ventanamicro.com \
--cc=tglx@linutronix.de \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).