Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp737250lqb; Fri, 24 May 2024 11:31:23 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXHo53MP5AXgCqPKKtqH11r7c+EmHHsbQUZG78SZPAQ8/5wgPTh0pA6jHa9Bk75oyV7fTrG8mdjQm7p/8sUvrI5fJiOMy3FqtjvlwMjCA== X-Google-Smtp-Source: AGHT+IHFLTNotthFS8qajWfxdlxzajVyfUxSyUJRFvUnWBrY96HIChGQMWFS6ZxAKAx0tCCiGx2v X-Received: by 2002:a05:6512:6c9:b0:51f:2f5a:54ae with SMTP id 2adb3069b0e04-5296529049fmr3297102e87.7.1716575483267; Fri, 24 May 2024 11:31:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716575483; cv=pass; d=google.com; s=arc-20160816; b=u0Ao1tTal1Peyn0A9W2Ecbm/cY9KU67+dYtxT+SLVsDtyGvVoRtWpbsGvcn5cyy/X+ 4mw8fjcnGT6mfJ35xyvvAT6D/cR0JS+21ZREWRlNw+EBae5EfDcEJS5ta2z1tAErN5ZN algGbP/pYXTj0CJ5c0/71IBAxzA/XJbtcrGMEdmnm4HFurC0ly8P51VdUg0AWT5xxR+w /OGNFMoLOe2NnE2vAsaHHnme3805OLE6BdgcSjJp3Z4JiWRdLH4pweQ9nKAT3gwFt27N XhW0lYyF3oUyRxSNHyDVVjPaDd+vW6i9t01ecF9bf7o2ErgDjoztpIlwzfnRcfo8PeTU 4njA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=k5/0PmDw861toPHKUvcW29ls0QVOfTRw5AjJ+CnPD2s=; fh=RWf2Y4f7RgQl9gNxXusQnDF1uHJkiQAnGcwuxXxp4Ss=; b=zv1hNGQxkKermmc7JIhuBDpOauF4S5swDRMK1PqT5y/D4Cmwdp/gmtYae8QtX6Toxc L0PZqvLKB8vk/Y6+NyElUAwoG2Gxo57kO636dLULDYivaOlO2EqJDBvwvuhmPgys6q+p 1WUcbshIfbYgjxUeFhpRBfdxWOpFJazH1zhLrUHjPn7aAGB2SeZPGnT2zgiZxYMyUhV9 UW7Uvxk7ML8jwENOzZzJeYxhRh5msPi+tU6ZeE4giRwcc+Yrthl8JZeEzt/NvdRmDyap h1cpzFHrYdugOkJZqVbFi75ZARpl7W13aMVUXjpCh+97hTIlD7TWIyDR/yjPvnd9jfRI QLzQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@raspberrypi.com header.s=google header.b=OnA3QUt5; arc=pass (i=1 spf=pass spfdomain=raspberrypi.com dkim=pass dkdomain=raspberrypi.com dmarc=pass fromdomain=raspberrypi.com); spf=pass (google.com: domain of linux-kernel+bounces-189005-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189005-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=raspberrypi.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a626cc6533fsi105839166b.593.2024.05.24.11.31.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 May 2024 11:31:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-189005-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@raspberrypi.com header.s=google header.b=OnA3QUt5; arc=pass (i=1 spf=pass spfdomain=raspberrypi.com dkim=pass dkdomain=raspberrypi.com dmarc=pass fromdomain=raspberrypi.com); spf=pass (google.com: domain of linux-kernel+bounces-189005-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189005-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=raspberrypi.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id CE1541F23549 for ; Fri, 24 May 2024 18:31:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4A74212EBC4; Fri, 24 May 2024 18:28:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="OnA3QUt5" Received: from mail-lj1-f228.google.com (mail-lj1-f228.google.com [209.85.208.228]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4E38D47F7E for ; Fri, 24 May 2024 18:27:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.228 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716575283; cv=none; b=VsmhETt0ulTK9gYpqrUCyseXxUFpza/4Fd59jSqj4ai/MI1bQD2gZ0Whd/zIIi+0+uya+aCWy/DawWtXsZhQHez5/fAV2G+ctaMDibwPX3Ui6hfUNf3s2xkslBfZY/QaN6F/yvwRQKosApvsLW1FIqKT/rMoLpflYVgdn6vstvI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716575283; c=relaxed/simple; bh=HeQH+726CyNd6SDwiRedJyMRoX6cs3MUOfByWaM6V4s=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dPCOxmrRmhzwTeaqXLqypysi982/oSaVIQrvN7zixAf9IZZjFFIe1VUM5tw28TdS1mlxeYPVEb07MVce3ywZwKr3MVou4TH6pnxd/bhVGROC8CH+0Gf04ccruZZS//uJvrAacT5kldPK0qQdtOw+llGR7i7/1pWnRWW+bzvj47k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=raspberrypi.com; spf=pass smtp.mailfrom=raspberrypi.com; dkim=pass (2048-bit key) header.d=raspberrypi.com header.i=@raspberrypi.com header.b=OnA3QUt5; arc=none smtp.client-ip=209.85.208.228 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=raspberrypi.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=raspberrypi.com Received: by mail-lj1-f228.google.com with SMTP id 38308e7fff4ca-2e6f51f9de4so107026801fa.3 for ; Fri, 24 May 2024 11:27:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1716575277; x=1717180077; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=k5/0PmDw861toPHKUvcW29ls0QVOfTRw5AjJ+CnPD2s=; b=OnA3QUt5z9UlqM+IzEmWliXQWN3Vih7wB/ZkTOLwpyO5zMFF1eG0xzF8cVkMtptg7U E7gm5r4ljsNTKp9a9y0mu2ieIbhfXnGqXaKXkGHy/ajn67eQPrp3NAEXoD1JA/LH+FkZ BGl15AKaR2Lwtswzi59KB61XRm/fOmKlXbNcsubDNI7OYA3AD8DI1OYsfaNqaRTkv6nk hpsKa3nN8GEvn1TR6M5mqRFTmFHVsE0kMYiY9+08IxJAiNLHW8LvvqEUSZyYrtxat9oG nb8ChHxsIlAdRQymUTID5X1imGJLXM2nL7WjmN5Y5FP9UZE7fSInfbCZvrYqeKYLR448 dhRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716575277; x=1717180077; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=k5/0PmDw861toPHKUvcW29ls0QVOfTRw5AjJ+CnPD2s=; b=njVuhUQjYGYai9krcV8fa8wYUg4+Hv8Vg4O2luyBaWYCqwwujKlMfVXbNlUTXOV+nF WXLKWPxNx2CWkquZ/WETdV3CiGCjBmdxm7/+qFYjpGgq7CRsNJ7yhrGrcdsneAMffG0O L2g68+QLul/iy3jaPWIaZ4vz8nEoiBd8UNr3PYFxDtr3PkAEp6igWmUDW4F3E2L5RtBB L7HtZ2caoOMi5/rUoF13esAjxnVxx8tp0KovRM4TmIon3oeh+A4HRXUlehjGqImacs4H kkhhTmUkl0iuYOzHcF5Y6ZAlS4Q3izR+5VYfyZdXvSzCRCCOZY7ertvAJ5L9zPAFbAcs PEDg== X-Forwarded-Encrypted: i=1; AJvYcCXiv6opl58fksHDCWtpZJeLb13tbUbTURs40xA1blxI5wE5YqSgnFTCI8WQyRqBN8tbIy0s+cB/tZEjQnU+2TcBKS1zYc/JpaRC22DI X-Gm-Message-State: AOJu0Yx+T+P9c7i4lMBv0ZSupapeekqtSJPUp7kD4Ubh3ejVYEV6nr4P wTFKLjnH3d8ouzEsjfIK3/P7Sp5ojvZceCWAuLUoA4Cfc9nmoCZFqIYrChqeuqu0HH/6K0nKFV8 cKSSR27GBaagy8w/wWIi9/rXoei4+kCUY X-Received: by 2002:a05:651c:4d4:b0:2e9:61c7:cad3 with SMTP id 38308e7fff4ca-2e961c7cceemr12892461fa.25.1716575276717; Fri, 24 May 2024 11:27:56 -0700 (PDT) Received: from raspberrypi.com ([188.39.149.98]) by smtp-relay.gmail.com with ESMTPS id 38308e7fff4ca-2e95bcedd3dsm330901fa.19.2024.05.24.11.27.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 May 2024 11:27:56 -0700 (PDT) X-Relaying-Domain: raspberrypi.com From: Dave Stevenson To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Florian Fainelli , Broadcom internal kernel review list , Ray Jui , Scott Branden , Vinod Koul , Maxime Ripard , Maarten Lankhorst , Thomas Zimmermann , David Airlie , Daniel Vetter , Ulf Hansson , Mark Brown , Christoph Hellwig , Marek Szyprowski , Robin Murphy , Liam Girdwood , Jaroslav Kysela , Takashi Iwai , Vladimir Murzin , Phil Elwell , Stefan Wahren , Serge Semin Cc: devicetree@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, dmaengine@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-mmc@vger.kernel.org, linux-spi@vger.kernel.org, iommu@lists.linux.dev, linux-sound@vger.kernel.org, Dave Stevenson Subject: [PATCH 09/18] dmaengine: bcm2835: Add function to handle DMA mapping Date: Fri, 24 May 2024 19:26:53 +0100 Message-Id: <20240524182702.1317935-10-dave.stevenson@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240524182702.1317935-1-dave.stevenson@raspberrypi.com> References: <20240524182702.1317935-1-dave.stevenson@raspberrypi.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The code handling DMA mapping is currently incorrect and needs a sequence of fixups. Move the mapping out into a separate function and structure to allow for those fixes to be applied more cleanly. Signed-off-by: Dave Stevenson --- drivers/dma/bcm2835-dma.c | 46 ++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/drivers/dma/bcm2835-dma.c b/drivers/dma/bcm2835-dma.c index aefaa1f01d7f..ef1d95bae84e 100644 --- a/drivers/dma/bcm2835-dma.c +++ b/drivers/dma/bcm2835-dma.c @@ -65,6 +65,10 @@ struct bcm2835_cb_entry { dma_addr_t paddr; }; +struct bcm2835_dma_chan_map { + dma_addr_t addr; +}; + struct bcm2835_chan { struct virt_dma_chan vc; @@ -74,6 +78,7 @@ struct bcm2835_chan { int ch; struct bcm2835_desc *desc; struct dma_pool *cb_pool; + struct bcm2835_dma_chan_map map; void __iomem *chan_base; int irq_number; @@ -268,6 +273,19 @@ static inline bool need_dst_incr(enum dma_transfer_direction direction) } return false; +}; + +static int bcm2835_dma_map_slave_addr(struct dma_chan *chan, + phys_addr_t dev_addr, + size_t dev_size, + enum dma_data_direction dev_dir) +{ + struct bcm2835_chan *c = to_bcm2835_dma_chan(chan); + struct bcm2835_dma_chan_map *map = &c->map; + + map->addr = dev_addr; + + return 0; } static void bcm2835_dma_free_cb_chain(struct bcm2835_desc *desc) @@ -734,13 +752,19 @@ static struct dma_async_tx_descriptor *bcm2835_dma_prep_slave_sg( } if (direction == DMA_DEV_TO_MEM) { - if (c->cfg.src_addr_width != DMA_SLAVE_BUSWIDTH_4_BYTES) + if (bcm2835_dma_map_slave_addr(chan, c->cfg.src_addr, + c->cfg.src_addr_width, + DMA_TO_DEVICE)) return NULL; - src = c->cfg.src_addr; + + src = c->map.addr; } else { - if (c->cfg.dst_addr_width != DMA_SLAVE_BUSWIDTH_4_BYTES) + if (bcm2835_dma_map_slave_addr(chan, c->cfg.dst_addr, + c->cfg.dst_addr_width, + DMA_FROM_DEVICE)) return NULL; - dst = c->cfg.dst_addr; + + dst = c->map.addr; } /* count frames in sg list */ @@ -795,14 +819,20 @@ static struct dma_async_tx_descriptor *bcm2835_dma_prep_dma_cyclic( __func__, buf_len, period_len); if (direction == DMA_DEV_TO_MEM) { - if (c->cfg.src_addr_width != DMA_SLAVE_BUSWIDTH_4_BYTES) + if (bcm2835_dma_map_slave_addr(chan, c->cfg.src_addr, + c->cfg.src_addr_width, + DMA_TO_DEVICE)) return NULL; - src = c->cfg.src_addr; + + src = c->map.addr; dst = buf_addr; } else { - if (c->cfg.dst_addr_width != DMA_SLAVE_BUSWIDTH_4_BYTES) + if (bcm2835_dma_map_slave_addr(chan, c->cfg.dst_addr, + c->cfg.dst_addr_width, + DMA_FROM_DEVICE)) return NULL; - dst = c->cfg.dst_addr; + + dst = c->map.addr; src = buf_addr; } -- 2.34.1