Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp2558521rdb; Mon, 5 Feb 2024 10:04:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IHV8d30agsiUeH1CCuv6k82i6vU87zHSNJ/kXsiGQLRaNbos/eWBzOYLRxSb8+O0U30yklC X-Received: by 2002:a17:90a:f286:b0:296:1e9:2c91 with SMTP id fs6-20020a17090af28600b0029601e92c91mr185296pjb.31.1707156278813; Mon, 05 Feb 2024 10:04:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707156278; cv=pass; d=google.com; s=arc-20160816; b=QUeHrMbyQ5shYMkR9W7mMx7b7xYzlLHBNFUr8SzD3jUTrxqH80v4F53II4b4Z3t4zJ p6Ci7kZqqfGDynPMo1K7RNQ91D9lHBnb9qXAOJIArTzZ/g29SOMRdAGODUV+kAgiiqcI 9bur9kpMs0J146NQNcMl8mDMofdJ4GN2s4V4jXKczd00rtLWRA/1lwEWKvruCImFq45w foYkmAlMw14t5FJKl50Y7EtgV8W4lGl8x5sfuKkeYR7G73YzaBTTP+pukMZArpwXUhTe wb7KkByYt4A8EUoMRYo74lz105K2CYbHo5vVPVV5n2de4hX/NbEZiAb/UjvxzG5sXbQY gx/A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=tPLP9OkxHICJfXGejI3/H51SrP6O8kiUdhtCIVdwvGU=; fh=rAZcQhYBr2lP5MkPljAEGL9E8E8cjduZvyWfNY3I/pk=; b=yhOqVo2SnRD3rZkD8Znmq9YOOiNagAxwihIvegrJ2BpIt6Ev/UtA5DhPZfgA038Q// F4/S1DOqFxqP8Ne9Q5kAlyvIN2uYO53RAyKEr2UxmsuxSigjFDMBC9oaj+HsY2GchlSP zARIy6RCwhV+cHrSKMe9y52mrELLeeO5DUgA3/eJjFYpsnTkgdC6KJOIZO9v5P9K+x8e 3WPs0A+E+3yGMEMLXfI+BBjn5AGcgrvYxYeItyoi11QZMpoyDJv+K5BnxiKZ4EAmWMwr 5MUH98o5AVwEFTSi7tsCepAkj8aa6GyT36ucXOSd7EGA0p8/9MYjEbXo55ICOgjQBGHd k8CQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-53177-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53177-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=1; AJvYcCWjerK3F0DmK4GYTDcD9rcFgqDM5LGG7mx6iVOd+q2gi6XqZYZOxStnkmYDHj8VKhR2lRyj83hzzn7uHzNs3OBcK5V0iF4XEU860C9qUg== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id fk1-20020a056a003a8100b006ddc61d9b9csi150431pfb.35.2024.02.05.10.04.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 10:04:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-53177-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-53177-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53177-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id C35382826B5 for ; Mon, 5 Feb 2024 18:04:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A67CA47A7B; Mon, 5 Feb 2024 18:04:00 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 05CAB44C66; Mon, 5 Feb 2024 18:03:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707156240; cv=none; b=HpXDpaOdxUl2mFDeVzKKGninC0v64FRZU9dCNveFEvj7MSYo1pVmazHsb/AnF9aD55vIoRdETF4O7UYMzWDYAFPZn420Wh3b46oXuDJWREZTkesFyOLo3aixPDfsbDhr0IQIJJDPfEwlMq6sjDudl7bdmcTpg1CS1mzRod6LGYw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707156240; c=relaxed/simple; bh=acHH8lLMt/+fXy9cDtqL91wGghvqnB/fGWuddTkpbls=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Os0AYlcbGpQOajvi6FoCkJsMSl71ZLlon7WDJquF/37rXpdpgqLzY+y2BSh8K5sFl6K9kjyHU5AiyedGPvNc85kV+Ho5zlyMMkW1czVjDNvT1e26XXRb6B9n8RtqnKgRp7H/u7ZFQlbtsw0llbcjgp29eR4hAswpN9J+UO9QPYQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1D0E212FC; Mon, 5 Feb 2024 10:04:39 -0800 (PST) Received: from [10.57.48.140] (unknown [10.57.48.140]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 651753F5A1; Mon, 5 Feb 2024 10:03:54 -0800 (PST) Message-ID: Date: Mon, 5 Feb 2024 18:03:53 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 05/12] bcm2835-dma: Derive slave DMA addresses correctly Content-Language: en-GB To: Andrea della Porta , Vinod Koul , Florian Fainelli , Ray Jui , Scott Branden , Broadcom internal kernel review list , dmaengine@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, "iommu@lists.linux.dev" Cc: Maxime Ripard , Dom Cobley , Phil Elwell References: <30da53ebdf43b712da790fd2ae0f0040f71762b8.1706948717.git.andrea.porta@suse.com> From: Robin Murphy In-Reply-To: <30da53ebdf43b712da790fd2ae0f0040f71762b8.1706948717.git.andrea.porta@suse.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2024-02-04 6:59 am, Andrea della Porta wrote: > From: Phil Elwell > > Slave addresses for DMA are meant to be supplied as physical addresses > (contrary to what struct snd_dmaengine_dai_dma_data does). It is up to > the DMA controller driver to perform the translation based on its own > view of the world, as described in Device Tree. > > Now that the Pi Device Trees have the correct peripheral mappings, > replace the hacky address munging with phys_to_dma(). > > Signed-off-by: Phil Elwell > --- > drivers/dma/bcm2835-dma.c | 23 +++++------------------ > 1 file changed, 5 insertions(+), 18 deletions(-) > > diff --git a/drivers/dma/bcm2835-dma.c b/drivers/dma/bcm2835-dma.c > index 237dcdb8d726..077812eda609 100644 > --- a/drivers/dma/bcm2835-dma.c > +++ b/drivers/dma/bcm2835-dma.c > @@ -18,6 +18,7 @@ > * Copyright 2012 Marvell International Ltd. > */ > #include > +#include Please read the comment at the top of that file; this driver is definitely not a DMA API implementation, and should not be including it. > #include > #include > #include > @@ -980,22 +981,12 @@ 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) > return NULL; > - src = c->cfg.src_addr; > - /* > - * One would think it ought to be possible to get the physical > - * to dma address mapping information from the dma-ranges DT > - * property, but I've not found a way yet that doesn't involve > - * open-coding the whole thing. > - */ > - if (c->is_40bit_channel) > - src |= 0x400000000ull; > + src = phys_to_dma(chan->device->dev, c->cfg.src_addr); FWIW I'd argue that abusing DMA API internals like this is even more hacky than bypassing it entirely. The appropriate public API for setting up the device end of a transfer is dma_map_resource(). Now, it *is* the case currently that the dma-direct implementation of that does not take dma_range_map into account, but that's already an open question: https://lore.kernel.org/linux-iommu/20220610080802.11147-1-Sergey.Semin@baikalelectronics.ru/ Thanks, Robin. > 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; > - if (c->is_40bit_channel) > - dst |= 0x400000000ull; > + dst = phys_to_dma(chan->device->dev, c->cfg.dst_addr); > info |= BCM2835_DMA_D_DREQ | BCM2835_DMA_S_INC; > } > > @@ -1064,17 +1055,13 @@ static struct dma_async_tx_descriptor *bcm2835_dma_prep_dma_cyclic( > if (direction == DMA_DEV_TO_MEM) { > if (c->cfg.src_addr_width != DMA_SLAVE_BUSWIDTH_4_BYTES) > return NULL; > - src = c->cfg.src_addr; > - if (c->is_40bit_channel) > - src |= 0x400000000ull; > + src = phys_to_dma(chan->device->dev, 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; > - if (c->is_40bit_channel) > - dst |= 0x400000000ull; > + dst = phys_to_dma(chan->device->dev, c->cfg.dst_addr); > src = buf_addr; > info |= BCM2835_DMA_D_DREQ | BCM2835_DMA_S_INC; >