altera_merlin_master_agent.sv 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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. // $Id: //acds/rel/18.1std/ip/merlin/altera_merlin_master_agent/altera_merlin_master_agent.sv#1 $
  13. // $Revision: #1 $
  14. // $Date: 2018/07/18 $
  15. // $Author: psgswbuild $
  16. // --------------------------------------
  17. // Merlin Master Agent
  18. //
  19. // Converts Avalon-MM transactions into
  20. // Merlin network packets.
  21. // --------------------------------------
  22. `timescale 1 ns / 1 ns
  23. module altera_merlin_master_agent
  24. #(
  25. // -------------------
  26. // Packet Format Parameters
  27. // -------------------
  28. parameter
  29. PKT_QOS_H = 109,
  30. PKT_QOS_L = 106,
  31. PKT_DATA_SIDEBAND_H = 105,
  32. PKT_DATA_SIDEBAND_L = 98,
  33. PKT_ADDR_SIDEBAND_H = 97,
  34. PKT_ADDR_SIDEBAND_L = 93,
  35. PKT_CACHE_H = 92,
  36. PKT_CACHE_L = 89,
  37. PKT_THREAD_ID_H = 88,
  38. PKT_THREAD_ID_L = 87,
  39. PKT_BEGIN_BURST = 81,
  40. PKT_PROTECTION_H = 80,
  41. PKT_PROTECTION_L = 80,
  42. PKT_BURSTWRAP_H = 79,
  43. PKT_BURSTWRAP_L = 77,
  44. PKT_BYTE_CNT_H = 76,
  45. PKT_BYTE_CNT_L = 74,
  46. PKT_ADDR_H = 73,
  47. PKT_ADDR_L = 42,
  48. PKT_BURST_SIZE_H = 86,
  49. PKT_BURST_SIZE_L = 84,
  50. PKT_BURST_TYPE_H = 94,
  51. PKT_BURST_TYPE_L = 93,
  52. PKT_TRANS_EXCLUSIVE = 83,
  53. PKT_TRANS_LOCK = 82,
  54. PKT_TRANS_COMPRESSED_READ = 41,
  55. PKT_TRANS_POSTED = 40,
  56. PKT_TRANS_WRITE = 39,
  57. PKT_TRANS_READ = 38,
  58. PKT_DATA_H = 37,
  59. PKT_DATA_L = 6,
  60. PKT_BYTEEN_H = 5,
  61. PKT_BYTEEN_L = 2,
  62. PKT_SRC_ID_H = 1,
  63. PKT_SRC_ID_L = 1,
  64. PKT_DEST_ID_H = 0,
  65. PKT_DEST_ID_L = 0,
  66. PKT_RESPONSE_STATUS_L = 110,
  67. PKT_RESPONSE_STATUS_H = 111,
  68. PKT_ORI_BURST_SIZE_L = 112,
  69. PKT_ORI_BURST_SIZE_H = 114,
  70. ST_DATA_W = 115,
  71. ST_CHANNEL_W = 1,
  72. // -------------------
  73. // Agent Parameters
  74. // -------------------
  75. AV_BURSTCOUNT_W = 3,
  76. ID = 1,
  77. SUPPRESS_0_BYTEEN_RSP = 1,
  78. BURSTWRAP_VALUE = 4,
  79. CACHE_VALUE = 0,
  80. SECURE_ACCESS_BIT = 1,
  81. USE_READRESPONSE = 0,
  82. USE_WRITERESPONSE = 0,
  83. // -------------------
  84. // Derived Parameters
  85. // -------------------
  86. PKT_BURSTWRAP_W = PKT_BURSTWRAP_H - PKT_BURSTWRAP_L + 1,
  87. PKT_BYTE_CNT_W = PKT_BYTE_CNT_H - PKT_BYTE_CNT_L + 1,
  88. PKT_PROTECTION_W = PKT_PROTECTION_H - PKT_PROTECTION_L + 1,
  89. PKT_ADDR_W = PKT_ADDR_H - PKT_ADDR_L + 1,
  90. PKT_DATA_W = PKT_DATA_H - PKT_DATA_L + 1,
  91. PKT_BYTEEN_W = PKT_BYTEEN_H - PKT_BYTEEN_L + 1,
  92. PKT_SRC_ID_W = PKT_SRC_ID_H - PKT_SRC_ID_L + 1,
  93. PKT_DEST_ID_W = PKT_DEST_ID_H - PKT_DEST_ID_L + 1,
  94. PKT_BURST_SIZE_W = PKT_BURST_SIZE_H - PKT_BURST_SIZE_L + 1
  95. ) (
  96. // -------------------
  97. // Clock & Reset
  98. // -------------------
  99. input clk,
  100. input reset,
  101. // -------------------
  102. // Avalon-MM Anti-Master
  103. // -------------------
  104. input [PKT_ADDR_W-1 : 0] av_address,
  105. input av_write,
  106. input av_read,
  107. input [PKT_DATA_W-1 : 0] av_writedata,
  108. output reg [PKT_DATA_W-1 : 0] av_readdata,
  109. output reg av_waitrequest,
  110. output reg av_readdatavalid,
  111. input [PKT_BYTEEN_W-1 : 0] av_byteenable,
  112. input [AV_BURSTCOUNT_W-1 : 0] av_burstcount,
  113. input av_debugaccess,
  114. input av_lock,
  115. output reg [1 : 0] av_response,
  116. output reg av_writeresponsevalid,
  117. // -------------------
  118. // Command Source
  119. // -------------------
  120. output reg cp_valid,
  121. output reg [ST_DATA_W-1 : 0] cp_data,
  122. output wire cp_startofpacket,
  123. output wire cp_endofpacket,
  124. input cp_ready,
  125. // -------------------
  126. // Response Sink
  127. // -------------------
  128. input rp_valid,
  129. input [ST_DATA_W-1 : 0] rp_data,
  130. input [ST_CHANNEL_W-1 : 0] rp_channel,
  131. input rp_startofpacket,
  132. input rp_endofpacket,
  133. output reg rp_ready
  134. );
  135. // ------------------------------------------------------------
  136. // Utility Functions
  137. // ------------------------------------------------------------
  138. function integer clogb2;
  139. input [31 : 0] value;
  140. begin
  141. for (clogb2 = 0; value > 0; clogb2 = clogb2 + 1)
  142. value = value >> 1;
  143. clogb2 = clogb2 - 1;
  144. end
  145. endfunction // clogb2
  146. localparam MAX_BURST = 1 << (AV_BURSTCOUNT_W - 1);
  147. localparam NUMSYMBOLS = PKT_BYTEEN_W;
  148. localparam BURSTING = (MAX_BURST > NUMSYMBOLS);
  149. localparam BITS_TO_ZERO = clogb2(NUMSYMBOLS);
  150. localparam BURST_SIZE = clogb2(NUMSYMBOLS);
  151. typedef enum bit [1 : 0]
  152. {
  153. FIXED = 2'b00,
  154. INCR = 2'b01,
  155. WRAP = 2'b10,
  156. OTHER_WRAP = 2'b11
  157. } MerlinBurstType;
  158. // --------------------------------------
  159. // Potential optimization: compare in words to save bits?
  160. // --------------------------------------
  161. wire is_burst;
  162. assign is_burst = (BURSTING) & (av_burstcount > NUMSYMBOLS);
  163. wire [31 : 0] burstwrap_value_int = BURSTWRAP_VALUE;
  164. wire [31 : 0] id_int = ID;
  165. wire [PKT_BURST_SIZE_W-1 : 0] burstsize_sig = BURST_SIZE[PKT_BURST_SIZE_W-1 : 0];
  166. wire [1 : 0] bursttype_value = burstwrap_value_int[PKT_BURSTWRAP_W-1] ? INCR : WRAP;
  167. // --------------------------------------
  168. // Address alignment
  169. //
  170. // The packet format requires that addresses be aligned to
  171. // the transaction size.
  172. // --------------------------------------
  173. wire [PKT_ADDR_W-1 : 0] av_address_aligned;
  174. generate
  175. if (NUMSYMBOLS > 1) begin
  176. assign av_address_aligned =
  177. {av_address[PKT_ADDR_W-1 : BITS_TO_ZERO], {BITS_TO_ZERO {1'b0}}};
  178. end
  179. else begin
  180. assign av_address_aligned = av_address;
  181. end
  182. endgenerate
  183. // --------------------------------------
  184. // Command & Response Construction
  185. // --------------------------------------
  186. always_comb begin
  187. cp_data = '0;
  188. cp_data[PKT_PROTECTION_L] = av_debugaccess;
  189. cp_data[PKT_PROTECTION_L+1] = SECURE_ACCESS_BIT[0]; // secure cache bit
  190. cp_data[PKT_PROTECTION_L+2] = 1'b0; // instruction/data cache bit
  191. cp_data[PKT_BURSTWRAP_H : PKT_BURSTWRAP_L] = burstwrap_value_int[PKT_BURSTWRAP_W-1 : 0];
  192. cp_data[PKT_BYTE_CNT_H : PKT_BYTE_CNT_L] = av_burstcount;
  193. cp_data[PKT_ADDR_H : PKT_ADDR_L] = av_address_aligned;
  194. cp_data[PKT_TRANS_EXCLUSIVE] = 1'b0;
  195. cp_data[PKT_TRANS_LOCK] = av_lock;
  196. cp_data[PKT_TRANS_COMPRESSED_READ] = av_read & is_burst;
  197. cp_data[PKT_TRANS_READ] = av_read;
  198. cp_data[PKT_TRANS_WRITE] = av_write;
  199. cp_data[PKT_TRANS_POSTED] = av_write & !USE_WRITERESPONSE;
  200. cp_data[PKT_DATA_H : PKT_DATA_L] = av_writedata;
  201. cp_data[PKT_BYTEEN_H : PKT_BYTEEN_L] = av_byteenable;
  202. cp_data[PKT_BURST_SIZE_H : PKT_BURST_SIZE_L] = burstsize_sig;
  203. cp_data[PKT_ORI_BURST_SIZE_H : PKT_ORI_BURST_SIZE_L] = burstsize_sig;
  204. cp_data[PKT_BURST_TYPE_H : PKT_BURST_TYPE_L] = bursttype_value;
  205. cp_data[PKT_SRC_ID_H : PKT_SRC_ID_L] = id_int[PKT_SRC_ID_W-1 : 0];
  206. cp_data[PKT_THREAD_ID_H : PKT_THREAD_ID_L] = '0;
  207. cp_data[PKT_CACHE_H : PKT_CACHE_L] = CACHE_VALUE[3 : 0];
  208. cp_data[PKT_QOS_H : PKT_QOS_L] = '0;
  209. cp_data[PKT_ADDR_SIDEBAND_H : PKT_ADDR_SIDEBAND_L] = '0;
  210. cp_data[PKT_DATA_SIDEBAND_H : PKT_DATA_SIDEBAND_L] = '0;
  211. av_readdata = rp_data[PKT_DATA_H : PKT_DATA_L];
  212. if (USE_WRITERESPONSE || USE_READRESPONSE)
  213. av_response = rp_data[PKT_RESPONSE_STATUS_H : PKT_RESPONSE_STATUS_L];
  214. else
  215. av_response = '0;
  216. end
  217. // --------------------------------------
  218. // Command Control
  219. // --------------------------------------
  220. reg hold_waitrequest;
  221. always @ (posedge clk, posedge reset) begin
  222. if (reset)
  223. hold_waitrequest <= 1'b1;
  224. else
  225. hold_waitrequest <= 1'b0;
  226. end
  227. always_comb begin
  228. cp_valid = 0;
  229. if ((av_write || av_read) && ~hold_waitrequest)
  230. cp_valid = 1;
  231. end
  232. generate if (BURSTING) begin
  233. reg sop_enable;
  234. always @(posedge clk, posedge reset) begin
  235. if (reset) begin
  236. sop_enable <= 1'b1;
  237. end
  238. else begin
  239. if (cp_valid && cp_ready) begin
  240. sop_enable <= 1'b0;
  241. if (cp_endofpacket)
  242. sop_enable <= 1'b1;
  243. end
  244. end
  245. end
  246. assign cp_startofpacket = sop_enable;
  247. assign cp_endofpacket = (av_read) | (av_burstcount == NUMSYMBOLS);
  248. end
  249. else begin
  250. assign cp_startofpacket = 1'b1;
  251. assign cp_endofpacket = 1'b1;
  252. end
  253. endgenerate
  254. // --------------------------------------
  255. // Backpressure & Readdatavalid
  256. // --------------------------------------
  257. always_comb begin
  258. rp_ready = 1;
  259. av_readdatavalid = 0;
  260. av_writeresponsevalid = 0;
  261. av_waitrequest = hold_waitrequest | !cp_ready;
  262. if (USE_WRITERESPONSE && (rp_data[PKT_TRANS_WRITE] == 1))
  263. av_writeresponsevalid = rp_valid;
  264. else
  265. av_readdatavalid = rp_valid;
  266. if (SUPPRESS_0_BYTEEN_RSP) begin
  267. if (rp_data[PKT_BYTEEN_H : PKT_BYTEEN_L] == 0)
  268. av_readdatavalid = 0;
  269. end
  270. end
  271. endmodule