iPXE
efiprefix.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2009 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 
00020 FILE_LICENCE ( GPL2_OR_LATER );
00021 
00022 #include <stdlib.h>
00023 #include <errno.h>
00024 #include <ipxe/device.h>
00025 #include <ipxe/efi/efi.h>
00026 #include <ipxe/efi/efi_driver.h>
00027 #include <ipxe/efi/efi_snp.h>
00028 #include <ipxe/efi/efi_autoboot.h>
00029 #include <ipxe/efi/efi_watchdog.h>
00030 #include <ipxe/efi/efi_blacklist.h>
00031 
00032 /**
00033  * EFI entry point
00034  *
00035  * @v image_handle      Image handle
00036  * @v systab            System table
00037  * @ret efirc           EFI return status code
00038  */
00039 EFI_STATUS EFIAPI _efi_start ( EFI_HANDLE image_handle,
00040                                EFI_SYSTEM_TABLE *systab ) {
00041         EFI_STATUS efirc;
00042         int rc;
00043 
00044         /* Initialise EFI environment */
00045         if ( ( efirc = efi_init ( image_handle, systab ) ) != 0 )
00046                 goto err_init;
00047 
00048         /* Record autoboot device (if any) */
00049         efi_set_autoboot();
00050 
00051         /* Claim SNP devices for use by iPXE */
00052         efi_snp_claim();
00053 
00054         /* Start watchdog holdoff timer */
00055         efi_watchdog_start();
00056 
00057         /* Call to main() */
00058         if ( ( rc = main() ) != 0 ) {
00059                 efirc = EFIRC ( rc );
00060                 goto err_main;
00061         }
00062 
00063  err_main:
00064         efi_watchdog_stop();
00065         efi_snp_release();
00066         efi_loaded_image->Unload ( image_handle );
00067         efi_driver_reconnect_all();
00068  err_init:
00069         return efirc;
00070 }
00071 
00072 /**
00073  * Probe EFI root bus
00074  *
00075  * @v rootdev           EFI root device
00076  */
00077 static int efi_probe ( struct root_device *rootdev __unused ) {
00078 
00079         /* Unloaded any blacklisted drivers */
00080         efi_unload_blacklist();
00081 
00082         /* Connect our drivers */
00083         return efi_driver_connect_all();
00084 }
00085 
00086 /**
00087  * Remove EFI root bus
00088  *
00089  * @v rootdev           EFI root device
00090  */
00091 static void efi_remove ( struct root_device *rootdev __unused ) {
00092 
00093         /* Disconnect our drivers */
00094         efi_driver_disconnect_all();
00095 }
00096 
00097 /** EFI root device driver */
00098 static struct root_driver efi_root_driver = {
00099         .probe = efi_probe,
00100         .remove = efi_remove,
00101 };
00102 
00103 /** EFI root device */
00104 struct root_device efi_root_device __root_device = {
00105         .dev = { .name = "EFI" },
00106         .driver = &efi_root_driver,
00107 };