[PATCH i-g-t v2 30/39] lib/chamelium/v3: Add save option to avoid doing autodetection every time

Louis Chauvet louis.chauvet at bootlin.com
Tue Jul 9 15:34:46 UTC 2024


Autodetection algorithm is slow. To help writing configuration files, add
an option save the configuration after an autodetection.

Signed-off-by: Louis Chauvet <louis.chauvet at bootlin.com>
---
 lib/chamelium/v3/igt_chamelium.c | 49 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/lib/chamelium/v3/igt_chamelium.c b/lib/chamelium/v3/igt_chamelium.c
index e5810e06dbc6..cf9eb330efe4 100644
--- a/lib/chamelium/v3/igt_chamelium.c
+++ b/lib/chamelium/v3/igt_chamelium.c
@@ -666,6 +666,43 @@ chamelium_v3_autodetect_mst_port(struct igt_chamelium_v3 *chamelium, int drm_fd,
 	free(port_name);
 }
 
+static void chamelium_v3_save_mapping(struct igt_chamelium_v3 *chamelium)
+{
+	struct chamelium_v3_port_mapping *tmp, *pos;
+	char *key_file_loc = NULL;
+	char *key_file_env = NULL;
+
+	igt_assert(chamelium);
+	igt_assert(igt_key_file);
+
+	igt_list_for_each_entry_safe(pos, tmp, &chamelium->port_mapping, link) {
+		char *section_name = NULL;
+
+		asprintf(&section_name, CHAMELIUM_CONFIG_SECTION ":%d", pos->port_id);
+		igt_assert(section_name);
+
+		if (pos->mst_path) {
+			g_key_file_set_string(igt_key_file, section_name,
+					      CHAMELIUM_V3_CONFIG_MST_PATH, pos->mst_path);
+			g_key_file_set_integer(igt_key_file, section_name,
+					       CHAMELIUM_V3_CONFIG_PARENT_ID, pos->parent_id);
+		} else {
+			g_key_file_set_string(igt_key_file, section_name,
+					      CHAMELIUM_V3_CONFIG_PORT_NAME, pos->connector_name);
+		}
+	}
+
+	key_file_env = getenv("IGT_CONFIG_PATH");
+	if (key_file_env) {
+		key_file_loc = key_file_env;
+	} else {
+		key_file_loc = malloc(100);
+		snprintf(key_file_loc, 100, "%s/.igtrc", g_get_home_dir());
+	}
+
+	g_key_file_save_to_file(igt_key_file, key_file_loc, NULL);
+}
+
 /**
  * chamelium_v3_fill_port_mapping() - Read the configuration file and fill the port_mapping
  *	structure.
@@ -705,6 +742,18 @@ void chamelium_v3_fill_port_mapping(struct igt_chamelium_v3 *chamelium, int drm_
 	}
 
 	chamelium_v3_port_mapping_info_list(&chamelium->port_mapping);
+
+	if (igt_key_file) {
+		if (g_key_file_get_boolean(igt_key_file, CHAMELIUM_CONFIG_SECTION, CHAMELIUM_V3_CONFIG_AUTODETECT_SAVE, NULL)) {
+			/*
+			 * Delete this option to avoid rewriting again the same configuration over
+			 * existing config file
+			 */
+			g_key_file_set_boolean(igt_key_file, CHAMELIUM_CONFIG_SECTION,
+					       CHAMELIUM_V3_CONFIG_AUTODETECT_SAVE, false);
+			chamelium_v3_save_mapping(chamelium);
+		}
+	}
 }
 
 /**

-- 
2.44.2



More information about the igt-dev mailing list