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

3 4
import chipsalliance.rocketchip.config.Parameters
import device.{AXI4Timer, TLTimer}
Z
Zihao Yu 已提交
5
import chisel3._
Z
zhanglinjuan 已提交
6
import chisel3.util._
7
import freechips.rocketchip.diplomacy.{AddressSet, LazyModule, LazyModuleImp}
8 9
import freechips.rocketchip.tilelink.{TLBuffer, TLFuzzer, TLIdentityNode, TLXbar}
import utils.DebugIdentityNode
10
import xiangshan.{HasXSParameter, XSCore}
L
LinJiawei 已提交
11 12 13 14 15 16 17 18


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

20
trait HasSoCParameter extends HasXSParameter{
21
  val soc = top.Parameters.get.socParameters
L
LinJiawei 已提交
22 23 24
  val EnableILA = soc.EnableILA
  val HasL2cache = soc.HasL2Cache
  val HasPrefetch = soc.HasPrefetch
25 26
}

L
LinJiawei 已提交
27
class ILABundle extends Bundle {}
28

Z
Zihao Yu 已提交
29

30 31 32
class DummyCore()(implicit p: Parameters) extends LazyModule {
  val mem = TLFuzzer(nOperations = 10)
  val mmio = TLFuzzer(nOperations = 10)
Z
zhanglinjuan 已提交
33

34
  lazy val module = new LazyModuleImp(this){
35

36 37 38 39 40 41
  }
}


class XSSoc()(implicit p: Parameters) extends LazyModule with HasSoCParameter {

L
linjiawei 已提交
42
  private val xsCore = LazyModule(new XSCore())
Z
zhanglinjuan 已提交
43

44 45
  // only mem and extDev visible externally
  val mem = xsCore.mem
46
  val dma = xsCore.dma
47
  val extDev = TLIdentityNode()
Z
nothing  
zhanglinjuan 已提交
48

49 50 51 52 53
  private val mmioXbar = TLXbar()
  private val clint = LazyModule(new TLTimer(
    Seq(AddressSet(0x38000000L, 0x0000ffffL)),
    sim = !env.FPGAPlatform
  ))
54

55 56 57 58 59 60 61 62 63 64
  mmioXbar :=
    TLBuffer() :=
    DebugIdentityNode() :=
    xsCore.mmio

  clint.node :=
    mmioXbar

  extDev :=
    mmioXbar
65 66 67 68 69 70

  lazy val module = new LazyModuleImp(this){
    val io = IO(new Bundle{
      val meip = Input(Bool())
      val ila = if(env.FPGAPlatform && EnableILA) Some(Output(new ILABundle)) else None
    })
Y
Yinan Xu 已提交
71 72 73
    xsCore.module.io.externalInterrupt.mtip := clint.module.io.mtip
    xsCore.module.io.externalInterrupt.msip := clint.module.io.msip
    xsCore.module.io.externalInterrupt.meip := RegNext(RegNext(io.meip))
74
  }
Z
Zihao Yu 已提交
75

Y
Yinan Xu 已提交
76
}
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111


//class XSSoc extends Module with HasSoCParameter {
//  val io = IO(new Bundle{
//    val mem = new TLCached(l1BusParams)
//    val mmio = new TLCached(l1BusParams)
//    val frontend = Flipped(new AXI4) //TODO: do we need it ?
//    val meip = Input(Bool())
//    val ila = if (env.FPGAPlatform && EnableILA) Some(Output(new ILABundle)) else None
//  })
//
//  val xsCore = Module(new XSCore)
//
//  io.frontend <> DontCare
//
//  io.mem <> xsCore.io.mem
//
//  val addrSpace = List(
//    (0x40000000L, 0x40000000L), // external devices
//    (0x38000000L, 0x00010000L)  // CLINT
//  )
//  val mmioXbar = Module(new NaiveTL1toN(addrSpace, xsCore.io.mem.params))
//  mmioXbar.io.in <> xsCore.io.mmio
//
//  val extDev = mmioXbar.io.out(0)
//  val clint = Module(new AXI4Timer(sim = !env.FPGAPlatform))
//  clint.io.in <> AXI4ToAXI4Lite(MMIOTLToAXI4(mmioXbar.io.out(1)))
//
//  io.mmio <> extDev
//
//  val mtipSync = clint.io.extra.get.mtip
//  val meipSync = RegNext(RegNext(io.meip))
//  ExcitingUtils.addSource(mtipSync, "mtip")
//  ExcitingUtils.addSource(meipSync, "meip")
//}