From 5c892e4f44b97ada013adc9438bb0c827c7ba85e Mon Sep 17 00:00:00 2001 From: Alessandro Comodi Date: Thu, 14 Jan 2021 16:24:43 +0100 Subject: [PATCH 1/9] 063-gtp-common: enable gtp_common in mergedb Signed-off-by: Alessandro Comodi --- utils/mergedb.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/utils/mergedb.sh b/utils/mergedb.sh index 4ff5f41c..5ea2b5dc 100755 --- a/utils/mergedb.sh +++ b/utils/mergedb.sh @@ -160,6 +160,9 @@ case "$1" in pcie_bot) cp "$2" "$tmp1" ;; + gtp_common) + cp "$2" "$tmp1" ;; + mask_*) db=$XRAY_DATABASE_DIR/$XRAY_DATABASE/$1.db ismask=true From ccccd20ed8bca3ab5ef7296c081944a09247fa12 Mon Sep 17 00:00:00 2001 From: Alessandro Comodi Date: Thu, 14 Jan 2021 16:25:06 +0100 Subject: [PATCH 2/9] 063-gtp-common: add gtp_common fuzzer Signed-off-by: Alessandro Comodi --- fuzzers/063-gtp-common-conf/Makefile | 27 ++++++ fuzzers/063-gtp-common-conf/attrs.json | 103 +++++++++++++++++++++++ fuzzers/063-gtp-common-conf/bits.dbf | 0 fuzzers/063-gtp-common-conf/generate.py | 75 +++++++++++++++++ fuzzers/063-gtp-common-conf/generate.tcl | 28 ++++++ fuzzers/063-gtp-common-conf/top.py | 97 +++++++++++++++++++++ 6 files changed, 330 insertions(+) create mode 100644 fuzzers/063-gtp-common-conf/Makefile create mode 100644 fuzzers/063-gtp-common-conf/attrs.json create mode 100644 fuzzers/063-gtp-common-conf/bits.dbf create mode 100644 fuzzers/063-gtp-common-conf/generate.py create mode 100644 fuzzers/063-gtp-common-conf/generate.tcl create mode 100644 fuzzers/063-gtp-common-conf/top.py diff --git a/fuzzers/063-gtp-common-conf/Makefile b/fuzzers/063-gtp-common-conf/Makefile new file mode 100644 index 00000000..2992e447 --- /dev/null +++ b/fuzzers/063-gtp-common-conf/Makefile @@ -0,0 +1,27 @@ +# Copyright (C) 2017-2020 The Project X-Ray Authors. +# +# Use of this source code is governed by a ISC-style +# license that can be found in the LICENSE file or at +# https://opensource.org/licenses/ISC +# +# SPDX-License-Identifier: ISC +N ?= 20 + +include ../fuzzer.mk + +database: build/segbits_gtp_common.db + +build/segbits_gtp_common.rdb: $(SPECIMENS_OK) + ${XRAY_SEGMATCH} -o build/segbits_gtp_common.rdb $(addsuffix /segdata_gtp_common.txt,$(SPECIMENS)) + +build/segbits_gtp_common.db: build/segbits_gtp_common.rdb + ${XRAY_DBFIXUP} --db-root build --zero-db bits.dbf \ + --seg-fn-in build/segbits_gtp_common.rdb \ + --seg-fn-out build/segbits_gtp_common.db + ${XRAY_MASKMERGE} build/mask_gtp_common.db $(addsuffix /segdata_gtp_common.txt,$(SPECIMENS)) + +pushdb: + ${XRAY_MERGEDB} gtp_common build/segbits_gtp_common.db + ${XRAY_MERGEDB} mask_gtp_common build/mask_gtp_common.db + +.PHONY: database pushdb diff --git a/fuzzers/063-gtp-common-conf/attrs.json b/fuzzers/063-gtp-common-conf/attrs.json new file mode 100644 index 00000000..e41c0a4a --- /dev/null +++ b/fuzzers/063-gtp-common-conf/attrs.json @@ -0,0 +1,103 @@ +{ + "PLL0_CFG": { + "type": "BIN", + "values": [134150145], + "digits": 27 + }, + "PLL0_REFCLK_DIV": { + "type": "INT", + "values": [1, 2], + "encoding": [16, 0], + "digits": 5 + }, + "PLL0_FBDIV_45": { + "type": "INT", + "values": [4, 5], + "encoding": [0, 1], + "digits": 1 + }, + "PLL0_FBDIV": { + "type": "INT", + "values": [1, 2, 3, 4, 5], + "encoding": [16, 0, 1, 2, 3], + "digits": 6 + }, + "PLL0_LOCK_CFG": { + "type": "BIN", + "values": [511], + "digits": 9 + }, + "PLL0_INIT_CFG": { + "type": "BIN", + "values": [16711425], + "digits": 24 + }, + "RSVD_ATTR0": { + "type": "BIN", + "values": [65535], + "digits": 16 + }, + "PLL1_DMON_CFG": { + "type": "BIN", + "values": [1], + "digits": 1 + }, + "PLL0_DMON_CFG": { + "type": "BIN", + "values": [1], + "digits": 1 + }, + "COMMON_CFG": { + "type": "BIN", + "values": [4294836225], + "digits": 32 + }, + "PLL_CLKOUT_CFG": { + "type": "BIN", + "values": [255], + "digits": 8 + }, + "BIAS_CFG": { + "type": "BIN", + "values": [18445618199572250625], + "digits": 64 + }, + "RSVD_ATTR1": { + "type": "BIN", + "values": [65535], + "digits": 16 + }, + "PLL1_INIT_CFG": { + "type": "BIN", + "values": [16711425], + "digits": 24 + }, + "PLL1_LOCK_CFG": { + "type": "BIN", + "values": [511], + "digits": 9 + }, + "PLL1_REFCLK_DIV": { + "type": "INT", + "values": [1, 2], + "encoding": [16, 0], + "digits": 5 + }, + "PLL1_FBDIV_45": { + "type": "INT", + "values": [4, 5], + "encoding": [0, 1], + "digits": 1 + }, + "PLL1_FBDIV": { + "type": "INT", + "values": [1, 2, 3, 4, 5], + "encoding": [16, 0, 1, 2, 3], + "digits": 6 + }, + "PLL1_CFG": { + "type": "BIN", + "values": [134150145], + "digits": 27 + } +} \ No newline at end of file diff --git a/fuzzers/063-gtp-common-conf/bits.dbf b/fuzzers/063-gtp-common-conf/bits.dbf new file mode 100644 index 00000000..e69de29b diff --git a/fuzzers/063-gtp-common-conf/generate.py b/fuzzers/063-gtp-common-conf/generate.py new file mode 100644 index 00000000..dda8cf81 --- /dev/null +++ b/fuzzers/063-gtp-common-conf/generate.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# Copyright (C) 2017-2020 The Project X-Ray Authors. +# +# Use of this source code is governed by a ISC-style +# license that can be found in the LICENSE file or at +# https://opensource.org/licenses/ISC +# +# SPDX-License-Identifier: ISC + +import json +import os +from enum import Enum + +from prjxray.segmaker import Segmaker + +INT = "INT" +BIN = "BIN" + + +def bitfilter(frame, bit): + # Filter out interconnect bits. + if frame not in [28, 29]: + return False + + return True + + +def main(): + segmk = Segmaker("design.bits") + + fuz_dir = os.getenv("FUZDIR", None) + assert fuz_dir + with open(os.path.join(fuz_dir, "attrs.json"), "r") as attr_file: + attrs = json.load(attr_file) + + print("Loading tags") + with open('params.json') as f: + params = json.load(f) + + site = params['site'] + + for param, param_info in attrs.items(): + value = params[param] + param_type = param_info["type"] + param_digits = param_info["digits"] + param_values = param_info["values"] + + if param_type == INT: + param_encodings = param_info["encoding"] + param_encoding = param_encodings[param_values.index(value)] + bitstr = [ + int(x) for x in "{value:0{digits}b}".format( + value=param_encoding, digits=param_digits)[::-1] + ] + + for i in range(param_digits): + segmk.add_site_tag(site, '%s[%u]' % (param, i), bitstr[i]) + else: + assert param_type == BIN + bitstr = [ + int(x) for x in "{value:0{digits}b}".format( + value=value, digits=param_digits)[::-1] + ] + + for i in range(param_digits): + segmk.add_site_tag(site, '%s[%u]' % (param, i), bitstr[i]) + + segmk.compile(bitfilter=bitfilter) + segmk.write() + + +if __name__ == '__main__': + main() diff --git a/fuzzers/063-gtp-common-conf/generate.tcl b/fuzzers/063-gtp-common-conf/generate.tcl new file mode 100644 index 00000000..ab44e0cb --- /dev/null +++ b/fuzzers/063-gtp-common-conf/generate.tcl @@ -0,0 +1,28 @@ +# Copyright (C) 2017-2020 The Project X-Ray Authors +# +# Use of this source code is governed by a ISC-style +# license that can be found in the LICENSE file or at +# https://opensource.org/licenses/ISC +# +# SPDX-License-Identifier: ISC +proc run {} { + create_project -force -part $::env(XRAY_PART) design design + read_verilog top.v + synth_design -top top + + set_property CFGBVS VCCO [current_design] + set_property CONFIG_VOLTAGE 3.3 [current_design] + set_property BITSTREAM.GENERAL.PERFRAMECRC YES [current_design] + + set_property IS_ENABLED 0 [get_drc_checks {NSTD-1}] + set_property IS_ENABLED 0 [get_drc_checks {UCIO-1}] + set_property IS_ENABLED 0 [get_drc_checks {REQP-48}] + + place_design + route_design + + write_checkpoint -force design.dcp + write_bitstream -force design.bit +} + +run diff --git a/fuzzers/063-gtp-common-conf/top.py b/fuzzers/063-gtp-common-conf/top.py new file mode 100644 index 00000000..cdad5b9b --- /dev/null +++ b/fuzzers/063-gtp-common-conf/top.py @@ -0,0 +1,97 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# Copyright (C) 2017-2020 The Project X-Ray Authors. +# +# Use of this source code is governed by a ISC-style +# license that can be found in the LICENSE file or at +# https://opensource.org/licenses/ISC +# +# SPDX-License-Identifier: ISC + +import json +import os +import random +from collections import namedtuple + +random.seed(int(os.getenv("SEED"), 16)) +from prjxray import util +from prjxray import verilog +from prjxray.db import Database + +INT = "INT" +BIN = "BIN" + + +def gen_sites(): + db = Database(util.get_db_root(), util.get_part()) + grid = db.grid() + for tile_name in sorted(grid.tiles()): + loc = grid.loc_of_tilename(tile_name) + gridinfo = grid.gridinfo_at_loc(loc) + + if gridinfo.tile_type not in [ + "GTP_COMMON", + "GTP_COMMON_MID_RIGHT", + "GTP_COMMON_MID_RIGHT", + ]: + continue + + for site_name, site_type in gridinfo.sites.items(): + if site_type != "GTPE2_COMMON": + continue + + return site_name, site_type + + +def main(): + print(''' +module top(); +''') + + site_name, site_type = gen_sites() + + params = dict() + params['site'] = site_name + + verilog_attr = "" + + verilog_attr = "#(" + + fuz_dir = os.getenv("FUZDIR", None) + assert fuz_dir + with open(os.path.join(fuz_dir, "attrs.json"), "r") as attrs_file: + attrs = json.load(attrs_file) + + for param, param_info in attrs.items(): + param_type = param_info["type"] + param_values = param_info["values"] + param_digits = param_info["digits"] + + if param_type == INT: + value = random.choice(param_values) + value_str = value + else: + assert param_type == BIN + value = random.randint(0, param_values[0]) + value_str = "{digits}'b{value:0{digits}b}".format( + value=value, digits=param_digits) + + params[param] = value + + verilog_attr += """ + .{}({}),""".format(param, value_str) + + verilog_attr = verilog_attr.rstrip(",") + verilog_attr += "\n)" + + print("(* KEEP, DONT_TOUCH *)") + print("GTPE2_COMMON {} gtp_common ();".format(verilog_attr)) + print("endmodule") + + with open('params.json', 'w') as f: + json.dump(params, f, indent=2) + + +if __name__ == '__main__': + main() From 703688478492bba3b621fc9f680a5f6da4c1d283 Mon Sep 17 00:00:00 2001 From: Alessandro Comodi Date: Fri, 15 Jan 2021 13:11:20 +0100 Subject: [PATCH 3/9] 063-gtp-common: add inverted and in_use features Signed-off-by: Alessandro Comodi --- fuzzers/063-gtp-common-conf/generate.py | 18 +++++-- fuzzers/063-gtp-common-conf/top.py | 66 +++++++++++++++++-------- 2 files changed, 60 insertions(+), 24 deletions(-) diff --git a/fuzzers/063-gtp-common-conf/generate.py b/fuzzers/063-gtp-common-conf/generate.py index dda8cf81..efe3d5ca 100644 --- a/fuzzers/063-gtp-common-conf/generate.py +++ b/fuzzers/063-gtp-common-conf/generate.py @@ -36,11 +36,15 @@ def main(): attrs = json.load(attr_file) print("Loading tags") - with open('params.json') as f: + with open("params.json") as f: params = json.load(f) - site = params['site'] + site = params["site"] + in_use = params["IN_USE"] + segmk.add_site_tag(site, "IN_USE", in_use) + + if in_use: for param, param_info in attrs.items(): value = params[param] param_type = param_info["type"] @@ -65,7 +69,15 @@ def main(): ] for i in range(param_digits): - segmk.add_site_tag(site, '%s[%u]' % (param, i), bitstr[i]) + segmk.add_site_tag(site, "%s[%u]" % (param, i), bitstr[i]) + + for param, invert in [("GTGREFCLK1", 0), ("GTGREFCLK0", 0), + ("PLL0LOCKDETCLK", 1), ("PLL1LOCKDETCLK", + 1), ("DRPCLK", 1)]: + if invert: + segmk.add_site_tag(site, "ZINV_" + param, 1 ^ params[param]) + else: + segmk.add_site_tag(site, "INV_" + param, params[param]) segmk.compile(bitfilter=bitfilter) segmk.write() diff --git a/fuzzers/063-gtp-common-conf/top.py b/fuzzers/063-gtp-common-conf/top.py index cdad5b9b..f4b6dda2 100644 --- a/fuzzers/063-gtp-common-conf/top.py +++ b/fuzzers/063-gtp-common-conf/top.py @@ -45,8 +45,14 @@ def gen_sites(): def main(): - print(''' -module top(); + print( + ''' +module top( + input wire in, + output wire out +); + +assign out = in; ''') site_name, site_type = gen_sites() @@ -63,30 +69,48 @@ module top(); with open(os.path.join(fuz_dir, "attrs.json"), "r") as attrs_file: attrs = json.load(attrs_file) - for param, param_info in attrs.items(): - param_type = param_info["type"] - param_values = param_info["values"] - param_digits = param_info["digits"] + in_use = bool(random.randint(0, 9)) + params["IN_USE"] = in_use - if param_type == INT: - value = random.choice(param_values) - value_str = value - else: - assert param_type == BIN - value = random.randint(0, param_values[0]) - value_str = "{digits}'b{value:0{digits}b}".format( - value=value, digits=param_digits) + if in_use: + for param, param_info in attrs.items(): + param_type = param_info["type"] + param_values = param_info["values"] + param_digits = param_info["digits"] - params[param] = value + if param_type == INT: + value = random.choice(param_values) + value_str = value + else: + assert param_type == BIN + value = random.randint(0, param_values[0]) + value_str = "{digits}'b{value:0{digits}b}".format( + value=value, digits=param_digits) - verilog_attr += """ - .{}({}),""".format(param, value_str) + params[param] = value - verilog_attr = verilog_attr.rstrip(",") - verilog_attr += "\n)" + verilog_attr += """ + .{}({}),""".format(param, value_str) + + for param in ["GTGREFCLK1", "GTGREFCLK0", "PLL0LOCKDETCLK", + "PLL1LOCKDETCLK", "DRPCLK"]: + is_inverted = random.randint(0, 1) + + params[param] = is_inverted + + verilog_attr += """ + .IS_{}_INVERTED({}),""".format(param, is_inverted) + + verilog_attr = verilog_attr.rstrip(",") + verilog_attr += "\n)" + + print("(* KEEP, DONT_TOUCH *)") + print( + """GTPE2_COMMON {} gtp_common ( + .GTREFCLK0(1'b0), + .GTREFCLK1(1'b0) +);""".format(verilog_attr)) - print("(* KEEP, DONT_TOUCH *)") - print("GTPE2_COMMON {} gtp_common ();".format(verilog_attr)) print("endmodule") with open('params.json', 'w') as f: From 10f4ea1de5f48358e83c4c715f70f50669785da6 Mon Sep 17 00:00:00 2001 From: Alessandro Comodi Date: Mon, 18 Jan 2021 15:27:25 +0100 Subject: [PATCH 4/9] 063-gtp-common: handle both gtp_common and gtp_common_mid Signed-off-by: Alessandro Comodi --- fuzzers/063-gtp-common-conf/Makefile | 33 +++++++-- fuzzers/063-gtp-common-conf/generate.py | 74 ++++++++++---------- fuzzers/063-gtp-common-conf/pushdb.sh | 15 +++++ fuzzers/063-gtp-common-conf/top.py | 90 +++++++++++++------------ 4 files changed, 128 insertions(+), 84 deletions(-) create mode 100644 fuzzers/063-gtp-common-conf/pushdb.sh diff --git a/fuzzers/063-gtp-common-conf/Makefile b/fuzzers/063-gtp-common-conf/Makefile index 2992e447..386d2b3f 100644 --- a/fuzzers/063-gtp-common-conf/Makefile +++ b/fuzzers/063-gtp-common-conf/Makefile @@ -5,23 +5,46 @@ # https://opensource.org/licenses/ISC # # SPDX-License-Identifier: ISC + +SHELL = bash + N ?= 20 -include ../fuzzer.mk +SPECIMENS := $(addprefix build/specimen_,$(shell seq -f '%03.0f' $(N))) +SPECIMENS_OK := $(addsuffix /OK,$(SPECIMENS)) +FUZDIR ?= ${PWD} + +all: database + +# generate.sh / top_generate.sh call make, hence the command must +# have a + before it. +$(SPECIMENS_OK): $(SPECIMENS_DEPS) + mkdir -p build + bash ${XRAY_DIR}/utils/top_generate.sh $(subst /OK,,$@) + +run: + $(MAKE) clean + $(MAKE) database + $(MAKE) pushdb + touch run.${XRAY_PART}.ok + +clean: + rm -rf build run.ok + +.PHONY: all run clean database: build/segbits_gtp_common.db build/segbits_gtp_common.rdb: $(SPECIMENS_OK) - ${XRAY_SEGMATCH} -o build/segbits_gtp_common.rdb $(addsuffix /segdata_gtp_common.txt,$(SPECIMENS)) + ${XRAY_SEGMATCH} -o build/segbits_gtp_common.rdb $$(find $(SPECIMENS) -name "segdata_gtp_common*") build/segbits_gtp_common.db: build/segbits_gtp_common.rdb ${XRAY_DBFIXUP} --db-root build --zero-db bits.dbf \ --seg-fn-in build/segbits_gtp_common.rdb \ --seg-fn-out build/segbits_gtp_common.db - ${XRAY_MASKMERGE} build/mask_gtp_common.db $(addsuffix /segdata_gtp_common.txt,$(SPECIMENS)) + ${XRAY_MASKMERGE} build/mask_gtp_common.db $$(find $(SPECIMENS) -name "segdata_gtp_common*") pushdb: - ${XRAY_MERGEDB} gtp_common build/segbits_gtp_common.db - ${XRAY_MERGEDB} mask_gtp_common build/mask_gtp_common.db + source pushdb.sh .PHONY: database pushdb diff --git a/fuzzers/063-gtp-common-conf/generate.py b/fuzzers/063-gtp-common-conf/generate.py index efe3d5ca..14ed3c88 100644 --- a/fuzzers/063-gtp-common-conf/generate.py +++ b/fuzzers/063-gtp-common-conf/generate.py @@ -21,7 +21,7 @@ BIN = "BIN" def bitfilter(frame, bit): # Filter out interconnect bits. - if frame not in [28, 29]: + if frame not in [28, 29, 0, 1]: return False return True @@ -37,47 +37,51 @@ def main(): print("Loading tags") with open("params.json") as f: - params = json.load(f) + params_list = json.load(f) - site = params["site"] - in_use = params["IN_USE"] + for params in params_list: + site = params["site"] + in_use = params["IN_USE"] - segmk.add_site_tag(site, "IN_USE", in_use) + segmk.add_site_tag(site, "IN_USE", in_use) - if in_use: - for param, param_info in attrs.items(): - value = params[param] - param_type = param_info["type"] - param_digits = param_info["digits"] - param_values = param_info["values"] + if in_use: + for param, param_info in attrs.items(): + value = params[param] + param_type = param_info["type"] + param_digits = param_info["digits"] + param_values = param_info["values"] - if param_type == INT: - param_encodings = param_info["encoding"] - param_encoding = param_encodings[param_values.index(value)] - bitstr = [ - int(x) for x in "{value:0{digits}b}".format( - value=param_encoding, digits=param_digits)[::-1] - ] + if param_type == INT: + param_encodings = param_info["encoding"] + param_encoding = param_encodings[param_values.index(value)] + bitstr = [ + int(x) for x in "{value:0{digits}b}".format( + value=param_encoding, digits=param_digits)[::-1] + ] - for i in range(param_digits): - segmk.add_site_tag(site, '%s[%u]' % (param, i), bitstr[i]) - else: - assert param_type == BIN - bitstr = [ - int(x) for x in "{value:0{digits}b}".format( - value=value, digits=param_digits)[::-1] - ] + for i in range(param_digits): + segmk.add_site_tag( + site, '%s[%u]' % (param, i), bitstr[i]) + else: + assert param_type == BIN + bitstr = [ + int(x) for x in "{value:0{digits}b}".format( + value=value, digits=param_digits)[::-1] + ] - for i in range(param_digits): - segmk.add_site_tag(site, "%s[%u]" % (param, i), bitstr[i]) + for i in range(param_digits): + segmk.add_site_tag( + site, "%s[%u]" % (param, i), bitstr[i]) - for param, invert in [("GTGREFCLK1", 0), ("GTGREFCLK0", 0), - ("PLL0LOCKDETCLK", 1), ("PLL1LOCKDETCLK", - 1), ("DRPCLK", 1)]: - if invert: - segmk.add_site_tag(site, "ZINV_" + param, 1 ^ params[param]) - else: - segmk.add_site_tag(site, "INV_" + param, params[param]) + for param, invert in [("GTGREFCLK1", 0), ("GTGREFCLK0", 0), + ("PLL0LOCKDETCLK", 1), ("PLL1LOCKDETCLK", + 1), ("DRPCLK", 1)]: + if invert: + segmk.add_site_tag( + site, "ZINV_" + param, 1 ^ params[param]) + else: + segmk.add_site_tag(site, "INV_" + param, params[param]) segmk.compile(bitfilter=bitfilter) segmk.write() diff --git a/fuzzers/063-gtp-common-conf/pushdb.sh b/fuzzers/063-gtp-common-conf/pushdb.sh new file mode 100644 index 00000000..b383f17f --- /dev/null +++ b/fuzzers/063-gtp-common-conf/pushdb.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +if ! test $(find . -name "segdata_gtp_common_mid_right.txt" | wc -c) -eq 0 +then + ${XRAY_MERGEDB} gtp_common_mid_right build/segbits_gtp_common.db + ${XRAY_MERGEDB} mask_gtp_common_mid_right build/mask_gtp_common.db + ${XRAY_MERGEDB} gtp_common_mid_left build/segbits_gtp_common.db + ${XRAY_MERGEDB} mask_gtp_common_mid_left build/mask_gtp_common.db +fi + +if ! test $(find . -name "segdata_gtp_common.txt" | wc -c) -eq 0 +then + ${XRAY_MERGEDB} gtp_common build/segbits_gtp_common.db + ${XRAY_MERGEDB} mask_gtp_common build/mask_gtp_common.db +fi diff --git a/fuzzers/063-gtp-common-conf/top.py b/fuzzers/063-gtp-common-conf/top.py index f4b6dda2..abd9b318 100644 --- a/fuzzers/063-gtp-common-conf/top.py +++ b/fuzzers/063-gtp-common-conf/top.py @@ -33,7 +33,6 @@ def gen_sites(): if gridinfo.tile_type not in [ "GTP_COMMON", "GTP_COMMON_MID_RIGHT", - "GTP_COMMON_MID_RIGHT", ]: continue @@ -41,7 +40,7 @@ def gen_sites(): if site_type != "GTPE2_COMMON": continue - return site_name, site_type + yield site_name, site_type def main(): @@ -55,66 +54,69 @@ module top( assign out = in; ''') - site_name, site_type = gen_sites() + params_list = list() - params = dict() - params['site'] = site_name + for site_name, site_type in gen_sites(): + params = dict() + params['site'] = site_name - verilog_attr = "" + verilog_attr = "" - verilog_attr = "#(" + verilog_attr = "#(" - fuz_dir = os.getenv("FUZDIR", None) - assert fuz_dir - with open(os.path.join(fuz_dir, "attrs.json"), "r") as attrs_file: - attrs = json.load(attrs_file) + fuz_dir = os.getenv("FUZDIR", None) + assert fuz_dir + with open(os.path.join(fuz_dir, "attrs.json"), "r") as attrs_file: + attrs = json.load(attrs_file) - in_use = bool(random.randint(0, 9)) - params["IN_USE"] = in_use + in_use = bool(random.randint(0, 9)) + params["IN_USE"] = in_use - if in_use: - for param, param_info in attrs.items(): - param_type = param_info["type"] - param_values = param_info["values"] - param_digits = param_info["digits"] + if in_use: + for param, param_info in attrs.items(): + param_type = param_info["type"] + param_values = param_info["values"] + param_digits = param_info["digits"] - if param_type == INT: - value = random.choice(param_values) - value_str = value - else: - assert param_type == BIN - value = random.randint(0, param_values[0]) - value_str = "{digits}'b{value:0{digits}b}".format( - value=value, digits=param_digits) + if param_type == INT: + value = random.choice(param_values) + value_str = value + else: + assert param_type == BIN + value = random.randint(0, param_values[0]) + value_str = "{digits}'b{value:0{digits}b}".format( + value=value, digits=param_digits) - params[param] = value + params[param] = value - verilog_attr += """ - .{}({}),""".format(param, value_str) + verilog_attr += """ + .{}({}),""".format(param, value_str) - for param in ["GTGREFCLK1", "GTGREFCLK0", "PLL0LOCKDETCLK", - "PLL1LOCKDETCLK", "DRPCLK"]: - is_inverted = random.randint(0, 1) + for param in ["GTGREFCLK1", "GTGREFCLK0", "PLL0LOCKDETCLK", + "PLL1LOCKDETCLK", "DRPCLK"]: + is_inverted = random.randint(0, 1) - params[param] = is_inverted + params[param] = is_inverted - verilog_attr += """ - .IS_{}_INVERTED({}),""".format(param, is_inverted) + verilog_attr += """ + .IS_{}_INVERTED({}),""".format(param, is_inverted) - verilog_attr = verilog_attr.rstrip(",") - verilog_attr += "\n)" + verilog_attr = verilog_attr.rstrip(",") + verilog_attr += "\n)" - print("(* KEEP, DONT_TOUCH *)") - print( - """GTPE2_COMMON {} gtp_common ( - .GTREFCLK0(1'b0), - .GTREFCLK1(1'b0) -);""".format(verilog_attr)) + print("(* KEEP, DONT_TOUCH, LOC=\"{}\" *)".format(site_name)) + print( + """GTPE2_COMMON {attrs} {site} ( + .GTREFCLK0(1'b0), + .GTREFCLK1(1'b0) + );""".format(attrs=verilog_attr, site=site_name)) + + params_list.append(params) print("endmodule") with open('params.json', 'w') as f: - json.dump(params, f, indent=2) + json.dump(params_list, f, indent=2) if __name__ == '__main__': From fb78c37356594a463d71e049a6ce8a1a04c08cf9 Mon Sep 17 00:00:00 2001 From: Alessandro Comodi Date: Mon, 18 Jan 2021 15:34:58 +0100 Subject: [PATCH 5/9] 063-gtp-common-conf: add to fuzzer Makefile Signed-off-by: Alessandro Comodi --- fuzzers/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/fuzzers/Makefile b/fuzzers/Makefile index 63c08d73..d33bc69f 100644 --- a/fuzzers/Makefile +++ b/fuzzers/Makefile @@ -158,6 +158,7 @@ $(eval $(call fuzzer,076-ps7,,all)) endif ifeq ($(XRAY_DATABASE),artix7) $(eval $(call fuzzer,061-pcie-conf,005-tilegrid,all)) +$(eval $(call fuzzer,063-gtp-common-conf,005-tilegrid,part)) endif endif endif From 47baef5aea80523e8c6011bf315a092682031bf3 Mon Sep 17 00:00:00 2001 From: Alessandro Comodi Date: Mon, 18 Jan 2021 15:35:32 +0100 Subject: [PATCH 6/9] mergedb: add gtp_common_mid Signed-off-by: Alessandro Comodi --- utils/mergedb.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/utils/mergedb.sh b/utils/mergedb.sh index 5ea2b5dc..92d32017 100755 --- a/utils/mergedb.sh +++ b/utils/mergedb.sh @@ -163,6 +163,12 @@ case "$1" in gtp_common) cp "$2" "$tmp1" ;; + gtp_common_mid_left) + sed < "$2" > "$tmp1" -e 's/^GTP_COMMON_MID_RIGHT\./GTP_COMMON_MID_LEFT./' ;; + + gtp_common_mid_right) + cp "$2" "$tmp1" ;; + mask_*) db=$XRAY_DATABASE_DIR/$XRAY_DATABASE/$1.db ismask=true From 5245999dc407aa19bd3618144b7d71bb4973f488 Mon Sep 17 00:00:00 2001 From: Alessandro Comodi Date: Mon, 18 Jan 2021 15:48:15 +0100 Subject: [PATCH 7/9] 063-gtp-common-conf: add license to pushdb.sh Signed-off-by: Alessandro Comodi --- fuzzers/063-gtp-common-conf/pushdb.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fuzzers/063-gtp-common-conf/pushdb.sh b/fuzzers/063-gtp-common-conf/pushdb.sh index b383f17f..99de30dd 100644 --- a/fuzzers/063-gtp-common-conf/pushdb.sh +++ b/fuzzers/063-gtp-common-conf/pushdb.sh @@ -1,4 +1,11 @@ #!/bin/bash +# Copyright (C) 2017-2020 The Project X-Ray Authors. +# +# Use of this source code is governed by a ISC-style +# license that can be found in the LICENSE file or at +# https://opensource.org/licenses/ISC +# +# SPDX-License-Identifier: ISC if ! test $(find . -name "segdata_gtp_common_mid_right.txt" | wc -c) -eq 0 then From 50553b0c17eac007f8bc8f45b92dd1a97387f1e7 Mon Sep 17 00:00:00 2001 From: Alessandro Comodi Date: Tue, 19 Jan 2021 11:31:21 +0100 Subject: [PATCH 8/9] 063-gtp-common-conf: fix Makefile to clean only current part Signed-off-by: Alessandro Comodi --- fuzzers/063-gtp-common-conf/Makefile | 27 +++++++++++++++------------ fuzzers/063-gtp-common-conf/pushdb.sh | 16 ++++++++-------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/fuzzers/063-gtp-common-conf/Makefile b/fuzzers/063-gtp-common-conf/Makefile index 386d2b3f..4e939577 100644 --- a/fuzzers/063-gtp-common-conf/Makefile +++ b/fuzzers/063-gtp-common-conf/Makefile @@ -10,16 +10,19 @@ SHELL = bash N ?= 20 -SPECIMENS := $(addprefix build/specimen_,$(shell seq -f '%03.0f' $(N))) +BUILD_DIR = build_${XRAY_PART} + +SPECIMENS := $(addprefix ${BUILD_DIR}/specimen_,$(shell seq -f '%03.0f' $(N))) SPECIMENS_OK := $(addsuffix /OK,$(SPECIMENS)) FUZDIR ?= ${PWD} + all: database # generate.sh / top_generate.sh call make, hence the command must # have a + before it. $(SPECIMENS_OK): $(SPECIMENS_DEPS) - mkdir -p build + mkdir -p ${BUILD_DIR} bash ${XRAY_DIR}/utils/top_generate.sh $(subst /OK,,$@) run: @@ -29,22 +32,22 @@ run: touch run.${XRAY_PART}.ok clean: - rm -rf build run.ok + rm -rf ${BUILD_DIR} run.${XRAY_PART}.ok .PHONY: all run clean -database: build/segbits_gtp_common.db +database: ${BUILD_DIR}/segbits_gtp_common.db -build/segbits_gtp_common.rdb: $(SPECIMENS_OK) - ${XRAY_SEGMATCH} -o build/segbits_gtp_common.rdb $$(find $(SPECIMENS) -name "segdata_gtp_common*") +${BUILD_DIR}/segbits_gtp_common.rdb: $(SPECIMENS_OK) + ${XRAY_SEGMATCH} -o ${BUILD_DIR}/segbits_gtp_common.rdb $$(find $(SPECIMENS) -name "segdata_gtp_common*") -build/segbits_gtp_common.db: build/segbits_gtp_common.rdb - ${XRAY_DBFIXUP} --db-root build --zero-db bits.dbf \ - --seg-fn-in build/segbits_gtp_common.rdb \ - --seg-fn-out build/segbits_gtp_common.db - ${XRAY_MASKMERGE} build/mask_gtp_common.db $$(find $(SPECIMENS) -name "segdata_gtp_common*") +${BUILD_DIR}/segbits_gtp_common.db: ${BUILD_DIR}/segbits_gtp_common.rdb + ${XRAY_DBFIXUP} --db-root ${BUILD_DIR} --zero-db bits.dbf \ + --seg-fn-in ${BUILD_DIR}/segbits_gtp_common.rdb \ + --seg-fn-out ${BUILD_DIR}/segbits_gtp_common.db + ${XRAY_MASKMERGE} ${BUILD_DIR}/mask_gtp_common.db $$(find $(SPECIMENS) -name "segdata_gtp_common*") pushdb: - source pushdb.sh + BUILD_DIR=$(BUILD_DIR) source pushdb.sh .PHONY: database pushdb diff --git a/fuzzers/063-gtp-common-conf/pushdb.sh b/fuzzers/063-gtp-common-conf/pushdb.sh index 99de30dd..b9c8d743 100644 --- a/fuzzers/063-gtp-common-conf/pushdb.sh +++ b/fuzzers/063-gtp-common-conf/pushdb.sh @@ -7,16 +7,16 @@ # # SPDX-License-Identifier: ISC -if ! test $(find . -name "segdata_gtp_common_mid_right.txt" | wc -c) -eq 0 +if ! test $(find ${BUILD_DIR} -name "segdata_gtp_common_mid_right.txt" | wc -c) -eq 0 then - ${XRAY_MERGEDB} gtp_common_mid_right build/segbits_gtp_common.db - ${XRAY_MERGEDB} mask_gtp_common_mid_right build/mask_gtp_common.db - ${XRAY_MERGEDB} gtp_common_mid_left build/segbits_gtp_common.db - ${XRAY_MERGEDB} mask_gtp_common_mid_left build/mask_gtp_common.db + ${XRAY_MERGEDB} gtp_common_mid_right ${BUILD_DIR}/segbits_gtp_common.db + ${XRAY_MERGEDB} mask_gtp_common_mid_right ${BUILD_DIR}/mask_gtp_common.db + ${XRAY_MERGEDB} gtp_common_mid_left ${BUILD_DIR}/segbits_gtp_common.db + ${XRAY_MERGEDB} mask_gtp_common_mid_left ${BUILD_DIR}/mask_gtp_common.db fi -if ! test $(find . -name "segdata_gtp_common.txt" | wc -c) -eq 0 +if ! test $(find ${BUILD_DIR} -name "segdata_gtp_common.txt" | wc -c) -eq 0 then - ${XRAY_MERGEDB} gtp_common build/segbits_gtp_common.db - ${XRAY_MERGEDB} mask_gtp_common build/mask_gtp_common.db + ${XRAY_MERGEDB} gtp_common ${BUILD_DIR}/segbits_gtp_common.db + ${XRAY_MERGEDB} mask_gtp_common ${BUILD_DIR}/mask_gtp_common.db fi From f8ae373dd51c720dd6c3855e1ddf78f60ad0dff2 Mon Sep 17 00:00:00 2001 From: Alessandro Comodi Date: Tue, 19 Jan 2021 17:13:37 +0100 Subject: [PATCH 9/9] 063-gtp-common-conf: add IBUFDS_GTE2 primitive as well This commit also solves an issue in the bitfilter function. Given that the GTP_COMMON and GTP_COMMON_MID_[LEFT|RIGHT] have the same bits, but in different frames, we need to add all of the possible frames to the bitfilter callback. This causes issues in determining the IN_USE feature, therefore, there must be two different bitfilter callbacks, one for GTP_COMMON, and one for GTP_COMMON_MID_[LEFT|RIGHT] Signed-off-by: Alessandro Comodi --- fuzzers/063-gtp-common-conf/generate.py | 52 ++++++++++++++++++-- fuzzers/063-gtp-common-conf/generate.tcl | 1 + fuzzers/063-gtp-common-conf/top.py | 60 ++++++++++++++++++++++-- prjxray/segmaker.py | 1 + 4 files changed, 106 insertions(+), 8 deletions(-) diff --git a/fuzzers/063-gtp-common-conf/generate.py b/fuzzers/063-gtp-common-conf/generate.py index 14ed3c88..5964ef96 100644 --- a/fuzzers/063-gtp-common-conf/generate.py +++ b/fuzzers/063-gtp-common-conf/generate.py @@ -19,9 +19,17 @@ INT = "INT" BIN = "BIN" -def bitfilter(frame, bit): +def bitfilter_gtp_common_mid(frame, bit): # Filter out interconnect bits. - if frame not in [28, 29, 0, 1]: + if frame not in [0, 1]: + return False + + return True + + +def bitfilter_gtp_common(frame, bit): + # Filter out interconnect bits. + if frame not in [28, 29]: return False return True @@ -37,10 +45,16 @@ def main(): print("Loading tags") with open("params.json") as f: - params_list = json.load(f) + params_dict = json.load(f) + tile_type = params_dict["tile_type"] + params_list = params_dict["params"] for params in params_list: site = params["site"] + + if "GTPE2_COMMON" not in site: + continue + in_use = params["IN_USE"] segmk.add_site_tag(site, "IN_USE", in_use) @@ -83,6 +97,38 @@ def main(): else: segmk.add_site_tag(site, "INV_" + param, params[param]) + for params in params_list: + site = params["site"] + + if "IBUFDS_GTE2" not in site: + continue + + in_use = params["IN_USE"] + segmk.add_site_tag(site, "IN_USE", in_use) + + if in_use: + tile = params["tile"] + + for param in ["CLKRCV_TRST", "CLKCM_CFG"]: + value = params[param] + segmk.add_site_tag(site, param, "TRUE" in value) + + bitstr = [ + int(x) for x in "{value:0{digits}b}".format( + value=params["CLKSWING_CFG"], digits=2)[::-1] + ] + + for i in range(2): + segmk.add_tile_tag( + tile, "IBUFDS_GTE2.%s[%u]" % (param, i), bitstr[i]) + + if tile_type == "GTP_COMMON": + bitfilter = bitfilter_gtp_common + elif tile_type == "GTP_COMMON_MID_RIGHT": + bitfilter = bitfilter_gtp_common_mid + else: + assert False, tile_type + segmk.compile(bitfilter=bitfilter) segmk.write() diff --git a/fuzzers/063-gtp-common-conf/generate.tcl b/fuzzers/063-gtp-common-conf/generate.tcl index ab44e0cb..0a95cab7 100644 --- a/fuzzers/063-gtp-common-conf/generate.tcl +++ b/fuzzers/063-gtp-common-conf/generate.tcl @@ -17,6 +17,7 @@ proc run {} { set_property IS_ENABLED 0 [get_drc_checks {NSTD-1}] set_property IS_ENABLED 0 [get_drc_checks {UCIO-1}] set_property IS_ENABLED 0 [get_drc_checks {REQP-48}] + set_property IS_ENABLED 0 [get_drc_checks {REQP-1619}] place_design route_design diff --git a/fuzzers/063-gtp-common-conf/top.py b/fuzzers/063-gtp-common-conf/top.py index abd9b318..e32bb45e 100644 --- a/fuzzers/063-gtp-common-conf/top.py +++ b/fuzzers/063-gtp-common-conf/top.py @@ -23,7 +23,7 @@ INT = "INT" BIN = "BIN" -def gen_sites(): +def gen_sites(site): db = Database(util.get_db_root(), util.get_part()) grid = db.grid() for tile_name in sorted(grid.tiles()): @@ -35,12 +35,14 @@ def gen_sites(): "GTP_COMMON_MID_RIGHT", ]: continue + else: + tile_type = gridinfo.tile_type for site_name, site_type in gridinfo.sites.items(): - if site_type != "GTPE2_COMMON": + if site_type != site: continue - yield site_name, site_type + yield tile_name, tile_type, site_name, site_type def main(): @@ -54,9 +56,17 @@ module top( assign out = in; ''') + params_dict = {"tile_type": None} params_list = list() - for site_name, site_type in gen_sites(): + for tile_name, tile_type, site_name, site_type in gen_sites( + "GTPE2_COMMON"): + + if params_dict["tile_type"]: + assert tile_type == params_dict["tile_type"] + else: + params_dict["tile_type"] = tile_type + params = dict() params['site'] = site_name @@ -113,10 +123,50 @@ assign out = in; params_list.append(params) + clkswing_cfg_tiles = dict() + for tile_name, _, site_name, site_type in gen_sites("IBUFDS_GTE2"): + # Both the IBUFDS_GTE2 in the same tile need to have + # the same CLKSWING_CFG parameter + if tile_name not in clkswing_cfg_tiles: + clkswing_cfg = random.randint(0, 3) + clkswing_cfg_tiles[tile_name] = clkswing_cfg + else: + clkswing_cfg = clkswing_cfg_tiles[tile_name] + + in_use = bool(random.randint(0, 9)) + params = { + "site": + site_name, + "tile": + tile_name, + "IN_USE": + in_use, + "CLKRCV_TRST": + verilog.quote("TRUE" if random.randint(0, 1) else "FALSE"), + "CLKCM_CFG": + verilog.quote("TRUE" if random.randint(0, 1) else "FALSE"), + "CLKSWING_CFG": + clkswing_cfg, + } + + if in_use: + print("(* KEEP, DONT_TOUCH, LOC=\"{}\" *)".format(site_name)) + print( + """ +IBUFDS_GTE2 #( + .CLKRCV_TRST({CLKRCV_TRST}), + .CLKCM_CFG({CLKCM_CFG}), + .CLKSWING_CFG({CLKSWING_CFG}) +) {site} ( + );""".format(**params)) + + params_list.append(params) + print("endmodule") + params_dict["params"] = params_list with open('params.json', 'w') as f: - json.dump(params_list, f, indent=2) + json.dump(params_dict, f, indent=2) if __name__ == '__main__': diff --git a/prjxray/segmaker.py b/prjxray/segmaker.py index 239a2cdc..19fc844e 100644 --- a/prjxray/segmaker.py +++ b/prjxray/segmaker.py @@ -331,6 +331,7 @@ class Segmaker: 'IDELAY': name_y0y1, 'ILOGIC': name_y0y1, 'OLOGIC': name_y0y1, + 'IBUFDS': name_y0y1, }.get(site_prefix, name_default)() self.verbose and print( 'site %s w/ %s prefix => tag %s' %