drivers/virtio/virtio_rtc_driver.c
Source file repositories/reference/linux-study-clean/drivers/virtio/virtio_rtc_driver.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/virtio/virtio_rtc_driver.c- Extension
.c- Size
- 35883 bytes
- Lines
- 1420
- 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.
- 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/completion.hlinux/device.hlinux/module.hlinux/pm.hlinux/virtio.hlinux/virtio_config.hlinux/virtio_ids.huapi/linux/virtio_rtc.hvirtio_rtc_internal.h
Detected Declarations
struct viortc_vqstruct viortc_devstruct viortc_msgfunction viortc_class_from_devfunction viortc_alarms_supportedfunction viortc_feed_vqfunction viortc_msg_initfunction viortc_msg_releasefunction viortc_do_cbfunction viortc_requestq_hdlrfunction viortc_cb_requestqfunction viortc_alarmq_hdlrfunction viortc_cb_alarmqfunction viortc_get_resp_errnofunction viortc_msg_xferfunction viortc_readfunction viortc_read_crossfunction viortc_cfgfunction viortc_clock_capfunction viortc_cross_capfunction viortc_read_alarmfunction viortc_set_alarmfunction viortc_set_alarm_enabledfunction viortc_init_rtc_class_clockfunction viortc_init_ptp_clockfunction viortc_init_clockfunction viortc_clocks_deinitfunction viortc_clocks_initfunction viortc_populate_vqfunction viortc_alloc_vq_bufsfunction viortc_init_vqsfunction __viortc_removefunction viortc_probefunction viortc_removefunction viortc_freezefunction viortc_restore
Annotated Snippet
struct viortc_vq {
struct virtqueue *vq;
spinlock_t lock;
};
/**
* struct viortc_dev - virtio_rtc device data
* @vdev: virtio device
* @viortc_class: RTC class wrapper for UTC-like clock, NULL if not available
* @vqs: virtqueues
* @clocks_to_unregister: Clock references, which are only used during device
* removal.
* For other uses, there would be a race between device
* creation and setting the pointers here.
* @alarmq_bufs: alarmq buffers list
* @num_alarmq_bufs: # of alarmq buffers
* @num_clocks: # of virtio_rtc clocks
*/
struct viortc_dev {
struct virtio_device *vdev;
struct viortc_class *viortc_class;
struct viortc_vq vqs[VIORTC_MAX_NR_QUEUES];
struct viortc_ptp_clock **clocks_to_unregister;
void **alarmq_bufs;
unsigned int num_alarmq_bufs;
u16 num_clocks;
};
/**
* struct viortc_msg - Message requested by driver, responded by device.
* @viortc: device data
* @req: request buffer
* @resp: response buffer
* @responded: vqueue callback signals response reception
* @refcnt: Message reference count, message and buffers will be deallocated
* once 0. refcnt is decremented in the vqueue callback and in the
* thread waiting on the responded completion.
* If a message response wait function times out, the message will be
* freed upon late reception (refcnt will reach 0 in the callback), or
* device removal.
* @req_size: size of request in bytes
* @resp_cap: maximum size of response in bytes
* @resp_actual_size: actual size of response
*/
struct viortc_msg {
struct viortc_dev *viortc;
void *req;
void *resp;
struct completion responded;
refcount_t refcnt;
unsigned int req_size;
unsigned int resp_cap;
unsigned int resp_actual_size;
};
/**
* viortc_class_from_dev() - Get RTC class object from virtio device.
* @dev: virtio device
*
* Context: Any context.
* Return: RTC class object if available, ERR_PTR otherwise.
*/
struct viortc_class *viortc_class_from_dev(struct device *dev)
{
struct virtio_device *vdev;
struct viortc_dev *viortc;
vdev = container_of(dev, typeof(*vdev), dev);
viortc = vdev->priv;
return viortc->viortc_class ?: ERR_PTR(-ENODEV);
}
/**
* viortc_alarms_supported() - Whether device and driver support alarms.
* @vdev: virtio device
*
* NB: Device and driver may not support alarms for the same clocks.
*
* Context: Any context.
* Return: True if both device and driver can support alarms.
*/
static bool viortc_alarms_supported(struct virtio_device *vdev)
{
return IS_ENABLED(CONFIG_VIRTIO_RTC_CLASS) &&
virtio_has_feature(vdev, VIRTIO_RTC_F_ALARM);
}
/**
* viortc_feed_vq() - Make a device write-only buffer available.
Annotation
- Immediate include surface: `linux/completion.h`, `linux/device.h`, `linux/module.h`, `linux/pm.h`, `linux/virtio.h`, `linux/virtio_config.h`, `linux/virtio_ids.h`, `uapi/linux/virtio_rtc.h`.
- Detected declarations: `struct viortc_vq`, `struct viortc_dev`, `struct viortc_msg`, `function viortc_class_from_dev`, `function viortc_alarms_supported`, `function viortc_feed_vq`, `function viortc_msg_init`, `function viortc_msg_release`, `function viortc_do_cb`, `function viortc_requestq_hdlr`.
- Atlas domain: Driver Families / drivers/virtio.
- Implementation status: source 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.