cleanup test_compldst_multi_mmu.py
[soc.git] / src / soc / experiment / test / test_compldst_multi_mmu.py
1 # test case for LOAD / STORE Computation Unit using MMU
2
3 from nmigen.sim import Simulator, Delay, Settle, Tick
4 from nmigen.cli import verilog, rtlil
5 from nmigen import Module, Signal, Mux, Cat, Elaboratable, Array, Repl
6 from nmigen.hdl.rec import Record, Layout
7
8 from nmutil.latch import SRLatch, latchregister
9 from nmutil.byterev import byte_reverse
10 from nmutil.extend import exts
11 from nmutil.util import wrap
12 from soc.fu.regspec import RegSpecAPI
13
14 from openpower.decoder.power_enums import MicrOp, Function, LDSTMode
15 from soc.fu.ldst.ldst_input_record import CompLDSTOpSubset
16 from openpower.decoder.power_decoder2 import Data
17 from openpower.consts import MSR
18
19 from soc.experiment.compalu_multi import go_record, CompUnitRecord
20 from soc.experiment.l0_cache import PortInterface
21 from soc.experiment.pimem import LDSTException
22 from soc.experiment.compldst_multi import LDSTCompUnit, load, store
23 from soc.config.test.test_loadstore import TestMemPspec
24
25 from soc.experiment.mmu import MMU
26 from nmutil.util import Display
27
28 from soc.config.loadstore import ConfigMemoryPortInterface
29 from soc.experiment.test import pagetables
30 from soc.experiment.test.test_wishbone import wb_get
31
32 ########################################
33
34 def wait_for_debug(sig, reason, wait=True, test1st=False):
35 v = (yield sig)
36 cnt = 0
37 print("wait for", reason, sig, v, wait, test1st)
38 if test1st and bool(v) == wait:
39 return
40 while True:
41 cnt = cnt + 1
42 if cnt > 15:
43 raise(Exception(reason))
44 break
45 yield
46 v = (yield sig)
47 #print("...wait for", sig, v)
48 if bool(v) == wait:
49 break
50
51 def store_debug(dut, src1, src2, src3, imm, imm_ok=True, update=False,
52 byterev=True,dcbz=False):
53 print("cut here ======================================")
54 print("ST", src1, src2, src3, imm, imm_ok, update)
55 if dcbz:
56 yield dut.oper_i.insn_type.eq(MicrOp.OP_DCBZ)
57 else:
58 yield dut.oper_i.insn_type.eq(MicrOp.OP_STORE)
59 yield dut.oper_i.data_len.eq(2) # half-word
60 yield dut.oper_i.byte_reverse.eq(byterev)
61 yield dut.src1_i.eq(src1)
62 yield dut.src2_i.eq(src2)
63 yield dut.src3_i.eq(src3)
64 yield dut.oper_i.imm_data.data.eq(imm)
65 yield dut.oper_i.imm_data.ok.eq(imm_ok)
66 #guess: this one was removed -- yield dut.oper_i.update.eq(update)
67 yield dut.issue_i.eq(1)
68 yield
69 yield dut.issue_i.eq(0)
70
71 if imm_ok:
72 active_rel = 0b101
73 else:
74 active_rel = 0b111
75 if dcbz:
76 active_rel = 0b001 # may be wrong, verify
77
78 # wait for all active rel signals to come up
79 cnt = 0
80 while True:
81 rel = yield dut.rd.rel_o # guess: wrong in dcbz case
82 cnt = cnt + 1
83 print("waitActiveRel",cnt)
84 if cnt > 10:
85 raise(Exception("Error1"))
86 print("rel EQ active_rel ?",rel,active_rel)
87 if rel == active_rel:
88 break
89 yield
90 yield dut.rd.go_i.eq(active_rel)
91 yield
92 yield dut.rd.go_i.eq(0)
93
94 yield from wait_for_debug(dut.adr_rel_o, "addr valid",False, test1st=True)
95 # yield from wait_for(dut.adr_rel_o)
96 # yield dut.ad.go.eq(1)
97 # yield
98 # yield dut.ad.go.eq(0)
99
100 if update:
101 yield from wait_for_debug(dut.wr.rel_o[1],"update")
102 yield dut.wr.go.eq(0b10)
103 yield
104 addr = yield dut.addr_o
105 print("addr", addr)
106 yield dut.wr.go.eq(0)
107 else:
108 addr = None
109 print("not update ===============")
110
111 yield from wait_for_debug(dut.sto_rel_o,"sto_rel_o")
112 yield dut.go_st_i.eq(1)
113 yield
114 yield dut.go_st_i.eq(0)
115 yield from wait_for_debug(dut.busy_o,"not_busy" ,False)
116 ###wait_for(dut.stwd_mem_o)
117 yield
118 return addr
119
120 # same thing as soc/src/soc/experiment/test/test_dcbz_pi.py
121 def ldst_sim(dut):
122 yield dut.mmu.rin.prtbl.eq(0x1000000) # set process table
123 addr = 0x100e0
124 data = 0xFF #just a single byte for this test
125 #data = 0xf553b658ba7e1f51
126
127 yield from store(dut, addr, 0, data, 0)
128 yield
129 ld_data, data_ok, ld_addr = yield from load(dut, addr, 0, 0)
130 print(data,data_ok,ld_addr)
131 assert(ld_data==data)
132 yield
133
134 data = 0
135
136 print("doing dcbz/store with data 0 .....")
137 yield from store_debug(dut, addr, 0, data, 0, dcbz=True) #hangs
138
139 ld_data, data_ok, ld_addr = yield from load(dut, addr, 0, 0)
140 print(data,data_ok,ld_addr)
141 print("ld_data is")
142 print(ld_data)
143 assert(ld_data==data)
144 print("dzbz test passed")
145
146 dut.stop = True # stop simulation
147
148 ########################################
149 class TestLDSTCompUnitMMU(LDSTCompUnit):
150
151 def __init__(self, rwid, pspec):
152 # use a LoadStore1 here
153 cmpi = ConfigMemoryPortInterface(pspec)
154 self.cmpi = cmpi
155 ldst = cmpi.pi
156 self.l0 = ldst
157
158 self.mmu = MMU()
159 LDSTCompUnit.__init__(self, ldst.pi, rwid, 4)
160
161 def elaborate(self, platform):
162 m = LDSTCompUnit.elaborate(self, platform)
163 m.submodules.l0 = self.l0
164 m.submodules.mmu = self.mmu
165 # link addr-go direct to rel
166 m.d.comb += self.ad.go_i.eq(self.ad.rel_o)
167
168 # link mmu and dcache together
169 dcache = self.l0.dcache
170 mmu = self.mmu
171 m.d.comb += dcache.m_in.eq(mmu.d_out) # MMUToDCacheType
172 m.d.comb += mmu.d_in.eq(dcache.m_out) # DCacheToMMUType
173
174 return m
175
176
177 def test_scoreboard_mmu():
178
179 m = Module()
180
181 units = {}
182 pspec = TestMemPspec(ldst_ifacetype='mmu_cache_wb',
183 imem_ifacetype='bare_wb',
184 addr_wid=48,
185 mask_wid=8,
186 reg_wid=64,
187 units=units)
188
189 dut = TestLDSTCompUnitMMU(16,pspec)
190
191 m.submodules.dut = dut
192
193 sim = Simulator(m)
194 sim.add_clock(1e-6)
195
196 dut.mem = pagetables.test1
197 dut.stop = False
198
199 sim.add_sync_process(wrap(ldst_sim(dut)))
200 sim.add_sync_process(wrap(wb_get(dut)))
201 with sim.write_vcd('test_scoreboard_mmu.vcd'):
202 sim.run()
203
204 ########################################
205 class TestLDSTCompUnitRegSpecMMU(LDSTCompUnit):
206
207 def __init__(self, pspec):
208 from soc.fu.ldst.pipe_data import LDSTPipeSpec
209 regspec = LDSTPipeSpec.regspec
210
211 # use a LoadStore1 here
212 cmpi = ConfigMemoryPortInterface(pspec)
213 self.cmpi = cmpi
214 ldst = cmpi.pi
215 self.l0 = ldst
216
217 self.mmu = MMU()
218 LDSTCompUnit.__init__(self, ldst.pi, regspec, 4)
219
220 def elaborate(self, platform):
221 m = LDSTCompUnit.elaborate(self, platform)
222 m.submodules.l0 = self.l0
223 m.submodules.mmu = self.mmu
224 # link addr-go direct to rel
225 m.d.comb += self.ad.go_i.eq(self.ad.rel_o)
226
227 # link mmu and dcache together
228 dcache = self.l0.dcache
229 mmu = self.mmu
230 m.d.comb += dcache.m_in.eq(mmu.d_out) # MMUToDCacheType
231 m.d.comb += mmu.d_in.eq(dcache.m_out) # DCacheToMMUType
232
233 return m
234
235 def test_scoreboard_regspec_mmu():
236
237 m = Module()
238
239 units = {}
240 pspec = TestMemPspec(ldst_ifacetype='mmu_cache_wb',
241 imem_ifacetype='bare_wb',
242 addr_wid=48,
243 mask_wid=8,
244 reg_wid=64,
245 units=units)
246
247 dut = TestLDSTCompUnitRegSpecMMU(pspec)
248
249 m.submodules.dut = dut
250
251 sim = Simulator(m)
252 sim.add_clock(1e-6)
253
254 dut.mem = pagetables.test1
255 dut.stop = False
256
257 sim.add_sync_process(wrap(ldst_sim(dut)))
258 sim.add_sync_process(wrap(wb_get(dut)))
259 with sim.write_vcd('test_scoreboard_regspec_mmu.vcd'):
260 sim.run()
261
262 if __name__ == '__main__':
263 test_scoreboard_regspec_mmu()
264 test_scoreboard_mmu()