anolis: sw64: add set time support for hypervisor based rtc

ANBZ: #4688

Calculate the offset between target time and current time, then
add it to current time in read_time method. with this support,
writable requirements of rtc clock of guest os can be met.

Signed-off-by: Du Yilong <duyilong@wxiat.com>
Reviewed-by: He Sheng <hesheng@wxiat.com>
Signed-off-by: Gu Zitao <guzitao@wxiat.com>
Reviewed-by: Gu Mi <gumi@linux.alibaba.com>
Reviewed-by: Guixin Liu <kanie@linux.alibaba.com>
Link: https://gitee.com/anolis/cloud-kernel/pulls/1695
This commit is contained in:
Du Yilong 2022-02-25 12:21:15 +08:00 committed by 小龙
parent 81cba38b94
commit 43d2ea95ae
1 changed files with 23 additions and 1 deletions

View File

@ -14,18 +14,40 @@
#include <linux/platform_device.h>
#define RTC_IO_ADDR (0x804910000000ULL)
unsigned long vtime_old, vtime_new;
static int sw64_virt_read_time(struct device *dev, struct rtc_time *tm)
{
unsigned long *ioaddr;
unsigned long vtime_now;
long vtime_offset;
ioaddr = ioremap(RTC_IO_ADDR, sizeof(long));
rtc_time64_to_tm(*ioaddr, tm);
if (!vtime_new) {
rtc_time64_to_tm(*ioaddr, tm);
} else {
vtime_now = *ioaddr;
vtime_offset = vtime_new - vtime_old;
vtime_now += vtime_offset;
rtc_time64_to_tm(vtime_now, tm);
}
return 0;
}
static int sw64_virt_set_time(struct device *dev, struct rtc_time *tm)
{
unsigned long *ioaddr;
ioaddr = ioremap(RTC_IO_ADDR, sizeof(long));
vtime_old = *ioaddr;
vtime_new = rtc_tm_to_time64(tm);
return 0;
}
static const struct rtc_class_ops rtc_sw64_virt_ops = {
.read_time = sw64_virt_read_time,
.set_time = sw64_virt_set_time,
};
static int __init rtc_sw64_virt_probe(struct platform_device *pdev)