All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kever Yang <kever.yang@rock-chips.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATH V2] usb: dwc2: invalidate the dcache before starting the DMA
Date: Thu, 6 Apr 2017 16:34:15 +0800	[thread overview]
Message-ID: <07c327aa-168f-82c8-e17c-b5999e6fcf60@rock-chips.com> (raw)
In-Reply-To: <960119ca-b657-11c1-5b2b-adebe688e215@denx.de>

Hi Eddie,


On 04/06/2017 10:14 AM, Marek Vasut wrote:
> On 04/06/2017 04:03 AM, Eddie Cai wrote:
>> We should invalidate the dcache before starting the DMA. In case there are
>> any dirty lines from the DMA buffer in the cache, subsequent cache-line
>> replacements may corrupt the buffer in memory while the DMA is still going on.
>> Cache-line replacement can happen if the CPU tries to bring some other memory
>> locations into the cache while the DMA is going on.
>>
>> Signed-off-by: Eddie Cai <eddie.cai.linux@gmail.com>
>> Reviewed-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
>> ---
>>   drivers/usb/host/dwc2.c | 19 +++++++++++++------
>>   1 file changed, 13 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/usb/host/dwc2.c b/drivers/usb/host/dwc2.c
>> index 5ac602e..e3a5d7d 100644
>> --- a/drivers/usb/host/dwc2.c
>> +++ b/drivers/usb/host/dwc2.c
>> @@ -811,12 +811,19 @@ static int transfer_chunk(struct dwc2_hc_regs *hc_regs, void *aligned_buffer,
>>   	       (*pid << DWC2_HCTSIZ_PID_OFFSET),
>>   	       &hc_regs->hctsiz);
>>   
>> -	if (!in && xfer_len) {
>> -		memcpy(aligned_buffer, buffer, xfer_len);
>> -
>> -		flush_dcache_range((unsigned long)aligned_buffer,
>> -				   (unsigned long)aligned_buffer +
>> -				   roundup(xfer_len, ARCH_DMA_MINALIGN));
>> +	if (xfer_len) {
>> +		if (in) {
>> +			invalidate_dcache_range(
>> +					(unsigned long)aligned_buffer,
>> +					(unsigned long)aligned_buffer +
> Should be uintptr_t all over the place to deal with 32/64 bit systems,
> otherwise great, thanks.
>
>> +					roundup(xfer_len, ARCH_DMA_MINALIGN));
>> +		} else {
>> +			memcpy(aligned_buffer, buffer, xfer_len);
>> +			flush_dcache_range(
>> +					(unsigned long)aligned_buffer,
>> +					(unsigned long)aligned_buffer +
>> +					roundup(xfer_len, ARCH_DMA_MINALIGN));
>> +		}
>>   	}
>>   
>>   	writel(phys_to_bus((unsigned long)aligned_buffer), &hc_regs->hcdma);
>>

Did you test with remove another invalidate_dcache_range() in this function?
I still think no need to have 2 invalidate_dcache in this function.

Thanks,
- Kever
>

  reply	other threads:[~2017-04-06  8:34 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-06  2:03 [U-Boot] [PATH V2] usb: dwc2: invalidate the dcache before starting the DMA Eddie Cai
2017-04-06  2:14 ` Marek Vasut
2017-04-06  8:34   ` Kever Yang [this message]
2017-04-06 10:20     ` Marek Vasut
2017-04-18  3:55       ` Kever Yang
2017-04-18 10:56         ` Eddie Cai

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=07c327aa-168f-82c8-e17c-b5999e6fcf60@rock-chips.com \
    --to=kever.yang@rock-chips.com \
    --cc=u-boot@lists.denx.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.