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

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


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

22
trait HasSoCParameter extends HasXSParameter{
L
LinJiawei 已提交
23 24 25 26
  val soc = Parameters.get.socParameters
  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 34 35
    val mem = new TLCached(l1BusParams)
    val mmio = new TLCached(l1BusParams)
    val frontend = Flipped(new AXI4) //TODO: do we need it ?
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
zhanglinjuan 已提交
41

42
  io.frontend <> DontCare
43

44
  io.mem <> xsCore.io.mem
Z
zhanglinjuan 已提交
45

Z
Zihao Yu 已提交
46
  val addrSpace = List(
47
    (0x40000000L, 0x40000000L), // external devices
L
LinJiawei 已提交
48
    (0x38000000L, 0x00010000L)  // CLINT
Z
Zihao Yu 已提交
49
  )
50
  val mmioXbar = Module(new NaiveTL1toN(addrSpace, xsCore.io.mem.params))
L
LinJiawei 已提交
51
  mmioXbar.io.in <> xsCore.io.mmio
Z
nothing  
zhanglinjuan 已提交
52

Z
Zihao Yu 已提交
53
  val extDev = mmioXbar.io.out(0)
L
LinJiawei 已提交
54
  val clint = Module(new AXI4Timer(sim = !env.FPGAPlatform))
55
  clint.io.in <> AXI4ToAXI4Lite(MMIOTLToAXI4(mmioXbar.io.out(1)))
56 57

  io.mmio <> extDev
Z
Zihao Yu 已提交
58 59

  val mtipSync = clint.io.extra.get.mtip
Z
Zihao Yu 已提交
60
  val meipSync = RegNext(RegNext(io.meip))
61 62
  ExcitingUtils.addSource(mtipSync, "mtip")
  ExcitingUtils.addSource(meipSync, "meip")
Y
Yinan Xu 已提交
63
}