mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson
synced 2025-08-27 06:50:37 +00:00

Expose the virtio-rtc UTC-like clock as an RTC clock to userspace - if it is present, and if it does not step on leap seconds. The RTC class enables the virtio-rtc device to resume the system from sleep states on RTC alarm. Support RTC alarm if the virtio-rtc alarm feature is present. The virtio-rtc device signals an alarm by marking an alarmq buffer as used. Peculiarities ------------- A virtio-rtc clock is a bit special for an RTC clock in that - the clock may step (also backwards) autonomously at any time and - the device, and its notification mechanism, will be reset during boot or resume from sleep. The virtio-rtc device avoids that the driver might miss an alarm. The device signals an alarm whenever the clock has reached or passed the alarm time, and also when the device is reset (on boot or resume from sleep), if the alarm time is in the past. Open Issue ---------- The CLOCK_BOOTTIME_ALARM will use the RTC clock to wake up from sleep, and implicitly assumes that no RTC clock steps will occur during sleep. The RTC class driver does not know whether the current alarm is a real-time alarm or a boot-time alarm. Perhaps this might be handled by the driver also setting a virtio-rtc monotonic alarm (which uses a clock similar to CLOCK_BOOTTIME_ALARM). The virtio-rtc monotonic alarm would just be used to wake up in case it was a CLOCK_BOOTTIME_ALARM alarm. Otherwise, the behavior should not differ from other RTC class drivers. Signed-off-by: Peter Hilber <quic_philber@quicinc.com> Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Message-Id: <20250509160734.1772-5-quic_philber@quicinc.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
123 lines
3.2 KiB
C
123 lines
3.2 KiB
C
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
/*
|
|
* virtio_rtc internal interfaces
|
|
*
|
|
* Copyright (C) 2022-2023 OpenSynergy GmbH
|
|
* Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
|
|
*/
|
|
|
|
#ifndef _VIRTIO_RTC_INTERNAL_H_
|
|
#define _VIRTIO_RTC_INTERNAL_H_
|
|
|
|
#include <linux/device.h>
|
|
#include <linux/err.h>
|
|
#include <linux/ptp_clock_kernel.h>
|
|
#include <linux/types.h>
|
|
|
|
/* driver core IFs */
|
|
|
|
struct viortc_dev;
|
|
|
|
int viortc_read(struct viortc_dev *viortc, u16 vio_clk_id, u64 *reading);
|
|
int viortc_read_cross(struct viortc_dev *viortc, u16 vio_clk_id, u8 hw_counter,
|
|
u64 *reading, u64 *cycles);
|
|
int viortc_cross_cap(struct viortc_dev *viortc, u16 vio_clk_id, u8 hw_counter,
|
|
bool *supported);
|
|
int viortc_read_alarm(struct viortc_dev *viortc, u16 vio_clk_id,
|
|
u64 *alarm_time, bool *enabled);
|
|
int viortc_set_alarm(struct viortc_dev *viortc, u16 vio_clk_id, u64 alarm_time,
|
|
bool alarm_enable);
|
|
int viortc_set_alarm_enabled(struct viortc_dev *viortc, u16 vio_clk_id,
|
|
bool alarm_enable);
|
|
|
|
struct viortc_class;
|
|
|
|
struct viortc_class *viortc_class_from_dev(struct device *dev);
|
|
|
|
/* PTP IFs */
|
|
|
|
struct viortc_ptp_clock;
|
|
|
|
#if IS_ENABLED(CONFIG_VIRTIO_RTC_PTP)
|
|
|
|
struct viortc_ptp_clock *viortc_ptp_register(struct viortc_dev *viortc,
|
|
struct device *parent_dev,
|
|
u16 vio_clk_id,
|
|
const char *ptp_clock_name);
|
|
int viortc_ptp_unregister(struct viortc_ptp_clock *vio_ptp,
|
|
struct device *parent_dev);
|
|
|
|
#else
|
|
|
|
static inline struct viortc_ptp_clock *
|
|
viortc_ptp_register(struct viortc_dev *viortc, struct device *parent_dev,
|
|
u16 vio_clk_id, const char *ptp_clock_name)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
static inline int viortc_ptp_unregister(struct viortc_ptp_clock *vio_ptp,
|
|
struct device *parent_dev)
|
|
{
|
|
return -ENODEV;
|
|
}
|
|
|
|
#endif
|
|
|
|
/* HW counter IFs */
|
|
|
|
/**
|
|
* viortc_hw_xtstamp_params() - get HW-specific xtstamp params
|
|
* @hw_counter: virtio_rtc HW counter type
|
|
* @cs_id: clocksource id corresponding to hw_counter
|
|
*
|
|
* Gets the HW-specific xtstamp params. Returns an error if the driver cannot
|
|
* support xtstamp.
|
|
*
|
|
* Context: Process context.
|
|
* Return: Zero on success, negative error code otherwise.
|
|
*/
|
|
int viortc_hw_xtstamp_params(u8 *hw_counter, enum clocksource_ids *cs_id);
|
|
|
|
/* RTC class IFs */
|
|
|
|
#if IS_ENABLED(CONFIG_VIRTIO_RTC_CLASS)
|
|
|
|
void viortc_class_alarm(struct viortc_class *viortc_class, u16 vio_clk_id);
|
|
|
|
void viortc_class_stop(struct viortc_class *viortc_class);
|
|
|
|
int viortc_class_register(struct viortc_class *viortc_class);
|
|
|
|
struct viortc_class *viortc_class_init(struct viortc_dev *viortc,
|
|
u16 vio_clk_id, bool have_alarm,
|
|
struct device *parent_dev);
|
|
|
|
#else /* CONFIG_VIRTIO_RTC_CLASS */
|
|
|
|
static inline void viortc_class_alarm(struct viortc_class *viortc_class,
|
|
u16 vio_clk_id)
|
|
{
|
|
}
|
|
|
|
static inline void viortc_class_stop(struct viortc_class *viortc_class)
|
|
{
|
|
}
|
|
|
|
static inline int viortc_class_register(struct viortc_class *viortc_class)
|
|
{
|
|
return -ENODEV;
|
|
}
|
|
|
|
static inline struct viortc_class *viortc_class_init(struct viortc_dev *viortc,
|
|
u16 vio_clk_id,
|
|
bool have_alarm,
|
|
struct device *parent_dev)
|
|
{
|
|
return ERR_PTR(-ENODEV);
|
|
}
|
|
|
|
#endif /* CONFIG_VIRTIO_RTC_CLASS */
|
|
|
|
#endif /* _VIRTIO_RTC_INTERNAL_H_ */
|