linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Xiaochun Lee <lixiaochun.2888@163.com>
To: nirmal.patel@linux.intel.com, jonathan.derrick@linux.dev
Cc: lpieralisi@kernel.org, robh@kernel.org, kw@linux.com,
	bhelgaas@google.com, linux-pci@vger.kernel.org,
	linux-kernel@vger.kernel.org, lkp@intel.com, xiaocli@redhat.com,
	Xiaochun Lee <lixc17@lenovo.com>
Subject: [PATCH v2 1/1] PCI: Set no io resource for bridges that behind VMD controller
Date: Tue, 27 Sep 2022 22:16:06 +0800	[thread overview]
Message-ID: <1664288166-7432-1-git-send-email-lixiaochun.2888@163.com> (raw)

From: Xiaochun Lee <lixc17@lenovo.com>

When enable VMDs on Intel CPUs, VMD controllers(8086:28c0) be
recognized by VMD driver and there are many failed messages of
BAR 13 when scan the bridges and assign IO resource behind it
as listed below, the bridge wants to get 0x6000 as its IO
resource, but there is no IO resources on the host bridge.

VMD host bridge resources:
vmd 0000:e2:00.5: PCI host bridge to bus 10001:00
pci_bus 10001:00: root bus resource [bus 00-1f]
pci_bus 10001:00: root bus resource [mem 0xf4000000-0xf5ffffff]
pci_bus 10001:00: root bus resource [mem 0x29ffff02010-0x29fffffffff 64bit]
pci_bus 10001:00: scanning bus

Read bridge IO resource:
pci 10001:00:02.0: PCI bridge to [bus 01]
pci 10001:00:02.0:   bridge window [io  0x1000-0x6fff]
pci 10001:00:03.0: PCI bridge to [bus 02]
pci 10001:00:03.0:   bridge window [io  0x1000-0x6fff]

Failed messages of BAR#13:
pci 10001:00:02.0: BAR 13: no space for [io  size 0x6000]
pci 10001:00:02.0: BAR 13: failed to assign [io  size 0x6000]
pci 10001:00:03.0: BAR 13: no space for [io  size 0x6000]
pci 10001:00:03.0: BAR 13: failed to assign [io  size 0x6000]

VMD-enabled root ports use
Enhanced Configuration Access Mechanism (ECAM) access
PCI Express configuration space, and offer VMD_CFGBAR as
base of PCI Express configuration space for the bridges
behind it. The configuration space includes IO resources,
but these IO resources are not actually used on X86,
it can result in BAR#13 assign IO resource failed.
Therefor,clear IO resources by setting an IO base value
greater than limit to these bridges here, so in this case,
we can leverage kernel parameter "pci=hpiosize=0KB" to
avoid this failed messages show up.

Signed-off-by: Xiaochun Lee <lixc17@lenovo.com>
---
 drivers/pci/quirks.c | 60 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)

diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 4944798e75b5..efecf12e8059 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -5956,3 +5956,63 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x56b1, aspm_l1_acceptable_latency
 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x56c0, aspm_l1_acceptable_latency);
 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x56c1, aspm_l1_acceptable_latency);
 #endif
+
+#if defined(CONFIG_X86_64) || defined(CONFIG_X86)
+
+#ifdef CONFIG_UML_X86
+#define is_vmd(bus)             false
+#endif /* CONFIG_UML_X86 */
+
+/*
+ * VMD-enabled root ports use Enhanced Configuration Access Mechanism (ECAM)
+ * access PCI Express configuration space, and offer VMD_CFGBAR as the
+ * base of PCI Express configuration space for the bridges behind it.
+ * The configuration space includes IO resources, but these IO
+ * resources are not actually used on X86, and it can result
+ * in BAR#13 assign IO resource failed. Therefor, clear IO resources
+ * by setting an IO base value greater than limit to these bridges here,
+ * so in this case, append kernel parameter "pci=hpiosize=0KB" can avoid
+ * the BAR#13 failed messages show up.
+ */
+static void quirk_vmd_no_iosize(struct pci_dev *bridge)
+{
+	u8 io_base_lo, io_limit_lo;
+	u16 io_low;
+	u32 io_upper16;
+	unsigned long io_mask,  base, limit;
+
+	io_mask = PCI_IO_RANGE_MASK;
+	if (bridge->io_window_1k)
+		io_mask = PCI_IO_1K_RANGE_MASK;
+
+	/* VMD Domain */
+	if (is_vmd(bridge->bus) && bridge->is_hotplug_bridge) {
+		pci_read_config_byte(bridge, PCI_IO_BASE, &io_base_lo);
+		pci_read_config_byte(bridge, PCI_IO_LIMIT, &io_limit_lo);
+		base = (io_base_lo & io_mask) << 8;
+		limit = (io_limit_lo & io_mask) << 8;
+		/* if there are defined io ports behind the bridge on x86,
+		 * we clear it, since there is only 64KB IO resource on it,
+		 * beyond that, hotplug io bridges don't needs IO port resource,
+		 * such as NVMes attach on it. So the corresponding range must be
+		 * turned off by writing base value greater than limit to the
+		 * bridge's base/limit registers.
+		 */
+		if (limit >= base) {
+			/* Clear upper 16 bits of I/O base/limit */
+			io_upper16 = 0;
+			/* set base value greater than limit */
+			io_low = 0x00f0;
+
+			/* Temporarily disable the I/O range before updating PCI_IO_BASE */
+			pci_write_config_dword(bridge, PCI_IO_BASE_UPPER16, 0x0000ffff);
+			/* Update lower 16 bits of I/O base/limit */
+			pci_write_config_word(bridge, PCI_IO_BASE, io_low);
+			/* Update upper 16 bits of I/O base/limit */
+			pci_write_config_dword(bridge, PCI_IO_BASE_UPPER16, io_upper16);
+		}
+	}
+}
+DECLARE_PCI_FIXUP_CLASS_HEADER(PCI_ANY_ID, PCI_ANY_ID,
+		PCI_CLASS_BRIDGE_PCI, 8, quirk_vmd_no_iosize);
+#endif
-- 
2.37.3


             reply	other threads:[~2022-09-27 14:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-27 14:16 Xiaochun Lee [this message]
2022-09-27 18:48 ` [PATCH v2 1/1] PCI: Set no io resource for bridges that behind VMD controller Bjorn Helgaas
2022-09-28  6:49   ` Xiaochun Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1664288166-7432-1-git-send-email-lixiaochun.2888@163.com \
    --to=lixiaochun.2888@163.com \
    --cc=bhelgaas@google.com \
    --cc=jonathan.derrick@linux.dev \
    --cc=kw@linux.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lixc17@lenovo.com \
    --cc=lkp@intel.com \
    --cc=lpieralisi@kernel.org \
    --cc=nirmal.patel@linux.intel.com \
    --cc=robh@kernel.org \
    --cc=xiaocli@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).