summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brown2008-10-13 00:34:45 +0200
committerMichael Brown2008-10-13 00:36:53 +0200
commitc0835339d06716b133aa653847023742a967f188 (patch)
tree25f22e63175c7919c8de678f5a5f1513bed516c8
parent[monojob] Allow for extremely slow system timers (diff)
downloadipxe-c0835339d06716b133aa653847023742a967f188.tar.gz
ipxe-c0835339d06716b133aa653847023742a967f188.tar.xz
ipxe-c0835339d06716b133aa653847023742a967f188.zip
[nap] Formalise the CPU sleeping API
-rw-r--r--src/arch/i386/core/nap.c12
-rw-r--r--src/arch/i386/include/bios.h2
-rw-r--r--src/arch/i386/include/bits/nap.h12
-rw-r--r--src/arch/i386/include/gpxe/bios_nap.h16
-rw-r--r--src/arch/i386/interface/pcbios/bios_nap.c14
-rw-r--r--src/config/defaults/pcbios.h1
-rw-r--r--src/config/nap.h15
-rw-r--r--src/core/console.c6
-rw-r--r--src/core/gdbudp.c2
-rw-r--r--src/core/null_nap.c3
-rw-r--r--src/include/gpxe/nap.h54
-rw-r--r--src/include/gpxe/null_nap.h21
12 files changed, 138 insertions, 20 deletions
diff --git a/src/arch/i386/core/nap.c b/src/arch/i386/core/nap.c
deleted file mode 100644
index 12bb5699..00000000
--- a/src/arch/i386/core/nap.c
+++ /dev/null
@@ -1,12 +0,0 @@
-
-#include <realmode.h>
-#include <bios.h>
-
-/**************************************************************************
- * Save power by halting the CPU until the next interrupt
- **************************************************************************/
-void cpu_nap ( void ) {
- __asm__ __volatile__ ( REAL_CODE ( "sti\n\t"
- "hlt\n\t"
- "cli\n\t" ) : : );
-}
diff --git a/src/arch/i386/include/bios.h b/src/arch/i386/include/bios.h
index 5f9d6ab0..979a092c 100644
--- a/src/arch/i386/include/bios.h
+++ b/src/arch/i386/include/bios.h
@@ -5,6 +5,4 @@
#define BDA_FBMS 0x0013
#define BDA_NUM_DRIVES 0x0075
-extern void cpu_nap ( void );
-
#endif /* BIOS_H */
diff --git a/src/arch/i386/include/bits/nap.h b/src/arch/i386/include/bits/nap.h
new file mode 100644
index 00000000..2c85444a
--- /dev/null
+++ b/src/arch/i386/include/bits/nap.h
@@ -0,0 +1,12 @@
+#ifndef _BITS_NAP_H
+#define _BITS_NAP_H
+
+/** @file
+ *
+ * i386-specific CPU sleeping API implementations
+ *
+ */
+
+#include <gpxe/bios_nap.h>
+
+#endif /* _BITS_MAP_H */
diff --git a/src/arch/i386/include/gpxe/bios_nap.h b/src/arch/i386/include/gpxe/bios_nap.h
new file mode 100644
index 00000000..f1c721e9
--- /dev/null
+++ b/src/arch/i386/include/gpxe/bios_nap.h
@@ -0,0 +1,16 @@
+#ifndef _GPXE_BIOS_NAP_H
+#define _GPXE_BIOS_NAP_H
+
+/** @file
+ *
+ * BIOS CPU sleeping
+ *
+ */
+
+#ifdef NAP_PCBIOS
+#define NAP_PREFIX_pcbios
+#else
+#define NAP_PREFIX_pcbios __pcbios_
+#endif
+
+#endif /* _GPXE_BIOS_NAP_H */
diff --git a/src/arch/i386/interface/pcbios/bios_nap.c b/src/arch/i386/interface/pcbios/bios_nap.c
new file mode 100644
index 00000000..2f4a0513
--- /dev/null
+++ b/src/arch/i386/interface/pcbios/bios_nap.c
@@ -0,0 +1,14 @@
+#include <gpxe/nap.h>
+#include <realmode.h>
+
+/**
+ * Save power by halting the CPU until the next interrupt
+ *
+ */
+static void bios_cpu_nap ( void ) {
+ __asm__ __volatile__ ( REAL_CODE ( "sti\n\t"
+ "hlt\n\t"
+ "cli\n\t" ) : : );
+}
+
+PROVIDE_NAP ( pcbios, cpu_nap, bios_cpu_nap );
diff --git a/src/config/defaults/pcbios.h b/src/config/defaults/pcbios.h
index 4cf2d7e4..a670e7a6 100644
--- a/src/config/defaults/pcbios.h
+++ b/src/config/defaults/pcbios.h
@@ -11,5 +11,6 @@
#define PCIAPI_PCBIOS
#define TIMER_PCBIOS
#define CONSOLE_PCBIOS
+#define NAP_PCBIOS
#endif /* CONFIG_DEFAULTS_PCBIOS_H */
diff --git a/src/config/nap.h b/src/config/nap.h
new file mode 100644
index 00000000..8648d925
--- /dev/null
+++ b/src/config/nap.h
@@ -0,0 +1,15 @@
+#ifndef CONFIG_NAP_H
+#define CONFIG_NAP_H
+
+/** @file
+ *
+ * CPU sleeping
+ *
+ */
+
+#include <config/defaults.h>
+
+//#undef NAP_PCBIOS
+//#define NAP_NULL
+
+#endif /* CONFIG_NAP_H */
diff --git a/src/core/console.c b/src/core/console.c
index 653f689d..c9773f71 100644
--- a/src/core/console.c
+++ b/src/core/console.c
@@ -1,11 +1,10 @@
#include "stddef.h"
#include "console.h"
#include <gpxe/process.h>
+#include <gpxe/nap.h>
/** @file */
-#include "bios.h"
-
static struct console_driver console_drivers[0]
__table_start ( struct console_driver, console );
static struct console_driver console_drivers_end[0]
@@ -82,9 +81,6 @@ static struct console_driver * has_input ( void ) {
*
* The character read will not be echoed back to any console.
*
- * @bug We need a cleaner way to pick up cpu_nap(). It makes a
- * real-mode call, and so we don't want to use it with LinuxBIOS.
- *
*/
int getchar ( void ) {
struct console_driver *console;
diff --git a/src/core/gdbudp.c b/src/core/gdbudp.c
index c49a1bca..26feb38a 100644
--- a/src/core/gdbudp.c
+++ b/src/core/gdbudp.c
@@ -19,7 +19,6 @@
#include <stdio.h>
#include <string.h>
#include <byteswap.h>
-#include <bios.h>
#include <gpxe/iobuf.h>
#include <gpxe/in.h>
#include <gpxe/if_arp.h>
@@ -27,6 +26,7 @@
#include <gpxe/ip.h>
#include <gpxe/udp.h>
#include <gpxe/netdevice.h>
+#include <gpxe/nap.h>
#include <gpxe/gdbstub.h>
#include <gpxe/gdbudp.h>
diff --git a/src/core/null_nap.c b/src/core/null_nap.c
new file mode 100644
index 00000000..a3b01eb1
--- /dev/null
+++ b/src/core/null_nap.c
@@ -0,0 +1,3 @@
+#include <gpxe/nap.h>
+
+PROVIDE_NAP_INLINE ( null, cpu_nap );
diff --git a/src/include/gpxe/nap.h b/src/include/gpxe/nap.h
new file mode 100644
index 00000000..f9ae3cf4
--- /dev/null
+++ b/src/include/gpxe/nap.h
@@ -0,0 +1,54 @@
+#ifndef _GPXE_NAP_H
+#define _GPXE_NAP_H
+
+/** @file
+ *
+ * CPU sleeping
+ *
+ */
+
+#include <gpxe/api.h>
+#include <config/nap.h>
+
+/**
+ * Calculate static inline CPU sleeping API function name
+ *
+ * @v _prefix Subsystem prefix
+ * @v _api_func API function
+ * @ret _subsys_func Subsystem API function
+ */
+#define NAP_INLINE( _subsys, _api_func ) \
+ SINGLE_API_INLINE ( NAP_PREFIX_ ## _subsys, _api_func )
+
+/**
+ * Provide an CPU sleeping API implementation
+ *
+ * @v _prefix Subsystem prefix
+ * @v _api_func API function
+ * @v _func Implementing function
+ */
+#define PROVIDE_NAP( _subsys, _api_func, _func ) \
+ PROVIDE_SINGLE_API ( NAP_PREFIX_ ## _subsys, _api_func, _func )
+
+/**
+ * Provide a static inline CPU sleeping API implementation
+ *
+ * @v _prefix Subsystem prefix
+ * @v _api_func API function
+ */
+#define PROVIDE_NAP_INLINE( _subsys, _api_func ) \
+ PROVIDE_SINGLE_API_INLINE ( NAP_PREFIX_ ## _subsys, _api_func )
+
+/* Include all architecture-independent I/O API headers */
+#include <gpxe/null_nap.h>
+
+/* Include all architecture-dependent I/O API headers */
+#include <bits/nap.h>
+
+/**
+ * Sleep until next CPU interrupt
+ *
+ */
+void cpu_nap ( void );
+
+#endif /* _GPXE_NAP_H */
diff --git a/src/include/gpxe/null_nap.h b/src/include/gpxe/null_nap.h
new file mode 100644
index 00000000..6dd0cda3
--- /dev/null
+++ b/src/include/gpxe/null_nap.h
@@ -0,0 +1,21 @@
+#ifndef _GPXE_NULL_NAP_H
+#define _GPXE_NULL_NAP_H
+
+/** @file
+ *
+ * Null CPU sleeping
+ *
+ */
+
+#ifdef NAP_NULL
+#define NAP_PREFIX_null
+#else
+#define NAP_PREFIX_null __null_
+#endif
+
+static inline __always_inline void
+NAP_INLINE ( null, cpu_nap ) ( void ) {
+ /* Do nothing */
+}
+
+#endif /* _GPXE_NULL_NAP_H */