]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPkg/Drivers/ArmScmiDxe/ScmiDxe.c
ArmPkg: Apply uncrustify changes
[mirror_edk2.git] / ArmPkg / Drivers / ArmScmiDxe / ScmiDxe.c
1 /** @file
2
3 Copyright (c) 2017-2021, Arm Limited. All rights reserved.<BR>
4
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 @par Specification Reference:
8 - Arm System Control and Management Interface - Platform Design Document
9 (https://developer.arm.com/documentation/den0056/)
10 **/
11
12 #include <Base.h>
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>
19
20 #include "ArmScmiBaseProtocolPrivate.h"
21 #include "ArmScmiClockProtocolPrivate.h"
22 #include "ArmScmiPerformanceProtocolPrivate.h"
23 #include "ScmiDxe.h"
24 #include "ScmiPrivate.h"
25
26 STATIC CONST SCMI_PROTOCOL_ENTRY Protocols[] = {
27 { ScmiProtocolIdBase, ScmiBaseProtocolInit },
28 { ScmiProtocolIdPerformance, ScmiPerformanceProtocolInit },
29 { ScmiProtocolIdClock, ScmiClockProtocolInit }
30 };
31
32 /** ARM SCMI driver entry point function.
33
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
37 the ImageHandle.
38
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.
42
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.
46 **/
47 EFI_STATUS
48 EFIAPI
49 ArmScmiDxeEntryPoint (
50 IN EFI_HANDLE ImageHandle,
51 IN EFI_SYSTEM_TABLE *SystemTable
52 )
53 {
54 EFI_STATUS Status;
55 SCMI_BASE_PROTOCOL *BaseProtocol;
56 UINT32 Version;
57 UINT32 Index;
58 UINT32 NumProtocols;
59 UINT32 ProtocolIndex;
60 UINT8 *SupportedList;
61 UINT32 SupportedListSize;
62
63 // Every SCMI implementation must implement the base protocol.
64 ASSERT (Protocols[0].Id == ScmiProtocolIdBase);
65
66 Status = ScmiBaseProtocolInit (&ImageHandle);
67 if (EFI_ERROR (Status)) {
68 ASSERT (FALSE);
69 return Status;
70 }
71
72 Status = gBS->LocateProtocol (
73 &gArmScmiBaseProtocolGuid,
74 NULL,
75 (VOID **)&BaseProtocol
76 );
77 if (EFI_ERROR (Status)) {
78 ASSERT (FALSE);
79 return Status;
80 }
81
82 // Get SCMI Base protocol version.
83 Status = BaseProtocol->GetVersion (BaseProtocol, &Version);
84 if (EFI_ERROR (Status)) {
85 ASSERT (FALSE);
86 return Status;
87 }
88
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))
92 {
93 ASSERT (FALSE);
94 return EFI_UNSUPPORTED;
95 }
96
97 // Apart from Base protocol, SCMI may implement various other protocols,
98 // query total protocols implemented by the SCP firmware.
99 NumProtocols = 0;
100 Status = BaseProtocol->GetTotalProtocols (BaseProtocol, &NumProtocols);
101 if (EFI_ERROR (Status)) {
102 ASSERT (FALSE);
103 return Status;
104 }
105
106 ASSERT (NumProtocols != 0);
107
108 SupportedListSize = (NumProtocols * sizeof (*SupportedList));
109
110 Status = gBS->AllocatePool (
111 EfiBootServicesData,
112 SupportedListSize,
113 (VOID **)&SupportedList
114 );
115 if (EFI_ERROR (Status)) {
116 ASSERT (FALSE);
117 return Status;
118 }
119
120 // Get the list of protocols supported by SCP firmware on the platform.
121 Status = BaseProtocol->DiscoverListProtocols (
122 BaseProtocol,
123 &SupportedListSize,
124 SupportedList
125 );
126 if (EFI_ERROR (Status)) {
127 gBS->FreePool (SupportedList);
128 ASSERT (FALSE);
129 return Status;
130 }
131
132 // Install supported protocol on ImageHandle.
133 for (ProtocolIndex = 1; ProtocolIndex < ARRAY_SIZE (Protocols);
134 ProtocolIndex++)
135 {
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);
141 return Status;
142 }
143
144 break;
145 }
146 }
147 }
148
149 gBS->FreePool (SupportedList);
150
151 return EFI_SUCCESS;
152 }