| 1 |
# nextpnr -- Next Generation Place and Route |
| 2 |
# |
| 3 |
# Copyright (C) 2024 The Project Beyond Authors. |
| 4 |
# |
| 5 |
# Permission to use, copy, modify, and/or distribute this software for any |
| 6 |
# purpose with or without fee is hereby granted, provided that the above |
| 7 |
# copyright notice and this permission notice appear in all copies. |
| 8 |
# |
| 9 |
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 10 |
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 11 |
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 12 |
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 13 |
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 14 |
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 15 |
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 16 |
# |
| 17 |
|
| 18 |
import json |
| 19 |
from os import path |
| 20 |
import sys |
| 21 |
import argparse |
| 22 |
import gzip |
| 23 |
|
| 24 |
# Configuration flags |
| 25 |
USE_LUT_PERMUTATION = True |
| 26 |
|
| 27 |
sys.path.append(path.join(path.dirname(__file__), "../../..")) |
| 28 |
from himbaechel_dbgen.chip import * |
| 29 |
|
| 30 |
@dataclass |
| 31 |
class TileExtraData(BBAStruct): |
| 32 |
name: IdString |
| 33 |
lobe: int = 0 |
| 34 |
tile_type: int = 0 |
| 35 |
|
| 36 |
def serialise_lists(self, context: str, bba: BBAWriter): |
| 37 |
pass |
| 38 |
def serialise(self, context: str, bba: BBAWriter): |
| 39 |
bba.u32(self.name.index) |
| 40 |
bba.u8(self.lobe) |
| 41 |
bba.u8(self.tile_type) |
| 42 |
bba.u16(0) # dummy |
| 43 |
|
| 44 |
@dataclass |
| 45 |
class PipExtraData(BBAStruct): |
| 46 |
name: IdString = field(default_factory=IdString) |
| 47 |
data_type: int = 0 |
| 48 |
input: int = 0 |
| 49 |
output: int = 0 |
| 50 |
|
| 51 |
def serialise_lists(self, context: str, bba: BBAWriter): |
| 52 |
pass |
| 53 |
def serialise(self, context: str, bba: BBAWriter): |
| 54 |
bba.u32(self.name.index) |
| 55 |
bba.u16(self.data_type) |
| 56 |
bba.u8(self.input) |
| 57 |
bba.u8(self.output) |
| 58 |
|
| 59 |
@dataclass |
| 60 |
class BelExtraData(BBAStruct): |
| 61 |
flags: int = 0 |
| 62 |
|
| 63 |
def serialise_lists(self, context: str, bba: BBAWriter): |
| 64 |
pass |
| 65 |
def serialise(self, context: str, bba: BBAWriter): |
| 66 |
bba.u32(self.flags) |
| 67 |
|
| 68 |
PLL_Z = 0 |
| 69 |
WFG_C_Z = 1 |
| 70 |
WFG_R_Z = 11 |
| 71 |
|
| 72 |
IOM_Z = 136 |
| 73 |
|
| 74 |
RAM_Z = 0 |
| 75 |
DSP1_Z = 1 |
| 76 |
DSP2_Z = 2 |
| 77 |
|
| 78 |
SOCIF_Z = 0 |
| 79 |
SERVICE_Z = 1 |
| 80 |
|
| 81 |
LUT_Z = 0 |
| 82 |
CY_Z = 32 |
| 83 |
XLUT_Z = CY_Z + 4 |
| 84 |
RF_Z = XLUT_Z + 8 |
| 85 |
XRF_Z = RF_Z + 2 |
| 86 |
FIFO_Z = XRF_Z + 1 |
| 87 |
XFIFO_Z = FIFO_Z + 2 |
| 88 |
CDC_Z = XFIFO_Z + 1 |
| 89 |
XCDC_Z = CDC_Z + 2 |
| 90 |
|
| 91 |
PIP_EXTRA_CROSSBAR = 1 |
| 92 |
PIP_EXTRA_MUX = 2 |
| 93 |
PIP_EXTRA_BYPASS = 3 |
| 94 |
PIP_EXTRA_LUT_PERMUTATION = 4 |
| 95 |
PIP_EXTRA_INTERCONNECT = 5 |
| 96 |
PIP_EXTRA_VIRTUAL = 6 |
| 97 |
|
| 98 |
BEL_EXTRA_FE_CSC = 1 |
| 99 |
BEL_EXTRA_FE_SCC = 2 |
| 100 |
|
| 101 |
TILE_EXTRA_FABRIC = 0 |
| 102 |
TILE_EXTRA_TUBE = 1 |
| 103 |
TILE_EXTRA_SOC = 2 |
| 104 |
TILE_EXTRA_RING = 3 |
| 105 |
TILE_EXTRA_FENCE = 4 |
| 106 |
|
| 107 |
def bel_z(tile_type, bel_name, bel_type): |
| 108 |
if tile_type.startswith("CKG"): |
| 109 |
if (bel_type=="PLL"): |
| 110 |
return PLL_Z |
| 111 |
else: |
| 112 |
if bel_name.startswith("WFG.WFG_C"): |
| 113 |
return int(bel_name.replace("WFG.WFG_C","")) + WFG_C_Z -1 |
| 114 |
else: |
| 115 |
return int(bel_name.replace("WFG.WFG_R","")) + WFG_R_Z -1 |
| 116 |
elif tile_type.startswith("HSSL"): |
| 117 |
if bel_type=="PMA": |
| 118 |
return 0 |
| 119 |
elif bel_type=="CRX": |
| 120 |
return int(bel_name.split(".")[0][7:]) * 2 - 1 |
| 121 |
else: |
| 122 |
return int(bel_name.split(".")[0][7:]) * 2 |
| 123 |
elif tile_type.startswith("IOB") and tile_type in ["IOB0","IOB1","IOB6","IOB7"]: #direct |
| 124 |
sp = bel_name.split(".") |
| 125 |
if bel_type=="IOP": |
| 126 |
return int(sp[0][1:]) * 4 |
| 127 |
else: |
| 128 |
return (int(sp[0][3:])-1) * 4 + (1 if sp[1][0]=='I' else 2 if sp[1][0]=='O' else 3) |
| 129 |
elif tile_type.startswith("IOB"): # complex |
| 130 |
sp = bel_name.split(".") |
| 131 |
if bel_type=="IOTP": |
| 132 |
return (int(sp[0][1:3]) *2 + (1 if sp[0][3]=='N' else 0)) * 4 |
| 133 |
elif bel_type=="IOM": |
| 134 |
return IOM_Z |
| 135 |
else: |
| 136 |
return (int(sp[0][3:])-1) * 4 + (1 if sp[1][0]=='I' else 2 if sp[1][0]=='O' else 3) |
| 137 |
elif tile_type == "CGB": |
| 138 |
if bel_type=="RAM": |
| 139 |
return RAM_Z |
| 140 |
elif bel_name=="S2.DSP1": |
| 141 |
return DSP1_Z |
| 142 |
else: |
| 143 |
return DSP2_Z |
| 144 |
elif tile_type == "SOCBank": |
| 145 |
if bel_type=="SOCIF": |
| 146 |
return SOCIF_Z |
| 147 |
else: |
| 148 |
return SERVICE_Z |
| 149 |
elif tile_type == "TILE": |
| 150 |
sp = bel_name.split(".") |
| 151 |
if bel_type=="BEYOND_FE": |
| 152 |
return (int(sp[1][2:])-1) % 32 |
| 153 |
elif bel_type=="CY": |
| 154 |
pos = int(sp[1][2:])-1 |
| 155 |
# in S1, S5 and S9 they are ordered other way arround |
| 156 |
return ((pos % 4) if pos < 12 else 3 - (pos % 4)) + CY_Z |
| 157 |
elif bel_type=="XLUT": |
| 158 |
return (int(sp[1][4:])-1) % 8 + XLUT_Z |
| 159 |
elif bel_type=="RF": |
| 160 |
return (int(sp[1][2:])-1) + RF_Z |
| 161 |
elif bel_type=="XRF": |
| 162 |
return (int(sp[1][3:])-1) + XRF_Z |
| 163 |
elif bel_type=="FIFO": |
| 164 |
return (int(sp[1][4:])-1) + FIFO_Z |
| 165 |
elif bel_type=="XFIFO": |
| 166 |
return (int(sp[1][5:])-1) + XFIFO_Z |
| 167 |
elif bel_type=="CDC": |
| 168 |
return (int(sp[1][3:])-1) + CDC_Z |
| 169 |
elif bel_type=="XCDC": |
| 170 |
return (int(sp[1][4:])-1) + XCDC_Z |
| 171 |
else: |
| 172 |
raise Exception(f"Unknown bel type {bel_type}") |
| 173 |
elif tile_type == "TUBE": |
| 174 |
sp = bel_name.split(".") |
| 175 |
return (int(sp[0][1:])-1)*20 + (int(sp[1][1:])-1) |
| 176 |
else: |
| 177 |
raise Exception(f"Unknown type {tile_type}") |
| 178 |
|
| 179 |
if USE_LUT_PERMUTATION: |
| 180 |
# Note PI1-PI4 are not real inputs but will appear |
| 181 |
# before actual BEL input to enable LUT permutation |
| 182 |
lut_to_beyond_fe = { |
| 183 |
"I1" : "PI1", |
| 184 |
"I2" : "PI2", |
| 185 |
"I3" : "PI3", |
| 186 |
"I4" : "PI4", |
| 187 |
"O" : "LO", |
| 188 |
"J" : "LJ", |
| 189 |
"K" : "LK", |
| 190 |
"D" : "LD", |
| 191 |
"X" : "LX", |
| 192 |
} |
| 193 |
else: |
| 194 |
lut_to_beyond_fe = { |
| 195 |
"I1" : "I1", |
| 196 |
"I2" : "I2", |
| 197 |
"I3" : "I3", |
| 198 |
"I4" : "I4", |
| 199 |
"O" : "LO", |
| 200 |
"J" : "LJ", |
| 201 |
"K" : "LK", |
| 202 |
"D" : "LD", |
| 203 |
"X" : "LX", |
| 204 |
} |
| 205 |
|
| 206 |
dff_to_beyond_fe = { |
| 207 |
"I" : "DI", |
| 208 |
"O" : "DO", |
| 209 |
"L" : "L", |
| 210 |
"CK" : "CK", |
| 211 |
"R" : "R", |
| 212 |
"J" : "DJ", |
| 213 |
"P" : "DP", |
| 214 |
"C" : "DC", |
| 215 |
"S" : "DS", |
| 216 |
"K" : "DK", |
| 217 |
} |
| 218 |
|
| 219 |
def is_complex(tile_type): |
| 220 |
return tile_type not in ["IOB0","IOB1","IOB6","IOB7"] |
| 221 |
|
| 222 |
def map_to_beyond(tile_type,bel_name,bel_type=None): |
| 223 |
if not tile_type in ["TILE"]: |
| 224 |
return (bel_name,bel_type) |
| 225 |
s = bel_name.split(".") |
| 226 |
if tile_type in ["TILE"]: |
| 227 |
# BEYOND_FE |
| 228 |
if not (s[1].startswith("LUT") or s[1].startswith("DFF")): |
| 229 |
return (bel_name,bel_type) |
| 230 |
if len(s)==3: |
| 231 |
# BEL and PORT |
| 232 |
if s[1].startswith("LUT"): |
| 233 |
pin = lut_to_beyond_fe[s[2]] |
| 234 |
else: |
| 235 |
pin = dff_to_beyond_fe[s[2]] |
| 236 |
if pin is None: |
| 237 |
return (None,bel_type) |
| 238 |
return (s[0]+".FE"+s[1][3:]+"."+pin, bel_type if type(bel_type) is int else "BEYOND_FE") |
| 239 |
else: |
| 240 |
# just BEL |
| 241 |
return (s[0]+".FE"+s[1][3:], "BEYOND_FE") |
| 242 |
|
| 243 |
split_map = ["TILE", "CGB"] |
| 244 |
|
| 245 |
def split_tilegrid(tilegrid): |
| 246 |
new_tilegrid = dict() |
| 247 |
for k,v in tilegrid.items(): |
| 248 |
if v["type"] not in split_map: |
| 249 |
new_tilegrid[k] = dict() |
| 250 |
data = dict(v) |
| 251 |
data["orig"] = data["type"] |
| 252 |
data["x"]=data["x"]*4 |
| 253 |
data["y"]=data["y"]*4 |
| 254 |
new_tilegrid[k][0] = data |
| 255 |
else: |
| 256 |
new_tilegrid[k] = dict() |
| 257 |
for i in range(4*4): |
| 258 |
data = dict(v) |
| 259 |
data["orig"] = data["type"] |
| 260 |
data["type"] = data["type"]+"_"+str(i) |
| 261 |
data["x"]=data["x"]*4 + i // 4 |
| 262 |
data["y"]=data["y"]*4 + i % 4 |
| 263 |
new_tilegrid[k][i] = data |
| 264 |
return new_tilegrid |
| 265 |
|
| 266 |
def determine_subtile(tile,bel): |
| 267 |
if tile=="TILE": |
| 268 |
if bel.startswith("SYSTEM"): |
| 269 |
s = 3 |
| 270 |
elif bel.startswith("RE") or bel.startswith("RS") or bel.startswith("RI"): |
| 271 |
s = int(bel.split(".")[0][2:])-1 |
| 272 |
elif bel.startswith("S"): |
| 273 |
s = int(bel.split(".")[0][1:])+3 |
| 274 |
else: |
| 275 |
return 0 |
| 276 |
return s |
| 277 |
elif tile=="CGB": |
| 278 |
if bel.startswith("SYSTEM"): |
| 279 |
s = 6 |
| 280 |
elif bel.startswith("RE"): |
| 281 |
s = 8 |
| 282 |
elif bel.startswith("RS"): |
| 283 |
s = int(bel.split(".")[0][2:]) |
| 284 |
elif bel.startswith("RI"): |
| 285 |
s = 5 |
| 286 |
elif bel.startswith("S1"): |
| 287 |
s = 0 |
| 288 |
elif bel.startswith("S2.DSP1"): |
| 289 |
s = 7 |
| 290 |
else: |
| 291 |
return 15 |
| 292 |
return s |
| 293 |
else: |
| 294 |
return 0 |
| 295 |
|
| 296 |
def split_per_bels(bels): |
| 297 |
new_bels = dict() |
| 298 |
for k,v in bels.items(): |
| 299 |
if k not in split_map: |
| 300 |
new_bels[k] = dict() |
| 301 |
data = dict(v) |
| 302 |
new_bels[k][0] = data |
| 303 |
else: |
| 304 |
new_bels[k] = dict() |
| 305 |
for i in range(4*4): |
| 306 |
new_bels[k][i] = dict() |
| 307 |
for item,bel in v.items(): |
| 308 |
(item, bel) = map_to_beyond(k,item,bel) |
| 309 |
if item is not None: |
| 310 |
num = determine_subtile(k,item) |
| 311 |
new_bels[k][num][item] = bel |
| 312 |
return new_bels |
| 313 |
|
| 314 |
def lookup_port_type(t): |
| 315 |
if t == "Input": return PinType.INPUT |
| 316 |
elif t == "Output": return PinType.OUTPUT |
| 317 |
elif t == "Bidir": return PinType.INOUT |
| 318 |
else: assert False |
| 319 |
|
| 320 |
def create_pips(tt, tile_type, muxes, num, args): |
| 321 |
file_path = path.join(args.db, args.device, tile_type + ".txt") |
| 322 |
if not path.isfile(file_path): |
| 323 |
return |
| 324 |
with open(file_path) as f: |
| 325 |
for item in f: |
| 326 |
line = item.strip().split(" ") |
| 327 |
name1,_ = map_to_beyond(tile_type,line[0]) |
| 328 |
name2,_ = map_to_beyond(tile_type,line[1]) |
| 329 |
if name1 is None or name2 is None: |
| 330 |
continue |
| 331 |
num1 = determine_subtile(tile_type,name1) |
| 332 |
num2 = determine_subtile(tile_type,name2) |
| 333 |
|
| 334 |
if name2 in muxes: |
| 335 |
name2 = name2 + "." + line[2] |
| 336 |
if num1==num and not tt.has_wire(name1): |
| 337 |
tt.create_wire(name=name1, type=tile_type + "_WIRE") |
| 338 |
if num2==num and not tt.has_wire(name2): |
| 339 |
tt.create_wire(name=name2, type=tile_type + "_WIRE") |
| 340 |
timing_class = line[3] |
| 341 |
# Only create PIP if both ends are in same subtile |
| 342 |
if num1==num and num2==num: |
| 343 |
tt.create_pip(name1,name2,timing_class) |
| 344 |
|
| 345 |
def create_tile_types(ch: Chip, bels, bel_pins, crossbars, interconnects, muxes, args): |
| 346 |
for tile_type,items in bels.items(): |
| 347 |
for num in items.keys(): |
| 348 |
if len(items)==1: |
| 349 |
sub_type = tile_type |
| 350 |
else: |
| 351 |
sub_type = f"{tile_type}_{num}" |
| 352 |
tt = ch.create_tile_type(sub_type) |
| 353 |
|
| 354 |
def lookup_site_wire(canon_name): |
| 355 |
if not tt.has_wire(canon_name): |
| 356 |
tt.create_wire(name=canon_name, type="BEL_PIN_WIRE") |
| 357 |
return canon_name |
| 358 |
|
| 359 |
# Create BELs inside tile |
| 360 |
for name,bel in bels[tile_type][num].items(): |
| 361 |
nb = tt.create_bel(name, bel, z=bel_z(tile_type,name,bel)) |
| 362 |
# Create wires for each BEL port |
| 363 |
for index in bel_pins[bel].keys(): |
| 364 |
pin = bel_pins[bel][index] |
| 365 |
tt.add_bel_pin(nb, pin["name"], lookup_site_wire(f"{name}."+pin["name"]), lookup_port_type(pin["direction"])) |
| 366 |
if (tile_type.startswith("TILE") and bel=="BEYOND_FE"): |
| 367 |
flag = 0 |
| 368 |
fe_nxd = int(name[name.index(".")+3:]) |
| 369 |
if (((fe_nxd-1) & 127) < 64): |
| 370 |
if ((fe_nxd-1)&31) < 16: |
| 371 |
if (fe_nxd & 1)==1: |
| 372 |
flag |= BEL_EXTRA_FE_SCC |
| 373 |
else: |
| 374 |
if (fe_nxd & 1)==0: |
| 375 |
flag |= BEL_EXTRA_FE_SCC |
| 376 |
|
| 377 |
if fe_nxd in (65, 80, 81, 96, 225,240,241,256, 321,336,337,352): |
| 378 |
flag |= BEL_EXTRA_FE_CSC |
| 379 |
nb.extra_data = BelExtraData(flag) |
| 380 |
|
| 381 |
# LUT drawers, LO already connected to LJ |
| 382 |
vi = tt.create_pip(f"{name}.LJ",f"{name}.LK","Virtual") |
| 383 |
vi.extra_data = PipExtraData(ch.strs.id(name),PIP_EXTRA_VIRTUAL,0,0) |
| 384 |
vi = tt.create_pip(f"{name}.LJ",f"{name}.LD","Virtual") |
| 385 |
vi.extra_data = PipExtraData(ch.strs.id(name),PIP_EXTRA_VIRTUAL,0,0) |
| 386 |
vi = tt.create_pip(f"{name}.LJ",f"{name}.LX","Virtual") |
| 387 |
vi.extra_data = PipExtraData(ch.strs.id(name),PIP_EXTRA_VIRTUAL,0,0) |
| 388 |
# DFF drawers, DO already connected to DJ |
| 389 |
vi = tt.create_pip(f"{name}.DJ",f"{name}.DP","Virtual") |
| 390 |
vi.extra_data = PipExtraData(ch.strs.id(name),PIP_EXTRA_VIRTUAL,0,0) |
| 391 |
vi = tt.create_pip(f"{name}.DJ",f"{name}.DC","Virtual") |
| 392 |
vi.extra_data = PipExtraData(ch.strs.id(name),PIP_EXTRA_VIRTUAL,0,0) |
| 393 |
vi = tt.create_pip(f"{name}.DJ",f"{name}.DS","Virtual") |
| 394 |
vi.extra_data = PipExtraData(ch.strs.id(name),PIP_EXTRA_VIRTUAL,0,0) |
| 395 |
vi = tt.create_pip(f"{name}.DJ",f"{name}.DK","Virtual") |
| 396 |
vi.extra_data = PipExtraData(ch.strs.id(name),PIP_EXTRA_VIRTUAL,0,0) |
| 397 |
# DFF bypass |
| 398 |
by = tt.create_pip(f"{name}.DI",f"{name}.DO","BYPASS") |
| 399 |
by.extra_data = PipExtraData(ch.strs.id(name),PIP_EXTRA_BYPASS,0,0) |
| 400 |
# LUT bypass |
| 401 |
by = tt.create_pip(f"{name}.I1",f"{name}.LO","BYPASS") |
| 402 |
by.extra_data = PipExtraData(ch.strs.id(name),PIP_EXTRA_BYPASS,1,0) |
| 403 |
elif (tile_type.startswith("TILE") and bel=="XLUT"): |
| 404 |
for out in ["G1","G2","G3","G4"]: |
| 405 |
vi = tt.create_pip(f"{name}.J",f"{name}.{out}","Virtual") |
| 406 |
vi.extra_data = PipExtraData(ch.strs.id(name),PIP_EXTRA_VIRTUAL,0,0) |
| 407 |
elif (tile_type.startswith("TILE") and bel=="CY"): |
| 408 |
# matrix of each input to each output combination |
| 409 |
# crossbar but use mux placeholder for convenience |
| 410 |
for inp in ["I1","I2","I3","I4"]: |
| 411 |
for out in ["O1","O2","O3","O4"]: |
| 412 |
pd = tt.create_pip(f"{name}."+inp,f"{name}."+out,"MATRIX_PIP") |
| 413 |
pd.extra_data = PipExtraData(ch.strs.id(f"{name}."+inp),PIP_EXTRA_MUX,int(inp[1:])-1,int(out[1:])-1) |
| 414 |
|
| 415 |
elif (tile_type.startswith("CKG") and bel=="WFG"): |
| 416 |
by = tt.create_pip(f"{name}.ZI",f"{name}.ZO","BYPASS") |
| 417 |
by.extra_data = PipExtraData(ch.strs.id(name),PIP_EXTRA_BYPASS,0,0) |
| 418 |
elif (tile_type.startswith("TUBE") and bel=="GCK"): |
| 419 |
# 20 clock signals comming to 20 GCK, SI1 is bypass |
| 420 |
by = tt.create_pip(f"{name}.SI1",f"{name}.SO","BYPASS") |
| 421 |
by.extra_data = PipExtraData(ch.strs.id(name),PIP_EXTRA_BYPASS,0,0) |
| 422 |
# there are CMD signals that can be bypassed as well |
| 423 |
by = tt.create_pip(f"{name}.CMD",f"{name}.SO","BYPASS") |
| 424 |
by.extra_data = PipExtraData(ch.strs.id(name),PIP_EXTRA_BYPASS,1,0) |
| 425 |
|
| 426 |
|
| 427 |
# Add LUT permutation |
| 428 |
if USE_LUT_PERMUTATION and tile_type=="TILE": |
| 429 |
for name,bel in bels[tile_type][num].items(): |
| 430 |
if bel=="BEYOND_FE": |
| 431 |
for inp in ["PI1","PI2","PI3","PI4"]: |
| 432 |
tt.create_wire(name=f"{name}."+inp, type="LUT_PERMUTATION_WIRE") |
| 433 |
for out in ["I1","I2","I3","I4"]: |
| 434 |
pd = tt.create_pip(f"{name}."+inp,f"{name}."+out,"LUT_PERMUTATION") |
| 435 |
pd.extra_data = PipExtraData(ch.strs.id(name),PIP_EXTRA_LUT_PERMUTATION,int(inp[2:])-1,int(out[1:])-1) |
| 436 |
|
| 437 |
# Create crossbars as multiple PIPs |
| 438 |
for name,xb in crossbars[tile_type][num].items(): |
| 439 |
inputs = list() |
| 440 |
outputs = list() |
| 441 |
for index in bel_pins[xb].keys(): |
| 442 |
pin = bel_pins[xb][index] |
| 443 |
tt.create_wire(name=f"{name}."+pin["name"], type="CROSSBAR_"+xb+"_INPUT_WIRE" if pin["direction"] == "Input" else "CROSSBAR_"+xb+"_OUTPUT_WIRE") |
| 444 |
for index in bel_pins[xb].keys(): |
| 445 |
pin = bel_pins[xb][index] |
| 446 |
if pin["direction"] == "Input": |
| 447 |
inputs.append(pin["name"]) |
| 448 |
else: |
| 449 |
outputs.append(pin["name"]) |
| 450 |
for inp in inputs: |
| 451 |
for out in outputs: |
| 452 |
pd = tt.create_pip(f"{name}."+inp,f"{name}."+out,"CROSSBAR_"+xb) |
| 453 |
pd.extra_data = PipExtraData(ch.strs.id(name),PIP_EXTRA_CROSSBAR,int(inp[1:])-1,int(out[1:])-1) |
| 454 |
|
| 455 |
# Interconnects are just PIPs with one I and one O |
| 456 |
for name,xb in interconnects[tile_type][num].items(): |
| 457 |
for index in bel_pins[xb].keys(): |
| 458 |
pin = bel_pins[xb][index] |
| 459 |
tt.create_wire(name=f"{name}."+pin["name"], type="INTERCONNECT_INPUT" if pin["direction"] == "Input" else "INTERCONNECT_OUTPUT") |
| 460 |
inp = f"{name}."+bel_pins[xb]["I"]["name"] |
| 461 |
out = f"{name}."+bel_pins[xb]["O"]["name"] |
| 462 |
pd = tt.create_pip(inp,out,"INTERCONNECT") |
| 463 |
pd.extra_data = PipExtraData(ch.strs.id(name),PIP_EXTRA_INTERCONNECT,0,0) |
| 464 |
|
| 465 |
# Create MUXes as many to one connections |
| 466 |
if tile_type in muxes: |
| 467 |
for (name, n) in muxes[tile_type][num].items(): |
| 468 |
for i in range(0,n+1): |
| 469 |
new_name = name + "." + str(i) |
| 470 |
if not tt.has_wire(new_name): |
| 471 |
tt.create_wire(name=new_name, type="MUX_WIRE") |
| 472 |
pd = tt.create_pip(new_name,name,"MUX_PIP") |
| 473 |
pd.extra_data = PipExtraData(ch.strs.id(name),PIP_EXTRA_MUX,i,0) |
| 474 |
|
| 475 |
m = muxes[tile_type] if tile_type in muxes else dict() |
| 476 |
mux = muxes[tile_type][num] if num in m else dict() |
| 477 |
create_pips(tt, tile_type, mux, num, args) |
| 478 |
|
| 479 |
def create_null(ch: Chip): |
| 480 |
tt = ch.create_tile_type("NULL") |
| 481 |
|
| 482 |
def set_timings(ch, pip_timings, bel_timings): |
| 483 |
speed = "DEFAULT" |
| 484 |
tmg = ch.set_speed_grades([speed]) |
| 485 |
for k,v in pip_timings.items(): |
| 486 |
tmg.set_pip_class(grade=speed, name=k, delay=TimingValue(v[0])) |
| 487 |
tmg.set_node_class(grade=speed, name=k, delay=TimingValue(v[0])) |
| 488 |
tmg.set_pip_class(grade=speed, name="INTERCONNECT", delay=TimingValue(0)) |
| 489 |
tmg.set_pip_class(grade=speed, name="MUX_PIP", delay=TimingValue(0)) |
| 490 |
tmg.set_pip_class(grade=speed, name="MATRIX_PIP", delay=TimingValue(0)) |
| 491 |
tmg.set_pip_class(grade=speed, name="LUT_PERMUTATION", delay=TimingValue(0)) |
| 492 |
tmg.set_pip_class(grade=speed, name="BYPASS", delay=TimingValue(142)) |
| 493 |
for k,g in bel_timings.items(): |
| 494 |
primitive = ch.timing.add_cell_variant(speed, k) |
| 495 |
for t,v in g.items(): |
| 496 |
if t=="IOPath": |
| 497 |
for from_port,values in v.items(): |
| 498 |
for to_port,data in values.items(): |
| 499 |
primitive.add_comb_arc(from_port, to_port, TimingValue(data[0], data[1])) |
| 500 |
elif t=="SetupHold": |
| 501 |
for from_port,values in v.items(): |
| 502 |
for to_port,data in values.items(): |
| 503 |
primitive.add_setup_hold(from_port, to_port, ClockEdge.RISING, TimingValue(data[0]), TimingValue(data[1])) |
| 504 |
elif t=="ClockOut": |
| 505 |
for from_port,values in v.items(): |
| 506 |
for to_port,data in values.items(): |
| 507 |
primitive.add_clock_out(from_port, to_port, ClockEdge.RISING, TimingValue(data[0],data[1])) |
| 508 |
|
| 509 |
def get_pos(tilegrid,name,bel): |
| 510 |
tile = tilegrid[name][0]["orig"] |
| 511 |
num = determine_subtile(tile,bel) |
| 512 |
item = tilegrid[name][num] |
| 513 |
x = item["x"] |
| 514 |
y = item["y"] |
| 515 |
return (tile,num,x,y) |
| 516 |
|
| 517 |
|
| 518 |
global_connections = dict() |
| 519 |
def load_globals(args): |
| 520 |
print("Load global connections...") |
| 521 |
with gzip.open(path.join(args.db, args.device, "GLOBAL.txt.gz"),"rt") as f: |
| 522 |
for item in f: |
| 523 |
line = item.strip().split(" ") |
| 524 |
tile_name = line[0].split(":")[0] |
| 525 |
if tile_name not in global_connections: |
| 526 |
global_connections[tile_name] = dict() |
| 527 |
if line[0] not in global_connections[tile_name]: |
| 528 |
global_connections[tile_name][line[0]] = list() |
| 529 |
global_connections[tile_name][line[0]].append(line) |
| 530 |
|
| 531 |
def create_nodes(ch, tile_name, tilegrid, muxes, pip_timings): |
| 532 |
if tile_name not in global_connections: |
| 533 |
return |
| 534 |
connections = global_connections[tile_name] |
| 535 |
for key,val in connections.items(): |
| 536 |
name1 = key.split(":") |
| 537 |
t1,_,x1,y1 = get_pos(tilegrid,name1[0],name1[1]) |
| 538 |
name1[1],_ = map_to_beyond(t1,name1[1]) |
| 539 |
if name1[1] is None: |
| 540 |
continue |
| 541 |
node = [NodeWire(x1, y1, name1[1])] |
| 542 |
timing = None |
| 543 |
timing_val = -1 |
| 544 |
for v in val: |
| 545 |
name2 = v[1].split(":") |
| 546 |
name2[1],_ = map_to_beyond(tilegrid[name2[0]][0]["orig"],name2[1]) |
| 547 |
t2,num,x2,y2 = get_pos(tilegrid,name2[0],name2[1]) |
| 548 |
if name2[1] is None: |
| 549 |
continue |
| 550 |
if pip_timings[v[3]][0] > timing_val: |
| 551 |
timing_val = pip_timings[v[3]][0] |
| 552 |
timing = v[3] |
| 553 |
if t2 in muxes and num in muxes[t2] and name2[1] in muxes[t2][num]: |
| 554 |
node.append(NodeWire(x2, y2, name2[1]+"."+v[2])) |
| 555 |
else: |
| 556 |
node.append(NodeWire(x2, y2, name2[1])) |
| 557 |
|
| 558 |
ch.add_node(node,timing_class=timing) |
| 559 |
|
| 560 |
|
| 561 |
subtile_connections = dict() |
| 562 |
def create_nodes_subtiles(ch, tilegrid, name, tile_type, muxes, pip_timings, args): |
| 563 |
if tile_type not in subtile_connections: |
| 564 |
subtile_connections[tile_type] = dict() |
| 565 |
|
| 566 |
file_path = path.join(args.db, args.device, tile_type + ".txt") |
| 567 |
if not path.isfile(file_path): |
| 568 |
return |
| 569 |
with open(file_path) as f: |
| 570 |
for item in f: |
| 571 |
line = item.strip().split(" ") |
| 572 |
name1 = line[0] |
| 573 |
name2 = line[1] |
| 574 |
name1,_ = map_to_beyond(tile_type,line[0]) |
| 575 |
name2,_ = map_to_beyond(tile_type,line[1]) |
| 576 |
if name1 is None or name2 is None: |
| 577 |
continue |
| 578 |
num1 = determine_subtile(tile_type,name1) |
| 579 |
num2 = determine_subtile(tile_type,name2) |
| 580 |
# Only create WIRE if ends are NOT in same subtile |
| 581 |
if num1!=num2: |
| 582 |
if name1 not in subtile_connections[tile_type] : |
| 583 |
subtile_connections[tile_type][name1] = list() |
| 584 |
subtile_connections[tile_type][name1].append([name1, name2, line[2], line[3]]) |
| 585 |
|
| 586 |
for name1,val in subtile_connections[tile_type].items(): |
| 587 |
_,_,x1,y1 = get_pos(tilegrid,name,name1) |
| 588 |
node = [NodeWire(x1, y1, name1)] |
| 589 |
timing_val = -1 |
| 590 |
timing = None |
| 591 |
for v in val: |
| 592 |
name2 = v[1] |
| 593 |
t2,num,x2,y2 = get_pos(tilegrid,name,name2) |
| 594 |
if pip_timings[v[3]][0] > timing_val: |
| 595 |
timing_val = pip_timings[v[3]][0] |
| 596 |
timing = v[3] |
| 597 |
if t2 in muxes and num in muxes[t2] and name2 in muxes[t2][num]: |
| 598 |
node.append(NodeWire(x2, y2, name2+"."+v[2])) |
| 599 |
else: |
| 600 |
node.append(NodeWire(x2, y2, name2)) |
| 601 |
|
| 602 |
ch.add_node(node,timing_class=timing) |
| 603 |
|
| 604 |
def import_package(ch, package, bels, tilegrid): |
| 605 |
pkg = ch.create_package(package) |
| 606 |
for name, data in tilegrid.items(): |
| 607 |
for key, item in data.items(): |
| 608 |
ty = item["orig"] |
| 609 |
x = item["x"] |
| 610 |
y = item["y"] |
| 611 |
if ty.startswith("IOB"): |
| 612 |
for bel,ty in bels[ty][key].items(): |
| 613 |
# Support for native primitives |
| 614 |
if ty =="IOTP": |
| 615 |
pin = name+"_"+bel[:4] |
| 616 |
elif ty =="IOP": |
| 617 |
pin = name+"_"+bel[:3] |
| 618 |
else: |
| 619 |
continue |
| 620 |
pkg.create_pad(pin, f"X{x}Y{y}", bel, "", int(name[3:])) |
| 621 |
|
| 622 |
def main(): |
| 623 |
xlbase = path.join(path.dirname(path.realpath(__file__)), "..") |
| 624 |
|
| 625 |
parser = argparse.ArgumentParser() |
| 626 |
parser.add_argument("--db", help="Project Beyond device database path (e.g. ../prjbeyond/database)", type=str, required=True) |
| 627 |
parser.add_argument("--device", help="name of device to export", type=str, required=True) |
| 628 |
parser.add_argument("--constids", help="name of nextpnr constids file to read", type=str, default=path.join(xlbase, "constids.inc")) |
| 629 |
parser.add_argument("--bba", help="bba file to write", type=str, required=True) |
| 630 |
args = parser.parse_args() |
| 631 |
|
| 632 |
with open(path.join(args.db, "devices.json")) as f: |
| 633 |
devices = json.load(f) |
| 634 |
|
| 635 |
width = (devices["families"][args.device]["max_col"] + 1) * 4 |
| 636 |
height = (devices["families"][args.device]["max_row"] + 1) * 4 |
| 637 |
packages = devices["families"][args.device]["packages"] |
| 638 |
|
| 639 |
ch = Chip("ng-ultra",args.device, width, height) |
| 640 |
ch.strs.read_constids(path.join(path.dirname(__file__), "..", "constids.inc")) |
| 641 |
|
| 642 |
# Data that is depending of location |
| 643 |
with open(path.join(args.db, args.device, "tilegrid.json")) as f: |
| 644 |
tilegrid = split_tilegrid(json.load(f)) |
| 645 |
|
| 646 |
with open(path.join(args.db, args.device, "bels.json")) as f: |
| 647 |
bels = split_per_bels(json.load(f)) |
| 648 |
|
| 649 |
with open(path.join(args.db, args.device, "crossbars.json")) as f: |
| 650 |
crossbars = split_per_bels(json.load(f)) |
| 651 |
|
| 652 |
with open(path.join(args.db, args.device, "interconnects.json")) as f: |
| 653 |
interconnects = split_per_bels(json.load(f)) |
| 654 |
|
| 655 |
with open(path.join(args.db, args.device, "muxes.json")) as f: |
| 656 |
muxes = split_per_bels(json.load(f)) |
| 657 |
|
| 658 |
# Data that is not related to position |
| 659 |
with open(path.join(args.db, args.device, "bel_pins.json")) as f: |
| 660 |
bel_pins = json.load(f) |
| 661 |
bel_pins["IOP"]["IO"] = { "direction": "Bidir", "name": "IO" } |
| 662 |
bel_pins["IOTP"]["IO"] = { "direction": "Bidir", "name": "IO" } |
| 663 |
|
| 664 |
with open(path.join(args.db, args.device, "pip_timings.json")) as f: |
| 665 |
pip_timings = json.load(f) |
| 666 |
|
| 667 |
with open(path.join(args.db, args.device, "bel_timings.json")) as f: |
| 668 |
bel_timings = json.load(f) |
| 669 |
|
| 670 |
create_tile_types(ch, bels, bel_pins, crossbars, interconnects, muxes, args) |
| 671 |
create_null(ch) |
| 672 |
set_timings(ch, pip_timings, bel_timings) |
| 673 |
|
| 674 |
for x in range(width): |
| 675 |
for y in range(height): |
| 676 |
ch.set_tile_type(x,y,"NULL") |
| 677 |
|
| 678 |
load_globals(args) |
| 679 |
for name, data in tilegrid.items(): |
| 680 |
for item in data.values(): |
| 681 |
ti = ch.set_tile_type(item["x"],item["y"],item["type"]) |
| 682 |
lobe = 0 |
| 683 |
if item["orig"] in ["TILE","CGB"]: |
| 684 |
tmp = name.replace("TILE[","").replace("CGB[","").replace("]","") |
| 685 |
x,y = tmp.split("x") |
| 686 |
lobe = ((int(y)-1) // 12)*2 + (1 if int(x)>46 else 0) + 1 |
| 687 |
elif item["orig"].startswith("IOB") or item["orig"].startswith("HSSL"): |
| 688 |
match item["orig"]: |
| 689 |
case "IOB0" | "IOB1": |
| 690 |
lobe = 5 |
| 691 |
case "IOB6" | "IOB7": |
| 692 |
lobe = 6 |
| 693 |
case "IOB8" | "IOB9" | "IOB10": |
| 694 |
lobe = 2 |
| 695 |
case "IOB11" | "IOB12" | "IOB13": |
| 696 |
lobe = 1 |
| 697 |
case "IOB2" | "IOB3" | "HSSL0" | "HSSL1" | "HSSL2" | "HSSL3": |
| 698 |
lobe = 7 |
| 699 |
case "IOB4" | "IOB5" | "HSSL4" | "HSSL5" | "HSSL6" | "HSSL7": |
| 700 |
lobe = 8 |
| 701 |
tile_type = 0 |
| 702 |
if item["orig"] in ["TILE","CGB","MESH"]: |
| 703 |
tile_type = TILE_EXTRA_FABRIC |
| 704 |
elif item["orig"] in ["TUBE"]: |
| 705 |
tile_type = TILE_EXTRA_TUBE |
| 706 |
elif item["orig"] in ["SOCBank"]: |
| 707 |
tile_type = TILE_EXTRA_SOC |
| 708 |
elif item["orig"].startswith("IOB") or item["orig"].startswith("HSSL") or item["orig"].startswith("CKG"): |
| 709 |
tile_type = TILE_EXTRA_RING |
| 710 |
elif item["orig"].startswith("FENCE"): |
| 711 |
tile_type = TILE_EXTRA_FENCE |
| 712 |
|
| 713 |
ti.extra_data = TileExtraData(ch.strs.id(name),lobe, tile_type) |
| 714 |
|
| 715 |
for name, data in tilegrid.items(): |
| 716 |
print(f"Generate nodes for {name}...") |
| 717 |
create_nodes_subtiles(ch, tilegrid, name, data[0]["orig"], muxes, pip_timings, args) |
| 718 |
create_nodes(ch, name, tilegrid, muxes, pip_timings) |
| 719 |
|
| 720 |
for package in packages: |
| 721 |
import_package(ch, package, bels, tilegrid) |
| 722 |
|
| 723 |
ch.write_bba(args.bba) |
| 724 |
|
| 725 |
if __name__ == '__main__': |
| 726 |
main() |