SoC.scala 3.2 KB
Newer Older
Z
Zihao Yu 已提交
1 2
package system

Z
Zihao Yu 已提交
3
import noop._
Z
Zihao Yu 已提交
4
import bus.axi4.{AXI4, AXI4Lite}
5
import bus.simplebus._
Z
Zihao Yu 已提交
6 7

import chisel3._
Z
zhanglinjuan 已提交
8
import chisel3.util._
9
import chisel3.util.experimental.BoringUtils
Z
Zihao Yu 已提交
10

11 12
trait HasSoCParameter {
  val EnableILA = false
Z
Zihao Yu 已提交
13
  val HasL2cache = true
14
  val HasPrefetch = false
15 16 17 18 19 20 21 22 23 24 25
}

class ILABundle extends Bundle {
  val WBUpc = UInt(32.W)
  val WBUvalid = UInt(1.W)
  val WBUrfWen = UInt(1.W)
  val WBUrfDest = UInt(5.W)
  val WBUrfData = UInt(64.W)
  val InstrCnt = UInt(64.W)
}

26
class NOOPSoC(implicit val p: NOOPConfig) extends Module with HasSoCParameter {
Z
Zihao Yu 已提交
27
  val io = IO(new Bundle{
28
    val mem = new AXI4
29
    val mmio = (if (p.FPGAPlatform) { new AXI4Lite } else { new SimpleBusUC })
30
    val mtip = Input(Bool())
Z
Zihao Yu 已提交
31
    val meip = Input(Bool())
32
    val ila = if (p.FPGAPlatform && EnableILA) Some(Output(new ILABundle)) else None
Z
Zihao Yu 已提交
33 34 35
  })

  val noop = Module(new NOOP)
Z
zhanglinjuan 已提交
36

37
	val cohMg = Module(new CoherenceManager)
38 39 40 41 42
  val xbar = Module(new SimpleBusCrossbarNto1(2))
  cohMg.io.in <> noop.io.imem.mem
  noop.io.dmem.coh <> cohMg.io.out.coh
  xbar.io.in(0) <> cohMg.io.out.mem
  xbar.io.in(1) <> noop.io.dmem.mem
Z
zhanglinjuan 已提交
43

Z
Zihao Yu 已提交
44
  if (HasL2cache) {
45 46
    val l2cacheOut = Wire(new SimpleBusC)
    if (HasPrefetch) {
Z
Zihao Yu 已提交
47 48 49 50 51 52 53 54 55 56 57 58 59 60
      val prefetcher = Module(new Prefetcher)
      prefetcher.io.in <> noop.io.prefetchReq
      val l2cacheIn = Wire(new SimpleBusUC)
      val l2cacheInReqArb = Module(new Arbiter(chiselTypeOf(noop.io.prefetchReq.bits), 2))
      l2cacheInReqArb.io.in(0) <> xbar.io.out.req
      l2cacheInReqArb.io.in(1) <> prefetcher.io.out
      l2cacheIn.req <> l2cacheInReqArb.io.out
      xbar.io.out.resp <> l2cacheIn.resp
      l2cacheOut <> Cache(in = l2cacheIn, mmio = 0.U.asTypeOf(new SimpleBusUC), flush = "b00".U, enable = true)(
        CacheConfig(name = "l2cache", totalSize = 128, cacheLevel = 2))
    } else {
      l2cacheOut <> Cache(in = xbar.io.out, mmio = 0.U.asTypeOf(new SimpleBusUC), flush = "b00".U, enable = true)(
        CacheConfig(name = "l2cache", totalSize = 128, cacheLevel = 2))
    }
61
    io.mem <> l2cacheOut.mem.toAXI4()
Z
Zihao Yu 已提交
62 63 64
    l2cacheOut.coh.resp.ready := true.B
    l2cacheOut.coh.req.valid := false.B
    l2cacheOut.coh.req.bits := DontCare
Z
Zihao Yu 已提交
65 66 67
  } else {
    io.mem <> xbar.io.out.toAXI4()
  }
Z
zhanglinjuan 已提交
68

Z
Zihao Yu 已提交
69 70 71
  if (!HasPrefetch) {
    noop.io.prefetchReq.ready := true.B
  }
Z
Zihao Yu 已提交
72

73 74 75
  noop.io.imem.coh.resp.ready := true.B
  noop.io.imem.coh.req.valid := false.B
  noop.io.imem.coh.req.bits := DontCare
Z
zhanglinjuan 已提交
76

77
  if (p.FPGAPlatform) io.mmio <> noop.io.mmio.toAXI4Lite()
Z
Zihao Yu 已提交
78
  else io.mmio <> noop.io.mmio
Z
nothing  
zhanglinjuan 已提交
79

Z
Zihao Yu 已提交
80
  val mtipSync = RegNext(RegNext(io.mtip))
Z
Zihao Yu 已提交
81
  val meipSync = RegNext(RegNext(io.meip))
Z
Zihao Yu 已提交
82
  BoringUtils.addSource(mtipSync, "mtip")
Z
Zihao Yu 已提交
83
  BoringUtils.addSource(meipSync, "meip")
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101

  // ILA
  if (p.FPGAPlatform) {
    def BoringUtilsConnect(sink: UInt, id: String) {
      val temp = WireInit(0.U(64.W))
      BoringUtils.addSink(temp, id)
      sink := temp
    }

    val dummy = WireInit(0.U.asTypeOf(new ILABundle))
    val ila = io.ila.getOrElse(dummy)
    BoringUtilsConnect(ila.WBUpc      ,"ilaWBUpc")
    BoringUtilsConnect(ila.WBUvalid   ,"ilaWBUvalid")
    BoringUtilsConnect(ila.WBUrfWen   ,"ilaWBUrfWen")
    BoringUtilsConnect(ila.WBUrfDest  ,"ilaWBUrfDest")
    BoringUtilsConnect(ila.WBUrfData  ,"ilaWBUrfData")
    BoringUtilsConnect(ila.InstrCnt   ,"ilaInstrCnt")
  }
Z
Zihao Yu 已提交
102
}