From patchwork Thu Jan 5 08:10:35 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: 9498593 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 18A30606DE for ; Thu, 5 Jan 2017 08:10:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 04AE728066 for ; Thu, 5 Jan 2017 08:10:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EA19628156; Thu, 5 Jan 2017 08:10:08 +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 41C5C28066 for ; Thu, 5 Jan 2017 08:10:08 +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 1cP37d-0008Pc-12; Thu, 05 Jan 2017 08:10:05 +0000 Received: from mail-co1nam03on0053.outbound.protection.outlook.com ([104.47.40.53] helo=NAM03-CO1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cP36c-0006IQ-BT for linux-arm-kernel@lists.infradead.org; Thu, 05 Jan 2017 08:09:04 +0000 Received: from BN3PR03CA0113.namprd03.prod.outlook.com (10.174.66.31) by DM2PR0301MB0751.namprd03.prod.outlook.com (10.160.97.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.817.10; Thu, 5 Jan 2017 08:08:42 +0000 Received: from BL2FFO11FD050.protection.gbl (2a01:111:f400:7c09::106) by BN3PR03CA0113.outlook.office365.com (2603:10b6:400:4::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.829.7 via Frontend Transport; Thu, 5 Jan 2017 08:08:43 +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 BL2FFO11FD050.mail.protection.outlook.com (10.173.161.212) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.803.8 via Frontend Transport; Thu, 5 Jan 2017 08:08:42 +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 v0588CZn031372; Thu, 5 Jan 2017 01:08:38 -0700 From: Minghuan Lian To: , , Subject: [PATCH v2,7/9] irqchip/ls-scfg-msi: add LS1046a MSI support Date: Thu, 5 Jan 2017 16:10:35 +0800 Message-ID: <1483603837-4629-7-git-send-email-Minghuan.Lian@nxp.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1483603837-4629-1-git-send-email-Minghuan.Lian@nxp.com> References: <1483603837-4629-1-git-send-email-Minghuan.Lian@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131280773231285934; (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)(39410400002)(39840400002)(39850400002)(39380400002)(39400400002)(39860400002)(39450400003)(2980300002)(1109001)(1110001)(339900001)(199003)(189002)(97736004)(85426001)(2906002)(92566002)(104016004)(4326007)(5001770100001)(81156014)(6666003)(105606002)(68736007)(81166006)(106466001)(2950100002)(38730400001)(5003940100001)(77096006)(8936002)(8656002)(47776003)(8676002)(76176999)(230783001)(189998001)(50226002)(36756003)(48376002)(54906002)(305945005)(50986999)(7416002)(626004)(86362001)(356003)(50466002)(5660300001)(2201001)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:DM2PR0301MB0751; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11FD050; 1:B+YwE5qfIXZqF6PcOEuH0+F04DLLQh5AzOozAGWjm/hxY+ApHVo53EGLHP3xYxdvc5+U6wbl9tMpzHOGxNHrjQcoUQ+L7Q1b4VB8f8Wl2ku5xtrscJ9QZXsktsoTGSf+7VLhnTHZN4Ujo519v5CB7Iye0Q3QjeTG3/wCluSAqR/8TTEDbMEBEv6TlDNVVrXkX9E1ih+eIdugzxewQNYjrB554GzjcvJvky1a2mEdkQ4JgZBFNtT8e5V1DY8VfjP06Krwc44j5kSaDXu1nlGiNQ1604uAsAo52+KlqGaxKnASivkFRsn9gq6h8z0Zy6a1NUTV6aNad4RnnFlE5WhT8hpdS+/bSWH9xyfcZhd5WlZeL3Hzy1yZegDvat/lpKif/fUbOf2TBZWruOktkcU9SKty+j69ThOAHBmLFob9wDFwv1P9kYdARyArWEo7C0CLWZN7aARdPr3WcLRSO4qB96vMnitHcssqiuBe4Zsgjcc0xO3yTmKYImkvcImX3DdYSZ+b0ZEHONtwzKeNqiVdm8O7YngUqcq4no15MmlUOBPLF+KGOCAbX8mq5ShSg69Dbt8TpEStsXDSzI/BNP5W8FWm6YVHr0gfP/CnsWLi88QgawLDKRrgliYdMqkF+G1bTtvOw7+1sRw7ZGB/wIx5l++IN5aJ6BXiHdpiMDksE3d0DwoU4Uut5gxZ8zQYiENJXxQWeAvfmYH11yJnrCAkvdxHYDQ8yyXotQOu37f3RxY= MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 29e7660a-36b3-4047-b54f-08d4354210be X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:DM2PR0301MB0751; X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB0751; 3:NXYfQFYIuOwv889T8dytOApEx8B7Y8rr4VR3MMkZrsPHntRU+mXl+C/hRXkrXM88GxAZIfp0UwxNH/3ViCUxzr/wtiDnXk7RXZcKHIfW7rtgf7HahJyMIX4XngY1PMhtBBcWH1UxdT6A5eZnx569biLjckCxmGzAuzB5qJXFYtSfosFT9ZWlsoZOrNe3yh48gjq/MOYzZoO07lgKVJyaMM7qKWsLPwq9ZVAaHFiyFvLttEM3/rukVOoNeH6PmkPWPFrHdqg+l787lvFwp1T7RB3tSw8wut0wYGL0c13y8acg9jgGDVbQ7KU9skHaepF7cUIvDPyliZdTyhGi5ESDF42U2VxmBtjDm9UpgWm9ElAD2vXKrJjJ+p3mksCk3m5D; 25:IpkDLLnPGCA9KB1s/oD86YAip7pH761rY6c43BSOhSgYTM3+O00ysXAp4pAs9Qb53zfehNsmZEvendYV4mVXGHnzwXa4xrF4uc2teU0FMHATsmVoDemq81qR/09e9U+QyjDu9J0LWXyopl1HY3Umg2YuBpiBYspCLHfacKF5Lo9uO4edalzXVifKrG9M/8/BEcqoc6MoTErHtnFzAeXozRse5PXP2+jCbFdZT4G/5P+jYa5fKqupSti0p8io1QBkgMeUE2oKF8naopLwtSfh/SV7sIShB+HV27zOtWSMHLxdyV9lI3PH6fQY14BkM1KgYfzl2WSpfMQCRsV18ShrW1zoUnITLdTrypL0C4qe57cVqgP1UWJ6Xp1aOUOqDsSd3dm8lDIkuO/Ab4D6Rlq0k/FOwEpHvalieC1J24EKCGGda/o8t+j/j94Mb5Ba9N8hyq27bYFlgRClMAzXB5izTg== X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB0751; 31:YdwBNKvvcly0GJI3jwc/z2iwg4+zTzpPV5z9hTiFRKGhcHE3088pbjIaCZGxL3irsicR5VK3yVNW+1tHY5gM2x1AYhlEiH1A8hwxetAtRhcvXTz2DIQsaEg1QAAxwKoE/WBJoz+C6+cb8a10/cLMkHxnN8PRLVwu7R08fEQJzMV4ciMWQ0NGoxBmwdpAWu8/bNGIA9oUmabTZ9By31NPbzJJ2bVBYhzj5YoVZ17I1ZPSieru1w+RU/3Vw7edV9PkDi7H4rmMrJ00wdpXOS3Yex6dJGv5RdtE8bP+sBpc78s= 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)(13018025)(8121501046)(5005006)(13017025)(13023025)(13024025)(13015025)(10201501046)(3002001)(6055026)(6096035)(20161123565025)(20161123563025)(20161123561025)(20161123559025)(20161123556025); SRVR:DM2PR0301MB0751; BCL:0; PCL:0; RULEID:(400006); SRVR:DM2PR0301MB0751; X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB0751; 4:EOb/OrTu4Eq6aBB97TuTBhp0KjTGUTj+fnwD0Bj3t0ny7WTD+nPNMVR9XyGZmSa0asq3JXTIt7bSkBiQEAIH6uMVX/MtcunxcTlxWlgTqQ1JhajLIh2y3symMFCKz46NeLeEcemNCFfOaSgxPsiK+npCK9hYwzYEALXo00LFJKLLMjNrSs1OGNXZrxKFGbPT/Jojt3AAdXp/ShQ0kVVjSKdomnXIUb809fT74Afz/iB1mfY5wOtgN+QsixJl7A9CVdDTR8s9RpvJ6VGbjHCElIQ0hITnBjMfah6FQsxT0h1B7ZI6bm0l6NgThWM/NQYzx9uzb/Knn08rnPR+ZP0OX4GazIfWRoqlEz3/AeYpWTBy7uIFw8FMcT6YrUfZetlhXnm1AQhBO15Lk5Zf3pKYqBVvRAdmOPfMaZ6sbDXLmyuvBSVXOMQyJm8CspwfGAzbULo6aMC0j05RdSU6jqHGgnR4/g+XzL1zPcRbBKHBrJI9s9kyAXJPbhU9Qn3GPo3A6EkcAD+HGs1RnHOHVFPiU/JZ3u9A3WN0D/ZYrY68kh9Lyz8hprRGTZ+6FM83dfzUD+wvDXzCDEqxbEK9zMBSH6sgB21yPykKLVCLrEb94T5eQU7TXwVzyKw/qsM1sfp8FRrlqlzYw4rfHyv+6ch/CDRXND1l10rQU1ZqLq0D6870W0hQNTnxIBRRYM6LXt5kgKnsu9zc1/TqX01/hmK+3GlxM+9gg2Q+hHnWQhLTCeJqKvPGh3Hj83so1jbyLHSP X-Forefront-PRVS: 0178184651 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM2PR0301MB0751; 23:1C4RcAArb7BGhl+exY7E2HCLXTkgrtiK5qTb+/u?= =?us-ascii?Q?FqgRvdnZQd4FCkIP9PFbyAgdoMINXz2HadfO+qAunIeAeLuXZbdoM3Jv9Wtb?= =?us-ascii?Q?HbLJOt+PcnUIAE7Q2fHUXmTe7U8RYHk01j0Fqfq69JVcQCuCRciQX3zBvALE?= =?us-ascii?Q?hdK9IKincRHNQf6dbVuIJsWsbSscj673HniXpZw6OmSIS2BjNwcdyJDW6I7k?= =?us-ascii?Q?6n6ppppaDZEW9DtyCqV9+v4yx2PTkqnAkBP1213B2sVxz0P6NOeLq/xJ9Cjm?= =?us-ascii?Q?GHztsvW/Os4pK1k6Pl/E6NTTsNb41UfgyWHsUgtZ95rUoxeqsrCbUs3snRKZ?= =?us-ascii?Q?11Ir4J/cRC5el9CZ5Ilw816Ygmwq/rhooDW9/MD632Ev4ojM/avJok3qWmIN?= =?us-ascii?Q?MfqE4iu1LaniXkCjAZUR/EuWW3194njNYVP5JPwYnVVsfqyNQu3aEziuAv4A?= =?us-ascii?Q?aInbVsOSkRNUgg6v71LWKEdi6BoZg+m6f01fHnkFupje7yEsUQlI1YO2LyWi?= =?us-ascii?Q?aDS01YqHBC7uv3MSsqtcZljcMTGSutqB3JfXl6uV2uWDP7hPfzBUEbGZvxXI?= =?us-ascii?Q?j1tOJPKwLhzNvNFN+Eh5mYZDSyqGaMkkQ3cjTcLil6+12C/XOdsDJsGt0ijq?= =?us-ascii?Q?uco+uAJxmQY5k+SlsorTH4ovtO8OcdE07vQAVHVazVi+IP6ZkEEBZC4zFQBN?= =?us-ascii?Q?Cdgy0DTIsY3N7Brkem4j6GArv0/IO1VE8rrxsOKrCYWV1EqWsfmJjcSy02XC?= =?us-ascii?Q?cxNgRhSXny71RSj69JZiCdDmG0UCLXchsHP55/JXaujceJrX/pZsCGMldI4G?= =?us-ascii?Q?DhtmfduQ4e+hZetL8yyi7qqXWcZUqQsoampxfgx4v0TltLtIw4y94ZP7JBkD?= =?us-ascii?Q?jUHAOqBtpFomy9kix1nLy7jX4CqFFBFtIouD1cNkat/gx7qR7E6EW/1XoXv2?= =?us-ascii?Q?BkQ0HkE8yK9Wheuby0vXQRUnPmGICc+gOnmDLaU+84yexhK0XvmrLKHtQeia?= =?us-ascii?Q?tTbpajFhGmba3LYG0l//jNei3vUdHBZTylUUTam6DMBj8tON6admMx3Qlpb2?= =?us-ascii?Q?gwBqq6ESzlJJeo3e6awi60RGWU/E9Tnyu+OU8woG8e/HfTGgeRLZCV/Pfu7/?= =?us-ascii?Q?YxKuyRjouyme8dnVbC/hI21Ot0kA1K+vBYrixeZX3oczMWlREiAXan+qDRcu?= =?us-ascii?Q?wzLj9YX5vQPFut3KBsI65Gs0DxezMoUXlGIjdTi/FQowQypWUHeFGg+8peX6?= =?us-ascii?Q?0GLtOJrjFXinhknRgOMlB+RA2kJLysvxsPRKHB0W4qHDQya7VwEqfCysgvly?= =?us-ascii?Q?w7B1IRfm6kpkn269bF1YQ05A=3D?= X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB0751; 6:3VgQun8qPHo4gGx4HxWu/ZWdmMp4sBuco/uRO2KG9att9yMUB6XvEMsC3ypT2ELFqzMG6NUFLUz2PPJZsjjYDPvHurN6NG/l9KEJoDVJTeH2vFufhWwBCpKEIB4TBrKe7IHpmOJlxAj0YG/vVqMaG7AnUkBdTbIoJMlzW+9p7nIi4O+KlO2gbXY/pxsefw3Unm0TxgNBKdrsgiKbxGMEjd6DVXRehYRolaL5uU0N7XnOwYB3xs37m5RZDVOkV0ZUooOI6+kYlphlLAVQAIMSzgmzJb6jm8xldVc/9SuqyjyJlx0mTas7vCuXCSK8JiTPD8t3MyUP+xc3FtdpdNFUpD4G/xxUb7d599HaQaKQkcF13WKquGXxBeLlQ4teGau8aPdF6+PY1FEWywYNZqy5TDVEkgnudQ2qriJOY3YDJHBhxNjflsvnbLFuH5eCWpAf; 5:jhMoooFJp0rK3xrSu1fZj1wC6EOeTpf4VFpy5jTQ6uiDnoWYOpcQATD5uX8t1tRMo10bO4PG4ZTYy614YQpwhEgaYQsASqlcUex9j3H7NHdmSduzODhr3DxJRauHVCTYJlLzyJkdEGTR6r88kx44jN2l5yd0/B40uWVk20XmuoHC6hT43S5GXM0j2CCHIyAY; 24:ithfxVv2OGTQzz5q9qFBJUlwx7AJPis0DZC2scD9R48ILoG7SA+nuvGB2mZxadUFQT0RJ2GVsoBUCDmEFrW9v8ACjKVSU78by3wWjms/KY8= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB0751; 7:tH7SJyGO+PCxpBq34ziObF2ZxUjupNhmAtUDXwWSnKqxHODlOAxidSrG8HTmc/fKHSejFv6/kbzJRpOIXOjdPLIuMWJNJAtpRww4EE2Ej27aw2Zg2Xy6aDQCWthwN55o+nM1FY4ZS9k5NWGRuVYOM4K8/GLFFQbJAwOxrx++B/V/xtlMrhvChqinAoOqaD+2TNEQePX8XKp97jJ5Drt9eS3/05sdj2tdqGip/lWCQIQVEv6HBAk/wOejsvkqy8gTshmZuzlBAajdaY4lc6eg6YSDbC/IExfyR1FBn7gL4WhvIL9QNNNmqvvzL/raQxl6vwOXRKvNKnyI0JwzEaRqDz2UJ2LMptwlT8stheqVPnwgN8ChAdm+DyS5o7nDS/mRWBFe/B7VmHFfJ/hafjorM6KSyiNR4R8hTYZ2Ws5A8WQD044jfdrzpHUxvyIkUUzFwWK5i3EQ+4qeorCRPDFn/Q== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Jan 2017 08:08:42.8633 (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: DM2PR0301MB0751 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170105_000902_630156_F2DAF0F2 X-CRM114-Status: GOOD ( 20.67 ) 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 --- v2-v1: - MSI dts node change has been merged into the patch 6/9 drivers/irqchip/irq-ls-scfg-msi.c | 161 +++++++++++++++++++++++++++++--------- 1 file changed, 126 insertions(+), 35 deletions(-) diff --git a/drivers/irqchip/irq-ls-scfg-msi.c b/drivers/irqchip/irq-ls-scfg-msi.c index cef67cc..67547bd 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,83 @@ 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[] = { + { .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 +265,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 +304,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 +317,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",