194c2cc17SsinceforYypackage xiangshan.backend.fu.NewCSR 294c2cc17SsinceforYy 394c2cc17SsinceforYyimport chisel3._ 494c2cc17SsinceforYyimport chisel3.util._ 594c2cc17SsinceforYyimport freechips.rocketchip.util._ 694c2cc17SsinceforYyimport org.chipsalliance.cde.config.Parameters 7b7a63495SNewPaulWalkerimport xiangshan.backend.fu.NewCSR.CSRDefines.{ 8b7a63495SNewPaulWalker CSRRWField => RW, 9b7a63495SNewPaulWalker CSRROField => RO, 10b7a63495SNewPaulWalker} 1194c2cc17SsinceforYyimport xiangshan.HasXSParameter 1294c2cc17SsinceforYy 1394c2cc17SsinceforYyimport scala.collection.immutable.SeqMap 1494c2cc17SsinceforYy 1594c2cc17SsinceforYytrait CSRCustom { self: NewCSR => 1694c2cc17SsinceforYy // Supervisor Custom Read/Write 171a610887SsinceforYy val sbpctl = Module(new CSRModule("Sbpctl", new SbpctlBundle)) 1894c2cc17SsinceforYy .setAddr(0x5C0) 1994c2cc17SsinceforYy 201a610887SsinceforYy val spfctl = Module(new CSRModule("Spfctl", new SpfctlBundle)) 2194c2cc17SsinceforYy .setAddr(0x5C1) 2294c2cc17SsinceforYy 2394c2cc17SsinceforYy // slvpredctl: load violation predict settings 2494c2cc17SsinceforYy // Default reset period: 2^16 2594c2cc17SsinceforYy // why this number: reset more frequently while keeping the overhead low 2694c2cc17SsinceforYy // Overhead: extra two redirections in every 64K cycles => ~0.1% overhead 271a610887SsinceforYy val slvpredctl = Module(new CSRModule("Slvpredctl", new SlvpredctlBundle)) 2894c2cc17SsinceforYy .setAddr(0x5C2) 2994c2cc17SsinceforYy 3094c2cc17SsinceforYy // smblockctl: memory block configurations 311a610887SsinceforYy val smblockctl = Module(new CSRModule("Smblockctl", new SmblockctlBundle)) 3294c2cc17SsinceforYy .setAddr(0x5C3) 3394c2cc17SsinceforYy 341a610887SsinceforYy val srnctl = Module(new CSRModule("Srnctl", new SrnctlBundle)) 3594c2cc17SsinceforYy .setAddr(0x5C4) 3694c2cc17SsinceforYy 37b7a63495SNewPaulWalker // Machine Level Custom Read/Write 38b7a63495SNewPaulWalker 39b7a63495SNewPaulWalker // mcorepwr: Core Power Down Status Enable 40b7a63495SNewPaulWalker val mcorepwr = Module(new CSRModule("Mcorepwr", new McorepwrBundle)) 41b7a63495SNewPaulWalker .setAddr(0xBC0) 42b7a63495SNewPaulWalker 43b7a63495SNewPaulWalker // mflushpwr: Flush L2 Cache Enable 44b7a63495SNewPaulWalker val mflushpwr = Module(new CSRModule("Mflushpwr", new MflushpwrBundle) 45b7a63495SNewPaulWalker with HasMachineFlushL2Bundle 46b7a63495SNewPaulWalker { 47b7a63495SNewPaulWalker regOut.L2_FLUSH_DONE := l2FlushDone 48b7a63495SNewPaulWalker }) 49b7a63495SNewPaulWalker .setAddr(0xBC1) 50b7a63495SNewPaulWalker 5194c2cc17SsinceforYy val customCSRMods = Seq( 5294c2cc17SsinceforYy sbpctl, 5394c2cc17SsinceforYy spfctl, 5494c2cc17SsinceforYy slvpredctl, 5594c2cc17SsinceforYy smblockctl, 5694c2cc17SsinceforYy srnctl, 57b7a63495SNewPaulWalker mcorepwr, 58b7a63495SNewPaulWalker mflushpwr, 5994c2cc17SsinceforYy ) 6001cdded8SXuan Hu 6194895e77SXuan Hu val customCSRMap: SeqMap[Int, (CSRAddrWriteBundle[_ <: CSRBundle], UInt)] = SeqMap.from( 628aa89407SXuan Hu customCSRMods.map(csr => (csr.addr -> (csr.w -> csr.rdata))).iterator 6394c2cc17SsinceforYy ) 6494c2cc17SsinceforYy 6594c2cc17SsinceforYy val customCSROutMap: SeqMap[Int, UInt] = SeqMap.from( 6694c2cc17SsinceforYy customCSRMods.map(csr => (csr.addr -> csr.regOut.asInstanceOf[CSRBundle].asUInt)).iterator 6794c2cc17SsinceforYy ) 6894c2cc17SsinceforYy} 6994c2cc17SsinceforYy 7094c2cc17SsinceforYyclass SbpctlBundle extends CSRBundle { 7194c2cc17SsinceforYy val LOOP_ENABLE = RW(6).withReset(true.B) 7294c2cc17SsinceforYy val RAS_ENABLE = RW(5).withReset(true.B) 7394c2cc17SsinceforYy val SC_ENABLE = RW(4).withReset(true.B) 7494c2cc17SsinceforYy val TAGE_ENABLE = RW(3).withReset(true.B) 7594c2cc17SsinceforYy val BIM_ENABLE = RW(2).withReset(true.B) 7694c2cc17SsinceforYy val BTB_ENABLE = RW(1).withReset(true.B) 7794c2cc17SsinceforYy val UBTB_ENABLE = RW(0).withReset(true.B) 7894c2cc17SsinceforYy} 7994c2cc17SsinceforYy 8094c2cc17SsinceforYyclass SpfctlBundle extends CSRBundle { 81*881e32f5SZifei Zhang val L2_PF_TP_ENABLE = RW( 21).withReset(true.B) // (Train L2, Prefetch L2) TP 82*881e32f5SZifei Zhang val L2_PF_VBOP_ENABLE = RW( 20).withReset(true.B) // (Train L2, Prefetch L2) VBOP 83*881e32f5SZifei Zhang val L2_PF_PBOP_ENABLE = RW( 19).withReset(true.B) // (Train L2, Prefetch L2) PBOP 84*881e32f5SZifei Zhang val L2_PF_RECV_ENABLE = RW( 18).withReset(true.B) // (Train L1, Prefetch L2) receive from sms 8594c2cc17SsinceforYy val L2_PF_STORE_ONLY = RW( 17).withReset(false.B) // L2 pf store only 8694c2cc17SsinceforYy val L1D_PF_ENABLE_STRIDE = RW( 16).withReset(true.B) // L1D prefetch enable stride 878419d406SXuan Hu val L1D_PF_ACTIVE_STRIDE = SpfctlL1DPfActiveStride(15, 10).withReset(SpfctlL1DPfActiveStride.initValue) // L1D prefetch active page stride 888419d406SXuan Hu val L1D_PF_ACTIVE_THRESHOLD = SpfctlL1DPfActiveThreshold( 9, 6).withReset(SpfctlL1DPfActiveThreshold.initValue) // L1D prefetch active page threshold 8994c2cc17SsinceforYy val L1D_PF_ENABLE_PHT = RW( 5).withReset(true.B) // L1D prefetch enable pht 9094c2cc17SsinceforYy val L1D_PF_ENABLE_AGT = RW( 4).withReset(true.B) // L1D prefetch enable agt 9194c2cc17SsinceforYy val L1D_PF_TRAIN_ON_HIT = RW( 3).withReset(false.B) // L1D train prefetch on hit 9294c2cc17SsinceforYy val L1D_PF_ENABLE = RW( 2).withReset(true.B) // L1D Cache Prefetcher Enable 93*881e32f5SZifei Zhang val L2_PF_ENABLE = RW( 1).withReset(true.B) // L2 Cache Prefetcher master Enable 9494c2cc17SsinceforYy val L1I_PF_ENABLE = RW( 0).withReset(true.B) // L1I Cache Prefetcher Enable 9594c2cc17SsinceforYy} 9694c2cc17SsinceforYy 9794c2cc17SsinceforYyclass SlvpredctlBundle extends CSRBundle { 988419d406SXuan Hu val LVPRED_TIMEOUT = SlvpredCtlTimeOut(8, 4).withReset(SlvpredCtlTimeOut.initValue) 994016eee8SsinceforYy val STORESET_NO_FAST_WAKEUP = RW(3).withReset(false.B) 1004016eee8SsinceforYy val STORESET_WAIT_STORE = RW(2).withReset(false.B) 1014016eee8SsinceforYy val NO_SPEC_LOAD = RW(1).withReset(false.B) 1024016eee8SsinceforYy val LVPRED_DISABLE = RW(0).withReset(false.B) 10394c2cc17SsinceforYy} 10494c2cc17SsinceforYy 10594c2cc17SsinceforYyclass SmblockctlBundle extends CSRBundle { 10641d8d239Shappy-lx val HD_MISALIGN_LD_ENABLE = RW( 9).withReset(true.B) // Enable hardware load misalign. 10741d8d239Shappy-lx val HD_MISALIGN_ST_ENABLE = RW( 8).withReset(true.B) // Enable hardware store misalign. 1084016eee8SsinceforYy val UNCACHE_WRITE_OUTSTANDING_ENABLE = RW( 7).withReset(false.B) // Enable uncache write outstanding (0). 1094016eee8SsinceforYy val CACHE_ERROR_ENABLE = RW( 6).withReset(true.B) // Enable cache error after reset (CE). 1104016eee8SsinceforYy val SOFT_PREFETCH_ENABLE = RW( 5).withReset(true.B) // Enable soft-prefetch after reset (SP). 1114016eee8SsinceforYy val LDLD_VIO_CHECK_ENABLE = RW( 4).withReset(true.B) // Enable load load violation check after reset (LVC). 1128419d406SXuan Hu val SBUFFER_THRESHOLD = SbufferThreshold(3, 0).withReset(SbufferThreshold.initValue) // Store buffer flush threshold (Th). 11394c2cc17SsinceforYy} 11494c2cc17SsinceforYy 11594c2cc17SsinceforYyclass SrnctlBundle extends CSRBundle { 11625dc4a82SXuan Hu val WFI_ENABLE = RW(2).withReset(true.B) 11725dc4a82SXuan Hu val FUSION_ENABLE = RW(0).withReset(true.B) 11894c2cc17SsinceforYy} 11994c2cc17SsinceforYy 120b7a63495SNewPaulWalkerclass McorepwrBundle extends CSRBundle { 121b7a63495SNewPaulWalker val POWER_DOWN_ENABLE = RW(0).withReset(false.B) 122b7a63495SNewPaulWalker} 123b7a63495SNewPaulWalker 124b7a63495SNewPaulWalkerclass MflushpwrBundle extends CSRBundle { 125b7a63495SNewPaulWalker val FLUSH_L2_ENABLE = RW(0).withReset(false.B) 126b7a63495SNewPaulWalker val L2_FLUSH_DONE = RO(1).withReset(false.B) 127b7a63495SNewPaulWalker} 128b7a63495SNewPaulWalker 1298419d406SXuan Huobject SbufferThreshold extends CSREnum with RWApply { 1308419d406SXuan Hu val initValue = Value(7.U) 1311a610887SsinceforYy} 1328419d406SXuan Hu 1338419d406SXuan Huobject SpfctlL1DPfActiveStride extends CSREnum with RWApply { 1348419d406SXuan Hu val initValue = Value(30.U) 1358419d406SXuan Hu} 1368419d406SXuan Hu 1378419d406SXuan Huobject SpfctlL1DPfActiveThreshold extends CSREnum with RWApply { 1388419d406SXuan Hu val initValue = Value(12.U) 1398419d406SXuan Hu} 1408419d406SXuan Hu 1418419d406SXuan Huobject SlvpredCtlTimeOut extends CSREnum with RWApply { 1428419d406SXuan Hu val initValue = Value(3.U) 1438419d406SXuan Hu} 1448419d406SXuan Hu 145