]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPkg/Drivers/ArmScmiDxe/ScmiDxe.c
0400799b5c521dcfa2ce866b0ffd48530e8cf0d1
[mirror_edk2.git] / ArmPkg / Drivers / ArmScmiDxe / ScmiDxe.c
1 /** @file
2
3 Copyright (c) 2017-2018, Arm Limited. All rights reserved.
4
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 System Control and Management Interface V1.0
14 http://infocenter.arm.com/help/topic/com.arm.doc.den0056a/
15 DEN0056A_System_Control_and_Management_Interface.pdf
16 **/
17
18 #include <Base.h>
19 #include <Library/DebugLib.h>
20 #include <Library/MemoryAllocationLib.h>
21 #include <Library/UefiBootServicesTableLib.h>
22 #include <Protocol/ArmScmiBaseProtocol.h>
23 #include <Protocol/ArmScmiClockProtocol.h>
24 #include <Protocol/ArmScmiPerformanceProtocol.h>
25
26 #include "ArmScmiBaseProtocolPrivate.h"
27 #include "ArmScmiClockProtocolPrivate.h"
28 #include "ArmScmiPerformanceProtocolPrivate.h"
29 #include "ScmiDxe.h"
30 #include "ScmiPrivate.h"
31
32 STATIC CONST SCMI_PROTOCOL_ENTRY Protocols[] = {
33 { SCMI_PROTOCOL_ID_BASE, ScmiBaseProtocolInit },
34 { SCMI_PROTOCOL_ID_PERFORMANCE, ScmiPerformanceProtocolInit },
35 { SCMI_PROTOCOL_ID_CLOCK, ScmiClockProtocolInit }
36 };
37
38 /** ARM SCMI driver entry point function.
39
40 This function installs the SCMI Base protocol and a list of other
41 protocols is queried using the Base protocol. If protocol is supported,
42 driver will call each protocol init function to install the protocol on
43 the ImageHandle.
44
45 @param[in] ImageHandle Handle to this EFI Image which will be used to
46 install Base, Clock and Performance protocols.
47 @param[in] SystemTable A pointer to boot time system table.
48
49 @retval EFI_SUCCESS Driver initalized successfully.
50 @retval EFI_UNSUPPORTED If SCMI base protocol version is not supported.
51 @retval !(EFI_SUCCESS) Other errors.
52 **/
53 EFI_STATUS
54 EFIAPI
55 ArmScmiDxeEntryPoint (
56 IN EFI_HANDLE ImageHandle,
57 IN EFI_SYSTEM_TABLE *SystemTable
58 )
59 {
60 EFI_STATUS Status;
61 SCMI_BASE_PROTOCOL *BaseProtocol;
62 UINT32 Version;
63 UINT32 Index;
64 UINT32 NumProtocols;
65 UINT32 ProtocolIndex;
66 UINT8 *SupportedList;
67 UINT32 SupportedListSize;
68
69 // Every SCMI implementation must implement the base protocol.
70 ASSERT (Protocols[0].Id == SCMI_PROTOCOL_ID_BASE);
71
72 Status = ScmiBaseProtocolInit (&ImageHandle);
73 if (EFI_ERROR (Status)) {
74 ASSERT (FALSE);
75 return Status;
76 }
77
78 Status = gBS->LocateProtocol (
79 &gArmScmiBaseProtocolGuid,
80 NULL,
81 (VOID**)&BaseProtocol
82 );
83 if (EFI_ERROR (Status)) {
84 ASSERT (FALSE);
85 return Status;
86 }
87
88 // Get SCMI Base protocol version.
89 Status = BaseProtocol->GetVersion (BaseProtocol, &Version);
90 if (EFI_ERROR (Status)) {
91 ASSERT (FALSE);
92 return Status;
93 }
94
95 if (Version != BASE_PROTOCOL_VERSION) {
96 ASSERT (FALSE);
97 return EFI_UNSUPPORTED;
98 }
99
100 // Apart from Base protocol, SCMI may implement various other protocols,
101 // query total protocols implemented by the SCP firmware.
102 NumProtocols = 0;
103 Status = BaseProtocol->GetTotalProtocols (BaseProtocol, &NumProtocols);
104 if (EFI_ERROR (Status)) {
105 ASSERT (FALSE);
106 return Status;
107 }
108
109 ASSERT (NumProtocols != 0);
110
111 SupportedListSize = (NumProtocols * sizeof (*SupportedList));
112
113 Status = gBS->AllocatePool (
114 EfiBootServicesData,
115 SupportedListSize,
116 (VOID**)&SupportedList
117 );
118 if (EFI_ERROR (Status)) {
119 ASSERT (FALSE);
120 return Status;
121 }
122
123 // Get the list of protocols supported by SCP firmware on the platform.
124 Status = BaseProtocol->DiscoverListProtocols (
125 BaseProtocol,
126 &SupportedListSize,
127 SupportedList
128 );
129 if (EFI_ERROR (Status)) {
130 gBS->FreePool (SupportedList);
131 ASSERT (FALSE);
132 return Status;
133 }
134
135 // Install supported protocol on ImageHandle.
136 for (ProtocolIndex = 1; ProtocolIndex < ARRAY_SIZE (Protocols);
137 ProtocolIndex++) {
138 for (Index = 0; Index < NumProtocols; Index++) {
139 if (Protocols[ProtocolIndex].Id == SupportedList[Index]) {
140 Status = Protocols[ProtocolIndex].InitFn (&ImageHandle);
141 if (EFI_ERROR (Status)) {
142 ASSERT_EFI_ERROR (Status);
143 return Status;
144 }
145 break;
146 }
147 }
148 }
149
150 gBS->FreePool (SupportedList);
151
152 return EFI_SUCCESS;
153 }