Pārlūkot izejas kodu

[efi] Move abstract device path and handle functions to efi_utils.c

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 10 gadus atpakaļ
vecāks
revīzija
2bf428c2a9

+ 1
- 1
src/image/efi_image.c Parādīt failu

@@ -26,7 +26,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
26 26
 #include <ipxe/efi/efi_snp.h>
27 27
 #include <ipxe/efi/efi_download.h>
28 28
 #include <ipxe/efi/efi_file.h>
29
-#include <ipxe/efi/efi_driver.h>
29
+#include <ipxe/efi/efi_utils.h>
30 30
 #include <ipxe/efi/efi_strings.h>
31 31
 #include <ipxe/efi/efi_wrap.h>
32 32
 #include <ipxe/image.h>

+ 0
- 4
src/include/ipxe/efi/efi_driver.h Parādīt failu

@@ -82,11 +82,7 @@ static inline void * efidev_get_drvdata ( struct efi_device *efidev ) {
82 82
 	return efidev->priv;
83 83
 }
84 84
 
85
-extern EFI_DEVICE_PATH_PROTOCOL *
86
-efi_devpath_end ( EFI_DEVICE_PATH_PROTOCOL *path );
87 85
 extern struct efi_device * efidev_parent ( struct device *dev );
88
-extern int efidev_child_add ( struct efi_device *efidev, EFI_HANDLE device );
89
-extern void efidev_child_del ( struct efi_device *efidev, EFI_HANDLE device );
90 86
 extern int efi_driver_install ( void );
91 87
 extern void efi_driver_uninstall ( void );
92 88
 extern int efi_driver_connect_all ( void );

+ 19
- 0
src/include/ipxe/efi/efi_utils.h Parādīt failu

@@ -0,0 +1,19 @@
1
+#ifndef _IPXE_EFI_UTILS_H
2
+#define _IPXE_EFI_UTILS_H
3
+
4
+/** @file
5
+ *
6
+ * EFI utilities
7
+ */
8
+
9
+FILE_LICENCE ( GPL2_OR_LATER );
10
+
11
+#include <ipxe/efi/efi.h>
12
+#include <ipxe/efi/Protocol/DevicePath.h>
13
+
14
+extern EFI_DEVICE_PATH_PROTOCOL *
15
+efi_devpath_end ( EFI_DEVICE_PATH_PROTOCOL *path );
16
+extern int efi_child_add ( EFI_HANDLE parent, EFI_HANDLE child );
17
+extern void efi_child_del ( EFI_HANDLE parent, EFI_HANDLE child );
18
+
19
+#endif /* _IPXE_EFI_UTILS_H */

+ 1
- 0
src/include/ipxe/errfile.h Parādīt failu

@@ -305,6 +305,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
305 305
 #define ERRFILE_xenstore	      ( ERRFILE_OTHER | 0x00420000 )
306 306
 #define ERRFILE_xenbus		      ( ERRFILE_OTHER | 0x00430000 )
307 307
 #define ERRFILE_xengrant	      ( ERRFILE_OTHER | 0x00440000 )
308
+#define ERRFILE_efi_utils	      ( ERRFILE_OTHER | 0x00450000 )
308 309
 
309 310
 /** @} */
310 311
 

+ 1
- 1
src/interface/efi/efi_debug.c Parādīt failu

@@ -32,7 +32,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
32 32
 #include <ipxe/uuid.h>
33 33
 #include <ipxe/base16.h>
34 34
 #include <ipxe/efi/efi.h>
35
-#include <ipxe/efi/efi_driver.h>
35
+#include <ipxe/efi/efi_utils.h>
36 36
 #include <ipxe/efi/Protocol/ComponentName.h>
37 37
 #include <ipxe/efi/Protocol/ComponentName2.h>
38 38
 #include <ipxe/efi/Protocol/DevicePathToText.h>

+ 1
- 74
src/interface/efi/efi_driver.c Parādīt failu

@@ -43,24 +43,6 @@ static EFI_DRIVER_BINDING_PROTOCOL efi_driver_binding;
43 43
 /** List of controlled EFI devices */
44 44
 static LIST_HEAD ( efi_devices );
45 45
 
46
-/**
47
- * Find end of device path
48
- *
49
- * @v path		Path to device
50
- * @ret path_end	End of device path
51
- */
52
-EFI_DEVICE_PATH_PROTOCOL * efi_devpath_end ( EFI_DEVICE_PATH_PROTOCOL *path ) {
53
-
54
-	while ( path->Type != END_DEVICE_PATH_TYPE ) {
55
-		path = ( ( ( void * ) path ) +
56
-			 /* There's this amazing new-fangled thing known as
57
-			  * a UINT16, but who wants to use one of those? */
58
-			 ( ( path->Length[1] << 8 ) | path->Length[0] ) );
59
-	}
60
-
61
-	return path;
62
-}
63
-
64 46
 /**
65 47
  * Find EFI device
66 48
  *
@@ -100,61 +82,6 @@ struct efi_device * efidev_parent ( struct device *dev ) {
100 82
 	return efidev;
101 83
 }
102 84
 
103
-/**
104
- * Add EFI device as child of EFI device
105
- *
106
- * @v efidev		EFI device
107
- * @v device		EFI child device handle
108
- * @ret efirc		EFI status code
109
- */
110
-int efidev_child_add ( struct efi_device *efidev, EFI_HANDLE device ) {
111
-	EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
112
-	void *devpath;
113
-	EFI_STATUS efirc;
114
-	int rc;
115
-
116
-	/* Re-open the device path protocol */
117
-	if ( ( efirc = bs->OpenProtocol ( efidev->device,
118
-					  &efi_device_path_protocol_guid,
119
-					  &devpath,
120
-					  efi_image_handle, device,
121
-					  EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
122
-					  ) ) != 0 ) {
123
-		rc = -EEFI ( efirc );
124
-		DBGC ( efidev->device, "EFIDRV %p %s could not add child",
125
-		       efidev->device, efi_handle_name ( efidev->device ) );
126
-		DBGC ( efidev->device, " %p %s: %s\n", device,
127
-		       efi_handle_name ( device ), strerror ( rc ) );
128
-		DBGC_EFI_OPENERS ( efidev->device, efidev->device,
129
-				   &efi_device_path_protocol_guid );
130
-		return rc;
131
-	}
132
-
133
-	DBGC2 ( efidev->device, "EFIDRV %p %s added child",
134
-		efidev->device, efi_handle_name ( efidev->device ) );
135
-	DBGC2 ( efidev->device, " %p %s\n", device, efi_handle_name ( device ));
136
-	return 0;
137
-}
138
-
139
-/**
140
- * Remove EFI device as child of EFI device
141
- *
142
- * @v efidev		EFI device
143
- * @v device		EFI child device handle
144
- * @ret efirc		EFI status code
145
- */
146
-void efidev_child_del ( struct efi_device *efidev, EFI_HANDLE device ) {
147
-	EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
148
-
149
-	bs->CloseProtocol ( efidev->device,
150
-			    &efi_device_path_protocol_guid,
151
-			    efi_image_handle, device );
152
-	DBGC2 ( efidev->device, "EFIDRV %p %s removed child",
153
-		efidev->device, efi_handle_name ( efidev->device ) );
154
-	DBGC2 ( efidev->device, " %p %s\n",
155
-		device, efi_handle_name ( device ) );
156
-}
157
-
158 85
 /**
159 86
  * Check to see if driver supports a device
160 87
  *
@@ -242,7 +169,7 @@ efi_driver_start ( EFI_DRIVER_BINDING_PROTOCOL *driver __unused,
242 169
 	/* Try to start this device */
243 170
 	for_each_table_entry ( efidrv, EFI_DRIVERS ) {
244 171
 		if ( ( rc = efidrv->supported ( device ) ) != 0 ) {
245
-			DBGC ( device, "EFIDEV %p %s is not supported by "
172
+			DBGC ( device, "EFIDRV %p %s is not supported by "
246 173
 			       "driver \"%s\": %s\n", device,
247 174
 			       efi_handle_name ( device ), efidrv->name,
248 175
 			       strerror ( rc ) );

+ 6
- 5
src/interface/efi/efi_snp.c Parādīt failu

@@ -31,6 +31,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
31 31
 #include <ipxe/efi/efi.h>
32 32
 #include <ipxe/efi/efi_driver.h>
33 33
 #include <ipxe/efi/efi_strings.h>
34
+#include <ipxe/efi/efi_utils.h>
34 35
 #include <ipxe/efi/efi_snp.h>
35 36
 #include <usr/autoboot.h>
36 37
 
@@ -1047,11 +1048,11 @@ static int efi_snp_probe ( struct net_device *netdev ) {
1047 1048
 	}
1048 1049
 
1049 1050
 	/* Add as child of EFI parent device */
1050
-	if ( ( rc = efidev_child_add ( efidev, snpdev->handle ) ) != 0 ) {
1051
+	if ( ( rc = efi_child_add ( efidev->device, snpdev->handle ) ) != 0 ) {
1051 1052
 		DBGC ( snpdev, "SNPDEV %p could not become child of %p %s: "
1052 1053
 		       "%s\n", snpdev, efidev->device,
1053 1054
 		       efi_handle_name ( efidev->device ), strerror ( rc ) );
1054
-		goto err_efidev_child_add;
1055
+		goto err_efi_child_add;
1055 1056
 	}
1056 1057
 
1057 1058
 	/* Install HII */
@@ -1078,8 +1079,8 @@ static int efi_snp_probe ( struct net_device *netdev ) {
1078 1079
 
1079 1080
 	if ( snpdev->package_list )
1080 1081
 		efi_snp_hii_uninstall ( snpdev );
1081
-	efidev_child_del ( efidev, snpdev->handle );
1082
- err_efidev_child_add:
1082
+	efi_child_del ( efidev->device, snpdev->handle );
1083
+ err_efi_child_add:
1083 1084
 	bs->UninstallMultipleProtocolInterfaces (
1084 1085
 			snpdev->handle,
1085 1086
 			&efi_simple_network_protocol_guid, &snpdev->snp,
@@ -1149,7 +1150,7 @@ static void efi_snp_remove ( struct net_device *netdev ) {
1149 1150
 	/* Uninstall the SNP */
1150 1151
 	if ( snpdev->package_list )
1151 1152
 		efi_snp_hii_uninstall ( snpdev );
1152
-	efidev_child_del ( snpdev->efidev, snpdev->handle );
1153
+	efi_child_del ( snpdev->efidev->device, snpdev->handle );
1153 1154
 	list_del ( &snpdev->list );
1154 1155
 	bs->UninstallMultipleProtocolInterfaces (
1155 1156
 			snpdev->handle,

+ 102
- 0
src/interface/efi/efi_utils.c Parādīt failu

@@ -0,0 +1,102 @@
1
+/*
2
+ * Copyright (C) 2011 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 <string.h>
23
+#include <errno.h>
24
+#include <ipxe/efi/efi.h>
25
+#include <ipxe/efi/efi_utils.h>
26
+
27
+/** @file
28
+ *
29
+ * EFI utilities
30
+ *
31
+ */
32
+
33
+/**
34
+ * Find end of device path
35
+ *
36
+ * @v path		Path to device
37
+ * @ret path_end	End of device path
38
+ */
39
+EFI_DEVICE_PATH_PROTOCOL * efi_devpath_end ( EFI_DEVICE_PATH_PROTOCOL *path ) {
40
+
41
+	while ( path->Type != END_DEVICE_PATH_TYPE ) {
42
+		path = ( ( ( void * ) path ) +
43
+			 /* There's this amazing new-fangled thing known as
44
+			  * a UINT16, but who wants to use one of those? */
45
+			 ( ( path->Length[1] << 8 ) | path->Length[0] ) );
46
+	}
47
+
48
+	return path;
49
+}
50
+
51
+/**
52
+ * Add EFI device as child of another EFI device
53
+ *
54
+ * @v parent		EFI parent device handle
55
+ * @v child		EFI child device handle
56
+ * @ret rc		Return status code
57
+ */
58
+int efi_child_add ( EFI_HANDLE parent, EFI_HANDLE child ) {
59
+	EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
60
+	void *devpath;
61
+	EFI_STATUS efirc;
62
+	int rc;
63
+
64
+	/* Re-open the device path protocol */
65
+	if ( ( efirc = bs->OpenProtocol ( parent,
66
+					  &efi_device_path_protocol_guid,
67
+					  &devpath,
68
+					  efi_image_handle, child,
69
+					  EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
70
+					  ) ) != 0 ) {
71
+		rc = -EEFI ( efirc );
72
+		DBGC ( parent, "EFIDEV %p %s could not add child",
73
+		       parent, efi_handle_name ( parent ) );
74
+		DBGC ( parent, " %p %s: %s\n", child,
75
+		       efi_handle_name ( child ), strerror ( rc ) );
76
+		DBGC_EFI_OPENERS ( parent, parent,
77
+				   &efi_device_path_protocol_guid );
78
+		return rc;
79
+	}
80
+
81
+	DBGC2 ( parent, "EFIDEV %p %s added child",
82
+		parent, efi_handle_name ( parent ) );
83
+	DBGC2 ( parent, " %p %s\n", child, efi_handle_name ( child ) );
84
+	return 0;
85
+}
86
+
87
+/**
88
+ * Remove EFI device as child of another EFI device
89
+ *
90
+ * @v parent		EFI parent device handle
91
+ * @v child		EFI child device handle
92
+ */
93
+void efi_child_del ( EFI_HANDLE parent, EFI_HANDLE child ) {
94
+	EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
95
+
96
+	bs->CloseProtocol ( parent, &efi_device_path_protocol_guid,
97
+			    efi_image_handle, child );
98
+	DBGC2 ( parent, "EFIDEV %p %s removed child",
99
+		parent, efi_handle_name ( parent ) );
100
+	DBGC2 ( parent, " %p %s\n",
101
+		child, efi_handle_name ( child ) );
102
+}

Notiek ielāde…
Atcelt
Saglabāt