| 1 |
/* |
| 2 |
* nextpnr -- Next Generation Place and Route |
| 3 |
* |
| 4 |
* Copyright (C) 2024 The Project Peppercorn Authors. |
| 5 |
* |
| 6 |
* Permission to use, copy, modify, and/or distribute this software for any |
| 7 |
* purpose with or without fee is hereby granted, provided that the above |
| 8 |
* copyright notice and this permission notice appear in all copies. |
| 9 |
* |
| 10 |
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 11 |
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 12 |
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 13 |
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 14 |
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 15 |
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 16 |
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 17 |
* |
| 18 |
*/ |
| 19 |
|
| 20 |
#include <boost/algorithm/string.hpp> |
| 21 |
#include "design_utils.h" |
| 22 |
|
| 23 |
#include "gatemate_util.h" |
| 24 |
#include "pack.h" |
| 25 |
|
| 26 |
#define HIMBAECHEL_CONSTIDS "uarch/gatemate/constids.inc" |
| 27 |
#include "himbaechel_constids.h" |
| 28 |
|
| 29 |
NEXTPNR_NAMESPACE_BEGIN |
| 30 |
|
| 31 |
inline bool is_bufg(const BaseCtx *ctx, const CellInfo *cell) { return cell->type.in(id_CC_BUFG); } |
| 32 |
|
| 33 |
void GateMatePacker::sort_bufg(unsigned max_num) |
| 34 |
{ |
| 35 |
struct ItemBufG |
| 36 |
{ |
| 37 |
CellInfo *cell; |
| 38 |
int32_t fan_out; |
| 39 |
ItemBufG(CellInfo *cell, int32_t fan_out) : cell(cell), fan_out(fan_out) {} |
| 40 |
}; |
| 41 |
|
| 42 |
log_info("Sort BUFGs..\n"); |
| 43 |
std::vector<ItemBufG> bufg; |
| 44 |
for (auto &cell : ctx->cells) { |
| 45 |
CellInfo &ci = *cell.second; |
| 46 |
if (!ci.type.in(id_CC_BUFG)) |
| 47 |
continue; |
| 48 |
|
| 49 |
NetInfo *i_net = ci.getPort(id_I); |
| 50 |
if (!i_net) { |
| 51 |
log_warning("Removing BUFG cell %s since there is no input used.\n", ci.name.c_str(ctx)); |
| 52 |
packed_cells.emplace(ci.name); // Remove if no input |
| 53 |
continue; |
| 54 |
} |
| 55 |
NetInfo *o_net = ci.getPort(id_O); |
| 56 |
if (!o_net) { |
| 57 |
log_warning("Removing BUFG cell %s since there is no output used.\n", ci.name.c_str(ctx)); |
| 58 |
packed_cells.emplace(ci.name); // Remove if no output |
| 59 |
continue; |
| 60 |
} |
| 61 |
bufg.push_back(ItemBufG(&ci, o_net->users.entries())); |
| 62 |
} |
| 63 |
|
| 64 |
if (bufg.size() > max_num) { |
| 65 |
log_warning("More than %d BUFG used. Those with highest fan-out will be used.\n", max_num); |
| 66 |
std::sort(bufg.begin(), bufg.end(), [](const ItemBufG &a, const ItemBufG &b) { return a.fan_out > b.fan_out; }); |
| 67 |
for (size_t i = 4; i < bufg.size(); i++) { |
| 68 |
log_warning("Removing BUFG cell %s.\n", bufg.at(i).cell->name.c_str(ctx)); |
| 69 |
CellInfo *cell = bufg.at(i).cell; |
| 70 |
NetInfo *i_net = cell->getPort(id_I); |
| 71 |
NetInfo *o_net = cell->getPort(id_O); |
| 72 |
for (auto s : o_net->users) { |
| 73 |
s.cell->disconnectPort(s.port); |
| 74 |
s.cell->connectPort(s.port, i_net); |
| 75 |
} |
| 76 |
packed_cells.emplace(bufg.at(i).cell->name); |
| 77 |
} |
| 78 |
} |
| 79 |
flush_cells(); |
| 80 |
} |
| 81 |
|
| 82 |
// clang-format off |
| 83 |
static int glb_mux_mapping[] = { |
| 84 |
// CLK0_0 CLK90_0 CLK180_0 CLK270_0 CLK0_1 CLK0_2 CLK0_3 |
| 85 |
4, 5, 6, 7, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, // GLBOUT 0 |
| 86 |
// CLK90_0 CLK0_1 CLK90_1 CLK180_1 CLK270_1 CLK90_2 CLK90_3 |
| 87 |
0, 1, 0, 0, 4, 5, 6, 7, 0, 2, 0, 0, 0, 3, 0, 0, // GLBOUT 1 |
| 88 |
// CLK180_0 CLK180_1 CLK0_2 CLK90_2 CLK180_2 CLK270_2 CLK180_3 |
| 89 |
0, 0, 1, 0, 0, 0, 2, 0, 4, 5, 6, 7, 0, 0, 3, 0, // GLBOUT 2 |
| 90 |
// CLK270_0 CLK270_1 CLK270_2 CLK0_3 CLK90_3 CLK180_3 CLK270_3 |
| 91 |
0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 4, 5, 6, 7, // GLBOUT 3 |
| 92 |
}; |
| 93 |
// clang-format on |
| 94 |
|
| 95 |
void GateMatePacker::pack_bufg() |
| 96 |
{ |
| 97 |
sort_bufg(uarch->strategy == MultiDieStrategy::FULL_USE ? 4 * uarch->dies : 4); |
| 98 |
|
| 99 |
log_info("Packing BUFGs..\n"); |
| 100 |
auto update_bufg_port = [&](std::vector<CellInfo *> &bufg, CellInfo *cell, int port_num, int pll_num) { |
| 101 |
CellInfo *b = net_only_drives(ctx, cell->getPort(ctx->idf("CLK%d", 90 * port_num)), is_bufg, id_I, false); |
| 102 |
if (b) { |
| 103 |
if (bufg[port_num] == nullptr) { |
| 104 |
bufg[port_num] = b; |
| 105 |
return true; |
| 106 |
} else { |
| 107 |
if (bufg[pll_num] == nullptr) { |
| 108 |
bufg[pll_num] = b; |
| 109 |
return true; |
| 110 |
} else { |
| 111 |
return false; |
| 112 |
} |
| 113 |
} |
| 114 |
} |
| 115 |
return true; |
| 116 |
}; |
| 117 |
|
| 118 |
unsigned max_plls = 4 * uarch->dies; |
| 119 |
// Index vector for permutation |
| 120 |
std::vector<unsigned> indexes(max_plls); |
| 121 |
for (unsigned i = 0; i < max_plls; ++i) |
| 122 |
indexes[i] = i; |
| 123 |
|
| 124 |
std::vector<CellInfo *> bufg(max_plls, nullptr); |
| 125 |
std::vector<CellInfo *> pll(max_plls, nullptr); |
| 126 |
pool<IdString> used_bufg; |
| 127 |
bool valid = true; |
| 128 |
do { |
| 129 |
valid = true; |
| 130 |
std::vector<std::vector<CellInfo *>> tmp_bufg(uarch->dies, std::vector<CellInfo *>(4, nullptr)); |
| 131 |
for (unsigned i = 0; i < max_plls; ++i) { |
| 132 |
if (indexes[i] < uarch->pll.size()) { |
| 133 |
for (int j = 0; j < 4; j++) |
| 134 |
valid &= update_bufg_port(tmp_bufg[i >> 2], uarch->pll[indexes[i]], j, i & 3); |
| 135 |
} |
| 136 |
} |
| 137 |
if (valid) { |
| 138 |
for (unsigned i = 0; i < max_plls; ++i) { |
| 139 |
bufg[i] = tmp_bufg[i >> 2][i & 3]; |
| 140 |
if (bufg[i]) |
| 141 |
used_bufg.insert(bufg[i]->name); |
| 142 |
if (indexes[i] < uarch->pll.size()) |
| 143 |
pll[i] = uarch->pll[indexes[i]]; |
| 144 |
} |
| 145 |
break; |
| 146 |
} |
| 147 |
} while (std::next_permutation(indexes.begin(), indexes.end())); |
| 148 |
if (!valid) |
| 149 |
log_error("Unable to place PLLs and BUFGs.\n"); |
| 150 |
|
| 151 |
for (unsigned i = 0; i < max_plls; ++i) { |
| 152 |
|
| 153 |
int die = i >> 2; |
| 154 |
if (!pll[i]) |
| 155 |
continue; |
| 156 |
CellInfo &ci = *pll[i]; |
| 157 |
ci.cluster = ci.name; |
| 158 |
ci.constr_abs_z = true; |
| 159 |
ci.constr_z = 2 + (i & 3); // Position to a proper Z location |
| 160 |
|
| 161 |
Loc fixed_loc = uarch->locations[std::make_pair(ctx->idf("PLL%d", i & 3), die)]; |
| 162 |
BelId pll_bel = ctx->getBelByLocation(fixed_loc); |
| 163 |
ctx->bindBel(pll_bel, &ci, PlaceStrength::STRENGTH_FIXED); |
| 164 |
|
| 165 |
pll_out(&ci, id_CLK0, fixed_loc); |
| 166 |
pll_out(&ci, id_CLK90, fixed_loc); |
| 167 |
pll_out(&ci, id_CLK180, fixed_loc); |
| 168 |
pll_out(&ci, id_CLK270, fixed_loc); |
| 169 |
|
| 170 |
move_ram_i_fixed(&ci, id_USR_PLL_LOCKED, fixed_loc); |
| 171 |
move_ram_i_fixed(&ci, id_USR_PLL_LOCKED_STDY, fixed_loc); |
| 172 |
move_ram_o_fixed(&ci, id_USR_LOCKED_STDY_RST, fixed_loc); |
| 173 |
move_ram_o_fixed(&ci, id_USR_CLK_REF, fixed_loc); |
| 174 |
move_ram_o_fixed(&ci, id_USR_SEL_A_B, fixed_loc); |
| 175 |
} |
| 176 |
|
| 177 |
for (auto &cell : ctx->cells) { |
| 178 |
CellInfo &ci = *cell.second; |
| 179 |
if (!ci.type.in(id_CC_BUFG)) |
| 180 |
continue; |
| 181 |
if (used_bufg.count(cell.second->name)) |
| 182 |
continue; |
| 183 |
|
| 184 |
NetInfo *in_net = ci.getPort(id_I); |
| 185 |
if (in_net) { |
| 186 |
if ((in_net->driver.cell && ctx->getBelBucketForCellType(in_net->driver.cell->type) != id_PLL) || |
| 187 |
!in_net->driver.cell) { |
| 188 |
for (unsigned i = 0; i < max_plls; ++i) { |
| 189 |
if (bufg[i] == nullptr && pll[i] == nullptr) { // PLL must not be used |
| 190 |
bufg[i] = &ci; |
| 191 |
break; |
| 192 |
} |
| 193 |
} |
| 194 |
} |
| 195 |
} |
| 196 |
} |
| 197 |
|
| 198 |
for (unsigned j = 0; j < max_plls; ++j) { |
| 199 |
if (bufg[j]) { |
| 200 |
CellInfo &ci = *bufg[j]; |
| 201 |
int i = j & 3; |
| 202 |
int die = j >> 2; |
| 203 |
uarch->global_signals.emplace(ci.getPort(id_O), j); |
| 204 |
int glb_mux = 0; |
| 205 |
NetInfo *in_net = ci.getPort(id_I); |
| 206 |
copy_constraint(in_net, ci.getPort(id_O)); |
| 207 |
if (in_net->driver.cell) { |
| 208 |
bool user_glb = true; |
| 209 |
if (ctx->getBelBucketForCellType(in_net->driver.cell->type) == id_IOSEL) { |
| 210 |
auto pad_info = uarch->bel_to_pad[in_net->driver.cell->bel]; |
| 211 |
if (pad_info->flags) { |
| 212 |
uarch->clkin[die]->params[ctx->idf("REF%d", i)] = Property(pad_info->flags - 1, 3); |
| 213 |
uarch->clkin[die]->params[ctx->idf("REF%d_INV", i)] = Property(Property::State::S0); |
| 214 |
uarch->clkin[die]->connectPorts(ctx->idf("CLK_REF%d", i), uarch->glbout[die], |
| 215 |
ctx->idf("CLK_REF_OUT%d", i)); |
| 216 |
int index = pad_info->flags - 1; |
| 217 |
if (!uarch->clkin[die]->getPort(ctx->idf("CLK%d", index))) { |
| 218 |
uarch->clkin[die]->connectPort(ctx->idf("CLK%d", index), |
| 219 |
in_net->driver.cell->getPort(id_Y)); |
| 220 |
} |
| 221 |
user_glb = false; |
| 222 |
} |
| 223 |
} |
| 224 |
if (ctx->getBelBucketForCellType(in_net->driver.cell->type) == id_PLL) { |
| 225 |
CellInfo *pll = in_net->driver.cell; |
| 226 |
int pll_index = ctx->getBelLocation(pll->bel).z - 2; |
| 227 |
int pll_out = 0; |
| 228 |
if (pll->getPort(id_CLK0) == in_net) |
| 229 |
pll_out = 0; |
| 230 |
else if (pll->getPort(id_CLK90) == in_net) |
| 231 |
pll_out = 1; |
| 232 |
else if (pll->getPort(id_CLK180) == in_net) |
| 233 |
pll_out = 2; |
| 234 |
else if (pll->getPort(id_CLK270) == in_net) |
| 235 |
pll_out = 3; |
| 236 |
else |
| 237 |
log_error("Unknown connecton on BUFG to PLL.\n"); |
| 238 |
glb_mux = glb_mux_mapping[i * 16 + pll_index * 4 + pll_out]; |
| 239 |
ci.movePortTo(id_I, uarch->glbout[die], |
| 240 |
ctx->idf("%s_%d", in_net->driver.port.c_str(ctx), pll_index)); |
| 241 |
user_glb = false; |
| 242 |
} |
| 243 |
if (user_glb) { |
| 244 |
ci.movePortTo(id_I, uarch->glbout[die], ctx->idf("USR_GLB%d", i)); |
| 245 |
move_ram_o_fixed(uarch->glbout[die], ctx->idf("USR_GLB%d", i), |
| 246 |
ctx->getBelLocation(uarch->glbout[die]->bel)); |
| 247 |
uarch->glbout[die]->params[ctx->idf("USR_GLB%d_EN", i)] = Property(Property::State::S1); |
| 248 |
} |
| 249 |
} else { |
| 250 |
// SER_CLK |
| 251 |
uarch->clkin[die]->connectPort(id_SER_CLK, in_net); |
| 252 |
uarch->clkin[die]->params[ctx->idf("REF%d", i)] = Property(0b100, 3); |
| 253 |
uarch->clkin[die]->params[ctx->idf("REF%d_INV", i)] = Property(Property::State::S0); |
| 254 |
uarch->clkin[die]->connectPorts(ctx->idf("CLK_REF%d", i), uarch->glbout[die], |
| 255 |
ctx->idf("CLK_REF_OUT%d", i)); |
| 256 |
} |
| 257 |
|
| 258 |
ci.movePortTo(id_O, uarch->glbout[die], ctx->idf("GLB%d", i)); |
| 259 |
uarch->glbout[die]->params[ctx->idf("GLB%d_EN", i)] = Property(Property::State::S1); |
| 260 |
uarch->glbout[die]->params[ctx->idf("GLB%d_CFG", i)] = Property(glb_mux, 3); |
| 261 |
packed_cells.emplace(ci.name); |
| 262 |
} |
| 263 |
} |
| 264 |
|
| 265 |
for (auto &cell : uarch->pll) { |
| 266 |
CellInfo &ci = *cell; |
| 267 |
int i = ci.constr_z - 2; |
| 268 |
NetInfo *clk = ci.getPort(id_CLK_REF); |
| 269 |
int die = uarch->tile_extra_data(ci.bel.tile)->die; |
| 270 |
if (clk) { |
| 271 |
if (clk->driver.cell) { |
| 272 |
auto pad_info = uarch->bel_to_pad[clk->driver.cell->bel]; |
| 273 |
uarch->clkin[die]->params[ctx->idf("REF%d", i)] = Property(pad_info->flags - 1, 3); |
| 274 |
uarch->clkin[die]->params[ctx->idf("REF%d_INV", i)] = Property(Property::State::S0); |
| 275 |
int index = pad_info->flags - 1; |
| 276 |
if (!uarch->clkin[die]->getPort(ctx->idf("CLK%d", index))) |
| 277 |
ci.movePortTo(id_CLK_REF, uarch->clkin[die], ctx->idf("CLK%d", index)); |
| 278 |
else |
| 279 |
ci.disconnectPort(id_CLK_REF); |
| 280 |
} else { |
| 281 |
// SER_CLK |
| 282 |
uarch->clkin[die]->params[ctx->idf("REF%d", i)] = Property(0b100, 3); |
| 283 |
uarch->clkin[die]->params[ctx->idf("REF%d_INV", i)] = Property(Property::State::S0); |
| 284 |
ci.movePortTo(id_CLK_REF, uarch->clkin[die], id_SER_CLK); |
| 285 |
} |
| 286 |
uarch->clkin[die]->connectPorts(ctx->idf("CLK_REF%d", i), &ci, id_CLK_REF); |
| 287 |
} |
| 288 |
|
| 289 |
NetInfo *feedback_net = ci.getPort(id_CLK_FEEDBACK); |
| 290 |
if (feedback_net) { |
| 291 |
if (!uarch->global_signals.count(feedback_net)) { |
| 292 |
ci.movePortTo(id_CLK_FEEDBACK, uarch->glbout[die], ctx->idf("USR_FB%d", i)); |
| 293 |
move_ram_o_fixed(uarch->glbout[die], ctx->idf("USR_FB%d", i), |
| 294 |
ctx->getBelLocation(uarch->glbout[die]->bel)); |
| 295 |
uarch->glbout[die]->params[ctx->idf("USR_FB%d_EN", i)] = Property(Property::State::S1); |
| 296 |
} else { |
| 297 |
int index = uarch->global_signals[feedback_net]; |
| 298 |
if ((index >> 2) != die) |
| 299 |
log_error("TODO: Feedback signal from another die.\n"); |
| 300 |
uarch->glbout[die]->params[ctx->idf("FB%d_CFG", i)] = Property(index, 2); |
| 301 |
ci.disconnectPort(id_CLK_FEEDBACK); |
| 302 |
} |
| 303 |
ci.connectPorts(id_CLK_FEEDBACK, uarch->glbout[die], ctx->idf("CLK_FB%d", i)); |
| 304 |
} |
| 305 |
} |
| 306 |
|
| 307 |
flush_cells(); |
| 308 |
} |
| 309 |
|
| 310 |
void GateMatePacker::pll_out(CellInfo *cell, IdString origPort, Loc fixed) |
| 311 |
{ |
| 312 |
NetInfo *net = cell->getPort(origPort); |
| 313 |
if (!net) |
| 314 |
return; |
| 315 |
CellInfo *bufg = nullptr; |
| 316 |
for (auto &usr : net->users) { |
| 317 |
if (usr.cell->type == id_CC_BUFG) |
| 318 |
bufg = usr.cell; |
| 319 |
} |
| 320 |
if (bufg) { |
| 321 |
if (net->users.entries() != 1) { |
| 322 |
log_error("Not handled BUFG.\n"); |
| 323 |
} |
| 324 |
} else { |
| 325 |
move_ram_i_fixed(cell, origPort, fixed); |
| 326 |
} |
| 327 |
} |
| 328 |
|
| 329 |
void GateMatePacker::insert_clocking() |
| 330 |
{ |
| 331 |
log_info("Insert clocking cells..\n"); |
| 332 |
for (int i = 0; i < uarch->dies; i++) { |
| 333 |
Loc fixed_loc = uarch->locations[std::make_pair(id_CLKIN, i)]; |
| 334 |
uarch->clkin.push_back(create_cell_ptr(id_CLKIN, ctx->idf("CLKIN%d", i))); |
| 335 |
BelId clkin_bel = ctx->getBelByLocation(fixed_loc); |
| 336 |
ctx->bindBel(clkin_bel, uarch->clkin.back(), PlaceStrength::STRENGTH_FIXED); |
| 337 |
uarch->glbout.push_back(create_cell_ptr(id_GLBOUT, ctx->idf("GLBOUT%d", i))); |
| 338 |
fixed_loc = uarch->locations[std::make_pair(id_GLBOUT, i)]; |
| 339 |
BelId glbout_bel = ctx->getBelByLocation(fixed_loc); |
| 340 |
ctx->bindBel(glbout_bel, uarch->glbout.back(), PlaceStrength::STRENGTH_FIXED); |
| 341 |
} |
| 342 |
} |
| 343 |
|
| 344 |
void GateMatePacker::remove_clocking() |
| 345 |
{ |
| 346 |
log_info("Remove unused clocking cells..\n"); |
| 347 |
auto remove_unused_cells = [&](std::vector<CellInfo *> &cells) { |
| 348 |
for (auto cell : cells) { |
| 349 |
bool used = false; |
| 350 |
for (auto port : cell->ports) { |
| 351 |
if (cell->getPort(port.first)) { |
| 352 |
used = true; |
| 353 |
break; |
| 354 |
} |
| 355 |
} |
| 356 |
if (!used) { |
| 357 |
BelId bel = cell->bel; |
| 358 |
if (bel != BelId()) |
| 359 |
ctx->unbindBel(bel); |
| 360 |
packed_cells.emplace(cell->name); |
| 361 |
} |
| 362 |
} |
| 363 |
}; |
| 364 |
remove_unused_cells(uarch->clkin); |
| 365 |
remove_unused_cells(uarch->glbout); |
| 366 |
flush_cells(); |
| 367 |
} |
| 368 |
|
| 369 |
static const char *fpga_mode_to_str(int mode) |
| 370 |
{ |
| 371 |
switch (mode) { |
| 372 |
case 1: |
| 373 |
return "LOWPOWER"; |
| 374 |
case 2: |
| 375 |
return "ECONOMY"; |
| 376 |
default: |
| 377 |
return "SPEED"; |
| 378 |
} |
| 379 |
} |
| 380 |
|
| 381 |
void GateMatePacker::pack_pll() |
| 382 |
{ |
| 383 |
log_info("Packing PLLs..\n"); |
| 384 |
for (auto &cell : ctx->cells) { |
| 385 |
CellInfo &ci = *cell.second; |
| 386 |
if (!ci.type.in(id_CC_PLL, id_CC_PLL_ADV)) |
| 387 |
continue; |
| 388 |
|
| 389 |
disconnect_if_gnd(&ci, id_CLK_REF); |
| 390 |
disconnect_if_gnd(&ci, id_USR_CLK_REF); |
| 391 |
disconnect_if_gnd(&ci, id_CLK_FEEDBACK); |
| 392 |
disconnect_if_gnd(&ci, id_USR_LOCKED_STDY_RST); |
| 393 |
|
| 394 |
if (uarch->pll.size() >= (uarch->dies * 4U)) |
| 395 |
log_error("Used more than available PLLs.\n"); |
| 396 |
|
| 397 |
if (ci.getPort(id_CLK_REF) == nullptr && ci.getPort(id_USR_CLK_REF) == nullptr) |
| 398 |
log_error("At least one reference clock (CLK_REF or USR_CLK_REF) must be set for cell '%s'.\n", |
| 399 |
ci.name.c_str(ctx)); |
| 400 |
|
| 401 |
if (ci.getPort(id_CLK_REF) != nullptr && ci.getPort(id_USR_CLK_REF) != nullptr) |
| 402 |
log_error("CLK_REF and USR_CLK_REF are not allowed to be set in same time for cell '%s'.\n", |
| 403 |
ci.name.c_str(ctx)); |
| 404 |
|
| 405 |
NetInfo *clk = ci.getPort(id_CLK_REF); |
| 406 |
delay_t period = ctx->getDelayFromNS(1.0e9 / ctx->setting<float>("target_freq")); |
| 407 |
if (clk) { |
| 408 |
if (clk->driver.cell) { |
| 409 |
if (ctx->getBelBucketForCellType(clk->driver.cell->type) == id_CC_BUFG) { |
| 410 |
NetInfo *in = clk->driver.cell->getPort(id_I); |
| 411 |
ci.disconnectPort(id_CLK_REF); |
| 412 |
ci.connectPort(id_CLK_REF, in); |
| 413 |
clk = in; |
| 414 |
} |
| 415 |
if (ctx->getBelBucketForCellType(clk->driver.cell->type) != id_IOSEL) |
| 416 |
log_error("CLK_REF must be driven with GPIO pin for cell '%s'.\n", ci.name.c_str(ctx)); |
| 417 |
auto pad_info = uarch->bel_to_pad[clk->driver.cell->bel]; |
| 418 |
if (pad_info->flags == 0) |
| 419 |
log_error("CLK_REF must be driven with CLK dedicated pin for cell '%s'.\n", ci.name.c_str(ctx)); |
| 420 |
} else { |
| 421 |
// SER_CLK |
| 422 |
if (clk != net_SER_CLK) |
| 423 |
log_error("CLK_REF connected to unknown pin for cell '%s'.\n", ci.name.c_str(ctx)); |
| 424 |
} |
| 425 |
if (clk->clkconstr) |
| 426 |
period = clk->clkconstr->period.minDelay(); |
| 427 |
} |
| 428 |
|
| 429 |
clk = ci.getPort(id_USR_CLK_REF); |
| 430 |
if (clk) { |
| 431 |
ci.params[ctx->id("USR_CLK_REF")] = Property(0b1, 1); |
| 432 |
if (clk->driver.cell) { |
| 433 |
if (ctx->getBelBucketForCellType(clk->driver.cell->type) == id_CC_BUFG) { |
| 434 |
NetInfo *in = clk->driver.cell->getPort(id_I); |
| 435 |
ci.disconnectPort(id_USR_CLK_REF); |
| 436 |
ci.connectPort(id_USR_CLK_REF, in); |
| 437 |
clk = in; |
| 438 |
} |
| 439 |
} |
| 440 |
if (clk->clkconstr) |
| 441 |
period = clk->clkconstr->period.minDelay(); |
| 442 |
} |
| 443 |
|
| 444 |
if (ci.getPort(id_CLK_REF_OUT)) |
| 445 |
log_error("Output CLK_REF_OUT cannot be used if PLL '%s' is used.\n", ci.name.c_str(ctx)); |
| 446 |
|
| 447 |
double out_clk_max = 0; |
| 448 |
int clk270_doub = 0; |
| 449 |
int clk180_doub = 0; |
| 450 |
if (ci.type == id_CC_PLL) { |
| 451 |
int low_jitter = int_or_default(ci.params, id_LOW_JITTER, 0); |
| 452 |
int ci_const = int_or_default(ci.params, id_CI_FILTER_CONST, 0); |
| 453 |
int cp_const = int_or_default(ci.params, id_CP_FILTER_CONST, 0); |
| 454 |
clk270_doub = int_or_default(ci.params, id_CLK270_DOUB, 0); |
| 455 |
clk180_doub = int_or_default(ci.params, id_CLK180_DOUB, 0); |
| 456 |
int lock_req = int_or_default(ci.params, id_LOCK_REQ, 0); |
| 457 |
|
| 458 |
if (!ci.getPort(id_CLK_FEEDBACK)) |
| 459 |
ci.params[id_LOCK_REQ] = Property(lock_req, 1); |
| 460 |
ci.params[id_CLK180_DOUB] = Property(clk180_doub, 1); |
| 461 |
ci.params[id_CLK270_DOUB] = Property(clk270_doub, 1); |
| 462 |
std::string mode = str_or_default(ci.params, id_PERF_MD, "SPEED"); |
| 463 |
boost::algorithm::to_upper(mode); |
| 464 |
int perf_md; |
| 465 |
double max_freq = 0.0; |
| 466 |
if (mode == "LOWPOWER") { |
| 467 |
perf_md = 1; |
| 468 |
max_freq = 250.00; |
| 469 |
} else if (mode == "ECONOMY") { |
| 470 |
perf_md = 2; |
| 471 |
max_freq = 312.50; |
| 472 |
} else if (mode == "SPEED") { |
| 473 |
perf_md = 3; |
| 474 |
max_freq = 416.75; |
| 475 |
} else { |
| 476 |
log_error("Unknown PERF_MD parameter value '%s' for cell %s.\n", mode.c_str(), ci.name.c_str(ctx)); |
| 477 |
} |
| 478 |
|
| 479 |
if (perf_md != uarch->fpga_mode) |
| 480 |
log_warning("PLL '%s' PERF_MD mode is '%s' but FPGA performance mode is '%s'.\n", ci.name.c_str(ctx), |
| 481 |
fpga_mode_to_str(perf_md), fpga_mode_to_str(uarch->fpga_mode)); |
| 482 |
|
| 483 |
double ref_clk = double_or_default(ci.params, id_REF_CLK, 0.0); |
| 484 |
if (ref_clk <= 0 || ref_clk > 125) |
| 485 |
log_error("REF_CLK parameter is out of range (0,125.00] for '%s'.\n", ci.name.c_str(ctx)); |
| 486 |
|
| 487 |
double out_clk = double_or_default(ci.params, id_OUT_CLK, 0.0); |
| 488 |
if (out_clk <= 0 || out_clk > max_freq) |
| 489 |
log_error("OUT_CLK parameter is out of range (0,%.2lf] for '%s'.\n", max_freq, ci.name.c_str(ctx)); |
| 490 |
|
| 491 |
if ((ci_const < 1) || (ci_const > 31)) { |
| 492 |
log_warning("CI const out of range. Set to default CI = 2 for '%s'.\n", ci.name.c_str(ctx)); |
| 493 |
ci_const = 2; |
| 494 |
} |
| 495 |
if ((cp_const < 1) || (cp_const > 31)) { |
| 496 |
log_warning("CP const out of range. Set to default CP = 4 for '%s'.\n", ci.name.c_str(ctx)); |
| 497 |
cp_const = 4; |
| 498 |
} |
| 499 |
// PLL_cfg_val_800_1400 PLL values from 11.08.2021 |
| 500 |
bool feedback = false; |
| 501 |
if (ci.getPort(id_CLK_FEEDBACK)) { |
| 502 |
ci.params[ctx->id("CFG_A_FB_PATH")] = Property(0b1, 1); |
| 503 |
feedback = true; |
| 504 |
} |
| 505 |
ci.params[ctx->id("CFG_A_FINE_TUNE")] = Property(0b00011001000, 11); |
| 506 |
ci.params[ctx->id("CFG_A_COARSE_TUNE")] = Property(0b100, 3); |
| 507 |
ci.params[ctx->id("CFG_A_AO_SW")] = Property(0b01000, 5); |
| 508 |
ci.params[ctx->id("CFG_A_OPEN_LOOP")] = Property(0b0, 1); |
| 509 |
ci.params[ctx->id("CFG_A_ENFORCE_LOCK")] = Property(0b0, 1); |
| 510 |
ci.params[ctx->id("CFG_A_PFD_SEL")] = Property(0b0, 1); |
| 511 |
ci.params[ctx->id("CFG_A_LOCK_DETECT_WIN")] = Property(0b0, 1); |
| 512 |
ci.params[ctx->id("CFG_A_SYNC_BYPASS")] = Property(0b0, 1); |
| 513 |
ci.params[ctx->id("CFG_A_FILTER_SHIFT")] = Property(0b10, 2); |
| 514 |
ci.params[ctx->id("CFG_A_FAST_LOCK")] = Property(0b1, 1); |
| 515 |
ci.params[ctx->id("CFG_A_SAR_LIMIT")] = Property(0b010, 3); |
| 516 |
ci.params[ctx->id("CFG_A_OP_LOCK")] = Property(0b0, 1); |
| 517 |
ci.params[ctx->id("CFG_A_PDIV0_MUX")] = Property(0b1, 1); |
| 518 |
ci.params[ctx->id("CFG_A_EN_COARSE_TUNE")] = Property(0b1, 1); |
| 519 |
ci.params[ctx->id("CFG_A_EN_USR_CFG")] = Property(0b0, 1); |
| 520 |
ci.params[ctx->id("CFG_A_PLL_EN_SEL")] = Property(0b0, 1); |
| 521 |
|
| 522 |
ci.params[ctx->id("CFG_A_CI_FILTER_CONST")] = Property(ci_const, 5); |
| 523 |
ci.params[ctx->id("CFG_A_CP_FILTER_CONST")] = Property(cp_const, 5); |
| 524 |
/* |
| 525 |
clock path selection |
| 526 |
0-0 PDIV0_MUX = 0, FB_PATH = 0 // DCO clock with intern feedback |
| 527 |
1-0 PDIV0_MUX = 1, FB_PATH = 0 // divided clock: PDIV1->M1->M2 with intern feedback DEFAULT |
| 528 |
0-1 not possible f_core = f_ref will set PDIV0_MUX = 1 |
| 529 |
1-1 PDIV0_MUX = 1, FB_PATH = 1 // divided clock: PDIV1->M1->M2 with extern feedback |
| 530 |
PDIV1->M1->M2->PDIV0->N1->N2 } |
| 531 |
*/ |
| 532 |
bool pdiv0_mux = true; |
| 533 |
PllCfgRecord val = get_pll_settings(ref_clk, out_clk, perf_md, low_jitter, pdiv0_mux, feedback); |
| 534 |
if (val.f_core > 0) { // cfg exists |
| 535 |
ci.params[ctx->id("CFG_A_K")] = Property(val.K, 12); |
| 536 |
ci.params[ctx->id("CFG_A_N1")] = Property(val.N1, 6); |
| 537 |
ci.params[ctx->id("CFG_A_N2")] = Property(val.N2, 10); |
| 538 |
ci.params[ctx->id("CFG_A_M1")] = Property(val.M1, 6); |
| 539 |
ci.params[ctx->id("CFG_A_M2")] = Property(val.M2, 10); |
| 540 |
ci.params[ctx->id("CFG_A_PDIV1_SEL")] = Property(val.PDIV1 == 2 ? 1 : 0, 1); |
| 541 |
} else { |
| 542 |
log_error("Unable to configure PLL %s.\n", ci.name.c_str(ctx)); |
| 543 |
} |
| 544 |
// Remove all not propagated parameters |
| 545 |
ci.unsetParam(id_PERF_MD); |
| 546 |
ci.unsetParam(id_REF_CLK); |
| 547 |
ci.unsetParam(id_OUT_CLK); |
| 548 |
ci.unsetParam(id_LOW_JITTER); |
| 549 |
ci.unsetParam(id_CI_FILTER_CONST); |
| 550 |
ci.unsetParam(id_CP_FILTER_CONST); |
| 551 |
out_clk_max = out_clk; |
| 552 |
} else { |
| 553 |
// Handling CC_PLL_ADV |
| 554 |
for (int i = 0; i < 2; i++) { |
| 555 |
char cfg = 'A' + i; |
| 556 |
IdString id = i == 0 ? id_PLL_CFG_A : id_PLL_CFG_B; |
| 557 |
ci.params[ctx->idf("CFG_%c_CI_FILTER_CONST", cfg)] = Property(extract_bits(ci.params, id, 0, 5), 5); |
| 558 |
ci.params[ctx->idf("CFG_%c_CP_FILTER_CONST", cfg)] = Property(extract_bits(ci.params, id, 5, 5), 5); |
| 559 |
ci.params[ctx->idf("CFG_%c_N1", cfg)] = Property(extract_bits(ci.params, id, 10, 6), 6); |
| 560 |
ci.params[ctx->idf("CFG_%c_N2", cfg)] = Property(extract_bits(ci.params, id, 16, 10), 10); |
| 561 |
ci.params[ctx->idf("CFG_%c_M1", cfg)] = Property(extract_bits(ci.params, id, 26, 6), 6); |
| 562 |
ci.params[ctx->idf("CFG_%c_M2", cfg)] = Property(extract_bits(ci.params, id, 32, 10), 10); |
| 563 |
ci.params[ctx->idf("CFG_%c_K", cfg)] = Property(extract_bits(ci.params, id, 42, 12), 12); |
| 564 |
ci.params[ctx->idf("CFG_%c_FB_PATH", cfg)] = Property(extract_bits(ci.params, id, 54, 1), 1); |
| 565 |
ci.params[ctx->idf("CFG_%c_FINE_TUNE", cfg)] = Property(extract_bits(ci.params, id, 55, 11), 11); |
| 566 |
ci.params[ctx->idf("CFG_%c_COARSE_TUNE", cfg)] = Property(extract_bits(ci.params, id, 66, 3), 3); |
| 567 |
ci.params[ctx->idf("CFG_%c_AO_SW", cfg)] = Property(extract_bits(ci.params, id, 69, 5), 5); |
| 568 |
ci.params[ctx->idf("CFG_%c_OPEN_LOOP", cfg)] = Property(extract_bits(ci.params, id, 74, 1), 1); |
| 569 |
ci.params[ctx->idf("CFG_%c_ENFORCE_LOCK", cfg)] = Property(extract_bits(ci.params, id, 75, 1), 1); |
| 570 |
ci.params[ctx->idf("CFG_%c_PFD_SEL", cfg)] = Property(extract_bits(ci.params, id, 76, 1), 1); |
| 571 |
ci.params[ctx->idf("CFG_%c_LOCK_DETECT_WIN", cfg)] = Property(extract_bits(ci.params, id, 77, 1), 1); |
| 572 |
ci.params[ctx->idf("CFG_%c_SYNC_BYPASS", cfg)] = Property(extract_bits(ci.params, id, 78, 1), 1); |
| 573 |
ci.params[ctx->idf("CFG_%c_FILTER_SHIFT", cfg)] = Property(extract_bits(ci.params, id, 79, 2), 2); |
| 574 |
ci.params[ctx->idf("CFG_%c_FAST_LOCK", cfg)] = Property(extract_bits(ci.params, id, 81, 1), 1); |
| 575 |
ci.params[ctx->idf("CFG_%c_SAR_LIMIT", cfg)] = Property(extract_bits(ci.params, id, 82, 3), 3); |
| 576 |
ci.params[ctx->idf("CFG_%c_OP_LOCK", cfg)] = Property(extract_bits(ci.params, id, 85, 1), 1); |
| 577 |
ci.params[ctx->idf("CFG_%c_PDIV1_SEL", cfg)] = Property(extract_bits(ci.params, id, 86, 1), 1); |
| 578 |
ci.params[ctx->idf("CFG_%c_PDIV0_MUX", cfg)] = Property(extract_bits(ci.params, id, 87, 1), 1); |
| 579 |
ci.params[ctx->idf("CFG_%c_EN_COARSE_TUNE", cfg)] = Property(extract_bits(ci.params, id, 88, 1), 1); |
| 580 |
ci.params[ctx->idf("CFG_%c_EN_USR_CFG", cfg)] = Property(extract_bits(ci.params, id, 89, 1), 1); |
| 581 |
ci.params[ctx->idf("CFG_%c_PLL_EN_SEL", cfg)] = Property(extract_bits(ci.params, id, 90, 1), 1); |
| 582 |
int N1 = int_or_default(ci.params, ctx->idf("CFG_%c_N1", cfg)); |
| 583 |
int N2 = int_or_default(ci.params, ctx->idf("CFG_%c_N2", cfg)); |
| 584 |
int M1 = int_or_default(ci.params, ctx->idf("CFG_%c_M1", cfg)); |
| 585 |
int M2 = int_or_default(ci.params, ctx->idf("CFG_%c_M2", cfg)); |
| 586 |
int K = int_or_default(ci.params, ctx->idf("CFG_%c_K", cfg)); |
| 587 |
int PDIV1 = bool_or_default(ci.params, ctx->idf("CFG_%c_PDIV1_SEL", cfg)) ? 2 : 0; |
| 588 |
double out_clk; |
| 589 |
double ref_clk = 1000.0f / ctx->getDelayNS(period); |
| 590 |
if (!bool_or_default(ci.params, ctx->idf("CFG_%c_FB_PATH", cfg))) { |
| 591 |
if (bool_or_default(ci.params, ctx->idf("CFG_%c_PDIV0_MUX", cfg))) { |
| 592 |
out_clk = (ref_clk * N1 * N2) / (K * 2 * M1 * M2); |
| 593 |
} else { |
| 594 |
out_clk = (ref_clk / K) * N1 * N2 * PDIV1; |
| 595 |
} |
| 596 |
} else { |
| 597 |
out_clk = (ref_clk / K) * N1 * N2; |
| 598 |
} |
| 599 |
if (out_clk > out_clk_max) |
| 600 |
out_clk_max = out_clk; |
| 601 |
} |
| 602 |
NetInfo *select_net = ci.getPort(id_USR_SEL_A_B); |
| 603 |
if (select_net == nullptr || select_net == net_PACKER_GND) { |
| 604 |
ci.params[ctx->id("SET_SEL")] = Property(0b0, 1); |
| 605 |
ci.params[ctx->id("USR_SET")] = Property(0b0, 1); |
| 606 |
ci.disconnectPort(id_USR_SEL_A_B); |
| 607 |
} else if (select_net == net_PACKER_VCC) { |
| 608 |
ci.params[ctx->id("SET_SEL")] = Property(0b1, 1); |
| 609 |
ci.params[ctx->id("USR_SET")] = Property(0b0, 1); |
| 610 |
ci.disconnectPort(id_USR_SEL_A_B); |
| 611 |
} else { |
| 612 |
ci.params[ctx->id("USR_SET")] = Property(0b1, 1); |
| 613 |
} |
| 614 |
ci.params[ctx->id("LOCK_REQ")] = Property(0b1, 1); |
| 615 |
ci.unsetParam(id_PLL_CFG_A); |
| 616 |
ci.unsetParam(id_PLL_CFG_B); |
| 617 |
if (!ci.getPort(id_CLK_FEEDBACK)) |
| 618 |
ci.params[ctx->id("LOCK_REQ")] = Property(0b1, 1); |
| 619 |
} |
| 620 |
|
| 621 |
// PLL control register A |
| 622 |
ci.params[ctx->id("PLL_RST")] = Property(0b1, 1); |
| 623 |
ci.params[ctx->id("PLL_EN")] = Property(0b1, 1); |
| 624 |
// PLL_AUTN - for Autonomous Mode - not set |
| 625 |
// SET_SEL - handled in CC_PLL_ADV |
| 626 |
// USR_SET - handled in CC_PLL_ADV |
| 627 |
// USR_CLK_REF - based on signals used |
| 628 |
ci.params[ctx->id("CLK_OUT_EN")] = Property(0b1, 1); |
| 629 |
// LOCK_REQ - set by CC_PLL parameter |
| 630 |
|
| 631 |
// PLL control register B |
| 632 |
// AUTN_CT_I - for Autonomous Mode - not set |
| 633 |
// CLK180_DOUB - set by CC_PLL parameter |
| 634 |
// CLK270_DOUB - set by CC_PLL parameter |
| 635 |
// bits 6 and 7 are unused |
| 636 |
// USR_CLK_OUT - part of routing, mux from chipdb |
| 637 |
|
| 638 |
if (ci.getPort(id_CLK0)) |
| 639 |
ctx->addClock(ci.getPort(id_CLK0)->name, out_clk_max); |
| 640 |
if (ci.getPort(id_CLK90)) |
| 641 |
ctx->addClock(ci.getPort(id_CLK90)->name, out_clk_max); |
| 642 |
if (ci.getPort(id_CLK180)) |
| 643 |
ctx->addClock(ci.getPort(id_CLK180)->name, clk180_doub ? out_clk_max * 2 : out_clk_max); |
| 644 |
if (ci.getPort(id_CLK270)) |
| 645 |
ctx->addClock(ci.getPort(id_CLK270)->name, clk270_doub ? out_clk_max * 2 : out_clk_max); |
| 646 |
|
| 647 |
ci.type = id_PLL; |
| 648 |
|
| 649 |
uarch->pll.push_back(&ci); |
| 650 |
} |
| 651 |
} |
| 652 |
|
| 653 |
void GateMatePacker::rewire_ram_o(CellInfo *first, IdString port, CellInfo *second) |
| 654 |
{ |
| 655 |
NetInfo *net = first->getPort(port); |
| 656 |
if (net && net->driver.cell) { |
| 657 |
net = net->driver.cell->getPort(id_I); |
| 658 |
if (net && net->driver.cell) { |
| 659 |
uint8_t val = int_or_default(net->driver.cell->params, id_INIT_L00, 0); |
| 660 |
switch (val) { |
| 661 |
case LUT_ZERO: |
| 662 |
net = net_PACKER_GND; |
| 663 |
break; |
| 664 |
case LUT_ONE: |
| 665 |
net = net_PACKER_VCC; |
| 666 |
break; |
| 667 |
case LUT_D0: |
| 668 |
net = net->driver.cell->getPort(id_IN1); |
| 669 |
break; |
| 670 |
default: |
| 671 |
log_error("Unsupported config, rewire from '%s' port '%s'.\n", first->name.c_str(ctx), port.c_str(ctx)); |
| 672 |
break; |
| 673 |
} |
| 674 |
second->connectPort(port, net); |
| 675 |
} else { |
| 676 |
log_error("Missing cell, rewire from '%s' port '%s'.\n", first->name.c_str(ctx), port.c_str(ctx)); |
| 677 |
} |
| 678 |
} else { |
| 679 |
log_error("Missing cell, rewire from '%s' port '%s'.\n", first->name.c_str(ctx), port.c_str(ctx)); |
| 680 |
} |
| 681 |
} |
| 682 |
|
| 683 |
void GateMatePacker::copy_clocks() |
| 684 |
{ |
| 685 |
if (uarch->dies == 1) |
| 686 |
return; |
| 687 |
switch (uarch->strategy) { |
| 688 |
case MultiDieStrategy::REUSE_CLK1: |
| 689 |
if (uarch->global_signals.size() > 1 || uarch->pll.size() > 1) |
| 690 |
log_error("Unable to use REUSE CLK1 strategy when there is more than one clock/PLL.\n"); |
| 691 |
strategy_clk1(); |
| 692 |
break; |
| 693 |
case MultiDieStrategy::CLOCK_MIRROR: |
| 694 |
if (uarch->global_signals.size() > 4 || uarch->pll.size() > 4) |
| 695 |
log_error("Unable to use MIRROR CLOCK strategy when there is more than 4 clocks/PLLs.\n"); |
| 696 |
strategy_mirror(); |
| 697 |
break; |
| 698 |
case MultiDieStrategy::FULL_USE: |
| 699 |
strategy_full(); |
| 700 |
break; |
| 701 |
} |
| 702 |
} |
| 703 |
|
| 704 |
void GateMatePacker::strategy_full() |
| 705 |
{ |
| 706 |
log_info("All resources for clock distribution..\n"); |
| 707 |
|
| 708 |
for (int new_die = 1; new_die < uarch->dies; new_die++) { |
| 709 |
// Create appropriate GPIO and IOSEL cells |
| 710 |
for (int i = 0; i < 4; i++) { |
| 711 |
NetInfo *in_net = uarch->clkin[new_die]->getPort(ctx->idf("CLK%d", i)); |
| 712 |
if (in_net && in_net->driver.cell) { |
| 713 |
CellInfo *iosel = in_net->driver.cell; |
| 714 |
auto pad_info = uarch->bel_to_pad[iosel->bel]; |
| 715 |
Loc l = uarch->locations[std::make_pair(IdString(pad_info->package_pin), new_die)]; |
| 716 |
CellInfo *iosel_new = ctx->getBoundBelCell(ctx->getBelByLocation(l)); |
| 717 |
if (!iosel_new) { |
| 718 |
iosel_new = create_cell_ptr(iosel->type, ctx->idf("%s$die%d", iosel->name.c_str(ctx), new_die)); |
| 719 |
iosel_new->params = iosel->params; |
| 720 |
ctx->bindBel(ctx->getBelByLocation(l), iosel_new, PlaceStrength::STRENGTH_FIXED); |
| 721 |
|
| 722 |
CellInfo *gpio = iosel->getPort(id_GPIO_IN)->driver.cell; |
| 723 |
CellInfo *gpio_new = |
| 724 |
create_cell_ptr(gpio->type, ctx->idf("%s$die%d", gpio->name.c_str(ctx), new_die)); |
| 725 |
gpio_new->params = gpio->params; |
| 726 |
ctx->bindBel(ctx->getBelByLocation({l.x, l.y, 0}), gpio_new, PlaceStrength::STRENGTH_FIXED); |
| 727 |
|
| 728 |
// Duplicate input connection |
| 729 |
gpio_new->connectPort(id_I, gpio->getPort(id_I)); |
| 730 |
// Connect IOSEL and CPE_IBUF |
| 731 |
gpio_new->connectPorts(id_Y, iosel_new, id_GPIO_IN); |
| 732 |
} |
| 733 |
uarch->clkin[new_die]->disconnectPort(ctx->idf("CLK%d", i)); |
| 734 |
if (iosel_new->getPort(id_IN1)) |
| 735 |
uarch->clkin[new_die]->connectPort(ctx->idf("CLK%d", i), iosel_new->getPort(id_IN1)); |
| 736 |
else |
| 737 |
iosel_new->connectPorts(id_IN1, uarch->clkin[new_die], ctx->idf("CLK%d", i)); |
| 738 |
} |
| 739 |
} |
| 740 |
} |
| 741 |
} |
| 742 |
|
| 743 |
void GateMatePacker::strategy_clk1() |
| 744 |
{ |
| 745 |
log_info("Reuse CLK1 for clock distribution..\n"); |
| 746 |
NetInfo *net = uarch->glbout[0]->getPort(id_GLB0); |
| 747 |
NetInfo *new_clk1 = ctx->createNet(ctx->id("$clk1$pin")); |
| 748 |
for (int new_die = 0; new_die < uarch->dies; new_die++) { |
| 749 |
CellInfo *iosel = create_cell_ptr(id_IOSEL, ctx->idf("$iosel_clk1$die%d", new_die)); |
| 750 |
iosel->setParam(id_DELAY_IBF, Property(1, 16)); |
| 751 |
iosel->setParam(id_INPUT_ENABLE, Property(1, 1)); |
| 752 |
if (new_die == 0) { |
| 753 |
// On die 0 it should be output as well |
| 754 |
iosel->setParam(id_DELAY_OBF, Property(1, 16)); |
| 755 |
iosel->setParam(id_OE_ENABLE, Property(1, 1)); |
| 756 |
iosel->setParam(id_OUT_SIGNAL, Property(1, 1)); |
| 757 |
iosel->setParam(id_SLEW, Property(1, 1)); |
| 758 |
} |
| 759 |
|
| 760 |
BelId bel = ctx->getBelByLocation(uarch->locations[std::make_pair(ctx->id("IO_SB_A7"), new_die)]); |
| 761 |
ctx->bindBel(bel, iosel, PlaceStrength::STRENGTH_FIXED); |
| 762 |
|
| 763 |
CellInfo *gpio = create_cell_ptr((new_die ? id_CPE_IBUF : id_CPE_IOBUF), ctx->idf("$clk1$die%d", new_die)); |
| 764 |
Loc loc = ctx->getBelLocation(bel); |
| 765 |
ctx->bindBel(ctx->getBelByLocation({loc.x, loc.y, 0}), gpio, PlaceStrength::STRENGTH_FIXED); |
| 766 |
|
| 767 |
uarch->clkin[new_die]->connectPort(id_CLK1, new_clk1); |
| 768 |
uarch->clkin[new_die]->params[ctx->id("REF1")] = Property(1, 3); |
| 769 |
uarch->glbout[new_die]->params[ctx->id("GLB1_EN")] = Property(Property::State::S1); |
| 770 |
uarch->glbout[new_die]->params[ctx->id("GLB1_CFG")] = Property(0, 3); |
| 771 |
uarch->clkin[new_die]->connectPorts(ctx->id("CLK_REF1"), uarch->glbout[new_die], ctx->id("CLK_REF_OUT1")); |
| 772 |
|
| 773 |
gpio->connectPorts(id_Y, iosel, id_GPIO_IN); |
| 774 |
|
| 775 |
if (new_die == 0) { |
| 776 |
iosel->connectPort(id_OUT1, ctx->getNetByAlias(uarch->global_signals.begin()->first->name)); |
| 777 |
CellInfo *cpe = move_ram_o_fixed(iosel, id_OUT1, loc).first; |
| 778 |
uarch->ignore.emplace(cpe->name); |
| 779 |
|
| 780 |
iosel->connectPorts(id_GPIO_OUT, gpio, id_A); |
| 781 |
iosel->connectPorts(id_GPIO_EN, gpio, id_T); |
| 782 |
gpio->connectPort(id_IO, new_clk1); |
| 783 |
} else { |
| 784 |
gpio->connectPort(id_I, new_clk1); |
| 785 |
} |
| 786 |
|
| 787 |
NetInfo *new_signal = ctx->createNet(ctx->idf("%s$die%d", net->name.c_str(ctx), new_die)); |
| 788 |
uarch->glbout[new_die]->connectPort(ctx->id("GLB1"), new_signal); |
| 789 |
copy_constraint(net, new_signal); |
| 790 |
uarch->global_mapping.emplace(std::make_pair(net->name, new_die), new_signal); |
| 791 |
uarch->global_clk_mapping.emplace(std::make_pair(id_CLOCK1, new_die), id_CLOCK2); |
| 792 |
} |
| 793 |
} |
| 794 |
|
| 795 |
void GateMatePacker::strategy_mirror() |
| 796 |
{ |
| 797 |
log_info("Mirror clocks..\n"); |
| 798 |
|
| 799 |
// Save first CLKIN inputs |
| 800 |
std::vector<CellInfo *> clk_iosel(4, nullptr); |
| 801 |
bool use_ser_clk = false; |
| 802 |
for (int i = 0; i < 4; i++) { |
| 803 |
NetInfo *in_net = uarch->clkin[0]->getPort(ctx->idf("CLK%d", i)); |
| 804 |
if (in_net) { |
| 805 |
if (in_net->driver.cell) |
| 806 |
clk_iosel[i] = in_net->driver.cell; |
| 807 |
else |
| 808 |
use_ser_clk = true; |
| 809 |
} |
| 810 |
uarch->clkin[0]->disconnectPort(ctx->idf("CLK%d", i)); |
| 811 |
} |
| 812 |
|
| 813 |
for (int new_die = 0; new_die < uarch->dies; new_die++) { |
| 814 |
// Reconnect CLKIN and create appropriate GPIO and IOSEL cells |
| 815 |
for (int i = 0; i < 4; i++) { |
| 816 |
if (clk_iosel[i]) { |
| 817 |
CellInfo *iosel = clk_iosel[i]; |
| 818 |
auto pad_info = uarch->bel_to_pad[iosel->bel]; |
| 819 |
Loc l = uarch->locations[std::make_pair(IdString(pad_info->package_pin), new_die)]; |
| 820 |
CellInfo *iosel_new = ctx->getBoundBelCell(ctx->getBelByLocation(l)); |
| 821 |
if (!iosel_new) { |
| 822 |
iosel_new = create_cell_ptr(iosel->type, ctx->idf("%s$die%d", iosel->name.c_str(ctx), new_die)); |
| 823 |
iosel_new->params = iosel->params; |
| 824 |
ctx->bindBel(ctx->getBelByLocation(l), iosel_new, PlaceStrength::STRENGTH_FIXED); |
| 825 |
|
| 826 |
CellInfo *gpio = iosel->getPort(id_GPIO_IN)->driver.cell; |
| 827 |
CellInfo *gpio_new = |
| 828 |
create_cell_ptr(gpio->type, ctx->idf("%s$die%d", gpio->name.c_str(ctx), new_die)); |
| 829 |
gpio_new->params = gpio->params; |
| 830 |
ctx->bindBel(ctx->getBelByLocation({l.x, l.y, 0}), gpio_new, PlaceStrength::STRENGTH_FIXED); |
| 831 |
|
| 832 |
// Duplicate input connection |
| 833 |
gpio_new->connectPort(id_I, gpio->getPort(id_I)); |
| 834 |
// Connect IOSEL and CPE_IBUF |
| 835 |
gpio_new->connectPorts(id_Y, iosel_new, id_GPIO_IN); |
| 836 |
} |
| 837 |
if (iosel_new->getPort(id_IN1)) |
| 838 |
uarch->clkin[new_die]->connectPort(ctx->idf("CLK%d", i), iosel_new->getPort(id_IN1)); |
| 839 |
else |
| 840 |
iosel_new->connectPorts(id_IN1, uarch->clkin[new_die], ctx->idf("CLK%d", i)); |
| 841 |
} |
| 842 |
} |
| 843 |
if (use_ser_clk) |
| 844 |
uarch->clkin[new_die]->connectPort(id_SER_CLK, net_SER_CLK); |
| 845 |
|
| 846 |
if (new_die != 0) { |
| 847 |
// Copy configuration from first die to other dies |
| 848 |
uarch->clkin[new_die]->params = uarch->clkin[0]->params; |
| 849 |
uarch->glbout[new_die]->params = uarch->glbout[0]->params; |
| 850 |
|
| 851 |
// Copy PLLs |
| 852 |
for (int i = 0; i < 4; i++) { |
| 853 |
Loc fixed_loc = uarch->locations[std::make_pair(ctx->idf("PLL%d", i), 0)]; |
| 854 |
BelId pll_bel = ctx->getBelByLocation(fixed_loc); |
| 855 |
CellInfo *pll = ctx->getBoundBelCell(pll_bel); |
| 856 |
if (pll) { |
| 857 |
// Create new PLL |
| 858 |
CellInfo *pll_new = create_cell_ptr(pll->type, ctx->idf("%s$die%d", pll->name.c_str(ctx), new_die)); |
| 859 |
pll_new->params = pll->params; |
| 860 |
// Bind to new location |
| 861 |
Loc new_loc = uarch->locations[std::make_pair(ctx->idf("PLL%d", i), new_die)]; |
| 862 |
BelId bel = ctx->getBelByLocation(new_loc); |
| 863 |
ctx->bindBel(bel, pll_new, PlaceStrength::STRENGTH_FIXED); |
| 864 |
|
| 865 |
if (pll->getPort(id_CLK_REF)) |
| 866 |
uarch->clkin[new_die]->connectPorts(ctx->idf("CLK_REF%d", i), pll_new, id_CLK_REF); |
| 867 |
|
| 868 |
if (pll->getPort(id_CLK0)) |
| 869 |
pll_new->connectPorts(id_CLK0, uarch->glbout[new_die], ctx->idf("CLK0_%d", i)); |
| 870 |
if (pll->getPort(id_CLK90)) |
| 871 |
pll_new->connectPorts(id_CLK90, uarch->glbout[new_die], ctx->idf("CLK90_%d", i)); |
| 872 |
if (pll->getPort(id_CLK180)) |
| 873 |
pll_new->connectPorts(id_CLK180, uarch->glbout[new_die], ctx->idf("CLK180_%d", i)); |
| 874 |
if (pll->getPort(id_CLK270)) |
| 875 |
pll_new->connectPorts(id_CLK270, uarch->glbout[new_die], ctx->idf("CLK270_%d", i)); |
| 876 |
if (pll->getPort(id_USR_LOCKED_STDY_RST)) |
| 877 |
rewire_ram_o(pll, id_USR_LOCKED_STDY_RST, pll_new); |
| 878 |
if (pll->getPort(id_USR_CLK_REF)) |
| 879 |
rewire_ram_o(pll, id_USR_CLK_REF, pll_new); |
| 880 |
if (pll->getPort(id_USR_SEL_A_B)) |
| 881 |
rewire_ram_o(pll, id_USR_SEL_A_B, pll_new); |
| 882 |
move_ram_o_fixed(pll_new, id_USR_LOCKED_STDY_RST, new_loc); |
| 883 |
move_ram_o_fixed(pll_new, id_USR_CLK_REF, new_loc); |
| 884 |
move_ram_o_fixed(pll_new, id_USR_SEL_A_B, new_loc); |
| 885 |
// TODO: AND outputs of all USR_LOCKED_STDY_RST and use that signal to drive logic |
| 886 |
} |
| 887 |
} |
| 888 |
// Copy GLBOUT inputs |
| 889 |
for (int i = 0; i < 4; i++) { |
| 890 |
Loc new_loc = uarch->locations[std::make_pair(id_GLBOUT, new_die)]; |
| 891 |
// Plain copy of user signals |
| 892 |
NetInfo *net = uarch->glbout[0]->getPort(ctx->idf("USR_GLB%d", i)); |
| 893 |
if (net) |
| 894 |
rewire_ram_o(uarch->glbout[0], ctx->idf("USR_GLB%d", i), uarch->glbout[new_die]); |
| 895 |
|
| 896 |
net = uarch->glbout[0]->getPort(ctx->idf("USR_FB%d", i)); |
| 897 |
if (net) |
| 898 |
rewire_ram_o(uarch->glbout[0], ctx->idf("USR_FB%d", i), uarch->glbout[new_die]); |
| 899 |
|
| 900 |
move_ram_o_fixed(uarch->glbout[new_die], ctx->idf("USR_GLB%d", i), new_loc); |
| 901 |
move_ram_o_fixed(uarch->glbout[new_die], ctx->idf("USR_FB%d", i), new_loc); |
| 902 |
|
| 903 |
if (uarch->glbout[0]->getPort(ctx->idf("CLK_REF_OUT%d", i))) |
| 904 |
uarch->clkin[new_die]->connectPorts(ctx->idf("CLK_REF%d", i), uarch->glbout[new_die], |
| 905 |
ctx->idf("CLK_REF_OUT%d", i)); |
| 906 |
} |
| 907 |
} |
| 908 |
for (int i = 0; i < 4; i++) { |
| 909 |
NetInfo *net = uarch->glbout[0]->getPort(ctx->idf("GLB%d", i)); |
| 910 |
if (net) { |
| 911 |
if (new_die != 0) { |
| 912 |
NetInfo *new_signal = ctx->createNet(ctx->idf("%s$die%d", net->name.c_str(ctx), new_die)); |
| 913 |
uarch->glbout[new_die]->connectPort(ctx->idf("GLB%d", i), new_signal); |
| 914 |
copy_constraint(net, new_signal); |
| 915 |
uarch->global_mapping.emplace(std::make_pair(net->name, new_die), new_signal); |
| 916 |
} else { |
| 917 |
uarch->global_mapping.emplace(std::make_pair(net->name, new_die), net); |
| 918 |
} |
| 919 |
} |
| 920 |
} |
| 921 |
} |
| 922 |
} |
| 923 |
|
| 924 |
static int clk_config_val(IdString name) |
| 925 |
{ |
| 926 |
switch (name.index) { |
| 927 |
case id_CLOCK1.index: |
| 928 |
return 0b00100011; |
| 929 |
case id_CLOCK2.index: |
| 930 |
return 0b00110011; |
| 931 |
case id_CLOCK3.index: |
| 932 |
return 0b00000011; |
| 933 |
case id_CLOCK4.index: |
| 934 |
return 0b00010011; |
| 935 |
} |
| 936 |
return 0; |
| 937 |
} |
| 938 |
|
| 939 |
static int ioclk_config_val(IdString name) |
| 940 |
{ |
| 941 |
switch (name.index) { |
| 942 |
case id_CLOCK1.index: |
| 943 |
return 0; |
| 944 |
case id_CLOCK2.index: |
| 945 |
return 1; |
| 946 |
case id_CLOCK3.index: |
| 947 |
return 2; |
| 948 |
case id_CLOCK4.index: |
| 949 |
return 3; |
| 950 |
} |
| 951 |
return 0; |
| 952 |
} |
| 953 |
|
| 954 |
void GateMatePacker::reassign_clocks() |
| 955 |
{ |
| 956 |
if (uarch->dies == 1) |
| 957 |
return; |
| 958 |
log_info("Reassign clocks..\n"); |
| 959 |
|
| 960 |
std::vector<std::vector<NetInfo *>> new_bufg(uarch->dies, std::vector<NetInfo *>(4)); |
| 961 |
|
| 962 |
for (auto &glob : uarch->global_signals) { |
| 963 |
const NetInfo *net = glob.first; |
| 964 |
auto users = net->users; // make a copy |
| 965 |
int count = 0; |
| 966 |
for (auto &user : users) { |
| 967 |
int cell_die = uarch->tile_extra_data(user.cell->bel.tile)->die; |
| 968 |
if (uarch->global_mapping.count(std::make_pair(net->name, cell_die))) { |
| 969 |
NetInfo *new_net = uarch->global_mapping.at(std::make_pair(net->name, cell_die)); |
| 970 |
if (uarch->ignore.count(user.cell->name)) |
| 971 |
continue; |
| 972 |
|
| 973 |
if (new_net == net) |
| 974 |
continue; |
| 975 |
|
| 976 |
user.cell->disconnectPort(user.port); |
| 977 |
|
| 978 |
if (user.port.in(id_CLOCK1, id_CLOCK2, id_CLOCK3, id_CLOCK4) && |
| 979 |
uarch->global_clk_mapping.count(std::make_pair(user.port, cell_die))) { |
| 980 |
IdString newPort = uarch->global_clk_mapping.at(std::make_pair(user.port, cell_die)); |
| 981 |
if (!user.cell->ports.count(newPort)) |
| 982 |
user.cell->addInput(newPort); |
| 983 |
user.cell->connectPort(newPort, new_net); |
| 984 |
|
| 985 |
if (user.cell->type == id_RAM) { |
| 986 |
int a0_clk = int_or_default(user.cell->params, id_RAM_cfg_forward_a0_clk, 0); |
| 987 |
int a1_clk = int_or_default(user.cell->params, id_RAM_cfg_forward_a1_clk, 0); |
| 988 |
int b0_clk = int_or_default(user.cell->params, id_RAM_cfg_forward_b0_clk, 0); |
| 989 |
int b1_clk = int_or_default(user.cell->params, id_RAM_cfg_forward_b1_clk, 0); |
| 990 |
|
| 991 |
if (a0_clk == clk_config_val(user.port)) |
| 992 |
user.cell->params[id_RAM_cfg_forward_a0_clk] = Property(clk_config_val(newPort), 8); |
| 993 |
if (a1_clk == clk_config_val(user.port)) |
| 994 |
user.cell->params[id_RAM_cfg_forward_a1_clk] = Property(clk_config_val(newPort), 8); |
| 995 |
if (b0_clk == clk_config_val(user.port)) |
| 996 |
user.cell->params[id_RAM_cfg_forward_b0_clk] = Property(clk_config_val(newPort), 8); |
| 997 |
if (b1_clk == clk_config_val(user.port)) |
| 998 |
user.cell->params[id_RAM_cfg_forward_b1_clk] = Property(clk_config_val(newPort), 8); |
| 999 |
} |
| 1000 |
if (user.cell->type == id_IOSEL) { |
| 1001 |
int in_clk = int_or_default(user.cell->params, id_IN_CLOCK, 0); |
| 1002 |
int out_clk = int_or_default(user.cell->params, id_OUT_CLOCK, 0); |
| 1003 |
if (in_clk == ioclk_config_val(user.port)) |
| 1004 |
user.cell->params[id_IN_CLOCK] = Property(ioclk_config_val(newPort), 2); |
| 1005 |
if (out_clk == ioclk_config_val(user.port)) |
| 1006 |
user.cell->params[id_OUT_CLOCK] = Property(ioclk_config_val(newPort), 2); |
| 1007 |
} |
| 1008 |
} else |
| 1009 |
user.cell->connectPort(user.port, new_net); |
| 1010 |
count++; |
| 1011 |
} else { |
| 1012 |
log_error("Global signal '%s' is not available in die %d.\n", net->name.c_str(ctx), cell_die); |
| 1013 |
} |
| 1014 |
} |
| 1015 |
if (count) |
| 1016 |
log_info(" reassign %d net '%s' users\n", count, net->name.c_str(ctx)); |
| 1017 |
} |
| 1018 |
flush_cells(); |
| 1019 |
} |
| 1020 |
|
| 1021 |
NEXTPNR_NAMESPACE_END |