summaryrefslogtreecommitdiff
path: root/rtl
diff options
context:
space:
mode:
authorAlejandro Soto <alejandro@34project.org>2023-10-06 08:24:19 -0600
committerAlejandro Soto <alejandro@34project.org>2023-10-06 08:24:51 -0600
commit8d22db83560d782c2f9e43e7359d7f616a3f4bb0 (patch)
tree92ccf43da05a15f5b8b9785e7bffca3533309918 /rtl
parent4b0ec51f7f6d0d2ad8a3993892a6d535cc7b0995 (diff)
rtl/cache: split token.sv out of cache_control.vs
Diffstat (limited to '')
-rw-r--r--rtl/cache/cache.sv12
-rw-r--r--rtl/cache/cache_control.sv61
-rw-r--r--rtl/cache/token.sv57
3 files changed, 84 insertions, 46 deletions
diff --git a/rtl/cache/cache.sv b/rtl/cache/cache.sv
index 6d5a204..829546f 100644
--- a/rtl/cache/cache.sv
+++ b/rtl/cache/cache.sv
@@ -60,9 +60,9 @@ module cache
word cache_mem_address;
line cache_mem_writedata;
logic cache_core_waitrequest, cache_mem_waitrequest, cache_mem_read, cache_mem_write,
- debug_ready;
+ debug_ready, send, lock_line, unlock_line;
- cache_control #(.TOKEN_AT_RESET(TOKEN_AT_RESET)) control
+ cache_control control
(
.core_read(cache_core_read),
.core_write(cache_core_write),
@@ -72,6 +72,14 @@ module cache
.mem_writedata(cache_mem_writedata),
.mem_read(cache_mem_read),
.mem_write(cache_mem_write),
+
+ .*
+ );
+
+ logic locked, may_send;
+
+ cache_token #(.TOKEN_AT_RESET(TOKEN_AT_RESET)) token
+ (
.*
);
diff --git a/rtl/cache/cache_control.sv b/rtl/cache/cache_control.sv
index 64b4ce1..b3bd220 100644
--- a/rtl/cache/cache_control.sv
+++ b/rtl/cache/cache_control.sv
@@ -1,7 +1,6 @@
`include "cache/defs.sv"
module cache_control
-#(parameter TOKEN_AT_RESET=0)
(
input logic clk,
rst_n,
@@ -22,23 +21,11 @@ module cache_control
output ring_req out_data, // lo que se envía
output logic out_data_valid, // este caché está enviando datos
- input ring_token in_token, // input del token
- input logic in_token_valid, // se está recibiendo el token
-
- output ring_token out_token, // output del token
- output logic out_token_valid, // se está enviando el token
-
// Señales para la SRAM
input addr_tag tag_rd, // valor de la tag de esa línea
input line data_rd, // datos de la línea
input line_state state_rd, // estado de la línnea
- input line monitor_update,
- input logic monitor_commit,
- output logic monitor_acquire,
- monitor_fail,
- monitor_release,
-
output addr_index index_rd,
index_wr,
output logic write_data,
@@ -54,9 +41,21 @@ module cache_control
mem_write,
output line mem_writedata,
+ input logic locked,
+ may_send,
+ output logic send,
+ lock_line,
+ unlock_line,
+
input logic dbg_write,
input addr_index debug_index,
- output logic debug_ready
+ output logic debug_ready,
+
+ input line monitor_update,
+ input logic monitor_commit,
+ output logic monitor_acquire,
+ monitor_fail,
+ monitor_release
);
enum int unsigned
@@ -67,10 +66,10 @@ module cache_control
REPLY
} state, next_state;
- logic accept_snoop, debug, end_reply, in_hold_valid, last_hop, lock_line,
- locked, may_send, may_send_if_token_held, mem_begin, mem_end, mem_read_end,
- mem_wait, out_stall, wait_reply, replace, retry, send, send_inval,
- send_read, snoop_hit, set_reply, unlock_line, writeback;
+ logic accept_snoop, debug, end_reply, in_hold_valid, last_hop,
+ mem_begin, mem_end, mem_read_end, mem_wait, out_stall, wait_reply,
+ replace, retry, send_inval, send_read, snoop_hit, set_reply,
+ writeback;
// in_hold: el paquete actual
ring_req in_hold, send_data, fwd_data, stall_data, out_data_next;
@@ -97,14 +96,6 @@ module cache_control
// Aceptar snoop si no es el último nodo y se tiene un mensaje válido
assign accept_snoop = in_hold_valid && !last_hop && (in_hold.inval || !in_hold.reply);
- // Solo se puede iniciar un request si se tiene el token y el token es
- // válido
- assign may_send = may_send_if_token_held && in_token_valid;
- assign may_send_if_token_held
- = (!in_token.e2.valid || in_token.e2.index != core_index || in_token.e2.tag != core_tag)
- && (!in_token.e1.valid || in_token.e1.index != core_index || in_token.e1.tag != core_tag)
- && (!in_token.e0.valid || in_token.e0.index != core_index || in_token.e0.tag != core_tag);
-
assign out_data = out_stall ? stall_data : out_data_next;
assign out_data_next = send ? send_data : fwd_data;
assign out_data_valid = out_stall || send || (in_hold_valid && !last_hop && in_data_ready);
@@ -392,13 +383,9 @@ module cache_control
always_ff @(posedge clk or negedge rst_n)
if (!rst_n) begin
- out_token <= {($bits(out_token)){1'b0}};
- out_token_valid <= TOKEN_AT_RESET;
-
in_hold_valid <= 0;
out_stall <= 0;
- locked <= 0;
wait_reply <= 0;
mem_read <= 0;
@@ -406,25 +393,11 @@ module cache_control
debug_ready <= 0;
end else begin
- out_token.e0.tag <= core_tag;
- out_token.e0.index <= core_index;
- out_token.e0.valid <= may_send_if_token_held && (send || locked) && !unlock_line;
-
- out_token.e2 <= in_token.e1;
- out_token.e1 <= in_token.e0;
- out_token_valid <= in_token_valid;
-
if (in_data_ready)
in_hold_valid <= in_data_valid;
out_stall <= out_data_valid && !out_data_ready;
- if (lock_line)
- locked <= 1;
-
- if (unlock_line)
- locked <= 0;
-
if (send)
wait_reply <= 1;
diff --git a/rtl/cache/token.sv b/rtl/cache/token.sv
new file mode 100644
index 0000000..cb3e59d
--- /dev/null
+++ b/rtl/cache/token.sv
@@ -0,0 +1,57 @@
+`include "cache/defs.sv"
+
+module cache_token
+#(parameter TOKEN_AT_RESET=0)
+(
+ input logic clk,
+ rst_n,
+
+ input addr_tag core_tag,
+ input addr_index core_index,
+
+ input ring_token in_token, // input del token
+ input logic in_token_valid, // se está recibiendo el token
+
+ output ring_token out_token, // output del token
+ output logic out_token_valid, // se está enviando el token
+
+ input logic send,
+ lock_line,
+ unlock_line,
+ output logic locked,
+ may_send
+);
+
+ logic may_send_if_token_held;
+
+ // Solo se puede iniciar un request si se tiene el token y el token es
+ // válido
+ assign may_send = may_send_if_token_held && in_token_valid;
+ assign may_send_if_token_held
+ = (!in_token.e2.valid || in_token.e2.index != core_index || in_token.e2.tag != core_tag)
+ && (!in_token.e1.valid || in_token.e1.index != core_index || in_token.e1.tag != core_tag)
+ && (!in_token.e0.valid || in_token.e0.index != core_index || in_token.e0.tag != core_tag);
+
+ always_ff @(posedge clk or negedge rst_n)
+ if (!rst_n) begin
+ out_token <= {($bits(out_token)){1'b0}};
+ out_token_valid <= TOKEN_AT_RESET;
+
+ locked <= 0;
+ end else begin
+ out_token.e0.tag <= core_tag;
+ out_token.e0.index <= core_index;
+ out_token.e0.valid <= may_send_if_token_held && (send || locked) && !unlock_line;
+
+ out_token.e2 <= in_token.e1;
+ out_token.e1 <= in_token.e0;
+ out_token_valid <= in_token_valid;
+
+ if (lock_line)
+ locked <= 1;
+
+ if (unlock_line)
+ locked <= 0;
+ end
+
+endmodule