xref: /XiangShan/src/main/scala/xiangshan/backend/fu/NewCSR/CSRCustom.scala (revision 25dc4a827ee27e3ccbaf02e8e5134872cba28fcd)
1package xiangshan.backend.fu.NewCSR
2
3import chisel3._
4import chisel3.util._
5import freechips.rocketchip.util._
6import org.chipsalliance.cde.config.Parameters
7import xiangshan.backend.fu.NewCSR.CSRDefines.{CSRRWField => RW}
8import xiangshan.HasXSParameter
9
10import scala.collection.immutable.SeqMap
11
12trait CSRCustom { self: NewCSR =>
13  // Supervisor Custom Read/Write
14  val sbpctl = Module(new CSRModule("sbpctl", new SbpctlBundle))
15    .setAddr(0x5C0)
16
17  val spfctl = Module(new CSRModule("spfctl", new SpfctlBundle))
18    .setAddr(0x5C1)
19
20  // slvpredctl: load violation predict settings
21  // Default reset period: 2^16
22  // why this number: reset more frequently while keeping the overhead low
23  // Overhead: extra two redirections in every 64K cycles => ~0.1% overhead
24  val slvpredctl = Module(new CSRModule("slvpredctl", new SlvpredctlBundle))
25    .setAddr(0x5C2)
26
27  // smblockctl: memory block configurations
28  val smblockctl = Module(new CSRModule("smblockctl", new SmblockctlBundle))
29    .setAddr(0x5C3)
30
31  val srnctl = Module(new CSRModule("srnctl", new SrnctlBundle))
32    .setAddr(0x5C4)
33
34  // sdsid: Differentiated Services ID
35  val sdsid = Module(new CSRModule("sdsid"))
36    .setAddr(0x9C0)
37
38  val sfetchctl = Module(new CSRModule("sfetchctl", new SfetchctlBundle))
39    .setAddr(0x9E0)
40
41  val customCSRMods = Seq(
42    sbpctl,
43    spfctl,
44    slvpredctl,
45    smblockctl,
46    srnctl,
47    sdsid,
48    sfetchctl,
49  )
50  val customCSRMap = SeqMap.from(
51    customCSRMods.map(csr => (csr.addr -> (csr.w -> csr.rdata.asInstanceOf[CSRBundle].asUInt))).iterator
52  )
53
54  val customCSROutMap: SeqMap[Int, UInt] = SeqMap.from(
55    customCSRMods.map(csr => (csr.addr -> csr.regOut.asInstanceOf[CSRBundle].asUInt)).iterator
56  )
57}
58
59class SbpctlBundle extends CSRBundle {
60  val LOOP_ENABLE = RW(6).withReset(true.B)
61  val RAS_ENABLE  = RW(5).withReset(true.B)
62  val SC_ENABLE   = RW(4).withReset(true.B)
63  val TAGE_ENABLE = RW(3).withReset(true.B)
64  val BIM_ENABLE  = RW(2).withReset(true.B)
65  val BTB_ENABLE  = RW(1).withReset(true.B)
66  val UBTB_ENABLE = RW(0).withReset(true.B)
67}
68
69class SpfctlBundle extends CSRBundle {
70  // turn off L2 BOP, turn on L1 SMS by default
71  val L2_PF_STORE_ONLY        = RW(    17).withReset(false.B)     // L2 pf store only
72  val L1D_PF_ENABLE_STRIDE    = RW(    16).withReset(true.B)      // L1D prefetch enable stride
73  val L1D_PF_ACTIVE_STRIDE    = RW(15, 10, /*resetVal= */ 30.U)   // L1D prefetch active page stride
74  val L1D_PF_ACTIVE_THRESHOLD = RW( 9,  6, /*resetVal= */ 12.U)   // L1D prefetch active page threshold
75  val L1D_PF_ENABLE_PHT       = RW(     5).withReset(true.B)      // L1D prefetch enable pht
76  val L1D_PF_ENABLE_AGT       = RW(     4).withReset(true.B)      // L1D prefetch enable agt
77  val L1D_PF_TRAIN_ON_HIT     = RW(     3).withReset(false.B)     // L1D train prefetch on hit
78  val L1D_PF_ENABLE           = RW(     2).withReset(true.B)      // L1D Cache Prefetcher Enable
79  val L2_PF_ENABLE            = RW(     1).withReset(true.B)      // L2  Cache Prefetcher Enable
80  val L1I_PF_ENABLE           = RW(     0).withReset(true.B)      // L1I Cache Prefetcher Enable
81}
82
83class SlvpredctlBundle extends CSRBundle {
84  val LVPRED_TIMEOUT          = RW(8, 4, /*resetVal= */ 3.U)
85  val STORESET_NO_FAST_WAKEUP = RW(3).withReset(0.U)
86  val STORESET_WAIT_STORE     = RW(2).withReset(0.U)
87  val NO_SPEC_LOAD            = RW(1).withReset(0.U)
88  val LVPRED_DISABLE          = RW(0).withReset(0.U)
89}
90
91class SmblockctlBundle extends CSRBundle {
92  val UNCACHE_WRITE_OUTSTANDING_ENABLE = RW(   7).withReset(0.U) // Enable uncache write outstanding (0). Todo:
93  val CACHE_ERROR_ENABLE               = RW(   6)                // Enable cache error after reset (CE).
94  val SOFT_PREFETCH_ENABLE             = RW(   5)                // Enable soft-prefetch after reset (SP).
95  val LDLD_VIO_CHECK_ENABLE            = RW(   4)                // Enable load load violation check after reset (LVC).
96  val SBUFFER_THRESHOLD                = RW(3, 0)                // Store buffer flush threshold (Th).
97}
98
99class SrnctlBundle extends CSRBundle {
100  val WFI_ENABLE     = RW(2).withReset(true.B)
101  val SVINVAL_ENABLE = RW(1).withReset(true.B)
102  val FUSION_ENABLE  = RW(0).withReset(true.B)
103}
104
105class SfetchctlBundle extends CSRBundle {
106  val ICACHE_PARITY_ENABLE = RW(0).withReset(false.B) // L1I Cache Parity check enable
107}