Browse Source

[efi] Generalise snpnet_dev_info() to efi_device_info()

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 9 years ago
parent
commit
b9a5ff2b03
3 changed files with 69 additions and 60 deletions
  1. 1
    60
      src/drivers/net/efi/snpnet.c
  2. 4
    0
      src/include/ipxe/efi/efi_utils.h
  3. 64
    0
      src/interface/efi/efi_utils.c

+ 1
- 60
src/drivers/net/efi/snpnet.c View File

30
 #include <ipxe/efi/efi.h>
30
 #include <ipxe/efi/efi.h>
31
 #include <ipxe/efi/Protocol/SimpleNetwork.h>
31
 #include <ipxe/efi/Protocol/SimpleNetwork.h>
32
 #include <ipxe/efi/efi_driver.h>
32
 #include <ipxe/efi/efi_driver.h>
33
-#include <ipxe/efi/efi_pci.h>
34
 #include <ipxe/efi/efi_utils.h>
33
 #include <ipxe/efi/efi_utils.h>
35
 #include "snpnet.h"
34
 #include "snpnet.h"
36
 
35
 
409
 	.poll = snpnet_poll,
408
 	.poll = snpnet_poll,
410
 };
409
 };
411
 
410
 
412
-/**
413
- * Get underlying PCI device information
414
- *
415
- * @v efidev		EFI device
416
- * @v dev		Generic device to fill in
417
- * @ret rc		Return status code
418
- */
419
-static int snpnet_pci_info ( struct efi_device *efidev, struct device *dev ) {
420
-	EFI_HANDLE device = efidev->device;
421
-	EFI_HANDLE pci_device;
422
-	struct pci_device pci;
423
-	int rc;
424
-
425
-	/* Find parent PCI device */
426
-	if ( ( rc = efi_locate_device ( device, &efi_pci_io_protocol_guid,
427
-					&pci_device ) ) != 0 ) {
428
-		DBGC ( device, "SNP %p %s is not a PCI device: %s\n",
429
-		       device, efi_handle_name ( device ), strerror ( rc ) );
430
-		return rc;
431
-	}
432
-
433
-	/* Get PCI device information */
434
-	if ( ( rc = efipci_info ( pci_device, &pci ) ) != 0 ) {
435
-		DBGC ( device, "SNP %p %s could not get PCI information: %s\n",
436
-		       device, efi_handle_name ( device ), strerror ( rc ) );
437
-		return rc;
438
-	}
439
-
440
-	/* Populate SNP device information */
441
-	memcpy ( &dev->desc, &pci.dev.desc, sizeof ( dev->desc ) );
442
-	snprintf ( dev->name, sizeof ( dev->name ), "SNP-%s", pci.dev.name );
443
-
444
-	return 0;
445
-}
446
-
447
-/**
448
- * Get underlying device information
449
- *
450
- * @v efidev		EFI device
451
- * @v dev		Generic device to fill in
452
- */
453
-static void snpnet_dev_info ( struct efi_device *efidev, struct device *dev ) {
454
-	EFI_HANDLE device = efidev->device;
455
-	int rc;
456
-
457
-	/* Try getting underlying PCI device information */
458
-	if ( ( rc = snpnet_pci_info ( efidev, dev ) ) == 0 )
459
-		return;
460
-
461
-	/* If we cannot get any underlying device information, fall
462
-	 * back to providing information about the EFI handle.
463
-	 */
464
-	DBGC ( device, "SNP %p %s could not get underlying device "
465
-	       "information\n", device, efi_handle_name ( device ) );
466
-	dev->desc.bus_type = BUS_TYPE_EFI;
467
-	snprintf ( dev->name, sizeof ( dev->name ), "SNP-%p", device );
468
-}
469
-
470
 /**
411
 /**
471
  * Attach driver to device
412
  * Attach driver to device
472
  *
413
  *
511
 	efidev_set_drvdata ( efidev, netdev );
452
 	efidev_set_drvdata ( efidev, netdev );
512
 
453
 
513
 	/* Populate underlying device information */
454
 	/* Populate underlying device information */
514
-	snpnet_dev_info ( efidev, &snp->dev );
455
+	efi_device_info ( device, "SNP", &snp->dev );
515
 	snp->dev.driver_name = "SNP";
456
 	snp->dev.driver_name = "SNP";
516
 	snp->dev.parent = &efidev->dev;
457
 	snp->dev.parent = &efidev->dev;
517
 	list_add ( &snp->dev.siblings, &efidev->dev.children );
458
 	list_add ( &snp->dev.siblings, &efidev->dev.children );

+ 4
- 0
src/include/ipxe/efi/efi_utils.h View File

11
 #include <ipxe/efi/efi.h>
11
 #include <ipxe/efi/efi.h>
12
 #include <ipxe/efi/Protocol/DevicePath.h>
12
 #include <ipxe/efi/Protocol/DevicePath.h>
13
 
13
 
14
+struct device;
15
+
14
 extern EFI_DEVICE_PATH_PROTOCOL *
16
 extern EFI_DEVICE_PATH_PROTOCOL *
15
 efi_devpath_end ( EFI_DEVICE_PATH_PROTOCOL *path );
17
 efi_devpath_end ( EFI_DEVICE_PATH_PROTOCOL *path );
16
 extern int efi_locate_device ( EFI_HANDLE device, EFI_GUID *protocol,
18
 extern int efi_locate_device ( EFI_HANDLE device, EFI_GUID *protocol,
17
 			       EFI_HANDLE *parent );
19
 			       EFI_HANDLE *parent );
18
 extern int efi_child_add ( EFI_HANDLE parent, EFI_HANDLE child );
20
 extern int efi_child_add ( EFI_HANDLE parent, EFI_HANDLE child );
19
 extern void efi_child_del ( EFI_HANDLE parent, EFI_HANDLE child );
21
 extern void efi_child_del ( EFI_HANDLE parent, EFI_HANDLE child );
22
+extern void efi_device_info ( EFI_HANDLE device, const char *prefix,
23
+			      struct device *dev );
20
 
24
 
21
 #endif /* _IPXE_EFI_UTILS_H */
25
 #endif /* _IPXE_EFI_UTILS_H */

+ 64
- 0
src/interface/efi/efi_utils.c View File

19
 
19
 
20
 FILE_LICENCE ( GPL2_OR_LATER );
20
 FILE_LICENCE ( GPL2_OR_LATER );
21
 
21
 
22
+#include <stdio.h>
22
 #include <string.h>
23
 #include <string.h>
23
 #include <errno.h>
24
 #include <errno.h>
24
 #include <ipxe/efi/efi.h>
25
 #include <ipxe/efi/efi.h>
26
+#include <ipxe/efi/efi_pci.h>
25
 #include <ipxe/efi/efi_utils.h>
27
 #include <ipxe/efi/efi_utils.h>
26
 
28
 
27
 /** @file
29
 /** @file
152
 	DBGC2 ( parent, " %p %s\n",
154
 	DBGC2 ( parent, " %p %s\n",
153
 		child, efi_handle_name ( child ) );
155
 		child, efi_handle_name ( child ) );
154
 }
156
 }
157
+
158
+/**
159
+ * Get underlying PCI device information
160
+ *
161
+ * @v device		EFI device handle
162
+ * @v prefix		Device name prefix
163
+ * @v dev		Generic device to fill in
164
+ * @ret rc		Return status code
165
+ */
166
+static int efi_pci_info ( EFI_HANDLE device, const char *prefix,
167
+			  struct device *dev ) {
168
+	EFI_HANDLE pci_device;
169
+	struct pci_device pci;
170
+	int rc;
171
+
172
+	/* Find parent PCI device */
173
+	if ( ( rc = efi_locate_device ( device, &efi_pci_io_protocol_guid,
174
+					&pci_device ) ) != 0 ) {
175
+		DBGC ( device, "EFIDEV %p %s is not a PCI device: %s\n",
176
+		       device, efi_handle_name ( device ), strerror ( rc ) );
177
+		return rc;
178
+	}
179
+
180
+	/* Get PCI device information */
181
+	if ( ( rc = efipci_info ( pci_device, &pci ) ) != 0 ) {
182
+		DBGC ( device, "EFIDEV %p %s could not get PCI information: "
183
+		       "%s\n", device, efi_handle_name ( device ),
184
+		       strerror ( rc ) );
185
+		return rc;
186
+	}
187
+
188
+	/* Populate device information */
189
+	memcpy ( &dev->desc, &pci.dev.desc, sizeof ( dev->desc ) );
190
+	snprintf ( dev->name, sizeof ( dev->name ), "%s-%s",
191
+		   prefix, pci.dev.name );
192
+
193
+	return 0;
194
+}
195
+
196
+/**
197
+ * Get underlying device information
198
+ *
199
+ * @v device		EFI device handle
200
+ * @v prefix		Device name prefix
201
+ * @v dev		Generic device to fill in
202
+ */
203
+void efi_device_info ( EFI_HANDLE device, const char *prefix,
204
+		       struct device *dev ) {
205
+	int rc;
206
+
207
+	/* Try getting underlying PCI device information */
208
+	if ( ( rc = efi_pci_info ( device, prefix, dev ) ) == 0 )
209
+		return;
210
+
211
+	/* If we cannot get any underlying device information, fall
212
+	 * back to providing information about the EFI handle.
213
+	 */
214
+	DBGC ( device, "EFIDEV %p %s could not get underlying device "
215
+	       "information\n", device, efi_handle_name ( device ) );
216
+	dev->desc.bus_type = BUS_TYPE_EFI;
217
+	snprintf ( dev->name, sizeof ( dev->name ), "%s-%p", prefix, device );
218
+}

Loading…
Cancel
Save