Skip to content

Commit eadc921

Browse files
fyin1jren1
authored andcommitted
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>
1 parent 80a9fe5 commit eadc921

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

devicemodel/core/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ do_close_post(struct vmctx *ctx)
543543
pci_irq_deinit(ctx);
544544
deinit_pci(ctx);
545545
atkbdc_deinit(ctx);
546+
vrtc_deinit(ctx);
546547
vm_destroy(ctx);
547548
vm_close(ctx);
548549
}

devicemodel/hw/platform/rtc.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,12 @@ vrtc_create_timer(struct vrtc *vrtc, time_t sec, time_t nsec, void (*cb)())
593593
return timerid;
594594
}
595595

596+
static void
597+
vrtc_delete_timer(timer_t timerid)
598+
{
599+
timer_delete(timerid);
600+
}
601+
596602
static int
597603
vrtc_time_update(struct vrtc *vrtc, time_t newtime, time_t newbase)
598604
{
@@ -1103,6 +1109,7 @@ vrtc_init(struct vmctx *ctx, int local_time)
11031109
assert(vrtc != NULL);
11041110
memset(vrtc, 0, sizeof(struct vrtc));
11051111
vrtc->vm = ctx;
1112+
ctx->vrtc = vrtc;
11061113

11071114
pthread_mutex_init(&vrtc->mtx, NULL);
11081115

@@ -1157,7 +1164,24 @@ vrtc_init(struct vmctx *ctx, int local_time)
11571164
}
11581165

11591166
void
1160-
vrtc_cleanup(struct vrtc *vrtc)
1167+
vrtc_deinit(struct vmctx *ctx)
11611168
{
1169+
struct vrtc *vrtc = ctx->vrtc;
1170+
struct inout_port iop;
1171+
1172+
memset(&iop, 0, sizeof(struct inout_port));
1173+
iop.name = "rtc";
1174+
iop.port = IO_RTC;
1175+
iop.size = 1;
1176+
unregister_inout(&iop);
1177+
1178+
memset(&iop, 0, sizeof(struct inout_port));
1179+
iop.name = "rtc";
1180+
iop.port = IO_RTC + 1;
1181+
iop.size = 1;
1182+
unregister_inout(&iop);
1183+
1184+
vrtc_delete_timer(vrtc->update_timer_id);
11621185
free(vrtc);
1186+
ctx->vrtc = NULL;
11631187
}

devicemodel/include/rtc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ struct vrtc;
3737
struct vmctx;
3838

3939
struct vrtc *vrtc_init(struct vmctx *ctx, int local_time);
40-
void vrtc_cleanup(struct vrtc *vrtc);
40+
void vrtc_deinit(struct vmctx *ctx);
4141
void vrtc_reset(struct vrtc *vrtc);
4242
time_t vrtc_get_time(struct vrtc *vrtc);
4343
int vrtc_set_time(struct vrtc *vrtc, time_t secs);

devicemodel/include/vmmapi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ struct vmctx {
5959

6060
/* fields to track virtual devices */
6161
struct atkbdc_base *atkbdc_base;
62+
struct vrtc *vrtc;
6263
};
6364

6465
/*

0 commit comments

Comments
 (0)