Index: sys/boot/efi/include/efilib.h =================================================================== --- sys/boot/efi/include/efilib.h +++ sys/boot/efi/include/efilib.h @@ -55,6 +55,9 @@ int efi_status_to_errno(EFI_STATUS); +void efi_time_init(void); +void efi_time_fini(void); + EFI_STATUS main(int argc, CHAR16 *argv[]); void exit(EFI_STATUS status); void delay(int usecs); Index: sys/boot/efi/libefi/Makefile =================================================================== --- sys/boot/efi/libefi/Makefile +++ sys/boot/efi/libefi/Makefile @@ -5,7 +5,13 @@ WARNS?= 2 SRCS= delay.c devpath.c efi_console.c efinet.c efipart.c env.c errno.c \ - handles.c libefi.c time.c + handles.c libefi.c + +.if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386" +SRCS+= time.c +.elif ${MACHINE_CPUARCH} == "aarch64" || ${MACHINE_CPUARCH} == "arm" +SRCS+= time_event.c +.endif # We implement a slightly non-standard %S in that it always takes a # CHAR16 that's common in UEFI-land instead of a wchar_t. This only Index: sys/boot/efi/libefi/time.c =================================================================== --- sys/boot/efi/libefi/time.c +++ sys/boot/efi/libefi/time.c @@ -58,6 +58,16 @@ #define SECSPERHOUR ( 60*60 ) #define SECSPERDAY (24 * SECSPERHOUR) +void +efi_time_init(void) +{ +} + +void +efi_time_fini(void) +{ +} + static time_t efi_time(EFI_TIME *ETime) { Index: sys/boot/efi/libefi/time_event.c =================================================================== --- sys/boot/efi/libefi/time_event.c +++ sys/boot/efi/libefi/time_event.c @@ -1,6 +1,5 @@ /*- - * Copyright (c) 2000 Doug Rabson - * Copyright (c) 2006 Marcel Moolenaar + * Copyright (c) 2016 Andrew Turner * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -23,38 +22,61 @@ * 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. - * - * $FreeBSD$ */ -#include +#include +__FBSDID("$FreeBSD$"); + +#include +#include + +#include +#include + +static EFI_EVENT time_event; +static uint64_t curtime; + +static void +time_update(EFI_EVENT event, void *context) +{ + + curtime += 10; +} + +void +efi_time_init(void) +{ -extern EFI_HANDLE IH; -extern EFI_SYSTEM_TABLE *ST; -extern EFI_BOOT_SERVICES *BS; -extern EFI_RUNTIME_SERVICES *RS; + /* Create a timer event */ + BS->CreateEvent(EVT_TIMER | EVT_NOTIFY_SIGNAL, TPL_CALLBACK, + time_update, 0, &time_event); + /* Use a 10ms timer */ + BS->SetTimer(time_event, TimerPeriodic, 100000); +} -extern struct devsw efipart_dev; -extern struct devsw efinet_dev; -extern struct netif_driver efinetif; +void +efi_time_fini(void) +{ -void *efi_get_table(EFI_GUID *tbl); + /* Cancel the timer */ + BS->SetTimer(time_event, TimerCancel, 0); + BS->CloseEvent(time_event); +} -int efi_register_handles(struct devsw *, EFI_HANDLE *, EFI_HANDLE *, int); -EFI_HANDLE efi_find_handle(struct devsw *, int); -int efi_handle_lookup(EFI_HANDLE, struct devsw **, int *, uint64_t *); -int efi_handle_update_dev(EFI_HANDLE, struct devsw *, int, uint64_t); +time_t +time(time_t *tloc) +{ + time_t t; -EFI_DEVICE_PATH *efi_lookup_image_devpath(EFI_HANDLE); -EFI_DEVICE_PATH *efi_lookup_devpath(EFI_HANDLE); -EFI_HANDLE efi_devpath_handle(EFI_DEVICE_PATH *); -EFI_DEVICE_PATH *efi_devpath_last_node(EFI_DEVICE_PATH *); -EFI_DEVICE_PATH *efi_devpath_trim(EFI_DEVICE_PATH *); -CHAR16 *efi_devpath_name(EFI_DEVICE_PATH *); -void efi_free_devpath_name(CHAR16 *); + t = curtime / 1000; + if (tloc != NULL) + *tloc = t; -int efi_status_to_errno(EFI_STATUS); + return (t); +} -EFI_STATUS main(int argc, CHAR16 *argv[]); -void exit(EFI_STATUS status); -void delay(int usecs); +time_t +getsecs() +{ + return time(0); +} Index: sys/boot/efi/loader/arch/amd64/elf64_freebsd.c =================================================================== --- sys/boot/efi/loader/arch/amd64/elf64_freebsd.c +++ sys/boot/efi/loader/arch/amd64/elf64_freebsd.c @@ -186,9 +186,12 @@ printf("Start @ 0x%lx ...\n", ehdr->e_entry); + efi_time_fini(); err = bi_load(fp->f_args, &modulep, &kernend); - if (err != 0) + if (err != 0) { + efi_time_init(); return(err); + } dev_cleanup(); Index: sys/boot/efi/loader/arch/arm/exec.c =================================================================== --- sys/boot/efi/loader/arch/arm/exec.c +++ sys/boot/efi/loader/arch/arm/exec.c @@ -73,8 +73,11 @@ e = (Elf_Ehdr *)&fmp->md_data; - if ((error = bi_load(fp->f_args, &modulep, &kernend)) != 0) + efi_time_fini(); + if ((error = bi_load(fp->f_args, &modulep, &kernend)) != 0) { + efi_time_init(); return (error); + } entry = efi_translate(e->e_entry); printf("Kernel entry at 0x%x...\n", (unsigned)entry); Index: sys/boot/efi/loader/arch/arm64/exec.c =================================================================== --- sys/boot/efi/loader/arch/arm64/exec.c +++ sys/boot/efi/loader/arch/arm64/exec.c @@ -113,9 +113,12 @@ ehdr = (Elf_Ehdr *)&(md->md_data); entry = efi_translate(ehdr->e_entry); + efi_time_fini(); err = bi_load(fp->f_args, &modulep, &kernendp); - if (err != 0) + if (err != 0) { + efi_time_init(); return (err); + } dev_cleanup(); Index: sys/boot/efi/loader/arch/i386/elf32_freebsd.c =================================================================== --- sys/boot/efi/loader/arch/i386/elf32_freebsd.c +++ sys/boot/efi/loader/arch/i386/elf32_freebsd.c @@ -71,9 +71,12 @@ return(EFTYPE); ehdr = (Elf_Ehdr *)&(md->md_data); + efi_time_fini(); err = bi_load(fp->f_args, &boothowto, &bootdev, &bootinfop, &modulep, &kernend); - if (err != 0) + if (err != 0) { + efi_time_init(); return(err); + } entry = ehdr->e_entry & 0xffffff; printf("Start @ 0x%lx ...\n", entry); Index: sys/boot/efi/loader/main.c =================================================================== --- sys/boot/efi/loader/main.c +++ sys/boot/efi/loader/main.c @@ -246,6 +246,9 @@ archsw.arch_zfs_probe = efi_zfs_probe; #endif + /* Init the time source */ + efi_time_init(); + has_kbd = has_keyboard(); /*