drivers/pci/pcie/ptm.c
Source file repositories/reference/linux-study-clean/drivers/pci/pcie/ptm.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/pci/pcie/ptm.c- Extension
.c- Size
- 13658 bytes
- Lines
- 588
- Domain
- Representative Device Path
- Bucket
- PCIe NVMe Storage Path
- Inferred role
- Representative Device Path: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Part of the selected hardware vertical slice: PCI discovery, driver binding, NVMe queues, block requests, DMA, interrupts, and completion.
- Part of the selected hardware vertical slice: PCI discovery, driver binding, NVMe queues, block requests, DMA, interrupts, and completion.
- 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/bitfield.hlinux/debugfs.hlinux/module.hlinux/init.hlinux/pci.h../pci.h
Detected Declarations
function Capabilityfunction pci_save_ptm_statefunction pci_restore_ptm_statefunction __pci_enable_ptmfunction pci_enable_ptmfunction __pci_disable_ptmfunction pci_disable_ptmfunction pci_suspend_ptmfunction pci_resume_ptmfunction pcie_ptm_enabledfunction context_update_writefunction context_update_readfunction context_valid_getfunction context_valid_setfunction local_clock_getfunction master_clock_getfunction t1_getfunction t2_getfunction t3_getfunction t4_getfunction pcie_ptm_create_debugfsfunction pcie_ptm_destroy_debugfsexport pci_enable_ptmexport pci_disable_ptmexport pcie_ptm_enabledexport pcie_ptm_create_debugfsexport pcie_ptm_destroy_debugfs
Annotated Snippet
static const struct file_operations context_update_fops = {
.open = simple_open,
.read = context_update_read,
.write = context_update_write,
};
static int context_valid_get(void *data, u64 *val)
{
struct pci_ptm_debugfs *ptm_debugfs = data;
bool valid;
int ret;
if (!ptm_debugfs->ops->context_valid_read)
return -EOPNOTSUPP;
mutex_lock(&ptm_debugfs->lock);
ret = ptm_debugfs->ops->context_valid_read(ptm_debugfs->pdata, &valid);
mutex_unlock(&ptm_debugfs->lock);
if (ret)
return ret;
*val = valid;
return 0;
}
static int context_valid_set(void *data, u64 val)
{
struct pci_ptm_debugfs *ptm_debugfs = data;
int ret;
if (!ptm_debugfs->ops->context_valid_write)
return -EOPNOTSUPP;
mutex_lock(&ptm_debugfs->lock);
ret = ptm_debugfs->ops->context_valid_write(ptm_debugfs->pdata, !!val);
mutex_unlock(&ptm_debugfs->lock);
return ret;
}
DEFINE_DEBUGFS_ATTRIBUTE(context_valid_fops, context_valid_get,
context_valid_set, "%llu\n");
static int local_clock_get(void *data, u64 *val)
{
struct pci_ptm_debugfs *ptm_debugfs = data;
u64 clock;
int ret;
if (!ptm_debugfs->ops->local_clock_read)
return -EOPNOTSUPP;
ret = ptm_debugfs->ops->local_clock_read(ptm_debugfs->pdata, &clock);
if (ret)
return ret;
*val = clock;
return 0;
}
DEFINE_DEBUGFS_ATTRIBUTE(local_clock_fops, local_clock_get, NULL, "%llu\n");
static int master_clock_get(void *data, u64 *val)
{
struct pci_ptm_debugfs *ptm_debugfs = data;
u64 clock;
int ret;
if (!ptm_debugfs->ops->master_clock_read)
return -EOPNOTSUPP;
ret = ptm_debugfs->ops->master_clock_read(ptm_debugfs->pdata, &clock);
if (ret)
return ret;
*val = clock;
return 0;
}
DEFINE_DEBUGFS_ATTRIBUTE(master_clock_fops, master_clock_get, NULL, "%llu\n");
static int t1_get(void *data, u64 *val)
{
struct pci_ptm_debugfs *ptm_debugfs = data;
u64 clock;
int ret;
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/debugfs.h`, `linux/module.h`, `linux/init.h`, `linux/pci.h`, `../pci.h`.
- Detected declarations: `function Capability`, `function pci_save_ptm_state`, `function pci_restore_ptm_state`, `function __pci_enable_ptm`, `function pci_enable_ptm`, `function __pci_disable_ptm`, `function pci_disable_ptm`, `function pci_suspend_ptm`, `function pci_resume_ptm`, `function pcie_ptm_enabled`.
- Atlas domain: Representative Device Path / PCIe NVMe Storage Path.
- 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.