xref: /XiangShan/src/main/scala/xiangshan/mem/MemCommon.scala (revision 5668a921eb594c3ea72da43594b3fb54e05959a3)
1/***************************************************************************************
2* Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences
3* Copyright (c) 2020-2021 Peng Cheng Laboratory
4*
5* XiangShan is licensed under Mulan PSL v2.
6* You can use this software according to the terms and conditions of the Mulan PSL v2.
7* You may obtain a copy of Mulan PSL v2 at:
8*          http://license.coscl.org.cn/MulanPSL2
9*
10* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
11* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
12* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13*
14* See the Mulan PSL v2 for more details.
15***************************************************************************************/
16
17package xiangshan.mem
18
19
20import chipsalliance.rocketchip.config.Parameters
21import chisel3._
22import chisel3.util._
23import xiangshan._
24import utils._
25import xiangshan.backend.rob.RobPtr
26import xiangshan.cache._
27import xiangshan.backend.fu.FenceToSbuffer
28
29object genWmask {
30  def apply(addr: UInt, sizeEncode: UInt): UInt = {
31    (LookupTree(sizeEncode, List(
32      "b00".U -> 0x1.U, //0001 << addr(2:0)
33      "b01".U -> 0x3.U, //0011
34      "b10".U -> 0xf.U, //1111
35      "b11".U -> 0xff.U //11111111
36    )) << addr(2, 0)).asUInt()
37  }
38}
39
40object genWdata {
41  def apply(data: UInt, sizeEncode: UInt): UInt = {
42    LookupTree(sizeEncode, List(
43      "b00".U -> Fill(8, data(7, 0)),
44      "b01".U -> Fill(4, data(15, 0)),
45      "b10".U -> Fill(2, data(31, 0)),
46      "b11".U -> data
47    ))
48  }
49}
50
51class LsPipelineBundle(implicit p: Parameters) extends XSBundle {
52  val vaddr = UInt(VAddrBits.W)
53  val paddr = UInt(PAddrBits.W)
54  // val func = UInt(6.W)
55  val mask = UInt(8.W)
56  val data = UInt((XLEN+1).W)
57  val uop = new MicroOp
58  val wlineflag = Bool() // store write the whole cache line
59
60  val miss = Bool()
61  val tlbMiss = Bool()
62  val ptwBack = Bool()
63  val mmio = Bool()
64  val rsIdx = UInt(log2Up(IssQueSize).W)
65
66  val forwardMask = Vec(8, Bool())
67  val forwardData = Vec(8, UInt(8.W))
68
69  //softprefetch
70  val isSoftPrefetch = Bool()
71
72  // For debug usage
73  val isFirstIssue = Bool()
74}
75
76class StoreDataBundle(implicit p: Parameters) extends XSBundle {
77  val data = UInt((XLEN+1).W)
78  val uop = new MicroOp
79}
80
81class LoadForwardQueryIO(implicit p: Parameters) extends XSBundle {
82  val vaddr = Output(UInt(VAddrBits.W))
83  val paddr = Output(UInt(PAddrBits.W))
84  val mask = Output(UInt(8.W))
85  val uop = Output(new MicroOp) // for replay
86  val pc = Output(UInt(VAddrBits.W)) //for debug
87  val valid = Output(Bool())
88
89  val forwardMaskFast = Input(Vec(8, Bool())) // resp to load_s1
90  val forwardMask = Input(Vec(8, Bool())) // resp to load_s2
91  val forwardData = Input(Vec(8, UInt(8.W))) // resp to load_s2
92
93  // val lqIdx = Output(UInt(LoadQueueIdxWidth.W))
94  val sqIdx = Output(new SqPtr)
95
96  // dataInvalid suggests store to load forward found forward should happen,
97  // but data is not available for now. If dataInvalid, load inst should
98  // be replayed from RS. Feedback type should be RSFeedbackType.dataInvalid
99  val dataInvalid = Input(Bool()) // Addr match, but data is not valid for now
100
101  // matchInvalid suggests in store to load forward logic, paddr cam result does
102  // to equal to vaddr cam result. If matchInvalid, a microarchitectural exception
103  // should be raised to flush SQ and committed sbuffer.
104  val matchInvalid = Input(Bool()) // resp to load_s2
105}
106
107// LoadForwardQueryIO used in load pipeline
108//
109// Difference between PipeLoadForwardQueryIO and LoadForwardQueryIO:
110// PipeIO use predecoded sqIdxMask for better forward timing
111class PipeLoadForwardQueryIO(implicit p: Parameters) extends LoadForwardQueryIO {
112  // val sqIdx = Output(new SqPtr) // for debug, should not be used in pipeline for timing reasons
113  // sqIdxMask is calcuated in earlier stage for better timing
114  val sqIdxMask = Output(UInt(StoreQueueSize.W))
115
116  // dataInvalid: addr match, but data is not valid for now
117  val dataInvalidFast = Input(Bool()) // resp to load_s1
118  // val dataInvalid = Input(Bool()) // resp to load_s2
119  val dataInvalidSqIdx = Input(UInt(log2Up(StoreQueueSize).W)) // resp to load_s2, sqIdx value
120}
121
122// Query load queue for ld-ld violation
123//
124// Req should be send in load_s1
125// Resp will be generated 1 cycle later
126//
127// Note that query req may be !ready, as dcache is releasing a block
128// If it happens, a replay from rs is needed.
129
130class LoadViolationQueryReq(implicit p: Parameters) extends XSBundle {
131  val paddr = UInt(PAddrBits.W)
132  val uop = new MicroOp // provide lqIdx
133}
134
135class LoadViolationQueryResp(implicit p: Parameters) extends XSBundle {
136  val have_violation = Bool()
137}
138
139class LoadViolationQueryIO(implicit p: Parameters) extends XSBundle {
140  val req = Decoupled(new LoadViolationQueryReq)
141  val resp = Flipped(Valid(new LoadViolationQueryResp))
142}
143
144// Bundle for load / store wait waking up
145class MemWaitUpdateReq(implicit p: Parameters) extends XSBundle {
146  val staIssue = Vec(exuParameters.StuCnt, ValidIO(new ExuInput))
147  val stdIssue = Vec(exuParameters.StuCnt, ValidIO(new ExuInput))
148}
149