[intel] Forcibly skip PHY reset on some models
[ipxe.git] / src / core / init.c
1 /*
2 * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
18 *
19 * You can also choose to distribute this program under the terms of
20 * the Unmodified Binary Distribution Licence (as given in the file
21 * COPYING.UBDL), provided that you have satisfied its requirements.
22 */
23
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25
26 #include <ipxe/device.h>
27 #include <ipxe/console.h>
28 #include <ipxe/init.h>
29
30 /** @file
31 *
32 * Initialisation, startup and shutdown routines
33 *
34 */
35
36 /** "startup() has been called" flag */
37 static int started = 0;
38
39 /**
40 * Initialise iPXE
41 *
42 * This function performs the one-time-only and irreversible
43 * initialisation steps, such as initialising the heap. It must be
44 * called before (almost) any other function.
45 *
46 * There is, by definition, no counterpart to this function on the
47 * shutdown path.
48 */
49 void initialise ( void ) {
50 struct init_fn *init_fn;
51
52 /* Call registered initialisation functions */
53 for_each_table_entry ( init_fn, INIT_FNS )
54 init_fn->initialise ();
55 }
56
57 /**
58 * Start up iPXE
59 *
60 * This function performs the repeatable initialisation steps, such as
61 * probing devices. You may call startup() and shutdown() multiple
62 * times (as is done via the PXE API when PXENV_START_UNDI is used).
63 */
64 void startup ( void ) {
65 struct startup_fn *startup_fn;
66
67 if ( started )
68 return;
69
70 /* Call registered startup functions */
71 for_each_table_entry ( startup_fn, STARTUP_FNS ) {
72 if ( startup_fn->startup )
73 startup_fn->startup();
74 }
75
76 started = 1;
77 }
78
79 /**
80 * Shut down iPXE
81 *
82 * @v flags Shutdown behaviour flags
83 *
84 * This function reverses the actions of startup(), and leaves iPXE in
85 * a state ready to be removed from memory. You may call startup()
86 * again after calling shutdown().
87 *
88 * Call this function only once, before either exiting main() or
89 * starting up a non-returnable image.
90 */
91 void shutdown ( int flags ) {
92 struct startup_fn *startup_fn;
93
94 if ( ! started )
95 return;
96
97 /* Call registered shutdown functions (in reverse order) */
98 for_each_table_entry_reverse ( startup_fn, STARTUP_FNS ) {
99 if ( startup_fn->shutdown )
100 startup_fn->shutdown ( flags );
101 }
102
103 /* Reset console */
104 console_reset();
105
106 started = 0;
107 }