drivers/usb/dwc3/debugfs.c
Source file repositories/reference/linux-study-clean/drivers/usb/dwc3/debugfs.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/dwc3/debugfs.c- Extension
.c- Size
- 25433 bytes
- Lines
- 1040
- Domain
- Driver Families
- Bucket
- drivers/usb
- 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/kernel.hlinux/slab.hlinux/ptrace.hlinux/types.hlinux/spinlock.hlinux/debugfs.hlinux/seq_file.hlinux/delay.hlinux/uaccess.hlinux/usb/ch9.hcore.hgadget.hio.hdebug.h
Detected Declarations
struct dwc3_ep_file_mapfunction dwc3_host_lspfunction dwc3_gadget_lspfunction dwc3_lsp_showfunction dwc3_lsp_openfunction dwc3_lsp_writefunction dwc3_mode_showfunction dwc3_mode_openfunction dwc3_mode_writefunction dwc3_testmode_showfunction dwc3_testmode_openfunction dwc3_testmode_writefunction dwc3_link_state_showfunction dwc3_link_state_openfunction dwc3_link_state_writefunction dwc3_tx_fifo_size_showfunction dwc3_rx_fifo_size_showfunction dwc3_tx_request_queue_showfunction dwc3_rx_request_queue_showfunction dwc3_rx_info_queue_showfunction dwc3_descriptor_fetch_queue_showfunction dwc3_event_queue_showfunction dwc3_transfer_type_showfunction dwc3_trb_ring_showfunction dwc3_ep_info_register_showfunction dwc3_debugfs_create_endpoint_dirfunction dwc3_debugfs_remove_endpoint_dirfunction dwc3_debugfs_initfunction dwc3_debugfs_exit
Annotated Snippet
static const struct file_operations dwc3_lsp_fops = {
.open = dwc3_lsp_open,
.write = dwc3_lsp_write,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
static int dwc3_mode_show(struct seq_file *s, void *unused)
{
struct dwc3 *dwc = s->private;
unsigned long flags;
u32 reg;
u32 mode;
int ret;
ret = pm_runtime_resume_and_get(dwc->dev);
if (ret < 0)
return ret;
spin_lock_irqsave(&dwc->lock, flags);
reg = dwc3_readl(dwc, DWC3_GCTL);
spin_unlock_irqrestore(&dwc->lock, flags);
mode = DWC3_GCTL_PRTCAP(reg);
switch (mode) {
case DWC3_GCTL_PRTCAP_HOST:
case DWC3_GCTL_PRTCAP_DEVICE:
case DWC3_GCTL_PRTCAP_OTG:
seq_printf(s, "%s\n", dwc3_mode_string(mode));
break;
default:
seq_printf(s, "UNKNOWN %08x\n", mode);
}
pm_runtime_put_sync(dwc->dev);
return 0;
}
static int dwc3_mode_open(struct inode *inode, struct file *file)
{
return single_open(file, dwc3_mode_show, inode->i_private);
}
static ssize_t dwc3_mode_write(struct file *file,
const char __user *ubuf, size_t count, loff_t *ppos)
{
struct seq_file *s = file->private_data;
struct dwc3 *dwc = s->private;
u32 mode = 0;
char buf[32];
if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
return -EFAULT;
if (dwc->dr_mode != USB_DR_MODE_OTG)
return count;
if (!strncmp(buf, "host", 4))
mode = DWC3_GCTL_PRTCAP_HOST;
if (!strncmp(buf, "device", 6))
mode = DWC3_GCTL_PRTCAP_DEVICE;
if (!strncmp(buf, "otg", 3))
mode = DWC3_GCTL_PRTCAP_OTG;
dwc3_set_mode(dwc, mode);
return count;
}
static const struct file_operations dwc3_mode_fops = {
.open = dwc3_mode_open,
.write = dwc3_mode_write,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
static int dwc3_testmode_show(struct seq_file *s, void *unused)
{
struct dwc3 *dwc = s->private;
unsigned long flags;
u32 reg;
int ret;
ret = pm_runtime_resume_and_get(dwc->dev);
if (ret < 0)
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/slab.h`, `linux/ptrace.h`, `linux/types.h`, `linux/spinlock.h`, `linux/debugfs.h`, `linux/seq_file.h`, `linux/delay.h`.
- Detected declarations: `struct dwc3_ep_file_map`, `function dwc3_host_lsp`, `function dwc3_gadget_lsp`, `function dwc3_lsp_show`, `function dwc3_lsp_open`, `function dwc3_lsp_write`, `function dwc3_mode_show`, `function dwc3_mode_open`, `function dwc3_mode_write`, `function dwc3_testmode_show`.
- Atlas domain: Driver Families / drivers/usb.
- 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.