drivers/usb/host/xhci-sideband.c
Source file repositories/reference/linux-study-clean/drivers/usb/host/xhci-sideband.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/host/xhci-sideband.c- Extension
.c- Size
- 13255 bytes
- Lines
- 495
- 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/xhci-sideband.hlinux/dma-direct.hxhci.h
Detected Declarations
function Copyrightfunction __xhci_sideband_remove_endpointfunction __xhci_sideband_remove_interrupterfunction xhci_sideband_notify_ep_ring_freefunction xhci_sideband_endpoint_bufferfunction xhci_sideband_remove_endpointfunction xhci_sideband_stop_endpointfunction xhci_sideband_get_endpoint_bufferfunction xhci_sideband_get_event_bufferfunction xhci_sideband_checkfunction xhci_sideband_interrupter_idfunction xhci_sideband_remove_interrupterfunction xhci_sideband_interrupter_idfunction xhci_sideband_registerfunction xhci_sideband_unregisterfunction scoped_guardexport xhci_sideband_notify_ep_ring_freeexport xhci_sideband_add_endpointexport xhci_sideband_remove_endpointexport xhci_sideband_stop_endpointexport xhci_sideband_get_endpoint_bufferexport xhci_sideband_get_event_bufferexport xhci_sideband_checkexport xhci_sideband_create_interrupterexport xhci_sideband_remove_interrupterexport xhci_sideband_interrupter_idexport xhci_sideband_registerexport xhci_sideband_unregister
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* xHCI host controller sideband support
*
* Copyright (c) 2023-2025, Intel Corporation.
*
* Author: Mathias Nyman
*/
#include <linux/usb/xhci-sideband.h>
#include <linux/dma-direct.h>
#include "xhci.h"
/* sideband internal helpers */
static struct sg_table *
xhci_ring_to_sgtable(struct xhci_sideband *sb, struct xhci_ring *ring)
{
struct xhci_segment *seg;
struct sg_table *sgt;
unsigned int n_pages;
struct page **pages;
struct device *dev;
size_t sz;
int i;
dev = xhci_to_hcd(sb->xhci)->self.sysdev;
sz = ring->num_segs * TRB_SEGMENT_SIZE;
n_pages = PAGE_ALIGN(sz) >> PAGE_SHIFT;
pages = kvmalloc_objs(struct page *, n_pages);
if (!pages)
return NULL;
sgt = kzalloc_obj(*sgt);
if (!sgt) {
kvfree(pages);
return NULL;
}
seg = ring->first_seg;
if (!seg)
goto err;
/*
* Rings can potentially have multiple segments, create an array that
* carries page references to allocated segments. Utilize the
* sg_alloc_table_from_pages() to create the sg table, and to ensure
* that page links are created.
*/
for (i = 0; i < ring->num_segs; i++) {
dma_get_sgtable(dev, sgt, seg->trbs, seg->dma,
TRB_SEGMENT_SIZE);
pages[i] = sg_page(sgt->sgl);
sg_free_table(sgt);
seg = seg->next;
}
if (sg_alloc_table_from_pages(sgt, pages, n_pages, 0, sz, GFP_KERNEL))
goto err;
/*
* Save first segment dma address to sg dma_address field for the sideband
* client to have access to the IOVA of the ring.
*/
sg_dma_address(sgt->sgl) = ring->first_seg->dma;
return sgt;
err:
kvfree(pages);
kfree(sgt);
return NULL;
}
/* Caller must hold sb->mutex */
static void
__xhci_sideband_remove_endpoint(struct xhci_sideband *sb, struct xhci_virt_ep *ep)
{
lockdep_assert_held(&sb->mutex);
/*
* Issue a stop endpoint command when an endpoint is removed.
* The stop ep cmd handler will handle the ring cleanup.
*/
xhci_stop_endpoint_sync(sb->xhci, ep, 0, GFP_KERNEL);
ep->sideband = NULL;
sb->eps[ep->ep_index] = NULL;
}
Annotation
- Immediate include surface: `linux/usb/xhci-sideband.h`, `linux/dma-direct.h`, `xhci.h`.
- Detected declarations: `function Copyright`, `function __xhci_sideband_remove_endpoint`, `function __xhci_sideband_remove_interrupter`, `function xhci_sideband_notify_ep_ring_free`, `function xhci_sideband_endpoint_buffer`, `function xhci_sideband_remove_endpoint`, `function xhci_sideband_stop_endpoint`, `function xhci_sideband_get_endpoint_buffer`, `function xhci_sideband_get_event_buffer`, `function xhci_sideband_check`.
- 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.