[reboot] Generalise warm reboot indicator to a flags bitmask

Allow for the possibility of additional reboot types by extending the
reboot() function to use a flags bitmask rather than a single flag.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2025-04-28 13:42:32 +01:00
parent ba2135d0fd
commit 7eaa2daf6f
6 changed files with 24 additions and 15 deletions

View File

@@ -37,13 +37,15 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** /**
* Reboot system * Reboot system
* *
* @v warm Perform a warm reboot * @v flags Reboot flags
*/ */
static void sbi_reboot ( int warm ) { static void sbi_reboot ( int flags ) {
struct sbi_return ret; struct sbi_return ret;
int warm;
int rc; int rc;
/* Reboot system */ /* Reboot system */
warm = ( flags & REBOOT_WARM );
ret = sbi_ecall_2 ( SBI_SRST, SBI_SRST_SYSTEM_RESET, ret = sbi_ecall_2 ( SBI_SRST, SBI_SRST_SYSTEM_RESET,
( warm ? SBI_RESET_WARM : SBI_RESET_COLD ), 0 ); ( warm ? SBI_RESET_WARM : SBI_RESET_COLD ), 0 );

View File

@@ -38,14 +38,14 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** /**
* Reboot system * Reboot system
* *
* @v warm Perform a warm reboot * @v flags Reboot flags
*/ */
static void bios_reboot ( int warm ) { static void bios_reboot ( int flags ) {
uint16_t flag; uint16_t type;
/* Configure BIOS for cold/warm reboot */ /* Configure BIOS for cold/warm reboot */
flag = ( warm ? BDA_REBOOT_WARM : 0 ); type = ( ( flags & REBOOT_WARM ) ? BDA_REBOOT_WARM : 0 );
put_real ( flag, BDA_SEG, BDA_REBOOT ); put_real ( type, BDA_SEG, BDA_REBOOT );
/* Jump to system reset vector */ /* Jump to system reset vector */
__asm__ __volatile__ ( REAL_CODE ( "ljmp $0xf000, $0xfff0" ) : ); __asm__ __volatile__ ( REAL_CODE ( "ljmp $0xf000, $0xfff0" ) : );

View File

@@ -37,9 +37,9 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** /**
* Reboot system * Reboot system
* *
* @v warm Perform a warm reboot * @v flags Reboot flags
*/ */
static void null_reboot ( int warm __unused ) { static void null_reboot ( int flags __unused ) {
printf ( "Cannot reboot; not implemented\n" ); printf ( "Cannot reboot; not implemented\n" );
while ( 1 ) {} while ( 1 ) {}

View File

@@ -59,6 +59,7 @@ static struct command_descriptor reboot_cmd =
*/ */
static int reboot_exec ( int argc, char **argv ) { static int reboot_exec ( int argc, char **argv ) {
struct reboot_options opts; struct reboot_options opts;
int flags = 0;
int rc; int rc;
/* Parse options */ /* Parse options */
@@ -66,7 +67,9 @@ static int reboot_exec ( int argc, char **argv ) {
return rc; return rc;
/* Reboot system */ /* Reboot system */
reboot ( opts.warm ); if ( opts.warm )
flags |= REBOOT_WARM;
reboot ( flags );
return 0; return 0;
} }

View File

@@ -51,9 +51,11 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** /**
* Reboot system * Reboot system
* *
* @v warm Perform a warm reboot * @v flags Reboot flags
*/ */
void reboot ( int warm ); void reboot ( int flags );
#define REBOOT_WARM 0x00000001 /**< Perform a warm reboot */
/** /**
* Power off system * Power off system

View File

@@ -37,13 +37,15 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** /**
* Reboot system * Reboot system
* *
* @v warm Perform a warm reboot * @v flags Reboot flags
*/ */
static void efi_reboot ( int warm ) { static void efi_reboot ( int flags ) {
EFI_RUNTIME_SERVICES *rs = efi_systab->RuntimeServices; EFI_RUNTIME_SERVICES *rs = efi_systab->RuntimeServices;
EFI_RESET_TYPE type;
/* Use runtime services to reset system */ /* Use runtime services to reset system */
rs->ResetSystem ( ( warm ? EfiResetWarm : EfiResetCold ), 0, 0, NULL ); type = ( ( flags & REBOOT_WARM ) ? EfiResetWarm : EfiResetCold );
rs->ResetSystem ( type, 0, 0, NULL );
} }
/** /**