init.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017  */
00018 
00019 FILE_LICENCE ( GPL2_OR_LATER );
00020 
00021 #include <gpxe/device.h>
00022 #include <gpxe/init.h>
00023 
00024 /** @file
00025  *
00026  * Initialisation, startup and shutdown routines
00027  *
00028  */
00029 
00030 /** "startup() has been called" flag */
00031 static int started = 0;
00032 
00033 /**
00034  * Initialise gPXE
00035  *
00036  * This function performs the one-time-only and irreversible
00037  * initialisation steps, such as initialising the heap.  It must be
00038  * called before (almost) any other function.
00039  *
00040  * There is, by definition, no counterpart to this function on the
00041  * shutdown path.
00042  */
00043 void initialise ( void ) {
00044         struct init_fn *init_fn;
00045 
00046         /* Call registered initialisation functions */
00047         for_each_table_entry ( init_fn, INIT_FNS )
00048                 init_fn->initialise ();
00049 }
00050 
00051 /**
00052  * Start up gPXE
00053  *
00054  * This function performs the repeatable initialisation steps, such as
00055  * probing devices.  You may call startup() and shutdown() multiple
00056  * times (as is done via the PXE API when PXENV_START_UNDI is used).
00057  */
00058 void startup ( void ) {
00059         struct startup_fn *startup_fn;
00060 
00061         if ( started )
00062                 return;
00063 
00064         /* Call registered startup functions */
00065         for_each_table_entry ( startup_fn, STARTUP_FNS ) {
00066                 if ( startup_fn->startup )
00067                         startup_fn->startup();
00068         }
00069 
00070         started = 1;
00071 }
00072 
00073 /**
00074  * Shut down gPXE
00075  *
00076  * @v flags             Shutdown behaviour flags
00077  *
00078  * This function reverses the actions of startup(), and leaves gPXE in
00079  * a state ready to be removed from memory.  You may call startup()
00080  * again after calling shutdown().
00081  *
00082  * Call this function only once, before either exiting main() or
00083  * starting up a non-returnable image.
00084  */
00085 void shutdown ( int flags ) {
00086         struct startup_fn *startup_fn;
00087 
00088         if ( ! started )
00089                 return;
00090 
00091         /* Call registered shutdown functions (in reverse order) */
00092         for_each_table_entry_reverse ( startup_fn, STARTUP_FNS ) {
00093                 if ( startup_fn->shutdown )
00094                         startup_fn->shutdown ( flags );
00095         }
00096 
00097         started = 0;
00098 }

Generated on Tue Apr 6 20:00:51 2010 for gPXE by  doxygen 1.5.7.1