From: Huacai Chen <chenhuacai@loongson.cn>
To: "Bjorn Helgaas" <bhelgaas@google.com>,
"Lorenzo Pieralisi" <lorenzo.pieralisi@arm.com>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Wilczyński" <kw@linux.com>
Cc: linux-pci@vger.kernel.org, Jianmin Lv <lvjianmin@loongson.cn>,
Xuefeng Li <lixuefeng@loongson.cn>,
Huacai Chen <chenhuacai@gmail.com>,
Jiaxun Yang <jiaxun.yang@flygoat.com>,
Huacai Chen <chenhuacai@loongson.cn>
Subject: [PATCH V16 4/7] PCI: loongson: Don't access non-existant devices
Date: Thu, 14 Jul 2022 20:42:13 +0800 [thread overview]
Message-ID: <20220714124216.1489304-5-chenhuacai@loongson.cn> (raw)
In-Reply-To: <20220714124216.1489304-1-chenhuacai@loongson.cn>
On LS2K/LS7A, some non-existant devices don't return 0xffffffff when
scanning (they are hidden devices for debug in fact, access the config
space may cause machine hang). This is a hardware flaw but we can only
avoid it by software now.
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
---
drivers/pci/controller/pci-loongson.c | 27 +++++++++++++++++++++------
1 file changed, 21 insertions(+), 6 deletions(-)
diff --git a/drivers/pci/controller/pci-loongson.c b/drivers/pci/controller/pci-loongson.c
index 2db180a9e628..594653154deb 100644
--- a/drivers/pci/controller/pci-loongson.c
+++ b/drivers/pci/controller/pci-loongson.c
@@ -26,6 +26,7 @@
#define FLAG_CFG0 BIT(0)
#define FLAG_CFG1 BIT(1)
#define FLAG_DEV_FIX BIT(2)
+#define FLAG_DEV_HIDDEN BIT(3)
struct loongson_pci_data {
u32 flags;
@@ -138,18 +139,32 @@ static void __iomem *cfg1_map(struct loongson_pci *priv,
return priv->cfg1_base + addroff;
}
+static bool pdev_may_exist(struct pci_bus *bus, unsigned int device, unsigned int function)
+{
+ return !(pci_is_root_bus(bus) && (device >= 9 && device <= 20) && (function > 0));
+}
+
static void __iomem *pci_loongson_map_bus(struct pci_bus *bus, unsigned int devfn,
int where)
{
+ unsigned int device = PCI_SLOT(devfn);
+ unsigned int function = PCI_FUNC(devfn);
struct loongson_pci *priv = pci_bus_to_loongson_pci(bus);
/*
* Do not read more than one device on the bus other than
* the host bus.
*/
- if (priv->data->flags & FLAG_DEV_FIX &&
- !pci_is_root_bus(bus) && PCI_SLOT(devfn) > 0)
- return NULL;
+ if ((priv->data->flags & FLAG_DEV_FIX) && bus->self) {
+ if (!pci_is_root_bus(bus) && (device > 0))
+ return NULL;
+ }
+
+ /* Don't access non-existant devices */
+ if (priv->data->flags & FLAG_DEV_HIDDEN) {
+ if (!pdev_may_exist(bus, device, function))
+ return NULL;
+ }
/* CFG0 can only access standard space */
if (where < PCI_CFG_SPACE_SIZE && priv->cfg0_base)
@@ -197,12 +212,12 @@ static struct pci_ops loongson_pci_ops32 = {
};
static const struct loongson_pci_data ls2k_pci_data = {
- .flags = FLAG_CFG1 | FLAG_DEV_FIX,
+ .flags = FLAG_CFG1 | FLAG_DEV_FIX | FLAG_DEV_HIDDEN,
.ops = &loongson_pci_ops,
};
static const struct loongson_pci_data ls7a_pci_data = {
- .flags = FLAG_CFG1 | FLAG_DEV_FIX,
+ .flags = FLAG_CFG1 | FLAG_DEV_FIX | FLAG_DEV_HIDDEN,
.ops = &loongson_pci_ops,
};
@@ -297,7 +312,7 @@ static int loongson_pci_ecam_init(struct pci_config_window *cfg)
return -ENOMEM;
cfg->priv = priv;
- data->flags = FLAG_CFG1;
+ data->flags = FLAG_CFG1 | FLAG_DEV_HIDDEN;
priv->data = data;
priv->cfg1_base = cfg->win - (cfg->busr.start << 16);
--
2.31.1
next prev parent reply other threads:[~2022-07-14 12:47 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-14 12:42 [PATCH V16 0/7] PCI: Loongson pci improvements and quirks Huacai Chen
2022-07-14 12:42 ` [PATCH V16 1/7] PCI/ACPI: Guard ARM64-specific mcfg_quirks Huacai Chen
2022-07-14 12:42 ` [PATCH V16 2/7] PCI: loongson: Use generic 8/16/32-bit config ops on LS2K/LS7A Huacai Chen
2022-07-14 12:42 ` [PATCH V16 3/7] PCI: loongson: Add ACPI init support Huacai Chen
2022-07-14 12:42 ` Huacai Chen [this message]
2022-07-14 12:42 ` [PATCH V16 5/7] PCI: loongson: Improve the MRRS quirk for LS7A Huacai Chen
2022-07-16 7:13 ` Jianmin Lv
2022-07-16 7:31 ` Huacai Chen
2022-07-14 12:42 ` [PATCH V16 6/7] PCI: Add quirk for LS7A to avoid reboot failure Huacai Chen
2022-07-14 12:42 ` [PATCH V16 7/7] PCI: Add quirk for multifunction devices of LS7A Huacai Chen
2022-07-15 3:44 ` Bjorn Helgaas
2022-07-15 8:05 ` Jianmin Lv
2022-07-15 16:37 ` Bjorn Helgaas
2022-07-16 2:27 ` Jianmin Lv
2022-07-16 3:23 ` Bjorn Helgaas
2022-07-16 6:12 ` Jianmin Lv
2022-07-16 7:35 ` Jianmin Lv
2022-07-16 8:37 ` Huacai Chen
2022-07-16 23:32 ` Bjorn Helgaas
2022-07-17 1:41 ` Jianmin Lv
2022-07-17 14:11 ` Huacai Chen
2022-07-18 17:00 ` Bjorn Helgaas
2022-07-21 4:47 ` Huacai Chen
2022-07-21 17:50 ` Bjorn Helgaas
2022-07-22 4:11 ` Huacai Chen
2022-07-15 22:18 ` [PATCH V16 0/7] PCI: Loongson pci improvements and quirks Bjorn Helgaas
2022-07-16 9:54 ` Huacai Chen
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=20220714124216.1489304-5-chenhuacai@loongson.cn \
--to=chenhuacai@loongson.cn \
--cc=bhelgaas@google.com \
--cc=chenhuacai@gmail.com \
--cc=jiaxun.yang@flygoat.com \
--cc=kw@linux.com \
--cc=linux-pci@vger.kernel.org \
--cc=lixuefeng@loongson.cn \
--cc=lorenzo.pieralisi@arm.com \
--cc=lvjianmin@loongson.cn \
--cc=robh@kernel.org \
/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).