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
 FILE_LICENCE ( GPL2_OR_LATER );
20
 FILE_LICENCE ( GPL2_OR_LATER );
21
 
21
 
22
 #include <stdlib.h>
22
 #include <stdlib.h>
23
+#include <errno.h>
23
 #include <ipxe/efi/efi.h>
24
 #include <ipxe/efi/efi.h>
24
 
25
 
25
 /**
26
 /**
38
 		return efirc;
39
 		return efirc;
39
 
40
 
40
 	/* Call to main() */
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
 			     struct io_buffer *iobuf ) {
56
 			     struct io_buffer *iobuf ) {
57
 	struct snpnet_device *snpnetdev = netdev->priv;
57
 	struct snpnet_device *snpnetdev = netdev->priv;
58
 	EFI_SIMPLE_NETWORK_PROTOCOL *snp = snpnetdev->snp;
58
 	EFI_SIMPLE_NETWORK_PROTOCOL *snp = snpnetdev->snp;
59
-	EFI_STATUS efirc;
60
 	void *txbuf=NULL;
59
 	void *txbuf=NULL;
61
 	size_t len = iob_len ( iobuf );
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
 	/* since GetStatus is so inconsistent, don't try more than one outstanding transmit at a time */
68
 	/* since GetStatus is so inconsistent, don't try more than one outstanding transmit at a time */
68
 	while ( txbuf == NULL ) {
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
 			DBGC ( snp, "SNP %p could not get status %s\n", snp,
72
 			DBGC ( snp, "SNP %p could not get status %s\n", snp,
72
-			       efi_strerror ( efirc ) );
73
+			       strerror ( rc ) );
73
 			break;
74
 			break;
74
 		}
75
 		}
75
 
76
 
86
 static void snpnet_poll ( struct net_device *netdev ) {
87
 static void snpnet_poll ( struct net_device *netdev ) {
87
 	struct snpnet_device *snpnetdev = netdev->priv;
88
 	struct snpnet_device *snpnetdev = netdev->priv;
88
 	EFI_SIMPLE_NETWORK_PROTOCOL *snp = snpnetdev->snp;
89
 	EFI_SIMPLE_NETWORK_PROTOCOL *snp = snpnetdev->snp;
89
-	EFI_STATUS efirc;
90
 	struct io_buffer *iobuf = NULL;
90
 	struct io_buffer *iobuf = NULL;
91
 	UINTN len;
91
 	UINTN len;
92
+	EFI_STATUS efirc;
93
+	int rc;
92
 
94
 
93
 	/* Process received packets */
95
 	/* Process received packets */
94
 	while ( 1 ) {
96
 	while ( 1 ) {
115
 		}
117
 		}
116
 
118
 
117
 		/* Other error? */
119
 		/* Other error? */
118
-		if ( efirc ) {
120
+		if ( efirc != 0 ) {
121
+			rc = -EEFI ( efirc );
119
 			DBGC ( snp, "SNP %p receive packet error: %s "
122
 			DBGC ( snp, "SNP %p receive packet error: %s "
120
 				    "(len was %zd, is now %zd)\n",
123
 				    "(len was %zd, is now %zd)\n",
121
-			       snp, efi_strerror ( efirc ), iob_len(iobuf),
124
+			       snp, strerror ( rc ), iob_len(iobuf),
122
 			       (size_t)len );
125
 			       (size_t)len );
123
-			netdev_rx_err ( netdev, iobuf, efirc );
126
+			netdev_rx_err ( netdev, iobuf, rc );
124
 			break;
127
 			break;
125
 		}
128
 		}
126
 
129
 
139
 static int snpnet_open ( struct net_device *netdev ) {
142
 static int snpnet_open ( struct net_device *netdev ) {
140
 	struct snpnet_device *snpnetdev = netdev->priv;
143
 	struct snpnet_device *snpnetdev = netdev->priv;
141
 	EFI_SIMPLE_NETWORK_PROTOCOL *snp = snpnetdev->snp;
144
 	EFI_SIMPLE_NETWORK_PROTOCOL *snp = snpnetdev->snp;
142
-	EFI_STATUS efirc;
145
+	EFI_MAC_ADDRESS *mac;
143
 	UINT32 enableFlags, disableFlags;
146
 	UINT32 enableFlags, disableFlags;
147
+	EFI_STATUS efirc;
148
+	int rc;
144
 
149
 
145
 	snpnetdev->close_state = snp->Mode->State;
150
 	snpnetdev->close_state = snp->Mode->State;
146
 	if ( snp->Mode->State != EfiSimpleNetworkInitialized ) {
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
 			DBGC ( snp, "SNP %p could not initialize: %s\n",
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
         /* Use the default MAC address */
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
 		DBGC ( snp, "SNP %p could not reset station address: %s\n",
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
 	/* Set up receive filters to receive unicast and broadcast packets
168
 	/* Set up receive filters to receive unicast and broadcast packets
179
 		enableFlags |= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS;
184
 		enableFlags |= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS;
180
 	}
185
 	}
181
 	disableFlags &= ~enableFlags;
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
 		DBGC ( snp, "SNP %p could not set receive filters: %s\n",
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
 	DBGC ( snp, "SNP %p opened\n", snp );
194
 	DBGC ( snp, "SNP %p opened\n", snp );
199
 	struct snpnet_device *snpnetdev = netdev->priv;
204
 	struct snpnet_device *snpnetdev = netdev->priv;
200
 	EFI_SIMPLE_NETWORK_PROTOCOL *snp = snpnetdev->snp;
205
 	EFI_SIMPLE_NETWORK_PROTOCOL *snp = snpnetdev->snp;
201
 	EFI_STATUS efirc;
206
 	EFI_STATUS efirc;
207
+	int rc;
202
 
208
 
203
 	if ( snpnetdev->close_state != EfiSimpleNetworkInitialized ) {
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
 			DBGC ( snp, "SNP %p could not shut down: %s\n",
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
 
270
 
265
 	/* Start the interface */
271
 	/* Start the interface */
266
 	if ( snp->Mode->State == EfiSimpleNetworkStopped ) {
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
 			DBGC ( snp, "SNP %p could not start: %s\n", snp,
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
 			goto err_start;
277
 			goto err_start;
273
 		}
278
 		}
274
 	}
279
 	}
310
  */
315
  */
311
 void snpnet_remove ( struct snp_device *snpdev ) {
316
 void snpnet_remove ( struct snp_device *snpdev ) {
312
 	EFI_SIMPLE_NETWORK_PROTOCOL *snp = snpdev->snp;
317
 	EFI_SIMPLE_NETWORK_PROTOCOL *snp = snpdev->snp;
313
-	EFI_STATUS efirc;
314
 	struct net_device *netdev = snpdev->netdev;
318
 	struct net_device *netdev = snpdev->netdev;
319
+	EFI_STATUS efirc;
320
+	int rc;
315
 
321
 
316
 	if ( snp->Mode->State == EfiSimpleNetworkInitialized &&
322
 	if ( snp->Mode->State == EfiSimpleNetworkInitialized &&
317
 	     snpdev->removal_state != EfiSimpleNetworkInitialized ) {
323
 	     snpdev->removal_state != EfiSimpleNetworkInitialized ) {
318
 		DBGC ( snp, "SNP %p shutting down\n", snp );
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
 			DBGC ( snp, "SNP %p could not shut down: %s\n",
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
 	if ( snp->Mode->State == EfiSimpleNetworkStarted &&
332
 	if ( snp->Mode->State == EfiSimpleNetworkStarted &&
327
 	     snpdev->removal_state == EfiSimpleNetworkStopped ) {
333
 	     snpdev->removal_state == EfiSimpleNetworkStopped ) {
328
 		DBGC ( snp, "SNP %p stopping\n", snp );
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
 				       user_to_virt ( image->data, 0 ),
176
 				       user_to_virt ( image->data, 0 ),
177
 				       image->len, &handle ) ) != 0 ) {
177
 				       image->len, &handle ) ) != 0 ) {
178
 		/* Not an EFI image */
178
 		/* Not an EFI image */
179
+		rc = -EEFI ( efirc );
179
 		DBGC ( image, "EFIIMAGE %p could not load: %s\n",
180
 		DBGC ( image, "EFIIMAGE %p could not load: %s\n",
180
-		       image, efi_strerror ( efirc ) );
181
-		rc = -ENOEXEC;
181
+		       image, strerror ( rc ) );
182
 		goto err_load_image;
182
 		goto err_load_image;
183
 	}
183
 	}
184
 
184
 
188
 				   NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL );
188
 				   NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL );
189
 	if ( efirc ) {
189
 	if ( efirc ) {
190
 		/* Should never happen */
190
 		/* Should never happen */
191
-		rc = EFIRC_TO_RC ( efirc );
191
+		rc = -EEFI ( efirc );
192
 		goto err_open_protocol;
192
 		goto err_open_protocol;
193
 	}
193
 	}
194
 
194
 
205
 
205
 
206
 	/* Start the image */
206
 	/* Start the image */
207
 	if ( ( efirc = bs->StartImage ( handle, NULL, NULL ) ) != 0 ) {
207
 	if ( ( efirc = bs->StartImage ( handle, NULL, NULL ) ) != 0 ) {
208
+		rc = -EEFI ( efirc );
208
 		DBGC ( image, "EFIIMAGE %p returned with status %s\n",
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
 		goto err_start_image;
211
 		goto err_start_image;
212
 	}
212
 	}
213
 
213
 
220
 	 * have no "unload" operation.
220
 	 * have no "unload" operation.
221
 	 */
221
 	 */
222
 	if ( ( efirc = bs->UnloadImage ( handle ) ) != 0 ) {
222
 	if ( ( efirc = bs->UnloadImage ( handle ) ) != 0 ) {
223
+		rc = -EEFI ( efirc );
223
 		DBGC ( image, "EFIIMAGE %p could not unload: %s\n",
224
 		DBGC ( image, "EFIIMAGE %p could not unload: %s\n",
224
-		       image, efi_strerror ( efirc ) );
225
+		       image, strerror ( rc ) );
225
 	}
226
 	}
226
  err_load_image:
227
  err_load_image:
227
 	free ( cmdline );
228
 	free ( cmdline );
246
 	EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
247
 	EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
247
 	EFI_HANDLE handle;
248
 	EFI_HANDLE handle;
248
 	EFI_STATUS efirc;
249
 	EFI_STATUS efirc;
250
+	int rc;
249
 
251
 
250
 	/* Attempt loading image */
252
 	/* Attempt loading image */
251
 	if ( ( efirc = bs->LoadImage ( FALSE, efi_image_handle, NULL,
253
 	if ( ( efirc = bs->LoadImage ( FALSE, efi_image_handle, NULL,
252
 				       user_to_virt ( image->data, 0 ),
254
 				       user_to_virt ( image->data, 0 ),
253
 				       image->len, &handle ) ) != 0 ) {
255
 				       image->len, &handle ) ) != 0 ) {
254
 		/* Not an EFI image */
256
 		/* Not an EFI image */
257
+		rc = -EEFI ( efirc );
255
 		DBGC ( image, "EFIIMAGE %p could not load: %s\n",
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
 	/* Unload the image.  We can't leave it loaded, because we
263
 	/* Unload the image.  We can't leave it loaded, because we

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

108
 		.required = (_required),				     \
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
 extern EFI_HANDLE efi_image_handle;
127
 extern EFI_HANDLE efi_image_handle;
129
 extern EFI_LOADED_IMAGE_PROTOCOL *efi_loaded_image;
128
 extern EFI_LOADED_IMAGE_PROTOCOL *efi_loaded_image;
130
 extern EFI_DEVICE_PATH_PROTOCOL *efi_loaded_image_path;
129
 extern EFI_DEVICE_PATH_PROTOCOL *efi_loaded_image_path;
131
 extern EFI_SYSTEM_TABLE *efi_systab;
130
 extern EFI_SYSTEM_TABLE *efi_systab;
132
 
131
 
133
-extern const char * efi_strerror ( EFI_STATUS efirc );
134
 extern const char * efi_guid_ntoa ( EFI_GUID *guid );
132
 extern const char * efi_guid_ntoa ( EFI_GUID *guid );
135
 
133
 
136
 extern void dbg_efi_protocols ( EFI_HANDLE handle );
134
 extern void dbg_efi_protocols ( EFI_HANDLE handle );

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

44
 extern EFI_DEVICE_PATH_PROTOCOL *
44
 extern EFI_DEVICE_PATH_PROTOCOL *
45
 efi_devpath_end ( EFI_DEVICE_PATH_PROTOCOL *path );
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
 #endif /* _IPXE_EFI_DRIVER_H */
49
 #endif /* _IPXE_EFI_DRIVER_H */

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

38
 
38
 
39
 extern struct efi_pci_device * efipci_create ( struct efi_driver *efidrv,
39
 extern struct efi_pci_device * efipci_create ( struct efi_driver *efidrv,
40
 					       EFI_HANDLE device );
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
 extern struct efi_pci_device * efipci_find_efi ( EFI_HANDLE device );
42
 extern struct efi_pci_device * efipci_find_efi ( EFI_HANDLE device );
43
 extern struct efi_pci_device * efipci_find ( struct device *dev );
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
 extern void efipci_child_del ( struct efi_pci_device *efipci,
46
 extern void efipci_child_del ( struct efi_pci_device *efipci,
47
 			       EFI_HANDLE device );
47
 			       EFI_HANDLE device );
48
 extern void efipci_destroy ( struct efi_driver *efidrv,
48
 extern void efipci_destroy ( struct efi_driver *efidrv,

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

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

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

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

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

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

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

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

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

21
 
21
 
22
 #include <stddef.h>
22
 #include <stddef.h>
23
 #include <stdio.h>
23
 #include <stdio.h>
24
+#include <string.h>
25
+#include <errno.h>
24
 #include <ipxe/efi/efi.h>
26
 #include <ipxe/efi/efi.h>
25
 #include <ipxe/efi/Protocol/DriverBinding.h>
27
 #include <ipxe/efi/Protocol/DriverBinding.h>
26
 #include <ipxe/efi/Protocol/ComponentName2.h>
28
 #include <ipxe/efi/Protocol/ComponentName2.h>
122
  * @v efidrv		EFI driver
124
  * @v efidrv		EFI driver
123
  * @ret efirc		EFI status code
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
 	EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
128
 	EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
127
 	EFI_DRIVER_BINDING_PROTOCOL *driver = &efidrv->driver;
129
 	EFI_DRIVER_BINDING_PROTOCOL *driver = &efidrv->driver;
128
 	EFI_COMPONENT_NAME2_PROTOCOL *wtf = &efidrv->wtf;
130
 	EFI_COMPONENT_NAME2_PROTOCOL *wtf = &efidrv->wtf;
129
 	EFI_STATUS efirc;
131
 	EFI_STATUS efirc;
132
+	int rc;
130
 
133
 
131
 	/* Configure driver binding protocol */
134
 	/* Configure driver binding protocol */
132
 	driver->ImageHandle = efi_image_handle;
135
 	driver->ImageHandle = efi_image_handle;
148
 			&efi_driver_binding_protocol_guid, driver,
151
 			&efi_driver_binding_protocol_guid, driver,
149
 			&efi_component_name2_protocol_guid, wtf,
152
 			&efi_component_name2_protocol_guid, wtf,
150
 			NULL ) ) != 0 ) {
153
 			NULL ) ) != 0 ) {
154
+		rc = -EEFI ( efirc );
151
 		DBGC ( efidrv, "EFIDRV %s could not install protocol: %s\n",
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
 	DBGC ( efidrv, "EFIDRV %s installed\n", efidrv->name );
160
 	DBGC ( efidrv, "EFIDRV %s installed\n", efidrv->name );

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

30
 #include <stdlib.h>
30
 #include <stdlib.h>
31
 #include <stdio.h>
31
 #include <stdio.h>
32
 #include <string.h>
32
 #include <string.h>
33
+#include <errno.h>
33
 #include <wchar.h>
34
 #include <wchar.h>
34
 #include <ipxe/image.h>
35
 #include <ipxe/image.h>
35
 #include <ipxe/efi/efi.h>
36
 #include <ipxe/efi/efi.h>
549
 int efi_file_install ( EFI_HANDLE *handle ) {
550
 int efi_file_install ( EFI_HANDLE *handle ) {
550
 	EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
551
 	EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
551
 	EFI_STATUS efirc;
552
 	EFI_STATUS efirc;
553
+	int rc;
552
 
554
 
553
 	/* Install the simple file system protocol and the block I/O
555
 	/* Install the simple file system protocol and the block I/O
554
 	 * protocol.  We don't have a block device, but large parts of
556
 	 * protocol.  We don't have a block device, but large parts of
563
 			&efi_block_io_protocol,
565
 			&efi_block_io_protocol,
564
 			&efi_simple_file_system_protocol_guid,
566
 			&efi_simple_file_system_protocol_guid,
565
 			&efi_simple_file_system_protocol, NULL ) ) != 0 ) {
567
 			&efi_simple_file_system_protocol, NULL ) ) != 0 ) {
568
+		rc = -EEFI ( efirc );
566
 		DBGC ( handle, "Could not install simple file system protocol: "
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
 	return 0;
574
 	return 0;

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

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

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

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

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

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

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

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

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

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

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

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

Loading…
Cancel
Save