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 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  24. #include <ipxe/device.h>
  25. #include <ipxe/console.h>
  26. #include <ipxe/init.h>
  27. /** @file
  28. *
  29. * Initialisation, startup and shutdown routines
  30. *
  31. */
  32. /** "startup() has been called" flag */
  33. static int started = 0;
  34. /** Colour for debug messages */
  35. #define colour table_start ( INIT_FNS )
  36. /**
  37. * Initialise iPXE
  38. *
  39. * This function performs the one-time-only and irreversible
  40. * initialisation steps, such as initialising the heap. It must be
  41. * called before (almost) any other function.
  42. *
  43. * There is, by definition, no counterpart to this function on the
  44. * shutdown path.
  45. */
  46. void initialise ( void ) {
  47. struct init_fn *init_fn;
  48. /* Call registered initialisation functions */
  49. for_each_table_entry ( init_fn, INIT_FNS )
  50. init_fn->initialise ();
  51. }
  52. /**
  53. * Start up iPXE
  54. *
  55. * This function performs the repeatable initialisation steps, such as
  56. * probing devices. You may call startup() and shutdown() multiple
  57. * times (as is done via the PXE API when PXENV_START_UNDI is used).
  58. */
  59. void startup ( void ) {
  60. struct startup_fn *startup_fn;
  61. if ( started )
  62. return;
  63. /* Call registered startup functions */
  64. for_each_table_entry ( startup_fn, STARTUP_FNS ) {
  65. if ( startup_fn->startup ) {
  66. DBGC ( colour, "INIT startup %s...\n",
  67. startup_fn->name );
  68. startup_fn->startup();
  69. }
  70. }
  71. started = 1;
  72. DBGC ( colour, "INIT startup complete\n" );
  73. }
  74. /**
  75. * Shut down iPXE
  76. *
  77. * @v flags Shutdown behaviour flags
  78. *
  79. * This function reverses the actions of startup(), and leaves iPXE in
  80. * a state ready to be removed from memory. You may call startup()
  81. * again after calling shutdown().
  82. *
  83. * Call this function only once, before either exiting main() or
  84. * starting up a non-returnable image.
  85. */
  86. void shutdown ( int flags ) {
  87. struct startup_fn *startup_fn;
  88. if ( ! started )
  89. return;
  90. /* Call registered shutdown functions (in reverse order) */
  91. for_each_table_entry_reverse ( startup_fn, STARTUP_FNS ) {
  92. if ( startup_fn->shutdown ) {
  93. DBGC ( colour, "INIT shutdown %s...\n",
  94. startup_fn->name );
  95. startup_fn->shutdown ( flags );
  96. }
  97. }
  98. /* Reset console */
  99. console_reset();
  100. started = 0;
  101. DBGC ( colour, "INIT shutdown complete\n" );
  102. }