/**
* Prepare for exit
*
- * @v flags Shutdown flags
+ * @v booting System is shutting down for OS boot
*/
-static void undionly_shutdown ( int flags ) {
+static void undionly_shutdown ( int booting ) {
/* If we are shutting down to boot an OS, clear the "keep PXE
* stack" flag.
*/
- if ( flags & SHUTDOWN_BOOT )
+ if ( booting )
preloaded_undi.flags &= ~UNDI_FL_KEEP_ALL;
}
bzimage_update_header ( image, &bzimg, bzimg.rm_kernel );
/* Prepare for exiting */
- shutdown ( SHUTDOWN_BOOT );
+ shutdown_boot();
DBGC ( image, "bzImage %p jumping to RM kernel at %04x:0000 "
"(stack %04x:%04zx)\n", image, ( bzimg.rm_kernel_seg + 0x20 ),
/* An ELF image has no callback interface, so we need to shut
* down before invoking it.
*/
- shutdown ( SHUTDOWN_BOOT );
+ shutdown_boot();
/* Jump to OS with flat physical addressing */
DBGC ( image, "ELF %p starting execution at %lx\n", image, entry );
/* Multiboot images may not return and have no callback
* interface, so shut everything down prior to booting the OS.
*/
- shutdown ( SHUTDOWN_BOOT );
+ shutdown_boot();
/* Build memory map after unhiding bootloader memory regions as part of
* shutting everything down.
/* Shut down now if NBI image will not return */
may_return = NBI_PROGRAM_RETURNS ( imgheader.flags );
if ( ! may_return )
- shutdown ( SHUTDOWN_BOOT );
+ shutdown_boot();
/* Execute NBI image */
if ( NBI_LINEAR_EXEC_ADDR ( imgheader.flags ) ) {
int13->cylinders, int13->heads, int13->sectors_per_track );
/* Hook INT 13 vector if not already hooked */
- if ( list_empty ( &int13s ) )
+ if ( list_empty ( &int13s ) ) {
int13_hook_vector();
+ devices_get();
+ }
/* Add to list of emulated drives */
list_add ( &int13->list, &int13s );
DBGC ( int13, "INT13 drive %02x unregistered\n", int13->drive );
/* Unhook INT 13 vector if no more drives */
- if ( list_empty ( &int13s ) )
+ if ( list_empty ( &int13s ) ) {
+ devices_put();
int13_unhook_vector();
+ }
/* Drop list's reference to drive */
ref_put ( &int13->refcnt );
if ( ! int_1a_hooked ) {
hook_bios_interrupt ( 0x1a, ( unsigned int ) pxe_int_1a,
&pxe_int_1a_vector );
+ devices_get();
int_1a_hooked = 1;
}
strerror ( rc ) );
return rc;
}
+ devices_put();
int_1a_hooked = 0;
}
pxe_deactivate();
/* Prepare for unload */
- shutdown ( SHUTDOWN_BOOT );
+ shutdown_boot();
/* Check to see if we still have any hooked interrupts */
if ( hooked_bios_interrupts != 0 ) {
break;
/* Perform final cleanup */
- shutdown ( SHUTDOWN_BOOT );
+ shutdown_boot();
/* Perform sequence of copies */
shuffle ( ix86->segs.es, ix86->regs.di, ix86->regs.cx );
break;
/* Perform final cleanup */
- shutdown ( SHUTDOWN_BOOT );
+ shutdown_boot();
/* Perform sequence of copies */
shuffle ( ix86->segs.es, ix86->regs.di, ix86->regs.cx );
/** Registered root devices */
static LIST_HEAD ( devices );
+/** Device removal inhibition counter */
+int device_keep_count = 0;
+
/**
* Probe a root device
*
* Remove all devices
*
*/
-static void remove_devices ( int flags ) {
+static void remove_devices ( int booting __unused ) {
struct root_device *rootdev;
struct root_device *tmp;
- if ( flags & SHUTDOWN_KEEP_DEVICES ) {
+ if ( device_keep_count != 0 ) {
DBG ( "Refusing to remove devices on shutdown\n" );
return;
}
shell();
}
- shutdown ( SHUTDOWN_EXIT | shutdown_exit_flags );
+ shutdown_exit();
return 0;
}
/**
* Prepare for exit
*
- * @v flags Shutdown flags
+ * @v booting System is shutting down for OS boot
*/
-static void snponly_shutdown ( int flags ) {
+static void snponly_shutdown ( int booting ) {
/* If we are shutting down to boot an OS, make sure the SNP does not
* stay active.
*/
- if ( flags & SHUTDOWN_BOOT )
+ if ( booting )
snponly_dev.removal_state = EfiSimpleNetworkStopped;
}
*/
static EFIAPI void efi_shutdown_hook ( EFI_EVENT event __unused,
void *context __unused ) {
- shutdown ( SHUTDOWN_BOOT );
+ shutdown_boot();
}
/**
/** Declare a root device */
#define __root_device __table_entry ( ROOT_DEVICES, 01 )
+extern int device_keep_count;
+
+/**
+ * Prevent devices from being removed on shutdown
+ *
+ */
+static inline void devices_get ( void ) {
+ device_keep_count++;
+}
+
+/**
+ * Allow devices to be removed on shutdown
+ *
+ */
+static inline void devices_put ( void ) {
+ device_keep_count--;
+}
+
extern struct device * identify_device ( struct interface *intf );
#define identify_device_TYPE( object_type ) \
typeof ( struct device * ( object_type ) )
/** @} */
-/** Shutdown flags */
-enum shutdown_flags {
- /** Shutdown is in order to exit (return to iPXE's caller) */
- SHUTDOWN_EXIT = 0x0001,
- /** Shutdown is in order to boot an OS */
- SHUTDOWN_BOOT = 0x0002,
- /** Do not remove devices */
- SHUTDOWN_KEEP_DEVICES = 0x0004,
-};
-
/**
* A startup/shutdown function
*
*/
struct startup_fn {
void ( * startup ) ( void );
- void ( * shutdown ) ( int flags );
+ void ( * shutdown ) ( int booting );
};
/** Startup/shutdown function table */
extern void initialise ( void );
extern void startup ( void );
-extern void shutdown ( int flags );
+extern void shutdown ( int booting );
+
+/**
+ * Shut down system for OS boot
+ *
+ */
+static inline void shutdown_boot ( void ) {
+ shutdown ( 1 );
+}
+
+/**
+ * Shut down system for exit back to firmware
+ *
+ */
+static inline void shutdown_exit ( void ) {
+ shutdown ( 0 );
+}
#endif /* _IPXE_INIT_H */
#include <ipxe/in.h>
struct net_device;
-extern int shutdown_exit_flags;
-
extern int netboot ( struct net_device *netdev );
extern int autoboot ( void );
extern int boot_next_server_and_filename ( struct in_addr next_server,
*
*/
-/** Shutdown flags for exit */
-int shutdown_exit_flags = 0;
-
/**
* Perform PXE menu boot when PXE stack is not available
*/
if ( fetch_intz_setting ( NULL, &keep_san_setting ) != 0 ) {
printf ( "Preserving connection to SAN device %#02x\n",
drive );
- shutdown_exit_flags |= SHUTDOWN_KEEP_DEVICES;
goto err_keep_san;
}