]> Gentwo Git Trees - linux/.git/commitdiff
drm/msm/registers: Fix encoding fields in 64b registers
authorRob Clark <robin.clark@oss.qualcomm.com>
Tue, 18 Nov 2025 15:29:49 +0000 (07:29 -0800)
committerRob Clark <robin.clark@oss.qualcomm.com>
Tue, 18 Nov 2025 15:31:59 +0000 (07:31 -0800)
Based on mesa commit 3f70b0578402 ("freedreno/registers: Fix encoding
fields in 64b registers"), but with some fixes to not skip emitting
interrupt enum values.

v2: Don't append "ull" to 32b reg MASK defines, to avoid printf format
    conversion warnings all over the place

Co-developed-by: Connor Abbott <cwabbott0@gmail.com>
Signed-off-by: Connor Abbott <cwabbott0@gmail.com>
Signed-off-by: Rob Clark <robin.clark@oss.qualcomm.com>
Patchwork: https://patchwork.freedesktop.org/patch/689141/
Message-ID: <20251118152952.226510-1-robin.clark@oss.qualcomm.com>

drivers/gpu/drm/msm/registers/gen_header.py

index 1d603dadfabd828ac7b94bb7351081d5d62a7f8a..2acad951f1e24a0dfa0bbf6dcff13e47a386fb9a 100644 (file)
@@ -189,12 +189,13 @@ class Bitset(object):
                print("    return (struct fd_reg_pair) {")
                print("        .reg = (uint32_t)%s," % reg.reg_offset())
                print("        .value =")
+               cast = "(uint64_t)" if reg.bit_size == 64 else ""
                for f in self.fields:
                        if f.type in [ "address", "waddress" ]:
                                continue
                        else:
                                type, val = f.ctype("fields.%s" % field_name(reg, f))
-                               print("            (%-40s << %2d) |" % (val, f.low))
+                               print("            (%s%-40s << %2d) |" % (cast, val, f.low))
                value_name = "dword"
                if reg.bit_size == 64:
                        value_name = "qword"
@@ -264,10 +265,11 @@ class Bitset(object):
                                  (prefix, prefix, prefix, skip))
 
 
-       def dump(self, is_deprecated, prefix=None):
+       def dump(self, is_deprecated, prefix=None, reg=None):
                if prefix is None:
                        prefix = self.name
-               if self.reg and self.reg.bit_size == 64:
+               reg64 = reg and self.reg and self.reg.bit_size == 64
+               if reg64:
                        print("static inline uint32_t %s_LO(uint32_t val)\n{" % prefix)
                        print("\treturn val;\n}")
                        print("static inline uint32_t %s_HI(uint32_t val)\n{" % prefix)
@@ -283,14 +285,17 @@ class Bitset(object):
                        elif f.type == "boolean" or (f.type is None and f.low == f.high):
                                tab_to("#define %s" % name, "0x%08x" % (1 << f.low))
                        else:
-                               tab_to("#define %s__MASK" % name, "0x%08x" % mask(f.low, f.high))
+                               typespec = "ull" if reg64 else "u"
+                               tab_to("#define %s__MASK" % name, "0x%08x%s" % (mask(f.low, f.high), typespec))
                                tab_to("#define %s__SHIFT" % name, "%d" % f.low)
                                type, val = f.ctype("val")
+                               ret_type = "uint64_t" if reg64 else "uint32_t"
+                               cast = "(uint64_t)" if reg64 else ""
 
-                               print("static inline uint32_t %s(%s val)\n{" % (name, type))
+                               print("static inline %s %s(%s val)\n{" % (ret_type, name, type))
                                if f.shr > 0:
                                        print("\tassert(!(val & 0x%x));" % mask(0, f.shr - 1))
-                               print("\treturn ((%s) << %s__SHIFT) & %s__MASK;\n}" % (val, name, name))
+                               print("\treturn (%s(%s) << %s__SHIFT) & %s__MASK;\n}" % (cast, val, name, name))
                print()
 
 class Array(object):
@@ -437,7 +442,7 @@ class Reg(object):
                        print("static inline%s uint32_t REG_%s(%s) { return 0x%08x + %s; }" % (depcrstr, self.full_name, proto, offset, strides))
 
                if self.bitset.inline:
-                       self.bitset.dump(is_deprecated, self.full_name)
+                       self.bitset.dump(is_deprecated, self.full_name, self)
                print("")
 
        def dump_pack_struct(self, is_deprecated):