From patchwork Fri Nov 11 13:56:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 18802 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp756675wru; Fri, 11 Nov 2022 06:03:35 -0800 (PST) X-Google-Smtp-Source: AA0mqf5zxuHpMWWDG+LDdp4zgCxclLDm1DI68wROwi1HtvkMOMWQTIPqzu7J5ueXzia1RfSxPNi3 X-Received: by 2002:a17:90a:fd14:b0:213:2030:123f with SMTP id cv20-20020a17090afd1400b002132030123fmr2117194pjb.3.1668175414874; Fri, 11 Nov 2022 06:03:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668175414; cv=none; d=google.com; s=arc-20160816; b=s+Wl8LthBnhAGJNtyvGJQye2S5F6tc8eWWTioT5l+wsg0L8zJs2a8bIw8Vaecf/F3D 92YZU32srKXWIj6bk6rarRQKsLkbdGeXf6AQUaD9ADC6qWR3CUHHVxld13j4pB0WdvPH u+wt9bARqWQa99Ydaw7TWvkos7xJl8lrWirbyp3OBm0OGevfVfeRLknMMYrIU6oPfSeP 4anmMCzqbn0WotvH7qE+C+j3mNzJf7J8kNB/e4PPph0pagPxCuu8wVkoLnhWosNa40tc aHmv2ObN6cuQDBZ4i4P1ScCZFPpLYmuUPgsW7l48njZuqY79qXhWIZo+TSHpiFb4MZGw 0rXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=92MQH4tsGJzqVWHKcfiMvA7FJnwUvqItKIXp1ZsQCJ8=; b=NU2ZFsxI+rKC0pHMl4/HnF0hae7d1Sgx/K03f+Nh3xzi7DZJamdvBlXQ3sXSvS8rs1 zNxB2yX+H7V/acEsejbhetWjZoIqmaJy/ttNHcSdh//dgeDa7SURYdV5c5AjBCUFwCEJ Juz06EgKES4nxOkHjm9lUOj9R8wSl2XqHqiro84pIEJXUOk1qEOwB7IrDhUaKsvFyOBH URpq1CMy47bk5kmAG66qSPWm7cYlpPuAtGPo22RAc/RO5KzNQ8ZW78aG2eGOdKc9Rrib uEE9TZpiDsr97e3S86qC59tVp6qtDepVbPrdPLVm0de5wJHLTioKAuzVHU56tUv5jgcs 1WLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=bvPrN6ax; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n24-20020a63a518000000b004701d95bd0csi2415606pgf.431.2022.11.11.06.03.03; Fri, 11 Nov 2022 06:03:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=bvPrN6ax; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233724AbiKKOBg (ORCPT + 99 others); Fri, 11 Nov 2022 09:01:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233758AbiKKOAz (ORCPT ); Fri, 11 Nov 2022 09:00:55 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA23A845EB; Fri, 11 Nov 2022 05:56:50 -0800 (PST) Message-ID: <20221111132706.445074807@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668175009; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=92MQH4tsGJzqVWHKcfiMvA7FJnwUvqItKIXp1ZsQCJ8=; b=bvPrN6axkYTIF2LbeMNOe+mUeY17g00ZVWsa3pBdSu3JEOoPUTytFVkIan722oupR0E7B8 ruRapWOMWrJnnYI6lGRY5eZ5BMgE+JQ0g6EuuHihNqcEPk0o4RN6udnD7mss2kBRsBdJc0 gYys914sOey8OInhnHJYWb1pj3v9Xe8Av3jxGR7q7R2LrZ9J4tvCjHe4rrqWdf7PNxehCT Rwt/PNz4/H3CqOboErI5qstR8Nj6gtyNJA2EvgzgLSQsIEkyao9Tx5oEHMZ25BwHZt1Qtu HWGGfZczAhaZot6RLR3/JsNNtO9TZ3j5M1Ix/sEsQXWkFN2JH1cVGAV2pMtBwA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668175009; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=92MQH4tsGJzqVWHKcfiMvA7FJnwUvqItKIXp1ZsQCJ8=; b=ohCWCJWinKORAyxBehsGXZErXCxGj/Qm9pNCGlsXZYTqFOTm3xGwzE6xksuSIkIbBUGinG KrSSQtP+7bRjbUCw== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Joerg Roedel , Will Deacon , linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Marc Zyngier , Greg Kroah-Hartman , Jason Gunthorpe , Dave Jiang , Alex Williamson , Kevin Tian , Dan Williams , Logan Gunthorpe , Ashok Raj , Jon Mason , Allen Hubbe , "Ahmed S. Darwish" , Reinette Chatre Subject: [patch 07/20] genirq/msi: Add pointers for per device irq domains References: <20221111131813.914374272@linutronix.de> MIME-Version: 1.0 Date: Fri, 11 Nov 2022 14:56:48 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749208703976236551?= X-GMAIL-MSGID: =?utf-8?q?1749208703976236551?= With the upcoming per device MSI interrupt domain support it is necessary to store the domain pointers per device. Instead of delegating that storage to device drivers or subsystems create a storage array in struct msi_device_data which will also take care of tearing down the irq domains when msi_device_data is cleaned up via devres. The interfaces into the MSI core will be changed from irqdomain pointer based interfaces to domain id based interfaces to support multiple MSI domains on a single device (e.g. PCI/MSI[-X] and PCI/IMS. Once the per device domain support is complete the irq domain pointer in struct device::msi.domain will not longer contain a pointer to the "global" MSI domain. It will contain a pointer to the MSI parent domain instead. It would be a horrible maze of conditionals to evaluate all over the place which domain pointer should be used, i.e. the "global" one in device::msi::domain or one from the internal pointer array. To avoid this evaluate in msi_setup_device_data() whether the irq domain which is associated to a device is a "global" or a parent MSI domain. If it is global then copy the pointer into the first entry in the irqdomain pointer array. This allows to convert interfaces and implementation to domain ids while keeping everything existing working. Signed-off-by: Thomas Gleixner --- include/linux/msi.h | 3 +++ include/linux/msi_api.h | 8 ++++++++ kernel/irq/msi.c | 14 ++++++++++++++ 3 files changed, 25 insertions(+) --- a/include/linux/msi.h +++ b/include/linux/msi.h @@ -77,6 +77,7 @@ struct msi_desc; struct pci_dev; struct platform_msi_priv_data; struct device_attribute; +struct irq_domain; void __get_cached_msi_msg(struct msi_desc *entry, struct msi_msg *msg); void get_cached_msi_msg(unsigned int irq, struct msi_msg *msg); @@ -176,6 +177,7 @@ enum msi_desc_filter { * @mutex: Mutex protecting the MSI descriptor store * @__store: Xarray for storing MSI descriptor pointers * @__iter_idx: Index to search the next entry for iterators + * @__irqdomains: Per device interrupt domains */ struct msi_device_data { unsigned long properties; @@ -183,6 +185,7 @@ struct msi_device_data { struct mutex mutex; struct xarray __store; unsigned long __iter_idx; + struct irq_domain *__irqdomains[MSI_MAX_DEVICE_IRQDOMAINS]; }; int msi_setup_device_data(struct device *dev); --- a/include/linux/msi_api.h +++ b/include/linux/msi_api.h @@ -10,6 +10,14 @@ struct device; +/* + * Per device interrupt domain related constants. + */ +enum msi_domain_ids { + MSI_DEFAULT_DOMAIN, + MSI_MAX_DEVICE_IRQDOMAINS, +}; + unsigned int msi_get_virq(struct device *dev, unsigned int index); #endif --- a/kernel/irq/msi.c +++ b/kernel/irq/msi.c @@ -21,6 +21,18 @@ static inline int msi_sysfs_create_group(struct device *dev); +static inline void msi_setup_default_irqdomain(struct device *dev, struct msi_device_data *md) +{ + if (!dev->msi.domain) + return; + /* + * If @dev::msi::domain is a global MSI domain, copy the pointer + * into the domain array to avoid conditionals all over the place. + */ + if (!irq_domain_is_msi_parent(dev->msi.domain)) + md->__irqdomains[MSI_DEFAULT_DOMAIN] = dev->msi.domain; +} + /** * msi_alloc_desc - Allocate an initialized msi_desc * @dev: Pointer to the device for which this is allocated @@ -213,6 +225,8 @@ int msi_setup_device_data(struct device return ret; } + msi_setup_default_irqdomain(dev, md); + xa_init(&md->__store); mutex_init(&md->mutex); dev->msi.data = md;