All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Ujfalusi <peter.ujfalusi@ti.com>
To: Takashi Iwai <tiwai@suse.de>,
	Russell King - ARM Linux <linux@arm.linux.org.uk>
Cc: alsa-devel@alsa-project.org, Mark Brown <broonie@kernel.org>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Jarkko Nikula <jarkko.nikula@bitmer.com>
Subject: Re: [PATCH] ASoC: omap-pcm: Lower the dma coherent mask to 32bits
Date: Mon, 9 Dec 2013 11:56:03 +0200	[thread overview]
Message-ID: <52A593B3.1010607@ti.com> (raw)
In-Reply-To: <s5hpppa3zc9.wl%tiwai@suse.de>

On 12/06/2013 03:04 PM, Takashi Iwai wrote:
> At Fri, 6 Dec 2013 12:25:43 +0000,
> Russell King - ARM Linux wrote:
>>
>> On Fri, Dec 06, 2013 at 09:12:22AM +0100, Takashi Iwai wrote:
>>> But, it's still unclear why only get_coherent_dma_mask() takes max_pfn
>>> into account for the check of dma_to_pfn(dev, mask).
>>>
>>> In dma_supported(), 
>>>
>>> 	unsigned long limit;
>>> 	limit = dma_to_pfn(dev, mask);
>>> 	if (limit < arm_dma_pfn_limit)
>>> 		return 0;
>>>
>>> while in get_coherent_dma_mask(),
>>>
>>> 	unsigned long max_dma_pfn;
>>> 	max_dma_pfn = min(max_pfn, arm_dma_pfn_limit);
>>> 	if (dma_to_pfn(dev, mask) < max_dma_pfn)
>>> 		return 0;
>>>
>>> So, the current code looks to me that the results from
>>> dma_set_coherent_mask() and the actual allocation may conflict.
>>
>> I did ask Peter to replace *both* with the same thing.
> 
> Well, I'm looking at different points.  You requested Peter to test
> both functions to take:
> 
>  	if (sizeof(mask) != sizeof(dma_addr_t) &&
>  	    mask > (dma_addr_t)~0 &&
>  	    dma_to_pfn(dev, ~0) < min(max_pfn, arm_dma_pfn_limit))
> 		return 0;
> 
> But, after that line, dma_supported() has another check:
> 
>  	if (dma_to_pfn(dev, mask) < arm_dma_pfn_limit)
>  		return 0;
> 
> and get_coherent_dma_mask() has a different check:
> 
>  	if (dma_to_pfn(dev, mask) < min(max_pfn, arm_dma_pfn_limit))
>  		return 0;
> 
> (the expressions here are expanded for easier comparison)
> 
> This is what I'm wondering.


The tests in get_coherent_dma_mask() and dma_supported() should be identical.
Fixing the dma_supported() checks and calling dma_supported() from
get_coherent_dma_mask() instead of doing the same test coded locally there
should be the preferred solution.

I think dma_supported() should be like this:

int dma_supported(struct device *dev, u64 mask)
{
	unsigned long max_dma_pfn;

	/*
	 * If the mask allows for more memory than we can address,
	 * and we actually have that much memory, then we must
	 * indicate that DMA to this device is not supported.
	 */
	max_dma_pfn = min(max_pfn, arm_dma_pfn_limit);
	if (sizeof(mask) != sizeof(dma_addr_t) &&
	    mask > (dma_addr_t)~0 &&
	    dma_to_pfn(dev, ~0) < max_dma_pfn)
		return 0;

	/*
	 * Translate the device's DMA mask to a PFN limit.  This
	 * PFN number includes the page which we can DMA to.
	 */
	if (dma_to_pfn(dev, mask) < max_dma_pfn)
		return 0;

	return 1;
}


-- 
Péter

  reply	other threads:[~2013-12-09  9:56 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-05  8:06 [PATCH] ASoC: omap-pcm: Lower the dma coherent mask to 32bits Peter Ujfalusi
2013-12-05  9:56 ` Russell King - ARM Linux
2013-12-05 15:33   ` Peter Ujfalusi
2013-12-05 19:28     ` Russell King - ARM Linux
2013-12-05 20:11       ` Takashi Iwai
2013-12-05 21:07         ` Russell King - ARM Linux
2013-12-06  8:12           ` Takashi Iwai
2013-12-06 12:25             ` Russell King - ARM Linux
2013-12-06 13:04               ` Takashi Iwai
2013-12-09  9:56                 ` Peter Ujfalusi [this message]
2013-12-09 17:03             ` Russell King - ARM Linux
2013-12-10  9:37               ` Peter Ujfalusi
2013-12-10 10:00                 ` Peter Ujfalusi
2013-12-13 11:46                 ` Peter Ujfalusi
2013-12-13 11:49                   ` Russell King - ARM Linux
2013-12-13 11:50                     ` Peter Ujfalusi
2013-12-06  9:31       ` Peter Ujfalusi
2013-12-06 12:33         ` Russell King - ARM Linux

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=52A593B3.1010607@ti.com \
    --to=peter.ujfalusi@ti.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=jarkko.nikula@bitmer.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux@arm.linux.org.uk \
    --cc=tiwai@suse.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.