From patchwork Mon Jan 11 02:17:46 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: 7998751 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 41C1ABEEED for ; Mon, 11 Jan 2016 02:25:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5C2D320263 for ; Mon, 11 Jan 2016 02:25:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 63E1F2026D for ; Mon, 11 Jan 2016 02:25:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757948AbcAKCZO (ORCPT ); Sun, 10 Jan 2016 21:25:14 -0500 Received: from smtp-3.sys.kth.se ([130.237.48.192]:54087 "EHLO smtp-3.sys.kth.se" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757833AbcAKCZM (ORCPT ); Sun, 10 Jan 2016 21:25:12 -0500 Received: from smtp-3.sys.kth.se (localhost.localdomain [127.0.0.1]) by smtp-3.sys.kth.se (Postfix) with ESMTP id 5849425A6; Mon, 11 Jan 2016 03:18:16 +0100 (CET) X-Virus-Scanned: by amavisd-new at kth.se Received: from smtp-3.sys.kth.se ([127.0.0.1]) by smtp-3.sys.kth.se (smtp-3.sys.kth.se [127.0.0.1]) (amavisd-new, port 10024) with LMTP id LatCJqCy8o5V; Mon, 11 Jan 2016 03:18:15 +0100 (CET) X-KTH-Auth: niso [89.233.230.99] X-KTH-mail-from: niklas.soderlund+renesas@ragnatech.se Received: from bismarck.berto.se (dynamic.0.6.79d1f80.14cc20ac3a53.cust.bredband2.com [89.233.230.99]) by smtp-3.sys.kth.se (Postfix) with ESMTPSA id 0C8AA25BD; Mon, 11 Jan 2016 03:18:15 +0100 (CET) From: =?UTF-8?q?Niklas=20S=C3=B6derlund?= To: dmaengine@vger.kernel.org, linux-sh@vger.kernel.org Cc: vinod.koul@intel.com, dan.j.williams@intel.com, geert+renesas@glider.be, laurent.pinchart+renesas@ideasonboard.com, =?UTF-8?q?Niklas=20S=C3=B6derlund?= Subject: [PATCH 1/2] dmaengine: rcar-dmac: add iommu support for slave transfers Date: Mon, 11 Jan 2016 03:17:46 +0100 Message-Id: <1452478667-30966-2-git-send-email-niklas.soderlund+renesas@ragnatech.se> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1452478667-30966-1-git-send-email-niklas.soderlund+renesas@ragnatech.se> References: <1452478667-30966-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.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 Enable slave transfers to devices behind IPMMU:s by mapping the slave addresses using the dma-mapping API. Signed-off-by: Niklas Söderlund --- drivers/dma/sh/rcar-dmac.c | 64 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 4 deletions(-) diff --git a/drivers/dma/sh/rcar-dmac.c b/drivers/dma/sh/rcar-dmac.c index 7820d07..da94809 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,6 +1102,24 @@ rcar_dmac_prep_dma_cyclic(struct dma_chan *chan, dma_addr_t buf_addr, return desc; } +static dma_addr_t __rcar_dmac_dma_map(struct dma_chan *chan, phys_addr_t addr, + size_t size, enum dma_data_direction dir) +{ + struct rcar_dmac_chan *rchan = to_rcar_dmac_chan(chan); + struct page *page = phys_to_page(addr); + size_t offset = addr - page_to_phys(page); + dma_addr_t map = dma_map_page(chan->device->dev, page, offset, size, + dir); + + if (dma_mapping_error(chan->device->dev, map)) { + dev_err(chan->device->dev, "chan%u: failed to map %zx@%pap", + rchan->index, size, &addr); + return 0; + } + + return map; +} + static int rcar_dmac_device_config(struct dma_chan *chan, struct dma_slave_config *cfg) { @@ -1110,10 +1129,47 @@ static int rcar_dmac_device_config(struct dma_chan *chan, * We could lock this, but you shouldn't be configuring the * channel, while using it... */ - rchan->src_slave_addr = cfg->src_addr; - rchan->dst_slave_addr = cfg->dst_addr; - rchan->src_xfer_size = cfg->src_addr_width; - rchan->dst_xfer_size = cfg->dst_addr_width; + + /* If we don't have a iommu domain no idea to trying to use it */ + if (!iommu_get_domain_for_dev(chan->device->dev)) { + rchan->src_slave_addr = cfg->src_addr; + rchan->dst_slave_addr = cfg->dst_addr; + rchan->src_xfer_size = cfg->src_addr_width; + rchan->dst_xfer_size = cfg->dst_addr_width; + return 0; + } + + /* unmap old */ + if (rchan->src_slave_addr) { + dma_unmap_page(chan->device->dev, rchan->src_slave_addr, + rchan->src_xfer_size, DMA_FROM_DEVICE); + rchan->src_slave_addr = 0; + rchan->src_xfer_size = 0; + } + + if (rchan->dst_slave_addr) { + dma_unmap_page(chan->device->dev, rchan->dst_slave_addr, + rchan->dst_xfer_size, DMA_TO_DEVICE); + rchan->dst_slave_addr = 0; + rchan->dst_xfer_size = 0; + } + + /* map new */ + if (cfg->src_addr) { + rchan->src_slave_addr = __rcar_dmac_dma_map(chan, cfg->src_addr, + cfg->src_addr_width, DMA_FROM_DEVICE); + if (!rchan->src_slave_addr) + return -EIO; + rchan->src_xfer_size = cfg->src_addr_width; + } + + if (cfg->dst_addr) { + rchan->dst_slave_addr = __rcar_dmac_dma_map(chan, cfg->dst_addr, + cfg->dst_addr_width, DMA_TO_DEVICE); + if (!rchan->dst_slave_addr) + return -EIO; + rchan->dst_xfer_size = cfg->dst_addr_width; + } return 0; }