From patchwork Sat Nov 27 01:20:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 1560497 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=linutronix.de header.i=@linutronix.de header.a=rsa-sha256 header.s=2020 header.b=2eIPTF3x; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=F4GuDJS8; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4J1DSM1NjPz9sVc for ; Sat, 27 Nov 2021 12:25:07 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345572AbhK0B2S (ORCPT ); Fri, 26 Nov 2021 20:28:18 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:35128 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347948AbhK0B0L (ORCPT ); Fri, 26 Nov 2021 20:26:11 -0500 Message-ID: <20211126230525.603398433@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1637976052; 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=OStoQ1k4lhD67pt01NEuqrVFlk3DmZUUJiTL5O5hAPA=; b=2eIPTF3xTaHSNXBIoN6UqqgFfwD0fJ1X1T9rr9vQ/2LfENBf9x4679Mo2RuhP9n8o8RsID PnEAypAhi616GnVO+gsc2xOAtuWMr4zBjlVOnNOOtDv/TFaKyRNAdBMjxKS/4JHJVMVGoZ WM12EP6pWvV4ZsO7GlLDsIBUy/ezmXIF/1d3ZFPMW5x3TBf0XpZh+FYDE99NYyZWIvzYgi BIqUxvpeT1xK0s9B7mfKENI+tGzeDcNGN6l89hiOEFrHrMdVn8Hh5EnSM+v1FR2r2Ei4Jg 6CiJ/KP+dYdUGxvoPE9tL/6S+FTAN/FPTY7BQjlvqgOjLHOCqkbvJ4Ec+bDtIQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1637976052; 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=OStoQ1k4lhD67pt01NEuqrVFlk3DmZUUJiTL5O5hAPA=; b=F4GuDJS8gR6I0V15qge6xQbu7oE67MdRvXQDexFplNMXCIE/Lzm4ICs8dJd43R0NUCg4Ec uDsRCB20i1Lf70AQ== From: Thomas Gleixner To: LKML Cc: Bjorn Helgaas , Marc Zygnier , Alex Williamson , Kevin Tian , Jason Gunthorpe , Megha Dey , Ashok Raj , linux-pci@vger.kernel.org, Greg Kroah-Hartman , Santosh Shilimkar , iommu@lists.linux-foundation.org, dmaengine@vger.kernel.org, Stuart Yoder , Laurentiu Tudor , Nishanth Menon , Tero Kristo , linux-arm-kernel@lists.infradead.org, x86@kernel.org, Vinod Koul , Mark Rutland , Will Deacon , Sinan Kaya Subject: [patch 28/37] genirq/msi: Provide interface to retrieve Linux interrupt number References: <20211126224100.303046749@linutronix.de> MIME-Version: 1.0 Date: Sat, 27 Nov 2021 02:20:51 +0100 (CET) Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org This allows drivers to retrieve the Linux interrupt number instead of fiddling with MSI descriptors. msi_get_virq() returns the Linux interrupt number or 0, __msi_get_virq() has more detailed return codes so pci_irq_vector() can use it as well. Signed-off-by: Thomas Gleixner --- include/linux/msi.h | 16 ++++++++++++++++ kernel/irq/msi.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) --- a/include/linux/msi.h +++ b/include/linux/msi.h @@ -169,6 +169,22 @@ static inline bool msi_device_has_proper } #endif +int __msi_get_virq(struct device *dev, unsigned int index); + +/** + * msi_get_virq - Return Linux interrupt number of a MSI interrupt + * @dev: Device to operate on + * @index: MSI interrupt index to look for (0-based) + * + * Return: The Linux interrupt number on success (> 0), 0 if not found + */ +static inline unsigned int msi_get_virq(struct device *dev, unsigned int index) +{ + int ret = __msi_get_virq(dev, index); + + return ret < 0 ? 0 : ret; +} + /* Helpers to hide struct msi_desc implementation details */ #define msi_desc_to_dev(desc) ((desc)->dev) #define dev_to_msi_list(dev) (&(dev)->msi_list) --- a/kernel/irq/msi.c +++ b/kernel/irq/msi.c @@ -120,6 +120,44 @@ int msi_setup_device_data(struct device return 0; } +/** + * __msi_get_virq - Return Linux interrupt number of a MSI interrupt + * @dev: Device to operate on + * @index: MSI interrupt index to look for (0-based) + * + * Return: The Linux interrupt number on success (> 0) + * -ENODEV when the device is not using MSI + * -ENOENT if no such entry exists + */ +int __msi_get_virq(struct device *dev, unsigned int index) +{ + struct msi_desc *desc; + bool pcimsi; + + if (!dev->msi.data) + return -ENODEV; + + pcimsi = msi_device_has_property(dev, MSI_PROP_PCI_MSI); + + for_each_msi_entry(desc, dev) { + /* PCI-MSI has only one descriptor for multiple interrupts. */ + if (pcimsi) { + if (desc->irq && index < desc->nvec_used) + return desc->irq + index; + break; + } + + /* + * PCI-MSIX and platform MSI use a descriptor per + * interrupt. + */ + if (desc->msi_index == index) + return desc->irq; + } + return -ENOENT; +} +EXPORT_SYMBOL_GPL(__msi_get_virq); + #ifdef CONFIG_SYSFS static ssize_t msi_mode_show(struct device *dev, struct device_attribute *attr, char *buf)