public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: puneets <puneets@nvidia.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/2] usb: align buffers at cacheline
Date: Fri, 24 Feb 2012 16:57:39 +0530	[thread overview]
Message-ID: <4F47742B.9040503@nvidia.com> (raw)
In-Reply-To: <201202231315.53796.vapier@gentoo.org>

Hi Mike,
On Thursday 23 February 2012 11:45 PM, Mike Frysinger wrote:
> * PGP Signed by an unknown key
>
> On Thursday 23 February 2012 09:25:25 Puneet Saxena wrote:
>> --- a/common/usb_storage.c
>> +++ b/common/usb_storage.c
>>
>> -static unsigned char usb_stor_buf[512];
>> -static ccb usb_ccb;
>> +#ifdef ARCH_DMA_MINALIGN
>> +	static ccb usb_ccb __attribute__((aligned(ARCH_DMA_MINALIGN)));
>> +#else
>> +	static ccb usb_ccb;
>> +#endif
> don't use ifdef's.  you may assume that ARCH_DMA_MINALIGN is always defined.
> after all, the ALLOC_CACHE_ALIGN_BUFFER() helper does.
>
>> int usb_stor_get_info(struct usb_device *dev, struct us_data *ss,
>> 				block_dev_desc_t *dev_desc)
>>   {
>>   	unsigned char perq, modi;
>> -	unsigned long cap[2];
>> +	ALLOC_CACHE_ALIGN_BUFFER(unsigned long, cap, 2);
>> +	ALLOC_CACHE_ALIGN_BUFFER(unsigned char, usb_stor_buf, 36);
>>   	unsigned long *capacity, *blksz;
>>   	ccb *pccb =&usb_ccb;
>>
>> +	/* GJ */
>> +	memset(usb_stor_buf, 0, sizeof(usb_stor_buf));
> you shrunk the buffer to 36 bytes, so that's good.  but the memset() should be
> dropped.  see what i posted to Marek when he tried moving this buffer locally
> if you want background.
>
>> --- a/drivers/usb/host/ehci-hcd.c
>> +++ b/drivers/usb/host/ehci-hcd.c
>>
>>   static void flush_invalidate(u32 addr, int size, int flush)
>>   {
>> +	/*
>> +	 * Size is the bytes actually moved during transaction,
>> +	 * which may not equal to the cache line. This results
>> +	 * stop address passed for invalidating cache may not be aligned.
>> +	 * Therfore making size as nultiple of cache line size.
>> +	 */
>> +	if (size&  (ARCH_DMA_MINALIGN - 1))
>> +			size = ((size / ARCH_DMA_MINALIGN) + 1)
>> +				* ARCH_DMA_MINALIGN;
> i don't think this logic should exist at all.  the arch is responsible for
> flushing enough of its cache to cover the requested size.
>
The patches under review is used to avoid the warnings -

1) ERROR: v7_dcache_inval_range - start address is not aligned - 0x3ffbd5d0

2) ERROR: v7_dcache_inval_range - stop address is not aligned - 0x3ffbd5f0

This piece of code assures that second warning should not appear.

By allocating Buffers cache line aligned we are making sure that "start 
address"
will always be aligned. Arch specific code is taking care of 
flushing/invalidating the
cache as per the requested size but 2nd warning appears before doing that.
As you see in code: stop address = start address + size, so we are 
required to assure
size to be multiple of cacheline(start address we are aligning already). 
The above piece
of code is meant for this.
other option could be to add code in arch specific file to align stop 
address. e.g in "v7_dcache_maint_range@

Cache_v7.c (arch\arm\cpu\armv7)"

>> --- a/include/scsi.h
>> +++ b/include/scsi.h
>>
>>   typedef struct SCSI_cmd_block{
>>   	unsigned char		cmd[16];			/* command */
>> -	unsigned char		sense_buf[64];		/* for request sense */
>> +	/* for request sense */
>> +#ifdef ARCH_DMA_MINALIGN
>> +	unsigned char		sense_buf[64]
>> +		__attribute__((aligned(ARCH_DMA_MINALIGN)));
>> +#else
>> +	unsigned char		sense_buf[64];
>> +#endif
>>
>> --- a/include/usb.h
>> +++ b/include/usb.h
>> struct usb_device {
>>   	int epmaxpacketout[16];		/* OUTput endpoint specific maximums */
>>
>>   	int configno;			/* selected config number */
>> -	struct usb_device_descriptor descriptor; /* Device Descriptor */
>> +	 /* Device Descriptor */
>> +#ifdef ARCH_DMA_MINALIGN
>> +	struct usb_device_descriptor descriptor
>> +		__attribute__((aligned(ARCH_DMA_MINALIGN)));
>> +#else
>> +	struct usb_device_descriptor descriptor;
>> +#endif
> i don't think either of these headers should be changed.  find&  fix the code
> that is causing a problem.
>
IMHO, scsi.h should be changed otherwise we may need to memcpy aligned 
local buffer to
this global buffer in "usb_request_sense @ Usb_storage.c (common).

> wrt the other random ALLOC_CACHE_ALIGN_BUFFER() changes, they look OK to me.
> -mike
>
> * Unknown Key
> * 0xE837F581


-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain
confidential information.  Any unauthorized review, use, disclosure or distribution
is prohibited.  If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------

  reply	other threads:[~2012-02-24 11:27 UTC|newest]

Thread overview: 83+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-17 10:50 [U-Boot] [PATCH] usb: align buffers at cache boundary Puneet Saxena
2012-02-17 17:23 ` Mike Frysinger
2012-02-23 14:25   ` [U-Boot] [PATCH 1/2] usb: align buffers at cacheline Puneet Saxena
2012-02-23 18:15     ` Mike Frysinger
2012-02-24 11:27       ` puneets [this message]
2012-02-24 12:42     ` Simon Glass
2012-02-27 15:36       ` [U-Boot] [PATCH v2 " Puneet Saxena
2012-02-27 16:49         ` Marek Vasut
2012-02-27 17:03           ` Simon Glass
2012-02-27 17:11             ` Marek Vasut
2012-02-27 17:27               ` Simon Glass
2012-02-29 14:21               ` [U-Boot] [PATCH v3 " Puneet Saxena
2012-02-29 21:35                 ` Marek Vasut
2012-03-01 13:51                   ` puneets
2012-03-01 18:38                     ` Marek Vasut
2012-03-02  6:56                       ` puneets
2012-03-02 10:43                         ` Marek Vasut
2012-03-02 12:50                           ` puneets
2012-03-02 12:58                             ` Marek Vasut
2012-03-02 13:35                               ` [U-Boot] [PATCH v4] " Puneet Saxena
2012-03-02 13:46                                 ` Marek Vasut
2012-03-02 14:00                                   ` puneets
2012-03-02 14:41                                     ` Marek Vasut
2012-03-02 15:21                                       ` puneets
2012-03-02 15:59                                         ` Marek Vasut
2012-03-02 16:45                                           ` Wolfgang Denk
2012-03-05  7:16                                             ` [U-Boot] [PATCH v5] " Puneet Saxena
2012-03-05 13:24                                               ` Eric Nelson
2012-03-05 13:35                                                 ` Marek Vasut
2012-03-05 14:46                                                 ` [U-Boot] [PATCH v8] " Puneet Saxena
2012-03-05 15:35                                                   ` Marek Vasut
2012-03-05 18:18                                                   ` Simon Glass
2012-03-06  0:36                                                     ` Marek Vasut
2012-03-06  0:39                                                       ` Marek Vasut
2012-03-06  7:00                                                     ` puneets
2012-03-06  8:22                                                       ` Marek Vasut
2012-03-06  3:07                                                   ` Mike Frysinger
2012-03-07  7:12                                                     ` puneets
2012-03-07  9:20                                                       ` puneets
2012-03-07 22:06                                                       ` Marek Vasut
2012-03-08 11:21                                                         ` puneets
2012-03-08 14:12                                                           ` Marek Vasut
2012-03-09  6:15                                                             ` puneets
2012-03-09 12:03                                                               ` Marek Vasut
2012-03-11  2:35                                                       ` Mike Frysinger
2012-03-14  2:05                                                         ` Marek Vasut
2012-03-16  4:39                                                       ` Marek Vasut
2012-03-16  7:42                                                         ` puneets
2012-03-16  8:52                                                           ` Marek Vasut
2012-03-19 14:29                                                             ` puneets
2012-03-19 14:43                                                               ` Marek Vasut
2012-03-19 15:19                                                                 ` Tom Warren
2012-03-19 15:46                                                                   ` Marek Vasut
2012-04-02 15:59                                                                     ` Tom Warren
2012-04-02 16:11                                                                       ` Marek Vasut
2012-04-02 16:16                                                                         ` Tom Warren
2012-04-02 16:32                                                                           ` Marek Vasut
2012-04-03  6:05                                                                             ` puneets
2012-03-05  7:27                                             ` [U-Boot] [PATCH v6] " Puneet Saxena
2012-03-05 12:03                                               ` Marek Vasut
2012-03-05 12:21                                                 ` [U-Boot] [PATCH v7] " Puneet Saxena
2012-03-05 12:41                                                   ` Marek Vasut
2012-03-06  3:28                                             ` [U-Boot] [PATCH v4] " Mike Frysinger
2012-03-06  8:24                                               ` Marek Vasut
2012-03-06 16:42                                                 ` Mike Frysinger
2012-02-29 14:21               ` [U-Boot] [PATCH v3 2/2] usb: Add CONFIG to fetch string descriptor Puneet Saxena
2012-02-29 21:29                 ` Marek Vasut
2012-03-01 11:07                   ` puneets
2012-03-01 11:45                     ` Marek Vasut
2012-03-01 12:59                       ` puneets
2012-03-01 13:13                         ` Marek Vasut
2012-03-05 12:48                           ` Marek Vasut
2012-03-05 13:14                             ` puneets
2012-03-05 21:15                               ` Marek Vasut
2012-02-28  9:34           ` [U-Boot] [PATCH v2 1/2] usb: align buffers at cacheline puneets
2012-02-29 21:38             ` Marek Vasut
2012-02-27 15:36       ` [U-Boot] [PATCH v2 2/2] usb: Add CONFIG to fetch string descriptor Puneet Saxena
2012-02-27 18:28         ` Mike Frysinger
2012-02-27 15:37       ` [U-Boot] [PATCH 1/2] usb: align buffers at cacheline puneets
2012-02-23 14:25   ` [U-Boot] [PATCH 2/2] usb: Add quirk "USB_QUIRK_STRING_FETCH_255" Puneet Saxena
2012-02-23 15:20     ` Tom Rini
2012-02-23 16:04     ` Tom Warren
2012-02-24  7:52       ` puneets

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=4F47742B.9040503@nvidia.com \
    --to=puneets@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