drivers/ptp/ptp_clock.c
Source file repositories/reference/linux-study-clean/drivers/ptp/ptp_clock.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/ptp/ptp_clock.c- Extension
.c- Size
- 17312 bytes
- Lines
- 712
- Domain
- Driver Families
- Bucket
- drivers/ptp
- 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.
- 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/device.hlinux/err.hlinux/init.hlinux/kernel.hlinux/module.hlinux/posix-clock.hlinux/pps_kernel.hlinux/property.hlinux/slab.hlinux/syscalls.hlinux/uaccess.hlinux/debugfs.hlinux/xarray.huapi/linux/sched/types.hptp_private.h
Detected Declarations
function queue_freefunction enqueue_external_timestampfunction ptp_clock_getresfunction ptp_clock_settimefunction ptp_clock_gettimefunction ptp_clock_adjtimefunction ptp_clock_releasefunction ptp_getcycles64function ptp_enablefunction ptp_aux_kworkerfunction ptp_n_perout_loopback_readfunction ptp_perout_loopback_writefunction unregister_vclockfunction ptp_clock_unregisterfunction ptp_clock_eventfunction list_for_each_entryfunction ptp_clock_indexfunction ptp_clock_of_node_matchfunction ptp_clock_index_by_of_nodefunction ptp_clock_dev_matchfunction ptp_clock_index_by_devfunction ptp_find_pinfunction ptp_find_pin_unlockedfunction ptp_schedule_workerfunction ptp_cancel_worker_syncfunction ptp_exitfunction ptp_initmodule init ptp_initexport ptp_clock_registerexport ptp_clock_unregisterexport ptp_clock_eventexport ptp_clock_indexexport ptp_clock_index_by_of_nodeexport ptp_clock_index_by_devexport ptp_find_pinexport ptp_find_pin_unlockedexport ptp_schedule_workerexport ptp_cancel_worker_sync
Annotated Snippet
static const struct file_operations ptp_n_perout_loopback_fops = {
.owner = THIS_MODULE,
.open = simple_open,
.read = ptp_n_perout_loopback_read,
};
static ssize_t ptp_perout_loopback_write(struct file *filep,
const char __user *buffer,
size_t count, loff_t *ppos)
{
struct ptp_clock *ptp = filep->private_data;
struct ptp_clock_info *ops = ptp->info;
unsigned int index, enable;
int len, cnt, err;
char buf[32] = {};
if (*ppos || !count)
return -EINVAL;
if (count >= sizeof(buf))
return -ENOSPC;
len = simple_write_to_buffer(buf, sizeof(buf) - 1,
ppos, buffer, count);
if (len < 0)
return len;
buf[len] = '\0';
cnt = sscanf(buf, "%u %u", &index, &enable);
if (cnt != 2)
return -EINVAL;
if (index >= ops->n_per_lp)
return -EINVAL;
if (enable != 0 && enable != 1)
return -EINVAL;
err = ops->perout_loopback(ops, index, enable);
if (err)
return err;
return count;
}
static const struct file_operations ptp_perout_loopback_ops = {
.owner = THIS_MODULE,
.open = simple_open,
.write = ptp_perout_loopback_write,
};
/* public interface */
struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info,
struct device *parent)
{
struct ptp_clock *ptp;
struct timestamp_event_queue *queue = NULL;
int err, index, major = MAJOR(ptp_devt);
char debugfsname[16];
size_t size;
if (WARN_ON_ONCE(info->n_alarm > PTP_MAX_ALARMS ||
(!info->gettimex64 && !info->gettime64) ||
!info->settime64))
return ERR_PTR(-EINVAL);
/* Initialize a clock structure. */
ptp = kzalloc_obj(struct ptp_clock);
if (!ptp) {
err = -ENOMEM;
goto no_memory;
}
err = xa_alloc(&ptp_clocks_map, &index, ptp, xa_limit_31b,
GFP_KERNEL);
if (err)
goto no_slot;
ptp->clock.ops = ptp_clock_ops;
ptp->info = info;
ptp->devid = MKDEV(major, index);
ptp->index = index;
INIT_LIST_HEAD(&ptp->tsevqs);
queue = kzalloc_obj(*queue);
if (!queue) {
err = -ENOMEM;
goto no_memory_queue;
}
list_add_tail(&queue->qlist, &ptp->tsevqs);
Annotation
- Immediate include surface: `linux/device.h`, `linux/err.h`, `linux/init.h`, `linux/kernel.h`, `linux/module.h`, `linux/posix-clock.h`, `linux/pps_kernel.h`, `linux/property.h`.
- Detected declarations: `function queue_free`, `function enqueue_external_timestamp`, `function ptp_clock_getres`, `function ptp_clock_settime`, `function ptp_clock_gettime`, `function ptp_clock_adjtime`, `function ptp_clock_release`, `function ptp_getcycles64`, `function ptp_enable`, `function ptp_aux_kworker`.
- Atlas domain: Driver Families / drivers/ptp.
- Implementation status: pattern 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.