hv: vm_event: send RTC change event in hv vRTC

This patch adds support for HV vrtc vm_event.

RTC change event is sent upon each date/time reg write. Those events
will be handled in DM. DM will try to emit an RTC change event(to
Libvirt) based on its strategy. Only support post-launched VMs.

The DM event handler has already implemented the rtc chanage event.
Those events will be processed the same way as vrtc events from DM vrtc.

Tracked-On: #8547
Signed-off-by: Wu Zhou <wu.zhou@intel.com>
Reviewed-by: Junjie Mao <junjie.mao@intel.com>
This commit is contained in:
Wu Zhou 2023-08-02 02:03:43 -07:00 committed by acrnsi-robot
parent 262a48f346
commit ab63fe1a92
1 changed files with 9 additions and 0 deletions

View File

@ -30,6 +30,7 @@
#include <asm/tsc.h> #include <asm/tsc.h>
#include <vrtc.h> #include <vrtc.h>
#include <logmsg.h> #include <logmsg.h>
#include <vm_event.h>
#include "mc146818rtc.h" #include "mc146818rtc.h"
@ -549,6 +550,8 @@ static bool vrtc_write(struct acrn_vcpu *vcpu, uint16_t addr, size_t width,
struct acrn_vrtc *vrtc = &vcpu->vm->vrtc; struct acrn_vrtc *vrtc = &vcpu->vm->vrtc;
struct acrn_vrtc temp_vrtc; struct acrn_vrtc temp_vrtc;
uint8_t mask = 0xFFU; uint8_t mask = 0xFFU;
struct vm_event rtc_chg_event;
struct rtc_change_event_data *edata = (struct rtc_change_event_data *)rtc_chg_event.event_data;
if ((width == 1U) && (addr == CMOS_ADDR_PORT)) { if ((width == 1U) && (addr == CMOS_ADDR_PORT)) {
vrtc->addr = (uint8_t)(value & 0x7FU); vrtc->addr = (uint8_t)(value & 0x7FU);
@ -595,6 +598,12 @@ static bool vrtc_write(struct acrn_vcpu *vcpu, uint16_t addr, size_t width,
vrtc->offset_rtctime += after - current; vrtc->offset_rtctime += after - current;
vrtc->last_rtctime = VRTC_BROKEN_TIME; vrtc->last_rtctime = VRTC_BROKEN_TIME;
spinlock_release(&vrtc_rebase_lock); spinlock_release(&vrtc_rebase_lock);
if (is_postlaunched_vm(vcpu->vm) && vrtc_is_time_register(vrtc->addr)) {
rtc_chg_event.type = VM_EVENT_RTC_CHG;
edata->delta_time = after - current;
edata->last_time = current;
send_vm_event(vcpu->vm, &rtc_chg_event);
}
break; break;
} }
} }