These changes are the raw update to qemu-2.6.
[kvmfornfv.git] / qemu / roms / ipxe / src / interface / efi / efi_debug.c
1 /*
2  * Copyright (C) 2013 Michael Brown <mbrown@fensystems.co.uk>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  *
19  * You can also choose to distribute this program under the terms of
20  * the Unmodified Binary Distribution Licence (as given in the file
21  * COPYING.UBDL), provided that you have satisfied its requirements.
22  */
23
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25
26 /**
27  * @file
28  *
29  * EFI debugging utilities
30  *
31  */
32
33 #include <stdio.h>
34 #include <string.h>
35 #include <errno.h>
36 #include <ipxe/uuid.h>
37 #include <ipxe/base16.h>
38 #include <ipxe/efi/efi.h>
39 #include <ipxe/efi/efi_utils.h>
40 #include <ipxe/efi/Protocol/ComponentName.h>
41 #include <ipxe/efi/Protocol/ComponentName2.h>
42 #include <ipxe/efi/Protocol/DevicePathToText.h>
43 #include <ipxe/efi/IndustryStandard/PeImage.h>
44
45 /** Device path to text protocol */
46 static EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *efidpt;
47 EFI_REQUEST_PROTOCOL ( EFI_DEVICE_PATH_TO_TEXT_PROTOCOL, &efidpt );
48
49 /** Iscsi4Dxe module GUID */
50 static EFI_GUID efi_iscsi4_dxe_guid = {
51         0x4579b72d, 0x7ec4, 0x4dd4,
52         { 0x84, 0x86, 0x08, 0x3c, 0x86, 0xb1, 0x82, 0xa7 }
53 };
54
55 /** VlanConfigDxe module GUID */
56 static EFI_GUID efi_vlan_config_dxe_guid = {
57         0xe4f61863, 0xfe2c, 0x4b56,
58         { 0xa8, 0xf4, 0x08, 0x51, 0x9b, 0xc4, 0x39, 0xdf }
59 };
60
61 /** A well-known GUID */
62 struct efi_well_known_guid {
63         /** GUID */
64         EFI_GUID *guid;
65         /** Name */
66         const char *name;
67 };
68
69 /** Well-known GUIDs */
70 static struct efi_well_known_guid efi_well_known_guids[] = {
71         { &efi_arp_protocol_guid,
72           "Arp" },
73         { &efi_arp_service_binding_protocol_guid,
74           "ArpSb" },
75         { &efi_block_io_protocol_guid,
76           "BlockIo" },
77         { &efi_bus_specific_driver_override_protocol_guid,
78           "BusSpecificDriverOverride" },
79         { &efi_component_name_protocol_guid,
80           "ComponentName" },
81         { &efi_component_name2_protocol_guid,
82           "ComponentName2" },
83         { &efi_device_path_protocol_guid,
84           "DevicePath" },
85         { &efi_driver_binding_protocol_guid,
86           "DriverBinding" },
87         { &efi_dhcp4_protocol_guid,
88           "Dhcp4" },
89         { &efi_dhcp4_service_binding_protocol_guid,
90           "Dhcp4Sb" },
91         { &efi_disk_io_protocol_guid,
92           "DiskIo" },
93         { &efi_graphics_output_protocol_guid,
94           "GraphicsOutput" },
95         { &efi_hii_config_access_protocol_guid,
96           "HiiConfigAccess" },
97         { &efi_ip4_protocol_guid,
98           "Ip4" },
99         { &efi_ip4_config_protocol_guid,
100           "Ip4Config" },
101         { &efi_ip4_service_binding_protocol_guid,
102           "Ip4Sb" },
103         { &efi_iscsi4_dxe_guid,
104           "IScsi4Dxe" },
105         { &efi_load_file_protocol_guid,
106           "LoadFile" },
107         { &efi_load_file2_protocol_guid,
108           "LoadFile2" },
109         { &efi_loaded_image_protocol_guid,
110           "LoadedImage" },
111         { &efi_loaded_image_device_path_protocol_guid,
112           "LoadedImageDevicePath"},
113         { &efi_managed_network_protocol_guid,
114           "ManagedNetwork" },
115         { &efi_managed_network_service_binding_protocol_guid,
116           "ManagedNetworkSb" },
117         { &efi_mtftp4_protocol_guid,
118           "Mtftp4" },
119         { &efi_mtftp4_service_binding_protocol_guid,
120           "Mtftp4Sb" },
121         { &efi_nii_protocol_guid,
122           "Nii" },
123         { &efi_nii31_protocol_guid,
124           "Nii31" },
125         { &efi_pci_io_protocol_guid,
126           "PciIo" },
127         { &efi_pci_root_bridge_io_protocol_guid,
128           "PciRootBridgeIo" },
129         { &efi_pxe_base_code_protocol_guid,
130           "PxeBaseCode" },
131         { &efi_simple_file_system_protocol_guid,
132           "SimpleFileSystem" },
133         { &efi_simple_network_protocol_guid,
134           "SimpleNetwork" },
135         { &efi_tcg_protocol_guid,
136           "Tcg" },
137         { &efi_tcp4_protocol_guid,
138           "Tcp4" },
139         { &efi_tcp4_service_binding_protocol_guid,
140           "Tcp4Sb" },
141         { &efi_udp4_protocol_guid,
142           "Udp4" },
143         { &efi_udp4_service_binding_protocol_guid,
144           "Udp4Sb" },
145         { &efi_vlan_config_protocol_guid,
146           "VlanConfig" },
147         { &efi_vlan_config_dxe_guid,
148           "VlanConfigDxe" },
149 };
150
151 /**
152  * Convert GUID to a printable string
153  *
154  * @v guid              GUID
155  * @ret string          Printable string
156  */
157 const char * efi_guid_ntoa ( EFI_GUID *guid ) {
158         union {
159                 union uuid uuid;
160                 EFI_GUID guid;
161         } u;
162         unsigned int i;
163
164         /* Sanity check */
165         if ( ! guid )
166                 return NULL;
167
168         /* Check for a match against well-known GUIDs */
169         for ( i = 0 ; i < ( sizeof ( efi_well_known_guids ) /
170                             sizeof ( efi_well_known_guids[0] ) ) ; i++ ) {
171                 if ( memcmp ( guid, efi_well_known_guids[i].guid,
172                               sizeof ( *guid ) ) == 0 ) {
173                         return efi_well_known_guids[i].name;
174                 }
175         }
176
177         /* Convert GUID to standard endianness */
178         memcpy ( &u.guid, guid, sizeof ( u.guid ) );
179         uuid_mangle ( &u.uuid );
180         return uuid_ntoa ( &u.uuid );
181 }
182
183 /**
184  * Name protocol open attributes
185  *
186  * @v attributes        Protocol open attributes
187  * @ret name            Protocol open attributes name
188  *
189  * Returns a (static) string with characters for each set bit
190  * corresponding to BY_(H)ANDLE_PROTOCOL, (G)ET_PROTOCOL,
191  * (T)EST_PROTOCOL, BY_(C)HILD_CONTROLLER, BY_(D)RIVER, and
192  * E(X)CLUSIVE.
193  */
194 static const char * efi_open_attributes_name ( unsigned int attributes ) {
195         static char attribute_chars[] = "HGTCDX";
196         static char name[ sizeof ( attribute_chars ) ];
197         char *tmp = name;
198         unsigned int i;
199
200         for ( i = 0 ; i < ( sizeof ( attribute_chars ) - 1 ) ; i++ ) {
201                 if ( attributes & ( 1 << i ) )
202                         *(tmp++) = attribute_chars[i];
203         }
204         *tmp = '\0';
205
206         return name;
207 }
208
209 /**
210  * Print list of openers of a given protocol on a given handle
211  *
212  * @v handle            EFI handle
213  * @v protocol          Protocol GUID
214  */
215 void dbg_efi_openers ( EFI_HANDLE handle, EFI_GUID *protocol ) {
216         EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
217         EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *openers;
218         EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *opener;
219         UINTN count;
220         unsigned int i;
221         EFI_STATUS efirc;
222         int rc;
223
224         /* Sanity check */
225         if ( ( ! handle ) || ( ! protocol ) ) {
226                 printf ( "EFI could not retrieve openers for %s on %p\n",
227                          efi_guid_ntoa ( protocol ), handle );
228                 return;
229         }
230
231         /* Retrieve list of openers */
232         if ( ( efirc = bs->OpenProtocolInformation ( handle, protocol, &openers,
233                                                      &count ) ) != 0 ) {
234                 rc = -EEFI ( efirc );
235                 printf ( "EFI could not retrieve openers for %s on %p: %s\n",
236                          efi_guid_ntoa ( protocol ), handle, strerror ( rc ) );
237                 return;
238         }
239
240         /* Dump list of openers */
241         for ( i = 0 ; i < count ; i++ ) {
242                 opener = &openers[i];
243                 printf ( "HANDLE %p %s %s opened %dx (%s)",
244                          handle, efi_handle_name ( handle ),
245                          efi_guid_ntoa ( protocol ), opener->OpenCount,
246                          efi_open_attributes_name ( opener->Attributes ) );
247                 printf ( " by %p %s", opener->AgentHandle,
248                          efi_handle_name ( opener->AgentHandle ) );
249                 if ( opener->ControllerHandle == handle ) {
250                         printf ( "\n" );
251                 } else {
252                         printf ( " for %p %s\n", opener->ControllerHandle,
253                                  efi_handle_name ( opener->ControllerHandle ) );
254                 }
255         }
256
257         /* Free list */
258         bs->FreePool ( openers );
259 }
260
261 /**
262  * Print list of protocol handlers attached to a handle
263  *
264  * @v handle            EFI handle
265  */
266 void dbg_efi_protocols ( EFI_HANDLE handle ) {
267         EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
268         EFI_GUID **protocols;
269         EFI_GUID *protocol;
270         UINTN count;
271         unsigned int i;
272         EFI_STATUS efirc;
273         int rc;
274
275         /* Sanity check */
276         if ( ! handle ) {
277                 printf ( "EFI could not retrieve protocols for %p\n", handle );
278                 return;
279         }
280
281         /* Retrieve list of protocols */
282         if ( ( efirc = bs->ProtocolsPerHandle ( handle, &protocols,
283                                                 &count ) ) != 0 ) {
284                 rc = -EEFI ( efirc );
285                 printf ( "EFI could not retrieve protocols for %p: %s\n",
286                          handle, strerror ( rc ) );
287                 return;
288         }
289
290         /* Dump list of protocols */
291         for ( i = 0 ; i < count ; i++ ) {
292                 protocol = protocols[i];
293                 printf ( "HANDLE %p %s %s supported\n",
294                          handle, efi_handle_name ( handle ),
295                          efi_guid_ntoa ( protocol ) );
296                 dbg_efi_openers ( handle, protocol );
297         }
298
299         /* Free list */
300         bs->FreePool ( protocols );
301 }
302
303 /**
304  * Get textual representation of device path
305  *
306  * @v path              Device path
307  * @ret text            Textual representation of device path, or NULL
308  */
309 const char * efi_devpath_text ( EFI_DEVICE_PATH_PROTOCOL *path ) {
310         EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
311         static char text[256];
312         void *start;
313         void *end;
314         size_t max_len;
315         size_t len;
316         CHAR16 *wtext;
317
318         /* Sanity checks */
319         if ( ! path ) {
320                 DBG ( "[NULL DevicePath]" );
321                 return NULL;
322         }
323
324         /* If we have no DevicePathToText protocol then use a raw hex string */
325         if ( ! efidpt ) {
326                 DBG ( "[No DevicePathToText]" );
327                 start = path;
328                 end = efi_devpath_end ( path );
329                 len = ( end - start );
330                 max_len = ( ( sizeof ( text ) - 1 /* NUL */ ) / 2 /* "xx" */ );
331                 if ( len > max_len )
332                         len = max_len;
333                 base16_encode ( start, len, text, sizeof ( text ) );
334                 return text;
335         }
336
337         /* Convert path to a textual representation */
338         wtext = efidpt->ConvertDevicePathToText ( path, TRUE, FALSE );
339         if ( ! wtext )
340                 return NULL;
341
342         /* Store path in buffer */
343         snprintf ( text, sizeof ( text ), "%ls", wtext );
344
345         /* Free path */
346         bs->FreePool ( wtext );
347
348         return text;
349 }
350
351 /**
352  * Get driver name
353  *
354  * @v wtf               Component name protocol
355  * @ret name            Driver name, or NULL
356  */
357 static const char * efi_driver_name ( EFI_COMPONENT_NAME_PROTOCOL *wtf ) {
358         static char name[64];
359         CHAR16 *driver_name;
360         EFI_STATUS efirc;
361
362         /* Sanity check */
363         if ( ! wtf ) {
364                 DBG ( "[NULL ComponentName]" );
365                 return NULL;
366         }
367
368         /* Try "eng" first; if that fails then try the first language */
369         if ( ( ( efirc = wtf->GetDriverName ( wtf, "eng",
370                                               &driver_name ) ) != 0 ) &&
371              ( ( efirc = wtf->GetDriverName ( wtf, wtf->SupportedLanguages,
372                                               &driver_name ) ) != 0 ) ) {
373                 return NULL;
374         }
375
376         /* Convert name from CHAR16 to char */
377         snprintf ( name, sizeof ( name ), "%ls", driver_name );
378         return name;
379 }
380
381 /**
382  * Get driver name
383  *
384  * @v wtf               Component name protocol
385  * @ret name            Driver name, or NULL
386  */
387 static const char * efi_driver_name2 ( EFI_COMPONENT_NAME2_PROTOCOL *wtf ) {
388         static char name[64];
389         CHAR16 *driver_name;
390         EFI_STATUS efirc;
391
392         /* Sanity check */
393         if ( ! wtf ) {
394                 DBG ( "[NULL ComponentName2]" );
395                 return NULL;
396         }
397
398         /* Try "en" first; if that fails then try the first language */
399         if ( ( ( efirc = wtf->GetDriverName ( wtf, "en",
400                                               &driver_name ) ) != 0 ) &&
401              ( ( efirc = wtf->GetDriverName ( wtf, wtf->SupportedLanguages,
402                                               &driver_name ) ) != 0 ) ) {
403                 return NULL;
404         }
405
406         /* Convert name from CHAR16 to char */
407         snprintf ( name, sizeof ( name ), "%ls", driver_name );
408         return name;
409 }
410
411 /**
412  * Get PE/COFF debug filename
413  *
414  * @v loaded            Loaded image
415  * @ret name            PE/COFF debug filename, or NULL
416  */
417 static const char *
418 efi_pecoff_debug_name ( EFI_LOADED_IMAGE_PROTOCOL *loaded ) {
419         static char buf[32];
420         EFI_IMAGE_DOS_HEADER *dos;
421         EFI_IMAGE_OPTIONAL_HEADER_UNION *pe;
422         EFI_IMAGE_OPTIONAL_HEADER32 *opt32;
423         EFI_IMAGE_OPTIONAL_HEADER64 *opt64;
424         EFI_IMAGE_DATA_DIRECTORY *datadir;
425         EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *debug;
426         EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY *codeview_nb10;
427         EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY *codeview_rsds;
428         EFI_IMAGE_DEBUG_CODEVIEW_MTOC_ENTRY *codeview_mtoc;
429         uint16_t dos_magic;
430         uint32_t pe_magic;
431         uint16_t opt_magic;
432         uint32_t codeview_magic;
433         size_t max_len;
434         char *name;
435         char *tmp;
436
437         /* Sanity check */
438         if ( ! loaded ) {
439                 DBG ( "[NULL LoadedImage]" );
440                 return NULL;
441         }
442
443         /* Parse DOS header */
444         dos = loaded->ImageBase;
445         if ( ! dos ) {
446                 DBG ( "[Missing DOS header]" );
447                 return NULL;
448         }
449         dos_magic = dos->e_magic;
450         if ( dos_magic != EFI_IMAGE_DOS_SIGNATURE ) {
451                 DBG ( "[Bad DOS signature %#04x]", dos_magic );
452                 return NULL;
453         }
454         pe = ( loaded->ImageBase + dos->e_lfanew );
455
456         /* Parse PE header */
457         pe_magic = pe->Pe32.Signature;
458         if ( pe_magic != EFI_IMAGE_NT_SIGNATURE ) {
459                 DBG ( "[Bad PE signature %#08x]", pe_magic );
460                 return NULL;
461         }
462         opt32 = &pe->Pe32.OptionalHeader;
463         opt64 = &pe->Pe32Plus.OptionalHeader;
464         opt_magic = opt32->Magic;
465         if ( opt_magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC ) {
466                 datadir = opt32->DataDirectory;
467         } else if ( opt_magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC ) {
468                 datadir = opt64->DataDirectory;
469         } else {
470                 DBG ( "[Bad optional header signature %#04x]", opt_magic );
471                 return NULL;
472         }
473
474         /* Parse data directory entry */
475         if ( ! datadir[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress ) {
476                 DBG ( "[Empty debug directory entry]" );
477                 return NULL;
478         }
479         debug = ( loaded->ImageBase +
480                   datadir[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress );
481
482         /* Parse debug directory entry */
483         if ( debug->Type != EFI_IMAGE_DEBUG_TYPE_CODEVIEW ) {
484                 DBG ( "[Not a CodeView debug directory entry (type %d)]",
485                       debug->Type );
486                 return NULL;
487         }
488         codeview_nb10 = ( loaded->ImageBase + debug->RVA );
489         codeview_rsds = ( loaded->ImageBase + debug->RVA );
490         codeview_mtoc = ( loaded->ImageBase + debug->RVA );
491         codeview_magic = codeview_nb10->Signature;
492
493         /* Parse CodeView entry */
494         if ( codeview_magic == CODEVIEW_SIGNATURE_NB10 ) {
495                 name = ( ( void * ) ( codeview_nb10 + 1 ) );
496         } else if ( codeview_magic == CODEVIEW_SIGNATURE_RSDS ) {
497                 name = ( ( void * ) ( codeview_rsds + 1 ) );
498         } else if ( codeview_magic == CODEVIEW_SIGNATURE_MTOC ) {
499                 name = ( ( void * ) ( codeview_mtoc + 1 ) );
500         } else {
501                 DBG ( "[Bad CodeView signature %#08x]", codeview_magic );
502                 return NULL;
503         }
504
505         /* Sanity check - avoid scanning endlessly through memory */
506         max_len = EFI_PAGE_SIZE; /* Reasonably sane */
507         if ( strnlen ( name, max_len ) == max_len ) {
508                 DBG ( "[Excessively long or invalid CodeView name]" );
509                 return NULL;
510         }
511
512         /* Skip any directory components.  We cannot modify this data
513          * or create a temporary buffer, so do not use basename().
514          */
515         while ( ( ( tmp = strchr ( name, '/' ) ) != NULL ) ||
516                 ( ( tmp = strchr ( name, '\\' ) ) != NULL ) ) {
517                 name = ( tmp + 1 );
518         }
519
520         /* Copy base name to buffer */
521         snprintf ( buf, sizeof ( buf ), "%s", name );
522
523         /* Strip file suffix, if present */
524         if ( ( tmp = strrchr ( name, '.' ) ) != NULL )
525                 *tmp = '\0';
526
527         return name;
528 }
529
530 /**
531  * Get initial loaded image name
532  *
533  * @v loaded            Loaded image
534  * @ret name            Initial loaded image name, or NULL
535  */
536 static const char *
537 efi_first_loaded_image_name ( EFI_LOADED_IMAGE_PROTOCOL *loaded ) {
538
539         /* Sanity check */
540         if ( ! loaded ) {
541                 DBG ( "[NULL LoadedImage]" );
542                 return NULL;
543         }
544
545         return ( ( loaded->ParentHandle == NULL ) ? "DxeCore(?)" : NULL );
546 }
547
548 /**
549  * Get loaded image name from file path
550  *
551  * @v loaded            Loaded image
552  * @ret name            Loaded image name, or NULL
553  */
554 static const char *
555 efi_loaded_image_filepath_name ( EFI_LOADED_IMAGE_PROTOCOL *loaded ) {
556
557         /* Sanity check */
558         if ( ! loaded ) {
559                 DBG ( "[NULL LoadedImage]" );
560                 return NULL;
561         }
562
563         return efi_devpath_text ( loaded->FilePath );
564 }
565
566 /** An EFI handle name type */
567 struct efi_handle_name_type {
568         /** Protocol */
569         EFI_GUID *protocol;
570         /**
571          * Get name
572          *
573          * @v interface         Protocol interface
574          * @ret name            Name of handle, or NULL on failure
575          */
576         const char * ( * name ) ( void *interface );
577 };
578
579 /**
580  * Define an EFI handle name type
581  *
582  * @v protocol          Protocol interface
583  * @v name              Method to get name
584  * @ret type            EFI handle name type
585  */
586 #define EFI_HANDLE_NAME_TYPE( protocol, name ) {        \
587         (protocol),                                     \
588         ( const char * ( * ) ( void * ) ) (name),       \
589         }
590
591 /** EFI handle name types */
592 static struct efi_handle_name_type efi_handle_name_types[] = {
593         /* Device path */
594         EFI_HANDLE_NAME_TYPE ( &efi_device_path_protocol_guid,
595                                efi_devpath_text ),
596         /* Driver name (for driver image handles) */
597         EFI_HANDLE_NAME_TYPE ( &efi_component_name2_protocol_guid,
598                                efi_driver_name2 ),
599         /* Driver name (via obsolete original ComponentName protocol) */
600         EFI_HANDLE_NAME_TYPE ( &efi_component_name_protocol_guid,
601                                efi_driver_name ),
602         /* PE/COFF debug filename (for image handles) */
603         EFI_HANDLE_NAME_TYPE ( &efi_loaded_image_protocol_guid,
604                                efi_pecoff_debug_name ),
605         /* Loaded image device path (for image handles) */
606         EFI_HANDLE_NAME_TYPE ( &efi_loaded_image_device_path_protocol_guid,
607                                efi_devpath_text ),
608         /* First loaded image name (for the DxeCore image) */
609         EFI_HANDLE_NAME_TYPE ( &efi_loaded_image_protocol_guid,
610                                efi_first_loaded_image_name ),
611         /* Handle's loaded image file path (for image handles) */
612         EFI_HANDLE_NAME_TYPE ( &efi_loaded_image_protocol_guid,
613                                efi_loaded_image_filepath_name ),
614 };
615
616 /**
617  * Get name of an EFI handle
618  *
619  * @v handle            EFI handle
620  * @ret text            Name of handle, or NULL
621  */
622 const char * efi_handle_name ( EFI_HANDLE handle ) {
623         EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
624         struct efi_handle_name_type *type;
625         unsigned int i;
626         void *interface;
627         const char *name;
628         EFI_STATUS efirc;
629
630         /* Fail immediately for NULL handles */
631         if ( ! handle )
632                 return NULL;
633
634         /* Try each name type in turn */
635         for ( i = 0 ; i < ( sizeof ( efi_handle_name_types ) /
636                             sizeof ( efi_handle_name_types[0] ) ) ; i++ ) {
637                 type = &efi_handle_name_types[i];
638                 DBG2 ( "<%d", i );
639
640                 /* Try to open the applicable protocol */
641                 efirc = bs->OpenProtocol ( handle, type->protocol, &interface,
642                                            efi_image_handle, handle,
643                                            EFI_OPEN_PROTOCOL_GET_PROTOCOL );
644                 if ( efirc != 0 ) {
645                         DBG2 ( ">" );
646                         continue;
647                 }
648
649                 /* Try to get name from this protocol */
650                 DBG2 ( "-" );
651                 name = type->name ( interface );
652                 DBG2 ( "%c", ( name ? ( name[0] ? 'Y' : 'E' ) : 'N' ) );
653
654                 /* Close protocol */
655                 bs->CloseProtocol ( handle, type->protocol,
656                                     efi_image_handle, handle );
657                 DBG2 ( ">" );
658
659                 /* Use this name, if possible */
660                 if ( name && name[0] )
661                         return name;
662         }
663
664         return "UNKNOWN";
665 }