Debian Codegraph @

himbaechel/uarch/gowin/gowin.h

raw
1 #ifndef GOWIN_H
2 #define GOWIN_H
3
4 #include "nextpnr.h"
5
6 NEXTPNR_NAMESPACE_BEGIN
7
8 namespace {
9 // Return true if a cell is a LUT
10 inline bool type_is_lut(IdString cell_type) { return cell_type.in(id_LUT1, id_LUT2, id_LUT3, id_LUT4); }
11 inline bool is_lut(const CellInfo *cell) { return type_is_lut(cell->type); }
12 // Return true if a cell is a DFF
13 inline bool type_is_dff(IdString cell_type)
14 {
15 return cell_type.in(id_DFF, id_DFFE, id_DFFN, id_DFFNE, id_DFFS, id_DFFSE, id_DFFNS, id_DFFNSE, id_DFFR, id_DFFRE,
16 id_DFFNR, id_DFFNRE, id_DFFP, id_DFFPE, id_DFFNP, id_DFFNPE, id_DFFC, id_DFFCE, id_DFFNC,
17 id_DFFNCE);
18 }
19 inline bool is_dff(const CellInfo *cell) { return type_is_dff(cell->type); }
20 // Return true if a cell is a ALU
21 inline bool type_is_alu(IdString cell_type) { return cell_type == id_ALU; }
22 inline bool is_alu(const CellInfo *cell) { return type_is_alu(cell->type); }
23
24 // io
25 inline bool type_is_io(IdString cell_type) { return cell_type.in(id_IBUF, id_OBUF, id_IOBUF, id_TBUF); }
26 inline bool is_io(const CellInfo *cell) { return type_is_io(cell->type); }
27
28 inline bool type_is_diffio(IdString cell_type)
29 {
30 return cell_type.in(id_ELVDS_IOBUF, id_ELVDS_IBUF, id_ELVDS_TBUF, id_ELVDS_OBUF, id_TLVDS_IOBUF, id_TLVDS_IBUF,
31 id_TLVDS_TBUF, id_TLVDS_OBUF, id_TLVDS_IBUF_ADC);
32 }
33 inline bool is_diffio(const CellInfo *cell) { return type_is_diffio(cell->type); }
34
35 // MIPI
36 inline bool type_is_mipi(IdString cell_type) { return cell_type.in(id_MIPI_OBUF, id_MIPI_OBUF_A, id_MIPI_IBUF); }
37 inline bool is_mipi(const CellInfo *cell) { return type_is_mipi(cell->type); }
38
39 // I3C
40 inline bool type_is_i3c(IdString cell_type) { return cell_type.in(id_I3C_IOBUF); }
41 inline bool is_i3c(const CellInfo *cell) { return type_is_i3c(cell->type); }
42
43 // IOLOGIC input and output separately
44
45 inline bool type_is_iologico(IdString cell_type)
46 {
47 return cell_type.in(id_ODDR, id_ODDRC, id_OSER4, id_OSER8, id_OSER10, id_OVIDEO, id_IOLOGICO_EMPTY);
48 }
49 inline bool is_iologico(const CellInfo *cell) { return type_is_iologico(cell->type); }
50
51 inline bool type_is_iologici(IdString cell_type)
52 {
53 return cell_type.in(id_IDDR, id_IDDRC, id_IDES4, id_IDES8, id_IDES10, id_IVIDEO, id_IOLOGICI_EMPTY);
54 }
55 inline bool is_iologici(const CellInfo *cell) { return type_is_iologici(cell->type); }
56
57 // Return true if a cell is a SSRAM
58 inline bool type_is_ssram(IdString cell_type)
59 {
60 return cell_type.in(id_RAM16SDP1, id_RAM16SDP2, id_RAM16SDP4, id_ROM16);
61 }
62 inline bool is_ssram(const CellInfo *cell) { return type_is_ssram(cell->type); }
63
64 // Return true if a cell is a BSRAM
65 inline bool type_is_bsram(IdString cell_type)
66 {
67 return cell_type.in(id_SP, id_SPX9, id_pROM, id_pROMX9, id_ROM, id_SDP, id_SDPB, id_SDPX9B, id_DP, id_DPB,
68 id_DPX9B);
69 }
70 inline bool is_bsram(const CellInfo *cell) { return type_is_bsram(cell->type); }
71
72 // Return true if a cell is a DSP
73 inline bool type_is_dsp(IdString cell_type)
74 {
75 return cell_type.in(id_PADD9, id_PADD18, id_MULT9X9, id_MULT18X18, id_MULT36X36, id_ALU54D, id_MULTALU18X18,
76 id_MULTALU36X18, id_MULTADDALU18X18, id_MULT12X12, id_MULTADDALU12X12, id_MULTALU27X18,
77 id_MULT27X36);
78 }
79 inline bool is_dsp(const CellInfo *cell) { return type_is_dsp(cell->type); }
80
81 // Return true if a cell is CLKDIV
82 inline bool type_is_clkdiv(IdString cell_type) { return cell_type == id_CLKDIV; }
83 inline bool is_clkdiv(const CellInfo *cell) { return type_is_clkdiv(cell->type); }
84
85 // Return true if a cell is CLKDIV2
86 inline bool type_is_clkdiv2(IdString cell_type) { return cell_type == id_CLKDIV2; }
87 inline bool is_clkdiv2(const CellInfo *cell) { return type_is_clkdiv2(cell->type); }
88
89 // Return true for HCLK Cells
90 inline bool is_hclk(const CellInfo *cell) { return type_is_clkdiv2(cell->type) || type_is_clkdiv(cell->type); }
91
92 // Return true if a cell is a UserFlash
93 inline bool type_is_userflash(IdString cell_type)
94 {
95 return cell_type.in(id_FLASH96K, id_FLASH256K, id_FLASH608K, id_FLASH128K, id_FLASH64K, id_FLASH64K, id_FLASH64KZ,
96 id_FLASH96KA);
97 }
98 inline bool is_userflash(const CellInfo *cell) { return type_is_userflash(cell->type); }
99
100 // Return true if a cell is a PLL
101 inline bool type_is_pll(IdString cell_type) { return cell_type.in(id_rPLL, id_PLLVR); }
102 inline bool is_pll(const CellInfo *cell) { return type_is_pll(cell->type); }
103
104 // Return true if a cell is a ADC
105 inline bool type_is_adc(IdString cell_type) { return cell_type.in(id_ADC); }
106 inline bool is_adc(const CellInfo *cell) { return type_is_adc(cell->type); }
107
108 // Return true if a cell is a EMCU
109 inline bool type_is_emcu(IdString cell_type) { return cell_type == id_EMCU; }
110 inline bool is_emcu(const CellInfo *cell) { return type_is_emcu(cell->type); }
111
112 // ==========================================
113 // extra data in the chip db
114 // ==========================================
115 NPNR_PACKED_STRUCT(struct Pad_extra_data_POD {
116 int32_t pll_tile;
117 int32_t pll_bel;
118 int32_t pll_type;
119 });
120
121 NPNR_PACKED_STRUCT(struct Tile_extra_data_POD {
122 int32_t class_id;
123 int16_t io16_x_off;
124 int16_t io16_y_off;
125 int32_t tile_flags;
126 // tile flags
127 static constexpr int32_t TILE_I3C_CAPABLE_IO = 1;
128 });
129
130 NPNR_PACKED_STRUCT(struct Bottom_io_cnd_POD {
131 int32_t wire_a_net;
132 int32_t wire_b_net;
133 });
134
135 NPNR_PACKED_STRUCT(struct Bottom_io_POD {
136 // simple OBUF
137 static constexpr int8_t NORMAL = 0;
138 // DDR
139 static constexpr int8_t DDR = 1;
140 RelSlice<Bottom_io_cnd_POD> conditions;
141 });
142
143 NPNR_PACKED_STRUCT(struct Spine_bel_POD {
144 int32_t spine;
145 int32_t bel_x;
146 int32_t bel_y;
147 int32_t bel_z;
148 });
149
150 NPNR_PACKED_STRUCT(struct Io_dlldly_bel_POD {
151 int32_t io;
152 int32_t dlldly;
153 });
154
155 NPNR_PACKED_STRUCT(struct Wire_bel_POD {
156 int32_t pip_xy;
157 int32_t pip_dst;
158 int32_t pip_src;
159 int32_t bel_x;
160 int32_t bel_y;
161 int32_t bel_z;
162 int32_t side;
163 });
164
165 NPNR_PACKED_STRUCT(struct Segment_POD {
166 int16_t x;
167 int16_t seg_idx;
168 int16_t min_x;
169 int16_t min_y;
170 int16_t max_x;
171 int16_t max_y;
172 int16_t top_row;
173 int16_t bottom_row;
174 uint32_t top_wire;
175 uint32_t bottom_wire;
176 RelSlice<uint32_t> top_gate_wire;
177 RelSlice<uint32_t> bottom_gate_wire;
178 });
179
180 NPNR_PACKED_STRUCT(struct SpineSelectWire_POD {
181 uint32_t spine;
182 int16_t x;
183 int16_t y;
184 uint32_t wire;
185 uint32_t vcc_gnd;
186 });
187
188 NPNR_PACKED_STRUCT(struct Constraint_POD {
189 int32_t net;
190 int32_t row;
191 int32_t col;
192 int32_t bel;
193 int32_t iostd;
194 });
195
196 NPNR_PACKED_STRUCT(struct Extra_package_data_POD { RelSlice<Constraint_POD> cst; });
197
198 NPNR_PACKED_STRUCT(struct Extra_chip_data_POD {
199 int32_t chip_flags;
200 int32_t dcs_prefix;
201 int16_t center_row;
202 int16_t center_col;
203 Bottom_io_POD bottom_io;
204 RelSlice<IdString> diff_io_types;
205 RelSlice<Spine_bel_POD> dqce_bels;
206 RelSlice<Spine_bel_POD> dcs_bels;
207 RelSlice<Wire_bel_POD> dhcen_bels;
208 RelSlice<Io_dlldly_bel_POD> io_dlldly_bels;
209 RelSlice<Segment_POD> segments;
210 RelSlice<SpineSelectWire_POD> spine_select_wires_top;
211 RelSlice<SpineSelectWire_POD> spine_select_wires_bottom;
212
213 // chip flags
214 static constexpr int32_t HAS_SP32 = 1;
215 static constexpr int32_t NEED_SP_FIX = 2;
216 static constexpr int32_t NEED_BSRAM_OUTREG_FIX = 4;
217 static constexpr int32_t NEED_BLKSEL_FIX = 8;
218 static constexpr int32_t HAS_BANDGAP = 16;
219 static constexpr int32_t HAS_PLL_HCLK = 32;
220 static constexpr int32_t HAS_CLKDIV_HCLK = 64;
221 static constexpr int32_t HAS_PINCFG = 128;
222 static constexpr int32_t HAS_DFF67 = 256;
223 static constexpr int32_t HAS_CIN_MUX = 512;
224 static constexpr int32_t NEED_BSRAM_RESET_FIX = 1024;
225 static constexpr int32_t NEED_SDP_FIX = 2048;
226 static constexpr int32_t NEED_CFGPINS_INVERSION = 4096;
227 static constexpr int32_t HAS_I2CCFG = 8192;
228 static constexpr int32_t HAS_5A_DSP = 16384;
229 static constexpr int32_t NEED_BSRAM_DP_CE_FIX = 32768;
230 });
231
232 } // namespace
233
234 // Bels Z ranges. It is desirable that these numbers be synchronized with the chipdb generator
235 namespace BelZ {
236 enum
237 {
238 LUT0_Z = 0,
239 LUT7_Z = 14,
240 MUX20_Z = 16,
241 MUX21_Z = 18,
242 MUX23_Z = 22,
243 MUX27_Z = 29,
244 ALU0_Z = 30, // :35, 6 ALU
245 RAMW_Z = 36, // RAM16SDP4
246
247 IOBA_Z = 50,
248 IOBB_Z = 51, // +IOBC...IOBL
249
250 IOLOGICA_Z = 70,
251 IDES16_Z = 74,
252 OSER16_Z = 75,
253
254 BUFG_Z = 76, // : 81 reserve just in case
255 BSRAM_Z = 100,
256
257 OSC_Z = 274,
258 PLL_Z = 275,
259 GSR_Z = 276,
260 VCC_Z = 277,
261 VSS_Z = 278,
262 BANDGAP_Z = 279,
263
264 DQCE_Z = 280, // : 286 reserve for 6 DQCEs
265 DCS_Z = 286, // : 288 reserve for 2 DCSs
266 DHCEN_Z = 288, // : 298
267
268 USERFLASH_Z = 298,
269
270 EMCU_Z = 300,
271
272 MIPIOBUF_Z = 301,
273 MIPIIBUF_Z = 302,
274
275 DLLDLY_Z = 303, // : 305 reserve for 2 DLLDLYs
276
277 PINCFG_Z = 400,
278
279 ADC_Z = 401,
280
281 // The two least significant bits encode Z for 9-bit adders and
282 // multipliers, if they are equal to 0, then we get Z of their common
283 // 18-bit equivalent.
284 DSP_Z = 509, // DSP
285
286 DSP_0_Z = 511, // DSP macro 0
287 PADD18_0_0_Z = 512,
288 PADD9_0_0_Z = 512 + 1,
289 PADD9_0_1_Z = 512 + 2,
290 PADD18_0_1_Z = 516,
291 PADD9_0_2_Z = 516 + 1,
292 PADD9_0_3_Z = 516 + 2,
293
294 MULT18X18_0_0_Z = 520,
295 MULT9X9_0_0_Z = 520 + 1,
296 MULT9X9_0_1_Z = 520 + 2,
297 MULT18X18_0_1_Z = 524,
298 MULT9X9_0_2_Z = 524 + 1,
299 MULT9X9_0_3_Z = 524 + 2,
300
301 ALU54D_0_Z = 524 + 3,
302 MULTALU18X18_0_Z = 528,
303 MULTALU36X18_0_Z = 528 + 1,
304 MULTADDALU18X18_0_Z = 528 + 2,
305
306 MULT36X36_Z = 528 + 3,
307
308 DSP_1_Z = 543, // DSP macro 1
309 PADD18_1_0_Z = 544,
310 PADD9_1_0_Z = 544 + 1,
311 PADD9_1_1_Z = 544 + 2,
312 PADD18_1_1_Z = 548,
313 PADD9_1_2_Z = 548 + 1,
314 PADD9_1_3_Z = 548 + 2,
315
316 MULT18X18_1_0_Z = 552,
317 MULT9X9_1_0_Z = 552 + 1,
318 MULT9X9_1_1_Z = 552 + 2,
319 MULT18X18_1_1_Z = 556,
320 MULT9X9_1_2_Z = 556 + 1,
321 MULT9X9_1_3_Z = 556 + 2,
322
323 ALU54D_1_Z = 556 + 3,
324 MULTALU18X18_1_Z = 560,
325 MULTALU36X18_1_Z = 560 + 1,
326 MULTADDALU18X18_1_Z = 560 + 2,
327
328 // HCLK Bels
329 CLKDIV2_0_Z = 610,
330 CLKDIV2_1_Z = 611,
331 CLKDIV2_2_Z = 612,
332 CLKDIV2_3_Z = 613,
333
334 CLKDIV_0_Z = 620,
335 CLKDIV_1_Z = 621,
336 CLKDIV_2_Z = 622,
337 CLKDIV_3_Z = 623,
338
339 MULT12X12_0_Z = 640,
340 MULT12X12_1_Z = 641,
341 MULTADDALU12X12_Z = 642,
342 MULTALU27X18_Z = 643,
343 };
344 }
345
346 NEXTPNR_NAMESPACE_END
347 #endif