Browse Source

[efi] Connect driver to devices as part of installation

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 10 years ago
parent
commit
2602965806
1 changed files with 69 additions and 20 deletions
  1. 69
    20
      src/interface/efi/efi_driver.c

+ 69
- 20
src/interface/efi/efi_driver.c View File

118
 	return EFI_UNSUPPORTED;
118
 	return EFI_UNSUPPORTED;
119
 }
119
 }
120
 
120
 
121
+/**
122
+ * Try to connect EFI driver
123
+ *
124
+ * @v efidrv		EFI driver
125
+ * @v handle		Controller handle
126
+ */
127
+static void efi_driver_connect ( struct efi_driver *efidrv, EFI_HANDLE handle ){
128
+	EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
129
+	EFI_HANDLE drivers[2] = { efidrv->driver.DriverBindingHandle, NULL };
130
+
131
+	bs->ConnectController ( handle, drivers, NULL, FALSE );
132
+}
133
+
134
+/**
135
+ * Try to disconnect EFI driver
136
+ *
137
+ * @v efidrv		EFI driver
138
+ * @v handle		Controller handle
139
+ */
140
+static void efi_driver_disconnect ( struct efi_driver *efidrv,
141
+				    EFI_HANDLE handle ) {
142
+	EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
143
+
144
+	bs->DisconnectController ( handle, efidrv->driver.DriverBindingHandle,
145
+				   NULL );
146
+}
147
+
148
+/**
149
+ * Connect/disconnect EFI driver from all handles
150
+ *
151
+ * @v efidrv		EFI driver
152
+ * @v method		Connect/disconnect method
153
+ * @ret rc		Return status code
154
+ */
155
+static int efi_driver_handles ( struct efi_driver *efidrv,
156
+				void ( * method ) ( struct efi_driver *efidrv,
157
+						    EFI_HANDLE handle ) ) {
158
+	EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
159
+	EFI_HANDLE *handles;
160
+	UINTN num_handles;
161
+	EFI_STATUS efirc;
162
+	UINTN i;
163
+	int rc;
164
+
165
+	/* Enumerate all handles */
166
+	if ( ( efirc = bs->LocateHandleBuffer ( AllHandles, NULL, NULL,
167
+						&num_handles,
168
+						&handles ) ) != 0 ) {
169
+		rc = -EEFI ( efirc );
170
+		DBGC ( efidrv, "EFIDRV %s could not list handles: %s\n",
171
+		       efidrv->name, strerror ( rc ) );
172
+		return rc;
173
+	}
174
+
175
+	/* Connect/disconnect driver from all handles */
176
+	for ( i = 0 ; i < num_handles ; i++ )
177
+		method ( efidrv, handles[i] );
178
+
179
+	/* Free list of handles */
180
+	bs->FreePool ( handles );
181
+
182
+	return 0;
183
+}
184
+
121
 /**
185
 /**
122
  * Install EFI driver
186
  * Install EFI driver
123
  *
187
  *
159
 		return rc;
223
 		return rc;
160
 	}
224
 	}
161
 
225
 
226
+	/* Connect devices */
227
+	DBGC ( efidrv, "EFIDRV %s connecting devices\n", efidrv->name );
228
+	efi_driver_handles ( efidrv, efi_driver_connect );
229
+
162
 	DBGC ( efidrv, "EFIDRV %s installed\n", efidrv->name );
230
 	DBGC ( efidrv, "EFIDRV %s installed\n", efidrv->name );
163
 	return 0;
231
 	return 0;
164
 }
232
 }
170
  */
238
  */
171
 void efi_driver_uninstall ( struct efi_driver *efidrv ) {
239
 void efi_driver_uninstall ( struct efi_driver *efidrv ) {
172
 	EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
240
 	EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
173
-	EFI_HANDLE *handles;
174
-	UINTN num_handles;
175
-	EFI_STATUS efirc;
176
-	UINTN i;
177
-	int rc;
178
 
241
 
179
 	/* Disconnect the driver from its devices */
242
 	/* Disconnect the driver from its devices */
180
-	if ( ( efirc = bs->LocateHandleBuffer ( AllHandles, NULL, NULL,
181
-						&num_handles,
182
-						&handles ) ) != 0 ) {
183
-		rc = -EEFI ( efirc );
184
-		DBGC ( efidrv, "EFIDRV %s could not list handles: %s\n",
185
-		       efidrv->name, strerror ( rc ) );
186
-		/* No way to disconnect driver; leave it loaded */
187
-		return;
188
-	}
189
 	DBGC ( efidrv, "EFIDRV %s disconnecting devices\n", efidrv->name );
243
 	DBGC ( efidrv, "EFIDRV %s disconnecting devices\n", efidrv->name );
190
-	for ( i = 0 ; i < num_handles ; i++ ) {
191
-		bs->DisconnectController ( handles[i],
192
-					   efidrv->driver.DriverBindingHandle,
193
-					   NULL );
194
-	}
195
-	bs->FreePool ( handles );
244
+	efi_driver_handles ( efidrv, efi_driver_disconnect );
196
 
245
 
197
 	/* Uninstall the driver */
246
 	/* Uninstall the driver */
198
 	bs->UninstallMultipleProtocolInterfaces (
247
 	bs->UninstallMultipleProtocolInterfaces (

Loading…
Cancel
Save