drivers/thunderbolt/tb.c
Source file repositories/reference/linux-study-clean/drivers/thunderbolt/tb.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/thunderbolt/tb.c- Extension
.c- Size
- 89563 bytes
- Lines
- 3400
- Domain
- Driver Families
- Bucket
- drivers/thunderbolt
- 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.
- 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/slab.hlinux/errno.hlinux/delay.hlinux/pm_runtime.hlinux/platform_data/x86/apple.htb.htb_regs.htunnel.h
Detected Declarations
struct tb_cmstruct tb_hotplug_eventfunction tb_queue_hotplugfunction tb_add_dp_resourcesfunction tb_switch_for_each_portfunction tb_remove_dp_resourcesfunction list_for_each_entry_safefunction tb_discover_dp_resourcefunction list_for_each_entryfunction tb_discover_dp_resourcesfunction list_for_each_entryfunction tb_enable_clxfunction tb_disable_clxfunction tb_increase_switch_tmu_accuracyfunction tb_increase_tmu_accuracyfunction tb_switch_tmu_hifi_uni_requiredfunction tb_tmu_hifi_uni_requiredfunction tb_enable_tmufunction tb_switch_discover_tunnelsfunction tb_switch_for_each_portfunction tb_switch_for_each_portfunction tb_port_configure_xdomainfunction tb_port_unconfigure_xdomainfunction tb_scan_xdomainfunction tb_switch_for_each_portfunction list_for_each_entryfunction tb_consumed_usb3_pcie_bandwidthfunction tb_consumed_dp_bandwidthfunction tb_asym_supportedfunction tb_maximum_bandwidthfunction availablefunction availablefunction tb_available_bandwidthfunction tb_release_unused_usb3_bandwidthfunction tb_reclaim_usb3_bandwidthfunction tb_tunnel_usb3function tb_create_usb3_tunnelsfunction tb_switch_for_each_portfunction tb_configure_asymfunction tb_for_each_upstream_port_on_pathfunction tb_configure_symfunction tb_for_each_upstream_port_on_pathfunction thatfunction tb_configure_linkfunction tb_port_get_link_generationfunction tb_scan_switchfunction tb_scan_portfunction tb_recalc_estimated_bandwidth_for_group
Annotated Snippet
struct tb_cm {
struct list_head tunnel_list;
struct list_head dp_resources;
bool hotplug_active;
struct delayed_work remove_work;
struct tb_bandwidth_group groups[MAX_GROUPS];
};
static inline struct tb *tcm_to_tb(struct tb_cm *tcm)
{
return ((void *)tcm - sizeof(struct tb));
}
struct tb_hotplug_event {
struct delayed_work work;
struct tb *tb;
u64 route;
u8 port;
bool unplug;
int retry;
};
static void tb_scan_port(struct tb_port *port);
static void tb_handle_hotplug(struct work_struct *work);
static void tb_dp_resource_unavailable(struct tb *tb, struct tb_port *port,
const char *reason);
static void tb_queue_dp_bandwidth_request(struct tb *tb, u64 route, u8 port,
int retry, unsigned long delay);
static void tb_queue_hotplug(struct tb *tb, u64 route, u8 port, bool unplug)
{
struct tb_hotplug_event *ev;
ev = kmalloc_obj(*ev);
if (!ev)
return;
ev->tb = tb;
ev->route = route;
ev->port = port;
ev->unplug = unplug;
INIT_DELAYED_WORK(&ev->work, tb_handle_hotplug);
queue_delayed_work(tb->wq, &ev->work, 0);
}
/* enumeration & hot plug handling */
static void tb_add_dp_resources(struct tb_switch *sw)
{
struct tb_cm *tcm = tb_priv(sw->tb);
struct tb_port *port;
tb_switch_for_each_port(sw, port) {
if (!tb_port_is_dpin(port))
continue;
if (!tb_switch_query_dp_resource(sw, port))
continue;
/*
* If DP IN on device router exist, position it at the
* beginning of the DP resources list, so that it is used
* before DP IN of the host router. This way external GPU(s)
* will be prioritized when pairing DP IN to a DP OUT.
*/
if (tb_route(sw))
list_add(&port->list, &tcm->dp_resources);
else
list_add_tail(&port->list, &tcm->dp_resources);
tb_port_dbg(port, "DP IN resource available\n");
}
}
static void tb_remove_dp_resources(struct tb_switch *sw)
{
struct tb_cm *tcm = tb_priv(sw->tb);
struct tb_port *port, *tmp;
/* Clear children resources first */
tb_switch_for_each_port(sw, port) {
if (tb_port_has_remote(port))
tb_remove_dp_resources(port->remote->sw);
}
list_for_each_entry_safe(port, tmp, &tcm->dp_resources, list) {
if (port->sw == sw) {
tb_port_dbg(port, "DP OUT resource unavailable\n");
list_del_init(&port->list);
}
Annotation
- Immediate include surface: `linux/slab.h`, `linux/errno.h`, `linux/delay.h`, `linux/pm_runtime.h`, `linux/platform_data/x86/apple.h`, `tb.h`, `tb_regs.h`, `tunnel.h`.
- Detected declarations: `struct tb_cm`, `struct tb_hotplug_event`, `function tb_queue_hotplug`, `function tb_add_dp_resources`, `function tb_switch_for_each_port`, `function tb_remove_dp_resources`, `function list_for_each_entry_safe`, `function tb_discover_dp_resource`, `function list_for_each_entry`, `function tb_discover_dp_resources`.
- Atlas domain: Driver Families / drivers/thunderbolt.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.