From patchwork Mon Apr 30 06:27:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nipun Gupta X-Patchwork-Id: 10370879 X-Patchwork-Delegate: bhelgaas@google.com 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 DE80160234 for ; Mon, 30 Apr 2018 06:28:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE68D287B5 for ; Mon, 30 Apr 2018 06:28:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C282D287C8; Mon, 30 Apr 2018 06:28:52 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1FD44287B5 for ; Mon, 30 Apr 2018 06:28:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752006AbeD3G2t (ORCPT ); Mon, 30 Apr 2018 02:28:49 -0400 Received: from mail-he1eur01on0089.outbound.protection.outlook.com ([104.47.0.89]:22125 "EHLO EUR01-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751854AbeD3G2o (ORCPT ); Mon, 30 Apr 2018 02:28:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=qVeDFBdK2ZXg1A9kjdH58jcDdysu3NfmqWLh2ByHBu0=; b=H/BIUoTAPJ6MxS6ZIrbzJicLpCh0ooPcqEj9MM6ssGRl0cfoj4dnDajsaMK8QfuxDgwMON/V20CddnmTgZRlsJC/FQaWEzxgTehCS/y3H0JD/VRGJlvmgILJcevV0plpwYe/4HxI9Yf7ud6FNyflx8ECeqzTzD9Gy2j440bicxM= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=nipun.gupta@nxp.com; Received: from b27504-OptiPlex-790.ap.freescale.net (14.142.187.166) by AM4PR0401MB2418.eurprd04.prod.outlook.com (2603:10a6:200:51::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.715.18; Mon, 30 Apr 2018 06:28:36 +0000 From: Nipun Gupta To: robin.murphy@arm.com, will.deacon@arm.com, robh+dt@kernel.org, robh@kernel.org, mark.rutland@arm.com, catalin.marinas@arm.com, gregkh@linuxfoundation.org Cc: hch@lst.de, joro@8bytes.org, m.szyprowski@samsung.com, shawnguo@kernel.org, frowand.list@gmail.com, bhelgaas@google.com, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-pci@vger.kernel.org, bharat.bhushan@nxp.com, stuyoder@gmail.com, laurentiu.tudor@nxp.com, leoyang.li@nxp.com, Nipun Gupta Subject: [PATCH v4 4/6] iommu: arm-smmu: Add support for the fsl-mc bus Date: Mon, 30 Apr 2018 11:57:19 +0530 Message-Id: <1525069641-8523-5-git-send-email-nipun.gupta@nxp.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1525069641-8523-1-git-send-email-nipun.gupta@nxp.com> References: <1524824826-29473-1-git-send-email-nipun.gupta@nxp.com> <1525069641-8523-1-git-send-email-nipun.gupta@nxp.com> MIME-Version: 1.0 X-Originating-IP: [14.142.187.166] X-ClientProxiedBy: PN1PR0101CA0006.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c00:e::16) To AM4PR0401MB2418.eurprd04.prod.outlook.com (2603:10a6:200:51::23) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(4534165)(7168020)(4627221)(201703031133081)(201702281549075)(5600026)(2017052603328)(7153060)(7193020); SRVR:AM4PR0401MB2418; X-Microsoft-Exchange-Diagnostics: 1; AM4PR0401MB2418; 3:3+xC1XijafBn2cQdhkAQQ0AbaQ6D8Ht8u3Je0dlniTDrgPuSVCkQFM2vHBbjsXz0tbBEuWckpBsI8Olmx8wAPMfzwJzawYV225I5CSqtLsOIBUjx4Vuufe95subbpGMbpSC17zdyNNhYzl/cITEzy+dVMmzC9yW2VquDl7yX5M4r5BElbh3buhhQMO5sRftXr15ZwPZpZg76x2FJkGzS5YV87pR4gyvjZ0ecx2Vh7BnhpKVBGy9uXf1nNIadIcqs; 25:eRZDI0s3bGHOI3Lcz3ntY+RT4pmePipbqiYB62u5hhLG/hr01bKTQzDv6KszW/qKbGcspOY6fpBUashndDlDx4qmFvr51vTPO07G7tupet6sy1B22ARTbEMVHqdDBBH9qqPC3Kz6EacI0yDh+SRa1NBu43PKlybDBqFwndMYUdh2r4Vq6Oof3HxHaXH8R7eXT1TOKI5Ugixy7BDjqylTzPAJ1l0R8VljmMjpS7k8eDAkyDqIhe+q0kuMkIcdx29DBKVbm3FEN8MxIQChKKKb/jXCaairjaLlaokgd8cgQ7xV+d7zz0lSS1uwG6vMrXIyOurFo7Yih293UH8dVbiVJA==; 31:YiSHiWeV/A/gFygTUzpiY86GhKh5rCjTeEgBnkvaTowlRpzsMdm1SdMd+JwGeAWjvpk/2uBGi4coff2P4HKy7qC+cXgWcKZWuUXHVrj3eKt8YRje4T3rsmsb7QYxxVi0caLXKYhJ/D8iJcUaePQESQQDPSg4gLPbyAZeBT+yyvu08uJ52oQZGzHwjHx43Ir9Oyn1b6JAqInoprgGj8mPBGP57utLIcPpfCJLNsCRftE= X-MS-TrafficTypeDiagnostic: AM4PR0401MB2418: X-Microsoft-Exchange-Diagnostics: 1; AM4PR0401MB2418; 20:iRHbUwiEMO1SR2Uaf6DDW1VDUMpS85Zj/kcCLwPDA2stu5w3Fn6+4qOS0yyMoKz5FDB5Xe6NzWiy7oiu3snOO2WhM8/LVTaX0OSA682LmUGESXMM+QZeFPoYt6Su73GrZpWAYauFahbIhHm9JjsDgiGvWnmUAJQYe9UDP4/9zBbL2UELYbK8857RV2BSOmxSHtLtRfk4JoOALw/QiVLYORtsK2HMsCZjoZTuefFQF9vzu/ct+1KDmeVSMK/XFCV1haIiJRFrEG8YnKtqt/tiSgOkDETmFkVTT4sejX7BHVOX1PZUHVpa1lmv5OcJwFSOpOhgRLN0UpeUIWfdLPUvH+HlGiIp86XiMM0oSAM9RqULHk8BexFKfxDO1LtVDSTC+VD3q8Kra/ThFyOBcSX85h2CV981B/6U6J+NNAYOYZwnjdPUKPewyBHb0+mRekkmZUszEPN5iVhzo/xkTNIhBnk/KW4JSWIH6+RprL2pFCpgPDDLzbME8hFjaOfBdT3n; 4:G2k4nPgiuh2alHqGzMFMFQCzhukzfH16Xp8aOr6Xe6g+EdvKrdu5F7WCg1U6DOCbLzpBfxQm/JmJgsvYfzx3qI9wcML7EKHz8vQ1+RFDoGAMUweGd3kFG6YIgoTrlHEKgqIPDJL+AmOtyNn69xfwdaA/26LK1Cl1Zx8rtKFHLpWE9wFPxCPS+dZUkWmZnIIvUVjkdVmMKqLYHFGOIWm1lUsJ9zKVipeWAb+sWgKY+t449x1oeo75BEE9MI99fDQxrK+oyT+3jNg4gA20hVqslIfCHEqqI/pp9DsOcQQ4+IDgVDwx5NaG1X0yBLmyhVtm X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3002001)(93006095)(93001095)(3231254)(944501410)(52105095)(10201501046)(6055026)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123562045)(20161123564045)(20161123558120)(6072148)(201708071742011); SRVR:AM4PR0401MB2418; BCL:0; PCL:0; RULEID:; SRVR:AM4PR0401MB2418; X-Forefront-PRVS: 0658BAF71F X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(396003)(39860400002)(39380400002)(376002)(366004)(346002)(189003)(199004)(36756003)(7736002)(52116002)(5660300001)(105586002)(106356001)(486006)(48376002)(50466002)(316002)(2616005)(55236004)(956004)(11346002)(446003)(476003)(51416003)(16526019)(186003)(6486002)(76176011)(44832011)(47776003)(26005)(97736004)(5009440100003)(66066001)(86362001)(68736007)(81156014)(81166006)(53936002)(16586007)(50226002)(2906002)(7416002)(25786009)(6506007)(8676002)(8936002)(478600001)(39060400002)(6666003)(386003)(6116002)(6512007)(3846002)(305945005)(4326008)(110426005); DIR:OUT; SFP:1101; SCL:1; SRVR:AM4PR0401MB2418; H:b27504-OptiPlex-790.ap.freescale.net; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM4PR0401MB2418; 23:5u08ZxSKft0MyGy7SwjuSYrHQRULIUIr9VskAUR?= =?us-ascii?Q?NGjsDK9LxCzJpYfmPL2UKLxRRYJ9Tz1NH4kBGWSG6tSK4RIZwMn8Sgswr5ks?= =?us-ascii?Q?7IUXR4cuE6qqIdaZZ6q7Yim8BvfR9Ma+NrLCMLFGDiuGHI1mhMw/4y1id36s?= =?us-ascii?Q?00k1ymDYnqpa6Aq1VMX0Q0ePuSMic09mGYcYyqOHMiC8vySzkvX5VEV7b6jb?= =?us-ascii?Q?A/EW+tb4FGQXLrdhhbwTZoBER3UZ0zTQ5owDRviN74dnMeHiZ0aHz5rFXNkc?=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vGp8SU0QOkltDBKVn7uBOtS?= =?us-ascii?Q?ronVJdhehaixFu+hFI55wojXOEE57uTJNt8tKBqVxbHsa6QFadoPwlvtpnov?= =?us-ascii?Q?D8SdyQmfDLMCCrjia23p7sUPqcjrJ/EAIeJrmUqzO1Uee1fKjYUCWlaF/foh?= =?us-ascii?Q?tIHDp/ydcbRXC7uvm3DJ/srg=3D?= X-Microsoft-Antispam-Message-Info: aFNYf2zsK0EYVQnEmjFYlUuFhuPRh9rVh6hk/xHQG00vCGrLIQY2QE1ZeiN2FEjt0L8jelLigZV7uiN7QuyO7aj0R7wyWD8PGLOuAoieclGOKjvhiV4YRDxGC8TdkZKTaKVUMB6YvFv+RqR27Kx+kCi3jgzLRCBz4uwmTiZiMx+DY9Ohz7Epqh1UgyaTecqP X-Microsoft-Exchange-Diagnostics: 1; AM4PR0401MB2418; 6:OA5U3JAW7RlsoF5FwUXS3j2FhH8DU3HOnwkd6p/Q/iDm1DHpeH/KpKckgQzTWMQSv1hCU8XBRSjWmRq5LDVoBESC9qeE3XMHJ22wdY7IcaTmjBllxql9whz2/EdeTb1NPb9ZahAQaveFtIu20PyIu5JtCreasmmymFmxk7HxHGZu9Hb1LkXGUerr32bGo1yPtWToVhK23SbAJt7G69i5Eks3raCmXZk/nu6zudAKPbWknbceAPVAFUXqjt+PjPx8iD01TgFTdCT6OqkcRUeHcA6CNxdH6N25L53iQ8qM1W6wQU4UtFyerqGD2ACyq+R+uqMp/bCitSd42a84wrxzy5CowQPjV40sLlvSk0t47p++AJgMxy0uvLsDm8WorQWog9+cYiDF267NYYY2Ard3btYm6WWAubKn8+zukMqYzIVUVntREu4NqD6iOLL6WyP7LLssYbR9KoIbwm+bxj3KOg==; 5:bOQ7vf+IO7DR8xTuAosJYHoyUNE3WFH1pG3mUcX7TYyKirV2CJ6HluSx1jwrV8szYshfGb9ZX/plbZVxvOq56XbnoL+mvF32N2lAj+NEfaT//8h5b7NDhng3fvmsy2siITHGYZLAVUjlmra9nOsWSnH6aMIKDkogNyuZLOmZhRw=; 24:bDWj7S13wtzQroeBsfpuYx+QKKV4RkwIMmHwfNSAqJHr6bEU08whxGURzL0b4o+JJFfe3YbWj9X2DfuAsHexe34ks+0FXXoqgtPxFpwA4zA= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM4PR0401MB2418; 7:Q/Ol0pW9rI63uBpPvUu4HzkzXShduiEHpQnOyDEOJr4IOV7CGcmRMqlUbfQ3ojXFyrzUjQn+zEgTxIgsBK5FQ3hjsgh03CmXFyEGffD98tAW6HbTthMubjRdwjjG7li0sIzkzqAD/LhelasLB8IphR5FRLujBV2WvoOJCK5Ekt/J2itQbEqHo339CtvhBcnD2CmKR+EHTW49fmlCTTGNS/C1gFoWsTH1Td/Ddox19Rtci6/i4A2N0c9hXkaeaSs9 X-MS-Office365-Filtering-Correlation-Id: 58ab5259-6bb4-439e-b137-08d5ae639d73 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2018 06:28:36.7728 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 58ab5259-6bb4-439e-b137-08d5ae639d73 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR0401MB2418 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Implement bus specific support for the fsl-mc bus including registering arm_smmu_ops and bus specific device add operations. Signed-off-by: Nipun Gupta --- drivers/iommu/arm-smmu.c | 7 +++++++ drivers/iommu/iommu.c | 21 +++++++++++++++++++++ include/linux/fsl/mc.h | 8 ++++++++ include/linux/iommu.h | 2 ++ 4 files changed, 38 insertions(+) diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c index 69e7c60..e1d5090 100644 --- a/drivers/iommu/arm-smmu.c +++ b/drivers/iommu/arm-smmu.c @@ -52,6 +52,7 @@ #include #include +#include #include "io-pgtable.h" #include "arm-smmu-regs.h" @@ -1459,6 +1460,8 @@ static struct iommu_group *arm_smmu_device_group(struct device *dev) if (dev_is_pci(dev)) group = pci_device_group(dev); + else if (dev_is_fsl_mc(dev)) + group = fsl_mc_device_group(dev); else group = generic_device_group(dev); @@ -2037,6 +2040,10 @@ static void arm_smmu_bus_init(void) bus_set_iommu(&pci_bus_type, &arm_smmu_ops); } #endif +#ifdef CONFIG_FSL_MC_BUS + if (!iommu_present(&fsl_mc_bus_type)) + bus_set_iommu(&fsl_mc_bus_type, &arm_smmu_ops); +#endif } static int arm_smmu_device_probe(struct platform_device *pdev) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index d2aa2320..6d4ce35 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -32,6 +32,7 @@ #include #include #include +#include #include static struct kset *iommu_group_kset; @@ -987,6 +988,26 @@ struct iommu_group *pci_device_group(struct device *dev) return iommu_group_alloc(); } +/* Get the IOMMU group for device on fsl-mc bus */ +struct iommu_group *fsl_mc_device_group(struct device *dev) +{ + struct device *cont_dev = fsl_mc_cont_dev(dev); + struct iommu_group *group; + + /* Container device is responsible for creating the iommu group */ + if (fsl_mc_is_cont_dev(dev)) { + group = iommu_group_alloc(); + if (IS_ERR(group)) + return NULL; + } else { + get_device(cont_dev); + group = iommu_group_get(cont_dev); + put_device(cont_dev); + } + + return group; +} + /** * iommu_group_get_for_dev - Find or create the IOMMU group for a device * @dev: target device diff --git a/include/linux/fsl/mc.h b/include/linux/fsl/mc.h index f27cb14..dddaca1 100644 --- a/include/linux/fsl/mc.h +++ b/include/linux/fsl/mc.h @@ -351,6 +351,14 @@ struct fsl_mc_io { #define dev_is_fsl_mc(_dev) (0) #endif +/* Macro to check if a device is a container device */ +#define fsl_mc_is_cont_dev(_dev) (to_fsl_mc_device(_dev)->flags & \ + FSL_MC_IS_DPRC) + +/* Macro to get the container device of a MC device */ +#define fsl_mc_cont_dev(_dev) (fsl_mc_is_cont_dev(_dev) ? \ + (_dev) : (_dev)->parent) + /* * module_fsl_mc_driver() - Helper macro for drivers that don't do * anything special in module init/exit. This eliminates a lot of diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 19938ee..2981200 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -389,6 +389,8 @@ static inline size_t iommu_map_sg(struct iommu_domain *domain, extern struct iommu_group *pci_device_group(struct device *dev); /* Generic device grouping function */ extern struct iommu_group *generic_device_group(struct device *dev); +/* FSL-MC device grouping function */ +struct iommu_group *fsl_mc_device_group(struct device *dev); /** * struct iommu_fwspec - per-device IOMMU instance data