drivers/thunderbolt/tmu.c
Source file repositories/reference/linux-study-clean/drivers/thunderbolt/tmu.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/thunderbolt/tmu.c- Extension
.c- Size
- 25695 bytes
- Lines
- 1073
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/delay.htb.h
Detected Declarations
function tb_switch_tmu_enhanced_is_supportedfunction tb_switch_set_tmu_mode_paramsfunction tb_switch_tmu_ucap_is_supportedfunction tb_switch_tmu_rate_readfunction tb_switch_tmu_rate_writefunction tb_port_tmu_writefunction tb_port_tmu_set_unidirectionalfunction tb_port_tmu_unidirectional_disablefunction tb_port_tmu_unidirectional_enablefunction tb_port_tmu_is_unidirectionalfunction tb_port_tmu_is_enhancedfunction tb_port_tmu_enhanced_enablefunction tb_port_set_tmu_mode_paramsfunction tb_port_tmu_rate_writefunction tb_port_tmu_time_syncfunction tb_port_tmu_time_sync_disablefunction tb_port_tmu_time_sync_enablefunction tb_switch_tmu_set_time_disruptionfunction tmu_mode_initfunction tb_switch_tmu_initfunction tb_switch_for_each_portfunction tb_switch_tmu_post_timefunction disable_enhancedfunction tb_switch_tmu_disablefunction tb_switch_tmu_offfunction tb_switch_tmu_enable_bidirectionalfunction tb_switch_tmu_disable_objectionsfunction tb_switch_tmu_enable_unidirectionalfunction tb_switch_tmu_enable_enhancedfunction tb_switch_tmu_change_mode_prevfunction tb_switch_tmu_change_modefunction tb_switch_tmu_enablefunction tb_switch_tmu_configure
Annotated Snippet
if (enhanced && tb_port_tmu_is_enhanced(up)) {
sw->tmu.mode = TB_SWITCH_TMU_MODE_MEDRES_ENHANCED_UNI;
} else if (ucap && tb_port_tmu_is_unidirectional(up)) {
if (tmu_rates[TB_SWITCH_TMU_MODE_LOWRES] == rate)
sw->tmu.mode = TB_SWITCH_TMU_MODE_LOWRES;
else if (tmu_rates[TB_SWITCH_TMU_MODE_HIFI_UNI] == rate)
sw->tmu.mode = TB_SWITCH_TMU_MODE_HIFI_UNI;
} else if (rate) {
sw->tmu.mode = TB_SWITCH_TMU_MODE_HIFI_BI;
}
} else if (rate) {
sw->tmu.mode = TB_SWITCH_TMU_MODE_HIFI_BI;
}
/* Update the initial request to match the current mode */
sw->tmu.mode_request = sw->tmu.mode;
sw->tmu.has_ucap = ucap;
return 0;
}
/**
* tb_switch_tmu_init() - Initialize switch TMU structures
* @sw: Switch to be initialized
*
* This function must be called before other TMU related functions to
* make sure the internal structures are filled in correctly. Does not
* change any hardware configuration.
*
* Return: %0 on success, negative errno otherwise.
*/
int tb_switch_tmu_init(struct tb_switch *sw)
{
struct tb_port *port;
int ret;
if (tb_switch_is_icm(sw))
return 0;
ret = tb_switch_find_cap(sw, TB_SWITCH_CAP_TMU);
if (ret > 0)
sw->tmu.cap = ret;
tb_switch_for_each_port(sw, port) {
int cap;
cap = tb_port_find_cap(port, TB_PORT_CAP_TIME1);
if (cap > 0)
port->cap_tmu = cap;
}
ret = tmu_mode_init(sw);
if (ret)
return ret;
tb_sw_dbg(sw, "TMU: current mode: %s\n", tmu_mode_name(sw->tmu.mode));
return 0;
}
/**
* tb_switch_tmu_post_time() - Update switch local time
* @sw: Switch whose time to update
*
* Updates switch local time using time posting procedure.
*
* Return: %0 on success, negative errno otherwise.
*/
int tb_switch_tmu_post_time(struct tb_switch *sw)
{
unsigned int post_time_high_offset, post_time_high = 0;
unsigned int post_local_time_offset, post_time_offset;
struct tb_switch *root_switch = sw->tb->root_switch;
u64 hi, mid, lo, local_time, post_time;
int i, ret, retries = 100;
u32 gm_local_time[3];
if (!tb_route(sw))
return 0;
if (!tb_switch_is_usb4(sw))
return 0;
/* Need to be able to read the grand master time */
if (!root_switch->tmu.cap)
return 0;
ret = tb_sw_read(root_switch, gm_local_time, TB_CFG_SWITCH,
root_switch->tmu.cap + TMU_RTR_CS_1,
ARRAY_SIZE(gm_local_time));
if (ret)
Annotation
- Immediate include surface: `linux/delay.h`, `tb.h`.
- Detected declarations: `function tb_switch_tmu_enhanced_is_supported`, `function tb_switch_set_tmu_mode_params`, `function tb_switch_tmu_ucap_is_supported`, `function tb_switch_tmu_rate_read`, `function tb_switch_tmu_rate_write`, `function tb_port_tmu_write`, `function tb_port_tmu_set_unidirectional`, `function tb_port_tmu_unidirectional_disable`, `function tb_port_tmu_unidirectional_enable`, `function tb_port_tmu_is_unidirectional`.
- Atlas domain: Driver Families / drivers/thunderbolt.
- Implementation status: source implementation candidate.
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.