drivers/thunderbolt/debugfs.c
Source file repositories/reference/linux-study-clean/drivers/thunderbolt/debugfs.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/thunderbolt/debugfs.c- Extension
.c- Size
- 65912 bytes
- Lines
- 2554
- Domain
- Driver Families
- Bucket
- drivers/thunderbolt
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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 an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/array_size.hlinux/bitfield.hlinux/debugfs.hlinux/delay.hlinux/pm_runtime.hlinux/string_choices.hlinux/uaccess.htb.hsb_regs.h
Detected Declarations
struct sb_regstruct tb_marginingenum usb4_margin_cap_voltage_indpenum usb4_margin_cap_time_indpfunction parse_linefunction path_write_onefunction regs_writefunction port_regs_writefunction path_writefunction switch_regs_writefunction parse_sb_linefunction sb_regs_writefunction port_sb_regs_writefunction retimer_sb_regs_writefunction margining_modify_error_counterfunction supports_softwarefunction supports_hardwarefunction all_lanesfunction independent_voltage_marginsfunction supports_timefunction independent_time_marginsfunction supports_optional_voltage_offset_rangefunction margining_ber_level_writefunction ber_level_showfunction margining_ber_level_showfunction margining_caps_showfunction margining_lanes_writefunction scoped_cond_guardfunction margining_lanes_showfunction scoped_cond_guardfunction margining_voltage_time_offset_writefunction scoped_cond_guardfunction margining_voltage_time_offset_showfunction scoped_cond_guardfunction margining_error_counter_writefunction scoped_cond_guardfunction margining_error_counter_showfunction scoped_cond_guardfunction margining_dwell_time_writefunction scoped_cond_guardfunction margining_dwell_time_showfunction scoped_cond_guardfunction margining_optional_voltage_offset_writefunction scoped_cond_guardfunction margining_optional_voltage_offset_showfunction scoped_cond_guardfunction margining_mode_writefunction margining_mode_show
Annotated Snippet
static const struct file_operations __space ## _fops = { \
.owner = THIS_MODULE, \
.open = __space ## _open, \
.release = single_release, \
.read = seq_read, \
.write = __write, \
.llseek = seq_lseek, \
}
#define DEBUGFS_ATTR_RO(__space) \
DEBUGFS_ATTR(__space, NULL)
#define DEBUGFS_ATTR_RW(__space) \
DEBUGFS_ATTR(__space, __space ## _write)
static struct dentry *tb_debugfs_root;
static void *validate_and_copy_from_user(const void __user *user_buf,
size_t *count)
{
size_t nbytes;
void *buf;
if (!*count)
return ERR_PTR(-EINVAL);
if (!access_ok(user_buf, *count))
return ERR_PTR(-EFAULT);
buf = (void *)get_zeroed_page(GFP_KERNEL);
if (!buf)
return ERR_PTR(-ENOMEM);
nbytes = min_t(size_t, *count, PAGE_SIZE);
if (copy_from_user(buf, user_buf, nbytes)) {
free_page((unsigned long)buf);
return ERR_PTR(-EFAULT);
}
*count = nbytes;
return buf;
}
static bool parse_line(char **line, u32 *offs, u32 *val, int short_fmt_len,
int long_fmt_len)
{
char *token;
u32 v[5];
int ret;
token = strsep(line, "\n");
if (!token)
return false;
/*
* For Adapter/Router configuration space:
* Short format is: offset value\n
* v[0] v[1]
* Long format as produced from the read side:
* offset relative_offset cap_id vs_cap_id value\n
* v[0] v[1] v[2] v[3] v[4]
*
* For Path configuration space:
* Short format is: offset value\n
* v[0] v[1]
* Long format as produced from the read side:
* offset relative_offset in_hop_id value\n
* v[0] v[1] v[2] v[3]
*
* For Counter configuration space:
* Short format is: offset\n
* v[0]
* Long format as produced from the read side:
* offset relative_offset counter_id value\n
* v[0] v[1] v[2] v[3]
*/
ret = sscanf(token, "%i %i %i %i %i", &v[0], &v[1], &v[2], &v[3], &v[4]);
/* In case of Counters, clear counter, "val" content is NA */
if (ret == short_fmt_len) {
*offs = v[0];
*val = v[short_fmt_len - 1];
return true;
} else if (ret == long_fmt_len) {
*offs = v[0];
*val = v[long_fmt_len - 1];
return true;
}
return false;
}
Annotation
- Immediate include surface: `linux/array_size.h`, `linux/bitfield.h`, `linux/debugfs.h`, `linux/delay.h`, `linux/pm_runtime.h`, `linux/string_choices.h`, `linux/uaccess.h`, `tb.h`.
- Detected declarations: `struct sb_reg`, `struct tb_margining`, `enum usb4_margin_cap_voltage_indp`, `enum usb4_margin_cap_time_indp`, `function parse_line`, `function path_write_one`, `function regs_write`, `function port_regs_write`, `function path_write`, `function switch_regs_write`.
- Atlas domain: Driver Families / drivers/thunderbolt.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.