Skip to content

Commit

Permalink
feat(DCache RAS): add DCache RAS inject support
Browse files Browse the repository at this point in the history
  • Loading branch information
cz4e committed Nov 25, 2024
1 parent f0370fb commit fee2558
Show file tree
Hide file tree
Showing 11 changed files with 396 additions and 52 deletions.
10 changes: 8 additions & 2 deletions src/main/scala/top/Configs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import utility._
import system._
import org.chipsalliance.cde.config._
import freechips.rocketchip.tile.{BusErrorUnit, BusErrorUnitParams, XLen}
import freechips.rocketchip.diplomacy._
import xiangshan.frontend.icache.ICacheParameters
import freechips.rocketchip.devices.debug._
import freechips.rocketchip.tile.{MaxHartIdBits, XLen}
Expand All @@ -35,7 +36,7 @@ import openLLC.{OpenLLCParam}
import xiangshan._
import xiangshan.backend.dispatch.DispatchParameters
import xiangshan.backend.regfile.{IntPregParams, VfPregParams}
import xiangshan.cache.DCacheParameters
import xiangshan.cache.{DCacheParameters, L1CacheCtrlParams}
import xiangshan.cache.mmu.{L2TLBParameters, TLBParameters}
import device.{EnableJtag, XSDebugModuleParams}
import huancun._
Expand Down Expand Up @@ -128,6 +129,7 @@ class MinimalConfig(n: Int = 1) extends Config(
nProbeEntries = 4,
nReleaseEntries = 8,
nMaxPrefetchEntry = 2,
cacheCtrlAddressOpt = Some(AddressSet(0x38022000, 0x7f))
)),
// ============ BPU ===============
EnableLoop = false,
Expand Down Expand Up @@ -254,7 +256,8 @@ class MinimalSimConfig(n: Int = 1) extends Config(
class WithNKBL1D(n: Int, ways: Int = 8) extends Config((site, here, up) => {
case XSTileKey =>
val sets = n * 1024 / ways / 64
up(XSTileKey).map(_.copy(
up(XSTileKey).map(
p => p.copy(
dcacheParametersOpt = Some(DCacheParameters(
nSets = sets,
nWays = ways,
Expand All @@ -265,6 +268,9 @@ class WithNKBL1D(n: Int, ways: Int = 8) extends Config((site, here, up) => {
nProbeEntries = 8,
nReleaseEntries = 18,
nMaxPrefetchEntry = 6,
enableTagEcc = true,
enableDataEcc = true,
cacheCtrlAddressOpt = Some(AddressSet(0x38022000, 0x7f))
))
))
})
Expand Down
14 changes: 12 additions & 2 deletions src/main/scala/xiangshan/L2Top.scala
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,21 @@ class L2TopInlined()(implicit p: Parameters) extends LazyModule
case None =>
memory_port.get := l1_xbar
}

mmio_xbar := TLBuffer.chainNode(2) := i_mmio_port
mmio_xbar := TLBuffer.chainNode(2) := d_mmio_port
beu.node := TLBuffer.chainNode(1) := mmio_xbar
mmio_port := TLBuffer() := mmio_xbar

if (dcacheParameters.cacheCtrlAddressOpt.nonEmpty) {
mmio_port :=
TLFilter(TLFilter.mSubtract(dcacheParameters.cacheCtrlAddressOpt.get)) :=
TLBuffer() :=
mmio_xbar
} else {
mmio_port :=
TLBuffer() :=
mmio_xbar
}

class Imp(wrapper: LazyModule) extends LazyModuleImp(wrapper) {
val io = IO(new Bundle {
Expand Down
3 changes: 3 additions & 0 deletions src/main/scala/xiangshan/Parameters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,9 @@ case class XSCoreParameters
nProbeEntries = 8,
nReleaseEntries = 18,
nMaxPrefetchEntry = 6,
enableTagEcc = true,
enableDataEcc = true,
cacheCtrlAddressOpt = Some(AddressSet(0x38022000, 0x7f))
)),
L2CacheParamsOpt: Option[L2Param] = Some(L2Param(
name = "l2",
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/xiangshan/XSTile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class XSTile()(implicit p: Parameters) extends LazyModule

// mmio
l2top.inner.i_mmio_port := l2top.inner.i_mmio_buffer.node := memBlock.frontendBridge.instr_uncache_node
l2top.inner.d_mmio_port := memBlock.uncache.clientNode
l2top.inner.d_mmio_port := memBlock.uncache_port

// =========== IO Connection ============
class XSTileImp(wrapper: LazyModule) extends LazyModuleImp(wrapper) {
Expand Down
8 changes: 8 additions & 0 deletions src/main/scala/xiangshan/backend/MemBlock.scala
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ class MemBlockInlined()(implicit p: Parameters) extends LazyModule

val dcache = LazyModule(new DCacheWrapper())
val uncache = LazyModule(new Uncache())
val uncache_port = TLTempNode()
val uncache_xbar = TLXbar()
val ptw = LazyModule(new L2TLBWrapper())
val ptw_to_l2_buffer = if (!coreParams.softPTW) LazyModule(new TLBuffer) else null
val l1d_to_l2_buffer = if (coreParams.dcacheParametersOpt.nonEmpty) LazyModule(new TLBuffer) else null
Expand All @@ -261,6 +263,12 @@ class MemBlockInlined()(implicit p: Parameters) extends LazyModule
ptw_to_l2_buffer.node := ptw.node
}

uncache_xbar := TLBuffer() := uncache.clientNode
if (dcache.uncacheNode.isDefined) {
dcache.uncacheNode.get := TLBuffer.chainNode(2) := uncache_xbar
}
uncache_port := TLBuffer.chainNode(2) := uncache_xbar

lazy val module = new MemBlockInlinedImp(this)
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/scala/xiangshan/backend/fu/PMA.scala
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ trait PMAMethod extends PMAConst {
MemMap("h00_3801_0000", "h00_3801_FFFF", "h0", "BEU", "RW"),
MemMap("h00_3802_0000", "h00_3802_0FFF", "h0", "DebugModule", "RWX"),
MemMap("h00_3802_1000", "h00_3802_1FFF", "h0", "MMPMA", "RW"),
MemMap("h00_3802_2000", "h00_3900_0000", "h0", "Reserved", ""),
MemMap("h00_3802_2000", "h00_3802_207F", "h0", "L1DCacheCtrl", "RW"),
MemMap("h00_3802_2080", "h00_38FF_FFFF", "h0", "Reserved", ""),
MemMap("h00_3900_0000", "h00_3900_1FFF", "h0", "L3CacheCtrl", "RW"),
MemMap("h00_3900_2000", "h00_39FF_FFFF", "h0", "Reserved", ""),
MemMap("h00_3A00_0000", "h00_3FFF_FFFF", "h0", "", "RW),
Expand Down Expand Up @@ -161,7 +162,7 @@ trait PMAMethod extends PMAConst {
addPMA(PMPPmemLowBounds(0), a = 1, w = true, r = true)
addPMA(0x3A000000L, a = 1)
addPMA(0x39002000L, a = 1, w = true, r = true)
addPMA(0x39000000L, a = 1)
addPMA(0x39000000L, a = 1, w = true, r = true)
addPMA(0x38022000L, a = 1, w = true, r = true)
addPMA(0x38021000L, a = 1, x = true, w = true, r = true)
addPMA(0x38020000L, a = 1, w = true, r = true)
Expand Down
160 changes: 160 additions & 0 deletions src/main/scala/xiangshan/cache/dcache/CtrlUnit.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/***************************************************************************************
* Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences
* Copyright (c) 2020-2021 Peng Cheng Laboratory
*
* XiangShan is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
*
* See the Mulan PSL v2 for more details.
***************************************************************************************/

package xiangshan.cache

import org.chipsalliance.cde.config.Parameters
import chisel3._
import chisel3.util._
import freechips.rocketchip.subsystem._
import freechips.rocketchip.diplomacy._
import freechips.rocketchip.regmapper._
import freechips.rocketchip.tilelink._
import freechips.rocketchip.interrupts._
import freechips.rocketchip.util._
import freechips.rocketchip.util.property
import chisel3.experimental.SourceInfo
import xiangshan._

case class L1CacheCtrlParams (
address: AddressSet,
beatBytes: Int = 8,
) {
def maxBanks = 1
def bankBytes = 128

def regWidth = 64
def regBytes = regWidth / 8

def ctrlOffset = 0x0
def delayOffset = ctrlOffset + regBytes
def maskOffset = delayOffset + regBytes

def nSignalComps = 2
}

class CtrlUnitCtrlBundle(implicit p: Parameters) extends XSBundle with HasDCacheParameters {
val zero0 = UInt((60-DCacheBanks).W) // padding bits
val comp = UInt(2.W) // components: 2'b01 tag, 2'b10 data
val ede = Bool() // error delay enable
val ese = Bool() // error signaling enable
}

class CtrlUnit(params: L1CacheCtrlParams)(implicit p: Parameters) extends LazyModule
with HasDCacheParameters
{
val device: SimpleDevice = new SimpleDevice("L1DCacheCtrl", Seq("xiangshan,l1dcache_ctrl"))

val node: TLRegisterNode = TLRegisterNode(
address = Seq(params.address),
device = device,
beatBytes = params.beatBytes,
concurrency = 1,
)

lazy val module = new CtrlUnitImp

class CtrlUnitImp extends LazyModuleImp(this) {
val io_pseudoError = IO(Vec(params.nSignalComps, DecoupledIO(Vec(DCacheBanks, UInt(DCacheSRAMRowBits.W)))))

require(params.maxBanks > 0, "At least one bank!")
require(params.maxBanks == 1, "Is it necessary to have more than 1 bank?")
require(params.regWidth == DCacheSRAMRowBits, "regWidth must be equal to DCacheSRAMRowBits!")
val ctrlRegs = RegInit(VecInit(Seq.fill(1)(0.U(params.regWidth.W))))
val delayRegs = RegInit(VecInit(Seq.fill(1)(0.U(params.regWidth.W))))
val maskRegs = RegInit(VecInit(Seq.fill(DCacheBanks)(0.U(DCacheSRAMRowBits.W))))

io_pseudoError.zipWithIndex.foreach {
case (pErr, i) =>
val ctrlReg = ctrlRegs(0)
val ctrlRegBundle = ctrlRegs(0).asTypeOf(new CtrlUnitCtrlBundle)
val delayReg = delayRegs(0)

require(io_pseudoError.length == ctrlRegBundle.comp.getWidth, "io_pseudoError must equal number of components!")
pErr.valid := ctrlRegBundle.ese && ctrlRegBundle.comp(i) && (!ctrlRegBundle.ede || delayReg === 0.U)
pErr.bits := maskRegs

when (pErr.fire) {
val newCtrlReg = WireInit(0.U.asTypeOf(ctrlRegBundle))
newCtrlReg := ctrlRegBundle
newCtrlReg.ese := false.B

ctrlReg := newCtrlReg.asUInt
}
}

ctrlRegs.map(_.asTypeOf(new CtrlUnitCtrlBundle)).zip(delayRegs).foreach {
case (ctl, delay) =>
when (ctl.ese && ctl.ede && delay =/= 0.U) {
delay := delay - 1.U
}
}

def ctrlRegDesc(i: Int) =
RegFieldDesc(
name = s"control_$i",
desc = s"Acting control of controller $i",
group = Some(s"controll_${i}"),
groupDesc = Some(s"Acting control of controller ${i}"),
reset = Some(0)
)

def delayRegDesc(i: Int) =
RegFieldDesc(
name = s"delay_$i",
desc = s"pseudo error delay $i",
group = Some(s"delay_${i}"),
groupDesc = Some(s"pseudo error delay ${i}"),
reset = Some(0)
)

def maskRegDesc(i: Int) =
RegFieldDesc(
name = s"mask_$i",
desc = s"pseudo error toggle mask$i",
group = Some(s"mask_${i}"),
groupDesc = Some(s"pseudo error toggle mask ${i}"),
reset = Some(0)
)

def ctrlRegField(x: UInt, i: Int) = {
RegField(params.regWidth, x, ctrlRegDesc(i))
}

def delayRegField(x: UInt, i: Int) = {
RegField(params.regWidth, x, delayRegDesc(i))
}

def maskRegField(x: UInt, i: Int) = {
RegField(params.regWidth, x, maskRegDesc(i))
}

val ctrlRegFields = ctrlRegs.zipWithIndex.map {
case (reg, i) =>
params.ctrlOffset -> Seq(ctrlRegField(reg, i))
}
val delayRegFields = delayRegs.zipWithIndex.map {
case (reg, i) =>
params.delayOffset -> Seq(delayRegField(reg, i))
}
val maskRegFields = maskRegs.zipWithIndex.map {
case (reg, i) =>
(params.maskOffset + 8 * i) -> Seq(maskRegField(reg, i))
}

node.regmap((ctrlRegFields ++ delayRegFields ++ maskRegFields):_*)
}
}
Loading

0 comments on commit fee2558

Please sign in to comment.