[Skiboot] [PATCH RFC 3/6] core/pci: Create the struct pci_device nodes automatically

Sergey Miroshnichenko s.miroshnichenko at yadro.com
Sat Mar 2 01:30:35 AEDT 2019


Currently the struct pci_device nodes are created only during the bus
rescan in skiboot (pci_scan_bus) initiated by an OS via OPAL. But these
structures also could be created if reading the configuration space via
OPAL reveals a new hotplugged device.

This will allow using the standard platform-independent PCIe hotplug driver
in Linux kernel ("pciehp") instead of requesting a Device Tree update.

Signed-off-by: Sergey Miroshnichenko <s.miroshnichenko at yadro.com>
---
 core/pci-opal.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/core/pci-opal.c b/core/pci-opal.c
index d7abb15b..009c8a6c 100644
--- a/core/pci-opal.c
+++ b/core/pci-opal.c
@@ -23,6 +23,13 @@
 #include <timebase.h>
 #include <timer.h>
 
+static struct pci_device *pci_create_dn(struct phb *phb, uint16_t bdfn)
+{
+	struct pci_device *parent = pci_find_parent_dev(phb, bdfn);
+
+	return pci_scan_one(phb, parent, bdfn);
+}
+
 #define OPAL_PCICFG_ACCESS_READ(op, cb, type)	\
 static int64_t opal_pci_config_##op(uint64_t phb_id,			\
 				    uint64_t bus_dev_func,		\
@@ -30,6 +37,7 @@ static int64_t opal_pci_config_##op(uint64_t phb_id,			\
 {									\
 	struct phb *phb = pci_get_phb(phb_id);				\
 	int64_t rc;							\
+	bool dev_found;							\
 									\
 	if (!opal_addr_valid((void *)data))				\
 		return OPAL_PARAMETER;					\
@@ -37,7 +45,14 @@ static int64_t opal_pci_config_##op(uint64_t phb_id,			\
 	if (!phb)							\
 		return OPAL_PARAMETER;					\
 	phb_lock(phb);							\
+									\
+	dev_found = pci_find_dev_safe(phb, bus_dev_func);		\
+									\
 	rc = phb->ops->cfg_##cb(phb, bus_dev_func, offset, data);	\
+									\
+	if (!rc && !dev_found && *data != 0xffffffff)			\
+		pci_create_dn(phb, bus_dev_func);			\
+									\
 	phb_unlock(phb);						\
 									\
 	return rc;							\
-- 
2.20.1



More information about the Skiboot mailing list