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 51

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 51 fafa1971
      spc_grant_o <= 5'b00000;
179
      spc_ready_o <= 0;
180
      spc_packetin_o <= 0;
181
      spc_stallreq_o <= 0;
182 4 fafa1971
 
183
      // Clear Wishbone Master interface outputs
184 51 fafa1971
      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 4 fafa1971
 
191
      // Prepare wakeup packet for SPARC Core, the resulting output is
192 51 fafa1971
      // spc_packetin_o <= `CPX_WIDTH'h1700000000000000000000000000000010001;
193
      wbm2spc_valid <= 1;
194
      wbm2spc_type <= `INT_RET;
195
      wbm2spc_miss <= 0;
196
      wbm2spc_error <= 0;
197
      wbm2spc_nc <= 0;
198
      wbm2spc_thread <= 0;
199
      wbm2spc_way_valid <= 0;
200
      wbm2spc_way <= 0;
201
      wbm2spc_boot_fetch <= 0;
202
      wbm2spc_atomic <= 0;
203
      wbm2spc_pfl <= 0;
204
      wbm2spc_data <= 64'h10001;
205 4 fafa1971
 
206 51 fafa1971
      // EDIT vvvv (uinitialized variables)
207
      wbm2spc_interrupt_source <= 7'h0;
208
      wbm2spc_interrupt_new <= 1'b0;
209
      // EDIT ^^^^
210
 
211 4 fafa1971
      // Clear state machine
212 51 fafa1971
      state <= `STATE_WAKEUP;
213 4 fafa1971
 
214
    end else begin
215
 
216
      // FSM State 0: STATE_WAKEUP
217
      // Send to the SPARC Core the wakeup packet
218
      if(state==`STATE_WAKEUP) begin
219
 
220
        // Send wakeup packet
221 51 fafa1971
        spc_ready_o <= 1;
222
        spc_packetin_o <= wbm2spc_packet;
223 4 fafa1971
 
224
// synopsys translate_off
225
        // Display comment
226 51 fafa1971
`ifdef DEBUG
227 4 fafa1971
        $display("INFO: SPC2WBM: SPARC Core to Wishbone Master bridge starting...");
228
        $display("INFO: SPC2WBM: Wakeup packet sent to SPARC Core");
229 51 fafa1971
`endif
230 4 fafa1971
// synopsys translate_on
231
 
232
        // Unconditional state change
233 51 fafa1971
        state <= `STATE_IDLE;
234 4 fafa1971
 
235
      // FSM State 1: STATE_IDLE
236
      // Wait for a request from the SPARC Core
237
      // If available send an interrupt packet to the Core
238
      end else if(state==`STATE_IDLE) begin
239
 
240
        // Check if there's an incoming request
241
        if(spc2wbm_req==1) begin
242
 
243
          // Clear previously modified outputs
244 51 fafa1971
          spc_ready_o <= 0;
245
          spc_packetin_o <= 0;
246 4 fafa1971
 
247
          // Stall other requests from the SPARC Core
248 51 fafa1971
          spc_stallreq_o <= 1;
249 4 fafa1971
 
250
          // Latch target region and atomicity
251 51 fafa1971
          spc2wbm_region <= spc_req_i;
252
          spc2wbm_atomic <= spc_atom_i;
253 4 fafa1971
 
254
          // Jump to next state
255 51 fafa1971
          state <= `STATE_REQUEST_LATCHED;
256 4 fafa1971
 
257
        // See if the interrupt vector has changed
258
        end else if(sys_interrupt_source_i!=wbm2spc_interrupt_source) begin
259
 
260
          // Set the flag for next cycle
261 51 fafa1971
          wbm2spc_interrupt_new <= 1;
262 4 fafa1971
 
263
          // Prepare the interrupt packet for the SPARC Core
264 51 fafa1971
          wbm2spc_valid <= 1;
265
          wbm2spc_type <= `INT_RET;
266
          wbm2spc_miss <= 0;
267
          wbm2spc_error <= 0;
268
          wbm2spc_nc <= 0;
269
          wbm2spc_thread <= 0;
270
          wbm2spc_way_valid <= 0;
271
          wbm2spc_way <= 0;
272
          wbm2spc_boot_fetch <= 0;
273
          wbm2spc_atomic <= 0;
274
          wbm2spc_pfl <= 0;
275 4 fafa1971
 
276
          // Stall other requests from the SPARC Core
277 51 fafa1971
          spc_stallreq_o <= 1;
278 4 fafa1971
 
279
        // Next cycle see if there's an int to be forwarded to the Core
280 11 fafa1971
        end else if(wbm2spc_interrupt_source!=6'b000000 && wbm2spc_interrupt_new) begin
281 4 fafa1971
 
282
          // Clean the flag
283 51 fafa1971
          wbm2spc_interrupt_new <= 0;
284 4 fafa1971
 
285
          // Send the interrupt packet to the Core
286 51 fafa1971
          spc_ready_o <= 1;
287
          spc_packetin_o <= wbm2spc_packet;
288 4 fafa1971
 
289
          // Stall other requests from the SPARC Core
290 51 fafa1971
          spc_stallreq_o <= 1;
291 4 fafa1971
 
292
          // Stay in this state
293 51 fafa1971
          state <= `STATE_IDLE;
294 4 fafa1971
 
295
        // Nothing to do, stay idle
296
        end else begin
297
 
298
          // Clear previously modified outputs
299 51 fafa1971
          spc_ready_o <= 0;
300
          spc_packetin_o <= 0;
301
          spc_stallreq_o <= 0;
302 4 fafa1971
 
303
          // Stay in this state
304 51 fafa1971
          state <= `STATE_IDLE;
305 4 fafa1971
 
306
        end
307
 
308
      // FSM State 2: STATE_REQUEST_LATCHED
309
      // We've just latched the request
310
      // Now we latch the packet
311
      // Start granting the request
312
      end else if(state==`STATE_REQUEST_LATCHED) begin
313
 
314
        // Latch the incoming packet
315 51 fafa1971
        spc2wbm_packet <= spc_packetout_i;
316 4 fafa1971
 
317
        // Grant the request to the SPARC Core
318 51 fafa1971
        spc_grant_o <= spc2wbm_region;
319 4 fafa1971
 
320
// synopsys translate_off
321
        // Print details of SPARC Core request
322 51 fafa1971
`ifdef DEBUG
323 4 fafa1971
        $display("INFO: SPC2WBM: *** NEW REQUEST FROM SPARC CORE ***");
324
        if(spc2wbm_region[0]==1) $display("INFO: SPC2WBM: Request to RAM Bank 0");
325
        else if(spc2wbm_region[1]==1) $display("INFO: SPC2WBM: Request to RAM Bank 1");
326
        else if(spc2wbm_region[2]==1) $display("INFO: SPC2WBM: Request to RAM Bank 2");
327
        else if(spc2wbm_region[3]==1) $display("INFO: SPC2WBM: Request to RAM Bank 3");
328
        else if(spc2wbm_region[4]==1) $display("INFO: SPC2WBM: Request targeted to I/O Block");
329
        else $display("INFO: SPC2WBM: Request to target region unknown");
330 12 fafa1971
        if(spc2wbm_atomic==1) $display("INFO: SPC2WBM: Request is ATOMIC");
331 4 fafa1971
        else $display("INFO: SPC2WBM: Request is not atomic");
332 51 fafa1971
`endif
333 4 fafa1971
// synopsys translate_on
334
 
335
        // Unconditional state change
336 51 fafa1971
        state <= `STATE_PACKET_LATCHED;
337 4 fafa1971
 
338
      // FSM State 3: STATE_PACKET_LATCHED
339
      // The packet has already been latched
340
      // Decode this packet to build the request for the Wishbone bus
341
      // The grant of the request to the SPARC Core has been completed
342
      end else if(state==`STATE_PACKET_LATCHED) begin
343
 
344
        // Clear previously modified outputs
345 51 fafa1971
        spc_grant_o <= 5'b0;
346 4 fafa1971
 
347
        // Issue a request on the Wishbone bus
348 51 fafa1971
        wbm_cycle_o <= 1;
349
        wbm_strobe_o <= 1;
350
        wbm_addr_o <= { spc2wbm_region, 19'b0, spc2wbm_addr[`PCX_AD_HI-`PCX_AD_LO:3], 3'b000 };
351
        wbm_data_o <= spc2wbm_data;
352 4 fafa1971
 
353
        // Handle write enable and byte select
354
        if(spc2wbm_type==`IMISS_RQ) begin
355
 
356
          // For instruction miss always read memory
357 51 fafa1971
          wbm_we_o <= 0;
358 4 fafa1971
          if(spc2wbm_region==5'b10000)
359
            // For accesses to SSI ROM only 32 bits are required
360 51 fafa1971
            wbm_sel_o <= (4'b1111<<(spc2wbm_addr[2]<<2));
361 4 fafa1971
          else
362
            // For accesses to RAM 256 bits are expected (2 ret packets)
363 51 fafa1971
            wbm_sel_o <= 8'b11111111;
364 4 fafa1971
 
365 11 fafa1971
        end else if(spc2wbm_type==`LOAD_RQ) begin
366
 
367
          // For data load use the provided data
368 51 fafa1971
          wbm_we_o <= 0;
369 11 fafa1971
          case(spc2wbm_size)
370 51 fafa1971
            `PCX_SZ_1B: wbm_sel_o <= (1'b1<<spc2wbm_addr[2:0]);
371
            `PCX_SZ_2B: wbm_sel_o <= (2'b11<<(spc2wbm_addr[2:1]<<1));
372
            `PCX_SZ_4B: wbm_sel_o <= (4'b1111<<(spc2wbm_addr[2]<<2));
373
            `PCX_SZ_8B: wbm_sel_o <= 8'b11111111;
374
            `PCX_SZ_16B: wbm_sel_o <= 8'b11111111;  // Requires a 2nd access
375
            default: wbm_sel_o <= 8'b00000000;
376 11 fafa1971
          endcase
377 4 fafa1971
 
378 11 fafa1971
        end else if(spc2wbm_type==`STORE_RQ) begin
379
 
380
          // For data store use the provided data
381 51 fafa1971
          wbm_we_o <= 1;
382 4 fafa1971
          case(spc2wbm_size)
383 51 fafa1971
            `PCX_SZ_1B: wbm_sel_o <= (1'b1<<spc2wbm_addr[2:0]);
384
            `PCX_SZ_2B: wbm_sel_o <= (2'b11<<(spc2wbm_addr[2:1]<<1));
385
            `PCX_SZ_4B: wbm_sel_o <= (4'b1111<<(spc2wbm_addr[2]<<2));
386
            `PCX_SZ_8B: wbm_sel_o <= 8'b11111111;
387
            `PCX_SZ_16B: wbm_sel_o <= 8'b11111111;  // Requires a 2nd access
388
            default: wbm_sel_o <= 8'b00000000;
389 4 fafa1971
          endcase
390
 
391 11 fafa1971
        end else begin
392
 
393 51 fafa1971
          wbm_we_o <= 1;
394
          wbm_sel_o <= 8'b00000000;
395 11 fafa1971
 
396 4 fafa1971
        end
397
 
398
// synopsys translate_off
399
        // Print details of request packet
400 51 fafa1971
`ifdef DEBUG
401 11 fafa1971
        $display("INFO: SPC2WBM: Valid bit is %X", spc2wbm_valid);
402 4 fafa1971
        case(spc2wbm_type)
403
          `LOAD_RQ: $display("INFO: SPC2WBM: Request of Type LOAD_RQ");
404
          `IMISS_RQ: $display("INFO: SPC2WBM: Request of Type IMISS_RQ");
405
          `STORE_RQ: $display("INFO: SPC2WBM: Request of Type STORE_RQ");
406
          `CAS1_RQ: $display("INFO: SPC2WBM: Request of Type CAS1_RQ");
407
          `CAS2_RQ: $display("INFO: SPC2WBM: Request of Type CAS2_RQ");
408
          `SWAP_RQ: $display("INFO: SPC2WBM: Request of Type SWAP_RQ");
409
          `STRLOAD_RQ: $display("INFO: SPC2WBM: Request of Type STRLOAD_RQ");
410
          `STRST_RQ: $display("INFO: SPC2WBM: Request of Type STRST_RQ");
411
          `STQ_RQ: $display("INFO: SPC2WBM: Request of Type STQ_RQ");
412
          `INT_RQ: $display("INFO: SPC2WBM: Request of Type INT_RQ");
413
          `FWD_RQ: $display("INFO: SPC2WBM: Request of Type FWD_RQ");
414
          `FWD_RPY: $display("INFO: SPC2WBM: Request of Type FWD_RPY");
415
          `RSVD_RQ: $display("INFO: SPC2WBM: Request of Type RSVD_RQ");
416
          default: $display("INFO: SPC2WBM: Request of Type Unknown");
417 11 fafa1971
        endcase
418 12 fafa1971
        $display("INFO: SPC2WBM: Non-Cacheable bit is %X", spc2wbm_nc);
419 11 fafa1971
        $display("INFO: SPC2WBM: CPU-ID is %X", spc2wbm_cpu_id);
420 4 fafa1971
        $display("INFO: SPC2WBM: Thread is %X", spc2wbm_thread);
421 11 fafa1971
        $display("INFO: SPC2WBM: Invalidate All is %X", spc2wbm_invalidate);
422
        $display("INFO: SPC2WBM: Replaced L1 Way is %X", spc2wbm_way);
423 4 fafa1971
        case(spc2wbm_size)
424
          `PCX_SZ_1B: $display("INFO: SPC2WBM: Request size is 1 Byte");
425
          `PCX_SZ_2B: $display("INFO: SPC2WBM: Request size is 2 Bytes");
426
          `PCX_SZ_4B: $display("INFO: SPC2WBM: Request size is 4 Bytes");
427
          `PCX_SZ_8B: $display("INFO: SPC2WBM: Request size is 8 Bytes");
428
          `PCX_SZ_16B: $display("INFO: SPC2WBM: Request size is 16 Bytes");
429
          default: $display("INFO: SPC2WBM: Request size is Unknown");
430
        endcase
431
        $display("INFO: SPC2WBM: Address is %X", spc2wbm_addr);
432
        $display("INFO: SPC2WBM: Data is %X", spc2wbm_data);
433 51 fafa1971
`endif
434 4 fafa1971
// synopsys translate_on
435
 
436
        // Unconditional state change
437 51 fafa1971
        state <= `STATE_REQUEST_GRANTED;
438 4 fafa1971
 
439
      // FSM State 4: STATE_REQUEST_GRANTED
440
      // Wishbone access completed, latch the incoming data
441
      end else if(state==`STATE_REQUEST_GRANTED) begin
442
 
443
        // Wait until Wishbone access completes
444
        if(wbm_ack_i==1) begin
445
 
446
          // Clear previously modified outputs
447 51 fafa1971
          if(spc2wbm_atomic==0) wbm_cycle_o <= 0;
448
          wbm_strobe_o <= 0;
449
          wbm_we_o <= 0;
450
          wbm_addr_o <= 64'b0;
451
          wbm_data_o <= 64'b0;
452
          wbm_sel_o <= 8'b0;
453 4 fafa1971
 
454
          // Latch the data and set up the return packet for the SPARC Core
455 51 fafa1971
          wbm2spc_valid <= 1;
456 4 fafa1971
          case(spc2wbm_type)
457
            `IMISS_RQ: begin
458 51 fafa1971
              wbm2spc_type <= `IFILL_RET; // I-Cache Miss
459
              wbm2spc_atomic <= 0;
460 4 fafa1971
            end
461
            `LOAD_RQ: begin
462 51 fafa1971
              wbm2spc_type <= `LOAD_RET;  // Load
463
              wbm2spc_atomic <= spc2wbm_atomic;
464 4 fafa1971
            end
465
            `STORE_RQ: begin
466 51 fafa1971
              wbm2spc_type <= `ST_ACK;    // Store
467
              wbm2spc_atomic <= spc2wbm_atomic;
468 4 fafa1971
            end
469
          endcase
470 51 fafa1971
          wbm2spc_miss <= 0;
471
          wbm2spc_error <= 0;
472
          wbm2spc_nc <= spc2wbm_nc;
473
          wbm2spc_thread <= spc2wbm_thread;
474
          wbm2spc_way_valid <= 0;
475
          wbm2spc_way <= 0;
476
          if(spc2wbm_region==5'b10000) wbm2spc_boot_fetch <= 1;
477
          else wbm2spc_boot_fetch <= 0;
478
          wbm2spc_pfl <= 0;
479
          if(spc2wbm_addr[3]==0) wbm2spc_data <= { wbm_data_i, 64'b0 };
480
          else wbm2spc_data <= { 64'b0, wbm_data_i };
481 4 fafa1971
 
482
          // See if other 64-bit Wishbone accesses are required
483
          if(
484
              // Instruction miss directed to RAM expects 256 bits
485
              ( (spc2wbm_type==`IMISS_RQ)&&(spc2wbm_region!=5'b10000) ) ||
486
              // Data access of 128 bits
487
              ( (spc2wbm_type==`LOAD_RQ)&&(spc2wbm_size==`PCX_SZ_16B) )
488
            )
489 51 fafa1971
            state <= `STATE_ACCESS2_BEGIN;
490 4 fafa1971
          else
491 51 fafa1971
            state <= `STATE_PACKET_READY;
492 4 fafa1971
 
493 51 fafa1971
        end else state <= `STATE_REQUEST_GRANTED;
494 4 fafa1971
 
495
      // FSM State 5: STATE_ACCESS2_BEGIN
496
      // If needed start a second read access to the Wishbone bus
497
      end else if(state==`STATE_ACCESS2_BEGIN) begin
498
 
499
        // Issue a second request on the Wishbone bus
500 51 fafa1971
        wbm_cycle_o <= 1;
501
        wbm_strobe_o <= 1;
502
        wbm_we_o <= 0;
503
        wbm_addr_o <= { spc2wbm_region, 19'b0, spc2wbm_addr[`PCX_AD_HI-`PCX_AD_LO:4], 4'b1000 };  // 2nd doubleword inside the same quadword
504
        wbm_data_o <= 64'b0;
505
        wbm_sel_o <= 8'b11111111;
506 4 fafa1971
 
507
        // Unconditional state change
508 51 fafa1971
        state <= `STATE_ACCESS2_END;
509 4 fafa1971
 
510
      // FSM State 6: STATE_ACCESS2_END
511
      // Latch the second data returning from Wishbone when ready
512
      end else if(state==`STATE_ACCESS2_END) begin
513
 
514
        // Wait until Wishbone access completes
515
        if(wbm_ack_i==1) begin
516
 
517
          // Clear previously modified outputs
518 51 fafa1971
          if(spc2wbm_atomic==0) wbm_cycle_o <= 0;
519
          wbm_strobe_o <= 0;
520
          wbm_we_o <= 0;
521
          wbm_addr_o <= 64'b0;
522
          wbm_data_o <= 64'b0;
523
          wbm_sel_o <= 8'b0;
524 4 fafa1971
 
525
          // Latch the data and set up the return packet for the SPARC Core
526 51 fafa1971
          wbm2spc_data[63:0] <= wbm_data_i;
527 4 fafa1971
 
528
          // See if two return packets are required or just one
529
          if(spc2wbm_type==`IMISS_RQ && spc2wbm_region==5'b10000)
530 51 fafa1971
            state <= `STATE_PACKET_READY;
531 4 fafa1971
          else
532 51 fafa1971
            state <= `STATE_ACCESS3_BEGIN;
533 4 fafa1971
 
534 51 fafa1971
        end else state <= `STATE_ACCESS2_END;
535 4 fafa1971
 
536
      // FSM State 7: STATE_ACCESS3_BEGIN
537
      // If needed start a third read access to the Wishbone bus
538
      // In the meanwhile we can return the first 128-bit packet
539
      end else if(state==`STATE_ACCESS3_BEGIN) begin
540
 
541
        // Return the packet to the SPARC Core
542 51 fafa1971
        spc_ready_o <= 1;
543
        spc_packetin_o <= wbm2spc_packet;
544 4 fafa1971
 
545
        // Issue a third request on the Wishbone bus
546 51 fafa1971
        wbm_cycle_o <= 1;
547
        wbm_strobe_o <= 1;
548
        wbm_we_o <= 0;
549
        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
550
        wbm_data_o <= 64'b0;
551
        wbm_sel_o <= 8'b11111111;
552 4 fafa1971
 
553
// synopsys translate_off
554
        // Print details of return packet
555 51 fafa1971
`ifdef DEBUG
556 12 fafa1971
        $display("INFO: WBM2SPC: *** RETURN PACKET TO SPARC CORE ***");
557
        $display("INFO: WBM2SPC: Valid bit is %X", wbm2spc_valid);
558 4 fafa1971
        case(wbm2spc_type)
559
          `IFILL_RET: $display("INFO: WBM2SPC: Return Packet of Type IFILL_RET");
560
          `LOAD_RET: $display("INFO: WBM2SPC: Return Packet of Type LOAD_RET");
561
          `ST_ACK: $display("INFO: WBM2SPC: Return Packet of Type ST_ACK");
562
          default: $display("INFO: WBM2SPC: Return Packet of Type Unknown");
563
        endcase
564 12 fafa1971
        $display("INFO: WBM2SPC: L2 Miss is %X", wbm2spc_miss);
565 11 fafa1971
        $display("INFO: WBM2SPC: Error is %X", wbm2spc_error);
566 12 fafa1971
        $display("INFO: WBM2SPC: Non-Cacheable bit is %X", wbm2spc_nc);
567 4 fafa1971
        $display("INFO: WBM2SPC: Thread is %X", wbm2spc_thread);
568 11 fafa1971
        $display("INFO: WBM2SPC: Way Valid is %X", wbm2spc_way_valid);
569
        $display("INFO: WBM2SPC: Replaced L2 Way is %X", wbm2spc_way);
570 12 fafa1971
        $display("INFO: WBM2SPC: Fetch for Boot is %X", wbm2spc_boot_fetch);
571
        $display("INFO: WBM2SPC: Atomic LD/ST or 2nd IFill Packet is %X", wbm2spc_atomic);
572
        $display("INFO: WBM2SPC: PFL is %X", wbm2spc_pfl);
573 4 fafa1971
        $display("INFO: WBM2SPC: Data is %X", wbm2spc_data);
574 51 fafa1971
`endif
575 4 fafa1971
// synopsys translate_on
576
 
577
        // Unconditional state change
578 51 fafa1971
        state <= `STATE_ACCESS3_END;
579 4 fafa1971
 
580
      // FSM State 8: STATE_ACCESS3_END
581
      // Latch the second data returning from Wishbone when ready
582
      end else if(state==`STATE_ACCESS3_END) begin
583
 
584
        // Clear previously modified outputs
585 51 fafa1971
        spc_ready_o <= 0;
586 4 fafa1971
 
587
        // Wait until Wishbone access completes
588
        if(wbm_ack_i==1) begin
589
 
590
          // Clear previously modified outputs
591 51 fafa1971
          if(spc2wbm_atomic==0) wbm_cycle_o <= 0;
592
          wbm_strobe_o <= 0;
593
          wbm_we_o <= 0;
594
          wbm_addr_o <= 64'b0;
595
          wbm_data_o <= 64'b0;
596
          wbm_sel_o <= 8'b0;
597 4 fafa1971
 
598
          // Latch the data and set up the return packet for the SPARC Core
599 51 fafa1971
          wbm2spc_data <= { wbm_data_i, 64'b0 };
600 4 fafa1971
 
601
          // Jump to next state
602 51 fafa1971
          state <= `STATE_ACCESS4_BEGIN;
603 4 fafa1971
 
604 51 fafa1971
        end else state <= `STATE_ACCESS3_END;
605 4 fafa1971
 
606
      // FSM State 9: STATE_ACCESS4_BEGIN
607
      // If needed start a second read access to the Wishbone bus
608
      end else if(state==`STATE_ACCESS4_BEGIN) begin
609
 
610
        // Issue a fourth request on the Wishbone bus
611 51 fafa1971
        wbm_cycle_o <= 1;
612
        wbm_strobe_o <= 1;
613
        wbm_we_o <= 0;
614
        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
615
        wbm_data_o <= 64'b0;
616
        wbm_sel_o <= 8'b11111111;
617 4 fafa1971
 
618
        // Unconditional state change
619 51 fafa1971
        state <= `STATE_ACCESS4_END;
620 4 fafa1971
 
621
      // FSM State 10: STATE_ACCESS4_END
622
      // Latch the second data returning from Wishbone when ready
623
      end else if(state==`STATE_ACCESS4_END) begin
624
 
625
        // Wait until Wishbone access completes
626
        if(wbm_ack_i==1) begin
627
 
628
          // Clear previously modified outputs
629 51 fafa1971
          if(spc2wbm_atomic==0) wbm_cycle_o <= 0;
630
          wbm_strobe_o <= 0;
631
          wbm_we_o <= 0;
632
          wbm_addr_o <= 64'b0;
633
          wbm_data_o <= 64'b0;
634
          wbm_sel_o <= 8'b0;
635 4 fafa1971
 
636
          // Latch the data and set up the return packet for the SPARC Core
637 51 fafa1971
          wbm2spc_atomic <= 1;
638
          wbm2spc_data[63:0] <= wbm_data_i;
639 4 fafa1971
 
640
          // Jump to next state
641 51 fafa1971
          state <= `STATE_PACKET_READY;
642 4 fafa1971
 
643 51 fafa1971
        end else state <= `STATE_ACCESS4_END;
644 4 fafa1971
 
645
      // FSM State 11: STATE_PACKET_READY
646
      // We can start returning the packet to the SPARC Core
647
      end else if(state==`STATE_PACKET_READY) begin
648
 
649
        // Return the packet to the SPARC Core
650 51 fafa1971
        spc_ready_o <= 1;
651
        spc_packetin_o <= wbm2spc_packet;
652 4 fafa1971
 
653
        // Unconditional state change
654 51 fafa1971
        state <= `STATE_IDLE;
655 4 fafa1971
 
656
// synopsys translate_off
657
        // Print details of return packet
658 51 fafa1971
`ifdef DEBUG
659 12 fafa1971
        $display("INFO: WBM2SPC: *** RETURN PACKET TO SPARC CORE ***");
660 11 fafa1971
        $display("INFO: WBM2SPC: Valid bit is %X", wbm2spc_valid);
661 4 fafa1971
        case(wbm2spc_type)
662
          `IFILL_RET: $display("INFO: WBM2SPC: Return Packet of Type IFILL_RET");
663
          `LOAD_RET: $display("INFO: WBM2SPC: Return Packet of Type LOAD_RET");
664
          `ST_ACK: $display("INFO: WBM2SPC: Return Packet of Type ST_ACK");
665
          default: $display("INFO: WBM2SPC: Return Packet of Type Unknown");
666
        endcase
667 12 fafa1971
        $display("INFO: WBM2SPC: L2 Miss is %X", wbm2spc_miss);
668 11 fafa1971
        $display("INFO: WBM2SPC: Error is %X", wbm2spc_error);
669
        $display("INFO: WBM2SPC: Non-Cacheable bit is %X", wbm2spc_nc);
670 4 fafa1971
        $display("INFO: WBM2SPC: Thread is %X", wbm2spc_thread);
671 11 fafa1971
        $display("INFO: WBM2SPC: Way Valid is %X", wbm2spc_way_valid);
672
        $display("INFO: WBM2SPC: Replaced L2 Way is %X", wbm2spc_way);
673 12 fafa1971
        $display("INFO: WBM2SPC: Fetch for Boot is %X", wbm2spc_boot_fetch);
674
        $display("INFO: WBM2SPC: Atomic LD/ST or 2nd IFill Packet is %X", wbm2spc_atomic);
675
        $display("INFO: WBM2SPC: PFL is %X", wbm2spc_pfl);
676 4 fafa1971
        $display("INFO: WBM2SPC: Data is %X", wbm2spc_data);
677 51 fafa1971
`endif
678 4 fafa1971
// synopsys translate_on
679
 
680
      end
681
    end
682
  end
683
 
684
endmodule
685
 

powered by: WebSVN 2.1.0

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