mirror of https://github.com/ipxe/ipxe.git
[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
parent
7348035231
commit
54409583e2
|
@ -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 () );
|
||||
}
|
||||
|
|
|
@ -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 ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -38,10 +38,10 @@ 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,
|
||||
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 );
|
||||
|
|
|
@ -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 )
|
||||
|
||||
/** @} */
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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).
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue