drivers/usb/gadget/udc/core.c
Source file repositories/reference/linux-study-clean/drivers/usb/gadget/udc/core.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/gadget/udc/core.c- Extension
.c- Size
- 55302 bytes
- Lines
- 1951
- Domain
- Driver Families
- Bucket
- drivers/usb
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/module.hlinux/device.hlinux/list.hlinux/idr.hlinux/err.hlinux/dma-mapping.hlinux/sched/task_stack.hlinux/workqueue.hlinux/usb/ch9.hlinux/usb/gadget.hlinux/usb.htrace.h
Detected Declarations
struct usb_udcfunction usb_ep_set_maxpacket_limitfunction implementationfunction disconnectfunction usb_ep_queuefunction usb_ep_alloc_requestfunction usb_ep_queuefunction zerofunction failfunction usb_ep_clear_haltfunction CLEAR_FEATUREfunction driverfunction usb_ep_fifo_flushfunction usb_gadget_frame_numberfunction usb_gadget_wakeupfunction usb_gadget_set_remote_wakeupfunction usb_gadget_set_selfpoweredfunction usb_gadget_clear_selfpoweredfunction transceiverfunction usb_gadget_vbus_drawfunction transceiverfunction usb_gadget_connect_lockedfunction activefunction usb_gadget_disconnect_lockedfunction disconnectfunction usb_gadget_deactivatefunction usb_gadget_activatefunction usb_gadget_map_request_by_devfunction usb_gadget_map_requestfunction usb_gadget_unmap_request_by_devfunction usb_gadget_unmap_requestfunction usb_gadget_giveback_requestfunction gadget_for_each_epfunction usb_gadget_ep_match_descfunction usb_gadget_check_configfunction usb_gadget_state_workfunction usb_gadget_set_statefunction usb_udc_connect_control_lockedfunction vbus_event_workfunction usb_udc_connect_controlfunction usb_gadget_udc_resetfunction usb_gadget_udc_start_lockedfunction usb_gadget_udc_stop_lockedfunction usb_gadget_udc_start_lockedfunction usb_gadget_enable_async_callbacksfunction callbackfunction usb_udc_releasefunction usb_udc_nop_release
Annotated Snippet
static const struct bus_type gadget_bus_type;
/**
* struct usb_udc - describes one usb device controller
* @driver: the gadget driver pointer. For use by the class code
* @dev: the child device to the actual controller
* @gadget: the gadget. For use by the class code
* @list: for use by the udc class driver
* @vbus: for udcs who care about vbus status, this value is real vbus status;
* for udcs who do not care about vbus status, this value is always true
* @started: the UDC's started state. True if the UDC had started.
* @allow_connect: Indicates whether UDC is allowed to be pulled up.
* Set/cleared by gadget_(un)bind_driver() after gadget driver is bound or
* unbound.
* @vbus_work: work routine to handle VBUS status change notifications.
* @connect_lock: protects udc->started, gadget->connect,
* gadget->allow_connect and gadget->deactivate. The routines
* usb_gadget_connect_locked(), usb_gadget_disconnect_locked(),
* usb_udc_connect_control_locked(), usb_gadget_udc_start_locked() and
* usb_gadget_udc_stop_locked() are called with this lock held.
*
* This represents the internal data structure which is used by the UDC-class
* to hold information about udc driver and gadget together.
*/
struct usb_udc {
struct usb_gadget_driver *driver;
struct usb_gadget *gadget;
struct device dev;
struct list_head list;
bool vbus;
bool started;
bool allow_connect;
struct work_struct vbus_work;
struct mutex connect_lock;
};
static const struct class udc_class;
static LIST_HEAD(udc_list);
/* Protects udc_list, udc->driver, driver->is_bound, and related calls */
static DEFINE_MUTEX(udc_lock);
/* ------------------------------------------------------------------------- */
/**
* usb_ep_set_maxpacket_limit - set maximum packet size limit for endpoint
* @ep:the endpoint being configured
* @maxpacket_limit:value of maximum packet size limit
*
* This function should be used only in UDC drivers to initialize endpoint
* (usually in probe function).
*/
void usb_ep_set_maxpacket_limit(struct usb_ep *ep,
unsigned maxpacket_limit)
{
ep->maxpacket_limit = maxpacket_limit;
ep->maxpacket = maxpacket_limit;
trace_usb_ep_set_maxpacket_limit(ep, 0);
}
EXPORT_SYMBOL_GPL(usb_ep_set_maxpacket_limit);
/**
* usb_ep_enable - configure endpoint, making it usable
* @ep:the endpoint being configured. may not be the endpoint named "ep0".
* drivers discover endpoints through the ep_list of a usb_gadget.
*
* When configurations are set, or when interface settings change, the driver
* will enable or disable the relevant endpoints. while it is enabled, an
* endpoint may be used for i/o until the driver receives a disconnect() from
* the host or until the endpoint is disabled.
*
* the ep0 implementation (which calls this routine) must ensure that the
* hardware capabilities of each endpoint match the descriptor provided
* for it. for example, an endpoint named "ep2in-bulk" would be usable
* for interrupt transfers as well as bulk, but it likely couldn't be used
* for iso transfers or for endpoint 14. some endpoints are fully
* configurable, with more generic names like "ep-a". (remember that for
* USB, "in" means "towards the USB host".)
*
* This routine may be called in an atomic (interrupt) context.
*
* returns zero, or a negative error code.
*/
int usb_ep_enable(struct usb_ep *ep)
{
int ret = 0;
if (ep->enabled)
goto out;
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/device.h`, `linux/list.h`, `linux/idr.h`, `linux/err.h`, `linux/dma-mapping.h`, `linux/sched/task_stack.h`.
- Detected declarations: `struct usb_udc`, `function usb_ep_set_maxpacket_limit`, `function implementation`, `function disconnect`, `function usb_ep_queue`, `function usb_ep_alloc_request`, `function usb_ep_queue`, `function zero`, `function fail`, `function usb_ep_clear_halt`.
- Atlas domain: Driver Families / drivers/usb.
- Implementation status: pattern implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.