From: Mike Frysinger <vapier@gentoo.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] usb: align buffers at cache boundary
Date: Fri, 17 Feb 2012 12:23:58 -0500 [thread overview]
Message-ID: <201202171224.00086.vapier@gentoo.org> (raw)
In-Reply-To: <1329475821-31491-1-git-send-email-puneets@nvidia.com>
On Friday 17 February 2012 05:50:21 Puneet Saxena wrote:
> This aligns buffers,passed to usb controller at
> dcache boundary.
>
> Buffer "stop" address = "start" address + size.
> Stop address can not be aligned even though
> "start" address is aligned as size does not fall
> at cache line boundary. Therefore "debug" in place of
> "printf" is added in "arch/arm/cpu/armv7/cache_v7.c".
> Cleaning and invalidating last cache line to avoid
> stale data to be reused.
the point is to align things based on the DMA constraints, not cacheline
constraints (with the assumption that DMA constraints will always be equal or
larger than cachelines and never smaller). so using CONFIG_SYS_CACHELINE_SIZE
is wrong. this is exactly why we have ARCH_DMA_MINALIGN.
> Ignoring "checkpatch.pl" warnings to replace "__attribute__((packed))"
> by "__packed" and "__attribute__((aligned(size)))" by "__aligned(size)".
> As "__GNUC__" directive should be defined to use "__packed" and
> "__aligned(size)" and current patch is not supporting it, ignoring
> the "checkpatch.pl" warning.
i don't understand this. we have linux/compiler.h which provides these macros
so you should be able to use them.
so NAK to this implementation for the reasons above
> --- a/arch/arm/cpu/armv7/cache_v7.c
> +++ b/arch/arm/cpu/armv7/cache_v7.c
>
> /*
> + * We can't avoid stop address not aligned with cache-line.
> + * Allocating cache -aligned buffer might waste memory.
> * If stop address is not aligned to cache-line do not
> - * invalidate the last cache-line
> + * invalidate the last cache-line and flush the last
> + * line to prevent affecting somebody else's buffer.
> */
> if (stop & (line_len - 1)) {
> - printf("ERROR: %s - stop address is not aligned - 0x%08x\n",
> + debug("ERROR: %s - stop address is not aligned - 0x%08x\n",
> __func__, stop);
> + v7_dcache_clean_inval_range(stop, stop + 1, line_len);
> /* align to the beginning of this cache line */
> stop &= ~(line_len - 1);
> }
pretty sure this is ignoring the problem and so shouldn't get merged
> --- a/common/usb.c
> +++ b/common/usb.c
>
> -static struct devrequest setup_packet;
> +#ifdef CONFIG_SYS_CACHELINE_SIZE
> + static struct devrequest setup_packet
> + __attribute__((aligned(CONFIG_SYS_CACHELINE_SIZE)));
> +#else
> + static struct devrequest setup_packet;
> +#endif
this is used in only one function, so it'd be better to simply move it to that
one function rather than keeping it as a global.
> --- a/common/usb_storage.c
> +++ b/common/usb_storage.c
>
> -static unsigned char usb_stor_buf[512];
> +#ifdef CONFIG_SYS_CACHELINE_SIZE
> + static unsigned char usb_stor_buf[512]
> + __attribute__((aligned(CONFIG_SYS_CACHELINE_SIZE)));
> +#else
> + static unsigned char usb_stor_buf[512];
> +#endif
Marek has already posted a patch fixing this
> --- a/drivers/usb/host/ehci-hcd.c
> +++ b/drivers/usb/host/ehci-hcd.c
> @@ -132,8 +132,20 @@ static void cache_qtd(struct qTD *qtd, int flush)
> int len = (qtd->qt_token & 0x7fff0000) >> 16;
>
> flush_invalidate((u32)qtd, sizeof(struct qTD), flush);
> +
> + /*
> + * Invalidate cache for the aligned address
> + * and for the data length which is DMAed.
> + * Do not invalidate again intermidiate address
> + * as it may not be aligned.
> + */
> +#if CONFIG_SYS_CACHELINE_SIZE
> + if (!((u32) ptr & (CONFIG_SYS_CACHELINE_SIZE - 1)) && len)
> + flush_invalidate((u32)ptr, len, flush);
> +#else
> if (ptr && len)
> flush_invalidate((u32)ptr, len, flush);
> +#endif
> }
ugh no. existing code is correct.
> --- 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 CONFIG_SYS_CACHELINE_SIZE
> + unsigned char sense_buf[64]
> + __attribute__((aligned(CONFIG_SYS_CACHELINE_SIZE)));
> +#else
> + unsigned char sense_buf[64];
> +#endif
pretty sure this is wrong
> --- 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 CONFIG_SYS_CACHELINE_SIZE
> + struct usb_device_descriptor descriptor
> + __attribute__((aligned(CONFIG_SYS_CACHELINE_SIZE)));
> +#else
> + struct usb_device_descriptor descriptor;
> +#endif
> struct usb_config config; /* config descriptor */
>
> int have_langid; /* whether string_langid is valid yet */
as is this
-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/20120217/e26c721c/attachment.pgp>
next prev parent reply other threads:[~2012-02-17 17:23 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 [this message]
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 ` [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=201202171224.00086.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