Skip to contentSkip to conversation

PCI: spacemit: Ignore PERST# bit for controllers

PATCH In review Ali Tariq 4 participants 5 messages Nov 4 – Nov 5

Subsystems (4)
lore
Share & tools
lore

Ali Tariq

author
#0 lore raw

PATCH 1/1 PCI: spacemit: Ignore PERST# bit for controllers

The k1_pcie_init() does not set PCIE_IGNORE_PERSTN bit of the control logic register, which causes controller to reset itself once PERST# signal is asserted even when acting as host.
On Orange Pi RV2 (SpacemiT K1), this resets the controller and wipes the IDs. k1_pcie_deinit() leaves PERST# asserted, so when k1_pcie_init() runs again, its first DBI access hangs the CPU.

Set PCIE_IGNORE_PERSTN bit of the control logic register of APMU in k1_pcie_init() before enabling resources so controllers dont end up resetting themselves when PERST# signal is asserted.

Fixes ff64e078e45f ("PCI: spacemit: Add SpacemiT PCIe host driver")

---
Hang log: https://kernelci.cloud-v.co/scheduler/job/420
Fixed Log: https://kernelci.cloud-v.co/scheduler/job/430

---
 drivers/pci/controller/dwc/pcie-spacemit-k1.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/pci/controller/dwc/pcie-spacemit-k1.c +9 -0
index 92a71ea90ac3..af6028e8825a 100644
@@ -47,6 +47,7 @@
 
 #define PCIE_CONTROL_LOGIC			0x0004
 #define PCIE_SOFT_RESET			BIT(0)
+#define PCIE_IGNORE_PERSTN		BIT(2)	/* 1: ignore PERST# */
 
 struct k1_pcie {
 	struct dw_pcie pci;
@@ -131,11 +132,19 @@ static int k1_pcie_init(struct dw_pcie_rp *pp)
 	struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
 	struct k1_pcie *k1 = to_k1_pcie(pci);
 	u32 reset_ctrl;
+	u32 ctrl_logic;
 	u32 val;
 	int ret;
 
 	k1_pcie_toggle_soft_reset(k1);
 
+	/*
+	 * Ignore the PERST# signal so the controller does not reset
+	 * itself when it pulls PERST# low.
+	 */
+	ctrl_logic = k1->pmu_off + PCIE_CONTROL_LOGIC;
+	regmap_set_bits(k1->pmu, ctrl_logic, PCIE_IGNORE_PERSTN);
+
 	ret = k1_pcie_enable_resources(k1);
 	if (ret)
 		return ret;
Signature · 1 line
2.34.1
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 7 lines

The k1_pcie_init() does not set PCIE_IGNORE_PERSTN bit of the control logic register, which causes controller to reset itself once PERST# signal is asserted even when acting as host.
On Orange Pi RV2 (SpacemiT K1), this resets the controller and wipes the IDs. k1_pcie_deinit() leaves PERST# asserted, so when k1_pcie_init() runs again, its first DBI access hangs the CPU.

Quoted 6 lines

Set PCIE_IGNORE_PERSTN bit of the control logic register of APMU in k1_pcie_init() before enabling resources so controllers dont end up resetting themselves when PERST# signal is asserted.

Fixes ff64e078e45f ("PCI: spacemit: Add SpacemiT PCIe host driver")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
reviewer
#2 lore raw
In reply to Ali Tariq
Quoted 25 lines · Ali Tariq

The k1_pcie_init() does not set PCIE_IGNORE_PERSTN bit of the control logic register, which causes controller to reset itself once PERST# signal is asserted even when acting as host.
On Orange Pi RV2 (SpacemiT K1), this resets the controller and wipes the IDs. k1_pcie_deinit() leaves PERST# asserted, so when k1_pcie_init() runs again, its first DBI access hangs the CPU.

Set PCIE_IGNORE_PERSTN bit of the control logic register of APMU in k1_pcie_init() before enabling resources so controllers dont end up resetting themselves when PERST# signal is asserted.

Fixes ff64e078e45f ("PCI: spacemit: Add SpacemiT PCIe host driver")

---
Hang log: https://kernelci.cloud-v.co/scheduler/job/420
Fixed Log: https://kernelci.cloud-v.co/scheduler/job/430

---
 drivers/pci/controller/dwc/pcie-spacemit-k1.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/pci/controller/dwc/pcie-spacemit-k1.c +0 -0
index 92a71ea90ac3..af6028e8825a 100644

drivers/pci/controller/dwc/pcie-spacemit-k1.c line 50

Quoted 4 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c +1 -0
@@ -47,6 +47,7 @@
 
 #define PCIE_CONTROL_LOGIC			0x0004
 #define PCIE_SOFT_RESET			BIT(0)
+#define PCIE_IGNORE_PERSTN		BIT(2)	/* 1: ignore PERST# */

A similar but earlier patch can be found here [1]

Signature · 1 line
Troy Mitchell
author
#3 lore raw
Quoted 27 lines · Troy Mitchell
Quoted 26 lines · Ali Tariq

The k1_pcie_init() does not set PCIE_IGNORE_PERSTN bit of the control logic register, which causes controller to reset itself once PERST# signal is asserted even when acting as host.
On Orange Pi RV2 (SpacemiT K1), this resets the controller and wipes the IDs. k1_pcie_deinit() leaves PERST# asserted, so when k1_pcie_init() runs again, its first DBI access hangs the CPU.

Set PCIE_IGNORE_PERSTN bit of the control logic register of APMU in k1_pcie_init() before enabling resources so controllers dont end up resetting themselves when PERST# signal is asserted.

Fixes ff64e078e45f ("PCI: spacemit: Add SpacemiT PCIe host driver")

---
Hang log: https://kernelci.cloud-v.co/scheduler/job/420
Fixed Log: https://kernelci.cloud-v.co/scheduler/job/430

---
  drivers/pci/controller/dwc/pcie-spacemit-k1.c | 9 +++++++++
  1 file changed, 9 insertions(+)
drivers/pci/controller/dwc/pcie-spacemit-k1.c +0 -0
index 92a71ea90ac3..af6028e8825a 100644
@@ -47,6 +47,7 @@
 
Quoted 7 lines

drivers/pci/controller/dwc/pcie-spacemit-k1.c line 50

Quoted 3 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c +1 -0
  #define PCIE_CONTROL_LOGIC			0x0004
  #define PCIE_SOFT_RESET			BIT(0)
+#define PCIE_IGNORE_PERSTN		BIT(2)	/* 1: ignore PERST# */

A similar but earlier patch can be found here [1]

Thank you for pointing.

I missed that. I will check that patch.

You can drop my patch.

Regards,
Ali

#4 lore raw
In reply to Ali Tariq

On Wed Nov 4, 2026 at 10:07 PM CST, Ali Tariq wrote:

Hi Ali,

Quoted 42 lines

The k1_pcie_init() does not set PCIE_IGNORE_PERSTN bit of the control logic register, which causes controller to reset itself once PERST# signal is asserted even when acting as host.
On Orange Pi RV2 (SpacemiT K1), this resets the controller and wipes the IDs. k1_pcie_deinit() leaves PERST# asserted, so when k1_pcie_init() runs again, its first DBI access hangs the CPU.

Set PCIE_IGNORE_PERSTN bit of the control logic register of APMU in k1_pcie_init() before enabling resources so controllers dont end up resetting themselves when PERST# signal is asserted.

Fixes ff64e078e45f ("PCI: spacemit: Add SpacemiT PCIe host driver")

---
Hang log: https://kernelci.cloud-v.co/scheduler/job/420
Fixed Log: https://kernelci.cloud-v.co/scheduler/job/430

---
 drivers/pci/controller/dwc/pcie-spacemit-k1.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/pci/controller/dwc/pcie-spacemit-k1.c +2 -0
index 92a71ea90ac3..af6028e8825a 100644
@@ -47,6 +47,7 @@
 
 #define PCIE_CONTROL_LOGIC			0x0004
 #define PCIE_SOFT_RESET			BIT(0)
+#define PCIE_IGNORE_PERSTN		BIT(2)	/* 1: ignore PERST# */
 
 struct k1_pcie {
 	struct dw_pcie pci;
@@ -131,11 +132,19 @@ static int k1_pcie_init(struct dw_pcie_rp *pp)
 	struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
 	struct k1_pcie *k1 = to_k1_pcie(pci);
 	u32 reset_ctrl;
+	u32 ctrl_logic;
 	u32 val;
 	int ret;
 
 	k1_pcie_toggle_soft_reset(k1);
 

drivers/pci/controller/dwc/pcie-spacemit-k1.c static int k1_pcie_init(struct dw_pcie_rp *pp) · line 150

Quoted 10 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c +7 -0
+	/*
+	 * Ignore the PERST# signal so the controller does not reset
+	 * itself when it pulls PERST# low.
+	 */
+	ctrl_logic = k1->pmu_off + PCIE_CONTROL_LOGIC;
+	regmap_set_bits(k1->pmu, ctrl_logic, PCIE_IGNORE_PERSTN);
+
 	ret = k1_pcie_enable_resources(k1);
 	if (ret)
 		return ret;

Thanks for investigating this and submitting a fix.

Our testing also confirms that setting PCIE_IGNORE_PERSTN prevents PERST# from resetting the local RC and resolves the DBI hang.

I will send a v2 of my earlier patch with an updated explanation and the test results.

Regards,
Encrow Thorne