Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F158863359
D14565.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D14565.id.diff
View Options
Index: sys/dev/efidev/efirtc.c
===================================================================
--- sys/dev/efidev/efirtc.c
+++ sys/dev/efidev/efirtc.c
@@ -41,21 +41,20 @@
#include "clock_if.h"
+static bool efirtc_zeroes_subseconds;
+static struct timespec efirtc_resadj;
+
+static const u_int us_per_s = 1000000;
+static const u_int ns_per_s = 1000000000;
+static const u_int ns_per_us = 1000;
+
static void
efirtc_identify(driver_t *driver, device_t parent)
{
- struct efi_tm tm;
- int error;
- /*
- * Check if we can read the time. This will stop us attaching when
- * there is no EFI Runtime support, or the gettime function is
- * unimplemented, e.g. on some builds of U-Boot.
- */
- error = efi_get_time(&tm);
- if (error != 0)
+ /* Don't add the driver unless we have working runtime services. */
+ if (efi_rt_ok() != 0)
return;
-
if (device_find_child(parent, "efirtc", -1) != NULL)
return;
if (BUS_ADD_CHILD(parent, 0, "efirtc", -1) == NULL)
@@ -65,16 +64,59 @@
static int
efirtc_probe(device_t dev)
{
+ struct efi_tm tm;
+ int error;
- device_quiet(dev);
- return (0);
+ /*
+ * Check whether we can read the time. This will stop us from attaching
+ * when there is EFI Runtime support but the gettime function is
+ * unimplemented, e.g. on some builds of U-Boot.
+ */
+ if ((error = efi_get_time(&tm)) != 0) {
+ if (bootverbose)
+ device_printf(dev, "cannot read EFI realtime clock\n");
+ return (error);
+ }
+ device_set_desc(dev, "EFI Realtime Clock");
+ return (BUS_PROBE_DEFAULT);
}
static int
efirtc_attach(device_t dev)
{
+ struct efi_tmcap tmcap;
+ long res;
+ int error;
+
+ bzero(&tmcap, sizeof(tmcap));
+ if ((error = efi_get_time_capabilities(&tmcap)) != 0) {
+ if (bootverbose)
+ device_printf(dev, "cannot get EFI time capabilities");
+ return (error);
+ }
+
+ /* Translate resolution in Hz to tick length in usec. */
+ if (tmcap.tc_res == 0)
+ res = us_per_s; /* 0 is insane, assume 1 Hz. */
+ else if (tmcap.tc_res > us_per_s)
+ res = 1; /* 1us is the best we can represent */
+ else
+ res = us_per_s / tmcap.tc_res;
+
+ /* Clock rounding adjustment is 1/2 of resolution, in nsec. */
+ efirtc_resadj.tv_nsec = (res * ns_per_us) / 2;
+
+ /* Does the clock zero the subseconds when time is set? */
+ efirtc_zeroes_subseconds = tmcap.tc_stz;
+
+ /*
+ * Register. If the clock zeroes out the subseconds when it's set,
+ * schedule the SetTime calls to happen just before top-of-second.
+ */
+ clock_register_flags(dev, res, CLOCKF_SETTIME_NO_ADJ);
+ if (efirtc_zeroes_subseconds)
+ clock_schedule(dev, ns_per_s - ns_per_us);
- clock_register(dev, 1000000);
return (0);
}
@@ -105,6 +147,7 @@
ct.year = tm.tm_year;
ct.nsec = tm.tm_nsec;
+ clock_dbgprint_ct(dev, CLOCK_DBG_READ, &ct);
return (clock_ct_to_ts(&ct, ts));
}
@@ -114,7 +157,17 @@
struct clocktime ct;
struct efi_tm tm;
+ /*
+ * We request a timespec with no resolution-adjustment so that we can
+ * apply it ourselves based on whether or not the clock zeroes the
+ * sub-second part of the time when setting the time.
+ */
+ ts->tv_sec -= utc_offset();
+ if (!efirtc_zeroes_subseconds)
+ timespecadd(ts, &efirtc_resadj);
+
clock_ts_to_ct(ts, &ct);
+ clock_dbgprint_ct(dev, CLOCK_DBG_WRITE, &ct);
bzero(&tm, sizeof(tm));
tm.tm_sec = ct.sec;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Jun 8, 12:18 AM (19 h, 41 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
33804031
Default Alt Text
D14565.id.diff (3 KB)
Attached To
Mode
D14565: Use EFI RTC capablities info when registering, add bootverbose diagnostics.
Attached
Detach File
Event Timeline
Log In to Comment