2018-06-12 19:40:22 +08:00
|
|
|
/*
|
|
|
|
* nextpnr -- Next Generation Place and Route
|
|
|
|
*
|
2021-06-09 20:09:08 +08:00
|
|
|
* Copyright (C) 2018 Claire Xenia Wolf <claire@yosyshq.com>
|
|
|
|
* Copyright (C) 2018 gatecat <gatecat@ds0.me>
|
|
|
|
* Copyright (C) 2018 Serge Bazanski <q3k@q3k.org>
|
2018-06-12 19:40:22 +08:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-06-13 23:07:42 +08:00
|
|
|
#include "cells.h"
|
2018-06-25 17:43:59 +08:00
|
|
|
#include "nextpnr.h"
|
2018-06-17 17:14:49 +08:00
|
|
|
#include "util.h"
|
2018-06-12 19:40:22 +08:00
|
|
|
|
2018-08-11 10:50:27 +08:00
|
|
|
#include <boost/range/iterator_range.hpp>
|
|
|
|
|
2018-06-12 20:31:26 +08:00
|
|
|
NEXTPNR_NAMESPACE_BEGIN
|
|
|
|
|
2021-02-03 18:21:45 +08:00
|
|
|
bool Arch::logic_cells_compatible(const CellInfo **it, const size_t size) const
|
2018-06-12 19:40:22 +08:00
|
|
|
{
|
|
|
|
bool dffs_exist = false, dffs_neg = false;
|
|
|
|
const NetInfo *cen = nullptr, *clk = nullptr, *sr = nullptr;
|
2018-06-19 19:35:01 +08:00
|
|
|
int locals_count = 0;
|
2018-06-12 19:40:22 +08:00
|
|
|
|
2018-09-30 22:13:18 +08:00
|
|
|
for (auto cell : boost::make_iterator_range(it, it + size)) {
|
2018-09-24 21:27:50 +08:00
|
|
|
NPNR_ASSERT(cell->type == id_ICESTORM_LC);
|
2018-07-18 18:51:07 +08:00
|
|
|
if (cell->lcInfo.dffEnable) {
|
2018-06-12 19:40:22 +08:00
|
|
|
if (!dffs_exist) {
|
|
|
|
dffs_exist = true;
|
2018-07-18 18:51:07 +08:00
|
|
|
cen = cell->lcInfo.cen;
|
|
|
|
clk = cell->lcInfo.clk;
|
|
|
|
sr = cell->lcInfo.sr;
|
2018-06-12 19:40:22 +08:00
|
|
|
|
2018-07-18 18:51:07 +08:00
|
|
|
if (cen != nullptr && !cen->is_global)
|
2018-06-19 19:35:01 +08:00
|
|
|
locals_count++;
|
2018-07-18 18:51:07 +08:00
|
|
|
if (clk != nullptr && !clk->is_global)
|
2018-06-19 19:35:01 +08:00
|
|
|
locals_count++;
|
2018-07-18 18:51:07 +08:00
|
|
|
if (sr != nullptr && !sr->is_global)
|
2018-06-19 19:35:01 +08:00
|
|
|
locals_count++;
|
2018-06-12 19:40:22 +08:00
|
|
|
|
2018-07-18 18:51:07 +08:00
|
|
|
if (cell->lcInfo.negClk) {
|
2018-06-12 19:40:22 +08:00
|
|
|
dffs_neg = true;
|
|
|
|
}
|
|
|
|
} else {
|
2018-07-18 18:51:07 +08:00
|
|
|
if (cen != cell->lcInfo.cen)
|
2018-06-12 19:40:22 +08:00
|
|
|
return false;
|
2018-07-18 18:51:07 +08:00
|
|
|
if (clk != cell->lcInfo.clk)
|
2018-06-12 19:40:22 +08:00
|
|
|
return false;
|
2018-07-18 18:51:07 +08:00
|
|
|
if (sr != cell->lcInfo.sr)
|
2018-06-12 19:40:22 +08:00
|
|
|
return false;
|
2018-07-18 18:51:07 +08:00
|
|
|
if (dffs_neg != cell->lcInfo.negClk)
|
2018-06-12 19:40:22 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-18 18:51:07 +08:00
|
|
|
locals_count += cell->lcInfo.inputCount;
|
2018-06-12 19:40:22 +08:00
|
|
|
}
|
|
|
|
|
2018-06-19 19:35:01 +08:00
|
|
|
return locals_count <= 32;
|
2018-06-12 19:40:22 +08:00
|
|
|
}
|
|
|
|
|
2019-04-17 20:07:38 +08:00
|
|
|
static inline bool _io_pintype_need_clk_in(unsigned pin_type) { return (pin_type & 0x01) == 0x00; }
|
|
|
|
|
|
|
|
static inline bool _io_pintype_need_clk_out(unsigned pin_type)
|
|
|
|
{
|
|
|
|
return ((pin_type & 0x30) == 0x30) || ((pin_type & 0x3c) && ((pin_type & 0x0c) != 0x08));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool _io_pintype_need_clk_en(unsigned pin_type)
|
|
|
|
{
|
|
|
|
return _io_pintype_need_clk_in(pin_type) || _io_pintype_need_clk_out(pin_type);
|
|
|
|
}
|
|
|
|
|
2022-12-07 17:27:58 +08:00
|
|
|
bool Arch::isBelLocationValid(BelId bel, bool explain_invalid) const
|
2018-06-12 19:40:22 +08:00
|
|
|
{
|
2021-02-16 19:52:16 +08:00
|
|
|
if (getBelType(bel) == id_ICESTORM_LC) {
|
2018-08-11 10:50:27 +08:00
|
|
|
std::array<const CellInfo *, 8> bel_cells;
|
|
|
|
size_t num_cells = 0;
|
2018-07-24 21:52:56 +08:00
|
|
|
Loc bel_loc = getBelLocation(bel);
|
|
|
|
for (auto bel_other : getBelsByTile(bel_loc.x, bel_loc.y)) {
|
2018-08-05 21:25:42 +08:00
|
|
|
CellInfo *ci_other = getBoundBelCell(bel_other);
|
2021-02-16 19:52:16 +08:00
|
|
|
if (ci_other != nullptr)
|
2018-08-11 10:50:27 +08:00
|
|
|
bel_cells[num_cells++] = ci_other;
|
2018-06-12 19:40:22 +08:00
|
|
|
}
|
2021-02-03 18:21:45 +08:00
|
|
|
return logic_cells_compatible(bel_cells.data(), num_cells);
|
2021-02-16 19:52:16 +08:00
|
|
|
} else {
|
2022-06-25 22:56:16 +08:00
|
|
|
const CellInfo *cell = getBoundBelCell(bel);
|
2021-02-16 19:52:16 +08:00
|
|
|
if (cell == nullptr)
|
|
|
|
return true;
|
|
|
|
else if (cell->type == id_SB_IO) {
|
|
|
|
// Do not allow placement of input SB_IOs on blocks where there a PLL is outputting to.
|
|
|
|
|
|
|
|
// Find shared PLL by looking for driving bel siblings from D_IN_0
|
|
|
|
// that are a PLL clock output.
|
|
|
|
auto wire = getBelPinWire(bel, id_D_IN_0);
|
|
|
|
for (auto pin : getWireBelPins(wire)) {
|
2022-08-11 01:58:22 +08:00
|
|
|
if (pin.pin.in(id_PLLOUT_A, id_PLLOUT_B)) {
|
2021-02-16 19:52:16 +08:00
|
|
|
// Is there a PLL there ?
|
2022-06-25 22:56:16 +08:00
|
|
|
const CellInfo *pll_cell = getBoundBelCell(pin.bel);
|
2021-02-16 19:52:16 +08:00
|
|
|
if (pll_cell == nullptr)
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Is that port actually used ?
|
|
|
|
if ((pin.pin == id_PLLOUT_B) && !is_sb_pll40_dual(this, pll_cell))
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Is that SB_IO used at an input ?
|
2022-06-25 22:56:16 +08:00
|
|
|
if ((cell->getPort(id_D_IN_0) == nullptr) && (cell->getPort(id_D_IN_1) == nullptr))
|
2021-02-16 19:52:16 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
// Are we perhaps a PAD INPUT Bel that can be placed here?
|
2022-06-25 22:56:16 +08:00
|
|
|
if (str_or_default(pll_cell->attrs, id_BEL_PAD_INPUT, "") == getBelName(bel).str(getCtx()))
|
2021-02-16 19:52:16 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
// Conflict
|
2022-10-31 07:21:41 +08:00
|
|
|
if (explain_invalid)
|
|
|
|
log_nonfatal_error("Cell '%s' conflicts with PLL cell '%s'\n", nameOf(cell), nameOf(pll_cell));
|
2021-02-16 19:52:16 +08:00
|
|
|
return false;
|
|
|
|
}
|
2018-07-24 08:18:49 +08:00
|
|
|
}
|
2018-11-19 02:21:41 +08:00
|
|
|
|
2021-02-16 19:52:16 +08:00
|
|
|
Loc ioLoc = getBelLocation(bel);
|
|
|
|
Loc compLoc = ioLoc;
|
|
|
|
compLoc.z = 1 - compLoc.z;
|
2018-09-24 22:14:28 +08:00
|
|
|
|
2021-02-16 19:52:16 +08:00
|
|
|
// Check LVDS pairing
|
|
|
|
if (cell->ioInfo.lvds) {
|
|
|
|
// Check correct z and complement location is free
|
2022-10-31 07:21:41 +08:00
|
|
|
if (ioLoc.z != 0) {
|
|
|
|
if (explain_invalid)
|
|
|
|
log_nonfatal_error("Bel '%s' can't be used for LVDS\n", getCtx()->nameOfBel(bel));
|
2021-02-16 19:52:16 +08:00
|
|
|
return false;
|
2022-10-31 07:21:41 +08:00
|
|
|
}
|
2021-02-16 19:52:16 +08:00
|
|
|
BelId compBel = getBelByLocation(compLoc);
|
|
|
|
CellInfo *compCell = getBoundBelCell(compBel);
|
2022-10-31 07:21:41 +08:00
|
|
|
if (compCell) {
|
|
|
|
if (explain_invalid)
|
|
|
|
log_nonfatal_error("Cell '%s' LVDS complement occupied by cell '%s'\n", nameOf(cell),
|
|
|
|
nameOf(compCell));
|
2021-02-16 19:52:16 +08:00
|
|
|
return false;
|
2022-10-31 07:21:41 +08:00
|
|
|
}
|
2021-02-16 19:52:16 +08:00
|
|
|
} else {
|
|
|
|
// Check LVDS IO is not placed at complement location
|
|
|
|
BelId compBel = getBelByLocation(compLoc);
|
2022-06-25 22:56:16 +08:00
|
|
|
const CellInfo *compCell = getBoundBelCell(compBel);
|
2022-10-31 07:21:41 +08:00
|
|
|
if (compCell && compCell->ioInfo.lvds) {
|
|
|
|
if (explain_invalid)
|
|
|
|
log_nonfatal_error("Cell '%s' can't occupy LVDS complement of cell '%s'\n", nameOf(cell),
|
|
|
|
nameOf(compCell));
|
2021-02-16 19:52:16 +08:00
|
|
|
return false;
|
2022-10-31 07:21:41 +08:00
|
|
|
}
|
2019-04-17 20:07:38 +08:00
|
|
|
|
2021-02-16 19:52:16 +08:00
|
|
|
// Check for conflicts on shared nets
|
|
|
|
// - CLOCK_ENABLE
|
|
|
|
// - OUTPUT_CLK
|
|
|
|
// - INPUT_CLK
|
|
|
|
if (compCell) {
|
|
|
|
bool use[6] = {
|
|
|
|
_io_pintype_need_clk_in(cell->ioInfo.pintype),
|
|
|
|
_io_pintype_need_clk_in(compCell->ioInfo.pintype),
|
|
|
|
_io_pintype_need_clk_out(cell->ioInfo.pintype),
|
|
|
|
_io_pintype_need_clk_out(compCell->ioInfo.pintype),
|
|
|
|
_io_pintype_need_clk_en(cell->ioInfo.pintype),
|
|
|
|
_io_pintype_need_clk_en(compCell->ioInfo.pintype),
|
|
|
|
};
|
2022-06-25 22:56:16 +08:00
|
|
|
const NetInfo *nets[] = {
|
|
|
|
cell->getPort(id_INPUT_CLK), compCell->getPort(id_INPUT_CLK),
|
|
|
|
cell->getPort(id_OUTPUT_CLK), compCell->getPort(id_OUTPUT_CLK),
|
|
|
|
cell->getPort(id_CLOCK_ENABLE), compCell->getPort(id_CLOCK_ENABLE),
|
2021-02-16 19:52:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
for (int i = 0; i < 6; i++)
|
2022-10-31 07:21:41 +08:00
|
|
|
if (use[i] && (nets[i] != nets[i ^ 1]) && (use[i ^ 1] || (nets[i ^ 1] != nullptr))) {
|
|
|
|
if (explain_invalid)
|
|
|
|
log_nonfatal_error("Net '%s' for cell '%s' conflicts with net '%s' for '%s'\n",
|
|
|
|
nameOf(nets[i]), nameOf(cell), nameOf(nets[i ^ 1]),
|
|
|
|
nameOf(compCell));
|
2021-02-16 19:52:16 +08:00
|
|
|
return false;
|
2022-10-31 07:21:41 +08:00
|
|
|
}
|
2021-02-16 19:52:16 +08:00
|
|
|
}
|
2019-04-17 20:07:38 +08:00
|
|
|
}
|
2018-09-24 22:14:28 +08:00
|
|
|
|
2021-02-16 19:52:16 +08:00
|
|
|
return get_bel_package_pin(bel) != "";
|
|
|
|
} else if (cell->type == id_SB_GB) {
|
|
|
|
if (cell->gbInfo.forPadIn)
|
|
|
|
return true;
|
|
|
|
NPNR_ASSERT(cell->ports.at(id_GLOBAL_BUFFER_OUTPUT).net != nullptr);
|
|
|
|
const NetInfo *net = cell->ports.at(id_GLOBAL_BUFFER_OUTPUT).net;
|
|
|
|
int glb_id = get_driven_glb_netwk(bel);
|
|
|
|
if (net->is_reset && net->is_enable)
|
|
|
|
return false;
|
|
|
|
else if (net->is_reset)
|
|
|
|
return (glb_id % 2) == 0;
|
|
|
|
else if (net->is_enable)
|
|
|
|
return (glb_id % 2) == 1;
|
|
|
|
else
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
// TODO: IO cell clock checks
|
2018-06-16 23:09:41 +08:00
|
|
|
return true;
|
2021-02-16 19:52:16 +08:00
|
|
|
}
|
2018-06-12 19:40:22 +08:00
|
|
|
}
|
|
|
|
}
|
2018-06-12 20:31:26 +08:00
|
|
|
|
|
|
|
NEXTPNR_NAMESPACE_END
|