Browse Source

[nap] Formalise the CPU sleeping API

tags/v0.9.6
Michael Brown 16 years ago
parent
commit
c0835339d0

+ 0
- 12
src/arch/i386/core/nap.c View File

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 View File

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

+ 12
- 0
src/arch/i386/include/bits/nap.h View File

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 View File

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 View File

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 View File

11
 #define PCIAPI_PCBIOS
11
 #define PCIAPI_PCBIOS
12
 #define TIMER_PCBIOS
12
 #define TIMER_PCBIOS
13
 #define CONSOLE_PCBIOS
13
 #define CONSOLE_PCBIOS
14
+#define NAP_PCBIOS
14
 
15
 
15
 #endif /* CONFIG_DEFAULTS_PCBIOS_H */
16
 #endif /* CONFIG_DEFAULTS_PCBIOS_H */

+ 15
- 0
src/config/nap.h View File

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 View File

1
 #include "stddef.h"
1
 #include "stddef.h"
2
 #include "console.h"
2
 #include "console.h"
3
 #include <gpxe/process.h>
3
 #include <gpxe/process.h>
4
+#include <gpxe/nap.h>
4
 
5
 
5
 /** @file */
6
 /** @file */
6
 
7
 
7
-#include "bios.h"
8
-
9
 static struct console_driver console_drivers[0]
8
 static struct console_driver console_drivers[0]
10
 	__table_start ( struct console_driver, console );
9
 	__table_start ( struct console_driver, console );
11
 static struct console_driver console_drivers_end[0]
10
 static struct console_driver console_drivers_end[0]
82
  *
81
  *
83
  * The character read will not be echoed back to any console.
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
 int getchar ( void ) {
85
 int getchar ( void ) {
90
 	struct console_driver *console;
86
 	struct console_driver *console;

+ 1
- 1
src/core/gdbudp.c View File

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

+ 3
- 0
src/core/null_nap.c View File

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

+ 54
- 0
src/include/gpxe/nap.h View File

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 View File

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 */

Loading…
Cancel
Save