diff --git a/sys/arch/arm/fdt/acpi_fdt.c b/sys/arch/arm/fdt/acpi_fdt.c index 155d850f0ebb..a1ff59a04225 100644 --- a/sys/arch/arm/fdt/acpi_fdt.c +++ b/sys/arch/arm/fdt/acpi_fdt.c @@ -1,4 +1,4 @@ -/* $NetBSD: acpi_fdt.c,v 1.15 2020/09/15 10:33:58 jmcneill Exp $ */ +/* $NetBSD: acpi_fdt.c,v 1.16 2020/10/10 15:34:05 jmcneill Exp $ */ /*- * Copyright (c) 2015-2017 Jared McNeill @@ -30,7 +30,7 @@ #include "opt_efi.h" #include -__KERNEL_RCSID(0, "$NetBSD: acpi_fdt.c,v 1.15 2020/09/15 10:33:58 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: acpi_fdt.c,v 1.16 2020/10/10 15:34:05 jmcneill Exp $"); #include #include @@ -54,7 +54,6 @@ __KERNEL_RCSID(0, "$NetBSD: acpi_fdt.c,v 1.15 2020/09/15 10:33:58 jmcneill Exp $ #ifdef EFI_RUNTIME #include -#include #endif static int acpi_fdt_match(device_t, cfdata_t, void *); @@ -62,22 +61,12 @@ static void acpi_fdt_attach(device_t, device_t, void *); static void acpi_fdt_poweroff(device_t); -#ifdef EFI_RUNTIME -static void acpi_fdt_efi_init(device_t); -static int acpi_fdt_efi_rtc_gettime(todr_chip_handle_t, struct clock_ymdhms *); -static int acpi_fdt_efi_rtc_settime(todr_chip_handle_t, struct clock_ymdhms *); -#endif - static void acpi_fdt_sysctl_init(void); extern struct arm32_bus_dma_tag acpi_coherent_dma_tag; static uint64_t smbios_table = 0; -#ifdef EFI_RUNTIME -static struct todr_chip_handle efi_todr; -#endif - static const char * const compatible[] = { "netbsd,acpi", NULL @@ -106,10 +95,6 @@ acpi_fdt_attach(device_t parent, device_t self, void *aux) aprint_naive("\n"); aprint_normal("\n"); -#ifdef EFI_RUNTIME - acpi_fdt_efi_init(self); -#endif - fdtbus_register_power_controller(self, faa->faa_phandle, &acpi_fdt_power_funcs); @@ -171,71 +156,3 @@ acpi_fdt_sysctl_init(void) CTL_CREATE, CTL_EOL); } } - -#ifdef EFI_RUNTIME -static void -acpi_fdt_efi_init(device_t dev) -{ - uint64_t efi_system_table; - struct efi_tm tm; - int error; - - const int chosen = OF_finddevice("/chosen"); - if (chosen < 0) - return; - - if (of_getprop_uint64(chosen, "netbsd,uefi-system-table", &efi_system_table) != 0) - return; - - error = arm_efirt_init(efi_system_table); - if (error) - return; - - aprint_debug_dev(dev, "EFI system table at %#" PRIx64 "\n", efi_system_table); - - if (arm_efirt_gettime(&tm) == 0) { - aprint_normal_dev(dev, "using EFI runtime services for RTC\n"); - efi_todr.cookie = NULL; - efi_todr.todr_gettime_ymdhms = acpi_fdt_efi_rtc_gettime; - efi_todr.todr_settime_ymdhms = acpi_fdt_efi_rtc_settime; - todr_attach(&efi_todr); - } -} - -static int -acpi_fdt_efi_rtc_gettime(todr_chip_handle_t tch, struct clock_ymdhms *dt) -{ - struct efi_tm tm; - int error; - - error = arm_efirt_gettime(&tm); - if (error) - return error; - - dt->dt_year = tm.tm_year; - dt->dt_mon = tm.tm_mon; - dt->dt_day = tm.tm_mday; - dt->dt_wday = 0; - dt->dt_hour = tm.tm_hour; - dt->dt_min = tm.tm_min; - dt->dt_sec = tm.tm_sec; - - return 0; -} - -static int -acpi_fdt_efi_rtc_settime(todr_chip_handle_t tch, struct clock_ymdhms *dt) -{ - struct efi_tm tm; - - memset(&tm, 0, sizeof(tm)); - tm.tm_year = dt->dt_year; - tm.tm_mon = dt->dt_mon; - tm.tm_mday = dt->dt_day; - tm.tm_hour = dt->dt_hour; - tm.tm_min = dt->dt_min; - tm.tm_sec = dt->dt_sec; - - return arm_efirt_settime(&tm); -} -#endif diff --git a/sys/arch/arm/fdt/arm_fdt.c b/sys/arch/arm/fdt/arm_fdt.c index 1527c37cc2a8..95572a123642 100644 --- a/sys/arch/arm/fdt/arm_fdt.c +++ b/sys/arch/arm/fdt/arm_fdt.c @@ -1,4 +1,4 @@ -/* $NetBSD: arm_fdt.c,v 1.11 2020/06/21 17:25:03 jmcneill Exp $ */ +/* $NetBSD: arm_fdt.c,v 1.12 2020/10/10 15:34:05 jmcneill Exp $ */ /*- * Copyright (c) 2017 Jared D. McNeill @@ -27,10 +27,11 @@ */ #include "opt_arm_timer.h" +#include "opt_efi.h" #include "opt_modular.h" #include -__KERNEL_RCSID(0, "$NetBSD: arm_fdt.c,v 1.11 2020/06/21 17:25:03 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: arm_fdt.c,v 1.12 2020/10/10 15:34:05 jmcneill Exp $"); #include #include @@ -47,9 +48,22 @@ __KERNEL_RCSID(0, "$NetBSD: arm_fdt.c,v 1.11 2020/06/21 17:25:03 jmcneill Exp $" #include +#ifdef EFI_RUNTIME +#include +#include +#endif + static int arm_fdt_match(device_t, cfdata_t, void *); static void arm_fdt_attach(device_t, device_t, void *); +#ifdef EFI_RUNTIME +static void arm_fdt_efi_init(device_t); +static int arm_fdt_efi_rtc_gettime(todr_chip_handle_t, struct clock_ymdhms *); +static int arm_fdt_efi_rtc_settime(todr_chip_handle_t, struct clock_ymdhms *); + +static struct todr_chip_handle efi_todr; +#endif + CFATTACH_DECL_NEW(arm_fdt, 0, arm_fdt_match, arm_fdt_attach, NULL, NULL); @@ -80,6 +94,10 @@ arm_fdt_attach(device_t parent, device_t self, void *aux) aprint_naive("\n"); aprint_normal("\n"); +#ifdef EFI_RUNTIME + arm_fdt_efi_init(self); +#endif + plat->ap_init_attach_args(&faa); faa.faa_name = ""; faa.faa_phandle = OF_peer(0); @@ -253,3 +271,71 @@ arm_fdt_module_init(void) } #endif /* !MODULAR */ } + +#ifdef EFI_RUNTIME +static void +arm_fdt_efi_init(device_t dev) +{ + uint64_t efi_system_table; + struct efi_tm tm; + int error; + + const int chosen = OF_finddevice("/chosen"); + if (chosen < 0) + return; + + if (of_getprop_uint64(chosen, "netbsd,uefi-system-table", &efi_system_table) != 0) + return; + + error = arm_efirt_init(efi_system_table); + if (error) + return; + + aprint_debug_dev(dev, "EFI system table at %#" PRIx64 "\n", efi_system_table); + + if (arm_efirt_gettime(&tm) == 0) { + aprint_normal_dev(dev, "using EFI runtime services for RTC\n"); + efi_todr.cookie = NULL; + efi_todr.todr_gettime_ymdhms = arm_fdt_efi_rtc_gettime; + efi_todr.todr_settime_ymdhms = arm_fdt_efi_rtc_settime; + todr_attach(&efi_todr); + } +} + +static int +arm_fdt_efi_rtc_gettime(todr_chip_handle_t tch, struct clock_ymdhms *dt) +{ + struct efi_tm tm; + int error; + + error = arm_efirt_gettime(&tm); + if (error) + return error; + + dt->dt_year = tm.tm_year; + dt->dt_mon = tm.tm_mon; + dt->dt_day = tm.tm_mday; + dt->dt_wday = 0; + dt->dt_hour = tm.tm_hour; + dt->dt_min = tm.tm_min; + dt->dt_sec = tm.tm_sec; + + return 0; +} + +static int +arm_fdt_efi_rtc_settime(todr_chip_handle_t tch, struct clock_ymdhms *dt) +{ + struct efi_tm tm; + + memset(&tm, 0, sizeof(tm)); + tm.tm_year = dt->dt_year; + tm.tm_mon = dt->dt_mon; + tm.tm_mday = dt->dt_day; + tm.tm_hour = dt->dt_hour; + tm.tm_min = dt->dt_min; + tm.tm_sec = dt->dt_sec; + + return arm_efirt_settime(&tm); +} +#endif