]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPkg/ArmScmiDxe: Add clock enable function
authorJeff Brasen <jbrasen@nvidia.com>
Thu, 13 Dec 2018 23:48:44 +0000 (16:48 -0700)
committerArd Biesheuvel <ard.biesheuvel@linaro.org>
Fri, 21 Dec 2018 17:30:46 +0000 (18:30 +0100)
Add function to allow enabling and disabling of the clock using the SCMI
interface. Add gArmScmiClock2ProtocolGuid to distinguish platforms that
support new API from those that just have the older protocol.

SCMI_CLOCK2_PROTOCOL also adds a version parameter to allow for future
changes. It is placed after the functions that are present in the
existing protocol to allow SCMI_CLOCK2_PROTOCOL to be cast to
SCMI_CLOCK_PROTOCOL so that only a single implementation of those
function are needed.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jeff Brasen <jbrasen@nvidia.com>
Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
ArmPkg/ArmPkg.dec
ArmPkg/Drivers/ArmScmiDxe/ArmScmiClockProtocolPrivate.h
ArmPkg/Drivers/ArmScmiDxe/ArmScmiDxe.inf
ArmPkg/Drivers/ArmScmiDxe/ScmiClockProtocol.c
ArmPkg/Include/Protocol/ArmScmiClock2Protocol.h [new file with mode: 0644]

index 0ec5e8efd6e0726456099e4bf0bd8f5849835dbd..473b077dd2998c52047ca168ceaa3ba5f1edaeca 100644 (file)
@@ -59,6 +59,7 @@
   ## Arm System Control and Management Interface(SCMI) Clock management protocol\r
   ## ArmPkg/Include/Protocol/ArmScmiClockProtocol.h\r
   gArmScmiClockProtocolGuid = { 0x91ce67a8, 0xe0aa, 0x4012, { 0xb9, 0x9f, 0xb6, 0xfc, 0xf3, 0x4, 0x8e, 0xaa } }\r
+  gArmScmiClock2ProtocolGuid = { 0xb8d8caf2, 0x9e94, 0x462c, { 0xa8, 0x34, 0x6c, 0x99, 0xfc, 0x05, 0xef, 0xcf } }\r
 \r
   ## Arm System Control and Management Interface(SCMI) Clock management protocol\r
   ## ArmPkg/Include/Protocol/ArmScmiPerformanceProtocol.h\r
index 0d1ec6f5ad2fef7706f5497ef5b4a56dba0dc12c..c135bacba62990fbfad3273c09e5bae258083e16 100644 (file)
@@ -59,6 +59,13 @@ typedef struct {
   CLOCK_RATE_DWORD Rate;\r
 } CLOCK_RATE_SET_ATTRIBUTES;\r
 \r
+\r
+// Message parameters for CLOCK_CONFIG_SET command.\r
+typedef struct {\r
+  UINT32 ClockId;\r
+  UINT32 Attributes;\r
+} CLOCK_CONFIG_SET_ATTRIBUTES;\r
+\r
 //  if ClockAttr Bit[0] is set then clock device is enabled.\r
 #define CLOCK_ENABLE_MASK         0x1\r
 #define CLOCK_ENABLED(ClockAttr)  ((ClockAttr & CLOCK_ENABLE_MASK) == 1)\r
index 05ce9c04ce468d74e5c6d38739f9056f3fc48694..9b29b9f9f3a90c801c60ba59fb497e4bad9e271f 100644 (file)
@@ -46,6 +46,7 @@
 [Protocols]\r
   gArmScmiBaseProtocolGuid\r
   gArmScmiClockProtocolGuid\r
+  gArmScmiClock2ProtocolGuid\r
   gArmScmiPerformanceProtocolGuid\r
 \r
 [Depex]\r
index 64d2afab722ae196e4f75e027216be642b4ca812..c7f27a301f17c37aba2832d2ea25b7797a29c136 100644 (file)
@@ -19,6 +19,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
@@ -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
diff --git a/ArmPkg/Include/Protocol/ArmScmiClock2Protocol.h b/ArmPkg/Include/Protocol/ArmScmiClock2Protocol.h
new file mode 100644 (file)
index 0000000..2d822c9
--- /dev/null
@@ -0,0 +1,197 @@
+/** @file\r
+\r
+  Copyright (c) 2017-2018, 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
+\r
+  System Control and Management Interface V1.0\r
+    http://infocenter.arm.com/help/topic/com.arm.doc.den0056a/\r
+    DEN0056A_System_Control_and_Management_Interface.pdf\r
+**/\r
+\r
+#ifndef ARM_SCMI_CLOCK2_PROTOCOL_H_\r
+#define ARM_SCMI_CLOCK2_PROTOCOL_H_\r
+\r
+#include <Protocol/ArmScmi.h>\r
+#include <Protocol/ArmScmiClockProtocol.h>\r
+\r
+#define ARM_SCMI_CLOCK2_PROTOCOL_GUID { \\r
+  0xb8d8caf2, 0x9e94, 0x462c, { 0xa8, 0x34, 0x6c, 0x99, 0xfc, 0x05, 0xef, 0xcf } \\r
+  }\r
+\r
+extern EFI_GUID gArmScmiClock2ProtocolGuid;\r
+\r
+#define SCMI_CLOCK2_PROTOCOL_VERSION 1\r
+\r
+typedef struct _SCMI_CLOCK2_PROTOCOL SCMI_CLOCK2_PROTOCOL;\r
+\r
+// Protocol Interface functions.\r
+\r
+/** Return version of the clock management protocol supported by SCP firmware.\r
+\r
+  @param[in]  This     A Pointer to SCMI_CLOCK2_PROTOCOL Instance.\r
+\r
+  @param[out] Version  Version of the supported SCMI Clock management protocol.\r
+\r
+  @retval EFI_SUCCESS       The version is returned.\r
+  @retval EFI_DEVICE_ERROR  SCP returns an SCMI error.\r
+  @retval !(EFI_SUCCESS)    Other errors.\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *SCMI_CLOCK2_GET_VERSION) (\r
+  IN  SCMI_CLOCK2_PROTOCOL  *This,\r
+  OUT UINT32                *Version\r
+  );\r
+\r
+/** Return total number of clock devices supported by the clock management\r
+   protocol.\r
+\r
+  @param[in]  This         A Pointer to SCMI_CLOCK2_PROTOCOL Instance.\r
+\r
+  @param[out] TotalClocks  Total number of clocks supported.\r
+\r
+  @retval EFI_SUCCESS       Total number of clocks supported is returned.\r
+  @retval EFI_DEVICE_ERROR  SCP returns an SCMI error.\r
+  @retval !(EFI_SUCCESS)    Other errors.\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *SCMI_CLOCK2_GET_TOTAL_CLOCKS) (\r
+  IN  SCMI_CLOCK2_PROTOCOL  *This,\r
+  OUT UINT32                *TotalClocks\r
+  );\r
+\r
+/** Return attributes of a clock device.\r
+\r
+  @param[in]  This        A Pointer to SCMI_CLOCK2_PROTOCOL Instance.\r
+  @param[in]  ClockId     Identifier for the clock device.\r
+\r
+  @param[out] Enabled         If TRUE, the clock device is enabled.\r
+  @param[out] ClockAsciiName  A NULL terminated ASCII string with the clock\r
+                              name, of up to 16 bytes.\r
+\r
+  @retval EFI_SUCCESS          Clock device attributes are returned.\r
+  @retval EFI_DEVICE_ERROR     SCP returns an SCMI error.\r
+  @retval !(EFI_SUCCESS)       Other errors.\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *SCMI_CLOCK2_GET_CLOCK_ATTRIBUTES) (\r
+  IN  SCMI_CLOCK2_PROTOCOL  *This,\r
+  IN  UINT32                ClockId,\r
+  OUT BOOLEAN               *Enabled,\r
+  OUT CHAR8                 *ClockAsciiName\r
+  );\r
+\r
+/** Return list of rates supported by a given clock device.\r
+\r
+  @param[in] This        A pointer to SCMI_CLOCK2_PROTOCOL Instance.\r
+  @param[in] ClockId     Identifier for the clock device.\r
+\r
+  @param[out] Format      SCMI_CLOCK_RATE_FORMAT_DISCRETE: Clock device\r
+                          supports range of clock rates which are non-linear.\r
+\r
+                          SCMI_CLOCK_RATE_FORMAT_LINEAR: Clock device supports\r
+                          range of linear clock rates from Min to Max in steps.\r
+\r
+  @param[out] TotalRates  Total number of rates.\r
+\r
+  @param[in,out] RateArraySize  Size of the RateArray.\r
+\r
+  @param[out] RateArray   List of clock rates.\r
+\r
+  @retval EFI_SUCCESS          List of clock rates are returned.\r
+  @retval EFI_DEVICE_ERROR     SCP returns an SCMI error.\r
+  @retval EFI_BUFFER_TOO_SMALL RateArraySize is too small for the result.\r
+                               It has been updated to the size needed.\r
+  @retval !(EFI_SUCCESS)       Other errors.\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *SCMI_CLOCK2_DESCRIBE_RATES) (\r
+  IN     SCMI_CLOCK2_PROTOCOL     *This,\r
+  IN     UINT32                   ClockId,\r
+  OUT    SCMI_CLOCK_RATE_FORMAT   *Format,\r
+  OUT    UINT32                   *TotalRates,\r
+  IN OUT UINT32                   *RateArraySize,\r
+  OUT    SCMI_CLOCK_RATE          *RateArray\r
+  );\r
+\r
+/** Get clock rate.\r
+\r
+  @param[in]  This        A Pointer to SCMI_CLOCK2_PROTOCOL Instance.\r
+  @param[in]  ClockId     Identifier for the clock device.\r
+\r
+  @param[out]  Rate       Clock rate.\r
+\r
+  @retval EFI_SUCCESS          Clock rate is returned.\r
+  @retval EFI_DEVICE_ERROR     SCP returns an SCMI error.\r
+  @retval !(EFI_SUCCESS)       Other errors.\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *SCMI_CLOCK2_RATE_GET) (\r
+  IN  SCMI_CLOCK2_PROTOCOL  *This,\r
+  IN  UINT32                ClockId,\r
+  OUT UINT64                *Rate\r
+  );\r
+\r
+/** Set clock rate.\r
+\r
+  @param[in]  This        A Pointer to SCMI_CLOCK2_PROTOCOL Instance.\r
+  @param[in]  ClockId     Identifier for the clock device.\r
+  @param[in]  Rate        Clock rate.\r
+\r
+  @retval EFI_SUCCESS          Clock rate set success.\r
+  @retval EFI_DEVICE_ERROR     SCP returns an SCMI error.\r
+  @retval !(EFI_SUCCESS)       Other errors.\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *SCMI_CLOCK2_RATE_SET) (\r
+  IN SCMI_CLOCK2_PROTOCOL   *This,\r
+  IN UINT32                 ClockId,\r
+  IN UINT64                 Rate\r
+  );\r
+\r
+/** Enable/Disable specified clock.\r
+    Function is only available under gArmScmiClock2ProtocolGuid\r
+\r
+  @param[in]  This        A Pointer to SCMI_CLOCK2_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
+typedef\r
+EFI_STATUS\r
+(EFIAPI *SCMI_CLOCK2_ENABLE) (\r
+  IN SCMI_CLOCK2_PROTOCOL   *This,\r
+  IN UINT32                 ClockId,\r
+  IN BOOLEAN                Enable\r
+  );\r
+\r
+typedef struct _SCMI_CLOCK2_PROTOCOL {\r
+  SCMI_CLOCK2_GET_VERSION           GetVersion;\r
+  SCMI_CLOCK2_GET_TOTAL_CLOCKS      GetTotalClocks;\r
+  SCMI_CLOCK2_GET_CLOCK_ATTRIBUTES  GetClockAttributes;\r
+  SCMI_CLOCK2_DESCRIBE_RATES        DescribeRates;\r
+  SCMI_CLOCK2_RATE_GET              RateGet;\r
+  SCMI_CLOCK2_RATE_SET              RateSet;\r
+\r
+  // Extension to original ClockProtocol, added here so SCMI_CLOCK2_PROTOCOL\r
+  // can be cast to SCMI_CLOCK_PROTOCOL\r
+  UINTN                             Version; // For future expandability\r
+  SCMI_CLOCK2_ENABLE                Enable;\r
+} SCMI_CLOCK2_PROTOCOL;\r
+\r
+#endif /* ARM_SCMI_CLOCK2_PROTOCOL_H_ */\r