]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/MnpDxe/MnpDriver.c
Use Mde library and definition instead of some native definitions in NetLib, to simpl...
[mirror_edk2.git] / MdeModulePkg / Universal / Network / MnpDxe / MnpDriver.c
index 932b21c5ef1d34de49213353b86f55cb0887f040..fe6b63beaccdcdaddaf23429930c878223b07027 100644 (file)
@@ -19,7 +19,6 @@ Abstract:
 **/\r
 \r
 #include "MnpDriver.h"\r
-#include "MnpDebug.h"\r
 #include "MnpImpl.h"\r
 \r
 \r
@@ -116,10 +115,9 @@ MnpDriverBindingStart (
 \r
   MnpInitialized  = FALSE;\r
 \r
-  MnpServiceData  = NetAllocateZeroPool (sizeof (MNP_SERVICE_DATA));\r
+  MnpServiceData  = AllocateZeroPool (sizeof (MNP_SERVICE_DATA));\r
   if (MnpServiceData == NULL) {\r
-    MNP_DEBUG_ERROR (("MnpDriverBindingStart(): Failed to allocate the "\r
-      L"Mnp Service Data.\n"));\r
+    DEBUG ((EFI_D_ERROR, "MnpDriverBindingStart(): Failed to allocate the Mnp Service Data.\n"));\r
 \r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
@@ -130,8 +128,7 @@ MnpDriverBindingStart (
   Status = MnpInitializeServiceData (MnpServiceData, This->DriverBindingHandle, ControllerHandle);\r
   if (EFI_ERROR (Status)) {\r
 \r
-    MNP_DEBUG_ERROR (("MnpDriverBindingStart: MnpInitializeServiceData "\r
-      L"failed, %r.\n",Status));\r
+    DEBUG ((EFI_D_ERROR, "MnpDriverBindingStart: MnpInitializeServiceData failed, %r.\n",Status));\r
     goto ErrorExit;\r
   }\r
 \r
@@ -168,7 +165,7 @@ ErrorExit:
           ControllerHandle\r
           );\r
 \r
-    NetFreePool (MnpServiceData);\r
+    gBS->FreePool (MnpServiceData);\r
   }\r
 \r
   return Status;\r
@@ -215,68 +212,59 @@ MnpDriverBindingStop (
                   );\r
   if (EFI_ERROR (Status)) {\r
 \r
-    MNP_DEBUG_ERROR (\r
-      ("MnpDriverBindingStop: Locate MNP Service Binding Protocol failed, %r.\n",\r
+    DEBUG (\r
+      (EFI_D_ERROR,\r
+      "MnpDriverBindingStop: Locate MNP Service Binding Protocol failed, %r.\n",\r
       Status)\r
       );\r
-    goto EXIT;\r
+    return EFI_DEVICE_ERROR;\r
   }\r
 \r
   MnpServiceData = MNP_SERVICE_DATA_FROM_THIS (ServiceBinding);\r
 \r
-  while (!NetListIsEmpty (&MnpServiceData->ChildrenList)) {\r
+  if (NumberOfChildren == 0) {\r
     //\r
-    // Don't use NetListRemoveHead here, the remove opreration will be done\r
-    // in ServiceBindingDestroyChild.\r
+    // Uninstall the MNP Service Binding Protocol.\r
     //\r
-    Instance = NET_LIST_HEAD (\r
-                &MnpServiceData->ChildrenList,\r
-                MNP_INSTANCE_DATA,\r
-                InstEntry\r
-                );\r
+    gBS->UninstallMultipleProtocolInterfaces (\r
+           ControllerHandle,\r
+           &gEfiManagedNetworkServiceBindingProtocolGuid,\r
+           ServiceBinding,\r
+           NULL\r
+           );\r
 \r
-    ServiceBinding->DestroyChild (ServiceBinding, Instance->Handle);\r
-  }\r
-\r
-  //\r
-  // Uninstall the MNP Service Binding Protocol.\r
-  //\r
-  Status = gBS->UninstallMultipleProtocolInterfaces (\r
-                  ControllerHandle,\r
-                  &gEfiManagedNetworkServiceBindingProtocolGuid,\r
-                  ServiceBinding,\r
-                  NULL\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
+    //\r
+    // Close the openned Snp protocol.\r
+    //\r
+    gBS->CloseProtocol (\r
+           ControllerHandle,\r
+           &gEfiSimpleNetworkProtocolGuid,\r
+           This->DriverBindingHandle,\r
+           ControllerHandle\r
+           );\r
 \r
-    MNP_DEBUG_ERROR (("MnpDriverBindingStop: Uninstall MNP Service Binding Protocol failed, %r.\n"));\r
-    goto EXIT;\r
-  }\r
+    //\r
+    // Flush the Mnp service data.\r
+    //\r
+    MnpFlushServiceData (MnpServiceData);\r
 \r
-  //\r
-  // Close the openned Snp protocol.\r
-  //\r
-  Status = gBS->CloseProtocol (\r
-                  ControllerHandle,\r
-                  &gEfiSimpleNetworkProtocolGuid,\r
-                  This->DriverBindingHandle,\r
-                  ControllerHandle\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
+    gBS->FreePool (MnpServiceData);\r
+  } else {\r
+    while (!IsListEmpty (&MnpServiceData->ChildrenList)) {\r
+      //\r
+      // Don't use NetListRemoveHead here, the remove opreration will be done\r
+      // in ServiceBindingDestroyChild.\r
+      //\r
+      Instance = NET_LIST_HEAD (\r
+                   &MnpServiceData->ChildrenList,\r
+                   MNP_INSTANCE_DATA,\r
+                   InstEntry\r
+                   );\r
 \r
-    MNP_DEBUG_ERROR (("MnpDriverBindingStop: Close SNP Protocol failed, %r.\n", Status));\r
-    goto EXIT;\r
+      ServiceBinding->DestroyChild (ServiceBinding, Instance->Handle);\r
+    }\r
   }\r
 \r
-  //\r
-  // Flush the Mnp service data.\r
-  //\r
-  MnpFlushServiceData (MnpServiceData);\r
-\r
-  NetFreePool (MnpServiceData);\r
-\r
-EXIT:\r
-\r
   return Status;\r
 }\r
 \r
@@ -320,10 +308,10 @@ MnpServiceBindingCreateChild (
   //\r
   // Allocate buffer for the new instance.\r
   //\r
-  Instance = NetAllocateZeroPool (sizeof (MNP_INSTANCE_DATA));\r
+  Instance = AllocateZeroPool (sizeof (MNP_INSTANCE_DATA));\r
   if (Instance == NULL) {\r
 \r
-    MNP_DEBUG_ERROR (("MnpServiceBindingCreateChild: Faild to allocate memory for the new instance.\n"));\r
+    DEBUG ((EFI_D_ERROR, "MnpServiceBindingCreateChild: Faild to allocate memory for the new instance.\n"));\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
@@ -340,8 +328,9 @@ MnpServiceBindingCreateChild (
                   );\r
   if (EFI_ERROR (Status)) {\r
 \r
-    MNP_DEBUG_ERROR (\r
-      ("MnpServiceBindingCreateChild: Failed to install the MNP protocol, %r.\n",\r
+    DEBUG (\r
+      (EFI_D_ERROR,\r
+      "MnpServiceBindingCreateChild: Failed to install the MNP protocol, %r.\n",\r
       Status)\r
       );\r
     goto ErrorExit;\r
@@ -367,12 +356,12 @@ MnpServiceBindingCreateChild (
   //\r
   // Add the child instance into ChildrenList.\r
   //\r
-  OldTpl = NET_RAISE_TPL (NET_TPL_LOCK);\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
 \r
-  NetListInsertTail (&MnpServiceData->ChildrenList, &Instance->InstEntry);\r
+  InsertTailList (&MnpServiceData->ChildrenList, &Instance->InstEntry);\r
   MnpServiceData->ChildrenNumber++;\r
 \r
-  NET_RESTORE_TPL (OldTpl);\r
+  gBS->RestoreTPL (OldTpl);\r
 \r
 ErrorExit:\r
 \r
@@ -387,7 +376,7 @@ ErrorExit:
             );\r
     }\r
 \r
-    NetFreePool (Instance);\r
+    gBS->FreePool (Instance);\r
   }\r
 \r
   return Status;\r
@@ -482,8 +471,9 @@ MnpServiceBindingDestroyChild (
                   );\r
   if (EFI_ERROR (Status)) {\r
 \r
-    MNP_DEBUG_ERROR (\r
-      ("MnpServiceBindingDestroyChild: Failed to uninstall the ManagedNetwork protocol, %r.\n",\r
+    DEBUG (\r
+      (EFI_D_ERROR,\r
+      "MnpServiceBindingDestroyChild: Failed to uninstall the ManagedNetwork protocol, %r.\n",\r
       Status)\r
       );\r
 \r
@@ -491,7 +481,7 @@ MnpServiceBindingDestroyChild (
     return Status;\r
   }\r
 \r
-  OldTpl = NET_RAISE_TPL (NET_TPL_LOCK);\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
 \r
   //\r
   // Reset the configuration.\r
@@ -511,12 +501,12 @@ MnpServiceBindingDestroyChild (
   //\r
   // Remove this instance from the ChildrenList.\r
   //\r
-  NetListRemoveEntry (&Instance->InstEntry);\r
+  RemoveEntryList (&Instance->InstEntry);\r
   MnpServiceData->ChildrenNumber--;\r
 \r
-  NET_RESTORE_TPL (OldTpl);\r
+  gBS->RestoreTPL (OldTpl);\r
 \r
-  NetFreePool (Instance);\r
+  gBS->FreePool (Instance);\r
 \r
   return Status;\r
 }\r
@@ -547,13 +537,12 @@ Returns:
 \r
 --*/\r
 {\r
-  return NetLibInstallAllDriverProtocols (\r
-          ImageHandle,\r
-          SystemTable,\r
-          &gMnpDriverBinding,\r
-          ImageHandle,\r
-          &gMnpComponentName,\r
-          NULL,\r
-          NULL\r
-          );\r
+  return EfiLibInstallDriverBindingComponentName2 (\r
+           ImageHandle,\r
+           SystemTable,\r
+           &gMnpDriverBinding,\r
+           ImageHandle,\r
+           &gMnpComponentName,\r
+           &gMnpComponentName2\r
+           );\r
 }\r