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.

efi_watchdog.c 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright (C) 2015 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. /**
  25. * @file
  26. *
  27. * EFI watchdog holdoff timer
  28. *
  29. */
  30. #include <errno.h>
  31. #include <string.h>
  32. #include <ipxe/retry.h>
  33. #include <ipxe/timer.h>
  34. #include <ipxe/efi/efi.h>
  35. #include <ipxe/efi/efi_watchdog.h>
  36. /** Watchdog holdoff interval (in seconds) */
  37. #define WATCHDOG_HOLDOFF_SECS 10
  38. /** Watchdog timeout (in seconds) */
  39. #define WATCHDOG_TIMEOUT_SECS ( 5 * 60 )
  40. /** Watchdog code (to be logged on watchdog timeout) */
  41. #define WATCHDOG_CODE 0x6950584544454144ULL
  42. /** Watchdog data (to be logged on watchdog timeout) */
  43. #define WATCHDOG_DATA L"iPXE";
  44. /**
  45. * Hold off watchdog timer
  46. *
  47. * @v retry Retry timer
  48. * @v over Failure indicator
  49. */
  50. static void efi_watchdog_expired ( struct retry_timer *timer,
  51. int over __unused ) {
  52. EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
  53. static CHAR16 data[] = WATCHDOG_DATA;
  54. EFI_STATUS efirc;
  55. int rc;
  56. DBGC2 ( timer, "EFI holding off watchdog timer\n" );
  57. /* Restart this holdoff timer */
  58. start_timer_fixed ( timer, ( WATCHDOG_HOLDOFF_SECS * TICKS_PER_SEC ) );
  59. /* Reset watchdog timer */
  60. if ( ( efirc = bs->SetWatchdogTimer ( WATCHDOG_TIMEOUT_SECS,
  61. WATCHDOG_CODE, sizeof ( data ),
  62. data ) ) != 0 ) {
  63. rc = -EEFI ( efirc );
  64. DBGC ( timer, "EFI could not set watchdog timer: %s\n",
  65. strerror ( rc ) );
  66. return;
  67. }
  68. }
  69. /** Watchdog holdoff timer */
  70. struct retry_timer efi_watchdog = TIMER_INIT ( efi_watchdog_expired );