Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

drm/msm/registers: Sync gen_header.py from mesa

Sync from mesa commit 04e2140d8be7 ("freedreno/registers: remove python
3.9 dependency for compiling msm").

Signed-off-by: Rob Clark <robin.clark@oss.qualcomm.com>
Patchwork: https://patchwork.freedesktop.org/patch/673556/

Rob Clark 90528176 f03464c6

+107 -50
+107 -50
drivers/gpu/drm/msm/registers/gen_header.py
··· 11 11 import argparse 12 12 import time 13 13 import datetime 14 - import re 15 14 16 15 class Error(Exception): 17 16 def __init__(self, message): ··· 30 31 def names(self): 31 32 return [n for (n, value) in self.values] 32 33 33 - def dump(self): 34 + def dump(self, is_deprecated): 34 35 use_hex = False 35 36 for (name, value) in self.values: 36 37 if value > 0x1000: ··· 44 45 print("\t%s = %d," % (name, value)) 45 46 print("};\n") 46 47 47 - def dump_pack_struct(self): 48 + def dump_pack_struct(self, is_deprecated): 48 49 pass 49 50 50 51 class Field(object): ··· 69 70 raise parser.error("booleans should be 1 bit fields") 70 71 elif self.type == "float" and not (high - low == 31 or high - low == 15): 71 72 raise parser.error("floats should be 16 or 32 bit fields") 72 - elif not self.type in builtin_types and not self.type in parser.enums: 73 + elif self.type not in builtin_types and self.type not in parser.enums: 73 74 raise parser.error("unknown type '%s'" % self.type) 74 75 75 76 def ctype(self, var_name): 76 - if self.type == None: 77 + if self.type is None: 77 78 type = "uint32_t" 78 79 val = var_name 79 80 elif self.type == "boolean": ··· 123 124 name = f.name.lower() 124 125 else: 125 126 # We hit this path when a reg is defined with no bitset fields, ie. 126 - # <reg32 offset="0x88db" name="RB_BLIT_DST_ARRAY_PITCH" low="0" high="28" shr="6" type="uint"/> 127 + # <reg32 offset="0x88db" name="RB_RESOLVE_SYSTEM_BUFFER_ARRAY_PITCH" low="0" high="28" shr="6" type="uint"/> 127 128 name = reg.name.lower() 128 129 129 130 if (name in [ "double", "float", "int" ]) or not (name[0].isalpha()): ··· 144 145 if stride else 145 146 "%s(i%d)" % (offset, idx) 146 147 for (idx, (ctype, stride, offset)) in enumerate(indices)]) 148 + 149 + def is_number(str): 150 + try: 151 + int(str) 152 + return True 153 + except ValueError: 154 + return False 155 + 156 + def sanitize_variant(variant): 157 + if variant and "-" in variant: 158 + return variant[:variant.index("-")] 159 + return variant 147 160 148 161 class Bitset(object): 149 162 def __init__(self, name, template): ··· 186 175 print("#endif\n") 187 176 188 177 print(" return (struct fd_reg_pair) {") 189 - if reg.array: 190 - print(" .reg = REG_%s(__i)," % reg.full_name) 191 - else: 192 - print(" .reg = REG_%s," % reg.full_name) 193 - 178 + print(" .reg = (uint32_t)%s," % reg.reg_offset()) 194 179 print(" .value =") 195 180 for f in self.fields: 196 181 if f.type in [ "address", "waddress" ]: ··· 211 204 212 205 print(" };") 213 206 214 - def dump_pack_struct(self, reg=None): 207 + def dump_pack_struct(self, is_deprecated, reg=None): 215 208 if not reg: 216 209 return 217 210 ··· 236 229 tab_to(" uint32_t", "dword;") 237 230 print("};\n") 238 231 232 + depcrstr = "" 233 + if is_deprecated: 234 + depcrstr = " FD_DEPRECATED" 239 235 if reg.array: 240 - print("static inline struct fd_reg_pair\npack_%s(uint32_t __i, struct %s fields)\n{" % 241 - (prefix, prefix)) 236 + print("static inline%s struct fd_reg_pair\npack_%s(uint32_t __i, struct %s fields)\n{" % 237 + (depcrstr, prefix, prefix)) 242 238 else: 243 - print("static inline struct fd_reg_pair\npack_%s(struct %s fields)\n{" % 244 - (prefix, prefix)) 239 + print("static inline%s struct fd_reg_pair\npack_%s(struct %s fields)\n{" % 240 + (depcrstr, prefix, prefix)) 245 241 246 242 self.dump_regpair_builder(reg) 247 243 ··· 263 253 (prefix, prefix, prefix, skip)) 264 254 265 255 266 - def dump(self, prefix=None): 267 - if prefix == None: 256 + def dump(self, is_deprecated, prefix=None): 257 + if prefix is None: 268 258 prefix = self.name 269 259 for f in self.fields: 270 260 if f.name: ··· 272 262 else: 273 263 name = prefix 274 264 275 - if not f.name and f.low == 0 and f.shr == 0 and not f.type in ["float", "fixed", "ufixed"]: 265 + if not f.name and f.low == 0 and f.shr == 0 and f.type not in ["float", "fixed", "ufixed"]: 276 266 pass 277 - elif f.type == "boolean" or (f.type == None and f.low == f.high): 267 + elif f.type == "boolean" or (f.type is None and f.low == f.high): 278 268 tab_to("#define %s" % name, "0x%08x" % (1 << f.low)) 279 269 else: 280 270 tab_to("#define %s__MASK" % name, "0x%08x" % mask(f.low, f.high)) ··· 296 286 self.domain = domain 297 287 self.variant = variant 298 288 self.parent = parent 289 + self.children = [] 299 290 if self.parent: 300 291 self.name = self.parent.name + "_" + self.local_name 301 292 else: ··· 348 337 offset += self.parent.total_offset() 349 338 return offset 350 339 351 - def dump(self): 340 + def dump(self, is_deprecated): 341 + depcrstr = "" 342 + if is_deprecated: 343 + depcrstr = " FD_DEPRECATED" 352 344 proto = indices_varlist(self.indices()) 353 345 strides = indices_strides(self.indices()) 354 346 array_offset = self.total_offset() 355 347 if self.fixed_offsets: 356 - print("static inline uint32_t __offset_%s(%s idx)" % (self.local_name, self.index_ctype())) 348 + print("static inline%s uint32_t __offset_%s(%s idx)" % (depcrstr, self.local_name, self.index_ctype())) 357 349 print("{\n\tswitch (idx) {") 358 350 if self.index_type: 359 351 for val, offset in zip(self.index_type.names(), self.offsets): ··· 371 357 else: 372 358 tab_to("#define REG_%s_%s(%s)" % (self.domain, self.name, proto), "(0x%08x + %s )\n" % (array_offset, strides)) 373 359 374 - def dump_pack_struct(self): 360 + def dump_pack_struct(self, is_deprecated): 375 361 pass 376 362 377 363 def dump_regpair_builder(self): ··· 387 373 self.bit_size = bit_size 388 374 if array: 389 375 self.name = array.name + "_" + self.name 376 + array.children.append(self) 390 377 self.full_name = self.domain + "_" + self.name 391 378 if "stride" in attrs: 392 379 self.stride = int(attrs["stride"], 0) ··· 412 397 else: 413 398 return self.offset 414 399 415 - def dump(self): 400 + def reg_offset(self): 401 + if self.array: 402 + offset = self.array.offset + self.offset 403 + return "(0x%08x + 0x%x*__i)" % (offset, self.array.stride) 404 + return "0x%08x" % self.offset 405 + 406 + def dump(self, is_deprecated): 407 + depcrstr = "" 408 + if is_deprecated: 409 + depcrstr = " FD_DEPRECATED " 416 410 proto = indices_prototype(self.indices()) 417 411 strides = indices_strides(self.indices()) 418 412 offset = self.total_offset() 419 413 if proto == '': 420 414 tab_to("#define REG_%s" % self.full_name, "0x%08x" % offset) 421 415 else: 422 - print("static inline uint32_t REG_%s(%s) { return 0x%08x + %s; }" % (self.full_name, proto, offset, strides)) 416 + print("static inline%s uint32_t REG_%s(%s) { return 0x%08x + %s; }" % (depcrstr, self.full_name, proto, offset, strides)) 423 417 424 418 if self.bitset.inline: 425 - self.bitset.dump(self.full_name) 419 + self.bitset.dump(is_deprecated, self.full_name) 420 + print("") 426 421 427 - def dump_pack_struct(self): 422 + def dump_pack_struct(self, is_deprecated): 428 423 if self.bitset.inline: 429 - self.bitset.dump_pack_struct(self) 424 + self.bitset.dump_pack_struct(is_deprecated, self) 430 425 431 426 def dump_regpair_builder(self): 432 - if self.bitset.inline: 433 - self.bitset.dump_regpair_builder(self) 427 + self.bitset.dump_regpair_builder(self) 434 428 435 429 def dump_py(self): 436 430 print("\tREG_%s = 0x%08x" % (self.full_name, self.offset)) ··· 475 451 476 452 def prefix(self, variant=None): 477 453 if self.current_prefix_type == "variant" and variant: 478 - return variant 454 + return sanitize_variant(variant) 479 455 elif self.current_stripe: 480 456 return self.current_stripe + "_" + self.current_domain 481 457 elif self.current_prefix: ··· 521 497 return varset 522 498 523 499 def parse_variants(self, attrs): 524 - if not "variants" in attrs: 500 + if "variants" not in attrs: 525 501 return None 526 - variant = attrs["variants"].split(",")[0] 527 - if "-" in variant: 528 - variant = variant[:variant.index("-")] 529 502 503 + variant = attrs["variants"].split(",")[0] 530 504 varset = self.parse_varset(attrs) 531 505 532 - assert varset.has_name(variant) 506 + if "-" in variant: 507 + # if we have a range, validate that both the start and end 508 + # of the range are valid enums: 509 + start = variant[:variant.index("-")] 510 + end = variant[variant.index("-") + 1:] 511 + assert varset.has_name(start) 512 + if end != "": 513 + assert varset.has_name(end) 514 + else: 515 + assert varset.has_name(variant) 533 516 534 517 return variant 535 518 ··· 600 569 error_str = str(xmlschema.error_log.filter_from_errors()[0]) 601 570 raise self.error("Schema validation failed for: " + filename + "\n" + error_str) 602 571 except ImportError as e: 603 - if self.validate: 604 - raise e 605 - 606 572 print("lxml not found, skipping validation", file=sys.stderr) 607 573 608 574 def do_parse(self, filename): ··· 668 640 elif name == "domain": 669 641 self.current_domain = attrs["name"] 670 642 if "prefix" in attrs: 671 - self.current_prefix = self.parse_variants(attrs) 643 + self.current_prefix = sanitize_variant(self.parse_variants(attrs)) 672 644 self.current_prefix_type = attrs["prefix"] 673 645 else: 674 646 self.current_prefix = None ··· 676 648 if "varset" in attrs: 677 649 self.current_varset = self.enums[attrs["varset"]] 678 650 elif name == "stripe": 679 - self.current_stripe = self.parse_variants(attrs) 651 + self.current_stripe = sanitize_variant(self.parse_variants(attrs)) 680 652 elif name == "enum": 681 653 self.current_enum_value = 0 682 654 self.current_enum = Enum(attrs["name"]) ··· 724 696 elif name == "reg32": 725 697 self.current_reg = None 726 698 elif name == "array": 699 + # if the array has no Reg children, push an implicit reg32: 700 + if len(self.current_array.children) == 0: 701 + attrs = { 702 + "name": "REG", 703 + "offset": "0", 704 + } 705 + self.parse_reg(attrs, 32) 727 706 self.current_array = self.current_array.parent 728 707 elif name == "enum": 729 708 self.current_enum = None ··· 746 711 if variants: 747 712 for variant, vreg in variants.items(): 748 713 if reg == vreg: 749 - d[(usage, variant)].append(reg) 714 + d[(usage, sanitize_variant(variant))].append(reg) 750 715 else: 751 716 for variant in self.variants: 752 - d[(usage, variant)].append(reg) 717 + d[(usage, sanitize_variant(variant))].append(reg) 753 718 754 719 print("#ifdef __cplusplus") 755 720 ··· 779 744 780 745 print("#endif") 781 746 747 + def has_variants(self, reg): 748 + return reg.name in self.variant_regs and not is_number(reg.name) and not is_number(reg.name[1:]) 749 + 782 750 def dump(self): 783 751 enums = [] 784 752 bitsets = [] ··· 795 757 regs.append(e) 796 758 797 759 for e in enums + bitsets + regs: 798 - e.dump() 760 + e.dump(self.has_variants(e)) 799 761 800 762 self.dump_reg_usages() 801 763 ··· 811 773 812 774 813 775 def dump_reg_variants(self, regname, variants): 814 - # Don't bother for things that only have a single variant: 815 - if len(variants) == 1: 776 + if is_number(regname) or is_number(regname[1:]): 816 777 return 817 778 print("#ifdef __cplusplus") 818 779 print("struct __%s {" % regname) ··· 862 825 xtravar = "__i, " 863 826 print("__%s(%sstruct __%s fields) {" % (regname, xtra, regname)) 864 827 for variant in variants.keys(): 865 - print(" if (%s == %s) {" % (varenum.upper(), variant)) 828 + if "-" in variant: 829 + start = variant[:variant.index("-")] 830 + end = variant[variant.index("-") + 1:] 831 + if end != "": 832 + print(" if ((%s >= %s) && (%s <= %s)) {" % (varenum.upper(), start, varenum.upper(), end)) 833 + else: 834 + print(" if (%s >= %s) {" % (varenum.upper(), start)) 835 + else: 836 + print(" if (%s == %s) {" % (varenum.upper(), variant)) 866 837 reg = variants[variant] 867 838 reg.dump_regpair_builder() 868 839 print(" } else") 869 840 print(" assert(!\"invalid variant\");") 841 + print(" return (struct fd_reg_pair){};") 870 842 print("}") 871 843 872 844 if bit_size == 64: ··· 888 842 889 843 def dump_structs(self): 890 844 for e in self.file: 891 - e.dump_pack_struct() 845 + e.dump_pack_struct(self.has_variants(e)) 892 846 893 847 for regname in self.variant_regs: 894 848 self.dump_reg_variants(regname, self.variant_regs[regname]) ··· 923 877 print("#endif") 924 878 print() 925 879 880 + print("#ifndef FD_NO_DEPRECATED_PACK") 881 + print("#define FD_DEPRECATED __attribute__((deprecated))") 882 + print("#else") 883 + print("#define FD_DEPRECATED") 884 + print("#endif") 885 + print() 886 + 926 887 func(p) 927 888 928 - print("\n#endif /* %s */" % guard) 889 + print() 890 + print("#undef FD_DEPRECATED") 891 + print() 892 + 893 + print("#endif /* %s */" % guard) 929 894 930 895 931 896 def dump_c_defines(args): ··· 953 896 p = Parser() 954 897 955 898 try: 956 - p.parse(args.rnn, args.xml) 899 + p.parse(args.rnn, args.xml, args.validate) 957 900 except Error as e: 958 901 print(e, file=sys.stderr) 959 902 exit(1)