1 from nmigen
import Elaboratable
, Module
, Signal
, Shape
, unsigned
, Cat
, Mux
2 from soc
.fu
.mmu
.pipe_data
import MMUInputData
, MMUOutputData
, MMUPipeSpec
3 from nmutil
.singlepipe
import ControlBase
5 from soc
.experiment
.mmu
import MMU
6 from soc
.experiment
.dcache
import DCache
8 from soc
.decoder
.power_fields
import DecodeFields
9 from soc
.decoder
.power_fieldsn
import SignalBitRange
10 from soc
.decoder
.power_decoder2
import decode_spr_num
11 from soc
.decoder
.power_enums
import MicrOp
, SPR
, XER_bits
14 class FSMMMUStage(ControlBase
):
15 def __init__(self
, pspec
):
20 self
.p
.data_i
= MMUInputData(pspec
)
21 self
.n
.data_o
= MMUOutputData(pspec
)
23 # this Function Unit is extremely unusual in that it actually stores a
24 # "thing" rather than "processes inputs and produces outputs". hence
25 # why it has to be a FSM. linking up LD/ST however is going to have
26 # to be done back in Issuer (or Core)
29 self
.dcache
= DCache()
31 # make life a bit easier in Core
32 self
.pspec
.mmu
= self
.mmu
33 self
.pspec
.dcache
= self
.dcache
35 # for SPR field number access
37 self
.fields
= DecodeFields(SignalBitRange
, [i
.ctx
.op
.insn
])
38 self
.fields
.create_specs()
40 def elaborate(self
, platform
):
41 m
= super().elaborate(platform
)
43 # link mmu and dcache together
44 m
.submodules
.dcache
= dcache
= self
.dcache
45 m
.submodules
.mmu
= mmu
= self
.mmu
46 m
.d
.comb
+= dcache
.m_in
.eq(mmu
.d_out
)
47 m
.d
.comb
+= mmu
.d_in
.eq(dcache
.m_out
)
48 m_in
, m_out
= mmu
.m_in
, mmu
.m_out
49 d_in
, d_out
= dcache
.d_in
, dcache
.d_out
51 data_i
, data_o
= self
.p
.data_i
, self
.n
.data_o
52 a_i
, b_i
, o
= data_i
.ra
, data_i
.rb
, data_o
.o
58 m
.d
.comb
+= self
.n
.valid_o
.eq(busy
& done
)
59 m
.d
.comb
+= self
.p
.ready_o
.eq(~busy
)
61 # take copy of X-Form SPR field
62 x_fields
= self
.fields
.FormXFX
63 spr
= Signal(len(x_fields
.SPR
))
64 comb
+= spr
.eq(decode_spr_num(x_fields
.SPR
))
67 with m
.If(self
.p
.valid_i
):
68 m
.d
.sync
+= busy
.eq(1)
71 # based on the Micro-Op, we work out which of MMU or DCache
72 # should "action" the operation. one of MMU or DCache gets
73 # enabled ("valid") and we twiddle our thumbs until it
77 with m
.Case(MicrOp
.OP_MTSPR
):
78 # subset SPR: first check a few bits
79 with m
.If(~spr
[9] & ~spr
[5]):
81 comb
+= dsisr
.eq(a_i
[:32])
85 # pass it over to the MMU instead
87 # kick the MMU and wait for it to complete
88 comb
+= m_in
.valid
.eq(1) # start
89 comb
+= m_in
.mtspr
.eq(1) # mtspr mode
90 comb
+= m_in
.sprn
.eq(spr
) # which SPR
91 comb
+= m_in
.rs
.eq(a_i
) # incoming operand (RS)
92 comb
+= done
.eq(m_out
.done
) # zzzz
94 with m
.Case(MicrOp
.OP_MFSPR
):
95 # subset SPR: first check a few bits
96 with m
.If(~spr
[9] & ~spr
[5]):
98 comb
+= o
.data
.eq(dsisr
)
100 comb
+= o
.data
.eq(dar
)
103 # pass it over to the MMU instead
105 # kick the MMU and wait for it to complete
106 comb
+= m_in
.valid
.eq(1) # start
107 comb
+= m_in
.mtspr
.eq(1) # mtspr mode
108 comb
+= m_in
.sprn
.eq(spr
) # which SPR
109 comb
+= m_in
.rs
.eq(a_i
) # incoming operand (RS)
110 comb
+= o
.data
.eq(m_out
.sprval
) # SPR from MMU
111 comb
+= o
.ok
.eq(m_out
.done
) # only when m_out valid
112 comb
+= done
.eq(m_out
.done
) # zzzz
114 with m
.Case(MicrOp
.OP_DCBZ
):
115 # activate dcbz mode (spec: v3.0B p850)
116 comb
+= d_in
.valid
.eq(1) # start
117 comb
+= d_in
.dcbz
.eq(1) # dcbz mode
118 comb
+= d_in
.addr
.eq(a_i
+ b_i
) # addr is (RA|0) + RB
119 comb
+= done
.eq(d_out
.done
) # zzzz
121 with m
.Case(MicrOp
.OP_TLBIE
):
122 # pass TLBIE request to MMU (spec: v3.0B p1034)
123 # note that the spr is *not* an actual spr number, it's
124 # just that those bits happen to match with field bits
126 comb
+= m_in
.valid
.eq(1) # start
127 comb
+= m_in
.tlbie
.eq(1) # mtspr mode
128 comb
+= m_in
.sprn
.eq(spr
) # use sprn to send insn bits
129 comb
+= m_in
.addr
.eq(b_i
) # incoming operand (RB)
130 comb
+= done
.eq(m_out
.done
) # zzzz
132 with m
.If(self
.n
.ready_i
& self
.n
.valid_o
):
133 m
.d
.sync
+= busy
.eq(0)