summaryrefslogtreecommitdiffstats
path: root/src/include/gpxe/init.h
blob: 0a2eb0bf45ed63999d96341a3b631307c6609250 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef _GPXE_INIT_H
#define _GPXE_INIT_H

#include <gpxe/tables.h>

/*
 * In order to avoid having objects dragged in just because main()
 * calls their initialisation function, we allow each object to
 * specify that it has a function that must be called to initialise
 * that object.  The function call_init_fns() will call all the
 * included objects' initialisation functions.
 *
 * Objects that require initialisation should include init.h and
 * register the initialisation function using INIT_FN().
 *
 * Objects may register up to three functions: init, reset and exit.
 * init gets called only once, at the point that Etherboot is
 * initialised (before the call to main()).  reset gets called between
 * each boot attempt.  exit gets called only once, just before the
 * loaded OS starts up (or just before Etherboot exits, if it exits,
 * or when the PXE NBP calls UNDI_SHUTDOWN, if it's a PXE NBP).
 *
 * The syntax is:
 *   INIT_FN ( init_order, init_function, reset_function, exit_function );
 * where init_order is an ordering taken from the list below.  Any
 * function may be left as NULL.
 */

/* An entry in the initialisation function table */

struct init_fn {
	void ( *init ) ( void );
	void ( *reset ) ( void );
	void ( *exit ) ( void );
};

/* Use double digits to avoid problems with "10" < "9" on alphabetic sort */
#define	INIT_CONSOLE	02
#define	INIT_CPU	03
#define	INIT_TIMERS	04
#define	INIT_LOADBUF	08
#define	INIT_PCMCIA	09
#define	INIT_RPC	11
#define INIT_PROCESS	12

/* Macro for creating an initialisation function table entry */
#define INIT_FN( init_order, init_func, reset_func, exit_func )	\
	struct init_fn PREFIX_OBJECT(init_fn__)			\
	    __table ( struct init_fn, init_fn, init_order ) = {	\
		.init = init_func,				\
		.reset = reset_func,				\
		.exit = exit_func,				\
	};

/* Function prototypes */

void call_init_fns ( void );
void call_reset_fns ( void );
void call_exit_fns ( void );

#endif /* _GPXE_INIT_H */