Przeglądaj źródła

[nap] Formalise the CPU sleeping API

tags/v0.9.6
Michael Brown 15 lat temu
rodzic
commit
c0835339d0

+ 0
- 12
src/arch/i386/core/nap.c Wyświetl plik

@@ -1,12 +0,0 @@
1
-
2
-#include <realmode.h>
3
-#include <bios.h>
4
-
5
-/**************************************************************************
6
- * Save power by halting the CPU until the next interrupt
7
- **************************************************************************/
8
-void cpu_nap ( void ) {
9
-	__asm__ __volatile__ ( REAL_CODE ( "sti\n\t"
10
-					   "hlt\n\t"
11
-					   "cli\n\t" ) : : );
12
-}

+ 0
- 2
src/arch/i386/include/bios.h Wyświetl plik

@@ -5,6 +5,4 @@
5 5
 #define BDA_FBMS 0x0013
6 6
 #define BDA_NUM_DRIVES 0x0075
7 7
 
8
-extern void cpu_nap ( void );
9
-
10 8
 #endif /* BIOS_H */

+ 12
- 0
src/arch/i386/include/bits/nap.h Wyświetl plik

@@ -0,0 +1,12 @@
1
+#ifndef _BITS_NAP_H
2
+#define _BITS_NAP_H
3
+
4
+/** @file
5
+ *
6
+ * i386-specific CPU sleeping API implementations
7
+ *
8
+ */
9
+
10
+#include <gpxe/bios_nap.h>
11
+
12
+#endif /* _BITS_MAP_H */

+ 16
- 0
src/arch/i386/include/gpxe/bios_nap.h Wyświetl plik

@@ -0,0 +1,16 @@
1
+#ifndef _GPXE_BIOS_NAP_H
2
+#define _GPXE_BIOS_NAP_H
3
+
4
+/** @file
5
+ *
6
+ * BIOS CPU sleeping
7
+ *
8
+ */
9
+
10
+#ifdef NAP_PCBIOS
11
+#define NAP_PREFIX_pcbios
12
+#else
13
+#define NAP_PREFIX_pcbios __pcbios_
14
+#endif
15
+
16
+#endif /* _GPXE_BIOS_NAP_H */

+ 14
- 0
src/arch/i386/interface/pcbios/bios_nap.c Wyświetl plik

@@ -0,0 +1,14 @@
1
+#include <gpxe/nap.h>
2
+#include <realmode.h>
3
+
4
+/**
5
+ * Save power by halting the CPU until the next interrupt
6
+ *
7
+ */
8
+static void bios_cpu_nap ( void ) {
9
+	__asm__ __volatile__ ( REAL_CODE ( "sti\n\t"
10
+					   "hlt\n\t"
11
+					   "cli\n\t" ) : : );
12
+}
13
+
14
+PROVIDE_NAP ( pcbios, cpu_nap, bios_cpu_nap );

+ 1
- 0
src/config/defaults/pcbios.h Wyświetl plik

@@ -11,5 +11,6 @@
11 11
 #define PCIAPI_PCBIOS
12 12
 #define TIMER_PCBIOS
13 13
 #define CONSOLE_PCBIOS
14
+#define NAP_PCBIOS
14 15
 
15 16
 #endif /* CONFIG_DEFAULTS_PCBIOS_H */

+ 15
- 0
src/config/nap.h Wyświetl plik

@@ -0,0 +1,15 @@
1
+#ifndef CONFIG_NAP_H
2
+#define CONFIG_NAP_H
3
+
4
+/** @file
5
+ *
6
+ * CPU sleeping
7
+ *
8
+ */
9
+
10
+#include <config/defaults.h>
11
+
12
+//#undef		NAP_PCBIOS
13
+//#define		NAP_NULL
14
+
15
+#endif /* CONFIG_NAP_H */

+ 1
- 5
src/core/console.c Wyświetl plik

@@ -1,11 +1,10 @@
1 1
 #include "stddef.h"
2 2
 #include "console.h"
3 3
 #include <gpxe/process.h>
4
+#include <gpxe/nap.h>
4 5
 
5 6
 /** @file */
6 7
 
7
-#include "bios.h"
8
-
9 8
 static struct console_driver console_drivers[0]
10 9
 	__table_start ( struct console_driver, console );
11 10
 static struct console_driver console_drivers_end[0]
@@ -82,9 +81,6 @@ static struct console_driver * has_input ( void ) {
82 81
  *
83 82
  * The character read will not be echoed back to any console.
84 83
  *
85
- * @bug We need a cleaner way to pick up cpu_nap().  It makes a
86
- * real-mode call, and so we don't want to use it with LinuxBIOS.
87
- *
88 84
  */
89 85
 int getchar ( void ) {
90 86
 	struct console_driver *console;

+ 1
- 1
src/core/gdbudp.c Wyświetl plik

@@ -19,7 +19,6 @@
19 19
 #include <stdio.h>
20 20
 #include <string.h>
21 21
 #include <byteswap.h>
22
-#include <bios.h>
23 22
 #include <gpxe/iobuf.h>
24 23
 #include <gpxe/in.h>
25 24
 #include <gpxe/if_arp.h>
@@ -27,6 +26,7 @@
27 26
 #include <gpxe/ip.h>
28 27
 #include <gpxe/udp.h>
29 28
 #include <gpxe/netdevice.h>
29
+#include <gpxe/nap.h>
30 30
 #include <gpxe/gdbstub.h>
31 31
 #include <gpxe/gdbudp.h>
32 32
 

+ 3
- 0
src/core/null_nap.c Wyświetl plik

@@ -0,0 +1,3 @@
1
+#include <gpxe/nap.h>
2
+
3
+PROVIDE_NAP_INLINE ( null, cpu_nap );

+ 54
- 0
src/include/gpxe/nap.h Wyświetl plik

@@ -0,0 +1,54 @@
1
+#ifndef _GPXE_NAP_H
2
+#define _GPXE_NAP_H
3
+
4
+/** @file
5
+ *
6
+ * CPU sleeping
7
+ *
8
+ */
9
+
10
+#include <gpxe/api.h>
11
+#include <config/nap.h>
12
+
13
+/**
14
+ * Calculate static inline CPU sleeping API function name
15
+ *
16
+ * @v _prefix		Subsystem prefix
17
+ * @v _api_func		API function
18
+ * @ret _subsys_func	Subsystem API function
19
+ */
20
+#define NAP_INLINE( _subsys, _api_func ) \
21
+	SINGLE_API_INLINE ( NAP_PREFIX_ ## _subsys, _api_func )
22
+
23
+/**
24
+ * Provide an CPU sleeping API implementation
25
+ *
26
+ * @v _prefix		Subsystem prefix
27
+ * @v _api_func		API function
28
+ * @v _func		Implementing function
29
+ */
30
+#define PROVIDE_NAP( _subsys, _api_func, _func ) \
31
+	PROVIDE_SINGLE_API ( NAP_PREFIX_ ## _subsys, _api_func, _func )
32
+
33
+/**
34
+ * Provide a static inline CPU sleeping API implementation
35
+ *
36
+ * @v _prefix		Subsystem prefix
37
+ * @v _api_func		API function
38
+ */
39
+#define PROVIDE_NAP_INLINE( _subsys, _api_func ) \
40
+	PROVIDE_SINGLE_API_INLINE ( NAP_PREFIX_ ## _subsys, _api_func )
41
+
42
+/* Include all architecture-independent I/O API headers */
43
+#include <gpxe/null_nap.h>
44
+
45
+/* Include all architecture-dependent I/O API headers */
46
+#include <bits/nap.h>
47
+
48
+/**
49
+ * Sleep until next CPU interrupt
50
+ *
51
+ */
52
+void cpu_nap ( void );
53
+
54
+#endif /* _GPXE_NAP_H */

+ 21
- 0
src/include/gpxe/null_nap.h Wyświetl plik

@@ -0,0 +1,21 @@
1
+#ifndef _GPXE_NULL_NAP_H
2
+#define _GPXE_NULL_NAP_H
3
+
4
+/** @file
5
+ *
6
+ * Null CPU sleeping
7
+ *
8
+ */
9
+
10
+#ifdef NAP_NULL
11
+#define NAP_PREFIX_null
12
+#else
13
+#define NAP_PREFIX_null __null_
14
+#endif
15
+
16
+static inline __always_inline void
17
+NAP_INLINE ( null, cpu_nap ) ( void ) {
18
+	/* Do nothing */
19
+}
20
+
21
+#endif /* _GPXE_NULL_NAP_H */

Ładowanie…
Anuluj
Zapisz