2 The driver binding and service binding protocol for IP4 driver.
4 Copyright (c) 2005 - 2006, Intel Corporation.<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 EFI_DRIVER_BINDING_PROTOCOL gIp4DriverBinding
= {
18 Ip4DriverBindingSupported
,
19 Ip4DriverBindingStart
,
27 This is the declaration of an EFI image entry point. This entry point is
28 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
29 both device drivers and bus drivers.
31 The entry point for IP4 driver which install the driver
32 binding and component name protocol on its image.
34 @param[in] ImageHandle The firmware allocated handle for the UEFI image.
35 @param[in] SystemTable A pointer to the EFI System Table.
37 @retval EFI_SUCCESS The operation completed successfully.
38 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
44 IN EFI_HANDLE ImageHandle
,
45 IN EFI_SYSTEM_TABLE
*SystemTable
48 return EfiLibInstallDriverBindingComponentName2 (
59 Test to see if this driver supports ControllerHandle. This service
60 is called by the EFI boot service ConnectController(). In
61 order to make drivers as small as possible, there are a few calling
62 restrictions for this service. ConnectController() must
63 follow these calling restrictions. If any other agent wishes to call
64 Supported() it must also follow these calling restrictions.
66 @param[in] This Protocol instance pointer.
67 @param[in] ControllerHandle Handle of device to test
68 @param[in] RemainingDevicePath Optional parameter use to pick a specific child
71 @retval EFI_SUCCESS This driver supports this device
72 @retval EFI_ALREADY_STARTED This driver is already running on this device
73 @retval other This driver does not support this device
78 Ip4DriverBindingSupported (
79 IN EFI_DRIVER_BINDING_PROTOCOL
* This
,
80 IN EFI_HANDLE ControllerHandle
,
81 IN EFI_DEVICE_PATH_PROTOCOL
* RemainingDevicePath OPTIONAL
87 // Test for the MNP service binding Protocol
89 Status
= gBS
->OpenProtocol (
91 &gEfiManagedNetworkServiceBindingProtocolGuid
,
93 This
->DriverBindingHandle
,
95 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
98 if (EFI_ERROR (Status
)) {
103 // Test for the Arp service binding Protocol
105 Status
= gBS
->OpenProtocol (
107 &gEfiArpServiceBindingProtocolGuid
,
109 This
->DriverBindingHandle
,
111 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
118 Clean up a IP4 service binding instance. It will release all
119 the resource allocated by the instance. The instance may be
120 partly initialized, or partly destroyed. If a resource is
121 destroyed, it is marked as that in case the destory failed and
122 being called again later.
124 @param[in] IpSb The IP4 serviceing binding instance to clean up
126 @retval EFI_SUCCESS The resource used by the instance are cleaned up
127 @retval other Failed to clean up some of the resources.
137 Create a new IP4 driver service binding private instance.
139 @param Controller The controller that has MNP service binding
141 @param ImageHandle The IP4 driver's image handle
142 @param Service The variable to receive the newly created IP4
145 @retval EFI_OUT_OF_RESOURCES Failed to allocate some resource
146 @retval EFI_SUCCESS A new IP4 service binding private is created.
147 @retval other Other error occurs.
152 IN EFI_HANDLE Controller
,
153 IN EFI_HANDLE ImageHandle
,
154 OUT IP4_SERVICE
**Service
160 ASSERT (Service
!= NULL
);
165 // allocate a service private data then initialize all the filed to
166 // empty resources, so if any thing goes wrong when allocating
167 // resources, Ip4CleanService can be called to clean it up.
169 IpSb
= AllocatePool (sizeof (IP4_SERVICE
));
172 return EFI_OUT_OF_RESOURCES
;
175 IpSb
->Signature
= IP4_SERVICE_SIGNATURE
;
176 IpSb
->ServiceBinding
.CreateChild
= Ip4ServiceBindingCreateChild
;
177 IpSb
->ServiceBinding
.DestroyChild
= Ip4ServiceBindingDestroyChild
;
178 IpSb
->State
= IP4_SERVICE_UNSTARTED
;
179 IpSb
->InDestory
= FALSE
;
181 IpSb
->NumChildren
= 0;
182 InitializeListHead (&IpSb
->Children
);
184 InitializeListHead (&IpSb
->Interfaces
);
185 IpSb
->DefaultInterface
= NULL
;
186 IpSb
->DefaultRouteTable
= NULL
;
188 Ip4InitAssembleTable (&IpSb
->Assemble
);
190 IpSb
->IgmpCtrl
.Igmpv1QuerySeen
= 0;
191 InitializeListHead (&IpSb
->IgmpCtrl
.Groups
);
193 IpSb
->Image
= ImageHandle
;
194 IpSb
->Controller
= Controller
;
196 IpSb
->MnpChildHandle
= NULL
;
199 IpSb
->MnpConfigData
.ReceivedQueueTimeoutValue
= 0;
200 IpSb
->MnpConfigData
.TransmitQueueTimeoutValue
= 0;
201 IpSb
->MnpConfigData
.ProtocolTypeFilter
= IP4_ETHER_PROTO
;
202 IpSb
->MnpConfigData
.EnableUnicastReceive
= TRUE
;
203 IpSb
->MnpConfigData
.EnableMulticastReceive
= TRUE
;
204 IpSb
->MnpConfigData
.EnableBroadcastReceive
= TRUE
;
205 IpSb
->MnpConfigData
.EnablePromiscuousReceive
= FALSE
;
206 IpSb
->MnpConfigData
.FlushQueuesOnReset
= TRUE
;
207 IpSb
->MnpConfigData
.EnableReceiveTimestamps
= FALSE
;
208 IpSb
->MnpConfigData
.DisableBackgroundPolling
= FALSE
;
210 ZeroMem (&IpSb
->SnpMode
, sizeof (EFI_SIMPLE_NETWORK_MODE
));
213 IpSb
->Ip4Config
= NULL
;
214 IpSb
->DoneEvent
= NULL
;
215 IpSb
->ReconfigEvent
= NULL
;
216 IpSb
->ActiveEvent
= NULL
;
219 // Create various resources. First create the route table, timer
220 // event and MNP child. IGMP, interface's initialization depend
223 IpSb
->DefaultRouteTable
= Ip4CreateRouteTable ();
225 if (IpSb
->DefaultRouteTable
== NULL
) {
226 Status
= EFI_OUT_OF_RESOURCES
;
230 Status
= gBS
->CreateEvent (
231 EVT_NOTIFY_SIGNAL
| EVT_TIMER
,
238 if (EFI_ERROR (Status
)) {
242 Status
= NetLibCreateServiceChild (
245 &gEfiManagedNetworkServiceBindingProtocolGuid
,
246 &IpSb
->MnpChildHandle
249 if (EFI_ERROR (Status
)) {
253 Status
= gBS
->OpenProtocol (
254 IpSb
->MnpChildHandle
,
255 &gEfiManagedNetworkProtocolGuid
,
256 (VOID
**) &IpSb
->Mnp
,
259 EFI_OPEN_PROTOCOL_BY_DRIVER
262 if (EFI_ERROR (Status
)) {
266 Status
= Ip4ServiceConfigMnp (IpSb
, TRUE
);
268 if (EFI_ERROR (Status
)) {
272 Status
= IpSb
->Mnp
->GetModeData (IpSb
->Mnp
, NULL
, &IpSb
->SnpMode
);
274 if (EFI_ERROR (Status
)) {
278 Status
= Ip4InitIgmp (IpSb
);
280 if (EFI_ERROR (Status
)) {
284 IpSb
->DefaultInterface
= Ip4CreateInterface (IpSb
->Mnp
, Controller
, ImageHandle
);
286 if (IpSb
->DefaultInterface
== NULL
) {
287 Status
= EFI_OUT_OF_RESOURCES
;
291 InsertHeadList (&IpSb
->Interfaces
, &IpSb
->DefaultInterface
->Link
);
293 IpSb
->MacString
= NULL
;
299 Ip4CleanService (IpSb
);
300 gBS
->FreePool (IpSb
);
307 Clean up a IP4 service binding instance. It will release all
308 the resource allocated by the instance. The instance may be
309 partly initialized, or partly destroyed. If a resource is
310 destroyed, it is marked as that in case the destory failed and
311 being called again later.
313 @param[in] IpSb The IP4 serviceing binding instance to clean up
315 @retval EFI_SUCCESS The resource used by the instance are cleaned up
316 @retval other Failed to clean up some of the resources.
326 if (IpSb
->DefaultInterface
!= NULL
) {
327 Status
= Ip4FreeInterface (IpSb
->DefaultInterface
, NULL
);
329 if (EFI_ERROR (Status
)) {
333 IpSb
->DefaultInterface
= NULL
;
336 if (IpSb
->DefaultRouteTable
!= NULL
) {
337 Ip4FreeRouteTable (IpSb
->DefaultRouteTable
);
338 IpSb
->DefaultRouteTable
= NULL
;
341 Ip4CleanAssembleTable (&IpSb
->Assemble
);
343 if (IpSb
->MnpChildHandle
!= NULL
) {
344 if (IpSb
->Mnp
!= NULL
) {
346 IpSb
->MnpChildHandle
,
347 &gEfiManagedNetworkProtocolGuid
,
355 NetLibDestroyServiceChild (
358 &gEfiManagedNetworkServiceBindingProtocolGuid
,
362 IpSb
->MnpChildHandle
= NULL
;
365 if (IpSb
->Timer
!= NULL
) {
366 gBS
->SetTimer (IpSb
->Timer
, TimerCancel
, 0);
367 gBS
->CloseEvent (IpSb
->Timer
);
372 if (IpSb
->Ip4Config
!= NULL
) {
373 IpSb
->Ip4Config
->Stop (IpSb
->Ip4Config
);
377 &gEfiIp4ConfigProtocolGuid
,
382 gBS
->CloseEvent (IpSb
->DoneEvent
);
383 gBS
->CloseEvent (IpSb
->ReconfigEvent
);
384 IpSb
->ActiveEvent
= NULL
;
385 IpSb
->Ip4Config
= NULL
;
393 Start this driver on ControllerHandle. This service is called by the
394 EFI boot service ConnectController(). In order to make
395 drivers as small as possible, there are a few calling restrictions for
396 this service. ConnectController() must follow these
397 calling restrictions. If any other agent wishes to call Start() it
398 must also follow these calling restrictions.
400 @param[in] This Protocol instance pointer.
401 @param[in] ControllerHandle Handle of device to bind driver to
402 @param[in] RemainingDevicePath Optional parameter use to pick a specific child
405 @retval EFI_SUCCESS This driver is added to ControllerHandle
406 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
407 @retval other This driver does not support this device
412 Ip4DriverBindingStart (
413 IN EFI_DRIVER_BINDING_PROTOCOL
* This
,
414 IN EFI_HANDLE ControllerHandle
,
415 IN EFI_DEVICE_PATH_PROTOCOL
* RemainingDevicePath OPTIONAL
422 // Test for the Ip4 service binding protocol
424 Status
= gBS
->OpenProtocol (
426 &gEfiIp4ServiceBindingProtocolGuid
,
428 This
->DriverBindingHandle
,
430 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
433 if (Status
== EFI_SUCCESS
) {
434 return EFI_ALREADY_STARTED
;
437 Status
= Ip4CreateService (ControllerHandle
, This
->DriverBindingHandle
, &IpSb
);
439 if (EFI_ERROR (Status
)) {
444 // Install the Ip4ServiceBinding Protocol onto ControlerHandle
446 Status
= gBS
->InstallMultipleProtocolInterfaces (
448 &gEfiIp4ServiceBindingProtocolGuid
,
449 &IpSb
->ServiceBinding
,
453 if (EFI_ERROR (Status
)) {
458 // ready to go: start the receiving and timer
460 Status
= Ip4ReceiveFrame (IpSb
->DefaultInterface
, NULL
, Ip4AccpetFrame
, IpSb
);
462 if (EFI_ERROR (Status
)) {
463 goto UNINSTALL_PROTOCOL
;
466 Status
= gBS
->SetTimer (IpSb
->Timer
, TimerPeriodic
, TICKS_PER_SECOND
);
468 if (EFI_ERROR (Status
)) {
469 goto UNINSTALL_PROTOCOL
;
473 // Initialize the IP4 ID
475 mIp4Id
= (UINT16
)NET_RANDOM (NetRandomInitSeed ());
477 Ip4SetVariableData (IpSb
);
482 gBS
->UninstallProtocolInterface (
484 &gEfiIp4ServiceBindingProtocolGuid
,
485 &IpSb
->ServiceBinding
489 Ip4CleanService (IpSb
);
490 gBS
->FreePool (IpSb
);
497 Stop this driver on ControllerHandle. This service is called by the
498 EFI boot service DisconnectController(). In order to
499 make drivers as small as possible, there are a few calling
500 restrictions for this service. DisconnectController()
501 must follow these calling restrictions. If any other agent wishes
502 to call Stop() it must also follow these calling restrictions.
504 @param[in] This Protocol instance pointer.
505 @param[in] ControllerHandle Handle of device to stop driver on
506 @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If number
507 of children is zero stop the entire bus driver.
508 @param[in] ChildHandleBuffer List of Child Handles to Stop.
510 @retval EFI_SUCCESS This driver is removed ControllerHandle
511 @retval other This driver was not removed from this device
516 Ip4DriverBindingStop (
517 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
518 IN EFI_HANDLE ControllerHandle
,
519 IN UINTN NumberOfChildren
,
520 IN EFI_HANDLE
*ChildHandleBuffer
523 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
525 IP4_PROTOCOL
*IpInstance
;
526 EFI_HANDLE NicHandle
;
533 // IP4 driver opens the MNP child, ARP children or the IP4_CONFIG protocol
534 // by driver. So the ControllerHandle may be the MNP child handle, ARP child
535 // handle, or the NIC (UNDI) handle because IP4_CONFIG protocol is installed
536 // in the NIC handle.
539 // First, check whether it is the IP4_CONFIG protocol being uninstalled.
540 // IP4_CONFIG protocol is installed on the NIC handle. It isn't necessary
541 // to clean up the default configuration if IP4_CONFIG is being stopped.
543 Status
= gBS
->OpenProtocol (
545 &gEfiIp4ConfigProtocolGuid
,
547 This
->DriverBindingHandle
,
549 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
552 if (Status
== EFI_SUCCESS
) {
554 // Retrieve the IP4 service binding protocol. If failed, it is
555 // likely that Ip4 ServiceBinding is uninstalled already. In this
556 // case, return immediately.
558 Status
= gBS
->OpenProtocol (
560 &gEfiIp4ServiceBindingProtocolGuid
,
561 (VOID
**) &ServiceBinding
,
562 This
->DriverBindingHandle
,
564 EFI_OPEN_PROTOCOL_GET_PROTOCOL
567 if (EFI_ERROR (Status
)) {
568 return EFI_DEVICE_ERROR
;
571 IpSb
= IP4_SERVICE_FROM_PROTOCOL (ServiceBinding
);
573 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
575 if (IpSb
->Ip4Config
!= NULL
&& (IpSb
->State
!= IP4_SERVICE_DESTORY
)) {
577 IpSb
->Ip4Config
->Stop (IpSb
->Ip4Config
);
579 Status
= gBS
->CloseProtocol (
581 &gEfiIp4ConfigProtocolGuid
,
586 if (EFI_ERROR (Status
)) {
587 gBS
->RestoreTPL (OldTpl
);
592 // If the auto configure hasn't complete, mark it as not started.
594 if (IpSb
->State
== IP4_SERVICE_STARTED
) {
595 IpSb
->State
= IP4_SERVICE_UNSTARTED
;
598 IpSb
->Ip4Config
= NULL
;
599 gBS
->CloseEvent (IpSb
->DoneEvent
);
600 gBS
->CloseEvent (IpSb
->ReconfigEvent
);
603 gBS
->RestoreTPL (OldTpl
);
608 // Either MNP or ARP protocol is being uninstalled. The controller
609 // handle is either the MNP child or ARP child. But, the IP4's
610 // service binding is installed on the NIC handle. So, need to open
611 // the protocol info to find the NIC handle.
614 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiManagedNetworkProtocolGuid
);
616 if (NicHandle
== NULL
) {
617 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiArpProtocolGuid
);
621 if (NicHandle
== NULL
) {
622 return EFI_DEVICE_ERROR
;
626 // Retrieve the IP4 service binding protocol
628 Status
= gBS
->OpenProtocol (
630 &gEfiIp4ServiceBindingProtocolGuid
,
631 (VOID
**) &ServiceBinding
,
632 This
->DriverBindingHandle
,
634 EFI_OPEN_PROTOCOL_GET_PROTOCOL
637 if (EFI_ERROR (Status
)) {
638 return EFI_DEVICE_ERROR
;
641 IpSb
= IP4_SERVICE_FROM_PROTOCOL (ServiceBinding
);
643 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
645 if (IpSb
->InDestory
) {
646 gBS
->RestoreTPL (OldTpl
);
651 while (!IsListEmpty (&IpSb
->Children
)) {
652 IpInstance
= NET_LIST_HEAD (&IpSb
->Children
, IP4_PROTOCOL
, Link
);
654 ServiceBinding
->DestroyChild (ServiceBinding
, IpInstance
->Handle
);
657 if (IpSb
->NumChildren
!= 0) {
658 Status
= EFI_DEVICE_ERROR
;
662 IpSb
->InDestory
= TRUE
;
665 IpSb
->State
= IP4_SERVICE_DESTORY
;
668 // Clear the variable data.
670 Ip4ClearVariableData (IpSb
);
673 // OK, clean other resources then uninstall the service binding protocol.
675 Status
= Ip4CleanService (IpSb
);
677 if (EFI_ERROR (Status
)) {
682 gBS
->UninstallProtocolInterface (
684 &gEfiIp4ServiceBindingProtocolGuid
,
688 gBS
->FreePool (IpSb
);
689 } else if (NumberOfChildren
== 0) {
690 IpSb
->InDestory
= TRUE
;
693 IpSb
->State
= IP4_SERVICE_DESTORY
;
696 // Clear the variable data.
698 Ip4ClearVariableData (IpSb
);
701 // OK, clean other resources then uninstall the service binding protocol.
703 Status
= Ip4CleanService (IpSb
);
705 if (EFI_ERROR (Status
)) {
710 gBS
->UninstallProtocolInterface (
712 &gEfiIp4ServiceBindingProtocolGuid
,
716 gBS
->FreePool (IpSb
);
719 while (!IsListEmpty (&IpSb
->Children
)) {
720 IpInstance
= NET_LIST_HEAD (&IpSb
->Children
, IP4_PROTOCOL
, Link
);
722 ServiceBinding
->DestroyChild (ServiceBinding
, IpInstance
->Handle
);
725 if (IpSb
->NumChildren
!= 0) {
726 Status
= EFI_DEVICE_ERROR
;
732 gBS
->RestoreTPL (OldTpl
);
738 Creates a child handle and installs a protocol.
740 The CreateChild() function installs a protocol on ChildHandle.
741 If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle.
742 If ChildHandle is not a pointer to NULL, then the protocol installs on the existing ChildHandle.
744 @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
745 @param ChildHandle Pointer to the handle of the child to create. If it is NULL,
746 then a new handle is created. If it is a pointer to an existing UEFI handle,
747 then the protocol is added to the existing UEFI handle.
749 @retval EFI_SUCCES The protocol was added to ChildHandle.
750 @retval EFI_INVALID_PARAMETER ChildHandle is NULL.
751 @retval EFI_OUT_OF_RESOURCES There are not enough resources availabe to create
753 @retval other The child handle was not created
758 Ip4ServiceBindingCreateChild (
759 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
760 IN OUT EFI_HANDLE
*ChildHandle
764 IP4_PROTOCOL
*IpInstance
;
769 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
770 return EFI_INVALID_PARAMETER
;
773 IpSb
= IP4_SERVICE_FROM_PROTOCOL (This
);
774 IpInstance
= AllocatePool (sizeof (IP4_PROTOCOL
));
776 if (IpInstance
== NULL
) {
777 return EFI_OUT_OF_RESOURCES
;
780 Ip4InitProtocol (IpSb
, IpInstance
);
783 // Install Ip4 onto ChildHandle
785 Status
= gBS
->InstallMultipleProtocolInterfaces (
787 &gEfiIp4ProtocolGuid
,
788 &IpInstance
->Ip4Proto
,
792 if (EFI_ERROR (Status
)) {
796 IpInstance
->Handle
= *ChildHandle
;
799 // Open the Managed Network protocol BY_CHILD.
801 Status
= gBS
->OpenProtocol (
802 IpSb
->MnpChildHandle
,
803 &gEfiManagedNetworkProtocolGuid
,
805 gIp4DriverBinding
.DriverBindingHandle
,
807 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
809 if (EFI_ERROR (Status
)) {
810 gBS
->UninstallMultipleProtocolInterfaces (
812 &gEfiIp4ProtocolGuid
,
813 &IpInstance
->Ip4Proto
,
821 // Insert it into the service binding instance.
823 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
825 InsertTailList (&IpSb
->Children
, &IpInstance
->Link
);
828 gBS
->RestoreTPL (OldTpl
);
832 if (EFI_ERROR (Status
)) {
834 Ip4CleanProtocol (IpInstance
);
836 gBS
->FreePool (IpInstance
);
844 Destroys a child handle with a protocol installed on it.
846 The DestroyChild() function does the opposite of CreateChild(). It removes a protocol
847 that was installed by CreateChild() from ChildHandle. If the removed protocol is the
848 last protocol on ChildHandle, then ChildHandle is destroyed.
850 @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
851 @param ChildHandle Handle of the child to destroy
853 @retval EFI_SUCCES The protocol was removed from ChildHandle.
854 @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.
855 @retval EFI_INVALID_PARAMETER Child handle is not a valid UEFI Handle.
856 @retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle
857 because its services are being used.
858 @retval other The child handle was not destroyed
863 Ip4ServiceBindingDestroyChild (
864 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
865 IN EFI_HANDLE ChildHandle
870 IP4_PROTOCOL
*IpInstance
;
871 EFI_IP4_PROTOCOL
*Ip4
;
875 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
876 return EFI_INVALID_PARAMETER
;
880 // Retrieve the private context data structures
882 IpSb
= IP4_SERVICE_FROM_PROTOCOL (This
);
884 Status
= gBS
->OpenProtocol (
886 &gEfiIp4ProtocolGuid
,
888 gIp4DriverBinding
.DriverBindingHandle
,
890 EFI_OPEN_PROTOCOL_GET_PROTOCOL
893 if (EFI_ERROR (Status
)) {
894 return EFI_UNSUPPORTED
;
897 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (Ip4
);
899 if (IpInstance
->Service
!= IpSb
) {
900 return EFI_INVALID_PARAMETER
;
903 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
906 // A child can be destoried more than once. For example,
907 // Ip4DriverBindingStop will destory all of its children.
908 // when UDP driver is being stopped, it will destory all
909 // the IP child it opens.
911 if (IpInstance
->State
== IP4_STATE_DESTORY
) {
912 gBS
->RestoreTPL (OldTpl
);
916 State
= IpInstance
->State
;
917 IpInstance
->State
= IP4_STATE_DESTORY
;
920 // Close the Managed Network protocol.
923 IpSb
->MnpChildHandle
,
924 &gEfiManagedNetworkProtocolGuid
,
925 gIp4DriverBinding
.DriverBindingHandle
,
930 // Uninstall the IP4 protocol first. Many thing happens during
932 // 1. The consumer of the IP4 protocol will be stopped if it
933 // opens the protocol BY_DRIVER. For eaxmple, if MNP driver is
934 // stopped, IP driver's stop function will be called, and uninstall
935 // EFI_IP4_PROTOCOL will trigger the UDP's stop function. This
936 // makes it possible to create the network stack bottom up, and
938 // 2. the upper layer will recycle the received packet. The recycle
939 // event's TPL is higher than this function. The recycle events
940 // will be called back before preceeding. If any packets not recycled,
941 // that means there is a resource leak.
943 Status
= gBS
->UninstallProtocolInterface (
945 &gEfiIp4ProtocolGuid
,
946 &IpInstance
->Ip4Proto
949 if (EFI_ERROR (Status
)) {
953 Status
= Ip4CleanProtocol (IpInstance
);
955 Ip4SetVariableData (IpSb
);
957 if (EFI_ERROR (Status
)) {
958 gBS
->InstallMultipleProtocolInterfaces (
960 &gEfiIp4ProtocolGuid
,
968 RemoveEntryList (&IpInstance
->Link
);
971 gBS
->RestoreTPL (OldTpl
);
973 gBS
->FreePool (IpInstance
);
977 IpInstance
->State
= State
;
978 gBS
->RestoreTPL (OldTpl
);