nextpnr/himbaechel/uarch/gatemate/gatemate.cc

158 lines
5.4 KiB
C++
Raw Normal View History

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;
}
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);
}
} else
log_error("Issue adding pass trough signal.\n");
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
}
}
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