]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[efi] Centralise definition of efi_cpu_nap()
authorMichael Brown <mcb30@ipxe.org>
Fri, 13 Sep 2024 13:26:34 +0000 (14:26 +0100)
committerMichael Brown <mcb30@ipxe.org>
Fri, 13 Sep 2024 13:38:23 +0000 (14:38 +0100)
Define a cpu_halt() function which is architecture-specific but
platform-independent, and merge the multiple architecture-specific
implementations of the EFI cpu_nap() function into a single central
efi_cpu_nap() that uses cpu_halt() if applicable.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
12 files changed:
src/arch/arm/include/bits/nap.h
src/arch/arm/include/ipxe/efi/efiarm_nap.h [deleted file]
src/arch/arm/interface/efi/efiarm_nap.c [deleted file]
src/arch/loong64/include/bits/nap.h
src/arch/loong64/include/ipxe/efi/efiloong64_nap.h [deleted file]
src/arch/loong64/interface/efi/efiloong64_nap.c [deleted file]
src/arch/x86/include/bits/nap.h
src/arch/x86/include/ipxe/efi/efix86_nap.h [deleted file]
src/config/defaults/efi.h
src/include/ipxe/efi/efi_nap.h [new file with mode: 0644]
src/include/ipxe/nap.h
src/interface/efi/efi_nap.c [moved from src/arch/x86/interface/efi/efix86_nap.c with 93% similarity]

index e30a7146b5dc70530932689b6eb2655e5e288722..dbdf3716614ccac7c571d992c3d4cb09ab0460e9 100644 (file)
@@ -9,6 +9,12 @@
 
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 
-#include <ipxe/efi/efiarm_nap.h>
+/**
+ * Sleep until next CPU interrupt
+ *
+ */
+static inline __attribute__ (( always_inline )) void cpu_halt ( void ) {
+       __asm__ __volatile__ ( "wfi" );
+}
 
-#endif /* _BITS_MAP_H */
+#endif /* _BITS_NAP_H */
diff --git a/src/arch/arm/include/ipxe/efi/efiarm_nap.h b/src/arch/arm/include/ipxe/efi/efiarm_nap.h
deleted file mode 100644 (file)
index dcbdd3e..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-#ifndef _IPXE_EFIARM_NAP_H
-#define _IPXE_EFIARM_NAP_H
-
-/** @file
- *
- * EFI CPU sleeping
- *
- */
-
-FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
-
-#ifdef NAP_EFIARM
-#define NAP_PREFIX_efiarm
-#else
-#define NAP_PREFIX_efiarm __efiarm_
-#endif
-
-#endif /* _IPXE_EFIARM_NAP_H */
diff --git a/src/arch/arm/interface/efi/efiarm_nap.c b/src/arch/arm/interface/efi/efiarm_nap.c
deleted file mode 100644 (file)
index fba7a5d..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (C) 2016 Michael Brown <mbrown@fensystems.co.uk>.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
- *
- * You can also choose to distribute this program under the terms of
- * the Unmodified Binary Distribution Licence (as given in the file
- * COPYING.UBDL), provided that you have satisfied its requirements.
- */
-
-FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
-
-#include <ipxe/nap.h>
-#include <ipxe/efi/efi.h>
-
-/** @file
- *
- * iPXE CPU sleeping API for EFI
- *
- */
-
-/**
- * Sleep until next interrupt
- *
- */
-static void efiarm_cpu_nap ( void ) {
-       /*
-        * I can't find any EFI API that allows us to put the CPU to
-        * sleep.  The CpuSleep() function is defined in CpuLib.h, but
-        * isn't part of any exposed protocol so we have no way to
-        * call it.
-        *
-        * The EFI shell doesn't seem to bother sleeping the CPU; it
-        * just sits there idly burning power.
-        *
-        * If a shutdown is in progess, there may be nothing to
-        * generate an interrupt since the timer is disabled in the
-        * first step of ExitBootServices().
-        */
-       if ( ! efi_shutdown_in_progress )
-               __asm__ __volatile__ ( "wfi" );
-}
-
-PROVIDE_NAP ( efiarm, cpu_nap, efiarm_cpu_nap );
index 2deba3558534a3a5e52604975586a52afa4edc34..d904db53783aab3422e24de4f984f95b7d590dde 100644 (file)
@@ -9,6 +9,12 @@
 
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 
-#include <ipxe/efi/efiloong64_nap.h>
+/**
+ * Sleep until next CPU interrupt
+ *
+ */
+static inline __attribute__ (( always_inline )) void cpu_halt ( void ) {
+       __asm__ __volatile__ ( "idle 0" );
+}
 
 #endif /* _BITS_NAP_H */
diff --git a/src/arch/loong64/include/ipxe/efi/efiloong64_nap.h b/src/arch/loong64/include/ipxe/efi/efiloong64_nap.h
deleted file mode 100644 (file)
index 5c0d386..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-#ifndef _IPXE_EFILOONG64_NAP_H
-#define _IPXE_EFILOONG64_NAP_H
-
-/** @file
- *
- * EFI CPU sleeping
- *
- */
-
-FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
-
-#ifdef NAP_EFILOONG64
-#define NAP_PREFIX_efiloong64
-#else
-#define NAP_PREFIX_efiloong64 __efiloong64_
-#endif
-
-#endif /* _IPXE_EFILOONG64_NAP_H */
diff --git a/src/arch/loong64/interface/efi/efiloong64_nap.c b/src/arch/loong64/interface/efi/efiloong64_nap.c
deleted file mode 100644 (file)
index 0a76097..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (c) 2023, Xiaotian Wu <wuxiaotian@loongson.cn>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
- *
- * You can also choose to distribute this program under the terms of
- * the Unmodified Binary Distribution Licence (as given in the file
- * COPYING.UBDL), provided that you have satisfied its requirements.
- */
-
-FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
-
-#include <ipxe/nap.h>
-#include <ipxe/efi/efi.h>
-
-/** @file
- *
- * iPXE CPU sleeping API for EFI
- *
- */
-
-/**
- * Sleep until next interrupt
- *
- */
-static void efiloong64_cpu_nap ( void ) {
-       /*
-        * I can't find any EFI API that allows us to put the CPU to
-        * sleep.  The CpuSleep() function is defined in CpuLib.h, but
-        * isn't part of any exposed protocol so we have no way to
-        * call it.
-        *
-        * The EFI shell doesn't seem to bother sleeping the CPU; it
-        * just sits there idly burning power.
-        *
-        * If a shutdown is in progess, there may be nothing to
-        * generate an interrupt since the timer is disabled in the
-        * first step of ExitBootServices().
-        */
-       if ( ! efi_shutdown_in_progress )
-               __asm__ __volatile__ ( "idle 0" );
-}
-
-PROVIDE_NAP ( efiloong64, cpu_nap, efiloong64_cpu_nap );
index 7103b94c04fa2651937f43473325a6cf04d1f42f..b7dea736d97cdbf2b6c347e33983648565d38b2e 100644 (file)
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 
 #include <ipxe/bios_nap.h>
-#include <ipxe/efi/efix86_nap.h>
 
-#endif /* _BITS_MAP_H */
+/**
+ * Sleep until next CPU interrupt
+ *
+ */
+static inline __attribute__ (( always_inline )) void cpu_halt ( void ) {
+       __asm__ __volatile__ ( "hlt" );
+}
+
+#endif /* _BITS_NAP_H */
diff --git a/src/arch/x86/include/ipxe/efi/efix86_nap.h b/src/arch/x86/include/ipxe/efi/efix86_nap.h
deleted file mode 100644 (file)
index 1a391c9..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-#ifndef _IPXE_EFIX86_NAP_H
-#define _IPXE_EFIX86_NAP_H
-
-/** @file
- *
- * EFI CPU sleeping
- *
- */
-
-FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
-
-#ifdef NAP_EFIX86
-#define NAP_PREFIX_efix86
-#else
-#define NAP_PREFIX_efix86 __efix86_
-#endif
-
-#endif /* _IPXE_EFIX86_NAP_H */
index b62ddb46a8c6738acb4e3321f8524a61cfcb7207..178b448cbd9895585d08d6d55fb713867a5eee48 100644 (file)
@@ -26,6 +26,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 #define ACPI_EFI
 #define FDT_EFI
 #define MPAPI_EFI
+#define NAP_EFI
 
 #define        NET_PROTO_IPV6          /* IPv6 protocol */
 #define        NET_PROTO_LLDP          /* Link Layer Discovery protocol */
@@ -53,7 +54,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 
 #if defined ( __i386__ ) || defined ( __x86_64__ )
 #define IOAPI_X86
-#define NAP_EFIX86
 #define ENTROPY_RDRAND
 #define        CPUID_CMD               /* x86 CPU feature detection command */
 #define        UNSAFE_STD              /* Avoid setting direction flag */
@@ -61,7 +61,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 
 #if defined ( __arm__ ) || defined ( __aarch64__ )
 #define IOAPI_ARM
-#define NAP_EFIARM
 #endif
 
 #if defined ( __aarch64__ )
@@ -70,7 +69,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 
 #if defined ( __loongarch__ )
 #define IOAPI_LOONG64
-#define NAP_EFILOONG64
 #endif
 
 #endif /* CONFIG_DEFAULTS_EFI_H */
diff --git a/src/include/ipxe/efi/efi_nap.h b/src/include/ipxe/efi/efi_nap.h
new file mode 100644 (file)
index 0000000..1ffb055
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef _IPXE_EFI_NAP_H
+#define _IPXE_EFI_NAP_H
+
+/** @file
+ *
+ * CPU sleeping
+ *
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+#ifdef NAP_EFI
+#define NAP_PREFIX_efi
+#else
+#define NAP_PREFIX_efi __efi_
+#endif
+
+#endif /* _IPXE_EFI_NAP_H */
index f4de778c441f7f1e2f1afefa4ad2ac1aeb9e9a52..8d5d8e3df828d94429e32d3245d853adffef89e4 100644 (file)
@@ -43,6 +43,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 
 /* Include all architecture-independent I/O API headers */
 #include <ipxe/null_nap.h>
+#include <ipxe/efi/efi_nap.h>
 #include <ipxe/linux/linux_nap.h>
 
 /* Include all architecture-dependent I/O API headers */
@@ -52,6 +53,12 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  * Sleep until next CPU interrupt
  *
  */
+void cpu_halt ( void );
+
+/**
+ * Sleep with interrupts enabled until next CPU interrupt
+ *
+ */
 void cpu_nap ( void );
 
 #endif /* _IPXE_NAP_H */
similarity index 93%
rename from src/arch/x86/interface/efi/efix86_nap.c
rename to src/interface/efi/efi_nap.c
index 296876b858ed9dae65ccea3e52417b3d06a8e441..2bb47627f930cda19efbf4b125175b03ef3f323f 100644 (file)
@@ -36,7 +36,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  * Sleep until next interrupt
  *
  */
-static void efix86_cpu_nap ( void ) {
+static void efi_cpu_nap ( void ) {
        /*
         * I can't find any EFI API that allows us to put the CPU to
         * sleep.  The CpuSleep() function is defined in CpuLib.h, but
@@ -51,7 +51,7 @@ static void efix86_cpu_nap ( void ) {
         * first step of ExitBootServices().
         */
        if ( ! efi_shutdown_in_progress )
-               __asm__ __volatile__ ( "hlt" );
+               cpu_halt();
 }
 
-PROVIDE_NAP ( efix86, cpu_nap, efix86_cpu_nap );
+PROVIDE_NAP ( efi, cpu_nap, efi_cpu_nap );