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.

init.c 2.5KB

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