From patchwork Wed Apr 12 05:21:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suman Anna X-Patchwork-Id: 97283 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp115076qgf; Tue, 11 Apr 2017 22:22:14 -0700 (PDT) X-Received: by 10.98.184.18 with SMTP id p18mr27680300pfe.186.1491974534138; Tue, 11 Apr 2017 22:22:14 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d10si7409364plj.56.2017.04.11.22.22.13; Tue, 11 Apr 2017 22:22:14 -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; dkim=pass header.i=@ti.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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752997AbdDLFWB (ORCPT + 21 others); Wed, 12 Apr 2017 01:22:01 -0400 Received: from fllnx210.ext.ti.com ([198.47.19.17]:27301 "EHLO fllnx210.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752211AbdDLFVz (ORCPT ); Wed, 12 Apr 2017 01:21:55 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by fllnx210.ext.ti.com (8.15.1/8.15.1) with ESMTP id v3C5LZEv009704; Wed, 12 Apr 2017 00:21:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ti.com; s=ti-com-17Q1; t=1491974495; bh=tFWq+Fc/YCDqvY55z73QLAf//IcOTVJghKNC8FoHlwk=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=ybOv4vGcsyXfH+WznmIrCsRuhrUydTsNZzCXLyE72tKXkq/vu8yeoGyHt5Em5zIOB L7oBQp2buTBmvn146R3qTxe97+4o7XqSI+ikloXWfBGnZoOGWEBawLhsK746TYpvM8 3tA9IS77OkuA/weobytjs8cjhyhOL6mjzqYH6ZEk= Received: from DFLE72.ent.ti.com (dfle72.ent.ti.com [128.247.5.109]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id v3C5LZKv032252; Wed, 12 Apr 2017 00:21:35 -0500 Received: from dflp33.itg.ti.com (10.64.6.16) by DFLE72.ent.ti.com (128.247.5.109) with Microsoft SMTP Server id 14.3.294.0; Wed, 12 Apr 2017 00:21:34 -0500 Received: from legion.dal.design.ti.com (legion.dal.design.ti.com [128.247.22.53]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id v3C5LZIR025865; Wed, 12 Apr 2017 00:21:35 -0500 Received: from localhost (irmo.am.dhcp.ti.com [128.247.83.68]) by legion.dal.design.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id v3C5LY304079; Wed, 12 Apr 2017 00:21:34 -0500 (CDT) From: Suman Anna To: Joerg Roedel CC: , Laurent Pinchart , Suman Anna , , , Joerg Roedel Subject: [PATCH v3 6/7] iommu/omap: Add iommu-group support Date: Wed, 12 Apr 2017 00:21:31 -0500 Message-ID: <20170412052132.14406-7-s-anna@ti.com> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170412052132.14406-1-s-anna@ti.com> References: <20170412052132.14406-1-s-anna@ti.com> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Joerg Roedel Support for IOMMU groups will become mandatory for drivers, so add it to the omap iommu driver. Signed-off-by: Joerg Roedel [s-anna@ti.com: minor error cleanups] Signed-off-by: Suman Anna --- v3 w.r.t v1: - iommu_group_get_for_dev() failure path cleanup code added in the add_device callback - iommu_group_alloc() added in the same place relative to iommu_device calls, but before pm_runtime calls - iommu_device_register() failure cleanup dropped since it is handled in patch 5 - omap_device_group() renamed to omap_iommu_device_group() following the convention on all OMAP IOMMU ops drivers/iommu/omap-iommu.c | 39 ++++++++++++++++++++++++++++++++++++++- drivers/iommu/omap-iommu.h | 1 + 2 files changed, 39 insertions(+), 1 deletion(-) -- 2.12.0 diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c index ef44fc740da7..95dfca36ccb9 100644 --- a/drivers/iommu/omap-iommu.c +++ b/drivers/iommu/omap-iommu.c @@ -943,9 +943,13 @@ static int omap_iommu_probe(struct platform_device *pdev) return err; platform_set_drvdata(pdev, obj); + obj->group = iommu_group_alloc(); + if (IS_ERR(obj->group)) + return PTR_ERR(obj->group); + err = iommu_device_sysfs_add(&obj->iommu, obj->dev, NULL, obj->name); if (err) - return err; + goto out_group; iommu_device_set_ops(&obj->iommu, &omap_iommu_ops); @@ -959,10 +963,13 @@ static int omap_iommu_probe(struct platform_device *pdev) omap_iommu_debugfs_add(obj); dev_info(&pdev->dev, "%s registered\n", obj->name); + return 0; out_sysfs: iommu_device_sysfs_remove(&obj->iommu); +out_group: + iommu_group_put(obj->group); return err; } @@ -970,6 +977,9 @@ static int omap_iommu_remove(struct platform_device *pdev) { struct omap_iommu *obj = platform_get_drvdata(pdev); + iommu_group_put(obj->group); + obj->group = NULL; + iommu_device_sysfs_remove(&obj->iommu); iommu_device_unregister(&obj->iommu); @@ -1217,6 +1227,7 @@ static int omap_iommu_add_device(struct device *dev) { struct omap_iommu_arch_data *arch_data; struct omap_iommu *oiommu; + struct iommu_group *group; struct device_node *np; struct platform_device *pdev; int ret; @@ -1262,6 +1273,19 @@ static int omap_iommu_add_device(struct device *dev) arch_data->iommu_dev = oiommu; dev->archdata.iommu = arch_data; + /* + * IOMMU group initialization calls into omap_iommu_device_group, which + * needs a valid dev->archdata.iommu pointer + */ + group = iommu_group_get_for_dev(dev); + if (IS_ERR(group)) { + iommu_device_unlink(&oiommu->iommu, dev); + dev->archdata.iommu = NULL; + kfree(arch_data); + return PTR_ERR(group); + } + iommu_group_put(group); + of_node_put(np); return 0; @@ -1275,12 +1299,24 @@ static void omap_iommu_remove_device(struct device *dev) return; iommu_device_unlink(&arch_data->iommu_dev->iommu, dev); + iommu_group_remove_device(dev); dev->archdata.iommu = NULL; kfree(arch_data); } +static struct iommu_group *omap_iommu_device_group(struct device *dev) +{ + struct omap_iommu_arch_data *arch_data = dev->archdata.iommu; + struct iommu_group *group = NULL; + + if (arch_data->iommu_dev) + group = arch_data->iommu_dev->group; + + return group; +} + static const struct iommu_ops omap_iommu_ops = { .domain_alloc = omap_iommu_domain_alloc, .domain_free = omap_iommu_domain_free, @@ -1292,6 +1328,7 @@ static const struct iommu_ops omap_iommu_ops = { .iova_to_phys = omap_iommu_iova_to_phys, .add_device = omap_iommu_add_device, .remove_device = omap_iommu_remove_device, + .device_group = omap_iommu_device_group, .pgsize_bitmap = OMAP_IOMMU_PGSIZES, }; diff --git a/drivers/iommu/omap-iommu.h b/drivers/iommu/omap-iommu.h index 758958a4712c..6e70515e6038 100644 --- a/drivers/iommu/omap-iommu.h +++ b/drivers/iommu/omap-iommu.h @@ -70,6 +70,7 @@ struct omap_iommu { u32 id; struct iommu_device iommu; + struct iommu_group *group; }; /**