microwatt.git
4 years agoMerge branch 'master' into litedram
Anton Blanchard [Tue, 19 May 2020 02:28:02 +0000 (12:28 +1000)]
Merge branch 'master' into litedram

4 years agoMerge pull request #176 from antonblanchard/console-improv
Anton Blanchard [Tue, 19 May 2020 01:53:34 +0000 (11:53 +1000)]
Merge pull request #176 from antonblanchard/console-improv

Console improvements from Ben

4 years agoMerge pull request #175 from antonblanchard/yosys-fixes-2
Anton Blanchard [Tue, 19 May 2020 01:38:16 +0000 (11:38 +1000)]
Merge pull request #175 from antonblanchard/yosys-fixes-2

Fix yosys build after MMU merge

4 years agoFix yosys build after MMU merge
Anton Blanchard [Tue, 19 May 2020 01:22:29 +0000 (11:22 +1000)]
Fix yosys build after MMU merge

Signed-off-by: Anton Blanchard <anton@linux.ibm.com>
4 years agoMerge pull request #174 from antonblanchard/yosys-fixes
Anton Blanchard [Tue, 19 May 2020 00:44:04 +0000 (10:44 +1000)]
Merge pull request #174 from antonblanchard/yosys-fixes

Some yosys fixes

4 years agoSome yosys fixes
Anton Blanchard [Mon, 18 May 2020 00:15:03 +0000 (10:15 +1000)]
Some yosys fixes

This gets the yosys build further along, but I'm now chasing what looks
like a yosys bug.

Signed-off-by: Anton Blanchard <anton@linux.ibm.com>
4 years agoMerge pull request #169 from paulusmack/mmu
Anton Blanchard [Mon, 18 May 2020 23:34:41 +0000 (09:34 +1000)]
Merge pull request #169 from paulusmack/mmu

Add radix MMU with dTLB and iTLB

4 years agolitedram: Regenerate
Benjamin Herrenschmidt [Fri, 15 May 2020 03:31:11 +0000 (13:31 +1000)]
litedram: Regenerate

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agosoc/core: Add reset latches
Benjamin Herrenschmidt [Fri, 15 May 2020 03:30:01 +0000 (13:30 +1000)]
soc/core: Add reset latches

This adds one-cycle latches to the various resets out of the soc and
into the various core modules. It *seems* to help vivado P&R a bit
and has shown to avoid timing violations under some circumstances.

Interestingly those resets never seem to appear in the bad timing
path. It looks like those long resets simply impose placement
constraints that Vivado satisfies at the expense of timing elsewhere.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agoarty/nexys: Rework reset with litedram
Benjamin Herrenschmidt [Fri, 15 May 2020 03:20:27 +0000 (13:20 +1000)]
arty/nexys: Rework reset with litedram

When using litedram, request a much longer PLL reset. This seems to
help get rid of all the grabled output after config.

Also use the clean system_rst out of litedram as our source of reset
for the rest of the SoC (it is synchronized with system_clk and takes
pll_locked into account already)

4 years agosoc_reset: Use counters, add synchronizers
Benjamin Herrenschmidt [Fri, 15 May 2020 03:15:48 +0000 (13:15 +1000)]
soc_reset: Use counters, add synchronizers

In some cases we need to keep the reset held for much longer,
so use counters rather than shift registers.

Additionally, some signals such as ext_rst and pll_locked
or signals going from the ext_clk domain to the pll_clk
domain need to be treated as async, and testing them without
synchronizers is asking for trouble.

Finally, make the external reset also reset the PLL.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agolitedram: Forward system reset signal
Benjamin Herrenschmidt [Fri, 15 May 2020 03:11:58 +0000 (13:11 +1000)]
litedram: Forward system reset signal

The wrapper wouldn't forward it. Make it do so

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agolitedram: Remove init delays
Benjamin Herrenschmidt [Fri, 15 May 2020 00:14:53 +0000 (10:14 +1000)]
litedram: Remove init delays

The clocks / resets are now stable

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agolitedram: Update to new LiteX/LiteDRAM version
Benjamin Herrenschmidt [Tue, 12 May 2020 10:27:15 +0000 (20:27 +1000)]
litedram: Update to new LiteX/LiteDRAM version

Things have changed a bit in upstream LiteX. LiteDRAM now exposes a
wishbone for the CSRs for example.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agodcache: Fix bug in store hit after dcbz case
Paul Mackerras [Fri, 15 May 2020 12:01:02 +0000 (22:01 +1000)]
dcache: Fix bug in store hit after dcbz case

This fixes a bug where a store that hits in the dcache immediately
following a dcbz has its write to the cache RAM suppressed (but not
its write to memory).  If a load to the same location comes along
before the cache line gets replaced, the load will return incorrect
data.

Fixes: 4db1676ef8b3 ("dcache: Don't assert on dcbz cache hit")
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agopp_soc_uart: Fix rx synchronizers and ensure stable tx init state
Benjamin Herrenschmidt [Thu, 14 May 2020 04:26:14 +0000 (14:26 +1000)]
pp_soc_uart: Fix rx synchronizers and ensure stable tx init state

The rx synchronizers were ... non existent. Someone forgot to add
a if rising_edge(clk) to the process.

For tx, ensure that we have a default value so that TX stays high
from TPGA configuration to the reset being sampled on the first clock
cycle.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agopp_fifo: Fix full fifo losing all data on simultaneous push & pop
Benjamin Herrenschmidt [Thu, 14 May 2020 02:30:11 +0000 (12:30 +1000)]
pp_fifo: Fix full fifo losing all data on simultaneous push & pop

The pp_fifo decides whether top = bottom means empty or full based
on whether the previous operation was a push or a pop.

If the fifo performs both in one cycle, it sets the previous op to
pop. That means that a full fifo being added a character and removed
one at the same time becomes empty.

Instead, just leave the previous op alone. If the fifo was empty, it
remains so, if it was full ditto.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agoMakefile: Improve clean a bit
Benjamin Herrenschmidt [Thu, 14 May 2020 00:12:44 +0000 (10:12 +1000)]
Makefile: Improve clean a bit

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agoconsole: Remove putstr()
Benjamin Herrenschmidt [Thu, 14 May 2020 02:03:39 +0000 (12:03 +1000)]
console: Remove putstr()

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agoconsole: Move console files
Benjamin Herrenschmidt [Thu, 14 May 2020 00:08:06 +0000 (10:08 +1000)]
console: Move console files

console.c goes to a new lib/ where we'll store other general utilities
and console.h goes to include/

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agoconsole: Replace putstr with puts
Benjamin Herrenschmidt [Thu, 14 May 2020 02:03:01 +0000 (12:03 +1000)]
console: Replace putstr with puts

It makes things a bit more standard and a bit nicer to read
without all those strlen(). Also console.c takes care of adding
the carriage returns before the linefeeds.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agoconsole: Improve putchar(), add puts()
Benjamin Herrenschmidt [Thu, 14 May 2020 00:09:36 +0000 (10:09 +1000)]
console: Improve putchar(), add puts()

Make putchar() match a standard prototype and add puts()

Also make puts() add carriage returns before linefeeds so the
users don't have to do it all over the place.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agosoc: Work around compile error with ghdl 0.37-dev
Paul Mackerras [Thu, 14 May 2020 05:43:33 +0000 (15:43 +1000)]
soc: Work around compile error with ghdl 0.37-dev

The ghdl packaged in Fedora 31 doesn't like a port map of the form
"rst => rst or core_reset", so this works around the problem by
doing the OR in a separate statement.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agoMerge branch 'mmu'
Paul Mackerras [Thu, 14 May 2020 05:41:51 +0000 (15:41 +1000)]
Merge branch 'mmu'

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agoMerge pull request #170 from antonblanchard/litedram
Anton Blanchard [Thu, 14 May 2020 05:08:33 +0000 (15:08 +1000)]
Merge pull request #170 from antonblanchard/litedram

LiteDRAM integration

4 years agolitedram: Use 32-bit CSR bus
Benjamin Herrenschmidt [Sat, 9 May 2020 01:20:59 +0000 (11:20 +1000)]
litedram: Use 32-bit CSR bus

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agolitedram: Add support for Microwatt-initialized controller
Benjamin Herrenschmidt [Fri, 8 May 2020 15:09:26 +0000 (01:09 +1000)]
litedram: Add support for Microwatt-initialized controller

This adds support for initializing the memory controller from microwatt
rather than using a built-in RiscV processor. This might require some
fixes to LiteX and LiteDRAM (they haven't been merged as of this commit
yet).

This is enabled in the shipped generated files and can be changed via
modifying the generator script to pass False to "mw_init"

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agohello_world: Use new headers and frequency from syscon
Benjamin Herrenschmidt [Fri, 8 May 2020 00:42:01 +0000 (10:42 +1000)]
hello_world: Use new headers and frequency from syscon

This uses the new header files for register definitions and
extracts the core frequency from syscon rather than hard coding it.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agolitedram: Improve sdram init boot messages
Benjamin Herrenschmidt [Tue, 24 Sep 2019 06:19:29 +0000 (16:19 +1000)]
litedram: Improve sdram init boot messages

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agoAdd microwatt_soc.h and io.h include file
Benjamin Herrenschmidt [Fri, 8 May 2020 00:27:33 +0000 (10:27 +1000)]
Add microwatt_soc.h and io.h include file

This contains C definitions for various Microwatt internal MMIOs
and a set of accessors.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agosyscon: Add syscon registers
Benjamin Herrenschmidt [Tue, 24 Sep 2019 12:24:31 +0000 (22:24 +1000)]
syscon: Add syscon registers

These provides some info about the SoC (though it's still somewhat
incomplete and needs more work, see comments).

There's also a control register for selecting DRAM vs. BRAM at 0
(and for soft-resetting the SoC but that isn't wired up yet).

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agofpga: Hookup nexys-video to litedram
Benjamin Herrenschmidt [Wed, 11 Sep 2019 09:59:13 +0000 (10:59 +0100)]
fpga: Hookup nexys-video to litedram

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agofpga: Hookup Arty to litedram
Benjamin Herrenschmidt [Tue, 10 Sep 2019 17:24:06 +0000 (18:24 +0100)]
fpga: Hookup Arty to litedram

The old toplevel.vhdl becomes top-generic.vhdl, which is to be used
by platforms that do not have a litedram option.

Arty has its own top-arty.vhdl which supports litedram and is now
hooked up

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agoMMU: Implement reading of the process table
Paul Mackerras [Fri, 24 Apr 2020 00:58:56 +0000 (10:58 +1000)]
MMU: Implement reading of the process table

This adds the PID register and repurposes SPR 720 as the PRTBL
register, which points to the base of the process table.  There
doesn't seem to be any point to implementing the partition table given
that we don't have hypervisor mode.

The MMU caches entry 0 of the process table internally (in pgtbl3)
plus the entry indexed by the value in the PID register (pgtbl0).
Both caches are invalidated by a tlbie[l] with RIC=2 or by a move to
PRTBL.  The pgtbl0 cache is invalidated by a move to PID.  The dTLB
and iTLB are cleared by a move to either PRTBL or PID.

Which of the two page table root pointers is used (pgtbl0 or pgtbl3)
depends on the MSB of the address being translated.  Since the segment
checking ensures that address(63) = address(62), this is sufficient to
map quadrants 0 and 3.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agotests/mmu: Add a test of PTE refetching on permission error
Paul Mackerras [Thu, 7 May 2020 10:12:46 +0000 (20:12 +1000)]
tests/mmu: Add a test of PTE refetching on permission error

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agotests/mmu: Add a test for dcbz with translation on
Paul Mackerras [Sun, 3 May 2020 22:57:05 +0000 (08:57 +1000)]
tests/mmu: Add a test for dcbz with translation on

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agoImplement slbia as a dTLB/iTLB flush
Paul Mackerras [Thu, 7 May 2020 10:02:21 +0000 (20:02 +1000)]
Implement slbia as a dTLB/iTLB flush

Slbia (with IH=7) is used in the Linux kernel to flush the ERATs
(our iTLB/dTLB), so make it do that.

This moves the logic to work out whether to flush a single entry
or the whole TLB from dcache and icache into mmu.  We now invalidate
all dTLB and iTLB entries when the AP (actual pagesize) field of
RB is non-zero on a tlbie[l], as well as when IS is non-zero.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agoDecode tlbiel as tlbie
Paul Mackerras [Sat, 2 May 2020 04:23:14 +0000 (14:23 +1000)]
Decode tlbiel as tlbie

The Linux kernel contains tlbiel instructions, which we can treat
identically to tlbie.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agotests/privileged: Update for instruction translation
Paul Mackerras [Thu, 7 May 2020 02:08:43 +0000 (12:08 +1000)]
tests/privileged: Update for instruction translation

Since setting MSR[PR] = 1 forces instruction translation on, we need
to set up translations for the problem state code to use.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agotests: mmu: Add tests for instruction translation
Paul Mackerras [Tue, 28 Apr 2020 06:00:00 +0000 (16:00 +1000)]
tests: mmu: Add tests for instruction translation

This adds tests of instruction translation to the mmu test.

This also clears the BSS and improves the linker script.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agoMMU: Do radix page table walks on iTLB misses
Paul Mackerras [Tue, 28 Apr 2020 04:54:22 +0000 (14:54 +1000)]
MMU: Do radix page table walks on iTLB misses

This hooks up the connections so that an OP_FETCH_FAILED coming down
to loadstore1 will get sent to the MMU for it to do a radix tree walk
for the instruction address.  The MMU then sends the resulting PTE to
the icache module to be installed in the iTLB.  If no valid PTE can
be found, the MMU sends an error signal back to loadstore1 which sends
it on to execute1 to generate an ISI.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agoAdd TLB to icache
Paul Mackerras [Mon, 27 Apr 2020 07:43:19 +0000 (17:43 +1000)]
Add TLB to icache

This adds a direct-mapped TLB to the icache, with 64 entries by default.
Execute1 now sends a "virt_mode" signal from MSR[IR] to fetch1 along
with redirects to indicate whether instruction addresses should be
translated through the TLB, and fetch1 sends that on to icache.
Similarly a "priv_mode" signal is sent to indicate the privilege
mode for instruction fetches.  This means that changes to MSR[IR]
or MSR[PR] don't take effect until the next redirect, meaning an
isync, rfid, branch, etc.

The icache uses a hash of the effective address (i.e. next instruction
address) to index the TLB.  The hash is an XOR of three fields of the
address; with a 64-entry TLB, the fields are bits 12--17, 18--23 and
24--29 of the address.  TLB invalidations simply invalidate the
indexed TLB entry without checking the contents.

If the icache detects a TLB miss with virt_mode=1, it will send a
fetch_failed indication through fetch2 to decode1, which will turn it
into a special OP_FETCH_FAILED opcode with unit=LDST.  That will get
sent down to loadstore1 which will currently just raise a Instruction
Storage Interrupt (0x400) exception.

One bit in the PTE obtained from the TLB is used to check whether an
instruction access is allowed -- the privilege bit (bit 3).  If bit 3
is 1 and priv_mode=0, then a fetch_failed indication is sent down to
fetch2 and to decode1, which generates an OP_FETCH_FAILED.  Any PTEs
with PTE bit 0 (EAA[3]) clear or bit 8 (R) clear should not be put
into the iTLB since such PTEs would not allow execution by any
context.

Tlbie operations get sent from mmu to icache over a new connection.

Unfortunately the privileged instruction tests are broken for now.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agotests: Add a test for the MMU radix page table walks
Paul Mackerras [Thu, 23 Apr 2020 05:33:36 +0000 (15:33 +1000)]
tests: Add a test for the MMU radix page table walks

This adds tests to check that the MMU and dTLB are translating
addresses and checking permissions correctly.

We use a simple 2-level radix tree.  The radix tree maps 2GB of
address space and has a 1024-entry page directory pointing to
512-entry page table pages.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agoMMU: Remove software-loaded dTLB mode
Paul Mackerras [Thu, 7 May 2020 00:17:08 +0000 (10:17 +1000)]
MMU: Remove software-loaded dTLB mode

This removes the hack where the tlbie instruction could be used to
load entries directly into the dTLB, because we don't report the
correct DSISR values for accesses that hit software-loaded dTLB
entries and have privilege or permission errors.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agoMMU: Refetch PTE on access fault
Paul Mackerras [Wed, 6 May 2020 10:21:01 +0000 (20:21 +1000)]
MMU: Refetch PTE on access fault

This is required by the architecture.  It means that the error bits
reported in DSISR or SRR1 now come from the permission/RC check done
on the refetched PTE rather than the TLB entry.  Unfortunately that
somewhat breaks the software-loaded TLB mode of operation in that
DSISR/SRR1 always report no PTE rather than permission error or
RC failure.

This also restructures the loadstore1 state machine a bit, combining
the FIRST_ACK_WAIT and LAST_ACK_WAIT states into a single state and
the MMU_LOOKUP_1ST and MMU_LOOKUP_LAST states likewise.  We now have a
'dwords_done' bit to say whether the first transfer of two (for an
unaligned access) has been done.

The cache paradox error (where a non-cacheable access finds a hit in
the cache) is now the only cause of DSI from the dcache.  This should
probably be a machine check rather than DSI in fact.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agoMMU: Implement data segment interrupts
Paul Mackerras [Thu, 23 Apr 2020 11:54:08 +0000 (21:54 +1000)]
MMU: Implement data segment interrupts

A data segment interrupt (DSegI) occurs when an address to be
translated by the MMU is outside the range of the radix tree
or the top two bits of the address (the quadrant) are 01 or 10.
This is detected in a new state of the MMU state machine, and
is sent back to loadstore1 as an error, which sends it on to
execute1 to generate an interrupt to the 0x380 vector.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agoMMU: Implement radix page table machinery
Paul Mackerras [Thu, 23 Apr 2020 05:28:22 +0000 (15:28 +1000)]
MMU: Implement radix page table machinery

This adds the necessary machinery to the MMU for it to do radix page
table walks.  The core elements are a shifter that can shift the
address right by between 0 and 47 bits, a mask generator that can
generate a mask of between 5 and 16 bits, a final mask generator,
and new states in the state machine.

(The final mask generator is used for transferring bits of the
original address into the resulting TLB entry when the leaf PTE
corresponds to a page size larger than 4kB.)

The hardware does not implement a partition table or a process table.
Software is expected to load the appropriate process table entry
into a new SPR called PGTBL0, SPR 720.  The contents should be
formatted as described in Book III section 5.7.6.2 of the Power ISA
v3.0B.  PGTBL0 is set to 0 on hard reset.  At present, the top two bits
of the address (the quadrant) are ignored.

There is currently no caching of any step in the translation process
or of the final result, other than the entry created in the dTLB.
That entry is a 4k page entry even if the leaf PTE found in the walk
corresponds to a larger page size.

This implementation can handle almost any page table layout and any
page size.  The RTS field (in PGTBL0) can have any value between 0
and 31, corresponding to a total address space size between 2^31
and 2^62 bytes.  The RPDS field of PGTBL0 can be any value between
5 and 16, except that a value of 0 is taken to disable radix page
table walking (for use when one is using software loading of TLB
entries).  The NLS field of the page directory entries can have any
value between 5 and 16.  The minimum page size is 4kB, meaning that
the sum of RPDS and the NLS values of the PDEs found on the path to
a leaf PTE must be less than or equal to RTS + 31 - 12.

The PGTBL0 SPR is in the mmu module; thus this adds a path for
loadstore1 to read and write SPRs in mmu.  This adds code in dcache
to service doubleword read requests from the MMU, as well as requests
to write dTLB entries.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agoAdd framework for implementing an MMU
Paul Mackerras [Wed, 22 Apr 2020 01:10:56 +0000 (11:10 +1000)]
Add framework for implementing an MMU

This adds a new module to implement an MMU.  At the moment it doesn't
do very much.  Tlbie instructions now get sent by loadstore1 to mmu,
which sends them to dcache, rather than loadstore1 sending them
directly to dcache.  TLB misses from dcache now get sent by loadstore1
to mmu, which currently just returns an error.  Loadstore1 then
generates a DSI in response to the error return from mmu.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agoImplement access permission checks
Paul Mackerras [Mon, 20 Apr 2020 02:43:06 +0000 (12:43 +1000)]
Implement access permission checks

This adds logic to the dcache to check the permissions encoded in
the PTE that it gets from the dTLB.  The bits that are checked are:

R must be 1
C must be 1 for a store
EAA(0) - if this is 1, MSR[PR] must be 0
EAA(2) must be 1 for a store
EAA(1) | EAA(2) must be 1 for a load

In addition, ATT(0) is used to indicate a cache-inhibited access.

This now implements DSISR bits 36, 38 and 45.

(Bit numbers above correspond to the ISA, i.e. using big-endian
numbering.)

MSR[PR] is now conveyed to loadstore1 for use in permission checking.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agoImplement data storage interrupts
Paul Mackerras [Tue, 7 Apr 2020 06:17:37 +0000 (16:17 +1000)]
Implement data storage interrupts

This adds a path from loadstore1 back to execute1 for reporting
errors, and machinery in execute1 for generating data storage
interrupts at vector 0x300.

If dcache is given two requests in successive cycles and the
first encounters an error (e.g. a TLB miss), it will now cancel
the second request.

Loadstore1 now responds to errors reported by dcache by sending
an exception signal to execute1 and returning to the idle state.
Execute1 then writes SRR0 and SRR1 and jumps to the 0x300 Data
Storage Interrupt vector.  DAR and DSISR are held in loadstore1.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agodcache: Implement data TLB
Paul Mackerras [Mon, 6 Apr 2020 07:54:45 +0000 (17:54 +1000)]
dcache: Implement data TLB

This adds a TLB to dcache, providing the ability to translate
addresses for loads and stores.  No protection mechanism has been
implemented yet.  The MSR_DR bit controls whether addresses are
translated through the TLB.

The TLB is a fixed-pagesize, set-associative cache.  Currently
the page size is 4kB and the TLB is 2-way set associative with 64
entries per set.

This implements the tlbie instruction.  RB bits 10 and 11 control
whether the whole TLB is invalidated (if either bit is 1) or just
a single entry corresponding to the effective page number in bits
12-63 of RB.

As an extension until we get a hardware page table walk, a tlbie
instruction with RB bits 9-11 set to 001 will load an entry into
the TLB.  The TLB entry value is in RS in the format of a radix PTE.

Currently there is no proper handling of TLB misses.  The load or
store will not be performed but no interrupt is generated.

In order to make timing at 100MHz on the Arty A7-100, we compare
the real address from each way of the TLB with the tag from each way
of the cache in parallel (requiring # TLB ways * # cache ways
comparators).  Then the result is selected based on which way hit in
the TLB.  That avoids a timing path going through the TLB EA
comparators, the multiplexer that selects the RA, and the cache tag
comparators.

The hack where addresses of the form 0xc------- are marked as
cache-inhibited is kept for now but restricted to real-mode accesses.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agoPass mtspr/mfspr to MMU-related SPRs down to loadstore1
Paul Mackerras [Wed, 22 Apr 2020 06:53:39 +0000 (16:53 +1000)]
Pass mtspr/mfspr to MMU-related SPRs down to loadstore1

This arranges for some mfspr and mtspr to get sent to loadstore1
instead of being handled in execute1.  In particular, DAR and DSISR
are handled this way.  They are therefore "slow" SPRs.

While we're at it, fix the spelling of HEIR and remove mention of
DAR and DSISR from the comments in execute1.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agomw_debug: Add support for reading GSPRs and writing memory
Paul Mackerras [Sat, 2 May 2020 03:31:07 +0000 (13:31 +1000)]
mw_debug: Add support for reading GSPRs and writing memory

This adds a "gpr" command for reading 1 or more GPRs/fast SPRs,
and a "mw" command for writing an 8-byte value to memory.  It also
adds an "icreset" command for resetting the instruction cache
and fixes the "creset" command to actually reset the core instead
of starting it.  The MSR is now printed along with the NIA in the
status information.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agodebug: Provide a way to examine GPRs, fast SPRs and MSR
Paul Mackerras [Sat, 2 May 2020 03:26:30 +0000 (13:26 +1000)]
debug: Provide a way to examine GPRs, fast SPRs and MSR

This provides commands on the debug interface to read the value of
the MSR or any of the 64 GSPR register file entries.  The GSPR values
are read using the B port of the register file in a cycle when
decode2 is not using it.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agoImprove architectural compliance of mfspr and mtspr
Paul Mackerras [Sat, 2 May 2020 10:08:10 +0000 (20:08 +1000)]
Improve architectural compliance of mfspr and mtspr

Mfspr from an unimplemented SPR should be a no-op in privileged state,
so in this case we need to write back whatever was previously in the
destination register.  For problem state, both mtspr and mfspr to
unimplemented SPRs should cause a program interrupt.

There are special cases in the architecture for SPRs 0, 4 5 and 6
which we still don't implement.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agodecode1: Implement eieio as a nop
Paul Mackerras [Sat, 2 May 2020 03:45:39 +0000 (13:45 +1000)]
decode1: Implement eieio as a nop

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agoImplement the extswsli instruction
Paul Mackerras [Sat, 2 May 2020 03:28:19 +0000 (13:28 +1000)]
Implement the extswsli instruction

This mainly required the addition of an entry to the opcode 31 decode
table and a 32-bit sign-extender in the rotator.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agosoc: Add DRAM address decoding
Benjamin Herrenschmidt [Tue, 10 Sep 2019 17:05:56 +0000 (18:05 +0100)]
soc: Add DRAM address decoding

Still not attached to any board

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agocore: Add alternate reset address
Benjamin Herrenschmidt [Thu, 7 May 2020 12:09:59 +0000 (22:09 +1000)]
core: Add alternate reset address

An external signal can control whether the core will start
executing at the standard or the alternate reset address.

This will be used when litedram is initialized by microwatt
itself, to route the reset to the built-in init code secondary
block RAM.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agolitedram: Add basic support for LiteX LiteDRAM
Benjamin Herrenschmidt [Tue, 10 Sep 2019 17:05:32 +0000 (18:05 +0100)]
litedram: Add basic support for LiteX LiteDRAM

This comes in two parts:

 - A generator script which uses LiteX to generate litedram cores
along with their init files for various boards (currently Arty and
Nexys-video). This comes with configs for arty and nexys_video.

 - A fusesoc "generator" which uses pre-generated litedram cores

The generation process is manual on purpose. This include pre-generated
cores for the two above boards.

This is done so that one doesn't have to install LiteX to build
microwatt. In addition, the generator script or wrapper vhdl tend to
break when LiteX changes significantly which happens.

This is still rather standalone and hasn't been plumbed into the SoC
or the FPGA toplevel files yet.

At this point LiteDRAM self-initializes using a built-in VexRiscv
"Minimum" core obtained from LiteX and included in this commit. There
is some plumbing to generate and cores that are initialized by Microwatt
directly but this isn't working yet and so isn't enabled yet.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agocore: Improve core reset
Benjamin Herrenschmidt [Fri, 8 May 2020 01:36:37 +0000 (11:36 +1000)]
core: Improve core reset

The icache would still spit out an instruction which could
cause a 0x700 instead of a reset.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agomw_debug: Fix core reset
Benjamin Herrenschmidt [Mon, 4 May 2020 12:16:22 +0000 (22:16 +1000)]
mw_debug: Fix core reset

mw_debug creset would poke the START bit instead of the RESET bit

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agoUpdate hello_world for 100Mhz clock
Benjamin Herrenschmidt [Thu, 30 Apr 2020 07:52:11 +0000 (17:52 +1000)]
Update hello_world for 100Mhz clock

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agoChange default frequency to 100Mhz
Benjamin Herrenschmidt [Mon, 30 Sep 2019 04:07:16 +0000 (14:07 +1000)]
Change default frequency to 100Mhz

LiteDRAM at the moment pretty much enforces 100Mhz, and our software
isn't quite yet adaptable, so switch out default to 100Mhz accross
the board. Recent timing improvements should make it a non-issue.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agoxics: Add missing fusesoc core file
Benjamin Herrenschmidt [Fri, 8 May 2020 01:40:39 +0000 (11:40 +1000)]
xics: Add missing fusesoc core file

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
4 years agoMerge pull request #166 from paulusmack/master
Anton Blanchard [Wed, 6 May 2020 23:59:19 +0000 (09:59 +1000)]
Merge pull request #166 from paulusmack/master

MSR fixes, implement privilege checking, implement dcbz

4 years agoexecute1: Fix interrupt delivery during slow instructions
Paul Mackerras [Mon, 4 May 2020 05:17:04 +0000 (15:17 +1000)]
execute1: Fix interrupt delivery during slow instructions

During slow instructions such as multiply or divide, if a decrementer
(or other asynchronous) interrupt becomes pending, it disrupts the
logic that keeps stall asserted until the end of the slow
instruction, and the interrupt logic starts trying to deliver the
interrupt before the slow instruction has finished.

To fix that, make the interrupt logic wait until it sees e_in.valid
set before setting exception to 1.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agowishbone_debug_master: Fix address auto-increment for memory writes
Paul Mackerras [Thu, 30 Apr 2020 23:00:21 +0000 (09:00 +1000)]
wishbone_debug_master: Fix address auto-increment for memory writes

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agoMerge remote-tracking branch 'remotes/origin/master'
Paul Mackerras [Wed, 6 May 2020 04:15:22 +0000 (14:15 +1000)]
Merge remote-tracking branch 'remotes/origin/master'

4 years agodcache: Don't assert on dcbz cache hit
Paul Mackerras [Sun, 3 May 2020 22:31:18 +0000 (08:31 +1000)]
dcache: Don't assert on dcbz cache hit

We can hit the assert for req_op = OP_STORE_HIT and reloading in the
case of dcbz, since it looks like a store.  Therefore we need to
exclude that case from the assert.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agoMerge pull request #165 from mikey/xics
Anton Blanchard [Wed, 6 May 2020 03:27:17 +0000 (13:27 +1000)]
Merge pull request #165 from mikey/xics

Implement XICS compliant interrupt controller

4 years agoMerge pull request #167 from tomtor/patch-1
Anton Blanchard [Fri, 1 May 2020 09:52:59 +0000 (19:52 +1000)]
Merge pull request #167 from tomtor/patch-1

Fix Rust README.md

4 years agoUpdate README.md
Tom Vijlbrief [Fri, 1 May 2020 07:39:49 +0000 (09:39 +0200)]
Update README.md

Fix formatting of Rust README

Signed-off-by: Tom Vijlbrief <tvijlbrief@gmail.com>
4 years agoChange the default cross compiler prefix to powerpc64le-linux-gnu-
Paul Mackerras [Wed, 29 Apr 2020 01:37:02 +0000 (11:37 +1000)]
Change the default cross compiler prefix to powerpc64le-linux-gnu-

That is what is used by the packaged cross-compilers on (at least)
Fedora and Ubuntu.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agoMakefile: fix typo
Paul Mackerras [Wed, 29 Apr 2020 01:11:22 +0000 (11:11 +1000)]
Makefile: fix typo

Fix a typo which meant that the console tests weren't getting
executed by 'make check'.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agotests: Add a test for privileged instruction interrupts
Paul Mackerras [Tue, 28 Apr 2020 23:09:23 +0000 (09:09 +1000)]
tests: Add a test for privileged instruction interrupts

This adds a test that tries to execute various privileged instructions
with MSR[PR] = 1.  This also incidentally tests some of the MSR bit
manipulations.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agodcache: Implement the dcbz instruction
Paul Mackerras [Tue, 28 Apr 2020 08:11:52 +0000 (18:11 +1000)]
dcache: Implement the dcbz instruction

This adds logic to dcache and loadstore1 to implement dcbz.  For now
it zeroes a single cache line (by default 64 bytes), not 128 bytes
like IBM Power processors do.

The dcbz operation is performed much like a load miss, except that
we are writing zeroes to memory instead of reading.  As each ack
comes back, we write zeroes to the BRAM instead of data from memory.
In this way we zero the line in memory and also zero the line of
cache memory, establishing the line in the cache if it wasn't already
resident.  If it was already resident then we overwrite the existing
line in the cache.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agoPlumb insn_type through to loadstore1
Paul Mackerras [Fri, 3 Apr 2020 03:50:17 +0000 (14:50 +1100)]
Plumb insn_type through to loadstore1

In preparation for adding a TLB to the dcache, this plumbs the
insn_type from execute1 through to loadstore1, so that we can have
other operations besides loads and stores (e.g. tlbie) going to
loadstore1 and thence to the dcache.  This also plumbs the unit field
of the decode ROM from decode2 through to execute1 to simplify the
logic around which ops need to go to loadstore1.

The load and store data formatting are now not conditional on the
op being OP_LOAD or OP_STORE.  This eliminates the inferred latches
clocked by each of the bits of r.op that we were getting previously.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agoexecute1: Generate privileged instruction interrupts when MSR[PR] = 1
Paul Mackerras [Tue, 28 Apr 2020 09:38:58 +0000 (19:38 +1000)]
execute1: Generate privileged instruction interrupts when MSR[PR] = 1

This adds logic to execute1 to check, when MSR[PR] = 1, whether each
instruction arriving to be executed is a privileged instruction.
If it is, a privileged-instruction type program interrupt is generated.
For the mtspr and mfspr instructions, we need to look at bit 20 of the
instruction (bit 4 of the SPR number) to determine if the SPR is
privileged.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agoexecute1: Improve architecture compliance of MSR and related instructions
Paul Mackerras [Tue, 28 Apr 2020 10:28:20 +0000 (20:28 +1000)]
execute1: Improve architecture compliance of MSR and related instructions

This makes our treatment of the MSR conform better with the ISA.

- On reset, initialize the MSR to have the SF and LE bits set and
  all the others reset.  For good measure initialize r properly too.

- Fix the bit numbering in msr_copy (the code was using big-endian
  bit numbers, not little-endian).

- Use constants like MSR_EE to index MSR bits instead of expressions
  like '63 - 48', for readability.

- Set MSR[SF, LE] and clear MSR[PR, IR, DR, RI] on interrupts.

- Copy the relevant fields for rfid instead of using msr_copy, because
  the partial function fields of the MSR should be left unchanged,
  not zeroed.  Our implementation of rfid is like the architecture
  description of hrfid, because we don't implement hypervisor mode.

- Return the whole MSR for mfmsr.

- Implement the L field for mtmsrd (L=1 copies just EE and RI).

- For mtmsrd with L=0, leave out the HV, ME and LE bits as per the arch.

- For mtmsrd and rfid, if PR ends up set, then also set EE, IR and DR
  as per the arch.

- A few other minor tidyups (no semantic change).

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agoMerge pull request #164 from mikey/tags
Anton Blanchard [Thu, 23 Apr 2020 09:50:16 +0000 (19:50 +1000)]
Merge pull request #164 from mikey/tags

Add VHDL TAGS

4 years agoMerge pull request #163 from paulusmack/excpath
Anton Blanchard [Thu, 23 Apr 2020 09:49:24 +0000 (19:49 +1000)]
Merge pull request #163 from paulusmack/excpath

Fix the bug causing the assert that Mikey hit

4 years agoXICS test case
Michael Neuling [Thu, 23 Apr 2020 04:37:29 +0000 (14:37 +1000)]
XICS test case

Checks interrupt masking and priorities.

Adds to `make test_xics` which is run in `make check` also.

Signed-off-by: Michael Neuling <mikey@neuling.org>
4 years agoXICS interrupt controller
Michael Neuling [Thu, 23 Apr 2020 04:36:05 +0000 (14:36 +1000)]
XICS interrupt controller

New unified ICP and ICS XICS compliant interrupt controller.
Configurable number of hardware sources.

Fixed hardware source number based on hardware line taken. All
hardware interrupts are a fixed priority. Level interrupts supported
only.

Hardwired to 0xc0004000 in SOC (UART is kept at 0xc0002000).

Signed-off-by: Michael Neuling <mikey@neuling.org>
4 years agoWire up sim uart TX interrupt
Michael Neuling [Thu, 23 Apr 2020 04:28:59 +0000 (14:28 +1000)]
Wire up sim uart TX interrupt

TX is always ready, so just always sent interrupt when enabled.

No RX interrupt.

Signed-off-by: Michael Neuling <mikey@neuling.org>
4 years agoAdd calls to dis/enable potato uart IRQ
Michael Neuling [Thu, 23 Apr 2020 04:28:08 +0000 (14:28 +1000)]
Add calls to dis/enable potato uart IRQ

Signed-off-by: Michael Neuling <mikey@neuling.org>
4 years agoAdd VHDL TAGS
Michael Neuling [Wed, 8 Apr 2020 07:35:32 +0000 (17:35 +1000)]
Add VHDL TAGS

Adds `make TAGS`

Signed-off-by: Michael Neuling <mikey@neuling.org>
4 years agoexecute1: Don't execute ld/st instruction when taking interrupt
Paul Mackerras [Wed, 22 Apr 2020 03:54:38 +0000 (13:54 +1000)]
execute1: Don't execute ld/st instruction when taking interrupt

This fixes a bug in the logic where we would still send a load
or store instruction to loadstore1 even though we have decided
to take an asynchronous interrupt.

Reported-by: Michael Neuling <mikey@neuling.org>
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
4 years agoMerge pull request #162 from antonblanchard/bin2hex-removal
Anton Blanchard [Thu, 16 Apr 2020 08:42:42 +0000 (18:42 +1000)]
Merge pull request #162 from antonblanchard/bin2hex-removal

rust_lib_demo: Remove bin2hex.py

4 years agoMerge pull request #161 from antonblanchard/hello-world-Makefile
Anton Blanchard [Thu, 16 Apr 2020 08:42:13 +0000 (18:42 +1000)]
Merge pull request #161 from antonblanchard/hello-world-Makefile

hello_world: Use Makefile automatic variables

4 years agorust_lib_demo: Remove bin2hex.py
Anton Blanchard [Thu, 16 Apr 2020 07:44:17 +0000 (17:44 +1000)]
rust_lib_demo: Remove bin2hex.py

We are using scripts/bin2hex.py, so we can get rid of this copy.

Signed-off-by: Anton Blanchard <anton@linux.ibm.com>
4 years agoMerge pull request #160 from antonblanchard/tomtor-rust-2
Anton Blanchard [Thu, 16 Apr 2020 07:40:52 +0000 (17:40 +1000)]
Merge pull request #160 from antonblanchard/tomtor-rust-2

Rebase Tom's rust demo patches

4 years agohello_world: Use Makefile automatic variables
Anton Blanchard [Thu, 16 Apr 2020 07:38:07 +0000 (17:38 +1000)]
hello_world: Use Makefile automatic variables

Fix a few whitespace issues while here.

Signed-off-by: Anton Blanchard <anton@linux.ibm.com>
4 years agorust_lib_demo: Use common console code
Anton Blanchard [Thu, 16 Apr 2020 07:14:18 +0000 (17:14 +1000)]
rust_lib_demo: Use common console code

Use a symlink to share the console code in hello_world. Not ideal,
but we can improve on it later.

Signed-off-by: Anton Blanchard <anton@linux.ibm.com>
4 years agorust_lib_demo: Update package dependencies to fix a build error
Anton Blanchard [Thu, 16 Apr 2020 07:08:15 +0000 (17:08 +1000)]
rust_lib_demo: Update package dependencies to fix a build error

I'm hitting a build error:

    error[E0050]: method `alloc` has 2 parameters but the declaration in trait `core::alloc::AllocRef::alloc` has 3

Updating the version of linked_list_allocator fixes it. I updated
heapless to while I was at it.

Signed-off-by: Anton Blanchard <anton@linux.ibm.com>
4 years agoAdd Rust demo
Tom Vijlbrief [Fri, 3 Jan 2020 09:34:21 +0000 (10:34 +0100)]
Add Rust demo

Signed-off-by: Tom Vijlbrief <tvijlbrief@gmail.com>
4 years agoMerge pull request #159 from shenki/fusesoc-ram-16k
Anton Blanchard [Thu, 16 Apr 2020 05:15:07 +0000 (15:15 +1000)]
Merge pull request #159 from shenki/fusesoc-ram-16k

FuseSoC needs 16kB of RAM

4 years agoSet default RAM to be 16K in microwatt.core
Joel Stanley [Wed, 15 Apr 2020 06:36:54 +0000 (16:06 +0930)]
Set default RAM to be 16K in microwatt.core

This allows it to run hello world out of the box.

Signed-off-by: Joel Stanley <joel@jms.id.au>
4 years agoREADME: hello world needs 16KB of RAM
Joel Stanley [Wed, 15 Apr 2020 06:32:21 +0000 (16:02 +0930)]
README: hello world needs 16KB of RAM

STACK_TOP is at 0x2000 (8K) so we need something larger as a minimum.

Signed-off-by: Joel Stanley <joel@jms.id.au>
4 years agoMerge pull request #158 from paulusmack/excpath
Anton Blanchard [Tue, 14 Apr 2020 02:47:00 +0000 (12:47 +1000)]
Merge pull request #158 from paulusmack/excpath

Fix exception stuff so we make timing again