[1/3] utils: codegen: gen-formats: Resolve Broadcom SAND modifiers
diff mbox series

Message ID 20260626120041.627376-2-naush@raspberrypi.com
State New
Headers show
Series
  • Add NV12MT_COL128 8/10-bit pixel formats
Related show

Commit Message

Naushir Patuck June 26, 2026, 11:54 a.m. UTC
The Broadcom SAND (coloumn mode) modifiers are defined through the
fourcc_mod_broadcom_code() column-height helper rather than a plain
fourcc_mod_code(), so the generator script cannot not resolve them.

Collapse line continuations and match the helper form so formats may
reference the DRM_FORMAT_MOD_BROADCOM_SAND* modifiers.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
---
 utils/codegen/gen-formats.py | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

Patch
diff mbox series

diff --git a/utils/codegen/gen-formats.py b/utils/codegen/gen-formats.py
index 740790e8f1a6..add04558f65f 100755
--- a/utils/codegen/gen-formats.py
+++ b/utils/codegen/gen-formats.py
@@ -18,13 +18,22 @@  class DRMFourCC(object):
     format_regex = re.compile(r"#define (DRM_FORMAT_[A-Z0-9_]+)[ \t]+fourcc_code\(('.', '.', '.', '.')\)")
     mod_vendor_regex = re.compile(r"#define DRM_FORMAT_MOD_VENDOR_([A-Z0-9_]+)[ \t]+([0-9a-fA-Fx]+)")
     mod_regex = re.compile(r"#define ([A-Za-z0-9_]+)[ \t]+fourcc_mod_code\(([A-Z0-9_]+), ([0-9a-fA-Fx]+)\)")
+    # Broadcom SAND modifiers are defined indirectly via a _COL_HEIGHT(v) helper
+    # that wraps fourcc_mod_broadcom_code(<code>, v) (which injects the BROADCOM
+    # vendor). Match that helper, strip _COL_HEIGHT to recover the convenience
+    # macro name, and use <code> as the value - valid as the convenience macro is
+    # the height-0 case, which contributes nothing to it.
+    mod_brcm_regex = re.compile(r"#define (DRM_FORMAT_MOD_BROADCOM_SAND[0-9]+)_COL_HEIGHT\(v\)"
+                                r"[ \t]+fourcc_mod_broadcom_code\(([0-9]+), v\)")
 
     def __init__(self, file):
         self.formats = {}
         self.vendors = {}
         self.mods = {}
 
-        for line in file:
+        # Collapse line continuations so multi-line macros match on one line.
+        lines = re.sub(r'\\[ \t]*\n', ' ', file.read()).splitlines()
+        for line in lines:
             match = DRMFourCC.format_regex.match(line)
             if match:
                 format, fourcc = match.groups()
@@ -43,6 +52,12 @@  class DRMFourCC(object):
                 self.mods[mod] = (vendor, int(value, 0))
                 continue
 
+            match = DRMFourCC.mod_brcm_regex.match(line)
+            if match:
+                mod, code = match.groups()
+                self.mods[mod] = ('BROADCOM', int(code))
+                continue
+
     def fourcc(self, name):
         return self.formats[name]