LSQWrapper.scala 6.6 KB
Newer Older
L
Lemover 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/***************************************************************************************
* Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences
*
* 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.
***************************************************************************************/

Y
Yinan Xu 已提交
16 17
package xiangshan.mem

18
import chipsalliance.rocketchip.config.Parameters
Y
Yinan Xu 已提交
19 20 21 22 23 24 25
import chisel3._
import chisel3.util._
import utils._
import xiangshan._
import xiangshan.cache._
import xiangshan.cache.{DCacheWordIO, DCacheLineIO, TlbRequestIO, MemoryOpConstants}
import xiangshan.mem._
26
import xiangshan.backend.roq.RoqLsqIO
Y
Yinan Xu 已提交
27

28
class ExceptionAddrIO(implicit p: Parameters) extends XSBundle {
Y
Yinan Xu 已提交
29 30 31 32 33
  val lsIdx = Input(new LSIdx)
  val isStore = Input(Bool())
  val vaddr = Output(UInt(VAddrBits.W))
}

34
class FwdEntry extends Bundle {
35 36
  val valid = Bool()
  val data = UInt(8.W)
W
William Wang 已提交
37 38
}

Y
Yinan Xu 已提交
39
// inflight miss block reqs
40
class InflightBlockInfo(implicit p: Parameters) extends XSBundle {
Y
Yinan Xu 已提交
41 42 43 44
  val block_addr = UInt(PAddrBits.W)
  val valid = Bool()
}

45
class LsqEnqIO(implicit p: Parameters) extends XSBundle {
Y
Yinan Xu 已提交
46
  val canAccept = Output(Bool())
47
  val needAlloc = Vec(RenameWidth, Input(UInt(2.W)))
Y
Yinan Xu 已提交
48 49 50 51
  val req = Vec(RenameWidth, Flipped(ValidIO(new MicroOp)))
  val resp = Vec(RenameWidth, Output(new LSIdx))
}

Y
Yinan Xu 已提交
52
// Load / Store Queue Wrapper for XiangShan Out of Order LSU
53
class LsqWrappper(implicit p: Parameters) extends XSModule with HasDCacheParameters {
Y
Yinan Xu 已提交
54
  val io = IO(new Bundle() {
Y
Yinan Xu 已提交
55
    val enq = new LsqEnqIO
56 57
    val brqRedirect = Flipped(ValidIO(new Redirect))
    val flush = Input(Bool())
Y
Yinan Xu 已提交
58 59
    val loadIn = Vec(LoadPipelineWidth, Flipped(Valid(new LsPipelineBundle)))
    val storeIn = Vec(StorePipelineWidth, Flipped(Valid(new LsPipelineBundle)))
60
    val storeDataIn = Vec(StorePipelineWidth, Flipped(Valid(new StoreDataBundle))) // store data, send to sq from rs
61
    val loadDataForwarded = Vec(LoadPipelineWidth, Input(Bool()))
62
    val needReplayFromRS = Vec(LoadPipelineWidth, Input(Bool()))
Y
Yinan Xu 已提交
63
    val sbuffer = Vec(StorePipelineWidth, Decoupled(new DCacheWordReq))
64
    val ldout = Vec(2, DecoupledIO(new ExuOutput)) // writeback int load
65
    val mmioStout = DecoupledIO(new ExuOutput) // writeback uncached store
66
    val forward = Vec(LoadPipelineWidth, Flipped(new PipeLoadForwardQueryIO))
67
    val roq = Flipped(new RoqLsqIO)
Y
Yinan Xu 已提交
68
    val rollback = Output(Valid(new Redirect))
69
    val dcache = Flipped(ValidIO(new Refill))
Y
Yinan Xu 已提交
70 71
    val uncache = new DCacheWordIO
    val exceptionAddr = new ExceptionAddrIO
W
William Wang 已提交
72
    val sqempty = Output(Bool())
73 74
    val issuePtrExt = Output(new SqPtr)
    val storeIssue = Vec(StorePipelineWidth, Flipped(Valid(new ExuInput)))
75 76
    val sqFull = Output(Bool())
    val lqFull = Output(Bool())
Y
Yinan Xu 已提交
77 78 79 80 81
  })

  val loadQueue = Module(new LoadQueue)
  val storeQueue = Module(new StoreQueue)

82 83 84 85
  // io.enq logic
  // LSQ: send out canAccept when both load queue and store queue are ready
  // Dispatch: send instructions to LSQ only when they are ready
  io.enq.canAccept := loadQueue.io.enq.canAccept && storeQueue.io.enq.canAccept
86 87
  loadQueue.io.enq.sqCanAccept := storeQueue.io.enq.canAccept
  storeQueue.io.enq.lqCanAccept := loadQueue.io.enq.canAccept
88
  for (i <- 0 until RenameWidth) {
89 90
    loadQueue.io.enq.needAlloc(i) := io.enq.needAlloc(i)(0)
    loadQueue.io.enq.req(i).valid := io.enq.needAlloc(i)(0) && io.enq.req(i).valid
91
    loadQueue.io.enq.req(i).bits  := io.enq.req(i).bits
Y
Yinan Xu 已提交
92

93 94 95
    storeQueue.io.enq.needAlloc(i) := io.enq.needAlloc(i)(1)
    storeQueue.io.enq.req(i).valid := io.enq.needAlloc(i)(1) && io.enq.req(i).valid
    storeQueue.io.enq.req(i).bits  := io.enq.req(i).bits
Y
Yinan Xu 已提交
96

97 98 99 100
    io.enq.resp(i).lqIdx := loadQueue.io.enq.resp(i)
    io.enq.resp(i).sqIdx := storeQueue.io.enq.resp(i)
  }

Y
Yinan Xu 已提交
101 102
  // load queue wiring
  loadQueue.io.brqRedirect <> io.brqRedirect
103
  loadQueue.io.flush <> io.flush
Y
Yinan Xu 已提交
104 105
  loadQueue.io.loadIn <> io.loadIn
  loadQueue.io.storeIn <> io.storeIn
106
  loadQueue.io.loadDataForwarded <> io.loadDataForwarded
107
  loadQueue.io.needReplayFromRS <> io.needReplayFromRS
Y
Yinan Xu 已提交
108
  loadQueue.io.ldout <> io.ldout
109
  loadQueue.io.roq <> io.roq
Y
Yinan Xu 已提交
110 111 112 113 114 115 116 117
  loadQueue.io.rollback <> io.rollback
  loadQueue.io.dcache <> io.dcache
  loadQueue.io.exceptionAddr.lsIdx := io.exceptionAddr.lsIdx
  loadQueue.io.exceptionAddr.isStore := DontCare

  // store queue wiring
  // storeQueue.io <> DontCare
  storeQueue.io.brqRedirect <> io.brqRedirect
118
  storeQueue.io.flush <> io.flush
Y
Yinan Xu 已提交
119
  storeQueue.io.storeIn <> io.storeIn
120
  storeQueue.io.storeDataIn <> io.storeDataIn
Y
Yinan Xu 已提交
121
  storeQueue.io.sbuffer <> io.sbuffer
122
  storeQueue.io.mmioStout <> io.mmioStout
123
  storeQueue.io.roq <> io.roq
Y
Yinan Xu 已提交
124 125
  storeQueue.io.exceptionAddr.lsIdx := io.exceptionAddr.lsIdx
  storeQueue.io.exceptionAddr.isStore := DontCare
126 127
  storeQueue.io.issuePtrExt <> io.issuePtrExt
  storeQueue.io.storeIssue <> io.storeIssue
Y
Yinan Xu 已提交
128

Y
Yinan Xu 已提交
129
  loadQueue.io.load_s1 <> io.forward
Y
Yinan Xu 已提交
130 131
  storeQueue.io.forward <> io.forward // overlap forwardMask & forwardData, DO NOT CHANGE SEQUENCE

W
William Wang 已提交
132 133
  storeQueue.io.sqempty <> io.sqempty

Y
Yinan Xu 已提交
134 135 136 137
  io.exceptionAddr.vaddr := Mux(io.exceptionAddr.isStore, storeQueue.io.exceptionAddr.vaddr, loadQueue.io.exceptionAddr.vaddr)

  // naive uncache arbiter
  val s_idle :: s_load :: s_store :: Nil = Enum(3)
138
  val pendingstate = RegInit(s_idle)
Y
Yinan Xu 已提交
139

140
  switch(pendingstate){
Y
Yinan Xu 已提交
141 142
    is(s_idle){
      when(io.uncache.req.fire()){
143
        pendingstate := Mux(loadQueue.io.uncache.req.valid, s_load, s_store)
Y
Yinan Xu 已提交
144 145 146 147
      }
    }
    is(s_load){
      when(io.uncache.resp.fire()){
148
        pendingstate := s_idle
Y
Yinan Xu 已提交
149 150 151 152
      }
    }
    is(s_store){
      when(io.uncache.resp.fire()){
153
        pendingstate := s_idle
Y
Yinan Xu 已提交
154 155 156 157 158 159 160 161 162 163 164 165 166
      }
    }
  }

  loadQueue.io.uncache := DontCare
  storeQueue.io.uncache := DontCare
  loadQueue.io.uncache.resp.valid := false.B
  storeQueue.io.uncache.resp.valid := false.B
  when(loadQueue.io.uncache.req.valid){
    io.uncache.req <> loadQueue.io.uncache.req
  }.otherwise{
    io.uncache.req <> storeQueue.io.uncache.req
  }
167
  when(pendingstate === s_load){
Y
Yinan Xu 已提交
168 169 170 171 172 173 174
    io.uncache.resp <> loadQueue.io.uncache.resp
  }.otherwise{
    io.uncache.resp <> storeQueue.io.uncache.resp
  }

  assert(!(loadQueue.io.uncache.req.valid && storeQueue.io.uncache.req.valid))
  assert(!(loadQueue.io.uncache.resp.valid && storeQueue.io.uncache.resp.valid))
175
  assert(!((loadQueue.io.uncache.resp.valid || storeQueue.io.uncache.resp.valid) && pendingstate === s_idle))
Y
Yinan Xu 已提交
176

177 178
  io.lqFull := loadQueue.io.lqFull
  io.sqFull := storeQueue.io.sqFull
Y
Yinan Xu 已提交
179
}