From patchwork Mon Nov 21 14:36:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 23802 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1626967wrr; Mon, 21 Nov 2022 06:38:36 -0800 (PST) X-Google-Smtp-Source: AA0mqf6bOzgcCr4ZVz/TzBFtnfq/GP6XmB40uCfUWtW4lLcPsH37pkgl+vfzKVTJsW/OxTn1ZLFi X-Received: by 2002:aa7:942f:0:b0:56b:a149:1d89 with SMTP id y15-20020aa7942f000000b0056ba1491d89mr810282pfo.83.1669041516030; Mon, 21 Nov 2022 06:38:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669041516; cv=none; d=google.com; s=arc-20160816; b=BkXFdX7J18vWLccIa2IkBzxFqQOBLhjyZgQZnuoJ2Q/zMEZiWOOTKfA+rPVIc7JKGn SoZPotiNjI7GCa3QVz+EA98iCqdg+WFaLR4OodTihLzXHMz4b3vGPjw5fAjNLMqCPRCY HiKjLcntDaaBJYJhHFwRXxU/fdS8DSgegkgBj6sqVRC31L9Kr+Lkk5Y/5urrA+0zDZ4P 08t4DktHyGk2qoTm8D2WMQoLdK6sU4qSIHmjDxlrW+x8Nsz4g5Wf95Z31Tyte+7NOgD6 9q3MqdmmDSHZ3X/yHSvSZQuWpewjhIagYzdNIGCmmVr3e6YEmhkXkdSmBTd/qJhp15qD xpdw== 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=W7qVbQgLsW9+eyoM2fn4CU+n/dlKHe6NknzgWNBQJFM=; b=C6xeHvsI7dn0l1JdI6PCP+Ct9UP/UzZAcoxvXphpvbwScxQBTbi3yAtV3zql/kYBun 8sq2milLjj+liGlUICfTn1+4NWVZuWiLJTyHuIltfsWf2ZfVLDdcJvB8BZLGcIgJyOmk Rr4XR9JrC23LBzWWtDM2Eh9RV7ToatKaS3u5/bqPm6EUVBxpRsQITTmPeASBaF+0/h4S Me4rDLvcWOMIHa/NBe5BaDJkmM5mnFuoYGaLpB7fzddp5aY6U/bSDu7UX99E2GFgVqg5 RDSyJDodEw52OXKfN/N0dP1qbBakxDsaa8gr2uYEnoS9zmQbc+DrSliSWrCtPYG/hlg1 bgDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=nQVGQACb; dkim=neutral (no key) header.i=@linutronix.de; 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 a38-20020a056a001d2600b0056c231e4447si12294579pfx.198.2022.11.21.06.38.21; Mon, 21 Nov 2022 06:38:36 -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=nQVGQACb; dkim=neutral (no key) header.i=@linutronix.de; 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 S231586AbiKUOhf (ORCPT + 99 others); Mon, 21 Nov 2022 09:37:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230176AbiKUOgl (ORCPT ); Mon, 21 Nov 2022 09:36:41 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0370DC6D16; Mon, 21 Nov 2022 06:36:30 -0800 (PST) Message-ID: <20221121083325.950255253@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669041388; 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=W7qVbQgLsW9+eyoM2fn4CU+n/dlKHe6NknzgWNBQJFM=; b=nQVGQACbwDgZgFx6Yzjx95AJmLSoQLwxKE1n+al/J1KQEZFIX5TbDcZEuaFUjQuLDeJ0iO GbY/q/6UgN99PnEeTDHVJMVoz5hbW2y4TWu8fv3219e4f1sBqPbJQRUt3TNboXcIQOHB3C BQ4SP8gLZ5wrn/taAL/7kxxIqz2CkmCAEdYIl1UAs8oMvGY6+X2j+Gks1jIXOzoFksie6R lUGpRKjCdlDJ9AsF04mx3GzyZrgsXv6tHTGy5OswCQ/tvR6t3kfFjmJxBjtszWXxvuxZ4z fn9fdLbTr84EWKgXasbHdlhHz4dN2pXJkVp0n+g5f0Z9KxvGffVK36G1nIHqPQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669041388; 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=W7qVbQgLsW9+eyoM2fn4CU+n/dlKHe6NknzgWNBQJFM=; b=U4VJ4dAgXGtzIyaO0c7BJIiFHBNo3jeZHyXGDxSY68cLTykCaDumafui4CSyQh6fJZRQaB 8m/CSoIAq4Bug9DQ== 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 Subject: [patch V2 08/21] genirq/msi: Add pointers for per device irq domains References: <20221121083210.309161925@linutronix.de> MIME-Version: 1.0 Date: Mon, 21 Nov 2022 15:36:28 +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?1750116876415461865?= X-GMAIL-MSGID: =?utf-8?q?1750116876415461865?= 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 Reviewed-by: Marc Zyngier --- 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); #ifdef CONFIG_GENERIC_MSI_IRQ @@ -180,6 +181,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; @@ -187,6 +189,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;