efi_init.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
00026 EFI_HANDLE efi_image_handle;
00027
00028
00029 EFI_SYSTEM_TABLE *efi_systab;
00030
00031
00032
00033
00034
00035
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
00051
00052
00053
00054
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
00064 efi_image_handle = image_handle;
00065 efi_systab = systab;
00066
00067
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
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
00094 return efirc;
00095 }
00096 }
00097
00098
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 }