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

L
LinJiawei 已提交
3
import noop.{Cache, CacheConfig}
Z
Zihao Yu 已提交
4
import bus.axi4.{AXI4, AXI4Lite}
5
import bus.simplebus._
Z
Zihao Yu 已提交
6
import device.AXI4Timer
Z
Zihao Yu 已提交
7
import chisel3._
Z
zhanglinjuan 已提交
8
import chisel3.util._
9
import chisel3.util.experimental.BoringUtils
L
LinJiawei 已提交
10 11 12 13 14 15 16 17 18 19
import top.Parameters
import xiangshan.XSCore


case class SoCParameters
(
  EnableILA: Boolean = false,
  HasL2Cache: Boolean = false,
  HasPrefetch: Boolean = false
)
Z
Zihao Yu 已提交
20

21
trait HasSoCParameter {
L
LinJiawei 已提交
22 23 24 25 26
  val soc = Parameters.get.socParameters
  val env = Parameters.get.envParameters
  val EnableILA = soc.EnableILA
  val HasL2cache = soc.HasL2Cache
  val HasPrefetch = soc.HasPrefetch
27 28
}

L
LinJiawei 已提交
29
class ILABundle extends Bundle {}
30

L
LinJiawei 已提交
31
class XSSoc extends Module with HasSoCParameter {
Z
Zihao Yu 已提交
32
  val io = IO(new Bundle{
33
    val mem = new AXI4
L
LinJiawei 已提交
34
    val mmio = if (env.FPGAPlatform) { new AXI4Lite } else { new SimpleBusUC }
35
    val frontend = Flipped(new AXI4)
Z
Zihao Yu 已提交
36
    val meip = Input(Bool())
L
LinJiawei 已提交
37
    val ila = if (env.FPGAPlatform && EnableILA) Some(Output(new ILABundle)) else None
Z
Zihao Yu 已提交
38 39
  })

L
LinJiawei 已提交
40
  val xsCore = Module(new XSCore)
Z
Zihao Yu 已提交
41
  val cohMg = Module(new CoherenceManager)
42
  val xbar = Module(new SimpleBusCrossbarNto1(2))
L
LinJiawei 已提交
43 44
  cohMg.io.in <> xsCore.io.imem.mem
  xsCore.io.dmem.coh <> cohMg.io.out.coh
45
  xbar.io.in(0) <> cohMg.io.out.mem
L
LinJiawei 已提交
46
  xbar.io.in(1) <> xsCore.io.dmem.mem
Z
zhanglinjuan 已提交
47

48 49
  val axi2sb = Module(new AXI42SimpleBusConverter())
  axi2sb.io.in <> io.frontend
L
LinJiawei 已提交
50
  xsCore.io.frontend <> axi2sb.io.out
51

Z
Zihao Yu 已提交
52
  if (HasL2cache) {
53
    val l2cacheOut = Wire(new SimpleBusC)
Z
Zihao Yu 已提交
54
    val l2cacheIn = if (HasPrefetch) {
Z
Zihao Yu 已提交
55 56
      val prefetcher = Module(new Prefetcher)
      val l2cacheIn = Wire(new SimpleBusUC)
Z
zhanglinjuan 已提交
57 58
      prefetcher.io.in <> xbar.io.out.req
      l2cacheIn.req <> prefetcher.io.out
Z
Zihao Yu 已提交
59
      xbar.io.out.resp <> l2cacheIn.resp
Z
Zihao Yu 已提交
60 61
      l2cacheIn
    } else xbar.io.out
62
    val l2Empty = Wire(Bool())
Z
Zihao Yu 已提交
63
    l2cacheOut <> Cache(in = l2cacheIn, mmio = 0.U.asTypeOf(new SimpleBusUC) :: Nil, flush = "b00".U, empty = l2Empty, enable = true)(
Z
Zihao Yu 已提交
64
      CacheConfig(name = "l2cache", totalSize = 128, cacheLevel = 2))
65
    io.mem <> l2cacheOut.mem.toAXI4()
Z
Zihao Yu 已提交
66 67 68
    l2cacheOut.coh.resp.ready := true.B
    l2cacheOut.coh.req.valid := false.B
    l2cacheOut.coh.req.bits := DontCare
Z
Zihao Yu 已提交
69 70 71
  } else {
    io.mem <> xbar.io.out.toAXI4()
  }
L
LinJiawei 已提交
72 73 74
  xsCore.io.imem.coh.resp.ready := true.B
  xsCore.io.imem.coh.req.valid := false.B
  xsCore.io.imem.coh.req.bits := DontCare
Z
zhanglinjuan 已提交
75

Z
Zihao Yu 已提交
76
  val addrSpace = List(
77
    (0x40000000L, 0x40000000L), // external devices
L
LinJiawei 已提交
78
    (0x38000000L, 0x00010000L)  // CLINT
Z
Zihao Yu 已提交
79 80
  )
  val mmioXbar = Module(new SimpleBusCrossbar1toN(addrSpace))
L
LinJiawei 已提交
81
  mmioXbar.io.in <> xsCore.io.mmio
Z
nothing  
zhanglinjuan 已提交
82

Z
Zihao Yu 已提交
83
  val extDev = mmioXbar.io.out(0)
L
LinJiawei 已提交
84
  val clint = Module(new AXI4Timer(sim = !env.FPGAPlatform))
Z
Zihao Yu 已提交
85
  clint.io.in <> mmioXbar.io.out(1).toAXI4Lite()
L
LinJiawei 已提交
86
  if (env.FPGAPlatform) io.mmio <> extDev.toAXI4Lite()
Z
Zihao Yu 已提交
87 88 89
  else io.mmio <> extDev

  val mtipSync = clint.io.extra.get.mtip
Z
Zihao Yu 已提交
90
  val meipSync = RegNext(RegNext(io.meip))
Z
Zihao Yu 已提交
91
  BoringUtils.addSource(mtipSync, "mtip")
Z
Zihao Yu 已提交
92
  BoringUtils.addSource(meipSync, "meip")
Y
Yinan Xu 已提交
93
}