Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752154AbcCGDuY (ORCPT ); Sun, 6 Mar 2016 22:50:24 -0500 Received: from mail-bl2on0086.outbound.protection.outlook.com ([65.55.169.86]:10816 "EHLO na01-bl2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751902AbcCGDuS (ORCPT ); Sun, 6 Mar 2016 22:50:18 -0500 X-Greylist: delayed 915 seconds by postgrey-1.27 at vger.kernel.org; Sun, 06 Mar 2016 22:50:18 EST Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none;nxp.com; dmarc=none action=none header.from=nxp.com; From: Minghuan Lian To: , CC: Marc Zyngier , Thomas Gleixner , Jason Cooper , Roy Zang , Mingkai Hu , Stuart Yoder , Yang-Leo Li , Minghuan Lian Subject: [PATCH 2/2 v5] irqchip/Layerscape: Add SCFG MSI controller support Date: Mon, 7 Mar 2016 11:36:22 +0800 Message-ID: <1457321782-3245-2-git-send-email-Minghuan.Lian@nxp.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1457321782-3245-1-git-send-email-Minghuan.Lian@nxp.com> References: <1457321782-3245-1-git-send-email-Minghuan.Lian@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131017953034298288;(91ab9b29-cfa4-454e-5278-08d120cd25b8);() X-Forefront-Antispam-Report: CIP:192.88.168.50;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(2980300002)(1110001)(1109001)(339900001)(189002)(199003)(11100500001)(50466002)(189998001)(47776003)(229853001)(85426001)(5001770100001)(2950100001)(19580395003)(87936001)(104016004)(5008740100001)(6806005)(586003)(76176999)(36756003)(105606002)(50986999)(77096005)(92566002)(5003940100001)(1096002)(106466001)(1220700001)(86362001)(19580405001)(81166005)(50226001)(2906002)(48376002)(4326007)(7059030)(217873001)(2101003);DIR:OUT;SFP:1101;SCL:1;SRVR:BY2PR03MB313;H:tx30smr01.am.freescale.net;FPR:;SPF:Fail;MLV:sfv;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BL2FFO11FD044;1:qBZ3W38ewTz3ERi8DjECMn6eECpHD37FTTJILuvDB+cYQzirVT1oJ3yFbxQm1dLGXfU+TIyQwYLR6j21HU8gFZVojfAiyfOt2UqQb2gkdu3z0dLNGkjpHWQUI0Ib+t4QAFneWJe0a/uLeO1QhddmK2w8ifEKww8aW0vB0g3pXrdYYRbURVmM8obQJC4FOtj7ixQjSs/VPP81FWqbzBXlsptY4kujuN/7127/Q7xpVZDjHmaIzz8jZn8pubxsxjuj2cyeH3YDvbV3FnAahKTL8tS7ce/e8mWxCe95N4xEhl9J6Ui0opd+DI85vgEHeONfuHDaYkIcp+6QthONWX+zeHLdqvS0SLGbGk1wpOucoekon9Kt1MpXJfpPQCUTi3sXJ56cdYY/F9TQ9PhKSamQqG5Z6K3SuKJTQt6HkbcyN1K4e+59O4mmiekeZKlgSof4WrvCuxNaOFbPRardCo6+mAeDKChqoi/mgga4LrbM56a45adLF6JFv+Xv7pjIz2A0sv3379HAAu3yhESaMVP/BEwwoDvltD7w1688zmPoBaLhLWP8LgqlfiMtdMKp6fI+QK0cXYBEgEG7Iw95EZStGRoQOcUvQLCbYPhqOEsYbG74/EdgF6YrUAeR0vAYngU3 MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 04a7e19c-f7d1-41b8-e3b0-08d346397845 X-Microsoft-Exchange-Diagnostics: 1;BY2PR03MB313;2:73PuF6tPzgdthKFb8vMQHT9YOajzbKYshve2KehLkUWmzmluuwnZCxjLOAO6AMyciwwcszcDKtv5tkrWCpAKbkmGi+RVTDaGlR6D22qRpCGgr9OukiMDEm51hjdQLIoyNvS5my0mOZ21dTS2DisiMXjHvGe4YJcDqUKn419yO6IIelJHOyX8ZiMdbShLnicI;3:AiOlUlkA1bRILby4kGbPR5ZCfuTD2qSfFirdIydMiikrWXlf/ZHWRc+FjSY1ZXIYeLdBB3Wlx5hhhgSgFoRJXgxFNgBXHZdd2mjnXJfxZI2MXA1U70bH9bxOz42Q/FVIiaQDTnzEqYC+s0mZrhZvfiaZvm2MulD6rhcJSCSGkyB/UCY3eVTuhUCZM3EIW5D000BOI9HT4uFiH4lXhrLDnmvw5Y0zCzqHiUmFS1M/QP0=;25:irc22PjMsYGa9xTb/Q51m7DC1enAvBDwMBLj5JkuuxBBFtKwvbWHGzgkHMcMd5VpZ70TCaYUn+9VQngDaoGTormiauTkta+tiv70Hu1XhVy5/lrlXxp905MB4+1hlsg6gSO5xR1u8qOu/brk2bB/O3wMXBgyS+PE0145XEz2SmY7S5ekTd/jP93S2sxWUA/ZQ+XV+JCT/2C7oQxwSc5M33uq9xCZ5tsSuipIMWK1md9f6uGBEVGAhwANr9Cc1faTSuTE3+tI65BtbEcXLymQTPHYTwL38+O47sy3J8cLHQWpWok5ltSUHQhh9I1vfRPt0oda9tJS8IhT0oOASte47g== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY2PR03MB313; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(2401047)(5005006)(13024025)(13023025)(13017025)(13015025)(13018025)(8121501046)(3002001)(10201501046);SRVR:BY2PR03MB313;BCL:0;PCL:0;RULEID:(400006);SRVR:BY2PR03MB313; X-Microsoft-Exchange-Diagnostics: 1;BY2PR03MB313;4:BKfsrMNR70Oeq0ioSqPLFSZddhxGUG5UYA38CzR69jKRhDv1xv+LWnpVpsrRHZU1khcrPtAO7nJswx2zJZfqRGq74bf8zJa+XFUzXEV5e7parC4zPPvNiwlC69+xJ88Mfkd+Wi2zIdgN/J/Np+ugoLrTB+5OyAR6dCV20OM9mbNtcv8pB4hYGaTds7lTLopXkpVOYojlV8lxF+c7B4DQCxUpYycOSte6QdvQMxJp68QuNC0CGbUbwe1u6kP9dmlyRFphP6yuEggi5CnTkIq9Ff6/o+2HwQlPnS0Vyig/b4a9QlCXYx/75H7EVTV766ycnGORd5PAJ74HdVH1+xmCU1vUVSMoHRNt8mmLECMQLK9pRU2fWjqcw4G6RIcH6li4+awBk8obdTw8m2uGemOSAJnEtnE/A/Hl/m+G4bpZ/hoWq8GKdh2Znhb9zbkR78aZsy2k0AapzRE5Jq+/AfeZrA== X-Forefront-PRVS: 087474FBFA X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BY2PR03MB313;23:RVsMB2HW/5rf7r+X0kVUYyozlfF+Hipn7XCaolgNq4?= =?us-ascii?Q?FJBRtZwnU8OSOWtqYuTprIbHOspAmBHKo5uAWQPtS+mV8GxzY0XBEoBpJ8lG?= =?us-ascii?Q?hyHJKp4Ag6KhCJkGwkOdwVBNjnsxY77Y6XiBFi7JCJL55DmhnXIhaZacDXHW?= =?us-ascii?Q?ynkyyHk+kJTiwzDfCgRdsphynqR9J+NoGsMPsNHIxcD6PykosAys/TLGrRis?= =?us-ascii?Q?ZvSxDux7ID1IYI10/TKbQ6JY+WAi3fZ1zXPrplnw+lo7yTRTjpcT0ICrrDa7?= =?us-ascii?Q?mUVfdvkoKaY/Io3SQFArWlRRsrigwuRdHv03HQsROLnufYDFdvCVx7SHw5Io?= =?us-ascii?Q?ZoC5taZxHtEbCcs9q+RtNBRpi0SiAZ+XE7CVpYiFfjsmQLg7k87rIA1oYxdH?= =?us-ascii?Q?my3q7qD90xJU+ZFSHcVFXSR8MEZf6JW2M9Z0xczP8pzMRE662bt851IQWOLM?= =?us-ascii?Q?yym8YvvAO3o31QxQeSjPAQR8oQkMnC8FX7K3ooIq4P3P2dNZa/gRSNz/s7x9?= =?us-ascii?Q?QZ5aj5IFS3snF6LQMoJmABTQob1N/4MUydttc7s7Jmyj7wLhnz6tigZrTQBF?= =?us-ascii?Q?mr49yXyTO5YL0kmrufscEeSDUZYifwurbxd1LhOFRdxx/c+om/oGyRMAIe6Q?= =?us-ascii?Q?JgwXKxeH9UmGIxpKMWxRKw65H1n6sdL6nNTMGLI717RSMDW9WtMr4igYFB1W?= =?us-ascii?Q?/pZHtMT4m/3t3me9D7l66KwxEU8gFHpt0bQF/Bs8qgrY5EFleK9xtc5ozR6B?= =?us-ascii?Q?PnIXOeIdbMjw3sqAJf2APAA6alz7M40/EF0eIOzcHpRbc0mhTuRrOohLVDxx?= =?us-ascii?Q?vp7eQmqrsLKXV9Alwf52/cptnsU36tx7cnRqo5rxfjjkQk+4nYWgLgIERFwC?= =?us-ascii?Q?t2Sd9gTpB7vw4y+SgkBTc5JVX9ZXvPT5lT68TFW/SYsni7t8UI6tn04VV/i3?= =?us-ascii?Q?dWPblZPMS06xuh7s2N9ADI1yLjtelMlkEEno0dGZ4uyIr3jwZJLIOl/u3Q+l?= =?us-ascii?Q?JZEDVrL5jlnWH7Q9b4XZiMNGcZ/zJ3e7Sd+7ezOZE8vjwoYkjsgbrXC4bMxy?= =?us-ascii?Q?nJEH+JF+2nAKGIVVHhTscH7zUK?= X-Microsoft-Exchange-Diagnostics: 1;BY2PR03MB313;5:ve29yHDbcEaUK0OOfBRxM1AQGVU2JY2YY+KW5zxOpO4vxteV8Vot29EE6fuJUgwQYc31TwQLANqSGZRlZAWY9E4TTOwBC5ffYIiP1gtHsWbikUsPHYnNp69cKGen3WLCHlvc5CrDJtH6X4IVpI8OB6KTvOGYXxa9C2qgiqI4ayI=;24:hrDHju5BHJOZ3+qdMpC+2y6cxqjYskkXuRg0b6lQXhzGaT6Swnc536mpWi7d7KkdJIASYRW2np1XFEM1uDwdc6rCcv+grC7JoD4VRgIBfwk= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Mar 2016 03:35:03.2582 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e;Ip=[192.88.168.50];Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR03MB313 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 7975 Lines: 296 Some kind of NXP Layerscape SoC provides a MSI implementation which uses two SCFG registers MSIIR and MSIR to support 32 MSI interrupts for each PCIe controller. The patch is to support it. Signed-off-by: Minghuan Lian --- Change log v5: 1. drop nr_irqs from struct ls_scfg_msi v4: 1. do not register irq_enable irq_disable 2. shorten the chip name to "SCFG" v3: 1. call of_node_to_fwnode() v2: 1. rename ls1-msi to ls-scfg-msi 2. remove reg-names MSIIR MSIR 3. remove calling set_irq_flags() drivers/irqchip/Kconfig | 5 + drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-ls-scfg-msi.c | 240 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 246 insertions(+) create mode 100644 drivers/irqchip/irq-ls-scfg-msi.c diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig index fb50911..0f2a3c3 100644 --- a/drivers/irqchip/Kconfig +++ b/drivers/irqchip/Kconfig @@ -218,3 +218,8 @@ config IRQ_MXS def_bool y if MACH_ASM9260 || ARCH_MXS select IRQ_DOMAIN select STMP_DEVICE + +config LS_SCFG_MSI + def_bool y if SOC_LS1021A || ARCH_LAYERSCAPE + depends on PCI && PCI_MSI + select PCI_MSI_IRQ_DOMAIN diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile index 18caacb..37e12de 100644 --- a/drivers/irqchip/Makefile +++ b/drivers/irqchip/Makefile @@ -59,3 +59,4 @@ obj-$(CONFIG_ARCH_SA1100) += irq-sa11x0.o obj-$(CONFIG_INGENIC_IRQ) += irq-ingenic.o obj-$(CONFIG_IMX_GPCV2) += irq-imx-gpcv2.o obj-$(CONFIG_PIC32_EVIC) += irq-pic32-evic.o +obj-$(CONFIG_LS_SCFG_MSI) += irq-ls-scfg-msi.o diff --git a/drivers/irqchip/irq-ls-scfg-msi.c b/drivers/irqchip/irq-ls-scfg-msi.c new file mode 100644 index 0000000..0314bc8 --- /dev/null +++ b/drivers/irqchip/irq-ls-scfg-msi.c @@ -0,0 +1,240 @@ +/* + * NXP SCFG MSI(-X) support + * + * Copyright (C) 2016 NXP Semiconductor. + * + * Author: Minghuan Lian + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MSI_MAX_IRQS 32 +#define MSI_IBS_SHIFT 3 +#define MSIR 4 + +struct ls_scfg_msi { + spinlock_t lock; + struct platform_device *pdev; + struct irq_domain *parent; + struct irq_domain *msi_domain; + void __iomem *regs; + phys_addr_t msiir_addr; + int irq; + DECLARE_BITMAP(used, MSI_MAX_IRQS); +}; + +static struct irq_chip ls_scfg_msi_irq_chip = { + .name = "MSI", + .irq_mask = pci_msi_mask_irq, + .irq_unmask = pci_msi_unmask_irq, +}; + +static struct msi_domain_info ls_scfg_msi_domain_info = { + .flags = (MSI_FLAG_USE_DEF_DOM_OPS | + MSI_FLAG_USE_DEF_CHIP_OPS | + MSI_FLAG_PCI_MSIX), + .chip = &ls_scfg_msi_irq_chip, +}; + +static void ls_scfg_msi_compose_msg(struct irq_data *data, struct msi_msg *msg) +{ + struct ls_scfg_msi *msi_data = irq_data_get_irq_chip_data(data); + + msg->address_hi = upper_32_bits(msi_data->msiir_addr); + msg->address_lo = lower_32_bits(msi_data->msiir_addr); + msg->data = data->hwirq << MSI_IBS_SHIFT; +} + +static int ls_scfg_msi_set_affinity(struct irq_data *irq_data, + const struct cpumask *mask, bool force) +{ + return -EINVAL; +} + +static struct irq_chip ls_scfg_msi_parent_chip = { + .name = "SCFG", + .irq_compose_msi_msg = ls_scfg_msi_compose_msg, + .irq_set_affinity = ls_scfg_msi_set_affinity, +}; + +static int ls_scfg_msi_domain_irq_alloc(struct irq_domain *domain, + unsigned int virq, + unsigned int nr_irqs, + void *args) +{ + struct ls_scfg_msi *msi_data = domain->host_data; + int pos, err = 0; + + WARN_ON(nr_irqs != 1); + + spin_lock(&msi_data->lock); + pos = find_first_zero_bit(msi_data->used, MSI_MAX_IRQS); + if (pos < MSI_MAX_IRQS) + __set_bit(pos, msi_data->used); + else + err = -ENOSPC; + spin_unlock(&msi_data->lock); + + if (err) + return err; + + irq_domain_set_info(domain, virq, pos, + &ls_scfg_msi_parent_chip, msi_data, + handle_simple_irq, NULL, NULL); + + return 0; +} + +static void ls_scfg_msi_domain_irq_free(struct irq_domain *domain, + unsigned int virq, unsigned int nr_irqs) +{ + struct irq_data *d = irq_domain_get_irq_data(domain, virq); + struct ls_scfg_msi *msi_data = irq_data_get_irq_chip_data(d); + int pos; + + pos = d->hwirq; + if (pos < 0 || pos >= MSI_MAX_IRQS) { + pr_err("failed to teardown msi. Invalid hwirq %d\n", pos); + return; + } + + spin_lock(&msi_data->lock); + __clear_bit(pos, msi_data->used); + spin_unlock(&msi_data->lock); +} + +static const struct irq_domain_ops ls_scfg_msi_domain_ops = { + .alloc = ls_scfg_msi_domain_irq_alloc, + .free = ls_scfg_msi_domain_irq_free, +}; + +static void ls_scfg_msi_irq_handler(struct irq_desc *desc) +{ + struct ls_scfg_msi *msi_data = irq_desc_get_handler_data(desc); + unsigned long val; + int pos, virq; + + chained_irq_enter(irq_desc_get_chip(desc), desc); + + val = ioread32be(msi_data->regs + MSIR); + for_each_set_bit(pos, &val, MSI_MAX_IRQS) { + virq = irq_find_mapping(msi_data->parent, (31 - pos)); + if (virq) + generic_handle_irq(virq); + } + + chained_irq_exit(irq_desc_get_chip(desc), desc); +} + +static int ls_scfg_msi_domains_init(struct ls_scfg_msi *msi_data) +{ + /* Initialize MSI domain parent */ + msi_data->parent = irq_domain_add_linear(NULL, + MSI_MAX_IRQS, + &ls_scfg_msi_domain_ops, + msi_data); + if (!msi_data->parent) { + dev_err(&msi_data->pdev->dev, "failed to create IRQ domain\n"); + return -ENOMEM; + } + + msi_data->msi_domain = pci_msi_create_irq_domain( + of_node_to_fwnode(msi_data->pdev->dev.of_node), + &ls_scfg_msi_domain_info, + msi_data->parent); + if (!msi_data->msi_domain) { + dev_err(&msi_data->pdev->dev, "failed to create MSI domain\n"); + irq_domain_remove(msi_data->parent); + return -ENOMEM; + } + + return 0; +} + +static int ls_scfg_msi_probe(struct platform_device *pdev) +{ + struct ls_scfg_msi *msi_data; + struct resource *res; + int ret; + + msi_data = devm_kzalloc(&pdev->dev, sizeof(*msi_data), GFP_KERNEL); + if (!msi_data) + return -ENOMEM; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + msi_data->regs = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(msi_data->regs)) { + dev_err(&pdev->dev, "failed to initialize 'regs'\n"); + return PTR_ERR(msi_data->regs); + } + msi_data->msiir_addr = res->start; + + msi_data->irq = platform_get_irq(pdev, 0); + if (msi_data->irq <= 0) { + dev_err(&pdev->dev, "failed to get MSI irq\n"); + return -ENODEV; + } + + msi_data->pdev = pdev; + spin_lock_init(&msi_data->lock); + + ret = ls_scfg_msi_domains_init(msi_data); + if (ret) + return ret; + + irq_set_chained_handler_and_data(msi_data->irq, + ls_scfg_msi_irq_handler, + msi_data); + + platform_set_drvdata(pdev, msi_data); + + return 0; +} + +static int ls_scfg_msi_remove(struct platform_device *pdev) +{ + struct ls_scfg_msi *msi_data = platform_get_drvdata(pdev); + + irq_set_chained_handler_and_data(msi_data->irq, NULL, NULL); + + irq_domain_remove(msi_data->msi_domain); + irq_domain_remove(msi_data->parent); + + platform_set_drvdata(pdev, NULL); + + return 0; +} + +static const struct of_device_id ls_scfg_msi_id[] = { + { .compatible = "fsl,1s1021a-msi", }, + { .compatible = "fsl,1s1043a-msi", }, + {}, +}; + +static struct platform_driver ls_scfg_msi_driver = { + .driver = { + .name = "ls-scfg-msi", + .of_match_table = ls_scfg_msi_id, + }, + .probe = ls_scfg_msi_probe, + .remove = ls_scfg_msi_remove, +}; + +module_platform_driver(ls_scfg_msi_driver); + +MODULE_AUTHOR("Minghuan Lian "); +MODULE_DESCRIPTION("NXP Layerscape SCFG MSI controller driver"); +MODULE_LICENSE("GPL v2"); -- 1.9.1