powerpc-utils/0001-drmgr-pci-Enable-in-kernel-functionality-to-update-d.patch

100 lines
2.7 KiB
Diff

From a6a7d375d38823a08d358b50866a95f6f326907e Mon Sep 17 00:00:00 2001
From: Haren Myneni <haren@linux.ibm.com>
Date: Tue, 13 Aug 2024 14:40:23 -0700
Subject: [PATCH 1/4] drmgr/pci: Enable in-kernel functionality to update
device tree
drmgr updates the device tree by writing to /proc/ppc64/ofdt. Also
invokes configure_connector RTAS call to retrieve new device nodes
for IO ADD. But this functionality need /dev/mem access which is
restricted under system lockdown.
The kernel updates provided a sysfs file (/sys/kernel/dlpar) that
will allow drmgr command invoke the following interfaces to update
the device tree.
dt add index <DRC index> ---> To add new device nodes to the device
tree which is used for IO ADD.
dt remove index <DRC index> ---> To remove device nodes for IO
REMOVE
This patch checks the kernel interface for the availability of
device tree update feature and adds do_dt_kernel_dlpar() to invoke
the above kernel interfaces.
Signed-off-by: Haren Myneni <haren@linux.ibm.com>
---
src/drmgr/common.c | 6 ++++++
src/drmgr/common_pci.c | 29 +++++++++++++++++++++++++++++
src/drmgr/dr.h | 1 +
3 files changed, 36 insertions(+)
diff --git a/src/drmgr/common.c b/src/drmgr/common.c
index bfec0b9bb966..70f4dfda92a5 100644
--- a/src/drmgr/common.c
+++ b/src/drmgr/common.c
@@ -1504,6 +1504,12 @@ int kernel_dlpar_exists(void)
if (strstr(buf, "cpu"))
return 1;
break;
+ case DRC_TYPE_PCI:
+ case DRC_TYPE_PHB:
+ case DRC_TYPE_SLOT:
+ if (strstr(buf, "dt"))
+ return 1;
+ break;
default:
return 0;
}
diff --git a/src/drmgr/common_pci.c b/src/drmgr/common_pci.c
index 1ef4ec9653b0..374129cf33e0 100644
--- a/src/drmgr/common_pci.c
+++ b/src/drmgr/common_pci.c
@@ -1619,3 +1619,32 @@ int disable_hp_children(char *drc_name)
}
return 0;
}
+
+/*
+ * kernel interface to update device tree nodes.
+ * dlpar dt [add|remove] index <#drc index>
+ */
+int do_dt_kernel_dlpar(uint32_t index, int action)
+{
+ char cmdbuf[256];
+ int offset;
+
+ offset = sprintf(cmdbuf, "%s ", "dt");
+
+ switch (action) {
+ case ADD:
+ offset += sprintf(cmdbuf + offset, "add ");
+ break;
+ case REMOVE:
+ offset += sprintf(cmdbuf + offset, "remove ");
+ break;
+ default:
+ /* Should not happen */
+ say(ERROR, "Invalid action type specified\n");
+ return -EINVAL;
+ }
+
+ offset += sprintf(cmdbuf + offset, "index 0x%x", index);
+
+ return do_kernel_dlpar(cmdbuf, offset);
+}
diff --git a/src/drmgr/dr.h b/src/drmgr/dr.h
index 60c31c44b7e3..72ede55547a3 100644
--- a/src/drmgr/dr.h
+++ b/src/drmgr/dr.h
@@ -188,4 +188,5 @@ static inline int do_kernel_dlpar(const char *cmd, int len)
{
return do_kernel_dlpar_common(cmd, len, 0);
}
+int do_dt_kernel_dlpar(uint32_t, int);
#endif
--
2.46.0