]> www.infradead.org Git - users/dwmw2/vmclock.git/commitdiff
Update from upstream driver (struct closer to virtio-rtc)
authorDavid Woodhouse <dwmw@amazon.co.uk>
Mon, 1 Jul 2024 13:34:12 +0000 (13:34 +0000)
committerDavid Woodhouse <dwmw@amazon.co.uk>
Mon, 1 Jul 2024 13:35:30 +0000 (13:35 +0000)
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
ptp_vmclock.c
vmclock-abi.h

index 687ecb8ed87c21284aaefee7f1d9017a2421f1b2..a759a38a46ed43d5d1f2b1de08a12c9a86ad2ef0 100644 (file)
@@ -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:
index 3f6473c3d9ec172e08eaf62d9b49a04e697690a3..4172ec31dcad478538d7b72b3de0e74eb84f4258 100644 (file)
@@ -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;