From patchwork Mon May 6 07:25:55 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Kardashevskiy X-Patchwork-Id: 241597 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 205362C00ED for ; Mon, 6 May 2013 17:34:03 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753550Ab3EFHdy (ORCPT ); Mon, 6 May 2013 03:33:54 -0400 Received: from mail-ye0-f176.google.com ([209.85.213.176]:61286 "EHLO mail-ye0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753579Ab3EFHdw (ORCPT ); Mon, 6 May 2013 03:33:52 -0400 Received: by mail-ye0-f176.google.com with SMTP id r9so480538yen.21 for ; Mon, 06 May 2013 00:33:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=DByp4KZh0dtAFoNqVp9soNnlLZG6gIYpQNn7YLoquFI=; b=kB86w6iYBzMmi+qy+cuhpv3az3tYZMK1+wmWI180JJtEO4mWfio9x5Z9VrDN8A5qYE abGiX1EfofSEcYEmsLzJjLt3zntAMAfPc0kjH7sf8ZQ9GwdzhExHYhw+S2sbq2tgkZxN n8FAgnF0gVMv8lvNmgw7qcf5bIjmw2qgJKfQ5FUmhE7Usp50FUZDtQFyzzt15a7NIiU7 kbnKv6MPnYgwmGOq7FQllFe458FbeYQ1HisXMoimJTAJoIKWqyiz3RxlrrjYLT7lynCW KqcODZDonN/E4Pb7aUPsjgxpCAWe+7Qa5OfhriqcvF4s27AehOaOBlKed6maOcFv42Ue ZWgA== X-Received: by 10.236.6.231 with SMTP id 67mr17412670yhn.171.1367825190521; Mon, 06 May 2013 00:26:30 -0700 (PDT) Received: from ka1.ozlabs.ibm.com (ibmaus65.lnk.telstra.net. [165.228.126.9]) by mx.google.com with ESMTPSA id a66sm37294534yhq.19.2013.05.06.00.26.25 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 06 May 2013 00:26:29 -0700 (PDT) From: Alexey Kardashevskiy To: linuxppc-dev@lists.ozlabs.org Cc: Alexey Kardashevskiy , David Gibson , Benjamin Herrenschmidt , Alexander Graf , Paul Mackerras , Joerg Roedel , Alex Williamson , kvm@vger.kernel.org, kvm-ppc@vger.kernel.org Subject: [PATCH 4/6] iommu: Add a function to find an iommu group by id Date: Mon, 6 May 2013 17:25:55 +1000 Message-Id: <1367825157-27231-5-git-send-email-aik@ozlabs.ru> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1367825157-27231-1-git-send-email-aik@ozlabs.ru> References: <1367825157-27231-1-git-send-email-aik@ozlabs.ru> X-Gm-Message-State: ALoCoQnQL1r6/MSHSnE8YV+8y+EuR8Z58rG7h9mu0Uu0XfR0VS1/S9oPxB5qa34wAfstL2lV1ngU Sender: kvm-ppc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm-ppc@vger.kernel.org As IOMMU groups are exposed to the user space by their numbers, the user space can use them in various kernel APIs so the kernel might need an API to find a group by its ID. As an example, QEMU VFIO on PPC64 platform needs it to associate a logical bus number (LIOBN) with a specific IOMMU group in order to support in-kernel handling of DMA map/unmap requests. This adds the iommu_group_get_by_id(id) function which performs this search. Signed-off-by: Alexey Kardashevskiy Signed-off-by: Paul Mackerras --- drivers/iommu/iommu.c | 29 +++++++++++++++++++++++++++++ include/linux/iommu.h | 1 + 2 files changed, 30 insertions(+) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index ddbdaca..5514dfa 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -204,6 +204,35 @@ again: } EXPORT_SYMBOL_GPL(iommu_group_alloc); +struct iommu_group *iommu_group_get_by_id(int id) +{ + struct kobject *group_kobj; + struct iommu_group *group; + const char *name; + + if (!iommu_group_kset) + return NULL; + + name = kasprintf(GFP_KERNEL, "%d", id); + if (!name) + return NULL; + + group_kobj = kset_find_obj(iommu_group_kset, name); + kfree(name); + + if (!group_kobj) + return NULL; + + group = container_of(group_kobj, struct iommu_group, kobj); + BUG_ON(group->id != id); + + kobject_get(group->devices_kobj); + kobject_put(&group->kobj); + + return group; +} +EXPORT_SYMBOL_GPL(iommu_group_get_by_id); + /** * iommu_group_get_iommudata - retrieve iommu_data registered for a group * @group: the group diff --git a/include/linux/iommu.h b/include/linux/iommu.h index f3b99e1..00e5d7d 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -113,6 +113,7 @@ struct iommu_ops { extern int bus_set_iommu(struct bus_type *bus, struct iommu_ops *ops); extern bool iommu_present(struct bus_type *bus); extern struct iommu_domain *iommu_domain_alloc(struct bus_type *bus); +extern struct iommu_group *iommu_group_get_by_id(int id); extern void iommu_domain_free(struct iommu_domain *domain); extern int iommu_attach_device(struct iommu_domain *domain, struct device *dev);