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 4

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
  input[5:0] sys_interrupt_source_i;            // Interrupt Requests
44
 
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
  reg spc2wbm_atom;
90
  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
  reg[(`CPX_ERR_HI-`CPX_ERR_LO):0] wbm2spc_error;                      // Error
96
  reg wbm2spc_rnwd_or_ncif;                                            // Read-Not-Write Data or Non-Cacheable Instruction Fetch
97
  reg[(`CPX_TH_HI-`CPX_TH_LO):0] wbm2spc_thread;                       // Thread
98
  reg[(`CPX_P_HI-`CPX_P_LO):0] wbm2spc_packet_id;                      // Packet ID
99
  reg[(`CPX_DA_HI-`CPX_DA_LO):0] wbm2spc_data;                         // Load Data
100
  reg[(`CPX_IN_HI-`CPX_IN_LO):0] wbm2spc_interrupt_source;             // Interrupt Source
101
  reg wbm2spc_reset_not_int;                                           // Reset and not interrupt packet
102
  reg[4:0] wbm2spc_virtual_cpu_target;                                 // ID of virtual CPU target
103
  reg[(`CPX_IN_HI-`CPX_IN_LO):0] wbm2spc_intsrc_or_resettype;          // Interrupt Source or Reset Type
104
  reg[(`CPX_IN_HI-`CPX_IN_LO):0] wbm2spc_new_irq;                      // New Interrupt Request Pending
105
 
106
  /*
107
   * Wires
108
   */
109
 
110
  // Decoded SPARC Core to Wishbone Master info
111
  wire spc2wbm_req;                                                     // Request
112
  wire spc2wbm_valid;                                                   // Valid
113
  wire[(`PCX_RQ_HI-`PCX_RQ_LO):0] spc2wbm_type;                         // Request type
114
  wire spc2wbm_rnwd_or_ncif;                                            // Read-Not-Write Data or Non-Cacheable Instruction Fetch
115
  wire[(`PCX_CP_HI-`PCX_CP_LO):0] spc2wbm_cpu_id;                       // CPU ID
116
  wire[(`PCX_TH_HI-`PCX_TH_LO):0] spc2wbm_thread;                       // Thread
117
  wire[(`PCX_BF_HI-`PCX_BF_LO):0] spc2wbm_buffer;                       // Buffer
118
  wire[(`PCX_P_HI-`PCX_P_LO):0] spc2wbm_packet_id;                      // Packet ID
119
  wire[(`PCX_SZ_HI-`PCX_SZ_LO):0] spc2wbm_size;                         // Load/Store size
120
  wire[(`PCX_ERR_HI-`PCX_ERR_LO):0] spc2wbm_error;                      // Error
121
  wire[(`PCX_AD_HI-`PCX_AD_LO):0] spc2wbm_addr;                         // Address
122
  wire[(`PCX_DA_HI-`PCX_DA_LO):0] spc2wbm_data;                         // Store Data
123
 
124
  // Return packets assembled with various fields
125
  wire[`CPX_WIDTH-1:0] wbm2spc_packet_dat;                              // Incoming Packet - Data
126
  wire[`CPX_WIDTH-1:0] wbm2spc_packet_int;                              // Incoming Packet - Interrupt
127
 
128
  /*
129
   * Encode/decode incoming info
130
   *
131
   * Legenda: available constants for some of the PCX/CPX fields.
132
   *
133
   * spc2wbm_size (3 bits) is one of:
134
   * - PCX_SZ_1B
135
   * - PCX_SZ_2B
136
   * - PCX_SZ_4B
137
   * - PCX_SZ_8B
138
   * - PCX_SZ_16B (Read accesses only)
139
   *
140
   * spc2wbm_type (5 bits) is one of:
141
   * { LOAD_RQ, IMISS_RQ, STORE_RQ, CAS1_RQ, CAS2_RQ, SWAP_RQ, STRLOAD_RQ, STRST_RQ, STQ_RQ,
142
   *   INT_RQ, FWD_RQ, FWD_RPY, RSVD_RQ }
143
   *
144
   * wbm2spc_type (4 bits) is one of:
145
   * { LOAD_RET, INV_RET, ST_ACK, AT_ACK, INT_RET, TEST_RET, FP_RET, IFILL_RET, EVICT_REQ,
146
   *   ERR_RET, STRLOAD_RET, STRST_ACK, FWD_RQ_RET, FWD_RPY_RET, RSVD_RET }
147
   *
148
   */
149
 
150
  // Decode info arriving from the SPC side
151
  assign spc2wbm_req = ( spc_req_i[4] | spc_req_i[3] | spc_req_i[2] | spc_req_i[1] | spc_req_i[0] );
152
  assign spc2wbm_valid = spc2wbm_packet[`PCX_VLD];
153
  assign spc2wbm_type = spc2wbm_packet[`PCX_RQ_HI:`PCX_RQ_LO];
154
  assign spc2wbm_rnwd_or_ncif = spc2wbm_packet[`PCX_R];
155
  assign spc2wbm_cpu_id = spc2wbm_packet[`PCX_CP_HI:`PCX_CP_LO];
156
  assign spc2wbm_thread = spc2wbm_packet[`PCX_TH_HI:`PCX_TH_LO];
157
  assign spc2wbm_buffer = spc2wbm_packet[`PCX_BF_HI:`PCX_BF_LO];
158
  assign spc2wbm_packet_id = spc2wbm_packet[`PCX_P_HI:`PCX_P_LO];
159
  assign spc2wbm_size = spc2wbm_packet[`PCX_SZ_HI:`PCX_SZ_LO];
160
  assign spc2wbm_error = spc2wbm_packet[`PCX_ERR_HI:`PCX_ERR_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
  assign wbm2spc_packet_dat = { wbm2spc_valid, wbm2spc_type, wbm2spc_error,
166
    wbm2spc_rnwd_or_ncif, wbm2spc_thread, 2'b00, wbm2spc_packet_id,
167
    2'b00, wbm2spc_data };
168
  assign wbm2spc_packet_int = { wbm2spc_valid, wbm2spc_type, wbm2spc_error,
169
    wbm2spc_rnwd_or_ncif, wbm2spc_thread, wbm2spc_interrupt_source,
170
    111'b0, wbm2spc_reset_not_int, 3'b0, wbm2spc_virtual_cpu_target,
171
    2'b0, wbm2spc_intsrc_or_resettype };
172
 
173
  /*
174
   * State Machine
175
   */
176
 
177
  always @(posedge sys_clock_i) begin
178
 
179
    // Initialization
180
    if(sys_reset_i==1) begin
181
 
182
      // Clear outputs going to SPARC Core inputs
183
      spc_grant_o = 5'b00000;
184
      spc_ready_o = 0;
185
      spc_packetin_o = 0;
186
      spc_stallreq_o = 0;
187
 
188
      // Clear Wishbone Master interface outputs
189
      wbm_cycle_o = 0;
190
      wbm_strobe_o = 0;
191
      wbm_we_o = 0;
192
      wbm_addr_o = 64'b0;
193
      wbm_data_o = 64'b0;
194
      wbm_sel_o = 8'b0;
195
 
196
      // Prepare wakeup packet for SPARC Core, the resulting output is
197
      // spc_packetin_o = `CPX_WIDTH'h1700000000000000000000000000000010001;
198
      wbm2spc_valid = 1;
199
      wbm2spc_type = `INT_RET;
200
      wbm2spc_error = 0;
201
      wbm2spc_rnwd_or_ncif = 0;
202
      wbm2spc_thread = 0;
203
      wbm2spc_packet_id = 0;
204
      wbm2spc_interrupt_source = 0;
205
      wbm2spc_reset_not_int = 1;
206
      wbm2spc_virtual_cpu_target = 0;
207
      wbm2spc_intsrc_or_resettype = 6'b000001;
208
      wbm2spc_new_irq = 0;  // Ignored for wakeup packet
209
 
210
      // Clear state machine
211
      state = `STATE_WAKEUP;
212
 
213
    end else begin
214
 
215
      // FSM State 0: STATE_WAKEUP
216
      // Send to the SPARC Core the wakeup packet
217
      if(state==`STATE_WAKEUP) begin
218
 
219
        // Send wakeup packet
220
        spc_ready_o = 1;
221
        spc_packetin_o = wbm2spc_packet_int;
222
 
223
// synopsys translate_off
224
        // Display comment
225
        $display("INFO: SPC2WBM: SPARC Core to Wishbone Master bridge starting...");
226
        $display("INFO: SPC2WBM: Wakeup packet sent to SPARC Core");
227
// synopsys translate_on
228
 
229
        // Unconditional state change
230
        state = `STATE_IDLE;
231
 
232
      // FSM State 1: STATE_IDLE
233
      // Wait for a request from the SPARC Core
234
      // If available send an interrupt packet to the Core
235
      end else if(state==`STATE_IDLE) begin
236
 
237
        // Check if there's an incoming request
238
        if(spc2wbm_req==1) begin
239
 
240
          // Clear previously modified outputs
241
          spc_ready_o = 0;
242
          spc_packetin_o = 0;
243
 
244
          // Stall other requests from the SPARC Core
245
          spc_stallreq_o = 1;
246
 
247
          // Latch target region and atomicity
248
          spc2wbm_region = spc_req_i;
249
          spc2wbm_atom = spc_atom_i;
250
 
251
          // Jump to next state
252
          state = `STATE_REQUEST_LATCHED;
253
 
254
        // See if the interrupt vector has changed
255
        end else if(sys_interrupt_source_i!=wbm2spc_interrupt_source) begin
256
 
257
          // Set the flag for next cycle
258
          wbm2spc_new_irq = 1;
259
 
260
          // Prepare the interrupt packet for the SPARC Core
261
          wbm2spc_valid = 1;
262
          wbm2spc_type = `INT_RET;
263
          wbm2spc_error = 0;
264
          wbm2spc_rnwd_or_ncif = 0;
265
          wbm2spc_thread = 0;
266
          wbm2spc_packet_id = 0;
267
          wbm2spc_interrupt_source = sys_interrupt_source_i;
268
          wbm2spc_reset_not_int = 0;
269
          wbm2spc_virtual_cpu_target = 0;
270
          wbm2spc_intsrc_or_resettype = sys_interrupt_source_i;
271
 
272
          // Stall other requests from the SPARC Core
273
          spc_stallreq_o = 1;
274
 
275
        // Next cycle see if there's an int to be forwarded to the Core
276
        end else if(wbm2spc_interrupt_source!=6'b000000 && wbm2spc_new_irq) begin
277
 
278
          // Clean the flag
279
          wbm2spc_new_irq = 0;
280
 
281
          // Send the interrupt packet to the Core
282
          spc_ready_o = 1;
283
          spc_packetin_o = wbm2spc_packet_int;
284
 
285
          // Stall other requests from the SPARC Core
286
          spc_stallreq_o = 1;
287
 
288
          // Stay in this state
289
          state = `STATE_IDLE;
290
 
291
        // Nothing to do, stay idle
292
        end else begin
293
 
294
          // Clear previously modified outputs
295
          spc_ready_o = 0;
296
          spc_packetin_o = 0;
297
          spc_stallreq_o = 0;
298
 
299
          // Stay in this state
300
          state = `STATE_IDLE;
301
 
302
        end
303
 
304
      // FSM State 2: STATE_REQUEST_LATCHED
305
      // We've just latched the request
306
      // Now we latch the packet
307
      // Start granting the request
308
      end else if(state==`STATE_REQUEST_LATCHED) begin
309
 
310
        // Latch the incoming packet
311
        spc2wbm_packet = spc_packetout_i;
312
 
313
        // Grant the request to the SPARC Core
314
        spc_grant_o = spc2wbm_region;
315
 
316
// synopsys translate_off
317
        // Print details of SPARC Core request
318
        $display("INFO: SPC2WBM: *** NEW REQUEST FROM SPARC CORE ***");
319
        if(spc2wbm_region[0]==1) $display("INFO: SPC2WBM: Request to RAM Bank 0");
320
        else if(spc2wbm_region[1]==1) $display("INFO: SPC2WBM: Request to RAM Bank 1");
321
        else if(spc2wbm_region[2]==1) $display("INFO: SPC2WBM: Request to RAM Bank 2");
322
        else if(spc2wbm_region[3]==1) $display("INFO: SPC2WBM: Request to RAM Bank 3");
323
        else if(spc2wbm_region[4]==1) $display("INFO: SPC2WBM: Request targeted to I/O Block");
324
        else $display("INFO: SPC2WBM: Request to target region unknown");
325
        if(spc2wbm_atom==1) $display("INFO: SPC2WBM: Request is ATOMIC");
326
        else $display("INFO: SPC2WBM: Request is not atomic");
327
// synopsys translate_on
328
 
329
        // Unconditional state change
330
        state = `STATE_PACKET_LATCHED;
331
 
332
      // FSM State 3: STATE_PACKET_LATCHED
333
      // The packet has already been latched
334
      // Decode this packet to build the request for the Wishbone bus
335
      // The grant of the request to the SPARC Core has been completed
336
      end else if(state==`STATE_PACKET_LATCHED) begin
337
 
338
        // Clear previously modified outputs
339
        spc_grant_o = 5'b0;
340
 
341
        // Issue a request on the Wishbone bus
342
        wbm_cycle_o = 1;
343
        wbm_strobe_o = 1;
344
        wbm_addr_o = { spc2wbm_region, 19'b0, spc2wbm_addr[`PCX_AD_HI-`PCX_AD_LO:3], 3'b000 };
345
        wbm_data_o = spc2wbm_data;
346
 
347
        // Handle write enable and byte select
348
        if(spc2wbm_type==`IMISS_RQ) begin
349
 
350
          // For instruction miss always read memory
351
          wbm_we_o = 0;
352
          if(spc2wbm_region==5'b10000)
353
            // For accesses to SSI ROM only 32 bits are required
354
            wbm_sel_o = (4'b1111<<(spc2wbm_addr[2]<<2));
355
          else
356
            // For accesses to RAM 256 bits are expected (2 ret packets)
357
            wbm_sel_o = 8'b11111111;
358
 
359
        end else begin
360
 
361
          // For data load/store use the provided data
362
          wbm_we_o = !spc2wbm_rnwd_or_ncif;
363
          case(spc2wbm_size)
364
            `PCX_SZ_1B: wbm_sel_o = (1'b1<<spc2wbm_addr[2:0]);
365
            `PCX_SZ_2B: wbm_sel_o = (2'b11<<(spc2wbm_addr[2:1]<<1));
366
            `PCX_SZ_4B: wbm_sel_o = (4'b1111<<(spc2wbm_addr[2]<<2));
367
            `PCX_SZ_8B: wbm_sel_o = 8'b11111111;
368
            `PCX_SZ_16B: wbm_sel_o = 8'b11111111;  // Requires a 2nd access
369
            default: wbm_sel_o = 8'b00000000;
370
          endcase
371
 
372
        end
373
 
374
// synopsys translate_off
375
        // Print details of request packet
376
        if(spc2wbm_valid==1) $display("INFO: SPC2WBM: Request has valid bit");
377
        else $display("INFO: SPC2WBM: Request has not valid bit");
378
        case(spc2wbm_type)
379
          `LOAD_RQ: $display("INFO: SPC2WBM: Request of Type LOAD_RQ");
380
          `IMISS_RQ: $display("INFO: SPC2WBM: Request of Type IMISS_RQ");
381
          `STORE_RQ: $display("INFO: SPC2WBM: Request of Type STORE_RQ");
382
          `CAS1_RQ: $display("INFO: SPC2WBM: Request of Type CAS1_RQ");
383
          `CAS2_RQ: $display("INFO: SPC2WBM: Request of Type CAS2_RQ");
384
          `SWAP_RQ: $display("INFO: SPC2WBM: Request of Type SWAP_RQ");
385
          `STRLOAD_RQ: $display("INFO: SPC2WBM: Request of Type STRLOAD_RQ");
386
          `STRST_RQ: $display("INFO: SPC2WBM: Request of Type STRST_RQ");
387
          `STQ_RQ: $display("INFO: SPC2WBM: Request of Type STQ_RQ");
388
          `INT_RQ: $display("INFO: SPC2WBM: Request of Type INT_RQ");
389
          `FWD_RQ: $display("INFO: SPC2WBM: Request of Type FWD_RQ");
390
          `FWD_RPY: $display("INFO: SPC2WBM: Request of Type FWD_RPY");
391
          `RSVD_RQ: $display("INFO: SPC2WBM: Request of Type RSVD_RQ");
392
          default: $display("INFO: SPC2WBM: Request of Type Unknown");
393
        endcase
394
        if(spc2wbm_type==`IMISS_RQ) begin
395
          if(spc2wbm_rnwd_or_ncif==1) $display("INFO: SPC2WBM: Request is Non-Cacheable");
396
          else $display("INFO: SPC2WBM: Request is Cacheable");
397
        end else begin
398
          if(spc2wbm_rnwd_or_ncif==1) $display("INFO: SPC2WBM: Request is a Read Access");
399
          else $display("INFO: SPC2WBM: Request is a Write Access");
400
        end
401
        $display("INFO: SPC2WBM: CPU ID is %X", spc2wbm_cpu_id);
402
        $display("INFO: SPC2WBM: Thread is %X", spc2wbm_thread);
403
        $display("INFO: SPC2WBM: Buffer is %X", spc2wbm_buffer);
404
        $display("INFO: SPC2WBM: Packet ID is %X", spc2wbm_packet_id);
405
        case(spc2wbm_size)
406
          `PCX_SZ_1B: $display("INFO: SPC2WBM: Request size is 1 Byte");
407
          `PCX_SZ_2B: $display("INFO: SPC2WBM: Request size is 2 Bytes");
408
          `PCX_SZ_4B: $display("INFO: SPC2WBM: Request size is 4 Bytes");
409
          `PCX_SZ_8B: $display("INFO: SPC2WBM: Request size is 8 Bytes");
410
          `PCX_SZ_16B: $display("INFO: SPC2WBM: Request size is 16 Bytes");
411
          default: $display("INFO: SPC2WBM: Request size is Unknown");
412
        endcase
413
        $display("INFO: SPC2WBM: Error is %X", spc2wbm_error);
414
        $display("INFO: SPC2WBM: Address is %X", spc2wbm_addr);
415
        $display("INFO: SPC2WBM: Data is %X", spc2wbm_data);
416
        $display("INFO: SPC2WBM: Request forwarded from SPARC Core to Wishbone Master");
417
// synopsys translate_on
418
 
419
        // Unconditional state change
420
        state = `STATE_REQUEST_GRANTED;
421
 
422
      // FSM State 4: STATE_REQUEST_GRANTED
423
      // Wishbone access completed, latch the incoming data
424
      end else if(state==`STATE_REQUEST_GRANTED) begin
425
 
426
        // Wait until Wishbone access completes
427
        if(wbm_ack_i==1) begin
428
 
429
          // Clear previously modified outputs
430
          if(spc2wbm_atom==0) wbm_cycle_o = 0;
431
          wbm_strobe_o = 0;
432
          wbm_we_o = 0;
433
          wbm_addr_o = 64'b0;
434
          wbm_data_o = 64'b0;
435
          wbm_sel_o = 8'b0;
436
 
437
          // Latch the data and set up the return packet for the SPARC Core
438
          wbm2spc_valid = 1;
439
          wbm2spc_rnwd_or_ncif = spc2wbm_rnwd_or_ncif;
440
          if(spc2wbm_addr[3]==0)
441
            wbm2spc_data = { wbm_data_i, 64'b0 };
442
          else
443
            wbm2spc_data = { 64'b0, wbm_data_i };
444
          case(spc2wbm_type)
445
            `IMISS_RQ: begin
446
              wbm2spc_type = `IFILL_RET; // I-Cache Miss
447
            end
448
            `LOAD_RQ: begin
449
              wbm2spc_type = `LOAD_RET;   // Load
450
            end
451
            `STORE_RQ: begin
452
              wbm2spc_type = `ST_ACK;    // Store
453
            end
454
          endcase
455
          wbm2spc_error = 0;
456
          wbm2spc_thread = spc2wbm_thread;
457
// CHECK THIS!!!!!!!
458
//        wbm2spc_packet_id = spc2wbm_packet_id;
459
          if(spc2wbm_region==5'b10000) wbm2spc_packet_id = 2'b01;
460
          else wbm2spc_packet_id = 2'b00;
461
 
462
          // See if other 64-bit Wishbone accesses are required
463
          if(
464
              // Instruction miss directed to RAM expects 256 bits
465
              ( (spc2wbm_type==`IMISS_RQ)&&(spc2wbm_region!=5'b10000) ) ||
466
              // Data access of 128 bits
467
              ( (spc2wbm_type==`LOAD_RQ)&&(spc2wbm_size==`PCX_SZ_16B) )
468
            )
469
            state = `STATE_ACCESS2_BEGIN;
470
          else
471
            state = `STATE_PACKET_READY;
472
 
473
        end else state = `STATE_REQUEST_GRANTED;
474
 
475
      // FSM State 5: STATE_ACCESS2_BEGIN
476
      // If needed start a second read access to the Wishbone bus
477
      end else if(state==`STATE_ACCESS2_BEGIN) begin
478
 
479
        // Issue a second request on the Wishbone bus
480
        wbm_cycle_o = 1;
481
        wbm_strobe_o = 1;
482
        wbm_we_o = 0;
483
        wbm_addr_o = { spc2wbm_region, 19'b0, spc2wbm_addr[`PCX_AD_HI-`PCX_AD_LO:4], 4'b1000 };  // 2nd doubleword inside the same quadword
484
        wbm_data_o = 64'b0;
485
        wbm_sel_o = 8'b11111111;
486
 
487
        // Unconditional state change
488
        state = `STATE_ACCESS2_END;
489
 
490
      // FSM State 6: STATE_ACCESS2_END
491
      // Latch the second data returning from Wishbone when ready
492
      end else if(state==`STATE_ACCESS2_END) begin
493
 
494
        // Wait until Wishbone access completes
495
        if(wbm_ack_i==1) begin
496
 
497
          // Clear previously modified outputs
498
          if(spc2wbm_atom==0) wbm_cycle_o = 0;
499
          wbm_strobe_o = 0;
500
          wbm_we_o = 0;
501
          wbm_addr_o = 64'b0;
502
          wbm_data_o = 64'b0;
503
          wbm_sel_o = 8'b0;
504
 
505
          // Latch the data and set up the return packet for the SPARC Core
506
          wbm2spc_data[63:0] = wbm_data_i;
507
 
508
          // See if two return packets are required or just one
509
          if(spc2wbm_type==`IMISS_RQ && spc2wbm_region==5'b10000)
510
            state = `STATE_PACKET_READY;
511
          else
512
            state = `STATE_ACCESS3_BEGIN;
513
 
514
        end else state = `STATE_ACCESS2_END;
515
 
516
      // FSM State 7: STATE_ACCESS3_BEGIN
517
      // If needed start a third read access to the Wishbone bus
518
      // In the meanwhile we can return the first 128-bit packet
519
      end else if(state==`STATE_ACCESS3_BEGIN) begin
520
 
521
        // Return the packet to the SPARC Core
522
        spc_ready_o = 1;
523
        spc_packetin_o = wbm2spc_packet_dat;
524
 
525
        // Issue a third request on the Wishbone bus
526
        wbm_cycle_o = 1;
527
        wbm_strobe_o = 1;
528
        wbm_we_o = 0;
529
        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
530
        wbm_data_o = 64'b0;
531
        wbm_sel_o = 8'b11111111;
532
 
533
// synopsys translate_off
534
        // Print details of return packet
535
        if(wbm2spc_valid==1) $display("INFO: WBM2SPC: Return packet has valid bit");
536
        else $display("INFO: WBM2SPC: Return packet has not valid bit");
537
        case(wbm2spc_type)
538
          `IFILL_RET: $display("INFO: WBM2SPC: Return Packet of Type IFILL_RET");
539
          `LOAD_RET: $display("INFO: WBM2SPC: Return Packet of Type LOAD_RET");
540
          `ST_ACK: $display("INFO: WBM2SPC: Return Packet of Type ST_ACK");
541
          default: $display("INFO: WBM2SPC: Return Packet of Type Unknown");
542
        endcase
543
        if(wbm2spc_type==`IFILL_RET) begin
544
          if(wbm2spc_rnwd_or_ncif==1) $display("INFO: WBM2SPC: Return Packet is Non-Cacheable");
545
          else $display("INFO: WBM2SPC: Return Packet is Cacheable");
546
        end else begin
547
          if(spc2wbm_rnwd_or_ncif==1) $display("INFO: WBM2SPC: Return Packet is a Read Access");
548
          else $display("INFO: WBM2SPC: Return Packet is a Write Access");
549
        end
550
        $display("INFO: WBM2SPC: Thread is %X", wbm2spc_thread);
551
        $display("INFO: WBM2SPC: Packet ID is %X", wbm2spc_packet_id);
552
        $display("INFO: WBM2SPC: Error is %X", wbm2spc_error);
553
        $display("INFO: WBM2SPC: Data is %X", wbm2spc_data);
554
        $display("INFO: WBM2SPC: Return Packet forwarded from Wishbone Master to SPARC Core");
555
// synopsys translate_on
556
 
557
        // Unconditional state change
558
        state = `STATE_ACCESS3_END;
559
 
560
      // FSM State 8: STATE_ACCESS3_END
561
      // Latch the second data returning from Wishbone when ready
562
      end else if(state==`STATE_ACCESS3_END) begin
563
 
564
        // Clear previously modified outputs
565
        spc_ready_o = 0;
566
 
567
        // Wait until Wishbone access completes
568
        if(wbm_ack_i==1) begin
569
 
570
          // Clear previously modified outputs
571
          if(spc2wbm_atom==0) wbm_cycle_o = 0;
572
          wbm_strobe_o = 0;
573
          wbm_we_o = 0;
574
          wbm_addr_o = 64'b0;
575
          wbm_data_o = 64'b0;
576
          wbm_sel_o = 8'b0;
577
 
578
          // Latch the data and set up the return packet for the SPARC Core
579
          wbm2spc_data = { wbm_data_i, 64'b0 };
580
 
581
          // Jump to next state
582
          state = `STATE_ACCESS4_BEGIN;
583
 
584
        end else state = `STATE_ACCESS3_END;
585
 
586
      // FSM State 9: STATE_ACCESS4_BEGIN
587
      // If needed start a second read access to the Wishbone bus
588
      end else if(state==`STATE_ACCESS4_BEGIN) begin
589
 
590
        // Issue a fourth request on the Wishbone bus
591
        wbm_cycle_o = 1;
592
        wbm_strobe_o = 1;
593
        wbm_we_o = 0;
594
        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
595
        wbm_data_o = 64'b0;
596
        wbm_sel_o = 8'b11111111;
597
 
598
        // Unconditional state change
599
        state = `STATE_ACCESS4_END;
600
 
601
      // FSM State 10: STATE_ACCESS4_END
602
      // Latch the second data returning from Wishbone when ready
603
      end else if(state==`STATE_ACCESS4_END) begin
604
 
605
        // Wait until Wishbone access completes
606
        if(wbm_ack_i==1) begin
607
 
608
          // Clear previously modified outputs
609
          if(spc2wbm_atom==0) wbm_cycle_o = 0;
610
          wbm_strobe_o = 0;
611
          wbm_we_o = 0;
612
          wbm_addr_o = 64'b0;
613
          wbm_data_o = 64'b0;
614
          wbm_sel_o = 8'b0;
615
 
616
          // Latch the data and set up the return packet for the SPARC Core
617
          wbm2spc_data[63:0] = wbm_data_i;
618
 
619
          // Jump to next state
620
          state = `STATE_PACKET_READY;
621
 
622
        end else state = `STATE_ACCESS4_END;
623
 
624
      // FSM State 11: STATE_PACKET_READY
625
      // We can start returning the packet to the SPARC Core
626
      end else if(state==`STATE_PACKET_READY) begin
627
 
628
        // Return the packet to the SPARC Core
629
        spc_ready_o = 1;
630
        spc_packetin_o = wbm2spc_packet_dat;
631
 
632
        // Unconditional state change
633
        state = `STATE_IDLE;
634
 
635
// synopsys translate_off
636
        // Print details of return packet
637
        if(wbm2spc_valid==1) $display("INFO: WBM2SPC: Return packet has valid bit");
638
        else $display("INFO: WBM2SPC: Return packet has not valid bit");
639
        case(wbm2spc_type)
640
          `IFILL_RET: $display("INFO: WBM2SPC: Return Packet of Type IFILL_RET");
641
          `LOAD_RET: $display("INFO: WBM2SPC: Return Packet of Type LOAD_RET");
642
          `ST_ACK: $display("INFO: WBM2SPC: Return Packet of Type ST_ACK");
643
          default: $display("INFO: WBM2SPC: Return Packet of Type Unknown");
644
        endcase
645
        if(wbm2spc_type==`IFILL_RET) begin
646
          if(wbm2spc_rnwd_or_ncif==1) $display("INFO: WBM2SPC: Return Packet is Non-Cacheable");
647
          else $display("INFO: WBM2SPC: Return Packet is Cacheable");
648
        end else begin
649
          if(spc2wbm_rnwd_or_ncif==1) $display("INFO: WBM2SPC: Return Packet is a Read Access");
650
          else $display("INFO: WBM2SPC: Return Packet is a Write Access");
651
        end
652
        $display("INFO: WBM2SPC: Thread is %X", wbm2spc_thread);
653
        $display("INFO: WBM2SPC: Packet ID is %X", wbm2spc_packet_id);
654
        $display("INFO: WBM2SPC: Error is %X", wbm2spc_error);
655
        $display("INFO: WBM2SPC: Data is %X", wbm2spc_data);
656
        $display("INFO: WBM2SPC: Return Packet forwarded from Wishbone Master to SPARC Core");
657
// synopsys translate_on
658
 
659
      end
660
    end
661
  end
662
 
663
endmodule
664
 

powered by: WebSVN 2.1.0

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