at master 5.5 kB view raw
1/* SPDX-License-Identifier: ((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) */ 2/* 3 * Copyright (C) 2022-2024 OpenSynergy GmbH 4 * Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved. 5 */ 6 7#ifndef _LINUX_VIRTIO_RTC_H 8#define _LINUX_VIRTIO_RTC_H 9 10#include <linux/types.h> 11 12/* alarm feature */ 13#define VIRTIO_RTC_F_ALARM 0 14 15/* read request message types */ 16 17#define VIRTIO_RTC_REQ_READ 0x0001 18#define VIRTIO_RTC_REQ_READ_CROSS 0x0002 19 20/* control request message types */ 21 22#define VIRTIO_RTC_REQ_CFG 0x1000 23#define VIRTIO_RTC_REQ_CLOCK_CAP 0x1001 24#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 32 33/* Message headers */ 34 35/** common request header */ 36struct virtio_rtc_req_head { 37 __le16 msg_type; 38 __u8 reserved[6]; 39}; 40 41/** common response header */ 42struct virtio_rtc_resp_head { 43#define VIRTIO_RTC_S_OK 0 44#define VIRTIO_RTC_S_EOPNOTSUPP 2 45#define VIRTIO_RTC_S_ENODEV 3 46#define VIRTIO_RTC_S_EINVAL 4 47#define VIRTIO_RTC_S_EIO 5 48 __u8 status; 49 __u8 reserved[7]; 50}; 51 52/** common notification header */ 53struct virtio_rtc_notif_head { 54 __le16 msg_type; 55 __u8 reserved[6]; 56}; 57 58/* read requests */ 59 60/* VIRTIO_RTC_REQ_READ message */ 61 62struct virtio_rtc_req_read { 63 struct virtio_rtc_req_head head; 64 __le16 clock_id; 65 __u8 reserved[6]; 66}; 67 68struct virtio_rtc_resp_read { 69 struct virtio_rtc_resp_head head; 70 __le64 clock_reading; 71}; 72 73/* VIRTIO_RTC_REQ_READ_CROSS message */ 74 75struct virtio_rtc_req_read_cross { 76 struct virtio_rtc_req_head head; 77 __le16 clock_id; 78/* Arm Generic Timer Counter-timer Virtual Count Register (CNTVCT_EL0) */ 79#define VIRTIO_RTC_COUNTER_ARM_VCT 0 80/* x86 Time-Stamp Counter */ 81#define VIRTIO_RTC_COUNTER_X86_TSC 1 82/* Invalid */ 83#define VIRTIO_RTC_COUNTER_INVALID 0xFF 84 __u8 hw_counter; 85 __u8 reserved[5]; 86}; 87 88struct virtio_rtc_resp_read_cross { 89 struct virtio_rtc_resp_head head; 90 __le64 clock_reading; 91 __le64 counter_cycles; 92}; 93 94/* control requests */ 95 96/* VIRTIO_RTC_REQ_CFG message */ 97 98struct virtio_rtc_req_cfg { 99 struct virtio_rtc_req_head head; 100 /* no request params */ 101}; 102 103struct virtio_rtc_resp_cfg { 104 struct virtio_rtc_resp_head head; 105 /** # of clocks -> clock ids < num_clocks are valid */ 106 __le16 num_clocks; 107 __u8 reserved[6]; 108}; 109 110/* VIRTIO_RTC_REQ_CLOCK_CAP message */ 111 112struct virtio_rtc_req_clock_cap { 113 struct virtio_rtc_req_head head; 114 __le16 clock_id; 115 __u8 reserved[6]; 116}; 117 118struct virtio_rtc_resp_clock_cap { 119 struct virtio_rtc_resp_head head; 120#define VIRTIO_RTC_CLOCK_UTC 0 121#define VIRTIO_RTC_CLOCK_TAI 1 122#define VIRTIO_RTC_CLOCK_MONOTONIC 2 123#define VIRTIO_RTC_CLOCK_UTC_SMEARED 3 124#define VIRTIO_RTC_CLOCK_UTC_MAYBE_SMEARED 4 125 __u8 type; 126#define VIRTIO_RTC_SMEAR_UNSPECIFIED 0 127#define VIRTIO_RTC_SMEAR_NOON_LINEAR 1 128#define VIRTIO_RTC_SMEAR_UTC_SLS 2 129 __u8 leap_second_smearing; 130#define VIRTIO_RTC_FLAG_ALARM_CAP (1 << 0) 131 __u8 flags; 132 __u8 reserved[5]; 133}; 134 135/* VIRTIO_RTC_REQ_CROSS_CAP message */ 136 137struct virtio_rtc_req_cross_cap { 138 struct virtio_rtc_req_head head; 139 __le16 clock_id; 140 __u8 hw_counter; 141 __u8 reserved[5]; 142}; 143 144struct virtio_rtc_resp_cross_cap { 145 struct virtio_rtc_resp_head head; 146#define VIRTIO_RTC_FLAG_CROSS_CAP (1 << 0) 147 __u8 flags; 148 __u8 reserved[7]; 149}; 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 198/** Union of request types for requestq */ 199union virtio_rtc_req_requestq { 200 struct virtio_rtc_req_read read; 201 struct virtio_rtc_req_read_cross read_cross; 202 struct virtio_rtc_req_cfg cfg; 203 struct virtio_rtc_req_clock_cap clock_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; 208}; 209 210/** Union of response types for requestq */ 211union virtio_rtc_resp_requestq { 212 struct virtio_rtc_resp_read read; 213 struct virtio_rtc_resp_read_cross read_cross; 214 struct virtio_rtc_resp_cfg cfg; 215 struct virtio_rtc_resp_clock_cap clock_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; 235}; 236 237#endif /* _LINUX_VIRTIO_RTC_H */