arch/arm/imxrt: Add support for ARMV8M_DCACHE_LINESIZE in imxrt_usbdev.c
Some checks failed
MemBrowse Memory Report / changes-filter (push) Waiting to run
MemBrowse Memory Report / load-targets (push) Waiting to run
MemBrowse Memory Report / identical (push) Blocked by required conditions
MemBrowse Memory Report / analyze (push) Blocked by required conditions
Build Documentation / build-html (push) Has been cancelled

Select the cache line size from either ARMV7M_DCACHE_LINESIZE or
ARMV8M_DCACHE_LINESIZE, so the driver can also be used with D-cache
enabled on the i.MX RT1180 Cortex-M33.

Also fix the imxrt1180-evk USB DMA allocator alignment. Pad the header
to the 32-byte DMA alignment, so that the buffer remains aligned.

Signed-off-by: Jukka Laitinen <jukka.laitinen@tii.ae>
This commit is contained in:
Jukka Laitinen 2026-10-01 09:23:51 +03:00 • committed by Xiang Xiao
parent 0fa3459dbe
commit 437306409e
2 changed files with 15 additions and 7 deletions

View file

@ -207,12 +207,18 @@ const struct trace_msg_t g_usb_trace_strings_intdecode[] =
#endif
#if defined(CONFIG_ARMV7M_DCACHE)
# define USB_DCACHE_LINESIZE ARMV7M_DCACHE_LINESIZE
#elif defined(CONFIG_ARMV8M_DCACHE)
# define USB_DCACHE_LINESIZE ARMV8M_DCACHE_LINESIZE
#endif
#if defined(CONFIG_ARMV7M_DCACHE) || defined(CONFIG_ARMV8M_DCACHE)
# define cache_aligned_alloc(s) \
kmm_memalign(ARMV7M_DCACHE_LINESIZE, \
(((s) + ARMV7M_DCACHE_LINESIZE - 1) & \
~(ARMV7M_DCACHE_LINESIZE - 1)))
# define CACHE_ALIGNED_DATA aligned_data(ARMV7M_DCACHE_LINESIZE)
# define DCACHE_LINEMASK (ARMV7M_DCACHE_LINESIZE - 1)
kmm_memalign(USB_DCACHE_LINESIZE, \
(((s) + USB_DCACHE_LINESIZE - 1) & \
~(USB_DCACHE_LINESIZE - 1)))
# define CACHE_ALIGNED_DATA aligned_data(USB_DCACHE_LINESIZE)
# define DCACHE_LINEMASK (USB_DCACHE_LINESIZE - 1)
# define DCACHE_ALIGN_UP(a) (((a) + DCACHE_LINEMASK) & ~DCACHE_LINEMASK)
# define IS_CACHE_ALIGNED(x,y) \
(((uintptr_t)(x) & DCACHE_LINEMASK) == 0 && \

View file

@ -61,6 +61,7 @@
* overhead and other endpoints.
*/
#define IMXRT_DMA_ALIGNMENT 32
#define IMXRT_DMA_POOL_SIZE (6 * 1024)
/****************************************************************************
@ -105,14 +106,15 @@ int imxrt_dma_alloc_init(void)
*
* gran_free() needs to know the size of the allocation being freed, but
* usbdev_dma_free() is not given a size (see include/nuttx/usb/usbdev.h).
* We work around this by prepending a small header that records the
* total granule allocation size.
* Reserve one alignment unit before the returned buffer and record the
* total allocation size there. This keeps the buffer cache-line aligned.
*
****************************************************************************/
struct usbdma_header_s
{
size_t allocsize;
uint8_t padding[IMXRT_DMA_ALIGNMENT - sizeof(size_t)];
};
void *usbdev_dma_alloc(size_t size)