2 Driver Binding functions and Service Binding functions for the Network driver module.
4 Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php.
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 EFI_DRIVER_BINDING_PROTOCOL gUdp6DriverBinding
= {
19 Udp6DriverBindingSupported
,
20 Udp6DriverBindingStart
,
21 Udp6DriverBindingStop
,
27 EFI_SERVICE_BINDING_PROTOCOL mUdp6ServiceBinding
= {
28 Udp6ServiceBindingCreateChild
,
29 Udp6ServiceBindingDestroyChild
33 Tests to see if this driver supports a given controller. If a child device is provided,
34 it further tests to see if this driver supports creating a handle for the specified child device.
36 This function checks to see if the driver specified by This supports the device specified by
37 ControllerHandle. Drivers will typically use the device path attached to
38 ControllerHandle and/or the services from the bus I/O abstraction attached to
39 ControllerHandle to determine if the driver supports ControllerHandle. This function
40 may be called many times during platform initialization. In order to reduce boot times, the tests
41 performed by this function must be very small, and take as little time as possible to execute. This
42 function must not change the state of any hardware devices, and this function must be aware that the
43 device specified by ControllerHandle may already be managed by the same driver or a
44 different driver. This function must match its calls to AllocatePages() with FreePages(),
45 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
46 Because ControllerHandle may have been previously started by the same driver, if a protocol is
47 already in the opened state, then it must not be closed with CloseProtocol(). This is required
48 to guarantee the state of ControllerHandle is not modified by this function.
50 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
51 @param[in] ControllerHandle The handle of the controller to test. This handle
52 must support a protocol interface that supplies
53 an I/O abstraction to the driver.
54 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
55 parameter is ignored by device drivers, and is optional for bus
56 drivers. For bus drivers, if this parameter is not NULL, then
57 the bus driver must determine if the bus controller specified
58 by ControllerHandle and the child controller specified
59 by RemainingDevicePath are both supported by this
62 @retval EFI_SUCCESS The device specified by ControllerHandle and
63 RemainingDevicePath is supported by the driver specified by This.
64 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
65 RemainingDevicePath is already being managed by the driver
67 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
68 RemainingDevicePath is already being managed by a different
69 driver or an application that requires exclusive access.
70 Currently not implemented.
71 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
72 RemainingDevicePath is not supported by the driver specified by This.
76 Udp6DriverBindingSupported (
77 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
78 IN EFI_HANDLE ControllerHandle
,
79 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
84 // Test for the Udp6ServiceBinding Protocol
86 Status
= gBS
->OpenProtocol (
88 &gEfiUdp6ServiceBindingProtocolGuid
,
90 This
->DriverBindingHandle
,
92 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
94 if (!EFI_ERROR (Status
)) {
95 return EFI_ALREADY_STARTED
;
98 // Test for the Ip6ServiceBinding Protocol
100 Status
= gBS
->OpenProtocol (
102 &gEfiIp6ServiceBindingProtocolGuid
,
104 This
->DriverBindingHandle
,
106 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
113 Start this driver on ControllerHandle.
115 This service is called by the EFI boot service ConnectController(). In order to make
116 drivers as small as possible, there are a few calling restrictions for
117 this service. ConnectController() must follow these
118 calling restrictions. If any other agent wishes to call Start() it
119 must also follow these calling restrictions.
121 @param[in] This Protocol instance pointer.
122 @param[in] ControllerHandle Handle of device to bind the driver to.
123 @param[in] RemainingDevicePath Optional parameter use to pick a specific child
126 @retval EFI_SUCCES This driver is added to ControllerHandle.
127 @retval EFI_OUT_OF_RESOURCES The required system resource can't be allocated.
128 @retval other This driver does not support this device.
133 Udp6DriverBindingStart (
134 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
135 IN EFI_HANDLE ControllerHandle
,
136 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
140 UDP6_SERVICE_DATA
*Udp6Service
;
143 // Allocate Private Context Data Structure.
145 Udp6Service
= AllocateZeroPool (sizeof (UDP6_SERVICE_DATA
));
146 if (Udp6Service
== NULL
) {
147 Status
= EFI_OUT_OF_RESOURCES
;
151 Status
= Udp6CreateService (Udp6Service
, This
->DriverBindingHandle
, ControllerHandle
);
152 if (EFI_ERROR (Status
)) {
157 // Install the Udp6ServiceBindingProtocol on the ControllerHandle.
159 Status
= gBS
->InstallMultipleProtocolInterfaces (
161 &gEfiUdp6ServiceBindingProtocolGuid
,
162 &Udp6Service
->ServiceBinding
,
165 if (EFI_ERROR (Status
)) {
166 Udp6CleanService (Udp6Service
);
169 Status
= Udp6SetVariableData (Udp6Service
);
173 if (EFI_ERROR (Status
)) {
174 if (Udp6Service
!= NULL
) {
175 FreePool (Udp6Service
);
182 Stop this driver on ControllerHandle.
184 This service is called by the EFI boot service DisconnectController(). In order to
185 make drivers as small as possible, there are a few calling
186 restrictions for this service. DisconnectController()
187 must follow these calling restrictions. If any other agent wishes
188 to call Stop(), it must also follow these calling restrictions.
190 @param[in] This Protocol instance pointer.
191 @param[in] ControllerHandle Handle of device to stop the driver on.
192 @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If the number
193 of children is zero stop the entire bus driver.
194 @param[in] ChildHandleBuffer List of Child Handles to Stop. It is optional.
196 @retval EFI_SUCCES This driver is removed ControllerHandle.
197 @retval EFI_DEVICE_ERROR Can't find the NicHandle from the ControllerHandle and specified GUID.
198 @retval other This driver was not removed from this device.
203 Udp6DriverBindingStop (
204 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
205 IN EFI_HANDLE ControllerHandle
,
206 IN UINTN NumberOfChildren
,
207 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL
211 EFI_HANDLE NicHandle
;
212 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
213 UDP6_SERVICE_DATA
*Udp6Service
;
214 UDP6_INSTANCE_DATA
*Instance
;
217 // Find the NicHandle where UDP6 ServiceBinding Protocol is installed.
219 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiIp6ProtocolGuid
);
220 if (NicHandle
== NULL
) {
221 return EFI_DEVICE_ERROR
;
225 // Retrieve the UDP6 ServiceBinding Protocol.
227 Status
= gBS
->OpenProtocol (
229 &gEfiUdp6ServiceBindingProtocolGuid
,
230 (VOID
**) &ServiceBinding
,
231 This
->DriverBindingHandle
,
233 EFI_OPEN_PROTOCOL_GET_PROTOCOL
235 if (EFI_ERROR (Status
)) {
236 return EFI_DEVICE_ERROR
;
239 Udp6Service
= UDP6_SERVICE_DATA_FROM_THIS (ServiceBinding
);
241 if (NumberOfChildren
== 0) {
243 gBS
->UninstallMultipleProtocolInterfaces (
245 &gEfiUdp6ServiceBindingProtocolGuid
,
246 &Udp6Service
->ServiceBinding
,
250 Udp6ClearVariableData (Udp6Service
);
252 Udp6CleanService (Udp6Service
);
254 FreePool (Udp6Service
);
257 while (!IsListEmpty (&Udp6Service
->ChildrenList
)) {
258 Instance
= NET_LIST_HEAD (&Udp6Service
->ChildrenList
, UDP6_INSTANCE_DATA
, Link
);
260 Status
= ServiceBinding
->DestroyChild (ServiceBinding
, Instance
->ChildHandle
);
268 Creates a child handle and installs a protocol.
270 The CreateChild() function installs a protocol on ChildHandle.
271 If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle.
272 If ChildHandle is not a pointer to NULL, then the protocol installs on the existing ChildHandle.
274 @param[in] This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
275 @param[in, out] ChildHandle Pointer to the handle of the child to create. If it is NULL,
276 then a new handle is created. If it is a pointer to an existing UEFI handle,
277 then the protocol is added to the existing UEFI handle.
279 @retval EFI_SUCCES The protocol was added to ChildHandle.
280 @retval EFI_INVALID_PARAMETER This is NULL or ChildHandle is NULL.
281 @retval EFI_OUT_OF_RESOURCES There are not enough resources availabe to create
283 @retval other The child handle was not created.
288 Udp6ServiceBindingCreateChild (
289 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
290 IN OUT EFI_HANDLE
*ChildHandle
294 UDP6_SERVICE_DATA
*Udp6Service
;
295 UDP6_INSTANCE_DATA
*Instance
;
299 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
300 return EFI_INVALID_PARAMETER
;
303 Udp6Service
= UDP6_SERVICE_DATA_FROM_THIS (This
);
306 // Allocate the instance private data structure.
308 Instance
= AllocateZeroPool (sizeof (UDP6_INSTANCE_DATA
));
309 if (Instance
== NULL
) {
310 return EFI_OUT_OF_RESOURCES
;
313 Udp6InitInstance (Udp6Service
, Instance
);
316 // Add an IpInfo for this instance.
318 Instance
->IpInfo
= IpIoAddIp (Udp6Service
->IpIo
);
319 if (Instance
->IpInfo
== NULL
) {
320 Status
= EFI_OUT_OF_RESOURCES
;
325 // Install the Udp6Protocol for this instance.
327 Status
= gBS
->InstallMultipleProtocolInterfaces (
329 &gEfiUdp6ProtocolGuid
,
330 &Instance
->Udp6Proto
,
333 if (EFI_ERROR (Status
)) {
337 Instance
->ChildHandle
= *ChildHandle
;
340 // Open the default Ip6 protocol in the IP_IO BY_CHILD.
342 Status
= gBS
->OpenProtocol (
343 Udp6Service
->IpIo
->ChildHandle
,
344 &gEfiIp6ProtocolGuid
,
346 gUdp6DriverBinding
.DriverBindingHandle
,
347 Instance
->ChildHandle
,
348 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
350 if (EFI_ERROR (Status
)) {
354 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
357 // Link this instance into the service context data and increase the ChildrenNumber.
359 InsertTailList (&Udp6Service
->ChildrenList
, &Instance
->Link
);
360 Udp6Service
->ChildrenNumber
++;
362 gBS
->RestoreTPL (OldTpl
);
368 if (Instance
->ChildHandle
!= NULL
) {
369 gBS
->UninstallMultipleProtocolInterfaces (
370 Instance
->ChildHandle
,
371 &gEfiUdp6ProtocolGuid
,
372 &Instance
->Udp6Proto
,
377 if (Instance
->IpInfo
!= NULL
) {
378 IpIoRemoveIp (Udp6Service
->IpIo
, Instance
->IpInfo
);
381 Udp6CleanInstance (Instance
);
389 Destroys a child handle with a set of I/O services.
390 The DestroyChild() function does the opposite of CreateChild(). It removes a protocol
391 that was installed by CreateChild() from ChildHandle. If the removed protocol is the
392 last protocol on ChildHandle, then ChildHandle is destroyed.
394 @param[in] This Protocol instance pointer.
395 @param[in] ChildHandle Handle of the child to destroy.
397 @retval EFI_SUCCES The I/O services were removed from the child
399 @retval EFI_UNSUPPORTED The child handle does not support the I/O services
400 that are being removed.
401 @retval EFI_INVALID_PARAMETER Child handle is NULL.
402 @retval EFI_ACCESS_DENIED The child handle could not be destroyed because
403 its I/O services are being used.
404 @retval other The child handle was not destroyed.
409 Udp6ServiceBindingDestroyChild (
410 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
411 IN EFI_HANDLE ChildHandle
415 UDP6_SERVICE_DATA
*Udp6Service
;
416 EFI_UDP6_PROTOCOL
*Udp6Proto
;
417 UDP6_INSTANCE_DATA
*Instance
;
420 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
421 return EFI_INVALID_PARAMETER
;
424 Udp6Service
= UDP6_SERVICE_DATA_FROM_THIS (This
);
427 // Try to get the Udp6 protocol from the ChildHandle.
429 Status
= gBS
->OpenProtocol (
431 &gEfiUdp6ProtocolGuid
,
432 (VOID
**) &Udp6Proto
,
433 gUdp6DriverBinding
.DriverBindingHandle
,
435 EFI_OPEN_PROTOCOL_GET_PROTOCOL
437 if (EFI_ERROR (Status
)) {
438 return EFI_UNSUPPORTED
;
441 Instance
= UDP6_INSTANCE_DATA_FROM_THIS (Udp6Proto
);
443 if (Instance
->Destroyed
) {
448 // Use the Destroyed flag to avoid the re-entering of the following code.
450 Instance
->Destroyed
= TRUE
;
453 // Close the Ip6 protocol.
456 Udp6Service
->IpIo
->ChildHandle
,
457 &gEfiIp6ProtocolGuid
,
458 gUdp6DriverBinding
.DriverBindingHandle
,
459 Instance
->ChildHandle
463 // Uninstall the Udp6Protocol previously installed on the ChildHandle.
465 Status
= gBS
->UninstallMultipleProtocolInterfaces (
467 &gEfiUdp6ProtocolGuid
,
468 (VOID
*) &Instance
->Udp6Proto
,
471 if (EFI_ERROR (Status
)) {
472 Instance
->Destroyed
= FALSE
;
477 // Reset the configuration in case the instance's consumer forgets to do this.
479 Udp6Proto
->Configure (Udp6Proto
, NULL
);
482 // Remove the IpInfo this instance consumes.
484 IpIoRemoveIp (Udp6Service
->IpIo
, Instance
->IpInfo
);
486 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
489 // Remove this instance from the service context data's ChildrenList.
491 RemoveEntryList (&Instance
->Link
);
492 Udp6Service
->ChildrenNumber
--;
495 // Clean the instance.
497 Udp6CleanInstance (Instance
);
499 gBS
->RestoreTPL (OldTpl
);
507 This is the declaration of an EFI image entry point. This entry point is
508 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers, including
509 both device drivers and bus drivers.
511 The entry point for Udp6 driver that installs the driver binding
512 and component name protocol on its ImageHandle.
514 @param[in] ImageHandle The firmware allocated handle for the UEFI image.
515 @param[in] SystemTable A pointer to the EFI System Table.
517 @retval EFI_SUCCESS The operation completed successfully.
518 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
523 Udp6DriverEntryPoint (
524 IN EFI_HANDLE ImageHandle
,
525 IN EFI_SYSTEM_TABLE
*SystemTable
531 // Install the Udp6DriverBinding and Udp6ComponentName protocols.
534 Status
= EfiLibInstallDriverBindingComponentName2 (
542 if (!EFI_ERROR (Status
)) {
544 // Initialize the UDP random port.
546 mUdp6RandomPort
= (UINT16
)(
547 ((UINT16
) NetRandomInitSeed ()) %