TianoCore EDK2 master
Loading...
Searching...
No Matches
ScmiDxe.c
Go to the documentation of this file.
1
12#include <Base.h>
13#include <Library/DebugLib.h>
19
23#include "ScmiDxe.h"
24#include "ScmiPrivate.h"
25
26STATIC CONST SCMI_PROTOCOL_ENTRY Protocols[] = {
27 { ScmiProtocolIdBase, ScmiBaseProtocolInit },
28 { ScmiProtocolIdPerformance, ScmiPerformanceProtocolInit },
29 { ScmiProtocolIdClock, ScmiClockProtocolInit }
30};
31
48EFIAPI
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 (
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}
EFI_STATUS ScmiBaseProtocolInit(IN OUT EFI_HANDLE *Handle)
EFI_STATUS ScmiClockProtocolInit(IN EFI_HANDLE *Handle)
EFI_STATUS ScmiPerformanceProtocolInit(IN EFI_HANDLE *Handle)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define STATIC
Definition: Base.h:264
#define FALSE
Definition: Base.h:307
#define ARRAY_SIZE(Array)
Definition: Base.h:1393
#define IN
Definition: Base.h:279
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
EFI_STATUS EFIAPI ArmScmiDxeEntryPoint(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: ScmiDxe.c:49
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
@ EfiBootServicesData