1 """PortInterface to LoadStoreUnitInterface adapter
3 PortInterface LoadStoreUnitInterface
4 ------------- ----------------------
9 data_len/4 x_mask/16 (translate using LenExpand)
11 busy_o/1 most likely to be x_busy_o
13 addr.data/48 x_addr_i (x_addr_i[:4] goes into LenExpand)
14 addr.ok/1 probably x_valid_i & ~x_stall_i
16 addr_ok_o/1 no equivalent. *might* work using x_stall_i
17 addr_exc_o/2(?) m_load_err_o and m_store_err_o
19 ld.data/64 m_ld_data_o
20 ld.ok/1 probably implicit, when x_busy drops low
21 st.data/64 x_st_data_i
22 st.ok/1 probably kinda redundant, set to x_st_i
25 from soc
.minerva
.units
.loadstore
import LoadStoreUnitInterface
26 from soc
.experiment
.pimem
import PortInterface
27 from soc
.scoreboard
.addr_match
import LenExpand
28 from nmigen
.utils
import log2_int
30 from nmigen
import Elaboratable
, Module
, Signal
33 class Pi2LSUI(Elaboratable
):
35 def __init__(self
, name
, pi
=None, lsui
=None,
36 data_wid
=64, mask_wid
=8, addr_wid
=48):
37 print ("pi2lsui reg mask addr", data_wid
, mask_wid
, addr_wid
)
38 self
.addrbits
= mask_wid
40 piname
= "%s_pi" % name
41 pi
= PortInterface(piname
, regwid
=data_wid
, addrwid
=addr_wid
)
44 lsui
= LoadStoreUnitInterface(addr_wid
, self
.addrbits
, data_wid
)
47 def splitaddr(self
, addr
):
48 """split the address into top and bottom bits of the memory granularity
50 return addr
[:self
.addrbits
], addr
[self
.addrbits
:]
52 def elaborate(self
, platform
):
54 pi
, lsui
, addrbits
= self
.pi
, self
.lsui
, self
.addrbits
55 m
.submodules
.lenexp
= lenexp
= LenExpand(log2_int(self
.addrbits
), 8)
57 ld_in_progress
= Signal(reset
=0)
59 m
.d
.comb
+= lsui
.x_ld_i
.eq(pi
.is_ld_i
)
60 m
.d
.comb
+= lsui
.x_st_i
.eq(pi
.is_st_i
)
61 m
.d
.comb
+= pi
.busy_o
.eq(lsui
.x_busy_o
)
63 with m
.If(pi
.addr
.ok
):
64 # expand the LSBs of address plus LD/ST len into 16-bit mask
65 lsbaddr
, msbaddr
= self
.splitaddr(pi
.addr
.data
)
66 m
.d
.comb
+= lenexp
.len_i
.eq(pi
.data_len
)
67 m
.d
.comb
+= lenexp
.addr_i
.eq(lsbaddr
) # LSBs of addr
68 m
.d
.comb
+= lsui
.x_mask_i
.eq(lenexp
.lexp_o
)
69 # pass through the address, indicate "valid"
70 m
.d
.comb
+= lsui
.x_addr_i
.eq(pi
.addr
.data
) # XXX hmmm...
71 m
.d
.comb
+= lsui
.x_valid_i
.eq(1)
72 # indicate "OK" - XXX should be checking address valid
73 m
.d
.comb
+= pi
.addr_ok_o
.eq(1)
75 with m
.If(pi
.is_ld_i
):
76 # shift/mask out the loaded data
77 m
.d
.comb
+= pi
.ld
.data
.eq((lsui
.m_ld_data_o
& lenexp
.rexp_o
) >>
79 # remember we're in the process of loading
80 m
.d
.sync
+= ld_in_progress
.eq(1)
82 # If a load happened on the previous cycle and the memory is
83 # not busy, that means it returned the data from the load. In
84 # that case ld.ok should be set andwe can clear the
86 with m
.If(ld_in_progress
& ~lsui
.x_busy_o
):
87 m
.d
.comb
+= pi
.ld
.ok
.eq(1)
88 m
.d
.sync
+= ld_in_progress
.eq(0)
90 m
.d
.comb
+= pi
.ld
.ok
.eq(0)
92 with m
.If(pi
.is_st_i
& pi
.st
.ok
):
93 m
.d
.comb
+= lsui
.x_st_data_i
.eq(pi
.st
.data
<< (lenexp
.addr_i
*8))