Index: apps/buffering.c =================================================================== --- apps/buffering.c (revision 23943) +++ apps/buffering.c (working copy) @@ -108,7 +108,11 @@ enum data_type type; /* Type of data buffered with this handle */ char path[MAX_PATH]; /* Path if data originated in a file */ int fd; /* File descriptor to path (-1 if closed) */ - size_t data; /* Start index of the handle's data buffer */ +#ifdef STORAGE_ALIGN_MASK + size_t start; /* Start index of the handle's data buffer, + for use by reset_handle. */ +#endif + size_t data; /* Start index of the handle's data */ volatile size_t ridx; /* Read pointer, relative to the main buffer */ size_t widx; /* Write pointer */ size_t filesize; /* File total length */ @@ -713,13 +717,25 @@ Use this after having set the new offset to use. */ static void reset_handle(int handle_id) { +#ifdef STORAGE_ALIGN_MASK + size_t alignment_pad; +#endif + logf("reset_handle(%d)", handle_id); struct memory_handle *h = find_handle(handle_id); if (!h) return; +#ifdef STORAGE_ALIGN_MASK + /* Align to cache line boundary */ + alignment_pad = (h->offset - (size_t)(&buffer[h->start])) + & STORAGE_ALIGN_MASK; + h->ridx = h->widx = h->data = RINGBUF_ADD(h->start, alignment_pad); +#else h->ridx = h->widx = h->data; +#endif + if (h == cur_handle) buf_widx = h->widx; h->available = 0; @@ -831,6 +847,9 @@ return; h->data = RINGBUF_ADD(h->data, delta); +#ifdef STORAGE_ALIGN_MASK + h->start = RINGBUF_ADD(h->start, delta); +#endif h->available -= delta; h->offset += delta; } @@ -981,7 +1000,13 @@ if (adjusted_offset > size) adjusted_offset = 0; +#ifdef STORAGE_ALIGN_MASK + /* Reserve extra space because alignment can move data forward */ + struct memory_handle *h = add_handle(size-adjusted_offset+STORAGE_ALIGN_MASK, + can_wrap, false); +#else struct memory_handle *h = add_handle(size-adjusted_offset, can_wrap, false); +#endif if (!h) { DEBUGF("bufopen: failed to add handle\n"); @@ -991,6 +1016,22 @@ strlcpy(h->path, file, MAX_PATH); h->offset = adjusted_offset; + +#ifdef STORAGE_ALIGN_MASK + if (type != TYPE_BITMAP) + { + size_t alignment_pad; + + /* Remember where data area starts, for use by reset_handle */ + h->start = buf_widx; + + /* Align to cache line boundary */ + alignment_pad = (adjusted_offset - (size_t)(&buffer[buf_widx])) + & STORAGE_ALIGN_MASK; + buf_widx = RINGBUF_ADD(buf_widx, alignment_pad); + } +#endif + h->ridx = buf_widx; h->widx = buf_widx; h->data = buf_widx; @@ -1522,7 +1563,12 @@ return false; buffer = buf; +#ifdef STORAGE_ALIGN_MASK + /* Preserve alignment when wrapping around */ + buffer_len = buflen & ~STORAGE_ALIGN_MASK; +#else buffer_len = buflen; +#endif guard_buffer = buf + buflen; buf_widx = 0; Index: firmware/export/config.h =================================================================== --- firmware/export/config.h (revision 23943) +++ firmware/export/config.h (working copy) @@ -878,6 +878,12 @@ #endif /* HAVE_USBSTACK */ +/* alignment for DMA */ +#ifdef HAVE_ATA_DMA +#ifdef CPU_PP502x +#define STORAGE_ALIGN_MASK 15 +#endif +#endif /* HAVE_ATA_DMA */ #endif /* __CONFIG_H__ */