From patchwork Fri Jan 8 08:23:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 7983241 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id DB7389F1CC for ; Fri, 8 Jan 2016 08:23:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E47582017E for ; Fri, 8 Jan 2016 08:23:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EF679201B9 for ; Fri, 8 Jan 2016 08:23:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752069AbcAHIXp (ORCPT ); Fri, 8 Jan 2016 03:23:45 -0500 Received: from mail-lb0-f181.google.com ([209.85.217.181]:33541 "EHLO mail-lb0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751690AbcAHIXo (ORCPT ); Fri, 8 Jan 2016 03:23:44 -0500 Received: by mail-lb0-f181.google.com with SMTP id sv6so213196054lbb.0 for ; Fri, 08 Jan 2016 00:23:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ragnatech-se.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=aGrMNFbPteEE914vkFmL8VAXyrYGc61UEJpLwxV24Js=; b=mdqdGncV3mVnniudqn1zPF88o3NllnVS09uchwsfpuI9cF5zEPYiMH7NCt5zby8PRc iHH9BvUoXPzxdik1A+OPbIcUnqtpTiFv030lj69XissfWNt55zJ1FWiTgnMYg1eyqnRS Jhfc4hEejjNOpjddSPJlkdDrE9BXRUkCtKMFTAb9Zi+GrmKHhcBdXqMYj/lxb1Dc2gKp NE5Auv33mX79woCJL/t6Ay9wgE4b/JAf/Z9AN+EV5lt5bShKkTy+lawjVrJvCqEgI8c2 vwDKxVr//t2oZGtX34GEgpLQGorlCmQH6EkrGj7sZYyckQXitbTAU/9oqz1k+3lRjIel CYCg== 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:in-reply-to :references:mime-version:content-type:content-transfer-encoding; bh=aGrMNFbPteEE914vkFmL8VAXyrYGc61UEJpLwxV24Js=; b=lFip9TKmk6hqIJkI7Wm2DQoaTwUjSG/u6CofEes3UhVi9UrlgXCvv3T+rmsmU/Rykm HlT9XM70AONBI4qhkqHbUZxL9xqxaMnPcqDNUBPFRhYZ1jwbndlyXCoKNVz6wd4wfc6q jpCX0ZkoSw2QMW7xBqEK01RbzMhpGkUZ1W+dnyPvRIOrpjqOsGZOUjA+q51JxhXkhu1e 8rq0up57j3jVHw74KQbbe/leE8MDlbJ0o4AyJ6rv+8Fvd7Olr9KnZndh1xmpcVYGLyYn rNPwfGbIjtI80khGbeQWNQrIkN4Rrd2utnBTx9rxkleVw2DU9gDpkeQOqR1kEPXiU3T3 gy1w== X-Gm-Message-State: ALoCoQnVzHMA5vqyg8IijN5ToL3ZYuPfpT7Mu4NkAN9tQJEhKpy1ACK493oDnX9dUpAwwcbSlIpuAIG/AZccpFR+ZmePjit8DA== X-Received: by 10.112.126.234 with SMTP id nb10mr32461574lbb.144.1452241423457; Fri, 08 Jan 2016 00:23:43 -0800 (PST) Received: from bismarck.berto.se (dynamic.0.6.79d1f80.14cc20ac3a53.cust.bredband2.com. [89.233.230.99]) by smtp.gmail.com with ESMTPSA id qb3sm18374691lbb.39.2016.01.08.00.23.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 08 Jan 2016 00:23:42 -0800 (PST) From: "=?UTF-8?q?Niklas=20S=C3=B6derlund?=" X-Google-Original-From: =?UTF-8?q?Niklas=20S=C3=B6derlund?= To: linux-sh@vger.kernel.org Cc: vinod.koul@intel.com, geert+renesas@glider.be, laurent.pinchart+renesas@ideasonboard.com, =?UTF-8?q?Niklas=20S=C3=B6derlund?= Subject: [RFC 2/4] dmaengine: rcar-dmac: add iommu support for slave transfers Date: Fri, 8 Jan 2016 09:23:04 +0100 Message-Id: <1452241386-22830-3-git-send-email-niklas.soderlund+renesas@ragnatech.se> X-Mailer: git-send-email 2.6.4 In-Reply-To: <1452241386-22830-1-git-send-email-niklas.soderlund+renesas@ragnatech.se> References: <1452241386-22830-1-git-send-email-niklas.soderlund+renesas@ragnatech.se> MIME-Version: 1.0 Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham 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 Enable slave transfers over IPMMU by mapping the slave addresses to the DMAC device iommu domain. The mapping is done directly when the slave device is configured and is never unmapped. The mapping is permanent for the device since there might be more then one channel that maps the same area. Think a rx/tx pair that operates on the same address but from separate channels. This makes it hard to map and unmap the addresses from device_alloc_chan_resources and device_free_chan_resources since all channels share the same iommu domain. Signed-off-by: Niklas Söderlund --- drivers/dma/sh/rcar-dmac.c | 50 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/drivers/dma/sh/rcar-dmac.c b/drivers/dma/sh/rcar-dmac.c index 7820d07..c1138a1 100644 --- a/drivers/dma/sh/rcar-dmac.c +++ b/drivers/dma/sh/rcar-dmac.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -1101,10 +1102,49 @@ rcar_dmac_prep_dma_cyclic(struct dma_chan *chan, dma_addr_t buf_addr, return desc; } +static int rcar_dmac_iommu_map(struct dma_chan *chan, phys_addr_t addr, + size_t size) +{ + struct rcar_dmac_chan *rchan = to_rcar_dmac_chan(chan); + struct iommu_domain *domain; + phys_addr_t base; + size_t min_pagesz, sz = 0; + int ret; + + if (!addr) + return 0; + + domain = iommu_get_domain_for_dev(chan->device->dev); + if (!domain) + return 0; + + /* do nothing if the address is already mapped to the domain */ + /* FIXME: what happens if size is larger for the new mapping? */ + if (iommu_iova_to_phys(domain, addr)) + return 0; + + min_pagesz = iommu_min_pgsize(domain); + + /* align the address with the min page size */ + base = addr & ~(min_pagesz - 1); + + /* recalculate size for aligned address */ + while (sz < size + addr - base) + sz += min_pagesz; + + ret = iommu_map(domain, base, base, sz, IOMMU_READ | IOMMU_WRITE); + if (ret) + dev_err(chan->device->dev, "chan%u: failed to map %pap", + rchan->index, &addr); + + return ret; +} + static int rcar_dmac_device_config(struct dma_chan *chan, struct dma_slave_config *cfg) { struct rcar_dmac_chan *rchan = to_rcar_dmac_chan(chan); + int ret = 0; /* * We could lock this, but you shouldn't be configuring the @@ -1115,7 +1155,15 @@ static int rcar_dmac_device_config(struct dma_chan *chan, rchan->src_xfer_size = cfg->src_addr_width; rchan->dst_xfer_size = cfg->dst_addr_width; - return 0; + ret = rcar_dmac_iommu_map(chan, rchan->src_slave_addr, + rchan->src_xfer_size); + if (ret) + return ret; + + ret = rcar_dmac_iommu_map(chan, rchan->dst_slave_addr, + rchan->dst_xfer_size); + + return ret; } static int rcar_dmac_chan_terminate_all(struct dma_chan *chan)