public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Allen Martin <amartin@nvidia.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 1/3] USB: make usb_kbd obey USB DMA alignment requirements
Date: Tue, 23 Oct 2012 09:51:20 -0700	[thread overview]
Message-ID: <20121023165120.GE13201@badger> (raw)
In-Reply-To: <201210230926.31221.marex@denx.de>

On Tue, Oct 23, 2012 at 12:26:31AM -0700, Marek Vasut wrote:
> Dear Allen Martin,
> 
> > Change usb_kbd driver to obey alignment requirements for USB DMA on
> > the buffer used for data transfer.  This is necessary for
> > architectures that enable dcache and enable USB DMA.
> > 
> > Signed-off-by: Allen Martin <amartin@nvidia.com>
> > ---
> >  common/usb_kbd.c |    8 ++++----
> >  1 file changed, 4 insertions(+), 4 deletions(-)
> > 
> > diff --git a/common/usb_kbd.c b/common/usb_kbd.c
> > index 19f01db..57928d9 100644
> > --- a/common/usb_kbd.c
> > +++ b/common/usb_kbd.c
> > @@ -106,15 +106,15 @@ static const unsigned char usb_kbd_num_keypad[] = {
> >  	(USB_KBD_NUMLOCK | USB_KBD_CAPSLOCK | USB_KBD_SCROLLLOCK)
> > 
> >  struct usb_kbd_pdata {
> > +	uint8_t		new[8];
> > +	uint8_t		old[8];
> > +
> 
> Some comment about the alignment won't hurt.

Good idea.

> 
> >  	uint32_t	repeat_delay;
> > 
> >  	uint32_t	usb_in_pointer;
> >  	uint32_t	usb_out_pointer;
> >  	uint8_t		usb_kbd_buffer[USB_KBD_BUFFER_LEN];
> > 
> > -	uint8_t		new[8];
> > -	uint8_t		old[8];
> > -
> >  	uint8_t		flags;
> >  };
> > 
> > @@ -426,7 +426,7 @@ static int usb_kbd_probe(struct usb_device *dev,
> > unsigned int ifnum)
> > 
> >  	USB_KBD_PRINTF("USB KBD: found set protocol...\n");
> > 
> > -	data = malloc(sizeof(struct usb_kbd_pdata));
> > +	data = memalign(USB_DMA_MINALIGN, sizeof(struct usb_kbd_pdata));
> 
> Don't we have ALLOC_CACHE_ALIGN_BUFFER and such stuff in include/common.h for 
> this purpose ?

There seems to be some discrepency here, because ehci-hcd.c uses
USB_DMA_MINALIGN for all cache operations, which may or may not be the
same as ARCH_DMA_MINALIGN, see usb.h:

/*
 * The EHCI spec says that we must align to at least 32 bytes.
 However,
 * some platforms require larger alignment.
 */
#if ARCH_DMA_MINALIGN > 32
#define USB_DMA_MINALIGN        ARCH_DMA_MINALIGN
#else
#define USB_DMA_MINALIGN        32
#endif

For tegra this is fine, because ARCH_DMA_MINALIGN > 32, but grepping
through header files, I see a few:

#define ARCH_DMA_MINALIGN       16

which will definately break.  It looks like all other usb class
drivers use ALLOC_CACHE_ALIGN_BUFFER() though, so for consistency the
usb keyboard driver probably should too, but it seems like a potential
problem.


> 
> >  	if (!data) {
> >  		printf("USB KBD: Error allocating private data\n");
> >  		return 0;
> 
> Best regards,
> Marek Vasut

-Allen
-- 
nvpublic

  parent reply	other threads:[~2012-10-23 16:51 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-23  5:47 [U-Boot] [PATCH v2 1/3] USB: make usb_kbd obey USB DMA alignment requirements Allen Martin
2012-10-23  5:47 ` [U-Boot] [PATCH v2 2/3] tegra: move TEGRA_DEVICE_SETTINGS to tegra-common-post.h Allen Martin
2012-10-23  7:27   ` Marek Vasut
2012-10-23 16:36     ` Stephen Warren
2012-10-23 22:01       ` Marek Vasut
2012-10-23 22:18         ` Stephen Warren
2012-10-24  0:30         ` Allen Martin
2012-11-02 20:06         ` Allen Martin
2012-11-02 20:40           ` Marek Vasut
2012-10-23 16:41   ` Stephen Warren
2012-10-23  5:47 ` [U-Boot] [PATCH v2 3/3] tegra: Enable USB keyboard Allen Martin
2012-10-23  7:26 ` [U-Boot] [PATCH v2 1/3] USB: make usb_kbd obey USB DMA alignment requirements Marek Vasut
2012-10-23 16:31   ` Stephen Warren
2012-10-23 16:51   ` Allen Martin [this message]
2012-10-23 22:04     ` Marek Vasut
2012-10-23 16:51 ` Stephen Warren
2012-10-23 17:02   ` Allen Martin
2012-10-23 22:03     ` Marek Vasut
2012-10-24  0:39       ` Allen Martin
2012-10-24  0:46         ` Allen Martin
2012-10-24  7:31         ` Marek Vasut
2012-10-24 17:24           ` Allen Martin
2012-10-24 20:17             ` Marek Vasut
2012-10-24 20:41               ` Stephen Warren

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=20121023165120.GE13201@badger \
    --to=amartin@nvidia.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox