Debian Codegraph @

himbaechel/uarch/xilinx/pack_io.cc

raw
1 /*
2 * nextpnr -- Next Generation Place and Route
3 *
4 * Copyright (C) 2019-23 Myrtle Shah <[email protected]>
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 <algorithm>
21 #include <boost/algorithm/string.hpp>
22 #include <queue>
23 #include <unordered_set>
24 #include "design_utils.h"
25 #include "extra_data.h"
26 #include "log.h"
27 #include "nextpnr.h"
28 #include "pack.h"
29 #include "pins.h"
30
31 #define HIMBAECHEL_CONSTIDS "uarch/xilinx/constids.inc"
32 #include "himbaechel_constids.h"
33
34 NEXTPNR_NAMESPACE_BEGIN
35
36 CellInfo *XilinxPacker::insert_obuf(IdString name, IdString type, NetInfo *i, NetInfo *o, NetInfo *tri)
37 {
38 auto obuf = create_cell(type, name);
39 obuf->connectPort(id_I, i);
40 obuf->connectPort(id_T, tri);
41 obuf->connectPort(id_O, o);
42 return obuf;
43 }
44
45 CellInfo *XilinxPacker::insert_outinv(IdString name, NetInfo *i, NetInfo *o)
46 {
47 auto inv = create_cell(id_INV, name);
48 inv->connectPort(id_I, i);
49 inv->connectPort(id_O, o);
50 return inv;
51 }
52
53 CellInfo *XC7Packer::insert_ibuf(IdString name, IdString type, NetInfo *i, NetInfo *o)
54 {
55 auto inbuf = create_cell(type, name);
56 inbuf->connectPort(id_I, i);
57 inbuf->connectPort(id_O, o);
58 return inbuf;
59 }
60
61 CellInfo *XC7Packer::insert_diffibuf(IdString name, IdString type, const std::array<NetInfo *, 2> &i, NetInfo *o)
62 {
63 auto inbuf = create_cell(type, name);
64 inbuf->connectPort(id_I, i[0]);
65 inbuf->connectPort(id_IB, i[1]);
66 inbuf->connectPort(id_O, o);
67 return inbuf;
68 }
69
70 NetInfo *XilinxPacker::invert_net(NetInfo *toinv)
71 {
72 if (toinv == nullptr)
73 return nullptr;
74 // If net is driven by an inverter, don't double-invert, which could cause problems with timing
75 // and IOLOGIC packing
76 if (toinv->driver.cell != nullptr && toinv->driver.cell->type == id_LUT1 &&
77 int_or_default(toinv->driver.cell->params, id_INIT, 0) == 1) {
78 NetInfo *preinv = toinv->driver.cell->getPort(id_I0);
79 // If only one user, also sweep the inversion LUT to avoid packing issues
80 if (toinv->users.entries() == 1) {
81 packed_cells.insert(toinv->driver.cell->name);
82 toinv->driver.cell->disconnectPort(id_I0);
83 toinv->driver.cell->disconnectPort(id_O);
84 }
85 return preinv;
86 } else {
87 NetInfo *inv = ctx->createNet(ctx->idf("%s$inverted%d", toinv->name.c_str(ctx), autoidx++));
88 create_lut(inv->name.str(ctx) + "$lut", {toinv}, inv, Property(1));
89 return inv;
90 }
91 }
92
93 std::pair<CellInfo *, PortRef> XilinxPacker::insert_pad_and_buf(CellInfo *npnr_io)
94 {
95 // Given a nextpnr IO buffer, create a PAD instance and insert an IO buffer if one isn't already present
96 std::pair<CellInfo *, PortRef> result;
97 std::unique_ptr<CellInfo> pad_cell = std::make_unique<CellInfo>(ctx, npnr_io->name, id_PAD);
98 pad_cell->addInout(id_PAD);
99 // Copy IO attributes to pad
100 for (auto &attr : npnr_io->attrs)
101 pad_cell->attrs[attr.first] = attr.second;
102 NetInfo *ionet = nullptr;
103 PortRef iobuf;
104 iobuf.cell = nullptr;
105 if (npnr_io->type == ctx->id("$nextpnr_obuf") || npnr_io->type == ctx->id("$nextpnr_iobuf")) {
106 ionet = npnr_io->getPort(id_I);
107 if (ionet != nullptr && ionet->driver.cell != nullptr)
108 if (toplevel_ports.count(ionet->driver.cell->type) &&
109 toplevel_ports.at(ionet->driver.cell->type).count(ionet->driver.port)) {
110 if (ionet->users.entries() > 1)
111 log_error("IO buffer '%s' is connected to more than a single top level IO pin.\n",
112 ionet->driver.cell->name.c_str(ctx));
113 iobuf = ionet->driver;
114 }
115 pad_cell->attrs[id_X_IO_DIR] = std::string(npnr_io->type == ctx->id("$nextpnr_obuf") ? "OUT" : "INOUT");
116 }
117 if (npnr_io->type == ctx->id("$nextpnr_ibuf") || npnr_io->type == ctx->id("$nextpnr_iobuf")) {
118 ionet = npnr_io->getPort(id_O);
119 if (ionet != nullptr)
120 for (auto &usr : ionet->users)
121 if (toplevel_ports.count(usr.cell->type) && toplevel_ports.at(usr.cell->type).count(usr.port)) {
122 if (ionet->users.entries() > 1)
123 log_error("IO buffer '%s' is connected to more than a single top level IO pin.\n",
124 usr.cell->name.c_str(ctx));
125 iobuf = usr;
126 }
127 pad_cell->attrs[id_X_IO_DIR] = std::string(npnr_io->type == ctx->id("$nextpnr_ibuf") ? "IN" : "INOUT");
128 }
129
130 if (!iobuf.cell) {
131 // No IO buffer, need to create one
132 log_error(
133 " IO port '%s' is missing an IO buffer, do you need to remove -noiopad from your Yosys arguments?\n",
134 npnr_io->name.c_str(ctx));
135 } else {
136 log_info(" IO port '%s' driven by %s '%s'\n", npnr_io->name.c_str(ctx), iobuf.cell->type.c_str(ctx),
137 iobuf.cell->name.c_str(ctx));
138 }
139
140 NPNR_ASSERT(ionet != nullptr);
141
142 for (auto &port : npnr_io->ports)
143 npnr_io->disconnectPort(port.first);
144
145 pad_cell->connectPort(id_PAD, ionet);
146 if (iobuf.cell->ports.at(iobuf.port).net != ionet) {
147 iobuf.cell->disconnectPort(iobuf.port);
148 iobuf.cell->connectPort(iobuf.port, ionet);
149 }
150
151 result.first = pad_cell.get();
152 result.second = iobuf;
153 // delete the npnr io and then add the pad, to avoid a name conflict
154 for (auto &port : npnr_io->ports) {
155 npnr_io->disconnectPort(port.first);
156 }
157 ctx->cells.erase(npnr_io->name);
158
159 ctx->cells[result.first->name] = std::move(pad_cell);
160
161 return result;
162 }
163
164 void XC7Packer::decompose_iob(CellInfo *xil_iob, bool is_hr, const std::string &iostandard)
165 {
166 bool is_se_ibuf = xil_iob->type.in(id_IBUF, id_IBUF_IBUFDISABLE, id_IBUF_INTERMDISABLE);
167 bool is_se_iobuf = xil_iob->type.in(id_IOBUF, id_IOBUF_DCIEN, id_IOBUF_INTERMDISABLE);
168 bool is_se_obuf = xil_iob->type.in(id_OBUF, id_OBUFT);
169
170 auto pad_site = [&](NetInfo *n) {
171 for (auto user : n->users)
172 if (user.cell->type == id_PAD)
173 return uarch->get_bel_site(ctx->getBelByNameStr(user.cell->attrs[id_BEL].as_string()));
174 NPNR_ASSERT_FALSE(("can't find PAD for net " + n->name.str(ctx)).c_str());
175 };
176
177 if (is_se_ibuf || is_se_iobuf) {
178 log_info("Generating input buffer for '%s'\n", xil_iob->name.c_str(ctx));
179 NetInfo *pad_net = xil_iob->getPort(is_se_iobuf ? id_IO : id_I);
180 NPNR_ASSERT(pad_net != nullptr);
181 auto site = pad_site(pad_net);
182 if (!is_se_iobuf)
183 xil_iob->disconnectPort(id_I);
184
185 NetInfo *top_out = xil_iob->getPort(id_O);
186 xil_iob->disconnectPort(id_O);
187
188 IdString ibuf_type = id_IBUF;
189 if (xil_iob->type.in(id_IBUF_IBUFDISABLE, id_IOBUF_DCIEN))
190 ibuf_type = id_IBUF_IBUFDISABLE;
191 if (xil_iob->type.in(id_IBUF_INTERMDISABLE, id_IOBUF_INTERMDISABLE))
192 ibuf_type = id_IBUF_INTERMDISABLE;
193
194 CellInfo *inbuf = insert_ibuf(int_name(xil_iob->name, "IBUF", is_se_iobuf), ibuf_type, pad_net, top_out);
195 std::string tile = ctx->get_tile_type(site.tile).str(ctx);
196 if (boost::starts_with(tile, "RIOB18"))
197 ctx->bindBel(uarch->get_site_bel(site, ctx->id("IOB18.INBUF_DCIEN")), inbuf, STRENGTH_LOCKED);
198 else
199 ctx->bindBel(uarch->get_site_bel(site, ctx->id("IOB33.INBUF_EN")), inbuf, STRENGTH_LOCKED);
200 xil_iob->movePortTo(id_IBUFDISABLE, inbuf, id_IBUFDISABLE);
201 xil_iob->movePortTo(id_INTERMDISABLE, inbuf, id_INTERMDISABLE);
202 }
203
204 if (is_se_obuf || is_se_iobuf) {
205 log_info("Generating output buffer for '%s'\n", xil_iob->name.c_str(ctx));
206 NetInfo *pad_net = xil_iob->getPort(is_se_iobuf ? id_IO : id_O);
207 NPNR_ASSERT(pad_net != nullptr);
208 auto site = pad_site(pad_net);
209 xil_iob->disconnectPort(is_se_iobuf ? id_IO : id_O);
210 bool has_dci = xil_iob->type == id_IOBUF_DCIEN;
211 CellInfo *obuf = insert_obuf(
212 int_name(xil_iob->name, (is_se_iobuf || xil_iob->type == id_OBUFT) ? "OBUFT" : "OBUF", !is_se_obuf),
213 is_se_iobuf ? (has_dci ? id_OBUFT_DCIEN : id_OBUFT) : xil_iob->type, xil_iob->getPort(id_I), pad_net,
214 xil_iob->getPort(id_T));
215 std::string tile = ctx->get_tile_type(site.tile).str(ctx);
216 if (boost::starts_with(tile, "RIOB18"))
217 ctx->bindBel(uarch->get_site_bel(site, ctx->id("IOB18.OUTBUF_DCIEN")), obuf, STRENGTH_LOCKED);
218 else
219 ctx->bindBel(uarch->get_site_bel(site, ctx->id("IOB33.OUTBUF")), obuf, STRENGTH_LOCKED);
220 xil_iob->movePortTo(id_DCITERMDISABLE, obuf, id_DCITERMDISABLE);
221 }
222
223 bool is_diff_ibuf = xil_iob->type.in(id_IBUFDS, id_IBUFDS_INTERMDISABLE, id_IBUFDS);
224 bool is_diff_iobuf = xil_iob->type.in(id_IOBUFDS, id_IOBUFDS_DCIEN);
225 bool is_diff_out_iobuf =
226 xil_iob->type.in(id_IOBUFDS_DIFF_OUT, id_IOBUFDS_DIFF_OUT_DCIEN, id_IOBUFDS_DIFF_OUT_INTERMDISABLE);
227 bool is_diff_obuf = xil_iob->type.in(id_OBUFDS, id_OBUFTDS);
228
229 if (is_diff_ibuf || is_diff_iobuf) {
230 NetInfo *pad_p_net = xil_iob->getPort((is_diff_iobuf || is_diff_out_iobuf) ? id_IO : id_I);
231 NPNR_ASSERT(pad_p_net != nullptr);
232 auto site_p = pad_site(pad_p_net);
233 NetInfo *pad_n_net = xil_iob->getPort((is_diff_iobuf || is_diff_out_iobuf) ? id_IOB : id_IB);
234 NPNR_ASSERT(pad_n_net != nullptr);
235 std::string tile_p = ctx->get_tile_type(site_p.tile).str(ctx);
236 bool is_riob18 = boost::starts_with(tile_p, "RIOB18");
237
238 if (!is_diff_iobuf && !is_diff_out_iobuf) {
239 xil_iob->disconnectPort(id_I);
240 xil_iob->disconnectPort(id_IB);
241 }
242
243 NetInfo *top_out = xil_iob->getPort(id_O);
244 xil_iob->disconnectPort(id_O);
245
246 IdString ibuf_type = id_IBUFDS;
247 CellInfo *inbuf = insert_diffibuf(int_name(xil_iob->name, "IBUF", is_se_iobuf), ibuf_type,
248 {pad_p_net, pad_n_net}, top_out);
249 if (is_riob18) {
250 ctx->bindBel(uarch->get_site_bel(site_p, ctx->id("IOB18M.INBUF_DCIEN")), inbuf, STRENGTH_LOCKED);
251 inbuf->attrs[id_X_IOB_SITE_TYPE] = std::string("IOB18M");
252 } else {
253 ctx->bindBel(uarch->get_site_bel(site_p, ctx->id("IOB33M.INBUF_EN")), inbuf, STRENGTH_LOCKED);
254 inbuf->attrs[id_X_IOB_SITE_TYPE] = std::string("IOB33M");
255 }
256 }
257
258 if (is_diff_obuf || is_diff_out_iobuf || is_diff_iobuf) {
259 // FIXME: true diff outputs
260 NetInfo *pad_p_net = xil_iob->getPort((is_diff_iobuf || is_diff_out_iobuf) ? id_IO : id_O);
261 NPNR_ASSERT(pad_p_net != nullptr);
262 auto site_p = pad_site(pad_p_net);
263 NetInfo *pad_n_net = xil_iob->getPort((is_diff_iobuf || is_diff_out_iobuf) ? id_IOB : id_OB);
264 NPNR_ASSERT(pad_n_net != nullptr);
265 auto site_n = pad_site(pad_n_net);
266 std::string tile_p = ctx->get_tile_type(site_p.tile).str(ctx);
267 bool is_riob18 = boost::starts_with(tile_p, "RIOB18");
268
269 xil_iob->disconnectPort((is_diff_iobuf || is_diff_out_iobuf) ? id_IO : id_O);
270 xil_iob->disconnectPort((is_diff_iobuf || is_diff_out_iobuf) ? id_IOB : id_OB);
271
272 NetInfo *inv_i = create_internal_net(xil_iob->name, is_diff_obuf ? "I_B" : "OBUFTDS$subnet$I_B");
273 CellInfo *inv = insert_outinv(int_name(xil_iob->name, is_diff_obuf ? "INV" : "OBUFTDS$subcell$INV"),
274 xil_iob->getPort(id_I), inv_i);
275 if (is_riob18) {
276 ctx->bindBel(uarch->get_site_bel(site_n, ctx->id("IOB18S.O_ININV")), inv, STRENGTH_LOCKED);
277 inv->attrs[id_X_IOB_SITE_TYPE] = std::string("IOB18S");
278 } else {
279 ctx->bindBel(uarch->get_site_bel(site_n, ctx->id("IOB33S.O_ININV")), inv, STRENGTH_LOCKED);
280 inv->attrs[id_X_IOB_SITE_TYPE] = std::string("IOB33S");
281 }
282
283 bool has_dci = xil_iob->type.in(id_IOBUFDS_DCIEN, id_IOBUFDSE3);
284
285 CellInfo *obuf_p = insert_obuf(int_name(xil_iob->name, is_diff_obuf ? "P" : "OBUFTDS$subcell$P"),
286 (is_diff_iobuf || is_diff_out_iobuf || (xil_iob->type == id_OBUFTDS))
287 ? (has_dci ? id_OBUFT_DCIEN : id_OBUFT)
288 : id_OBUF,
289 xil_iob->getPort(id_I), pad_p_net, xil_iob->getPort(id_T));
290
291 if (is_riob18) {
292 ctx->bindBel(uarch->get_site_bel(site_p, ctx->id("IOB18M.OUTBUF_DCIEN")), obuf_p, STRENGTH_LOCKED);
293 obuf_p->attrs[id_X_IOB_SITE_TYPE] = std::string("IOB18M");
294 } else {
295 ctx->bindBel(uarch->get_site_bel(site_p, ctx->id("IOB33M.OUTBUF")), obuf_p, STRENGTH_LOCKED);
296 obuf_p->attrs[id_X_IOB_SITE_TYPE] = std::string("IOB33M");
297 }
298 obuf_p->connectPort(id_DCITERMDISABLE, xil_iob->getPort(id_DCITERMDISABLE));
299
300 CellInfo *obuf_n = insert_obuf(int_name(xil_iob->name, is_diff_obuf ? "N" : "OBUFTDS$subcell$N"),
301 (is_diff_iobuf || is_diff_out_iobuf || (xil_iob->type == id_OBUFTDS))
302 ? (has_dci ? id_OBUFT_DCIEN : id_OBUFT)
303 : id_OBUF,
304 inv_i, pad_n_net, xil_iob->getPort(id_T));
305
306 if (is_riob18) {
307 ctx->bindBel(uarch->get_site_bel(site_n, ctx->id("IOB18S.OUTBUF_DCIEN")), obuf_n, STRENGTH_LOCKED);
308 obuf_n->attrs[id_X_IOB_SITE_TYPE] = std::string("IOB18S");
309 } else {
310 ctx->bindBel(uarch->get_site_bel(site_n, ctx->id("IOB33S.OUTBUF")), obuf_n, STRENGTH_LOCKED);
311 obuf_n->attrs[id_X_IOB_SITE_TYPE] = std::string("IOB33S");
312 }
313 obuf_n->connectPort(id_DCITERMDISABLE, xil_iob->getPort(id_DCITERMDISABLE));
314
315 xil_iob->disconnectPort(id_DCITERMDISABLE);
316 }
317 }
318
319 void XC7Packer::pack_io()
320 {
321 log_info("Inserting IO buffers..\n");
322
323 get_top_level_pins(ctx, toplevel_ports);
324 // Insert PAD cells on top level IO, and IO buffers where one doesn't exist already
325 std::vector<CellInfo *> npnr_io;
326 for (auto &cell : ctx->cells) {
327 CellInfo *ci = cell.second.get();
328 if (ci->type == ctx->id("$nextpnr_ibuf") || ci->type == ctx->id("$nextpnr_iobuf") ||
329 ci->type == ctx->id("$nextpnr_obuf"))
330 npnr_io.push_back(ci);
331 }
332 std::vector<std::pair<CellInfo *, PortRef>> pad_and_buf;
333 for (auto ci : npnr_io) {
334 pad_and_buf.push_back(insert_pad_and_buf(ci));
335 }
336 flush_cells();
337 pool<BelId> used_io_bels;
338 int unconstr_io_count = 0;
339 for (auto &iob : pad_and_buf) {
340 CellInfo *pad = iob.first;
341 // Process location constraints
342 if (pad->attrs.count(id_PACKAGE_PIN)) {
343 pad->attrs[id_LOC] = pad->attrs.at(id_PACKAGE_PIN);
344 }
345 if (pad->attrs.count(id_LOC)) {
346 std::string loc = pad->attrs.at(id_LOC).to_string();
347 BelId bel = ctx->get_package_pin_bel(ctx->id(loc));
348 if (bel == BelId())
349 log_error("Unable to constrain IO '%s', device does not have a pin named '%s'\n", pad->name.c_str(ctx),
350 loc.c_str());
351 log_info(" Constraining '%s' to pad '%s'\n", pad->name.c_str(ctx), ctx->nameOfBel(bel));
352 pad->attrs[id_BEL] = std::string(ctx->nameOfBel(bel));
353 }
354 if (pad->attrs.count(id_BEL)) {
355 used_io_bels.insert(ctx->getBelByNameStr(pad->attrs.at(id_BEL).as_string()));
356 } else {
357 ++unconstr_io_count;
358 }
359 }
360 // Constrain unconstrained IO
361 for (auto &iob : pad_and_buf) {
362 CellInfo *pad = iob.first;
363 if (!pad->attrs.count(id_BEL)) {
364 log_error("FIXME: unconstrained IO not supported (pad %s)\n", ctx->nameOf(pad));
365 ;
366 }
367 }
368 // Decompose macro IO primitives to smaller primitives that map logically to the actual IO Bels
369 for (auto &iob : pad_and_buf) {
370 if (packed_cells.count(iob.second.cell->name))
371 continue;
372 decompose_iob(iob.second.cell, true, str_or_default(iob.first->attrs, id_IOSTANDARD, ""));
373 packed_cells.insert(iob.second.cell->name);
374 }
375 flush_cells();
376
377 dict<IdString, XFormRule> hriobuf_rules, hpiobuf_rules;
378 hriobuf_rules[id_OBUF].new_type = id_IOB33_OUTBUF;
379 hriobuf_rules[id_OBUF].port_xform[id_I] = id_IN;
380 hriobuf_rules[id_OBUF].port_xform[id_O] = id_OUT;
381 hriobuf_rules[id_OBUF].port_xform[id_T] = id_TRI;
382 hriobuf_rules[id_OBUFT] = XFormRule(hriobuf_rules[id_OBUF]);
383
384 hriobuf_rules[id_IBUF].new_type = id_IOB33_INBUF_EN;
385 hriobuf_rules[id_IBUF].port_xform[id_I] = id_PAD;
386 hriobuf_rules[id_IBUF].port_xform[id_O] = id_OUT;
387 hriobuf_rules[id_IBUF_INTERMDISABLE] = XFormRule(hriobuf_rules[id_IBUF]);
388 hriobuf_rules[id_IBUF_IBUFDISABLE] = XFormRule(hriobuf_rules[id_IBUF]);
389 hriobuf_rules[id_IBUFDS_INTERMDISABLE_INT] = XFormRule(hriobuf_rules[id_IBUF]);
390 hriobuf_rules[id_IBUFDS_INTERMDISABLE_INT].port_xform[id_IB] = id_DIFFI_IN;
391 hriobuf_rules[id_IBUFDS] = XFormRule(hriobuf_rules[id_IBUF]);
392 hriobuf_rules[id_IBUFDS].port_xform[id_IB] = id_DIFFI_IN;
393
394 hpiobuf_rules[id_OBUF].new_type = id_IOB18_OUTBUF_DCIEN;
395 hpiobuf_rules[id_OBUF].port_xform[id_I] = id_IN;
396 hpiobuf_rules[id_OBUF].port_xform[id_O] = id_OUT;
397 hpiobuf_rules[id_OBUF].port_xform[id_T] = id_TRI;
398 hpiobuf_rules[id_OBUFT] = XFormRule(hpiobuf_rules[id_OBUF]);
399
400 hpiobuf_rules[id_IBUF].new_type = id_IOB18_INBUF_DCIEN;
401 hpiobuf_rules[id_IBUF].port_xform[id_I] = id_PAD;
402 hpiobuf_rules[id_IBUF].port_xform[id_O] = id_OUT;
403 hpiobuf_rules[id_IBUF_INTERMDISABLE] = XFormRule(hpiobuf_rules[id_IBUF]);
404 hpiobuf_rules[id_IBUF_IBUFDISABLE] = XFormRule(hpiobuf_rules[id_IBUF]);
405 hriobuf_rules[id_IBUFDS_INTERMDISABLE_INT] = XFormRule(hriobuf_rules[id_IBUF]);
406 hpiobuf_rules[id_IBUFDS_INTERMDISABLE_INT].port_xform[id_IB] = id_DIFFI_IN;
407 hpiobuf_rules[id_IBUFDS] = XFormRule(hpiobuf_rules[id_IBUF]);
408 hpiobuf_rules[id_IBUFDS].port_xform[id_IB] = id_DIFFI_IN;
409
410 // Special xform for OBUFx and IBUFx.
411 dict<IdString, XFormRule> rules;
412 for (auto &cell : ctx->cells) {
413 CellInfo *ci = cell.second.get();
414 if (!ci->attrs.count(id_BEL) && ci->bel == BelId())
415 continue;
416 std::string belname =
417 ci->attrs.count(id_BEL) ? ci->attrs[id_BEL].as_string() : std::string(ctx->nameOfBel(ci->bel));
418 size_t pos = belname.find(".");
419 if (belname.substr(pos + 1, 5) == "IOB18")
420 rules = hpiobuf_rules;
421 else if (belname.substr(pos + 1, 5) == "IOB33")
422 rules = hriobuf_rules;
423 else
424 log_error("Unexpected IOBUF BEL %s\n", belname.c_str());
425 if (rules.count(ci->type)) {
426 xform_cell(rules, ci);
427 }
428 }
429
430 dict<IdString, XFormRule> hrio_rules;
431 hrio_rules[id_PAD].new_type = id_PAD;
432
433 hrio_rules[id_INV].new_type = id_INVERTER;
434 hrio_rules[id_INV].port_xform[id_I] = id_IN;
435 hrio_rules[id_INV].port_xform[id_O] = id_OUT;
436
437 hrio_rules[id_PS7].new_type = id_PS7_PS7;
438
439 generic_xform(hrio_rules, true);
440
441 for (auto &cell : ctx->cells) {
442 CellInfo *ci = cell.second.get();
443 std::string type = ci->type.str(ctx);
444 if (!boost::starts_with(type, "IOB33") && !boost::starts_with(type, "IOB18"))
445 continue;
446 if (!ci->attrs.count(id_X_IOB_SITE_TYPE))
447 continue;
448 type.replace(0, 5, ci->attrs.at(id_X_IOB_SITE_TYPE).as_string());
449 ci->type = ctx->id(type);
450 }
451
452 // check all PAD cells for IOSTANDARD/DRIVE
453 for (auto &cell : ctx->cells) {
454 CellInfo *ci = cell.second.get();
455 std::string type = ci->type.str(ctx);
456 if (type != "PAD")
457 continue;
458 check_valid_pad(ci, type);
459 }
460 }
461
462 void XC7Packer::check_valid_pad(CellInfo *ci, std::string type)
463 {
464 auto iostandard_id = id_IOSTANDARD;
465 auto iostandard_attr = ci->attrs.find(iostandard_id);
466 if (iostandard_attr == ci->attrs.end())
467 log_error("port %s has no IOSTANDARD property", ci->name.c_str(ctx));
468
469 auto iostandard = iostandard_attr->second.as_string();
470 if (!boost::starts_with(iostandard, "LVTTL") && !boost::starts_with(iostandard, "LVCMOS"))
471 return;
472
473 auto drive_attr = ci->attrs.find(id_DRIVE);
474 // no drive strength attribute: use default
475 if (drive_attr == ci->attrs.end())
476 return;
477 auto drive = drive_attr->second.as_int64();
478
479 bool is_iob33 = boost::starts_with(type, "IOB33");
480 if (is_iob33) {
481 if (drive == 4 || drive == 8 || drive == 12)
482 return;
483 if (iostandard != "LVCMOS12" && drive == 16)
484 return;
485 if ((iostandard == "LVCMOS18" || iostandard == "LVTTL") && drive == 24)
486 return;
487 } else { // IOB18
488 if (drive == 2 || drive == 4 || drive == 6 || drive == 8)
489 return;
490 if (iostandard != "LVCMOS12" && (drive == 12 || drive == 16))
491 return;
492 }
493
494 log_error("unsupported DRIVE strength property %s for port %s", drive_attr->second.c_str(), ci->name.c_str(ctx));
495 }
496
497 SiteIndex XC7Packer::get_ologic_site(BelId io_bel)
498 {
499 BelId ibc_bel;
500 if (boost::contains(uarch->bel_name_in_site(io_bel).str(ctx), "IOB18"))
501 ibc_bel = uarch->get_site_bel(uarch->get_bel_site(io_bel), ctx->id("IOB18.OUTBUF_DCIEN"));
502 else
503 ibc_bel = uarch->get_site_bel(uarch->get_bel_site(io_bel), ctx->id("IOB33.OUTBUF"));
504 NPNR_ASSERT(ibc_bel != BelId());
505
506 std::queue<WireId> visit;
507 visit.push(ctx->getBelPinWire(ibc_bel, id_IN));
508
509 while (!visit.empty()) {
510 WireId cursor = visit.front();
511 visit.pop();
512 for (auto bp : ctx->getWireBelPins(cursor)) {
513 auto site = uarch->get_bel_site(bp.bel);
514 if (boost::starts_with(uarch->get_site_name(site).str(ctx), "OLOGIC"))
515 return site;
516 }
517 for (auto pip : ctx->getPipsUphill(cursor))
518 visit.push(ctx->getPipSrcWire(pip));
519 }
520 NPNR_ASSERT_FALSE("failed to find OLOGIC");
521 }
522
523 SiteIndex XC7Packer::get_ilogic_site(BelId io_bel)
524 {
525 BelId ibc_bel;
526 if (boost::contains(uarch->bel_name_in_site(io_bel).str(ctx), "IOB18"))
527 ibc_bel = uarch->get_site_bel(uarch->get_bel_site(io_bel), ctx->id("IOB18.INBUF_DCIEN"));
528 else
529 ibc_bel = uarch->get_site_bel(uarch->get_bel_site(io_bel), ctx->id("IOB33.INBUF_EN"));
530
531 NPNR_ASSERT(ibc_bel != BelId());
532
533 std::queue<WireId> visit;
534 visit.push(ctx->getBelPinWire(ibc_bel, id_OUT));
535
536 while (!visit.empty()) {
537 WireId cursor = visit.front();
538 visit.pop();
539 for (auto bp : ctx->getWireBelPins(cursor)) {
540 auto site = uarch->get_bel_site(bp.bel);
541 if (boost::starts_with(uarch->get_site_name(site).str(ctx), "ILOGIC"))
542 return site;
543 }
544 for (auto pip : ctx->getPipsDownhill(cursor))
545 visit.push(ctx->getPipDstWire(pip));
546 }
547 NPNR_ASSERT_FALSE("failed to find ILOGIC");
548 }
549
550 SiteIndex XC7Packer::get_idelay_site(BelId io_bel)
551 {
552 BelId ibc_bel;
553 if (boost::contains(uarch->bel_name_in_site(io_bel).str(ctx), "IOB18"))
554 ibc_bel = uarch->get_site_bel(uarch->get_bel_site(io_bel), ctx->id("IOB18.INBUF_DCIEN"));
555 else
556 ibc_bel = uarch->get_site_bel(uarch->get_bel_site(io_bel), ctx->id("IOB33.INBUF_EN"));
557
558 NPNR_ASSERT(ibc_bel != BelId());
559
560 std::queue<WireId> visit;
561 visit.push(ctx->getBelPinWire(ibc_bel, id_OUT));
562
563 while (!visit.empty()) {
564 WireId cursor = visit.front();
565 visit.pop();
566 for (auto bp : ctx->getWireBelPins(cursor)) {
567 auto site = uarch->get_bel_site(bp.bel);
568 if (boost::starts_with(uarch->get_site_name(site).str(ctx), "IDELAY"))
569 return site;
570 }
571 for (auto pip : ctx->getPipsDownhill(cursor))
572 visit.push(ctx->getPipDstWire(pip));
573 }
574 NPNR_ASSERT_FALSE("failed to find IDELAY");
575 }
576
577 SiteIndex XC7Packer::get_odelay_site(BelId io_bel)
578 {
579 BelId obc_bel;
580 if (boost::contains(uarch->bel_name_in_site(io_bel).str(ctx), "IOB18"))
581 obc_bel = uarch->get_site_bel(uarch->get_bel_site(io_bel), ctx->id("IOB18.OUTBUF_DCIEN"));
582 else
583 log_error("BEL %s is located on a high range bank. High range banks do not have ODELAY\n",
584 ctx->nameOfBel(io_bel));
585
586 std::queue<WireId> visit;
587 visit.push(ctx->getBelPinWire(obc_bel, id_IN));
588
589 while (!visit.empty()) {
590 WireId cursor = visit.front();
591 visit.pop();
592 for (auto bp : ctx->getWireBelPins(cursor)) {
593 auto site = uarch->get_bel_site(bp.bel);
594 if (boost::starts_with(uarch->get_site_name(site).str(ctx), "ODELAY"))
595 return site;
596 }
597 for (auto pip : ctx->getPipsUphill(cursor))
598 visit.push(ctx->getPipSrcWire(pip));
599 }
600 NPNR_ASSERT_FALSE("failed to find ODELAY");
601 }
602
603 SiteIndex XC7Packer::get_ioctrl_site(BelId io_bel)
604 {
605 int hclk_tile = uarch->hclk_for_iob(io_bel);
606 const auto &extra_data = uarch->tile_extra_data(hclk_tile);
607
608 for (int site = 0; site < extra_data->sites.ssize(); site++) {
609 auto &site_data = extra_data->sites[site];
610 if (boost::starts_with(IdString(site_data.name_prefix).str(ctx), "IDELAYCTRL"))
611 return SiteIndex(hclk_tile, site);
612 }
613
614 NPNR_ASSERT_FALSE("failed to find IOCTRL");
615 }
616
617 void XC7Packer::fold_inverter(CellInfo *cell, std::string port)
618 {
619 IdString p = ctx->id(port);
620 NetInfo *net = cell->getPort(p);
621 if (!net)
622 return;
623 CellInfo *drv = net->driver.cell;
624 if (!drv)
625 return;
626 if (drv->type == id_LUT1 && int_or_default(drv->params, id_INIT, 0) == 1) {
627 cell->disconnectPort(p);
628 NetInfo *preinv = drv->getPort(id_I0);
629 cell->connectPort(p, preinv);
630 cell->params[ctx->idf("IS_%s_INVERTED", port.c_str())] = 1;
631 if (net->users.empty())
632 packed_cells.insert(drv->name);
633 } else if (drv->type == id_INV) {
634 cell->disconnectPort(p);
635 NetInfo *preinv = drv->getPort(id_I);
636 cell->connectPort(p, preinv);
637 cell->params[ctx->idf("IS_%s_INVERTED", port.c_str())] = 1;
638 if (net->users.empty())
639 packed_cells.insert(drv->name);
640 }
641 }
642
643 void XC7Packer::pack_iologic()
644 {
645 log_info("Packing IOLOGIC...\n");
646 dict<IdString, BelId> iodelay_to_io;
647 dict<IdString, XFormRule> iologic_rules;
648
649 // IDDR
650 iologic_rules[id_IDDR].new_type = id_ILOGICE3_IFF;
651 iologic_rules[id_IDDR].port_multixform[id_C] = {id_CK, id_CKB};
652 iologic_rules[id_IDDR].port_xform[id_S] = id_SR;
653 iologic_rules[id_IDDR].port_xform[id_R] = id_SR;
654
655 // SERDES
656 iologic_rules[id_ISERDESE2].new_type = id_ISERDESE2_ISERDESE2;
657 iologic_rules[id_OSERDESE2].new_type = id_OSERDESE2_OSERDESE2;
658
659 // DELAY
660 iologic_rules[id_IDELAYE2].new_type = id_IDELAYE2_IDELAYE2;
661 iologic_rules[id_ODELAYE2].new_type = id_ODELAYE2_ODELAYE2;
662
663 // Handles pseudo-diff output buffers without finding multiple sinks
664 auto find_p_outbuf = [&](NetInfo *net) {
665 CellInfo *outbuf = nullptr;
666 for (auto &usr : net->users) {
667 IdString type = usr.cell->type;
668 if (type.in(id_IOB33_OUTBUF, id_IOB33M_OUTBUF, id_IOB18_OUTBUF_DCIEN, id_IOB18M_OUTBUF_DCIEN)) {
669 if (outbuf != nullptr)
670 return (CellInfo *)nullptr; // drives multiple outputs
671 outbuf = usr.cell;
672 } else if (type == id_ODELAYE2) {
673 auto dataout = usr.cell->ports.find(id_DATAOUT);
674 if (dataout != usr.cell->ports.end()) {
675 for (auto &user : dataout->second.net->users) {
676 IdString dataout_type = user.cell->type;
677 if (dataout_type.in(id_IOB18_OUTBUF_DCIEN, id_IOB18M_OUTBUF_DCIEN)) {
678 if (outbuf != nullptr)
679 return (CellInfo *)nullptr; // drives multiple outputs
680 outbuf = user.cell;
681 }
682 }
683 } else {
684 if (outbuf != nullptr)
685 return (CellInfo *)nullptr; // drives multiple outputs
686 }
687 }
688 }
689 return outbuf;
690 };
691
692 for (auto &cell : ctx->cells) {
693 CellInfo *ci = cell.second.get();
694 if (ci->type == id_IDELAYE2) {
695 NetInfo *d = ci->getPort(id_IDATAIN);
696 if (!d || !d->driver.cell)
697 log_error("%s '%s' has disconnected IDATAIN input\n", ci->type.c_str(ctx), ctx->nameOf(ci));
698 CellInfo *drv = d->driver.cell;
699 BelId io_bel;
700 if (boost::contains(drv->type.str(ctx), "INBUF_EN") || boost::contains(drv->type.str(ctx), "INBUF_DCIEN"))
701 io_bel = drv->bel;
702 else
703 log_error("%s '%s' has IDATAIN input connected to illegal cell type %s\n", ci->type.c_str(ctx),
704 ctx->nameOf(ci), drv->type.c_str(ctx));
705 SiteIndex iol_site = get_idelay_site(io_bel);
706
707 BelId idelay_bel = uarch->get_site_bel(iol_site, id_IDELAYE2);
708 NPNR_ASSERT(idelay_bel != BelId());
709 log_info(" binding input delay cell '%s' to bel '%s'\n", ctx->nameOf(ci), ctx->nameOfBel(idelay_bel));
710 ctx->bindBel(idelay_bel, ci, STRENGTH_LOCKED);
711
712 ci->attrs[id_X_IO_BEL] = ctx->getBelName(io_bel).str(ctx);
713 iodelay_to_io[ci->name] = io_bel;
714 } else if (ci->type == id_ODELAYE2) {
715 NetInfo *dataout = ci->getPort(id_DATAOUT);
716 if (!dataout || dataout->users.empty())
717 log_error("%s '%s' has disconnected DATAOUT input\n", ci->type.c_str(ctx), ctx->nameOf(ci));
718 BelId io_bel;
719 auto no_users = dataout->users.entries();
720 for (auto userport : dataout->users) {
721 CellInfo *user = userport.cell;
722 auto user_type = user->type.str(ctx);
723 // OBUFDS has the negative pin connected to an inverter
724 if (no_users == 2 && user_type == "INVERTER")
725 continue;
726 if (boost::contains(user_type, "OUTBUF_EN") || boost::contains(user_type, "OUTBUF_DCIEN"))
727 io_bel = user->bel;
728 else
729 // TODO: support SIGNAL_PATTERN = CLOCK
730 log_error("%s '%s' has DATAOUT connected to unsupported cell type %s\n", ci->type.c_str(ctx),
731 ctx->nameOf(ci), user_type.c_str());
732 }
733 SiteIndex iol_site = get_odelay_site(io_bel);
734
735 BelId odelay_bel = uarch->get_site_bel(iol_site, id_ODELAYE2);
736 NPNR_ASSERT(odelay_bel != BelId());
737 log_info(" binding output delay cell '%s' to bel '%s'\n", ctx->nameOf(ci), ctx->nameOfBel(odelay_bel));
738 ctx->bindBel(odelay_bel, ci, STRENGTH_LOCKED);
739
740 ci->attrs[id_X_IO_BEL] = ctx->getBelName(io_bel).str(ctx);
741 iodelay_to_io[ci->name] = io_bel;
742 }
743 }
744
745 for (auto &cell : ctx->cells) {
746 CellInfo *ci = cell.second.get();
747 if (ci->type == id_ODDR) {
748 NetInfo *q = ci->getPort(id_Q);
749 if (q == nullptr || q->users.empty())
750 log_error("%s '%s' has disconnected Q output\n", ci->type.c_str(ctx), ctx->nameOf(ci));
751 BelId io_bel;
752 CellInfo *ob = find_p_outbuf(q);
753 if (ob != nullptr)
754 io_bel = ob->bel;
755 else
756 log_error("%s '%s' has illegal fanout on Q output\n", ci->type.c_str(ctx), ctx->nameOf(ci));
757 SiteIndex ol_site = get_ologic_site(io_bel);
758
759 PortRef dest_port = *q->users.begin();
760 auto is_tristate = dest_port.port == id_TRI;
761
762 dict<IdString, XFormRule> oddr_rules;
763 if (boost::contains(uarch->get_site_name(ol_site).str(ctx), "IOB18"))
764 oddr_rules[id_ODDR].new_type = is_tristate ? id_OLOGICE2_TFF : id_OLOGICE2_OUTFF;
765 else
766 oddr_rules[id_ODDR].new_type = is_tristate ? id_OLOGICE3_TFF : id_OLOGICE3_OUTFF;
767 oddr_rules[id_ODDR].port_xform[id_C] = id_CK;
768 oddr_rules[id_ODDR].port_xform[id_S] = id_SR;
769 oddr_rules[id_ODDR].port_xform[id_R] = id_SR;
770 xform_cell(oddr_rules, ci);
771
772 BelId oddr_bel = uarch->get_site_bel(ol_site, is_tristate ? ctx->id("TFF") : ctx->id("OUTFF"));
773 NPNR_ASSERT(oddr_bel != BelId());
774 log_info(" binding output DDR cell '%s' to bel '%s'\n", ctx->nameOf(ci), ctx->nameOfBel(oddr_bel));
775 ctx->bindBel(oddr_bel, ci, STRENGTH_LOCKED);
776 } else if (ci->type == id_OSERDESE2) {
777
778 NetInfo *shiftin1 = ci->getPort(id_SHIFTIN1), *shiftin2 = ci->getPort(id_SHIFTIN2),
779 *tbytein = ci->getPort(id_TBYTEIN);
780
781 // If connected to ground (i.e. unused) this can't actually be routed so remove it
782 if (shiftin1 && shiftin1->name == ctx->id("$PACKER_GND_NET")) {
783 ci->disconnectPort(id_SHIFTIN1);
784 shiftin1 = nullptr;
785 }
786 if (shiftin2 && shiftin2->name == ctx->id("$PACKER_GND_NET")) {
787 ci->disconnectPort(id_SHIFTIN2);
788 shiftin2 = nullptr;
789 }
790 if (tbytein && tbytein->name == ctx->id("$PACKER_GND_NET")) {
791 ci->disconnectPort(id_TBYTEIN);
792 tbytein = nullptr;
793 }
794
795 auto serdes_mode = str_or_default(ci->params, id_SERDES_MODE, "MASTER");
796
797 if (serdes_mode == "MASTER") {
798 NetInfo *q = ci->getPort(id_OQ);
799 NetInfo *ofb = ci->getPort(id_OFB);
800 bool q_disconnected = !q || q->users.empty();
801 bool ofb_disconnected = !ofb || ofb->users.empty();
802 if (q_disconnected && ofb_disconnected) {
803 log_error("%s '%s' has disconnected OQ/OFB output ports\n", ci->type.c_str(ctx), ctx->nameOf(ci));
804 }
805 BelId io_bel;
806 CellInfo *ob = !q_disconnected ? find_p_outbuf(q) : find_p_outbuf(ofb);
807 if (ob != nullptr)
808 io_bel = ob->bel;
809 else
810 log_error("%s '%s' has illegal fanout on OQ or OFB output\n", ci->type.c_str(ctx), ctx->nameOf(ci));
811
812 SiteIndex ol_site = get_ologic_site(io_bel);
813
814 BelId oserdes_bel = uarch->get_site_bel(ol_site, id_OSERDESE2);
815 NPNR_ASSERT(oserdes_bel != BelId());
816 log_info(" binding output SERDES cell '%s' to bel '%s'\n", ctx->nameOf(ci),
817 ctx->nameOfBel(oserdes_bel));
818 ctx->bindBel(oserdes_bel, ci, STRENGTH_LOCKED);
819
820 if (shiftin1 != nullptr || shiftin2 != nullptr) {
821 CellInfo *cascaded_cell = shiftin1 ? shiftin1->driver.cell : shiftin2->driver.cell;
822 if (!cascaded_cell || !cascaded_cell->type.in(id_OSERDESE2))
823 log_error("OSERDESE2 cell '%s' has SHIFTIN driven by illegal cell '%s'\n", ctx->nameOf(ci),
824 cascaded_cell ? ctx->nameOf(cascaded_cell) : "");
825
826 // cascaded location is one below master, so place the cascaded cell there
827 SiteIndex cascade_site = uarch->rel_site(ol_site, 0, -1);
828 NPNR_ASSERT(cascade_site != SiteIndex());
829 BelId cascade_bel = uarch->get_site_bel(cascade_site, id_OSERDESE2);
830 NPNR_ASSERT(cascade_bel != BelId());
831 log_info(" binding cascaded output SERDES cell '%s' to bel '%s'\n", ctx->nameOf(cascaded_cell),
832 ctx->nameOfBel(cascade_bel));
833 ctx->bindBel(cascade_bel, cascaded_cell, STRENGTH_LOCKED);
834 }
835
836 } else if (serdes_mode == "SLAVE") {
837
838 NetInfo *shiftout1 = ci->getPort(id_SHIFTOUT1);
839 NetInfo *shiftout2 = ci->getPort(id_SHIFTOUT2);
840 if (!shiftout1 && !shiftout2)
841 log_error("OSERDESE2 cell '%s' with SERDES_MODE SLAVE must have SHIFTOUT1/2 connected.\n",
842 ctx->nameOf(ci));
843 for (auto net : {shiftout1, shiftout2}) {
844 if (!net)
845 continue;
846 if (net->users.entries() != 1)
847 log_error(
848 "OSERDESE2 cell '%s' with SERDES_MODE SLAVE has multiple fanout on SHIFTOUT net '%s'\n",
849 ctx->nameOf(ci), ctx->nameOf(net));
850 auto usr = *(net->users.begin());
851 if (usr.cell->type != id_OSERDESE2 || !usr.port.in(id_SHIFTIN1, id_SHIFTIN2))
852 log_error("OSERDESE2 cell '%s' has SHIFTOUT driving illegal cell port '%s.%s'\n",
853 ctx->nameOf(ci), ctx->nameOf(usr.cell), ctx->nameOf(usr.port));
854 }
855 } else {
856 log_error("OSERDESE2 cell '%s' has unsupported SERDES_MODE '%s'\n", ctx->nameOf(ci),
857 serdes_mode.c_str());
858 }
859
860 } else if (ci->type == id_IDDR) {
861 fold_inverter(ci, "C");
862
863 BelId io_bel;
864 NetInfo *d = ci->getPort(id_D);
865 if (!d || !d->driver.cell)
866 log_error("%s '%s' has disconnected D input\n", ci->type.c_str(ctx), ctx->nameOf(ci));
867 CellInfo *drv = d->driver.cell;
868 if (boost::contains(drv->type.str(ctx), "INBUF_EN") || boost::contains(drv->type.str(ctx), "INBUF_DCIEN"))
869 io_bel = drv->bel;
870 else if (boost::contains(drv->type.str(ctx), "IDELAYE2") && d->driver.port == id_DATAOUT)
871 io_bel = iodelay_to_io.at(drv->name);
872 else
873 log_error("%s '%s' has D input connected to illegal cell type %s\n", ci->type.c_str(ctx),
874 ctx->nameOf(ci), drv->type.c_str(ctx));
875
876 SiteIndex il_site = get_ilogic_site(io_bel);
877
878 BelId iddr_bel = uarch->get_site_bel(il_site, ctx->id("IFF"));
879 NPNR_ASSERT(iddr_bel != BelId());
880 log_info(" binding input DDR cell '%s' to bel '%s'\n", ctx->nameOf(ci), ctx->nameOfBel(iddr_bel));
881 ctx->bindBel(iddr_bel, ci, STRENGTH_LOCKED);
882 } else if (ci->type == id_ISERDESE2) {
883 fold_inverter(ci, "CLKB");
884 fold_inverter(ci, "OCLKB");
885
886 std::string iobdelay = str_or_default(ci->params, id_IOBDELAY, "NONE");
887 BelId io_bel;
888
889 if (iobdelay == "IFD") {
890 NetInfo *d = ci->getPort(id_DDLY);
891 if (!d || !d->driver.cell)
892 log_error("%s '%s' has disconnected DDLY input\n", ci->type.c_str(ctx), ctx->nameOf(ci));
893 CellInfo *drv = d->driver.cell;
894 if (boost::contains(drv->type.str(ctx), "IDELAYE2") && d->driver.port == id_DATAOUT)
895 io_bel = iodelay_to_io.at(drv->name);
896 else
897 log_error("%s '%s' has DDLY input connected to illegal cell type %s\n", ci->type.c_str(ctx),
898 ctx->nameOf(ci), drv->type.c_str(ctx));
899 } else if (iobdelay == "NONE") {
900 NetInfo *d = ci->getPort(id_D);
901 if (!d || !d->driver.cell)
902 log_error("%s '%s' has disconnected D input\n", ci->type.c_str(ctx), ctx->nameOf(ci));
903 CellInfo *drv = d->driver.cell;
904 if (boost::contains(drv->type.str(ctx), "INBUF_EN") ||
905 boost::contains(drv->type.str(ctx), "INBUF_DCIEN"))
906 io_bel = drv->bel;
907 else
908 log_error("%s '%s' has D input connected to illegal cell type %s\n", ci->type.c_str(ctx),
909 ctx->nameOf(ci), drv->type.c_str(ctx));
910 } else {
911 log_error("%s '%s' has unsupported IOBDELAY value '%s'\n", ci->type.c_str(ctx), ctx->nameOf(ci),
912 iobdelay.c_str());
913 }
914
915 SiteIndex il_site = get_ilogic_site(io_bel);
916
917 BelId iserdes_bel = uarch->get_site_bel(il_site, id_ISERDESE2);
918 NPNR_ASSERT(iserdes_bel != BelId());
919 log_info(" binding input SERDES cell '%s' to bel '%s'\n", ctx->nameOf(ci), ctx->nameOfBel(iserdes_bel));
920 ctx->bindBel(iserdes_bel, ci, STRENGTH_LOCKED);
921 }
922 }
923
924 flush_cells();
925 generic_xform(iologic_rules, false);
926 flush_cells();
927 }
928
929 void XC7Packer::pack_idelayctrl()
930 {
931 CellInfo *idelayctrl = nullptr;
932 for (auto &cell : ctx->cells) {
933 CellInfo *ci = cell.second.get();
934 if (ci->type == id_IDELAYCTRL) {
935 if (idelayctrl)
936 log_error("Found more than one IDELAYCTRL cell!\n");
937 idelayctrl = ci;
938 }
939 }
940 if (!idelayctrl)
941 return;
942 std::set<SiteIndex> ioctrl_sites;
943 for (auto &cell : ctx->cells) {
944 CellInfo *ci = cell.second.get();
945 if (ci->type.in(id_IDELAYE2_IDELAYE2, id_ODELAYE2_ODELAYE2)) {
946 if (ci->bel == BelId())
947 continue;
948 ioctrl_sites.insert(get_ioctrl_site(ctx->getBelByNameStr(ci->attrs.at(id_X_IO_BEL).as_string())));
949 }
950 }
951 if (ioctrl_sites.empty())
952 log_error("Found IDELAYCTRL but no I/ODELAYs\n");
953 NetInfo *rdy = idelayctrl->getPort(id_RDY);
954 idelayctrl->disconnectPort(id_RDY);
955 std::vector<NetInfo *> dup_rdys;
956 int i = 0;
957 for (auto site : ioctrl_sites) {
958 CellInfo *dup_idc =
959 create_cell(id_IDELAYCTRL, int_name(idelayctrl->name, "CTRL_DUP_" + std::to_string(i), false));
960 dup_idc->connectPort(id_REFCLK, idelayctrl->getPort(id_REFCLK));
961 dup_idc->connectPort(id_RST, idelayctrl->getPort(id_RST));
962 if (rdy) {
963 NetInfo *dup_rdy =
964 (ioctrl_sites.size() == 1)
965 ? rdy
966 : create_internal_net(idelayctrl->name, "CTRL_DUP_" + std::to_string(i) + "_RDY", false);
967 dup_idc->connectPort(id_RDY, dup_rdy);
968 dup_rdys.push_back(dup_rdy);
969 }
970 BelId idc_bel = uarch->get_site_bel(site, id_IDELAYCTRL);
971 NPNR_ASSERT(idc_bel != BelId());
972 ctx->bindBel(idc_bel, dup_idc, STRENGTH_LOCKED);
973 ++i;
974 }
975 idelayctrl->disconnectPort(id_REFCLK);
976 idelayctrl->disconnectPort(id_RST);
977
978 if (rdy != nullptr) {
979 // AND together all the RDY signals
980 std::vector<NetInfo *> int_anded_rdy;
981 int_anded_rdy.push_back(dup_rdys.front());
982 for (size_t j = 1; j < dup_rdys.size(); j++) {
983 NetInfo *anded_net =
984 (j == (dup_rdys.size() - 1))
985 ? rdy
986 : create_internal_net(idelayctrl->name, "ANDED_RDY_" + std::to_string(j), false);
987 create_lut(idelayctrl->name.str(ctx) + "/RDY_AND_LUT_" + std::to_string(j),
988 {int_anded_rdy.at(j - 1), dup_rdys.at(j)}, anded_net, Property(8));
989 int_anded_rdy.push_back(anded_net);
990 }
991 }
992
993 packed_cells.insert(idelayctrl->name);
994 flush_cells();
995
996 ioctrl_rules[id_IDELAYCTRL].new_type = id_IDELAYCTRL_IDELAYCTRL;
997
998 generic_xform(ioctrl_rules);
999 }
1000
1001 NEXTPNR_NAMESPACE_END