From patchwork Fri Oct 18 15:08:29 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonios Motakis X-Patchwork-Id: 3068281 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 885F79F243 for ; Fri, 18 Oct 2013 15:09:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 618982037D for ; Fri, 18 Oct 2013 15:09:30 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 320D020374 for ; Fri, 18 Oct 2013 15:09:29 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VXBg6-0001Yx-EZ; Fri, 18 Oct 2013 15:09:26 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VXBg3-0006m1-PW; Fri, 18 Oct 2013 15:09:23 +0000 Received: from mail-wi0-f178.google.com ([209.85.212.178]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VXBg0-0006kC-NJ for linux-arm-kernel@lists.infradead.org; Fri, 18 Oct 2013 15:09:21 +0000 Received: by mail-wi0-f178.google.com with SMTP id hn9so1166676wib.11 for ; Fri, 18 Oct 2013 08:08:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=vqjwWfUS+6bUOzTbw4SEMCUdXjO29jhrim02DqcjBZ4=; b=RHAK1yYq30wqc5iao7CRWuwqNx6Ne1qGFEOgcPcwZBA2dmnY2PlNiVeiANFQ8+MsGg YkRTQA1vxSNZjlvbn/+3PEiFHvNJfU+dHsGLAM1UtKmeLOXTCQM16kj8lx7nIzZ7YUA+ ck5Sdkz4dM/SsgZO2hwgJyncgJ/AkuJHvoKNl745poX5TpKcsI2SJdY3Z9UVzrj4SfCv TKIK+Rt9FyYyRZixd6BRJ5s78m8JkBIi0PrvfAZayJYGuFVNUfSTI9O43BRcsRttcNZu U4jA3J3i8tP9/1LjNCtA8f5e+unrOa98/r3GMNRi6TD0GAjXt1Ue3aP7cQJ+tAgzpgBr /yfA== X-Gm-Message-State: ALoCoQnBf/wrkL7koqwaIVYM/lQgF7IySSLwdG1nJN6XlA3XiqDumZzck09DetnuG0YtOQ8gtMYB X-Received: by 10.194.241.228 with SMTP id wl4mr3118934wjc.2.1382108932402; Fri, 18 Oct 2013 08:08:52 -0700 (PDT) Received: from localhost.localdomain (home.tvelocity.eu. [82.67.68.96]) by mx.google.com with ESMTPSA id gg20sm26779923wic.1.2013.10.18.08.08.50 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 18 Oct 2013 08:08:51 -0700 (PDT) From: Antonios Motakis To: Will Deacon , Joerg Roedel , linux-arm-kernel@lists.infradead.org (moderated list:ARM SMMU DRIVER), iommu@lists.linux-foundation.org (open list:IOMMU DRIVERS), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2] ARM: SMMU: add devices attached to the SMMU to an IOMMU group Date: Fri, 18 Oct 2013 17:08:29 +0200 Message-Id: <1382108910-18049-1-git-send-email-a.motakis@virtualopensystems.com> X-Mailer: git-send-email 1.8.1.2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131018_110920_850642_BF85DFB1 X-CRM114-Status: GOOD ( 12.43 ) X-Spam-Score: -2.6 (--) Cc: Antonios Motakis , iommu@lists.linux-foundation.org, tech@virtualopensystems.com, kvmarm@lists.cs.columbia.edu X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP IOMMU groups are expected by certain users of the IOMMU API, e.g. VFIO. Add new devices found by the SMMU driver to an IOMMU group to satisfy those users. Changes from v1: * Added check that dev->archdata.iommu has not been set already by an IOMMU driver. This way we can also skip checking for an existing IOMMU group. Signed-off-by: Antonios Motakis Acked-by: Alex Williamson --- drivers/iommu/arm-smmu.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c index 0f45a48..6762885 100644 --- a/drivers/iommu/arm-smmu.c +++ b/drivers/iommu/arm-smmu.c @@ -1502,6 +1502,13 @@ static int arm_smmu_add_device(struct device *dev) { struct arm_smmu_device *child, *parent, *smmu; struct arm_smmu_master *master = NULL; + struct iommu_group *group; + int ret; + + if (dev->archdata.iommu) { + dev_warn(dev, "IOMMU driver already assigned to device\n"); + return -EINVAL; + } spin_lock(&arm_smmu_devices_lock); list_for_each_entry(parent, &arm_smmu_devices, list) { @@ -1534,13 +1541,23 @@ static int arm_smmu_add_device(struct device *dev) if (!master) return -ENODEV; + group = iommu_group_alloc(); + if (IS_ERR(group)) { + dev_err(dev, "Failed to allocate IOMMU group\n"); + return PTR_ERR(group); + } + + ret = iommu_group_add_device(group, dev); + iommu_group_put(group); dev->archdata.iommu = smmu; - return 0; + + return ret; } static void arm_smmu_remove_device(struct device *dev) { dev->archdata.iommu = NULL; + iommu_group_remove_device(dev); } static struct iommu_ops arm_smmu_ops = {