DM: refine cleanup functionality of virtual RTC

The patch includes:
1. vrtc_cleanup -> vrtc_deinit to align with other devices
2. delete timer created in vrtc_init
3. make call to vrtc_deinit in cleanup path

Signed-off-by: Yin Fengwei <fengwei.yin@intel.com>
Acked-by: Eddie Dong <Eddie.dong@intel.com>
This commit is contained in:
Yin Fengwei 2018-03-30 14:46:35 +08:00 committed by Jack Ren
parent cf9b9f6ba0
commit 583025fb39
4 changed files with 28 additions and 2 deletions

View File

@ -543,6 +543,7 @@ do_close_post(struct vmctx *ctx)
pci_irq_deinit(ctx);
deinit_pci(ctx);
atkbdc_deinit(ctx);
vrtc_deinit(ctx);
vm_destroy(ctx);
vm_close(ctx);
}

View File

@ -593,6 +593,12 @@ vrtc_create_timer(struct vrtc *vrtc, time_t sec, time_t nsec, void (*cb)())
return timerid;
}
static void
vrtc_delete_timer(timer_t timerid)
{
timer_delete(timerid);
}
static int
vrtc_time_update(struct vrtc *vrtc, time_t newtime, time_t newbase)
{
@ -1103,6 +1109,7 @@ vrtc_init(struct vmctx *ctx, int local_time)
assert(vrtc != NULL);
memset(vrtc, 0, sizeof(struct vrtc));
vrtc->vm = ctx;
ctx->vrtc = vrtc;
pthread_mutex_init(&vrtc->mtx, NULL);
@ -1157,7 +1164,24 @@ vrtc_init(struct vmctx *ctx, int local_time)
}
void
vrtc_cleanup(struct vrtc *vrtc)
vrtc_deinit(struct vmctx *ctx)
{
struct vrtc *vrtc = ctx->vrtc;
struct inout_port iop;
memset(&iop, 0, sizeof(struct inout_port));
iop.name = "rtc";
iop.port = IO_RTC;
iop.size = 1;
unregister_inout(&iop);
memset(&iop, 0, sizeof(struct inout_port));
iop.name = "rtc";
iop.port = IO_RTC + 1;
iop.size = 1;
unregister_inout(&iop);
vrtc_delete_timer(vrtc->update_timer_id);
free(vrtc);
ctx->vrtc = NULL;
}

View File

@ -37,7 +37,7 @@ struct vrtc;
struct vmctx;
struct vrtc *vrtc_init(struct vmctx *ctx, int local_time);
void vrtc_cleanup(struct vrtc *vrtc);
void vrtc_deinit(struct vmctx *ctx);
void vrtc_reset(struct vrtc *vrtc);
time_t vrtc_get_time(struct vrtc *vrtc);
int vrtc_set_time(struct vrtc *vrtc, time_t secs);

View File

@ -59,6 +59,7 @@ struct vmctx {
/* fields to track virtual devices */
struct atkbdc_base *atkbdc_base;
struct vrtc *vrtc;
};
/*