3 Copyright (c) 2017-2021, Arm Limited. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
7 @par Specification Reference:
8 - Arm System Control and Management Interface - Platform Design Document
9 (https://developer.arm.com/documentation/den0056/)
13 #include <Library/DebugLib.h>
14 #include <Library/MemoryAllocationLib.h>
15 #include <Library/UefiBootServicesTableLib.h>
16 #include <Protocol/ArmScmiBaseProtocol.h>
17 #include <Protocol/ArmScmiClockProtocol.h>
18 #include <Protocol/ArmScmiPerformanceProtocol.h>
20 #include "ArmScmiBaseProtocolPrivate.h"
21 #include "ArmScmiClockProtocolPrivate.h"
22 #include "ArmScmiPerformanceProtocolPrivate.h"
24 #include "ScmiPrivate.h"
26 STATIC CONST SCMI_PROTOCOL_ENTRY Protocols
[] = {
27 { ScmiProtocolIdBase
, ScmiBaseProtocolInit
},
28 { ScmiProtocolIdPerformance
, ScmiPerformanceProtocolInit
},
29 { ScmiProtocolIdClock
, ScmiClockProtocolInit
}
32 /** ARM SCMI driver entry point function.
34 This function installs the SCMI Base protocol and a list of other
35 protocols is queried using the Base protocol. If protocol is supported,
36 driver will call each protocol init function to install the protocol on
39 @param[in] ImageHandle Handle to this EFI Image which will be used to
40 install Base, Clock and Performance protocols.
41 @param[in] SystemTable A pointer to boot time system table.
43 @retval EFI_SUCCESS Driver initalized successfully.
44 @retval EFI_UNSUPPORTED If SCMI base protocol version is not supported.
45 @retval !(EFI_SUCCESS) Other errors.
49 ArmScmiDxeEntryPoint (
50 IN EFI_HANDLE ImageHandle
,
51 IN EFI_SYSTEM_TABLE
*SystemTable
55 SCMI_BASE_PROTOCOL
*BaseProtocol
;
61 UINT32 SupportedListSize
;
63 // Every SCMI implementation must implement the base protocol.
64 ASSERT (Protocols
[0].Id
== ScmiProtocolIdBase
);
66 Status
= ScmiBaseProtocolInit (&ImageHandle
);
67 if (EFI_ERROR (Status
)) {
72 Status
= gBS
->LocateProtocol (
73 &gArmScmiBaseProtocolGuid
,
75 (VOID
**)&BaseProtocol
77 if (EFI_ERROR (Status
)) {
82 // Get SCMI Base protocol version.
83 Status
= BaseProtocol
->GetVersion (BaseProtocol
, &Version
);
84 if (EFI_ERROR (Status
)) {
89 // Accept any version between SCMI v1.0 and SCMI v2.0
90 if ((Version
< BASE_PROTOCOL_VERSION_V1
) ||
91 (Version
> BASE_PROTOCOL_VERSION_V2
))
94 return EFI_UNSUPPORTED
;
97 // Apart from Base protocol, SCMI may implement various other protocols,
98 // query total protocols implemented by the SCP firmware.
100 Status
= BaseProtocol
->GetTotalProtocols (BaseProtocol
, &NumProtocols
);
101 if (EFI_ERROR (Status
)) {
106 ASSERT (NumProtocols
!= 0);
108 SupportedListSize
= (NumProtocols
* sizeof (*SupportedList
));
110 Status
= gBS
->AllocatePool (
113 (VOID
**)&SupportedList
115 if (EFI_ERROR (Status
)) {
120 // Get the list of protocols supported by SCP firmware on the platform.
121 Status
= BaseProtocol
->DiscoverListProtocols (
126 if (EFI_ERROR (Status
)) {
127 gBS
->FreePool (SupportedList
);
132 // Install supported protocol on ImageHandle.
133 for (ProtocolIndex
= 1; ProtocolIndex
< ARRAY_SIZE (Protocols
);
136 for (Index
= 0; Index
< NumProtocols
; Index
++) {
137 if (Protocols
[ProtocolIndex
].Id
== SupportedList
[Index
]) {
138 Status
= Protocols
[ProtocolIndex
].InitFn (&ImageHandle
);
139 if (EFI_ERROR (Status
)) {
140 ASSERT_EFI_ERROR (Status
);
149 gBS
->FreePool (SupportedList
);