From patchwork Fri May 24 18:26:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Stevenson X-Patchwork-Id: 13673527 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C4B5EC25B79 for ; Fri, 24 May 2024 18:30:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=WPMboe5ZcoVa3r8YT8lXr2/g4id591dtGl/x/FLuzDE=; b=0XaFwhqOEvtr8T NP3FJlcsd68ygsYxG9uyLT5MMjUUsCsXC1aKqttzHXbuZOGPxtQSMnLD7cEGRa9vYQpK5iszOGCg6 rLIzjvF4bKGNRAtcRj5dWAorm6g4Q12ryVegqvV+hpwckpxgwJBxPN5DGa1EG/IzuZEpNNS195RgX /2AAa47G6Sz7QUYnRSbTgSELgvbLP02ZZSRrlxVDb+bK9hKgFvS5b8UerUJKjOiXsWXeoJZynzweh gV82Wbn1QHjO2tcX9PhYR+PbbsthbnpdSN+U0hpRww6UkGWNE8BKix1plvh2EaUWCPCsTh2S0okA5 JzpiYW4t1obKriLIiYYA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sAZg1-00000009aa5-14uM; Fri, 24 May 2024 18:30:01 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sAZeF-00000009ZJp-0fvk for linux-arm-kernel@bombadil.infradead.org; Fri, 24 May 2024 18:28:11 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=k5/0PmDw861toPHKUvcW29ls0QVOfTRw5AjJ+CnPD2s=; b=Phhl5jJbQLlwU9SOhH/jP5pc1J cwdf5Z82En0KqHLAPY8GmztmJQtSmZC87Uc+INDImxEKOs1PVNp+exbb+ONCd4iI+PXkP0r8CV46x ATzLciqbL/Q3zp34q0+BDScJaYWgnQ2S9LNo20grLQ+R7lN/Uwjis6rT+WsgMqLgGeKQPzstP0vs2 Me8v4vDLunSU2Tq+r9zv0uUftuckAgdw22GVT2r3qSuqBqRYKGhkv4UpRWXYqRjo2qtW6CkhrERPx FYPCRO9Jgfw1DzYGVuJ5IFLW65cdReUoG6NdExECrv84DjKgO7/ivruETE4PNhvkapr+v+TaC2BIw CeZCbsHQ==; Received: from mail-lj1-x263.google.com ([2a00:1450:4864:20::263]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sAZe4-00000009vJ6-2RuC for linux-arm-kernel@lists.infradead.org; Fri, 24 May 2024 18:28:09 +0000 Received: by mail-lj1-x263.google.com with SMTP id 38308e7fff4ca-2e6f51f9de4so107026771fa.3 for ; Fri, 24 May 2024 11:27:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1716575277; x=1717180077; darn=lists.infradead.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=Dh6NQKltq7FpXHQmBpFEyZXRgz5Yg6aTm8tvHIX+OaPu99iN4qMaixQ0T9h7eJRJvb 2p1T/F0mt0piHiaU+St7kDfQeopS5e/WdyXt7EqdjdVgJCWX4SlLJ7rUAUXfhKNV8TJC 2eLnZhzOvsAfyE2AFJhSEIkSZV8+44n6LOr0NQHuiL0L468fco6rikvS81SlvXh8ZZGt D+jOTOnNSqr/92doZkKgyWx65abTSzdYozv8/6JcEnU6fLS9L9kV6QNtPe/OBmSs7fzx XJj/KTiIpk3d53JHKNVD3qsFZeZx+3BHnF/8CDILmXWnqox8ec9N1jyT3UPAnuctttZP dnmg== 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=SWrgG4wqv/Cg6sry2wWG7vz0fYGjRaV+YG4JgqfriMhJWqRk9jOzkdFIkAg184cmsH MkYaa1zd+XyJEgbcrdTaqIKfziHwHKFCoOmtVAkuxVRyqksh6ZjplzjKfkUa3LvV8MYf brVYnsQX5SBL46+loje+Z3qqod7Sl0zYxir+HxmJnAIFDzTn/rpvpfOiVzFC+QxZgxda 9aFT6siXYr0PU+r7TM6ppSHit2T7dLwfTR05R8CvuIORYL6JkxMwri5C7BBrChbVPhby TwGZLSSYWbS+Y79vuC0rsY606yH6JPP0h0wNrFGpVhIMQUgRJaRe3dcn95ncrQjD8o+G dgBg== X-Forwarded-Encrypted: i=1; AJvYcCXUXWIquPwcrFGqhIi3+niFjC0Qu2ZQL3Bujc9utodwDUnvPlq23wfdKHjPIyqByiU4/swos047PLEut2Jtft0tEFLR16uZ75fuJxHtb9BvFzVJ5i8= X-Gm-Message-State: AOJu0Yy6NsrIMO19blM5LXEctZnkwIowggkcu9YJnEA7mPbk5AzXL7dP ein3q2zbRxgQIz2pK51fYUbYziQvp9ZNPUieiTlfW4zXdLYsd042t4ZupkyAy3SpfrZCviG+Bu8 760ekfuzHoEaMTha7jKZirk692VK1k39W X-Google-Smtp-Source: AGHT+IEHAWM6BIO0Edq+CWHOn6Y+ZIrJttwNlxlncG6HGF/KksFdkfl8n2+vvBn5hfO9zRO5ovw/15yBiAgP 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240524_192801_726018_1BC74387 X-CRM114-Status: GOOD ( 16.57 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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; }