1 /*
2  * Copyright (C) 2024 Intel Corporation.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef VRTC_H
8 #define VRTC_H
9 
10 /**
11  * @defgroup vp-dm_vperipheral vp-dm.vperipheral
12  * @ingroup vp-dm
13  * @brief Implementation of virtual peripheral devices in hypervisor.
14  *
15  * This module implements the virtualization of all peripheral devices in hypervisor. The virtual device initial
16  * function is usually called by the VM initialization function and registers their port IO and memory IO access
17  * functions. So when a guest VM accesses its peripheral device by port IO or memory IO, it would cause VM exit and then
18  * call their registered functions.
19  * @{
20  */
21 
22 /**
23  * @file
24  * @brief Definitions for the virtual RTC device.
25  *
26  * This file defines types and data structure for the virtual RTC device.
27  */
28 
29 typedef int32_t time_t;
30 
31 /* Register layout of the RTC */
32 struct rtcdev {
33 	uint8_t	sec;
34 	uint8_t	alarm_sec;
35 	uint8_t	min;
36 	uint8_t	alarm_min;
37 	uint8_t	hour;
38 	uint8_t	alarm_hour;
39 	uint8_t	day_of_week;
40 	uint8_t	day_of_month;
41 	uint8_t	month;
42 	uint8_t	year;
43 	uint8_t	reg_a;
44 	uint8_t	reg_b;
45 	uint8_t	reg_c;
46 	uint8_t	reg_d;
47 	uint8_t	res[36];
48 	uint8_t	century;
49 };
50 
51 /**
52  * @brief Data structure to illustrate a virtual RTC device.
53  *
54  * This structure contains the information of a virtual RTC device.
55  *
56  * @consistency self.vm->vrtc == self
57  * @alignment N/A
58  *
59  * @remark N/A
60  */
61 struct acrn_vrtc {
62 	struct acrn_vm	*vm; /**< Pointer to the VM that owns the virtual RTC device. */
63 	/**
64 	 * @brief The RTC register to read or write.
65 	 *
66 	 * To access RTC registers, the guest writes the register index to the RTC address port and then reads/writes
67 	 * the register value from/to the RTC data port. This field is used to store the register index.
68 	 */
69 	uint32_t	addr;
70 	time_t		base_rtctime; /**< Base time calculated from physical RTC register. */
71 	time_t		offset_rtctime; /**< RTC offset against base time. */
72 	time_t		last_rtctime; /**< Last RTC time, to keep monotonicity. */
73 	uint64_t	base_tsc; /**< Base TSC value. */
74 	struct rtcdev	rtcdev; /**< Register layout of RTC. */
75 };
76 
77 #endif /* VRTC_H */
78 
79 /**
80  * @}
81  */