Browse Source

[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>
tags/v1.20.1
Michael Brown 11 years ago
parent
commit
54409583e2

+ 2
- 1
src/arch/x86/prefix/efiprefix.c View File

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

+ 45
- 38
src/drivers/net/efi/snpnet.c View File

@@ -56,20 +56,21 @@ static int snpnet_transmit ( struct net_device *netdev,
56 56
 			     struct io_buffer *iobuf ) {
57 57
 	struct snpnet_device *snpnetdev = netdev->priv;
58 58
 	EFI_SIMPLE_NETWORK_PROTOCOL *snp = snpnetdev->snp;
59
-	EFI_STATUS efirc;
60 59
 	void *txbuf=NULL;
61 60
 	size_t len = iob_len ( iobuf );
61
+	EFI_STATUS efirc;
62
+	int rc;
62 63
 
63
-	efirc = snp->Transmit ( snp, 0, len, iobuf->data, NULL, NULL, NULL );
64
-	if (efirc) {
65
-		return EFIRC_TO_RC ( efirc );
64
+	if ( ( efirc = snp->Transmit ( snp, 0, len, iobuf->data, NULL, NULL,
65
+				       NULL ) ) != 0 ) {
66
+		return -EEFI ( efirc );
66 67
 	}
67 68
 	/* since GetStatus is so inconsistent, don't try more than one outstanding transmit at a time */
68 69
 	while ( txbuf == NULL ) {
69
-		efirc = snp->GetStatus ( snp, NULL, &txbuf );
70
-		if ( efirc ) {
70
+		if ( ( efirc = snp->GetStatus ( snp, NULL, &txbuf ) ) != 0 ) {
71
+			rc = -EEFI ( efirc );
71 72
 			DBGC ( snp, "SNP %p could not get status %s\n", snp,
72
-			       efi_strerror ( efirc ) );
73
+			       strerror ( rc ) );
73 74
 			break;
74 75
 		}
75 76
 
@@ -86,9 +87,10 @@ static int snpnet_transmit ( struct net_device *netdev,
86 87
 static void snpnet_poll ( struct net_device *netdev ) {
87 88
 	struct snpnet_device *snpnetdev = netdev->priv;
88 89
 	EFI_SIMPLE_NETWORK_PROTOCOL *snp = snpnetdev->snp;
89
-	EFI_STATUS efirc;
90 90
 	struct io_buffer *iobuf = NULL;
91 91
 	UINTN len;
92
+	EFI_STATUS efirc;
93
+	int rc;
92 94
 
93 95
 	/* Process received packets */
94 96
 	while ( 1 ) {
@@ -115,12 +117,13 @@ static void snpnet_poll ( struct net_device *netdev ) {
115 117
 		}
116 118
 
117 119
 		/* Other error? */
118
-		if ( efirc ) {
120
+		if ( efirc != 0 ) {
121
+			rc = -EEFI ( efirc );
119 122
 			DBGC ( snp, "SNP %p receive packet error: %s "
120 123
 				    "(len was %zd, is now %zd)\n",
121
-			       snp, efi_strerror ( efirc ), iob_len(iobuf),
124
+			       snp, strerror ( rc ), iob_len(iobuf),
122 125
 			       (size_t)len );
123
-			netdev_rx_err ( netdev, iobuf, efirc );
126
+			netdev_rx_err ( netdev, iobuf, rc );
124 127
 			break;
125 128
 		}
126 129
 
@@ -139,25 +142,27 @@ static void snpnet_poll ( struct net_device *netdev ) {
139 142
 static int snpnet_open ( struct net_device *netdev ) {
140 143
 	struct snpnet_device *snpnetdev = netdev->priv;
141 144
 	EFI_SIMPLE_NETWORK_PROTOCOL *snp = snpnetdev->snp;
142
-	EFI_STATUS efirc;
145
+	EFI_MAC_ADDRESS *mac;
143 146
 	UINT32 enableFlags, disableFlags;
147
+	EFI_STATUS efirc;
148
+	int rc;
144 149
 
145 150
 	snpnetdev->close_state = snp->Mode->State;
146 151
 	if ( snp->Mode->State != EfiSimpleNetworkInitialized ) {
147
-		efirc = snp->Initialize ( snp, 0, 0 );
148
-		if ( efirc ) {
152
+		if ( ( efirc = snp->Initialize ( snp, 0, 0 ) ) != 0 ) {
153
+			rc = -EEFI ( efirc );
149 154
 			DBGC ( snp, "SNP %p could not initialize: %s\n",
150
-			       snp, efi_strerror ( efirc ) );
151
-			return EFIRC_TO_RC ( efirc );
155
+			       snp, strerror ( rc ) );
156
+			return rc;
152 157
 		}
153 158
 	}
154 159
 
155 160
         /* Use the default MAC address */
156
-	efirc = snp->StationAddress ( snp, FALSE,
157
-				      (EFI_MAC_ADDRESS *)netdev->ll_addr );
158
-	if ( efirc ) {
161
+	mac = ( ( void * ) netdev->ll_addr );
162
+	if ( ( efirc = snp->StationAddress ( snp, FALSE, mac ) ) != 0 ) {
163
+		rc = -EEFI ( efirc );
159 164
 		DBGC ( snp, "SNP %p could not reset station address: %s\n",
160
-		       snp, efi_strerror ( efirc ) );
165
+		       snp, strerror ( rc ) );
161 166
 	}
162 167
 
163 168
 	/* Set up receive filters to receive unicast and broadcast packets
@@ -179,11 +184,11 @@ static int snpnet_open ( struct net_device *netdev ) {
179 184
 		enableFlags |= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS;
180 185
 	}
181 186
 	disableFlags &= ~enableFlags;
182
-	efirc = snp->ReceiveFilters ( snp, enableFlags, disableFlags,
183
-				      FALSE, 0, NULL );
184
-	if ( efirc ) {
187
+	if ( ( efirc = snp->ReceiveFilters ( snp, enableFlags, disableFlags,
188
+					     FALSE, 0, NULL ) ) != 0 ) {
189
+		rc = -EEFI ( efirc );
185 190
 		DBGC ( snp, "SNP %p could not set receive filters: %s\n",
186
-		       snp, efi_strerror ( efirc ) );
191
+		       snp, strerror ( rc ) );
187 192
 	}
188 193
 
189 194
 	DBGC ( snp, "SNP %p opened\n", snp );
@@ -199,12 +204,13 @@ static void snpnet_close ( struct net_device *netdev ) {
199 204
 	struct snpnet_device *snpnetdev = netdev->priv;
200 205
 	EFI_SIMPLE_NETWORK_PROTOCOL *snp = snpnetdev->snp;
201 206
 	EFI_STATUS efirc;
207
+	int rc;
202 208
 
203 209
 	if ( snpnetdev->close_state != EfiSimpleNetworkInitialized ) {
204
-		efirc = snp->Shutdown ( snp );
205
-		if ( efirc ) {
210
+		if ( ( efirc = snp->Shutdown ( snp ) ) != 0 ) {
211
+			rc = -EEFI ( efirc );
206 212
 			DBGC ( snp, "SNP %p could not shut down: %s\n",
207
-			       snp, efi_strerror ( efirc ) );
213
+			       snp, strerror ( rc ) );
208 214
 		}
209 215
 	}
210 216
 }
@@ -264,11 +270,10 @@ int snpnet_probe ( struct snp_device *snpdev ) {
264 270
 
265 271
 	/* Start the interface */
266 272
 	if ( snp->Mode->State == EfiSimpleNetworkStopped ) {
267
-		efirc = snp->Start ( snp );
268
-		if ( efirc ) {
273
+		if ( ( efirc = snp->Start ( snp ) ) != 0 ) {
274
+			rc = -EEFI ( efirc );
269 275
 			DBGC ( snp, "SNP %p could not start: %s\n", snp,
270
-			       efi_strerror ( efirc ) );
271
-			rc = EFIRC_TO_RC ( efirc );
276
+			       strerror ( rc ) );
272 277
 			goto err_start;
273 278
 		}
274 279
 	}
@@ -310,25 +315,27 @@ err_start:
310 315
  */
311 316
 void snpnet_remove ( struct snp_device *snpdev ) {
312 317
 	EFI_SIMPLE_NETWORK_PROTOCOL *snp = snpdev->snp;
313
-	EFI_STATUS efirc;
314 318
 	struct net_device *netdev = snpdev->netdev;
319
+	EFI_STATUS efirc;
320
+	int rc;
315 321
 
316 322
 	if ( snp->Mode->State == EfiSimpleNetworkInitialized &&
317 323
 	     snpdev->removal_state != EfiSimpleNetworkInitialized ) {
318 324
 		DBGC ( snp, "SNP %p shutting down\n", snp );
319
-		efirc = snp->Shutdown ( snp );
320
-		if ( efirc ) {
325
+		if ( ( efirc = snp->Shutdown ( snp ) ) != 0 ) {
326
+			rc = -EEFI ( efirc );
321 327
 			DBGC ( snp, "SNP %p could not shut down: %s\n",
322
-			       snp, efi_strerror ( efirc ) );
328
+			       snp, strerror ( rc ) );
323 329
 		}
324 330
 	}
325 331
 
326 332
 	if ( snp->Mode->State == EfiSimpleNetworkStarted &&
327 333
 	     snpdev->removal_state == EfiSimpleNetworkStopped ) {
328 334
 		DBGC ( snp, "SNP %p stopping\n", snp );
329
-		efirc = snp->Stop ( snp );
330
-		if ( efirc ) {
331
-			DBGC ( snp, "SNP %p could not be stopped\n", snp );
335
+		if ( ( efirc = snp->Stop ( snp ) ) != 0 ) {
336
+			rc = -EEFI ( efirc );
337
+			DBGC ( snp, "SNP %p could not be stopped: %s\n",
338
+			       snp, strerror ( rc ) );
332 339
 		}
333 340
 	}
334 341
 

+ 11
- 8
src/image/efi_image.c View File

@@ -176,9 +176,9 @@ static int efi_image_exec ( struct image *image ) {
176 176
 				       user_to_virt ( image->data, 0 ),
177 177
 				       image->len, &handle ) ) != 0 ) {
178 178
 		/* Not an EFI image */
179
+		rc = -EEFI ( efirc );
179 180
 		DBGC ( image, "EFIIMAGE %p could not load: %s\n",
180
-		       image, efi_strerror ( efirc ) );
181
-		rc = -ENOEXEC;
181
+		       image, strerror ( rc ) );
182 182
 		goto err_load_image;
183 183
 	}
184 184
 
@@ -188,7 +188,7 @@ static int efi_image_exec ( struct image *image ) {
188 188
 				   NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL );
189 189
 	if ( efirc ) {
190 190
 		/* Should never happen */
191
-		rc = EFIRC_TO_RC ( efirc );
191
+		rc = -EEFI ( efirc );
192 192
 		goto err_open_protocol;
193 193
 	}
194 194
 
@@ -205,9 +205,9 @@ static int efi_image_exec ( struct image *image ) {
205 205
 
206 206
 	/* Start the image */
207 207
 	if ( ( efirc = bs->StartImage ( handle, NULL, NULL ) ) != 0 ) {
208
+		rc = -EEFI ( efirc );
208 209
 		DBGC ( image, "EFIIMAGE %p returned with status %s\n",
209
-		       image, efi_strerror ( efirc ) );
210
-		rc = EFIRC_TO_RC ( efirc );
210
+		       image, strerror ( rc ) );
211 211
 		goto err_start_image;
212 212
 	}
213 213
 
@@ -220,8 +220,9 @@ static int efi_image_exec ( struct image *image ) {
220 220
 	 * have no "unload" operation.
221 221
 	 */
222 222
 	if ( ( efirc = bs->UnloadImage ( handle ) ) != 0 ) {
223
+		rc = -EEFI ( efirc );
223 224
 		DBGC ( image, "EFIIMAGE %p could not unload: %s\n",
224
-		       image, efi_strerror ( efirc ) );
225
+		       image, strerror ( rc ) );
225 226
 	}
226 227
  err_load_image:
227 228
 	free ( cmdline );
@@ -246,15 +247,17 @@ static int efi_image_probe ( struct image *image ) {
246 247
 	EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
247 248
 	EFI_HANDLE handle;
248 249
 	EFI_STATUS efirc;
250
+	int rc;
249 251
 
250 252
 	/* Attempt loading image */
251 253
 	if ( ( efirc = bs->LoadImage ( FALSE, efi_image_handle, NULL,
252 254
 				       user_to_virt ( image->data, 0 ),
253 255
 				       image->len, &handle ) ) != 0 ) {
254 256
 		/* Not an EFI image */
257
+		rc = -EEFI ( efirc );
255 258
 		DBGC ( image, "EFIIMAGE %p could not load: %s\n",
256
-		       image, efi_strerror ( efirc ) );
257
-		return -ENOEXEC;
259
+		       image, strerror ( rc ) );
260
+		return rc;
258 261
 	}
259 262
 
260 263
 	/* Unload the image.  We can't leave it loaded, because we

+ 10
- 12
src/include/ipxe/efi/efi.h View File

@@ -108,29 +108,27 @@ struct efi_config_table {
108 108
 		.required = (_required),				     \
109 109
 	}
110 110
 
111
-/** Convert a iPXE status code to an EFI status code
111
+/**
112
+ * Convert an iPXE status code to an EFI status code
112 113
  *
113
- * FIXME: actually perform some kind of conversion.  iPXE error codes
114
- * will be detected as EFI error codes; both have the top bit set, and
115
- * the success return code is zero for both.  Anything that just
116
- * reports a numerical error will be OK, anything attempting to
117
- * interpret the value or to display a text equivalent will be
118
- * screwed.
114
+ * @v rc		iPXE status code
115
+ * @ret efirc		EFI status code
119 116
  */
120
-#define RC_TO_EFIRC( rc ) (rc)
117
+#define EFIRC( rc ) ERRNO_TO_PLATFORM ( -(rc) )
121 118
 
122
-/** Convert an EFI status code to a iPXE status code
119
+/**
120
+ * Convert an EFI status code to an iPXE status code
123 121
  *
124
- * FIXME: as above
122
+ * @v efirc		EFI status code
123
+ * @ret rc		iPXE status code (before negation)
125 124
  */
126
-#define EFIRC_TO_RC( efirc ) (efirc)
125
+#define EEFI( efirc ) EPLATFORM ( EINFO_EPLATFORM, efirc )
127 126
 
128 127
 extern EFI_HANDLE efi_image_handle;
129 128
 extern EFI_LOADED_IMAGE_PROTOCOL *efi_loaded_image;
130 129
 extern EFI_DEVICE_PATH_PROTOCOL *efi_loaded_image_path;
131 130
 extern EFI_SYSTEM_TABLE *efi_systab;
132 131
 
133
-extern const char * efi_strerror ( EFI_STATUS efirc );
134 132
 extern const char * efi_guid_ntoa ( EFI_GUID *guid );
135 133
 
136 134
 extern void dbg_efi_protocols ( EFI_HANDLE handle );

+ 1
- 1
src/include/ipxe/efi/efi_driver.h View File

@@ -44,6 +44,6 @@ struct efi_driver {
44 44
 extern EFI_DEVICE_PATH_PROTOCOL *
45 45
 efi_devpath_end ( EFI_DEVICE_PATH_PROTOCOL *path );
46 46
 
47
-extern EFI_STATUS efi_driver_install ( struct efi_driver *efidrv );
47
+extern int efi_driver_install ( struct efi_driver *efidrv );
48 48
 
49 49
 #endif /* _IPXE_EFI_DRIVER_H */

+ 3
- 3
src/include/ipxe/efi/efi_pci.h View File

@@ -38,11 +38,11 @@ struct efi_pci_device {
38 38
 
39 39
 extern struct efi_pci_device * efipci_create ( struct efi_driver *efidrv,
40 40
 					       EFI_HANDLE device );
41
-extern EFI_STATUS efipci_enable ( struct efi_pci_device *efipci );
41
+extern int efipci_enable ( struct efi_pci_device *efipci );
42 42
 extern struct efi_pci_device * efipci_find_efi ( EFI_HANDLE device );
43 43
 extern struct efi_pci_device * efipci_find ( struct device *dev );
44
-extern EFI_STATUS efipci_child_add ( struct efi_pci_device *efipci,
45
-				     EFI_HANDLE device );
44
+extern int efipci_child_add ( struct efi_pci_device *efipci,
45
+			      EFI_HANDLE device );
46 46
 extern void efipci_child_del ( struct efi_pci_device *efipci,
47 47
 			       EFI_HANDLE device );
48 48
 extern void efipci_destroy ( struct efi_driver *efidrv,

+ 9
- 0
src/include/ipxe/errfile.h View File

@@ -266,6 +266,15 @@ FILE_LICENCE ( GPL2_OR_LATER );
266 266
 #define ERRFILE_nslookup	      ( ERRFILE_OTHER | 0x00300000 )
267 267
 #define ERRFILE_efi_snp_hii	      ( ERRFILE_OTHER | 0x00310000 )
268 268
 #define ERRFILE_readline	      ( ERRFILE_OTHER | 0x00320000 )
269
+#define ERRFILE_efi_bofm	      ( ERRFILE_OTHER | 0x00330000 )
270
+#define ERRFILE_efi_console	      ( ERRFILE_OTHER | 0x00340000 )
271
+#define ERRFILE_efi_debug	      ( ERRFILE_OTHER | 0x00350000 )
272
+#define ERRFILE_efi_download	      ( ERRFILE_OTHER | 0x00360000 )
273
+#define ERRFILE_efi_driver	      ( ERRFILE_OTHER | 0x00370000 )
274
+#define ERRFILE_efi_file	      ( ERRFILE_OTHER | 0x00380000 )
275
+#define ERRFILE_efi_init	      ( ERRFILE_OTHER | 0x00390000 )
276
+#define ERRFILE_efi_timer	      ( ERRFILE_OTHER | 0x003a0000 )
277
+#define ERRFILE_efi_umalloc	      ( ERRFILE_OTHER | 0x003b0000 )
269 278
 
270 279
 /** @} */
271 280
 

+ 18
- 14
src/interface/efi/efi_bofm.c View File

@@ -181,7 +181,7 @@ efi_bofm_supported ( EFI_DRIVER_BINDING_PROTOCOL *driver,
181 181
 	/* Create corresponding PCI device, if any */
182 182
 	efipci = efipci_create ( efidrv, device );
183 183
 	if ( ! efipci ) {
184
-		efirc = EFI_UNSUPPORTED;
184
+		rc = -ENOTSUP;
185 185
 		goto err_not_pci;
186 186
 	}
187 187
 
@@ -189,16 +189,15 @@ efi_bofm_supported ( EFI_DRIVER_BINDING_PROTOCOL *driver,
189 189
 	if ( ( rc = bofm_find_driver ( &efipci->pci ) ) != 0 ) {
190 190
 		DBGCP ( efidrv, "EFIBOFM " PCI_FMT " has no driver\n",
191 191
 			PCI_ARGS ( &efipci->pci ) );
192
-		efirc = EFI_UNSUPPORTED;
193 192
 		goto err_no_driver;
194 193
 	}
195 194
 
196 195
 	/* Locate BOFM protocol */
197 196
 	if ( ( efirc = bs->LocateProtocol ( &bofm1_protocol_guid, NULL,
198 197
 					    &bofm1.interface ) ) != 0 ) {
198
+		rc = -EEFI ( efirc );
199 199
 		DBGC ( efidrv, "EFIBOFM " PCI_FMT " cannot find BOFM "
200 200
 		       "protocol\n", PCI_ARGS ( &efipci->pci ) );
201
-		efirc = EFI_UNSUPPORTED;
202 201
 		goto err_not_bofm;
203 202
 	}
204 203
 
@@ -207,9 +206,10 @@ efi_bofm_supported ( EFI_DRIVER_BINDING_PROTOCOL *driver,
207 206
 						      0x04 /* Can change MAC */,
208 207
 						      0x00 /* No iSCSI */,
209 208
 						      0x02 /* Version */ ))!=0){
209
+		rc = -EEFI ( efirc );
210 210
 		DBGC ( efidrv, "EFIBOFM " PCI_FMT " could not register "
211 211
 		       "support: %s\n", PCI_ARGS ( &efipci->pci ),
212
-		       efi_strerror ( efirc ) );
212
+		       strerror ( rc ) );
213 213
 		goto err_cannot_register;
214 214
 	}
215 215
 
@@ -226,7 +226,7 @@ efi_bofm_supported ( EFI_DRIVER_BINDING_PROTOCOL *driver,
226 226
  err_no_driver:
227 227
 	efipci_destroy ( efidrv, efipci );
228 228
  err_not_pci:
229
-	return efirc;
229
+	return EFIRC ( rc );
230 230
 }
231 231
 
232 232
 /**
@@ -254,25 +254,27 @@ static EFI_STATUS EFIAPI efi_bofm_start ( EFI_DRIVER_BINDING_PROTOCOL *driver,
254 254
 	struct efi_pci_device *efipci;
255 255
 	IBM_BOFM_TABLE *bofmtab;
256 256
 	IBM_BOFM_TABLE *bofmtab2;
257
-	EFI_STATUS efirc;
258 257
 	int bofmrc;
258
+	EFI_STATUS efirc;
259
+	int rc;
259 260
 
260 261
 	DBGCP ( efidrv, "EFIBOFM DRIVER_START %p (%p)\n", device, child );
261 262
 
262 263
 	/* Create corresponding PCI device */
263 264
 	efipci = efipci_create ( efidrv, device );
264 265
 	if ( ! efipci ) {
265
-		efirc = EFI_OUT_OF_RESOURCES;
266
+		rc = -ENOMEM;
266 267
 		goto err_create;
267 268
 	}
268 269
 
269 270
 	/* Enable PCI device */
270
-	if ( ( efirc = efipci_enable ( efipci ) ) != 0 )
271
+	if ( ( rc = efipci_enable ( efipci ) ) != 0 )
271 272
 		goto err_enable;
272 273
 
273 274
 	/* Locate BOFM protocol */
274 275
 	if ( ( efirc = bs->LocateProtocol ( &bofm1_protocol_guid, NULL,
275 276
 					    &bofm1.interface ) ) != 0 ) {
277
+		rc = -EEFI ( efirc );
276 278
 		DBGC ( efidrv, "EFIBOFM " PCI_FMT " cannot find BOFM "
277 279
 		       "protocol\n", PCI_ARGS ( &efipci->pci ) );
278 280
 		goto err_locate_bofm;
@@ -324,17 +326,19 @@ static EFI_STATUS EFIAPI efi_bofm_start ( EFI_DRIVER_BINDING_PROTOCOL *driver,
324 326
 	if ( bofmtab2 ) {
325 327
 		if ( ( efirc = bofm2.bofm2->SetStatus ( bofm2.bofm2, device,
326 328
 							FALSE, bofmrc ) ) != 0){
329
+			rc = -EEFI ( efirc );
327 330
 			DBGC ( efidrv, "EFIBOFM " PCI_FMT " could not set "
328 331
 			       "BOFM2 status: %s\n", PCI_ARGS ( &efipci->pci ),
329
-			       efi_strerror ( efirc ) );
332
+			       strerror ( rc ) );
330 333
 			goto err_set_status;
331 334
 		}
332 335
 	} else {
333 336
 		if ( ( efirc = bofm1.bofm1->SetStatus ( bofm1.bofm1, device,
334 337
 							FALSE, bofmrc ) ) != 0){
338
+			rc = -EEFI ( efirc );
335 339
 			DBGC ( efidrv, "EFIBOFM " PCI_FMT " could not set "
336 340
 			       "BOFM status: %s\n", PCI_ARGS ( &efipci->pci ),
337
-			       efi_strerror ( efirc ) );
341
+			       strerror ( rc ) );
338 342
 			goto err_set_status;
339 343
 		}
340 344
 	}
@@ -350,7 +354,7 @@ static EFI_STATUS EFIAPI efi_bofm_start ( EFI_DRIVER_BINDING_PROTOCOL *driver,
350 354
  err_enable:
351 355
 	efipci_destroy ( efidrv, efipci );
352 356
  err_create:
353
-	return efirc;
357
+	return EFIRC ( rc );
354 358
 }
355 359
 
356 360
 /**
@@ -385,12 +389,12 @@ static struct efi_driver efi_bofm_driver =
385 389
  */
386 390
 static void efi_bofm_driver_init ( void ) {
387 391
 	struct efi_driver *efidrv = &efi_bofm_driver;
388
-	EFI_STATUS efirc;
392
+	int rc;
389 393
 
390 394
 	/* Install driver */
391
-	if ( ( efirc = efi_driver_install ( efidrv ) ) != 0 ) {
395
+	if ( ( rc = efi_driver_install ( efidrv ) ) != 0 ) {
392 396
 		DBGC ( efidrv, "EFIBOFM could not install driver: %s\n",
393
-		       efi_strerror ( efirc ) );
397
+		       strerror ( rc ) );
394 398
 		return;
395 399
 	}
396 400
 

+ 5
- 2
src/interface/efi/efi_console.c View File

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

+ 4
- 1
src/interface/efi/efi_debug.c View File

@@ -28,6 +28,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
28 28
 
29 29
 #include <stdio.h>
30 30
 #include <string.h>
31
+#include <errno.h>
31 32
 #include <ipxe/uuid.h>
32 33
 #include <ipxe/efi/efi.h>
33 34
 #include <ipxe/efi/efi_driver.h>
@@ -67,12 +68,14 @@ void dbg_efi_protocols ( EFI_HANDLE handle ) {
67 68
 	UINTN count;
68 69
 	unsigned int i;
69 70
 	EFI_STATUS efirc;
71
+	int rc;
70 72
 
71 73
 	/* Retrieve list of protocols */
72 74
 	if ( ( efirc = bs->ProtocolsPerHandle ( handle, &protocols,
73 75
 						&count ) ) != 0 ) {
76
+		rc = -EEFI ( efirc );
74 77
 		printf ( "EFI could not retrieve protocols for %p: %s\n",
75
-			 handle, efi_strerror ( efirc ) );
78
+			 handle, strerror ( rc ) );
76 79
 		return;
77 80
 	}
78 81
 

+ 19
- 8
src/interface/efi/efi_download.c View File

@@ -20,6 +20,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
20 20
 
21 21
 #include <stdlib.h>
22 22
 #include <string.h>
23
+#include <errno.h>
23 24
 #include <ipxe/open.h>
24 25
 #include <ipxe/process.h>
25 26
 #include <ipxe/iobuf.h>
@@ -59,7 +60,7 @@ struct efi_download_file {
59 60
  */
60 61
 static void efi_download_close ( struct efi_download_file *file, int rc ) {
61 62
 
62
-	file->finish_callback ( file->context, RC_TO_EFIRC ( rc ) );
63
+	file->finish_callback ( file->context, EFIRC ( rc ) );
63 64
 
64 65
 	intf_shutdown ( &file->xfer, rc );
65 66
 }
@@ -77,6 +78,7 @@ static int efi_download_deliver_iob ( struct efi_download_file *file,
77 78
 				      struct xfer_metadata *meta ) {
78 79
 	EFI_STATUS efirc;
79 80
 	size_t len = iob_len ( iobuf );
81
+	int rc;
80 82
 
81 83
 	/* Calculate new buffer position */
82 84
 	if ( meta->flags & XFER_FL_ABS_OFFSET )
@@ -84,14 +86,21 @@ static int efi_download_deliver_iob ( struct efi_download_file *file,
84 86
 	file->pos += meta->offset;
85 87
 
86 88
 	/* Call out to the data handler */
87
-	efirc = file->data_callback ( file->context, iobuf->data,
88
-				      len, file->pos );
89
+	if ( ( efirc = file->data_callback ( file->context, iobuf->data,
90
+					     len, file->pos ) ) != 0 ) {
91
+		rc = -EEFI ( efirc );
92
+		goto err_callback;
93
+	}
89 94
 
90 95
 	/* Update current buffer position */
91 96
 	file->pos += len;
92 97
 
98
+	/* Success */
99
+	rc = 0;
100
+
101
+ err_callback:
93 102
 	free_iob ( iobuf );
94
-	return EFIRC_TO_RC ( efirc );
103
+	return rc;
95 104
 }
96 105
 
97 106
 /** Data transfer interface operations */
@@ -135,7 +144,7 @@ efi_download_start ( IPXE_DOWNLOAD_PROTOCOL *This __unused,
135 144
 	rc = xfer_open ( &file->xfer, LOCATION_URI_STRING, Url );
136 145
 	if ( rc ) {
137 146
 		free ( file );
138
-		return RC_TO_EFIRC ( rc );
147
+		return EFIRC ( rc );
139 148
 	}
140 149
 
141 150
 	file->pos = 0;
@@ -162,7 +171,7 @@ efi_download_abort ( IPXE_DOWNLOAD_PROTOCOL *This __unused,
162 171
 		     EFI_STATUS Status ) {
163 172
 	struct efi_download_file *file = File;
164 173
 
165
-	efi_download_close ( file, EFIRC_TO_RC ( Status ) );
174
+	efi_download_close ( file, -EEFI ( Status ) );
166 175
 	return EFI_SUCCESS;
167 176
 }
168 177
 
@@ -195,6 +204,7 @@ static IPXE_DOWNLOAD_PROTOCOL ipxe_download_protocol_interface = {
195 204
 int efi_download_install ( EFI_HANDLE *handle ) {
196 205
 	EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
197 206
 	EFI_STATUS efirc;
207
+	int rc;
198 208
 
199 209
 	efirc = bs->InstallMultipleProtocolInterfaces (
200 210
 			handle,
@@ -202,9 +212,10 @@ int efi_download_install ( EFI_HANDLE *handle ) {
202 212
 			&ipxe_download_protocol_interface,
203 213
 			NULL );
204 214
 	if ( efirc ) {
215
+		rc = -EEFI ( efirc );
205 216
 		DBG ( "Could not install download protocol: %s\n",
206
-		      efi_strerror ( efirc ) );
207
-		return EFIRC_TO_RC ( efirc );
217
+		      strerror ( rc ) );
218
+		return rc;
208 219
 	}
209 220
 
210 221
 	return 0;

+ 7
- 3
src/interface/efi/efi_driver.c View File

@@ -21,6 +21,8 @@ FILE_LICENCE ( GPL2_OR_LATER );
21 21
 
22 22
 #include <stddef.h>
23 23
 #include <stdio.h>
24
+#include <string.h>
25
+#include <errno.h>
24 26
 #include <ipxe/efi/efi.h>
25 27
 #include <ipxe/efi/Protocol/DriverBinding.h>
26 28
 #include <ipxe/efi/Protocol/ComponentName2.h>
@@ -122,11 +124,12 @@ efi_driver_get_controller_name ( EFI_COMPONENT_NAME2_PROTOCOL *wtf __unused,
122 124
  * @v efidrv		EFI driver
123 125
  * @ret efirc		EFI status code
124 126
  */
125
-EFI_STATUS efi_driver_install ( struct efi_driver *efidrv ) {
127
+int efi_driver_install ( struct efi_driver *efidrv ) {
126 128
 	EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
127 129
 	EFI_DRIVER_BINDING_PROTOCOL *driver = &efidrv->driver;
128 130
 	EFI_COMPONENT_NAME2_PROTOCOL *wtf = &efidrv->wtf;
129 131
 	EFI_STATUS efirc;
132
+	int rc;
130 133
 
131 134
 	/* Configure driver binding protocol */
132 135
 	driver->ImageHandle = efi_image_handle;
@@ -148,9 +151,10 @@ EFI_STATUS efi_driver_install ( struct efi_driver *efidrv ) {
148 151
 			&efi_driver_binding_protocol_guid, driver,
149 152
 			&efi_component_name2_protocol_guid, wtf,
150 153
 			NULL ) ) != 0 ) {
154
+		rc = -EEFI ( efirc );
151 155
 		DBGC ( efidrv, "EFIDRV %s could not install protocol: %s\n",
152
-		       efidrv->name, efi_strerror ( efirc ) );
153
-		return efirc;
156
+		       efidrv->name, strerror ( rc ) );
157
+		return rc;
154 158
 	}
155 159
 
156 160
 	DBGC ( efidrv, "EFIDRV %s installed\n", efidrv->name );

+ 5
- 2
src/interface/efi/efi_file.c View File

@@ -30,6 +30,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
30 30
 #include <stdlib.h>
31 31
 #include <stdio.h>
32 32
 #include <string.h>
33
+#include <errno.h>
33 34
 #include <wchar.h>
34 35
 #include <ipxe/image.h>
35 36
 #include <ipxe/efi/efi.h>
@@ -549,6 +550,7 @@ static EFI_BLOCK_IO_PROTOCOL efi_block_io_protocol = {
549 550
 int efi_file_install ( EFI_HANDLE *handle ) {
550 551
 	EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
551 552
 	EFI_STATUS efirc;
553
+	int rc;
552 554
 
553 555
 	/* Install the simple file system protocol and the block I/O
554 556
 	 * protocol.  We don't have a block device, but large parts of
@@ -563,9 +565,10 @@ int efi_file_install ( EFI_HANDLE *handle ) {
563 565
 			&efi_block_io_protocol,
564 566
 			&efi_simple_file_system_protocol_guid,
565 567
 			&efi_simple_file_system_protocol, NULL ) ) != 0 ) {
568
+		rc = -EEFI ( efirc );
566 569
 		DBGC ( handle, "Could not install simple file system protocol: "
567
-		       "%s\n", efi_strerror ( efirc ) );
568
-		return EFIRC_TO_RC ( efirc );
570
+		       "%s\n", strerror ( rc ) );
571
+		return rc;
569 572
 	}
570 573
 
571 574
 	return 0;

+ 8
- 3
src/interface/efi/efi_init.c View File

@@ -20,6 +20,7 @@
20 20
 FILE_LICENCE ( GPL2_OR_LATER );
21 21
 
22 22
 #include <string.h>
23
+#include <errno.h>
23 24
 #include <ipxe/efi/efi.h>
24 25
 #include <ipxe/efi/Protocol/LoadedImage.h>
25 26
 #include <ipxe/efi/Protocol/DevicePath.h>
@@ -94,6 +95,7 @@ EFI_STATUS efi_init ( EFI_HANDLE image_handle,
94 95
 	void *loaded_image;
95 96
 	void *loaded_image_path;
96 97
 	EFI_STATUS efirc;
98
+	int rc;
97 99
 
98 100
 	/* Store image handle and system table pointer for future use */
99 101
 	efi_image_handle = image_handle;
@@ -149,8 +151,9 @@ EFI_STATUS efi_init ( EFI_HANDLE image_handle,
149 151
 				&efi_loaded_image_protocol_guid,
150 152
 				&loaded_image, image_handle, NULL,
151 153
 				EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) {
154
+		rc = -EEFI ( efirc );
152 155
 		DBGC ( systab, "EFI could not get loaded image protocol: %s",
153
-		       efi_strerror ( efirc ) );
156
+		       strerror ( rc ) );
154 157
 		return efirc;
155 158
 	}
156 159
 	efi_loaded_image = loaded_image;
@@ -162,8 +165,9 @@ EFI_STATUS efi_init ( EFI_HANDLE image_handle,
162 165
 				&efi_loaded_image_device_path_protocol_guid,
163 166
 				&loaded_image_path, image_handle, NULL,
164 167
 				EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) {
168
+		rc = -EEFI ( efirc );
165 169
 		DBGC ( systab, "EFI could not get loaded image device path "
166
-		       "protocol: %s", efi_strerror ( efirc ) );
170
+		       "protocol: %s", strerror ( rc ) );
167 171
 		return efirc;
168 172
 	}
169 173
 	efi_loaded_image_path = loaded_image_path;
@@ -179,8 +183,9 @@ EFI_STATUS efi_init ( EFI_HANDLE image_handle,
179 183
 	if ( ( efirc = bs->CreateEvent ( EVT_SIGNAL_EXIT_BOOT_SERVICES,
180 184
 					 TPL_CALLBACK, efi_shutdown_hook,
181 185
 					 NULL, &efi_shutdown_event ) ) != 0 ) {
186
+		rc = -EEFI ( efirc );
182 187
 		DBGC ( systab, "EFI could not create ExitBootServices event: "
183
-		       "%s\n", efi_strerror ( efirc ) );
188
+		       "%s\n", strerror ( rc ) );
184 189
 		return efirc;
185 190
 	}
186 191
 

+ 25
- 22
src/interface/efi/efi_pci.c View File

@@ -57,13 +57,15 @@ static unsigned long efipci_address ( struct pci_device *pci,
57 57
 int efipci_read ( struct pci_device *pci, unsigned long location,
58 58
 		  void *value ) {
59 59
 	EFI_STATUS efirc;
60
+	int rc;
60 61
 
61 62
 	if ( ( efirc = efipci->Pci.Read ( efipci, EFIPCI_WIDTH ( location ),
62 63
 					  efipci_address ( pci, location ), 1,
63 64
 					  value ) ) != 0 ) {
65
+		rc = -EEFI ( efirc );
64 66
 		DBG ( "EFIPCI config read from " PCI_FMT " offset %02lx "
65 67
 		      "failed: %s\n", PCI_ARGS ( pci ),
66
-		      EFIPCI_OFFSET ( location ), efi_strerror ( efirc ) );
68
+		      EFIPCI_OFFSET ( location ), strerror ( rc ) );
67 69
 		return -EIO;
68 70
 	}
69 71
 
@@ -73,13 +75,15 @@ int efipci_read ( struct pci_device *pci, unsigned long location,
73 75
 int efipci_write ( struct pci_device *pci, unsigned long location,
74 76
 		   unsigned long value ) {
75 77
 	EFI_STATUS efirc;
78
+	int rc;
76 79
 
77 80
 	if ( ( efirc = efipci->Pci.Write ( efipci, EFIPCI_WIDTH ( location ),
78 81
 					   efipci_address ( pci, location ), 1,
79 82
 					   &value ) ) != 0 ) {
83
+		rc = -EEFI ( efirc );
80 84
 		DBG ( "EFIPCI config write to " PCI_FMT " offset %02lx "
81 85
 		      "failed: %s\n", PCI_ARGS ( pci ),
82
-		      EFIPCI_OFFSET ( location ), efi_strerror ( efirc ) );
86
+		      EFIPCI_OFFSET ( location ), strerror ( rc ) );
83 87
 		return -EIO;
84 88
 	}
85 89
 
@@ -149,6 +153,7 @@ struct efi_pci_device * efipci_create ( struct efi_driver *efidrv,
149 153
 					  efidrv->driver.DriverBindingHandle,
150 154
 					  device,
151 155
 					  EFI_OPEN_PROTOCOL_BY_DRIVER )) !=0 ){
156
+		rc = -EEFI ( efirc );
152 157
 		DBGCP ( efipci, "EFIPCI device %p is not a PCI device\n",
153 158
 			device );
154 159
 		goto err_open_protocol;
@@ -160,8 +165,9 @@ struct efi_pci_device * efipci_create ( struct efi_driver *efidrv,
160 165
 						    &pci_segment,
161 166
 						    &pci_bus, &pci_dev,
162 167
 						    &pci_fn ) ) != 0 ) {
168
+		rc = -EEFI ( efirc );
163 169
 		DBGC ( efipci, "EFIPCI device %p could not get PCI "
164
-		       "location: %s\n", device, efi_strerror ( efirc ) );
170
+		       "location: %s\n", device, strerror ( rc ) );
165 171
 		goto err_get_location;
166 172
 	}
167 173
 	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,
185 191
 					  efidrv->driver.DriverBindingHandle,
186 192
 					  device,
187 193
 					  EFI_OPEN_PROTOCOL_BY_DRIVER )) !=0 ){
194
+		rc = -EEFI ( efirc );
188 195
 		DBGC ( efipci, "EFIPCI " PCI_FMT " has no device path\n",
189 196
 		       PCI_ARGS ( &efipci->pci ) );
190 197
 		goto err_no_device_path;
@@ -213,9 +220,9 @@ struct efi_pci_device * efipci_create ( struct efi_driver *efidrv,
213 220
  * Enable EFI PCI device
214 221
  *
215 222
  * @v efipci		EFI PCI device
216
- * @ret efirc		EFI status code
223
+ * @ret rc		Return status code
217 224
  */
218
-EFI_STATUS efipci_enable ( struct efi_pci_device *efipci ) {
225
+int efipci_enable ( struct efi_pci_device *efipci ) {
219 226
 	EFI_PCI_IO_PROTOCOL *pci_io = efipci->pci_io;
220 227
 
221 228
 	/* Try to enable I/O cycles, memory cycles, and bus mastering.
@@ -273,8 +280,7 @@ struct efi_pci_device * efipci_find ( struct device *dev ) {
273 280
  * @v device		EFI child device
274 281
  * @ret efirc		EFI status code
275 282
  */
276
-EFI_STATUS efipci_child_add ( struct efi_pci_device *efipci,
277
-			      EFI_HANDLE device ) {
283
+int efipci_child_add ( struct efi_pci_device *efipci, EFI_HANDLE device ) {
278 284
 	EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
279 285
 	struct efi_driver *efidrv = efipci->efidrv;
280 286
 	union {
@@ -282,6 +288,7 @@ EFI_STATUS efipci_child_add ( struct efi_pci_device *efipci,
282 288
 		void *interface;
283 289
 	} pci_io;
284 290
 	EFI_STATUS efirc;
291
+	int rc;
285 292
 
286 293
 	/* Re-open the PCI_IO_PROTOCOL */
287 294
 	if ( ( efirc = bs->OpenProtocol ( efipci->device,
@@ -291,9 +298,10 @@ EFI_STATUS efipci_child_add ( struct efi_pci_device *efipci,
291 298
 					  device,
292 299
 					  EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
293 300
 					  ) ) != 0 ) {
301
+		rc = -EEFI ( efirc );
294 302
 		DBGC ( efipci, "EFIPCI " PCI_FMT " could not add child: %s\n",
295
-		       PCI_ARGS ( &efipci->pci ), efi_strerror ( efirc ) );
296
-		return efirc;
303
+		       PCI_ARGS ( &efipci->pci ), strerror ( rc ) );
304
+		return rc;
297 305
 	}
298 306
 
299 307
 	return 0;
@@ -355,7 +363,6 @@ efipci_supported ( EFI_DRIVER_BINDING_PROTOCOL *driver, EFI_HANDLE device,
355 363
 	struct efi_driver *efidrv =
356 364
 		container_of ( driver, struct efi_driver, driver );
357 365
 	struct efi_pci_device *efipci;
358
-	EFI_STATUS efirc;
359 366
 	int rc;
360 367
 
361 368
 	DBGCP ( efidrv, "EFIPCI DRIVER_SUPPORTED %p (%p)\n", device, child );
@@ -364,7 +371,7 @@ efipci_supported ( EFI_DRIVER_BINDING_PROTOCOL *driver, EFI_HANDLE device,
364 371
 	efipci = efipci_create ( efidrv, device );
365 372
 	if ( ! efipci ) {
366 373
 		/* Non-PCI devices are simply unsupported */
367
-		efirc = EFI_UNSUPPORTED;
374
+		rc = -ENOTSUP;
368 375
 		goto err_not_pci;
369 376
 	}
370 377
 
@@ -372,7 +379,6 @@ efipci_supported ( EFI_DRIVER_BINDING_PROTOCOL *driver, EFI_HANDLE device,
372 379
 	if ( ( rc = pci_find_driver ( &efipci->pci ) ) != 0 ) {
373 380
 		DBGCP ( efipci, "EFIPCI " PCI_FMT " has no driver\n",
374 381
 			PCI_ARGS ( &efipci->pci ) );
375
-		efirc = EFI_UNSUPPORTED;
376 382
 		goto err_no_driver;
377 383
 	}
378 384
 
@@ -387,7 +393,7 @@ efipci_supported ( EFI_DRIVER_BINDING_PROTOCOL *driver, EFI_HANDLE device,
387 393
  err_no_driver:
388 394
 	efipci_destroy ( efidrv, efipci );
389 395
  err_not_pci:
390
-	return efirc;
396
+	return EFIRC ( rc );
391 397
 }
392 398
 
393 399
 /**
@@ -404,7 +410,6 @@ efipci_start ( EFI_DRIVER_BINDING_PROTOCOL *driver, EFI_HANDLE device,
404 410
 	struct efi_driver *efidrv =
405 411
 		container_of ( driver, struct efi_driver, driver );
406 412
 	struct efi_pci_device *efipci;
407
-	EFI_STATUS efirc;
408 413
 	int rc;
409 414
 
410 415
 	DBGC ( efidrv, "EFIPCI DRIVER_START %p (%p)\n", device, child );
@@ -412,7 +417,7 @@ efipci_start ( EFI_DRIVER_BINDING_PROTOCOL *driver, EFI_HANDLE device,
412 417
 	/* Create corresponding PCI device */
413 418
 	efipci = efipci_create ( efidrv, device );
414 419
 	if ( ! efipci ) {
415
-		efirc = EFI_OUT_OF_RESOURCES;
420
+		rc = -ENOMEM;
416 421
 		goto err_create;
417 422
 	}
418 423
 
@@ -420,12 +425,11 @@ efipci_start ( EFI_DRIVER_BINDING_PROTOCOL *driver, EFI_HANDLE device,
420 425
 	if ( ( rc = pci_find_driver ( &efipci->pci ) ) != 0 ) {
421 426
 		DBGC ( efipci, "EFIPCI " PCI_FMT " has no driver\n",
422 427
 		       PCI_ARGS ( &efipci->pci ) );
423
-		efirc = RC_TO_EFIRC ( rc );
424 428
 		goto err_find_driver;
425 429
 	}
426 430
 
427 431
 	/* Enable PCI device */
428
-	if ( ( efirc = efipci_enable ( efipci ) ) != 0 )
432
+	if ( ( rc = efipci_enable ( efipci ) ) != 0 )
429 433
 		goto err_enable;
430 434
 
431 435
 	/* Probe driver */
@@ -433,7 +437,6 @@ efipci_start ( EFI_DRIVER_BINDING_PROTOCOL *driver, EFI_HANDLE device,
433 437
 		DBGC ( efipci, "EFIPCI " PCI_FMT " could not probe driver "
434 438
 		       "\"%s\": %s\n", PCI_ARGS ( &efipci->pci ),
435 439
 		       efipci->pci.id->name, strerror ( rc ) );
436
-		efirc = RC_TO_EFIRC ( rc );
437 440
 		goto err_probe;
438 441
 	}
439 442
 
@@ -445,7 +448,7 @@ efipci_start ( EFI_DRIVER_BINDING_PROTOCOL *driver, EFI_HANDLE device,
445 448
  err_find_driver:
446 449
 	efipci_destroy ( efidrv, efipci );
447 450
  err_create:
448
-	return efirc;
451
+	return EFIRC ( rc );
449 452
 }
450 453
 
451 454
 /**
@@ -494,12 +497,12 @@ static struct efi_driver efipci_driver =
494 497
  */
495 498
 static void efipci_driver_startup ( void ) {
496 499
 	struct efi_driver *efidrv = &efipci_driver;
497
-	EFI_STATUS efirc;
500
+	int rc;
498 501
 
499 502
 	/* Install driver */
500
-	if ( ( efirc = efi_driver_install ( efidrv ) ) != 0 ) {
503
+	if ( ( rc = efi_driver_install ( efidrv ) ) != 0 ) {
501 504
 		DBGC ( efidrv, "EFIPCI could not install driver: %s\n",
502
-		       efi_strerror ( efirc ) );
505
+		       strerror ( rc ) );
503 506
 		return;
504 507
 	}
505 508
 

+ 18
- 24
src/interface/efi/efi_snp.c View File

@@ -177,7 +177,7 @@ efi_snp_initialize ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
177 177
 	if ( ( rc = netdev_open ( snpdev->netdev ) ) != 0 ) {
178 178
 		DBGC ( snpdev, "SNPDEV %p could not open %s: %s\n",
179 179
 		       snpdev, snpdev->netdev->name, strerror ( rc ) );
180
-		return RC_TO_EFIRC ( rc );
180
+		return EFIRC ( rc );
181 181
 	}
182 182
 
183 183
 	snpdev->mode.State = EfiSimpleNetworkInitialized;
@@ -206,7 +206,7 @@ efi_snp_reset ( EFI_SIMPLE_NETWORK_PROTOCOL *snp, BOOLEAN ext_verify ) {
206 206
 	if ( ( rc = netdev_open ( snpdev->netdev ) ) != 0 ) {
207 207
 		DBGC ( snpdev, "SNPDEV %p could not reopen %s: %s\n",
208 208
 		       snpdev, snpdev->netdev->name, strerror ( rc ) );
209
-		return RC_TO_EFIRC ( rc );
209
+		return EFIRC ( rc );
210 210
 	}
211 211
 
212 212
 	snpdev->mode.State = EfiSimpleNetworkInitialized;
@@ -366,7 +366,7 @@ efi_snp_mcast_ip_to_mac ( EFI_SIMPLE_NETWORK_PROTOCOL *snp, BOOLEAN ipv6,
366 366
 					   ip, mac ) ) != 0 ) {
367 367
 		DBGC ( snpdev, "SNPDEV %p could not hash %s: %s\n",
368 368
 		       snpdev, ip_str, strerror ( rc ) );
369
-		return RC_TO_EFIRC ( rc );
369
+		return EFIRC ( rc );
370 370
 	}
371 371
 
372 372
 	return 0;
@@ -490,7 +490,6 @@ efi_snp_transmit ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
490 490
 	struct io_buffer *iobuf;
491 491
 	size_t payload_len;
492 492
 	int rc;
493
-	EFI_STATUS efirc;
494 493
 
495 494
 	DBGC2 ( snpdev, "SNPDEV %p TRANSMIT %p+%lx", snpdev, data,
496 495
 		( ( unsigned long ) len ) );
@@ -515,25 +514,25 @@ efi_snp_transmit ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
515 514
 			DBGC ( snpdev, "SNPDEV %p TX invalid header length "
516 515
 			       "%ld\n", snpdev,
517 516
 			       ( ( unsigned long ) ll_header_len ) );
518
-			efirc = EFI_INVALID_PARAMETER;
517
+			rc = -EINVAL;
519 518
 			goto err_sanity;
520 519
 		}
521 520
 		if ( len < ll_header_len ) {
522 521
 			DBGC ( snpdev, "SNPDEV %p invalid packet length %ld\n",
523 522
 			       snpdev, ( ( unsigned long ) len ) );
524
-			efirc = EFI_BUFFER_TOO_SMALL;
523
+			rc = -EINVAL;
525 524
 			goto err_sanity;
526 525
 		}
527 526
 		if ( ! ll_dest ) {
528 527
 			DBGC ( snpdev, "SNPDEV %p TX missing destination "
529 528
 			       "address\n", snpdev );
530
-			efirc = EFI_INVALID_PARAMETER;
529
+			rc = -EINVAL;
531 530
 			goto err_sanity;
532 531
 		}
533 532
 		if ( ! net_proto ) {
534 533
 			DBGC ( snpdev, "SNPDEV %p TX missing network "
535 534
 			       "protocol\n", snpdev );
536
-			efirc = EFI_INVALID_PARAMETER;
535
+			rc = -EINVAL;
537 536
 			goto err_sanity;
538 537
 		}
539 538
 		if ( ! ll_src )
@@ -547,7 +546,7 @@ efi_snp_transmit ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
547 546
 	if ( ! iobuf ) {
548 547
 		DBGC ( snpdev, "SNPDEV %p TX could not allocate %ld-byte "
549 548
 		       "buffer\n", snpdev, ( ( unsigned long ) len ) );
550
-		efirc = EFI_DEVICE_ERROR;
549
+		rc = -ENOMEM;
551 550
 		goto err_alloc_iob;
552 551
 	}
553 552
 	iob_reserve ( iobuf, ( MAX_LL_HEADER_LEN -
@@ -562,7 +561,6 @@ efi_snp_transmit ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
562 561
 						htons ( *net_proto ) )) != 0 ){
563 562
 			DBGC ( snpdev, "SNPDEV %p TX could not construct "
564 563
 			       "header: %s\n", snpdev, strerror ( rc ) );
565
-			efirc = RC_TO_EFIRC ( rc );
566 564
 			goto err_ll_push;
567 565
 		}
568 566
 	}
@@ -571,7 +569,6 @@ efi_snp_transmit ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
571 569
 	if ( ( rc = netdev_tx ( snpdev->netdev, iob_disown ( iobuf ) ) ) != 0){
572 570
 		DBGC ( snpdev, "SNPDEV %p TX could not transmit: %s\n",
573 571
 		       snpdev, strerror ( rc ) );
574
-		efirc = RC_TO_EFIRC ( rc );
575 572
 		goto err_tx;
576 573
 	}
577 574
 
@@ -586,7 +583,7 @@ efi_snp_transmit ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
586 583
 	free_iob ( iobuf );
587 584
  err_alloc_iob:
588 585
  err_sanity:
589
-	return efirc;
586
+	return EFIRC ( rc );
590 587
 }
591 588
 
592 589
 /**
@@ -615,7 +612,6 @@ efi_snp_receive ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
615 612
 	uint16_t iob_net_proto;
616 613
 	unsigned int iob_flags;
617 614
 	int rc;
618
-	EFI_STATUS efirc;
619 615
 
620 616
 	DBGC2 ( snpdev, "SNPDEV %p RECEIVE %p(+%lx)", snpdev, data,
621 617
 		( ( unsigned long ) *len ) );
@@ -627,7 +623,7 @@ efi_snp_receive ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
627 623
 	iobuf = netdev_rx_dequeue ( snpdev->netdev );
628 624
 	if ( ! iobuf ) {
629 625
 		DBGC2 ( snpdev, "\n" );
630
-		efirc = EFI_NOT_READY;
626
+		rc = -EAGAIN;
631 627
 		goto out_no_packet;
632 628
 	}
633 629
 	DBGC2 ( snpdev, "+%zx\n", iob_len ( iobuf ) );
@@ -642,7 +638,6 @@ efi_snp_receive ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
642 638
 					&iob_flags ) ) != 0 ) {
643 639
 		DBGC ( snpdev, "SNPDEV %p could not parse header: %s\n",
644 640
 		       snpdev, strerror ( rc ) );
645
-		efirc = RC_TO_EFIRC ( rc );
646 641
 		goto out_bad_ll_header;
647 642
 	}
648 643
 
@@ -656,12 +651,12 @@ efi_snp_receive ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
656 651
 	if ( net_proto )
657 652
 		*net_proto = ntohs ( iob_net_proto );
658 653
 
659
-	efirc = 0;
654
+	rc = 0;
660 655
 
661 656
  out_bad_ll_header:
662 657
 	free_iob ( iobuf );
663 658
 out_no_packet:
664
-	return efirc;
659
+	return EFIRC ( rc );
665 660
 }
666 661
 
667 662
 /**
@@ -879,9 +874,9 @@ static int efi_snp_probe ( struct net_device *netdev ) {
879 874
 	if ( ( efirc = bs->CreateEvent ( EVT_NOTIFY_WAIT, TPL_NOTIFY,
880 875
 					 efi_snp_wait_for_packet, snpdev,
881 876
 					 &snpdev->snp.WaitForPacket ) ) != 0 ){
877
+		rc = -EEFI ( efirc );
882 878
 		DBGC ( snpdev, "SNPDEV %p could not create event: %s\n",
883
-		       snpdev, efi_strerror ( efirc ) );
884
-		rc = EFIRC_TO_RC ( efirc );
879
+		       snpdev, strerror ( rc ) );
885 880
 		goto err_create_event;
886 881
 	}
887 882
 
@@ -944,18 +939,17 @@ static int efi_snp_probe ( struct net_device *netdev ) {
944 939
 			&efi_component_name2_protocol_guid, &snpdev->name2,
945 940
 			&efi_load_file_protocol_guid, &snpdev->load_file,
946 941
 			NULL ) ) != 0 ) {
942
+		rc = -EEFI ( efirc );
947 943
 		DBGC ( snpdev, "SNPDEV %p could not install protocols: "
948
-		       "%s\n", snpdev, efi_strerror ( efirc ) );
949
-		rc = EFIRC_TO_RC ( efirc );
944
+		       "%s\n", snpdev, strerror ( rc ) );
950 945
 		goto err_install_protocol_interface;
951 946
 	}
952 947
 
953 948
 	/* Add as child of PCI device */
954
-	if ( ( efirc = efipci_child_add ( efipci, snpdev->handle ) ) != 0 ) {
949
+	if ( ( rc = efipci_child_add ( efipci, snpdev->handle ) ) != 0 ) {
955 950
 		DBGC ( snpdev, "SNPDEV %p could not become child of " PCI_FMT
956 951
 		       ": %s\n", snpdev, PCI_ARGS ( &efipci->pci ),
957
-		       efi_strerror ( efirc ) );
958
-		rc = EFIRC_TO_RC ( efirc );
952
+		       strerror ( rc ) );
959 953
 		goto err_efipci_child_add;
960 954
 	}
961 955
 

+ 7
- 7
src/interface/efi/efi_snp_hii.c View File

@@ -544,7 +544,7 @@ efi_snp_hii_extract_config ( const EFI_HII_CONFIG_ACCESS_PROTOCOL *hii,
544 544
 		if ( ( rc = efi_snp_hii_process ( snpdev, pos, progress,
545 545
 						  results, &have_setting,
546 546
 						  efi_snp_hii_fetch ) ) != 0 ) {
547
-			return RC_TO_EFIRC ( rc );
547
+			return EFIRC ( rc );
548 548
 		}
549 549
 	}
550 550
 
@@ -558,7 +558,7 @@ efi_snp_hii_extract_config ( const EFI_HII_CONFIG_ACCESS_PROTOCOL *hii,
558 558
 			if ( ( rc = efi_snp_hii_fetch ( snpdev, setting->name,
559 559
 							NULL, results,
560 560
 							NULL ) ) != 0 ) {
561
-				return RC_TO_EFIRC ( rc );
561
+				return EFIRC ( rc );
562 562
 			}
563 563
 		}
564 564
 	}
@@ -592,7 +592,7 @@ efi_snp_hii_route_config ( const EFI_HII_CONFIG_ACCESS_PROTOCOL *hii,
592 592
 		if ( ( rc = efi_snp_hii_process ( snpdev, pos, progress,
593 593
 						  NULL, NULL,
594 594
 						  efi_snp_hii_store ) ) != 0 ) {
595
-			return RC_TO_EFIRC ( rc );
595
+			return EFIRC ( rc );
596 596
 		}
597 597
 	}
598 598
 
@@ -657,9 +657,9 @@ int efi_snp_hii_install ( struct efi_snp_device *snpdev ) {
657 657
 	if ( ( efirc = efihii->NewPackageList ( efihii, snpdev->package_list,
658 658
 						snpdev->handle,
659 659
 						&snpdev->hii_handle ) ) != 0 ) {
660
+		rc = -EEFI ( efirc );
660 661
 		DBGC ( snpdev, "SNPDEV %p could not add HII packages: %s\n",
661
-		       snpdev, efi_strerror ( efirc ) );
662
-		rc = EFIRC_TO_RC ( efirc );
662
+		       snpdev, strerror ( rc ) );
663 663
 		goto err_new_package_list;
664 664
 	}
665 665
 
@@ -668,9 +668,9 @@ int efi_snp_hii_install ( struct efi_snp_device *snpdev ) {
668 668
 			 &snpdev->handle,
669 669
 			 &efi_hii_config_access_protocol_guid, &snpdev->hii,
670 670
 			 NULL ) ) != 0 ) {
671
+		rc = -EEFI ( efirc );
671 672
 		DBGC ( snpdev, "SNPDEV %p could not install HII protocol: %s\n",
672
-		       snpdev, efi_strerror ( efirc ) );
673
-		rc = EFIRC_TO_RC ( efirc );
673
+		       snpdev, strerror ( rc ) );
674 674
 		goto err_install_protocol;
675 675
 	}
676 676
 

+ 0
- 46
src/interface/efi/efi_strerror.c View File

@@ -1,46 +0,0 @@
1
-/*
2
- * Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>.
3
- *
4
- * This program is free software; you can redistribute it and/or
5
- * modify it under the terms of the GNU General Public License as
6
- * published by the Free Software Foundation; either version 2 of the
7
- * License, or any later version.
8
- *
9
- * This program is distributed in the hope that it will be useful, but
10
- * WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
- * General Public License for more details.
13
- *
14
- * You should have received a copy of the GNU General Public License
15
- * along with this program; if not, write to the Free Software
16
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17
- * 02110-1301, USA.
18
- */
19
-
20
-FILE_LICENCE ( GPL2_OR_LATER );
21
-
22
-#include <stdio.h>
23
-#include <ipxe/efi/efi.h>
24
-
25
-/** @file
26
- *
27
- * iPXE error message formatting for EFI
28
- *
29
- */
30
-
31
-/**
32
- * Format EFI status code
33
- *
34
- * @v efirc		EFI status code
35
- * @v efi_strerror	EFI status code string
36
- */
37
-const char * efi_strerror ( EFI_STATUS efirc ) {
38
-	static char errbuf[32];
39
-
40
-	if ( ! efirc )
41
-		return "No error";
42
-
43
-	snprintf ( errbuf, sizeof ( errbuf ), "Error %lld",
44
-		   ( unsigned long long ) ( efirc ^ MAX_BIT ) );
45
-	return errbuf;
46
-}

+ 8
- 3
src/interface/efi/efi_timer.c View File

@@ -19,6 +19,8 @@
19 19
 
20 20
 FILE_LICENCE ( GPL2_OR_LATER );
21 21
 
22
+#include <string.h>
23
+#include <errno.h>
22 24
 #include <limits.h>
23 25
 #include <assert.h>
24 26
 #include <unistd.h>
@@ -54,10 +56,12 @@ EFI_REQUIRE_PROTOCOL ( EFI_CPU_ARCH_PROTOCOL, &cpu_arch );
54 56
 static void efi_udelay ( unsigned long usecs ) {
55 57
 	EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
56 58
 	EFI_STATUS efirc;
59
+	int rc;
57 60
 
58 61
 	if ( ( efirc = bs->Stall ( usecs ) ) != 0 ) {
62
+		rc = -EEFI ( efirc );
59 63
 		DBG ( "EFI could not delay for %ldus: %s\n",
60
-		      usecs, efi_strerror ( efirc ) );
64
+		      usecs, strerror ( rc ) );
61 65
 		/* Probably screwed */
62 66
 	}
63 67
 }
@@ -70,12 +74,13 @@ static void efi_udelay ( unsigned long usecs ) {
70 74
 static unsigned long efi_currticks ( void ) {
71 75
 	UINT64 time;
72 76
 	EFI_STATUS efirc;
77
+	int rc;
73 78
 
74 79
 	/* Read CPU timer 0 (TSC) */
75 80
 	if ( ( efirc = cpu_arch->GetTimerValue ( cpu_arch, 0, &time,
76 81
 						 NULL ) ) != 0 ) {
77
-		DBG ( "EFI could not read CPU timer: %s\n",
78
-		      efi_strerror ( efirc ) );
82
+		rc = -EEFI ( efirc );
83
+		DBG ( "EFI could not read CPU timer: %s\n", strerror ( rc ) );
79 84
 		/* Probably screwed */
80 85
 		return -1UL;
81 86
 	}

+ 7
- 2
src/interface/efi/efi_umalloc.c View File

@@ -19,6 +19,8 @@
19 19
 
20 20
 FILE_LICENCE ( GPL2_OR_LATER );
21 21
 
22
+#include <string.h>
23
+#include <errno.h>
22 24
 #include <assert.h>
23 25
 #include <ipxe/umalloc.h>
24 26
 #include <ipxe/efi/efi.h>
@@ -49,6 +51,7 @@ static userptr_t efi_urealloc ( userptr_t old_ptr, size_t new_size ) {
49 51
 	userptr_t new_ptr = UNOWHERE;
50 52
 	size_t old_size;
51 53
 	EFI_STATUS efirc;
54
+	int rc;
52 55
 
53 56
 	/* Allocate new memory if necessary.  If allocation fails,
54 57
 	 * return without touching the old block.
@@ -59,8 +62,9 @@ static userptr_t efi_urealloc ( userptr_t old_ptr, size_t new_size ) {
59 62
 						   EfiBootServicesData,
60 63
 						   new_pages,
61 64
 						   &phys_addr ) ) != 0 ) {
65
+			rc = -EEFI ( efirc );
62 66
 			DBG ( "EFI could not allocate %d pages: %s\n",
63
-			      new_pages, efi_strerror ( efirc ) );
67
+			      new_pages, strerror ( rc ) );
64 68
 			return UNULL;
65 69
 		}
66 70
 		assert ( phys_addr != 0 );
@@ -84,8 +88,9 @@ static userptr_t efi_urealloc ( userptr_t old_ptr, size_t new_size ) {
84 88
 		old_pages = ( EFI_SIZE_TO_PAGES ( old_size ) + 1 );
85 89
 		phys_addr = user_to_phys ( old_ptr, -EFI_PAGE_SIZE );
86 90
 		if ( ( efirc = bs->FreePages ( phys_addr, old_pages ) ) != 0 ){
91
+			rc = -EEFI ( efirc );
87 92
 			DBG ( "EFI could not free %d pages at %llx: %s\n",
88
-			      old_pages, phys_addr, efi_strerror ( efirc ) );
93
+			      old_pages, phys_addr, strerror ( rc ) );
89 94
 			/* Not fatal; we have leaked memory but successfully
90 95
 			 * allocated (if asked to do so).
91 96
 			 */

Loading…
Cancel
Save