linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: robin.murphy@arm.com (Robin Murphy)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 7/7] OF: Don't set default coherent DMA mask
Date: Fri, 27 Jul 2018 12:36:00 +0100	[thread overview]
Message-ID: <c7a9c7ae-1f4a-af9d-df78-1f48bb5c28a5@arm.com> (raw)
In-Reply-To: <92d6b010-b5c0-fc59-0668-5b455e26c912@ti.com>

On 27/07/18 01:22, Grygorii Strashko wrote:
[...]
>> the result of this change is pretty strange as for me :(
>> Resulted code:
>>
>> 	/*
>> 	 * If @dev is expected to be DMA-capable then the bus code that created
>> 	 * it should have initialised its dma_mask pointer by this point. For
>> 	 * now, we'll continue the legacy behaviour of coercing it to the
>> 	 * coherent mask if not, but we'll no longer do so quietly.
>> 	 */
>> 	if (!dev->dma_mask) {
>> 		dev_warn(dev, "DMA mask not set\n");
>> 		dev->dma_mask = &dev->coherent_dma_mask;
>> ^this will always produce warning in case of platform-bus or if there are no bus driver.
>> even if DT contains correct definition of dma-range
>> 	}
>>
>> 	if (!size && dev->coherent_dma_mask)
>>
>> ^ coherent_dma_mask is zero, so size will not be calculated
> pls, ignore this particular comment
> 
>> 		size = max(dev->coherent_dma_mask, dev->coherent_dma_mask + 1);
>> 	else if (!size)
>> 		size = 1ULL << 32;
>>
>> 	dev->dma_pfn_offset = offset;
>>
>> 	/*
>> 	 * Limit coherent and dma mask based on size and default mask
>> 	 * set by the driver.
>> 	 */
>> 	mask = DMA_BIT_MASK(ilog2(dma_addr + size - 1) + 1);
>> 	dev->bus_dma_mask = mask;
>> 	dev->coherent_dma_mask &= mask;
>>
>> ^^ if nobody set coherent_dma_mask before it will stay null forever unless drivers
>> will overwrite it. Again even if DT has correct definition for dma-range.

That is intentional. Consider a 32-bit device on a bus with an upstream 
DMA range of 40 bits (which could easily happen with e.g. PCI). If the 
firmware code gives that device 40-bit DMA masks and the driver doesn't 
change them, then DMA is not going to work correctly. Therefore the 
firmware code cannot safely make {coherent_}dma_mask larger than the 
default value passed in, and if the default is 0 then that should be 
fixed in whatever code created the device, not worked around later.

Robin.

>>
>> 	*dev->dma_mask &= mask;
>>
>> 	coherent = of_dma_is_coherent(np);
>> 	dev_dbg(dev, "device is%sdma coherent\n",
>> 		coherent ? " " : " not ");
>>
>>
> 
> FYI, with below diff i can boot at least:
> 
> diff --git a/drivers/of/device.c b/drivers/of/device.c
> index 5957cd4..f7dc121 100644
> --- a/drivers/of/device.c
> +++ b/drivers/of/device.c
> @@ -150,8 +150,8 @@ int of_dma_configure(struct device *dev, struct device_node *np, bool force_dma)
>           */
>          mask = DMA_BIT_MASK(ilog2(dma_addr + size - 1) + 1);
>          dev->bus_dma_mask = mask;
> -       dev->coherent_dma_mask &= mask;
> -       *dev->dma_mask &= mask;
> +       dev->coherent_dma_mask = mask;
> +       *dev->dma_mask = mask;
>   
>          coherent = of_dma_is_coherent(np);
>          dev_dbg(dev, "device is%sdma coherent\n",
> 
> 
> 

  reply	other threads:[~2018-07-27 11:36 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-23 22:16 [PATCH v2 0/7] Stop losing firmware-set DMA masks Robin Murphy
2018-07-23 22:16 ` [PATCH v2 1/7] ACPI/IORT: Support address size limit for root complexes Robin Murphy
2018-07-23 22:16 ` [PATCH v2 2/7] dma-mapping: Generalise dma_32bit_limit flag Robin Murphy
2018-07-25 11:29   ` Christoph Hellwig
2018-07-27 17:45   ` Grygorii Strashko
2018-07-27 20:11     ` Robin Murphy
2018-07-27 20:41       ` Grygorii Strashko
2018-07-23 22:16 ` [PATCH v2 3/7] ACPI/IORT: Set bus DMA mask as appropriate Robin Murphy
2018-07-25 11:29   ` Christoph Hellwig
2018-07-25 13:16   ` Lorenzo Pieralisi
2018-07-23 22:16 ` [PATCH v2 4/7] of/device: " Robin Murphy
2018-07-25 11:30   ` Christoph Hellwig
2018-07-23 22:16 ` [PATCH v2 5/7] iommu/dma: Respect bus DMA limit for IOVAs Robin Murphy
2018-07-26  8:58   ` Christoph Hellwig
2018-07-23 22:16 ` [PATCH v2 6/7] ACPI/IORT: Don't set default coherent DMA mask Robin Murphy
2018-07-25 15:27   ` Lorenzo Pieralisi
2018-07-25 15:43     ` Robin Murphy
2018-07-23 22:16 ` [PATCH v2 7/7] OF: " Robin Murphy
2018-07-26 23:52   ` Grygorii Strashko
2018-07-27  0:22     ` Grygorii Strashko
2018-07-27 11:36       ` Robin Murphy [this message]
2018-07-27 17:34         ` Grygorii Strashko
2018-07-27 19:46           ` Robin Murphy
2018-07-27 18:13         ` Russell King - ARM Linux
2018-07-27 18:45           ` Grygorii Strashko
2018-07-27 20:42             ` Robin Murphy
2018-07-27 19:29           ` Robin Murphy
2018-07-25 11:31 ` [PATCH v2 0/7] Stop losing firmware-set DMA masks Christoph Hellwig
2018-07-25 12:11   ` Joerg Roedel
2018-07-25 12:12   ` Robin Murphy
2018-07-25 12:17     ` Will Deacon
2018-07-25 13:58   ` Ard Biesheuvel
2018-07-26  9:00 ` Christoph Hellwig
2018-07-26 23:45 ` Grygorii Strashko
2018-07-27 10:55   ` Robin Murphy
2018-07-27 17:22     ` Grygorii Strashko
2018-07-29 12:32 ` Arnd Bergmann
2018-07-31 11:24   ` Robin Murphy
2018-08-06 10:01     ` Arnd Bergmann
2018-08-06 12:13       ` Christoph Hellwig
2018-08-06 12:13         ` Arnd Bergmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c7a9c7ae-1f4a-af9d-df78-1f48bb5c28a5@arm.com \
    --to=robin.murphy@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).