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 frontend = Flipped(new AXI4)
31
    val mtip = Input(Bool())
Z
Zihao Yu 已提交
32
    val meip = Input(Bool())
33
    val ila = if (p.FPGAPlatform && EnableILA) Some(Output(new ILABundle)) else None
Z
Zihao Yu 已提交
34 35 36
  })

  val noop = Module(new NOOP)
Z
Zihao Yu 已提交
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

44 45 46 47
  val axi2sb = Module(new AXI42SimpleBusConverter())
  axi2sb.io.in <> io.frontend
  noop.io.frontend <> axi2sb.io.out

Z
Zihao Yu 已提交
48
  if (HasL2cache) {
49
    val l2cacheOut = Wire(new SimpleBusC)
Z
Zihao Yu 已提交
50
    val l2cacheIn = if (HasPrefetch) {
Z
Zihao Yu 已提交
51 52 53 54 55 56 57 58
      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
Z
Zihao Yu 已提交
59 60
      l2cacheIn
    } else xbar.io.out
61
    l2cacheOut <> Cache(in = l2cacheIn, mmio = 0.U.asTypeOf(new SimpleBusUC) :: Nil, flush = "b00".U, enable = true)(
Z
Zihao Yu 已提交
62
      CacheConfig(name = "l2cache", totalSize = 128, cacheLevel = 2))
63
    io.mem <> l2cacheOut.mem.toAXI4()
Z
Zihao Yu 已提交
64 65 66
    l2cacheOut.coh.resp.ready := true.B
    l2cacheOut.coh.req.valid := false.B
    l2cacheOut.coh.req.bits := DontCare
Z
Zihao Yu 已提交
67 68 69
  } else {
    io.mem <> xbar.io.out.toAXI4()
  }
Z
zhanglinjuan 已提交
70

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

75 76 77
  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 已提交
78

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

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

  // 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 已提交
104
}