2015-09-01 23:47:18 +02:00
|
|
|
package uncore
|
|
|
|
|
|
|
|
import Chisel._
|
2016-04-22 00:35:37 +02:00
|
|
|
import junctions.SmiIO
|
2015-10-22 03:16:44 +02:00
|
|
|
import cde.Parameters
|
2016-02-17 23:06:34 +01:00
|
|
|
import scala.collection.mutable.HashMap
|
|
|
|
import scala.collection.mutable.ArrayBuffer
|
2015-09-01 23:47:18 +02:00
|
|
|
|
2016-02-17 23:06:34 +01:00
|
|
|
/** Stores a map between SCR file names and address in the SCR file, which can
|
|
|
|
* later be dumped to a header file for the test bench. */
|
2016-02-23 05:15:57 +01:00
|
|
|
class SCRFileMap(prefix: String, maxAddress: Int, baseAddress: BigInt) {
|
2016-02-17 23:06:34 +01:00
|
|
|
private val addr2name = HashMap.empty[Int, String]
|
|
|
|
private val name2addr = HashMap.empty[String, Int]
|
|
|
|
|
|
|
|
def allocate(address: Int, name: String): Int = {
|
|
|
|
Predef.assert(!addr2name.contains(address), "address already allocated")
|
|
|
|
Predef.assert(!name2addr.contains(name), "name already allocated")
|
|
|
|
Predef.assert(address < maxAddress, "address too large")
|
|
|
|
addr2name += (address -> name)
|
|
|
|
name2addr += (name -> address)
|
2016-02-23 05:15:57 +01:00
|
|
|
println(prefix + ": %x -> ".format(baseAddress + address) + name)
|
2016-02-17 23:06:34 +01:00
|
|
|
address
|
|
|
|
}
|
|
|
|
|
|
|
|
def allocate(name: String): Int = {
|
|
|
|
val addr = (0 until maxAddress).filter{ addr => !addr2name.contains(addr) }(0)
|
|
|
|
allocate(addr, name)
|
|
|
|
}
|
|
|
|
|
|
|
|
def as_c_header(): String = {
|
|
|
|
addr2name.map{ case(address, name) =>
|
2016-04-28 17:31:56 +02:00
|
|
|
List(
|
|
|
|
"#define " + prefix + "__" + name + "__PADDR 0x%x".format(baseAddress + address),
|
|
|
|
"#define " + prefix + "__" + name + "__OFFSET 0x%x".format(address)
|
|
|
|
)
|
|
|
|
}.flatten.mkString("\n") + "\n"
|
2016-02-17 23:06:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class SCRIO(map: SCRFileMap)(implicit p: Parameters) extends HtifBundle()(p) {
|
2016-01-14 22:47:47 +01:00
|
|
|
val rdata = Vec(nSCR, Bits(INPUT, scrDataBits))
|
2015-09-01 23:47:18 +02:00
|
|
|
val wen = Bool(OUTPUT)
|
|
|
|
val waddr = UInt(OUTPUT, log2Up(nSCR))
|
2015-10-06 06:41:46 +02:00
|
|
|
val wdata = Bits(OUTPUT, scrDataBits)
|
2016-02-17 23:06:34 +01:00
|
|
|
|
2016-02-23 05:15:57 +01:00
|
|
|
def attach(regs: Seq[Data], name_base: String): Seq[Data] = {
|
|
|
|
regs.zipWithIndex.map{ case(reg, i) => attach(reg, name_base + "__" + i) }
|
|
|
|
}
|
|
|
|
|
2016-03-06 02:20:54 +01:00
|
|
|
def attach(reg: Data, name: String): Data = {
|
2016-02-17 23:06:34 +01:00
|
|
|
val addr = map.allocate(name)
|
2016-03-06 02:20:54 +01:00
|
|
|
when (wen && (waddr === UInt(addr))) {
|
|
|
|
reg := wdata
|
2016-02-17 23:06:34 +01:00
|
|
|
}
|
2016-03-06 02:20:54 +01:00
|
|
|
rdata(addr) := reg
|
2016-02-17 23:06:34 +01:00
|
|
|
reg
|
|
|
|
}
|
|
|
|
|
|
|
|
def allocate(address: Int, name: String): Unit = {
|
|
|
|
map.allocate(address, name)
|
|
|
|
}
|
2015-09-01 23:47:18 +02:00
|
|
|
}
|
|
|
|
|
2016-02-23 05:15:57 +01:00
|
|
|
class SCRFile(prefix: String, baseAddress: BigInt)(implicit p: Parameters) extends HtifModule()(p) {
|
|
|
|
val map = new SCRFileMap(prefix, 64, baseAddress)
|
2016-02-17 23:06:34 +01:00
|
|
|
AllSCRFiles += map
|
|
|
|
|
2015-09-01 23:47:18 +02:00
|
|
|
val io = new Bundle {
|
2016-01-12 01:18:44 +01:00
|
|
|
val smi = new SmiIO(scrDataBits, scrAddrBits).flip
|
2016-02-17 23:06:34 +01:00
|
|
|
val scr = new SCRIO(map)
|
2015-09-01 23:47:18 +02:00
|
|
|
}
|
|
|
|
|
2016-01-14 22:47:47 +01:00
|
|
|
val scr_rdata = Wire(Vec(io.scr.rdata.size, Bits(width=scrDataBits)))
|
2015-09-01 23:47:18 +02:00
|
|
|
for (i <- 0 until scr_rdata.size)
|
|
|
|
scr_rdata(i) := io.scr.rdata(i)
|
|
|
|
|
|
|
|
val read_addr = Reg(init = UInt(0, scrAddrBits))
|
|
|
|
val resp_valid = Reg(init = Bool(false))
|
|
|
|
|
|
|
|
io.smi.req.ready := !resp_valid
|
|
|
|
io.smi.resp.valid := resp_valid
|
|
|
|
io.smi.resp.bits := scr_rdata(read_addr)
|
|
|
|
|
|
|
|
io.scr.wen := io.smi.req.fire() && io.smi.req.bits.rw
|
|
|
|
io.scr.wdata := io.smi.req.bits.data
|
|
|
|
io.scr.waddr := io.smi.req.bits.addr
|
|
|
|
|
|
|
|
when (io.smi.req.fire()) {
|
|
|
|
read_addr := io.smi.req.bits.addr
|
|
|
|
resp_valid := Bool(true)
|
|
|
|
}
|
|
|
|
when (io.smi.resp.fire()) { resp_valid := Bool(false) }
|
|
|
|
}
|
2016-02-17 23:06:34 +01:00
|
|
|
|
|
|
|
/** Every elaborated SCR file ends up in this global arry so it can be printed
|
|
|
|
* out later. */
|
|
|
|
object AllSCRFiles {
|
|
|
|
private var maps = ArrayBuffer.empty[SCRFileMap]
|
|
|
|
|
|
|
|
def +=(map: SCRFileMap): Unit = { maps += map }
|
|
|
|
def foreach( f: (SCRFileMap => Unit) ): Unit = { maps.foreach{ m => f(m) } }
|
|
|
|
}
|