Skip to content

Commit 724aad2

Browse files
committed
include: drivers: usb: rename UDC buffer to USB buffer
Rename it to USB buffers so we can use it in host support without confusion. Keep the UDC_* macros for now, we can deprecate and remove them later. Move the UDC_BUF_FORCE_NOCACHE Kconfig option level up and also rename it so that it can be used by the UHC drivers. Do not keep the prompt, as it is not something a user would select in menuconfig. Signed-off-by: Johann Fischer <[email protected]>
1 parent 7445e68 commit 724aad2

File tree

11 files changed

+94
-44
lines changed

11 files changed

+94
-44
lines changed

doc/connectivity/usb/device_next/api/udc.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ API reference
1717

1818
.. doxygengroup:: udc_api
1919

20-
.. doxygengroup:: udc_buf
20+
.. doxygengroup:: usb_buf

drivers/usb/Kconfig

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
# Copyright (c) 2016 Wind River Systems, Inc.
44
# SPDX-License-Identifier: Apache-2.0
55

6+
config USB_BUF_FORCE_NOCACHE
7+
bool
8+
depends on NOCACHE_MEMORY && DCACHE
9+
help
10+
Place the buffer pools in the nocache memory region if the driver
11+
cannot handle buffers in cached memory.
12+
613
source "drivers/usb/bc12/Kconfig"
714
source "drivers/usb/udc/Kconfig"
815
source "drivers/usb/uhc/Kconfig"

drivers/usb/common/buf/usb_buf.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include <zephyr/kernel.h>
88
#include <zephyr/net_buf.h>
9-
#include <zephyr/drivers/usb/udc_buf.h>
9+
#include <zephyr/drivers/usb/usb_buf.h>
1010

1111
static inline uint8_t *usb_pool_data_alloc(struct net_buf *const buf,
1212
size_t *const size, k_timeout_t timeout)
@@ -15,8 +15,8 @@ static inline uint8_t *usb_pool_data_alloc(struct net_buf *const buf,
1515
struct k_heap *const pool = buf_pool->alloc->alloc_data;
1616
void *b;
1717

18-
*size = UDC_ROUND_UP(*size);
19-
b = k_heap_aligned_alloc(pool, UDC_BUF_ALIGN, *size, timeout);
18+
*size = USB_BUF_ROUND_UP(*size);
19+
b = k_heap_aligned_alloc(pool, USB_BUF_ALIGN, *size, timeout);
2020
if (b == NULL) {
2121
*size = 0;
2222
return NULL;

drivers/usb/udc/Kconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ config UDC_BUF_POOL_SIZE
2525
help
2626
Total amount of memory available for UDC requests.
2727

28-
config UDC_BUF_FORCE_NOCACHE
28+
config USB_BUF_FORCE_NOCACHE
2929
bool "Place the buffer pools in the nocache memory region"
3030
depends on NOCACHE_MEMORY && DCACHE
3131
help

drivers/usb/udc/Kconfig.mcux

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ config UDC_NXP_EHCI
77
depends on DT_HAS_NXP_EHCI_ENABLED
88
select PINCTRL
99
select NOCACHE_MEMORY if CPU_HAS_DCACHE
10-
imply UDC_BUF_FORCE_NOCACHE
10+
imply USB_BUF_FORCE_NOCACHE
1111
imply UDC_WORKQUEUE
1212
help
1313
NXP MCUX USB Device Controller Driver for EHCI.

drivers/usb/udc/udc_common.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <zephyr/sys/byteorder.h>
1111
#include <zephyr/sys/__assert.h>
1212
#include <zephyr/usb/usb_ch9.h>
13-
#include <zephyr/drivers/usb/udc_buf.h>
13+
#include <zephyr/drivers/usb/usb_buf.h>
1414
#include "udc_common.h"
1515

1616
#include <zephyr/logging/log.h>

include/zephyr/drivers/usb/udc.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
#include <zephyr/kernel.h>
1616
#include <zephyr/device.h>
17-
#include <zephyr/drivers/usb/udc_buf.h>
17+
#include <zephyr/drivers/usb/usb_buf.h>
1818
#include <zephyr/sys/atomic.h>
1919
#include <zephyr/usb/usb_ch9.h>
2020

include/zephyr/drivers/usb/udc_buf.h renamed to include/zephyr/drivers/usb/usb_buf.h

+76-33
Original file line numberDiff line numberDiff line change
@@ -9,58 +9,58 @@
99
* @brief Buffers for USB device support
1010
*/
1111

12-
#ifndef ZEPHYR_INCLUDE_UDC_BUF_H
13-
#define ZEPHYR_INCLUDE_UDC_BUF_H
12+
#ifndef ZEPHYR_INCLUDE_USB_BUF_H
13+
#define ZEPHYR_INCLUDE_USB_BUF_H
1414

1515
#include <zephyr/kernel.h>
1616
#include <zephyr/net_buf.h>
1717

18-
#if defined(CONFIG_DCACHE) && !defined(CONFIG_UDC_BUF_FORCE_NOCACHE)
18+
#if defined(CONFIG_DCACHE) && !defined(CONFIG_USB_BUF_FORCE_NOCACHE)
1919
/*
2020
* Here we try to get DMA-safe buffers, but we lack a consistent source of
2121
* information about data cache properties, such as line cache size, and a
2222
* consistent source of information about what part of memory is DMA'able.
2323
* For now, we simply assume that all available memory is DMA'able and use
2424
* Kconfig option DCACHE_LINE_SIZE for alignment and granularity.
2525
*/
26-
#define Z_UDC_BUF_ALIGN CONFIG_DCACHE_LINE_SIZE
27-
#define Z_UDC_BUF_GRANULARITY CONFIG_DCACHE_LINE_SIZE
26+
#define Z_USB_BUF_ALIGN CONFIG_DCACHE_LINE_SIZE
27+
#define Z_USB_BUF_GRANULARITY CONFIG_DCACHE_LINE_SIZE
2828
#else
2929
/*
3030
* Default alignment and granularity to pointer size if the platform does not
3131
* have a data cache or buffers are placed in nocache memory region.
3232
*/
33-
#define Z_UDC_BUF_ALIGN sizeof(void *)
34-
#define Z_UDC_BUF_GRANULARITY sizeof(void *)
33+
#define Z_USB_BUF_ALIGN sizeof(void *)
34+
#define Z_USB_BUF_GRANULARITY sizeof(void *)
3535
#endif
3636

3737

38-
#if defined(CONFIG_UDC_BUF_FORCE_NOCACHE)
38+
#if defined(CONFIG_USB_BUF_FORCE_NOCACHE)
3939
/*
4040
* The usb transfer buffer needs to be in __nocache section
4141
*/
42-
#define Z_UDC_BUF_SECTION __nocache
42+
#define Z_USB_BUF_SECTION __nocache
4343
#else
44-
#define Z_UDC_BUF_SECTION
44+
#define Z_USB_BUF_SECTION
4545
#endif
4646

4747
/**
48-
* @brief Buffer macros and definitions used in USB device support
49-
* @defgroup udc_buf Buffer macros and definitions used in USB device support
48+
* @brief USB buffer macros and definitions
49+
* @defgroup usb_buf USB buffer macros and definitions
5050
* @ingroup usb
5151
* @since 4.0
52-
* @version 0.1.0
52+
* @version 0.1.1
5353
* @{
5454
*/
5555

5656
/** Buffer alignment required by the UDC driver */
57-
#define UDC_BUF_ALIGN Z_UDC_BUF_ALIGN
57+
#define USB_BUF_ALIGN Z_USB_BUF_ALIGN
5858

5959
/** Buffer granularity required by the UDC driver */
60-
#define UDC_BUF_GRANULARITY Z_UDC_BUF_GRANULARITY
60+
#define USB_BUF_GRANULARITY Z_USB_BUF_GRANULARITY
6161

6262
/** Round up to the granularity required by the UDC driver */
63-
#define UDC_ROUND_UP(size) ROUND_UP(size, Z_UDC_BUF_GRANULARITY)
63+
#define USB_BUF_ROUND_UP(size) ROUND_UP(size, Z_USB_BUF_GRANULARITY)
6464

6565
/**
6666
* @brief Define a UDC driver-compliant static buffer
@@ -71,9 +71,9 @@
7171
* @param name Buffer name
7272
* @param size Buffer size
7373
*/
74-
#define UDC_STATIC_BUF_DEFINE(name, size) \
75-
static uint8_t Z_UDC_BUF_SECTION __aligned(UDC_BUF_ALIGN) \
76-
name[UDC_ROUND_UP(size)];
74+
#define USB_STATIC_BUF_DEFINE(name, size) \
75+
static uint8_t Z_USB_BUF_SECTION __aligned(USB_BUF_ALIGN) \
76+
name[USB_BUF_ROUND_UP(size)];
7777

7878
/**
7979
* @brief Verify that the buffer is aligned as required by the UDC driver
@@ -82,13 +82,13 @@
8282
*
8383
* @param buf Buffer pointer
8484
*/
85-
#define IS_UDC_ALIGNED(buf) IS_ALIGNED(buf, UDC_BUF_ALIGN)
85+
#define IS_USB_BUF_ALIGNED(buf) IS_ALIGNED(buf, USB_BUF_ALIGN)
8686

8787
/**
8888
* @cond INTERNAL_HIDDEN
8989
*/
90-
#define UDC_HEAP_DEFINE(name, bytes, in_section) \
91-
uint8_t in_section __aligned(UDC_BUF_ALIGN) \
90+
#define USB_BUF_HEAP_DEFINE(name, bytes, in_section) \
91+
uint8_t in_section __aligned(USB_BUF_ALIGN) \
9292
kheap_##name[MAX(bytes, Z_HEAP_MIN_SIZE)]; \
9393
STRUCT_SECTION_ITERABLE(k_heap, name) = { \
9494
.heap = { \
@@ -97,10 +97,10 @@
9797
}, \
9898
}
9999

100-
#define UDC_K_HEAP_DEFINE(name, size) \
101-
COND_CODE_1(CONFIG_UDC_BUF_FORCE_NOCACHE, \
102-
(UDC_HEAP_DEFINE(name, size, __nocache)), \
103-
(UDC_HEAP_DEFINE(name, size, __noinit)))
100+
#define USB_BUF_K_HEAP_DEFINE(name, size) \
101+
COND_CODE_1(CONFIG_USB_BUF_FORCE_NOCACHE, \
102+
(USB_BUF_HEAP_DEFINE(name, size, __nocache)), \
103+
(USB_BUF_HEAP_DEFINE(name, size, __noinit)))
104104

105105
extern const struct net_buf_data_cb net_buf_dma_cb;
106106
/** @endcond */
@@ -119,9 +119,9 @@ extern const struct net_buf_data_cb net_buf_dma_cb;
119119
* @param ud_size User data space to reserve per buffer.
120120
* @param fdestroy Optional destroy callback when buffer is freed.
121121
*/
122-
#define UDC_BUF_POOL_VAR_DEFINE(pname, count, size, ud_size, fdestroy) \
122+
#define USB_BUF_POOL_VAR_DEFINE(pname, count, size, ud_size, fdestroy) \
123123
_NET_BUF_ARRAY_DEFINE(pname, count, ud_size); \
124-
UDC_K_HEAP_DEFINE(net_buf_mem_pool_##pname, size); \
124+
USB_BUF_K_HEAP_DEFINE(net_buf_mem_pool_##pname, size); \
125125
static const struct net_buf_data_alloc net_buf_data_alloc_##pname = { \
126126
.cb = &net_buf_dma_cb, \
127127
.alloc_data = &net_buf_mem_pool_##pname, \
@@ -146,25 +146,68 @@ extern const struct net_buf_data_cb net_buf_dma_cb;
146146
* @param ud_size User data space to reserve per buffer.
147147
* @param fdestroy Optional destroy callback when buffer is freed.
148148
*/
149-
#define UDC_BUF_POOL_DEFINE(pname, count, size, ud_size, fdestroy) \
149+
#define USB_BUF_POOL_DEFINE(pname, count, size, ud_size, fdestroy) \
150150
_NET_BUF_ARRAY_DEFINE(pname, count, ud_size); \
151-
BUILD_ASSERT((UDC_BUF_GRANULARITY) % (UDC_BUF_ALIGN) == 0, \
151+
BUILD_ASSERT((USB_BUF_GRANULARITY) % (USB_BUF_ALIGN) == 0, \
152152
"Code assumes granurality is multiple of alignment"); \
153-
static uint8_t Z_UDC_BUF_SECTION __aligned(UDC_BUF_ALIGN) \
154-
net_buf_data_##pname[count][UDC_ROUND_UP(size)]; \
153+
static uint8_t Z_USB_BUF_SECTION __aligned(USB_BUF_ALIGN) \
154+
net_buf_data_##pname[count][USB_BUF_ROUND_UP(size)]; \
155155
static const struct net_buf_pool_fixed net_buf_fixed_##pname = { \
156156
.data_pool = (uint8_t *)net_buf_data_##pname, \
157157
}; \
158158
static const struct net_buf_data_alloc net_buf_fixed_alloc_##pname = { \
159159
.cb = &net_buf_fixed_cb, \
160160
.alloc_data = (void *)&net_buf_fixed_##pname, \
161-
.max_alloc_size = UDC_ROUND_UP(size), \
161+
.max_alloc_size = USB_BUF_ROUND_UP(size), \
162162
}; \
163163
static STRUCT_SECTION_ITERABLE(net_buf_pool, pname) = \
164164
NET_BUF_POOL_INITIALIZER(pname, &net_buf_fixed_alloc_##pname, \
165165
_net_buf_##pname, count, ud_size, \
166166
fdestroy)
167167

168+
/**
169+
* @brief Buffer alignment required by the UDC driver
170+
* @see USB_BUF_ALIGN
171+
*/
172+
#define UDC_BUF_ALIGN USB_BUF_ALIGN
173+
174+
/**
175+
* @brief Buffer granularity required by the UDC driver
176+
* @see USB_BUF_GRANULARITY
177+
*/
178+
#define UDC_BUF_GRANULARITY USB_BUF_GRANULARITY
179+
180+
/**
181+
* @brief Round up to the granularity required by the UDC driver
182+
* @see USB_BUF_ROUND_UP
183+
*/
184+
#define UDC_ROUND_UP(size) USB_BUF_ROUND_UP(size)
185+
186+
/**
187+
* @brief Define a UDC driver-compliant static buffer
188+
* @see USB_STATIC_BUF_DEFINE
189+
*/
190+
#define UDC_STATIC_BUF_DEFINE(name, size) USB_STATIC_BUF_DEFINE(name, size)
191+
192+
/**
193+
* @brief Verify that the buffer is aligned as required by the UDC driver
194+
* @see IS_UDC_ALIGNED
195+
*/
196+
#define IS_UDC_ALIGNED(buf) IS_USB_BUF_ALIGNED(buf)
197+
198+
/**
199+
* @brief Define a new pool for UDC buffers based on fixed-size data
200+
* @see USB_BUF_POOL_VAR_DEFINE
201+
*/
202+
#define UDC_BUF_POOL_VAR_DEFINE(pname, count, size, ud_size, fdestroy) \
203+
USB_BUF_POOL_VAR_DEFINE(pname, count, size, ud_size, fdestroy)
204+
205+
/**
206+
* @brief Define a new pool for UDC buffers based on fixed-size data
207+
* @see USB_BUF_POOL_DEFINE
208+
*/
209+
#define UDC_BUF_POOL_DEFINE(pname, count, size, ud_size, fdestroy) \
210+
USB_BUF_POOL_DEFINE(pname, count, size, ud_size, fdestroy)
168211
/**
169212
* @}
170213
*/

include/zephyr/usb/usbd.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include <zephyr/usb/bos.h>
1919
#include <zephyr/usb/usb_ch9.h>
2020
#include <zephyr/usb/usbd_msg.h>
21-
#include <zephyr/drivers/usb/udc_buf.h>
21+
#include <zephyr/drivers/usb/usb_buf.h>
2222
#include <zephyr/sys/byteorder.h>
2323
#include <zephyr/sys/slist.h>
2424
#include <zephyr/logging/log.h>

modules/hal_nxp/mcux/mcux-sdk-ng/middleware/usb_device_config.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ BUILD_ASSERT(NUM_INSTS <= 1, "Only one USB device supported");
102102
/*! @brief How many the DTD are supported. */
103103
#define USB_DEVICE_CONFIG_EHCI_MAX_DTD (16U)
104104

105-
#ifndef CONFIG_UDC_BUF_FORCE_NOCACHE
105+
#ifndef CONFIG_USB_BUF_FORCE_NOCACHE
106106
#ifdef CONFIG_NOCACHE_MEMORY
107107
#define USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE (1U)
108108
#endif

samples/bluetooth/bap_broadcast_source/src/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include <zephyr/bluetooth/uuid.h>
2222
#include <zephyr/device.h>
2323
#include <zephyr/devicetree.h>
24-
#include <zephyr/drivers/usb/udc_buf.h>
24+
#include <zephyr/drivers/usb/usb_buf.h>
2525
#include <zephyr/kernel.h>
2626
#include <zephyr/net_buf.h>
2727
#include <zephyr/sys/__assert.h>

0 commit comments

Comments
 (0)