Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp755467imu; Tue, 11 Dec 2018 07:07:13 -0800 (PST) X-Google-Smtp-Source: AFSGD/UBCjEoUXWvreVdL2BOKS6I3aeJ/wXLmbI2jI3LCWGgC1tLvmnUQt3qRSjfe0Pzqx9GXpTW X-Received: by 2002:a17:902:9a8b:: with SMTP id w11mr15926685plp.121.1544540833776; Tue, 11 Dec 2018 07:07:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544540833; cv=none; d=google.com; s=arc-20160816; b=qge3grqni5iVgHC7wL6DEmuJFmHUptzU70ngGJatYL4l00URA9X8ZC1bPUFp+ulq3/ j4lEHRlF5zrmbwGSV93Xe3d1dYkfcj3PsCRoLmCsZgwZRFTvG3cmkkSOEuYPWI0a1DPg Y+yObAS2TeP2ITMNuuzAfnbZCqyPEPzOg/o17pLWuHs/XdRmGWrQdGFFuGflHsrYgwnn JMcTGCrzOH1rtDt49hd3mGBtxxxrxs+wVNEC3Ei5n0O5V3BTtKZUO8q5rrF493k0Aknc 7Sy2nKnzplxAOobISpu9/R2vHyTDVPLqG32UfvuUGVh/iVSC1zgtii6MTCJz7KTIHR+o cHog== 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=ebAw4+Gt6LuDWddK5AOJYQ/xc6HJ2+uWIgeekHR4h/g=; b=FPuk1oFxIpPaGy5Ie4bqnCuhhCCfssyOfOQRd7cc17fFPO7iYCZ7OxmWjBBWHXbzqh KU5xH37zFDsYgrLRNJj9Lv78Zx0AiGLBcQeQgaY+FP4fwXihPhxDwdPTGfOwRkOGYxrN c1p4X/RHmUS86WKdUEeIBU9ekYYkN4s2WnF6LR8SXUIw3NRePx3OUArzFGnPO6bqMjFT BvTkMsiveMN3g3+XVsTrDAZeTEQ+VNKcAaeei3T5vZFfCcG04yNLanUCYop6dNTqoyhg NoRjH3ZF/ID7fWFI9kt9xbwCPBNHhbsZZCej7TFLpjbfdLg6jbPNH570JuIoBy6WJ6SZ yTyg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x10si12078408pgl.209.2018.12.11.07.06.57; Tue, 11 Dec 2018 07:07:13 -0800 (PST) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726739AbeLKPFY (ORCPT + 99 others); Tue, 11 Dec 2018 10:05:24 -0500 Received: from 8bytes.org ([81.169.241.247]:53524 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726328AbeLKPFS (ORCPT ); Tue, 11 Dec 2018 10:05:18 -0500 Received: by theia.8bytes.org (Postfix, from userid 1000) id 74AA03AF; Tue, 11 Dec 2018 16:05:15 +0100 (CET) From: Joerg Roedel To: iommu@lists.linux-foundation.org Cc: Lorenzo Pieralisi , Hanjun Guo , Sudeep Holla , Joerg Roedel , jroedel@suse.de, Robin Murphy , linux-kernel@vger.kernel.org Subject: [PATCH 2/4] iommu: Consolitate ->add/remove_device() calls Date: Tue, 11 Dec 2018 16:05:11 +0100 Message-Id: <20181211150513.15161-3-joro@8bytes.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181211150513.15161-1-joro@8bytes.org> References: <20181211150513.15161-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 Put them into separate functions and call those where the plain ops have been called before. Signed-off-by: Joerg Roedel --- drivers/iommu/iommu.c | 51 +++++++++++++++++++++---------------------- include/linux/iommu.h | 3 +++ 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index edbdf5d6962c..1e8f4e0c9198 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -110,6 +110,23 @@ void iommu_device_unregister(struct iommu_device *iommu) spin_unlock(&iommu_device_lock); } +int iommu_probe_device(struct device *dev) +{ + const struct iommu_ops *ops = dev->bus->iommu_ops; + + WARN_ON(dev->iommu_group); + + return ops->add_device(dev); +} + +void iommu_release_device(struct device *dev) +{ + const struct iommu_ops *ops = dev->bus->iommu_ops; + + if (dev->iommu_group) + ops->remove_device(dev); +} + static struct iommu_domain *__iommu_domain_alloc(struct bus_type *bus, unsigned type); static int __iommu_attach_device(struct iommu_domain *domain, @@ -1117,16 +1134,7 @@ struct iommu_domain *iommu_group_default_domain(struct iommu_group *group) static int add_iommu_group(struct device *dev, void *data) { - struct iommu_callback_data *cb = data; - const struct iommu_ops *ops = cb->ops; - int ret; - - if (!ops->add_device) - return 0; - - WARN_ON(dev->iommu_group); - - ret = ops->add_device(dev); + int ret = iommu_probe_device(dev); /* * We ignore -ENODEV errors for now, as they just mean that the @@ -1141,11 +1149,7 @@ static int add_iommu_group(struct device *dev, void *data) static int remove_iommu_group(struct device *dev, void *data) { - struct iommu_callback_data *cb = data; - const struct iommu_ops *ops = cb->ops; - - if (ops->remove_device && dev->iommu_group) - ops->remove_device(dev); + iommu_release_device(dev); return 0; } @@ -1153,27 +1157,22 @@ static int remove_iommu_group(struct device *dev, void *data) static int iommu_bus_notifier(struct notifier_block *nb, unsigned long action, void *data) { + unsigned long group_action = 0; struct device *dev = data; - const struct iommu_ops *ops = dev->bus->iommu_ops; struct iommu_group *group; - unsigned long group_action = 0; /* * ADD/DEL call into iommu driver ops if provided, which may * result in ADD/DEL notifiers to group->notifier */ if (action == BUS_NOTIFY_ADD_DEVICE) { - if (ops->add_device) { - int ret; + int ret; - ret = ops->add_device(dev); - return (ret) ? NOTIFY_DONE : NOTIFY_OK; - } + ret = iommu_probe_device(dev); + return (ret) ? NOTIFY_DONE : NOTIFY_OK; } else if (action == BUS_NOTIFY_REMOVED_DEVICE) { - if (ops->remove_device && dev->iommu_group) { - ops->remove_device(dev); - return 0; - } + iommu_release_device(dev); + return NOTIFY_OK; } /* diff --git a/include/linux/iommu.h b/include/linux/iommu.h index a1d28f42cb77..cb36f32cd3c2 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -398,6 +398,9 @@ void iommu_fwspec_free(struct device *dev); int iommu_fwspec_add_ids(struct device *dev, u32 *ids, int num_ids); const struct iommu_ops *iommu_ops_from_fwnode(struct fwnode_handle *fwnode); +int iommu_probe_device(struct device *dev); +void iommu_release_device(struct device *dev); + #else /* CONFIG_IOMMU_API */ struct iommu_ops {}; -- 2.17.1