Skip to content

Commit 98e1008

Browse files
committed
Silicon/RK3588: Fix MCFG when CFG0 TLPs are being correctly filtered
Some devices (either single or multi-function) manage to appear only once, so we must expose the original ECAM base in this case, starting from dev 0.
1 parent 105f7b9 commit 98e1008

File tree

7 files changed

+97
-29
lines changed

7 files changed

+97
-29
lines changed

edk2-rockchip/Silicon/Rockchip/RK3588/AcpiTables/Mcfg.aslc

+3-15
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,17 @@
99
*
1010
**/
1111

12-
#include <IndustryStandard/Acpi.h>
13-
#include <IndustryStandard/MemoryMappedConfigurationSpaceAccessTable.h>
1412
#include "AcpiTables.h"
1513

16-
#pragma pack(push, 1)
17-
1814
//
19-
// The root port config is not part of ECAM.
20-
// OSes can parse additional config spaces in MCFG, but we'll hide it for now.
15+
// MCFG may get patched by AcpiPlatformDxe.
2116
//
2217

23-
typedef struct {
24-
EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_BASE_ADDRESS_TABLE_HEADER Header;
25-
EFI_ACPI_MEMORY_MAPPED_ENHANCED_CONFIGURATION_SPACE_BASE_ADDRESS_ALLOCATION_STRUCTURE Entry[5];
26-
} EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_SPACE_ACCESS_DESCRIPTION_TABLE;
27-
28-
EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_SPACE_ACCESS_DESCRIPTION_TABLE Mcfg = {
18+
RK3588_MCFG_TABLE Mcfg = {
2919
{
3020
ACPI_HEADER (
3121
EFI_ACPI_6_4_PCI_EXPRESS_MEMORY_MAPPED_CONFIGURATION_SPACE_BASE_ADDRESS_DESCRIPTION_TABLE_SIGNATURE,
32-
EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_SPACE_ACCESS_DESCRIPTION_TABLE,
22+
RK3588_MCFG_TABLE,
3323
EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_SPACE_ACCESS_TABLE_REVISION
3424
),
3525
},
@@ -72,6 +62,4 @@ EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_SPACE_ACCESS_DESCRIPTION_TABLE Mcfg = {
7262
}
7363
};
7464

75-
#pragma pack(pop)
76-
7765
VOID* CONST ReferenceAcpiTable = &Mcfg;

edk2-rockchip/Silicon/Rockchip/RK3588/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.c

+51-12
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include <Library/AcpiLib.h>
1313
#include <Library/BaseMemoryLib.h>
1414
#include <Library/DebugLib.h>
15+
#include <Library/UefiBootServicesTableLib.h>
16+
#include <AcpiTables.h>
1517
#include <VarStoreData.h>
1618

1719
STATIC CONST EFI_GUID mAcpiTableFile = {
@@ -153,12 +155,26 @@ AcpiVerifyUpdateTable (
153155
return Result;
154156
}
155157

156-
//
157-
// Monitor the ACPI tables being installed and when
158-
// a DSDT/SSDT is detected validate that we want to
159-
// install it, and if so update any "NameOp" defined
160-
// variables contained in the table from PCD values
161-
//
158+
STATIC
159+
BOOLEAN
160+
AcpiFixupMcfg (
161+
IN EFI_ACPI_DESCRIPTION_HEADER *AcpiHeader
162+
)
163+
{
164+
RK3588_MCFG_TABLE *Table;
165+
UINT32 Seg;
166+
167+
Table = (RK3588_MCFG_TABLE *) AcpiHeader;
168+
169+
for (Seg = 0; Seg < ARRAY_SIZE (Table->Entry); Seg++) {
170+
if ((PcdGet32 (PcdPcieEcamCompliantSegmentsMask) & (1 << Seg)) != 0) {
171+
Table->Entry[Seg].BaseAddress -= 0x8000;
172+
}
173+
}
174+
175+
return TRUE;
176+
}
177+
162178
STATIC
163179
BOOLEAN
164180
AcpiHandleDynamicNamespace (
@@ -169,11 +185,30 @@ AcpiHandleDynamicNamespace (
169185
case SIGNATURE_32 ('D', 'S', 'D', 'T'):
170186
case SIGNATURE_32 ('S', 'S', 'D', 'T'):
171187
return AcpiVerifyUpdateTable (AcpiHeader);
188+
case SIGNATURE_32 ('M', 'C', 'F', 'G'):
189+
return AcpiFixupMcfg (AcpiHeader);
172190
}
173191

174192
return TRUE;
175193
}
176194

195+
STATIC
196+
VOID
197+
EFIAPI
198+
NotifyEndOfDxeEvent (
199+
IN EFI_EVENT Event,
200+
IN VOID *Context
201+
)
202+
{
203+
EFI_STATUS Status;
204+
205+
Status = LocateAndInstallAcpiFromFvConditional (&mAcpiTableFile, &AcpiHandleDynamicNamespace);
206+
if (EFI_ERROR (Status)) {
207+
DEBUG ((DEBUG_WARN, "AcpiPlatform: Failed to install firmware ACPI as config table. Status=%r\n",
208+
Status));
209+
}
210+
}
211+
177212
EFI_STATUS
178213
EFIAPI
179214
AcpiPlatformDxeInitialize (
@@ -182,18 +217,22 @@ AcpiPlatformDxeInitialize (
182217
)
183218
{
184219
EFI_STATUS Status;
220+
EFI_EVENT Event;
185221

186222
if ((PcdGet32 (PcdConfigTableMode) & CONFIG_TABLE_MODE_ACPI) == 0) {
187223
DEBUG ((DEBUG_WARN, "AcpiPlatform: ACPI support is disabled by the settings.\n"));
188224
return EFI_UNSUPPORTED;
189225
}
190226

191-
Status = LocateAndInstallAcpiFromFvConditional (&mAcpiTableFile, &AcpiHandleDynamicNamespace);
192-
if (EFI_ERROR (Status)) {
193-
DEBUG ((DEBUG_WARN, "AcpiPlatform: Failed to install firmware ACPI as config table. Status=%r\n",
194-
Status));
195-
return Status;
196-
}
227+
Status = gBS->CreateEventEx (
228+
EVT_NOTIFY_SIGNAL, // Type
229+
TPL_CALLBACK, // NotifyTpl
230+
NotifyEndOfDxeEvent, // NotifyFunction
231+
NULL, // NotifyContext
232+
&gEfiEndOfDxeEventGroupGuid, // EventGroup
233+
&Event // Event
234+
);
235+
ASSERT_EFI_ERROR (Status);
197236

198237
return EFI_SUCCESS;
199238
}

edk2-rockchip/Silicon/Rockchip/RK3588/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf

+3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@
3030
AcpiLib
3131
BaseMemoryLib
3232
DebugLib
33+
UefiBootServicesTableLib
3334
UefiDriverEntryPoint
3435

3536
[Guids]
37+
gEfiEndOfDxeEventGroupGuid
3638

3739
[Protocols]
3840

@@ -44,6 +46,7 @@
4446
gRK3588TokenSpaceGuid.PcdComboPhy2Mode
4547
gRK3588TokenSpaceGuid.PcdPcie30Supported
4648
gRK3588TokenSpaceGuid.PcdPcie30State
49+
gRK3588TokenSpaceGuid.PcdPcieEcamCompliantSegmentsMask
4750

4851
[Depex]
4952
gRockchipPlatformConfigAppliedProtocolGuid

edk2-rockchip/Silicon/Rockchip/RK3588/Include/AcpiTables.h

+8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#define __ACPITABLES_H__
1616

1717
#include <IndustryStandard/Acpi.h>
18+
#include <IndustryStandard/MemoryMappedConfigurationSpaceAccessTable.h>
1819

1920
#define EFI_ACPI_OEM_ID {'R','K','C','P',' ',' '}
2021

@@ -58,4 +59,11 @@
5859
0 \
5960
}
6061

62+
#pragma pack(push, 1)
63+
typedef struct {
64+
EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_BASE_ADDRESS_TABLE_HEADER Header;
65+
EFI_ACPI_MEMORY_MAPPED_ENHANCED_CONFIGURATION_SPACE_BASE_ADDRESS_ALLOCATION_STRUCTURE Entry[5];
66+
} RK3588_MCFG_TABLE;
67+
#pragma pack(pop)
68+
6169
#endif // __ACPITABLES_H__

edk2-rockchip/Silicon/Rockchip/RK3588/Library/Rk3588PciHostBridgeLib/PciHostBridgeInit.c

+27-2
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ PciePinmuxInit(
197197
ASSERT(MuxNum < 2);
198198
GpioSetIomuxConfig(&mPcie20x1_2_IomuxConfigs[MuxNum][0], 3);
199199
break;
200-
200+
201201
default:
202202
return;
203203
}
@@ -255,7 +255,7 @@ PciSetupClocks (
255255
default:
256256
break;
257257
}
258-
258+
259259
}
260260

261261
STATIC
@@ -448,6 +448,29 @@ PciSetupAtu (
448448
gBS->Stall (10000);
449449
}
450450

451+
STATIC
452+
VOID
453+
PciValidateCfg0 (
454+
IN UINT32 Segment,
455+
IN EFI_PHYSICAL_ADDRESS Cfg0Base
456+
)
457+
{
458+
EFI_STATUS Status;
459+
460+
//
461+
// If the downstream device doesn't appear mirrored, config accesses
462+
// must not be shifted by 0x8000 anymore.
463+
//
464+
if (MmioRead32 (Cfg0Base) != 0xffffffff
465+
&& MmioRead32 (Cfg0Base + 0x8000) == 0xffffffff) {
466+
Status = PcdSet32S (PcdPcieEcamCompliantSegmentsMask,
467+
PcdGet32 (PcdPcieEcamCompliantSegmentsMask) | (1 << Segment));
468+
ASSERT_EFI_ERROR (Status);
469+
470+
DEBUG((DEBUG_INFO, "PCIe: Working CFG0 TLP filtering for connected device!\n"));
471+
}
472+
}
473+
451474
EFI_STATUS
452475
InitializePciHost (
453476
UINT32 Segment
@@ -564,5 +587,7 @@ InitializePciHost (
564587
PciGetLinkSpeedWidth (DbiBase, &LinkSpeed, &LinkWidth);
565588
PciPrintLinkSpeedWidth (LinkSpeed, LinkWidth);
566589

590+
PciValidateCfg0 (Segment, PcieBase + Cfg0Base);
591+
567592
return EFI_SUCCESS;
568593
}

edk2-rockchip/Silicon/Rockchip/RK3588/Library/Rk3588PciHostBridgeLib/Rk3588PciHostBridgeLib.inf

+2
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,5 @@
5151
gRK3588TokenSpaceGuid.PcdComboPhy2Mode
5252

5353
gRK3588TokenSpaceGuid.PcdPcie30State
54+
55+
gRK3588TokenSpaceGuid.PcdPcieEcamCompliantSegmentsMask

edk2-rockchip/Silicon/Rockchip/RK3588/RK3588.dec

+3
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,6 @@
8888

8989
gRK3588TokenSpaceGuid.PcdUsbDpPhy0Usb3State|0|UINT32|0x00000501
9090
gRK3588TokenSpaceGuid.PcdUsbDpPhy1Usb3State|0|UINT32|0x00000502
91+
92+
[PcdsDynamicEx]
93+
gRK3588TokenSpaceGuid.PcdPcieEcamCompliantSegmentsMask|0|UINT32|0x20000001

0 commit comments

Comments
 (0)