efi_init.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2008 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., 675 Mass Ave, Cambridge, MA 02139, USA.
00017  */
00018 
00019 FILE_LICENCE ( GPL2_OR_LATER );
00020 
00021 #include <string.h>
00022 #include <gpxe/efi/efi.h>
00023 #include <gpxe/uuid.h>
00024 
00025 /** Image handle passed to entry point */
00026 EFI_HANDLE efi_image_handle;
00027 
00028 /** System table passed to entry point */
00029 EFI_SYSTEM_TABLE *efi_systab;
00030 
00031 /**
00032  * Look up EFI configuration table
00033  *
00034  * @v guid              Configuration table GUID
00035  * @ret table           Configuration table, or NULL
00036  */
00037 static void * efi_find_table ( EFI_GUID *guid ) {
00038         unsigned int i;
00039 
00040         for ( i = 0 ; i < efi_systab->NumberOfTableEntries ; i++ ) {
00041                 if ( memcmp ( &efi_systab->ConfigurationTable[i].VendorGuid,
00042                               guid, sizeof ( *guid ) ) == 0 )
00043                         return efi_systab->ConfigurationTable[i].VendorTable;
00044         }
00045 
00046         return NULL;
00047 }
00048 
00049 /**
00050  * Initialise EFI environment
00051  *
00052  * @v image_handle      Image handle
00053  * @v systab            System table
00054  * @ret efirc           EFI return status code
00055  */
00056 EFI_STATUS efi_init ( EFI_HANDLE image_handle,
00057                       EFI_SYSTEM_TABLE *systab ) {
00058         EFI_BOOT_SERVICES *bs;
00059         struct efi_protocol *prot;
00060         struct efi_config_table *tab;
00061         EFI_STATUS efirc;
00062 
00063         /* Store image handle and system table pointer for future use */
00064         efi_image_handle = image_handle;
00065         efi_systab = systab;
00066 
00067         /* Sanity checks */
00068         if ( ! systab )
00069                 return EFI_NOT_AVAILABLE_YET;
00070         if ( ! systab->ConOut )
00071                 return EFI_NOT_AVAILABLE_YET;
00072         if ( ! systab->BootServices ) {
00073                 DBGC ( systab, "EFI provided no BootServices entry point\n" );
00074                 return EFI_NOT_AVAILABLE_YET;
00075         }
00076         if ( ! systab->RuntimeServices ) {
00077                 DBGC ( systab, "EFI provided no RuntimeServices entry "
00078                        "point\n" );
00079                 return EFI_NOT_AVAILABLE_YET;
00080         }
00081         DBGC ( systab, "EFI handle %p systab %p\n", image_handle, systab );
00082 
00083         /* Look up used protocols */
00084         bs = systab->BootServices;
00085         for_each_table_entry ( prot, EFI_PROTOCOLS ) {
00086                 if ( ( efirc = bs->LocateProtocol ( &prot->u.guid, NULL,
00087                                                     prot->protocol ) ) == 0 ) {
00088                         DBGC ( systab, "EFI protocol %s is at %p\n",
00089                                uuid_ntoa ( &prot->u.uuid ), *(prot->protocol));
00090                 } else {
00091                         DBGC ( systab, "EFI does not provide protocol %s\n",
00092                                uuid_ntoa ( &prot->u.uuid ) );
00093                         /* All protocols are required */
00094                         return efirc;
00095                 }
00096         }
00097 
00098         /* Look up used configuration tables */
00099         for_each_table_entry ( tab, EFI_CONFIG_TABLES ) {
00100                 if ( ( *(tab->table) = efi_find_table ( &tab->u.guid ) ) ) {
00101                         DBGC ( systab, "EFI configuration table %s is at %p\n",
00102                                uuid_ntoa ( &tab->u.uuid ), *(tab->table) );
00103                 } else {
00104                         DBGC ( systab, "EFI does not provide configuration "
00105                                "table %s\n", uuid_ntoa ( &tab->u.uuid ) );
00106                         if ( tab->required )
00107                                 return EFI_NOT_AVAILABLE_YET;
00108                 }
00109         }
00110 
00111         return 0;
00112 }

Generated on Tue Apr 6 20:01:09 2010 for gPXE by  doxygen 1.5.7.1