12#ifndef ZEPHYR_INCLUDE_UDC_BUF_H
13#define ZEPHYR_INCLUDE_UDC_BUF_H
18#if defined(CONFIG_DCACHE) && !defined(CONFIG_UDC_BUF_FORCE_NOCACHE)
26#define Z_UDC_BUF_ALIGN CONFIG_DCACHE_LINE_SIZE
27#define Z_UDC_BUF_GRANULARITY CONFIG_DCACHE_LINE_SIZE
33#define Z_UDC_BUF_ALIGN sizeof(void *)
34#define Z_UDC_BUF_GRANULARITY sizeof(void *)
45#define UDC_BUF_ALIGN Z_UDC_BUF_ALIGN
48#define UDC_BUF_GRANULARITY Z_UDC_BUF_GRANULARITY
59#define UDC_STATIC_BUF_DEFINE(name, size) \
60 static uint8_t __aligned(UDC_BUF_ALIGN) name[ROUND_UP(size, UDC_BUF_GRANULARITY)];
69#define IS_UDC_ALIGNED(buf) IS_ALIGNED(buf, UDC_BUF_ALIGN)
74#define UDC_HEAP_DEFINE(name, bytes, in_section) \
75 uint8_t in_section __aligned(UDC_BUF_ALIGN) \
76 kheap_##name[MAX(bytes, Z_HEAP_MIN_SIZE)]; \
77 STRUCT_SECTION_ITERABLE(k_heap, name) = { \
79 .init_mem = kheap_##name, \
80 .init_bytes = MAX(bytes, Z_HEAP_MIN_SIZE), \
84#define UDC_K_HEAP_DEFINE(name, size) \
85 COND_CODE_1(CONFIG_UDC_BUF_FORCE_NOCACHE, \
86 (UDC_HEAP_DEFINE(name, size, __nocache)), \
87 (UDC_HEAP_DEFINE(name, size, __noinit)))
89extern const struct net_buf_data_cb net_buf_dma_cb;
106#define UDC_BUF_POOL_VAR_DEFINE(pname, count, size, ud_size, fdestroy) \
107 _NET_BUF_ARRAY_DEFINE(pname, count, ud_size); \
108 UDC_K_HEAP_DEFINE(net_buf_mem_pool_##pname, size); \
109 static const struct net_buf_data_alloc net_buf_data_alloc_##pname = { \
110 .cb = &net_buf_dma_cb, \
111 .alloc_data = &net_buf_mem_pool_##pname, \
112 .max_alloc_size = 0, \
114 static STRUCT_SECTION_ITERABLE(net_buf_pool, pname) = \
115 NET_BUF_POOL_INITIALIZER(pname, &net_buf_data_alloc_##pname, \
116 _net_buf_##pname, count, ud_size, \
133#define UDC_BUF_POOL_DEFINE(pname, count, size, ud_size, fdestroy) \
134 _NET_BUF_ARRAY_DEFINE(pname, count, ud_size); \
135 BUILD_ASSERT((UDC_BUF_GRANULARITY) % (UDC_BUF_ALIGN) == 0, \
136 "Code assumes granurality is multiple of alignment"); \
137 static uint8_t __nocache __aligned(UDC_BUF_ALIGN) \
138 net_buf_data_##pname[count][ROUND_UP(size, UDC_BUF_GRANULARITY)];\
139 static const struct net_buf_pool_fixed net_buf_fixed_##pname = { \
140 .data_pool = (uint8_t *)net_buf_data_##pname, \
142 static const struct net_buf_data_alloc net_buf_fixed_alloc_##pname = { \
143 .cb = &net_buf_fixed_cb, \
144 .alloc_data = (void *)&net_buf_fixed_##pname, \
145 .max_alloc_size = ROUND_UP(size, UDC_BUF_GRANULARITY), \
147 static STRUCT_SECTION_ITERABLE(net_buf_pool, pname) = \
148 NET_BUF_POOL_INITIALIZER(pname, &net_buf_fixed_alloc_##pname, \
149 _net_buf_##pname, count, ud_size, \