[PATCH i-g-t v2 24/39] lib/chamelium/v3: Introduce new configuration format for MST support
Louis Chauvet
louis.chauvet at bootlin.com
Tue Jul 9 15:34:40 UTC 2024
The current Chamelium v2 configuration format does not accommodate MST
usage. To maintain compatibility with existing configuration files, this
commit introduces a new format with a distinct prefix for Chamelium v3
port mapping.
Support for the Chamelium v2 format is retained to facilitate the
transition between Chamelium v2 and v3. The v2 format will be used if the
v3 format is not present in the file.
Signed-off-by: Louis Chauvet <louis.chauvet at bootlin.com>
---
lib/chamelium/v3/igt_chamelium.c | 126 ++++++++++++++++++++++++++++++++++++++-
1 file changed, 123 insertions(+), 3 deletions(-)
diff --git a/lib/chamelium/v3/igt_chamelium.c b/lib/chamelium/v3/igt_chamelium.c
index d528b40ca0c7..26f6b83cd10a 100644
--- a/lib/chamelium/v3/igt_chamelium.c
+++ b/lib/chamelium/v3/igt_chamelium.c
@@ -13,6 +13,11 @@
#define CHAMELIUM_V2_CONFIG_PREFIX "Chamelium"
#define CHAMELIUM_V2_CONFIG_PORT_ID "ChameliumPortID"
+#define CHAMELIUM_V3_CONFIG_PORT_NAME "PortName"
+#define CHAMELIUM_V3_CONFIG_MST_PATH "MstPath"
+#define CHAMELIUM_V3_CONFIG_PARENT_ID "ChameliumParentID"
+#define CHAMELIUM_V3_CONFIG_AUTODETECT_SAVE "ChameliumAutodetectSave"
+
struct igt_chamelium_v3 {
xmlrpc_env env;
xmlrpc_client *client;
@@ -172,7 +177,7 @@ static void chamelium_v3_fill_port_mapping_from_config_v2(struct igt_chamelium_v
}
} else {
igt_warn("Skipping malformed entry %s: Missing "
- CHAMELIUM_V2_CONFIG_PORT_ID "\n",
+ CHAMELIUM_V2_CONFIG_PORT_ID "\n",
group_list[group_idx]);
chamelium_v3_port_mapping_free(port_mapping);
}
@@ -186,6 +191,115 @@ static void chamelium_v3_fill_port_mapping_from_config_v2(struct igt_chamelium_v
free(group_list);
}
+/**
+ * chamelium_v3_fill_port_mapping_from_config_v2() - Read the configuration file using the chamelium
+ * v3 format
+ *
+ * @chamelium: chamelium to store the port mapping into
+ *
+ * Read the configuration file to search a chamelium configuration, using the Cv3 format. It will
+ * ignore any malformed entry.
+ */
+static void chamelium_v3_fill_port_mapping_from_config_v3(struct igt_chamelium_v3 *chamelium)
+{
+ char **group_list;
+
+ igt_assert(igt_key_file);
+
+ group_list = g_key_file_get_groups(igt_key_file, NULL);
+ for (int group_idx = 0; group_list[group_idx]; group_idx++) {
+ if (strstr(group_list[group_idx], CHAMELIUM_CONFIG_SECTION ":")) {
+ struct chamelium_v3_port_mapping *port_mapping = NULL;
+ uint32_t chamelium_port_id;
+ char *tmp_end;
+ GError *error = NULL;
+ char *chamelium_port_id_str =
+ group_list[group_idx] + (sizeof(CHAMELIUM_CONFIG_SECTION ":") - 1);
+
+ errno = 0;
+ chamelium_port_id = strtoul(chamelium_port_id_str, &tmp_end, 0);
+
+ if (chamelium_port_id_str == tmp_end) {
+ igt_warn("Failed to read config file, expecting ["
+ CHAMELIUM_CONFIG_SECTION ":<int>], found %s\n",
+ group_list[group_idx]);
+ goto exit_loop;
+ } else if (errno == ERANGE) {
+ igt_warn("Range error during parsing of number, expecting \"%.*s\", strtolu returned %d",
+ (int)(tmp_end - chamelium_port_id_str),
+ chamelium_port_id_str, chamelium_port_id);
+ goto exit_loop;
+ }
+
+ port_mapping = chamelium_v3_port_mapping_alloc();
+ port_mapping->port_id = chamelium_port_id;
+
+ if (g_key_file_has_key(igt_key_file, group_list[group_idx],
+ CHAMELIUM_V3_CONFIG_PORT_NAME, NULL)) {
+ port_mapping->connector_name = g_key_file_get_string(igt_key_file,
+ group_list[group_idx],
+ CHAMELIUM_V3_CONFIG_PORT_NAME,
+ &error);
+ if (error) {
+ igt_info("Skipping malformed entry %s: %s\n",
+ group_list[group_idx], error->message);
+ goto exit_loop;
+ }
+ }
+
+ if (g_key_file_has_key(igt_key_file, group_list[group_idx],
+ CHAMELIUM_V3_CONFIG_MST_PATH, NULL)) {
+ port_mapping->mst_path = g_key_file_get_string(igt_key_file,
+ group_list[group_idx],
+ CHAMELIUM_V3_CONFIG_MST_PATH,
+ &error);
+ if (error) {
+ igt_warn("Skipping malformed entry %s: %s\n",
+ group_list[group_idx], error->message);
+ goto exit_loop;
+ }
+ }
+
+ if (g_key_file_has_key(igt_key_file, group_list[group_idx],
+ CHAMELIUM_V3_CONFIG_PARENT_ID, NULL)) {
+ port_mapping->parent_id = g_key_file_get_integer(igt_key_file,
+ group_list[group_idx],
+ CHAMELIUM_V3_CONFIG_PARENT_ID,
+ &error);
+ port_mapping->is_children = true;
+ if (error) {
+ igt_warn("Skipping malformed entry %s: %s\n",
+ group_list[group_idx],
+ error->message);
+ goto exit_loop;
+ }
+ }
+
+ if (port_mapping->is_children && !port_mapping->mst_path) {
+ igt_warn("If the port have a " CHAMELIUM_V3_CONFIG_PARENT_ID
+ ", it must also have an " CHAMELIUM_V3_CONFIG_MST_PATH
+ ". Skipping malformed entry %s.\n",
+ group_list[group_idx]);
+ goto exit_loop;
+ }
+
+ igt_list_add(&port_mapping->link, &chamelium->port_mapping);
+
+ if (error)
+ free(error);
+ continue;
+exit_loop:
+ if (error)
+ free(error);
+ if (port_mapping)
+ chamelium_v3_port_mapping_free(port_mapping);
+ }
+
+ free(group_list[group_idx]);
+ }
+ free(group_list);
+}
+
/**
* chamelium_v3_port_mapping_info_list() - Display the current configured port mapping for the
* chamelium
@@ -212,11 +326,17 @@ static void chamelium_v3_port_mapping_info_list(struct igt_list_head *head)
* structure.
*
* @chamelium: chamelium to store the port mapping into
+ *
+ * It will read the configuration file searching for a Cv3 configuration. If this configuration does
+ * not exist or is empty, it will try to read a Cv2 configuration.
*/
void chamelium_v3_fill_port_mapping(struct igt_chamelium_v3 *chamelium)
{
- if (igt_key_file)
- chamelium_v3_fill_port_mapping_from_config_v2(chamelium);
+ if (igt_key_file) {
+ chamelium_v3_fill_port_mapping_from_config_v3(chamelium);
+ if (igt_list_length(&chamelium->port_mapping) == 0)
+ chamelium_v3_fill_port_mapping_from_config_v2(chamelium);
+ }
chamelium_v3_port_mapping_info_list(&chamelium->port_mapping);
}
--
2.44.2
More information about the igt-dev
mailing list