Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1745389lql; Wed, 13 Mar 2024 07:10:24 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWX0da5fKtauWiz0K08CLrS9vdhoG8IzfhS3vsRNbBMHNjHvnDj8P6b+W0VagRnUKKpDML7q2KyZQj5xRRUgLlYxQE85+2SmGwg9lMajw== X-Google-Smtp-Source: AGHT+IEKwBqKSkzDeARTdiTnjFWdPqusBtIE08pxMhBgt9d2dsRCSlISV6620efU8iWGs4SrF8Mi X-Received: by 2002:a0c:eb4e:0:b0:690:b39e:bf0d with SMTP id c14-20020a0ceb4e000000b00690b39ebf0dmr4389156qvq.8.1710339023944; Wed, 13 Mar 2024 07:10:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710339023; cv=pass; d=google.com; s=arc-20160816; b=FgG1wtSV0XqAA0v5tptE9F/gzu9MI6aDLUWRW1q/s2cQ1n2+ruRxtgOZqcHCFrA8Yg N4OyKkmuvUnss/4NRLkJ5arvbmq/NK9vHPRWPQbxF47scAlJhoXhFETK8Ioc/HPiEkPL Vq5o73+GRjzTYf2xjCwEVG3JBCHx/9ejk4JzH9jTa7OxV0nYl/IxfFIouu89YbKqVKx3 pzpwnxMZCVa7Wgd6PKCk8cfqGOGYGDz8Il03ow2HsTOI9Hg4Yc5Jh2S56YLNAaaIke6s Q2YesyvhvgQJutQOQ9T8V/mnGW41gbZq25q3/YndLxBoJba6PBvhWFq0g/YNejV1nObz hy5Q== 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=3F4XzmOcl2eqQO65zKyWh9Neo+d3tuBvcb7/Ztq+tSY=; fh=iyHFlOxnUGRxnonxqCwqLhS9Rz95olFgu9DZ8AhPTbY=; b=t8HuiIei1v+gN6tT4/ZsrP+3Y3X0OM3PcUJMiU+dWF9ExIqb89VUN2ZhafzQGTESe5 3+cQmP3+P/H2uAo6nuNY5OJ24KmLawPom7bpuGh/pxF3fD5zRaQt8GGdmWMjLIsPsWvT xjnS5/jcYQxLJt1faTiNCj8z+9PWEztf2/6BCspenhiUpklUGcrZ0vT4hA03idOoNCbn ih6aoZwJvWKO+aZxN9quNBeViVagagJH+vV5EVv3pO1xwDZYBKZummF71Pl4OERcRSdh 7vyBBM3W8qKWphZsKjbg/mcDwHzKFHYBqi79WdZwHMnDQ6mXJjUNCZCmTzmZlot7BEwM AcAg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.com header.s=google header.b=eJ6yNPuH; arc=pass (i=1 spf=pass spfdomain=suse.com dkim=pass dkdomain=suse.com dmarc=pass fromdomain=suse.com); spf=pass (google.com: domain of linux-kernel+bounces-101595-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101595-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id c6-20020a056214224600b0068ffe744a27si10214321qvc.63.2024.03.13.07.10.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 07:10:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-101595-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=google header.b=eJ6yNPuH; arc=pass (i=1 spf=pass spfdomain=suse.com dkim=pass dkdomain=suse.com dmarc=pass fromdomain=suse.com); spf=pass (google.com: domain of linux-kernel+bounces-101595-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101595-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id AA80A1C22830 for ; Wed, 13 Mar 2024 14:10:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 80D794645B; Wed, 13 Mar 2024 14:09:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="eJ6yNPuH" Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) (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 2B17B4AEFD for ; Wed, 13 Mar 2024 14:08:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710338941; cv=none; b=jvOW3km5TINZS+1vPkWXQjrgIvHQYxHt43fH1nFWje7HLR9sXvY3IFPf3JLjZccVcaK1veprqEstYHNmP7eblNMey9Mk0dxLsBiY4aBzDaoGmgaP/VMTHv3A+pOoW2XdiJ6CevrTKtiXwtjhWmiY7x5OsRNN3gJ4ouJJc+FqG64= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710338941; c=relaxed/simple; bh=Q1WIk6CPB8+nC5PxADAz/f8d11T7ZlVqHzr3q9+xO00=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gm9lCNd1JpepsVcTKRpoTeQe5X8PskD9q+LzF3aSM2sWvcrU1IUBSy3eQHexXw7dZpWlZulJeq6U+w9soxcmJaQUqwuRL6LdgGS0055SlTjb+so95YzEkiTlseyTb6w6LHeRrkxSQhpfN0p3dSM/K278LjEqMPWZKPM5X74PDjY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=eJ6yNPuH; arc=none smtp.client-ip=209.85.218.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-a44f2d894b7so140304166b.1 for ; Wed, 13 Mar 2024 07:08:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1710338937; x=1710943737; 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=3F4XzmOcl2eqQO65zKyWh9Neo+d3tuBvcb7/Ztq+tSY=; b=eJ6yNPuHNnWgZvjI2kfaGwKTrkeohWo2z1XUchPP0f+A3fGLiceAdsu2AwPBgXp7Wt TMeAlW+E9bEnETEu3Wqgq8x6CxexelTv5ru14h6soOWIbwfhn1V0Nu93JiHgOGBFzbmR SHK7CXByXVXFxrnS3vwXLc3TWLHo8UAZzCGMJVN7dAAt8PsAoQ/j5UxMy2gSIRdN8vix USt+TVN1JuWfr9uKd+IHCgKlbz6+3EQeRs6ym4xfJDnk36cue0/Sa4H/X8Jz3VmsTRfu y7Zvgo/4NBtrqAK/Si8Ettjj3EUC4q2tp7UaU8pkudM/OboAxBxIRDOot3OGHnLhvPf2 e7jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710338937; x=1710943737; 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=3F4XzmOcl2eqQO65zKyWh9Neo+d3tuBvcb7/Ztq+tSY=; b=THChAC39MmAlS/Dqv0uSayChC2ny/EmWzykqndqFT6irTNIYVqm1ybkW2zwCDPJtEr d0eMDffWk2tlTloC26z8MkoEGjKFJmymwfspsj9LCApglMBtzIvtVmw+ZsfCjKQCfbGf s/+dZJmoOFWxlm0d35yVRTMqcsg7HscyuFIQpY1cCY0leWii89S42M5qzAZgWKekBBIO e9c9HbHkF3CVBIpTpIZ9cG7eN0nKmR3dP6LjwA+4UvP/xXCMeoFFlwfXAkYzx2y1jtb2 8hQN/fJ8P7fYuqyONw93Fv4V4s7oqQG6Litw6kLgpPeuTh+FPfFDDZm2t6qLNxCzgJKP yJow== X-Forwarded-Encrypted: i=1; AJvYcCXCIBJ0ePM2gzv6W4d6xlqv1VjFvZHM4GoglJBpCClB/7MDdWpOW55HuJddv85HqVHXErTk49M1Fs+fMucTSky/Luk97JRAcJ+m6vhy X-Gm-Message-State: AOJu0YxS6Z4DC2N6n7IQYmwGoxEszeddf6DDuCIUlCi4D+y1C4w/OjLj yzJkEpmcHhujpYq0C6sg77MywZPRzK13pEzxu3FklBWWQeBIWyTl2N2i/VTbFKQ= X-Received: by 2002:a17:907:94c1:b0:a46:181f:c1c3 with SMTP id dn1-20020a17090794c100b00a46181fc1c3mr5229336ejc.70.1710338937681; Wed, 13 Mar 2024 07:08:57 -0700 (PDT) Received: from localhost (host-82-56-173-172.retail.telecomitalia.it. [82.56.173.172]) by smtp.gmail.com with ESMTPSA id le13-20020a170906ae0d00b00a461d26713fsm3587962ejb.103.2024.03.13.07.08.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 07:08:57 -0700 (PDT) From: Andrea della Porta To: Vinod Koul , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Florian Fainelli , Ray Jui , Scott Branden , Broadcom internal kernel review list , Saenz Julienne , dmaengine@vger.kernel.org, devicetree@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, dave.stevenson@raspberrypi.com Cc: Phil Elwell , Maxime Ripard , Stefan Wahren , Dom Cobley , Andrea della Porta Subject: [PATCH v2 07/15] dmaengine: bcm2835: move CB info generation into separate function Date: Wed, 13 Mar 2024 15:08:32 +0100 Message-ID: <1336c1bc9d7076080f101e530068030640aff8e5.1710226514.git.andrea.porta@suse.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Actually the generation of the Control Block info follows some simple rules. So handle this with a separate function to avoid open coding for every DMA operation. Another advantage is that we can easier introduce other platforms with different info bits. Signed-off-by: Stefan Wahren Signed-off-by: Andrea della Porta --- drivers/dma/bcm2835-dma.c | 54 +++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/drivers/dma/bcm2835-dma.c b/drivers/dma/bcm2835-dma.c index 88aaf7769864..c651aca363c2 100644 --- a/drivers/dma/bcm2835-dma.c +++ b/drivers/dma/bcm2835-dma.c @@ -226,6 +226,34 @@ static inline struct bcm2835_desc *to_bcm2835_dma_desc( return container_of(t, struct bcm2835_desc, vd.tx); } +static u32 bcm2835_dma_prepare_cb_info(struct bcm2835_chan *c, + enum dma_transfer_direction direction, + bool zero_page) +{ + u32 result = WAIT_RESP(c->dreq) | WIDE_SOURCE(c->dreq) | + WIDE_DEST(c->dreq) | BURST_LENGTH(c->dreq); + + if (direction == DMA_MEM_TO_MEM) + return result | BCM2835_DMA_D_INC | BCM2835_DMA_S_INC; + + /* Setup DREQ channel */ + if (c->dreq != 0) + result |= BCM2835_DMA_PER_MAP(c->dreq); + + if (direction == DMA_DEV_TO_MEM) { + result |= BCM2835_DMA_S_DREQ | BCM2835_DMA_D_INC; + } else { + result |= BCM2835_DMA_D_DREQ | BCM2835_DMA_S_INC; + + /* non-lite channels can write zeroes w/o accessing memory */ + if (zero_page && !c->is_lite_channel) { + result |= BCM2835_DMA_S_IGNORE; + } + } + + return result; +} + static void bcm2835_dma_free_cb_chain(struct bcm2835_desc *desc) { size_t i; @@ -656,9 +684,7 @@ static struct dma_async_tx_descriptor *bcm2835_dma_prep_dma_memcpy( { struct bcm2835_chan *c = to_bcm2835_dma_chan(chan); struct bcm2835_desc *d; - u32 info = BCM2835_DMA_D_INC | BCM2835_DMA_S_INC | - WAIT_RESP(c->dreq) | WIDE_SOURCE(c->dreq) | - WIDE_DEST(c->dreq) | BURST_LENGTH(c->dreq); + u32 info = bcm2835_dma_prepare_cb_info(c, DMA_MEM_TO_MEM, false); u32 extra = BCM2835_DMA_INT_EN; size_t max_len = bcm2835_dma_max_frame_length(c); size_t frames; @@ -689,8 +715,7 @@ static struct dma_async_tx_descriptor *bcm2835_dma_prep_slave_sg( struct bcm2835_chan *c = to_bcm2835_dma_chan(chan); struct bcm2835_desc *d; dma_addr_t src = 0, dst = 0; - u32 info = WAIT_RESP(c->dreq) | WIDE_SOURCE(c->dreq) | - WIDE_DEST(c->dreq) | BURST_LENGTH(c->dreq); + u32 info = bcm2835_dma_prepare_cb_info(c, direction, false); u32 extra = BCM2835_DMA_INT_EN; size_t frames; @@ -700,19 +725,14 @@ static struct dma_async_tx_descriptor *bcm2835_dma_prep_slave_sg( return NULL; } - if (c->dreq != 0) - info |= BCM2835_DMA_PER_MAP(c->dreq); - if (direction == DMA_DEV_TO_MEM) { if (c->cfg.src_addr_width != DMA_SLAVE_BUSWIDTH_4_BYTES) return NULL; src = c->cfg.src_addr; - info |= BCM2835_DMA_S_DREQ | BCM2835_DMA_D_INC; } else { if (c->cfg.dst_addr_width != DMA_SLAVE_BUSWIDTH_4_BYTES) return NULL; dst = c->cfg.dst_addr; - info |= BCM2835_DMA_D_DREQ | BCM2835_DMA_S_INC; } /* count frames in sg list */ @@ -742,8 +762,8 @@ static struct dma_async_tx_descriptor *bcm2835_dma_prep_dma_cyclic( struct bcm2835_chan *c = to_bcm2835_dma_chan(chan); struct bcm2835_desc *d; dma_addr_t src, dst; - u32 info = WAIT_RESP(c->dreq) | WIDE_SOURCE(c->dreq) | - WIDE_DEST(c->dreq) | BURST_LENGTH(c->dreq); + u32 info = bcm2835_dma_prepare_cb_info(c, direction, + buf_addr == od->zero_page); u32 extra = 0; size_t max_len = bcm2835_dma_max_frame_length(c); size_t frames; @@ -774,26 +794,16 @@ static struct dma_async_tx_descriptor *bcm2835_dma_prep_dma_cyclic( "%s: buffer_length (%zd) is not a multiple of period_len (%zd)\n", __func__, buf_len, period_len); - /* Setup DREQ channel */ - if (c->dreq != 0) - info |= BCM2835_DMA_PER_MAP(c->dreq); - if (direction == DMA_DEV_TO_MEM) { if (c->cfg.src_addr_width != DMA_SLAVE_BUSWIDTH_4_BYTES) return NULL; src = c->cfg.src_addr; dst = buf_addr; - info |= BCM2835_DMA_S_DREQ | BCM2835_DMA_D_INC; } else { if (c->cfg.dst_addr_width != DMA_SLAVE_BUSWIDTH_4_BYTES) return NULL; dst = c->cfg.dst_addr; src = buf_addr; - info |= BCM2835_DMA_D_DREQ | BCM2835_DMA_S_INC; - - /* non-lite channels can write zeroes w/o accessing memory */ - if (buf_addr == od->zero_page && !c->is_lite_channel) - info |= BCM2835_DMA_S_IGNORE; } /* calculate number of frames */ -- 2.35.3