[PATCH i-g-t 20/20] tools/intel_vbt_decode: Decode device handle as a bitmask

Ville Syrjala ville.syrjala at linux.intel.com
Fri May 31 14:23:54 UTC 2024


From: Ville Syrjälä <ville.syrjala at linux.intel.com>

Some VBT blocks contain bitmasks of device handles (where multiple
bits can be set simultanously). Allow decoding such things by
having child_device_handle() take in the whole bitmask instead of
assuming just one bit.

We'll cheat a bit with a static buffer for the output string.
That should be fine given the simplicity of the tool.

Signed-off-by: Ville Syrjälä <ville.syrjala at linux.intel.com>
---
 tools/intel_vbt_decode.c | 29 +++++++++++++++++++++++++----
 1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/tools/intel_vbt_decode.c b/tools/intel_vbt_decode.c
index b0c30ffcbc0a..40c05fbadacb 100644
--- a/tools/intel_vbt_decode.c
+++ b/tools/intel_vbt_decode.c
@@ -820,9 +820,17 @@ static const int num_child_device_handles =
 static const char *child_device_handle(struct context *context,
 				       uint16_t handle)
 {
-	int i;
+	static char buffer[64];
+	size_t len = sizeof(buffer);
+	char *ptr = buffer;
+	bool first = true;
+
+	if (handle == 0)
+		return "none";
+
+	for (int i = 0; i < num_child_device_handles; i++) {
+		int r;
 
-	for (i = 0; i < num_child_device_handles; i++) {
 		if (!(child_device_handles[i].handle & handle))
 			continue;
 
@@ -834,10 +842,23 @@ static const char *child_device_handle(struct context *context,
 		    context->bdb->version > child_device_handles[i].max_ver)
 			continue;
 
-		return child_device_handles[i].name;
+		handle &= ~child_device_handles[i].handle;
+
+		r = snprintf(ptr, len, "%s%s", first ? "" : ",",
+			     child_device_handles[i].name);
+		if (r < 0 || r >= len)
+			break;
+
+		first = false;
+		ptr += r;
+		len -= r;
 	}
 
-	return "unknown";
+	if (handle)
+		snprintf(ptr, len, "%sunknown(0x%x)",
+			 first ? "" : ",", handle);
+
+	return buffer;
 }
 
 static const char *dvo_port_names[] = {
-- 
2.44.1



More information about the igt-dev mailing list