dm: vm_event: add support for RTC change event

When a guest OS performs an RTC change action, we wish this event be
captured by developers, and then they can decide what to do with it.
(e.g., whether to change physical RTC)

There are some facts that makes RTC change event a bit complicated:
- There are 7 RTC date/time regs (year, month…). They can only be
  updated one by one.
- RTC time is not reliable before date/time update is finished.
- Guests can update RTC date/time regs in any order.
- Guests may update RTC date/time regs during either RTC halted or not
  halted.

A single date/time update event is not reliable. We have to wait for
the guest to finish the update process. So the DM's event handler
sets up a timer, and wait for some time (1 second). If no more change
happens befor the timer expires, we can conclude that the RTC
change has been done. Then the rtc change event is emitted.

This logic of event handler can be used to process HV vrtc time change
event too.

Tracked-On: #8547
Signed-off-by: Wu Zhou <wu.zhou@intel.com>
Reviewed-by: Jian Jun Chen <jian.jun.chen@intel.com>
This commit is contained in:
Wu Zhou
2023-08-08 16:48:38 +08:00
committed by acrnsi-robot
parent 9197529da9
commit 262a48f346
4 changed files with 127 additions and 6 deletions

View File

@@ -842,6 +842,16 @@ struct vm_event {
uint8_t event_data[VM_EVENT_DATA_LEN];
};
struct rtc_change_event_data {
int64_t last_time; /* time(in secs) of the RTC defore been set */
int64_t delta_time; /* delta of time(in secs) the RTC has been changed */
};
/* DM vrtc's reference time is besed on sys time, while the HV vrtc is based on pRTC.
* When the delta time is sent to users, they need to know what it is relative to.
*/
#define RTC_CHG_RELATIVE_PHYSICAL_RTC 0
#define RTC_CHG_RELATIVE_SERVICE_VM_SYS_TIME 1
/**
* @}
*/