History

virtio_rtc: Add RTC class driver

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.

Peter Hilber committed 1 year ago

Commit 9d4f22f1 parent e2ef1676 files · +934 −11Browse files

Showing the changes to include/uapi/linux (1 of 6 files). Show all

Unified · Split

include/uapi/linux/virtio_rtc.h+87−1
@@ -9,6 +9,9 @@ · 8 unmodified lines
9 9
10#include <linux/types.h>10#include <linux/types.h>
11 11
12/* alarm feature */
13#define VIRTIO_RTC_F_ALARM 0
14
12/* read request message types */15/* read request message types */
13 16
14#define VIRTIO_RTC_REQ_READ 0x000117#define VIRTIO_RTC_REQ_READ 0x0001
@@ -19,6 +22,13 @@ · 4 unmodified lines
19#define VIRTIO_RTC_REQ_CFG 0x100022#define VIRTIO_RTC_REQ_CFG 0x1000
20#define VIRTIO_RTC_REQ_CLOCK_CAP 0x100123#define VIRTIO_RTC_REQ_CLOCK_CAP 0x1001
21#define VIRTIO_RTC_REQ_CROSS_CAP 0x100224#define VIRTIO_RTC_REQ_CROSS_CAP 0x1002
25#define VIRTIO_RTC_REQ_READ_ALARM 0x1003
26#define VIRTIO_RTC_REQ_SET_ALARM 0x1004
27#define VIRTIO_RTC_REQ_SET_ALARM_ENABLED 0x1005
28
29/* alarmq message types */
30
31#define VIRTIO_RTC_NOTIF_ALARM 0x2000
22 32
23/* Message headers */33/* Message headers */
24 34
@@ -39,6 +49,12 @@ struct virtio_rtc_resp_head { · 14 unmodified lines
39 __u8 reserved[7];49 __u8 reserved[7];
40};50};
41 51
52/** common notification header */
53struct virtio_rtc_notif_head {
54 __le16 msg_type;
55 __u8 reserved[6];
56};
57
42/* read requests */58/* read requests */
43 59
44/* VIRTIO_RTC_REQ_READ message */60/* VIRTIO_RTC_REQ_READ message */
@@ -111,7 +127,9 @@ struct virtio_rtc_resp_clock_cap { · 66 unmodified lines
111#define VIRTIO_RTC_SMEAR_NOON_LINEAR 1127#define VIRTIO_RTC_SMEAR_NOON_LINEAR 1
112#define VIRTIO_RTC_SMEAR_UTC_SLS 2128#define VIRTIO_RTC_SMEAR_UTC_SLS 2
113 __u8 leap_second_smearing;129 __u8 leap_second_smearing;
114 __u8 reserved[6];130#define VIRTIO_RTC_FLAG_ALARM_CAP (1 << 0)
131 __u8 flags;
132 __u8 reserved[5];
115};133};
116 134
117/* VIRTIO_RTC_REQ_CROSS_CAP message */135/* VIRTIO_RTC_REQ_CROSS_CAP message */
@@ -130,6 +148,53 @@ struct virtio_rtc_resp_cross_cap { · 12 unmodified lines
130 __u8 reserved[7];148 __u8 reserved[7];
131};149};
132 150
151/* VIRTIO_RTC_REQ_READ_ALARM message */
152
153struct virtio_rtc_req_read_alarm {
154 struct virtio_rtc_req_head head;
155 __le16 clock_id;
156 __u8 reserved[6];
157};
158
159struct virtio_rtc_resp_read_alarm {
160 struct virtio_rtc_resp_head head;
161 __le64 alarm_time;
162#define VIRTIO_RTC_FLAG_ALARM_ENABLED (1 << 0)
163 __u8 flags;
164 __u8 reserved[7];
165};
166
167/* VIRTIO_RTC_REQ_SET_ALARM message */
168
169struct virtio_rtc_req_set_alarm {
170 struct virtio_rtc_req_head head;
171 __le64 alarm_time;
172 __le16 clock_id;
173 /* flag VIRTIO_RTC_FLAG_ALARM_ENABLED */
174 __u8 flags;
175 __u8 reserved[5];
176};
177
178struct virtio_rtc_resp_set_alarm {
179 struct virtio_rtc_resp_head head;
180 /* no response params */
181};
182
183/* VIRTIO_RTC_REQ_SET_ALARM_ENABLED message */
184
185struct virtio_rtc_req_set_alarm_enabled {
186 struct virtio_rtc_req_head head;
187 __le16 clock_id;
188 /* flag VIRTIO_RTC_ALARM_ENABLED */
189 __u8 flags;
190 __u8 reserved[5];
191};
192
193struct virtio_rtc_resp_set_alarm_enabled {
194 struct virtio_rtc_resp_head head;
195 /* no response params */
196};
197
133/** Union of request types for requestq */198/** Union of request types for requestq */
134union virtio_rtc_req_requestq {199union virtio_rtc_req_requestq {
135 struct virtio_rtc_req_read read;200 struct virtio_rtc_req_read read;
@@ -137,6 +202,9 @@ union virtio_rtc_req_requestq { · 1 unmodified line
137 struct virtio_rtc_req_cfg cfg;202 struct virtio_rtc_req_cfg cfg;
138 struct virtio_rtc_req_clock_cap clock_cap;203 struct virtio_rtc_req_clock_cap clock_cap;
139 struct virtio_rtc_req_cross_cap cross_cap;204 struct virtio_rtc_req_cross_cap cross_cap;
205 struct virtio_rtc_req_read_alarm read_alarm;
206 struct virtio_rtc_req_set_alarm set_alarm;
207 struct virtio_rtc_req_set_alarm_enabled set_alarm_enabled;
140};208};
141 209
142/** Union of response types for requestq */210/** Union of response types for requestq */
@@ -146,6 +214,24 @@ union virtio_rtc_resp_requestq { · 3 unmodified lines
146 struct virtio_rtc_resp_cfg cfg;214 struct virtio_rtc_resp_cfg cfg;
147 struct virtio_rtc_resp_clock_cap clock_cap;215 struct virtio_rtc_resp_clock_cap clock_cap;
148 struct virtio_rtc_resp_cross_cap cross_cap;216 struct virtio_rtc_resp_cross_cap cross_cap;
217 struct virtio_rtc_resp_read_alarm read_alarm;
218 struct virtio_rtc_resp_set_alarm set_alarm;
219 struct virtio_rtc_resp_set_alarm_enabled set_alarm_enabled;
220};
221
222/* alarmq notifications */
223
224/* VIRTIO_RTC_NOTIF_ALARM notification */
225
226struct virtio_rtc_notif_alarm {
227 struct virtio_rtc_notif_head head;
228 __le16 clock_id;
229 __u8 reserved[6];
230};
231
232/** Union of notification types for alarmq */
233union virtio_rtc_notif_alarmq {
234 struct virtio_rtc_notif_alarm alarm;
149};235};
150 236
151#endif /* _LINUX_VIRTIO_RTC_H */237#endif /* _LINUX_VIRTIO_RTC_H */