From e2388681df4aec97ab9a3f883baf37f51a710a00 Mon Sep 17 00:00:00 2001
From: Haren Myneni <haren@linux.ibm.com>
Date: Tue, 13 Aug 2024 14:40:26 -0700
Subject: [PATCH 2/4] drmgr/SLOT: Add kernel interface support for device tree
 update

Use the following kernel interfaces for SLOT device type to update
the device tree if this feature is enabled in the kernel.

dt add index <DRC index>  --> for IO add
dt remove index <DRC index> --> for IO remove

Signed-off-by: Haren Myneni <haren@linux.ibm.com>
---
 src/drmgr/drslot_chrp_slot.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/src/drmgr/drslot_chrp_slot.c b/src/drmgr/drslot_chrp_slot.c
index 0966c256aa01..180b10857add 100644
--- a/src/drmgr/drslot_chrp_slot.c
+++ b/src/drmgr/drslot_chrp_slot.c
@@ -71,7 +71,10 @@ release_slot(struct dr_node *slot)
 	if (rc)
 		return rc;
 
-	rc = remove_device_tree_nodes(slot->ofdt_path);
+	if (kernel_dlpar_exists())
+		rc = do_dt_kernel_dlpar(slot->drc_index, REMOVE);
+	else
+		rc = remove_device_tree_nodes(slot->ofdt_path);
 	if (rc) {
 		acquire_drc(slot->drc_index);
 		return rc;
@@ -160,7 +163,6 @@ static int
 acquire_slot(char *drc_name, struct dr_node **slot)
 {
 	struct dr_connector drc;
-	struct of_node *of_nodes;
 	char path[DR_PATH_MAX];
 	int rc;
 
@@ -180,14 +182,21 @@ acquire_slot(char *drc_name, struct dr_node **slot)
 	if (rc)
 		return rc;
 
-	of_nodes = configure_connector(drc.index);
-	if (of_nodes == NULL) {
-		release_drc(drc.index, PCI_DLPAR_DEV);
-		return -1;
+	if (kernel_dlpar_exists()) {
+		rc = do_dt_kernel_dlpar(drc.index, ADD);
+	} else {
+		struct of_node *of_nodes;
+
+		of_nodes = configure_connector(drc.index);
+		if (of_nodes == NULL) {
+			release_drc(drc.index, PCI_DLPAR_DEV);
+			return -1;
+		}
+
+		rc = add_device_tree_nodes(path, of_nodes);
+		free_of_node(of_nodes);
 	}
 
-	rc = add_device_tree_nodes(path, of_nodes);
-	free_of_node(of_nodes);
 	if (rc) {
 		say(ERROR, "add_device_tree_nodes failed at %s\n", path);
 		release_drc(drc.index, PCI_DLPAR_DEV);
-- 
2.46.0

