altera_merlin_burst_uncompressor.sv 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. // (C) 2001-2018 Intel Corporation. All rights reserved.
  2. // Your use of Intel Corporation's design tools, logic functions and other
  3. // software and tools, and its AMPP partner logic functions, and any output
  4. // files from any of the foregoing (including device programming or simulation
  5. // files), and any associated documentation or information are expressly subject
  6. // to the terms and conditions of the Intel Program License Subscription
  7. // Agreement, Intel FPGA IP License Agreement, or other applicable
  8. // license agreement, including, without limitation, that your use is for the
  9. // sole purpose of programming logic devices manufactured by Intel and sold by
  10. // Intel or its authorized distributors. Please refer to the applicable
  11. // agreement for further details.
  12. // (C) 2001-2012 Altera Corporation. All rights reserved.
  13. // Your use of Altera Corporation's design tools, logic functions and other
  14. // software and tools, and its AMPP partner logic functions, and any output
  15. // files any of the foregoing (including device programming or simulation
  16. // files), and any associated documentation or information are expressly subject
  17. // to the terms and conditions of the Altera Program License Subscription
  18. // Agreement, Altera MegaCore Function License Agreement, or other applicable
  19. // license agreement, including, without limitation, that your use is for the
  20. // sole purpose of programming logic devices manufactured by Altera and sold by
  21. // Altera or its authorized distributors. Please refer to the applicable
  22. // agreement for further details.
  23. // $Id: //acds/rel/18.1std/ip/merlin/altera_merlin_slave_agent/altera_merlin_burst_uncompressor.sv#1 $
  24. // $Revision: #1 $
  25. // $Date: 2018/07/18 $
  26. // $Author: psgswbuild $
  27. // ------------------------------------------
  28. // Merlin Burst Uncompressor
  29. //
  30. // Compressed read bursts -> uncompressed
  31. // ------------------------------------------
  32. `timescale 1 ns / 1 ns
  33. module altera_merlin_burst_uncompressor
  34. #(
  35. parameter ADDR_W = 16,
  36. parameter BURSTWRAP_W = 3,
  37. parameter BYTE_CNT_W = 4,
  38. parameter PKT_SYMBOLS = 4,
  39. parameter BURST_SIZE_W = 3
  40. )
  41. (
  42. input clk,
  43. input reset,
  44. // sink ST signals
  45. input sink_startofpacket,
  46. input sink_endofpacket,
  47. input sink_valid,
  48. output sink_ready,
  49. // sink ST "data"
  50. input [ADDR_W - 1: 0] sink_addr,
  51. input [BURSTWRAP_W - 1 : 0] sink_burstwrap,
  52. input [BYTE_CNT_W - 1 : 0] sink_byte_cnt,
  53. input sink_is_compressed,
  54. input [BURST_SIZE_W-1 : 0] sink_burstsize,
  55. // source ST signals
  56. output source_startofpacket,
  57. output source_endofpacket,
  58. output source_valid,
  59. input source_ready,
  60. // source ST "data"
  61. output [ADDR_W - 1: 0] source_addr,
  62. output [BURSTWRAP_W - 1 : 0] source_burstwrap,
  63. output [BYTE_CNT_W - 1 : 0] source_byte_cnt,
  64. // Note: in the slave agent, the output should always be uncompressed. In
  65. // other applications, it may be required to leave-compressed or not. How to
  66. // control? Seems like a simple mux - pass-through if no uncompression is
  67. // required.
  68. output source_is_compressed,
  69. output [BURST_SIZE_W-1 : 0] source_burstsize
  70. );
  71. //----------------------------------------------------
  72. // AXSIZE decoding
  73. //
  74. // Turns the axsize value into the actual number of bytes
  75. // being transferred.
  76. // ---------------------------------------------------
  77. function reg[63:0] bytes_in_transfer;
  78. input [BURST_SIZE_W-1:0] axsize;
  79. case (axsize)
  80. 4'b0000: bytes_in_transfer = 64'b0000000000000000000000000000000000000000000000000000000000000001;
  81. 4'b0001: bytes_in_transfer = 64'b0000000000000000000000000000000000000000000000000000000000000010;
  82. 4'b0010: bytes_in_transfer = 64'b0000000000000000000000000000000000000000000000000000000000000100;
  83. 4'b0011: bytes_in_transfer = 64'b0000000000000000000000000000000000000000000000000000000000001000;
  84. 4'b0100: bytes_in_transfer = 64'b0000000000000000000000000000000000000000000000000000000000010000;
  85. 4'b0101: bytes_in_transfer = 64'b0000000000000000000000000000000000000000000000000000000000100000;
  86. 4'b0110: bytes_in_transfer = 64'b0000000000000000000000000000000000000000000000000000000001000000;
  87. 4'b0111: bytes_in_transfer = 64'b0000000000000000000000000000000000000000000000000000000010000000;
  88. 4'b1000: bytes_in_transfer = 64'b0000000000000000000000000000000000000000000000000000000100000000;
  89. 4'b1001: bytes_in_transfer = 64'b0000000000000000000000000000000000000000000000000000001000000000;
  90. default:bytes_in_transfer = 64'b0000000000000000000000000000000000000000000000000000000000000001;
  91. endcase
  92. endfunction
  93. // num_symbols is PKT_SYMBOLS, appropriately sized.
  94. wire [31:0] int_num_symbols = PKT_SYMBOLS;
  95. wire [BYTE_CNT_W-1:0] num_symbols = int_num_symbols[BYTE_CNT_W-1:0];
  96. // def: Burst Compression. In a merlin network, a compressed burst is one
  97. // which is transmitted in a single beat. Example: read burst. In
  98. // constrast, an uncompressed burst (example: write burst) is transmitted in
  99. // one beat per writedata item.
  100. //
  101. // For compressed bursts which require response packets, burst
  102. // uncompression is required. Concrete example: a read burst of size 8
  103. // occupies one response-fifo position. When that fifo position reaches the
  104. // front of the FIFO, the slave starts providing the required 8 readdatavalid
  105. // pulses. The 8 return response beats must be provided in a single packet,
  106. // with incrementing address and decrementing byte_cnt fields. Upon receipt
  107. // of the final readdata item of the burst, the response FIFO item is
  108. // retired.
  109. // Burst uncompression logic provides:
  110. // a) 2-state FSM (idle, busy)
  111. // reset to idle state
  112. // transition to busy state for 2nd and subsequent rdv pulses
  113. // - a single-cycle burst (aka non-burst read) causes no transition to
  114. // busy state.
  115. // b) response startofpacket/endofpacket logic. The response FIFO item
  116. // will have sop asserted, and may have eop asserted. (In the case of
  117. // multiple read bursts transmit in the command fabric in a single packet,
  118. // the eop assertion will come in a later FIFO item.) To support packet
  119. // conservation, and emit a well-formed packet on the response fabric,
  120. // i) response fabric startofpacket is asserted only for the first resp.
  121. // beat;
  122. // ii) response fabric endofpacket is asserted only for the last resp.
  123. // beat.
  124. // c) response address field. The response address field contains an
  125. // incrementing sequence, such that each readdata item is associated with
  126. // its slave-map location. N.b. a) computing the address correctly requires
  127. // knowledge of burstwrap behavior b) there may be no clients of the address
  128. // field, which makes this field a good target for optimization. See
  129. // burst_uncompress_address_counter below.
  130. // d) response byte_cnt field. The response byte_cnt field contains a
  131. // decrementing sequence, such that each beat of the response contains the
  132. // count of bytes to follow. In the case of sub-bursts in a single packet,
  133. // the byte_cnt field may decrement down to num_symbols, then back up to
  134. // some value, multiple times in the packet.
  135. reg burst_uncompress_busy;
  136. reg [BYTE_CNT_W:0] burst_uncompress_byte_counter;
  137. wire [BYTE_CNT_W-1:0] burst_uncompress_byte_counter_lint;
  138. wire first_packet_beat;
  139. wire last_packet_beat;
  140. assign first_packet_beat = sink_valid & ~burst_uncompress_busy;
  141. assign burst_uncompress_byte_counter_lint = burst_uncompress_byte_counter[BYTE_CNT_W-1:0];
  142. // First cycle: burst_uncompress_byte_counter isn't ready yet, mux the input to
  143. // the output.
  144. assign source_byte_cnt =
  145. first_packet_beat ? sink_byte_cnt : burst_uncompress_byte_counter_lint;
  146. assign source_valid = sink_valid;
  147. // Last packet beat is set throughout receipt of an uncompressed read burst
  148. // from the response FIFO - this forces all the burst uncompression machinery
  149. // idle.
  150. assign last_packet_beat = ~sink_is_compressed |
  151. (
  152. burst_uncompress_busy ?
  153. (sink_valid & (burst_uncompress_byte_counter_lint == num_symbols)) :
  154. sink_valid & (sink_byte_cnt == num_symbols)
  155. );
  156. always @(posedge clk or posedge reset) begin
  157. if (reset) begin
  158. burst_uncompress_busy <= '0;
  159. burst_uncompress_byte_counter <= '0;
  160. end
  161. else begin
  162. if (source_valid & source_ready & sink_valid) begin
  163. // No matter what the current state, last_packet_beat leads to
  164. // idle.
  165. if (last_packet_beat) begin
  166. burst_uncompress_busy <= '0;
  167. burst_uncompress_byte_counter <= '0;
  168. end
  169. else begin
  170. if (burst_uncompress_busy) begin
  171. burst_uncompress_byte_counter <= (burst_uncompress_byte_counter > 0) ?
  172. (burst_uncompress_byte_counter_lint - num_symbols) :
  173. (sink_byte_cnt - num_symbols);
  174. end
  175. else begin // not busy, at least one more beat to go
  176. burst_uncompress_byte_counter <= sink_byte_cnt - num_symbols;
  177. // To do: should busy go true for numsymbols-size compressed
  178. // bursts?
  179. burst_uncompress_busy <= 1'b1;
  180. end
  181. end
  182. end
  183. end
  184. end
  185. reg [ADDR_W - 1 : 0 ] burst_uncompress_address_base;
  186. reg [ADDR_W - 1 : 0] burst_uncompress_address_offset;
  187. wire [63:0] decoded_burstsize_wire;
  188. wire [ADDR_W-1:0] decoded_burstsize;
  189. localparam ADD_BURSTWRAP_W = (ADDR_W > BURSTWRAP_W) ? ADDR_W : BURSTWRAP_W;
  190. wire [ADD_BURSTWRAP_W-1:0] addr_width_burstwrap;
  191. // The input burstwrap value can be used as a mask against address values,
  192. // but with one caveat: the address width may be (probably is) wider than
  193. // the burstwrap width. The spec says: extend the msb of the burstwrap
  194. // value out over the entire address width (but only if the address width
  195. // actually is wider than the burstwrap width; otherwise it's a 0-width or
  196. // negative range and concatenation multiplier).
  197. generate
  198. if (ADDR_W > BURSTWRAP_W) begin : addr_sign_extend
  199. // Sign-extend, just wires:
  200. assign addr_width_burstwrap[ADDR_W - 1 : BURSTWRAP_W] =
  201. {(ADDR_W - BURSTWRAP_W) {sink_burstwrap[BURSTWRAP_W - 1]}};
  202. assign addr_width_burstwrap[BURSTWRAP_W-1:0] = sink_burstwrap [BURSTWRAP_W-1:0];
  203. end
  204. else begin
  205. assign addr_width_burstwrap[BURSTWRAP_W-1 : 0] = sink_burstwrap;
  206. end
  207. endgenerate
  208. always @(posedge clk or posedge reset) begin
  209. if (reset) begin
  210. burst_uncompress_address_base <= '0;
  211. end
  212. else if (first_packet_beat & source_ready) begin
  213. burst_uncompress_address_base <= sink_addr & ~addr_width_burstwrap[ADDR_W-1:0];
  214. end
  215. end
  216. assign decoded_burstsize_wire = bytes_in_transfer(sink_burstsize); //expand it to 64 bits
  217. assign decoded_burstsize = decoded_burstsize_wire[ADDR_W-1:0]; //then take the width that is needed
  218. wire [ADDR_W : 0] p1_burst_uncompress_address_offset =
  219. (
  220. (first_packet_beat ?
  221. sink_addr :
  222. burst_uncompress_address_offset) + decoded_burstsize
  223. ) &
  224. addr_width_burstwrap[ADDR_W-1:0];
  225. wire [ADDR_W-1:0] p1_burst_uncompress_address_offset_lint = p1_burst_uncompress_address_offset [ADDR_W-1:0];
  226. always @(posedge clk or posedge reset) begin
  227. if (reset) begin
  228. burst_uncompress_address_offset <= '0;
  229. end
  230. else begin
  231. if (source_ready & source_valid) begin
  232. burst_uncompress_address_offset <= p1_burst_uncompress_address_offset_lint;
  233. // if (first_packet_beat) begin
  234. // burst_uncompress_address_offset <=
  235. // (sink_addr + num_symbols) & addr_width_burstwrap;
  236. // end
  237. // else begin
  238. // burst_uncompress_address_offset <=
  239. // (burst_uncompress_address_offset + num_symbols) & addr_width_burstwrap;
  240. // end
  241. end
  242. end
  243. end
  244. // On the first packet beat, send the input address out unchanged,
  245. // while values are computed/registered for 2nd and subsequent beats.
  246. assign source_addr = first_packet_beat ? sink_addr :
  247. burst_uncompress_address_base | burst_uncompress_address_offset;
  248. assign source_burstwrap = sink_burstwrap;
  249. assign source_burstsize = sink_burstsize;
  250. //-------------------------------------------------------------------
  251. // A single (compressed) read burst will have sop/eop in the same beat.
  252. // A sequence of read sub-bursts emitted by a burst adapter in response to a
  253. // single read burst will have sop on the first sub-burst, eop on the last.
  254. // Assert eop only upon (sink_endofpacket & last_packet_beat) to preserve
  255. // packet conservation.
  256. assign source_startofpacket = sink_startofpacket & ~burst_uncompress_busy;
  257. assign source_endofpacket = sink_endofpacket & last_packet_beat;
  258. assign sink_ready = source_valid & source_ready & last_packet_beat;
  259. // This is correct for the slave agent usage, but won't always be true in the
  260. // width adapter. To do: add an "please uncompress" input, and use it to
  261. // pass-through or modify, and set source_is_compressed accordingly.
  262. assign source_is_compressed = 1'b0;
  263. endmodule