add OP_TLBIE to mmu fsm
[soc.git] / src / soc / fu / mmu / fsm.py
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
4
5 from soc.experiment.mmu import MMU
6 from soc.experiment.dcache import DCache
7
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
12
13
14 class FSMMMUStage(ControlBase):
15 def __init__(self, pspec):
16 super().__init__()
17 self.pspec = pspec
18
19 # set up p/n data
20 self.p.data_i = MMUInputData(pspec)
21 self.n.data_o = MMUOutputData(pspec)
22
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)
27
28 self.mmu = MMU()
29 self.dcache = DCache()
30
31 # make life a bit easier in Core
32 self.pspec.mmu = self.mmu
33 self.pspec.dcache = self.dcache
34
35 # for SPR field number access
36 i = self.p.data_i
37 self.fields = DecodeFields(SignalBitRange, [i.ctx.op.insn])
38 self.fields.create_specs()
39
40 def elaborate(self, platform):
41 m = super().elaborate(platform)
42
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
49 data_i, data_o = self.p.data_i, self.n.data_o
50 a_i, b_i = data_i.ra, data_i.rb
51 op = data_i.ctx.op
52
53 # busy/done signals
54 busy = Signal()
55 done = Signal()
56 m.d.comb += self.n.valid_o.eq(busy & done)
57 m.d.comb += self.p.ready_o.eq(~busy)
58
59 # take copy of X-Form SPR field
60 x_fields = self.fields.FormXFX
61 spr = Signal(len(x_fields.SPR))
62 comb += spr.eq(decode_spr_num(x_fields.SPR))
63
64 with m.If(~busy):
65 with m.If(self.p.valid_i):
66 m.d.sync += busy.eq(1)
67 with m.Else():
68
69 # based on the Micro-Op, we work out which of MMU or DCache
70 # should "action" the operation. one of MMU or DCache gets
71 # enabled ("valid") and we twiddle our thumbs until it
72 # responds ("done").
73 with m.Switch(op):
74
75 with m.Case(MicrOp.OP_MTSPR):
76 # subset SPR: first check a few bits
77 with m.If(~spr[9] & ~spr[5]):
78 with m.If(spr[0]):
79 comb += dsisr.eq(a_i[:32])
80 with m.Else():
81 comb += dar.eq(a_i)
82 comb += done.eq(1)
83 # pass it over to the MMU instead
84 with m.Else():
85 # kick the MMU and wait for it to complete
86 comb += mmu.m_in.valid.eq(1) # start
87 comb += mmu.m_in.mtspr.eq(1) # mtspr mode
88 comb += mmu.m_in.sprn.eq(spr) # which SPR
89 comb += mmu.m_in.rs.eq(a_i) # incoming operand (RS)
90 comb += done.eq(mmu.m_out.done) # zzzz
91
92 with m.Case(MicrOp.OP_DCBZ):
93 # activate dcbz mode (spec: v3.0B p850)
94 comb += dcache.d_in.valid.eq(1) # start
95 comb += dcache.d_in.dcbz.eq(1) # dcbz mode
96 comb += dcache.d_in.addr.eq(a_i + b_i) # addr is (RA|0) + RB
97 comb += done.eq(dcache.d_out.done) # zzzz
98
99 with m.Case(MicrOp.OP_TLBIE):
100 # pass TLBIE request to MMU (spec: v3.0B p1034)
101 # note that the spr is *not* an actual spr number, it's
102 # just that those bits happen to match with field bits
103 # RIC, PRS, R
104 comb += mmu.m_in.valid.eq(1) # start
105 comb += mmu.m_in.tlbie.eq(1) # mtspr mode
106 comb += mmu.m_in.sprn.eq(spr) # use sprn to send insn bits
107 comb += mmu.m_in.addr.eq(b_i) # incoming operand (RB)
108 comb += done.eq(mmu.m_out.done) # zzzz
109
110 with m.If(self.n.ready_i & self.n.valid_o):
111 m.d.sync += busy.eq(0)
112
113 return m
114
115 def __iter__(self):
116 yield from self.p
117 yield from self.n
118
119 def ports(self):
120 return list(self)