From patchwork Mon Sep 10 13:49:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nipun Gupta X-Patchwork-Id: 10594181 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-2.web.codeaurora.org (Postfix) with ESMTP id 1986A109C for ; Mon, 10 Sep 2018 13:51:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0B9B5290E0 for ; Mon, 10 Sep 2018 13:51:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F33F4290E4; Mon, 10 Sep 2018 13:51:23 +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 60788290E0 for ; Mon, 10 Sep 2018 13:51:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728522AbeIJSpC (ORCPT ); Mon, 10 Sep 2018 14:45:02 -0400 Received: from mail-db5eur01on0061.outbound.protection.outlook.com ([104.47.2.61]:34336 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728635AbeIJSpB (ORCPT ); Mon, 10 Sep 2018 14:45:01 -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:X-MS-Exchange-SenderADCheck; bh=uEgAqhZqTeLuJSDtixR/HVfgPxOwCcqmERq0rRRqhu8=; b=T59KSJNcqQrFfEszndMqvRVs1uRSR6QOrEmdHqpha+SQzXnl0u6xvz2v5he4GLYayLMiISz2CV0BfA3yCS0Ah5jSiIMbviXLvbi7l1acFuTlbVH7C+wk1S6COaC8XnybyH+qf4r5AsElmmlD1mQG5tSgpw7PfGt5btu25GwN/co= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=nipun.gupta@nxp.com; Received: from b27504-OptiPlex-790.ap.freescale.net (14.143.30.134) by DB7PR04MB4476.eurprd04.prod.outlook.com (2603:10a6:5:35::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1122.17; Mon, 10 Sep 2018 13:50:23 +0000 From: Nipun Gupta To: joro@8bytes.org, 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, laurentiu.tudor@nxp.com, bhelgaas@google.com, hch@lst.de Cc: m.szyprowski@samsung.com, shawnguo@kernel.org, frowand.list@gmail.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, leoyang.li@nxp.com, Nipun Gupta Subject: [PATCH 4/7 v7] iommu/arm-smmu: Add support for the fsl-mc bus Date: Mon, 10 Sep 2018 19:19:18 +0530 Message-Id: <1536587361-11047-5-git-send-email-nipun.gupta@nxp.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1536587361-11047-1-git-send-email-nipun.gupta@nxp.com> References: <1536587361-11047-1-git-send-email-nipun.gupta@nxp.com> MIME-Version: 1.0 X-Originating-IP: [14.143.30.134] X-ClientProxiedBy: PN1PR0101CA0049.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c00:d::11) To DB7PR04MB4476.eurprd04.prod.outlook.com (2603:10a6:5:35::14) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5fdcd16d-b1a7-40eb-8559-08d617245db0 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989137)(4534165)(7168020)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020);SRVR:DB7PR04MB4476; X-Microsoft-Exchange-Diagnostics: 1;DB7PR04MB4476;3:r2jhMMH6YsAdjG3ye7MrlqyunHLA7DVbQ8ZkRTMrmlkMZHG58vOuMdD20EmBBLJmRIOElcpFOirgnQOtzOYKCVoPvKcem0mtuR+Yiv6c+6i0oX7xj4Zpev21Qy6afchlX6tCjLb2fJqsLuUmem65XSQXgbx1BVq7Xq2eve0VtTCNR4F5DTmcV5HV2KHVf7baY+XMpR+Ws3fsOvpRcJC1XV+FrIe+g2u/S9qpNhaWxEE23/7ZtHnZJu/JrQNmS3aL;25:wa5NR8zuuCTQPIiLvYBGIvZjVOD0RF2JqqkyBKfz6ZKPBlVK7psRBex+7oS4olEBZK2EXY73nNh6Cscr5AgxIYgwZJ23QFdW0YHuRnUoLQZ9vW3STJU4h/0hqzpOA2tOYUZtZcDSs7WbZNKlE7fR24tMsSnHuYfNQO/IJhqfOt3dcS5DfA+9EG7kEBF+GTXDQCWAb6RwRldp65SwVLU40ClZBRxtKAqmmr3hC9JRDmADvieD2raqCFm+kI0jQEiuiD4pPLvtIEyoYjURnYrMM6mhOENuPxis2/VM8YUHsyphWeAz8TEQWy+R+qVOOftaH61Xcjf7fZ32LqVQHongBg==;31:M9rhukK6oKXS0+ZhEY/xXgEgM1V8Eo2pqAelnk7VLG2j+4ZPVZWnAUqOZyisKoHpTaHMbXWGdk38VqExGqlO+RUJh7iz1hv1tuUj9giPY9WiZEwsOvWNpVo77vSYr3QoAUKz8xiJs6qgNqdYS68WnBB7JcTJWfREk7WzX1YH9fx2F4jd0Edg3nUQD5isx10GIF6zzJM6hkG/U4WM+RdDHeLXZrAHM5EdkJPKEEDac20= X-MS-TrafficTypeDiagnostic: DB7PR04MB4476: X-Microsoft-Exchange-Diagnostics: 1;DB7PR04MB4476;20:ueqXvJ6swqSC0w/lozvVoKX7WQW4FVECexssRKGJrOGQgt9QjBU60PE0lkPAwLQCUg7nX9LG354o08ffGaanY0QmuqZmHqN80kyAhgGFh7CdYuDeqXr0+9qnL+THSByZZ8oydxtmhEZhoaLNwQudcXl74lKv0p2K1pWF4Uu3RVELCfzmdT7gFjsZaEDBnR+DyGCODMtJEUBS4QYF89ExxqEiY9j7eslxSK+DfoDD7BBcdHJLrSVxYkFPGshN8lOEOqPYC08xAFW4TMGdio1SYCcXAcdu3JNp/PE7i+29uDkxE9EPDlINrWwlwI27VkU4n719IkejvmFJsuS+Z9NynHx4Qk9a90YWlWMW/C0LpeADt+LoaccJUsYb/F+tUV8jSvJslJsXgap/blwFxNsYoWyIgJmI6krlIn3OliUxsDDwzhJFC34WB7LyLd+TXioiOmgnMyIs/k7vNvvCAEbxRhFdUEISlVj9SgaCw2jx/quu/9sgQgLg/gOtkluUD3qu;4:IsF8am8vYDSy41UK0trMN4ydKvP1Yi8TIRFCEBm0AGHxb3ixNDMQSLqZJ0Oc35gOxZxd87Ih/7DedZB+uYfRwalCVXsKCY1txf/CTgUJEuCmi0/rrqbm5I3ifs7eQ9jwKSK0gSyIZDGBF1NZFYy+Py85PO/BFEz5XI5mXX2f4q58Ili8ZRL9ZCHkqFi9KMaInBv+EXgvZouWGd/GhzgyF7wdOwQQtpo0c4u9/Baf2nKmNhEN+ARGiOINylyyn5SfclHtiTY4zGwVKbcf5QPV9MjDsl+AvuF5kHBHDi9OLfD3GKhYM7Q0zabx/bET4474NcuHQZkBnAokMflaS8ZddMmbSU7M+mkVN+kdEXmAvKA= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(180628864354917)(185117386973197); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(823301075)(93006095)(93001095)(3231311)(944501410)(52105095)(3002001)(10201501046)(6055026)(149027)(150027)(6041310)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123558120)(201708071742011)(7699050);SRVR:DB7PR04MB4476;BCL:0;PCL:0;RULEID:;SRVR:DB7PR04MB4476; X-Forefront-PRVS: 07915F544A X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(366004)(396003)(136003)(39860400002)(346002)(376002)(199004)(189003)(48376002)(81166006)(8936002)(81156014)(105586002)(106356001)(44832011)(53936002)(47776003)(50466002)(7416002)(316002)(956004)(16586007)(6512007)(2616005)(575784001)(476003)(26005)(186003)(66066001)(486006)(11346002)(25786009)(6506007)(386003)(50226002)(446003)(2906002)(16526019)(86362001)(55236004)(6116002)(3846002)(97736004)(4326008)(68736007)(7736002)(5009440100003)(305945005)(6486002)(8676002)(478600001)(52116002)(51416003)(5660300001)(76176011)(39060400002)(6666003)(36756003)(110426005)(921003)(1121003);DIR:OUT;SFP:1101;SCL:1;SRVR:DB7PR04MB4476;H:b27504-OptiPlex-790.ap.freescale.net;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; Received-SPF: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: 1;DB7PR04MB4476;23:UqXiShuUzrMRGLGGA9gonXGoImkrqoVrywmTbMcEZmM20EMIzkMp2zPSUGtPShBZcHadcVFh4p4+5YLWEzKxGsVzKkpFtlNxAqehbn+da6QhZJ5iIyVehqH/xPOFCgPO+qwomkqIHbGVuhWBoaarCCp3vvZuhcnq/Ctk+SJsMwC6Bu2C4X7/jfG54rvXWXLzmTEpnHcvzUTqIfme5wS/pD67m95QQ5x/oTog/kfGl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ncVYGqDlfN8IJvxfegO2wNSd36KqW8Kk2Hu0/v25zara2IHQ06k0=;7:q6Vpz2C6L92j0r95E+Esm8UxWR0FWkq6tvo6IjXHwGs86/AQHvuH3k/uXpbkmsMQ/w9vFrj9WNmNXPfPP47OEGOwQXqHkDDSmorG2o27bYSmOV10KT8MyODxzQWEWR7CakmmQ+NBs4vUlcQi18Zt2cyzxC1KMOptyVxKGtojle2Fvld5/GAYnwfG3sMPnNfU2PWgdeAq0yeiEhLCNiUqSW085v3KGhoSWiGqO2JH9zW3dkT2x9hArNXkNA4HMTtd SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2018 13:50:23.5624 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5fdcd16d-b1a7-40eb-8559-08d617245db0 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR04MB4476 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 Reviewed-by: Robin Murphy --- drivers/iommu/arm-smmu.c | 7 +++++++ drivers/iommu/iommu.c | 13 +++++++++++++ include/linux/fsl/mc.h | 8 ++++++++ include/linux/iommu.h | 2 ++ 4 files changed, 30 insertions(+) diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c index f7a96bc..a011bb6 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 d227b86..df2f49e 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; @@ -988,6 +989,18 @@ 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; + + group = iommu_group_get(cont_dev); + if (!group) + group = iommu_group_alloc(); + 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 7447b0b..209891d 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