]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[init] Remove concept of "shutdown exit flags"
authorMichael Brown <mcb30@ipxe.org>
Thu, 27 Jan 2011 20:35:48 +0000 (20:35 +0000)
committerMichael Brown <mcb30@ipxe.org>
Thu, 27 Jan 2011 20:40:26 +0000 (20:40 +0000)
Remove the concept of shutdown exit flags, and replace it with a
counter used to keep track of exposed interfaces that require devices
to remain active.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
17 files changed:
src/arch/i386/drivers/net/undionly.c
src/arch/i386/image/bzimage.c
src/arch/i386/image/elfboot.c
src/arch/i386/image/multiboot.c
src/arch/i386/image/nbi.c
src/arch/i386/interface/pcbios/int13.c
src/arch/i386/interface/pxe/pxe_call.c
src/arch/i386/interface/pxe/pxe_preboot.c
src/arch/i386/interface/syslinux/comboot_call.c
src/core/device.c
src/core/main.c
src/drivers/net/efi/snponly.c
src/image/efi_image.c
src/include/ipxe/device.h
src/include/ipxe/init.h
src/include/usr/autoboot.h
src/usr/autoboot.c

index ab9c61fb12692af41a11870318af57c8df069b1a..c38b574dbc433a8c1f7435d1bc7cd2839b1d9427 100644 (file)
@@ -114,13 +114,13 @@ struct root_device undi_root_device __root_device = {
 /**
  * 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;
 }
 
index 900e34e1a5f956d2c0f011c5d51b29f7f59d3d8c..45a1e8620b52f8ced129fadfa7c052a497228730 100644 (file)
@@ -477,7 +477,7 @@ static int bzimage_exec ( struct image *image ) {
        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 ),
index 7cb51bf9ad34c5577d72bba41cc82a574c3fc067..331d3764c77e9d79ec2b92d4eaaa5e5bf5828c8d 100644 (file)
@@ -48,7 +48,7 @@ static int elfboot_exec ( struct image *image ) {
        /* 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 );
index 041f0f2ae4b02db32fa322c032f292b426a80494..3ed4d84077de65616553284e860d457a670be1cb 100644 (file)
@@ -278,7 +278,7 @@ static int multiboot_exec ( struct image *image ) {
        /* 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.
index 67f0d5111ba57163b15378c0b664c92dca29a153..804b230371ecf914be211173eff9d02393c2f75a 100644 (file)
@@ -406,7 +406,7 @@ static int nbi_exec ( struct image *image ) {
        /* 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 ) ) {
index 1d973e77808cdf86b5827be287c49843ffdef440..a27dbad7a00ebbfc2f09d895709baac26588fc9a 100644 (file)
@@ -1209,8 +1209,10 @@ static int int13_hook ( struct uri *uri, unsigned int drive ) {
               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 );
@@ -1277,8 +1279,10 @@ static void int13_unhook ( unsigned int drive ) {
        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 );
index f6324bbf638b93c247713cd184fe0ab8ed34d3ac..f320800068b8b263a34499a537c1c90c624d9048 100644 (file)
@@ -448,6 +448,7 @@ void pxe_activate ( struct net_device *netdev ) {
        if ( ! int_1a_hooked ) {
                hook_bios_interrupt ( 0x1a, ( unsigned int ) pxe_int_1a,
                                      &pxe_int_1a_vector );
+               devices_get();
                int_1a_hooked = 1;
        }
 
@@ -475,6 +476,7 @@ int pxe_deactivate ( void ) {
                              strerror ( rc ) );
                        return rc;
                }
+               devices_put();
                int_1a_hooked = 0;
        }
 
index 7698df52875a7accbe4e3107e37cb84fa9e5973b..9e4853b0140ade0dc2c4f017133527af9187153a 100644 (file)
@@ -290,7 +290,7 @@ PXENV_EXIT_t pxenv_stop_undi ( struct s_PXENV_STOP_UNDI *stop_undi ) {
        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 ) {
index 0c52b28a8b7c8ccf361005ab466b80d2ae6a4774..950832702f0b001e429a39019bd2bc3c71ae03b0 100644 (file)
@@ -531,7 +531,7 @@ static __asmcall void int22 ( struct i386_all_regs *ix86 ) {
                        break;
 
                /* Perform final cleanup */
-               shutdown ( SHUTDOWN_BOOT );
+               shutdown_boot();
 
                /* Perform sequence of copies */
                shuffle ( ix86->segs.es, ix86->regs.di, ix86->regs.cx );
@@ -608,7 +608,7 @@ static __asmcall void int22 ( struct i386_all_regs *ix86 ) {
                        break;
 
                /* Perform final cleanup */
-               shutdown ( SHUTDOWN_BOOT );
+               shutdown_boot();
 
                /* Perform sequence of copies */
                shuffle ( ix86->segs.es, ix86->regs.di, ix86->regs.cx );
index cb2c23b0acfd3a9454c995a9edfea22b2e4d4fa4..dc182e032505a4c87785f6f6ad4809aafcdb4741 100644 (file)
@@ -35,6 +35,9 @@ FILE_LICENCE ( GPL2_OR_LATER );
 /** Registered root devices */
 static LIST_HEAD ( devices );
 
+/** Device removal inhibition counter */
+int device_keep_count = 0;
+
 /**
  * Probe a root device
  *
@@ -87,11 +90,11 @@ static void probe_devices ( void ) {
  * 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;
        }
index a1128dd0261deccfd717c8b0384868cf1bee4245..e2b4e3e2e7bb96a9d89f9d60b149886a520942b6 100644 (file)
@@ -85,7 +85,7 @@ __asmcall int main ( void ) {
                        shell();
        }
 
-       shutdown ( SHUTDOWN_EXIT | shutdown_exit_flags );
+       shutdown_exit();
 
        return 0;
 }
index 435ed4fb597416831c95134fc7d3841cba5803cc..6fcc54a0193a1491051f80be17ae33f19b5bfae6 100644 (file)
@@ -114,13 +114,13 @@ struct root_device snp_root_device __root_device = {
 /**
  * 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;
 }
 
index 6b6600de8033b73229cdcfac9683b81ecb54b001..bf2e6f4af1734b9a818518830eaeb5a73fc2d347 100644 (file)
@@ -39,7 +39,7 @@ static EFI_EVENT efi_shutdown_event;
  */
 static EFIAPI void efi_shutdown_hook ( EFI_EVENT event __unused,
                                       void *context __unused ) {
-       shutdown ( SHUTDOWN_BOOT );
+       shutdown_boot();
 }
 
 /**
index 068268ba48eadc4f39536a14f102bb4531b1c430..635ce59cc70322f70521286ec8568760370ea5f7 100644 (file)
@@ -112,6 +112,24 @@ struct root_driver {
 /** 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 ) )
index 10ff8695dddbbbbe8a781062be36830a89af1ab9..954cda45374bb17b6e5c067f89f950bf2b4c2c76 100644 (file)
@@ -32,16 +32,6 @@ struct init_fn {
 
 /** @} */
 
-/** 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
  *
@@ -50,7 +40,7 @@ enum shutdown_flags {
  */
 struct startup_fn {
        void ( * startup ) ( void );
-       void ( * shutdown ) ( int flags );
+       void ( * shutdown ) ( int booting );
 };
 
 /** Startup/shutdown function table */
@@ -76,6 +66,22 @@ struct startup_fn {
 
 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 */
index e9abf833f684db2aeb9eb898c6bd8ebfe4bf8733..32763beee85fb7bb0a590561f2e8bd22111f5e61 100644 (file)
@@ -12,8 +12,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
 #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,
index 738c3ceaaf9f739aead37579baa44ab104b34e86..df152e3ac7142bd0fb3f3bb44172f1607f970cc2 100644 (file)
@@ -40,9 +40,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
  *
  */
 
-/** Shutdown flags for exit */
-int shutdown_exit_flags = 0;
-
 /**
  * Perform PXE menu boot when PXE stack is not available
  */
@@ -193,7 +190,6 @@ int boot_root_path ( const char *root_path ) {
        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;
        }