3 Copyright (c) 2005 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
21 #include "MnpDriver.h"
26 EFI_DRIVER_BINDING_PROTOCOL gMnpDriverBinding
= {
27 MnpDriverBindingSupported
,
28 MnpDriverBindingStart
,
37 Test to see if this driver supports ControllerHandle.
39 @param This Protocol instance pointer.
40 @param ControllerHandle Handle of device to test.
41 @param RemainingDevicePath Optional parameter use to pick a specific child
44 @retval EFI_SUCCES This driver supports this device.
45 @retval EFI_ALREADY_STARTED This driver is already running on this device.
46 @retval other This driver does not support this device.
51 MnpDriverBindingSupported (
52 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
53 IN EFI_HANDLE ControllerHandle
,
54 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
60 // Test to see if MNP is already installed.
62 Status
= gBS
->OpenProtocol (
64 &gEfiManagedNetworkServiceBindingProtocolGuid
,
66 This
->DriverBindingHandle
,
68 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
70 if (!EFI_ERROR (Status
)) {
72 return EFI_ALREADY_STARTED
;
76 // Test to see if SNP is installed.
78 Status
= gBS
->OpenProtocol (
80 &gEfiSimpleNetworkProtocolGuid
,
82 This
->DriverBindingHandle
,
84 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
92 Start this driver on ControllerHandle.
94 @param This Protocol instance pointer.
95 @param ControllerHandle Handle of device to bind driver to.
96 @param RemainingDevicePath Optional parameter use to pick a specific child
99 @retval EFI_SUCCES This driver is added to ControllerHandle.
100 @retval EFI_ALREADY_STARTED This driver is already running on
102 @retval other This driver does not support this device.
107 MnpDriverBindingStart (
108 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
109 IN EFI_HANDLE ControllerHandle
,
110 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
114 MNP_SERVICE_DATA
*MnpServiceData
;
115 BOOLEAN MnpInitialized
;
117 MnpInitialized
= FALSE
;
119 MnpServiceData
= NetAllocateZeroPool (sizeof (MNP_SERVICE_DATA
));
120 if (MnpServiceData
== NULL
) {
121 MNP_DEBUG_ERROR (("MnpDriverBindingStart(): Failed to allocate the "
122 L
"Mnp Service Data.\n"));
124 return EFI_OUT_OF_RESOURCES
;
128 // Initialize the Mnp Service Data.
130 Status
= MnpInitializeServiceData (MnpServiceData
, This
->DriverBindingHandle
, ControllerHandle
);
131 if (EFI_ERROR (Status
)) {
133 MNP_DEBUG_ERROR (("MnpDriverBindingStart: MnpInitializeServiceData "
134 L
"failed, %r.\n",Status
));
138 MnpInitialized
= TRUE
;
141 // Install the MNP Service Binding Protocol.
143 Status
= gBS
->InstallMultipleProtocolInterfaces (
145 &gEfiManagedNetworkServiceBindingProtocolGuid
,
146 &MnpServiceData
->ServiceBinding
,
152 if (EFI_ERROR (Status
)) {
154 if (MnpInitialized
) {
156 // Flush the Mnp Service Data.
158 MnpFlushServiceData (MnpServiceData
);
162 // Close the Simple Network Protocol.
166 &gEfiSimpleNetworkProtocolGuid
,
167 This
->DriverBindingHandle
,
171 NetFreePool (MnpServiceData
);
179 Stop this driver on ControllerHandle.
181 @param This Protocol instance pointer.
182 @param ControllerHandle Handle of device to stop driver on.
183 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number
184 of children is zero stop the entire bus driver.
185 @param ChildHandleBuffer List of Child Handles to Stop.
187 @retval EFI_SUCCES This driver is removed ControllerHandle.
188 @retval other This driver was not removed from this device.
193 MnpDriverBindingStop (
194 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
195 IN EFI_HANDLE ControllerHandle
,
196 IN UINTN NumberOfChildren
,
197 IN EFI_HANDLE
*ChildHandleBuffer
201 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
202 MNP_SERVICE_DATA
*MnpServiceData
;
203 MNP_INSTANCE_DATA
*Instance
;
206 // Retrieve the MNP service binding protocol from the ControllerHandle.
208 Status
= gBS
->OpenProtocol (
210 &gEfiManagedNetworkServiceBindingProtocolGuid
,
211 (VOID
**) &ServiceBinding
,
212 This
->DriverBindingHandle
,
214 EFI_OPEN_PROTOCOL_GET_PROTOCOL
216 if (EFI_ERROR (Status
)) {
219 ("MnpDriverBindingStop: Locate MNP Service Binding Protocol failed, %r.\n",
222 return EFI_DEVICE_ERROR
;
225 MnpServiceData
= MNP_SERVICE_DATA_FROM_THIS (ServiceBinding
);
227 if (NumberOfChildren
== 0) {
229 // Uninstall the MNP Service Binding Protocol.
231 gBS
->UninstallMultipleProtocolInterfaces (
233 &gEfiManagedNetworkServiceBindingProtocolGuid
,
239 // Close the openned Snp protocol.
243 &gEfiSimpleNetworkProtocolGuid
,
244 This
->DriverBindingHandle
,
249 // Flush the Mnp service data.
251 MnpFlushServiceData (MnpServiceData
);
253 NetFreePool (MnpServiceData
);
255 while (!NetListIsEmpty (&MnpServiceData
->ChildrenList
)) {
257 // Don't use NetListRemoveHead here, the remove opreration will be done
258 // in ServiceBindingDestroyChild.
260 Instance
= NET_LIST_HEAD (
261 &MnpServiceData
->ChildrenList
,
266 ServiceBinding
->DestroyChild (ServiceBinding
, Instance
->Handle
);
275 Creates a child handle with a set of I/O services.
277 @param This Protocol instance pointer.
278 @param ChildHandle Pointer to the handle of the child to create. If
279 it is NULL, then a new handle is created. If it is
280 not NULL, then the I/O services are added to the
281 existing child handle.
283 @retval EFI_SUCCES The child handle was created with the I/O
285 @retval EFI_OUT_OF_RESOURCES There are not enough resources availabe to create
287 @retval other The child handle was not created.
292 MnpServiceBindingCreateChild (
293 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
294 IN EFI_HANDLE
*ChildHandle
298 MNP_SERVICE_DATA
*MnpServiceData
;
299 MNP_INSTANCE_DATA
*Instance
;
303 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
305 return EFI_INVALID_PARAMETER
;
308 MnpServiceData
= MNP_SERVICE_DATA_FROM_THIS (This
);
311 // Allocate buffer for the new instance.
313 Instance
= NetAllocateZeroPool (sizeof (MNP_INSTANCE_DATA
));
314 if (Instance
== NULL
) {
316 MNP_DEBUG_ERROR (("MnpServiceBindingCreateChild: Faild to allocate memory for the new instance.\n"));
317 return EFI_OUT_OF_RESOURCES
;
321 // Init the instance data.
323 MnpInitializeInstanceData (MnpServiceData
, Instance
);
325 Status
= gBS
->InstallMultipleProtocolInterfaces (
327 &gEfiManagedNetworkProtocolGuid
,
328 &Instance
->ManagedNetwork
,
331 if (EFI_ERROR (Status
)) {
334 ("MnpServiceBindingCreateChild: Failed to install the MNP protocol, %r.\n",
341 // Save the instance's childhandle.
343 Instance
->Handle
= *ChildHandle
;
345 Status
= gBS
->OpenProtocol (
346 MnpServiceData
->ControllerHandle
,
347 &gEfiSimpleNetworkProtocolGuid
,
349 gMnpDriverBinding
.DriverBindingHandle
,
351 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
353 if (EFI_ERROR (Status
)) {
358 // Add the child instance into ChildrenList.
360 OldTpl
= NET_RAISE_TPL (NET_TPL_LOCK
);
362 NetListInsertTail (&MnpServiceData
->ChildrenList
, &Instance
->InstEntry
);
363 MnpServiceData
->ChildrenNumber
++;
365 NET_RESTORE_TPL (OldTpl
);
369 if (EFI_ERROR (Status
)) {
371 if (Instance
->Handle
!= NULL
) {
373 gBS
->UninstallMultipleProtocolInterfaces (
374 &gEfiManagedNetworkProtocolGuid
,
375 &Instance
->ManagedNetwork
,
380 NetFreePool (Instance
);
388 Destroys a child handle with a set of I/O services.
390 @param This Protocol instance pointer.
391 @param ChildHandle Handle of the child to destroy.
393 @retval EFI_SUCCES The I/O services were removed from the child
395 @retval EFI_UNSUPPORTED The child handle does not support the I/O services
396 that are being removed.
397 @retval EFI_INVALID_PARAMETER Child handle is not a valid EFI Handle.
398 @retval EFI_ACCESS_DENIED The child handle could not be destroyed because
399 its I/O services are being used.
400 @retval other The child handle was not destroyed.
405 MnpServiceBindingDestroyChild (
406 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
407 IN EFI_HANDLE ChildHandle
411 MNP_SERVICE_DATA
*MnpServiceData
;
412 EFI_MANAGED_NETWORK_PROTOCOL
*ManagedNetwork
;
413 MNP_INSTANCE_DATA
*Instance
;
416 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
418 return EFI_INVALID_PARAMETER
;
421 MnpServiceData
= MNP_SERVICE_DATA_FROM_THIS (This
);
424 // Try to retrieve ManagedNetwork Protocol from ChildHandle.
426 Status
= gBS
->OpenProtocol (
428 &gEfiManagedNetworkProtocolGuid
,
429 (VOID
**) &ManagedNetwork
,
430 gMnpDriverBinding
.DriverBindingHandle
,
432 EFI_OPEN_PROTOCOL_GET_PROTOCOL
434 if (EFI_ERROR (Status
)) {
436 return EFI_UNSUPPORTED
;
439 Instance
= MNP_INSTANCE_DATA_FROM_THIS (ManagedNetwork
);
442 // MnpServiceBindingDestroyChild may be called twice: first called by
443 // MnpServiceBindingStop, second called by uninstalling the MNP protocol
444 // in this ChildHandle. Use destroyed to make sure the resource clean code
445 // will only excecute once.
447 if (Instance
->Destroyed
) {
452 Instance
->Destroyed
= TRUE
;
455 // Close the Simple Network protocol.
458 MnpServiceData
->ControllerHandle
,
459 &gEfiSimpleNetworkProtocolGuid
,
460 gMnpDriverBinding
.DriverBindingHandle
,
465 // Uninstall the ManagedNetwork protocol.
467 Status
= gBS
->UninstallMultipleProtocolInterfaces (
469 &gEfiManagedNetworkProtocolGuid
,
470 &Instance
->ManagedNetwork
,
473 if (EFI_ERROR (Status
)) {
476 ("MnpServiceBindingDestroyChild: Failed to uninstall the ManagedNetwork protocol, %r.\n",
480 Instance
->Destroyed
= FALSE
;
484 OldTpl
= NET_RAISE_TPL (NET_TPL_LOCK
);
487 // Reset the configuration.
489 ManagedNetwork
->Configure (ManagedNetwork
, NULL
);
492 // Try to flush the RcvdPacketQueue.
494 MnpFlushRcvdDataQueue (Instance
);
497 // Clean the RxTokenMap.
499 NetMapClean (&Instance
->RxTokenMap
);
502 // Remove this instance from the ChildrenList.
504 NetListRemoveEntry (&Instance
->InstEntry
);
505 MnpServiceData
->ChildrenNumber
--;
507 NET_RESTORE_TPL (OldTpl
);
509 NetFreePool (Instance
);
517 MnpDriverEntryPoint (
518 IN EFI_HANDLE ImageHandle
,
519 IN EFI_SYSTEM_TABLE
*SystemTable
525 The entry point for Mnp driver which installs the driver binding and component name
526 protocol on its ImageHandle.
530 ImageHandle - The image handle of the driver.
531 SystemTable - The system table.
535 EFI_SUCCESS - If the driver binding and component name protocols are successfully
536 installed, otherwise if failed.
540 return EfiLibInstallDriverBindingComponentName2 (