SoC.scala 2.6 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
import xiangshan.{XSConfig, XSCore}
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
}

L
LinJiawei 已提交
18
class ILABundle extends Bundle {}
19

L
LinJiawei 已提交
20
class XSSoc(implicit val p: XSConfig) extends Module with HasSoCParameter {
Z
Zihao Yu 已提交
21
  val io = IO(new Bundle{
22
    val mem = new AXI4
L
LinJiawei 已提交
23
    val mmio = if (p.FPGAPlatform) { new AXI4Lite } else { new SimpleBusUC }
24
    val frontend = Flipped(new AXI4)
Z
Zihao Yu 已提交
25
    val meip = Input(Bool())
26
    val ila = if (p.FPGAPlatform && EnableILA) Some(Output(new ILABundle)) else None
Z
Zihao Yu 已提交
27 28
  })

L
LinJiawei 已提交
29
  val xsCore = Module(new XSCore)
Z
Zihao Yu 已提交
30
  val cohMg = Module(new CoherenceManager)
31
  val xbar = Module(new SimpleBusCrossbarNto1(2))
L
LinJiawei 已提交
32 33
  cohMg.io.in <> xsCore.io.imem.mem
  xsCore.io.dmem.coh <> cohMg.io.out.coh
34
  xbar.io.in(0) <> cohMg.io.out.mem
L
LinJiawei 已提交
35
  xbar.io.in(1) <> xsCore.io.dmem.mem
Z
zhanglinjuan 已提交
36

37 38
  val axi2sb = Module(new AXI42SimpleBusConverter())
  axi2sb.io.in <> io.frontend
L
LinJiawei 已提交
39
  xsCore.io.frontend <> axi2sb.io.out
40

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

Z
Zihao Yu 已提交
65 66 67 68 69
  val addrSpace = List(
    (0x40000000L, 0x08000000L), // external devices
    (0x48000000L, 0x00010000L)  // CLINT
  )
  val mmioXbar = Module(new SimpleBusCrossbar1toN(addrSpace))
L
LinJiawei 已提交
70
  mmioXbar.io.in <> xsCore.io.mmio
Z
nothing  
zhanglinjuan 已提交
71

Z
Zihao Yu 已提交
72 73 74 75 76 77 78
  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 已提交
79
  val meipSync = RegNext(RegNext(io.meip))
Z
Zihao Yu 已提交
80
  BoringUtils.addSource(mtipSync, "mtip")
Z
Zihao Yu 已提交
81
  BoringUtils.addSource(meipSync, "meip")
L
LinJiawei 已提交
82
}