[efi] Perform meaningful error code conversions

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>
pull/13/head
Michael Brown 2013-04-18 21:29:53 +01:00
parent 7348035231
commit 54409583e2
20 changed files with 212 additions and 200 deletions

View File

@ -20,6 +20,7 @@
FILE_LICENCE ( GPL2_OR_LATER ); FILE_LICENCE ( GPL2_OR_LATER );
#include <stdlib.h> #include <stdlib.h>
#include <errno.h>
#include <ipxe/efi/efi.h> #include <ipxe/efi/efi.h>
/** /**
@ -38,5 +39,5 @@ EFI_STATUS EFIAPI _efi_start ( EFI_HANDLE image_handle,
return efirc; return efirc;
/* Call to main() */ /* Call to main() */
return RC_TO_EFIRC ( main () ); return EFIRC ( main () );
} }

View File

@ -56,20 +56,21 @@ static int snpnet_transmit ( struct net_device *netdev,
struct io_buffer *iobuf ) { struct io_buffer *iobuf ) {
struct snpnet_device *snpnetdev = netdev->priv; struct snpnet_device *snpnetdev = netdev->priv;
EFI_SIMPLE_NETWORK_PROTOCOL *snp = snpnetdev->snp; EFI_SIMPLE_NETWORK_PROTOCOL *snp = snpnetdev->snp;
EFI_STATUS efirc;
void *txbuf=NULL; void *txbuf=NULL;
size_t len = iob_len ( iobuf ); size_t len = iob_len ( iobuf );
EFI_STATUS efirc;
int rc;
efirc = snp->Transmit ( snp, 0, len, iobuf->data, NULL, NULL, NULL ); if ( ( efirc = snp->Transmit ( snp, 0, len, iobuf->data, NULL, NULL,
if (efirc) { NULL ) ) != 0 ) {
return EFIRC_TO_RC ( efirc ); return -EEFI ( efirc );
} }
/* since GetStatus is so inconsistent, don't try more than one outstanding transmit at a time */ /* since GetStatus is so inconsistent, don't try more than one outstanding transmit at a time */
while ( txbuf == NULL ) { while ( txbuf == NULL ) {
efirc = snp->GetStatus ( snp, NULL, &txbuf ); if ( ( efirc = snp->GetStatus ( snp, NULL, &txbuf ) ) != 0 ) {
if ( efirc ) { rc = -EEFI ( efirc );
DBGC ( snp, "SNP %p could not get status %s\n", snp, DBGC ( snp, "SNP %p could not get status %s\n", snp,
efi_strerror ( efirc ) ); strerror ( rc ) );
break; break;
} }
@ -86,9 +87,10 @@ static int snpnet_transmit ( struct net_device *netdev,
static void snpnet_poll ( struct net_device *netdev ) { static void snpnet_poll ( struct net_device *netdev ) {
struct snpnet_device *snpnetdev = netdev->priv; struct snpnet_device *snpnetdev = netdev->priv;
EFI_SIMPLE_NETWORK_PROTOCOL *snp = snpnetdev->snp; EFI_SIMPLE_NETWORK_PROTOCOL *snp = snpnetdev->snp;
EFI_STATUS efirc;
struct io_buffer *iobuf = NULL; struct io_buffer *iobuf = NULL;
UINTN len; UINTN len;
EFI_STATUS efirc;
int rc;
/* Process received packets */ /* Process received packets */
while ( 1 ) { while ( 1 ) {
@ -115,12 +117,13 @@ static void snpnet_poll ( struct net_device *netdev ) {
} }
/* Other error? */ /* Other error? */
if ( efirc ) { if ( efirc != 0 ) {
rc = -EEFI ( efirc );
DBGC ( snp, "SNP %p receive packet error: %s " DBGC ( snp, "SNP %p receive packet error: %s "
"(len was %zd, is now %zd)\n", "(len was %zd, is now %zd)\n",
snp, efi_strerror ( efirc ), iob_len(iobuf), snp, strerror ( rc ), iob_len(iobuf),
(size_t)len ); (size_t)len );
netdev_rx_err ( netdev, iobuf, efirc ); netdev_rx_err ( netdev, iobuf, rc );
break; break;
} }
@ -139,25 +142,27 @@ static void snpnet_poll ( struct net_device *netdev ) {
static int snpnet_open ( struct net_device *netdev ) { static int snpnet_open ( struct net_device *netdev ) {
struct snpnet_device *snpnetdev = netdev->priv; struct snpnet_device *snpnetdev = netdev->priv;
EFI_SIMPLE_NETWORK_PROTOCOL *snp = snpnetdev->snp; EFI_SIMPLE_NETWORK_PROTOCOL *snp = snpnetdev->snp;
EFI_STATUS efirc; EFI_MAC_ADDRESS *mac;
UINT32 enableFlags, disableFlags; UINT32 enableFlags, disableFlags;
EFI_STATUS efirc;
int rc;
snpnetdev->close_state = snp->Mode->State; snpnetdev->close_state = snp->Mode->State;
if ( snp->Mode->State != EfiSimpleNetworkInitialized ) { if ( snp->Mode->State != EfiSimpleNetworkInitialized ) {
efirc = snp->Initialize ( snp, 0, 0 ); if ( ( efirc = snp->Initialize ( snp, 0, 0 ) ) != 0 ) {
if ( efirc ) { rc = -EEFI ( efirc );
DBGC ( snp, "SNP %p could not initialize: %s\n", DBGC ( snp, "SNP %p could not initialize: %s\n",
snp, efi_strerror ( efirc ) ); snp, strerror ( rc ) );
return EFIRC_TO_RC ( efirc ); return rc;
} }
} }
/* Use the default MAC address */ /* Use the default MAC address */
efirc = snp->StationAddress ( snp, FALSE, mac = ( ( void * ) netdev->ll_addr );
(EFI_MAC_ADDRESS *)netdev->ll_addr ); if ( ( efirc = snp->StationAddress ( snp, FALSE, mac ) ) != 0 ) {
if ( efirc ) { rc = -EEFI ( efirc );
DBGC ( snp, "SNP %p could not reset station address: %s\n", 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 /* 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; enableFlags |= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS;
} }
disableFlags &= ~enableFlags; disableFlags &= ~enableFlags;
efirc = snp->ReceiveFilters ( snp, enableFlags, disableFlags, if ( ( efirc = snp->ReceiveFilters ( snp, enableFlags, disableFlags,
FALSE, 0, NULL ); FALSE, 0, NULL ) ) != 0 ) {
if ( efirc ) { rc = -EEFI ( efirc );
DBGC ( snp, "SNP %p could not set receive filters: %s\n", 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 ); 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; struct snpnet_device *snpnetdev = netdev->priv;
EFI_SIMPLE_NETWORK_PROTOCOL *snp = snpnetdev->snp; EFI_SIMPLE_NETWORK_PROTOCOL *snp = snpnetdev->snp;
EFI_STATUS efirc; EFI_STATUS efirc;
int rc;
if ( snpnetdev->close_state != EfiSimpleNetworkInitialized ) { if ( snpnetdev->close_state != EfiSimpleNetworkInitialized ) {
efirc = snp->Shutdown ( snp ); if ( ( efirc = snp->Shutdown ( snp ) ) != 0 ) {
if ( efirc ) { rc = -EEFI ( efirc );
DBGC ( snp, "SNP %p could not shut down: %s\n", 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 */ /* Start the interface */
if ( snp->Mode->State == EfiSimpleNetworkStopped ) { if ( snp->Mode->State == EfiSimpleNetworkStopped ) {
efirc = snp->Start ( snp ); if ( ( efirc = snp->Start ( snp ) ) != 0 ) {
if ( efirc ) { rc = -EEFI ( efirc );
DBGC ( snp, "SNP %p could not start: %s\n", snp, DBGC ( snp, "SNP %p could not start: %s\n", snp,
efi_strerror ( efirc ) ); strerror ( rc ) );
rc = EFIRC_TO_RC ( efirc );
goto err_start; goto err_start;
} }
} }
@ -310,25 +315,27 @@ err_start:
*/ */
void snpnet_remove ( struct snp_device *snpdev ) { void snpnet_remove ( struct snp_device *snpdev ) {
EFI_SIMPLE_NETWORK_PROTOCOL *snp = snpdev->snp; EFI_SIMPLE_NETWORK_PROTOCOL *snp = snpdev->snp;
EFI_STATUS efirc;
struct net_device *netdev = snpdev->netdev; struct net_device *netdev = snpdev->netdev;
EFI_STATUS efirc;
int rc;
if ( snp->Mode->State == EfiSimpleNetworkInitialized && if ( snp->Mode->State == EfiSimpleNetworkInitialized &&
snpdev->removal_state != EfiSimpleNetworkInitialized ) { snpdev->removal_state != EfiSimpleNetworkInitialized ) {
DBGC ( snp, "SNP %p shutting down\n", snp ); DBGC ( snp, "SNP %p shutting down\n", snp );
efirc = snp->Shutdown ( snp ); if ( ( efirc = snp->Shutdown ( snp ) ) != 0 ) {
if ( efirc ) { rc = -EEFI ( efirc );
DBGC ( snp, "SNP %p could not shut down: %s\n", DBGC ( snp, "SNP %p could not shut down: %s\n",
snp, efi_strerror ( efirc ) ); snp, strerror ( rc ) );
} }
} }
if ( snp->Mode->State == EfiSimpleNetworkStarted && if ( snp->Mode->State == EfiSimpleNetworkStarted &&
snpdev->removal_state == EfiSimpleNetworkStopped ) { snpdev->removal_state == EfiSimpleNetworkStopped ) {
DBGC ( snp, "SNP %p stopping\n", snp ); DBGC ( snp, "SNP %p stopping\n", snp );
efirc = snp->Stop ( snp ); if ( ( efirc = snp->Stop ( snp ) ) != 0 ) {
if ( efirc ) { rc = -EEFI ( efirc );
DBGC ( snp, "SNP %p could not be stopped\n", snp ); DBGC ( snp, "SNP %p could not be stopped: %s\n",
snp, strerror ( rc ) );
} }
} }

View File

@ -176,9 +176,9 @@ static int efi_image_exec ( struct image *image ) {
user_to_virt ( image->data, 0 ), user_to_virt ( image->data, 0 ),
image->len, &handle ) ) != 0 ) { image->len, &handle ) ) != 0 ) {
/* Not an EFI image */ /* Not an EFI image */
rc = -EEFI ( efirc );
DBGC ( image, "EFIIMAGE %p could not load: %s\n", DBGC ( image, "EFIIMAGE %p could not load: %s\n",
image, efi_strerror ( efirc ) ); image, strerror ( rc ) );
rc = -ENOEXEC;
goto err_load_image; goto err_load_image;
} }
@ -188,7 +188,7 @@ static int efi_image_exec ( struct image *image ) {
NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL ); NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL );
if ( efirc ) { if ( efirc ) {
/* Should never happen */ /* Should never happen */
rc = EFIRC_TO_RC ( efirc ); rc = -EEFI ( efirc );
goto err_open_protocol; goto err_open_protocol;
} }
@ -205,9 +205,9 @@ static int efi_image_exec ( struct image *image ) {
/* Start the image */ /* Start the image */
if ( ( efirc = bs->StartImage ( handle, NULL, NULL ) ) != 0 ) { if ( ( efirc = bs->StartImage ( handle, NULL, NULL ) ) != 0 ) {
rc = -EEFI ( efirc );
DBGC ( image, "EFIIMAGE %p returned with status %s\n", DBGC ( image, "EFIIMAGE %p returned with status %s\n",
image, efi_strerror ( efirc ) ); image, strerror ( rc ) );
rc = EFIRC_TO_RC ( efirc );
goto err_start_image; goto err_start_image;
} }
@ -220,8 +220,9 @@ static int efi_image_exec ( struct image *image ) {
* have no "unload" operation. * have no "unload" operation.
*/ */
if ( ( efirc = bs->UnloadImage ( handle ) ) != 0 ) { if ( ( efirc = bs->UnloadImage ( handle ) ) != 0 ) {
rc = -EEFI ( efirc );
DBGC ( image, "EFIIMAGE %p could not unload: %s\n", DBGC ( image, "EFIIMAGE %p could not unload: %s\n",
image, efi_strerror ( efirc ) ); image, strerror ( rc ) );
} }
err_load_image: err_load_image:
free ( cmdline ); free ( cmdline );
@ -246,15 +247,17 @@ static int efi_image_probe ( struct image *image ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices; EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
EFI_HANDLE handle; EFI_HANDLE handle;
EFI_STATUS efirc; EFI_STATUS efirc;
int rc;
/* Attempt loading image */ /* Attempt loading image */
if ( ( efirc = bs->LoadImage ( FALSE, efi_image_handle, NULL, if ( ( efirc = bs->LoadImage ( FALSE, efi_image_handle, NULL,
user_to_virt ( image->data, 0 ), user_to_virt ( image->data, 0 ),
image->len, &handle ) ) != 0 ) { image->len, &handle ) ) != 0 ) {
/* Not an EFI image */ /* Not an EFI image */
rc = -EEFI ( efirc );
DBGC ( image, "EFIIMAGE %p could not load: %s\n", DBGC ( image, "EFIIMAGE %p could not load: %s\n",
image, efi_strerror ( efirc ) ); image, strerror ( rc ) );
return -ENOEXEC; return rc;
} }
/* Unload the image. We can't leave it loaded, because we /* Unload the image. We can't leave it loaded, because we

View File

@ -108,29 +108,27 @@ struct efi_config_table {
.required = (_required), \ .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 * @v rc iPXE status code
* will be detected as EFI error codes; both have the top bit set, and * @ret efirc EFI status code
* 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.
*/ */
#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_HANDLE efi_image_handle;
extern EFI_LOADED_IMAGE_PROTOCOL *efi_loaded_image; extern EFI_LOADED_IMAGE_PROTOCOL *efi_loaded_image;
extern EFI_DEVICE_PATH_PROTOCOL *efi_loaded_image_path; extern EFI_DEVICE_PATH_PROTOCOL *efi_loaded_image_path;
extern EFI_SYSTEM_TABLE *efi_systab; extern EFI_SYSTEM_TABLE *efi_systab;
extern const char * efi_strerror ( EFI_STATUS efirc );
extern const char * efi_guid_ntoa ( EFI_GUID *guid ); extern const char * efi_guid_ntoa ( EFI_GUID *guid );
extern void dbg_efi_protocols ( EFI_HANDLE handle ); extern void dbg_efi_protocols ( EFI_HANDLE handle );

View File

@ -44,6 +44,6 @@ struct efi_driver {
extern EFI_DEVICE_PATH_PROTOCOL * extern EFI_DEVICE_PATH_PROTOCOL *
efi_devpath_end ( EFI_DEVICE_PATH_PROTOCOL *path ); 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 */ #endif /* _IPXE_EFI_DRIVER_H */

View File

@ -38,10 +38,10 @@ struct efi_pci_device {
extern struct efi_pci_device * efipci_create ( struct efi_driver *efidrv, extern struct efi_pci_device * efipci_create ( struct efi_driver *efidrv,
EFI_HANDLE device ); 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_efi ( EFI_HANDLE device );
extern struct efi_pci_device * efipci_find ( struct device *dev ); extern struct efi_pci_device * efipci_find ( struct device *dev );
extern EFI_STATUS efipci_child_add ( struct efi_pci_device *efipci, extern int efipci_child_add ( struct efi_pci_device *efipci,
EFI_HANDLE device ); EFI_HANDLE device );
extern void efipci_child_del ( struct efi_pci_device *efipci, extern void efipci_child_del ( struct efi_pci_device *efipci,
EFI_HANDLE device ); EFI_HANDLE device );

View File

@ -266,6 +266,15 @@ FILE_LICENCE ( GPL2_OR_LATER );
#define ERRFILE_nslookup ( ERRFILE_OTHER | 0x00300000 ) #define ERRFILE_nslookup ( ERRFILE_OTHER | 0x00300000 )
#define ERRFILE_efi_snp_hii ( ERRFILE_OTHER | 0x00310000 ) #define ERRFILE_efi_snp_hii ( ERRFILE_OTHER | 0x00310000 )
#define ERRFILE_readline ( ERRFILE_OTHER | 0x00320000 ) #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 )
/** @} */ /** @} */

View File

@ -181,7 +181,7 @@ efi_bofm_supported ( EFI_DRIVER_BINDING_PROTOCOL *driver,
/* Create corresponding PCI device, if any */ /* Create corresponding PCI device, if any */
efipci = efipci_create ( efidrv, device ); efipci = efipci_create ( efidrv, device );
if ( ! efipci ) { if ( ! efipci ) {
efirc = EFI_UNSUPPORTED; rc = -ENOTSUP;
goto err_not_pci; goto err_not_pci;
} }
@ -189,16 +189,15 @@ efi_bofm_supported ( EFI_DRIVER_BINDING_PROTOCOL *driver,
if ( ( rc = bofm_find_driver ( &efipci->pci ) ) != 0 ) { if ( ( rc = bofm_find_driver ( &efipci->pci ) ) != 0 ) {
DBGCP ( efidrv, "EFIBOFM " PCI_FMT " has no driver\n", DBGCP ( efidrv, "EFIBOFM " PCI_FMT " has no driver\n",
PCI_ARGS ( &efipci->pci ) ); PCI_ARGS ( &efipci->pci ) );
efirc = EFI_UNSUPPORTED;
goto err_no_driver; goto err_no_driver;
} }
/* Locate BOFM protocol */ /* Locate BOFM protocol */
if ( ( efirc = bs->LocateProtocol ( &bofm1_protocol_guid, NULL, if ( ( efirc = bs->LocateProtocol ( &bofm1_protocol_guid, NULL,
&bofm1.interface ) ) != 0 ) { &bofm1.interface ) ) != 0 ) {
rc = -EEFI ( efirc );
DBGC ( efidrv, "EFIBOFM " PCI_FMT " cannot find BOFM " DBGC ( efidrv, "EFIBOFM " PCI_FMT " cannot find BOFM "
"protocol\n", PCI_ARGS ( &efipci->pci ) ); "protocol\n", PCI_ARGS ( &efipci->pci ) );
efirc = EFI_UNSUPPORTED;
goto err_not_bofm; goto err_not_bofm;
} }
@ -207,9 +206,10 @@ efi_bofm_supported ( EFI_DRIVER_BINDING_PROTOCOL *driver,
0x04 /* Can change MAC */, 0x04 /* Can change MAC */,
0x00 /* No iSCSI */, 0x00 /* No iSCSI */,
0x02 /* Version */ ))!=0){ 0x02 /* Version */ ))!=0){
rc = -EEFI ( efirc );
DBGC ( efidrv, "EFIBOFM " PCI_FMT " could not register " DBGC ( efidrv, "EFIBOFM " PCI_FMT " could not register "
"support: %s\n", PCI_ARGS ( &efipci->pci ), "support: %s\n", PCI_ARGS ( &efipci->pci ),
efi_strerror ( efirc ) ); strerror ( rc ) );
goto err_cannot_register; goto err_cannot_register;
} }
@ -226,7 +226,7 @@ efi_bofm_supported ( EFI_DRIVER_BINDING_PROTOCOL *driver,
err_no_driver: err_no_driver:
efipci_destroy ( efidrv, efipci ); efipci_destroy ( efidrv, efipci );
err_not_pci: 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; struct efi_pci_device *efipci;
IBM_BOFM_TABLE *bofmtab; IBM_BOFM_TABLE *bofmtab;
IBM_BOFM_TABLE *bofmtab2; IBM_BOFM_TABLE *bofmtab2;
EFI_STATUS efirc;
int bofmrc; int bofmrc;
EFI_STATUS efirc;
int rc;
DBGCP ( efidrv, "EFIBOFM DRIVER_START %p (%p)\n", device, child ); DBGCP ( efidrv, "EFIBOFM DRIVER_START %p (%p)\n", device, child );
/* Create corresponding PCI device */ /* Create corresponding PCI device */
efipci = efipci_create ( efidrv, device ); efipci = efipci_create ( efidrv, device );
if ( ! efipci ) { if ( ! efipci ) {
efirc = EFI_OUT_OF_RESOURCES; rc = -ENOMEM;
goto err_create; goto err_create;
} }
/* Enable PCI device */ /* Enable PCI device */
if ( ( efirc = efipci_enable ( efipci ) ) != 0 ) if ( ( rc = efipci_enable ( efipci ) ) != 0 )
goto err_enable; goto err_enable;
/* Locate BOFM protocol */ /* Locate BOFM protocol */
if ( ( efirc = bs->LocateProtocol ( &bofm1_protocol_guid, NULL, if ( ( efirc = bs->LocateProtocol ( &bofm1_protocol_guid, NULL,
&bofm1.interface ) ) != 0 ) { &bofm1.interface ) ) != 0 ) {
rc = -EEFI ( efirc );
DBGC ( efidrv, "EFIBOFM " PCI_FMT " cannot find BOFM " DBGC ( efidrv, "EFIBOFM " PCI_FMT " cannot find BOFM "
"protocol\n", PCI_ARGS ( &efipci->pci ) ); "protocol\n", PCI_ARGS ( &efipci->pci ) );
goto err_locate_bofm; goto err_locate_bofm;
@ -324,17 +326,19 @@ static EFI_STATUS EFIAPI efi_bofm_start ( EFI_DRIVER_BINDING_PROTOCOL *driver,
if ( bofmtab2 ) { if ( bofmtab2 ) {
if ( ( efirc = bofm2.bofm2->SetStatus ( bofm2.bofm2, device, if ( ( efirc = bofm2.bofm2->SetStatus ( bofm2.bofm2, device,
FALSE, bofmrc ) ) != 0){ FALSE, bofmrc ) ) != 0){
rc = -EEFI ( efirc );
DBGC ( efidrv, "EFIBOFM " PCI_FMT " could not set " DBGC ( efidrv, "EFIBOFM " PCI_FMT " could not set "
"BOFM2 status: %s\n", PCI_ARGS ( &efipci->pci ), "BOFM2 status: %s\n", PCI_ARGS ( &efipci->pci ),
efi_strerror ( efirc ) ); strerror ( rc ) );
goto err_set_status; goto err_set_status;
} }
} else { } else {
if ( ( efirc = bofm1.bofm1->SetStatus ( bofm1.bofm1, device, if ( ( efirc = bofm1.bofm1->SetStatus ( bofm1.bofm1, device,
FALSE, bofmrc ) ) != 0){ FALSE, bofmrc ) ) != 0){
rc = -EEFI ( efirc );
DBGC ( efidrv, "EFIBOFM " PCI_FMT " could not set " DBGC ( efidrv, "EFIBOFM " PCI_FMT " could not set "
"BOFM status: %s\n", PCI_ARGS ( &efipci->pci ), "BOFM status: %s\n", PCI_ARGS ( &efipci->pci ),
efi_strerror ( efirc ) ); strerror ( rc ) );
goto err_set_status; goto err_set_status;
} }
} }
@ -350,7 +354,7 @@ static EFI_STATUS EFIAPI efi_bofm_start ( EFI_DRIVER_BINDING_PROTOCOL *driver,
err_enable: err_enable:
efipci_destroy ( efidrv, efipci ); efipci_destroy ( efidrv, efipci );
err_create: 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 ) { static void efi_bofm_driver_init ( void ) {
struct efi_driver *efidrv = &efi_bofm_driver; struct efi_driver *efidrv = &efi_bofm_driver;
EFI_STATUS efirc; int rc;
/* Install driver */ /* 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", DBGC ( efidrv, "EFIBOFM could not install driver: %s\n",
efi_strerror ( efirc ) ); strerror ( rc ) );
return; return;
} }

View File

@ -20,6 +20,8 @@
FILE_LICENCE ( GPL2_OR_LATER ); FILE_LICENCE ( GPL2_OR_LATER );
#include <stddef.h> #include <stddef.h>
#include <string.h>
#include <errno.h>
#include <assert.h> #include <assert.h>
#include <ipxe/efi/efi.h> #include <ipxe/efi/efi.h>
#include <ipxe/ansiesc.h> #include <ipxe/ansiesc.h>
@ -227,6 +229,7 @@ static int efi_getchar ( void ) {
const char *ansi_seq; const char *ansi_seq;
EFI_INPUT_KEY key; EFI_INPUT_KEY key;
EFI_STATUS efirc; EFI_STATUS efirc;
int rc;
/* If we are mid-sequence, pass out the next byte */ /* If we are mid-sequence, pass out the next byte */
if ( *ansi_input ) if ( *ansi_input )
@ -234,8 +237,8 @@ static int efi_getchar ( void ) {
/* Read key from real EFI console */ /* Read key from real EFI console */
if ( ( efirc = conin->ReadKeyStroke ( conin, &key ) ) != 0 ) { if ( ( efirc = conin->ReadKeyStroke ( conin, &key ) ) != 0 ) {
DBG ( "EFI could not read keystroke: %s\n", rc = -EEFI ( efirc );
efi_strerror ( efirc ) ); DBG ( "EFI could not read keystroke: %s\n", strerror ( rc ) );
return 0; return 0;
} }
DBG2 ( "EFI read key stroke with unicode %04x scancode %04x\n", DBG2 ( "EFI read key stroke with unicode %04x scancode %04x\n",

View File

@ -28,6 +28,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <errno.h>
#include <ipxe/uuid.h> #include <ipxe/uuid.h>
#include <ipxe/efi/efi.h> #include <ipxe/efi/efi.h>
#include <ipxe/efi/efi_driver.h> #include <ipxe/efi/efi_driver.h>
@ -67,12 +68,14 @@ void dbg_efi_protocols ( EFI_HANDLE handle ) {
UINTN count; UINTN count;
unsigned int i; unsigned int i;
EFI_STATUS efirc; EFI_STATUS efirc;
int rc;
/* Retrieve list of protocols */ /* Retrieve list of protocols */
if ( ( efirc = bs->ProtocolsPerHandle ( handle, &protocols, if ( ( efirc = bs->ProtocolsPerHandle ( handle, &protocols,
&count ) ) != 0 ) { &count ) ) != 0 ) {
rc = -EEFI ( efirc );
printf ( "EFI could not retrieve protocols for %p: %s\n", printf ( "EFI could not retrieve protocols for %p: %s\n",
handle, efi_strerror ( efirc ) ); handle, strerror ( rc ) );
return; return;
} }

View File

@ -20,6 +20,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <errno.h>
#include <ipxe/open.h> #include <ipxe/open.h>
#include <ipxe/process.h> #include <ipxe/process.h>
#include <ipxe/iobuf.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 ) { 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 ); intf_shutdown ( &file->xfer, rc );
} }
@ -77,6 +78,7 @@ static int efi_download_deliver_iob ( struct efi_download_file *file,
struct xfer_metadata *meta ) { struct xfer_metadata *meta ) {
EFI_STATUS efirc; EFI_STATUS efirc;
size_t len = iob_len ( iobuf ); size_t len = iob_len ( iobuf );
int rc;
/* Calculate new buffer position */ /* Calculate new buffer position */
if ( meta->flags & XFER_FL_ABS_OFFSET ) 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; file->pos += meta->offset;
/* Call out to the data handler */ /* Call out to the data handler */
efirc = file->data_callback ( file->context, iobuf->data, if ( ( efirc = file->data_callback ( file->context, iobuf->data,
len, file->pos ); len, file->pos ) ) != 0 ) {
rc = -EEFI ( efirc );
goto err_callback;
}
/* Update current buffer position */ /* Update current buffer position */
file->pos += len; file->pos += len;
/* Success */
rc = 0;
err_callback:
free_iob ( iobuf ); free_iob ( iobuf );
return EFIRC_TO_RC ( efirc ); return rc;
} }
/** Data transfer interface operations */ /** 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 ); rc = xfer_open ( &file->xfer, LOCATION_URI_STRING, Url );
if ( rc ) { if ( rc ) {
free ( file ); free ( file );
return RC_TO_EFIRC ( rc ); return EFIRC ( rc );
} }
file->pos = 0; file->pos = 0;
@ -162,7 +171,7 @@ efi_download_abort ( IPXE_DOWNLOAD_PROTOCOL *This __unused,
EFI_STATUS Status ) { EFI_STATUS Status ) {
struct efi_download_file *file = File; struct efi_download_file *file = File;
efi_download_close ( file, EFIRC_TO_RC ( Status ) ); efi_download_close ( file, -EEFI ( Status ) );
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -195,6 +204,7 @@ static IPXE_DOWNLOAD_PROTOCOL ipxe_download_protocol_interface = {
int efi_download_install ( EFI_HANDLE *handle ) { int efi_download_install ( EFI_HANDLE *handle ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices; EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
EFI_STATUS efirc; EFI_STATUS efirc;
int rc;
efirc = bs->InstallMultipleProtocolInterfaces ( efirc = bs->InstallMultipleProtocolInterfaces (
handle, handle,
@ -202,9 +212,10 @@ int efi_download_install ( EFI_HANDLE *handle ) {
&ipxe_download_protocol_interface, &ipxe_download_protocol_interface,
NULL ); NULL );
if ( efirc ) { if ( efirc ) {
rc = -EEFI ( efirc );
DBG ( "Could not install download protocol: %s\n", DBG ( "Could not install download protocol: %s\n",
efi_strerror ( efirc ) ); strerror ( rc ) );
return EFIRC_TO_RC ( efirc ); return rc;
} }
return 0; return 0;

View File

@ -21,6 +21,8 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <errno.h>
#include <ipxe/efi/efi.h> #include <ipxe/efi/efi.h>
#include <ipxe/efi/Protocol/DriverBinding.h> #include <ipxe/efi/Protocol/DriverBinding.h>
#include <ipxe/efi/Protocol/ComponentName2.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 * @v efidrv EFI driver
* @ret efirc EFI status code * @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_BOOT_SERVICES *bs = efi_systab->BootServices;
EFI_DRIVER_BINDING_PROTOCOL *driver = &efidrv->driver; EFI_DRIVER_BINDING_PROTOCOL *driver = &efidrv->driver;
EFI_COMPONENT_NAME2_PROTOCOL *wtf = &efidrv->wtf; EFI_COMPONENT_NAME2_PROTOCOL *wtf = &efidrv->wtf;
EFI_STATUS efirc; EFI_STATUS efirc;
int rc;
/* Configure driver binding protocol */ /* Configure driver binding protocol */
driver->ImageHandle = efi_image_handle; 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_driver_binding_protocol_guid, driver,
&efi_component_name2_protocol_guid, wtf, &efi_component_name2_protocol_guid, wtf,
NULL ) ) != 0 ) { NULL ) ) != 0 ) {
rc = -EEFI ( efirc );
DBGC ( efidrv, "EFIDRV %s could not install protocol: %s\n", DBGC ( efidrv, "EFIDRV %s could not install protocol: %s\n",
efidrv->name, efi_strerror ( efirc ) ); efidrv->name, strerror ( rc ) );
return efirc; return rc;
} }
DBGC ( efidrv, "EFIDRV %s installed\n", efidrv->name ); DBGC ( efidrv, "EFIDRV %s installed\n", efidrv->name );

View File

@ -30,6 +30,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <errno.h>
#include <wchar.h> #include <wchar.h>
#include <ipxe/image.h> #include <ipxe/image.h>
#include <ipxe/efi/efi.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 ) { int efi_file_install ( EFI_HANDLE *handle ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices; EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
EFI_STATUS efirc; EFI_STATUS efirc;
int rc;
/* Install the simple file system protocol and the block I/O /* Install the simple file system protocol and the block I/O
* protocol. We don't have a block device, but large parts of * 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_block_io_protocol,
&efi_simple_file_system_protocol_guid, &efi_simple_file_system_protocol_guid,
&efi_simple_file_system_protocol, NULL ) ) != 0 ) { &efi_simple_file_system_protocol, NULL ) ) != 0 ) {
rc = -EEFI ( efirc );
DBGC ( handle, "Could not install simple file system protocol: " DBGC ( handle, "Could not install simple file system protocol: "
"%s\n", efi_strerror ( efirc ) ); "%s\n", strerror ( rc ) );
return EFIRC_TO_RC ( efirc ); return rc;
} }
return 0; return 0;

View File

@ -20,6 +20,7 @@
FILE_LICENCE ( GPL2_OR_LATER ); FILE_LICENCE ( GPL2_OR_LATER );
#include <string.h> #include <string.h>
#include <errno.h>
#include <ipxe/efi/efi.h> #include <ipxe/efi/efi.h>
#include <ipxe/efi/Protocol/LoadedImage.h> #include <ipxe/efi/Protocol/LoadedImage.h>
#include <ipxe/efi/Protocol/DevicePath.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;
void *loaded_image_path; void *loaded_image_path;
EFI_STATUS efirc; EFI_STATUS efirc;
int rc;
/* Store image handle and system table pointer for future use */ /* Store image handle and system table pointer for future use */
efi_image_handle = image_handle; efi_image_handle = image_handle;
@ -149,8 +151,9 @@ EFI_STATUS efi_init ( EFI_HANDLE image_handle,
&efi_loaded_image_protocol_guid, &efi_loaded_image_protocol_guid,
&loaded_image, image_handle, NULL, &loaded_image, image_handle, NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) { EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) {
rc = -EEFI ( efirc );
DBGC ( systab, "EFI could not get loaded image protocol: %s", DBGC ( systab, "EFI could not get loaded image protocol: %s",
efi_strerror ( efirc ) ); strerror ( rc ) );
return efirc; return efirc;
} }
efi_loaded_image = loaded_image; efi_loaded_image = loaded_image;
@ -162,8 +165,9 @@ EFI_STATUS efi_init ( EFI_HANDLE image_handle,
&efi_loaded_image_device_path_protocol_guid, &efi_loaded_image_device_path_protocol_guid,
&loaded_image_path, image_handle, NULL, &loaded_image_path, image_handle, NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) { EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) {
rc = -EEFI ( efirc );
DBGC ( systab, "EFI could not get loaded image device path " DBGC ( systab, "EFI could not get loaded image device path "
"protocol: %s", efi_strerror ( efirc ) ); "protocol: %s", strerror ( rc ) );
return efirc; return efirc;
} }
efi_loaded_image_path = loaded_image_path; 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, if ( ( efirc = bs->CreateEvent ( EVT_SIGNAL_EXIT_BOOT_SERVICES,
TPL_CALLBACK, efi_shutdown_hook, TPL_CALLBACK, efi_shutdown_hook,
NULL, &efi_shutdown_event ) ) != 0 ) { NULL, &efi_shutdown_event ) ) != 0 ) {
rc = -EEFI ( efirc );
DBGC ( systab, "EFI could not create ExitBootServices event: " DBGC ( systab, "EFI could not create ExitBootServices event: "
"%s\n", efi_strerror ( efirc ) ); "%s\n", strerror ( rc ) );
return efirc; return efirc;
} }

View File

@ -57,13 +57,15 @@ static unsigned long efipci_address ( struct pci_device *pci,
int efipci_read ( struct pci_device *pci, unsigned long location, int efipci_read ( struct pci_device *pci, unsigned long location,
void *value ) { void *value ) {
EFI_STATUS efirc; EFI_STATUS efirc;
int rc;
if ( ( efirc = efipci->Pci.Read ( efipci, EFIPCI_WIDTH ( location ), if ( ( efirc = efipci->Pci.Read ( efipci, EFIPCI_WIDTH ( location ),
efipci_address ( pci, location ), 1, efipci_address ( pci, location ), 1,
value ) ) != 0 ) { value ) ) != 0 ) {
rc = -EEFI ( efirc );
DBG ( "EFIPCI config read from " PCI_FMT " offset %02lx " DBG ( "EFIPCI config read from " PCI_FMT " offset %02lx "
"failed: %s\n", PCI_ARGS ( pci ), "failed: %s\n", PCI_ARGS ( pci ),
EFIPCI_OFFSET ( location ), efi_strerror ( efirc ) ); EFIPCI_OFFSET ( location ), strerror ( rc ) );
return -EIO; 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, int efipci_write ( struct pci_device *pci, unsigned long location,
unsigned long value ) { unsigned long value ) {
EFI_STATUS efirc; EFI_STATUS efirc;
int rc;
if ( ( efirc = efipci->Pci.Write ( efipci, EFIPCI_WIDTH ( location ), if ( ( efirc = efipci->Pci.Write ( efipci, EFIPCI_WIDTH ( location ),
efipci_address ( pci, location ), 1, efipci_address ( pci, location ), 1,
&value ) ) != 0 ) { &value ) ) != 0 ) {
rc = -EEFI ( efirc );
DBG ( "EFIPCI config write to " PCI_FMT " offset %02lx " DBG ( "EFIPCI config write to " PCI_FMT " offset %02lx "
"failed: %s\n", PCI_ARGS ( pci ), "failed: %s\n", PCI_ARGS ( pci ),
EFIPCI_OFFSET ( location ), efi_strerror ( efirc ) ); EFIPCI_OFFSET ( location ), strerror ( rc ) );
return -EIO; return -EIO;
} }
@ -149,6 +153,7 @@ struct efi_pci_device * efipci_create ( struct efi_driver *efidrv,
efidrv->driver.DriverBindingHandle, efidrv->driver.DriverBindingHandle,
device, device,
EFI_OPEN_PROTOCOL_BY_DRIVER )) !=0 ){ EFI_OPEN_PROTOCOL_BY_DRIVER )) !=0 ){
rc = -EEFI ( efirc );
DBGCP ( efipci, "EFIPCI device %p is not a PCI device\n", DBGCP ( efipci, "EFIPCI device %p is not a PCI device\n",
device ); device );
goto err_open_protocol; goto err_open_protocol;
@ -160,8 +165,9 @@ struct efi_pci_device * efipci_create ( struct efi_driver *efidrv,
&pci_segment, &pci_segment,
&pci_bus, &pci_dev, &pci_bus, &pci_dev,
&pci_fn ) ) != 0 ) { &pci_fn ) ) != 0 ) {
rc = -EEFI ( efirc );
DBGC ( efipci, "EFIPCI device %p could not get PCI " 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; goto err_get_location;
} }
DBGC2 ( efipci, "EFIPCI device %p is PCI %04lx:%02lx:%02lx.%lx\n", 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, efidrv->driver.DriverBindingHandle,
device, device,
EFI_OPEN_PROTOCOL_BY_DRIVER )) !=0 ){ EFI_OPEN_PROTOCOL_BY_DRIVER )) !=0 ){
rc = -EEFI ( efirc );
DBGC ( efipci, "EFIPCI " PCI_FMT " has no device path\n", DBGC ( efipci, "EFIPCI " PCI_FMT " has no device path\n",
PCI_ARGS ( &efipci->pci ) ); PCI_ARGS ( &efipci->pci ) );
goto err_no_device_path; goto err_no_device_path;
@ -213,9 +220,9 @@ struct efi_pci_device * efipci_create ( struct efi_driver *efidrv,
* Enable EFI PCI device * Enable EFI PCI device
* *
* @v efipci 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; EFI_PCI_IO_PROTOCOL *pci_io = efipci->pci_io;
/* Try to enable I/O cycles, memory cycles, and bus mastering. /* 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 * @v device EFI child device
* @ret efirc EFI status code * @ret efirc EFI status code
*/ */
EFI_STATUS efipci_child_add ( struct efi_pci_device *efipci, int efipci_child_add ( struct efi_pci_device *efipci, EFI_HANDLE device ) {
EFI_HANDLE device ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices; EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
struct efi_driver *efidrv = efipci->efidrv; struct efi_driver *efidrv = efipci->efidrv;
union { union {
@ -282,6 +288,7 @@ EFI_STATUS efipci_child_add ( struct efi_pci_device *efipci,
void *interface; void *interface;
} pci_io; } pci_io;
EFI_STATUS efirc; EFI_STATUS efirc;
int rc;
/* Re-open the PCI_IO_PROTOCOL */ /* Re-open the PCI_IO_PROTOCOL */
if ( ( efirc = bs->OpenProtocol ( efipci->device, if ( ( efirc = bs->OpenProtocol ( efipci->device,
@ -291,9 +298,10 @@ EFI_STATUS efipci_child_add ( struct efi_pci_device *efipci,
device, device,
EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) ) != 0 ) { ) ) != 0 ) {
rc = -EEFI ( efirc );
DBGC ( efipci, "EFIPCI " PCI_FMT " could not add child: %s\n", DBGC ( efipci, "EFIPCI " PCI_FMT " could not add child: %s\n",
PCI_ARGS ( &efipci->pci ), efi_strerror ( efirc ) ); PCI_ARGS ( &efipci->pci ), strerror ( rc ) );
return efirc; return rc;
} }
return 0; return 0;
@ -355,7 +363,6 @@ efipci_supported ( EFI_DRIVER_BINDING_PROTOCOL *driver, EFI_HANDLE device,
struct efi_driver *efidrv = struct efi_driver *efidrv =
container_of ( driver, struct efi_driver, driver ); container_of ( driver, struct efi_driver, driver );
struct efi_pci_device *efipci; struct efi_pci_device *efipci;
EFI_STATUS efirc;
int rc; int rc;
DBGCP ( efidrv, "EFIPCI DRIVER_SUPPORTED %p (%p)\n", device, child ); 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 ); efipci = efipci_create ( efidrv, device );
if ( ! efipci ) { if ( ! efipci ) {
/* Non-PCI devices are simply unsupported */ /* Non-PCI devices are simply unsupported */
efirc = EFI_UNSUPPORTED; rc = -ENOTSUP;
goto err_not_pci; 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 ) { if ( ( rc = pci_find_driver ( &efipci->pci ) ) != 0 ) {
DBGCP ( efipci, "EFIPCI " PCI_FMT " has no driver\n", DBGCP ( efipci, "EFIPCI " PCI_FMT " has no driver\n",
PCI_ARGS ( &efipci->pci ) ); PCI_ARGS ( &efipci->pci ) );
efirc = EFI_UNSUPPORTED;
goto err_no_driver; goto err_no_driver;
} }
@ -387,7 +393,7 @@ efipci_supported ( EFI_DRIVER_BINDING_PROTOCOL *driver, EFI_HANDLE device,
err_no_driver: err_no_driver:
efipci_destroy ( efidrv, efipci ); efipci_destroy ( efidrv, efipci );
err_not_pci: 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 = struct efi_driver *efidrv =
container_of ( driver, struct efi_driver, driver ); container_of ( driver, struct efi_driver, driver );
struct efi_pci_device *efipci; struct efi_pci_device *efipci;
EFI_STATUS efirc;
int rc; int rc;
DBGC ( efidrv, "EFIPCI DRIVER_START %p (%p)\n", device, child ); 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 */ /* Create corresponding PCI device */
efipci = efipci_create ( efidrv, device ); efipci = efipci_create ( efidrv, device );
if ( ! efipci ) { if ( ! efipci ) {
efirc = EFI_OUT_OF_RESOURCES; rc = -ENOMEM;
goto err_create; 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 ) { if ( ( rc = pci_find_driver ( &efipci->pci ) ) != 0 ) {
DBGC ( efipci, "EFIPCI " PCI_FMT " has no driver\n", DBGC ( efipci, "EFIPCI " PCI_FMT " has no driver\n",
PCI_ARGS ( &efipci->pci ) ); PCI_ARGS ( &efipci->pci ) );
efirc = RC_TO_EFIRC ( rc );
goto err_find_driver; goto err_find_driver;
} }
/* Enable PCI device */ /* Enable PCI device */
if ( ( efirc = efipci_enable ( efipci ) ) != 0 ) if ( ( rc = efipci_enable ( efipci ) ) != 0 )
goto err_enable; goto err_enable;
/* Probe driver */ /* 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 " DBGC ( efipci, "EFIPCI " PCI_FMT " could not probe driver "
"\"%s\": %s\n", PCI_ARGS ( &efipci->pci ), "\"%s\": %s\n", PCI_ARGS ( &efipci->pci ),
efipci->pci.id->name, strerror ( rc ) ); efipci->pci.id->name, strerror ( rc ) );
efirc = RC_TO_EFIRC ( rc );
goto err_probe; goto err_probe;
} }
@ -445,7 +448,7 @@ efipci_start ( EFI_DRIVER_BINDING_PROTOCOL *driver, EFI_HANDLE device,
err_find_driver: err_find_driver:
efipci_destroy ( efidrv, efipci ); efipci_destroy ( efidrv, efipci );
err_create: err_create:
return efirc; return EFIRC ( rc );
} }
/** /**
@ -494,12 +497,12 @@ static struct efi_driver efipci_driver =
*/ */
static void efipci_driver_startup ( void ) { static void efipci_driver_startup ( void ) {
struct efi_driver *efidrv = &efipci_driver; struct efi_driver *efidrv = &efipci_driver;
EFI_STATUS efirc; int rc;
/* Install driver */ /* 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", DBGC ( efidrv, "EFIPCI could not install driver: %s\n",
efi_strerror ( efirc ) ); strerror ( rc ) );
return; return;
} }

View File

@ -177,7 +177,7 @@ efi_snp_initialize ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
if ( ( rc = netdev_open ( snpdev->netdev ) ) != 0 ) { if ( ( rc = netdev_open ( snpdev->netdev ) ) != 0 ) {
DBGC ( snpdev, "SNPDEV %p could not open %s: %s\n", DBGC ( snpdev, "SNPDEV %p could not open %s: %s\n",
snpdev, snpdev->netdev->name, strerror ( rc ) ); snpdev, snpdev->netdev->name, strerror ( rc ) );
return RC_TO_EFIRC ( rc ); return EFIRC ( rc );
} }
snpdev->mode.State = EfiSimpleNetworkInitialized; 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 ) { if ( ( rc = netdev_open ( snpdev->netdev ) ) != 0 ) {
DBGC ( snpdev, "SNPDEV %p could not reopen %s: %s\n", DBGC ( snpdev, "SNPDEV %p could not reopen %s: %s\n",
snpdev, snpdev->netdev->name, strerror ( rc ) ); snpdev, snpdev->netdev->name, strerror ( rc ) );
return RC_TO_EFIRC ( rc ); return EFIRC ( rc );
} }
snpdev->mode.State = EfiSimpleNetworkInitialized; snpdev->mode.State = EfiSimpleNetworkInitialized;
@ -366,7 +366,7 @@ efi_snp_mcast_ip_to_mac ( EFI_SIMPLE_NETWORK_PROTOCOL *snp, BOOLEAN ipv6,
ip, mac ) ) != 0 ) { ip, mac ) ) != 0 ) {
DBGC ( snpdev, "SNPDEV %p could not hash %s: %s\n", DBGC ( snpdev, "SNPDEV %p could not hash %s: %s\n",
snpdev, ip_str, strerror ( rc ) ); snpdev, ip_str, strerror ( rc ) );
return RC_TO_EFIRC ( rc ); return EFIRC ( rc );
} }
return 0; return 0;
@ -490,7 +490,6 @@ efi_snp_transmit ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
struct io_buffer *iobuf; struct io_buffer *iobuf;
size_t payload_len; size_t payload_len;
int rc; int rc;
EFI_STATUS efirc;
DBGC2 ( snpdev, "SNPDEV %p TRANSMIT %p+%lx", snpdev, data, DBGC2 ( snpdev, "SNPDEV %p TRANSMIT %p+%lx", snpdev, data,
( ( unsigned long ) len ) ); ( ( unsigned long ) len ) );
@ -515,25 +514,25 @@ efi_snp_transmit ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
DBGC ( snpdev, "SNPDEV %p TX invalid header length " DBGC ( snpdev, "SNPDEV %p TX invalid header length "
"%ld\n", snpdev, "%ld\n", snpdev,
( ( unsigned long ) ll_header_len ) ); ( ( unsigned long ) ll_header_len ) );
efirc = EFI_INVALID_PARAMETER; rc = -EINVAL;
goto err_sanity; goto err_sanity;
} }
if ( len < ll_header_len ) { if ( len < ll_header_len ) {
DBGC ( snpdev, "SNPDEV %p invalid packet length %ld\n", DBGC ( snpdev, "SNPDEV %p invalid packet length %ld\n",
snpdev, ( ( unsigned long ) len ) ); snpdev, ( ( unsigned long ) len ) );
efirc = EFI_BUFFER_TOO_SMALL; rc = -EINVAL;
goto err_sanity; goto err_sanity;
} }
if ( ! ll_dest ) { if ( ! ll_dest ) {
DBGC ( snpdev, "SNPDEV %p TX missing destination " DBGC ( snpdev, "SNPDEV %p TX missing destination "
"address\n", snpdev ); "address\n", snpdev );
efirc = EFI_INVALID_PARAMETER; rc = -EINVAL;
goto err_sanity; goto err_sanity;
} }
if ( ! net_proto ) { if ( ! net_proto ) {
DBGC ( snpdev, "SNPDEV %p TX missing network " DBGC ( snpdev, "SNPDEV %p TX missing network "
"protocol\n", snpdev ); "protocol\n", snpdev );
efirc = EFI_INVALID_PARAMETER; rc = -EINVAL;
goto err_sanity; goto err_sanity;
} }
if ( ! ll_src ) if ( ! ll_src )
@ -547,7 +546,7 @@ efi_snp_transmit ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
if ( ! iobuf ) { if ( ! iobuf ) {
DBGC ( snpdev, "SNPDEV %p TX could not allocate %ld-byte " DBGC ( snpdev, "SNPDEV %p TX could not allocate %ld-byte "
"buffer\n", snpdev, ( ( unsigned long ) len ) ); "buffer\n", snpdev, ( ( unsigned long ) len ) );
efirc = EFI_DEVICE_ERROR; rc = -ENOMEM;
goto err_alloc_iob; goto err_alloc_iob;
} }
iob_reserve ( iobuf, ( MAX_LL_HEADER_LEN - iob_reserve ( iobuf, ( MAX_LL_HEADER_LEN -
@ -562,7 +561,6 @@ efi_snp_transmit ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
htons ( *net_proto ) )) != 0 ){ htons ( *net_proto ) )) != 0 ){
DBGC ( snpdev, "SNPDEV %p TX could not construct " DBGC ( snpdev, "SNPDEV %p TX could not construct "
"header: %s\n", snpdev, strerror ( rc ) ); "header: %s\n", snpdev, strerror ( rc ) );
efirc = RC_TO_EFIRC ( rc );
goto err_ll_push; 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){ if ( ( rc = netdev_tx ( snpdev->netdev, iob_disown ( iobuf ) ) ) != 0){
DBGC ( snpdev, "SNPDEV %p TX could not transmit: %s\n", DBGC ( snpdev, "SNPDEV %p TX could not transmit: %s\n",
snpdev, strerror ( rc ) ); snpdev, strerror ( rc ) );
efirc = RC_TO_EFIRC ( rc );
goto err_tx; goto err_tx;
} }
@ -586,7 +583,7 @@ efi_snp_transmit ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
free_iob ( iobuf ); free_iob ( iobuf );
err_alloc_iob: err_alloc_iob:
err_sanity: err_sanity:
return efirc; return EFIRC ( rc );
} }
/** /**
@ -615,7 +612,6 @@ efi_snp_receive ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
uint16_t iob_net_proto; uint16_t iob_net_proto;
unsigned int iob_flags; unsigned int iob_flags;
int rc; int rc;
EFI_STATUS efirc;
DBGC2 ( snpdev, "SNPDEV %p RECEIVE %p(+%lx)", snpdev, data, DBGC2 ( snpdev, "SNPDEV %p RECEIVE %p(+%lx)", snpdev, data,
( ( unsigned long ) *len ) ); ( ( unsigned long ) *len ) );
@ -627,7 +623,7 @@ efi_snp_receive ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
iobuf = netdev_rx_dequeue ( snpdev->netdev ); iobuf = netdev_rx_dequeue ( snpdev->netdev );
if ( ! iobuf ) { if ( ! iobuf ) {
DBGC2 ( snpdev, "\n" ); DBGC2 ( snpdev, "\n" );
efirc = EFI_NOT_READY; rc = -EAGAIN;
goto out_no_packet; goto out_no_packet;
} }
DBGC2 ( snpdev, "+%zx\n", iob_len ( iobuf ) ); DBGC2 ( snpdev, "+%zx\n", iob_len ( iobuf ) );
@ -642,7 +638,6 @@ efi_snp_receive ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
&iob_flags ) ) != 0 ) { &iob_flags ) ) != 0 ) {
DBGC ( snpdev, "SNPDEV %p could not parse header: %s\n", DBGC ( snpdev, "SNPDEV %p could not parse header: %s\n",
snpdev, strerror ( rc ) ); snpdev, strerror ( rc ) );
efirc = RC_TO_EFIRC ( rc );
goto out_bad_ll_header; goto out_bad_ll_header;
} }
@ -656,12 +651,12 @@ efi_snp_receive ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
if ( net_proto ) if ( net_proto )
*net_proto = ntohs ( iob_net_proto ); *net_proto = ntohs ( iob_net_proto );
efirc = 0; rc = 0;
out_bad_ll_header: out_bad_ll_header:
free_iob ( iobuf ); free_iob ( iobuf );
out_no_packet: 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, if ( ( efirc = bs->CreateEvent ( EVT_NOTIFY_WAIT, TPL_NOTIFY,
efi_snp_wait_for_packet, snpdev, efi_snp_wait_for_packet, snpdev,
&snpdev->snp.WaitForPacket ) ) != 0 ){ &snpdev->snp.WaitForPacket ) ) != 0 ){
rc = -EEFI ( efirc );
DBGC ( snpdev, "SNPDEV %p could not create event: %s\n", DBGC ( snpdev, "SNPDEV %p could not create event: %s\n",
snpdev, efi_strerror ( efirc ) ); snpdev, strerror ( rc ) );
rc = EFIRC_TO_RC ( efirc );
goto err_create_event; 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_component_name2_protocol_guid, &snpdev->name2,
&efi_load_file_protocol_guid, &snpdev->load_file, &efi_load_file_protocol_guid, &snpdev->load_file,
NULL ) ) != 0 ) { NULL ) ) != 0 ) {
rc = -EEFI ( efirc );
DBGC ( snpdev, "SNPDEV %p could not install protocols: " DBGC ( snpdev, "SNPDEV %p could not install protocols: "
"%s\n", snpdev, efi_strerror ( efirc ) ); "%s\n", snpdev, strerror ( rc ) );
rc = EFIRC_TO_RC ( efirc );
goto err_install_protocol_interface; goto err_install_protocol_interface;
} }
/* Add as child of PCI device */ /* 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 DBGC ( snpdev, "SNPDEV %p could not become child of " PCI_FMT
": %s\n", snpdev, PCI_ARGS ( &efipci->pci ), ": %s\n", snpdev, PCI_ARGS ( &efipci->pci ),
efi_strerror ( efirc ) ); strerror ( rc ) );
rc = EFIRC_TO_RC ( efirc );
goto err_efipci_child_add; goto err_efipci_child_add;
} }

View 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, if ( ( rc = efi_snp_hii_process ( snpdev, pos, progress,
results, &have_setting, results, &have_setting,
efi_snp_hii_fetch ) ) != 0 ) { 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, if ( ( rc = efi_snp_hii_fetch ( snpdev, setting->name,
NULL, results, NULL, results,
NULL ) ) != 0 ) { 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, if ( ( rc = efi_snp_hii_process ( snpdev, pos, progress,
NULL, NULL, NULL, NULL,
efi_snp_hii_store ) ) != 0 ) { 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, if ( ( efirc = efihii->NewPackageList ( efihii, snpdev->package_list,
snpdev->handle, snpdev->handle,
&snpdev->hii_handle ) ) != 0 ) { &snpdev->hii_handle ) ) != 0 ) {
rc = -EEFI ( efirc );
DBGC ( snpdev, "SNPDEV %p could not add HII packages: %s\n", DBGC ( snpdev, "SNPDEV %p could not add HII packages: %s\n",
snpdev, efi_strerror ( efirc ) ); snpdev, strerror ( rc ) );
rc = EFIRC_TO_RC ( efirc );
goto err_new_package_list; goto err_new_package_list;
} }
@ -668,9 +668,9 @@ int efi_snp_hii_install ( struct efi_snp_device *snpdev ) {
&snpdev->handle, &snpdev->handle,
&efi_hii_config_access_protocol_guid, &snpdev->hii, &efi_hii_config_access_protocol_guid, &snpdev->hii,
NULL ) ) != 0 ) { NULL ) ) != 0 ) {
rc = -EEFI ( efirc );
DBGC ( snpdev, "SNPDEV %p could not install HII protocol: %s\n", DBGC ( snpdev, "SNPDEV %p could not install HII protocol: %s\n",
snpdev, efi_strerror ( efirc ) ); snpdev, strerror ( rc ) );
rc = EFIRC_TO_RC ( efirc );
goto err_install_protocol; goto err_install_protocol;
} }

View File

@ -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;
}

View File

@ -19,6 +19,8 @@
FILE_LICENCE ( GPL2_OR_LATER ); FILE_LICENCE ( GPL2_OR_LATER );
#include <string.h>
#include <errno.h>
#include <limits.h> #include <limits.h>
#include <assert.h> #include <assert.h>
#include <unistd.h> #include <unistd.h>
@ -54,10 +56,12 @@ EFI_REQUIRE_PROTOCOL ( EFI_CPU_ARCH_PROTOCOL, &cpu_arch );
static void efi_udelay ( unsigned long usecs ) { static void efi_udelay ( unsigned long usecs ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices; EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
EFI_STATUS efirc; EFI_STATUS efirc;
int rc;
if ( ( efirc = bs->Stall ( usecs ) ) != 0 ) { if ( ( efirc = bs->Stall ( usecs ) ) != 0 ) {
rc = -EEFI ( efirc );
DBG ( "EFI could not delay for %ldus: %s\n", DBG ( "EFI could not delay for %ldus: %s\n",
usecs, efi_strerror ( efirc ) ); usecs, strerror ( rc ) );
/* Probably screwed */ /* Probably screwed */
} }
} }
@ -70,12 +74,13 @@ static void efi_udelay ( unsigned long usecs ) {
static unsigned long efi_currticks ( void ) { static unsigned long efi_currticks ( void ) {
UINT64 time; UINT64 time;
EFI_STATUS efirc; EFI_STATUS efirc;
int rc;
/* Read CPU timer 0 (TSC) */ /* Read CPU timer 0 (TSC) */
if ( ( efirc = cpu_arch->GetTimerValue ( cpu_arch, 0, &time, if ( ( efirc = cpu_arch->GetTimerValue ( cpu_arch, 0, &time,
NULL ) ) != 0 ) { NULL ) ) != 0 ) {
DBG ( "EFI could not read CPU timer: %s\n", rc = -EEFI ( efirc );
efi_strerror ( efirc ) ); DBG ( "EFI could not read CPU timer: %s\n", strerror ( rc ) );
/* Probably screwed */ /* Probably screwed */
return -1UL; return -1UL;
} }

View File

@ -19,6 +19,8 @@
FILE_LICENCE ( GPL2_OR_LATER ); FILE_LICENCE ( GPL2_OR_LATER );
#include <string.h>
#include <errno.h>
#include <assert.h> #include <assert.h>
#include <ipxe/umalloc.h> #include <ipxe/umalloc.h>
#include <ipxe/efi/efi.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; userptr_t new_ptr = UNOWHERE;
size_t old_size; size_t old_size;
EFI_STATUS efirc; EFI_STATUS efirc;
int rc;
/* Allocate new memory if necessary. If allocation fails, /* Allocate new memory if necessary. If allocation fails,
* return without touching the old block. * return without touching the old block.
@ -59,8 +62,9 @@ static userptr_t efi_urealloc ( userptr_t old_ptr, size_t new_size ) {
EfiBootServicesData, EfiBootServicesData,
new_pages, new_pages,
&phys_addr ) ) != 0 ) { &phys_addr ) ) != 0 ) {
rc = -EEFI ( efirc );
DBG ( "EFI could not allocate %d pages: %s\n", DBG ( "EFI could not allocate %d pages: %s\n",
new_pages, efi_strerror ( efirc ) ); new_pages, strerror ( rc ) );
return UNULL; return UNULL;
} }
assert ( phys_addr != 0 ); 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 ); old_pages = ( EFI_SIZE_TO_PAGES ( old_size ) + 1 );
phys_addr = user_to_phys ( old_ptr, -EFI_PAGE_SIZE ); phys_addr = user_to_phys ( old_ptr, -EFI_PAGE_SIZE );
if ( ( efirc = bs->FreePages ( phys_addr, old_pages ) ) != 0 ){ if ( ( efirc = bs->FreePages ( phys_addr, old_pages ) ) != 0 ){
rc = -EEFI ( efirc );
DBG ( "EFI could not free %d pages at %llx: %s\n", 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 /* Not fatal; we have leaked memory but successfully
* allocated (if asked to do so). * allocated (if asked to do so).
*/ */