-/* $OpenBSD: efi_machdep.c,v 1.5 2023/01/14 12:11:10 kettenis Exp $ */
+/* $OpenBSD: efi_machdep.c,v 1.6 2023/04/30 17:24:24 kettenis Exp $ */
/*
* Copyright (c) 2022 Mark Kettenis <kettenis@openbsd.org>
};
void efi_map_runtime(struct efi_softc *);
-int efi_gettime(struct todr_chip_handle *, struct timeval *);
-int efi_settime(struct todr_chip_handle *, struct timeval *);
label_t efi_jmpbuf;
uint64_t system_table;
bus_space_handle_t memh;
EFI_SYSTEM_TABLE *st;
- EFI_TIME time;
- EFI_STATUS status;
uint16_t major, minor;
int i;
printf(" rev 0x%x\n", st->FirmwareRevision);
}
efi_leave(sc);
-
- if (efi_enter_check(sc))
- return;
- status = sc->sc_rs->GetTime(&time, NULL);
- efi_leave(sc);
- if (status != EFI_SUCCESS)
- return;
-
- /*
- * EDK II implementations provide an implementation of
- * GetTime() that returns a fixed compiled-in time on hardware
- * without a (supported) RTC. So only use this interface as a
- * last resort.
- */
- sc->sc_todr.cookie = sc;
- sc->sc_todr.todr_gettime = efi_gettime;
- sc->sc_todr.todr_settime = efi_settime;
- sc->sc_todr.todr_quality = -1000;
- todr_attach(&sc->sc_todr);
}
void
lcr3(sc->sc_cr3);
intr_restore(sc->sc_psw);
}
-
-int
-efi_gettime(struct todr_chip_handle *handle, struct timeval *tv)
-{
- struct efi_softc *sc = handle->cookie;
- struct clock_ymdhms dt;
- EFI_TIME time;
- EFI_STATUS status;
-
- if (efi_enter_check(sc))
- return EFAULT;
- status = sc->sc_rs->GetTime(&time, NULL);
- efi_leave(sc);
- if (status != EFI_SUCCESS)
- return EIO;
-
- dt.dt_year = time.Year;
- dt.dt_mon = time.Month;
- dt.dt_day = time.Day;
- dt.dt_hour = time.Hour;
- dt.dt_min = time.Minute;
- dt.dt_sec = time.Second;
-
- if (dt.dt_sec > 59 || dt.dt_min > 59 || dt.dt_hour > 23 ||
- dt.dt_day > 31 || dt.dt_day == 0 ||
- dt.dt_mon > 12 || dt.dt_mon == 0 ||
- dt.dt_year < POSIX_BASE_YEAR)
- return EINVAL;
-
- tv->tv_sec = clock_ymdhms_to_secs(&dt);
- tv->tv_usec = 0;
- return 0;
-}
-
-int
-efi_settime(struct todr_chip_handle *handle, struct timeval *tv)
-{
- struct efi_softc *sc = handle->cookie;
- struct clock_ymdhms dt;
- EFI_TIME time;
- EFI_STATUS status;
-
- clock_secs_to_ymdhms(tv->tv_sec, &dt);
-
- time.Year = dt.dt_year;
- time.Month = dt.dt_mon;
- time.Day = dt.dt_day;
- time.Hour = dt.dt_hour;
- time.Minute = dt.dt_min;
- time.Second = dt.dt_sec;
- time.Nanosecond = 0;
- time.TimeZone = 0;
- time.Daylight = 0;
-
- if (efi_enter_check(sc))
- return EFAULT;
- status = sc->sc_rs->SetTime(&time);
- efi_leave(sc);
- if (status != EFI_SUCCESS)
- return EIO;
- return 0;
-}