public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Mike Frysinger <vapier@gentoo.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 4/4] USB:gadget:designware Fix memory nonalignment issue
Date: Tue, 6 Mar 2012 11:08:09 -0500	[thread overview]
Message-ID: <201203061108.12155.vapier@gentoo.org> (raw)
In-Reply-To: <201203061051.57410.marex@denx.de>

On Tuesday 06 March 2012 04:51:57 Marek Vasut wrote:
> > On 3/5/2012 11:51 PM, Marek Vasut wrote:
> > > Amit Virdi wrote:
> > >> While receiving packets from FIFO sometimes the buffer provided was
> > >> nonaligned. Fix this by taking a temporary aligned buffer and then
> > >> copying the content to nonaligned buffer.
> > >> 
> > >> --- a/drivers/usb/gadget/designware_udc.c
> > >> +++ b/drivers/usb/gadget/designware_udc.c
> > >> @@ -202,6 +202,7 @@ static int usbgetpckfromfifo(int epNum, u8 *bufp,
> > >> u32 len) u32 i, nw, nb;
> > >> 
> > >>   	u32 *wrdp;
> > >>   	u8 *bytp;
> > >> 
> > >> +	u32 tmp[128];
> > >> 
> > >>   	if (readl(&udc_regs_p->dev_stat)&  DEV_STAT_RXFIFO_EMPTY)
> > >>   	
> > >>   		return -1;
> > >> 
> > >> @@ -209,7 +210,12 @@ static int usbgetpckfromfifo(int epNum, u8 *bufp,
> > >> u32 len) nw = len / sizeof(u32);
> > >> 
> > >>   	nb = len % sizeof(u32);
> > >> 
> > >> -	wrdp = (u32 *)bufp;
> > >> +	/* use tmp buf if bufp is not word aligned */
> > >> +	if ((int)bufp&  0x3)
> > >> +		wrdp = (u32 *)&tmp[0];
> > >> +	else
> > >> +		wrdp = (u32 *)bufp;
> > >> +
> > >> 
> > >>   	for (i = 0; i<  nw; i++) {
> > >>   	
> > >>   		writel(readl(fifo_ptr), wrdp);
> > >>   		wrdp++;
> > >> 
> > >> @@ -223,6 +229,13 @@ static int usbgetpckfromfifo(int epNum, u8 *bufp,
> > >> u32 len) }
> > >> 
> > >>   	readl(&outep_regs_p[epNum].write_done);
> > >> 
> > >> +	/* copy back tmp buffer to bufp if bufp is not word aligned */
> > >> +	if ((int)bufp&  0x3) {
> > >> +		bytp = (u8 *)&tmp[0];
> > >> +		for (i = 0; i<  len; i++)
> > >> +			bufp[i] = bytp[i];
> > >> +	}
> > >> +
> > >> 
> > >>   	return 0;
> > >>   
> > >>   }
> > > 
> > > This addresses EHCI cache problem, that's why you need bounce buffer,
> > > right?
> > 
> > No. The problem was we were copying data word-by-word to a non-word
> > aligned memory in the USB gadget. So, this is different from the USB
> > host controller issue.
> 
> I see ... why isn't buffer aligned by the usb stack then?

because it might not be a requirement higher up.  i.e. it's dealing with a 
data byte stream.  forcing all higher layers to use 32bit alignment because 
this host controller requires 32bit alignment in its FIFOs is incorrect.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120306/3e706ea1/attachment.pgp>

  reply	other threads:[~2012-03-06 16:08 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-16 12:03 [U-Boot] [PATCH 0/4] USB: Add support for designware UDC Amit Virdi
2012-02-16 12:03 ` [U-Boot] [PATCH 1/4] USB:gadget:designware USB device controller (UDC) implementation Amit Virdi
2012-03-05 18:12   ` Marek Vasut
2012-03-06  4:32     ` Amit Virdi
2012-02-16 12:03 ` [U-Boot] [PATCH 2/4] USB:gadget:designware Device controller bugfixes Amit Virdi
2012-03-05 18:13   ` Marek Vasut
2012-03-06  4:34     ` Amit Virdi
2012-02-16 12:03 ` [U-Boot] [PATCH 3/4] USB:gadget:designware Support high speed Amit Virdi
2012-03-05 18:15   ` Marek Vasut
2012-03-06  5:44     ` Amit Virdi
2012-02-16 12:03 ` [U-Boot] [PATCH 4/4] USB:gadget:designware Fix memory nonalignment issue Amit Virdi
2012-03-05 18:21   ` Marek Vasut
2012-03-06  9:36     ` Amit Virdi
2012-03-06  9:51       ` Marek Vasut
2012-03-06 16:08         ` Mike Frysinger [this message]
2012-03-07  7:14           ` Amit Virdi
2012-03-06 16:09   ` Mike Frysinger
2012-03-07  7:04     ` Amit Virdi
2012-02-24 11:56 ` [U-Boot] [PATCH 0/4] USB: Add support for designware UDC Amit Virdi
2012-03-05 18:06   ` Marek Vasut

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=201203061108.12155.vapier@gentoo.org \
    --to=vapier@gentoo.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox