2 Driver Binding functions and Service Binding functions for the Network driver module.
4 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
12 EFI_DRIVER_BINDING_PROTOCOL gUdp6DriverBinding
= {
13 Udp6DriverBindingSupported
,
14 Udp6DriverBindingStart
,
15 Udp6DriverBindingStop
,
21 EFI_SERVICE_BINDING_PROTOCOL mUdp6ServiceBinding
= {
22 Udp6ServiceBindingCreateChild
,
23 Udp6ServiceBindingDestroyChild
27 Tests to see if this driver supports a given controller. If a child device is provided,
28 it further tests to see if this driver supports creating a handle for the specified child device.
30 This function checks to see if the driver specified by This supports the device specified by
31 ControllerHandle. Drivers will typically use the device path attached to
32 ControllerHandle and/or the services from the bus I/O abstraction attached to
33 ControllerHandle to determine if the driver supports ControllerHandle. This function
34 may be called many times during platform initialization. In order to reduce boot times, the tests
35 performed by this function must be very small, and take as little time as possible to execute. This
36 function must not change the state of any hardware devices, and this function must be aware that the
37 device specified by ControllerHandle may already be managed by the same driver or a
38 different driver. This function must match its calls to AllocatePages() with FreePages(),
39 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
40 Because ControllerHandle may have been previously started by the same driver, if a protocol is
41 already in the opened state, then it must not be closed with CloseProtocol(). This is required
42 to guarantee the state of ControllerHandle is not modified by this function.
44 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
45 @param[in] ControllerHandle The handle of the controller to test. This handle
46 must support a protocol interface that supplies
47 an I/O abstraction to the driver.
48 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
49 parameter is ignored by device drivers, and is optional for bus
50 drivers. For bus drivers, if this parameter is not NULL, then
51 the bus driver must determine if the bus controller specified
52 by ControllerHandle and the child controller specified
53 by RemainingDevicePath are both supported by this
56 @retval EFI_SUCCESS The device specified by ControllerHandle and
57 RemainingDevicePath is supported by the driver specified by This.
58 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
59 RemainingDevicePath is already being managed by the driver
61 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
62 RemainingDevicePath is already being managed by a different
63 driver or an application that requires exclusive access.
64 Currently not implemented.
65 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
66 RemainingDevicePath is not supported by the driver specified by This.
70 Udp6DriverBindingSupported (
71 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
72 IN EFI_HANDLE ControllerHandle
,
73 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
79 // Test for the Udp6ServiceBinding Protocol
81 Status
= gBS
->OpenProtocol (
83 &gEfiUdp6ServiceBindingProtocolGuid
,
85 This
->DriverBindingHandle
,
87 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
89 if (!EFI_ERROR (Status
)) {
90 return EFI_ALREADY_STARTED
;
94 // Test for the Ip6ServiceBinding Protocol
96 Status
= gBS
->OpenProtocol (
98 &gEfiIp6ServiceBindingProtocolGuid
,
100 This
->DriverBindingHandle
,
102 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
109 Start this driver on ControllerHandle.
111 This service is called by the EFI boot service ConnectController(). In order to make
112 drivers as small as possible, there are a few calling restrictions for
113 this service. ConnectController() must follow these
114 calling restrictions. If any other agent wishes to call Start() it
115 must also follow these calling restrictions.
117 @param[in] This Protocol instance pointer.
118 @param[in] ControllerHandle Handle of device to bind the driver to.
119 @param[in] RemainingDevicePath Optional parameter use to pick a specific child
122 @retval EFI_SUCCESS This driver is added to ControllerHandle.
123 @retval EFI_OUT_OF_RESOURCES The required system resource can't be allocated.
124 @retval other This driver does not support this device.
129 Udp6DriverBindingStart (
130 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
131 IN EFI_HANDLE ControllerHandle
,
132 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
136 UDP6_SERVICE_DATA
*Udp6Service
;
139 // Allocate Private Context Data Structure.
141 Udp6Service
= AllocateZeroPool (sizeof (UDP6_SERVICE_DATA
));
142 if (Udp6Service
== NULL
) {
143 Status
= EFI_OUT_OF_RESOURCES
;
147 Status
= Udp6CreateService (Udp6Service
, This
->DriverBindingHandle
, ControllerHandle
);
148 if (EFI_ERROR (Status
)) {
153 // Install the Udp6ServiceBindingProtocol on the ControllerHandle.
155 Status
= gBS
->InstallMultipleProtocolInterfaces (
157 &gEfiUdp6ServiceBindingProtocolGuid
,
158 &Udp6Service
->ServiceBinding
,
161 if (EFI_ERROR (Status
)) {
162 Udp6CleanService (Udp6Service
);
166 if (EFI_ERROR (Status
)) {
167 if (Udp6Service
!= NULL
) {
168 FreePool (Udp6Service
);
176 Callback function which provided by user to remove one node in NetDestroyLinkList process.
178 @param[in] Entry The entry to be removed.
179 @param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList.
181 @retval EFI_INVALID_PARAMETER Entry is NULL or Context is NULL.
182 @retval EFI_SUCCESS The entry has been removed successfully.
183 @retval Others Fail to remove the entry.
188 Udp6DestroyChildEntryInHandleBuffer (
189 IN LIST_ENTRY
*Entry
,
193 UDP6_INSTANCE_DATA
*Instance
;
194 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
195 UINTN NumberOfChildren
;
196 EFI_HANDLE
*ChildHandleBuffer
;
198 if ((Entry
== NULL
) || (Context
== NULL
)) {
199 return EFI_INVALID_PARAMETER
;
202 Instance
= NET_LIST_USER_STRUCT_S (Entry
, UDP6_INSTANCE_DATA
, Link
, UDP6_INSTANCE_DATA_SIGNATURE
);
203 ServiceBinding
= ((UDP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*)Context
)->ServiceBinding
;
204 NumberOfChildren
= ((UDP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*)Context
)->NumberOfChildren
;
205 ChildHandleBuffer
= ((UDP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*)Context
)->ChildHandleBuffer
;
207 if (!NetIsInHandleBuffer (Instance
->ChildHandle
, NumberOfChildren
, ChildHandleBuffer
)) {
211 return ServiceBinding
->DestroyChild (ServiceBinding
, Instance
->ChildHandle
);
215 Stop this driver on ControllerHandle.
217 This service is called by the EFI boot service DisconnectController(). In order to
218 make drivers as small as possible, there are a few calling
219 restrictions for this service. DisconnectController()
220 must follow these calling restrictions. If any other agent wishes
221 to call Stop(), it must also follow these calling restrictions.
223 @param[in] This Protocol instance pointer.
224 @param[in] ControllerHandle Handle of device to stop the driver on.
225 @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If the number
226 of children is zero stop the entire bus driver.
227 @param[in] ChildHandleBuffer List of Child Handles to Stop. It is optional.
229 @retval EFI_SUCCESS This driver is removed ControllerHandle.
230 @retval EFI_DEVICE_ERROR Can't find the NicHandle from the ControllerHandle and specified GUID.
231 @retval other This driver was not removed from this device.
236 Udp6DriverBindingStop (
237 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
238 IN EFI_HANDLE ControllerHandle
,
239 IN UINTN NumberOfChildren
,
240 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL
244 EFI_HANDLE NicHandle
;
245 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
246 UDP6_SERVICE_DATA
*Udp6Service
;
248 UDP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT Context
;
251 // Find the NicHandle where UDP6 ServiceBinding Protocol is installed.
253 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiIp6ProtocolGuid
);
254 if (NicHandle
== NULL
) {
259 // Retrieve the UDP6 ServiceBinding Protocol.
261 Status
= gBS
->OpenProtocol (
263 &gEfiUdp6ServiceBindingProtocolGuid
,
264 (VOID
**)&ServiceBinding
,
265 This
->DriverBindingHandle
,
267 EFI_OPEN_PROTOCOL_GET_PROTOCOL
269 if (EFI_ERROR (Status
)) {
270 return EFI_DEVICE_ERROR
;
273 Udp6Service
= UDP6_SERVICE_DATA_FROM_THIS (ServiceBinding
);
275 if (NumberOfChildren
!= 0) {
277 // NumberOfChildren is not zero, destroy the children instances in ChildHandleBuffer.
279 List
= &Udp6Service
->ChildrenList
;
280 Context
.ServiceBinding
= ServiceBinding
;
281 Context
.NumberOfChildren
= NumberOfChildren
;
282 Context
.ChildHandleBuffer
= ChildHandleBuffer
;
283 Status
= NetDestroyLinkList (
285 Udp6DestroyChildEntryInHandleBuffer
,
289 } else if (IsListEmpty (&Udp6Service
->ChildrenList
)) {
290 Status
= gBS
->UninstallMultipleProtocolInterfaces (
292 &gEfiUdp6ServiceBindingProtocolGuid
,
293 &Udp6Service
->ServiceBinding
,
297 Udp6CleanService (Udp6Service
);
298 FreePool (Udp6Service
);
305 Creates a child handle and installs a protocol.
307 The CreateChild() function installs a protocol on ChildHandle.
308 If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle.
309 If ChildHandle is not a pointer to NULL, then the protocol installs on the existing ChildHandle.
311 @param[in] This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
312 @param[in, out] ChildHandle Pointer to the handle of the child to create. If it is NULL,
313 then a new handle is created. If it is a pointer to an existing UEFI handle,
314 then the protocol is added to the existing UEFI handle.
316 @retval EFI_SUCCESS The protocol was added to ChildHandle.
317 @retval EFI_INVALID_PARAMETER This is NULL or ChildHandle is NULL.
318 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to create
320 @retval other The child handle was not created.
325 Udp6ServiceBindingCreateChild (
326 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
327 IN OUT EFI_HANDLE
*ChildHandle
331 UDP6_SERVICE_DATA
*Udp6Service
;
332 UDP6_INSTANCE_DATA
*Instance
;
336 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
337 return EFI_INVALID_PARAMETER
;
340 Udp6Service
= UDP6_SERVICE_DATA_FROM_THIS (This
);
343 // Allocate the instance private data structure.
345 Instance
= AllocateZeroPool (sizeof (UDP6_INSTANCE_DATA
));
346 if (Instance
== NULL
) {
347 return EFI_OUT_OF_RESOURCES
;
350 Udp6InitInstance (Udp6Service
, Instance
);
353 // Add an IpInfo for this instance.
355 Instance
->IpInfo
= IpIoAddIp (Udp6Service
->IpIo
);
356 if (Instance
->IpInfo
== NULL
) {
357 Status
= EFI_OUT_OF_RESOURCES
;
362 // Install the Udp6Protocol for this instance.
364 Status
= gBS
->InstallMultipleProtocolInterfaces (
366 &gEfiUdp6ProtocolGuid
,
367 &Instance
->Udp6Proto
,
370 if (EFI_ERROR (Status
)) {
374 Instance
->ChildHandle
= *ChildHandle
;
377 // Open the default Ip6 protocol in the IP_IO BY_CHILD.
379 Status
= gBS
->OpenProtocol (
380 Udp6Service
->IpIo
->ChildHandle
,
381 &gEfiIp6ProtocolGuid
,
383 gUdp6DriverBinding
.DriverBindingHandle
,
384 Instance
->ChildHandle
,
385 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
387 if (EFI_ERROR (Status
)) {
392 // Open this instance's Ip6 protocol in the IpInfo BY_CHILD.
394 Status
= gBS
->OpenProtocol (
395 Instance
->IpInfo
->ChildHandle
,
396 &gEfiIp6ProtocolGuid
,
398 gUdp6DriverBinding
.DriverBindingHandle
,
399 Instance
->ChildHandle
,
400 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
402 if (EFI_ERROR (Status
)) {
406 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
409 // Link this instance into the service context data and increase the ChildrenNumber.
411 InsertTailList (&Udp6Service
->ChildrenList
, &Instance
->Link
);
412 Udp6Service
->ChildrenNumber
++;
414 gBS
->RestoreTPL (OldTpl
);
420 if (Instance
->ChildHandle
!= NULL
) {
421 gBS
->UninstallMultipleProtocolInterfaces (
422 Instance
->ChildHandle
,
423 &gEfiUdp6ProtocolGuid
,
424 &Instance
->Udp6Proto
,
429 if (Instance
->IpInfo
!= NULL
) {
430 IpIoRemoveIp (Udp6Service
->IpIo
, Instance
->IpInfo
);
433 Udp6CleanInstance (Instance
);
441 Destroys a child handle with a set of I/O services.
442 The DestroyChild() function does the opposite of CreateChild(). It removes a protocol
443 that was installed by CreateChild() from ChildHandle. If the removed protocol is the
444 last protocol on ChildHandle, then ChildHandle is destroyed.
446 @param[in] This Protocol instance pointer.
447 @param[in] ChildHandle Handle of the child to destroy.
449 @retval EFI_SUCCESS The I/O services were removed from the child
451 @retval EFI_UNSUPPORTED The child handle does not support the I/O services
452 that are being removed.
453 @retval EFI_INVALID_PARAMETER Child handle is NULL.
454 @retval EFI_ACCESS_DENIED The child handle could not be destroyed because
455 its I/O services are being used.
456 @retval other The child handle was not destroyed.
461 Udp6ServiceBindingDestroyChild (
462 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
463 IN EFI_HANDLE ChildHandle
467 UDP6_SERVICE_DATA
*Udp6Service
;
468 EFI_UDP6_PROTOCOL
*Udp6Proto
;
469 UDP6_INSTANCE_DATA
*Instance
;
472 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
473 return EFI_INVALID_PARAMETER
;
476 Udp6Service
= UDP6_SERVICE_DATA_FROM_THIS (This
);
479 // Try to get the Udp6 protocol from the ChildHandle.
481 Status
= gBS
->OpenProtocol (
483 &gEfiUdp6ProtocolGuid
,
485 gUdp6DriverBinding
.DriverBindingHandle
,
487 EFI_OPEN_PROTOCOL_GET_PROTOCOL
489 if (EFI_ERROR (Status
)) {
490 return EFI_UNSUPPORTED
;
493 Instance
= UDP6_INSTANCE_DATA_FROM_THIS (Udp6Proto
);
495 if (Instance
->InDestroy
) {
500 // Use the Destroyed flag to avoid the re-entering of the following code.
502 Instance
->InDestroy
= TRUE
;
505 // Close the Ip6 protocol on the default IpIo.
507 Status
= gBS
->CloseProtocol (
508 Udp6Service
->IpIo
->ChildHandle
,
509 &gEfiIp6ProtocolGuid
,
510 gUdp6DriverBinding
.DriverBindingHandle
,
511 Instance
->ChildHandle
513 if (EFI_ERROR (Status
)) {
514 Instance
->InDestroy
= FALSE
;
519 // Close the Ip6 protocol on this instance's IpInfo.
521 Status
= gBS
->CloseProtocol (
522 Instance
->IpInfo
->ChildHandle
,
523 &gEfiIp6ProtocolGuid
,
524 gUdp6DriverBinding
.DriverBindingHandle
,
525 Instance
->ChildHandle
527 if (EFI_ERROR (Status
)) {
528 Instance
->InDestroy
= FALSE
;
533 // Uninstall the Udp6Protocol previously installed on the ChildHandle.
535 Status
= gBS
->UninstallMultipleProtocolInterfaces (
537 &gEfiUdp6ProtocolGuid
,
538 (VOID
*)&Instance
->Udp6Proto
,
541 if (EFI_ERROR (Status
)) {
542 Instance
->InDestroy
= FALSE
;
547 // Reset the configuration in case the instance's consumer forgets to do this.
549 Udp6Proto
->Configure (Udp6Proto
, NULL
);
552 // Remove the IpInfo this instance consumes.
554 IpIoRemoveIp (Udp6Service
->IpIo
, Instance
->IpInfo
);
556 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
559 // Remove this instance from the service context data's ChildrenList.
561 RemoveEntryList (&Instance
->Link
);
562 Udp6Service
->ChildrenNumber
--;
565 // Clean the instance.
567 Udp6CleanInstance (Instance
);
569 gBS
->RestoreTPL (OldTpl
);
577 This is the declaration of an EFI image entry point. This entry point is
578 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers, including
579 both device drivers and bus drivers.
581 The entry point for Udp6 driver that installs the driver binding
582 and component name protocol on its ImageHandle.
584 @param[in] ImageHandle The firmware allocated handle for the UEFI image.
585 @param[in] SystemTable A pointer to the EFI System Table.
587 @retval EFI_SUCCESS The operation completed successfully.
588 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
593 Udp6DriverEntryPoint (
594 IN EFI_HANDLE ImageHandle
,
595 IN EFI_SYSTEM_TABLE
*SystemTable
601 // Install the Udp6DriverBinding and Udp6ComponentName protocols.
604 Status
= EfiLibInstallDriverBindingComponentName2 (
612 if (!EFI_ERROR (Status
)) {
614 // Initialize the UDP random port.
616 mUdp6RandomPort
= (UINT16
)(
617 ((UINT16
)NetRandomInitSeed ()) %