From patchwork Fri May 30 11:20:18 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hiroshi Doyu X-Patchwork-Id: 354077 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 7EA021400D6 for ; Fri, 30 May 2014 21:20:47 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753089AbaE3LUo (ORCPT ); Fri, 30 May 2014 07:20:44 -0400 Received: from hqemgate14.nvidia.com ([216.228.121.143]:12084 "EHLO hqemgate14.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752368AbaE3LUn (ORCPT ); Fri, 30 May 2014 07:20:43 -0400 Received: from hqnvupgp08.nvidia.com (Not Verified[216.228.121.13]) by hqemgate14.nvidia.com id ; Fri, 30 May 2014 04:21:01 -0700 Received: from hqemhub01.nvidia.com ([172.20.12.94]) by hqnvupgp08.nvidia.com (PGP Universal service); Fri, 30 May 2014 04:15:39 -0700 X-PGP-Universal: processed; by hqnvupgp08.nvidia.com on Fri, 30 May 2014 04:15:39 -0700 Received: from deemhub02.nvidia.com (10.21.69.138) by hqemhub01.nvidia.com (172.20.150.30) with Microsoft SMTP Server (TLS) id 8.3.342.0; Fri, 30 May 2014 04:20:42 -0700 Received: from oreo.nvidia.com (10.21.65.27) by deemhub02.nvidia.com (10.21.69.138) with Microsoft SMTP Server (TLS) id 8.3.342.0; Fri, 30 May 2014 13:20:40 +0200 From: Hiroshi Doyu To: Subject: [PATCHv8 05/21] iommu/core: add ops->{bound,unbind}_driver() Date: Fri, 30 May 2014 14:20:18 +0300 Message-ID: <1401448834-32659-6-git-send-email-hdoyu@nvidia.com> X-Mailer: git-send-email 2.0.0.rc1.15.g7e76a2f In-Reply-To: <1401448834-32659-1-git-send-email-hdoyu@nvidia.com> References: <1401448834-32659-1-git-send-email-hdoyu@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org ops->{bound,unbind}_driver() functions are called at BUS_NOTIFY_{BOUND,UNBIND}_DRIVER respectively. This is necessary to control the device population order. IOMMU master devices depend on an IOMMU device instanciation. IOMMU master devices can be registered to an IOMMU only after it's successfully populated. This IOMMU registration is done via ops->bound_driver(). Currently this population can be deferred if depending IOMMU device hasn't yet been populated in driver core. This cannot be done via ops->add_device() since after add_device() device's population/instanciation can be still deferred via probe(). Signed-off-by: Hiroshi Doyu --- drivers/iommu/iommu.c | 13 +++++++++++-- include/linux/iommu.h | 4 ++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index e5555fcfe703..5469d361e7bc 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -540,14 +540,23 @@ static int iommu_bus_notifier(struct notifier_block *nb, * 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) { + switch (action) { + case BUS_NOTIFY_ADD_DEVICE: if (ops->add_device) return ops->add_device(dev); - } else if (action == BUS_NOTIFY_DEL_DEVICE) { + case BUS_NOTIFY_DEL_DEVICE: if (ops->remove_device && dev->iommu_group) { ops->remove_device(dev); return 0; } + case BUS_NOTIFY_BOUND_DRIVER: + if (ops->bound_driver) + ops->bound_driver(dev); + break; + case BUS_NOTIFY_UNBIND_DRIVER: + if (ops->unbind_driver) + ops->unbind_driver(dev); + break; } /* diff --git a/include/linux/iommu.h b/include/linux/iommu.h index b96a5b2136e4..141eea25bdea 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -97,6 +97,8 @@ enum iommu_attr { * @domain_has_cap: domain capabilities query * @add_device: add device to iommu grouping * @remove_device: remove device from iommu grouping + * @bound_driver: called at BUS_NOTIFY_BOUND_DRIVER + * @unbind_driver: called at BUS_NOTIFY_UNBIND_DRIVER * @domain_get_attr: Query domain attributes * @domain_set_attr: Change domain attributes * @pgsize_bitmap: bitmap of supported page sizes @@ -115,6 +117,8 @@ struct iommu_ops { unsigned long cap); int (*add_device)(struct device *dev); void (*remove_device)(struct device *dev); + int (*bound_driver)(struct device *dev); + void (*unbind_driver)(struct device *dev); int (*device_group)(struct device *dev, unsigned int *groupid); int (*domain_get_attr)(struct iommu_domain *domain, enum iommu_attr attr, void *data);