From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6A8ECC021AA for ; Wed, 19 Feb 2025 23:53:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=AxsI5hx1U00SsNRDv901DQtcJhDoy9q2VCbcg6I8Ypc=; b=DOXHB7GEtr6zteHxPnK4tm6hKP I1Gg9R68NFf58f1QolQEkHzdXyIxp6fUAYZzDCZJmrUuRp/bNX+jDji+4LJWcs+8Ywtkoa7qq74JH 5gMbFZXhzyNKQHICCbWSdywVUHww00rNUopntDv91S+itPMG9jC2qrwGCQSJY5/2v0ORrnrEN8XXz M0KV26u58OL+NNjorUszGKSQpS97Q27/HeNX4odLwWxvj0BI0+Q+oh3/ExmB/ybYW4L9Nz9lvyx64 lrte/gzI8/oKcuVfAP/xKb01mkp39+hUfAWbxQw+LY5zQm5rByh78DIK19nLdhqi88BtHCtrgIPJN 1503r/uQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tktsl-0000000FneU-0kn9; Wed, 19 Feb 2025 23:53:35 +0000 Received: from linux.microsoft.com ([13.77.154.182]) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tktrG-0000000FnF4-2EAc for linux-arm-kernel@lists.infradead.org; Wed, 19 Feb 2025 23:52:03 +0000 Received: from [10.137.184.60] (unknown [131.107.160.188]) by linux.microsoft.com (Postfix) with ESMTPSA id 01FA32043DEB; Wed, 19 Feb 2025 15:51:59 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 01FA32043DEB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1740009120; bh=AxsI5hx1U00SsNRDv901DQtcJhDoy9q2VCbcg6I8Ypc=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=ktnrQxzhg8EhdAYLRHWi59CTjsWdX+RZHt9AeHw4gX2wcmvSMV36JUDiq5apyQzps 6sT7qtZaFzbfDnZh04pSaKBIoNSKDClg0OLz32kbUmBdY/90wSeu82XjEpHj7XUYtG SvfhXDK92ktiXTtrhL56mLp6jAldejO118ML+HFU= Message-ID: <5cd71475-b107-4269-829f-2c492f625aae@linux.microsoft.com> Date: Wed, 19 Feb 2025 15:51:59 -0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH hyperv-next v4 6/6] PCI: hv: Get vPCI MSI IRQ domain from DeviceTree To: Bjorn Helgaas , rafael@kernel.org, lenb@kernel.org, linux-acpi@vger.kernel.org Cc: arnd@arndb.de, bhelgaas@google.com, bp@alien8.de, catalin.marinas@arm.com, conor+dt@kernel.org, dave.hansen@linux.intel.com, decui@microsoft.com, haiyangz@microsoft.com, hpa@zytor.com, krzk+dt@kernel.org, kw@linux.com, kys@microsoft.com, lpieralisi@kernel.org, manivannan.sadhasivam@linaro.org, mingo@redhat.com, robh@kernel.org, ssengar@linux.microsoft.com, tglx@linutronix.de, wei.liu@kernel.org, will@kernel.org, devicetree@vger.kernel.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, x86@kernel.org, benhill@microsoft.com, bperkins@microsoft.com, sunilmut@microsoft.com References: <20250212174203.GA81135@bhelgaas> Content-Language: en-US From: Roman Kisel In-Reply-To: <20250212174203.GA81135@bhelgaas> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250219_155202_629531_85C9BBF9 X-CRM114-Status: GOOD ( 32.26 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 2/12/2025 9:42 AM, Bjorn Helgaas wrote: > On Tue, Feb 11, 2025 at 05:43:21PM -0800, Roman Kisel wrote: [...] >> */ >> - hv_msi_gic_irq_domain = acpi_irq_create_hierarchy(0, HV_PCI_MSI_SPI_NR, >> - fn, &hv_pci_domain_ops, >> - chip_data); >> +#ifdef CONFIG_ACPI >> + if (!acpi_disabled) >> + hv_msi_gic_irq_domain = acpi_irq_create_hierarchy(0, HV_PCI_MSI_SPI_NR, >> + fn, &hv_pci_domain_ops, >> + chip_data); >> +#endif >> +#if defined(CONFIG_OF) >> + if (!hv_msi_gic_irq_domain) >> + hv_msi_gic_irq_domain = irq_domain_create_hierarchy( >> + hv_pci_of_irq_domain_parent(), 0, HV_PCI_MSI_SPI_NR, >> + fn, &hv_pci_domain_ops, >> + chip_data); >> +#endif > > I don't know if acpi_irq_create_hierarchy() is helping or hurting > here. It obscures the fact that the only difference is the first > argument to irq_domain_create_hierarchy(). If we could open-code or > have a helper to figure out that irq_domain "parent" argument for the > ACPI case, then we'd only have one call of > irq_domain_create_hierarchy() here and it seems like it might be > simpler. > Hey Bjorn, folks, I've added few ACPI maintainers and the ACPI list as we're discussing making a small change to the ACPI subsystem to make one static variable available to make the code above less messy. Change [1] makes the GSI dispatcher function available to the outside world. Would you suggest going in that direction or there is a better approach to converge the code above that deals with IRQ domains both in the ACPI and DT cases? [1] From c6fb8bda21d6c00a308b1febc201a3a7e704c5a9 Mon Sep 17 00:00:00 2001 From: Roman Kisel Date: Wed, 19 Feb 2025 15:04:06 -0800 Subject: [PATCH] Refactor the ACPI GIC case --- drivers/acpi/irq.c | 14 ++++++- drivers/pci/controller/pci-hyperv.c | 62 +++++++++++++++++------------ include/linux/acpi.h | 5 ++- 3 files changed, 52 insertions(+), 29 deletions(-) diff --git a/drivers/acpi/irq.c b/drivers/acpi/irq.c index 1687483ff319..6243db610137 100644 --- a/drivers/acpi/irq.c +++ b/drivers/acpi/irq.c @@ -12,7 +12,7 @@ enum acpi_irq_model_id acpi_irq_model; -static struct fwnode_handle *(*acpi_get_gsi_domain_id)(u32 gsi); +static acpi_gsi_domain_disp_fn acpi_get_gsi_domain_id; static u32 (*acpi_gsi_to_irq_fallback)(u32 gsi); /** @@ -307,12 +307,22 @@ EXPORT_SYMBOL_GPL(acpi_irq_get); * for a given GSI */ void __init acpi_set_irq_model(enum acpi_irq_model_id model, - struct fwnode_handle *(*fn)(u32)) + acpi_gsi_domain_disp_fn fn) { acpi_irq_model = model; acpi_get_gsi_domain_id = fn; } +/** + * acpi_get_gsi_dispatcher - Returns dispatcher function that + * computes the domain fwnode for a + * given GSI. + */ +acpi_gsi_domain_disp_fn acpi_get_gsi_dispatcher(void) +{ + return acpi_get_gsi_domain_id; +} + /** * acpi_set_gsi_to_irq_fallback - Register a GSI transfer * callback to fallback to arch specified implementation. diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index 24725bea9ef1..59e670e1cb6e 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -910,16 +910,29 @@ static struct irq_domain *hv_pci_of_irq_domain_parent(void) of_node_put(parent); } - /* - * `domain == NULL` shouldn't happen. - * - * If somehow the code does end up in that state, treat this as a configuration - * issue rather than a hard error, emit a warning, and let the code proceed. - * The NULL parent domain is an acceptable option for the `irq_domain_create_hierarchy` - * function called later. - */ + return domain; +} + +#endif + +#ifdef CONFIG_ACPI + +static struct irq_domain *hv_pci_acpi_irq_domain_parent(void) +{ + struct irq_domain *domain; + acpi_gsi_domain_disp_fn gsi_domain_disp_fn; + + if (acpi_irq_model != ACPI_IRQ_MODEL_GIC) + return NULL; + gsi_domain_disp_fn = acpi_get_gsi_dispatcher(); + if (!gsi_domain_disp_fn) + return NULL; + domain = irq_find_matching_fwnode(gsi_domain_disp_fn(0), + DOMAIN_BUS_ANY); + if (!domain) - WARN_ONCE(1, "No interrupt-parent found, check the DeviceTree data.\n"); + return NULL; + return domain; } @@ -929,6 +942,7 @@ static int hv_pci_irqchip_init(void) { static struct hv_pci_chip_data *chip_data; struct fwnode_handle *fn = NULL; + struct irq_domain *irq_domain_parent = NULL; int ret = -ENOMEM; chip_data = kzalloc(sizeof(*chip_data), GFP_KERNEL); @@ -944,29 +958,25 @@ static int hv_pci_irqchip_init(void) * IRQ domain once enabled, should not be removed since there is no * way to ensure that all the corresponding devices are also gone and * no interrupts will be generated. - * - * In the ACPI case, the parent IRQ domain is supplied by the ACPI - * subsystem, and it is the default GSI domain pointing to the GIC. - * Neither is available outside of the ACPI subsystem, cannot avoid - * the messy ifdef below. - * There is apparently no such default in the OF subsystem, and - * `hv_pci_of_irq_domain_parent` finds the parent IRQ domain that - * points to the GIC as well. - * None of these two cases reaches for the MSI parent domain. */ #ifdef CONFIG_ACPI if (!acpi_disabled) - hv_msi_gic_irq_domain = acpi_irq_create_hierarchy(0, HV_PCI_MSI_SPI_NR, - fn, &hv_pci_domain_ops, - chip_data); + irq_domain_parent = hv_pci_acpi_irq_domain_parent(); #endif #if defined(CONFIG_OF) - if (!hv_msi_gic_irq_domain) - hv_msi_gic_irq_domain = irq_domain_create_hierarchy( - hv_pci_of_irq_domain_parent(), 0, HV_PCI_MSI_SPI_NR, - fn, &hv_pci_domain_ops, - chip_data); + if (!irq_domain_parent) + irq_domain_parent = hv_pci_of_irq_domain_parent(); #endif + if (!irq_domain_parent) { + WARN_ONCE(1, "Invalid firmware configuration for VMBus interrupts\n"); + ret = -EINVAL; + goto free_chip; + } + + hv_msi_gic_irq_domain = irq_domain_create_hierarchy( + irq_domain_parent, 0, HV_PCI_MSI_SPI_NR, + fn, &hv_pci_domain_ops, + chip_data); if (!hv_msi_gic_irq_domain) { pr_err("Failed to create Hyper-V arm64 vPCI MSI IRQ domain\n"); diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 6adcd1b92b20..cd70a72c7073 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -336,8 +336,11 @@ int acpi_register_gsi (struct device *dev, u32 gsi, int triggering, int polarity int acpi_gsi_to_irq (u32 gsi, unsigned int *irq); int acpi_isa_irq_to_gsi (unsigned isa_irq, u32 *gsi); +typedef struct fwnode_handle *(*acpi_gsi_domain_disp_fn)(u32); + void acpi_set_irq_model(enum acpi_irq_model_id model, - struct fwnode_handle *(*)(u32)); + acpi_gsi_domain_disp_fn fn); +acpi_gsi_domain_disp_fn acpi_get_gsi_dispatcher(void); void acpi_set_gsi_to_irq_fallback(u32 (*)(u32)); struct irq_domain *acpi_irq_create_hierarchy(unsigned int flags, -- 2.43.0 -- Thank you, Roman