You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. FILE_LICENCE ( GPL2_OR_LATER );
  19. #include <gpxe/device.h>
  20. #include <gpxe/init.h>
  21. /** @file
  22. *
  23. * Initialisation, startup and shutdown routines
  24. *
  25. */
  26. /** "startup() has been called" flag */
  27. static int started = 0;
  28. /**
  29. * Initialise gPXE
  30. *
  31. * This function performs the one-time-only and irreversible
  32. * initialisation steps, such as initialising the heap. It must be
  33. * called before (almost) any other function.
  34. *
  35. * There is, by definition, no counterpart to this function on the
  36. * shutdown path.
  37. */
  38. void initialise ( void ) {
  39. struct init_fn *init_fn;
  40. /* Call registered initialisation functions */
  41. for_each_table_entry ( init_fn, INIT_FNS )
  42. init_fn->initialise ();
  43. }
  44. /**
  45. * Start up gPXE
  46. *
  47. * This function performs the repeatable initialisation steps, such as
  48. * probing devices. You may call startup() and shutdown() multiple
  49. * times (as is done via the PXE API when PXENV_START_UNDI is used).
  50. */
  51. void startup ( void ) {
  52. struct startup_fn *startup_fn;
  53. if ( started )
  54. return;
  55. /* Call registered startup functions */
  56. for_each_table_entry ( startup_fn, STARTUP_FNS ) {
  57. if ( startup_fn->startup )
  58. startup_fn->startup();
  59. }
  60. started = 1;
  61. }
  62. /**
  63. * Shut down gPXE
  64. *
  65. * @v flags Shutdown behaviour flags
  66. *
  67. * This function reverses the actions of startup(), and leaves gPXE in
  68. * a state ready to be removed from memory. You may call startup()
  69. * again after calling shutdown().
  70. *
  71. * Call this function only once, before either exiting main() or
  72. * starting up a non-returnable image.
  73. */
  74. void shutdown ( int flags ) {
  75. struct startup_fn *startup_fn;
  76. if ( ! started )
  77. return;
  78. /* Call registered shutdown functions (in reverse order) */
  79. for_each_table_entry_reverse ( startup_fn, STARTUP_FNS ) {
  80. if ( startup_fn->shutdown )
  81. startup_fn->shutdown ( flags );
  82. }
  83. started = 0;
  84. }