From: puneets <puneets@nvidia.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/2] usb: align buffers at cacheline
Date: Mon, 27 Feb 2012 21:07:44 +0530 [thread overview]
Message-ID: <4F4BA348.3040909@nvidia.com> (raw)
In-Reply-To: <CAPnjgZ2h5o7LGkitVhsm99nBv0Qw0Be7DaUMULNq4qHKQbufMA@mail.gmail.com>
Hi,
On Friday 24 February 2012 06:12 PM, Simon Glass wrote:
> Hi,
>
> On Thu, Feb 23, 2012 at 6:25 AM, Puneet Saxena<puneets@nvidia.com> wrote:
>> As DMA expects the buffers to be equal and larger then
>> cache lines, This aligns buffers at cacheline.
>>
>> Signed-off-by: Puneet Saxena<puneets@nvidia.com>
>> Signed-off-by: Jim Lin<jilin@nvidia.com>
>> ---
>> Changes for v2:
>> - Split the commit in to 2 commits
>> - "ARCH_DMA_MINALIGN" replacement
>> - Making stop address cache line aligned by
>> making size as multiple of cache line
>> - incorporated Marek and Mike's comment
>>
>> common/cmd_usb.c | 3 +-
>> common/usb.c | 53 ++++++++++++++++++----------------
>> common/usb_storage.c | 66 ++++++++++++++++++++++--------------------
>> drivers/usb/host/ehci-hcd.c | 9 ++++++
>> include/scsi.h | 8 ++++-
>> include/usb.h | 8 ++++-
>> 6 files changed, 88 insertions(+), 59 deletions(-)
>> diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
>> index d893b2a..82652f5 100644
>> --- a/drivers/usb/host/ehci-hcd.c
>> +++ b/drivers/usb/host/ehci-hcd.c
>> @@ -120,6 +120,15 @@ static struct descriptor {
>> */
>> 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;
> Can we just use:
>
> size = ALIGN(size, ARCH_DMA_MINALIGN)
>
> here or does it increase size even if already aligned?
size = ALIGN(size, ARCH_DMA_MINALIGN) can be used in place of this.
The code in patch does not increase the size if size is already aligned.
>> if (flush)
>> flush_dcache_range(addr, addr + size);
>> else
>> diff --git a/include/scsi.h b/include/scsi.h
>> index c52759c..c1f573e 100644
>> --- a/include/scsi.h
>> +++ b/include/scsi.h
>> @@ -26,7 +26,13 @@
>>
>> 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
> I think Mike said this, but I thought ARCH_DMA_MINALIGN should always
> be defined.
>
> Is it possible to align something in the middle of a structure? How
> does that work? I'm suppose you have this working, I would just like
> to understand what the resulting code does in this case.
>
I verified that ARCH_DMA_MINALIGN is already defined so I will not check
it in next patch.
Yes it would align the variable in middle at the time of instantiating
the structure.
Compiler generates the addresses of this variable and structure
variable, as 32 __BYTE__ aligned(cache line is 32).
It try to accommodate all the variables in these two addresses till 32 byte.
Another solution could be, Align whole structure of cacheline and keep
the buffer as first element.
However in case more than one buffers are in a structure, only option is
to align individual buffer in place of
whole structure.
>> unsigned char status; /* SCSI Status */
>> unsigned char target; /* Target ID */
>> unsigned char lun; /* Target LUN */
>> diff --git a/include/usb.h b/include/usb.h
>> index 06170cd..d38817a 100644
>> --- a/include/usb.h
>> +++ b/include/usb.h
>> @@ -109,7 +109,13 @@ 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
> Same question here, it seems even more exotic - maybe you will need a
> memcpy somewhere after all?
>
>> struct usb_config config; /* config descriptor */
>>
>> int have_langid; /* whether string_langid is valid yet */
>> --
>> 1.7.1
>>
> Regards,
> Simon
-----------------------------------------------------------------------------------
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.
-----------------------------------------------------------------------------------
next prev parent reply other threads:[~2012-02-27 15:37 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
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 ` puneets [this message]
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=4F4BA348.3040909@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