Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp586654ybz; Wed, 15 Apr 2020 14:36:00 -0700 (PDT) X-Google-Smtp-Source: APiQypITOo7ZYeYT9pt6Do+W4l2VJVfLz578L1+7t/owsm4GgaEgprXybvukY/kE3lWEgAMK/urb X-Received: by 2002:a50:cc87:: with SMTP id q7mr26273670edi.96.1586986560251; Wed, 15 Apr 2020 14:36:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586986560; cv=none; d=google.com; s=arc-20160816; b=sqeRF1OsmUCbYTrmld4bMCiPUHVVeHaE/x2Dc4ubrmzHUbYgnqYI03z86VPGKGcPMj oZddMjn0eetNKL0Yq/dAjNKWqJMk1PtDnvk6g/Qz3vYo56ogYhr6BufDRbKMX3v0zbwR kfd21DLnL80MzObIDExceGESjcRLIYdRYorR1gFMMVy6Zh1qR9P2QKGXDOV4rhcpUL1b R2zFP9F2eOVAehEiCci8CRT7eWkgQKGZM9yS3DQ+1NRM2Ecf7lpxc40OrJMEm5bTiqof EAOHmBc+ncF5Y8gNIbLtITLKMIabco3wO5D2qooUbnTXYP75zK5dJSfYYlE3yrSM5QGm fFzQ== 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=MMs/GPKMMBqenGvGZdL5HAVHkkuK7zxIQOvkgJIQBJTIxpENI6tRC5FlY1Ot964I+6 vyMM8+6ndy12Y6VmOEPGSWMcXNY8CAFVHMw96q4d60S+FSzwn5MV4WHxDfnXmEIEvSOA igcaDJhw4wVfEhOl74HHus/FsS6WfLXTw3iBqAjOkidWSKPpg2v+hZ9fAqeOpDe0Town Uh7f8KJRxL3YuJnat8ZQ0/gVo381UH5P4Bpkc0v+HAfXbTnmFPlZduKJNSKNzmpJ3PdG QyN88awzKynKAKdCN91M3WZ6nHDMsjSxQvQwUko1cqf+q7TnHUDIFup4HGkAruFXrTdK Aq+w== 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 rv23si9698752ejb.330.2020.04.15.14.35.36; Wed, 15 Apr 2020 14:36:00 -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 S1731413AbgDNNWf (ORCPT + 99 others); Tue, 14 Apr 2020 09:22:35 -0400 Received: from 8bytes.org ([81.169.241.247]:35334 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2502896AbgDNNQG (ORCPT ); Tue, 14 Apr 2020 09:16:06 -0400 Received: by theia.8bytes.org (Postfix, from userid 1000) id 49BD8694; Tue, 14 Apr 2020 15:15:55 +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: 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 v2 20/33] iommu/virtio: Convert to probe/release_device() call-backs Date: Tue, 14 Apr 2020 15:15:29 +0200 Message-Id: <20200414131542.25608-21-joro@8bytes.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200414131542.25608-1-joro@8bytes.org> References: <20200414131542.25608-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