drivers/usb/dwc2/hcd.c
Source file repositories/reference/linux-study-clean/drivers/usb/dwc2/hcd.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/dwc2/hcd.c- Extension
.c- Size
- 167946 bytes
- Lines
- 5998
- 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/delay.hlinux/io.hlinux/slab.hlinux/usb.hlinux/usb/hcd.hlinux/usb/ch11.hlinux/usb/of.hcore.hhcd.h
Detected Declarations
struct wrapper_priv_datafunction Copyrightfunction dwc2_gahbcfg_initfunction dwc2_gusbcfg_initfunction dwc2_vbus_supply_initfunction dwc2_vbus_supply_exitfunction dwc2_enable_host_interruptsfunction dwc2_disable_host_interruptsfunction dwc2_calculate_dynamic_fifofunction MPSfunction dwc2_config_fifosfunction dwc2_calc_frame_intervalfunction dwc2_read_packetfunction dwc2_dump_channel_infofunction dwc2_host_startfunction dwc2_host_disconnectfunction dwc2_host_hub_infofunction dwc2_hc_enable_slave_intsfunction dwc2_hc_enable_dma_intsfunction dwc2_hc_enable_intsfunction dwc2_hc_initfunction dwc2_hc_haltfunction dwc2_hc_cleanupfunction dwc2_hc_set_even_odd_framefunction dwc2_set_pid_isocfunction dwc2_hc_write_packetfunction dwc2_hc_do_pingfunction dwc2_hc_start_transferfunction dwc2_hc_start_transfer_ddmafunction dwc2_hc_continue_transferfunction dwc2_kill_urbs_in_qh_listfunction list_for_each_entry_safefunction dwc2_qh_list_freefunction list_for_each_entry_safefunction dwc2_kill_all_urbsfunction dwc2_hcd_startfunction dwc2_hcd_cleanup_channelsfunction dwc2_hcd_connectfunction dwc2_hcd_disconnectfunction dwc2_hcd_rem_wakeupfunction dwc2_hcd_stopfunction dwc2_hcd_urb_enqueuefunction dwc2_hcd_urb_dequeuefunction dwc2_hcd_endpoint_disablefunction dwc2_hcd_endpoint_resetfunction dwc2_core_initfunction usfunction dwc2_core_host_init
Annotated Snippet
struct wrapper_priv_data {
struct dwc2_hsotg *hsotg;
};
/* Gets the dwc2_hsotg from a usb_hcd */
static struct dwc2_hsotg *dwc2_hcd_to_hsotg(struct usb_hcd *hcd)
{
struct wrapper_priv_data *p;
p = (struct wrapper_priv_data *)&hcd->hcd_priv;
return p->hsotg;
}
/**
* dwc2_host_get_tt_info() - Get the dwc2_tt associated with context
*
* This will get the dwc2_tt structure (and ttport) associated with the given
* context (which is really just a struct urb pointer).
*
* The first time this is called for a given TT we allocate memory for our
* structure. When everyone is done and has called dwc2_host_put_tt_info()
* then the refcount for the structure will go to 0 and we'll free it.
*
* @hsotg: The HCD state structure for the DWC OTG controller.
* @context: The priv pointer from a struct dwc2_hcd_urb.
* @mem_flags: Flags for allocating memory.
* @ttport: We'll return this device's port number here. That's used to
* reference into the bitmap if we're on a multi_tt hub.
*
* Return: a pointer to a struct dwc2_tt. Don't forget to call
* dwc2_host_put_tt_info()! Returns NULL upon memory alloc failure.
*/
struct dwc2_tt *dwc2_host_get_tt_info(struct dwc2_hsotg *hsotg, void *context,
gfp_t mem_flags, int *ttport)
{
struct urb *urb = context;
struct dwc2_tt *dwc_tt = NULL;
if (urb->dev->tt) {
*ttport = urb->dev->ttport;
dwc_tt = urb->dev->tt->hcpriv;
if (!dwc_tt) {
size_t bitmap_size;
/*
* For single_tt we need one schedule. For multi_tt
* we need one per port.
*/
bitmap_size = DWC2_ELEMENTS_PER_LS_BITMAP *
sizeof(dwc_tt->periodic_bitmaps[0]);
if (urb->dev->tt->multi)
bitmap_size *= urb->dev->tt->hub->maxchild;
dwc_tt = kzalloc(sizeof(*dwc_tt) + bitmap_size,
mem_flags);
if (!dwc_tt)
return NULL;
dwc_tt->usb_tt = urb->dev->tt;
dwc_tt->usb_tt->hcpriv = dwc_tt;
}
dwc_tt->refcount++;
}
return dwc_tt;
}
/**
* dwc2_host_put_tt_info() - Put the dwc2_tt from dwc2_host_get_tt_info()
*
* Frees resources allocated by dwc2_host_get_tt_info() if all current holders
* of the structure are done.
*
* It's OK to call this with NULL.
*
* @hsotg: The HCD state structure for the DWC OTG controller.
* @dwc_tt: The pointer returned by dwc2_host_get_tt_info.
*/
void dwc2_host_put_tt_info(struct dwc2_hsotg *hsotg, struct dwc2_tt *dwc_tt)
{
/* Model kfree and make put of NULL a no-op */
if (!dwc_tt)
return;
WARN_ON(dwc_tt->refcount < 1);
dwc_tt->refcount--;
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/delay.h`, `linux/io.h`.
- Detected declarations: `struct wrapper_priv_data`, `function Copyright`, `function dwc2_gahbcfg_init`, `function dwc2_gusbcfg_init`, `function dwc2_vbus_supply_init`, `function dwc2_vbus_supply_exit`, `function dwc2_enable_host_interrupts`, `function dwc2_disable_host_interrupts`, `function dwc2_calculate_dynamic_fifo`, `function MPS`.
- 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.