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.

efiprefix.c 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Copyright (C) 2009 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 <stdlib.h>
  21. #include <errno.h>
  22. #include <ipxe/device.h>
  23. #include <ipxe/efi/efi.h>
  24. #include <ipxe/efi/efi_driver.h>
  25. #include <ipxe/efi/efi_snp.h>
  26. #include <ipxe/efi/efi_autoboot.h>
  27. #include <ipxe/efi/efi_watchdog.h>
  28. #include <ipxe/efi/efi_blacklist.h>
  29. /**
  30. * EFI entry point
  31. *
  32. * @v image_handle Image handle
  33. * @v systab System table
  34. * @ret efirc EFI return status code
  35. */
  36. EFI_STATUS EFIAPI _efi_start ( EFI_HANDLE image_handle,
  37. EFI_SYSTEM_TABLE *systab ) {
  38. EFI_STATUS efirc;
  39. int rc;
  40. /* Initialise EFI environment */
  41. if ( ( efirc = efi_init ( image_handle, systab ) ) != 0 )
  42. goto err_init;
  43. /* Record autoboot device (if any) */
  44. efi_set_autoboot();
  45. /* Claim SNP devices for use by iPXE */
  46. efi_snp_claim();
  47. /* Start watchdog holdoff timer */
  48. efi_watchdog_start();
  49. /* Call to main() */
  50. if ( ( rc = main() ) != 0 ) {
  51. efirc = EFIRC ( rc );
  52. goto err_main;
  53. }
  54. err_main:
  55. efi_watchdog_stop();
  56. efi_snp_release();
  57. efi_loaded_image->Unload ( image_handle );
  58. efi_driver_reconnect_all();
  59. err_init:
  60. return efirc;
  61. }
  62. /**
  63. * Probe EFI root bus
  64. *
  65. * @v rootdev EFI root device
  66. */
  67. static int efi_probe ( struct root_device *rootdev __unused ) {
  68. /* Unloaded any blacklisted drivers */
  69. efi_unload_blacklist();
  70. /* Connect our drivers */
  71. return efi_driver_connect_all();
  72. }
  73. /**
  74. * Remove EFI root bus
  75. *
  76. * @v rootdev EFI root device
  77. */
  78. static void efi_remove ( struct root_device *rootdev __unused ) {
  79. /* Disconnect our drivers */
  80. efi_driver_disconnect_all();
  81. }
  82. /** EFI root device driver */
  83. static struct root_driver efi_root_driver = {
  84. .probe = efi_probe,
  85. .remove = efi_remove,
  86. };
  87. /** EFI root device */
  88. struct root_device efi_root_device __root_device = {
  89. .dev = { .name = "EFI" },
  90. .driver = &efi_root_driver,
  91. };