| 1 |
/* |
| 2 |
* nextpnr -- Next Generation Place and Route |
| 3 |
* |
| 4 |
* Copyright (C) 2023 gatecat <[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 |
#ifndef HIMBAECHEL_XILINX_H |
| 21 |
#define HIMBAECHEL_XILINX_H |
| 22 |
|
| 23 |
#include "extra_data.h" |
| 24 |
#include "himbaechel_api.h" |
| 25 |
#include "log.h" |
| 26 |
#include "nextpnr.h" |
| 27 |
#include "util.h" |
| 28 |
|
| 29 |
#include "himbaechel_helpers.h" |
| 30 |
|
| 31 |
NEXTPNR_NAMESPACE_BEGIN |
| 32 |
|
| 33 |
struct XilinxCellTags |
| 34 |
{ |
| 35 |
union |
| 36 |
{ |
| 37 |
struct |
| 38 |
{ |
| 39 |
bool is_memory, is_srl; |
| 40 |
int input_count, output_count; |
| 41 |
int memory_group; |
| 42 |
bool only_drives_carry; |
| 43 |
NetInfo *input_sigs[6], *output_sigs[2]; |
| 44 |
NetInfo *address_msb[3]; |
| 45 |
NetInfo *di1_net, *di2_net, *wclk; |
| 46 |
} lut; |
| 47 |
struct |
| 48 |
{ |
| 49 |
bool is_latch, is_clkinv, is_srinv, ffsync; |
| 50 |
bool is_paired; |
| 51 |
NetInfo *clk, *sr, *ce, *d; |
| 52 |
} ff; |
| 53 |
struct |
| 54 |
{ |
| 55 |
NetInfo *out_sigs[8], *cout_sigs[8], *x_sigs[8]; |
| 56 |
} carry; |
| 57 |
struct |
| 58 |
{ |
| 59 |
NetInfo *sel, *out; |
| 60 |
} mux; |
| 61 |
}; |
| 62 |
}; |
| 63 |
|
| 64 |
struct SiteIndex |
| 65 |
{ |
| 66 |
SiteIndex() : tile(-1), site(-1) {}; |
| 67 |
SiteIndex(int32_t tile, int32_t site) : tile(tile), site(site) {}; |
| 68 |
|
| 69 |
int32_t tile; |
| 70 |
int32_t site; |
| 71 |
bool operator==(const SiteIndex &other) const { return tile == other.tile && site == other.site; } |
| 72 |
bool operator!=(const SiteIndex &other) const { return tile != other.tile || site != other.site; } |
| 73 |
bool operator<(const SiteIndex &other) const |
| 74 |
{ |
| 75 |
return (tile < other.tile) || (tile == other.tile && site < other.site); |
| 76 |
} |
| 77 |
unsigned hash() const { return mkhash(tile, site); } |
| 78 |
}; |
| 79 |
|
| 80 |
struct XilinxImpl : HimbaechelAPI |
| 81 |
{ |
| 82 |
|
| 83 |
struct LogicTileStatus |
| 84 |
{ |
| 85 |
// z -> cell |
| 86 |
CellInfo *cells[128]; |
| 87 |
|
| 88 |
// Eight-tile valid and dirty status |
| 89 |
struct EigthTileStatus |
| 90 |
{ |
| 91 |
mutable bool valid = true, dirty = true; |
| 92 |
} eights[8]; |
| 93 |
struct HalfTileStatus |
| 94 |
{ |
| 95 |
mutable bool valid = true, dirty = true; |
| 96 |
} halfs[8]; |
| 97 |
}; |
| 98 |
|
| 99 |
struct BRAMTileStatus |
| 100 |
{ |
| 101 |
CellInfo *cells[12] = {nullptr}; |
| 102 |
}; |
| 103 |
|
| 104 |
struct TileStatus |
| 105 |
{ |
| 106 |
std::unique_ptr<LogicTileStatus> lts; |
| 107 |
std::unique_ptr<BRAMTileStatus> bts; |
| 108 |
std::vector<int> site_variant; |
| 109 |
}; |
| 110 |
|
| 111 |
~XilinxImpl(); |
| 112 |
po::options_description getUArchOptions() override; |
| 113 |
void init_database(Arch *arch) override; |
| 114 |
|
| 115 |
void init(Context *ctx) override; |
| 116 |
|
| 117 |
// Bels |
| 118 |
void notifyBelChange(BelId bel, CellInfo *cell) override; |
| 119 |
void update_logic_bel(BelId bel, CellInfo *cell); |
| 120 |
void update_bram_bel(BelId bel, CellInfo *cell); |
| 121 |
|
| 122 |
bool isBelLocationValid(BelId bel, bool explain_invalid = false) const override; |
| 123 |
bool xc7_logic_tile_valid(IdString tileType, const LogicTileStatus <s) const; |
| 124 |
|
| 125 |
// Pips |
| 126 |
bool is_pip_unavail(PipId pip) const; |
| 127 |
bool checkPipAvail(PipId pip) const override { return !is_pip_unavail(pip); } |
| 128 |
bool checkPipAvailForNet(PipId pip, const NetInfo *net) const override { return !is_pip_unavail(pip); } |
| 129 |
|
| 130 |
// Flow management |
| 131 |
void parse_xdc(const std::string &filename); |
| 132 |
void pack() override; |
| 133 |
void prePlace() override; |
| 134 |
void preRoute() override; |
| 135 |
void postPlace() override; |
| 136 |
void postRoute() override; |
| 137 |
void write_fasm(const std::string &filename); |
| 138 |
|
| 139 |
void configurePlacerHeap(PlacerHeapCfg &cfg) override; |
| 140 |
void configurePlacerStatic(PlacerStaticCfg &cfg) override; |
| 141 |
|
| 142 |
void fixup_placement(); |
| 143 |
void fixup_routing(); |
| 144 |
void route_clocks(); |
| 145 |
|
| 146 |
// Misc utility functions |
| 147 |
const XlnxTileInstExtraDataPOD *tile_extra_data(int tile) const; |
| 148 |
IdString bel_tile_type(BelId bel) const; |
| 149 |
bool is_logic_tile(BelId bel) const; |
| 150 |
bool is_bram_tile(BelId bel) const; |
| 151 |
|
| 152 |
SiteIndex get_bel_site(BelId bel) const; |
| 153 |
SiteIndex rel_site(SiteIndex site, int dx, int dy) const; |
| 154 |
Loc rel_site_loc(SiteIndex site) const; |
| 155 |
IdString get_site_name(SiteIndex site) const; |
| 156 |
IdString bel_name_in_site(BelId bel) const; |
| 157 |
IdStringList get_site_bel_name(BelId bel) const; |
| 158 |
BelId get_site_bel(SiteIndex site, IdString bel_name) const; |
| 159 |
WireId lookup_wire(int tile, IdString wire_name) const; |
| 160 |
|
| 161 |
int hclk_for_iob(BelId pad) const; |
| 162 |
int hclk_for_ioi(int tile) const; |
| 163 |
|
| 164 |
std::string tile_name(int tile) const; |
| 165 |
|
| 166 |
std::vector<XilinxCellTags> cell_tags; |
| 167 |
const XilinxCellTags *get_tags(const CellInfo *cell) const |
| 168 |
{ |
| 169 |
return cell ? &cell_tags.at(cell->flat_index) : nullptr; |
| 170 |
} |
| 171 |
|
| 172 |
std::vector<TileStatus> tile_status; |
| 173 |
|
| 174 |
// Improved delay predictions where sites are located far from their associated interconnect |
| 175 |
dict<WireId, Loc> source_locs, sink_locs; |
| 176 |
bool is_general_routing(WireId wire) const; |
| 177 |
void find_source_sink_locs(); |
| 178 |
|
| 179 |
delay_t predictDelay(BelId src_bel, IdString src_pin, BelId dst_bel, IdString dst_pin) const override; |
| 180 |
delay_t estimateDelay(WireId src, WireId dst) const override; |
| 181 |
BoundingBox getRouteBoundingBox(WireId src, WireId dst) const override; |
| 182 |
|
| 183 |
private: |
| 184 |
HimbaechelHelpers h; |
| 185 |
void assign_cell_tags(); |
| 186 |
}; |
| 187 |
|
| 188 |
NEXTPNR_NAMESPACE_END |
| 189 |
#endif |