microwatt.git
4 years agofpga: Add support for Genesys2
Boris Shingarov [Sun, 12 Jul 2020 18:07:21 +0000 (14:07 -0400)]
fpga: Add support for Genesys2

Signed-off-by: Boris Shingarov <shingarov@labware.com>
4 years agoacorn: Add support for the Acorn CLE 215+
Benjamin Herrenschmidt [Tue, 7 Jul 2020 23:37:45 +0000 (09:37 +1000)]
acorn: Add support for the Acorn CLE 215+

This is a NiteFury based PCIe M2 form-factor board originally
used for mining. It contains a speed grade 2 Artix 7 200T,
1GB of DDR3 and 32MB of flash.

The serial port is routed to pin 2 (RX) and 3 (TX) of the P2
connector (pin 1 is GND).

Note: Only 16MB of flash is currently usable until code is added
to configure the flash controller to use 4-bytes address commands
on that part.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agoMerge pull request #229 from ozbenh/litedram
Michael Neuling [Fri, 7 Aug 2020 04:42:31 +0000 (14:42 +1000)]
Merge pull request #229 from ozbenh/litedram

Litedram: Misc improvements and support for different DRAM geometries

4 years agoMerge pull request #233 from paulusmack/master
Michael Neuling [Wed, 22 Jul 2020 09:51:24 +0000 (19:51 +1000)]
Merge pull request #233 from paulusmack/master

Changes to improve timing

4 years agoloadstore1: Better expression for store data formatting
Paul Mackerras [Sat, 18 Jul 2020 06:37:03 +0000 (16:37 +1000)]
loadstore1: Better expression for store data formatting

This rearranges the code used for store data formatting so that the
"for i in 0 to 7" loop indexes the output bytes rather than the
input bytes.  The new expression is formally identical to the old
but is easier to synthesize.  This reduces the number of LUTs by
about 250 on the Artix-7 and improves timing.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agoloadstore1: Further tweaks to improve synthesis with yosys/nextpnr
Paul Mackerras [Wed, 15 Jul 2020 23:26:47 +0000 (09:26 +1000)]
loadstore1: Further tweaks to improve synthesis with yosys/nextpnr

This reworks the way that the busy and done signals are generated in
loadstore in order to work around some problems where yosys/nextpnr
are reporting combinatorial loops (not in fact on the current code but
on minor variations needed for supporting the FPU).  It seems that
yosys has problems with the case statement on v.state.

This also lifts the maddr and byte_sel generation out of the case
statement.  The overall result is a slight reduction in resource usage
(~30 6-input LUTs on the A7-100).

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agodcache: Ease timing on wishbone data and byte selects
Paul Mackerras [Fri, 10 Jul 2020 09:04:37 +0000 (19:04 +1000)]
dcache: Ease timing on wishbone data and byte selects

This eliminates a path where the inputs to r1.wb.dat and r1.wb.sel
depend on req_op, which depends on the TLB and cache hit detection.
In fact they only need to depend on the nature of the request in
r0.req (i.e. DCBZ, store, cacheable load, or non-cacheable load).
This sets them at the beginning of the code for IDLE state rather
than inside the req_op case statement.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agodecode1: Fix formatting
Paul Mackerras [Tue, 14 Jul 2020 23:00:44 +0000 (09:00 +1000)]
decode1: Fix formatting

Commit d5c8c33baecc ("decode1: Reformat to 4-space indentation") resulted
in some rows of major_decode_rom_array being misaligned.  This fixes it.
No code change.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agoloadstore1: Separate address calculation for MMU to ease timing
Paul Mackerras [Mon, 13 Jul 2020 07:43:52 +0000 (17:43 +1000)]
loadstore1: Separate address calculation for MMU to ease timing

This computes the address sent to the MMU separately from that sent
to the dcache.  This means that the address sent to the MMU doesn't
have the delay through the lsu_sum adder, making it available earlier.
The path through the lsu_sum adder and through the MMU to the MMU
done and err outputs showed up as a critical path on some builds.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agoloadstore1: Generate busy signal earlier
Paul Mackerras [Mon, 13 Jul 2020 02:18:53 +0000 (12:18 +1000)]
loadstore1: Generate busy signal earlier

This makes the calculation of busy as simple as possible and dependent
only on register outputs.  The timing of busy is critical, as it gates
the valid signal for the next instruction, and therefore any delays
in dropping busy at the end of a load or store directly impact the
timing of a host of other paths.

This also separates the 'done without error' and 'done with error'
cases from the MMU into separate signals that are both driven directly
from registers.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agodcache: Output separate done-without-error and error-done signals
Paul Mackerras [Sun, 12 Jul 2020 10:05:53 +0000 (20:05 +1000)]
dcache: Output separate done-without-error and error-done signals

This reduces the complexity of the logic in the places where these
signals are used.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agodcache: Ease timing on calculation of acks remaining
Paul Mackerras [Sat, 11 Jul 2020 12:23:31 +0000 (22:23 +1000)]
dcache: Ease timing on calculation of acks remaining

This moves the incrementing or decrementing of r1.acks_pending
to the cycle after a strobe is output or an ack is seen on the
wishbone, and simplifies the logic that determines whether the
cycle is now complete.  This means that the path from seeing
req_op equal to OP_STORE_HIT or OP_STORE_MISS to setting r1.state
and r1.cyc now just involves the stbs_done bit rather than a more
complex calculation involving the possibly incremented r1.acks_pending.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agodcache: Improve timing of valid/done outputs
Paul Mackerras [Sat, 11 Jul 2020 07:46:03 +0000 (17:46 +1000)]
dcache: Improve timing of valid/done outputs

This makes d_out.valid and m_out.done come directly from registers in
order to improve timing.  The inputs to the registers are set by the
same conditions that cause r1.hit_load_valid, r1.slow_valid,
r1.error_done and r1.stcx_fail to be set.

Note that the STORE_WAIT_ACK state doesn't test r1.mmu_req but assumes
that the request came from loadstore1.  This is because we normally
have r1.full = 0 in this state, which means that r1.mmu_req can
change at any time.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agocore: Don't generate logic for log data when LOG_LENGTH = 0
Paul Mackerras [Sat, 11 Jul 2020 05:40:27 +0000 (15:40 +1000)]
core: Don't generate logic for log data when LOG_LENGTH = 0

This adds "if LOG_LENGTH > 0 generate" to the places in the core
where log output data is latched, so that when LOG_LENGTH = 0 we
don't create the logic to collect the data which won't be stored.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agocountzero: Faster algorithm for count leading/trailing zeroes
Paul Mackerras [Sat, 11 Jul 2020 02:05:43 +0000 (12:05 +1000)]
countzero: Faster algorithm for count leading/trailing zeroes

This uses an algorithm for count leading/trailing zeroes that is
faster on FPGAs, which makes timing easier.  cntlz* and cnttz*
still take two cycles, though.

For count trailing zeroes, we compute x & -x, which for non-zero x
has a single 1 bit in the position of the least-significant 1 bit
in x.  This one-hot representation can then be converted to a bit
number with six 32-input OR gates.  For count leading zeroes, we
simply do a bit-reversal on x and then use the same algorithm.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agoMMU: Improve timing of done signal back to loadstore1
Paul Mackerras [Sat, 11 Jul 2020 01:00:53 +0000 (11:00 +1000)]
MMU: Improve timing of done signal back to loadstore1

This makes the l_out.done signal come from a clean latch, which
improves timing.  The cost is that TLB load and invalidation
operations to the dcache now signal done back to loadstore1 one
cycle later than before, but that doesn't seem to affect overall
performance noticeably.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agodcache: Remove dependency of r1.wb.adr/dat/sel on req_op
Paul Mackerras [Fri, 10 Jul 2020 23:10:24 +0000 (09:10 +1000)]
dcache:  Remove dependency of r1.wb.adr/dat/sel on req_op

This improves timing by setting r1.wb.{adr,dat,sel} to the next
request when doing a write cycle on the wishbone before we know
whether the next request has a TLB and cache hit or not, i.e.
without depending on req_op.  r1.wb.stb still depends on req_op.

This contains a workaround for what is probably a bug elsewhere,
in that changing r1.wb.sel unconditionally once we see stall=0
from the wishbone causes incorrect behaviour.  Making it
conditional on there being a valid following request appears
to fix the problem.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agodcache: Update TLB PLRU one cycle later
Paul Mackerras [Fri, 10 Jul 2020 10:32:35 +0000 (20:32 +1000)]
dcache: Update TLB PLRU one cycle later

This puts the inputs to the TLB PLRU through a register stage, so
the TLB PLRU update is done in the cycle after the TLB tag
matching rather than the same cycle.  This improves timing.
The PLRU output is only used when writing the TLB in response to
a tlbwe request from the MMU, and that doesn't happen within one
cycle of a virtual-mode load or store, so the fact that the
tlb victim way information is delayed by one cycle doesn't
create any problems.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agoloadstore1: Eliminate two_dwords variable
Paul Mackerras [Fri, 10 Jul 2020 10:11:15 +0000 (20:11 +1000)]
loadstore1: Eliminate two_dwords variable

The computation of two_dwords from r.second_bytes has shown up as
part of a critical path at times.  Instead we add a 'last_dword'
flag to the reg_stage_t record which tells us more directly
whether a valid flag coming in from dcache means that the
instruction is done, thereby shortening the path to the busy output
back to execute1.

This also simplifies some of the trim_ctl logic.  The two_dwords = 0
case could never have use_second(i) = 1 for any of the bytes being
transferred, so "not use_second(i)" is always 1.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agoexecute1: Ease timing on redirect_nia
Paul Mackerras [Fri, 10 Jul 2020 09:07:47 +0000 (19:07 +1000)]
execute1: Ease timing on redirect_nia

This eliminates a dependency of r.f.redirect_nia on the carry out
from the main adder in the case of a conditional trap instruction.
We can set r.f.redirect_nia unconditionally, even if no interrupt
is generated.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agodcache: Do PLRU update one cycle later
Paul Mackerras [Fri, 10 Jul 2020 07:47:52 +0000 (17:47 +1000)]
dcache: Do PLRU update one cycle later

This does the PLRU update based on r1.cache_hit and r1.hit_way rather
than req_op and req_hit_way, which means there is now a register
between the TLB and cache tag lookup and the PLRU update, which should
help with timing.

The PLRU victim selection now becomes valid one cycle later, in the
cycle where r1.write_tag = 1.  We now have replace_way coming from
the PLRU when r1.write_tag = 1 and from r1.store_way at other times,
and we use that instead of r1.store_way in situations where we need
it to be valid in the first cycle of the RELOAD_WAIT_ACK state.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agoicache: Do PLRU update one cycle later
Paul Mackerras [Fri, 10 Jul 2020 00:04:56 +0000 (10:04 +1000)]
icache: Do PLRU update one cycle later

This does the PLRU update based on r.hit_valid and r.hit_way rather
than req_is_hit and req_hit_way, which means there is now a register
between the TLB and cache tag lookup and the PLRU update, which
should help with timing.

As a result, the PLRU victim way selection becomes valid one cycle
later, in the cycle when r.state = CLR_TAG.  So we have to use the
PLRU output directly in the CLR_TAG state and r.store_way in the
WAIT_ACK state.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agoMerge pull request #232 from gromero/for-anton
Michael Neuling [Tue, 14 Jul 2020 06:08:04 +0000 (16:08 +1000)]
Merge pull request #232 from gromero/for-anton

Enhance hello_world

4 years agoEnhance hello_world
Gustavo Romero [Mon, 13 Jul 2020 19:54:32 +0000 (16:54 -0300)]
Enhance hello_world

This commit enhances hello_world.bin output by printing
a ASCII lightbulb, which turns out to be Microwatt's logo,
instead of simply a "Hello World" text message.

Signed-off-by: Gustavo Romero <gustavo.romero@protonmail.com>
4 years agoMerge pull request #228 from ozbenh/misc
Michael Neuling [Thu, 9 Jul 2020 02:25:50 +0000 (12:25 +1000)]
Merge pull request #228 from ozbenh/misc

Misc nexys video fixes

4 years agoMerge pull request #222 from iamjpn/master
Michael Neuling [Thu, 9 Jul 2020 01:10:45 +0000 (11:10 +1000)]
Merge pull request #222 from iamjpn/master

core: Implement PVR register

4 years agotests: Add tests for the PVR
Jordan Niethe [Wed, 8 Jul 2020 04:34:42 +0000 (14:34 +1000)]
tests: Add tests for the PVR

The PVR is a privileged read-only SPR. Test reading and writing in both
supervisor and problem state. In supervisor state reading returns
microwatt's assigned PVR number and writing is a noop. In problem state
both reading and writing cause privileged instruction interrupts.

Signed-off-by: Jordan Niethe <jniethe5@gmail.com>
4 years agolitedram: Regenerate
Benjamin Herrenschmidt [Wed, 8 Jul 2020 07:34:40 +0000 (17:34 +1000)]
litedram: Regenerate

This regenerate litedram for all targets (genesys2 is new in this
build) using the latest LiteX.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agolitedram: Update generator to work with latest LiteX
Benjamin Herrenschmidt [Wed, 8 Jul 2020 07:30:10 +0000 (17:30 +1000)]
litedram: Update generator to work with latest LiteX

Some changes in LiteX broke us. Adapt the build system and
increase the init RAM size to 24KB.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agolitedram: Add generator for Genesys2
Benjamin Herrenschmidt [Wed, 24 Jun 2020 03:43:29 +0000 (13:43 +1000)]
litedram: Add generator for Genesys2

(Not yet generated)

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agolitedram: l2: Add a few comments about litedram behaviour
Benjamin Herrenschmidt [Fri, 26 Jun 2020 04:52:06 +0000 (14:52 +1000)]
litedram: l2: Add a few comments about litedram behaviour

litedram ignores a couple of signals of his "pseudo-axi" port,
this adds a bit of documentation around it.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agolitedram: l2: Add support for more geometries
Benjamin Herrenschmidt [Wed, 24 Jun 2020 02:02:55 +0000 (12:02 +1000)]
litedram: l2: Add support for more geometries

Make the DRAM data lines and user port width configurable, also
don't hard wire dependency on the wishbone data width.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agolitedram: l2: Latency improvements
Benjamin Herrenschmidt [Mon, 22 Jun 2020 07:27:05 +0000 (17:27 +1000)]
litedram: l2: Latency improvements

This implements in the L2 cache the feature already in the L1s
allowing a request to be completed before the end of a refill
using partial line valid bits, and starting a refill from the
row of the first miss on that line instead of the beginning of
the line.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agocorefile/nexys_video: Parameter fixes
Benjamin Herrenschmidt [Wed, 8 Jul 2020 04:00:27 +0000 (14:00 +1000)]
corefile/nexys_video: Parameter fixes

This fixes up a few issues with parameters:

Only arty has "has_uart1" since we haven't added plumbing for a second UART
anywhere else. Also "uart_is_16550" was mixing on one of the nexys_video
targets, and nexys_video toplevel was missing LOG_LENGTH.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agofpga: nexys-video: Wire up core_alt_reset
Benjamin Herrenschmidt [Fri, 26 Jun 2020 13:34:14 +0000 (23:34 +1000)]
fpga: nexys-video: Wire up core_alt_reset

It looks like we left it dangling

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agonexys_video: Fix nexys-video build
Benjamin Herrenschmidt [Thu, 25 Jun 2020 04:05:03 +0000 (14:05 +1000)]
nexys_video: Fix nexys-video build

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agospi: Send dummy clocks at boot
Benjamin Herrenschmidt [Wed, 8 Jul 2020 06:13:27 +0000 (16:13 +1000)]
spi: Send dummy clocks at boot

When using an FPGA which routes the SPI clock via STARTUPE2 as is
done on the Nexys Video (or optionally on Arty), the HW needs at
least 3 beats of that clock to complete the switch from the internal
config clock to the one we provide.

This works around it by having the SPI controller send 8 dummy
clocks at boot time with CS held high.

Without this, flash identification will fail those boards

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agoMerge pull request #223 from mikey/ecp5
Paul Mackerras [Wed, 8 Jul 2020 00:48:26 +0000 (10:48 +1000)]
Merge pull request #223 from mikey/ecp5

Make ECP5 devices work and add github artifacts

4 years agoCreate github artifacts for ECP5 devices
Michael Neuling [Tue, 7 Jul 2020 11:18:34 +0000 (21:18 +1000)]
Create github artifacts for ECP5 devices

ECP5 eval board (tested and working) and Orange Crap (untested)

Signed-off-by: Michael Neuling <mikey@neuling.org>
4 years agoAdd PLL for ECP5 device
Michael Neuling [Tue, 7 Jul 2020 11:15:34 +0000 (21:15 +1000)]
Add PLL for ECP5 device

Means we can synthesize at 40Mhz (where we currently make timing) and
our UART still works at 115200 baud.

Tested working hello world unmodified with ECP5 eval board. Orange
Crab is updated but is untested.

Signed-off-by: Michael Neuling <mikey@neuling.org>
4 years agoMerge pull request #220 from mikey/ghdl-makefile
Anton Blanchard [Tue, 7 Jul 2020 10:54:06 +0000 (20:54 +1000)]
Merge pull request #220 from mikey/ghdl-makefile

Use $(GHDL) rather than ghdl in Makefile

4 years agoMerge pull request #209 from mikey/yosys
Anton Blanchard [Tue, 7 Jul 2020 10:44:02 +0000 (20:44 +1000)]
Merge pull request #209 from mikey/yosys

Make yosys/nextpnr work and add to CI

4 years agocore: Implement PVR register
Jordan Niethe [Tue, 7 Jul 2020 10:37:52 +0000 (20:37 +1000)]
core: Implement PVR register

Microwatt has been allocated a PVR version of 0x0063. Implement a PVR
with this value.

Signed-off-by: Jordan Niethe <jniethe5@gmail.com>
4 years agoUse $(GHDL) rather than ghdl in Makefile
Michael Neuling [Sat, 4 Jul 2020 01:12:05 +0000 (11:12 +1000)]
Use $(GHDL) rather than ghdl in Makefile

Suggestion from @eine in PR #219.

Signed-off-by: Michael Neuling <mikey@neuling.org>
4 years agoAdd yosys/nextpnr ecp5 and verilog build to CI
Michael Neuling [Mon, 22 Jun 2020 03:10:13 +0000 (13:10 +1000)]
Add yosys/nextpnr ecp5 and verilog build to CI

This works now, so let's make sure it continues to.

Signed-off-by: Michael Neuling <mikey@neuling.org>
4 years agoAdd FPGA_TARGET=ECP5-EVN make option for synthesis build
Michael Neuling [Tue, 23 Jun 2020 07:05:23 +0000 (17:05 +1000)]
Add FPGA_TARGET=ECP5-EVN make option for synthesis build

This allows these targets
  FPGA_TARGET=ORANGE-CRAB make microwatt.bit
  FPGA_TARGET=ECP5-EVN make microwatt.bit
Default is ORANGE-CRAB as before

ECP5-EVN is tested on real hardware. The console only works at 38400 so
needs this in console.c and a recompile of hello_world to work:

  -#define UART_FREQ 115200
  +#define UART_FREQ 38400

With this 'FPGA_TARGET=ECP5-EVN make prog' works on the ECP5 dev board.

Signed-off-by: Michael Neuling <mikey@neuling.org>
4 years agoAdd SYNTH_ECP5_FLAGS option for building
Michael Neuling [Thu, 2 Jul 2020 04:36:14 +0000 (14:36 +1000)]
Add SYNTH_ECP5_FLAGS option for building

This is useful to specify "-noflatten" which helps CI stay under 8GB
limit.

Normally the AUTONAME stage of yosys will take around 10GB if
operating on the whole design. With -noflatten, AUTONAME occurs only
per VHDL entity, so only consumes around 3GB of memory. This gets us
under the limitations on github actions.

More discussion here:
  https://github.com/antonblanchard/microwatt/pull/209#issuecomment-652186078

Signed-off-by: Michael Neuling <mikey@neuling.org>
4 years agoAdd ram file to synthesis build dependencies
Michael Neuling [Thu, 2 Jul 2020 05:55:30 +0000 (15:55 +1000)]
Add ram file to synthesis build dependencies

Signed-off-by: Michael Neuling <mikey@neuling.org>
4 years agoAdd uart16550 files to yosys/nextpnr build
Michael Neuling [Thu, 2 Jul 2020 04:34:43 +0000 (14:34 +1000)]
Add uart16550 files to yosys/nextpnr build

These are verilog so need passed to yosys differently than the VHDL
files.

Signed-off-by: Michael Neuling <mikey@neuling.org>
4 years agoAdd uart16550 files from fusesoc
Michael Neuling [Thu, 2 Jul 2020 04:11:16 +0000 (14:11 +1000)]
Add uart16550 files from fusesoc

These are needed for synthesis that doesn't use fusesoc natively.

These were pulled in via 'fusesoc fetch ::uart16550:1.5.5-r1'

Signed-off-by: Michael Neuling <mikey@neuling.org>
4 years agoBuild to tmp file so nextpnr errors don't confuse make
Michael Neuling [Mon, 22 Jun 2020 03:09:09 +0000 (13:09 +1000)]
Build to tmp file so nextpnr errors don't confuse make

nextpnr will leave an output file around even when it errors out, so
build to a tmp file and move it when we succeed so we don't confuse
make.

Signed-off-by: Michael Neuling <mikey@neuling.org>
4 years agoFix building with yosys/nextpnr
Michael Neuling [Mon, 22 Jun 2020 03:09:09 +0000 (13:09 +1000)]
Fix building with yosys/nextpnr

Add --no-formal so that asserts are removed by yosys as nextpnr
doesn't like them.

This was suggested by @tgingold here:
  https://github.com/YosysHQ/yosys/issues/2068#issuecomment-644545863

Signed-off-by: Michael Neuling <mikey@neuling.org>
4 years agoAdd yosys builds files to gitignore
Michael Neuling [Mon, 22 Jun 2020 03:11:03 +0000 (13:11 +1000)]
Add yosys builds files to gitignore

Signed-off-by: Michael Neuling <mikey@neuling.org>
4 years agoSend line feed if we get a carriage return in hello world.
Michael Neuling [Tue, 23 Jun 2020 07:07:12 +0000 (17:07 +1000)]
Send line feed if we get a carriage return in hello world.

Signed-off-by: Michael Neuling <mikey@neuling.org>
4 years agoMerge pull request #216 from paulusmack/cfar
Michael Neuling [Tue, 30 Jun 2020 05:47:36 +0000 (15:47 +1000)]
Merge pull request #216 from paulusmack/cfar

Timing and speed improvements, implement CFAR register

4 years agoMerge pull request #206 from Jbalkind/icachecleanup
Paul Mackerras [Tue, 30 Jun 2020 05:01:06 +0000 (15:01 +1000)]
Merge pull request #206 from Jbalkind/icachecleanup

Icache constants cleanup

4 years agoexecute1: Do forwarding of the CR result to the next instruction
Paul Mackerras [Fri, 19 Jun 2020 10:00:16 +0000 (20:00 +1000)]
execute1: Do forwarding of the CR result to the next instruction

This adds a path to allow the CR result of one instruction to be
forwarded to the next instruction, so that sequences such as
cmp; bc can avoid having a 1-cycle bubble.

Forwarding is not available for dot-form (Rc=1) instructions,
since the CR result for them is calculated in writeback.  The
decode.output_cr field is used to identify those instructions
that compute the CR result in execute1.

For some reason, the multiply instructions incorrectly had
output_cr = 1 in the decode tables.  This fixes that.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agoexecute1: Add latch to redirect path
Paul Mackerras [Fri, 19 Jun 2020 08:00:37 +0000 (18:00 +1000)]
execute1: Add latch to redirect path

This latches the redirect signal inside execute1, so that it is sent
a cycle later to fetch1 (and to decode/icache as flush).  This breaks
a long combinatorial chain from the branch and interrupt detection
in execute1 through the redirect/flush signals all the way back to
fetch1, icache and decode.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agological: Only do output inversion for OP_AND, OP_OR and OP_XOR
Paul Mackerras [Fri, 19 Jun 2020 07:13:06 +0000 (17:13 +1000)]
logical: Only do output inversion for OP_AND, OP_OR and OP_XOR

It's not needed for the other ops (popcnt, parity, etc.) and the
logical unit shows up as a critical path from time to time.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agocore: Implement CFAR register
Paul Mackerras [Mon, 15 Jun 2020 07:45:55 +0000 (17:45 +1000)]
core: Implement CFAR register

This implements the CFAR SPR as a slow SPR stored in 'ctrl'.  Taken
branches and rfid update it to the address of the branch or rfid
instruction.

To simplify the logic, this makes rfid use the branch logic to
generate its redirect (requiring SRR0 to come in to execute1 on
the B input and SRR1 on the A input), and the masking of the bottom
2 bits of NIA is moved to fetch1.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agoMerge pull request #213 from ozbenh/uart16550
Michael Neuling [Mon, 29 Jun 2020 02:19:06 +0000 (12:19 +1000)]
Merge pull request #213 from ozbenh/uart16550

Add support for standard 16550 style UART

4 years agoMerge pull request #212 from ozbenh/liteeth
Michael Neuling [Mon, 29 Jun 2020 02:18:44 +0000 (12:18 +1000)]
Merge pull request #212 from ozbenh/liteeth

liteeth: Hook up LiteX LiteEth ethernet controller

4 years agoMerge pull request #214 from shingarov/fix-ld-target
Michael Neuling [Mon, 29 Jun 2020 00:24:49 +0000 (10:24 +1000)]
Merge pull request #214 from shingarov/fix-ld-target

Fix ld error in elf maketarget

4 years agoFix ld error in elf maketarget
Boris Shingarov [Thu, 25 Jun 2020 09:31:45 +0000 (05:31 -0400)]
Fix ld error in elf maketarget

The sdram_init ELF fails to link:

powerpc64le-linux-gnu-ld -static -nostdlib -T sdram_init.lds \
    --gc-sections -o sdram_init.elf head.o main.o sdram.o console.o \
    libc.o sdram_init.lds
powerpc64le-linux-gnu-ld: error: linker script file 'sdram_init.lds'
    appears multiple times
make: *** [Makefile:70: sdram_init.elf] Error 1

This is because sdram_init.lds is one of the prerequisites, and thus is
contained in $^.  However, it is also explicitly specified as part of
LDFLAGS, as the argument to -T.

Signed-off-by: Boris Shingarov <shingarov@labware.com>
4 years agotests: Add updated micropython build with 16550 support
Benjamin Herrenschmidt [Fri, 19 Jun 2020 11:18:33 +0000 (21:18 +1000)]
tests: Add updated micropython build with 16550 support

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agosim_console: Fix polling to check for POLLIN
Benjamin Herrenschmidt [Fri, 19 Jun 2020 10:27:31 +0000 (20:27 +1000)]
sim_console: Fix polling to check for POLLIN

Under some circumstances we get POLLHUP which we incorrectly
treat as having a character in the buffer.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agouart: Make 16550 the default
Benjamin Herrenschmidt [Thu, 18 Jun 2020 07:14:55 +0000 (17:14 +1000)]
uart: Make 16550 the default

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agosyscon: Add flag to indicate the timebase frequency
Benjamin Herrenschmidt [Tue, 23 Jun 2020 05:44:37 +0000 (15:44 +1000)]
syscon: Add flag to indicate the timebase frequency

This adds a flag (currently not set) to indicate that the core is using
the architected timebase frequency of 512Mhz. When not set, the core is
using the proc frequency for the timebase.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agoconsole: Add support for the 16550 UART
Benjamin Herrenschmidt [Thu, 18 Jun 2020 07:14:41 +0000 (17:14 +1000)]
console: Add support for the 16550 UART

And rebuild various binaries

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agouart: Add a simulation model for the 16550 compatible UART
Benjamin Herrenschmidt [Thu, 18 Jun 2020 04:00:28 +0000 (14:00 +1000)]
uart: Add a simulation model for the 16550 compatible UART

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agouart: Rename sim_uart.vhdl to sim_pp_uart.vhdl
Benjamin Herrenschmidt [Thu, 18 Jun 2020 01:18:30 +0000 (11:18 +1000)]
uart: Rename sim_uart.vhdl to sim_pp_uart.vhdl

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agoconsole: Cleanup console API
Benjamin Herrenschmidt [Thu, 18 Jun 2020 01:06:33 +0000 (11:06 +1000)]
console: Cleanup console API

Use a more generic console_init() instead of potato_uart_init(),
and do the same for interrupt control. There should be no
change in behaviour.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agouart: Import and hook up opencore 16550 compatible UART
Benjamin Herrenschmidt [Tue, 16 Jun 2020 12:42:15 +0000 (22:42 +1000)]
uart: Import and hook up opencore 16550 compatible UART

This imports via fusesoc a 16550 compatible (ie "standard") UART,
and wires it up optionally in the SoC instead of the potato one.

This also adds support for a second UART (which is always a
16550) to Arty, wired to JC "bottom" port.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agoex1: Add SPR_TBU support
Benjamin Herrenschmidt [Thu, 18 Jun 2020 09:41:00 +0000 (19:41 +1000)]
ex1: Add SPR_TBU support

It's used by the boot wrapper in Linux and possibly some userspace
programs.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agoliteeth: Hook up LiteX LiteEth ethernet controller
Benjamin Herrenschmidt [Sat, 13 Jun 2020 00:04:31 +0000 (10:04 +1000)]
liteeth: Hook up LiteX LiteEth ethernet controller

Currently only generated for Arty.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agoMerge pull request #211 from shenki/spi-constraint
Michael Neuling [Tue, 23 Jun 2020 06:58:06 +0000 (16:58 +1000)]
Merge pull request #211 from shenki/spi-constraint

spi: Fix dat_i_l constraints

4 years agospi: Fix dat_i_l constraints
Joel Stanley [Mon, 22 Jun 2020 09:03:14 +0000 (18:33 +0930)]
spi: Fix dat_i_l constraints

No cells matched 'get_cells -hierarchical -filter {NAME =~*/spi_rxtx/dat_i_l*}'. [build/microwatt_0/src/microwatt_0/fpga/arty_a7.xdc:42]

The signal is in it's own process so the net name ends up being
spi_rxtx/input_delay_1.dat_i_l_reg.

After this change the log shows:

Applied set_property IOB = TRUE for soc0/\spiflash_gen.spiflash /spi_rxtx/\input_delay_1.dat_i_l_reg . (constraint file  fpga/arty_a7.xdc, line 42).
Applied set_property IOB = TRUE for soc0/\spiflash_gen.spiflash /spi_rxtx/\input_delay_1.dat_i_l_reg . (constraint file  fpga/arty_a7.xdc, line 42).
Applied set_property IOB = TRUE for soc0/\spiflash_gen.spiflash /spi_rxtx/\input_delay_1.dat_i_l_reg . (constraint file  fpga/arty_a7.xdc, line 42).
Applied set_property IOB = TRUE for soc0/\spiflash_gen.spiflash /spi_rxtx/\input_delay_1.dat_i_l_reg . (constraint file  fpga/arty_a7.xdc, line 42).

Signed-off-by: Joel Stanley <joel@jms.id.au>
4 years agoMerge pull request #210 from ozbenh/xics
Michael Neuling [Tue, 23 Jun 2020 04:32:42 +0000 (14:32 +1000)]
Merge pull request #210 from ozbenh/xics

xics: Cleanups and add a simple ICS for use by Linux

4 years agoxics: Add support for reduced priority field size
Benjamin Herrenschmidt [Mon, 22 Jun 2020 13:38:34 +0000 (23:38 +1000)]
xics: Add support for reduced priority field size

This makes the ICS support less than the 8 architected bits
and sets the soc to use 3 bits by default.

All the supported bits set translates to "masked" (and will read
back at 0xff), any small value is used as-is.

Linux doesn't use priorities above 5, so this is a way to save
silicon. The number of supported priority bits is exposed to the
OS via the config register.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agoxics: Add simple ICS
Benjamin Herrenschmidt [Wed, 17 Jun 2020 12:11:58 +0000 (22:11 +1000)]
xics: Add simple ICS

Move the external interrupt generation to a separate module
"ICS" (source controller) which a register per source containing
currently only the priority control.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agoxics/icp: MFRR starts at 0xff not 0x00
Benjamin Herrenschmidt [Wed, 17 Jun 2020 12:07:33 +0000 (22:07 +1000)]
xics/icp: MFRR starts at 0xff not 0x00

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agotests/xics: Ensure no compiler optimisations in delay()
Benjamin Herrenschmidt [Wed, 17 Jun 2020 12:06:28 +0000 (22:06 +1000)]
tests/xics: Ensure no compiler optimisations in delay()

In case it would be tempted to "read ahead" the delay function

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agoxics: ICP should be big endian !
Benjamin Herrenschmidt [Wed, 17 Jun 2020 11:51:16 +0000 (21:51 +1000)]
xics: ICP should be big endian !

That's how Linux expects it. This also simplifies the
register access implementation since the bit fields now
align properly regardless of the access size.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agotests: Fix Makefile.test to not allow host includes
Benjamin Herrenschmidt [Wed, 17 Jun 2020 04:00:04 +0000 (14:00 +1000)]
tests: Fix Makefile.test to not allow host includes

xics was including the host limits.h for example

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agoMerge pull request #208 from paulusmack/faster
Michael Neuling [Fri, 19 Jun 2020 01:50:47 +0000 (11:50 +1000)]
Merge pull request #208 from paulusmack/faster

Make the core go faster

Several major improvements in here:
- Simple branch predictor
- Reduced latency for mispredicted branches and interrupts by removing fetch2 stage
- Cache improvements
  o Request critical dword first on refill
  o Handle hits while refilling, including on line being refilled
  o Sizes doubled for both D and I
- Loadstore improvements: can now do one load or store every two cycles in most cases
- Optimized 2-cycle multiplier for Xilinx 7-series parts using DSP slices
- Timing improvements, including:
  o Stash buffer in decode1
  o Reduced width of execute1 result mux
  o Improved SPR decode in decode1
  o Some non-critical operation take a cycle longer so we can break some long combinatorial chains
- Core logging: logs 256 bits of info every cycle into a ring buffer, to help with debugging and performance analysis

This increases the LUT usage for the "synth" + A35 target from 9182 to 10297 = 12%.

4 years agoMerge pull request #207 from ozbenh/misc
Paul Mackerras [Wed, 17 Jun 2020 21:26:01 +0000 (07:26 +1000)]
Merge pull request #207 from ozbenh/misc

Random cleanups of the SoC interfaces

4 years agofpga: Add a xilinx_specific fileset to microwatt.core
Paul Mackerras [Tue, 16 Jun 2020 06:59:54 +0000 (16:59 +1000)]
fpga: Add a xilinx_specific fileset to microwatt.core

At present this just has the Xilinx-specific multiplier code, but
might in future have other things.

This also adds the xilinx_specific fileset to the synth target.
Without that it was failing because there was no multiplier.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agoMake LOG_LENGTH configurable per FPGA variant
Paul Mackerras [Tue, 16 Jun 2020 01:37:25 +0000 (11:37 +1000)]
Make LOG_LENGTH configurable per FPGA variant

This plumbs the LOG_LENGTH parameter (which controls how many entries
the core log RAM has) up to the top level so that it can be set on
the fusesoc command line and have different default values on
different FPGAs.

It now defaults to 512 entries generally and on the Artix-7 35 parts,
and 2048 on the larger Artix-7 FPGAs.  It can be set to 0 if desired.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agoexecute1: Reduce width of the result mux to help timing
Paul Mackerras [Mon, 15 Jun 2020 06:59:08 +0000 (16:59 +1000)]
execute1: Reduce width of the result mux to help timing

This reduces the number of different things that are assigned to
the result variable.

- The computations for the popcnt, prty, cmpb and exts instruction
  families are moved into the logical unit.
- The result of mfspr from the slow SPRs is computed in 'spr_val'
  before being assigned to 'result'.
- Writes to LR as a result of a blr or bclr instruction are done
  through the exc_write path to writeback.

This eases timing considerably.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agocore: Implement a simple branch predictor
Paul Mackerras [Mon, 15 Jun 2020 05:43:05 +0000 (15:43 +1000)]
core: Implement a simple branch predictor

This implements a simple branch predictor in the decode1 stage.  If it
sees that the instruction is b or bc and the branch is predicted to be
taken, it sends a flush and redirect upstream (to icache and fetch1)
to redirect fetching to the branch target.  The prediction is sent
downstream with the branch instruction, and execute1 now only sends
a flush/redirect upstream if the prediction was wrong.  Unconditional
branches are always predicted to be taken, and conditional branches
are predicted to be taken if and only if the offset is negative.
Branches that take the branch address from a register (bclr, bcctr)
are predicted not taken, as we don't have any way to predict the
branch address.

Since we can now have a mflr being executed immediately after a bl
or bcl, we now track the update to LR in the hazard tracker, using
the second write register field that is used to track RA updates for
update-form loads and stores.

For those branches that update LR but don't write any other result
(i.e. that don't decrementer CTR), we now write back LR in the same
cycle as the instruction rather than taking a second cycle for the
LR writeback.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agodecode1: Improve timing for slow SPR decode path
Paul Mackerras [Mon, 15 Jun 2020 00:02:14 +0000 (10:02 +1000)]
decode1: Improve timing for slow SPR decode path

This makes the logic that works out decode.unit and decode.sgl_pipe
for mtspr/mfspr to/from slow SPRs detect the fact that the
instruction is mtspr/mfspr based on a match with the instruction
word rather than looking at v.decode.insn_type.  This improves timing
substantially, as the ROM lookup to get v.decode is relatively slow.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agodecode1: Add a stash buffer to the output
Paul Mackerras [Sun, 14 Jun 2020 23:28:03 +0000 (09:28 +1000)]
decode1: Add a stash buffer to the output

This means that the busy signal from execute1 (which can be driven
combinatorially from mmu or dcache) now stops at decode1 and doesn't
go on to icache or fetch1.  This helps with timing.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agosoc: Slight cleanup of IRQ assignments
Benjamin Herrenschmidt [Sat, 13 Jun 2020 12:29:54 +0000 (22:29 +1000)]
soc: Slight cleanup of IRQ assignments

Use a separate process to assign selected interrupts to the
interrupt array, and document them.

There's only one interrupt *for now* but that will change
and this way is clearer.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agosoc: Rename uart_dat8 to uart0_dat8
Benjamin Herrenschmidt [Sat, 13 Jun 2020 12:05:39 +0000 (22:05 +1000)]
soc: Rename uart_dat8 to uart0_dat8

Just for consistency. Will come in handy if we ever add a second one

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agosoc: Rename wb_dram_ctrl to wb_ext_io and rework decoding
Benjamin Herrenschmidt [Sat, 13 Jun 2020 12:04:45 +0000 (22:04 +1000)]
soc: Rename wb_dram_ctrl to wb_ext_io and rework decoding

This makes the control bus currently going out of "soc" towards
litedram more generic for external IO devices added by the
top-level rather than inside the SoC proper.

This is mostly renaming of signals and a small change on how the
address decoder operates, using a separate "cascaded" decode for
the external IOs.

We make the region 0xc8nn_nnnn be the "external IO" region for
now.

This will make it easier / cleaner to add more external devices.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agoMinor refactor of icache to make less dependent on wishbone
Jonathan Balkind [Sat, 13 Jun 2020 22:39:18 +0000 (18:39 -0400)]
Minor refactor of icache to make less dependent on wishbone

Signed-off-by: Jonathan Balkind <jbalkind@princeton.edu>
4 years agodcache: Reduce back-to-back store latency from 3 cycles to 2
Paul Mackerras [Sat, 13 Jun 2020 13:00:13 +0000 (23:00 +1000)]
dcache: Reduce back-to-back store latency from 3 cycles to 2

This uses the machinery we already had for comparing the real address
of a new request with the tag of a previous request (r1.reload_tag)
to get better timing on comparing the address of a second store with
the one in progress.  The comparison is now on the set size rather
than the page size, but since set size can't be larger than the page
size (and usually will equal the page size), that is OK.

The same comparison can also be used to tell when we can satisfy
a load miss during a cache line refill.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agosoc: Don't require dram wishbones signals to be wired by toplevel
Benjamin Herrenschmidt [Sat, 13 Jun 2020 12:19:33 +0000 (22:19 +1000)]
soc: Don't require dram wishbones signals to be wired by toplevel

Currently, when not using litedram, the top level still has to hook
up "dummy" wishbones to the main dram and control dram busses coming
out of the SoC and provide ack signals.

Instead, make the SoC generate the acks internally when not using
litedram and use defaults to make the wiring entirely optional.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agosoc: Add defaults for some input signals
Benjamin Herrenschmidt [Sat, 13 Jun 2020 11:57:01 +0000 (21:57 +1000)]
soc: Add defaults for some input signals

That way the top-level's don't need to assign them

Also remove generics that are set to the default anyways

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agosoc: Remove unused RESET_LOW generic
Benjamin Herrenschmidt [Sat, 13 Jun 2020 11:51:31 +0000 (21:51 +1000)]
soc: Remove unused RESET_LOW generic

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>