SoC.scala 3.3 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
import device.AXI4Timer
Z
Zihao Yu 已提交
7 8

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

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

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)
}

27
class NOOPSoC(implicit val p: NOOPConfig) extends Module with HasSoCParameter {
Z
Zihao Yu 已提交
28
  val io = IO(new Bundle{
29
    val mem = new AXI4
30
    val mmio = (if (p.FPGAPlatform) { new AXI4Lite } else { new SimpleBusUC })
31
    val frontend = Flipped(new AXI4)
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
      val prefetcher = Module(new Prefetcher)
      val l2cacheIn = Wire(new SimpleBusUC)
Z
zhanglinjuan 已提交
53 54
      prefetcher.io.in <> xbar.io.out.req
      l2cacheIn.req <> prefetcher.io.out
Z
Zihao Yu 已提交
55
      xbar.io.out.resp <> l2cacheIn.resp
Z
Zihao Yu 已提交
56 57
      l2cacheIn
    } else xbar.io.out
58
    val l2Empty = Wire(Bool())
Z
Zihao Yu 已提交
59
    l2cacheOut <> Cache(in = l2cacheIn, mmio = 0.U.asTypeOf(new SimpleBusUC) :: Nil, flush = "b00".U, empty = l2Empty, enable = true)(
Z
Zihao Yu 已提交
60
      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
  
69 70 71
  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 已提交
72

Z
Zihao Yu 已提交
73 74 75 76 77 78
  val addrSpace = List(
    (0x40000000L, 0x08000000L), // external devices
    (0x48000000L, 0x00010000L)  // CLINT
  )
  val mmioXbar = Module(new SimpleBusCrossbar1toN(addrSpace))
  mmioXbar.io.in <> noop.io.mmio
Z
nothing  
zhanglinjuan 已提交
79

Z
Zihao Yu 已提交
80 81 82 83 84 85 86
  val extDev = mmioXbar.io.out(0)
  val clint = Module(new AXI4Timer(sim = !p.FPGAPlatform))
  clint.io.in <> mmioXbar.io.out(1).toAXI4Lite()
  if (p.FPGAPlatform) io.mmio <> extDev.toAXI4Lite()
  else io.mmio <> extDev

  val mtipSync = clint.io.extra.get.mtip
Z
Zihao Yu 已提交
87
  val meipSync = RegNext(RegNext(io.meip))
Z
Zihao Yu 已提交
88
  BoringUtils.addSource(mtipSync, "mtip")
Z
Zihao Yu 已提交
89
  BoringUtils.addSource(meipSync, "meip")
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107

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