drivers/usb/host/xhci-mem.c
Source file repositories/reference/linux-study-clean/drivers/usb/host/xhci-mem.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/host/xhci-mem.c- Extension
.c- Size
- 72891 bytes
- Lines
- 2515
- Domain
- Driver Families
- Bucket
- drivers/usb
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/usb.hlinux/overflow.hlinux/pci.hlinux/slab.hlinux/dmapool.hlinux/dma-mapping.hxhci.hxhci-trace.hxhci-debugfs.h
Detected Declarations
function Copyrightfunction xhci_segment_freefunction xhci_ring_segments_freefunction xhci_set_link_trbfunction xhci_initialize_ring_segmentsfunction xhci_ring_initfunction xhci_link_ringsfunction xhci_for_each_ring_segfunction systemsfunction xhci_remove_segment_mappingfunction xhci_update_stream_segment_mappingfunction xhci_for_each_ring_segfunction xhci_remove_stream_mappingfunction xhci_update_stream_mappingfunction xhci_ring_freefunction xhci_initialize_ring_infofunction xhci_alloc_segments_for_ringfunction xhci_free_endpoint_ringfunction xhci_ring_expansionfunction xhci_free_container_ctxfunction xhci_free_port_bw_ctxfunction xhci_free_stream_ctxfunction xhci_setup_streams_ep_input_ctxfunction xhci_setup_no_streams_ep_input_ctxfunction xhci_free_stream_infofunction xhci_free_tt_infofunction xhci_alloc_tt_infofunction xhci_free_virt_devicefunction tt_infofunction xhci_alloc_virt_devicefunction xhci_copy_ep0_dequeue_into_input_ctxfunction tofunction xhci_setup_addressable_virt_devfunction portfunction list_for_each_entryfunction xhci_parse_exponent_intervalfunction microframesfunction xhci_parse_microframe_intervalfunction xhci_parse_frame_intervalfunction xhci_get_endpoint_intervalfunction xhci_get_endpoint_multfunction xhci_get_endpoint_max_burstfunction xhci_get_endpoint_typefunction usb_alloc_streamsfunction usb_endpoint_xfer_isocfunction xhci_endpoint_zerofunction xhci_clear_endpoint_bw_infofunction xhci_update_bw_info
Annotated Snippet
if (!seg->bounce_buf) {
dma_pool_free(xhci->segment_pool, seg->trbs, dma);
kfree(seg);
return NULL;
}
}
seg->num = num;
seg->dma = dma;
seg->next = NULL;
return seg;
}
static void xhci_segment_free(struct xhci_hcd *xhci, struct xhci_segment *seg)
{
if (seg->trbs) {
dma_pool_free(xhci->segment_pool, seg->trbs, seg->dma);
seg->trbs = NULL;
}
kfree(seg->bounce_buf);
kfree(seg);
}
static void xhci_ring_segments_free(struct xhci_hcd *xhci, struct xhci_ring *ring)
{
struct xhci_segment *seg, *next;
ring->last_seg->next = NULL;
seg = ring->first_seg;
while (seg) {
next = seg->next;
xhci_segment_free(xhci, seg);
seg = next;
}
}
/*
* Only for transfer and command rings where driver is the producer, not for
* event rings.
*
* Change the last TRB in the segment to be a Link TRB which points to the
* DMA address of the next segment. The caller needs to set any Link TRB
* related flags, such as End TRB, Toggle Cycle, and no snoop.
*/
static void xhci_set_link_trb(struct xhci_segment *seg, bool chain_links)
{
union xhci_trb *trb;
u32 val;
if (!seg || !seg->next)
return;
trb = &seg->trbs[TRBS_PER_SEGMENT - 1];
/* Set the last TRB in the segment to have a TRB type ID of Link TRB */
val = le32_to_cpu(trb->link.control);
val &= ~TRB_TYPE_BITMASK;
val |= TRB_TYPE(TRB_LINK);
if (chain_links)
val |= TRB_CHAIN;
trb->link.control = cpu_to_le32(val);
trb->link.segment_ptr = cpu_to_le64(seg->next->dma);
}
static void xhci_initialize_ring_segments(struct xhci_hcd *xhci, struct xhci_ring *ring)
{
struct xhci_segment *seg;
bool chain_links;
if (ring->type == TYPE_EVENT)
return;
chain_links = xhci_link_chain_quirk(xhci, ring->type);
xhci_for_each_ring_seg(ring->first_seg, seg)
xhci_set_link_trb(seg, chain_links);
/* See section 4.9.2.1 and 6.4.4.1 */
ring->last_seg->trbs[TRBS_PER_SEGMENT - 1].link.control |= cpu_to_le32(LINK_TOGGLE);
}
void xhci_ring_init(struct xhci_hcd *xhci, struct xhci_ring *ring)
{
xhci_initialize_ring_segments(xhci, ring);
xhci_initialize_ring_info(ring);
trace_xhci_ring_alloc(ring);
}
/*
* Link the src ring segments to the dst ring.
Annotation
- Immediate include surface: `linux/usb.h`, `linux/overflow.h`, `linux/pci.h`, `linux/slab.h`, `linux/dmapool.h`, `linux/dma-mapping.h`, `xhci.h`, `xhci-trace.h`.
- Detected declarations: `function Copyright`, `function xhci_segment_free`, `function xhci_ring_segments_free`, `function xhci_set_link_trb`, `function xhci_initialize_ring_segments`, `function xhci_ring_init`, `function xhci_link_rings`, `function xhci_for_each_ring_seg`, `function systems`, `function xhci_remove_segment_mapping`.
- Atlas domain: Driver Families / drivers/usb.
- Implementation status: integration 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.