Skip to content

Commit

Permalink
devide MSWI.scala to MSWI part and SWI part
Browse files Browse the repository at this point in the history
  • Loading branch information
PorterLu committed Jun 16, 2023
1 parent 442ff0f commit 703a56b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/main/scala/devices/tilelink/CLINT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ trait CanHavePeripheryCLINT { this: BaseSubsystem =>
val mswiOpt = clintParams.mswi.map { params =>
val tlbus = locateTLBusWrapper(p(MSWIAttachKey).slaveWhere)
val beatBytes = tlbus.beatBytes
val mswi = LazyModule(new MSWI(params, MTIMERParams(MTIMEBaseAddress = params.BaseAddress + SWIConsts.size), clintParams.isACLINT, beatBytes))
val mswi = LazyModule(new MSWI(params, MTIMERParams(mtimeBaseAddress = params.baseAddress + SWIConsts.size), clintParams.isACLINT, beatBytes))
mswi.node := tlbus.coupleTo("mswi") { TLFragmenter(tlbus) := _ }

InModuleBody {
Expand Down
31 changes: 1 addition & 30 deletions src/main/scala/devices/tilelink/MSWI.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,9 @@ import freechips.rocketchip.subsystem._
import freechips.rocketchip.tilelink._
import freechips.rocketchip.util._

object SWIConsts
{
def sipOffset(hart: Int) = hart * sipBytes
def sipBytes = 4
def size = 0x4000
def ipiWidth = 32
def ints = 1
def clintSize = 0x10000
}

case class MSWIParams(baseAddress: BigInt = 0x02000000, intStages: Int = 0)
{
def address = AddressSet(BaseAddress, SWIConsts.size - 1)
def address = AddressSet(baseAddress, SWIConsts.size - 1)
}

case class MSWIAttachParams(
Expand Down Expand Up @@ -119,22 +109,3 @@ class MSWI(mswiParams: MSWIParams, mtimerParams: MTIMERParams, isACLINT: Boolean
node.regmap(mapping:_*)
}
}

object SWI {
def apply(mswiType: String, intnode: IntNexusNode, intStages: Int) = {
import SWIConsts._

val nTiles = intnode.out.size
val ipi = Seq.fill(nTiles) { RegInit(0.U(1.W)) }

val (intnode_out, _) = intnode.out.unzip
intnode_out.zipWithIndex.foreach { case (int, i) =>
int(0) := ShiftRegister(ipi(i)(0), intStages)
}

val swiRegGroup = RegFieldGroup(mswiType + "sip", Some(mswiType.toUpperCase + "SIP Bits"), ipi.zipWithIndex.flatMap { case (r, i) =>
RegField(1, r, RegFieldDesc(mswiType + s"sip_$i", mswiType.toUpperCase + s"SIP bit for Hart $i", reset=Some(0))) :: RegField(SWIConsts.ipiWidth - 1) :: Nil })

swiRegGroup
}
}
42 changes: 42 additions & 0 deletions src/main/scala/devices/tilelink/SWI.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// See LICENSE.SiFive for license details.

package freechips.rocketchip.devices.tilelink

import chisel3._
import chisel3.util.ShiftRegister
import org.chipsalliance.cde.config.{Field, Parameters}
import freechips.rocketchip.diplomacy._
import freechips.rocketchip.interrupts._
import freechips.rocketchip.regmapper._
import freechips.rocketchip.subsystem._
import freechips.rocketchip.tilelink._
import freechips.rocketchip.util._

object SWIConsts
{
def sipOffset(hart: Int) = hart * sipBytes
def sipBytes = 4
def size = 0x4000
def ipiWidth = 32
def ints = 1
def clintSize = 0x10000
}

object SWI {
def apply(swiType: String, intnode: IntNexusNode, intStages: Int) = {
import SWIConsts._

val nTiles = intnode.out.size
val ipi = Seq.fill(nTiles) { RegInit(0.U(1.W)) }

val (intnode_out, _) = intnode.out.unzip
intnode_out.zipWithIndex.foreach { case (int, i) =>
int(0) := ShiftRegister(ipi(i)(0), intStages)
}

val swiRegGroup = RegFieldGroup(swiType + "sip", Some(swiType.toUpperCase + "SIP Bits"), ipi.zipWithIndex.flatMap { case (r, i) =>
RegField(1, r, RegFieldDesc(swiType + s"sip_$i", swiType.toUpperCase + s"SIP bit for Hart $i", reset=Some(0))) :: RegField(SWIConsts.ipiWidth - 1) :: Nil })

swiRegGroup
}
}

0 comments on commit 703a56b

Please sign in to comment.