OpenCores
URL https://opencores.org/ocsvn/s1_core/s1_core/trunk

Subversion Repositories s1_core

[/] [s1_core/] [trunk/] [hdl/] [rtl/] [s1_top/] [spc2wbm.v] - Blame information for rev 12

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 fafa1971
/*
2
 * Bridge from SPARC Core to Wishbone Master
3
 *
4
 * (C) 2007 Simply RISC LLP
5
 * AUTHOR: Fabrizio Fazzino <fabrizio.fazzino@srisc.com>
6
 *
7
 * LICENSE:
8
 * This is a Free Hardware Design; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * version 2 as published by the Free Software Foundation.
11
 * The above named program is distributed in the hope that it will
12
 * be useful, but WITHOUT ANY WARRANTY; without even the implied
13
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 * See the GNU General Public License for more details.
15
 *
16
 * DESCRIPTION:
17
 * This block implements a bridge from one SPARC Core of the
18
 * OpenSPARC T1 to a master interface that makes use of the
19
 * Wishbone interconnect protocol.
20
 * For informations about Sun Microsystems' OpenSPARC T1
21
 * refer to the web site http://www.opensparc.net
22
 * For informations about OpenCores' Wishbone interconnect
23
 * please refer to the web site http://www.opencores.org
24
 */
25
 
26
`include "s1_defs.h"
27
 
28
module spc2wbm (
29
    sys_clock_i, sys_reset_i, sys_interrupt_source_i,
30
    spc_req_i, spc_atom_i, spc_packetout_i,
31
    spc_grant_o, spc_ready_o, spc_packetin_o, spc_stallreq_o,
32
    wbm_ack_i, wbm_data_i,
33
    wbm_cycle_o, wbm_strobe_o, wbm_we_o, wbm_addr_o, wbm_data_o, wbm_sel_o
34
  );
35
 
36
  /*
37
   * Inputs
38
   */
39
 
40
  // System inputs
41
  input sys_clock_i;                            // System Clock
42
  input sys_reset_i;                            // System Reset
43 11 fafa1971
  input[5:0] sys_interrupt_source_i;            // Encoded Interrupt Source
44 4 fafa1971
 
45
  // SPARC-side inputs connected to the PCX (Processor-to-Cache Xbar) outputs of the SPARC Core
46
  input[4:0] spc_req_i;                         // Request
47
  input spc_atom_i;                             // Atomic Request
48
  input[(`PCX_WIDTH-1):0] spc_packetout_i;      // Outgoing Packet
49
 
50
  // Wishbone Master interface inputs
51
  input wbm_ack_i;                              // Ack
52
  input[(`WB_DATA_WIDTH-1):0] wbm_data_i;       // Data In
53
 
54
  /*
55
   * Registered Outputs
56
   */
57
 
58
  // SPARC-side outputs connected to the CPX (Cache-to-Processor Xbar) inputs of the SPARC Core
59
  output[4:0] spc_grant_o;                      // Grant
60
  reg[4:0] spc_grant_o;                         // Grant
61
  output spc_ready_o;                           // Ready
62
  reg spc_ready_o;                              // Ready
63
  output[`CPX_WIDTH-1:0] spc_packetin_o;        // Incoming Packet
64
  reg[`CPX_WIDTH-1:0] spc_packetin_o;           // Incoming Packet
65
  output spc_stallreq_o;                        // Stall Request
66
  reg spc_stallreq_o;                           // Stall Request
67
 
68
  // Wishbone Master interface outputs
69
  output wbm_cycle_o;                           // Cycle Start
70
  reg wbm_cycle_o;                              // Cycle Start
71
  output wbm_strobe_o;                          // Strobe Request
72
  reg wbm_strobe_o;                             // Strobe Request
73
  output wbm_we_o;                              // Write Enable
74
  reg wbm_we_o;                                 // Write Enable
75
  output[`WB_ADDR_WIDTH-1:0] wbm_addr_o;        // Address Bus
76
  reg[`WB_ADDR_WIDTH-1:0] wbm_addr_o;           // Address Bus
77
  output[`WB_DATA_WIDTH-1:0] wbm_data_o;        // Data Out
78
  reg[`WB_DATA_WIDTH-1:0] wbm_data_o;           // Data Out
79
  output[`WB_DATA_WIDTH/8-1:0] wbm_sel_o;       // Select Output
80
  reg[`WB_DATA_WIDTH/8-1:0] wbm_sel_o;          // Select Output
81
 
82
  /*
83
   * Registers
84
   */
85
 
86
  // Registers to latch requests from SPARC Core to Wishbone Master
87
  reg[3:0] state;
88
  reg[4:0] spc2wbm_region;                                             // Target region number (one-hot encoded)
89 12 fafa1971
  reg spc2wbm_atomic;                                                  // Request is Atomic
90 4 fafa1971
  reg[(`PCX_WIDTH-1):0] spc2wbm_packet;                                // Latched Packet
91
 
92
  // Wishbone Master to SPARC Core info used to encode the return packet
93
  reg wbm2spc_valid;                                                   // Valid
94
  reg[(`CPX_RQ_HI-`CPX_RQ_LO):0] wbm2spc_type;                         // Request type
95 12 fafa1971
  reg wbm2spc_miss;                                                    // L2 Miss
96
  reg[(`CPX_ERR_HI-`CPX_ERR_LO-1):0] wbm2spc_error;                    // Error
97 11 fafa1971
  reg wbm2spc_nc;                                                      // Non-Cacheable
98 4 fafa1971
  reg[(`CPX_TH_HI-`CPX_TH_LO):0] wbm2spc_thread;                       // Thread
99 11 fafa1971
  reg wbm2spc_way_valid;                                               // L2 Way Valid
100
  reg[(`CPX_WY_HI-`CPX_WY_LO):0] wbm2spc_way;                          // Replaced L2 Way
101 12 fafa1971
  reg wbm2spc_boot_fetch;                                              // Fetch for Boot
102
  reg wbm2spc_atomic;                                                  // Atomic LD/ST or 2nd IFill packet
103
  reg wbm2spc_pfl;                                                     // PFL
104 4 fafa1971
  reg[(`CPX_DA_HI-`CPX_DA_LO):0] wbm2spc_data;                         // Load Data
105 11 fafa1971
  reg[6:0] wbm2spc_interrupt_source;                                   // Encoded Interrupt Source
106
  reg wbm2spc_interrupt_new;                                           // New Interrupt Pending
107
 
108
 
109 4 fafa1971
  /*
110
   * Wires
111
   */
112
 
113
  // Decoded SPARC Core to Wishbone Master info
114
  wire spc2wbm_req;                                                     // Request
115
  wire spc2wbm_valid;                                                   // Valid
116
  wire[(`PCX_RQ_HI-`PCX_RQ_LO):0] spc2wbm_type;                         // Request type
117 11 fafa1971
  wire spc2wbm_nc;                                                      // Non-Cacheable
118 4 fafa1971
  wire[(`PCX_CP_HI-`PCX_CP_LO):0] spc2wbm_cpu_id;                       // CPU ID
119
  wire[(`PCX_TH_HI-`PCX_TH_LO):0] spc2wbm_thread;                       // Thread
120 11 fafa1971
  wire spc2wbm_invalidate;                                              // Invalidate all
121
  wire[(`PCX_WY_HI-`PCX_WY_LO):0] spc2wbm_way;                          // Replaced L1 Way
122 4 fafa1971
  wire[(`PCX_SZ_HI-`PCX_SZ_LO):0] spc2wbm_size;                         // Load/Store size
123
  wire[(`PCX_AD_HI-`PCX_AD_LO):0] spc2wbm_addr;                         // Address
124
  wire[(`PCX_DA_HI-`PCX_DA_LO):0] spc2wbm_data;                         // Store Data
125
 
126
  // Return packets assembled with various fields
127 11 fafa1971
  wire[`CPX_WIDTH-1:0] wbm2spc_packet;                                  // Incoming Packet
128 4 fafa1971
 
129
  /*
130
   * Encode/decode incoming info
131
   *
132
   * Legenda: available constants for some of the PCX/CPX fields.
133
   *
134
   * spc2wbm_size (3 bits) is one of:
135
   * - PCX_SZ_1B
136
   * - PCX_SZ_2B
137
   * - PCX_SZ_4B
138
   * - PCX_SZ_8B
139
   * - PCX_SZ_16B (Read accesses only)
140
   *
141
   * spc2wbm_type (5 bits) is one of:
142
   * { LOAD_RQ, IMISS_RQ, STORE_RQ, CAS1_RQ, CAS2_RQ, SWAP_RQ, STRLOAD_RQ, STRST_RQ, STQ_RQ,
143
   *   INT_RQ, FWD_RQ, FWD_RPY, RSVD_RQ }
144
   *
145
   * wbm2spc_type (4 bits) is one of:
146
   * { LOAD_RET, INV_RET, ST_ACK, AT_ACK, INT_RET, TEST_RET, FP_RET, IFILL_RET, EVICT_REQ,
147
   *   ERR_RET, STRLOAD_RET, STRST_ACK, FWD_RQ_RET, FWD_RPY_RET, RSVD_RET }
148
   *
149
   */
150
 
151
  // Decode info arriving from the SPC side
152
  assign spc2wbm_req = ( spc_req_i[4] | spc_req_i[3] | spc_req_i[2] | spc_req_i[1] | spc_req_i[0] );
153
  assign spc2wbm_valid = spc2wbm_packet[`PCX_VLD];
154
  assign spc2wbm_type = spc2wbm_packet[`PCX_RQ_HI:`PCX_RQ_LO];
155 11 fafa1971
  assign spc2wbm_nc = spc2wbm_packet[`PCX_NC];
156 4 fafa1971
  assign spc2wbm_cpu_id = spc2wbm_packet[`PCX_CP_HI:`PCX_CP_LO];
157
  assign spc2wbm_thread = spc2wbm_packet[`PCX_TH_HI:`PCX_TH_LO];
158 11 fafa1971
  assign spc2wbm_invalidate = spc2wbm_packet[`PCX_INVALL];
159
  assign spc2wbm_way = spc2wbm_packet[`PCX_WY_HI:`PCX_WY_LO];
160 4 fafa1971
  assign spc2wbm_size = spc2wbm_packet[`PCX_SZ_HI:`PCX_SZ_LO];
161
  assign spc2wbm_addr = spc2wbm_packet[`PCX_AD_HI:`PCX_AD_LO];
162
  assign spc2wbm_data = spc2wbm_packet[`PCX_DA_HI:`PCX_DA_LO];
163
 
164
  // Encode info going to the SPC side assembling return packets
165 12 fafa1971
  assign wbm2spc_packet = { wbm2spc_valid, wbm2spc_type, wbm2spc_miss, wbm2spc_error, wbm2spc_nc, wbm2spc_thread,
166
    wbm2spc_way_valid, wbm2spc_way, wbm2spc_boot_fetch, wbm2spc_atomic, wbm2spc_pfl, wbm2spc_data };
167 4 fafa1971
 
168
  /*
169
   * State Machine
170
   */
171
 
172
  always @(posedge sys_clock_i) begin
173
 
174
    // Initialization
175
    if(sys_reset_i==1) begin
176
 
177
      // Clear outputs going to SPARC Core inputs
178
      spc_grant_o = 5'b00000;
179
      spc_ready_o = 0;
180
      spc_packetin_o = 0;
181
      spc_stallreq_o = 0;
182
 
183
      // Clear Wishbone Master interface outputs
184
      wbm_cycle_o = 0;
185
      wbm_strobe_o = 0;
186
      wbm_we_o = 0;
187
      wbm_addr_o = 64'b0;
188
      wbm_data_o = 64'b0;
189
      wbm_sel_o = 8'b0;
190
 
191
      // Prepare wakeup packet for SPARC Core, the resulting output is
192
      // spc_packetin_o = `CPX_WIDTH'h1700000000000000000000000000000010001;
193
      wbm2spc_valid = 1;
194
      wbm2spc_type = `INT_RET;
195 12 fafa1971
      wbm2spc_miss = 0;
196 4 fafa1971
      wbm2spc_error = 0;
197 11 fafa1971
      wbm2spc_nc = 0;
198 4 fafa1971
      wbm2spc_thread = 0;
199 11 fafa1971
      wbm2spc_way_valid = 0;
200
      wbm2spc_way = 0;
201 12 fafa1971
      wbm2spc_boot_fetch = 0;
202
      wbm2spc_atomic = 0;
203
      wbm2spc_pfl = 0;
204 11 fafa1971
      wbm2spc_data = 64'h10001;
205 4 fafa1971
 
206
      // Clear state machine
207
      state = `STATE_WAKEUP;
208
 
209
    end else begin
210
 
211
      // FSM State 0: STATE_WAKEUP
212
      // Send to the SPARC Core the wakeup packet
213
      if(state==`STATE_WAKEUP) begin
214
 
215
        // Send wakeup packet
216
        spc_ready_o = 1;
217 11 fafa1971
        spc_packetin_o = wbm2spc_packet;
218 4 fafa1971
 
219
// synopsys translate_off
220
        // Display comment
221
        $display("INFO: SPC2WBM: SPARC Core to Wishbone Master bridge starting...");
222
        $display("INFO: SPC2WBM: Wakeup packet sent to SPARC Core");
223
// synopsys translate_on
224
 
225
        // Unconditional state change
226
        state = `STATE_IDLE;
227
 
228
      // FSM State 1: STATE_IDLE
229
      // Wait for a request from the SPARC Core
230
      // If available send an interrupt packet to the Core
231
      end else if(state==`STATE_IDLE) begin
232
 
233
        // Check if there's an incoming request
234
        if(spc2wbm_req==1) begin
235
 
236
          // Clear previously modified outputs
237
          spc_ready_o = 0;
238
          spc_packetin_o = 0;
239
 
240
          // Stall other requests from the SPARC Core
241
          spc_stallreq_o = 1;
242
 
243
          // Latch target region and atomicity
244
          spc2wbm_region = spc_req_i;
245 12 fafa1971
          spc2wbm_atomic = spc_atom_i;
246 4 fafa1971
 
247
          // Jump to next state
248
          state = `STATE_REQUEST_LATCHED;
249
 
250
        // See if the interrupt vector has changed
251
        end else if(sys_interrupt_source_i!=wbm2spc_interrupt_source) begin
252
 
253
          // Set the flag for next cycle
254 11 fafa1971
          wbm2spc_interrupt_new = 1;
255 4 fafa1971
 
256
          // Prepare the interrupt packet for the SPARC Core
257
          wbm2spc_valid = 1;
258
          wbm2spc_type = `INT_RET;
259 12 fafa1971
          wbm2spc_miss = 0;
260 4 fafa1971
          wbm2spc_error = 0;
261 11 fafa1971
          wbm2spc_nc = 0;
262 4 fafa1971
          wbm2spc_thread = 0;
263 11 fafa1971
          wbm2spc_way_valid = 0;
264
          wbm2spc_way = 0;
265 12 fafa1971
          wbm2spc_boot_fetch = 0;
266
          wbm2spc_atomic = 0;
267
          wbm2spc_pfl = 0;
268 4 fafa1971
 
269
          // Stall other requests from the SPARC Core
270
          spc_stallreq_o = 1;
271
 
272
        // Next cycle see if there's an int to be forwarded to the Core
273 11 fafa1971
        end else if(wbm2spc_interrupt_source!=6'b000000 && wbm2spc_interrupt_new) begin
274 4 fafa1971
 
275
          // Clean the flag
276 11 fafa1971
          wbm2spc_interrupt_new = 0;
277 4 fafa1971
 
278
          // Send the interrupt packet to the Core
279
          spc_ready_o = 1;
280 11 fafa1971
          spc_packetin_o = wbm2spc_packet;
281 4 fafa1971
 
282
          // Stall other requests from the SPARC Core
283
          spc_stallreq_o = 1;
284
 
285
          // Stay in this state
286
          state = `STATE_IDLE;
287
 
288
        // Nothing to do, stay idle
289
        end else begin
290
 
291
          // Clear previously modified outputs
292
          spc_ready_o = 0;
293
          spc_packetin_o = 0;
294
          spc_stallreq_o = 0;
295
 
296
          // Stay in this state
297
          state = `STATE_IDLE;
298
 
299
        end
300
 
301
      // FSM State 2: STATE_REQUEST_LATCHED
302
      // We've just latched the request
303
      // Now we latch the packet
304
      // Start granting the request
305
      end else if(state==`STATE_REQUEST_LATCHED) begin
306
 
307
        // Latch the incoming packet
308
        spc2wbm_packet = spc_packetout_i;
309
 
310
        // Grant the request to the SPARC Core
311
        spc_grant_o = spc2wbm_region;
312
 
313
// synopsys translate_off
314
        // Print details of SPARC Core request
315
        $display("INFO: SPC2WBM: *** NEW REQUEST FROM SPARC CORE ***");
316
        if(spc2wbm_region[0]==1) $display("INFO: SPC2WBM: Request to RAM Bank 0");
317
        else if(spc2wbm_region[1]==1) $display("INFO: SPC2WBM: Request to RAM Bank 1");
318
        else if(spc2wbm_region[2]==1) $display("INFO: SPC2WBM: Request to RAM Bank 2");
319
        else if(spc2wbm_region[3]==1) $display("INFO: SPC2WBM: Request to RAM Bank 3");
320
        else if(spc2wbm_region[4]==1) $display("INFO: SPC2WBM: Request targeted to I/O Block");
321
        else $display("INFO: SPC2WBM: Request to target region unknown");
322 12 fafa1971
        if(spc2wbm_atomic==1) $display("INFO: SPC2WBM: Request is ATOMIC");
323 4 fafa1971
        else $display("INFO: SPC2WBM: Request is not atomic");
324
// synopsys translate_on
325
 
326
        // Unconditional state change
327
        state = `STATE_PACKET_LATCHED;
328
 
329
      // FSM State 3: STATE_PACKET_LATCHED
330
      // The packet has already been latched
331
      // Decode this packet to build the request for the Wishbone bus
332
      // The grant of the request to the SPARC Core has been completed
333
      end else if(state==`STATE_PACKET_LATCHED) begin
334
 
335
        // Clear previously modified outputs
336
        spc_grant_o = 5'b0;
337
 
338
        // Issue a request on the Wishbone bus
339
        wbm_cycle_o = 1;
340
        wbm_strobe_o = 1;
341
        wbm_addr_o = { spc2wbm_region, 19'b0, spc2wbm_addr[`PCX_AD_HI-`PCX_AD_LO:3], 3'b000 };
342
        wbm_data_o = spc2wbm_data;
343
 
344
        // Handle write enable and byte select
345
        if(spc2wbm_type==`IMISS_RQ) begin
346
 
347
          // For instruction miss always read memory
348
          wbm_we_o = 0;
349
          if(spc2wbm_region==5'b10000)
350
            // For accesses to SSI ROM only 32 bits are required
351
            wbm_sel_o = (4'b1111<<(spc2wbm_addr[2]<<2));
352
          else
353
            // For accesses to RAM 256 bits are expected (2 ret packets)
354
            wbm_sel_o = 8'b11111111;
355
 
356 11 fafa1971
        end else if(spc2wbm_type==`LOAD_RQ) begin
357
 
358
          // For data load use the provided data
359
          wbm_we_o = 0;
360
          case(spc2wbm_size)
361
            `PCX_SZ_1B: wbm_sel_o = (1'b1<<spc2wbm_addr[2:0]);
362
            `PCX_SZ_2B: wbm_sel_o = (2'b11<<(spc2wbm_addr[2:1]<<1));
363
            `PCX_SZ_4B: wbm_sel_o = (4'b1111<<(spc2wbm_addr[2]<<2));
364
            `PCX_SZ_8B: wbm_sel_o = 8'b11111111;
365
            `PCX_SZ_16B: wbm_sel_o = 8'b11111111;  // Requires a 2nd access
366
            default: wbm_sel_o = 8'b00000000;
367
          endcase
368 4 fafa1971
 
369 11 fafa1971
        end else if(spc2wbm_type==`STORE_RQ) begin
370
 
371
          // For data store use the provided data
372
          wbm_we_o = 1;
373 4 fafa1971
          case(spc2wbm_size)
374
            `PCX_SZ_1B: wbm_sel_o = (1'b1<<spc2wbm_addr[2:0]);
375
            `PCX_SZ_2B: wbm_sel_o = (2'b11<<(spc2wbm_addr[2:1]<<1));
376
            `PCX_SZ_4B: wbm_sel_o = (4'b1111<<(spc2wbm_addr[2]<<2));
377
            `PCX_SZ_8B: wbm_sel_o = 8'b11111111;
378
            `PCX_SZ_16B: wbm_sel_o = 8'b11111111;  // Requires a 2nd access
379
            default: wbm_sel_o = 8'b00000000;
380
          endcase
381
 
382 11 fafa1971
        end else begin
383
 
384
          wbm_we_o = 1;
385
          wbm_sel_o = 8'b00000000;
386
 
387 4 fafa1971
        end
388
 
389
// synopsys translate_off
390
        // Print details of request packet
391 11 fafa1971
        $display("INFO: SPC2WBM: Valid bit is %X", spc2wbm_valid);
392 4 fafa1971
        case(spc2wbm_type)
393
          `LOAD_RQ: $display("INFO: SPC2WBM: Request of Type LOAD_RQ");
394
          `IMISS_RQ: $display("INFO: SPC2WBM: Request of Type IMISS_RQ");
395
          `STORE_RQ: $display("INFO: SPC2WBM: Request of Type STORE_RQ");
396
          `CAS1_RQ: $display("INFO: SPC2WBM: Request of Type CAS1_RQ");
397
          `CAS2_RQ: $display("INFO: SPC2WBM: Request of Type CAS2_RQ");
398
          `SWAP_RQ: $display("INFO: SPC2WBM: Request of Type SWAP_RQ");
399
          `STRLOAD_RQ: $display("INFO: SPC2WBM: Request of Type STRLOAD_RQ");
400
          `STRST_RQ: $display("INFO: SPC2WBM: Request of Type STRST_RQ");
401
          `STQ_RQ: $display("INFO: SPC2WBM: Request of Type STQ_RQ");
402
          `INT_RQ: $display("INFO: SPC2WBM: Request of Type INT_RQ");
403
          `FWD_RQ: $display("INFO: SPC2WBM: Request of Type FWD_RQ");
404
          `FWD_RPY: $display("INFO: SPC2WBM: Request of Type FWD_RPY");
405
          `RSVD_RQ: $display("INFO: SPC2WBM: Request of Type RSVD_RQ");
406
          default: $display("INFO: SPC2WBM: Request of Type Unknown");
407 11 fafa1971
        endcase
408 12 fafa1971
        $display("INFO: SPC2WBM: Non-Cacheable bit is %X", spc2wbm_nc);
409 11 fafa1971
        $display("INFO: SPC2WBM: CPU-ID is %X", spc2wbm_cpu_id);
410 4 fafa1971
        $display("INFO: SPC2WBM: Thread is %X", spc2wbm_thread);
411 11 fafa1971
        $display("INFO: SPC2WBM: Invalidate All is %X", spc2wbm_invalidate);
412
        $display("INFO: SPC2WBM: Replaced L1 Way is %X", spc2wbm_way);
413 4 fafa1971
        case(spc2wbm_size)
414
          `PCX_SZ_1B: $display("INFO: SPC2WBM: Request size is 1 Byte");
415
          `PCX_SZ_2B: $display("INFO: SPC2WBM: Request size is 2 Bytes");
416
          `PCX_SZ_4B: $display("INFO: SPC2WBM: Request size is 4 Bytes");
417
          `PCX_SZ_8B: $display("INFO: SPC2WBM: Request size is 8 Bytes");
418
          `PCX_SZ_16B: $display("INFO: SPC2WBM: Request size is 16 Bytes");
419
          default: $display("INFO: SPC2WBM: Request size is Unknown");
420
        endcase
421
        $display("INFO: SPC2WBM: Address is %X", spc2wbm_addr);
422
        $display("INFO: SPC2WBM: Data is %X", spc2wbm_data);
423
// synopsys translate_on
424
 
425
        // Unconditional state change
426
        state = `STATE_REQUEST_GRANTED;
427
 
428
      // FSM State 4: STATE_REQUEST_GRANTED
429
      // Wishbone access completed, latch the incoming data
430
      end else if(state==`STATE_REQUEST_GRANTED) begin
431
 
432
        // Wait until Wishbone access completes
433
        if(wbm_ack_i==1) begin
434
 
435
          // Clear previously modified outputs
436 12 fafa1971
          if(spc2wbm_atomic==0) wbm_cycle_o = 0;
437 4 fafa1971
          wbm_strobe_o = 0;
438
          wbm_we_o = 0;
439
          wbm_addr_o = 64'b0;
440
          wbm_data_o = 64'b0;
441
          wbm_sel_o = 8'b0;
442
 
443
          // Latch the data and set up the return packet for the SPARC Core
444
          wbm2spc_valid = 1;
445
          case(spc2wbm_type)
446
            `IMISS_RQ: begin
447
              wbm2spc_type = `IFILL_RET; // I-Cache Miss
448 12 fafa1971
              wbm2spc_atomic = 0;
449 4 fafa1971
            end
450
            `LOAD_RQ: begin
451 11 fafa1971
              wbm2spc_type = `LOAD_RET;  // Load
452 12 fafa1971
              wbm2spc_atomic = spc2wbm_atomic;
453 4 fafa1971
            end
454
            `STORE_RQ: begin
455
              wbm2spc_type = `ST_ACK;    // Store
456 12 fafa1971
              wbm2spc_atomic = spc2wbm_atomic;
457 4 fafa1971
            end
458
          endcase
459 12 fafa1971
          wbm2spc_miss = 0;
460 4 fafa1971
          wbm2spc_error = 0;
461 11 fafa1971
          wbm2spc_nc = spc2wbm_nc;
462 4 fafa1971
          wbm2spc_thread = spc2wbm_thread;
463 11 fafa1971
          wbm2spc_way_valid = 0;
464
          wbm2spc_way = 0;
465 12 fafa1971
          if(spc2wbm_region==5'b10000) wbm2spc_boot_fetch = 1;
466
          else wbm2spc_boot_fetch = 0;
467
          wbm2spc_pfl = 0;
468 11 fafa1971
          if(spc2wbm_addr[3]==0) wbm2spc_data = { wbm_data_i, 64'b0 };
469
          else wbm2spc_data = { 64'b0, wbm_data_i };
470 4 fafa1971
 
471
          // See if other 64-bit Wishbone accesses are required
472
          if(
473
              // Instruction miss directed to RAM expects 256 bits
474
              ( (spc2wbm_type==`IMISS_RQ)&&(spc2wbm_region!=5'b10000) ) ||
475
              // Data access of 128 bits
476
              ( (spc2wbm_type==`LOAD_RQ)&&(spc2wbm_size==`PCX_SZ_16B) )
477
            )
478
            state = `STATE_ACCESS2_BEGIN;
479
          else
480
            state = `STATE_PACKET_READY;
481
 
482
        end else state = `STATE_REQUEST_GRANTED;
483
 
484
      // FSM State 5: STATE_ACCESS2_BEGIN
485
      // If needed start a second read access to the Wishbone bus
486
      end else if(state==`STATE_ACCESS2_BEGIN) begin
487
 
488
        // Issue a second request on the Wishbone bus
489
        wbm_cycle_o = 1;
490
        wbm_strobe_o = 1;
491
        wbm_we_o = 0;
492
        wbm_addr_o = { spc2wbm_region, 19'b0, spc2wbm_addr[`PCX_AD_HI-`PCX_AD_LO:4], 4'b1000 };  // 2nd doubleword inside the same quadword
493
        wbm_data_o = 64'b0;
494
        wbm_sel_o = 8'b11111111;
495
 
496
        // Unconditional state change
497
        state = `STATE_ACCESS2_END;
498
 
499
      // FSM State 6: STATE_ACCESS2_END
500
      // Latch the second data returning from Wishbone when ready
501
      end else if(state==`STATE_ACCESS2_END) begin
502
 
503
        // Wait until Wishbone access completes
504
        if(wbm_ack_i==1) begin
505
 
506
          // Clear previously modified outputs
507 12 fafa1971
          if(spc2wbm_atomic==0) wbm_cycle_o = 0;
508 4 fafa1971
          wbm_strobe_o = 0;
509
          wbm_we_o = 0;
510
          wbm_addr_o = 64'b0;
511
          wbm_data_o = 64'b0;
512
          wbm_sel_o = 8'b0;
513
 
514
          // Latch the data and set up the return packet for the SPARC Core
515
          wbm2spc_data[63:0] = wbm_data_i;
516
 
517
          // See if two return packets are required or just one
518
          if(spc2wbm_type==`IMISS_RQ && spc2wbm_region==5'b10000)
519
            state = `STATE_PACKET_READY;
520
          else
521
            state = `STATE_ACCESS3_BEGIN;
522
 
523
        end else state = `STATE_ACCESS2_END;
524
 
525
      // FSM State 7: STATE_ACCESS3_BEGIN
526
      // If needed start a third read access to the Wishbone bus
527
      // In the meanwhile we can return the first 128-bit packet
528
      end else if(state==`STATE_ACCESS3_BEGIN) begin
529
 
530
        // Return the packet to the SPARC Core
531
        spc_ready_o = 1;
532 11 fafa1971
        spc_packetin_o = wbm2spc_packet;
533 4 fafa1971
 
534
        // Issue a third request on the Wishbone bus
535
        wbm_cycle_o = 1;
536
        wbm_strobe_o = 1;
537
        wbm_we_o = 0;
538
        wbm_addr_o = { spc2wbm_region, 19'b0, spc2wbm_addr[`PCX_AD_HI-`PCX_AD_LO:5], 5'b10000 };  // 3nd doubleword inside the same 256-bit data
539
        wbm_data_o = 64'b0;
540
        wbm_sel_o = 8'b11111111;
541
 
542
// synopsys translate_off
543
        // Print details of return packet
544 12 fafa1971
        $display("INFO: WBM2SPC: *** RETURN PACKET TO SPARC CORE ***");
545
        $display("INFO: WBM2SPC: Valid bit is %X", wbm2spc_valid);
546 4 fafa1971
        case(wbm2spc_type)
547
          `IFILL_RET: $display("INFO: WBM2SPC: Return Packet of Type IFILL_RET");
548
          `LOAD_RET: $display("INFO: WBM2SPC: Return Packet of Type LOAD_RET");
549
          `ST_ACK: $display("INFO: WBM2SPC: Return Packet of Type ST_ACK");
550
          default: $display("INFO: WBM2SPC: Return Packet of Type Unknown");
551
        endcase
552 12 fafa1971
        $display("INFO: WBM2SPC: L2 Miss is %X", wbm2spc_miss);
553 11 fafa1971
        $display("INFO: WBM2SPC: Error is %X", wbm2spc_error);
554 12 fafa1971
        $display("INFO: WBM2SPC: Non-Cacheable bit is %X", wbm2spc_nc);
555 4 fafa1971
        $display("INFO: WBM2SPC: Thread is %X", wbm2spc_thread);
556 11 fafa1971
        $display("INFO: WBM2SPC: Way Valid is %X", wbm2spc_way_valid);
557
        $display("INFO: WBM2SPC: Replaced L2 Way is %X", wbm2spc_way);
558 12 fafa1971
        $display("INFO: WBM2SPC: Fetch for Boot is %X", wbm2spc_boot_fetch);
559
        $display("INFO: WBM2SPC: Atomic LD/ST or 2nd IFill Packet is %X", wbm2spc_atomic);
560
        $display("INFO: WBM2SPC: PFL is %X", wbm2spc_pfl);
561 4 fafa1971
        $display("INFO: WBM2SPC: Data is %X", wbm2spc_data);
562
// synopsys translate_on
563
 
564
        // Unconditional state change
565
        state = `STATE_ACCESS3_END;
566
 
567
      // FSM State 8: STATE_ACCESS3_END
568
      // Latch the second data returning from Wishbone when ready
569
      end else if(state==`STATE_ACCESS3_END) begin
570
 
571
        // Clear previously modified outputs
572
        spc_ready_o = 0;
573
 
574
        // Wait until Wishbone access completes
575
        if(wbm_ack_i==1) begin
576
 
577
          // Clear previously modified outputs
578 12 fafa1971
          if(spc2wbm_atomic==0) wbm_cycle_o = 0;
579 4 fafa1971
          wbm_strobe_o = 0;
580
          wbm_we_o = 0;
581
          wbm_addr_o = 64'b0;
582
          wbm_data_o = 64'b0;
583
          wbm_sel_o = 8'b0;
584
 
585
          // Latch the data and set up the return packet for the SPARC Core
586
          wbm2spc_data = { wbm_data_i, 64'b0 };
587
 
588
          // Jump to next state
589
          state = `STATE_ACCESS4_BEGIN;
590
 
591
        end else state = `STATE_ACCESS3_END;
592
 
593
      // FSM State 9: STATE_ACCESS4_BEGIN
594
      // If needed start a second read access to the Wishbone bus
595
      end else if(state==`STATE_ACCESS4_BEGIN) begin
596
 
597
        // Issue a fourth request on the Wishbone bus
598
        wbm_cycle_o = 1;
599
        wbm_strobe_o = 1;
600
        wbm_we_o = 0;
601
        wbm_addr_o = { spc2wbm_region, 19'b0, spc2wbm_addr[`PCX_AD_HI-`PCX_AD_LO:5], 5'b11000 };  // 4th doubleword inside the same 256-bit data
602
        wbm_data_o = 64'b0;
603
        wbm_sel_o = 8'b11111111;
604
 
605
        // Unconditional state change
606
        state = `STATE_ACCESS4_END;
607
 
608
      // FSM State 10: STATE_ACCESS4_END
609
      // Latch the second data returning from Wishbone when ready
610
      end else if(state==`STATE_ACCESS4_END) begin
611
 
612
        // Wait until Wishbone access completes
613
        if(wbm_ack_i==1) begin
614
 
615
          // Clear previously modified outputs
616 12 fafa1971
          if(spc2wbm_atomic==0) wbm_cycle_o = 0;
617 4 fafa1971
          wbm_strobe_o = 0;
618
          wbm_we_o = 0;
619
          wbm_addr_o = 64'b0;
620
          wbm_data_o = 64'b0;
621
          wbm_sel_o = 8'b0;
622
 
623
          // Latch the data and set up the return packet for the SPARC Core
624 12 fafa1971
          wbm2spc_atomic = 1;
625 4 fafa1971
          wbm2spc_data[63:0] = wbm_data_i;
626
 
627
          // Jump to next state
628
          state = `STATE_PACKET_READY;
629
 
630
        end else state = `STATE_ACCESS4_END;
631
 
632
      // FSM State 11: STATE_PACKET_READY
633
      // We can start returning the packet to the SPARC Core
634
      end else if(state==`STATE_PACKET_READY) begin
635
 
636
        // Return the packet to the SPARC Core
637
        spc_ready_o = 1;
638 11 fafa1971
        spc_packetin_o = wbm2spc_packet;
639 4 fafa1971
 
640
        // Unconditional state change
641
        state = `STATE_IDLE;
642
 
643
// synopsys translate_off
644
        // Print details of return packet
645 12 fafa1971
        $display("INFO: WBM2SPC: *** RETURN PACKET TO SPARC CORE ***");
646 11 fafa1971
        $display("INFO: WBM2SPC: Valid bit is %X", wbm2spc_valid);
647 4 fafa1971
        case(wbm2spc_type)
648
          `IFILL_RET: $display("INFO: WBM2SPC: Return Packet of Type IFILL_RET");
649
          `LOAD_RET: $display("INFO: WBM2SPC: Return Packet of Type LOAD_RET");
650
          `ST_ACK: $display("INFO: WBM2SPC: Return Packet of Type ST_ACK");
651
          default: $display("INFO: WBM2SPC: Return Packet of Type Unknown");
652
        endcase
653 12 fafa1971
        $display("INFO: WBM2SPC: L2 Miss is %X", wbm2spc_miss);
654 11 fafa1971
        $display("INFO: WBM2SPC: Error is %X", wbm2spc_error);
655
        $display("INFO: WBM2SPC: Non-Cacheable bit is %X", wbm2spc_nc);
656 4 fafa1971
        $display("INFO: WBM2SPC: Thread is %X", wbm2spc_thread);
657 11 fafa1971
        $display("INFO: WBM2SPC: Way Valid is %X", wbm2spc_way_valid);
658
        $display("INFO: WBM2SPC: Replaced L2 Way is %X", wbm2spc_way);
659 12 fafa1971
        $display("INFO: WBM2SPC: Fetch for Boot is %X", wbm2spc_boot_fetch);
660
        $display("INFO: WBM2SPC: Atomic LD/ST or 2nd IFill Packet is %X", wbm2spc_atomic);
661
        $display("INFO: WBM2SPC: PFL is %X", wbm2spc_pfl);
662 4 fafa1971
        $display("INFO: WBM2SPC: Data is %X", wbm2spc_data);
663
// synopsys translate_on
664
 
665
      end
666
    end
667
  end
668
 
669
endmodule
670
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.