]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPkg/Drivers/ArmScmiDxe/ScmiClockProtocol.c
ArmPkg: Fix Ecc error 7008 for SCMI_CLOCK_RATE
[mirror_edk2.git] / ArmPkg / Drivers / ArmScmiDxe / ScmiClockProtocol.c
index 64d2afab722ae196e4f75e027216be642b4ca812..5c06e31bda226643d1c09c0c268dfc4f0ed1f98f 100644 (file)
@@ -1,14 +1,8 @@
 /** @file\r
 \r
-  Copyright (c) 2017-2018, Arm Limited. All rights reserved.\r
+  Copyright (c) 2017-2021, Arm Limited. All rights reserved.\r
 \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
-  http://opensource.org/licenses/bsd-license.php\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
   System Control and Management Interface V1.0\r
     http://infocenter.arm.com/help/topic/com.arm.doc.den0056a/\r
@@ -19,6 +13,7 @@
 #include <Library/DebugLib.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
 #include <Protocol/ArmScmiClockProtocol.h>\r
+#include <Protocol/ArmScmiClock2Protocol.h>\r
 \r
 #include "ArmScmiClockProtocolPrivate.h"\r
 #include "ScmiPrivate.h"\r
@@ -194,12 +189,14 @@ ClockDescribeRates (
   CLOCK_DESCRIBE_RATES   *DescribeRates;\r
   CLOCK_RATE_DWORD       *Rate;\r
 \r
-  UINT32                 RequiredArraySize = 0;\r
-  UINT32                 RateIndex = 0;\r
+  UINT32                 RequiredArraySize;\r
+  UINT32                 RateIndex;\r
   UINT32                 RateNo;\r
   UINT32                 RateOffset;\r
 \r
   *TotalRates = 0;\r
+  RequiredArraySize = 0;\r
+  RateIndex = 0;\r
 \r
   Status = ScmiCommandGetPayload (&MessageParams);\r
   if (EFI_ERROR (Status)) {\r
@@ -258,22 +255,26 @@ ClockDescribeRates (
       for (RateNo = 0; RateNo < NUM_RATES (DescribeRates->NumRatesFlags); RateNo++) {\r
         Rate = &DescribeRates->Rates[RateOffset++];\r
         // Non-linear discrete rates.\r
-        RateArray[RateIndex++].Rate = ConvertTo64Bit (Rate->Low, Rate->High);\r
+        RateArray[RateIndex++].DiscreteRate.Rate =\r
+          ConvertTo64Bit (Rate->Low, Rate->High);\r
       }\r
     } else {\r
       for (RateNo = 0; RateNo < NUM_RATES (DescribeRates->NumRatesFlags); RateNo++) {\r
         // Linear clock rates from minimum to maximum in steps\r
         // Minimum clock rate.\r
         Rate = &DescribeRates->Rates[RateOffset++];\r
-        RateArray[RateIndex].Min = ConvertTo64Bit (Rate->Low, Rate->High);\r
+        RateArray[RateIndex].ContinuousRate.Min =\r
+          ConvertTo64Bit (Rate->Low, Rate->High);\r
 \r
         Rate = &DescribeRates->Rates[RateOffset++];\r
         // Maximum clock rate.\r
-        RateArray[RateIndex].Max = ConvertTo64Bit (Rate->Low, Rate->High);\r
+        RateArray[RateIndex].ContinuousRate.Max =\r
+          ConvertTo64Bit (Rate->Low, Rate->High);\r
 \r
         Rate = &DescribeRates->Rates[RateOffset++];\r
         // Step.\r
-        RateArray[RateIndex++].Step = ConvertTo64Bit (Rate->Low, Rate->High);\r
+        RateArray[RateIndex++].ContinuousRate.Step =\r
+          ConvertTo64Bit (Rate->Low, Rate->High);\r
       }\r
     }\r
   } while (NUM_REMAIN_RATES (DescribeRates->NumRatesFlags) != 0);\r
@@ -388,6 +389,53 @@ ClockRateSet (
   return Status;\r
 }\r
 \r
+/** Enable/Disable specified clock.\r
+\r
+  @param[in]  This        A Pointer to SCMI_CLOCK_PROTOCOL Instance.\r
+  @param[in]  ClockId     Identifier for the clock device.\r
+  @param[in]  Enable      TRUE to enable, FALSE to disable.\r
+\r
+  @retval EFI_SUCCESS          Clock enable/disable successful.\r
+  @retval EFI_DEVICE_ERROR     SCP returns an SCMI error.\r
+  @retval !(EFI_SUCCESS)       Other errors.\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+ClockEnable (\r
+  IN SCMI_CLOCK2_PROTOCOL *This,\r
+  IN UINT32               ClockId,\r
+  IN BOOLEAN              Enable\r
+  )\r
+{\r
+  EFI_STATUS                  Status;\r
+  CLOCK_CONFIG_SET_ATTRIBUTES *ClockConfigSetAttributes;\r
+  SCMI_COMMAND                Cmd;\r
+  UINT32                      PayloadLength;\r
+\r
+  Status = ScmiCommandGetPayload ((UINT32**)&ClockConfigSetAttributes);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  // Fill arguments for clock protocol command.\r
+  ClockConfigSetAttributes->ClockId    = ClockId;\r
+  ClockConfigSetAttributes->Attributes = Enable ? BIT0 : 0;\r
+\r
+  Cmd.ProtocolId = SCMI_PROTOCOL_ID_CLOCK;\r
+  Cmd.MessageId  = SCMI_MESSAGE_ID_CLOCK_CONFIG_SET;\r
+\r
+  PayloadLength = sizeof (CLOCK_CONFIG_SET_ATTRIBUTES);\r
+\r
+  // Execute and wait for response on a SCMI channel.\r
+  Status = ScmiCommandExecute (\r
+             &Cmd,\r
+             &PayloadLength,\r
+             NULL\r
+             );\r
+\r
+  return Status;\r
+}\r
+\r
 // Instance of the SCMI clock management protocol.\r
 STATIC CONST SCMI_CLOCK_PROTOCOL ScmiClockProtocol = {\r
   ClockGetVersion,\r
@@ -398,6 +446,18 @@ STATIC CONST SCMI_CLOCK_PROTOCOL ScmiClockProtocol = {
   ClockRateSet\r
  };\r
 \r
+// Instance of the SCMI clock management protocol.\r
+STATIC CONST SCMI_CLOCK2_PROTOCOL ScmiClock2Protocol = {\r
+  (SCMI_CLOCK2_GET_VERSION)ClockGetVersion,\r
+  (SCMI_CLOCK2_GET_TOTAL_CLOCKS)ClockGetTotalClocks,\r
+  (SCMI_CLOCK2_GET_CLOCK_ATTRIBUTES)ClockGetClockAttributes,\r
+  (SCMI_CLOCK2_DESCRIBE_RATES)ClockDescribeRates,\r
+  (SCMI_CLOCK2_RATE_GET)ClockRateGet,\r
+  (SCMI_CLOCK2_RATE_SET)ClockRateSet,\r
+  SCMI_CLOCK2_PROTOCOL_VERSION,\r
+  ClockEnable\r
+ };\r
+\r
 /** Initialize clock management protocol and install protocol on a given handle.\r
 \r
   @param[in] Handle              Handle to install clock management protocol.\r
@@ -413,6 +473,8 @@ ScmiClockProtocolInit (
                 Handle,\r
                 &gArmScmiClockProtocolGuid,\r
                 &ScmiClockProtocol,\r
+                &gArmScmiClock2ProtocolGuid,\r
+                &ScmiClock2Protocol,\r
                 NULL\r
                 );\r
 }\r