From patchwork Thu Jul 25 15:34:59 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonios Motakis X-Patchwork-Id: 2833456 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 40AC4C0319 for ; Thu, 25 Jul 2013 15:35:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 85B4D20336 for ; Thu, 25 Jul 2013 15:35:43 +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 34BA720335 for ; Thu, 25 Jul 2013 15:35:42 +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 1V2NZs-0008AQ-6c; Thu, 25 Jul 2013 15:35:40 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1V2NZp-00052w-U2; Thu, 25 Jul 2013 15:35:37 +0000 Received: from mail-wi0-f173.google.com ([209.85.212.173]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1V2NZm-00051Y-UX for linux-arm-kernel@lists.infradead.org; Thu, 25 Jul 2013 15:35:35 +0000 Received: by mail-wi0-f173.google.com with SMTP id hq4so5784303wib.0 for ; Thu, 25 Jul 2013 08:35:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:x-gm-message-state; bh=5+ODxODp0ciWKSE47WTCvxZYfd4k1xy7/Ti1AITWbzs=; b=TR9KjKeE2ySUbPBG8Nn+djG+LFo0bEr152R+qwQq0VJab0LtdoawDHBsq7bZ3b8vn0 ZKR/3Yq52ZihY1bzdqYgCgn+QhOL1DgBg97XA6KwMqejoRdxNmFHLbn8DznzdB1kRtpr hW3oPEYsPIQyDdumWpkObrm4VgwrSopMf9PWwsZZVlM0sphtXBY4rdD+Lj3qX05Fb2Pl GQBB3ggi7sKf1Tpsi90NEXE3SvoA7mezMvBZbzj5C+I8hB4J0PScGV9gUq9V/kl7qltO FPRwqsVkugbl3Dzh4wWcErr2JUbgPz4HWMIbdhew/jocVlmM0DuB2ap0tyxTBJ3QlBug L2yA== X-Received: by 10.194.179.129 with SMTP id dg1mr32090053wjc.38.1374766512060; Thu, 25 Jul 2013 08:35:12 -0700 (PDT) Received: from localhost.localdomain (home.tvelocity.eu. [82.67.68.96]) by mx.google.com with ESMTPSA id mb20sm4548063wic.1.2013.07.25.08.35.09 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 25 Jul 2013 08:35:11 -0700 (PDT) From: Antonios Motakis To: linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org, linux-samsung-soc@vger.kernel.org Subject: [PATCHv2 1/2] iommu/exynos: add devices attached to the System MMU to an IOMMU group Date: Thu, 25 Jul 2013 17:34:59 +0200 Message-Id: <1374766502-14823-1-git-send-email-a.motakis@virtualopensystems.com> X-Mailer: git-send-email 1.8.1.2 X-Gm-Message-State: ALoCoQnGBEzEIrEAr4/bA+6K7nfojQiavdyx9jyYf0lUhdqcf+F9+3PvONpcaSkX/p8KU/CpoR45 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130725_113535_102026_7B677715 X-CRM114-Status: GOOD ( 12.33 ) X-Spam-Score: -2.6 (--) Cc: Sachin Kamat , Joerg Roedel , open list , Varun Sethi , Antonios Motakis , Cho KyongHo , 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.2 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. Since each device is behind its own System MMU, we can allocate a new IOMMU group for each device. This patch depends on Cho KyongHo's patch series titled "[PATCH v7 00/12] iommu/exynos: Fixes and Enhancements of System MMU driver with DT", applied on a Linux 3.10.1 kernel. It has been tested on the Arndale board. Changes since in v2: - Removed possibility for minor memory leak in case of misbehaving platform drivers Signed-off-by: Antonios Motakis --- drivers/iommu/exynos-iommu.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/drivers/iommu/exynos-iommu.c b/drivers/iommu/exynos-iommu.c index 51d43bb..c7dd4b5 100644 --- a/drivers/iommu/exynos-iommu.c +++ b/drivers/iommu/exynos-iommu.c @@ -1134,6 +1134,32 @@ static phys_addr_t exynos_iommu_iova_to_phys(struct iommu_domain *domain, return phys; } +static int exynos_iommu_add_device(struct device *dev) +{ + struct iommu_group *group; + int ret; + + group = iommu_group_get(dev); + + if (!group) { + 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); + + return ret; +} + +static void exynos_iommu_remove_device(struct device *dev) +{ + iommu_group_remove_device(dev); +} + static struct iommu_ops exynos_iommu_ops = { .domain_init = &exynos_iommu_domain_init, .domain_destroy = &exynos_iommu_domain_destroy, @@ -1142,6 +1168,8 @@ static struct iommu_ops exynos_iommu_ops = { .map = &exynos_iommu_map, .unmap = &exynos_iommu_unmap, .iova_to_phys = &exynos_iommu_iova_to_phys, + .add_device = exynos_iommu_add_device, + .remove_device = exynos_iommu_remove_device, .pgsize_bitmap = SECT_SIZE | LPAGE_SIZE | SPAGE_SIZE, };