iPXE
efi_watchdog.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2015 Michael Brown <mbrown@fensystems.co.uk>.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301, USA.
00018  *
00019  * You can also choose to distribute this program under the terms of
00020  * the Unmodified Binary Distribution Licence (as given in the file
00021  * COPYING.UBDL), provided that you have satisfied its requirements.
00022  */
00023 
00024 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00025 
00026 /**
00027  * @file
00028  *
00029  * EFI watchdog holdoff timer
00030  *
00031  */
00032 
00033 #include <errno.h>
00034 #include <string.h>
00035 #include <ipxe/retry.h>
00036 #include <ipxe/timer.h>
00037 #include <ipxe/efi/efi.h>
00038 #include <ipxe/efi/efi_watchdog.h>
00039 
00040 /** Watchdog holdoff interval (in seconds) */
00041 #define WATCHDOG_HOLDOFF_SECS 10
00042 
00043 /** Watchdog timeout (in seconds) */
00044 #define WATCHDOG_TIMEOUT_SECS ( 5 * 60 )
00045 
00046 /** Watchdog code (to be logged on watchdog timeout) */
00047 #define WATCHDOG_CODE 0x6950584544454144ULL
00048 
00049 /** Watchdog data (to be logged on watchdog timeout) */
00050 #define WATCHDOG_DATA L"iPXE";
00051 
00052 /**
00053  * Hold off watchdog timer
00054  *
00055  * @v retry             Retry timer
00056  * @v over              Failure indicator
00057  */
00058 static void efi_watchdog_expired ( struct retry_timer *timer,
00059                                    int over __unused ) {
00060         EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
00061         static CHAR16 data[] = WATCHDOG_DATA;
00062         EFI_STATUS efirc;
00063         int rc;
00064 
00065         DBGC2 ( timer, "EFI holding off watchdog timer\n" );
00066 
00067         /* Restart this holdoff timer */
00068         start_timer_fixed ( timer, ( WATCHDOG_HOLDOFF_SECS * TICKS_PER_SEC ) );
00069 
00070         /* Reset watchdog timer */
00071         if ( ( efirc = bs->SetWatchdogTimer ( WATCHDOG_TIMEOUT_SECS,
00072                                               WATCHDOG_CODE, sizeof ( data ),
00073                                               data ) ) != 0 ) {
00074                 rc = -EEFI ( efirc );
00075                 DBGC ( timer, "EFI could not set watchdog timer: %s\n",
00076                        strerror ( rc ) );
00077                 return;
00078         }
00079 }
00080 
00081 /** Watchdog holdoff timer */
00082 struct retry_timer efi_watchdog = TIMER_INIT ( efi_watchdog_expired );