Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp630926ybz; Wed, 29 Apr 2020 06:41:53 -0700 (PDT) X-Google-Smtp-Source: APiQypIMSNtSm31Gqz1ewgy4eNEImeoHBRaTbgYYI+jHKV1+qKgK+vVhNqOXrQ5fxrz7aDtvmg4p X-Received: by 2002:a05:6402:4a:: with SMTP id f10mr2588178edu.274.1588167712980; Wed, 29 Apr 2020 06:41:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588167712; cv=none; d=google.com; s=arc-20160816; b=LMt6Zp+cImfcOJOO4+OD1qcdKA5Su0fsdr13fkOZFWBFbdF4p/UGqjLtQAs9H4WNLQ D/6kOBQnV76MpHuwYaMQvIZVTxme63MevOVfqYuQkL+HXpKvr64xT+Y3kDnmM7gVK0Ek 1vcJIt53x1u+//jFmhX411R4xZSrdSNo6+cxGZlrUxWXx1Gv1I7xyTjssebwqyYE5JQG E0smxWf31iEXhRM1GwZI5d9xJOHFF2vqYGpqQWd7+GRRJmwRzLdE4Yp5cG6leWbFRQ46 172NNJT/4jH74raXhjKL5Wmn6UsiVZJzPbW4MvPKisItveSIi9e5p95kM1w+ZL504oab EjBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=2v8+BR6yScSC4c7RVzfvCaaHiPfQeKwATmdHIIaZs1Q=; b=QzA0swXXP1Y+ElyGna1goeUMaDAfYtMfR+dp3Hpbp6HVdPtgIwCf4pUkf+8qtIgpKp DibFMPyQNA8H+ZBmF4F4qNH3MxGZnYTrWgp4KWOPVq35x1UWwIG0sa/HL50jE0ApFGfL L9mgc1BZKjFsUjI13c/iT3kpZQ/QK6buHcT+AuT9RS65HBbIwRk8FXSxHeHllU5a6icm fq9Zx/oz/L610dT34m+mvit2sIZr/Obwlluuj4N0JczKFaMzq+MGS2z1hlxoV/habqu9 Wo4LHVTC835LjDOi8QPQXmO1syMm/YSF9cUja+kwtBY0AoKucP+cFr+9lovYSL+OMP2d FtTg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j34si3298878edc.516.2020.04.29.06.41.29; Wed, 29 Apr 2020 06:41:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728373AbgD2NjZ (ORCPT + 99 others); Wed, 29 Apr 2020 09:39:25 -0400 Received: from 8bytes.org ([81.169.241.247]:40134 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727995AbgD2Nhu (ORCPT ); Wed, 29 Apr 2020 09:37:50 -0400 Received: by theia.8bytes.org (Postfix, from userid 1000) id 1F089ED8; Wed, 29 Apr 2020 15:37:39 +0200 (CEST) From: Joerg Roedel To: Joerg Roedel , Will Deacon , Robin Murphy , Marek Szyprowski , Kukjin Kim , Krzysztof Kozlowski , David Woodhouse , Lu Baolu , Andy Gross , Bjorn Andersson , Matthias Brugger , Rob Clark , Heiko Stuebner , Gerald Schaefer , Thierry Reding , Jonathan Hunter , Jean-Philippe Brucker Cc: Daniel Drake , jonathan.derrick@intel.com, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-s390@vger.kernel.org, linux-tegra@vger.kernel.org, virtualization@lists.linux-foundation.org, Joerg Roedel Subject: [PATCH v3 20/34] iommu/virtio: Convert to probe/release_device() call-backs Date: Wed, 29 Apr 2020 15:36:58 +0200 Message-Id: <20200429133712.31431-21-joro@8bytes.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200429133712.31431-1-joro@8bytes.org> References: <20200429133712.31431-1-joro@8bytes.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Joerg Roedel Convert the VirtIO IOMMU driver to use the probe_device() and release_device() call-backs of iommu_ops, so that the iommu core code does the group and sysfs setup. Signed-off-by: Joerg Roedel --- drivers/iommu/virtio-iommu.c | 41 +++++++++--------------------------- 1 file changed, 10 insertions(+), 31 deletions(-) diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c index d5cac4f46ca5..bda300c2a438 100644 --- a/drivers/iommu/virtio-iommu.c +++ b/drivers/iommu/virtio-iommu.c @@ -865,24 +865,23 @@ static struct viommu_dev *viommu_get_by_fwnode(struct fwnode_handle *fwnode) return dev ? dev_to_virtio(dev)->priv : NULL; } -static int viommu_add_device(struct device *dev) +static struct iommu_device *viommu_probe_device(struct device *dev) { int ret; - struct iommu_group *group; struct viommu_endpoint *vdev; struct viommu_dev *viommu = NULL; struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); if (!fwspec || fwspec->ops != &viommu_ops) - return -ENODEV; + return ERR_PTR(-ENODEV); viommu = viommu_get_by_fwnode(fwspec->iommu_fwnode); if (!viommu) - return -ENODEV; + return ERR_PTR(-ENODEV); vdev = kzalloc(sizeof(*vdev), GFP_KERNEL); if (!vdev) - return -ENOMEM; + return ERR_PTR(-ENOMEM); vdev->dev = dev; vdev->viommu = viommu; @@ -896,45 +895,25 @@ static int viommu_add_device(struct device *dev) goto err_free_dev; } - ret = iommu_device_link(&viommu->iommu, dev); - if (ret) - goto err_free_dev; + return &viommu->iommu; - /* - * Last step creates a default domain and attaches to it. Everything - * must be ready. - */ - group = iommu_group_get_for_dev(dev); - if (IS_ERR(group)) { - ret = PTR_ERR(group); - goto err_unlink_dev; - } - - iommu_group_put(group); - - return PTR_ERR_OR_ZERO(group); - -err_unlink_dev: - iommu_device_unlink(&viommu->iommu, dev); err_free_dev: generic_iommu_put_resv_regions(dev, &vdev->resv_regions); kfree(vdev); - return ret; + return ERR_PTR(ret); } -static void viommu_remove_device(struct device *dev) +static void viommu_release_device(struct device *dev) { - struct viommu_endpoint *vdev; struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); + struct viommu_endpoint *vdev; if (!fwspec || fwspec->ops != &viommu_ops) return; vdev = dev_iommu_priv_get(dev); - iommu_group_remove_device(dev); - iommu_device_unlink(&vdev->viommu->iommu, dev); generic_iommu_put_resv_regions(dev, &vdev->resv_regions); kfree(vdev); } @@ -960,8 +939,8 @@ static struct iommu_ops viommu_ops = { .unmap = viommu_unmap, .iova_to_phys = viommu_iova_to_phys, .iotlb_sync = viommu_iotlb_sync, - .add_device = viommu_add_device, - .remove_device = viommu_remove_device, + .probe_device = viommu_probe_device, + .release_device = viommu_release_device, .device_group = viommu_device_group, .get_resv_regions = viommu_get_resv_regions, .put_resv_regions = generic_iommu_put_resv_regions, -- 2.17.1