2012-02-26 02:09:26 +01:00
|
|
|
package rocket
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2011-11-09 23:52:17 +01:00
|
|
|
import Chisel._;
|
2011-10-26 08:02:47 +02:00
|
|
|
import Node._;
|
2011-11-09 23:52:17 +01:00
|
|
|
import Constants._;
|
2011-10-26 08:02:47 +02:00
|
|
|
import scala.math._;
|
|
|
|
|
2011-11-10 06:54:11 +01:00
|
|
|
// interface between I$ and pipeline/ITLB (32 bits wide)
|
2012-06-05 22:30:39 +02:00
|
|
|
class ioImem extends Bundle
|
2011-10-26 08:02:47 +02:00
|
|
|
{
|
2012-01-18 19:28:48 +01:00
|
|
|
val invalidate = Bool(INPUT);
|
|
|
|
val itlb_miss = Bool(INPUT);
|
|
|
|
val req_val = Bool(INPUT);
|
|
|
|
val req_idx = Bits(PGIDX_BITS, INPUT);
|
|
|
|
val req_ppn = Bits(PPN_BITS, INPUT);
|
|
|
|
val resp_data = Bits(32, OUTPUT);
|
|
|
|
val resp_val = Bool(OUTPUT);
|
2011-10-26 08:02:47 +02:00
|
|
|
}
|
|
|
|
|
2012-02-07 23:07:42 +01:00
|
|
|
class ioRocketICache extends Bundle()
|
2011-11-05 04:52:21 +01:00
|
|
|
{
|
2011-10-26 08:02:47 +02:00
|
|
|
val cpu = new ioImem();
|
2012-03-06 09:31:44 +01:00
|
|
|
val mem = new ioUncachedRequestor
|
2011-10-26 08:02:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// basic direct mapped instruction cache
|
2011-11-10 09:50:09 +01:00
|
|
|
// 32 bit wide cpu port, 128 bit wide memory port, 64 byte cachelines
|
2011-10-26 08:02:47 +02:00
|
|
|
// parameters :
|
|
|
|
// lines = # cache lines
|
2012-04-10 09:09:58 +02:00
|
|
|
class rocketICache(sets: Int, assoc: Int, co: CoherencePolicyWithUncached) extends Component
|
2012-04-04 03:06:02 +02:00
|
|
|
{
|
2012-02-07 23:07:42 +01:00
|
|
|
val io = new ioRocketICache();
|
2011-11-07 09:58:25 +01:00
|
|
|
|
2012-01-25 01:51:30 +01:00
|
|
|
val lines = sets * assoc;
|
2011-11-09 23:52:17 +01:00
|
|
|
val addrbits = PADDR_BITS;
|
2012-06-06 21:47:17 +02:00
|
|
|
val indexbits = log2Up(sets);
|
2011-12-12 15:49:16 +01:00
|
|
|
val offsetbits = OFFSET_BITS;
|
2011-10-26 08:02:47 +02:00
|
|
|
val tagmsb = addrbits - 1;
|
|
|
|
val taglsb = indexbits+offsetbits;
|
2011-11-12 09:25:06 +01:00
|
|
|
val tagbits = addrbits-taglsb;
|
2011-10-26 08:02:47 +02:00
|
|
|
val indexmsb = taglsb-1;
|
|
|
|
val indexlsb = offsetbits;
|
|
|
|
val offsetmsb = indexlsb-1;
|
2011-11-07 09:58:25 +01:00
|
|
|
val databits = 32;
|
2012-06-06 21:47:17 +02:00
|
|
|
val offsetlsb = log2Up(databits/8);
|
|
|
|
val rf_cnt_bits = log2Up(REFILL_CYCLES);
|
2012-01-25 00:13:49 +01:00
|
|
|
|
|
|
|
require(PGIDX_BITS >= taglsb); // virtually-indexed, physically-tagged constraint
|
2012-06-06 21:47:17 +02:00
|
|
|
require(isPow2(sets) && isPow2(assoc));
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2012-01-12 03:27:11 +01:00
|
|
|
val s_reset :: s_ready :: s_request :: s_refill_wait :: s_refill :: Nil = Enum(5) { UFix() };
|
2011-10-26 08:02:47 +02:00
|
|
|
val state = Reg(resetVal = s_reset);
|
2012-03-06 09:31:44 +01:00
|
|
|
val invalidated = Reg() { Bool() }
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2012-01-25 01:51:30 +01:00
|
|
|
val r_cpu_req_idx = Reg { Bits() }
|
|
|
|
val r_cpu_req_ppn = Reg { Bits() }
|
2011-11-12 09:25:06 +01:00
|
|
|
val r_cpu_req_val = Reg(resetVal = Bool(false));
|
2012-01-12 04:20:20 +01:00
|
|
|
|
2012-05-24 19:33:15 +02:00
|
|
|
val rdy = Bool()
|
|
|
|
val tag_hit = Bool()
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2012-01-12 04:20:20 +01:00
|
|
|
when (io.cpu.req_val && rdy) {
|
2012-02-12 02:20:33 +01:00
|
|
|
r_cpu_req_val := Bool(true)
|
|
|
|
r_cpu_req_idx := io.cpu.req_idx
|
2011-11-05 04:52:21 +01:00
|
|
|
}
|
2012-02-12 02:20:33 +01:00
|
|
|
.otherwise {
|
|
|
|
r_cpu_req_val := Bool(false)
|
2011-11-05 04:52:21 +01:00
|
|
|
}
|
2012-01-25 00:13:49 +01:00
|
|
|
when (state === s_ready && r_cpu_req_val && !io.cpu.itlb_miss) {
|
2012-02-12 02:20:33 +01:00
|
|
|
r_cpu_req_ppn := io.cpu.req_ppn
|
2012-01-25 00:13:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
val r_cpu_hit_addr = Cat(io.cpu.req_ppn, r_cpu_req_idx)
|
|
|
|
val r_cpu_hit_tag = r_cpu_hit_addr(tagmsb,taglsb)
|
|
|
|
val r_cpu_miss_addr = Cat(r_cpu_req_ppn, r_cpu_req_idx)
|
|
|
|
val r_cpu_miss_tag = r_cpu_miss_addr(tagmsb,taglsb)
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2011-11-13 07:13:29 +01:00
|
|
|
// refill counter
|
2011-12-09 09:42:43 +01:00
|
|
|
val refill_count = Reg(resetVal = UFix(0, rf_cnt_bits));
|
2012-02-29 12:08:04 +01:00
|
|
|
when (io.mem.xact_rep.valid) {
|
2012-02-12 02:20:33 +01:00
|
|
|
refill_count := refill_count + UFix(1);
|
2011-11-05 04:52:21 +01:00
|
|
|
}
|
2012-03-06 09:31:44 +01:00
|
|
|
val refill_done = io.mem.xact_rep.valid && refill_count.andR
|
2012-01-25 01:51:30 +01:00
|
|
|
|
2012-06-06 21:47:17 +02:00
|
|
|
val repl_way = if (assoc == 1) UFix(0) else LFSR16(state === s_ready && r_cpu_req_val && !io.cpu.itlb_miss && !tag_hit)(log2Up(assoc)-1,0)
|
|
|
|
val word_shift = Cat(r_cpu_req_idx(offsetmsb-rf_cnt_bits,offsetlsb), UFix(0, log2Up(databits))).toUFix
|
2012-03-07 00:47:19 +01:00
|
|
|
val tag_we = refill_done
|
2011-11-12 09:25:06 +01:00
|
|
|
val tag_addr =
|
2012-03-06 09:31:44 +01:00
|
|
|
Mux((state === s_refill), r_cpu_req_idx(indexmsb,indexlsb),
|
2012-01-25 00:13:49 +01:00
|
|
|
io.cpu.req_idx(indexmsb,indexlsb)).toUFix;
|
2011-12-04 04:41:15 +01:00
|
|
|
val data_addr =
|
2012-01-25 00:13:49 +01:00
|
|
|
Mux((state === s_refill_wait) || (state === s_refill), Cat(r_cpu_req_idx(indexmsb,offsetbits), refill_count),
|
|
|
|
io.cpu.req_idx(indexmsb, offsetbits-rf_cnt_bits)).toUFix;
|
2012-01-25 01:51:30 +01:00
|
|
|
|
2012-05-01 10:24:36 +02:00
|
|
|
val data_mux = (new Mux1H(assoc)){Bits(width = databits)}
|
2012-01-25 01:51:30 +01:00
|
|
|
var any_hit = Bool(false)
|
|
|
|
for (i <- 0 until assoc)
|
|
|
|
{
|
|
|
|
val repl_me = (repl_way === UFix(i))
|
2012-06-08 09:13:14 +02:00
|
|
|
val tag_array = Mem(sets, seqRead = true){ Bits(width = tagbits) }
|
2012-06-06 11:47:22 +02:00
|
|
|
val tag_rdata = Reg() { Bits(width = tagbits) }
|
|
|
|
when (tag_we && repl_me) { tag_array(tag_addr) := r_cpu_miss_tag }
|
|
|
|
.otherwise { tag_rdata := tag_array(tag_addr) }
|
2012-01-25 01:51:30 +01:00
|
|
|
|
|
|
|
// valid bit array
|
2012-02-27 02:51:46 +01:00
|
|
|
val vb_array = Reg(resetVal = Bits(0, sets));
|
2012-01-25 01:51:30 +01:00
|
|
|
when (io.cpu.invalidate) {
|
2012-03-06 09:31:44 +01:00
|
|
|
vb_array := Bits(0)
|
2012-01-25 01:51:30 +01:00
|
|
|
}
|
2012-02-12 02:20:33 +01:00
|
|
|
.elsewhen (tag_we && repl_me) {
|
2012-03-06 09:31:44 +01:00
|
|
|
vb_array := vb_array.bitSet(r_cpu_req_idx(indexmsb,indexlsb).toUFix, !invalidated)
|
2012-01-25 01:51:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
val valid = vb_array(r_cpu_req_idx(indexmsb,indexlsb)).toBool;
|
|
|
|
val hit = valid && (tag_rdata === r_cpu_hit_addr(tagmsb,taglsb))
|
|
|
|
|
|
|
|
// data array
|
2012-06-08 09:13:14 +02:00
|
|
|
val data_array = Mem(sets*REFILL_CYCLES, seqRead = true){ io.mem.xact_rep.bits.data.clone }
|
2012-06-06 11:47:22 +02:00
|
|
|
val data_out = Reg(){ io.mem.xact_rep.bits.data.clone }
|
|
|
|
when (io.mem.xact_rep.valid && repl_me) { data_array(data_addr) := io.mem.xact_rep.bits.data }
|
|
|
|
.otherwise { data_out := data_array(data_addr) }
|
2012-01-25 01:51:30 +01:00
|
|
|
|
|
|
|
data_mux.io.sel(i) := hit
|
|
|
|
data_mux.io.in(i) := (data_out >> word_shift)(databits-1,0);
|
|
|
|
|
|
|
|
any_hit = any_hit || hit
|
|
|
|
}
|
|
|
|
tag_hit := any_hit
|
2011-12-04 04:41:15 +01:00
|
|
|
|
2012-03-07 00:47:19 +01:00
|
|
|
val finish_q = (new queue(1)) { new TransactionFinish }
|
2012-03-09 03:47:32 +01:00
|
|
|
finish_q.io.enq.valid := refill_done && io.mem.xact_rep.bits.require_ack
|
2012-03-07 00:47:19 +01:00
|
|
|
finish_q.io.enq.bits.global_xact_id := io.mem.xact_rep.bits.global_xact_id
|
|
|
|
|
2011-11-07 09:58:25 +01:00
|
|
|
// output signals
|
2012-01-25 00:13:49 +01:00
|
|
|
io.cpu.resp_val := !io.cpu.itlb_miss && (state === s_ready) && r_cpu_req_val && tag_hit;
|
2012-01-25 01:51:30 +01:00
|
|
|
rdy := !io.cpu.itlb_miss && (state === s_ready) && (!r_cpu_req_val || tag_hit);
|
|
|
|
io.cpu.resp_data := data_mux.io.out
|
2012-03-07 00:47:19 +01:00
|
|
|
io.mem.xact_init.valid := (state === s_request) && finish_q.io.enq.ready
|
2012-04-10 09:09:58 +02:00
|
|
|
io.mem.xact_init.bits.x_type := co.getTransactionInitTypeOnUncachedRead
|
2012-02-29 12:08:04 +01:00
|
|
|
io.mem.xact_init.bits.address := r_cpu_miss_addr(tagmsb,indexlsb).toUFix
|
2012-03-07 00:47:19 +01:00
|
|
|
io.mem.xact_finish <> finish_q.io.deq
|
2011-10-26 08:02:47 +02:00
|
|
|
|
|
|
|
// control state machine
|
2012-03-06 09:31:44 +01:00
|
|
|
when (io.cpu.invalidate) {
|
|
|
|
invalidated := Bool(true)
|
|
|
|
}
|
2011-10-26 08:02:47 +02:00
|
|
|
switch (state) {
|
|
|
|
is (s_reset) {
|
2012-02-12 02:20:33 +01:00
|
|
|
state := s_ready;
|
2011-10-26 08:02:47 +02:00
|
|
|
}
|
|
|
|
is (s_ready) {
|
2012-03-06 09:31:44 +01:00
|
|
|
when (r_cpu_req_val && !tag_hit && !io.cpu.itlb_miss) {
|
2012-02-12 02:20:33 +01:00
|
|
|
state := s_request;
|
2011-11-13 00:00:45 +01:00
|
|
|
}
|
2012-03-06 09:31:44 +01:00
|
|
|
invalidated := Bool(false)
|
2011-10-26 08:02:47 +02:00
|
|
|
}
|
|
|
|
is (s_request)
|
|
|
|
{
|
2012-03-07 00:47:19 +01:00
|
|
|
when (io.mem.xact_init.ready && finish_q.io.enq.ready) {
|
2012-02-12 02:20:33 +01:00
|
|
|
state := s_refill_wait;
|
2011-11-12 09:25:06 +01:00
|
|
|
}
|
2011-10-26 08:02:47 +02:00
|
|
|
}
|
|
|
|
is (s_refill_wait) {
|
2012-03-06 09:31:44 +01:00
|
|
|
when (io.mem.xact_abort.valid) {
|
|
|
|
state := s_request
|
|
|
|
}
|
2012-02-29 12:08:04 +01:00
|
|
|
when (io.mem.xact_rep.valid) {
|
2012-02-12 02:20:33 +01:00
|
|
|
state := s_refill;
|
2011-11-12 09:25:06 +01:00
|
|
|
}
|
2011-10-26 08:02:47 +02:00
|
|
|
}
|
|
|
|
is (s_refill) {
|
2012-03-06 09:31:44 +01:00
|
|
|
when (refill_done) {
|
2012-02-12 02:20:33 +01:00
|
|
|
state := s_ready;
|
2011-11-12 09:25:06 +01:00
|
|
|
}
|
2011-10-26 08:02:47 +02:00
|
|
|
}
|
2012-02-29 12:08:04 +01:00
|
|
|
}
|
2011-10-26 08:02:47 +02:00
|
|
|
}
|