[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230812122128.3409733-1-peng.fan@oss.nxp.com>
Date: Sat, 12 Aug 2023 20:21:28 +0800
From: "Peng Fan (OSS)" <peng.fan@....nxp.com>
To: bhelgaas@...gle.com, pali@...nel.org
Cc: linux-pci@...r.kernel.org, linux-kernel@...r.kernel.org,
Peng Fan <peng.fan@....com>
Subject: [PATCH] pci: introduce static_nr to indicate domain_nr from which IDA
From: Peng Fan <peng.fan@....com>
When pci node is created used an overlay, when the overlay is
reverted/destroyed, the "linux,pci-domain" property is no longer
existed, so of_get_pci_domain_nr will return failure. Then
of_pci_bus_release_domain_nr will actually use the dynamic IDA,
even if the IDA was allocated in static IDA.
Introduce a static_nr field in pci_bus to indicate the IDA
is in dynamic or static IDA to address the upper issue.
Fixes: c14f7ccc9f5d ("PCI: Assign PCI domain IDs by ida_alloc()")
Signed-off-by: Peng Fan <peng.fan@....com>
---
drivers/pci/pci.c | 22 ++++++++++++++--------
include/linux/pci.h | 1 +
2 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 60230da957e0..5c98502bcda6 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -6881,10 +6881,10 @@ static void of_pci_reserve_static_domain_nr(void)
}
}
-static int of_pci_bus_find_domain_nr(struct device *parent)
+static int of_pci_bus_find_domain_nr(struct pci_bus *bus, struct device *parent)
{
static bool static_domains_reserved = false;
- int domain_nr;
+ int domain_nr, ret;
/* On the first call scan device tree for static allocations. */
if (!static_domains_reserved) {
@@ -6892,6 +6892,8 @@ static int of_pci_bus_find_domain_nr(struct device *parent)
static_domains_reserved = true;
}
+ bus->static_nr = 0;
+
if (parent) {
/*
* If domain is in DT, allocate it in static IDA. This
@@ -6899,10 +6901,14 @@ static int of_pci_bus_find_domain_nr(struct device *parent)
* in DT.
*/
domain_nr = of_get_pci_domain_nr(parent->of_node);
- if (domain_nr >= 0)
- return ida_alloc_range(&pci_domain_nr_static_ida,
- domain_nr, domain_nr,
- GFP_KERNEL);
+ if (domain_nr >= 0) {
+ ret = ida_alloc_range(&pci_domain_nr_static_ida,
+ domain_nr, domain_nr, GFP_KERNEL);
+ if (ret >= 0)
+ bus->static_nr = 1;
+
+ return ret;
+ }
}
/*
@@ -6920,7 +6926,7 @@ static void of_pci_bus_release_domain_nr(struct pci_bus *bus, struct device *par
return;
/* Release domain from IDA where it was allocated. */
- if (of_get_pci_domain_nr(parent->of_node) == bus->domain_nr)
+ if (bus->static_nr)
ida_free(&pci_domain_nr_static_ida, bus->domain_nr);
else
ida_free(&pci_domain_nr_dynamic_ida, bus->domain_nr);
@@ -6928,7 +6934,7 @@ static void of_pci_bus_release_domain_nr(struct pci_bus *bus, struct device *par
int pci_bus_find_domain_nr(struct pci_bus *bus, struct device *parent)
{
- return acpi_disabled ? of_pci_bus_find_domain_nr(parent) :
+ return acpi_disabled ? of_pci_bus_find_domain_nr(bus, parent) :
acpi_pci_bus_find_domain_nr(bus);
}
diff --git a/include/linux/pci.h b/include/linux/pci.h
index eeb2e6f6130f..6dd16e069ab8 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -665,6 +665,7 @@ struct pci_bus {
unsigned char cur_bus_speed; /* enum pci_bus_speed */
#ifdef CONFIG_PCI_DOMAINS_GENERIC
int domain_nr;
+ unsigned int static_nr:1;
#endif
char name[48];
--
2.37.1
Powered by blists - more mailing lists