cours3: soclib_vci_local_crossbar_simple.h

File soclib_vci_local_crossbar_simple.h, 15.0 KB (added by fpecheux, 17 years ago)

Un premier interconnect compatible VCI, avec sorties de Mealy

Line 
1//////////////////////////////////////////////////////////////////////////
2// File : soclib_vci_local_crossbar.h
3// Date : 15/04/2004
4// author : Alain Greiner
5// Copyright : UPMC - LIP6
6//
7// This component is a modified version of the generic VCI ADVANCED local crossbar.
8// It can be used in a one-level hierarchical interconnect.
9//
10// This component contains two fully independant crossbars :
11// - The requests crossbar contains as many multiplexors as the number
12// of initiator ports (i.e. NB_TARGET) . Each multiplexor is controled
13// by a private FSM. Each initiator port is either "not allocated",
14// or "allocated" to a single target port.
15// - The response crossbar contains as many multiplexors as the number
16// of target ports (i.e. NB_INIT) . Each multiplexor is controled
17// by a private FSM. Each target port is either "not allocated",
18// or "allocated" to a single initiator port.
19//
20// The CMDACK and RSPACK signals are not controled by the corresponding FSM but by every FSM of the other type,
21// using a logical door .
22//
23//
24// Only the FSM where the packet is supposed to go is allocated to the VCI port the packet comes from.
25// The FSM where it comes from is not aware that an FSM is allocated to its port, therefore it can be allocated
26// to an other port.
27//
28// Those crossbar are not "fully connected":
29// - a local target port can be connected to a local initiator port.
30// - a local target port can be connected to a micro-network initiator port.
31//
32// There is no buffer to store VCI requests or responses in this component,
33// and all output signals are Mealy signals.
34//
35//////////////////////////////////////////////////////////////////////////
36// This component has three "constructor" parameters :
37// - char* name : instance name
38// - int* indexes : global index of the subsystem
39// - SOCLIB_MAPPING_TABLE segtab : the segment table
40//////////////////////////////////////////////////////////////////////////
41// This component has 10 "template" parameters :
42// - int NB_INIT : number of VCI initiators
43// - int NB_TARGET : number of VCI targets
44//
45// (Using shorthand VCI_PARAM for these ones)
46// - int ADDRSIZE : number of bits for the VCI ADDRESS field
47// - int CELLSIZE : number of bytes for the VCI DATA field
48// - int ERRSIZE : number of extra bits for the VCI ERROR field
49// - int PLENSIZE : number of extra bits for the VCI PLEN field
50// - int CLENSIZE : number of extra bits for the VCI CLEN field
51// - int SRCIDSIZE : number of bits for the VCI SRCID field
52// - int TRDIDSIZE : number of bits for the VCI TRDID field
53// - int PKTIDSIZE : number of bits for the VCI PKTID field
54//////////////////////////////////////////////////////////////////////////
55
56#ifndef SOCLIB_VCI_LOCAL_CROSSBAR_SIMPLE_H
57#define SOCLIB_VCI_LOCAL_CROSSBAR_SIMPLE_H
58
59#include <systemc.h>
60#include "shared/soclib_vci_interfaces.h"
61#include "shared/soclib_mapping_table.h"
62
63///////////////////////////////////////////////////////////
64// Structure definition
65//////////////////////////////////////////////////////////
66
67template<int NB_INIT,
68 int NB_TARGET,
69 VCI_PARAM_DECLAR>
70
71struct SOCLIB_VCI_LOCAL_CROSSBAR_SIMPLE : sc_module{
72
73 // STRUCTURAL PARAMETERS
74
75 const char *NAME; // instance name
76 int *GLOBAL_ROUTING_TABLE;
77 int *LOCAL_ROUTING_TABLE;
78 int GLOBAL_ADDR_OFFSET, GLOBAL_ADDR_MASK, GLOBAL_ADDR;
79 int LOCAL_ADDR_OFFSET, LOCAL_ADDR_MASK;
80 int GLOBAL_ID_OFFSET, GLOBAL_ID_MASK, GLOBAL_ID;
81 int LOCAL_ID_OFFSET, LOCAL_ID_MASK;
82
83#define GLOBAL_ADDR_OF(x) (((x)>>GLOBAL_ADDR_OFFSET)&GLOBAL_ADDR_MASK)
84#define LOCAL_ADDR_OF(x) (((x)>>LOCAL_ADDR_OFFSET)&LOCAL_ADDR_MASK)
85#define GLOBAL_ID_OF(x) (((x)>>GLOBAL_ID_OFFSET)&GLOBAL_ID_MASK)
86#define LOCAL_ID_OF(x) (((x)>>LOCAL_ID_OFFSET)&LOCAL_ID_MASK)
87
88 // I/O PORTS
89
90 sc_in<bool> CLK ;
91 sc_in<bool> RESETN;
92 // VCI Target ports connected to the local initiators
93ADVANCED_VCI_TARGET<VCI_PARAM> TLOC_VCI[NB_INIT];
94 // VCI Initiator ports connected to the local targets
95ADVANCED_VCI_INITIATOR<VCI_PARAM> ILOC_VCI[NB_TARGET];
96
97 // REGISTERS
98
99 // TLOC FSMs
100 sc_signal<bool> TLOC_ALLOCATED[NB_INIT]; // state of the local target ports
101 sc_signal<int> TLOC_INDEX[NB_INIT];
102
103
104 // ILOC FSMs
105 sc_signal<bool> ILOC_ALLOCATED[NB_TARGET]; // state of the local initiator ports
106 sc_signal<int> ILOC_INDEX[NB_TARGET];
107
108 ////////////////////////////////////////////////
109 // constructor
110 ////////////////////////////////////////////////
111
112 SC_HAS_PROCESS(SOCLIB_VCI_LOCAL_CROSSBAR_SIMPLE);
113
114 SOCLIB_VCI_LOCAL_CROSSBAR_SIMPLE ( sc_module_name insname,
115 int *indexes,
116 SOCLIB_MAPPING_TABLE mapping_table)
117{
118 int level;
119#ifdef SOCVIEW
120 char newname[100];
121
122 for (int i=0;i<NB_INIT;i++)
123 {
124 sprintf(newname,"TLOC_ALLOCATED_%2.2d",i);
125 TLOC_ALLOCATED[i].rename(newname);
126 sprintf(newname,"TLOC_INDEX_%2.2d",i);
127 TLOC_INDEX[i].rename(newname);
128 }
129
130 for (int i=0;i<NB_TARGET;i++)
131 {
132 sprintf(newname,"ILOC_ALLOCATED_%2.2d",i);
133 ILOC_ALLOCATED[i].rename(newname); // allocation register
134 sprintf(newname,"ILOC_INDEX_%2.2d",i);
135 ILOC_INDEX[i].rename(newname); // state of the target output port
136 }
137#endif
138 SC_METHOD(transition);
139 sensitive_pos << CLK;
140
141 SC_METHOD(genMealy);
142 sensitive_neg << CLK;
143
144 for (int i = 0 ; i < NB_TARGET ; i++) {
145 sensitive << ILOC_VCI[i].CMDACK;
146 sensitive << ILOC_VCI[i].RSPVAL;
147 sensitive << ILOC_VCI[i].RDATA;
148 sensitive << ILOC_VCI[i].REOP;
149 sensitive << ILOC_VCI[i].RERROR;
150 sensitive << ILOC_VCI[i].RTRDID;
151 sensitive << ILOC_VCI[i].RPKTID;
152 sensitive << ILOC_VCI[i].RSRCID;
153 }
154
155 for (int i = 0 ; i < NB_INIT ; i++) {
156 sensitive << TLOC_VCI[i].RSPACK;
157 sensitive << TLOC_VCI[i].CMDVAL;
158 sensitive << TLOC_VCI[i].ADDRESS;
159 sensitive << TLOC_VCI[i].WDATA;
160 sensitive << TLOC_VCI[i].CMD;
161 sensitive << TLOC_VCI[i].EOP;
162 sensitive << TLOC_VCI[i].PLEN;
163 sensitive << TLOC_VCI[i].CONS;
164 sensitive << TLOC_VCI[i].CONTIG;
165 sensitive << TLOC_VCI[i].CFIXED;
166 sensitive << TLOC_VCI[i].WRAP;
167 sensitive << TLOC_VCI[i].CLEN;
168 sensitive << TLOC_VCI[i].TRDID;
169 sensitive << TLOC_VCI[i].PKTID;
170 sensitive << TLOC_VCI[i].SRCID;
171 }
172
173 NAME = (const char*) insname;
174 for (level = 0; indexes[level]!=-1; ++level)
175 /**/;
176 GLOBAL_ID = mapping_table.ident(level, indexes);
177 NAME = (const char*) insname;
178 mapping_table.paramsTo( level,
179 GLOBAL_ADDR_OFFSET, GLOBAL_ADDR_MASK,
180 GLOBAL_ID_OFFSET, GLOBAL_ID_MASK);
181 mapping_table.localParams( level,
182 LOCAL_ADDR_OFFSET, LOCAL_ADDR_MASK,
183 LOCAL_ID_OFFSET, LOCAL_ID_MASK );
184
185 GLOBAL_ROUTING_TABLE = new int[GLOBAL_ADDR_MASK+1];
186 mapping_table.initRoutingTableTo(level, indexes, GLOBAL_ROUTING_TABLE);
187
188 LOCAL_ROUTING_TABLE = new int[LOCAL_ADDR_MASK+1];
189 mapping_table.initLocalRoutingTable(level, indexes, LOCAL_ROUTING_TABLE);
190
191 // Checking structural parameters
192
193 if ((NB_TARGET > 16) || (NB_TARGET < 1)) {
194 printf("Error in the SOCLIB_VCI_LOCAL_CROSSBAR component : %s\n", NAME);
195 printf("The NB_TARGET parameter cannot be larger than 16\n");
196 sc_stop();
197 }
198
199 if ((NB_INIT > 16) || (NB_INIT < 1)) {
200 printf("Error in the SOCLIB_VCI_LOCAL_CROSSBAR component : %s\n", NAME);
201 printf("The NB_INIT parameter cannot be larger than 16\n");
202 sc_stop();
203 }
204
205 printf("Successful Instanciation of SOCLIB_VCI_LOCAL_CROSSBAR : %s\n", NAME);
206
207 }; // end constructor
208
209 /////////////////////////////////////////////////////////////
210 // transition()
211 /////////////////////////////////////////////////////////////
212
213 void transition() {
214 // INITIALISATION
215 if (RESETN == false) {
216 for (int n = 0 ; n < NB_TARGET ; n++) {
217 ILOC_ALLOCATED[n] = false;
218 ILOC_INDEX[n] = 0;
219 }
220 for (int n = 0 ; n < NB_INIT ; n++) {
221 TLOC_ALLOCATED[n] = false;
222 TLOC_INDEX[n] = 0;
223 }
224 return;
225 } // end RESETN
226
227 // Loop on the TLOC FSMs
228
229 for(int t = 0 ; t < NB_INIT ; t++) {
230 if(TLOC_ALLOCATED[t] == false) { // local target port not allocated
231 for(int i = 0 ; i < NB_TARGET ; i++) {
232 int l = (i + TLOC_INDEX[t] + 1) % NB_TARGET;
233 if(ILOC_VCI[l].RSPVAL == true) {
234 int id = (int)ILOC_VCI[l].RSRCID.read();
235 int global_index = GLOBAL_ID_OF(id);
236 int local_index = LOCAL_ID_OF(id);
237 if ((global_index == GLOBAL_ID) && (local_index == t)) {
238 TLOC_ALLOCATED[t] = true;
239 TLOC_INDEX[t] = l;
240 break;
241 }
242 }
243 } // end for i
244 } else { // local target port allocated
245 // it is allocated to a local initiator port
246 if((ILOC_VCI[TLOC_INDEX[t]].RSPVAL == true) &&
247 (TLOC_VCI[t].RSPACK == true) &&
248 (ILOC_VCI[TLOC_INDEX[t]].REOP == true)) { TLOC_ALLOCATED[t] = false; }
249 }
250 } // end for t
251
252 // Loop on the ILOC FSMs
253
254 for(int i = 0 ; i < NB_TARGET ; i++) {
255 if(ILOC_ALLOCATED[i] == false) { // local initiator port not allocated
256 for(int t = 0 ; t < NB_INIT ; t++) {
257 int u = (t + ILOC_INDEX[i] + 1) % NB_INIT;
258 if(TLOC_VCI[u].CMDVAL == true) {
259 unsigned int address = TLOC_VCI[u].ADDRESS.read();
260 int global_index = GLOBAL_ROUTING_TABLE[GLOBAL_ADDR_OF(address)];
261 int local_index = LOCAL_ROUTING_TABLE[LOCAL_ADDR_OF(address)];
262 if (local_index == i && global_index == GLOBAL_ID) {
263 ILOC_ALLOCATED[i] = true;
264 ILOC_INDEX[i] = u;
265
266 break;
267 }
268 }
269 } // end for t
270 } else { // local initiator port allocated
271 if((TLOC_VCI[ILOC_INDEX[i]].CMDVAL == true) &&
272 (ILOC_VCI[i].CMDACK == true) &&(TLOC_VCI[ILOC_INDEX[i]].EOP == true))
273 { ILOC_ALLOCATED[i] = false;}
274 }
275 } // end for i
276
277
278 }; // end transition()
279
280 //////////////////////////////////////////////////////:
281 // genMealy()
282 //////////////////////////////////////////////////////:
283
284 void genMealy()
285 {
286
287 // VCI local target ports
288
289 for (int i=0 ; i<NB_INIT ; i++) {
290 if (TLOC_ALLOCATED[i] == true) { // allocated
291 int k = TLOC_INDEX[i];
292
293 TLOC_VCI[i].RSPVAL = ILOC_VCI[k].RSPVAL.read();
294 TLOC_VCI[i].RERROR = ILOC_VCI[k].RERROR.read();
295 TLOC_VCI[i].REOP = ILOC_VCI[k].REOP.read();
296 TLOC_VCI[i].RTRDID = ILOC_VCI[k].RTRDID.read();
297 TLOC_VCI[i].RPKTID = ILOC_VCI[k].RPKTID.read();
298 TLOC_VCI[i].RSRCID = ILOC_VCI[k].RSRCID.read();
299 TLOC_VCI[i].RDATA = ILOC_VCI[k].RDATA.read();
300
301 } else { // not allocated
302 TLOC_VCI[i].RSPVAL = false;
303 TLOC_VCI[i].RERROR = 0;
304 TLOC_VCI[i].REOP = false;
305 TLOC_VCI[i].RTRDID = 0;
306 TLOC_VCI[i].RPKTID = 0;
307 TLOC_VCI[i].RSRCID = 0;
308 TLOC_VCI[i].RDATA = 0;
309 }
310 }//endfor
311
312 // VCI local initiator ports
313
314 for (int i=0 ; i<NB_TARGET ; i++) {
315 if (ILOC_ALLOCATED[i] == true) { // allocated
316 int j = ILOC_INDEX[i];
317
318 ILOC_VCI[i].CMDVAL = TLOC_VCI[j].CMDVAL.read();
319 ILOC_VCI[i].ADDRESS = TLOC_VCI[j].ADDRESS.read();
320 ILOC_VCI[i].WDATA = TLOC_VCI[j].WDATA.read();
321 ILOC_VCI[i].BE = TLOC_VCI[j].BE.read();
322 ILOC_VCI[i].CMD = TLOC_VCI[j].CMD.read();
323 ILOC_VCI[i].PLEN = TLOC_VCI[j].PLEN.read();
324 ILOC_VCI[i].EOP = TLOC_VCI[j].EOP.read();
325 ILOC_VCI[i].CONS = TLOC_VCI[j].CONS.read();
326 ILOC_VCI[i].CONTIG = TLOC_VCI[j].CONTIG.read();
327 ILOC_VCI[i].CFIXED = TLOC_VCI[j].CFIXED.read();
328 ILOC_VCI[i].WRAP = TLOC_VCI[j].WRAP.read();
329 ILOC_VCI[i].CLEN = TLOC_VCI[j].CLEN.read();
330 ILOC_VCI[i].TRDID = TLOC_VCI[j].TRDID.read();
331 ILOC_VCI[i].PKTID = TLOC_VCI[j].PKTID.read();
332 ILOC_VCI[i].SRCID = TLOC_VCI[j].SRCID.read();
333 } else { // not allocated
334 ILOC_VCI[i].CMDVAL = false;
335 ILOC_VCI[i].ADDRESS = 0;
336 ILOC_VCI[i].WDATA = 0;
337 ILOC_VCI[i].BE = 0;
338 ILOC_VCI[i].CMD = 0;
339 ILOC_VCI[i].PLEN = 0;
340 ILOC_VCI[i].EOP = false;
341 ILOC_VCI[i].CONS = false;
342 ILOC_VCI[i].CONTIG = false;
343 ILOC_VCI[i].CFIXED = false;
344 ILOC_VCI[i].WRAP = false;
345 ILOC_VCI[i].CLEN = 0;
346 ILOC_VCI[i].TRDID = 0;
347 ILOC_VCI[i].PKTID = 0;
348 ILOC_VCI[i].SRCID = 0;
349 }
350 } // end for
351
352// Each ack output is controlled by the FSM that is allocated on the VCI port at this time
353
354 //for the ILOCs
355 bool iloc_rspack;
356 for(int j = 0; j<NB_TARGET; j++){
357 iloc_rspack = 0;
358 for ( int i = 0; i<NB_INIT; i++){
359 iloc_rspack = iloc_rspack | ((TLOC_VCI[i].RSPACK)&&(TLOC_ALLOCATED[i])&&(TLOC_INDEX[i]==j));
360 }
361 ILOC_VCI[j].RSPACK=iloc_rspack;
362 }
363
364 //for the TLOCs
365 bool tloc_cmdack;
366 for(int i = 0; i < NB_INIT; i++){
367 tloc_cmdack = 0;
368 for ( int j = 0; j<NB_TARGET; j++){
369 tloc_cmdack = tloc_cmdack | ((ILOC_VCI[j].CMDACK)&&(ILOC_ALLOCATED[j])&&(ILOC_INDEX[j]==i));
370 }
371 TLOC_VCI[i].CMDACK=tloc_cmdack;
372 }
373
374
375 }; // end genMealy()
376
377
378 }; // end structure SOCLIB_VCI_LOCAL_CROSSBAR_SIMPLE
379
380#undef LOCAL_PORT_ALLOCATED
381#undef GLOBAL_ADDR_OF
382#undef LOCAL_ADDR_OF
383#undef GLOBAL_ID_OF
384#undef LOCAL_ID_OF
385
386#endif