drivers/virtio/virtio_rtc_ptp.c
Source file repositories/reference/linux-study-clean/drivers/virtio/virtio_rtc_ptp.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/virtio/virtio_rtc_ptp.c- Extension
.c- Size
- 8816 bytes
- Lines
- 348
- Domain
- Driver Families
- Bucket
- drivers/virtio
- 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.
- 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/ptp_clock_kernel.huapi/linux/virtio_rtc.hvirtio_rtc_internal.h
Detected Declarations
struct viortc_ptp_clockstruct viortc_ptp_cross_ctxfunction viortc_hw_xtstamp_paramsfunction viortc_ptp_get_time_fnfunction viortc_ptp_do_xtstampfunction viortc_ptp_getcrosststampfunction viortc_ptp_adjfinefunction viortc_ptp_adjtimefunction viortc_ptp_settime64function viortc_ptp_gettimex64function viortc_ptp_enablefunction viortc_ptp_unregisterfunction viortc_ptp_get_cross_cap
Annotated Snippet
struct viortc_ptp_clock {
struct ptp_clock *ptp_clock;
struct viortc_dev *viortc;
struct ptp_clock_info ptp_info;
u16 vio_clk_id;
bool have_cross;
};
/**
* struct viortc_ptp_cross_ctx - context for get_device_system_crosststamp()
* @device_time: device clock reading
* @system_counterval: HW counter value at device_time
*
* Provides the already obtained crosststamp to get_device_system_crosststamp().
*/
struct viortc_ptp_cross_ctx {
ktime_t device_time;
struct system_counterval_t system_counterval;
};
/* Weak function in case get_device_system_crosststamp() is not supported */
int __weak viortc_hw_xtstamp_params(u8 *hw_counter, enum clocksource_ids *cs_id)
{
return -EOPNOTSUPP;
}
/**
* viortc_ptp_get_time_fn() - callback for get_device_system_crosststamp()
* @device_time: device clock reading
* @system_counterval: HW counter value at device_time
* @ctx: context with already obtained crosststamp
*
* Return: zero (success).
*/
static int viortc_ptp_get_time_fn(ktime_t *device_time,
struct system_counterval_t *system_counterval,
void *ctx)
{
struct viortc_ptp_cross_ctx *vio_ctx = ctx;
*device_time = vio_ctx->device_time;
*system_counterval = vio_ctx->system_counterval;
return 0;
}
/**
* viortc_ptp_do_xtstamp() - get crosststamp from device
* @vio_ptp: virtio_rtc PTP clock
* @hw_counter: virtio_rtc HW counter type
* @cs_id: clocksource id corresponding to hw_counter
* @ctx: context for get_device_system_crosststamp()
*
* Reads HW-specific crosststamp from device.
*
* Context: Process context.
* Return: Zero on success, negative error code otherwise.
*/
static int viortc_ptp_do_xtstamp(struct viortc_ptp_clock *vio_ptp,
u8 hw_counter, enum clocksource_ids cs_id,
struct viortc_ptp_cross_ctx *ctx)
{
u64 max_ns, ns;
int ret;
ctx->system_counterval.cs_id = cs_id;
ret = viortc_read_cross(vio_ptp->viortc, vio_ptp->vio_clk_id,
hw_counter, &ns,
&ctx->system_counterval.cycles);
if (ret)
return ret;
max_ns = (u64)ktime_to_ns(KTIME_MAX);
if (ns > max_ns)
return -EINVAL;
ctx->device_time = ns_to_ktime(ns);
return 0;
}
/*
* PTP clock operations
*/
/**
* viortc_ptp_getcrosststamp() - PTP clock getcrosststamp op
* @ptp: PTP clock info
* @xtstamp: crosststamp
Annotation
- Immediate include surface: `linux/device.h`, `linux/err.h`, `linux/ptp_clock_kernel.h`, `uapi/linux/virtio_rtc.h`, `virtio_rtc_internal.h`.
- Detected declarations: `struct viortc_ptp_clock`, `struct viortc_ptp_cross_ctx`, `function viortc_hw_xtstamp_params`, `function viortc_ptp_get_time_fn`, `function viortc_ptp_do_xtstamp`, `function viortc_ptp_getcrosststamp`, `function viortc_ptp_adjfine`, `function viortc_ptp_adjtime`, `function viortc_ptp_settime64`, `function viortc_ptp_gettimex64`.
- Atlas domain: Driver Families / drivers/virtio.
- 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.