2024-12-10 22:48:07 +08:00
|
|
|
/*
|
|
|
|
* nextpnr -- Next Generation Place and Route
|
|
|
|
*
|
|
|
|
* Copyright (C) 2024 The Project Peppercorn Authors.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2024-12-16 23:58:46 +08:00
|
|
|
#include "gatemate.h"
|
2024-12-20 18:03:10 +08:00
|
|
|
#include "design_utils.h"
|
2024-12-10 22:48:07 +08:00
|
|
|
|
|
|
|
#define GEN_INIT_CONSTIDS
|
|
|
|
#define HIMBAECHEL_CONSTIDS "uarch/gatemate/constids.inc"
|
|
|
|
|
|
|
|
#include "himbaechel_constids.h"
|
|
|
|
|
|
|
|
NEXTPNR_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
GateMateImpl::~GateMateImpl() {};
|
|
|
|
|
|
|
|
void GateMateImpl::init_database(Arch *arch)
|
|
|
|
{
|
|
|
|
const ArchArgs &args = arch->args;
|
|
|
|
init_uarch_constids(arch);
|
|
|
|
arch->load_chipdb(stringf("gatemate/chipdb-%s.bin", args.device.c_str()));
|
2024-12-17 02:21:32 +08:00
|
|
|
arch->set_package("FBGA324");
|
2024-12-10 22:48:07 +08:00
|
|
|
arch->set_speed_grade("DEFAULT");
|
|
|
|
}
|
|
|
|
|
2024-12-18 15:56:54 +08:00
|
|
|
void GateMateImpl::init(Context *ctx) { HimbaechelAPI::init(ctx); }
|
2024-12-16 18:19:56 +08:00
|
|
|
|
|
|
|
delay_t GateMateImpl::estimateDelay(WireId src, WireId dst) const
|
|
|
|
{
|
|
|
|
int sx, sy, dx, dy;
|
|
|
|
tile_xy(ctx->chip_info, src.tile, sx, sy);
|
|
|
|
tile_xy(ctx->chip_info, dst.tile, dx, dy);
|
|
|
|
|
2024-12-16 23:58:46 +08:00
|
|
|
return 100 * (std::abs(dx - sx) / 4 + std::abs(dy - sy) / 4 + 2);
|
2024-12-16 18:19:56 +08:00
|
|
|
}
|
|
|
|
|
2024-12-25 22:48:09 +08:00
|
|
|
bool GateMateImpl::isBelLocationValid(BelId bel, bool explain_invalid) const
|
|
|
|
{
|
|
|
|
CellInfo *cell = ctx->getBoundBelCell(bel);
|
|
|
|
if (cell == nullptr) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (ctx->getBelType(bel) == id_CPE) {
|
|
|
|
Loc loc = ctx->getBelLocation(bel);
|
|
|
|
int x = loc.x - 2;
|
|
|
|
int y = loc.y - 2;
|
2024-12-26 16:34:24 +08:00
|
|
|
if (x < 2 || x > 167)
|
2024-12-25 22:48:09 +08:00
|
|
|
return false;
|
2024-12-26 16:34:24 +08:00
|
|
|
if (y < 2 || y > 127)
|
2024-12-25 22:48:09 +08:00
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2025-01-08 21:08:41 +08:00
|
|
|
void updateLUT(Context *ctx, CellInfo *cell, IdString port, IdString init)
|
|
|
|
{
|
|
|
|
if (cell->params.count(init) == 0) return;
|
|
|
|
unsigned init_val = int_or_default(cell->params, init);
|
|
|
|
WireId pin_wire = ctx->getBelPinWire(cell->bel, port);
|
|
|
|
for (PipId pip : ctx->getPipsUphill(pin_wire)) {
|
|
|
|
if (!ctx->getBoundPipNet(pip))
|
|
|
|
continue;
|
|
|
|
const auto extra_data = *reinterpret_cast<const GateMatePipExtraDataPOD *>(
|
|
|
|
chip_pip_info(ctx->chip_info, pip).extra_data.get());
|
|
|
|
if (!extra_data.name)
|
|
|
|
continue;
|
|
|
|
if (extra_data.type == PipExtra::PIP_EXTRA_MUX && (extra_data.flags & MUX_CPE_INV)) {
|
|
|
|
if (port.in(id_IN1,id_IN3,id_IN5,id_IN7))
|
|
|
|
init_val = (init_val & 0b1010) >> 1 | (init_val & 0b0101) << 1;
|
|
|
|
else
|
|
|
|
init_val = (init_val & 0b0011) << 2 | (init_val & 0b1100) >> 2;
|
|
|
|
cell->params[init] = Property(init_val, 4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-16 18:19:56 +08:00
|
|
|
void GateMateImpl::postRoute()
|
|
|
|
{
|
2024-12-20 18:03:10 +08:00
|
|
|
ctx->assignArchInfo();
|
|
|
|
log_break();
|
|
|
|
log_info("Resources spent on routing:\n");
|
|
|
|
for (auto &net : ctx->nets) {
|
|
|
|
NetInfo *ni = net.second.get();
|
|
|
|
for (auto &w : ni->wires) {
|
|
|
|
if (w.second.pip != PipId()) {
|
|
|
|
const auto extra_data = *reinterpret_cast<const GateMatePipExtraDataPOD *>(
|
|
|
|
chip_pip_info(ctx->chip_info, w.second.pip).extra_data.get());
|
|
|
|
if (!extra_data.name)
|
|
|
|
continue;
|
|
|
|
if (extra_data.type == PipExtra::PIP_EXTRA_CPE) {
|
|
|
|
IdStringList id = ctx->getPipName(w.second.pip);
|
2024-12-20 19:03:53 +08:00
|
|
|
BelId bel = ctx->getBelByName(IdStringList::concat(id[0], id_CPE));
|
2024-12-20 18:03:10 +08:00
|
|
|
if (!ctx->getBoundBelCell(bel)) {
|
2024-12-20 19:03:53 +08:00
|
|
|
CellInfo *cell = ctx->createCell(ctx->id(ctx->nameOfBel(bel)), id_CPE);
|
2024-12-20 18:03:10 +08:00
|
|
|
ctx->bindBel(bel, cell, PlaceStrength::STRENGTH_FIXED);
|
2024-12-25 23:39:01 +08:00
|
|
|
if (IdString(extra_data.name) == id_RAM_O2) {
|
|
|
|
cell->params[id_INIT_L00] = Property(0b1010, 4);
|
|
|
|
cell->params[id_INIT_L01] = Property(0b1111, 4);
|
|
|
|
cell->params[id_INIT_L02] = Property(0b1111, 4);
|
|
|
|
cell->params[id_INIT_L03] = Property(0b1111, 4);
|
|
|
|
cell->params[id_INIT_L10] = Property(0b1000, 4);
|
|
|
|
cell->params[id_INIT_L20] = Property(0b1100, 4);
|
|
|
|
cell->params[id_O2] = Property(0b11, 2);
|
|
|
|
cell->params[id_RAM_O2] = Property(1, 1);
|
2025-01-13 20:16:58 +08:00
|
|
|
} else if (IdString(extra_data.name) == id_RAM_O1) {
|
|
|
|
cell->params[id_INIT_L00] = Property(0b1010, 4);
|
|
|
|
cell->params[id_INIT_L01] = Property(0b1111, 4);
|
|
|
|
cell->params[id_INIT_L02] = Property(0b1111, 4);
|
|
|
|
cell->params[id_INIT_L03] = Property(0b1111, 4);
|
|
|
|
cell->params[id_INIT_L10] = Property(0b1000, 4);
|
|
|
|
cell->params[id_INIT_L20] = Property(0b1010, 4);
|
|
|
|
cell->params[id_O1] = Property(0b11, 2);
|
|
|
|
cell->params[id_RAM_O1] = Property(1, 1);
|
|
|
|
} else {
|
|
|
|
log_error("Issue adding pass trough signal for %s.\n",IdString(extra_data.name).c_str(ctx));
|
2024-12-25 23:39:01 +08:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
log_error("Issue adding pass trough signal.\n");
|
2024-12-20 18:03:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-01-08 21:08:41 +08:00
|
|
|
|
|
|
|
for (auto &cell : ctx->cells) {
|
|
|
|
if (cell.second->type == id_CPE) {
|
|
|
|
// if LUT part used
|
|
|
|
updateLUT(ctx, cell.second.get(), id_IN1, id_INIT_L00);
|
|
|
|
updateLUT(ctx, cell.second.get(), id_IN2, id_INIT_L00);
|
|
|
|
updateLUT(ctx, cell.second.get(), id_IN3, id_INIT_L01);
|
|
|
|
updateLUT(ctx, cell.second.get(), id_IN4, id_INIT_L01);
|
|
|
|
updateLUT(ctx, cell.second.get(), id_IN5, id_INIT_L02);
|
|
|
|
updateLUT(ctx, cell.second.get(), id_IN6, id_INIT_L02);
|
|
|
|
updateLUT(ctx, cell.second.get(), id_IN7, id_INIT_L03);
|
|
|
|
updateLUT(ctx, cell.second.get(), id_IN8, id_INIT_L03);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-20 18:03:10 +08:00
|
|
|
print_utilisation(ctx);
|
|
|
|
|
2024-12-16 18:19:56 +08:00
|
|
|
const ArchArgs &args = ctx->args;
|
|
|
|
if (args.options.count("out")) {
|
2024-12-18 15:56:54 +08:00
|
|
|
write_bitstream(args.device, args.options.at("out"));
|
2024-12-16 18:19:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-01-09 21:27:21 +08:00
|
|
|
void GateMateImpl::postPlace()
|
|
|
|
{
|
|
|
|
log_break();
|
|
|
|
log_info("Limiting routing...\n");
|
|
|
|
for (auto &cell : ctx->cells) {
|
|
|
|
CellInfo &ci = *cell.second;
|
|
|
|
if (ci.type == id_CPE) {
|
|
|
|
if (!ci.params.count(id_FUNCTION)) continue;
|
|
|
|
uint8_t func = int_or_default(ci.params, id_FUNCTION, 0);
|
|
|
|
if (func!=4) continue; // Skip all that are not MUX
|
|
|
|
for (int i = 1; i <= 4; i++) {
|
|
|
|
IdString port = ctx->idf("IN%d", i);
|
|
|
|
NetInfo *net = ci.getPort(port);
|
|
|
|
if (!net)
|
|
|
|
continue;
|
|
|
|
WireId dwire = ctx->getBelPinWire(ci.bel, port);
|
|
|
|
for (PipId pip : ctx->getPipsUphill(dwire)) {
|
|
|
|
const auto extra_data = *reinterpret_cast<const GateMatePipExtraDataPOD *>(
|
|
|
|
chip_pip_info(ctx->chip_info, pip).extra_data.get());
|
|
|
|
if (!extra_data.name)
|
|
|
|
continue;
|
|
|
|
if (extra_data.type == PipExtra::PIP_EXTRA_MUX && (extra_data.flags & MUX_CPE_INV)) {
|
|
|
|
blocked_pips.emplace(pip);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ctx->assignArchInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-12-18 17:44:25 +08:00
|
|
|
void GateMateImpl::setupArchContext()
|
|
|
|
{
|
|
|
|
const ArchArgs &args = ctx->args;
|
|
|
|
if (args.options.count("read")) {
|
|
|
|
if (!read_bitstream(args.device, args.options.at("read")))
|
|
|
|
log_error("Loading bitstream failed.\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-20 16:38:14 +08:00
|
|
|
// Bel bucket functions
|
|
|
|
IdString GateMateImpl::getBelBucketForCellType(IdString cell_type) const
|
|
|
|
{
|
2024-12-21 19:15:03 +08:00
|
|
|
if (cell_type.in(id_CC_IBUF, id_CC_OBUF, id_CC_TOBUF, id_CC_IOBUF, id_CC_LVDS_IBUF, id_CC_LVDS_TOBUF,
|
|
|
|
id_CC_LVDS_OBUF, id_CC_LVDS_IOBUF))
|
2024-12-20 16:38:14 +08:00
|
|
|
return id_GPIO;
|
|
|
|
else
|
|
|
|
return cell_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GateMateImpl::isValidBelForCellType(IdString cell_type, BelId bel) const
|
|
|
|
{
|
|
|
|
IdString bel_type = ctx->getBelType(bel);
|
|
|
|
if (bel_type == id_GPIO)
|
2024-12-21 19:15:03 +08:00
|
|
|
return cell_type.in(id_CC_IBUF, id_CC_OBUF, id_CC_TOBUF, id_CC_IOBUF, id_CC_LVDS_IBUF, id_CC_LVDS_TOBUF,
|
|
|
|
id_CC_LVDS_OBUF, id_CC_LVDS_IOBUF);
|
2024-12-20 16:38:14 +08:00
|
|
|
else
|
|
|
|
return (bel_type == cell_type);
|
|
|
|
}
|
|
|
|
|
2024-12-10 22:48:07 +08:00
|
|
|
struct GateMateArch : HimbaechelArch
|
|
|
|
{
|
|
|
|
GateMateArch() : HimbaechelArch("gatemate") {};
|
|
|
|
bool match_device(const std::string &device) override
|
|
|
|
{
|
|
|
|
return device.size() > 6 && device.substr(0, 6) == "CCGM1A";
|
|
|
|
}
|
|
|
|
std::unique_ptr<HimbaechelAPI> create(const std::string &device, const dict<std::string, std::string> &args)
|
|
|
|
{
|
|
|
|
return std::make_unique<GateMateImpl>();
|
|
|
|
}
|
|
|
|
} gateMateArch;
|
|
|
|
|
|
|
|
NEXTPNR_NAMESPACE_END
|