From patchwork Tue Jan 17 09:32:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "M.h. Lian" X-Patchwork-Id: 9520291 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6F64F60244 for ; Tue, 17 Jan 2017 09:31:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5EB25284EB for ; Tue, 17 Jan 2017 09:31:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 504CB28516; Tue, 17 Jan 2017 09:31:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 915C5284EB for ; Tue, 17 Jan 2017 09:31:26 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cTQ6v-0003Bi-GV; Tue, 17 Jan 2017 09:31:25 +0000 Received: from merlin.infradead.org ([2001:4978:20e::2]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cTQ6T-0002E0-7D for linux-arm-kernel@bombadil.infradead.org; Tue, 17 Jan 2017 09:30:57 +0000 Received: from mail-sn1nam02on0054.outbound.protection.outlook.com ([104.47.36.54] helo=NAM02-SN1-obe.outbound.protection.outlook.com) by merlin.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cTQ6S-0000nB-21 for linux-arm-kernel@lists.infradead.org; Tue, 17 Jan 2017 09:30:56 +0000 Received: from CY1PR03CA0037.namprd03.prod.outlook.com (10.174.128.47) by CY1PR0301MB0748.namprd03.prod.outlook.com (10.160.159.154) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.845.12; Tue, 17 Jan 2017 09:30:49 +0000 Received: from BN1AFFO11FD026.protection.gbl (2a01:111:f400:7c10::111) by CY1PR03CA0037.outlook.office365.com (2603:10b6:600::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.845.12 via Frontend Transport; Tue, 17 Jan 2017 09:30:49 +0000 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=fail action=none header.from=nxp.com; nxp.com; dkim=none (message not signed) header.d=none; Received-SPF: Fail (protection.outlook.com: domain of nxp.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BN1AFFO11FD026.mail.protection.outlook.com (10.58.52.86) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.803.8 via Frontend Transport; Tue, 17 Jan 2017 09:30:48 +0000 Received: from lmh.ap.freescale.net (lmh.ap.freescale.net [10.193.20.69]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id v0H9UGHD018177; Tue, 17 Jan 2017 02:30:44 -0700 From: Minghuan Lian To: , , Subject: [PATCH v3 7/9] irqchip/ls-scfg-msi: add LS1046a MSI support Date: Tue, 17 Jan 2017 17:32:41 +0800 Message-ID: <1484645563-29877-8-git-send-email-Minghuan.Lian@nxp.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1484645563-29877-1-git-send-email-Minghuan.Lian@nxp.com> References: <1484645563-29877-1-git-send-email-Minghuan.Lian@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131291190484268295; (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)(336005)(7916002)(39840400002)(39860400002)(39450400003)(39400400002)(39410400002)(39380400002)(39850400002)(2980300002)(1109001)(1110001)(339900001)(189002)(199003)(50466002)(81166006)(48376002)(8936002)(8676002)(2950100002)(305945005)(86362001)(36756003)(81156014)(5660300001)(7416002)(97736004)(189998001)(30001)(6666003)(5001770100001)(2906002)(50226002)(2201001)(4326007)(85426001)(77096006)(5003940100001)(38730400001)(105606002)(50986999)(92566002)(8656002)(68736007)(104016004)(230783001)(106466001)(356003)(47776003)(76176999)(626004)(54906002)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR0301MB0748; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1AFFO11FD026; 1:67w/gDc30+4GYBZT5eAMLpLstZVb0Iix5v09KwrkpfhE4pG0ZGcfQmHGKum0j15qe7PLODPdKju6NagkXQqmbjmTt4HXcKBLszuSKaRKhUqDmAH9RHC0ROgaN6nf4nAnCp5mp8sVo18W49rkh0V6fSA9K9iFPP59l6JnHC4JpD9cB5LeEV10vfc+gK9/tWxg5mnbqv6FqpmnjVODTl9gHaqgkiZEKMyye6rBfe8sweyUpc1CKKZ7+Jnr3XZ3Ha/ItiTg33fkXr1Dv3dsNAEZkEQcOJXP0McjpBRoxhApoh8UsyeIrZyxBghf9aOO++0eHX9xbLtTx39hl8ws725Vpv7chvwYmZXRNPkJLL6+9e8X4s1L5FVZLPODsElNMs+yDWnKdYnAiHHXLwLFK8JqOnIhqn8eDTtbaH/iz4PgUmspB2OEsMp465pt4vnZhXfkwwKNIZdUdqT/BsnWVlied3LZoftjVCSIqx16he9MHrlP7eDGSpAKHHNJoDc4HACsWswSusaju+Wwzge1pNZ+1yVMdzrgMnAabC0cwIsu0GcBb3dkr4SP4SfXOyvw2mXwmU/NSv2vPStnYTZDdyq0E1W1PtCRPGgoG4CO/6wdF5HtwXWUtjgDBB2ZrEWKx03LgsIDi0HKAefjwRlAhSJreyCPMk0z9r6jDzawxWSGkoB7geCPCTBxVPf9WjkiKiOesGRrBEQu2C9pnvB8uRdKQwIKZfKuzA8AXGwT/mk/lAA= MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 5ad4a82c-d35d-4e14-93aa-08d43ebb8568 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:CY1PR0301MB0748; X-Microsoft-Exchange-Diagnostics: 1; CY1PR0301MB0748; 3:CypdFEYYUuZhzRD3j3JFLdIbsB/NE65Mmq9TMvTTi+RGU822qoVDQQzAVLDOPYZwmimxo7GF0aTnoN8s05O8jH7ImE6OvZExTrI+ax8vYqC3UWExnCH01mvhBeGmw0ctcCYc+i49nTw/6e0GfdvKGEEzhgeydshzvG1cXeWIlcqqXCXk+jmG+8LgQKE0FdTuCtdCV42VMQxXex0pNhmNsawKCGfbo457NsQ4kvyGzZMLQdZZK56dAkxsk1yo1PuKqRysErLwnix4DTK2bJ8Jqbsu9vgj0sAx0sW1/VCy7stLC/2ScrH9LaMrvGtdGoVVdpG31HwS4+yJL+2qCk2VzdxNNdOk082v8bKdBPKMqDLwLcD3stUblmFE73OHjt/R; 25:99Wd35F7udCwWGGqryl/BEPlla+81wArAZRNyvrb4TK/IZWDMZesh9MBpO+/um9Cntn3WjFWFZIlJasCJbTe2dSSUXK7okrO3IBC9I0M8Vvsh3HmgdY0TSTba7oVI0O2oYBpgHp0SlbE8U9ESSoFmqpWg0Anhd5ZznwDbrBaVLPkvVENtsCX6WRmPcSYFatDVCnlF1Y1By0tZ9tzvFHPnh41eWkAbUsIBTHgk+LUg177p87vOvwljB/C4taa1oSmv3Q/iWasomJ6uyEwsR7fIWmOJwxnLtuISad5XxompX0b9SL2RtfcfyaYJoEs/PFkG0OElDCizQAe9RuCShxboLmIXm5c04wk0+GzeRYxUzTaIT4nixyVeRrHCTZeS7zVBQdZ9oOr7VUJtw14XA4Pu4SjCsOxFkn7DXgy8MLatrGGYpxRwMFX/sPdRIt65ogbtfwHyuOCJoaG5c4xt76Fgg== X-Microsoft-Exchange-Diagnostics: 1; CY1PR0301MB0748; 31:9CaJxzU+oaa+GY471TWukoVS1xrsV3D/ZZ7ZqTW5LhLQ5TKNji02Jn332i9PuGqRi7GC2EiDck/DFfhgr+odYSeuHVVBhE+Pq535InR1/fkYJ7v/phZIzm8OAEQRKSjHDaBUl85uG2oYM79QVPzr804buQJVbDs06HDYEg43+TPTzNNHmljER3NwIYbQWZyv70rUIrHuVSD+yTLleQMu5JSRd4OKmPbMP1Ms/w07XsmH4SG9Aft0VV0Lzy8QKC1vQPXtpEYxfWpmN+vapkRKTQngvx4p9YtPQkVCMqatYEQ= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6095060)(601004)(2401047)(8121501046)(5005006)(13024025)(13015025)(13023025)(13018025)(13017025)(10201501046)(3002001)(6055026)(6096035)(20161123561025)(20161123556025)(20161123563025)(20161123559025)(20161123565025); SRVR:CY1PR0301MB0748; BCL:0; PCL:0; RULEID:(400006); SRVR:CY1PR0301MB0748; X-Microsoft-Exchange-Diagnostics: 1; CY1PR0301MB0748; 4:j38Sve/aYR0JLK0RAnraye1Ylo206vlKE+JGVNqLPr4Oe+2RHx+C4UzlDAdqiqoAwCe3QVQ8D+t5BYA2rpP+y0dOTMNHJqHH1jNpKIv/NJNrANXY9UjbYuKmDUfZ05s/waUY/9lqwLJ7fakbhXNKOPr/I9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EVfCF929RbU6g+hXDAeBph+qJxsexUY9jnX3k3jOkYrh2Kjpdnt14hnxi?= =?us-ascii?Q?9F5Oa9teVksdcP+AK5fdIIKQf6H0ecT3IKrlff9EY6GBykQ8/A44eTqk/6vq?= =?us-ascii?Q?/w2sVAzrZLrCTVXt+xXixZUG6zyS+gqgH8T+yVw+VIdhC?= X-Microsoft-Exchange-Diagnostics: 1; CY1PR0301MB0748; 6:KjEjqbaR0vbdlxaLBLKZghu0y6dyVucxrZXV6N4LPFQ8mTVQLb0W2nSIRZFgQbAPzuqB1GQlJhGJdCUF8j2kmwxWh2rDozK8zsF2Kwn8N47Kr6toZIbqQiuPraiam/q72ANEtisnTmX9qd9UhddcHqRb1+JV//CNogA99lj67rJbDklO/1aUA8ks7zrk2qPxO3bv3kpA/26e+uGSXcJ5hax80IgCZP3nYO43SpvojvlQVu04DnuWXAse28LO89NVHVlmd3phl392O1GHJH0NvILvAN2W82lhWmgiSrnL3r8PxWn41syH0wYSczYy9snHfNrrbc+I1QeLGSHVp88RljrJP0KCmjP9CqPt7uF12TC12e18sNEZy8e/4Aa63NCbzeF5A6ad2mhn7PyGjqX0qaKcyLepVa3QKy6ZD5kzpSDqLlYFvTbMs6aZova8lizv; 5:M+TysmsOVtifk3mYWCz08Qi2mIgMctD3fqaGd4FAl82rx3V45LyPRD6SO1kKF53uSZ+tsHwcYNy2CAs9wOsT36UKdSpmQkydRit4NxfihnLk/oCt8bcpBq5wtDO0v4JaW1tSkafX1VqfAw3+1o6iqxP9Qh5Sh/kLHfrlX1fFHEKmwH7Y+w1YXgW5aZnwRgTk; 24:sVzQLAf/1n9QVs/YD1fDs4XuWL9ptr84h6wOpV74pJWwLj+I48kuvOS5C04mH0DurhsbiZfIowCyR+z3G6yZhuLZ9PB7MrNK/K1tA9n0uZc= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY1PR0301MB0748; 7:CmKZ9mwK2/+m4ToZCK67a0rHIMbn50D17JtLdpgVw0wdMY6GCoKrL3sKz0qZJJRsaqhB/ar4MTZjF5I2hBt4Uee43iAReIRmPab3pDnYOAvbOh26ArRrKAI6ezAovMQ1huG0DRwix5nl7upw+xBrd1MXZ7S6HpZPkJJDeNzDRaMUM4GMtGuO5UF8DmF8oJ8jUjZzuR8FR5CMcZV1G/jDI06r7zhmRlie34Gu/WqWsxdUeH39x7MqurXQYpXtXDnxn7mvEmX/n2QJiqmMOYZYlt3RWFkLm/r/MKO//x+S7WIg9uVPokD5VO3cA/9lPIIqHGMedk1JZc9QfMO7UbCpByWCdkTD2BXfiDu2mUbvjkMsK3QSXx6YvPbxTEJ4w2ZyFmtyvI3Lj6PV5CynSQtEJqieM1BrDmkWzM6CrhEi7Ez8mu+sNMWvDM7CMuTusgjm6PsFMgsGPIW9xOflg13g4w== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jan 2017 09:30:48.1460 (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: CY1PR0301MB0748 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170117_043056_241844_EBDFABDF X-CRM114-Status: GOOD ( 23.03 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rob Herring , Jason Cooper , Roy Zang , Marc Zyngier , Stuart Yoder , Yang-Leo Li , Minghuan Lian , Scott Wood , Mingkai Hu Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP LS1046a includes 4 MSIRs, each MSIR is assigned a dedicate GIC SPI interrupt and provides 32 MSI interrupts. Compared to previous MSI, LS1046a's IBS(interrupt bit select) shift is changed to 2 and total MSI interrupt number is changed to 128. The patch adds structure 'ls_scfg_msir' to describe MSIR setting and 'ibs_shift' to store the different value between the SoCs. Signed-off-by: Minghuan Lian --- v3-v2: - keep the old misspelled compatible strings v2-v1: - MSI dts node change has been merged into the patch 6/9 drivers/irqchip/irq-ls-scfg-msi.c | 165 ++++++++++++++++++++++++++++++-------- 1 file changed, 130 insertions(+), 35 deletions(-) diff --git a/drivers/irqchip/irq-ls-scfg-msi.c b/drivers/irqchip/irq-ls-scfg-msi.c index cef67cc..0b1f34d 100644 --- a/drivers/irqchip/irq-ls-scfg-msi.c +++ b/drivers/irqchip/irq-ls-scfg-msi.c @@ -17,13 +17,24 @@ #include #include #include +#include #include #include #include -#define MSI_MAX_IRQS 32 -#define MSI_IBS_SHIFT 3 -#define MSIR 4 +#define MSI_IRQS_PER_MSIR 32 +#define MSI_MSIR_OFFSET 4 + +struct ls_scfg_msi_cfg { + u32 ibs_shift; /* Shift of interrupt bit select */ +}; + +struct ls_scfg_msir { + struct ls_scfg_msi *msi_data; + unsigned int index; + unsigned int gic_irq; + void __iomem *reg; +}; struct ls_scfg_msi { spinlock_t lock; @@ -32,8 +43,11 @@ struct ls_scfg_msi { struct irq_domain *msi_domain; void __iomem *regs; phys_addr_t msiir_addr; - int irq; - DECLARE_BITMAP(used, MSI_MAX_IRQS); + struct ls_scfg_msi_cfg *cfg; + u32 msir_num; + struct ls_scfg_msir *msir; + u32 irqs_num; + unsigned long *used; }; static struct irq_chip ls_scfg_msi_irq_chip = { @@ -55,7 +69,7 @@ static void ls_scfg_msi_compose_msg(struct irq_data *data, struct msi_msg *msg) 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; + msg->data = data->hwirq; } static int ls_scfg_msi_set_affinity(struct irq_data *irq_data, @@ -81,8 +95,8 @@ static int ls_scfg_msi_domain_irq_alloc(struct irq_domain *domain, 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) + pos = find_first_zero_bit(msi_data->used, msi_data->irqs_num); + if (pos < msi_data->irqs_num) __set_bit(pos, msi_data->used); else err = -ENOSPC; @@ -106,7 +120,7 @@ static void ls_scfg_msi_domain_irq_free(struct irq_domain *domain, int pos; pos = d->hwirq; - if (pos < 0 || pos >= MSI_MAX_IRQS) { + if (pos < 0 || pos >= msi_data->irqs_num) { pr_err("failed to teardown msi. Invalid hwirq %d\n", pos); return; } @@ -123,15 +137,17 @@ static void ls_scfg_msi_domain_irq_free(struct irq_domain *domain, static void ls_scfg_msi_irq_handler(struct irq_desc *desc) { - struct ls_scfg_msi *msi_data = irq_desc_get_handler_data(desc); + struct ls_scfg_msir *msir = irq_desc_get_handler_data(desc); + struct ls_scfg_msi *msi_data = msir->msi_data; unsigned long val; - int pos, virq; + int pos, virq, hwirq; 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)); + val = ioread32be(msir->reg); + for_each_set_bit(pos, &val, MSI_IRQS_PER_MSIR) { + hwirq = ((31 - pos) << msi_data->cfg->ibs_shift) | msir->index; + virq = irq_find_mapping(msi_data->parent, hwirq); if (virq) generic_handle_irq(virq); } @@ -143,7 +159,7 @@ 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, + msi_data->irqs_num, &ls_scfg_msi_domain_ops, msi_data); if (!msi_data->parent) { @@ -164,16 +180,87 @@ static int ls_scfg_msi_domains_init(struct ls_scfg_msi *msi_data) return 0; } +static int ls_scfg_msi_setup_hwirq(struct ls_scfg_msi *msi_data, int index) +{ + struct ls_scfg_msir *msir; + int virq, i, hwirq; + + virq = platform_get_irq(msi_data->pdev, index); + if (virq <= 0) + return -ENODEV; + + msir = &msi_data->msir[index]; + msir->index = index; + msir->msi_data = msi_data; + msir->gic_irq = virq; + msir->reg = msi_data->regs + MSI_MSIR_OFFSET + 4 * index; + + irq_set_chained_handler_and_data(msir->gic_irq, + ls_scfg_msi_irq_handler, + msir); + + /* Release the hwirqs corresponding to this MSIR */ + for (i = 0; i < MSI_IRQS_PER_MSIR; i++) { + hwirq = i << msi_data->cfg->ibs_shift | msir->index; + bitmap_clear(msi_data->used, hwirq, 1); + } + + return 0; +} + +static int ls_scfg_msi_teardown_hwirq(struct ls_scfg_msir *msir) +{ + struct ls_scfg_msi *msi_data = msir->msi_data; + int i, hwirq; + + if (msir->gic_irq > 0) + irq_set_chained_handler_and_data(msir->gic_irq, NULL, NULL); + + for (i = 0; i < MSI_IRQS_PER_MSIR; i++) { + hwirq = i << msi_data->cfg->ibs_shift | msir->index; + bitmap_set(msi_data->used, hwirq, 1); + } + + return 0; +} + +static struct ls_scfg_msi_cfg ls1021_msi_cfg = { + .ibs_shift = 3, +}; + +static struct ls_scfg_msi_cfg ls1046_msi_cfg = { + .ibs_shift = 2, +}; + +static const struct of_device_id ls_scfg_msi_id[] = { + /* The following two misspelled compatibles are obsolete */ + { .compatible = "fsl,1s1021a-msi", .data = &ls1021_msi_cfg}, + { .compatible = "fsl,1s1043a-msi", .data = &ls1021_msi_cfg}, + + { .compatible = "fsl,ls1021a-msi", .data = &ls1021_msi_cfg }, + { .compatible = "fsl,ls1043a-msi", .data = &ls1021_msi_cfg }, + { .compatible = "fsl,ls1046a-msi", .data = &ls1046_msi_cfg }, + {}, +}; +MODULE_DEVICE_TABLE(of, ls_scfg_msi_id); + static int ls_scfg_msi_probe(struct platform_device *pdev) { + const struct of_device_id *match; struct ls_scfg_msi *msi_data; struct resource *res; - int ret; + int i, ret; + + match = of_match_device(ls_scfg_msi_id, &pdev->dev); + if (!match) + return -ENODEV; msi_data = devm_kzalloc(&pdev->dev, sizeof(*msi_data), GFP_KERNEL); if (!msi_data) return -ENOMEM; + msi_data->cfg = (struct ls_scfg_msi_cfg *) match->data; + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); msi_data->regs = devm_ioremap_resource(&pdev->dev, res); if (IS_ERR(msi_data->regs)) { @@ -182,23 +269,37 @@ static int ls_scfg_msi_probe(struct platform_device *pdev) } 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); + msi_data->irqs_num = MSI_IRQS_PER_MSIR * + (1 << msi_data->cfg->ibs_shift); + msi_data->used = devm_kcalloc(&pdev->dev, + BITS_TO_LONGS(msi_data->irqs_num), + sizeof(*msi_data->used), + GFP_KERNEL); + if (!msi_data->used) + return -ENOMEM; + /* + * Reserve all the hwirqs + * The available hwirqs will be released in ls1_msi_setup_hwirq() + */ + bitmap_set(msi_data->used, 0, msi_data->irqs_num); + + msi_data->msir_num = of_irq_count(pdev->dev.of_node); + msi_data->msir = devm_kcalloc(&pdev->dev, msi_data->msir_num, + sizeof(*msi_data->msir), + GFP_KERNEL); + if (!msi_data->msir) + return -ENOMEM; + + for (i = 0; i < msi_data->msir_num; i++) + ls_scfg_msi_setup_hwirq(msi_data, i); + 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; @@ -207,8 +308,10 @@ static int ls_scfg_msi_probe(struct platform_device *pdev) static int ls_scfg_msi_remove(struct platform_device *pdev) { struct ls_scfg_msi *msi_data = platform_get_drvdata(pdev); + int i; - irq_set_chained_handler_and_data(msi_data->irq, NULL, NULL); + for (i = 0; i < msi_data->msir_num; i++) + ls_scfg_msi_teardown_hwirq(&msi_data->msir[i]); irq_domain_remove(msi_data->msi_domain); irq_domain_remove(msi_data->parent); @@ -218,14 +321,6 @@ static int ls_scfg_msi_remove(struct platform_device *pdev) return 0; } -static const struct of_device_id ls_scfg_msi_id[] = { - { .compatible = "fsl,1s1021a-msi", }, /* a typo */ - { .compatible = "fsl,1s1043a-msi", }, /* a typo */ - { .compatible = "fsl,ls1021a-msi", }, - { .compatible = "fsl,ls1043a-msi", }, - {}, -}; - static struct platform_driver ls_scfg_msi_driver = { .driver = { .name = "ls-scfg-msi",