[efi] Centralise definition of efi_cpu_nap()

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>
diff --git a/src/arch/arm/include/bits/nap.h b/src/arch/arm/include/bits/nap.h
index e30a714..dbdf371 100644
--- a/src/arch/arm/include/bits/nap.h
+++ b/src/arch/arm/include/bits/nap.h
@@ -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
index dcbdd3e..0000000
--- a/src/arch/arm/include/ipxe/efi/efiarm_nap.h
+++ /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
index fba7a5d..0000000
--- a/src/arch/arm/interface/efi/efiarm_nap.c
+++ /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 );
diff --git a/src/arch/loong64/include/bits/nap.h b/src/arch/loong64/include/bits/nap.h
index 2deba35..d904db5 100644
--- a/src/arch/loong64/include/bits/nap.h
+++ b/src/arch/loong64/include/bits/nap.h
@@ -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
index 5c0d386..0000000
--- a/src/arch/loong64/include/ipxe/efi/efiloong64_nap.h
+++ /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
index 0a76097..0000000
--- a/src/arch/loong64/interface/efi/efiloong64_nap.c
+++ /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 );
diff --git a/src/arch/x86/include/bits/nap.h b/src/arch/x86/include/bits/nap.h
index 7103b94..b7dea73 100644
--- a/src/arch/x86/include/bits/nap.h
+++ b/src/arch/x86/include/bits/nap.h
@@ -10,6 +10,13 @@
 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
index 1a391c9..0000000
--- a/src/arch/x86/include/ipxe/efi/efix86_nap.h
+++ /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 */
diff --git a/src/config/defaults/efi.h b/src/config/defaults/efi.h
index b62ddb4..178b448 100644
--- a/src/config/defaults/efi.h
+++ b/src/config/defaults/efi.h
@@ -26,6 +26,7 @@
 #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 @@
 
 #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 @@
 
 #if defined ( __arm__ ) || defined ( __aarch64__ )
 #define IOAPI_ARM
-#define NAP_EFIARM
 #endif
 
 #if defined ( __aarch64__ )
@@ -70,7 +69,6 @@
 
 #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
index 0000000..1ffb055
--- /dev/null
+++ b/src/include/ipxe/efi/efi_nap.h
@@ -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 */
diff --git a/src/include/ipxe/nap.h b/src/include/ipxe/nap.h
index f4de778..8d5d8e3 100644
--- a/src/include/ipxe/nap.h
+++ b/src/include/ipxe/nap.h
@@ -43,6 +43,7 @@
 
 /* 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 @@
  * 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 */
diff --git a/src/arch/x86/interface/efi/efix86_nap.c b/src/interface/efi/efi_nap.c
similarity index 92%
rename from src/arch/x86/interface/efi/efix86_nap.c
rename to src/interface/efi/efi_nap.c
index 296876b..2bb4762 100644
--- a/src/arch/x86/interface/efi/efix86_nap.c
+++ b/src/interface/efi/efi_nap.c
@@ -36,7 +36,7 @@
  * 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 @@
 	 * 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 );