Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

init.c 2.6KB

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