drivers/usb/dwc2/hcd_ddma.c
Source file repositories/reference/linux-study-clean/drivers/usb/dwc2/hcd_ddma.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/dwc2/hcd_ddma.c- Extension
.c- Size
- 37107 bytes
- Lines
- 1355
- 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/dma-mapping.hlinux/io.hlinux/slab.hlinux/usb.hlinux/usb/hcd.hlinux/usb/ch11.hcore.hhcd.h
Detected Declarations
function Copyrightfunction dwc2_desclist_idx_incfunction dwc2_desclist_idx_decfunction dwc2_max_desc_numfunction dwc2_frame_incr_valfunction dwc2_desc_list_allocfunction dwc2_desc_list_freefunction dwc2_frame_list_allocfunction dwc2_frame_list_freefunction dwc2_per_sched_enablefunction dwc2_per_sched_disablefunction dwc2_update_frame_listfunction dwc2_release_channel_ddmafunction dwc2_hcd_qh_init_ddmafunction dwc2_hcd_qh_free_ddmafunction dwc2_frame_to_desc_idxfunction dwc2_calc_starting_framefunction numberfunction dwc2_recalc_initial_desc_idxfunction listfunction dwc2_fill_host_isoc_dma_descfunction dwc2_init_isoc_dma_descfunction list_for_each_entryfunction dwc2_fill_host_dma_descfunction Lastfunction dwc2_init_non_isoc_dma_descfunction list_for_each_entryfunction dwc2_hcd_start_xfer_ddmafunction dwc2_cmpl_host_isoc_dma_descfunction dwc2_complete_isoc_xfer_ddmafunction list_for_each_entry_safefunction list_for_each_entry_safefunction dwc2_update_non_isoc_urb_state_ddmafunction dwc2_process_non_isoc_descfunction dwc2_complete_non_isoc_xfer_ddmafunction list_for_each_safefunction dwc2_hcd_complete_xfer_ddmafunction list_for_each_entry_safe
Annotated Snippet
if (!hsotg->frame_list) {
retval = dwc2_frame_list_alloc(hsotg, mem_flags);
if (retval)
goto err1;
/* Enable periodic schedule on first periodic QH */
dwc2_per_sched_enable(hsotg, HCFG_FRLISTEN_64);
}
}
qh->ntd = 0;
return 0;
err1:
dwc2_desc_list_free(hsotg, qh);
err0:
return retval;
}
/**
* dwc2_hcd_qh_free_ddma() - Frees a QH structure's Descriptor DMA related
* members
*
* @hsotg: The HCD state structure for the DWC OTG controller
* @qh: The QH to free
*
* Frees descriptor list memory associated with the QH. If QH is periodic and
* the last, frees FrameList memory and disables periodic scheduling.
*/
void dwc2_hcd_qh_free_ddma(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh)
{
unsigned long flags;
dwc2_desc_list_free(hsotg, qh);
/*
* Channel still assigned due to some reasons.
* Seen on Isoc URB dequeue. Channel halted but no subsequent
* ChHalted interrupt to release the channel. Afterwards
* when it comes here from endpoint disable routine
* channel remains assigned.
*/
spin_lock_irqsave(&hsotg->lock, flags);
if (qh->channel)
dwc2_release_channel_ddma(hsotg, qh);
spin_unlock_irqrestore(&hsotg->lock, flags);
if ((qh->ep_type == USB_ENDPOINT_XFER_ISOC ||
qh->ep_type == USB_ENDPOINT_XFER_INT) &&
(hsotg->params.uframe_sched ||
!hsotg->periodic_channels) && hsotg->frame_list) {
dwc2_per_sched_disable(hsotg);
dwc2_frame_list_free(hsotg);
}
}
static u8 dwc2_frame_to_desc_idx(struct dwc2_qh *qh, u16 frame_idx)
{
if (qh->dev_speed == USB_SPEED_HIGH)
/* Descriptor set (8 descriptors) index which is 8-aligned */
return (frame_idx & ((MAX_DMA_DESC_NUM_HS_ISOC / 8) - 1)) * 8;
else
return frame_idx & (MAX_DMA_DESC_NUM_GENERIC - 1);
}
/*
* Determine starting frame for Isochronous transfer.
* Few frames skipped to prevent race condition with HC.
*/
static u16 dwc2_calc_starting_frame(struct dwc2_hsotg *hsotg,
struct dwc2_qh *qh, u16 *skip_frames)
{
u16 frame;
hsotg->frame_number = dwc2_hcd_get_frame_number(hsotg);
/*
* next_active_frame is always frame number (not uFrame) both in FS
* and HS!
*/
/*
* skip_frames is used to limit activated descriptors number
* to avoid the situation when HC services the last activated
* descriptor firstly.
* Example for FS:
* Current frame is 1, scheduled frame is 3. Since HC always fetches
* the descriptor corresponding to curr_frame+1, the descriptor
* corresponding to frame 2 will be fetched. If the number of
* descriptors is max=64 (or greather) the list will be fully programmed
* with Active descriptors and it is possible case (rare) that the
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/spinlock.h`, `linux/interrupt.h`, `linux/dma-mapping.h`, `linux/io.h`, `linux/slab.h`, `linux/usb.h`.
- Detected declarations: `function Copyright`, `function dwc2_desclist_idx_inc`, `function dwc2_desclist_idx_dec`, `function dwc2_max_desc_num`, `function dwc2_frame_incr_val`, `function dwc2_desc_list_alloc`, `function dwc2_desc_list_free`, `function dwc2_frame_list_alloc`, `function dwc2_frame_list_free`, `function dwc2_per_sched_enable`.
- 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.