@@ -306,6 +306,43 @@ static void efi_get_time(struct timespec *now)
now->tv_nsec = 0;
}
+static int efi_read_timezone(s16 *timezone)
+{
+ efi_status_t status;
+ efi_time_t eft;
+ efi_time_cap_t cap;
+
+ status = efi.get_time(&eft, &cap);
+
+ if (status != EFI_SUCCESS) {
+ /* should never happen */
+ pr_err("efitime: can't read timezone.\n");
+ return -EINVAL;
+ }
+
+ *timezone = (s16)le16_to_cpu(eft.timezone);
+ return 0;
+}
+
+void __init efi_warp_clock(void)
+{
+ s16 timezone;
+
+ if (!efi_read_timezone(&timezone)) {
+ /* TimeZone value, 2047 or 0 means UTC */
+ if (timezone != 0 && timezone != 2047) {
+ struct timespec adjust;
+
+ persistent_clock_is_local = 1;
+ adjust.tv_sec = timezone * 60;
+ adjust.tv_nsec = 0;
+ timekeeping_inject_offset(&adjust);
+ pr_info("RTC timezone is %d mins behind of UTC.\n", timezone);
+ pr_info("Adjusted system time to UTC.\n");
+ }
+ }
+}
+
/*
* Tell the kernel about the EFI memory map. This might include
* more than the max 128 entries that can fit in the e820 legacy
@@ -715,10 +715,12 @@ extern void efi_memmap_walk (efi_freemem_callback_t callback, void *arg);
extern void efi_gettimeofday (struct timespec *ts);
extern void efi_enter_virtual_mode (void); /* switch EFI to virtual mode, if possible */
#ifdef CONFIG_X86
+extern void efi_warp_clock(void);
extern void efi_late_init(void);
extern void efi_free_boot_services(void);
extern efi_status_t efi_query_variable_store(u32 attributes, unsigned long size);
#else
+static inline void efi_warp_clock(void) {}
static inline void efi_late_init(void) {}
static inline void efi_free_boot_services(void) {}
@@ -570,6 +570,11 @@ asmlinkage void __init start_kernel(void)
hrtimers_init();
softirq_init();
timekeeping_init();
+#ifdef CONFIG_X86_64
+ /* adjust system time by timezone */
+ if (efi_enabled(EFI_RUNTIME_SERVICES))
+ efi_warp_clock();
+#endif
time_init();
sched_clock_postinit();
perf_event_init();
@@ -176,7 +176,7 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
update_vsyscall_tz();
if (firsttime) {
firsttime = 0;
- if (!tv)
+ if (!tv && !persistent_clock_is_local)
warp_clock();
}
}
EFI time services provide the interface to store timezone to BIOS. The timezone value from EFI indicates the offset of RTC time in minutes from UTC. The formula is: Localtime = UTC - TimeZone. This patch add a efI_warp_clock() function to initial process for adjust system time base on timezone value from EFI time services. It will also set persistent_clock_is_local global variable to avoid user space adjust timezone again. This efi warp clock mechanism will triggered on x86_64 EFI machine when timezone value is neither 0 nor 2047(UNSPECIFIED), kernel assume the value of RTC is local time. On the other hand, system just follow the old logic when timezone value from EFI is 0 or 2047, kernel assume the value of RTC is UTC time. About the 2047(EFI_UNSPECIFIED_TIMEZONE) value, it's the default value of UEFI BIOS if there didn't have software set it through EFI interface. We can _NOT_ follow EFI spec to interpret the RTC time as a local time if timezone value is EFI_UNSPECIFIED_TIMEZONE, that's because Linux stored UTC to BIOS on shipped UEFI machines. Signed-off-by: Lee, Chun-Yi <jlee@suse.com> --- arch/x86/platform/efi/efi.c | 37 +++++++++++++++++++++++++++++++++++++ include/linux/efi.h | 2 ++ init/main.c | 5 +++++ kernel/time.c | 2 +- 4 files changed, 45 insertions(+), 1 deletions(-)