From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753151AbcBZLbs (ORCPT ); Fri, 26 Feb 2016 06:31:48 -0500 Received: from mout.kundenserver.de ([212.227.17.13]:49318 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751310AbcBZLbq (ORCPT ); Fri, 26 Feb 2016 06:31:46 -0500 From: Arnd Bergmann To: Alexandre Courbot Cc: Alexandre Courbot , Ulf Hansson , Stephen Warren , Thierry Reding , linux-mmc , "linux-tegra@vger.kernel.org" , Linux Kernel Mailing List Subject: Re: [PATCH] mmc: sdhci-tegra: Set DMA mask Date: Fri, 26 Feb 2016 12:31:36 +0100 Message-ID: <6561324.RvoTsUTSRM@wuerfel> User-Agent: KMail/4.11.5 (Linux/3.16.0-10-generic; KDE/4.11.5; x86_64; ; ) In-Reply-To: References: <1456305079-27779-1-git-send-email-acourbot@nvidia.com> <29473125.UhEGU5khX5@wuerfel> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Provags-ID: V03:K0:ssg1JTWY9jlj1wVhnX0AcOXQJzi+GxoO8MIQ7byq4tWkJ3Kh+f3 oLcVzU4wdgQosrejOK05eAFARcVsFuPmVHglHfvbUkBrHqTISjuQNQlpthFrcoQHUPZVxv5 rFkgoD9QKjaOfzVxxihI+n7h2dw4rjkUQogIxU2d6tYIgEf1A1zPeSJPMywBzC0yLST8kAv uiq0UrEeImLQQOuYDk8Tw== X-UI-Out-Filterresults: notjunk:1;V01:K0:sHGjC2+a9Qc=:48iWQuZFA8kUpEpRJqLERO mbG5T33DYqNpCroCox025p3mUkLjcdF98548+zO/WOt4X6OXkPj14vwBjUYMsiFEx8sMMBIQX B0myynh5wYdkKR7yO8/7Uyo19D5eB4H05geA3hYcMrOFRo9PBqbXx4FFFWtlW91PzsfoR2xl/ X5qTkR0sRvWRSv7QDE09XWioM7gjgb7xEjBcwjKSChzYFELOm9T+Z0IvJNjcREOFmxToHDT5W dM7lDH9oKrq6GrzvGXnRGW2PpFd8aCFra6RhIQtkYHaRniVW2j/++LrFG9Dg49A9f0Tgnhvwb KDJ4cK/E1mj5DTx+9aZOcYU2LeiIsHwW8RbLvoUL8JX6zj1VCiI/d7v4Ld99ywMTtjK46faQP uenlVQ4hHKUmwH3mIiY8phmjtc17NMB+CK3yO/c/JGej5NGV/oqPCich10w9lwwASZ3AWqFaG 1GNs4H4bm01tPR9drMysFSszc6b9MZzN1W2FrYj/LEjSv13jBqziEUxZpzC3NlGEACFC0bHVJ GlBTcuT/UurNIYrdYxoXAv/nZE3lgruwyGDwa9HAlXI8b2ENnDdKCHsv1fr3s1LpVNnjMQDtr gco7hiVVkUzMPy2bTH6KLvCUL68jcewSXvI46VlA0mV71ODPNd2YSC+NpFrGOJs5WNFYKHbWE TW8W60MVw281HVI/aF8J6pyTNRl/G8xAgtXHzogMGn9kwXEZ4n08JdY4mfSpD7AHe0rM7e4Oy oOhlvTq201LYhD7z Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Friday 26 February 2016 16:24:34 Alexandre Courbot wrote: > On Thu, Feb 25, 2016 at 11:52 PM, Arnd Bergmann wrote: > >> Actually even if we specify a dma-ranges on the parent DT node, the > >> DMA range will still be limited to 32 bits because of the following > >> code in of_dma_configure(): > >> > >> /* > >> * Set default coherent_dma_mask to 32 bit. Drivers are expected to > >> * setup the correct supported mask. > >> */ > >> if (!dev->coherent_dma_mask) > >> dev->coherent_dma_mask = DMA_BIT_MASK(32); > >> > >> /* > >> * Set it to coherent_dma_mask by default if the architecture > >> * code has not set it. > >> */ > >> if (!dev->dma_mask) > >> dev->dma_mask = &dev->coherent_dma_mask; > >> > >> .... > >> /* gets dma-ranges into dma_addr and size */ > >> .... > >> > >> > >> *dev->dma_mask = min((*dev->dma_mask), > >> DMA_BIT_MASK(ilog2(dma_addr + size))); > >> > >> So unless the DMA mask is set on the device before of_dma_configure() > >> is called, the min() statement will choose the 32 bits mask that has > >> been previously set. So IIUC in any case, the driver will need to call > >> dma_set_mask() > > > > Yes, the driver definitely has to call dma_set_mask(), the property of > > the parent bus is used to make that fail when the bus doesn't support > > it. > > And that's where things seem to stop working: the driver's probe > function is invoked by the platform bus, *after* of_dma_configure() is > called. So unless I am missing something there is no way for the > driver to set the DMA mask in such a way that of_dma_configure() can > see it and do the right thing. > > In other words, most of the DMA mask logic in of_dma_configure() > doesn't seem to have any effect (and a 32 bits mask will be set), at > least on the platform bus. That is correct: of_dma_configure has to set a 32-bit DMA mask because that is the default that we expect to see in Linux drivers. A lot of drivers don't call dma_set_mask() at all, so this is the most reasonable value that typically works, unless the device is more limited, or you want the extra performance you get on devices that actually support a bigger mask. > >> Can I have your thoughts on this? Am I missing something? > > > > One point: I think the dma_set_mask() probably should be in the > > generic part of the sdhci driver, not the tegra specific portion. > > Ok, but then how does the generic part of the driver knows which DMA > mask applies to the device? If dma_set_mask() succeeds when passed a 64-bit mask, the driver can pass high addresses into dma_map_*() and put the result into the 64-bit DMA registers of the device. That is all the driver needs to know here. When the bus is more limited than the device, we either have an swiotlb/iommu that will use bounce buffers to map dma_map_* work anyway (using low DMA addresses for high memory), or we don't have an swiotlb and the dma_set_mask() operation has to fail. Arnd