From 8f7ca8028a3cfaed78ca132f3998189a7b7588b9 Mon Sep 17 00:00:00 2001 From: kib Date: Mon, 25 Jun 2018 11:01:12 +0000 Subject: [PATCH] Provide a helper function acpi_get_fadt_bootflags() to fetch the FADT x86 boot flags. Reviewed by: royger Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D16004 MFC after: 1 week --- sys/dev/vt/hw/vga/vt_vga.c | 35 ++++++++--------------------------- sys/x86/include/x86_var.h | 1 + sys/x86/isa/atrtc.c | 26 +++----------------------- sys/x86/x86/cpu_machdep.c | 23 +++++++++++++++++++++++ 4 files changed, 35 insertions(+), 50 deletions(-) diff --git a/sys/dev/vt/hw/vga/vt_vga.c b/sys/dev/vt/hw/vga/vt_vga.c index 773b0eaad3a5..1c7d312af225 100644 --- a/sys/dev/vt/hw/vga/vt_vga.c +++ b/sys/dev/vt/hw/vga/vt_vga.c @@ -48,9 +48,8 @@ __FBSDID("$FreeBSD$"); #include #include - -#if ((defined(__amd64__) || defined(__i386__)) && defined(DEV_ACPI)) -#include +#if defined(__amd64__) || defined(__i386__) +#include #endif struct vga_softc { @@ -1213,36 +1212,18 @@ vga_initialize(struct vt_device *vd, int textmode) static bool vga_acpi_disabled(void) { -#if ((defined(__amd64__) || defined(__i386__)) && defined(DEV_ACPI)) - ACPI_TABLE_FADT *fadt; - vm_paddr_t physaddr; +#if (defined(__amd64__) || defined(__i386__) uint16_t flags; int ignore; ignore = 0; TUNABLE_INT_FETCH("hw.vga.acpi_ignore_no_vga", &ignore); - - if (ignore) - return (false); - - physaddr = acpi_find_table(ACPI_SIG_FADT); - if (physaddr == 0) - return (false); - - fadt = acpi_map_table(physaddr, ACPI_SIG_FADT); - if (fadt == NULL) { - printf("vt_vga: unable to map FADT ACPI table\n"); - return (false); - } - - flags = fadt->BootFlags; - acpi_unmap_table(fadt); - - if (flags & ACPI_FADT_NO_VGA) - return (true); -#endif - + if (ignore || !acpi_get_fadt_bootflags(&flags)) + return (false); + return ((flags & ACPI_FADT_NO_VGA) != 0); +#else return (false); +#endif } static int diff --git a/sys/x86/include/x86_var.h b/sys/x86/include/x86_var.h index 4e9871f434b6..286c01261f0f 100644 --- a/sys/x86/include/x86_var.h +++ b/sys/x86/include/x86_var.h @@ -116,6 +116,7 @@ cpu_getmaxphyaddr(void) #endif } +bool acpi_get_fadt_bootflags(uint16_t *flagsp); void *alloc_fpusave(int flags); void busdma_swi(void); bool cpu_mwait_usable(void); diff --git a/sys/x86/isa/atrtc.c b/sys/x86/isa/atrtc.c index c67174e0f3d4..b7ff50413d7c 100644 --- a/sys/x86/isa/atrtc.c +++ b/sys/x86/isa/atrtc.c @@ -32,7 +32,6 @@ #include __FBSDID("$FreeBSD$"); -#include "opt_acpi.h" #include "opt_isa.h" #include @@ -55,10 +54,8 @@ __FBSDID("$FreeBSD$"); #endif #include #include "clock_if.h" - -#ifdef DEV_ACPI #include -#endif +#include /* * atrtc_lock protects low-level access to individual hardware registers. @@ -261,29 +258,12 @@ static struct isa_pnp_id atrtc_ids[] = { static bool atrtc_acpi_disabled(void) { -#ifdef DEV_ACPI - ACPI_TABLE_FADT *fadt; - vm_paddr_t physaddr; uint16_t flags; - physaddr = acpi_find_table(ACPI_SIG_FADT); - if (physaddr == 0) + if (!acpi_get_fadt_bootflags(&flags)) return (false); - - fadt = acpi_map_table(physaddr, ACPI_SIG_FADT); - if (fadt == NULL) { - printf("at_rtc: unable to map FADT ACPI table\n"); - return (false); - } - - flags = fadt->BootFlags; - acpi_unmap_table(fadt); - - if (flags & ACPI_FADT_NO_CMOS_RTC) + return ((flags & ACPI_FADT_NO_CMOS_RTC) != 0); return (true); -#endif - - return (false); } static int diff --git a/sys/x86/x86/cpu_machdep.c b/sys/x86/x86/cpu_machdep.c index ec70d822e890..d897d518cbc3 100644 --- a/sys/x86/x86/cpu_machdep.c +++ b/sys/x86/x86/cpu_machdep.c @@ -41,6 +41,7 @@ #include __FBSDID("$FreeBSD$"); +#include "opt_acpi.h" #include "opt_atpic.h" #include "opt_cpu.h" #include "opt_ddb.h" @@ -98,6 +99,8 @@ __FBSDID("$FreeBSD$"); #include +#include + #define STATE_RUNNING 0x0 #define STATE_MWAIT 0x1 #define STATE_SLEEPING 0x2 @@ -930,3 +933,23 @@ restore_wp(bool old_wp) load_cr0(rcr0() | CR0_WP); } +bool +acpi_get_fadt_bootflags(uint16_t *flagsp) +{ +#ifdef DEV_ACPI + ACPI_TABLE_FADT *fadt; + vm_paddr_t physaddr; + + physaddr = acpi_find_table(ACPI_SIG_FADT); + if (physaddr == 0) + return (false); + fadt = acpi_map_table(physaddr, ACPI_SIG_FADT); + if (fadt == NULL) + return (false); + *flagsp = fadt->BootFlags; + acpi_unmap_table(fadt); + return (true); +#else + return (false); +#endif +}