Re: svn commit: r326066 - in head/sys: arm64/conf conf dev/efidev modules/efirt

2017-11-21 Thread Ian Lepore
On Tue, 2017-11-21 at 17:23 +, Andrew Turner wrote:
> Author: andrew
> Date: Tue Nov 21 17:23:16 2017
> New Revision: 326066
> URL: https://svnweb.freebsd.org/changeset/base/326066
> 
> Log:
>   Add a driver for the EFI RTC. This uses the EFI Runtime Services to query
>   the system time.
>   
>   As we seem to only read this time on boot, and this is the only source of
>   time on many arm64 machines we need to enable this by default there. As
>   this is not always the case with U-Boot firmware, or when we have been
>   booted from a non-UEFI environment we only enable the device driver when
>   the Runtime Services are present and reading the time doesn't result in an
>   error.

If the efi runtime returns an error for the case where time is invalid
because the clock oscillator is stopped, this "don't attach on error"
logic will result in the clock never working, because it is typically
the act of writing a valid time to the device that starts the
oscillator and clears the error condition.

It might make sense to always attach the device, but only report an
error in clock_settime() once.

-- Ian
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r326066 - in head/sys: arm64/conf conf dev/efidev modules/efirt

2017-11-21 Thread Andrew Turner
Author: andrew
Date: Tue Nov 21 17:23:16 2017
New Revision: 326066
URL: https://svnweb.freebsd.org/changeset/base/326066

Log:
  Add a driver for the EFI RTC. This uses the EFI Runtime Services to query
  the system time.
  
  As we seem to only read this time on boot, and this is the only source of
  time on many arm64 machines we need to enable this by default there. As
  this is not always the case with U-Boot firmware, or when we have been
  booted from a non-UEFI environment we only enable the device driver when
  the Runtime Services are present and reading the time doesn't result in an
  error.
  
  PR:   212185
  Reviewed by:  imp, kib
  Tested by:emaste
  Relnotes: yes
  Sponsored by: DARPA, AFRL
  Differential Revision:https://reviews.freebsd.org/D12650

Added:
  head/sys/dev/efidev/efirtc.c   (contents, props changed)
Modified:
  head/sys/arm64/conf/GENERIC
  head/sys/conf/files
  head/sys/modules/efirt/Makefile

Modified: head/sys/arm64/conf/GENERIC
==
--- head/sys/arm64/conf/GENERIC Tue Nov 21 16:38:30 2017(r326065)
+++ head/sys/arm64/conf/GENERIC Tue Nov 21 17:23:16 2017(r326066)
@@ -226,6 +226,7 @@ device  md  # Memory "disks"
 device gif # IPv6 and IPv4 tunneling
 device firmware# firmware assist module
 device psci# Support for ARM PSCI
+optionsEFIRT   # EFI Runtime Services
 
 # EXT_RESOURCES pseudo devices
 optionsEXT_RESOURCES

Modified: head/sys/conf/files
==
--- head/sys/conf/files Tue Nov 21 16:38:30 2017(r326065)
+++ head/sys/conf/files Tue Nov 21 17:23:16 2017(r326066)
@@ -1615,6 +1615,7 @@ dev/ed/if_ed_pccard.c optional ed pccard
 dev/ed/if_ed_pci.c optional ed pci
 dev/efidev/efidev.coptional efirt
 dev/efidev/efirt.c optional efirt
+dev/efidev/efirtc.coptional efirt
 dev/e1000/if_em.c  optional em \
compile-with "${NORMAL_C} -I$S/dev/e1000"
 dev/e1000/em_txrx.coptional em \

Added: head/sys/dev/efidev/efirtc.c
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/sys/dev/efidev/efirtc.cTue Nov 21 17:23:16 2017
(r326066)
@@ -0,0 +1,151 @@
+/*-
+ * Copyright (c) 2017 Andrew Turner
+ * All rights reserved.
+ *
+ * This software was developed by SRI International and the University of
+ * Cambridge Computer Laboratory under DARPA/AFRL contract FA8750-10-C-0237
+ * ("CTSRD"), as part of the DARPA CRASH research programme.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include 
+__FBSDID("$FreeBSD$");
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "clock_if.h"
+
+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();
+   if (error != 0)
+   return;
+
+   if (device_find_child(parent, "efirtc", -1) != NULL)
+   return;
+   if (BUS_ADD_CHILD(parent, 0, "efirtc", -1) == NULL)
+   device_printf(parent, "add child failed\n");
+}
+
+static int
+efirtc_probe(device_t dev)
+{
+
+   device_quiet(dev);
+   return (0);
+}
+