WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit b774d8d

Browse files
committed
Pcie30PhyLib: Assorted fixes
- Clean up dead code. - Perform init only once. This fixes an issue in bifurcation mode where PCIe 3x2 init would reset the PHY, forcing the previously configured PCIe 3x4 link to restart at the lowest speed. - Set PHP_GRF_PCIESEL_CON to fix routing of PCIe3x1 controllers to the PCIe 3 PHY instead of the Combo PHY. - Wait for sram_init_done (does not seem necessary since sram_bypass=0x1, but just follow suit with the BSP code). Signed-off-by: Mario Bălănică <[email protected]>
1 parent 73d6d6a commit b774d8d

File tree

2 files changed

+62
-72
lines changed

2 files changed

+62
-72
lines changed

edk2-rockchip/Silicon/Rockchip/RK3588/Library/Pcie30PhyLib/Pcie30PhyLib.c

Lines changed: 56 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Copyright (c) 2023, David Gwynne <[email protected]>
66
* Copyright (c) 2023, Jared McNeill <[email protected]>
77
* Copyright (c) 2023, Molly Sophia <[email protected]>
8+
* Copyright (c) 2025, Mario Bălănică <[email protected]>
89
*
910
* SPDX-License-Identifier: BSD-2-Clause-Patent
1011
*
@@ -18,100 +19,85 @@
1819
#include <Library/CruLib.h>
1920
#include <Library/UefiBootServicesTableLib.h>
2021
#include <Library/PcdLib.h>
22+
#include <VarStoreData.h>
2123

22-
#define PCIE30_PHY_GRF 0xfd5b8000
23-
/* PCIEPHY_GRF */
24-
#define GRF_PCIE30_PHY_CON(n) (PCIE30_PHY_GRF + 0x0000 + (n) * 0x4) /* 0 .. 9 */
25-
#define GRF_PCIE30_PHY_STATUS(n) (PCIE30_PHY_GRF + 0x0080 + (n) * 0x4) /* 0 .. 2 */
26-
#define GRF_PCIE30_PHY_PRT0_CON(n) (PCIE30_PHY_GRF + 0x0100 + (n) * 0x4) /* 0 .. 39 */
27-
/* CON1 and CON9 */
28-
#define GRF_PCIE30PHY_DA_OCM_MASK BIT15
29-
#define GRF_PCIE30PHY_DA_OCM BIT15
30-
/* CON5 */
31-
#define GRF_PCIE30PHY_LANE0_LINK_NUM_SHIFT 0
32-
#define GRF_PCIE30PHY_LANE0_LINK_NUM_MASK (0xfU << GRF_PCIE30PHY_LANE0_LINK_NUM_SHIFT)
33-
/* CON6 */
34-
#define GRF_PCIE30PHY_LANE1_LINK_NUM_SHIFT 0
35-
#define GRF_PCIE30PHY_LANE1_LINK_NUM_MASK (0xfU << GRF_PCIE30PHY_LANE1_LINK_NUM_SHIFT)
36-
37-
/* STATUS0 */
38-
#define GRF_PCIE30PHY_SRAM_INIT_DONE BIT14
39-
40-
#define SOFTRST_INDEX 27
41-
#define SOFTRST_BIT 14
42-
43-
STATIC
44-
VOID
45-
GrfUpdateRegister (
46-
IN EFI_PHYSICAL_ADDRESS Reg,
47-
IN UINT32 Mask,
48-
IN UINT32 Val
49-
)
50-
{
51-
ASSERT ((Mask & ~0xFFFF) == 0);
52-
ASSERT ((Val & ~0xFFFF) == 0);
53-
ASSERT ((Mask & Val) == Val);
24+
#define PHP_GRF_BASE 0xfd5b0000
25+
#define PCIE3PHY_GRF_BASE 0xfd5b8000
5426

55-
MmioWrite32 (Reg, (Mask << 16) | Val);
56-
}
27+
/* PHP_GRF */
28+
#define PHP_GRF_PCIESEL_CON 0x100
29+
30+
/* PCIE3PHY_GRF */
31+
#define PCIE3PHY_GRF_CMN_CON0 0x0
32+
#define PCIE3PHY_GRF_PHY0_STATUS1 0x904
33+
#define PCIE3PHY_GRF_PHY1_STATUS1 0xa04
34+
#define PCIE3PHY_SRAM_INIT_DONE(reg) ((reg & BIT0) != 0)
35+
36+
STATIC EFI_STATUS mInitStatus = EFI_NOT_READY;
5737

5838
EFI_STATUS
5939
Pcie30PhyInit (
6040
VOID
6141
)
6242
{
63-
// UINTN Retry;
43+
UINT8 Mode;
44+
UINT32 Reg;
45+
UINTN Retry;
6446

65-
DEBUG ((DEBUG_INFO, "PCIe30: PHY init\n"));
66-
DEBUG ((DEBUG_INFO, "PCIe30: PHY mode %d\n", PcdGet8 (PcdPcie30PhyMode)));
47+
if (mInitStatus != EFI_NOT_READY) {
48+
return mInitStatus;
49+
}
6750

68-
// MicroSecondDelay(100000);
51+
Mode = PcdGet8 (PcdPcie30PhyMode);
6952

70-
/* Disable power domain */
53+
DEBUG ((DEBUG_INFO, "PCIe30: PHY init\n"));
54+
DEBUG ((DEBUG_INFO, "PCIe30: PHY mode %d\n", Mode));
55+
56+
/* Enable power domain */
7157
MmioWrite32 (0xFD8D8150, 0x1 << 23 | 0x1 << 21); // PD_PCIE & PD_PHP
7258

73-
/* Phy mode: from pcd Pcie30PhyMode */
74-
MmioWrite32 (GRF_PCIE30_PHY_CON (0), (0x7 << 16) | PcdGet8 (PcdPcie30PhyMode));
59+
/* Phy mode */
60+
Reg = Mode;
61+
MmioWrite32 (PCIE3PHY_GRF_BASE + PCIE3PHY_GRF_CMN_CON0, (0x7 << 16) | Reg);
62+
63+
/* Set pcie1ln_sel in PHP_GRF_PCIESEL_CON */
64+
Reg &= 0x3;
65+
if (Reg) {
66+
MmioWrite32 (PHP_GRF_BASE + PHP_GRF_PCIESEL_CON, (0x3 << 16) | Reg);
67+
}
7568

69+
/* Assert PHY Reset */
7670
MmioWrite32 (0xFD7C8A00, (0x1 << 10) | (0x1 << 26));
71+
MicroSecondDelay (1);
7772

7873
/* Deassert PCIe PMA output clamp mode */
79-
MmioWrite32 (GRF_PCIE30_PHY_CON (0), (0x1 << 8) | (0x1 << 24));
74+
MmioWrite32 (PCIE3PHY_GRF_BASE + PCIE3PHY_GRF_CMN_CON0, (0x1 << 8) | (0x1 << 24));
8075

8176
/* Deassert PHY Reset */
8277
MmioWrite32 (0xFD7C8A00, (0x1 << 26));
8378

84-
// /* Enable clocks */
85-
// PmuCruEnableClock (2, 13);
86-
// PmuCruEnableClock (2, 14);
87-
// CruEnableClock (33, 8);
88-
89-
// /* Assert reset */
90-
// CruAssertSoftReset (SOFTRST_INDEX, SOFTRST_BIT);
91-
// gBS->Stall (1000);
79+
for (Retry = 500; Retry > 0; Retry--) {
80+
Reg = MmioRead32 (PCIE3PHY_GRF_BASE + PCIE3PHY_GRF_PHY0_STATUS1);
81+
if (Mode == PCIE30_PHY_MODE_AGGREGATION) {
82+
Reg &= MmioRead32 (PCIE3PHY_GRF_BASE + PCIE3PHY_GRF_PHY1_STATUS1);
83+
}
9284

93-
// MicroSecondDelay (1);
85+
if (PCIE3PHY_SRAM_INIT_DONE (Reg)) {
86+
break;
87+
}
9488

95-
// GrfUpdateRegister (GRF_PCIE30_PHY_CON (9), GRF_PCIE30PHY_DA_OCM_MASK, GRF_PCIE30PHY_DA_OCM);
96-
// GrfUpdateRegister (GRF_PCIE30_PHY_CON (5), GRF_PCIE30PHY_LANE0_LINK_NUM_MASK, PCIE30PHY_LANE0_LINK_NUM);
97-
// GrfUpdateRegister (GRF_PCIE30_PHY_CON (6), GRF_PCIE30PHY_LANE1_LINK_NUM_MASK, PCIE30PHY_LANE1_LINK_NUM);
98-
// GrfUpdateRegister (GRF_PCIE30_PHY_CON (1), GRF_PCIE30PHY_DA_OCM_MASK, GRF_PCIE30PHY_DA_OCM);
89+
MicroSecondDelay (100);
90+
}
9991

100-
// /* De-assert reset */
101-
// CruDeassertSoftReset (SOFTRST_INDEX, SOFTRST_BIT);
102-
103-
// for (Retry = 500; Retry > 0; Retry--) {
104-
// MicroSecondDelay (100);
105-
106-
// if ((MmioRead32 (GRF_PCIE30_PHY_STATUS (0)) & GRF_PCIE30PHY_SRAM_INIT_DONE) != 0) {
107-
// break;
108-
// }
109-
// }
110-
// if (Retry == 0) {
111-
// DEBUG ((DEBUG_WARN, "PCIe30: Failed to enable PCIe 3.0 PHY\n"));
112-
// return EFI_TIMEOUT;
113-
// }
92+
if (Retry == 0) {
93+
DEBUG ((DEBUG_WARN, "PCIe30: PHY init failed\n"));
94+
mInitStatus = EFI_TIMEOUT;
95+
goto Exit;
96+
}
11497

11598
DEBUG ((DEBUG_INFO, "PCIe30: PHY init complete\n"));
116-
return EFI_SUCCESS;
99+
mInitStatus = EFI_SUCCESS;
100+
101+
Exit:
102+
return mInitStatus;
117103
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Copyright 2017, 2020 NXP
44
Copyright 2021-2023, Jared McNeill <[email protected]>
55
Copyright 2023, Molly Sophia <[email protected]>
6-
Copyright (c) 2023-2024, Mario Bălănică <[email protected]>
6+
Copyright (c) 2023-2025, Mario Bălănică <[email protected]>
77
88
SPDX-License-Identifier: BSD-2-Clause-Patent
99
@@ -577,6 +577,7 @@ InitializePciHost (
577577
EFI_PHYSICAL_ADDRESS ApbBase = PCIE_APB_BASE (Segment);
578578
EFI_PHYSICAL_ADDRESS DbiBase = PCIE_DBI_BASE (Segment);
579579
EFI_PHYSICAL_ADDRESS PcieBase = PCIE_CFG_BASE (Segment);
580+
EFI_STATUS Status;
580581
UINTN Retry;
581582
UINT32 LinkSpeed;
582583
UINT32 LinkWidth;
@@ -622,7 +623,10 @@ InitializePciHost (
622623

623624
if ((Segment == PCIE_SEGMENT_PCIE30X4) || (Segment == PCIE_SEGMENT_PCIE30X2)) {
624625
/* Configure PCIe 3.0 PHY */
625-
Pcie30PhyInit ();
626+
Status = Pcie30PhyInit ();
627+
if (EFI_ERROR (Status)) {
628+
return Status;
629+
}
626630
}
627631

628632
/* Combo PHY for PCIe 2.0 is configured earlier by RK3588Dxe */

0 commit comments

Comments
 (0)