From: David Woodhouse Date: Mon, 1 Jul 2024 13:34:12 +0000 (+0000) Subject: Update from upstream driver (struct closer to virtio-rtc) X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=feb83d07650fd52d9e256ca84fc3b1a9e654c3a8;p=users%2Fdwmw2%2Fvmclock.git Update from upstream driver (struct closer to virtio-rtc) Signed-off-by: David Woodhouse --- diff --git a/ptp_vmclock.c b/ptp_vmclock.c index 687ecb8..a759a38 100644 --- a/ptp_vmclock.c +++ b/ptp_vmclock.c @@ -513,14 +513,16 @@ static int vmclock_probe(struct platform_device *pdev) } /* Only UTC, or TAI with offset */ - if (!tai_adjust(st->clk, NULL)) + if (!tai_adjust(st->clk, NULL)) { + dev_info(dev, "vmclock does not provide unambiguous UTC\n"); st->cs_id = CSID_GENERIC; + } if (st->cs_id) { st->sys_cs_id = st->cs_id; st->ptp_clock_info = ptp_vmclock_info; - strncpy(st->ptp_clock_info.name, st->name, sizeof(st->ptp_clock_info.name)); + strscpy(st->ptp_clock_info.name, st->name, sizeof(st->ptp_clock_info.name)); st->ptp_clock = ptp_clock_register(&st->ptp_clock_info, dev); if (IS_ERR(st->ptp_clock)) { @@ -529,8 +531,18 @@ static int vmclock_probe(struct platform_device *pdev) vmclock_remove(pdev); goto out; } + } else if (!st->miscdev.minor) { + /* Neither miscdev nor PTP registered */ + dev_info(dev, "vmclock: Neither miscdev nor PTP available; not registering\n"); + ret = -ENODEV; + goto out; } + dev_info(dev, "%s: registered %s%s%s\n", st->name, + st->miscdev.minor ? "miscdev" : "", + (st->miscdev.minor && st->ptp_clock) ? ", " : "", + st->ptp_clock ? "PTP" : ""); + dev_set_drvdata(dev, st); out: diff --git a/vmclock-abi.h b/vmclock-abi.h index 3f6473c..4172ec3 100644 --- a/vmclock-abi.h +++ b/vmclock-abi.h @@ -94,11 +94,11 @@ struct vmclock_abi { #define VMCLOCK_STATUS_FREERUNNING 3 #define VMCLOCK_STATUS_UNRELIABLE 4 - uint8_t counter_id; -#define VMCLOCK_COUNTER_INVALID 0 + uint8_t counter_id; /* VIRTIO_RTC_COUNTER_xxx */ +#define VMCLOCK_COUNTER_ARM_VCNT 0 #define VMCLOCK_COUNTER_X86_TSC 1 -#define VMCLOCK_COUNTER_ARM_VCNT 2 -#define VMCLOCK_COUNTER_X86_ART 3 +#define VMCLOCK_COUNTER_X86_ART 2 +#define VMCLOCK_COUNTER_INVALID 0xff /* * By providing the offset from UTC to TAI, the guest can know both @@ -116,30 +116,32 @@ struct vmclock_abi { * it may do so in a fashion consistent with the other systems * in the nearby environment. */ - uint8_t leap_second_smearing_hint; + uint8_t leap_second_smearing_hint; /* Not quite VIRTIO_RTC_SUBTYPE_xxx */ /* Provide true UTC to users, unsmeared. */; #define VMCLOCK_SMEARING_NONE 0 /* * https://aws.amazon.com/blogs/aws/look-before-you-leap-the-coming-leap-second-and-aws/ + * https://developers.google.com/time/smear + * * From noon on the day before to noon on the day after, smear the * clock by a linear 1/86400s per second. */ -#define VMCLOCK_SMEARING_LINEAR_86400 1 +#define VMCLOCK_SMEARING_NOON_LINEAR 2 /* * draft-kuhn-leapsecond-00 * For the 1000s leading up to the leap second, smear the clock by * clock by a linear 1ms per second. */ -#define VMCLOCK_SMEARING_UTC_SLS 2 +#define VMCLOCK_SMEARING_UTC_SLS 4 /* * What time is exposed in the time_sec/time_frac_sec fields? */ - uint8_t time_type; -#define VMCLOCK_TIME_UNKNOWN 0 /* Invalid / no time exposed */ -#define VMCLOCK_TIME_UTC 1 /* Since 1970-01-01 00:00:00z */ -#define VMCLOCK_TIME_TAI 2 /* Since 1970-01-01 00:00:00z */ -#define VMCLOCK_TIME_MONOTONIC 3 /* Since undefined epoch */ + uint8_t time_type; /* VIRTIO_RTC_TYPE_xxx */ +#define VMCLOCK_TIME_UTC 0 /* Since 1970-01-01 00:00:00z */ +#define VMCLOCK_TIME_TAI 1 /* Since 1970-01-01 00:00:00z */ +#define VMCLOCK_TIME_MONOTONIC 2 /* Since undefined epoch */ +#define VMCLOCK_TIME_SMEARED_INVALID 3 /* UTC but with smeared leap seconds */ /* Bit shift for counter_period_frac_sec and its error rate */ uint8_t counter_period_shift;