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 
00031 /**
00032  * EFI entry point
00033  *
00034  * @v image_handle      Image handle
00035  * @v systab            System table
00036  * @ret efirc           EFI return status code
00037  */
00038 EFI_STATUS EFIAPI _efi_start ( EFI_HANDLE image_handle,
00039                                EFI_SYSTEM_TABLE *systab ) {
00040         EFI_STATUS efirc;
00041         int rc;
00042 
00043         /* Initialise EFI environment */
00044         if ( ( efirc = efi_init ( image_handle, systab ) ) != 0 )
00045                 goto err_init;
00046 
00047         /* Record autoboot device (if any) */
00048         efi_set_autoboot();
00049 
00050         /* Claim SNP devices for use by iPXE */
00051         efi_snp_claim();
00052 
00053         /* Start watchdog holdoff timer */
00054         efi_watchdog_start();
00055 
00056         /* Call to main() */
00057         if ( ( rc = main() ) != 0 ) {
00058                 efirc = EFIRC ( rc );
00059                 goto err_main;
00060         }
00061 
00062  err_main:
00063         efi_watchdog_stop();
00064         efi_snp_release();
00065         efi_loaded_image->Unload ( image_handle );
00066         efi_driver_reconnect_all();
00067  err_init:
00068         return efirc;
00069 }
00070 
00071 /**
00072  * Probe EFI root bus
00073  *
00074  * @v rootdev           EFI root device
00075  */
00076 static int efi_probe ( struct root_device *rootdev __unused ) {
00077 
00078         return efi_driver_connect_all();
00079 }
00080 
00081 /**
00082  * Remove EFI root bus
00083  *
00084  * @v rootdev           EFI root device
00085  */
00086 static void efi_remove ( struct root_device *rootdev __unused ) {
00087 
00088         efi_driver_disconnect_all();
00089 }
00090 
00091 /** EFI root device driver */
00092 static struct root_driver efi_root_driver = {
00093         .probe = efi_probe,
00094         .remove = efi_remove,
00095 };
00096 
00097 /** EFI root device */
00098 struct root_device efi_root_device __root_device = {
00099         .dev = { .name = "EFI" },
00100         .driver = &efi_root_driver,
00101 };