From patchwork Mon Sep 18 10:04:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liviu Dudau X-Patchwork-Id: 112903 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp3527306qgf; Mon, 18 Sep 2017 04:06:05 -0700 (PDT) X-Google-Smtp-Source: ADKCNb7sWkdOUei5ROF7R6fsLQzTht1bPbIelyxwkbjadLX/gcIUuJw3O+NlOaolWAD03SmutJpX X-Received: by 10.99.53.205 with SMTP id c196mr31875434pga.430.1505732765687; Mon, 18 Sep 2017 04:06:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505732765; cv=none; d=google.com; s=arc-20160816; b=Kc58xv5DuZM7sfgdFeCzTyQ74b7gzJ75vrHAnswwa/xb4kRJzpRn0BxZDWZ1m+4Q0V bxUL2fmGbhn+BWUcRbUIS9P9iJUlxjcUD8sxOap6Y2U3BN98gInKCn3B3270t0uiKMYb UcdaJz8/kA5BgQvxdHzwNj7UZ9U+to/U3Q13mLYm5nnQnJJp7AANwFXOcGz4Dz2lZokS WPXFfupwOsuF+1xjpba6aiVVxRvVNr15rpVycv3LHRvedXK/R6NDWUXNH2lf5KOwIrCY 1mN2bwhR9emBzrKtywW2y8DWEg4XSMRau8M0XX/PpXruemR9sMBVF1pbeX/RfV1JnbZl rE+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=DB0elBxc0hkCWmGyqCqeAsAHMRfByQvqn/Q+HdIDA6Y=; b=qi0XZ3ACkbGrqR3k5LmbdUf+aJzKvfBXG/MlGQofhFxjLTmIF+FvG70+WBTfaD+33x lfAUrMPV596ABByAnim66OYCegy0BN4yaPYVPloLPVqDG0TIYtKD3fW1hFK/yNpIRBzz Ecog8PvjDyyQfjlJZLCIP78MY2zuXMuzzNFP+8ai9bzJPzrhzJI4wW70UpcOo46nM7Ke uLskBmGY+bJoYI5/Lj/e4Yy6GsLeQXmSdbJtdjmvX/GKE8Tpq7TZc+JVrn8xqOuBmlQj vfEOI1EbGqAfskj8so3rfiyHWVKb7X/6o0vdKg/UROdQ6L9D+zPbcW0+gsXD3ZwVFoAN PaSQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z96si4693668plh.681.2017.09.18.04.06.05; Mon, 18 Sep 2017 04:06:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753603AbdIRLGC (ORCPT + 26 others); Mon, 18 Sep 2017 07:06:02 -0400 Received: from fw-tnat.cambridge.arm.com ([217.140.96.140]:58721 "EHLO cam-smtp0.cambridge.arm.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750898AbdIRLGB (ORCPT ); Mon, 18 Sep 2017 07:06:01 -0400 X-Greylist: delayed 3675 seconds by postgrey-1.27 at vger.kernel.org; Mon, 18 Sep 2017 07:06:01 EDT Received: from e110455-lin.cambridge.arm.com (e110455-lin.cambridge.arm.com [10.2.131.60]) by cam-smtp0.cambridge.arm.com (8.13.8/8.13.8) with ESMTP id v8IA4Q8u028685; Mon, 18 Sep 2017 11:04:26 +0100 From: Liviu Dudau To: Laurent Pinchart Cc: Magnus Damm , Geert Uytterhoeven , Shawn Lin , Joerg Roedel , IOMMU ML , LKML Subject: [PATCH] iommu/ipmmu-vmsa: Do not replace bus IOMMU ops on driver init. Date: Mon, 18 Sep 2017 11:04:44 +0100 Message-Id: <20170918100444.21878-1-Liviu.Dudau@arm.com> X-Mailer: git-send-email 2.14.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If the IPMMU driver is compiled in the kernel it will replace the platform bus IOMMU ops on running the ipmmu_init() function, regardless if there is any IPMMU hardware present or not. This screws up systems that just want to build a generic kernel that runs on multiple platforms and use a different IOMMU implementation. Move the bus_set_iommu() call at the end of the ipmmu_probe() function when we know that hardware is present. With current IOMMU framework it should be safe (at least for OF case). Now that the ipmmu_init() and ipmmu_exit() functions are simple calls to platform_driver_register() and platform_driver_unregister(), replace them with the module_platform_driver() macro call. Signed-off-by: Liviu Dudau Cc: Laurent Pinchart --- drivers/iommu/ipmmu-vmsa.c | 29 +++++------------------------ 1 file changed, 5 insertions(+), 24 deletions(-) -- 2.14.1 diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c index 2a38aa15be17d..c60569c74678d 100644 --- a/drivers/iommu/ipmmu-vmsa.c +++ b/drivers/iommu/ipmmu-vmsa.c @@ -1055,10 +1055,11 @@ static int ipmmu_probe(struct platform_device *pdev) ipmmu_device_reset(mmu); /* - * We can't create the ARM mapping here as it requires the bus to have - * an IOMMU, which only happens when bus_set_iommu() is called in - * ipmmu_init() after the probe function returns. + * Now that we have validated the presence of the hardware, set + * the bus IOMMU ops to enable future domain and device setup. */ + if (!iommu_present(&platform_bus_type)) + bus_set_iommu(&platform_bus_type, &ipmmu_ops); spin_lock(&ipmmu_devices_lock); list_add(&mmu->list, &ipmmu_devices); @@ -1100,27 +1101,7 @@ static struct platform_driver ipmmu_driver = { .remove = ipmmu_remove, }; -static int __init ipmmu_init(void) -{ - int ret; - - ret = platform_driver_register(&ipmmu_driver); - if (ret < 0) - return ret; - - if (!iommu_present(&platform_bus_type)) - bus_set_iommu(&platform_bus_type, &ipmmu_ops); - - return 0; -} - -static void __exit ipmmu_exit(void) -{ - return platform_driver_unregister(&ipmmu_driver); -} - -subsys_initcall(ipmmu_init); -module_exit(ipmmu_exit); +module_platform_driver(ipmmu_driver); MODULE_DESCRIPTION("IOMMU API for Renesas VMSA-compatible IPMMU"); MODULE_AUTHOR("Laurent Pinchart ");