Skip to contentSkip to conversation

PCI: Fix up L1SS capability for Intel Apollo Lake PCIe bridge

PATCH Superseded Ron Lee 3 participants 3 messages Feb 6, 2023 – Apr 11, 2023

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Ron Lee

author
#0 lore raw

PATCH v3 1/1 PCI: Fix up L1SS capability for Intel Apollo Lake PCIe bridge

On Google Coral and Reef family Chromebooks with Intel Apollo Lake SoC, the PCIe bridge lost its L1 PM Substates capability after resumed from D3cold. This patch save the capability header and the pointer offset to the L1SS capability after this bridge initialized, and recover them every time resuming from D3cold.

---
Change from v2: traverse the capability link list to find the L1SS capability header and pointer offset to the L1SS capability, save them after the bridge initialized and restore them after resuming from D3cold.

 drivers/pci/quirks.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
drivers/pci/quirks.c +41 -0
index 285acc4aaccc..4e1c8c4c7e9a 100644
@@ -5992,3 +5992,44 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a2d, dpc_log_size);
 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a2f, dpc_log_size);
 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a31, dpc_log_size);
 #endif
+
+#ifdef CONFIG_PCIEASPM
+static u16 pos_to_l1ss;
+static u32 l1ss_header;
+static void chromeos_save_apl_pci_l1ss_capability(struct pci_dev *pdev)
+{
+	u32 header;
+	int pos = PCI_CFG_SPACE_SIZE;
+
+	while (pos) {
+		pci_read_config_dword(pdev, pos, &header);
+		if (PCI_EXT_CAP_NEXT(header) == pdev->l1ss)
+			pos_to_l1ss = pos;
+		else if (PCI_EXT_CAP_ID(header) == PCI_EXT_CAP_ID_L1SS)
+			l1ss_header = header;
+
+		pos = PCI_EXT_CAP_NEXT(header);
+	}
+}
+
+static void chromeos_fixup_apl_pci_l1ss_capability(struct pci_dev *pdev)
+{
+	u32 header;
+
+	if (!pos_to_l1ss || !l1ss_header)
+		return;
+
+	pci_info(pdev, "Fixup L1SS Capability\n");
+	/* Fixup the header of L1SS Capability if missing */
+	pci_read_config_dword(pdev, pdev->l1ss, &header);
+	if (PCI_EXT_CAP_ID(header) != PCI_EXT_CAP_ID_L1SS)
+		pci_write_config_dword(pdev, pdev->l1ss, l1ss_header);
+
+	/* Fixup the link to L1SS Capability if missing*/
+	pci_read_config_dword(pdev, pos_to_l1ss, &header);
+	if (PCI_EXT_CAP_NEXT(header) != pdev->l1ss)
+		pci_write_config_dword(pdev, pos_to_l1ss, pdev->l1ss << 20);
+}
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x5ad6, chromeos_save_apl_pci_l1ss_capability);
+DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, 0x5ad6, chromeos_fixup_apl_pci_l1ss_capability);
+#endif
Signature · 1 line
2.17.1
#1 lore raw
Quoted 55 lines · Ron Lee

On Google Coral and Reef family Chromebooks with Intel Apollo Lake SoC, the PCIe bridge lost its L1 PM Substates capability after resumed from D3cold. This patch save the capability header and the pointer offset to the L1SS capability after this bridge initialized, and recover them every time resuming from D3cold.

---
Change from v2: traverse the capability link list to find the L1SS capability header and pointer offset to the L1SS capability, save them after the bridge initialized and restore them after resuming from D3cold.

 drivers/pci/quirks.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
drivers/pci/quirks.c +31 -0
index 285acc4aaccc..4e1c8c4c7e9a 100644
@@ -5992,3 +5992,44 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a2d, dpc_log_size);
 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a2f, dpc_log_size);
 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a31, dpc_log_size);
 #endif
+
+#ifdef CONFIG_PCIEASPM
+static u16 pos_to_l1ss;
+static u32 l1ss_header;
+static void chromeos_save_apl_pci_l1ss_capability(struct pci_dev *pdev)
+{
+	u32 header;
+	int pos = PCI_CFG_SPACE_SIZE;
+
+	while (pos) {
+		pci_read_config_dword(pdev, pos, &header);
+		if (PCI_EXT_CAP_NEXT(header) == pdev->l1ss)
+			pos_to_l1ss = pos;
+		else if (PCI_EXT_CAP_ID(header) == PCI_EXT_CAP_ID_L1SS)
+			l1ss_header = header;
+
+		pos = PCI_EXT_CAP_NEXT(header);
+	}
+}
+
+static void chromeos_fixup_apl_pci_l1ss_capability(struct pci_dev *pdev)
+{
+	u32 header;
+
+	if (!pos_to_l1ss || !l1ss_header)
+		return;
+
+	pci_info(pdev, "Fixup L1SS Capability\n");
+	/* Fixup the header of L1SS Capability if missing */
+	pci_read_config_dword(pdev, pdev->l1ss, &header);
+	if (PCI_EXT_CAP_ID(header) != PCI_EXT_CAP_ID_L1SS)

drivers/pci/quirks.c DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a2d, dpc_log_size); · line 6035

Quoted 10 lines
drivers/pci/quirks.c +10 -0
+		pci_write_config_dword(pdev, pdev->l1ss, l1ss_header);
+
+	/* Fixup the link to L1SS Capability if missing*/
+	pci_read_config_dword(pdev, pos_to_l1ss, &header);
+	if (PCI_EXT_CAP_NEXT(header) != pdev->l1ss)
+		pci_write_config_dword(pdev, pos_to_l1ss, pdev->l1ss << 20);
+}
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x5ad6, chromeos_save_apl_pci_l1ss_capability);
+DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, 0x5ad6, chromeos_fixup_apl_pci_l1ss_capability);
+#endif

What do you think of the possible revision below?

- Moved to arch/x86/pci/fixup.c since this is x86-only.
- Save prev cap offset & header, L1SS offset & header. This means we can fix up even when CONFIG_PCIEASPM is not enabled, we can restore the entire previous cap header (not just the link), and should be safe since only one device per system should match the Device ID.

Bjorn

commit e082cb8ab59f ("PCI: Fix up L1SS capability for Intel Apollo Lake Root Port") parent 52589007b243

Author: Ron Lee <[email protected]>
Date:   Mon Apr 3 16:30:16 2023 -0500

PCI: Fix up L1SS capability for Intel Apollo Lake Root Port

On Google Coral and Reef family Chromebooks with Intel Apollo Lake SoC, firmware clobbers the headers of the L1 PM Substates capability and the previous capability when returning from D3cold to D0.

Save those headers at enumeration-time and restore them at resume.

arch/x86/pci/fixup.c +58 -0
index 615a76d70019..ad0dfb22b4a6 100644
@@ -824,3 +824,61 @@ static void rs690_fix_64bit_dma(struct pci_dev *pdev)
 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x7910, rs690_fix_64bit_dma);
 
 #endif
+
+/*
+ * When returning from D3cold to D0, firmware on some Google Coral and Reef
+ * family Chromebooks with Intel Apollo Lake SoC clobbers the headers of
+ * both the L1 PM Substates capability and the previous capability for the
+ * "Celeron N3350/Pentium N4200/Atom E3900 Series PCI Express Port B #1".
+ *
+ * Save those values at enumeration-time and restore them at resume.
+ */
+
+static u16 prev_cap, l1ss_cap;
+static u32 prev_header, l1ss_header;
+
+static void chromeos_save_apl_pci_l1ss_capability(struct pci_dev *dev)
+{
+	int pos = PCI_CFG_SPACE_SIZE, prev = 0;
+	u32 header, pheader = 0;
+
+	while (pos) {
+		pci_read_config_dword(dev, pos, &header);
+		if (PCI_EXT_CAP_ID(header) == PCI_EXT_CAP_ID_L1SS) {
+			prev_cap = prev;
+			prev_header = pheader;
+			l1ss_cap = pos;
+			l1ss_header = header;
+		}
+
+		prev = pos;
+		prev_header = header;
+		pos = PCI_EXT_CAP_NEXT(header);
+	}
+}
+
+static void chromeos_fixup_apl_pci_l1ss_capability(struct pci_dev *dev)
+{
+	u32 header;
+
+	if (!prev_cap || !prev_header || !l1ss_cap || !l1ss_header)
+		return;
+
+	/* Fixup the header of L1SS Capability if missing */
+	pci_read_config_dword(dev, l1ss_cap, &header);
+	if (header != l1ss_header) {
+		pci_write_config_dword(dev, l1ss_cap, l1ss_header);
+		pci_info(dev, "restore L1SS Capability header (was %#010x now %#010x)\n",
+			 header, l1ss_header);
+	}
+
+	/* Fixup the link to L1SS Capability if missing */
+	pci_read_config_dword(dev, prev_cap, &header);
+	if (header != prev_header) {
+		pci_write_config_dword(dev, prev_cap, prev_header);
+		pci_info(dev, "restore previous Capability header (was %#010x now %#010x)\n",
+			 header, prev_header);
+	}
+}
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x5ad6, chromeos_save_apl_pci_l1ss_capability);
+DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, 0x5ad6, chromeos_fixup_apl_pci_l1ss_capability);
#2 lore raw
Quoted 12 lines

What do you think of the possible revision below?

- Moved to arch/x86/pci/fixup.c since this is x86-only.
- Save prev cap offset & header, L1SS offset & header. This means we can fix up even when CONFIG_PCIEASPM is not enabled, we can restore the entire previous cap header (not just the link), and should be safe since only one device per system should match the Device ID.

Bjorn

Hi Bjorn,

Thank you revise this patch,
it is more concise and make sense moving to arch/x86/pci/fixup.c I corrected the following statement in the loop.

arch/x86/pci/fixup.c static void rs690_fix_64bit_dma(struct pci_dev *pdev) · line 855

Quoted 1 line
arch/x86/pci/fixup.c +1 -0
+		prev_header = header;

BTW, I add "return" to stop traversal once L1SS capability was found, will submit the v4 patch later for you review.

+ while (pos) {
+ pci_read_config_dword(dev, pos, &header);
+ if (PCI_EXT_CAP_ID(header) == PCI_EXT_CAP_ID_L1SS) {
+ prev_cap = prev;
+ prev_header = pheader;
+ l1ss_cap = pos;
+ l1ss_header = header;
+ return;
+ }
+
+ prev = pos;
+ pheader = header;
+ pos = PCI_EXT_CAP_NEXT(header);
+ }

Quoted 90 lines

commit e082cb8ab59f ("PCI: Fix up L1SS capability for Intel Apollo Lake Root Port") parent 52589007b243

Author: Ron Lee <[email protected]>
Date:   Mon Apr 3 16:30:16 2023 -0500

PCI: Fix up L1SS capability for Intel Apollo Lake Root Port

On Google Coral and Reef family Chromebooks with Intel Apollo Lake SoC, firmware clobbers the headers of the L1 PM Substates capability and the previous capability when returning from D3cold to D0.

Save those headers at enumeration-time and restore them at resume.

[email protected]/T/#u

arch/x86/pci/fixup.c index renamed from arch/x86/pci/fixup.c +0 -0

615a76d70019..ad0dfb22b4a6 100644

arch/x86/pci/fixup.c +48 -0
@@ -824,3 +824,61 @@ static void rs690_fix_64bit_dma(struct pci_dev *pdev)
 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x7910,
 rs690_fix_64bit_dma);
 
 #endif
+
+/*
+ * When returning from D3cold to D0, firmware on some Google Coral and
+Reef
+ * family Chromebooks with Intel Apollo Lake SoC clobbers the headers
+of
+ * both the L1 PM Substates capability and the previous capability for
+the
+ * "Celeron N3350/Pentium N4200/Atom E3900 Series PCI Express Port B #1".
+ *
+ * Save those values at enumeration-time and restore them at resume.
+ */
+
+static u16 prev_cap, l1ss_cap;
+static u32 prev_header, l1ss_header;
+
+static void chromeos_save_apl_pci_l1ss_capability(struct pci_dev *dev)
+{
+	int pos = PCI_CFG_SPACE_SIZE, prev = 0;
+	u32 header, pheader = 0;
+
+	while (pos) {
+		pci_read_config_dword(dev, pos, &header);
+		if (PCI_EXT_CAP_ID(header) == PCI_EXT_CAP_ID_L1SS) {
+			prev_cap = prev;
+			prev_header = pheader;
+			l1ss_cap = pos;
+			l1ss_header = header;
+		}
+
+		prev = pos;
+		prev_header = header;
+		pos = PCI_EXT_CAP_NEXT(header);
+	}
+}
+
+static void chromeos_fixup_apl_pci_l1ss_capability(struct pci_dev *dev)
+{
+	u32 header;
+
+	if (!prev_cap || !prev_header || !l1ss_cap || !l1ss_header)
+		return;
+
+	/* Fixup the header of L1SS Capability if missing */
+	pci_read_config_dword(dev, l1ss_cap, &header);
+	if (header != l1ss_header) {
+		pci_write_config_dword(dev, l1ss_cap, l1ss_header);
+		pci_info(dev, "restore L1SS Capability header (was %#010x now

%#010x)\n",

arch/x86/pci/fixup.c +8 -0
+			 header, l1ss_header);
+	}
+
+	/* Fixup the link to L1SS Capability if missing */
+	pci_read_config_dword(dev, prev_cap, &header);
+	if (header != prev_header) {
+		pci_write_config_dword(dev, prev_cap, prev_header);
+		pci_info(dev, "restore previous Capability header (was %#010x

now %#010x)\n",

arch/x86/pci/fixup.c +7 -0
+			 header, prev_header);
+	}
+}
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x5ad6,
+chromeos_save_apl_pci_l1ss_capability);
+DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, 0x5ad6,
+chromeos_fixup_apl_pci_l1ss_capability);