2011-10-26 08:02:47 +02:00
|
|
|
package Top {
|
|
|
|
|
|
|
|
import Chisel._;
|
|
|
|
import Node._;
|
|
|
|
import Constants._;
|
|
|
|
|
|
|
|
class ioMem() extends Bundle
|
|
|
|
{
|
|
|
|
val req_val = Bool('output);
|
|
|
|
val req_rdy = Bool('input);
|
|
|
|
val req_rw = Bool('output);
|
2011-11-10 08:18:14 +01:00
|
|
|
val req_addr = UFix(PADDR_BITS, 'output);
|
2011-12-09 09:42:43 +01:00
|
|
|
val req_wdata = Bits(MEM_DATA_BITS, 'output);
|
|
|
|
val req_tag = Bits(MEM_TAG_BITS, 'output);
|
2011-10-26 08:02:47 +02:00
|
|
|
|
|
|
|
val resp_val = Bool('input);
|
2011-12-09 09:42:43 +01:00
|
|
|
val resp_tag = Bits(MEM_TAG_BITS, 'input);
|
|
|
|
val resp_data = Bits(MEM_DATA_BITS, 'input);
|
2011-10-26 08:02:47 +02:00
|
|
|
}
|
|
|
|
|
2011-12-09 09:42:43 +01:00
|
|
|
class ioMemArbiter extends Bundle() {
|
2011-10-26 08:02:47 +02:00
|
|
|
val mem = new ioMem();
|
|
|
|
val dcache = new ioDcache();
|
|
|
|
// val icache = new ioIcache();
|
|
|
|
val icache = new ioIPrefetcherMem().flip();
|
|
|
|
}
|
|
|
|
|
|
|
|
class rocketMemArbiter extends Component {
|
2011-12-09 09:42:43 +01:00
|
|
|
val io = new ioMemArbiter();
|
2011-10-26 08:02:47 +02:00
|
|
|
|
|
|
|
// *****************************
|
|
|
|
// Interface to memory
|
|
|
|
// *****************************
|
|
|
|
|
|
|
|
// Memory request is valid if either icache or dcache have a valid request
|
|
|
|
io.mem.req_val := (io.icache.req_val || io.dcache.req_val);
|
|
|
|
|
|
|
|
// Set read/write bit. Icache always reads
|
|
|
|
io.mem.req_rw := Mux(io.icache.req_val,Bool(false),io.dcache.req_rw);
|
|
|
|
|
|
|
|
// Give priority to Icache
|
|
|
|
io.mem.req_addr := Mux(io.icache.req_val,io.icache.req_addr,io.dcache.req_addr);
|
|
|
|
|
2011-12-09 09:42:43 +01:00
|
|
|
// low bit of tag=0 for I$, 1 for D$
|
|
|
|
io.mem.req_tag := Cat(Mux(io.icache.req_val, io.icache.req_tag, io.dcache.req_tag), !io.icache.req_val)
|
2011-10-26 08:02:47 +02:00
|
|
|
|
|
|
|
// Just pass through write data (only D$ will write)
|
|
|
|
io.mem.req_wdata := io.dcache.req_wdata;
|
|
|
|
|
|
|
|
// *****************************
|
|
|
|
// Interface to caches
|
|
|
|
// *****************************
|
|
|
|
|
|
|
|
// Read for request from cache if the memory is ready. Give priority to I$
|
|
|
|
io.icache.req_rdy := io.mem.req_rdy;
|
|
|
|
io.dcache.req_rdy := io.mem.req_rdy && !io.icache.req_val;
|
|
|
|
|
|
|
|
// Response will only be valid for D$ or I$ not both because of tag bits
|
2011-12-09 09:42:43 +01:00
|
|
|
io.icache.resp_val := io.mem.resp_val && !io.mem.resp_tag(0).toBool;
|
|
|
|
io.dcache.resp_val := io.mem.resp_val && io.mem.resp_tag(0).toBool;
|
2011-10-26 08:02:47 +02:00
|
|
|
|
|
|
|
// Feed through data to both
|
|
|
|
io.icache.resp_data := io.mem.resp_data;
|
|
|
|
io.dcache.resp_data := io.mem.resp_data;
|
|
|
|
|
2011-12-09 09:42:43 +01:00
|
|
|
io.icache.resp_tag := io.mem.resp_tag >> UFix(1)
|
|
|
|
io.dcache.resp_tag := io.mem.resp_tag >> UFix(1)
|
2011-10-26 08:02:47 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|