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

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [rtl/] [rocketlib/] [types_rocket.vhd] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 sergeykhbr
-----------------------------------------------------------------------------
2
--! @file
3
--! @copyright Copyright 2015 GNSS Sensor Ltd. All right reserved.
4
--! @author    Sergey Khabarov - sergeykhbr@gmail.com
5
--! @brief     System Top level modules and interconnect declarations.
6
-----------------------------------------------------------------------------
7
 
8
--! Standard library.
9
library ieee;
10
use ieee.std_logic_1164.all;
11
use ieee.numeric_std.all;
12
library commonlib;
13
use commonlib.types_common.all;
14
--! Technology definition library.
15
library techmap;
16
use techmap.gencomp.all;
17
--! CPU, System Bus and common peripheries library.
18
library ambalib;
19
use ambalib.types_amba4.all;
20
 
21
--! @brief   Declaration of components visible on SoC top level.
22
package types_rocket is
23
 
24
--! @name Scala inherited constants.
25
--! @brief The following constants were define in Rocket-chip generator.
26
--! @{
27
 
28
--! @brief   Bits allocated for the memory tag value.
29
--! @details This value is defined \i Config.scala and depends of others
30
--!          configuration paramters, like number of master, clients, channels
31
--!          and so on. It is not used in VHDL implemenation.
32
constant MEM_TAG_BITS  : integer := 6;
33
--! @brief   SCALA generated value. Not used in VHDL.
34
constant MEM_ADDR_BITS : integer := 26;
35
--! @}
36
 
37
  --! @name   Rocket Chip interrupt pins 
38
  --!
39
  --! Interrupts types:
40
  --!    1. Local (inside tile) Software interrupts
41
  --!    2. Local (inside tile) interrupts from timer
42
  --!    3. External (global) interrupts from PLIC (Platorm-Level       Interrupt       Controller).
43
  --! @}
44
 
45
  constant CFG_CORE_IRQ_DEBUG : integer := 0;
46
  --! Local Timer's interrupt (machine mode)
47
  constant CFG_CORE_IRQ_MTIP  : integer := CFG_CORE_IRQ_DEBUG + 1;
48
  --! Local sofware interrupt (machine mode)
49
  constant CFG_CORE_IRQ_MSIP  : integer := CFG_CORE_IRQ_MTIP + 1;
50
  --! External PLIC's interrupt (machine mode)
51
  constant CFG_CORE_IRQ_MEIP  : integer := CFG_CORE_IRQ_MSIP + 1;
52
  --! External PLIC's interrupt (superuser mode)
53
  constant CFG_CORE_IRQ_SEIP  : integer := CFG_CORE_IRQ_MEIP + 1;
54
  -- Total number of implemented interrupts
55
  constant CFG_CORE_IRQ_TOTAL : integer := CFG_CORE_IRQ_SEIP + 1;
56
  --! @}
57
 
58
 
59
  --! @name    Memory Transaction types.
60
  --! @details TileLinkIO interface uses these constant to identify the payload
61
  --!          size of the transaction.
62
  --! @{
63
  constant MT_B  : integer := 0;  --! int8_t   Memory Transaction.
64
  constant MT_H  : integer := 1;  --! int16_t  Memory Transaction.
65
  constant MT_W  : integer := 2;  --! int32_t  Memory Transaction.
66
  constant MT_D  : integer := 3;  --! int64_t  Memory Transaction.
67
  constant MT_BU : integer := 4;  --! uint8_t  Memory Transaction.
68
  constant MT_HU : integer := 5;  --! uint16_t Memory Transaction.
69
  constant MT_WU : integer := 6;  --! uint32_t Memory Transaction.
70
  constant MT_Q  : integer := 7;  --! AXI data-width Memory Transaction (default 128-bits).
71
  --! @}
72
 
73
  --! @brief Memory operation types
74
  --! @details The union bits [5:1] contains information about current transaction
75
  constant M_XRD     : std_logic_vector(4 downto 0) := "00000"; --! int load
76
  constant M_XWR     : std_logic_vector(4 downto 0) := "00001"; --! int store
77
  constant M_PFR     : std_logic_vector(4 downto 0) := "00010"; --! prefetch with intent to read
78
  constant M_PFW     : std_logic_vector(4 downto 0) := "00011"; --! prefetch with intent to write
79
  constant M_XA_SWAP : std_logic_vector(4 downto 0) := "00100";
80
  constant M_NOP     : std_logic_vector(4 downto 0) := "00101";
81
  constant M_XLR     : std_logic_vector(4 downto 0) := "00110";
82
  constant M_XSC     : std_logic_vector(4 downto 0) := "00111";
83
  constant M_XA_ADD  : std_logic_vector(4 downto 0) := "01000";
84
  constant M_XA_XOR  : std_logic_vector(4 downto 0) := "01001";
85
  constant M_XA_OR   : std_logic_vector(4 downto 0) := "01010";
86
  constant M_XA_AND  : std_logic_vector(4 downto 0) := "01011";
87
  constant M_XA_MIN  : std_logic_vector(4 downto 0) := "01100";
88
  constant M_XA_MAX  : std_logic_vector(4 downto 0) := "01101";
89
  constant M_XA_MINU : std_logic_vector(4 downto 0) := "01110";
90
  constant M_XA_MAXU : std_logic_vector(4 downto 0) := "01111";
91
  constant M_FLUSH   : std_logic_vector(4 downto 0) := "10000"; --! write back dirty data and cede R/W permissions
92
  constant M_PRODUCE : std_logic_vector(4 downto 0) := "10001"; --! write back dirty data and cede W permissions
93
  constant M_CLEAN   : std_logic_vector(4 downto 0) := "10011"; --! write back dirty data and retain R/W permissions
94
 
95
  function isAMO(cmd : std_logic_vector(4 downto 0)) return std_logic;
96
  --def isPrefetch(cmd: UInt) = cmd === M_PFR || cmd === M_PFW
97
  --def isRead(cmd: UInt) = cmd === M_XRD || cmd === M_XLR || cmd === M_XSC || isAMO(cmd)
98
  function isWrite(cmd : std_logic_vector(4 downto 0)) return std_logic;
99
  --def isWriteIntent(cmd: UInt) = isWrite(cmd) || cmd === M_PFW || cmd === M_XLR
100
 
101
  --! <Definitions.scala> Object Acquire {}
102
  constant ACQUIRE_GET_SINGLE_DATA_BEAT : std_logic_vector(2 downto 0) := "000"; -- Get a single beat of data
103
  constant ACQUIRE_GET_BLOCK_DATA       : std_logic_vector(2 downto 0) := "001"; -- Get a whole block of data
104
  constant ACQUIRE_PUT_SINGLE_DATA_BEAT : std_logic_vector(2 downto 0) := "010"; -- Put a single beat of data.
105
  constant ACQUIRE_PUT_BLOCK_DATA       : std_logic_vector(2 downto 0) := "011"; -- Put  a whole block of data.
106
  constant ACQUIRE_PUT_ATOMIC_DATA      : std_logic_vector(2 downto 0) := "100"; -- Performe an atomic memory op
107
  constant ACQUIRE_GET_PREFETCH_BLOCK   : std_logic_vector(2 downto 0) := "101"; -- Prefetch a whole block of data
108
  constant ACQUIRE_PUT_PREFETCH_BLOCK   : std_logic_vector(2 downto 0) := "110"; -- Prefetch a whole block of data, with intent to write
109
 
110
  --! <tilelink.scala> Object Grant {}
111
  constant GRANT_ACK_RELEASE          : std_logic_vector(3 downto 0) := "0000"; -- For acking Releases
112
  constant GRANT_ACK_PREFETCH         : std_logic_vector(3 downto 0) := "0001"; -- For acking any kind of Prefetch
113
  constant GRANT_ACK_NON_PREFETCH_PUT : std_logic_vector(3 downto 0) := "0011"; -- For acking any kind of non-prfetch Put
114
  constant GRANT_SINGLE_BEAT_GET      : std_logic_vector(3 downto 0) := "0100"; -- Supplying a single beat of Get
115
  constant GRANT_BLOCK_GET            : std_logic_vector(3 downto 0) := "0101"; -- Supplying all beats of a GetBlock
116
 
117
  --! MESI coherence
118
  constant CACHED_ACQUIRE_SHARED      : std_logic_vector(2 downto 0) := "000"; -- get 
119
  constant CACHED_ACQUIRE_EXCLUSIVE   : std_logic_vector(2 downto 0) := "001"; -- put
120
 
121
  constant CACHED_GRANT_SHARED        : std_logic_vector(3 downto 0) := "0000";
122
  constant CACHED_GRANT_EXCLUSIVE     : std_logic_vector(3 downto 0) := "0001";
123
  constant CACHED_GRANT_EXCLUSIVE_ACK : std_logic_vector(3 downto 0) := "0010";
124
 
125
  --! @brief Memory Operation size decoder
126
  --! @details TileLink bus has encoded Memory Operation size
127
  --!          in the union[n+1:n] bits of the acquire request.
128
  --! @warning Sign bit isn't transmitted in union since 20160930.
129
  constant MEMOP_XSIZE_TOTAL : integer := 8;
130
  type memop_xsize_type is array (0 to MEMOP_XSIZE_TOTAL-1) of std_logic_vector(2 downto 0);
131
  constant opSizeToXSize : memop_xsize_type := (
132
    MT_B => "000",
133
    MT_H => "001",
134
    MT_W => "010",
135
    MT_D => "011",
136
    MT_BU => "100",
137
    MT_HU => "101",
138
    MT_WU => "110",
139
    MT_Q => conv_std_logic_vector(log2(CFG_NASTI_DATA_BYTES),3)
140
  );
141
 
142
 
143
type tile_in_type is record
144
    a_ready : std_logic;
145
    b_valid : std_logic;
146
    b_opcode : std_logic_vector(2 downto 0);
147
    b_param : std_logic_vector(1 downto 0);
148
    b_size : std_logic_vector(3 downto 0);
149
    b_source : std_logic_vector(2 downto 0);
150
    b_address : std_logic_vector(31 downto 0);
151
    b_mask : std_logic_vector(7 downto 0);
152
    b_data : std_logic_vector(63 downto 0);
153
    c_ready : std_logic;
154
    d_valid : std_logic;
155
    d_opcode : std_logic_vector(2 downto 0);
156
    d_param : std_logic_vector(1 downto 0);
157
    d_size : std_logic_vector(3 downto 0);
158
    d_source : std_logic_vector(2 downto 0);
159
    d_sink : std_logic_vector(3 downto 0);
160
    d_addr_lo : std_logic_vector(2 downto 0);
161
    d_data : std_logic_vector(63 downto 0);
162
    d_error : std_logic;
163
    e_ready : std_logic;
164
end record;
165
 
166
type tile_out_type is record
167
    a_valid : std_logic;
168
    a_opcode : std_logic_vector(2 downto 0);
169
    a_param : std_logic_vector(2 downto 0);
170
    a_size : std_logic_vector(3 downto 0);
171
    a_source : std_logic_vector(2 downto 0);
172
    a_address : std_logic_vector(31 downto 0);
173
    a_mask : std_logic_vector(7 downto 0);
174
    a_data : std_logic_vector(63 downto 0);
175
    b_ready : std_logic;
176
    c_valid : std_logic;
177
    c_opcode : std_logic_vector(2 downto 0);
178
    c_param : std_logic_vector(2 downto 0);
179
    c_size : std_logic_vector(3 downto 0);
180
    c_source : std_logic_vector(2 downto 0);
181
    c_address : std_logic_vector(31 downto 0);
182
    c_data : std_logic_vector(63 downto 0);
183
    c_error : std_logic;
184
    d_ready : std_logic;
185
    e_valid : std_logic;
186
    e_sink : std_logic_vector(3 downto 0);
187
end record;
188
 
189
 
190
  --! @brief Decode Acquire request from the Cached/Uncached TileLink
191
  --! @param[in] a_type   Request type depends of the built_in flag
192
  --! @param[in] built_in This flag defines cached or uncached request. For
193
  --!                     the uncached this value is set to 1.
194
  --! @param[in] u        Union bits. This value is decoding depending of
195
  --!                     types operation (rd/wr) and cached/uncached.
196
  procedure procedureDecodeTileAcquire (
197
    a_type    : in std_logic_vector(2 downto 0);
198
    built_in  : in std_logic;
199
    u         : in std_logic_vector(10 downto 0);--was 16
200
    write     : out std_logic;
201
    wmask     : out std_logic_vector(CFG_NASTI_DATA_BYTES-1 downto 0);
202
    axi_sz    : out std_logic_vector(2 downto 0);
203
    byte_addr : out std_logic_vector(2 downto 0);
204
    beat_cnt  : out integer
205
  );
206
 
207
 
208
--! @brief   RocketTile component declaration.
209
--! @details This module implements Risc-V Core with L1-cache, 
210
--!          branch predictor and other stuffs of the RocketTile.
211
--! @param[in] xindex1 Cached Tile AXI master index
212
--! @param[in] xindex2 Uncached Tile AXI master index
213
--! @param[in] hartid  Tile ID. At least 0 must be implemented.
214
--! @param[in] reset_vector  Reset instruction pointer value.
215
--! @param[in] rst     Reset signal with active HIGH level.
216
--! @param[in] soft_rst Software Reset via DSU
217
--! @param[in] clk_sys System clock (BUS/CPU clock).
218
--! @param[in] slvo    Bus-to-Slave device signals.
219
--! @param[in] msti    Bus-to-Master device signals.
220
--! @param[out] msto1  CachedTile-to-Bus request signals.
221
--! @param[out] msto2  UncachedTile-to-Bus request signals.
222
--! @param[in] interrupts  Interrupts line supported by Rocket chip.
223
component rocket_l1only is
224
generic (
225
    hartid : integer := 0;
226
    reset_vector : integer := 16#1000#
227
);
228
port (
229
    nrst     : in std_logic;
230
    clk_sys  : in std_logic;
231
    msti1    : in nasti_master_in_type;
232
    msto1    : out nasti_master_out_type;
233
    mstcfg1  : out nasti_master_config_type;
234
    msti2    : in nasti_master_in_type;
235
    msto2    : out nasti_master_out_type;
236
    mstcfg2  : out nasti_master_config_type;
237
    interrupts : in std_logic_vector(CFG_CORE_IRQ_TOTAL-1 downto 0)
238
);
239
end component;
240
 
241
end; -- package declaration
242
 
243
--! -----------------
244
package body types_rocket is
245
 
246
  function isAMO(cmd : std_logic_vector(4 downto 0))
247
    return std_logic is
248
    variable t1 : std_logic;
249
  begin
250
    t1 := '0';
251
    if cmd = M_XA_SWAP then
252
      t1 := '1';
253
    end if;
254
    return (cmd(3) or t1);
255
  end;
256
 
257
  function isWrite(cmd : std_logic_vector(4 downto 0))
258
    return std_logic is
259
    variable ret : std_logic;
260
  begin
261
    ret := isAMO(cmd);
262
    if cmd = M_XWR then ret := '1'; end if;
263
    if cmd = M_XSC then ret := '1'; end if;
264
    return (ret);
265
  end;
266
 
267
  --! @brief Decode Acquire request from the Cached/Uncached TileLink
268
  --! @param[in] a_type   Request type depends of the built_in flag
269
  --! @param[in] built_in This flag defines cached or uncached request. For
270
  --!                     the uncached this value is set to 1.
271
  --! @param[in] u        Union bits. This value is decoding depending of
272
  --!                     types operation (rd/wr) and cached/uncached.
273
  procedure procedureDecodeTileAcquire(
274
    a_type    : in std_logic_vector(2 downto 0);
275
    built_in  : in std_logic;
276
    u         : in std_logic_vector(10 downto 0);--was 16
277
    write     : out std_logic;
278
    wmask     : out std_logic_vector(CFG_NASTI_DATA_BYTES-1 downto 0);
279
    axi_sz    : out std_logic_vector(2 downto 0);
280
    byte_addr : out std_logic_vector(2 downto 0);
281
    beat_cnt  : out integer
282
  ) is
283
  begin
284
 
285
    if built_in = '1' then
286
      -- Cached request
287
      case a_type is
288
      when ACQUIRE_GET_SINGLE_DATA_BEAT =>
289
          write := '0';
290
          wmask := (others => '0');
291
          --! union used as: 
292
          --!   addr[2:0] & op_sz[1:0] & mem_op_code[M_SZ-1:0] & alloc[0]
293
          --!   [10:8][7:6][5:1][0]
294
          byte_addr := u(10 downto 8);--tst.block.byte_addr;
295
          axi_sz := opSizeToXSize(conv_integer(u(7 downto 6)));
296
          beat_cnt := 0;
297
      when ACQUIRE_GET_PREFETCH_BLOCK |
298
           ACQUIRE_PUT_PREFETCH_BLOCK |
299
           ACQUIRE_GET_BLOCK_DATA =>
300
          -- cache line size / data bits width
301
          write := '0';
302
          wmask := (others => '0');
303
          byte_addr := (others => '0');
304
          axi_sz := conv_std_logic_vector(CFG_NASTI_ADDR_OFFSET,3);
305
          beat_cnt := 7;--3;--tlDataBeats-1; 
306
      when ACQUIRE_PUT_SINGLE_DATA_BEAT =>
307
          -- Single beat data.
308
          write := '1';
309
          --! union used as: 
310
          --!   wmask[log2(64)-1:0] & alloc[0]
311
          wmask := u(CFG_NASTI_DATA_BYTES downto 1);
312
          byte_addr := (others => '0');
313
          axi_sz := conv_std_logic_vector(CFG_NASTI_ADDR_OFFSET,3);
314
          beat_cnt := 0;
315
      when ACQUIRE_PUT_BLOCK_DATA =>
316
          -- Multibeat data.
317
          write := '1';
318
          wmask := (others => '1');
319
          byte_addr := (others => '0');
320
          axi_sz := conv_std_logic_vector(CFG_NASTI_ADDR_OFFSET,3);
321
          beat_cnt := 7;--3;--tlDataBeats-1; 
322
      when ACQUIRE_PUT_ATOMIC_DATA =>
323
          -- Single beat data. 64 bits width
324
          write := '1';
325
          --if CFG_NASTI_DATA_BITS = 128 then
326
          --    if u(12) = '0' then
327
          --        wmask(7 downto 0) := (others => '1');
328
          --        wmask(15 downto 8) := (others => '0');
329
          --    else 
330
          --        wmask(7 downto 0) := (others => '0');
331
          --        wmask(15 downto 8) := (others => '1');
332
          --    end if;
333
          --else
334
              wmask := (others => '1');
335
          --end if;
336
          byte_addr := (others => '0');
337
          axi_sz := opSizeToXSize(conv_integer(u(7 downto 6)));
338
          beat_cnt := 0;
339
      when others =>
340
          write := '0';
341
          wmask := (others => '0');
342
          byte_addr := (others => '0');
343
          axi_sz := (others => '0');
344
          beat_cnt := 0;
345
      end case;
346
    else --! built_in = '0'
347
      --! Cached request
348
      case a_type is
349
      when CACHED_ACQUIRE_SHARED =>
350
          --! Uncore/coherence/Metadata.scala
351
          --!      union = op_code[4:0] & '1';
352
          write := '0';
353
          wmask := (others => '0');
354
          byte_addr := u(10 downto 8);--tst.block.byte_addr;
355
          axi_sz := opSizeToXSize(conv_integer(u(7 downto 6)));
356
          beat_cnt := 0;
357
      when CACHED_ACQUIRE_EXCLUSIVE =>
358
          -- Single beat data.
359
          write := '1';
360
          --! Uncore/coherence/Metadata.scala
361
          --!      union = op_code[4:0] & '1';
362
          --! unclear how to manage it.
363
          --wmask := u(CFG_NASTI_DATA_BYTES downto 1);
364
          wmask := (others => '1');
365
          byte_addr := (others => '0');
366
          axi_sz := conv_std_logic_vector(CFG_NASTI_ADDR_OFFSET,3);
367
          beat_cnt := 0;
368
      when others =>
369
          write := '0';
370
          wmask := (others => '0');
371
          byte_addr := (others => '0');
372
          axi_sz := (others => '0');
373
          beat_cnt := 0;
374
      end case;
375
    end if;
376
  end procedure;
377
 
378
end; -- package body

powered by: WebSVN 2.1.0

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