]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[efi] Perform meaningful error code conversions
authorMichael Brown <mcb30@ipxe.org>
Thu, 18 Apr 2013 20:29:53 +0000 (21:29 +0100)
committerMichael Brown <mcb30@ipxe.org>
Fri, 19 Apr 2013 12:34:19 +0000 (13:34 +0100)
Exploit the redefinition of iPXE error codes to include a "platform
error code" to allow for meaningful conversion of EFI_STATUS values to
iPXE errors and vice versa.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
20 files changed:
src/arch/x86/prefix/efiprefix.c
src/drivers/net/efi/snpnet.c
src/image/efi_image.c
src/include/ipxe/efi/efi.h
src/include/ipxe/efi/efi_driver.h
src/include/ipxe/efi/efi_pci.h
src/include/ipxe/errfile.h
src/interface/efi/efi_bofm.c
src/interface/efi/efi_console.c
src/interface/efi/efi_debug.c
src/interface/efi/efi_download.c
src/interface/efi/efi_driver.c
src/interface/efi/efi_file.c
src/interface/efi/efi_init.c
src/interface/efi/efi_pci.c
src/interface/efi/efi_snp.c
src/interface/efi/efi_snp_hii.c
src/interface/efi/efi_strerror.c [deleted file]
src/interface/efi/efi_timer.c
src/interface/efi/efi_umalloc.c

index bfa94d404de17bcb31777912795b53417e3e14ca..a847045a5dda9e9b6ed27f1fa878712c5f48e68a 100644 (file)
@@ -20,6 +20,7 @@
 FILE_LICENCE ( GPL2_OR_LATER );
 
 #include <stdlib.h>
+#include <errno.h>
 #include <ipxe/efi/efi.h>
 
 /**
@@ -38,5 +39,5 @@ EFI_STATUS EFIAPI _efi_start ( EFI_HANDLE image_handle,
                return efirc;
 
        /* Call to main() */
-       return RC_TO_EFIRC ( main () );
+       return EFIRC ( main () );
 }
index 9779081511019ceb088edd30cd5e9cb9b282efdb..cd9e7e386eb7632e6e9fddd5b6dd9699cb8bab9f 100644 (file)
@@ -56,20 +56,21 @@ static int snpnet_transmit ( struct net_device *netdev,
                             struct io_buffer *iobuf ) {
        struct snpnet_device *snpnetdev = netdev->priv;
        EFI_SIMPLE_NETWORK_PROTOCOL *snp = snpnetdev->snp;
-       EFI_STATUS efirc;
        void *txbuf=NULL;
        size_t len = iob_len ( iobuf );
+       EFI_STATUS efirc;
+       int rc;
 
-       efirc = snp->Transmit ( snp, 0, len, iobuf->data, NULL, NULL, NULL );
-       if (efirc) {
-               return EFIRC_TO_RC ( efirc );
+       if ( ( efirc = snp->Transmit ( snp, 0, len, iobuf->data, NULL, NULL,
+                                      NULL ) ) != 0 ) {
+               return -EEFI ( efirc );
        }
        /* since GetStatus is so inconsistent, don't try more than one outstanding transmit at a time */
        while ( txbuf == NULL ) {
-               efirc = snp->GetStatus ( snp, NULL, &txbuf );
-               if ( efirc ) {
+               if ( ( efirc = snp->GetStatus ( snp, NULL, &txbuf ) ) != 0 ) {
+                       rc = -EEFI ( efirc );
                        DBGC ( snp, "SNP %p could not get status %s\n", snp,
-                              efi_strerror ( efirc ) );
+                              strerror ( rc ) );
                        break;
                }
 
@@ -86,9 +87,10 @@ static int snpnet_transmit ( struct net_device *netdev,
 static void snpnet_poll ( struct net_device *netdev ) {
        struct snpnet_device *snpnetdev = netdev->priv;
        EFI_SIMPLE_NETWORK_PROTOCOL *snp = snpnetdev->snp;
-       EFI_STATUS efirc;
        struct io_buffer *iobuf = NULL;
        UINTN len;
+       EFI_STATUS efirc;
+       int rc;
 
        /* Process received packets */
        while ( 1 ) {
@@ -115,12 +117,13 @@ static void snpnet_poll ( struct net_device *netdev ) {
                }
 
                /* Other error? */
-               if ( efirc ) {
+               if ( efirc != 0 ) {
+                       rc = -EEFI ( efirc );
                        DBGC ( snp, "SNP %p receive packet error: %s "
                                    "(len was %zd, is now %zd)\n",
-                              snp, efi_strerror ( efirc ), iob_len(iobuf),
+                              snp, strerror ( rc ), iob_len(iobuf),
                               (size_t)len );
-                       netdev_rx_err ( netdev, iobuf, efirc );
+                       netdev_rx_err ( netdev, iobuf, rc );
                        break;
                }
 
@@ -139,25 +142,27 @@ static void snpnet_poll ( struct net_device *netdev ) {
 static int snpnet_open ( struct net_device *netdev ) {
        struct snpnet_device *snpnetdev = netdev->priv;
        EFI_SIMPLE_NETWORK_PROTOCOL *snp = snpnetdev->snp;
-       EFI_STATUS efirc;
+       EFI_MAC_ADDRESS *mac;
        UINT32 enableFlags, disableFlags;
+       EFI_STATUS efirc;
+       int rc;
 
        snpnetdev->close_state = snp->Mode->State;
        if ( snp->Mode->State != EfiSimpleNetworkInitialized ) {
-               efirc = snp->Initialize ( snp, 0, 0 );
-               if ( efirc ) {
+               if ( ( efirc = snp->Initialize ( snp, 0, 0 ) ) != 0 ) {
+                       rc = -EEFI ( efirc );
                        DBGC ( snp, "SNP %p could not initialize: %s\n",
-                              snp, efi_strerror ( efirc ) );
-                       return EFIRC_TO_RC ( efirc );
+                              snp, strerror ( rc ) );
+                       return rc;
                }
        }
 
         /* Use the default MAC address */
-       efirc = snp->StationAddress ( snp, FALSE,
-                                     (EFI_MAC_ADDRESS *)netdev->ll_addr );
-       if ( efirc ) {
+       mac = ( ( void * ) netdev->ll_addr );
+       if ( ( efirc = snp->StationAddress ( snp, FALSE, mac ) ) != 0 ) {
+               rc = -EEFI ( efirc );
                DBGC ( snp, "SNP %p could not reset station address: %s\n",
-                      snp, efi_strerror ( efirc ) );
+                      snp, strerror ( rc ) );
        }
 
        /* Set up receive filters to receive unicast and broadcast packets
@@ -179,11 +184,11 @@ static int snpnet_open ( struct net_device *netdev ) {
                enableFlags |= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS;
        }
        disableFlags &= ~enableFlags;
-       efirc = snp->ReceiveFilters ( snp, enableFlags, disableFlags,
-                                     FALSE, 0, NULL );
-       if ( efirc ) {
+       if ( ( efirc = snp->ReceiveFilters ( snp, enableFlags, disableFlags,
+                                            FALSE, 0, NULL ) ) != 0 ) {
+               rc = -EEFI ( efirc );
                DBGC ( snp, "SNP %p could not set receive filters: %s\n",
-                      snp, efi_strerror ( efirc ) );
+                      snp, strerror ( rc ) );
        }
 
        DBGC ( snp, "SNP %p opened\n", snp );
@@ -199,12 +204,13 @@ static void snpnet_close ( struct net_device *netdev ) {
        struct snpnet_device *snpnetdev = netdev->priv;
        EFI_SIMPLE_NETWORK_PROTOCOL *snp = snpnetdev->snp;
        EFI_STATUS efirc;
+       int rc;
 
        if ( snpnetdev->close_state != EfiSimpleNetworkInitialized ) {
-               efirc = snp->Shutdown ( snp );
-               if ( efirc ) {
+               if ( ( efirc = snp->Shutdown ( snp ) ) != 0 ) {
+                       rc = -EEFI ( efirc );
                        DBGC ( snp, "SNP %p could not shut down: %s\n",
-                              snp, efi_strerror ( efirc ) );
+                              snp, strerror ( rc ) );
                }
        }
 }
@@ -264,11 +270,10 @@ int snpnet_probe ( struct snp_device *snpdev ) {
 
        /* Start the interface */
        if ( snp->Mode->State == EfiSimpleNetworkStopped ) {
-               efirc = snp->Start ( snp );
-               if ( efirc ) {
+               if ( ( efirc = snp->Start ( snp ) ) != 0 ) {
+                       rc = -EEFI ( efirc );
                        DBGC ( snp, "SNP %p could not start: %s\n", snp,
-                              efi_strerror ( efirc ) );
-                       rc = EFIRC_TO_RC ( efirc );
+                              strerror ( rc ) );
                        goto err_start;
                }
        }
@@ -310,25 +315,27 @@ err_start:
  */
 void snpnet_remove ( struct snp_device *snpdev ) {
        EFI_SIMPLE_NETWORK_PROTOCOL *snp = snpdev->snp;
-       EFI_STATUS efirc;
        struct net_device *netdev = snpdev->netdev;
+       EFI_STATUS efirc;
+       int rc;
 
        if ( snp->Mode->State == EfiSimpleNetworkInitialized &&
             snpdev->removal_state != EfiSimpleNetworkInitialized ) {
                DBGC ( snp, "SNP %p shutting down\n", snp );
-               efirc = snp->Shutdown ( snp );
-               if ( efirc ) {
+               if ( ( efirc = snp->Shutdown ( snp ) ) != 0 ) {
+                       rc = -EEFI ( efirc );
                        DBGC ( snp, "SNP %p could not shut down: %s\n",
-                              snp, efi_strerror ( efirc ) );
+                              snp, strerror ( rc ) );
                }
        }
 
        if ( snp->Mode->State == EfiSimpleNetworkStarted &&
             snpdev->removal_state == EfiSimpleNetworkStopped ) {
                DBGC ( snp, "SNP %p stopping\n", snp );
-               efirc = snp->Stop ( snp );
-               if ( efirc ) {
-                       DBGC ( snp, "SNP %p could not be stopped\n", snp );
+               if ( ( efirc = snp->Stop ( snp ) ) != 0 ) {
+                       rc = -EEFI ( efirc );
+                       DBGC ( snp, "SNP %p could not be stopped: %s\n",
+                              snp, strerror ( rc ) );
                }
        }
 
index 0368b82c4eb589ae4463a9906a12e62c3e74ecd5..0e90954b23a4b98d62affe282c3caff16517b9bd 100644 (file)
@@ -176,9 +176,9 @@ static int efi_image_exec ( struct image *image ) {
                                       user_to_virt ( image->data, 0 ),
                                       image->len, &handle ) ) != 0 ) {
                /* Not an EFI image */
+               rc = -EEFI ( efirc );
                DBGC ( image, "EFIIMAGE %p could not load: %s\n",
-                      image, efi_strerror ( efirc ) );
-               rc = -ENOEXEC;
+                      image, strerror ( rc ) );
                goto err_load_image;
        }
 
@@ -188,7 +188,7 @@ static int efi_image_exec ( struct image *image ) {
                                   NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL );
        if ( efirc ) {
                /* Should never happen */
-               rc = EFIRC_TO_RC ( efirc );
+               rc = -EEFI ( efirc );
                goto err_open_protocol;
        }
 
@@ -205,9 +205,9 @@ static int efi_image_exec ( struct image *image ) {
 
        /* Start the image */
        if ( ( efirc = bs->StartImage ( handle, NULL, NULL ) ) != 0 ) {
+               rc = -EEFI ( efirc );
                DBGC ( image, "EFIIMAGE %p returned with status %s\n",
-                      image, efi_strerror ( efirc ) );
-               rc = EFIRC_TO_RC ( efirc );
+                      image, strerror ( rc ) );
                goto err_start_image;
        }
 
@@ -220,8 +220,9 @@ static int efi_image_exec ( struct image *image ) {
         * have no "unload" operation.
         */
        if ( ( efirc = bs->UnloadImage ( handle ) ) != 0 ) {
+               rc = -EEFI ( efirc );
                DBGC ( image, "EFIIMAGE %p could not unload: %s\n",
-                      image, efi_strerror ( efirc ) );
+                      image, strerror ( rc ) );
        }
  err_load_image:
        free ( cmdline );
@@ -246,15 +247,17 @@ static int efi_image_probe ( struct image *image ) {
        EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
        EFI_HANDLE handle;
        EFI_STATUS efirc;
+       int rc;
 
        /* Attempt loading image */
        if ( ( efirc = bs->LoadImage ( FALSE, efi_image_handle, NULL,
                                       user_to_virt ( image->data, 0 ),
                                       image->len, &handle ) ) != 0 ) {
                /* Not an EFI image */
+               rc = -EEFI ( efirc );
                DBGC ( image, "EFIIMAGE %p could not load: %s\n",
-                      image, efi_strerror ( efirc ) );
-               return -ENOEXEC;
+                      image, strerror ( rc ) );
+               return rc;
        }
 
        /* Unload the image.  We can't leave it loaded, because we
index 3aaac60eed018309b557f3a98c6f1e966aa54a82..0a21c6e74b996f69d3724eb3e16611d1402f2ec4 100644 (file)
@@ -108,29 +108,27 @@ struct efi_config_table {
                .required = (_required),                                     \
        }
 
-/** Convert a iPXE status code to an EFI status code
+/**
+ * Convert an iPXE status code to an EFI status code
  *
- * FIXME: actually perform some kind of conversion.  iPXE error codes
- * will be detected as EFI error codes; both have the top bit set, and
- * the success return code is zero for both.  Anything that just
- * reports a numerical error will be OK, anything attempting to
- * interpret the value or to display a text equivalent will be
- * screwed.
+ * @v rc               iPXE status code
+ * @ret efirc          EFI status code
  */
-#define RC_TO_EFIRC( rc ) (rc)
+#define EFIRC( rc ) ERRNO_TO_PLATFORM ( -(rc) )
 
-/** Convert an EFI status code to a iPXE status code
+/**
+ * Convert an EFI status code to an iPXE status code
  *
- * FIXME: as above
+ * @v efirc            EFI status code
+ * @ret rc             iPXE status code (before negation)
  */
-#define EFIRC_TO_RC( efirc ) (efirc)
+#define EEFI( efirc ) EPLATFORM ( EINFO_EPLATFORM, efirc )
 
 extern EFI_HANDLE efi_image_handle;
 extern EFI_LOADED_IMAGE_PROTOCOL *efi_loaded_image;
 extern EFI_DEVICE_PATH_PROTOCOL *efi_loaded_image_path;
 extern EFI_SYSTEM_TABLE *efi_systab;
 
-extern const char * efi_strerror ( EFI_STATUS efirc );
 extern const char * efi_guid_ntoa ( EFI_GUID *guid );
 
 extern void dbg_efi_protocols ( EFI_HANDLE handle );
index e5872ced3da0c77825d8441ffe372744b410044c..d7eec96496df9ffa2f2e07839f536b2b95bf702d 100644 (file)
@@ -44,6 +44,6 @@ struct efi_driver {
 extern EFI_DEVICE_PATH_PROTOCOL *
 efi_devpath_end ( EFI_DEVICE_PATH_PROTOCOL *path );
 
-extern EFI_STATUS efi_driver_install ( struct efi_driver *efidrv );
+extern int efi_driver_install ( struct efi_driver *efidrv );
 
 #endif /* _IPXE_EFI_DRIVER_H */
index 6429f2109122081e91cc668035d122cb7fe70377..e6b31970908cb13306c41ea881dc0330f6ce0162 100644 (file)
@@ -38,11 +38,11 @@ struct efi_pci_device {
 
 extern struct efi_pci_device * efipci_create ( struct efi_driver *efidrv,
                                               EFI_HANDLE device );
-extern EFI_STATUS efipci_enable ( struct efi_pci_device *efipci );
+extern int efipci_enable ( struct efi_pci_device *efipci );
 extern struct efi_pci_device * efipci_find_efi ( EFI_HANDLE device );
 extern struct efi_pci_device * efipci_find ( struct device *dev );
-extern EFI_STATUS efipci_child_add ( struct efi_pci_device *efipci,
-                                    EFI_HANDLE device );
+extern int efipci_child_add ( struct efi_pci_device *efipci,
+                             EFI_HANDLE device );
 extern void efipci_child_del ( struct efi_pci_device *efipci,
                               EFI_HANDLE device );
 extern void efipci_destroy ( struct efi_driver *efidrv,
index f906dbd554d43146ab7b85fe7b1cfe31bd8f515b..67edcc9317409f1bcb06b8c09e11e1149358518f 100644 (file)
@@ -266,6 +266,15 @@ FILE_LICENCE ( GPL2_OR_LATER );
 #define ERRFILE_nslookup             ( ERRFILE_OTHER | 0x00300000 )
 #define ERRFILE_efi_snp_hii          ( ERRFILE_OTHER | 0x00310000 )
 #define ERRFILE_readline             ( ERRFILE_OTHER | 0x00320000 )
+#define ERRFILE_efi_bofm             ( ERRFILE_OTHER | 0x00330000 )
+#define ERRFILE_efi_console          ( ERRFILE_OTHER | 0x00340000 )
+#define ERRFILE_efi_debug            ( ERRFILE_OTHER | 0x00350000 )
+#define ERRFILE_efi_download         ( ERRFILE_OTHER | 0x00360000 )
+#define ERRFILE_efi_driver           ( ERRFILE_OTHER | 0x00370000 )
+#define ERRFILE_efi_file             ( ERRFILE_OTHER | 0x00380000 )
+#define ERRFILE_efi_init             ( ERRFILE_OTHER | 0x00390000 )
+#define ERRFILE_efi_timer            ( ERRFILE_OTHER | 0x003a0000 )
+#define ERRFILE_efi_umalloc          ( ERRFILE_OTHER | 0x003b0000 )
 
 /** @} */
 
index c313d2e97ab439313fb5fbed93c29bc892db8db8..8a8489bd8264ba402fcbc330b305850d93a87e5a 100644 (file)
@@ -181,7 +181,7 @@ efi_bofm_supported ( EFI_DRIVER_BINDING_PROTOCOL *driver,
        /* Create corresponding PCI device, if any */
        efipci = efipci_create ( efidrv, device );
        if ( ! efipci ) {
-               efirc = EFI_UNSUPPORTED;
+               rc = -ENOTSUP;
                goto err_not_pci;
        }
 
@@ -189,16 +189,15 @@ efi_bofm_supported ( EFI_DRIVER_BINDING_PROTOCOL *driver,
        if ( ( rc = bofm_find_driver ( &efipci->pci ) ) != 0 ) {
                DBGCP ( efidrv, "EFIBOFM " PCI_FMT " has no driver\n",
                        PCI_ARGS ( &efipci->pci ) );
-               efirc = EFI_UNSUPPORTED;
                goto err_no_driver;
        }
 
        /* Locate BOFM protocol */
        if ( ( efirc = bs->LocateProtocol ( &bofm1_protocol_guid, NULL,
                                            &bofm1.interface ) ) != 0 ) {
+               rc = -EEFI ( efirc );
                DBGC ( efidrv, "EFIBOFM " PCI_FMT " cannot find BOFM "
                       "protocol\n", PCI_ARGS ( &efipci->pci ) );
-               efirc = EFI_UNSUPPORTED;
                goto err_not_bofm;
        }
 
@@ -207,9 +206,10 @@ efi_bofm_supported ( EFI_DRIVER_BINDING_PROTOCOL *driver,
                                                      0x04 /* Can change MAC */,
                                                      0x00 /* No iSCSI */,
                                                      0x02 /* Version */ ))!=0){
+               rc = -EEFI ( efirc );
                DBGC ( efidrv, "EFIBOFM " PCI_FMT " could not register "
                       "support: %s\n", PCI_ARGS ( &efipci->pci ),
-                      efi_strerror ( efirc ) );
+                      strerror ( rc ) );
                goto err_cannot_register;
        }
 
@@ -226,7 +226,7 @@ efi_bofm_supported ( EFI_DRIVER_BINDING_PROTOCOL *driver,
  err_no_driver:
        efipci_destroy ( efidrv, efipci );
  err_not_pci:
-       return efirc;
+       return EFIRC ( rc );
 }
 
 /**
@@ -254,25 +254,27 @@ static EFI_STATUS EFIAPI efi_bofm_start ( EFI_DRIVER_BINDING_PROTOCOL *driver,
        struct efi_pci_device *efipci;
        IBM_BOFM_TABLE *bofmtab;
        IBM_BOFM_TABLE *bofmtab2;
-       EFI_STATUS efirc;
        int bofmrc;
+       EFI_STATUS efirc;
+       int rc;
 
        DBGCP ( efidrv, "EFIBOFM DRIVER_START %p (%p)\n", device, child );
 
        /* Create corresponding PCI device */
        efipci = efipci_create ( efidrv, device );
        if ( ! efipci ) {
-               efirc = EFI_OUT_OF_RESOURCES;
+               rc = -ENOMEM;
                goto err_create;
        }
 
        /* Enable PCI device */
-       if ( ( efirc = efipci_enable ( efipci ) ) != 0 )
+       if ( ( rc = efipci_enable ( efipci ) ) != 0 )
                goto err_enable;
 
        /* Locate BOFM protocol */
        if ( ( efirc = bs->LocateProtocol ( &bofm1_protocol_guid, NULL,
                                            &bofm1.interface ) ) != 0 ) {
+               rc = -EEFI ( efirc );
                DBGC ( efidrv, "EFIBOFM " PCI_FMT " cannot find BOFM "
                       "protocol\n", PCI_ARGS ( &efipci->pci ) );
                goto err_locate_bofm;
@@ -324,17 +326,19 @@ static EFI_STATUS EFIAPI efi_bofm_start ( EFI_DRIVER_BINDING_PROTOCOL *driver,
        if ( bofmtab2 ) {
                if ( ( efirc = bofm2.bofm2->SetStatus ( bofm2.bofm2, device,
                                                        FALSE, bofmrc ) ) != 0){
+                       rc = -EEFI ( efirc );
                        DBGC ( efidrv, "EFIBOFM " PCI_FMT " could not set "
                               "BOFM2 status: %s\n", PCI_ARGS ( &efipci->pci ),
-                              efi_strerror ( efirc ) );
+                              strerror ( rc ) );
                        goto err_set_status;
                }
        } else {
                if ( ( efirc = bofm1.bofm1->SetStatus ( bofm1.bofm1, device,
                                                        FALSE, bofmrc ) ) != 0){
+                       rc = -EEFI ( efirc );
                        DBGC ( efidrv, "EFIBOFM " PCI_FMT " could not set "
                               "BOFM status: %s\n", PCI_ARGS ( &efipci->pci ),
-                              efi_strerror ( efirc ) );
+                              strerror ( rc ) );
                        goto err_set_status;
                }
        }
@@ -350,7 +354,7 @@ static EFI_STATUS EFIAPI efi_bofm_start ( EFI_DRIVER_BINDING_PROTOCOL *driver,
  err_enable:
        efipci_destroy ( efidrv, efipci );
  err_create:
-       return efirc;
+       return EFIRC ( rc );
 }
 
 /**
@@ -385,12 +389,12 @@ static struct efi_driver efi_bofm_driver =
  */
 static void efi_bofm_driver_init ( void ) {
        struct efi_driver *efidrv = &efi_bofm_driver;
-       EFI_STATUS efirc;
+       int rc;
 
        /* Install driver */
-       if ( ( efirc = efi_driver_install ( efidrv ) ) != 0 ) {
+       if ( ( rc = efi_driver_install ( efidrv ) ) != 0 ) {
                DBGC ( efidrv, "EFIBOFM could not install driver: %s\n",
-                      efi_strerror ( efirc ) );
+                      strerror ( rc ) );
                return;
        }
 
index a30ca301b85d76927912635b317fdcacdc4a3a56..d86d30c91e2d05f77c1da03d904db95aae5c06cb 100644 (file)
@@ -20,6 +20,8 @@
 FILE_LICENCE ( GPL2_OR_LATER );
 
 #include <stddef.h>
+#include <string.h>
+#include <errno.h>
 #include <assert.h>
 #include <ipxe/efi/efi.h>
 #include <ipxe/ansiesc.h>
@@ -227,6 +229,7 @@ static int efi_getchar ( void ) {
        const char *ansi_seq;
        EFI_INPUT_KEY key;
        EFI_STATUS efirc;
+       int rc;
 
        /* If we are mid-sequence, pass out the next byte */
        if ( *ansi_input )
@@ -234,8 +237,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: %s\n",
-                     efi_strerror ( efirc ) );
+               rc = -EEFI ( efirc );
+               DBG ( "EFI could not read keystroke: %s\n", strerror ( rc ) );
                return 0;
        }
        DBG2 ( "EFI read key stroke with unicode %04x scancode %04x\n",
index a7ba7e2edd4f2ede8324d87a74fe8a2aadac6c5e..4ed6660772e45af069ce8e685f609944dd250f58 100644 (file)
@@ -28,6 +28,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
 
 #include <stdio.h>
 #include <string.h>
+#include <errno.h>
 #include <ipxe/uuid.h>
 #include <ipxe/efi/efi.h>
 #include <ipxe/efi/efi_driver.h>
@@ -67,12 +68,14 @@ void dbg_efi_protocols ( EFI_HANDLE handle ) {
        UINTN count;
        unsigned int i;
        EFI_STATUS efirc;
+       int rc;
 
        /* Retrieve list of protocols */
        if ( ( efirc = bs->ProtocolsPerHandle ( handle, &protocols,
                                                &count ) ) != 0 ) {
+               rc = -EEFI ( efirc );
                printf ( "EFI could not retrieve protocols for %p: %s\n",
-                        handle, efi_strerror ( efirc ) );
+                        handle, strerror ( rc ) );
                return;
        }
 
index 7b19ad3a2ddcfa43759c031390bc5cf41e1de017..80279f7f9fe556c885442c0a5cde6636ab89a155 100644 (file)
@@ -20,6 +20,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
 
 #include <stdlib.h>
 #include <string.h>
+#include <errno.h>
 #include <ipxe/open.h>
 #include <ipxe/process.h>
 #include <ipxe/iobuf.h>
@@ -59,7 +60,7 @@ struct efi_download_file {
  */
 static void efi_download_close ( struct efi_download_file *file, int rc ) {
 
-       file->finish_callback ( file->context, RC_TO_EFIRC ( rc ) );
+       file->finish_callback ( file->context, EFIRC ( rc ) );
 
        intf_shutdown ( &file->xfer, rc );
 }
@@ -77,6 +78,7 @@ static int efi_download_deliver_iob ( struct efi_download_file *file,
                                      struct xfer_metadata *meta ) {
        EFI_STATUS efirc;
        size_t len = iob_len ( iobuf );
+       int rc;
 
        /* Calculate new buffer position */
        if ( meta->flags & XFER_FL_ABS_OFFSET )
@@ -84,14 +86,21 @@ static int efi_download_deliver_iob ( struct efi_download_file *file,
        file->pos += meta->offset;
 
        /* Call out to the data handler */
-       efirc = file->data_callback ( file->context, iobuf->data,
-                                     len, file->pos );
+       if ( ( efirc = file->data_callback ( file->context, iobuf->data,
+                                            len, file->pos ) ) != 0 ) {
+               rc = -EEFI ( efirc );
+               goto err_callback;
+       }
 
        /* Update current buffer position */
        file->pos += len;
 
+       /* Success */
+       rc = 0;
+
+ err_callback:
        free_iob ( iobuf );
-       return EFIRC_TO_RC ( efirc );
+       return rc;
 }
 
 /** Data transfer interface operations */
@@ -135,7 +144,7 @@ efi_download_start ( IPXE_DOWNLOAD_PROTOCOL *This __unused,
        rc = xfer_open ( &file->xfer, LOCATION_URI_STRING, Url );
        if ( rc ) {
                free ( file );
-               return RC_TO_EFIRC ( rc );
+               return EFIRC ( rc );
        }
 
        file->pos = 0;
@@ -162,7 +171,7 @@ efi_download_abort ( IPXE_DOWNLOAD_PROTOCOL *This __unused,
                     EFI_STATUS Status ) {
        struct efi_download_file *file = File;
 
-       efi_download_close ( file, EFIRC_TO_RC ( Status ) );
+       efi_download_close ( file, -EEFI ( Status ) );
        return EFI_SUCCESS;
 }
 
@@ -195,6 +204,7 @@ static IPXE_DOWNLOAD_PROTOCOL ipxe_download_protocol_interface = {
 int efi_download_install ( EFI_HANDLE *handle ) {
        EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
        EFI_STATUS efirc;
+       int rc;
 
        efirc = bs->InstallMultipleProtocolInterfaces (
                        handle,
@@ -202,9 +212,10 @@ int efi_download_install ( EFI_HANDLE *handle ) {
                        &ipxe_download_protocol_interface,
                        NULL );
        if ( efirc ) {
+               rc = -EEFI ( efirc );
                DBG ( "Could not install download protocol: %s\n",
-                     efi_strerror ( efirc ) );
-               return EFIRC_TO_RC ( efirc );
+                     strerror ( rc ) );
+               return rc;
        }
 
        return 0;
index deb3cf2cd59c906c9ad0bb23de3d54bdabd4fe9b..13ed1f501eeb8cb77ab1f9de5c6676af6dcd0953 100644 (file)
@@ -21,6 +21,8 @@ FILE_LICENCE ( GPL2_OR_LATER );
 
 #include <stddef.h>
 #include <stdio.h>
+#include <string.h>
+#include <errno.h>
 #include <ipxe/efi/efi.h>
 #include <ipxe/efi/Protocol/DriverBinding.h>
 #include <ipxe/efi/Protocol/ComponentName2.h>
@@ -122,11 +124,12 @@ efi_driver_get_controller_name ( EFI_COMPONENT_NAME2_PROTOCOL *wtf __unused,
  * @v efidrv           EFI driver
  * @ret efirc          EFI status code
  */
-EFI_STATUS efi_driver_install ( struct efi_driver *efidrv ) {
+int efi_driver_install ( struct efi_driver *efidrv ) {
        EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
        EFI_DRIVER_BINDING_PROTOCOL *driver = &efidrv->driver;
        EFI_COMPONENT_NAME2_PROTOCOL *wtf = &efidrv->wtf;
        EFI_STATUS efirc;
+       int rc;
 
        /* Configure driver binding protocol */
        driver->ImageHandle = efi_image_handle;
@@ -148,9 +151,10 @@ EFI_STATUS efi_driver_install ( struct efi_driver *efidrv ) {
                        &efi_driver_binding_protocol_guid, driver,
                        &efi_component_name2_protocol_guid, wtf,
                        NULL ) ) != 0 ) {
+               rc = -EEFI ( efirc );
                DBGC ( efidrv, "EFIDRV %s could not install protocol: %s\n",
-                      efidrv->name, efi_strerror ( efirc ) );
-               return efirc;
+                      efidrv->name, strerror ( rc ) );
+               return rc;
        }
 
        DBGC ( efidrv, "EFIDRV %s installed\n", efidrv->name );
index 6f9d44f83e39357b1d07f8c736091354de7e13ec..4c482d2e5e91c30d63d85bfa7169100242f46fbb 100644 (file)
@@ -30,6 +30,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <errno.h>
 #include <wchar.h>
 #include <ipxe/image.h>
 #include <ipxe/efi/efi.h>
@@ -549,6 +550,7 @@ static EFI_BLOCK_IO_PROTOCOL efi_block_io_protocol = {
 int efi_file_install ( EFI_HANDLE *handle ) {
        EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
        EFI_STATUS efirc;
+       int rc;
 
        /* Install the simple file system protocol and the block I/O
         * protocol.  We don't have a block device, but large parts of
@@ -563,9 +565,10 @@ int efi_file_install ( EFI_HANDLE *handle ) {
                        &efi_block_io_protocol,
                        &efi_simple_file_system_protocol_guid,
                        &efi_simple_file_system_protocol, NULL ) ) != 0 ) {
+               rc = -EEFI ( efirc );
                DBGC ( handle, "Could not install simple file system protocol: "
-                      "%s\n", efi_strerror ( efirc ) );
-               return EFIRC_TO_RC ( efirc );
+                      "%s\n", strerror ( rc ) );
+               return rc;
        }
 
        return 0;
index e40de4dd59ec8ea3770272568932d13f5905fb87..2f6ca89c2aef7bd812482fcf560e3d5d2d60a3e6 100644 (file)
@@ -20,6 +20,7 @@
 FILE_LICENCE ( GPL2_OR_LATER );
 
 #include <string.h>
+#include <errno.h>
 #include <ipxe/efi/efi.h>
 #include <ipxe/efi/Protocol/LoadedImage.h>
 #include <ipxe/efi/Protocol/DevicePath.h>
@@ -94,6 +95,7 @@ EFI_STATUS efi_init ( EFI_HANDLE image_handle,
        void *loaded_image;
        void *loaded_image_path;
        EFI_STATUS efirc;
+       int rc;
 
        /* Store image handle and system table pointer for future use */
        efi_image_handle = image_handle;
@@ -149,8 +151,9 @@ EFI_STATUS efi_init ( EFI_HANDLE image_handle,
                                &efi_loaded_image_protocol_guid,
                                &loaded_image, image_handle, NULL,
                                EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) {
+               rc = -EEFI ( efirc );
                DBGC ( systab, "EFI could not get loaded image protocol: %s",
-                      efi_strerror ( efirc ) );
+                      strerror ( rc ) );
                return efirc;
        }
        efi_loaded_image = loaded_image;
@@ -162,8 +165,9 @@ EFI_STATUS efi_init ( EFI_HANDLE image_handle,
                                &efi_loaded_image_device_path_protocol_guid,
                                &loaded_image_path, image_handle, NULL,
                                EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) {
+               rc = -EEFI ( efirc );
                DBGC ( systab, "EFI could not get loaded image device path "
-                      "protocol: %s", efi_strerror ( efirc ) );
+                      "protocol: %s", strerror ( rc ) );
                return efirc;
        }
        efi_loaded_image_path = loaded_image_path;
@@ -179,8 +183,9 @@ EFI_STATUS efi_init ( EFI_HANDLE image_handle,
        if ( ( efirc = bs->CreateEvent ( EVT_SIGNAL_EXIT_BOOT_SERVICES,
                                         TPL_CALLBACK, efi_shutdown_hook,
                                         NULL, &efi_shutdown_event ) ) != 0 ) {
+               rc = -EEFI ( efirc );
                DBGC ( systab, "EFI could not create ExitBootServices event: "
-                      "%s\n", efi_strerror ( efirc ) );
+                      "%s\n", strerror ( rc ) );
                return efirc;
        }
 
index 0288cf326d3088ecbc6cb35c8a9750a4c8d1a030..d6095d3e334d11aa42ac2330fb557426647f165b 100644 (file)
@@ -57,13 +57,15 @@ static unsigned long efipci_address ( struct pci_device *pci,
 int efipci_read ( struct pci_device *pci, unsigned long location,
                  void *value ) {
        EFI_STATUS efirc;
+       int rc;
 
        if ( ( efirc = efipci->Pci.Read ( efipci, EFIPCI_WIDTH ( location ),
                                          efipci_address ( pci, location ), 1,
                                          value ) ) != 0 ) {
+               rc = -EEFI ( efirc );
                DBG ( "EFIPCI config read from " PCI_FMT " offset %02lx "
                      "failed: %s\n", PCI_ARGS ( pci ),
-                     EFIPCI_OFFSET ( location ), efi_strerror ( efirc ) );
+                     EFIPCI_OFFSET ( location ), strerror ( rc ) );
                return -EIO;
        }
 
@@ -73,13 +75,15 @@ int efipci_read ( struct pci_device *pci, unsigned long location,
 int efipci_write ( struct pci_device *pci, unsigned long location,
                   unsigned long value ) {
        EFI_STATUS efirc;
+       int rc;
 
        if ( ( efirc = efipci->Pci.Write ( efipci, EFIPCI_WIDTH ( location ),
                                           efipci_address ( pci, location ), 1,
                                           &value ) ) != 0 ) {
+               rc = -EEFI ( efirc );
                DBG ( "EFIPCI config write to " PCI_FMT " offset %02lx "
                      "failed: %s\n", PCI_ARGS ( pci ),
-                     EFIPCI_OFFSET ( location ), efi_strerror ( efirc ) );
+                     EFIPCI_OFFSET ( location ), strerror ( rc ) );
                return -EIO;
        }
 
@@ -149,6 +153,7 @@ struct efi_pci_device * efipci_create ( struct efi_driver *efidrv,
                                          efidrv->driver.DriverBindingHandle,
                                          device,
                                          EFI_OPEN_PROTOCOL_BY_DRIVER )) !=0 ){
+               rc = -EEFI ( efirc );
                DBGCP ( efipci, "EFIPCI device %p is not a PCI device\n",
                        device );
                goto err_open_protocol;
@@ -160,8 +165,9 @@ struct efi_pci_device * efipci_create ( struct efi_driver *efidrv,
                                                    &pci_segment,
                                                    &pci_bus, &pci_dev,
                                                    &pci_fn ) ) != 0 ) {
+               rc = -EEFI ( efirc );
                DBGC ( efipci, "EFIPCI device %p could not get PCI "
-                      "location: %s\n", device, efi_strerror ( efirc ) );
+                      "location: %s\n", device, strerror ( rc ) );
                goto err_get_location;
        }
        DBGC2 ( efipci, "EFIPCI device %p is PCI %04lx:%02lx:%02lx.%lx\n",
@@ -185,6 +191,7 @@ struct efi_pci_device * efipci_create ( struct efi_driver *efidrv,
                                          efidrv->driver.DriverBindingHandle,
                                          device,
                                          EFI_OPEN_PROTOCOL_BY_DRIVER )) !=0 ){
+               rc = -EEFI ( efirc );
                DBGC ( efipci, "EFIPCI " PCI_FMT " has no device path\n",
                       PCI_ARGS ( &efipci->pci ) );
                goto err_no_device_path;
@@ -213,9 +220,9 @@ struct efi_pci_device * efipci_create ( struct efi_driver *efidrv,
  * Enable EFI PCI device
  *
  * @v efipci           EFI PCI device
- * @ret efirc          EFI status code
+ * @ret rc             Return status code
  */
-EFI_STATUS efipci_enable ( struct efi_pci_device *efipci ) {
+int efipci_enable ( struct efi_pci_device *efipci ) {
        EFI_PCI_IO_PROTOCOL *pci_io = efipci->pci_io;
 
        /* Try to enable I/O cycles, memory cycles, and bus mastering.
@@ -273,8 +280,7 @@ struct efi_pci_device * efipci_find ( struct device *dev ) {
  * @v device           EFI child device
  * @ret efirc          EFI status code
  */
-EFI_STATUS efipci_child_add ( struct efi_pci_device *efipci,
-                             EFI_HANDLE device ) {
+int efipci_child_add ( struct efi_pci_device *efipci, EFI_HANDLE device ) {
        EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
        struct efi_driver *efidrv = efipci->efidrv;
        union {
@@ -282,6 +288,7 @@ EFI_STATUS efipci_child_add ( struct efi_pci_device *efipci,
                void *interface;
        } pci_io;
        EFI_STATUS efirc;
+       int rc;
 
        /* Re-open the PCI_IO_PROTOCOL */
        if ( ( efirc = bs->OpenProtocol ( efipci->device,
@@ -291,9 +298,10 @@ EFI_STATUS efipci_child_add ( struct efi_pci_device *efipci,
                                          device,
                                          EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
                                          ) ) != 0 ) {
+               rc = -EEFI ( efirc );
                DBGC ( efipci, "EFIPCI " PCI_FMT " could not add child: %s\n",
-                      PCI_ARGS ( &efipci->pci ), efi_strerror ( efirc ) );
-               return efirc;
+                      PCI_ARGS ( &efipci->pci ), strerror ( rc ) );
+               return rc;
        }
 
        return 0;
@@ -355,7 +363,6 @@ efipci_supported ( EFI_DRIVER_BINDING_PROTOCOL *driver, EFI_HANDLE device,
        struct efi_driver *efidrv =
                container_of ( driver, struct efi_driver, driver );
        struct efi_pci_device *efipci;
-       EFI_STATUS efirc;
        int rc;
 
        DBGCP ( efidrv, "EFIPCI DRIVER_SUPPORTED %p (%p)\n", device, child );
@@ -364,7 +371,7 @@ efipci_supported ( EFI_DRIVER_BINDING_PROTOCOL *driver, EFI_HANDLE device,
        efipci = efipci_create ( efidrv, device );
        if ( ! efipci ) {
                /* Non-PCI devices are simply unsupported */
-               efirc = EFI_UNSUPPORTED;
+               rc = -ENOTSUP;
                goto err_not_pci;
        }
 
@@ -372,7 +379,6 @@ efipci_supported ( EFI_DRIVER_BINDING_PROTOCOL *driver, EFI_HANDLE device,
        if ( ( rc = pci_find_driver ( &efipci->pci ) ) != 0 ) {
                DBGCP ( efipci, "EFIPCI " PCI_FMT " has no driver\n",
                        PCI_ARGS ( &efipci->pci ) );
-               efirc = EFI_UNSUPPORTED;
                goto err_no_driver;
        }
 
@@ -387,7 +393,7 @@ efipci_supported ( EFI_DRIVER_BINDING_PROTOCOL *driver, EFI_HANDLE device,
  err_no_driver:
        efipci_destroy ( efidrv, efipci );
  err_not_pci:
-       return efirc;
+       return EFIRC ( rc );
 }
 
 /**
@@ -404,7 +410,6 @@ efipci_start ( EFI_DRIVER_BINDING_PROTOCOL *driver, EFI_HANDLE device,
        struct efi_driver *efidrv =
                container_of ( driver, struct efi_driver, driver );
        struct efi_pci_device *efipci;
-       EFI_STATUS efirc;
        int rc;
 
        DBGC ( efidrv, "EFIPCI DRIVER_START %p (%p)\n", device, child );
@@ -412,7 +417,7 @@ efipci_start ( EFI_DRIVER_BINDING_PROTOCOL *driver, EFI_HANDLE device,
        /* Create corresponding PCI device */
        efipci = efipci_create ( efidrv, device );
        if ( ! efipci ) {
-               efirc = EFI_OUT_OF_RESOURCES;
+               rc = -ENOMEM;
                goto err_create;
        }
 
@@ -420,12 +425,11 @@ efipci_start ( EFI_DRIVER_BINDING_PROTOCOL *driver, EFI_HANDLE device,
        if ( ( rc = pci_find_driver ( &efipci->pci ) ) != 0 ) {
                DBGC ( efipci, "EFIPCI " PCI_FMT " has no driver\n",
                       PCI_ARGS ( &efipci->pci ) );
-               efirc = RC_TO_EFIRC ( rc );
                goto err_find_driver;
        }
 
        /* Enable PCI device */
-       if ( ( efirc = efipci_enable ( efipci ) ) != 0 )
+       if ( ( rc = efipci_enable ( efipci ) ) != 0 )
                goto err_enable;
 
        /* Probe driver */
@@ -433,7 +437,6 @@ efipci_start ( EFI_DRIVER_BINDING_PROTOCOL *driver, EFI_HANDLE device,
                DBGC ( efipci, "EFIPCI " PCI_FMT " could not probe driver "
                       "\"%s\": %s\n", PCI_ARGS ( &efipci->pci ),
                       efipci->pci.id->name, strerror ( rc ) );
-               efirc = RC_TO_EFIRC ( rc );
                goto err_probe;
        }
 
@@ -445,7 +448,7 @@ efipci_start ( EFI_DRIVER_BINDING_PROTOCOL *driver, EFI_HANDLE device,
  err_find_driver:
        efipci_destroy ( efidrv, efipci );
  err_create:
-       return efirc;
+       return EFIRC ( rc );
 }
 
 /**
@@ -494,12 +497,12 @@ static struct efi_driver efipci_driver =
  */
 static void efipci_driver_startup ( void ) {
        struct efi_driver *efidrv = &efipci_driver;
-       EFI_STATUS efirc;
+       int rc;
 
        /* Install driver */
-       if ( ( efirc = efi_driver_install ( efidrv ) ) != 0 ) {
+       if ( ( rc = efi_driver_install ( efidrv ) ) != 0 ) {
                DBGC ( efidrv, "EFIPCI could not install driver: %s\n",
-                      efi_strerror ( efirc ) );
+                      strerror ( rc ) );
                return;
        }
 
index 95e39b7d954916a2c438d52255f31359695ca84d..adeb38de3f1d5ce69ae42d767b106025559f2bf4 100644 (file)
@@ -177,7 +177,7 @@ efi_snp_initialize ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
        if ( ( rc = netdev_open ( snpdev->netdev ) ) != 0 ) {
                DBGC ( snpdev, "SNPDEV %p could not open %s: %s\n",
                       snpdev, snpdev->netdev->name, strerror ( rc ) );
-               return RC_TO_EFIRC ( rc );
+               return EFIRC ( rc );
        }
 
        snpdev->mode.State = EfiSimpleNetworkInitialized;
@@ -206,7 +206,7 @@ efi_snp_reset ( EFI_SIMPLE_NETWORK_PROTOCOL *snp, BOOLEAN ext_verify ) {
        if ( ( rc = netdev_open ( snpdev->netdev ) ) != 0 ) {
                DBGC ( snpdev, "SNPDEV %p could not reopen %s: %s\n",
                       snpdev, snpdev->netdev->name, strerror ( rc ) );
-               return RC_TO_EFIRC ( rc );
+               return EFIRC ( rc );
        }
 
        snpdev->mode.State = EfiSimpleNetworkInitialized;
@@ -366,7 +366,7 @@ efi_snp_mcast_ip_to_mac ( EFI_SIMPLE_NETWORK_PROTOCOL *snp, BOOLEAN ipv6,
                                           ip, mac ) ) != 0 ) {
                DBGC ( snpdev, "SNPDEV %p could not hash %s: %s\n",
                       snpdev, ip_str, strerror ( rc ) );
-               return RC_TO_EFIRC ( rc );
+               return EFIRC ( rc );
        }
 
        return 0;
@@ -490,7 +490,6 @@ efi_snp_transmit ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
        struct io_buffer *iobuf;
        size_t payload_len;
        int rc;
-       EFI_STATUS efirc;
 
        DBGC2 ( snpdev, "SNPDEV %p TRANSMIT %p+%lx", snpdev, data,
                ( ( unsigned long ) len ) );
@@ -515,25 +514,25 @@ efi_snp_transmit ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
                        DBGC ( snpdev, "SNPDEV %p TX invalid header length "
                               "%ld\n", snpdev,
                               ( ( unsigned long ) ll_header_len ) );
-                       efirc = EFI_INVALID_PARAMETER;
+                       rc = -EINVAL;
                        goto err_sanity;
                }
                if ( len < ll_header_len ) {
                        DBGC ( snpdev, "SNPDEV %p invalid packet length %ld\n",
                               snpdev, ( ( unsigned long ) len ) );
-                       efirc = EFI_BUFFER_TOO_SMALL;
+                       rc = -EINVAL;
                        goto err_sanity;
                }
                if ( ! ll_dest ) {
                        DBGC ( snpdev, "SNPDEV %p TX missing destination "
                               "address\n", snpdev );
-                       efirc = EFI_INVALID_PARAMETER;
+                       rc = -EINVAL;
                        goto err_sanity;
                }
                if ( ! net_proto ) {
                        DBGC ( snpdev, "SNPDEV %p TX missing network "
                               "protocol\n", snpdev );
-                       efirc = EFI_INVALID_PARAMETER;
+                       rc = -EINVAL;
                        goto err_sanity;
                }
                if ( ! ll_src )
@@ -547,7 +546,7 @@ efi_snp_transmit ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
        if ( ! iobuf ) {
                DBGC ( snpdev, "SNPDEV %p TX could not allocate %ld-byte "
                       "buffer\n", snpdev, ( ( unsigned long ) len ) );
-               efirc = EFI_DEVICE_ERROR;
+               rc = -ENOMEM;
                goto err_alloc_iob;
        }
        iob_reserve ( iobuf, ( MAX_LL_HEADER_LEN -
@@ -562,7 +561,6 @@ efi_snp_transmit ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
                                                htons ( *net_proto ) )) != 0 ){
                        DBGC ( snpdev, "SNPDEV %p TX could not construct "
                               "header: %s\n", snpdev, strerror ( rc ) );
-                       efirc = RC_TO_EFIRC ( rc );
                        goto err_ll_push;
                }
        }
@@ -571,7 +569,6 @@ efi_snp_transmit ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
        if ( ( rc = netdev_tx ( snpdev->netdev, iob_disown ( iobuf ) ) ) != 0){
                DBGC ( snpdev, "SNPDEV %p TX could not transmit: %s\n",
                       snpdev, strerror ( rc ) );
-               efirc = RC_TO_EFIRC ( rc );
                goto err_tx;
        }
 
@@ -586,7 +583,7 @@ efi_snp_transmit ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
        free_iob ( iobuf );
  err_alloc_iob:
  err_sanity:
-       return efirc;
+       return EFIRC ( rc );
 }
 
 /**
@@ -615,7 +612,6 @@ efi_snp_receive ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
        uint16_t iob_net_proto;
        unsigned int iob_flags;
        int rc;
-       EFI_STATUS efirc;
 
        DBGC2 ( snpdev, "SNPDEV %p RECEIVE %p(+%lx)", snpdev, data,
                ( ( unsigned long ) *len ) );
@@ -627,7 +623,7 @@ efi_snp_receive ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
        iobuf = netdev_rx_dequeue ( snpdev->netdev );
        if ( ! iobuf ) {
                DBGC2 ( snpdev, "\n" );
-               efirc = EFI_NOT_READY;
+               rc = -EAGAIN;
                goto out_no_packet;
        }
        DBGC2 ( snpdev, "+%zx\n", iob_len ( iobuf ) );
@@ -642,7 +638,6 @@ efi_snp_receive ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
                                        &iob_flags ) ) != 0 ) {
                DBGC ( snpdev, "SNPDEV %p could not parse header: %s\n",
                       snpdev, strerror ( rc ) );
-               efirc = RC_TO_EFIRC ( rc );
                goto out_bad_ll_header;
        }
 
@@ -656,12 +651,12 @@ efi_snp_receive ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
        if ( net_proto )
                *net_proto = ntohs ( iob_net_proto );
 
-       efirc = 0;
+       rc = 0;
 
  out_bad_ll_header:
        free_iob ( iobuf );
 out_no_packet:
-       return efirc;
+       return EFIRC ( rc );
 }
 
 /**
@@ -879,9 +874,9 @@ static int efi_snp_probe ( struct net_device *netdev ) {
        if ( ( efirc = bs->CreateEvent ( EVT_NOTIFY_WAIT, TPL_NOTIFY,
                                         efi_snp_wait_for_packet, snpdev,
                                         &snpdev->snp.WaitForPacket ) ) != 0 ){
+               rc = -EEFI ( efirc );
                DBGC ( snpdev, "SNPDEV %p could not create event: %s\n",
-                      snpdev, efi_strerror ( efirc ) );
-               rc = EFIRC_TO_RC ( efirc );
+                      snpdev, strerror ( rc ) );
                goto err_create_event;
        }
 
@@ -944,18 +939,17 @@ static int efi_snp_probe ( struct net_device *netdev ) {
                        &efi_component_name2_protocol_guid, &snpdev->name2,
                        &efi_load_file_protocol_guid, &snpdev->load_file,
                        NULL ) ) != 0 ) {
+               rc = -EEFI ( efirc );
                DBGC ( snpdev, "SNPDEV %p could not install protocols: "
-                      "%s\n", snpdev, efi_strerror ( efirc ) );
-               rc = EFIRC_TO_RC ( efirc );
+                      "%s\n", snpdev, strerror ( rc ) );
                goto err_install_protocol_interface;
        }
 
        /* Add as child of PCI device */
-       if ( ( efirc = efipci_child_add ( efipci, snpdev->handle ) ) != 0 ) {
+       if ( ( rc = efipci_child_add ( efipci, snpdev->handle ) ) != 0 ) {
                DBGC ( snpdev, "SNPDEV %p could not become child of " PCI_FMT
                       ": %s\n", snpdev, PCI_ARGS ( &efipci->pci ),
-                      efi_strerror ( efirc ) );
-               rc = EFIRC_TO_RC ( efirc );
+                      strerror ( rc ) );
                goto err_efipci_child_add;
        }
 
index 3a1193a3855f4a6c128d8f5bad18afd18baaa9ee..9ea15a6238150bf16e88dc339b3e24fa51c5fe6c 100644 (file)
@@ -544,7 +544,7 @@ efi_snp_hii_extract_config ( const EFI_HII_CONFIG_ACCESS_PROTOCOL *hii,
                if ( ( rc = efi_snp_hii_process ( snpdev, pos, progress,
                                                  results, &have_setting,
                                                  efi_snp_hii_fetch ) ) != 0 ) {
-                       return RC_TO_EFIRC ( rc );
+                       return EFIRC ( rc );
                }
        }
 
@@ -558,7 +558,7 @@ efi_snp_hii_extract_config ( const EFI_HII_CONFIG_ACCESS_PROTOCOL *hii,
                        if ( ( rc = efi_snp_hii_fetch ( snpdev, setting->name,
                                                        NULL, results,
                                                        NULL ) ) != 0 ) {
-                               return RC_TO_EFIRC ( rc );
+                               return EFIRC ( rc );
                        }
                }
        }
@@ -592,7 +592,7 @@ efi_snp_hii_route_config ( const EFI_HII_CONFIG_ACCESS_PROTOCOL *hii,
                if ( ( rc = efi_snp_hii_process ( snpdev, pos, progress,
                                                  NULL, NULL,
                                                  efi_snp_hii_store ) ) != 0 ) {
-                       return RC_TO_EFIRC ( rc );
+                       return EFIRC ( rc );
                }
        }
 
@@ -657,9 +657,9 @@ int efi_snp_hii_install ( struct efi_snp_device *snpdev ) {
        if ( ( efirc = efihii->NewPackageList ( efihii, snpdev->package_list,
                                                snpdev->handle,
                                                &snpdev->hii_handle ) ) != 0 ) {
+               rc = -EEFI ( efirc );
                DBGC ( snpdev, "SNPDEV %p could not add HII packages: %s\n",
-                      snpdev, efi_strerror ( efirc ) );
-               rc = EFIRC_TO_RC ( efirc );
+                      snpdev, strerror ( rc ) );
                goto err_new_package_list;
        }
 
@@ -668,9 +668,9 @@ int efi_snp_hii_install ( struct efi_snp_device *snpdev ) {
                         &snpdev->handle,
                         &efi_hii_config_access_protocol_guid, &snpdev->hii,
                         NULL ) ) != 0 ) {
+               rc = -EEFI ( efirc );
                DBGC ( snpdev, "SNPDEV %p could not install HII protocol: %s\n",
-                      snpdev, efi_strerror ( efirc ) );
-               rc = EFIRC_TO_RC ( efirc );
+                      snpdev, strerror ( rc ) );
                goto err_install_protocol;
        }
 
diff --git a/src/interface/efi/efi_strerror.c b/src/interface/efi/efi_strerror.c
deleted file mode 100644 (file)
index 46bfbbb..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>.
- *
- * 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., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
- */
-
-FILE_LICENCE ( GPL2_OR_LATER );
-
-#include <stdio.h>
-#include <ipxe/efi/efi.h>
-
-/** @file
- *
- * iPXE 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;
-}
index b110cae29b8c31815dae0af2ab2a467bb96bc569..7a1ff786910b6e85045eb43c119e984d5853a829 100644 (file)
@@ -19,6 +19,8 @@
 
 FILE_LICENCE ( GPL2_OR_LATER );
 
+#include <string.h>
+#include <errno.h>
 #include <limits.h>
 #include <assert.h>
 #include <unistd.h>
@@ -54,10 +56,12 @@ EFI_REQUIRE_PROTOCOL ( EFI_CPU_ARCH_PROTOCOL, &cpu_arch );
 static void efi_udelay ( unsigned long usecs ) {
        EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
        EFI_STATUS efirc;
+       int rc;
 
        if ( ( efirc = bs->Stall ( usecs ) ) != 0 ) {
+               rc = -EEFI ( efirc );
                DBG ( "EFI could not delay for %ldus: %s\n",
-                     usecs, efi_strerror ( efirc ) );
+                     usecs, strerror ( rc ) );
                /* Probably screwed */
        }
 }
@@ -70,12 +74,13 @@ static void efi_udelay ( unsigned long usecs ) {
 static unsigned long efi_currticks ( void ) {
        UINT64 time;
        EFI_STATUS efirc;
+       int rc;
 
        /* Read CPU timer 0 (TSC) */
        if ( ( efirc = cpu_arch->GetTimerValue ( cpu_arch, 0, &time,
                                                 NULL ) ) != 0 ) {
-               DBG ( "EFI could not read CPU timer: %s\n",
-                     efi_strerror ( efirc ) );
+               rc = -EEFI ( efirc );
+               DBG ( "EFI could not read CPU timer: %s\n", strerror ( rc ) );
                /* Probably screwed */
                return -1UL;
        }
index b49949327531a30ddea3e970f2d028a155df50ee..356efaa6f8a777a50f7abd45207998e6496d95d2 100644 (file)
@@ -19,6 +19,8 @@
 
 FILE_LICENCE ( GPL2_OR_LATER );
 
+#include <string.h>
+#include <errno.h>
 #include <assert.h>
 #include <ipxe/umalloc.h>
 #include <ipxe/efi/efi.h>
@@ -49,6 +51,7 @@ static userptr_t efi_urealloc ( userptr_t old_ptr, size_t new_size ) {
        userptr_t new_ptr = UNOWHERE;
        size_t old_size;
        EFI_STATUS efirc;
+       int rc;
 
        /* Allocate new memory if necessary.  If allocation fails,
         * return without touching the old block.
@@ -59,8 +62,9 @@ static userptr_t efi_urealloc ( userptr_t old_ptr, size_t new_size ) {
                                                   EfiBootServicesData,
                                                   new_pages,
                                                   &phys_addr ) ) != 0 ) {
+                       rc = -EEFI ( efirc );
                        DBG ( "EFI could not allocate %d pages: %s\n",
-                             new_pages, efi_strerror ( efirc ) );
+                             new_pages, strerror ( rc ) );
                        return UNULL;
                }
                assert ( phys_addr != 0 );
@@ -84,8 +88,9 @@ 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 ){
+                       rc = -EEFI ( efirc );
                        DBG ( "EFI could not free %d pages at %llx: %s\n",
-                             old_pages, phys_addr, efi_strerror ( efirc ) );
+                             old_pages, phys_addr, strerror ( rc ) );
                        /* Not fatal; we have leaked memory but successfully
                         * allocated (if asked to do so).
                         */