1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
|
/** @file
Multiple APIC Description Table (MADT)
Copyright (c) 2012 - 2014, ARM Ltd. All rights reserved.<BR>
Copyright (c) 2014 - 2016, AMD Inc. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
/**
Derived from:
ArmPlatformPkg/ArmJunoPkg/AcpiTables/Madt.aslc
**/
#include <Uefi.h>
#include <Library/ArmLib.h>
#include <Library/DebugLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Guid/ArmMpCoreInfo.h>
#include <AmdStyxAcpiLib.h>
#include <Protocol/AmdMpCoreInfo.h>
AMD_MP_CORE_INFO_PROTOCOL *mAmdMpCoreInfoProtocol = NULL;
// ARM PL390 General Interrupt Controller
#define GIC_BASE (FixedPcdGet64 (PcdGicInterruptInterfaceBase))
#define GICD_BASE (FixedPcdGet64 (PcdGicDistributorBase))
#define GICV_BASE (FixedPcdGet64 (PcdGicVirtualInterruptInterfaceBase))
#define GICH_BASE (FixedPcdGet64 (PcdGicHypervisorInterruptInterfaceBase))
#define VGIC_MAINT_INT (FixedPcdGet32 (PcdGicVirtualMaintenanceInterrupt))
#define GICVR_BASE (FixedPcdGet64 (PcdGicVirtualRegisterInterfaceBase))
#define GIC_MSI_FRAME (FixedPcdGet64 (PcdGicMSIFrameBase))
#define GIC_VERSION (FixedPcdGet8 (PcdGicVersion))
#define GICD_ID ( 0 )
#define GICD_VECTOR ( 0 )
#define GICM_ID ( 0 )
#define GICM_SPI_COUNT ( 0x100 )
#define GICM_SPI_BASE ( 0x40 )
#define GSIV_SPI_OFFSET ( 32 )
#if STYX_A0
#define MSI_TYPER_FLAG ( 1 ) // Ignore TYPER register and use Count/Base fields
#else
#define MSI_TYPER_FLAG ( 0 ) // Use TYPER register and ignore Count/Base fields
#endif
#define PARKING_PROTOCOL_VERSION (FixedPcdGet32 (PcdParkingProtocolVersion))
#define PARKED_OFFSET ( 4096 )
#define CORES_PER_CLUSTER (FixedPcdGet32 (PcdSocCoresPerCluster))
#define PARKED_ADDRESS(Base, ClusterId, CoreId) \
((Base) + (CORES_PER_CLUSTER * ClusterId + CoreId) * PARKED_OFFSET)
/* Macro to populate EFI_ACPI_5_1_GIC_STRUCTURE */
#define AMD_GIC(CpuNum, ClusterId, CoreId, PerfInt) { \
EFI_ACPI_5_1_GIC, /* UINT8 Type */ \
sizeof (EFI_ACPI_5_1_GIC_STRUCTURE), /* UINT8 Length */ \
EFI_ACPI_RESERVED_WORD, /* UINT16 Reserved */ \
CpuNum, /* UINT32 CPUInterfaceNumber */ \
(ClusterId << 8) | CoreId, /* UINT32 AcpiProcessorUid */ \
EFI_ACPI_5_1_GIC_ENABLED, /* UINT32 Flags */ \
PARKING_PROTOCOL_VERSION, /* UINT32 ParkingProtocolVersion */ \
PerfInt, /* UINT32 PerformanceInterruptGsiv */ \
0, /* UINT64 ParkedAddress */ \
GIC_BASE, /* UINT64 PhysicalBaseAddress */ \
GICV_BASE, /* UINT64 GICV */ \
GICH_BASE, /* UINT64 GICH */ \
VGIC_MAINT_INT, /* UINT32 VGICMaintenanceInterrupt */ \
GICVR_BASE, /* UINT64 GICRBaseAddress */ \
(ClusterId << 8) | CoreId /* UINT64 MPIDR */ \
}
/* Macro to initialise EFI_ACPI_5_1_GIC_DISTRIBUTOR_STRUCTURE */
#define AMD_GICD(Id, Vec) { \
EFI_ACPI_5_1_GICD, /* UINT8 Type */ \
sizeof (EFI_ACPI_5_1_GIC_DISTRIBUTOR_STRUCTURE), /* UINT8 Length */ \
EFI_ACPI_RESERVED_WORD, /* UINT16 Reserved1 */ \
Id, /* UINT32 GicId */ \
GICD_BASE, /* UINT64 PhysicalBaseAddress */ \
Vec, /* UINT32 SystemVectorBase */ \
EFI_ACPI_RESERVED_DWORD /* UINT32 Reserved2 */ \
}
/* Macro to initialise EFI_ACPI_5_1_GIC_MSI_FRAME_STRUCTURE */
#define AMD_GICM(Id, SpiCount, SpiBase) { \
EFI_ACPI_5_1_GIC_MSI_FRAME, /* UINT8 Type */ \
sizeof(EFI_ACPI_5_1_GIC_MSI_FRAME_STRUCTURE), /* UINT8 Length */ \
EFI_ACPI_RESERVED_WORD, /* UINT16 Reserved1 */ \
Id, /* UINT32 GicMsiFrameId */ \
GIC_MSI_FRAME, /* UINT64 PhysicalBaseAddress */ \
MSI_TYPER_FLAG, /* UINT32 Flags */ \
SpiCount, /* UINT16 SPICount */ \
SpiBase /* UINT16 SPIBase */ \
}
//
// NOTE: NUM_CORES is a pre-processor macro passed in with -D option
//
#pragma pack(push, 1)
typedef struct {
EFI_ACPI_5_1_MULTIPLE_APIC_DESCRIPTION_TABLE_HEADER Header;
EFI_ACPI_5_1_GIC_STRUCTURE GicC[NUM_CORES];
EFI_ACPI_5_1_GIC_DISTRIBUTOR_STRUCTURE GicD;
EFI_ACPI_5_1_GIC_MSI_FRAME_STRUCTURE GicM;
} EFI_ACPI_5_1_ARM_MADT_STRUCTURE;
#pragma pack(pop)
STATIC EFI_ACPI_5_1_ARM_MADT_STRUCTURE AcpiMadt = {
{
AMD_ACPI_HEADER (EFI_ACPI_5_1_MULTIPLE_APIC_DESCRIPTION_TABLE_SIGNATURE,
EFI_ACPI_5_1_ARM_MADT_STRUCTURE,
EFI_ACPI_5_1_MULTIPLE_APIC_DESCRIPTION_TABLE_REVISION),
GIC_BASE, // UINT32 LocalApicAddress
0 // UINT32 Flags
},
{
/*
* GIC Interface for Cluster 0 CPU 0
*/
AMD_GIC(0, 0, 0, 39), // EFI_ACPI_5_1_GIC_STRUCTURE
#if (NUM_CORES > 1)
/*
* GIC Interface for Cluster 0 CPU 1
*/
AMD_GIC(1, 0, 1, 40), // EFI_ACPI_5_1_GIC_STRUCTURE
#endif
#if (NUM_CORES > 2)
/*
* GIC Interface for Cluster 1 CPU 0
*/
AMD_GIC(2, 1, 0, 41), // EFI_ACPI_5_1_GIC_STRUCTURE
#endif
#if (NUM_CORES > 3)
/*
* GIC Interface for Cluster 1 CPU 1
*/
AMD_GIC(3, 1, 1, 42), // EFI_ACPI_5_1_GIC_STRUCTURE
#endif
#if (NUM_CORES > 4)
/*
* GIC Interface for Cluster 2 CPU 0
*/
AMD_GIC(4, 2, 0, 43), // EFI_ACPI_5_1_GIC_STRUCTURE
#endif
#if (NUM_CORES > 5)
/*
* GIC Interface for Cluster 2 CPU 1
*/
AMD_GIC(5, 2, 1, 44), // EFI_ACPI_5_1_GIC_STRUCTURE
#endif
#if (NUM_CORES > 6)
/*
* GIC Interface for Cluster 3 CPU 0
*/
AMD_GIC(6, 3, 0, 45), // EFI_ACPI_5_1_GIC_STRUCTURE
#endif
#if (NUM_CORES > 7)
/*
* GIC Interface for Cluster 3 CPU 1
*/
AMD_GIC(7, 3, 1, 46), // EFI_ACPI_5_1_GIC_STRUCTURE
#endif
},
/*
* GIC Distributor
*/
AMD_GICD(GICD_ID, GICD_VECTOR), // EFI_ACPI_5_1_GIC_DISTRIBUTOR_STRUCTURE
/*
* GIC MSI Frame
*/
AMD_GICM(GICM_ID, GICM_SPI_COUNT, GICM_SPI_BASE),
};
STATIC
EFI_STATUS
BuildGicC (
EFI_ACPI_5_1_GIC_STRUCTURE *GicC,
UINT32 CpuNum,
UINT32 ClusterId,
UINT32 CoreId,
EFI_PHYSICAL_ADDRESS MpParkingBase
)
{
UINT32 MpId, PmuSpi;
EFI_STATUS Status;
MpId = (UINT32) GET_MPID (ClusterId, CoreId);
Status = mAmdMpCoreInfoProtocol->GetPmuSpiFromMpId (MpId, &PmuSpi);
if (EFI_ERROR (Status))
return Status;
GicC->Type = EFI_ACPI_5_1_GIC;
GicC->Length = sizeof (EFI_ACPI_5_1_GIC_STRUCTURE);
GicC->Reserved = EFI_ACPI_RESERVED_WORD;
GicC->CPUInterfaceNumber = CpuNum;
GicC->AcpiProcessorUid = MpId;
GicC->Flags = EFI_ACPI_5_1_GIC_ENABLED;
GicC->ParkingProtocolVersion = PARKING_PROTOCOL_VERSION;
GicC->ParkedAddress = PARKED_ADDRESS(MpParkingBase, ClusterId, CoreId);
GicC->PhysicalBaseAddress = GIC_BASE;
GicC->GICV = GICV_BASE;
GicC->GICH = GICH_BASE;
GicC->VGICMaintenanceInterrupt = VGIC_MAINT_INT;
GicC->GICRBaseAddress = GICVR_BASE;
GicC->PerformanceInterruptGsiv = PmuSpi + GSIV_SPI_OFFSET;
GicC->MPIDR = MpId;
return EFI_SUCCESS;
}
STATIC
VOID
BuildGicD (
EFI_ACPI_5_1_GIC_DISTRIBUTOR_STRUCTURE *GicD,
UINT32 GicId,
UINT32 SystemVectorBase
)
{
GicD->Type = EFI_ACPI_5_1_GICD;
GicD->Length = sizeof (EFI_ACPI_5_1_GIC_DISTRIBUTOR_STRUCTURE);
GicD->Reserved1 = EFI_ACPI_RESERVED_WORD;
GicD->GicId = GicId;
GicD->PhysicalBaseAddress = GICD_BASE;
GicD->SystemVectorBase = SystemVectorBase;
#if 0
GicD->Reserved2 = EFI_ACPI_RESERVED_DWORD;
#else
GicD->GicVersion = EFI_ACPI_RESERVED_BYTE;
GicD->Reserved2[0] = EFI_ACPI_RESERVED_BYTE;
GicD->Reserved2[1] = EFI_ACPI_RESERVED_BYTE;
GicD->Reserved2[2] = EFI_ACPI_RESERVED_BYTE;
#endif
}
STATIC
VOID
BuildGicM (
EFI_ACPI_5_1_GIC_MSI_FRAME_STRUCTURE *GicM,
UINT32 MsiFrameId,
UINT16 SpiCount,
UINT16 SpiBase
)
{
GicM->Type = EFI_ACPI_5_1_GIC_MSI_FRAME;
GicM->Length = sizeof(EFI_ACPI_5_1_GIC_MSI_FRAME_STRUCTURE);
GicM->Reserved1 = EFI_ACPI_RESERVED_WORD;
GicM->GicMsiFrameId = MsiFrameId;
GicM->PhysicalBaseAddress = GIC_MSI_FRAME;
GicM->Flags = MSI_TYPER_FLAG;
GicM->SPICount = SpiCount;
GicM->SPIBase = SpiBase;
}
EFI_ACPI_DESCRIPTION_HEADER *
MadtHeader (
VOID
)
{
EFI_ACPI_5_1_GIC_STRUCTURE *GicC;
EFI_ACPI_5_1_GIC_DISTRIBUTOR_STRUCTURE *GicD;
EFI_ACPI_5_1_GIC_MSI_FRAME_STRUCTURE *GicM;
ARM_CORE_INFO *ArmCoreInfoTable;
UINTN CoreCount, CpuNum;
EFI_STATUS Status;
EFI_PHYSICAL_ADDRESS MpParkingBase;
UINTN MpParkingSize;
Status = gBS->LocateProtocol (
&gAmdMpCoreInfoProtocolGuid,
NULL,
(VOID **)&mAmdMpCoreInfoProtocol
);
ASSERT_EFI_ERROR (Status);
// Get pointer to ARM core info table
ArmCoreInfoTable = mAmdMpCoreInfoProtocol->GetArmCoreInfoTable (&CoreCount);
ASSERT (ArmCoreInfoTable != NULL);
// Make sure SoC's core count does not exceed what we want to build
ASSERT (CoreCount <= NUM_CORES);
ASSERT (CoreCount <= PcdGet32(PcdSocCoreCount));
MpParkingSize = 0;
MpParkingBase = mAmdMpCoreInfoProtocol->GetMpParkingBase(&MpParkingSize);
if (MpParkingBase && MpParkingSize < (CoreCount * SIZE_4KB)) {
DEBUG ((EFI_D_ERROR, "MADT: Parking Protocol not supported.\n"));
MpParkingBase = 0;
}
GicC = (EFI_ACPI_5_1_GIC_STRUCTURE *)&AcpiMadt.GicC[0];
AcpiMadt.Header.Header.Length = sizeof (EFI_ACPI_5_1_MULTIPLE_APIC_DESCRIPTION_TABLE_HEADER);
for (CpuNum = 0; CpuNum < CoreCount; ++CpuNum, ++GicC) {
DEBUG ((EFI_D_ERROR, "MADT: Core[%d]: ClusterId = %d CoreId = %d\n",
CpuNum, ArmCoreInfoTable[CpuNum].ClusterId, ArmCoreInfoTable[CpuNum].CoreId));
Status = BuildGicC (GicC, CpuNum,
ArmCoreInfoTable[CpuNum].ClusterId,
ArmCoreInfoTable[CpuNum].CoreId,
MpParkingBase
);
ASSERT_EFI_ERROR (Status);
AcpiMadt.Header.Header.Length += sizeof (EFI_ACPI_5_1_GIC_STRUCTURE);
}
GicD = (EFI_ACPI_5_1_GIC_DISTRIBUTOR_STRUCTURE *)(UINT8 *)((UINTN)&AcpiMadt + (UINTN)AcpiMadt.Header.Header.Length);
BuildGicD (GicD, GICD_ID, GICD_VECTOR);
AcpiMadt.Header.Header.Length += sizeof (EFI_ACPI_5_1_GIC_DISTRIBUTOR_STRUCTURE);
GicM = (EFI_ACPI_5_1_GIC_MSI_FRAME_STRUCTURE *)(UINT8 *)((UINTN)&AcpiMadt + (UINTN)AcpiMadt.Header.Header.Length);
BuildGicM (GicM, GICM_ID, GICM_SPI_COUNT, GICM_SPI_BASE);
AcpiMadt.Header.Header.Length += sizeof (EFI_ACPI_5_1_GIC_MSI_FRAME_STRUCTURE);
return &AcpiMadt.Header.Header;
}
|