From 3f85626fa95cb356a655d3538db6f05231f07003 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Tue, 18 Nov 2008 19:45:44 -0800 Subject: [efi] Add efi_strerror() EFI_STATUS is defined as an INTN, which maps to UINT32 (i.e. unsigned int) on i386 and UINT64 (i.e. unsigned long) on x86_64. This would require a cast each time the error status is printed. Add efi_strerror() to avoid this ickiness and simultaneously enable prettier reporting of EFI status codes. --- src/image/efi_image.c | 12 +++++------ src/include/gpxe/efi/efi.h | 2 ++ src/interface/efi/efi_console.c | 3 ++- src/interface/efi/efi_io.c | 14 +++++++------ src/interface/efi/efi_pci.c | 8 ++++---- src/interface/efi/efi_snp.c | 15 +++++++------- src/interface/efi/efi_strerror.c | 43 ++++++++++++++++++++++++++++++++++++++++ src/interface/efi/efi_timer.c | 7 ++++--- src/interface/efi/efi_umalloc.c | 8 ++++---- 9 files changed, 81 insertions(+), 31 deletions(-) create mode 100644 src/interface/efi/efi_strerror.c diff --git a/src/image/efi_image.c b/src/image/efi_image.c index 5992b622..ae95debc 100644 --- a/src/image/efi_image.c +++ b/src/image/efi_image.c @@ -43,16 +43,16 @@ static int efi_image_exec ( struct image *image ) { user_to_virt ( image->data, 0 ), image->len, &handle ) ) != 0 ) { /* Not an EFI image */ - DBGC ( image, "EFIIMAGE %p could not load: %x\n", - image, efirc ); + DBGC ( image, "EFIIMAGE %p could not load: %s\n", + image, efi_strerror ( efirc ) ); return -ENOEXEC; } /* Start the image */ if ( ( efirc = bs->StartImage ( handle, &exit_data_size, &exit_data ) ) != 0 ) { - DBGC ( image, "EFIIMAGE %p returned with status %x\n", - image, efirc ); + DBGC ( image, "EFIIMAGE %p returned with status %s\n", + image, efi_strerror ( efirc ) ); goto done; } @@ -81,8 +81,8 @@ static int efi_image_load ( struct image *image ) { user_to_virt ( image->data, 0 ), image->len, &handle ) ) != 0 ) { /* Not an EFI image */ - DBGC ( image, "EFIIMAGE %p could not load: %x\n", - image, efirc ); + DBGC ( image, "EFIIMAGE %p could not load: %s\n", + image, efi_strerror ( efirc ) ); return -ENOEXEC; } diff --git a/src/include/gpxe/efi/efi.h b/src/include/gpxe/efi/efi.h index cd35f68a..8c9f789a 100644 --- a/src/include/gpxe/efi/efi.h +++ b/src/include/gpxe/efi/efi.h @@ -90,4 +90,6 @@ struct efi_protocol { extern EFI_HANDLE efi_image_handle; extern EFI_SYSTEM_TABLE *efi_systab; +extern const char * efi_strerror ( EFI_STATUS efirc ); + #endif /* _EFI_H */ diff --git a/src/interface/efi/efi_console.c b/src/interface/efi/efi_console.c index df774e49..b78de618 100644 --- a/src/interface/efi/efi_console.c +++ b/src/interface/efi/efi_console.c @@ -224,7 +224,8 @@ static int efi_getchar ( void ) { /* Read key from real EFI console */ if ( ( efirc = conin->ReadKeyStroke ( conin, &key ) ) != 0 ) { - DBG ( "EFI could not read keystroke: %x\n", efirc ); + DBG ( "EFI could not read keystroke: %s\n", + efi_strerror ( efirc ) ); return 0; } DBG2 ( "EFI read key stroke with unicode %04x scancode %04x\n", diff --git a/src/interface/efi/efi_io.c b/src/interface/efi/efi_io.c index ef21213c..e11f9bfd 100644 --- a/src/interface/efi/efi_io.c +++ b/src/interface/efi/efi_io.c @@ -86,7 +86,8 @@ unsigned long long efi_ioread ( volatile void *io_addr, size_t size ) { if ( ( efirc = read ( cpu_io, efi_width ( size ), ( intptr_t ) io_addr, 1, ( void * ) &data ) ) != 0 ) { - DBG ( "EFI I/O read at %p failed: %x\n", io_addr, efirc ); + DBG ( "EFI I/O read at %p failed: %s\n", + io_addr, efi_strerror ( efirc ) ); return -1ULL; } @@ -111,7 +112,8 @@ void efi_iowrite ( unsigned long long data, volatile void *io_addr, if ( ( efirc = write ( cpu_io, efi_width ( size ), ( intptr_t ) io_addr, 1, ( void * ) &data ) ) != 0 ) { - DBG ( "EFI I/O write at %p failed: %x\n", io_addr, efirc ); + DBG ( "EFI I/O write at %p failed: %s\n", + io_addr, efi_strerror ( efirc ) ); } } @@ -134,8 +136,8 @@ void efi_ioreads ( volatile void *io_addr, void *data, if ( ( efirc = read ( cpu_io, efi_width ( size ), ( intptr_t ) io_addr, count, ( void * ) data ) ) != 0 ) { - DBG ( "EFI I/O string read at %p failed: %x\n", - io_addr, efirc ); + DBG ( "EFI I/O string read at %p failed: %s\n", + io_addr, efi_strerror ( efirc ) ); } } @@ -158,8 +160,8 @@ void efi_iowrites ( volatile void *io_addr, const void *data, if ( ( efirc = write ( cpu_io, efi_width ( size ), ( intptr_t ) io_addr, count, ( void * ) data ) ) != 0 ) { - DBG ( "EFI I/O write at %p failed: %x\n", - io_addr, efirc ); + DBG ( "EFI I/O write at %p failed: %s\n", + io_addr, efi_strerror ( efirc ) ); } } diff --git a/src/interface/efi/efi_pci.c b/src/interface/efi/efi_pci.c index 308a5388..f87b5407 100644 --- a/src/interface/efi/efi_pci.c +++ b/src/interface/efi/efi_pci.c @@ -46,9 +46,9 @@ int efipci_read ( struct pci_device *pci, unsigned long location, efipci_address ( pci, location ), 1, value ) ) != 0 ) { DBG ( "EFIPCI config read from %02x:%02x.%x offset %02lx " - "failed: %x\n", pci->bus, PCI_SLOT ( pci->devfn ), + "failed: %s\n", pci->bus, PCI_SLOT ( pci->devfn ), PCI_FUNC ( pci->devfn ), EFIPCI_OFFSET ( location ), - efirc ); + efi_strerror ( efirc ) ); return -EIO; } @@ -63,9 +63,9 @@ int efipci_write ( struct pci_device *pci, unsigned long location, efipci_address ( pci, location ), 1, &value ) ) != 0 ) { DBG ( "EFIPCI config write to %02x:%02x.%x offset %02lx " - "failed: %x\n", pci->bus, PCI_SLOT ( pci->devfn ), + "failed: %s\n", pci->bus, PCI_SLOT ( pci->devfn ), PCI_FUNC ( pci->devfn ), EFIPCI_OFFSET ( location ), - efirc ); + efi_strerror ( efirc ) ); return -EIO; } diff --git a/src/interface/efi/efi_snp.c b/src/interface/efi/efi_snp.c index a3494cc0..6256aeea 100644 --- a/src/interface/efi/efi_snp.c +++ b/src/interface/efi/efi_snp.c @@ -737,7 +737,8 @@ efi_snp_netdev ( EFI_DRIVER_BINDING_PROTOCOL *driver, EFI_HANDLE device ) { if ( ( efirc = u.pci->GetLocation ( u.pci, &pci_segment, &pci_bus, &pci_dev, &pci_fn ) ) != 0 ) { DBGC ( driver, "SNPDRV %p device %p could not get PCI " - "location: %x\n", driver, device, efirc ); + "location: %s\n", + driver, device, efi_strerror ( efirc ) ); goto out_no_pci_location; } DBGCP ( driver, "SNPDRV %p device %p is PCI %04x:%02x:%02x.%x\n", @@ -786,7 +787,7 @@ efi_snp_snpdev ( EFI_DRIVER_BINDING_PROTOCOL *driver, EFI_HANDLE device ) { device, EFI_OPEN_PROTOCOL_GET_PROTOCOL))!=0){ DBGC ( driver, "SNPDRV %p device %p could not locate SNP: " - "%x\n", driver, device, efirc ); + "%s\n", driver, device, efi_strerror ( efirc ) ); return NULL; } @@ -869,8 +870,8 @@ efi_snp_driver_start ( EFI_DRIVER_BINDING_PROTOCOL *driver, if ( ( efirc = bs->CreateEvent ( EVT_NOTIFY_WAIT, TPL_NOTIFY, efi_snp_wait_for_packet, snpdev, &snpdev->snp.WaitForPacket ) ) != 0 ){ - DBGC ( snpdev, "SNPDEV %p could not create event: %x\n", - snpdev, efirc ); + DBGC ( snpdev, "SNPDEV %p could not create event: %s\n", + snpdev, efi_strerror ( efirc ) ); goto err_create_event; } @@ -882,8 +883,8 @@ efi_snp_driver_start ( EFI_DRIVER_BINDING_PROTOCOL *driver, if ( ( efirc = bs->InstallProtocolInterface ( &device, &efi_simple_network_protocol_guid, EFI_NATIVE_INTERFACE, &snpdev->snp ) ) != 0 ) { - DBGC ( snpdev, "SNPDEV %p could not install protocol: %x\n", - snpdev, efirc ); + DBGC ( snpdev, "SNPDEV %p could not install protocol: %s\n", + snpdev, efi_strerror ( efirc ) ); goto err_install_protocol_interface; } @@ -970,7 +971,7 @@ int efi_snp_install ( void ) { EFI_NATIVE_INTERFACE, driver ) ) != 0 ) { DBGC ( driver, "SNPDRV %p could not install driver binding: " - "%x\n", driver, efirc ); + "%s\n", driver, efi_strerror ( efirc ) ); return EFIRC_TO_RC ( efirc ); } diff --git a/src/interface/efi/efi_strerror.c b/src/interface/efi/efi_strerror.c new file mode 100644 index 00000000..adfeaed5 --- /dev/null +++ b/src/interface/efi/efi_strerror.c @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2008 Michael Brown . + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include +#include + +/** @file + * + * gPXE error message formatting for EFI + * + */ + +/** + * Format EFI status code + * + * @v efirc EFI status code + * @v efi_strerror EFI status code string + */ +const char * efi_strerror ( EFI_STATUS efirc ) { + static char errbuf[32]; + + if ( ! efirc ) + return "No error"; + + snprintf ( errbuf, sizeof ( errbuf ), "Error %lld", + ( unsigned long long ) ( efirc ^ MAX_BIT ) ); + return errbuf; +} diff --git a/src/interface/efi/efi_timer.c b/src/interface/efi/efi_timer.c index 66211770..d1ba43af 100644 --- a/src/interface/efi/efi_timer.c +++ b/src/interface/efi/efi_timer.c @@ -53,8 +53,8 @@ static void efi_udelay ( unsigned long usecs ) { EFI_STATUS efirc; if ( ( efirc = bs->Stall ( usecs ) ) != 0 ) { - DBG ( "EFI could not delay for %ldus: %x\n", - usecs, efirc ); + DBG ( "EFI could not delay for %ldus: %s\n", + usecs, efi_strerror ( efirc ) ); /* Probably screwed */ } } @@ -71,7 +71,8 @@ static unsigned long efi_currticks ( void ) { /* Read CPU timer 0 (TSC) */ if ( ( efirc = cpu_arch->GetTimerValue ( cpu_arch, 0, &time, NULL ) ) != 0 ) { - DBG ( "EFI could not read CPU timer: %x\n", efirc ); + DBG ( "EFI could not read CPU timer: %s\n", + efi_strerror ( efirc ) ); /* Probably screwed */ return -1UL; } diff --git a/src/interface/efi/efi_umalloc.c b/src/interface/efi/efi_umalloc.c index 531a1c3a..4de3789d 100644 --- a/src/interface/efi/efi_umalloc.c +++ b/src/interface/efi/efi_umalloc.c @@ -56,8 +56,8 @@ static userptr_t efi_urealloc ( userptr_t old_ptr, size_t new_size ) { EfiBootServicesData, new_pages, &phys_addr ) ) != 0 ) { - DBG ( "EFI could not allocate %d pages: %x\n", - new_pages, efirc ); + DBG ( "EFI could not allocate %d pages: %s\n", + new_pages, efi_strerror ( efirc ) ); return UNULL; } assert ( phys_addr != 0 ); @@ -81,8 +81,8 @@ static userptr_t efi_urealloc ( userptr_t old_ptr, size_t new_size ) { old_pages = ( EFI_SIZE_TO_PAGES ( old_size ) + 1 ); phys_addr = user_to_phys ( old_ptr, -EFI_PAGE_SIZE ); if ( ( efirc = bs->FreePages ( phys_addr, old_pages ) ) != 0 ){ - DBG ( "EFI could not free %d pages at %llx: %x\n", - old_pages, phys_addr, efirc ); + DBG ( "EFI could not free %d pages at %llx: %s\n", + old_pages, phys_addr, efi_strerror ( efirc ) ); /* Not fatal; we have leaked memory but successfully * allocated (if asked to do so). */ -- cgit v1.2.3-55-g7522