]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/Mtftp6Dxe/Mtftp6Driver.c
NetworkPkg: comments clean up.
[mirror_edk2.git] / NetworkPkg / Mtftp6Dxe / Mtftp6Driver.c
CommitLineData
a3bcde70
HT
1/** @file\r
2 Driver Binding functions and Service Binding functions\r
3 implementation for Mtftp6 Driver.\r
4\r
76389e18 5 Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
a3bcde70
HT
6\r
7 This program and the accompanying materials\r
8 are licensed and made available under the terms and conditions of the BSD License\r
9 which accompanies this distribution. The full text of the license may be found at\r
10 http://opensource.org/licenses/bsd-license.php.\r
11\r
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15**/\r
16\r
17#include "Mtftp6Impl.h"\r
18\r
19\r
20EFI_DRIVER_BINDING_PROTOCOL gMtftp6DriverBinding = {\r
21 Mtftp6DriverBindingSupported,\r
22 Mtftp6DriverBindingStart,\r
23 Mtftp6DriverBindingStop,\r
24 0xa,\r
25 NULL,\r
26 NULL\r
27};\r
28\r
29EFI_SERVICE_BINDING_PROTOCOL gMtftp6ServiceBindingTemplate = {\r
30 Mtftp6ServiceBindingCreateChild,\r
31 Mtftp6ServiceBindingDestroyChild\r
32};\r
33\r
34\r
35/**\r
36 Destory the MTFTP6 service. The MTFTP6 service may be partly initialized,\r
37 or partly destroyed. If a resource is destroyed, it is marked as such in\r
38 case the destroy failed and is called again later.\r
39\r
40 @param[in] Service The MTFTP6 service to be destroyed.\r
41\r
42**/\r
43VOID\r
44Mtftp6DestroyService (\r
45 IN MTFTP6_SERVICE *Service\r
46 )\r
47{\r
48 //\r
49 // Make sure all children instances have been already destoryed.\r
50 //\r
51 ASSERT (Service->ChildrenNum == 0);\r
52\r
53 if (Service->DummyUdpIo != NULL) {\r
54 UdpIoFreeIo (Service->DummyUdpIo);\r
55 }\r
56\r
57 if (Service->Timer != NULL) {\r
58 gBS->CloseEvent (Service->Timer);\r
59 }\r
60\r
61 FreePool (Service);\r
62}\r
63\r
64\r
65/**\r
66 Create then initialize a MTFTP6 service binding instance.\r
67\r
68 @param[in] Controller The controller to install the MTFTP6 service\r
69 binding on.\r
70 @param[in] Image The driver binding image of the MTFTP6 driver.\r
71 @param[out] Service The variable to receive the created service\r
72 binding instance.\r
73\r
74 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources to create the instance\r
75 @retval EFI_DEVICE_ERROR Failed to create a NULL UDP port to keep connection with UDP.\r
76 @retval EFI_SUCCESS The service instance is created for the controller.\r
77\r
78**/\r
79EFI_STATUS\r
80Mtftp6CreateService (\r
81 IN EFI_HANDLE Controller,\r
82 IN EFI_HANDLE Image,\r
83 OUT MTFTP6_SERVICE **Service\r
84 )\r
85{\r
86 MTFTP6_SERVICE *Mtftp6Srv;\r
87 EFI_STATUS Status;\r
88\r
89 ASSERT (Service != NULL);\r
90\r
91 *Service = NULL;\r
92 Mtftp6Srv = AllocateZeroPool (sizeof (MTFTP6_SERVICE));\r
93\r
94 if (Mtftp6Srv == NULL) {\r
95 return EFI_OUT_OF_RESOURCES;\r
96 }\r
97\r
98 Mtftp6Srv->Signature = MTFTP6_SERVICE_SIGNATURE;\r
99 Mtftp6Srv->Controller = Controller;\r
100 Mtftp6Srv->Image = Image;\r
101 Mtftp6Srv->InDestory = FALSE;\r
102 Mtftp6Srv->ChildrenNum = 0;\r
103\r
104 CopyMem (\r
105 &Mtftp6Srv->ServiceBinding,\r
106 &gMtftp6ServiceBindingTemplate,\r
107 sizeof (EFI_SERVICE_BINDING_PROTOCOL)\r
108 );\r
109\r
110 InitializeListHead (&Mtftp6Srv->Children);\r
111\r
112 //\r
113 // Create a internal timer for all instances.\r
114 //\r
115 Status = gBS->CreateEvent (\r
116 EVT_NOTIFY_SIGNAL | EVT_TIMER,\r
117 TPL_CALLBACK,\r
118 Mtftp6OnTimerTick,\r
119 Mtftp6Srv,\r
120 &Mtftp6Srv->Timer\r
121 );\r
122\r
123 if (EFI_ERROR (Status)) {\r
124 FreePool (Mtftp6Srv);\r
125 return Status;\r
126 }\r
127\r
128 //\r
129 // Create a dummy Udp6Io to build parent-child relationship between Udp6 driver\r
130 // and Mtftp6 driver.\r
131 //\r
132 Mtftp6Srv->DummyUdpIo = UdpIoCreateIo (\r
133 Controller,\r
134 Image,\r
135 Mtftp6ConfigDummyUdpIo,\r
136 UDP_IO_UDP6_VERSION,\r
137 NULL\r
138 );\r
139\r
140 if (Mtftp6Srv->DummyUdpIo == NULL) {\r
141 gBS->CloseEvent (Mtftp6Srv->Timer);\r
142 FreePool (Mtftp6Srv);\r
143 return EFI_DEVICE_ERROR;\r
144 }\r
145\r
146 *Service = Mtftp6Srv;\r
147 return EFI_SUCCESS;\r
148}\r
149\r
150\r
151/**\r
152 Destroy the MTFTP6 instance and recycle the resources.\r
153\r
154 @param[in] Instance The pointer to the MTFTP6 instance.\r
155\r
156**/\r
157VOID\r
158Mtftp6DestroyInstance (\r
159 IN MTFTP6_INSTANCE *Instance\r
160 )\r
161{\r
162 LIST_ENTRY *Entry;\r
163 LIST_ENTRY *Next;\r
164 MTFTP6_BLOCK_RANGE *Block;\r
165\r
166 if (Instance->Config != NULL) {\r
167 FreePool (Instance->Config);\r
168 }\r
169\r
170 if (Instance->Token != NULL && Instance->Token->Event != NULL) {\r
171 gBS->SignalEvent (Instance->Token->Event);\r
172 }\r
173\r
174 if (Instance->LastPacket != NULL) {\r
175 NetbufFree (Instance->LastPacket);\r
176 }\r
177\r
178 if (Instance->UdpIo!= NULL) {\r
179 UdpIoFreeIo (Instance->UdpIo);\r
180 }\r
181\r
182 if (Instance->McastUdpIo != NULL) {\r
183 UdpIoFreeIo (Instance->McastUdpIo);\r
184 }\r
185\r
186 NET_LIST_FOR_EACH_SAFE (Entry, Next, &Instance->BlkList) {\r
187 Block = NET_LIST_USER_STRUCT (Entry, MTFTP6_BLOCK_RANGE, Link);\r
188 RemoveEntryList (Entry);\r
189 FreePool (Block);\r
190 }\r
191\r
192 FreePool (Instance);\r
193}\r
194\r
195\r
196/**\r
197 Create the MTFTP6 instance and initialize it.\r
198\r
199 @param[in] Service The pointer to the MTFTP6 service.\r
200 @param[out] Instance The pointer to the MTFTP6 instance.\r
201\r
202 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources.\r
203 @retval EFI_SUCCESS The MTFTP6 instance is created.\r
204\r
205**/\r
206EFI_STATUS\r
207Mtftp6CreateInstance (\r
208 IN MTFTP6_SERVICE *Service,\r
209 OUT MTFTP6_INSTANCE **Instance\r
210 )\r
211{\r
212 MTFTP6_INSTANCE *Mtftp6Ins;\r
213\r
214 *Instance = NULL;\r
215 Mtftp6Ins = AllocateZeroPool (sizeof (MTFTP6_INSTANCE));\r
216\r
217 if (Mtftp6Ins == NULL) {\r
218 return EFI_OUT_OF_RESOURCES;\r
219 }\r
220\r
221 Mtftp6Ins->Signature = MTFTP6_INSTANCE_SIGNATURE;\r
222 Mtftp6Ins->InDestory = FALSE;\r
223 Mtftp6Ins->Service = Service;\r
224\r
225 CopyMem (\r
226 &Mtftp6Ins->Mtftp6,\r
227 &gMtftp6ProtocolTemplate,\r
228 sizeof (EFI_MTFTP6_PROTOCOL)\r
229 );\r
230\r
231 InitializeListHead (&Mtftp6Ins->Link);\r
232 InitializeListHead (&Mtftp6Ins->BlkList);\r
233\r
234 *Instance = Mtftp6Ins;\r
235\r
236 return EFI_SUCCESS;\r
237}\r
238\r
239\r
240/**\r
241 This is the declaration of an EFI image entry point. This entry point is\r
242 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers, including\r
243 both device drivers and bus drivers.\r
244\r
245 Entry point of the MTFTP6 driver to install various protocols.\r
246\r
247 @param[in] ImageHandle The firmware allocated handle for the UEFI image.\r
248 @param[in] SystemTable The pointer to the EFI System Table.\r
249\r
250 @retval EFI_SUCCESS The operation completed successfully.\r
251 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
252\r
253**/\r
254EFI_STATUS\r
255EFIAPI\r
256Mtftp6DriverEntryPoint (\r
257 IN EFI_HANDLE ImageHandle,\r
258 IN EFI_SYSTEM_TABLE *SystemTable\r
259 )\r
260{\r
261 return EfiLibInstallDriverBindingComponentName2 (\r
262 ImageHandle,\r
263 SystemTable,\r
264 &gMtftp6DriverBinding,\r
265 ImageHandle,\r
266 &gMtftp6ComponentName,\r
267 &gMtftp6ComponentName2\r
268 );\r
269}\r
270\r
271\r
272/**\r
76389e18 273 Test to see if this driver supports Controller. This service\r
a3bcde70
HT
274 is called by the EFI boot service ConnectController(). In\r
275 order to make drivers as small as possible, there are calling\r
276 restrictions for this service. ConnectController() must\r
277 follow these calling restrictions. If any other agent wishes to call\r
278 Supported(), it must also follow these calling restrictions.\r
279\r
280 @param[in] This Protocol instance pointer.\r
76389e18 281 @param[in] Controller Handle of device to test\r
a3bcde70
HT
282 @param[in] RemainingDevicePath Optional parameter use to pick a specific child.\r
283 device to start.\r
284\r
285 @retval EFI_SUCCESS This driver supports this device.\r
286 @retval Others This driver does not support this device.\r
287\r
288**/\r
289EFI_STATUS\r
290EFIAPI\r
291Mtftp6DriverBindingSupported (\r
292 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
293 IN EFI_HANDLE Controller,\r
294 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
295 )\r
296{\r
297 return gBS->OpenProtocol (\r
298 Controller,\r
299 &gEfiUdp6ServiceBindingProtocolGuid,\r
300 NULL,\r
301 This->DriverBindingHandle,\r
302 Controller,\r
303 EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
304 );\r
305}\r
306\r
307\r
308/**\r
76389e18 309 Start this driver on Controller. This service is called by the\r
a3bcde70
HT
310 EFI boot service ConnectController(). In order to make\r
311 drivers as small as possible, there are calling restrictions for\r
312 this service. ConnectController() must follow these\r
313 calling restrictions. If any other agent wishes to call Start() it\r
314 must also follow these calling restrictions.\r
315\r
316 @param[in] This Protocol instance pointer.\r
76389e18 317 @param[in] Controller Handle of device to bind driver to.\r
a3bcde70
HT
318 @param[in] RemainingDevicePath Optional parameter use to pick a specific child\r
319 device to start.\r
320\r
76389e18 321 @retval EFI_SUCCESS This driver is added to Controller.\r
322 @retval EFI_ALREADY_STARTED This driver is already running on Controller.\r
a3bcde70
HT
323 @retval Others This driver does not support this device.\r
324\r
325**/\r
326EFI_STATUS\r
327EFIAPI\r
328Mtftp6DriverBindingStart (\r
329 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
330 IN EFI_HANDLE Controller,\r
331 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
332 )\r
333{\r
334 MTFTP6_SERVICE *Service;\r
335 EFI_STATUS Status;\r
336\r
337 //\r
338 // Directly return if driver is already running on this Nic handle.\r
339 //\r
340 Status = gBS->OpenProtocol (\r
341 Controller,\r
342 &gEfiMtftp6ServiceBindingProtocolGuid,\r
343 NULL,\r
344 This->DriverBindingHandle,\r
345 Controller,\r
346 EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
347 );\r
348\r
349 if (!EFI_ERROR (Status)) {\r
350 return EFI_ALREADY_STARTED;\r
351 }\r
352\r
353 //\r
354 // Create Mtftp6 service for this Nic handle\r
355 //\r
356 Status = Mtftp6CreateService (\r
357 Controller,\r
358 This->DriverBindingHandle,\r
359 &Service\r
360 );\r
361\r
362 if (EFI_ERROR (Status)) {\r
363 return Status;\r
364 }\r
365\r
366 ASSERT (Service != NULL);\r
367\r
368 //\r
369 // Start the internal timer to track the packet retransmission.\r
370 //\r
371 Status = gBS->SetTimer (\r
372 Service->Timer,\r
373 TimerPeriodic,\r
374 TICKS_PER_SECOND\r
375 );\r
376\r
377 if (EFI_ERROR (Status)) {\r
378 goto ON_ERROR;\r
379 }\r
380\r
381 //\r
382 // Install the Mtftp6 service on the Nic handle.\r
383 //\r
384 Status = gBS->InstallMultipleProtocolInterfaces (\r
385 &Controller,\r
386 &gEfiMtftp6ServiceBindingProtocolGuid,\r
387 &Service->ServiceBinding,\r
388 NULL\r
389 );\r
390\r
391 if (EFI_ERROR (Status)) {\r
392 goto ON_ERROR;\r
393 }\r
394\r
395 return EFI_SUCCESS;\r
396\r
397ON_ERROR:\r
398\r
399 Mtftp6DestroyService (Service);\r
400 return Status;\r
401}\r
402\r
403\r
404/**\r
76389e18 405 Stop this driver on Controller. This service is called by the\r
a3bcde70 406 EFI boot service DisconnectController(). In order to\r
76389e18 407 make drivers as small as possible, there are calling\r
a3bcde70
HT
408 restrictions for this service. DisconnectController()\r
409 must follow these calling restrictions. If any other agent wishes\r
76389e18 410 to call Stop(), it must also follow these calling restrictions.\r
a3bcde70
HT
411\r
412 @param[in] This Protocol instance pointer.\r
76389e18 413 @param[in] Controller Handle of device to stop driver on\r
a3bcde70
HT
414 @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r
415 children is zero, stop the entire bus driver.\r
416 @param[in] ChildHandleBuffer List of Child Handles to Stop.\r
417\r
76389e18 418 @retval EFI_SUCCESS This driver is removed Controller.\r
a3bcde70
HT
419 @retval EFI_DEVICE_ERROR An unexpected error.\r
420 @retval Others This driver was not removed from this device.\r
421\r
422**/\r
423EFI_STATUS\r
424EFIAPI\r
425Mtftp6DriverBindingStop (\r
426 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
427 IN EFI_HANDLE Controller,\r
428 IN UINTN NumberOfChildren,\r
429 IN EFI_HANDLE *ChildHandleBuffer\r
430 )\r
431{\r
432 EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;\r
433 MTFTP6_SERVICE *Service;\r
434 MTFTP6_INSTANCE *Instance;\r
435 EFI_HANDLE NicHandle;\r
436 EFI_STATUS Status;\r
437 EFI_TPL OldTpl;\r
438\r
439 //\r
440 // Locate the Nic handle to retrieve the Mtftp6 private data.\r
441 //\r
442 NicHandle = NetLibGetNicHandle (Controller, &gEfiUdp6ProtocolGuid);\r
443\r
444 if (NicHandle == NULL) {\r
445 return EFI_DEVICE_ERROR;\r
446 }\r
447\r
448 Status = gBS->OpenProtocol (\r
449 NicHandle,\r
450 &gEfiMtftp6ServiceBindingProtocolGuid,\r
451 (VOID **) &ServiceBinding,\r
452 This->DriverBindingHandle,\r
453 NicHandle,\r
454 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
455 );\r
456\r
457 if (EFI_ERROR (Status)) {\r
458 return EFI_DEVICE_ERROR;\r
459 }\r
460\r
461 Service = MTFTP6_SERVICE_FROM_THIS (ServiceBinding);\r
462\r
463 if (Service->InDestory) {\r
464 return EFI_SUCCESS;\r
465 }\r
466\r
467 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
468\r
469 if (NumberOfChildren == 0) {\r
470 //\r
471 // Destory the Mtftp6 service if there is no Mtftp6 child instance left.\r
472 //\r
473 Service->InDestory = TRUE;\r
474\r
475 gBS->UninstallProtocolInterface (\r
476 NicHandle,\r
477 &gEfiMtftp6ServiceBindingProtocolGuid,\r
478 ServiceBinding\r
479 );\r
480\r
481 Mtftp6DestroyService (Service);\r
482\r
483 } else {\r
484 //\r
485 // Destory the Mtftp6 child instance one by one.\r
486 //\r
487 while (!IsListEmpty (&Service->Children)) {\r
488 Instance = NET_LIST_HEAD (&Service->Children, MTFTP6_INSTANCE, Link);\r
489 Mtftp6ServiceBindingDestroyChild (ServiceBinding, Instance->Handle);\r
490 }\r
491\r
492 if (Service->ChildrenNum != 0) {\r
493 Status = EFI_DEVICE_ERROR;\r
494 }\r
495 }\r
496\r
497 gBS->RestoreTPL (OldTpl);\r
498 return Status;\r
499}\r
500\r
501\r
502/**\r
503 Creates a child handle and installs a protocol.\r
504\r
505 The CreateChild() function installs a protocol on ChildHandle.\r
506 If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle.\r
507 If ChildHandle is not a pointer to NULL, then the protocol installs on the existing ChildHandle.\r
508\r
509 @param[in] This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.\r
510 @param[in, out] ChildHandle Pointer to the handle of the child to create. If it is NULL,\r
511 then a new handle is created. If it is a pointer to an existing\r
512 UEFI handle, then the protocol is added to the existing UEFI handle.\r
513\r
514 @retval EFI_SUCCES The protocol was added to ChildHandle.\r
515 @retval EFI_INVALID_PARAMETER ChildHandle is NULL.\r
516 @retval Others The child handle was not created.\r
517\r
518**/\r
519EFI_STATUS\r
520EFIAPI\r
521Mtftp6ServiceBindingCreateChild (\r
522 IN EFI_SERVICE_BINDING_PROTOCOL *This,\r
523 IN OUT EFI_HANDLE *ChildHandle\r
524 )\r
525{\r
526 MTFTP6_SERVICE *Service;\r
527 MTFTP6_INSTANCE *Instance;\r
528 EFI_STATUS Status;\r
529 EFI_TPL OldTpl;\r
530 VOID *Udp6;\r
531\r
532 if (This == NULL || ChildHandle == NULL) {\r
533 return EFI_INVALID_PARAMETER;\r
534 }\r
535\r
536 Service = MTFTP6_SERVICE_FROM_THIS (This);\r
537\r
538 Status = Mtftp6CreateInstance (Service, &Instance);\r
539\r
540 if (EFI_ERROR (Status)) {\r
541 return Status;\r
542 }\r
543\r
544 ASSERT (Instance != NULL);\r
545\r
546 //\r
547 // Install the Mtftp6 protocol on the new child handle.\r
548 //\r
549 Status = gBS->InstallMultipleProtocolInterfaces (\r
550 ChildHandle,\r
551 &gEfiMtftp6ProtocolGuid,\r
552 &Instance->Mtftp6,\r
553 NULL\r
554 );\r
555\r
556 if (EFI_ERROR (Status)) {\r
557 goto ON_ERROR;\r
558 }\r
559\r
560 Instance->Handle = *ChildHandle;\r
561\r
562 //\r
563 // Open the Udp6 protocol by child.\r
564 //\r
565 Status = gBS->OpenProtocol (\r
566 Service->DummyUdpIo->UdpHandle,\r
567 &gEfiUdp6ProtocolGuid,\r
568 (VOID **) &Udp6,\r
569 gMtftp6DriverBinding.DriverBindingHandle,\r
570 Instance->Handle,\r
571 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
572 );\r
573\r
574 if (EFI_ERROR (Status)) {\r
575 gBS->UninstallMultipleProtocolInterfaces (\r
576 Instance->Handle,\r
577 &gEfiMtftp6ProtocolGuid,\r
578 &Instance->Mtftp6,\r
579 NULL\r
580 );\r
581\r
582 goto ON_ERROR;\r
583 }\r
584\r
585 //\r
586 // Add the new Mtftp6 instance into the children list of Mtftp6 service.\r
587 //\r
588 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
589\r
590 InsertTailList (&Service->Children, &Instance->Link);\r
591 Service->ChildrenNum++;\r
592\r
593 gBS->RestoreTPL (OldTpl);\r
594 return EFI_SUCCESS;\r
595\r
596ON_ERROR:\r
597\r
598 Mtftp6DestroyInstance (Instance);\r
599 return Status;\r
600}\r
601\r
602\r
603/**\r
604 Destroys a child handle with a protocol installed on it.\r
605\r
606 The DestroyChild() function does the opposite of CreateChild(). It removes a protocol\r
607 that was installed by CreateChild() from ChildHandle. If the removed protocol is the\r
608 last protocol on ChildHandle, then ChildHandle is destroyed.\r
609\r
610 @param[in] This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.\r
611 @param[in] ChildHandle Handle of the child to destroy.\r
612\r
613 @retval EFI_SUCCES The protocol was removed from ChildHandle.\r
614 @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.\r
615 @retval EFI_INVALID_PARAMETER Child handle is not a valid UEFI Handle.\r
616 @retval Others The child handle was not destroyed\r
617\r
618**/\r
619EFI_STATUS\r
620EFIAPI\r
621Mtftp6ServiceBindingDestroyChild (\r
622 IN EFI_SERVICE_BINDING_PROTOCOL *This,\r
623 IN EFI_HANDLE ChildHandle\r
624 )\r
625{\r
626 MTFTP6_SERVICE *Service;\r
627 MTFTP6_INSTANCE *Instance;\r
628 EFI_MTFTP6_PROTOCOL *Mtftp6;\r
629 EFI_STATUS Status;\r
630 EFI_TPL OldTpl;\r
631\r
632 if (This == NULL || ChildHandle == NULL) {\r
633 return EFI_INVALID_PARAMETER;\r
634 }\r
635\r
636 //\r
637 // Locate the Nic handle to retrieve the Mtftp6 private data.\r
638 //\r
639 Status = gBS->OpenProtocol (\r
640 ChildHandle,\r
641 &gEfiMtftp6ProtocolGuid,\r
642 (VOID **) &Mtftp6,\r
643 gMtftp6DriverBinding.DriverBindingHandle,\r
644 ChildHandle,\r
645 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
646 );\r
647\r
648 if (EFI_ERROR (Status)) {\r
649 return EFI_UNSUPPORTED;\r
650 }\r
651\r
652 Instance = MTFTP6_INSTANCE_FROM_THIS (Mtftp6);\r
653 Service = MTFTP6_SERVICE_FROM_THIS (This);\r
654\r
655 if (Instance->Service != Service) {\r
656 return EFI_INVALID_PARAMETER;\r
657 }\r
658\r
659 //\r
660 // Check whether the instance already in destory state.\r
661 //\r
662 if (Instance->InDestory) {\r
663 return EFI_SUCCESS;\r
664 }\r
665\r
666 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
667\r
668 Instance->InDestory = TRUE;\r
669\r
670 gBS->CloseProtocol (\r
671 Service->DummyUdpIo->UdpHandle,\r
672 &gEfiUdp6ProtocolGuid,\r
673 gMtftp6DriverBinding.DriverBindingHandle,\r
674 ChildHandle\r
675 );\r
676\r
677 //\r
678 // Uninstall the MTFTP6 protocol first to enable a top down destruction.\r
679 //\r
680 Status = gBS->UninstallProtocolInterface (\r
681 ChildHandle,\r
682 &gEfiMtftp6ProtocolGuid,\r
683 Mtftp6\r
684 );\r
685\r
686 if (EFI_ERROR (Status)) {\r
687 Instance->InDestory = FALSE;\r
688 gBS->RestoreTPL (OldTpl);\r
689 return Status;\r
690 }\r
691\r
692 //\r
693 // Remove the Mtftp6 instance from the children list of Mtftp6 service.\r
694 //\r
695 RemoveEntryList (&Instance->Link);\r
696 Service->ChildrenNum --;\r
697\r
698 Mtftp6DestroyInstance (Instance);\r
699\r
700 gBS->RestoreTPL (OldTpl);\r
701\r
702 return EFI_SUCCESS;\r
703}\r