From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 38FA7C43215 for ; Wed, 13 Nov 2019 20:34:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E3A4A206F0 for ; Wed, 13 Nov 2019 20:34:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726409AbfKMUe3 (ORCPT ); Wed, 13 Nov 2019 15:34:29 -0500 Received: from foss.arm.com ([217.140.110.172]:58006 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726162AbfKMUe3 (ORCPT ); Wed, 13 Nov 2019 15:34:29 -0500 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 2ECF57A7; Wed, 13 Nov 2019 12:34:28 -0800 (PST) Received: from [10.1.196.37] (e121345-lin.cambridge.arm.com [10.1.196.37]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9CFC03F52E; Wed, 13 Nov 2019 12:34:23 -0800 (PST) Subject: Re: [PATCH] dma-mapping: treat dev->bus_dma_mask as a DMA limit To: Nicolas Saenz Julienne , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Bjorn Helgaas , Lorenzo Pieralisi , Hanjun Guo , Sudeep Holla , Jens Axboe , Joerg Roedel , Rob Herring , Frank Rowand , Christoph Hellwig , Marek Szyprowski Cc: Benjamin Herrenschmidt , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux-ide@vger.kernel.org, Paul Mackerras , "H. Peter Anvin" , Paul Burton , Michael Ellerman , x86@kernel.org, phil@raspberrypi.org, linux-acpi@vger.kernel.org, Ingo Molnar , James Hogan , Len Brown , devicetree@vger.kernel.org, Borislav Petkov , Thomas Gleixner , linux-arm-kernel@lists.infradead.org, "Rafael J. Wysocki" , linux-mips@vger.kernel.org, Ralf Baechle , iommu@lists.linux-foundation.org, linuxppc-dev@lists.ozlabs.org References: <20191113161340.27228-1-nsaenzjulienne@suse.de> From: Robin Murphy Message-ID: Date: Wed, 13 Nov 2019 20:34:15 +0000 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <20191113161340.27228-1-nsaenzjulienne@suse.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org On 13/11/2019 4:13 pm, Nicolas Saenz Julienne wrote: > Using a mask to represent bus DMA constraints has a set of limitations. > The biggest one being it can only hold a power of two (minus one). The > DMA mapping code is already aware of this and treats dev->bus_dma_mask > as a limit. This quirk is already used by some architectures although > still rare. > > With the introduction of the Raspberry Pi 4 we've found a new contender > for the use of bus DMA limits, as its PCIe bus can only address the > lower 3GB of memory (of a total of 4GB). This is impossible to represent > with a mask. To make things worse the device-tree code rounds non power > of two bus DMA limits to the next power of two, which is unacceptable in > this case. > > In the light of this, rename dev->bus_dma_mask to dev->bus_dma_limit all > over the tree and treat it as such. Note that dev->bus_dma_limit is > meant to contain the higher accesible DMA address. Neat, you win a "why didn't I do it that way in the first place?" :) Looking at it without all the history of previous attempts, this looks entirely reasonable, and definitely a step in the right direction. [...] > diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c > index 5a7551d060f2..f18827cf96df 100644 > --- a/drivers/acpi/arm64/iort.c > +++ b/drivers/acpi/arm64/iort.c > @@ -1097,7 +1097,7 @@ void iort_dma_setup(struct device *dev, u64 *dma_addr, u64 *dma_size) > * Limit coherent and dma mask based on size > * retrieved from firmware. > */ > - dev->bus_dma_mask = mask; > + dev->bus_dma_limit = mask; Although this preserves the existing behaviour, as in of_dma_configure() we can do better here since we have the original address range to hand. I think it's worth keeping the ACPI and OF paths in sync for minor tweaks like this, rather than letting them diverge unnecessarily. Otherwise, the rest looks OK to me - in principle we could store it as an exclusive limit such that we could then streamline the min_not_zero() tests to just min(mask, limit - 1), but that's probably too clever for its own good. Robin. > dev->coherent_dma_mask = mask; > *dev->dma_mask = mask; > }