a89868898000be321c6339e639761471a9f9c035
1 from nmigen
import Elaboratable
, Module
, Signal
, Shape
, unsigned
, Cat
, Mux
2 from nmigen
import Const
3 from soc
.fu
.mmu
.pipe_data
import MMUInputData
, MMUOutputData
, MMUPipeSpec
4 from nmutil
.singlepipe
import ControlBase
5 from nmutil
.util
import rising_edge
7 from soc
.experiment
.mmu
import MMU
8 from soc
.experiment
.dcache
import DCache
10 from soc
.decoder
.power_fields
import DecodeFields
11 from soc
.decoder
.power_fieldsn
import SignalBitRange
12 from soc
.decoder
.power_decoder2
import decode_spr_num
13 from soc
.decoder
.power_enums
import MicrOp
, SPR
, XER_bits
15 from soc
.experiment
.pimem
import PortInterface
16 from soc
.experiment
.pimem
import PortInterfaceBase
18 from soc
.experiment
.mem_types
import LoadStore1ToDCacheType
, LoadStore1ToMMUType
19 from soc
.experiment
.mem_types
import DCacheToLoadStore1Type
, MMUToLoadStore1Type
21 # for testing purposes
22 from soc
.experiment
.testmem
import TestMemory
24 # glue logic for microwatt mmu and dcache
25 class LoadStore1(PortInterfaceBase
):
26 def __init__(self
, regwid
=64, addrwid
=4):
27 super().__init
__(regwid
, addrwid
)
28 self
.d_in
= LoadStore1ToDCacheType()
29 self
.d_out
= DCacheToLoadStore1Type()
30 self
.l_in
= LoadStore1ToMMUType()
31 self
.l_out
= MMUToLoadStore1Type()
32 # for debugging with gtkwave only
33 self
.debug1
= Signal()
34 self
.debug2
= Signal()
36 def set_wr_addr(self
, m
, addr
, mask
):
37 m
.d
.comb
+= self
.d_in
.addr
.eq(addr
)
38 m
.d
.comb
+= self
.l_in
.addr
.eq(addr
)
42 def set_rd_addr(self
, m
, addr
, mask
):
43 m
.d
.comb
+= self
.d_in
.addr
.eq(addr
)
44 m
.d
.comb
+= self
.l_in
.addr
.eq(addr
)
45 m
.d
.comb
+= self
.debug1
.eq(1)
49 def set_wr_data(self
, m
, data
, wen
):
50 m
.d
.comb
+= self
.d_in
.data
.eq(data
)
55 def get_rd_data(self
, m
):
57 m
.d
.comb
+= self
.debug2
.eq(1) #const high
58 data
= self
.d_out
.data
61 def elaborate(self
, platform
):
62 m
= super().elaborate(platform
)
68 yield from super().ports()
71 class FSMMMUStage(ControlBase
):
72 def __init__(self
, pspec
):
77 self
.p
.data_i
= MMUInputData(pspec
)
78 self
.n
.data_o
= MMUOutputData(pspec
)
80 # incoming PortInterface
81 self
.ldst
= LoadStore1() # TODO make this depend on pspec
82 self
.pi
= self
.ldst
.pi
84 # this Function Unit is extremely unusual in that it actually stores a
85 # "thing" rather than "processes inputs and produces outputs". hence
86 # why it has to be a FSM. linking up LD/ST however is going to have
87 # to be done back in Issuer (or Core)
90 self
.dcache
= DCache()
93 # for verification of DCache
94 # XXX -- read testmem.py
95 self
.testmem
= TestMemory(regwid
, aw
, granularity
=regwid
//8, init
=False)
97 # make life a bit easier in Core
98 self
.pspec
.mmu
= self
.mmu
99 self
.pspec
.dcache
= self
.dcache
101 # debugging output for gtkw
102 self
.debug0
= Signal(4)
103 self
.debug_wb_cyc
= Signal()
104 self
.debug_wb_stb
= Signal()
105 self
.debug_wb_we
= Signal()
106 #self.debug1 = Signal(64)
107 #self.debug2 = Signal(64)
108 #self.debug3 = Signal(64)
110 # for SPR field number access
112 self
.fields
= DecodeFields(SignalBitRange
, [i
.ctx
.op
.insn
])
113 self
.fields
.create_specs()
115 def elaborate(self
, platform
):
116 m
= super().elaborate(platform
)
119 # link mmu and dcache together
120 m
.submodules
.dcache
= dcache
= self
.dcache
121 m
.submodules
.mmu
= mmu
= self
.mmu
122 m
.submodules
.ldst
= ldst
= self
.ldst
123 m
.submodules
.testmem
= testmem
= self
.testmem
124 m
.d
.comb
+= dcache
.m_in
.eq(mmu
.d_out
)
125 m
.d
.comb
+= mmu
.d_in
.eq(dcache
.m_out
)
126 l_in
, l_out
= mmu
.l_in
, mmu
.l_out
127 d_in
, d_out
= dcache
.d_in
, dcache
.d_out
129 # link ldst and dcache together
130 comb
+= l_in
.eq(self
.ldst
.l_in
)
131 comb
+= self
.ldst
.l_out
.eq(l_out
)
132 comb
+= d_in
.eq(self
.ldst
.d_in
)
133 comb
+= self
.ldst
.d_out
.eq(self
.dcache
.d_out
)
135 # [TODO] connect DCache wishbone (wb_out,wb_in) to testmemory
137 # connect DCache wishbone master to debugger
138 comb
+= self
.debug_wb_cyc
.eq(dcache
.wb_out
.cyc
)
139 comb
+= self
.debug_wb_stb
.eq(dcache
.wb_out
.stb
)
140 comb
+= self
.debug_wb_we
.eq(dcache
.wb_out
.we
)
142 data_i
, data_o
= self
.p
.data_i
, self
.n
.data_o
143 a_i
, b_i
, o
= data_i
.ra
, data_i
.rb
, data_o
.o
146 # TODO: link these SPRs somewhere
153 m
.d
.comb
+= self
.n
.valid_o
.eq(busy
& done
)
154 m
.d
.comb
+= self
.p
.ready_o
.eq(~busy
)
156 # take copy of X-Form SPR field
157 x_fields
= self
.fields
.FormXFX
158 spr
= Signal(len(x_fields
.SPR
))
159 comb
+= spr
.eq(decode_spr_num(x_fields
.SPR
))
161 # ok so we have to "pulse" the MMU (or dcache) rather than
162 # hold the valid hi permanently. guess what this does...
165 m
.d
.comb
+= blip
.eq(rising_edge(m
, valid
))
168 with m
.If(self
.p
.valid_i
):
169 m
.d
.sync
+= busy
.eq(1)
172 # based on the Micro-Op, we work out which of MMU or DCache
173 # should "action" the operation. one of MMU or DCache gets
174 # enabled ("valid") and we twiddle our thumbs until it
177 # FIXME: properly implement MicrOp.OP_MTSPR and MicrOp.OP_MFSPR
179 with m
.Switch(op
.insn_type
):
180 comb
+= self
.debug0
.eq(3)
181 with m
.Case(MicrOp
.OP_MTSPR
):
182 # subset SPR: first check a few bits
183 with m
.If(~spr
[9] & ~spr
[5]):
185 comb
+= dsisr
.eq(a_i
[:32])
189 # pass it over to the MMU instead
191 # blip the MMU and wait for it to complete
192 comb
+= valid
.eq(1) # start "pulse"
193 comb
+= l_in
.valid
.eq(blip
) # start
194 comb
+= l_in
.mtspr
.eq(1) # mtspr mode
195 comb
+= l_in
.sprn
.eq(spr
) # which SPR
196 comb
+= l_in
.rs
.eq(a_i
) # incoming operand (RS)
197 comb
+= done
.eq(l_out
.done
) # zzzz
199 with m
.Case(MicrOp
.OP_MFSPR
):
200 comb
+= self
.debug0
.eq(3)
201 # subset SPR: first check a few bits
202 with m
.If(~spr
[9] & ~spr
[5]):
204 comb
+= o
.data
.eq(dsisr
)
206 comb
+= o
.data
.eq(dar
)
209 # pass it over to the MMU instead
211 # blip the MMU and wait for it to complete
212 comb
+= valid
.eq(1) # start "pulse"
213 comb
+= l_in
.valid
.eq(blip
) # start
214 comb
+= l_in
.mtspr
.eq(0) # mfspr!=mtspr
215 comb
+= l_in
.sprn
.eq(spr
) # which SPR
216 comb
+= l_in
.rs
.eq(a_i
) # incoming operand (RS)
217 comb
+= o
.data
.eq(l_out
.sprval
) # SPR from MMU
218 comb
+= o
.ok
.eq(l_out
.done
) # only when l_out valid
219 comb
+= done
.eq(l_out
.done
) # zzzz
221 with m
.Case(MicrOp
.OP_DCBZ
):
222 # activate dcbz mode (spec: v3.0B p850)
223 comb
+= valid
.eq(1) # start "pulse"
224 comb
+= d_in
.valid
.eq(blip
) # start
225 comb
+= d_in
.dcbz
.eq(1) # dcbz mode
226 comb
+= d_in
.addr
.eq(a_i
+ b_i
) # addr is (RA|0) + RB
227 comb
+= done
.eq(d_out
.store_done
) # TODO
228 comb
+= self
.debug0
.eq(1)
230 with m
.Case(MicrOp
.OP_TLBIE
):
231 # pass TLBIE request to MMU (spec: v3.0B p1034)
232 # note that the spr is *not* an actual spr number, it's
233 # just that those bits happen to match with field bits
235 comb
+= valid
.eq(1) # start "pulse"
236 comb
+= l_in
.valid
.eq(blip
) # start
237 comb
+= l_in
.tlbie
.eq(1) # mtspr mode
238 comb
+= l_in
.sprn
.eq(spr
) # use sprn to send insn bits
239 comb
+= l_in
.addr
.eq(b_i
) # incoming operand (RB)
240 comb
+= done
.eq(l_out
.done
) # zzzz
241 comb
+= self
.debug0
.eq(2)
243 with m
.If(self
.n
.ready_i
& self
.n
.valid_o
):
244 m
.d
.sync
+= busy
.eq(0)