drivers/usb/dwc2/gadget.c
Source file repositories/reference/linux-study-clean/drivers/usb/dwc2/gadget.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/dwc2/gadget.c- Extension
.c- Size
- 151541 bytes
- Lines
- 5740
- Domain
- Driver Families
- Bucket
- drivers/usb
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- 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/spinlock.hlinux/interrupt.hlinux/platform_device.hlinux/dma-mapping.hlinux/mutex.hlinux/seq_file.hlinux/delay.hlinux/io.hlinux/slab.hlinux/usb/ch9.hlinux/usb/gadget.hlinux/usb/phy.hlinux/usb/composite.hcore.hhw.h
Detected Declarations
function Copyrightfunction dwc2_set_bitfunction dwc2_clear_bitfunction using_dmafunction using_desc_dmafunction dwc2_gadget_incr_frame_numfunction lastfunction dwc2_hsotg_en_gsintfunction dwc2_hsotg_disable_gsintfunction dwc2_hsotg_ctrl_epintfunction dwc2_hsotg_tx_fifo_countfunction dwc2_hsotg_tx_fifo_total_depthfunction dwc2_gadget_wkup_alert_handlerfunction dwc2_hsotg_tx_fifo_average_depthfunction dwc2_hsotg_init_fifofunction is_ep_periodicfunction dwc2_hsotg_map_dmafunction dwc2_gadget_alloc_ctrl_desc_chainsfunction spacefunction get_ep_limitfunction dwc2_hsotg_read_framenofunction dwc2_gadget_get_chain_limitfunction dwc2_gadget_get_desc_paramsfunction dwc2_gadget_fill_nonisoc_xfer_ddma_onefunction dwc2_gadget_config_nonisoc_xfer_ddmafunction dwc2_gadget_fill_isoc_descfunction dwc2_gadget_start_isoc_ddmafunction dwc2_hsotg_start_reqfunction dwc2_hsotg_map_dmafunction dwc2_hsotg_handle_unaligned_buf_startfunction dwc2_hsotg_handle_unaligned_buf_completefunction dwc2_gadget_target_frame_elapsedfunction dwc2_gadget_set_ep0_desc_chainfunction dwc2_hsotg_ep_queuefunction dwc2_hsotg_ep_queue_lockfunction dwc2_hsotg_ep_free_requestfunction dwc2_hsotg_complete_oursetupfunction dwc2_hsotg_set_test_modefunction dwc2_hsotg_send_replyfunction dwc2_hsotg_process_req_statusfunction dwc2_gadget_start_next_requestfunction dwc2_hsotg_process_req_featurefunction dwc2_hsotg_stall_ep0function nextfunction dwc2_hsotg_complete_setupfunction dwc2_hsotg_enqueue_setupfunction dwc2_hsotg_program_zlpfunction dwc2_hsotg_complete_request
Annotated Snippet
if (--timeout == 0) {
dev_err(hsotg->dev,
"%s: timeout flushing fifos (GRSTCTL=%08x)\n",
__func__, val);
break;
}
udelay(1);
}
dev_dbg(hsotg->dev, "FIFOs reset, timeout at %d\n", timeout);
}
/**
* dwc2_hsotg_ep_alloc_request - allocate USB rerequest structure
* @ep: USB endpoint to allocate request for.
* @flags: Allocation flags
*
* Allocate a new USB request structure appropriate for the specified endpoint
*/
static struct usb_request *dwc2_hsotg_ep_alloc_request(struct usb_ep *ep,
gfp_t flags)
{
struct dwc2_hsotg_req *req;
req = kzalloc_obj(*req, flags);
if (!req)
return NULL;
INIT_LIST_HEAD(&req->queue);
return &req->req;
}
/**
* is_ep_periodic - return true if the endpoint is in periodic mode.
* @hs_ep: The endpoint to query.
*
* Returns true if the endpoint is in periodic mode, meaning it is being
* used for an Interrupt or ISO transfer.
*/
static inline int is_ep_periodic(struct dwc2_hsotg_ep *hs_ep)
{
return hs_ep->periodic;
}
/**
* dwc2_hsotg_unmap_dma - unmap the DMA memory being used for the request
* @hsotg: The device state.
* @hs_ep: The endpoint for the request
* @hs_req: The request being processed.
*
* This is the reverse of dwc2_hsotg_map_dma(), called for the completion
* of a request to ensure the buffer is ready for access by the caller.
*/
static void dwc2_hsotg_unmap_dma(struct dwc2_hsotg *hsotg,
struct dwc2_hsotg_ep *hs_ep,
struct dwc2_hsotg_req *hs_req)
{
struct usb_request *req = &hs_req->req;
usb_gadget_unmap_request(&hsotg->gadget, req, hs_ep->map_dir);
}
/*
* dwc2_gadget_alloc_ctrl_desc_chains - allocate DMA descriptor chains
* for Control endpoint
* @hsotg: The device state.
*
* This function will allocate 4 descriptor chains for EP 0: 2 for
* Setup stage, per one for IN and OUT data/status transactions.
*/
static int dwc2_gadget_alloc_ctrl_desc_chains(struct dwc2_hsotg *hsotg)
{
hsotg->setup_desc[0] =
dmam_alloc_coherent(hsotg->dev,
sizeof(struct dwc2_dma_desc),
&hsotg->setup_desc_dma[0],
GFP_KERNEL);
if (!hsotg->setup_desc[0])
goto fail;
hsotg->setup_desc[1] =
dmam_alloc_coherent(hsotg->dev,
sizeof(struct dwc2_dma_desc),
&hsotg->setup_desc_dma[1],
GFP_KERNEL);
if (!hsotg->setup_desc[1])
goto fail;
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/spinlock.h`, `linux/interrupt.h`, `linux/platform_device.h`, `linux/dma-mapping.h`, `linux/mutex.h`, `linux/seq_file.h`.
- Detected declarations: `function Copyright`, `function dwc2_set_bit`, `function dwc2_clear_bit`, `function using_dma`, `function using_desc_dma`, `function dwc2_gadget_incr_frame_num`, `function last`, `function dwc2_hsotg_en_gsint`, `function dwc2_hsotg_disable_gsint`, `function dwc2_hsotg_ctrl_epint`.
- Atlas domain: Driver Families / drivers/usb.
- Implementation status: source 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.