#include <linux/device.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <uapi/linux/kvm_para.h>
#include <asm/kvm_para.h>
#include <asm/kvmclock.h>
#include <uapi/asm/kvm_para.h>
#include <linux/ptp_clock_kernel.h>
struct ptp_clock *ptp_clock;
struct ptp_clock_info caps;
DEFINE_SPINLOCK(kvm_ptp_lock);
static struct pvclock_vsyscall_time_info *hv_clock;
static struct kvm_clock_pairing clock_pair;
static phys_addr_t clock_pair_gpa;
static int ptp_kvm_get_time_fn(ktime_t *device_time,
struct system_counterval_t *system_counter,
struct pvclock_vcpu_time_info *src;
spin_lock(&kvm_ptp_lock);
preempt_disable_notrace();
cpu = smp_processor_id();
src = &hv_clock[cpu].pvti;
version = pvclock_read_begin(src);
ret = kvm_hypercall2(KVM_HC_CLOCK_PAIRING,
KVM_CLOCK_PAIRING_WALLCLOCK);
pr_err_ratelimited("clock pairing hypercall ret %lu\n", ret);
spin_unlock(&kvm_ptp_lock);
preempt_enable_notrace();
tspec.tv_sec = clock_pair.sec;
tspec.tv_nsec = clock_pair.nsec;
ret = __pvclock_read_cycles(src, clock_pair.tsc);
} while (pvclock_read_retry(src, version));
preempt_enable_notrace();
system_counter->cycles = ret;
system_counter->cs = &kvm_clock;
*device_time = timespec64_to_ktime(tspec);
spin_unlock(&kvm_ptp_lock);