]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Dxe/Hand/DriverSupport.c
MdeModulePkg: Use new added Perf macros
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Hand / DriverSupport.c
index d705899412b6bfecf7cbd932f427fe87dd09f8a8..ab3cc0c07e57b7400af148a3bb458e4fd3fab840 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Support functions to connect/disconnect UEFI Driver model Protocol\r
 \r
-Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -22,19 +22,27 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 /**\r
   Connects one or more drivers to a controller.\r
 \r
-  @param  ControllerHandle                      Handle of the controller to be\r
-                                                connected.\r
-  @param  DriverImageHandle                     DriverImageHandle A pointer to an\r
-                                                ordered list of driver image\r
-                                                handles.\r
-  @param  RemainingDevicePath                   RemainingDevicePath A pointer to\r
-                                                the device path that specifies a\r
-                                                child of the controller specified\r
-                                                by ControllerHandle.\r
-  @param  Recursive                             Whether the function would be\r
-                                                called recursively or not.\r
-\r
-  @return Status code.\r
+  @param  ControllerHandle      The handle of the controller to which driver(s) are to be connected.\r
+  @param  DriverImageHandle     A pointer to an ordered list handles that support the\r
+                                EFI_DRIVER_BINDING_PROTOCOL.\r
+  @param  RemainingDevicePath   A pointer to the device path that specifies a child of the\r
+                                controller specified by ControllerHandle.\r
+  @param  Recursive             If TRUE, then ConnectController() is called recursively\r
+                                until the entire tree of controllers below the controller specified\r
+                                by ControllerHandle have been created. If FALSE, then\r
+                                the tree of controllers is only expanded one level.\r
+\r
+  @retval EFI_SUCCESS           1) One or more drivers were connected to ControllerHandle.\r
+                                2) No drivers were connected to ControllerHandle, but\r
+                                RemainingDevicePath is not NULL, and it is an End Device\r
+                                Path Node.\r
+  @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
+  @retval EFI_NOT_FOUND         1) There are no EFI_DRIVER_BINDING_PROTOCOL instances\r
+                                present in the system.\r
+                                2) No drivers were connected to ControllerHandle.\r
+  @retval EFI_SECURITY_VIOLATION \r
+                                The user has no permission to start UEFI device drivers on the device path \r
+                                associated with the ControllerHandle or specified by the RemainingDevicePath.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -57,6 +65,11 @@ CoreConnectController (
   EFI_HANDLE                           *ChildHandleBuffer;\r
   UINTN                                ChildHandleCount;\r
   UINTN                                Index;\r
+  UINTN                                HandleFilePathSize;\r
+  UINTN                                RemainingDevicePathSize;\r
+  EFI_DEVICE_PATH_PROTOCOL             *HandleFilePath;\r
+  EFI_DEVICE_PATH_PROTOCOL             *FilePath;\r
+  EFI_DEVICE_PATH_PROTOCOL             *TempFilePath;\r
 \r
   //\r
   // Make sure ControllerHandle is valid\r
@@ -66,6 +79,40 @@ CoreConnectController (
     return Status;\r
   }\r
 \r
+  if (gSecurity2 != NULL) {\r
+    //\r
+    // Check whether the user has permission to start UEFI device drivers.\r
+    //\r
+    Status = CoreHandleProtocol (ControllerHandle, &gEfiDevicePathProtocolGuid, (VOID **)&HandleFilePath);\r
+    if (!EFI_ERROR (Status)) {\r
+      ASSERT (HandleFilePath != NULL);\r
+      FilePath     = HandleFilePath;\r
+      TempFilePath = NULL;\r
+      if (RemainingDevicePath != NULL && !Recursive) {\r
+        HandleFilePathSize      = GetDevicePathSize (HandleFilePath) - sizeof (EFI_DEVICE_PATH_PROTOCOL);\r
+        RemainingDevicePathSize = GetDevicePathSize (RemainingDevicePath);\r
+        TempFilePath = AllocateZeroPool (HandleFilePathSize + RemainingDevicePathSize);\r
+        ASSERT (TempFilePath != NULL);\r
+        CopyMem (TempFilePath, HandleFilePath, HandleFilePathSize);\r
+        CopyMem ((UINT8 *) TempFilePath + HandleFilePathSize, RemainingDevicePath, RemainingDevicePathSize);\r
+        FilePath = TempFilePath;\r
+      }\r
+      Status = gSecurity2->FileAuthentication (\r
+                            gSecurity2,\r
+                            FilePath,\r
+                            NULL,\r
+                            0,\r
+                            FALSE\r
+                            );\r
+      if (TempFilePath != NULL) {\r
+        FreePool (TempFilePath);\r
+      }\r
+      if (EFI_ERROR (Status)) {\r
+        return Status;\r
+      }\r
+    }\r
+  }\r
+  \r
   Handle = ControllerHandle;\r
 \r
   //\r
@@ -369,6 +416,8 @@ CoreConnectSingleController (
   DriverBindingHandleBuffer             = NULL;\r
   NumberOfSortedDriverBindingProtocols  = 0;\r
   SortedDriverBindingProtocols          = NULL;\r
+  PlatformDriverOverride                = NULL;\r
+  NewDriverBindingHandleBuffer          = NULL;\r
 \r
   //\r
   // Get list of all Driver Binding Protocol Instances\r
@@ -578,13 +627,13 @@ CoreConnectSingleController (
     for (Index = 0; (Index < NumberOfSortedDriverBindingProtocols) && !DriverFound; Index++) {\r
       if (SortedDriverBindingProtocols[Index] != NULL) {\r
         DriverBinding = SortedDriverBindingProtocols[Index];\r
-        PERF_START (DriverBinding->DriverBindingHandle, "DB:Support:", NULL, 0);\r
+        PERF_DRIVER_BINDING_SUPPORT_BEGIN (DriverBinding->DriverBindingHandle, ControllerHandle);\r
         Status = DriverBinding->Supported(\r
                                   DriverBinding,\r
                                   ControllerHandle,\r
                                   RemainingDevicePath\r
                                   );\r
-        PERF_END (DriverBinding->DriverBindingHandle, "DB:Support:", NULL, 0);\r
+        PERF_DRIVER_BINDING_SUPPORT_END (DriverBinding->DriverBindingHandle, ControllerHandle);\r
         if (!EFI_ERROR (Status)) {\r
           SortedDriverBindingProtocols[Index] = NULL;\r
           DriverFound = TRUE;\r
@@ -593,13 +642,13 @@ CoreConnectSingleController (
           // A driver was found that supports ControllerHandle, so attempt to start the driver\r
           // on ControllerHandle.\r
           //\r
-          PERF_START (DriverBinding->DriverBindingHandle, "DB:Start:", NULL, 0);\r
+          PERF_DRIVER_BINDING_START_BEGIN (DriverBinding->DriverBindingHandle, ControllerHandle);\r
           Status = DriverBinding->Start (\r
                                     DriverBinding,\r
                                     ControllerHandle,\r
                                     RemainingDevicePath\r
                                     );\r
-          PERF_END (DriverBinding->DriverBindingHandle, "DB:Start:", NULL, 0);\r
+          PERF_DRIVER_BINDING_START_END (DriverBinding->DriverBindingHandle, ControllerHandle);\r
 \r
           if (!EFI_ERROR (Status)) {\r
             //\r