Commit graph

460 commits

Author SHA1 Message Date
Udi
13b313d220 [ibex/dv] Update Ibex PMP tests
This PR adds a riscv-dv option `enable_write_pmp_csr=1` to each of the
tests in the existing PMP test suite.

This will enable the core to execute a directed test sequence to write
random values to each `pmpaddr` and `pmpcfg` CSR in order to test write
accessibility and spec compliance.

The original values stored in these CSRs are restored after this random
write.

Signed-off-by: Udi <udij@google.com>
2020-08-06 01:29:25 -07:00
Pirmin Vogel
597070400d [dv] Add custom CSRs to yaml description file
This is related to lowRISC/ibex#1038.

Signed-off-by: Pirmin Vogel <vogelpi@lowrisc.org>
2020-07-24 19:39:22 +02:00
Udi
c9331c0e34 [dv/ibex] Update CSR listings
This PR updates the `implemented_csrs` list in `riscv_core_setting.sv`
and adds the two custom CSRs `cpuctrl` and `secureseed` to the
`custom_csrs` list. Both are for use by the riscv-dv generator.

Signed-off-by: Udi <udij@google.com>
2020-07-24 10:10:21 -07:00
Rupert Swarbrick
46ff63ad88 Properly vendor in mem_model from OpenTitan
This removes the manually copied version at dv/uvm/core_ibex/common
and vendors things properly now that the vendor tool supports such
things (this picks up the same OpenTitan version as the previous
commit: lowRISC/opentitan@067272a2).
2020-07-24 08:05:40 +01:00
Rupert Swarbrick
94d5057168 Track mem_err_shift better in the ICache scoreboard
This fixes a test failure that I was seeing when following a "many
errors" test by something different. To reproduce,

  make -C dv/uvm/icache/dv \
       SEED=1465832714 \
       TESTS=ibex_icache_stress_all_with_reset

There are actually two different ways this can come unstuck:

(1) Memory request goes out and gets put into the response queue.
    req_i goes low. Sequence changes. req_i goes high and we get the
    response from the previous request (but mem_err_shift has changed
    in the meantime).

    To fix this, we pair up the memory seed and its associated
    mem_err_shift in the scoreboard queue, rather than retrieving
    mem_err_shift from the config object when the response comes in.

(2) Memory request goes out. Sequence changes. Memory request is
    handled (with new mem_err_shift). Scoreboard sees the result. New
    sequence generates its first item.

    In this case, the scoreboard will expect the old mem_err_shift and
    see the new one. To fix this, we add an extra entry to the list of
    valid states in the scoreboard if needed so that we also check the
    mem_err_shift currently in the config object.

You might worry about what happens if we have two back-to-back
sequence changes that change mem_err_shift without ever changing seed:
what happens if we have a situation like (1), but for the "middle"
sequence. To avoid this problem, we actually add the extra entry in
the fix for (2), so it will look like a new seed arrived as part of
the middle sequence, so long as we have read at least one
result (always true in the core sequence).
2020-07-22 21:09:40 +01:00
Rupert Swarbrick
84bcf4973a Minor rejigs to Makefile dvsim wrapper
This now allows you to specify how many seeds to run. Sadly, you can't
say "give me 10 seeds, starting at 1234" because dvsim doesn't support
that at the moment. But it does at least avoid quite such long command
lines.

Instead of:

    ../../../../vendor/lowrisc_ip/dvsim/dvsim.py \
      ibex_icache_sim_cfg.hjson \
      --scratch-root ../../../../build \
      --reseed 5 \
      -c

you can run:

    make RESEED=5 COVERAGE=1
2020-07-22 21:09:40 +01:00
Rupert Swarbrick
e8d86ecb96 Remove duplicated files from dv/uvm/core_ibex/common/utils
We now have a clock/reset interface and the dv_utils stuff vendored
from OpenTitan so can delete the duplicates and point the file list at
the vendored files.

The only difficulty is that the clock interfaces are slightly
different, so there are a couple of minor changes to the core_ibex
test lib, renaming "clk_if" to "clk_rst_if" and changing how we apply
resets.

Note that the testbench (core_ibex_tb_top.sv) starts the clock and
resets the DUT at the start of time. This is different from how other
OpenTitan VIP does things (where the reset happens in the sequence),
but this is the smallest change I could make from how it worked
before (where the reset happened in the clock interface itself).
2020-07-22 21:09:25 +01:00
Rupert Swarbrick
1dda6401c3 Define an Ibex-specific top_pkg core
The idea is that this can supply top_pkg.sv, a top-level thing in
OpenTitan, for DV code we vendor from there. It's probably better to
do this than to directly vendor in OpenTitan's top_pkg, because the
latter has information about e.g. flash memory layout, which doesn't
really have any meaning for Ibex.
2020-07-22 21:09:25 +01:00
Rupert Swarbrick
c5cd7d6819 [dvsim] Print a more helpful path to coverage dashboard
cov_report_page is used by dvsim's SimCfg.py to print a message to the
console with the path to the dashboard HTML page. Most of these
messages have the full path (useful for copy-pasting), but this one
didn't.

This is essentially a duplicate of OpenTitan PR 2934[1] (because we're
not able to vendor these files properly yet).

[1] https://github.com/lowRISC/opentitan/pull/2934
2020-07-22 21:08:38 +01:00
Pirmin Vogel
d7c13aa904 [dv] Fix typos
These typos cause compilation failures.

Signed-off-by: Pirmin Vogel <vogelpi@lowrisc.org>
2020-07-20 10:29:30 +02:00
Udi
1619ea2bc7 [dv/ibex] Enhance riscv_debug_single_step test
As pointed out by @tomroberts-lowrisc in #983, the current
implementation of riscv_debug_single_step_test cannot handle
single-stepping over instructions that change the PC.
This PR aims to introduce this functionality, utilizing the
new instr_monitor_if.

Now, if the core single-steps onto a branch/jump instruction, the
testbench will log the new target PC and compare it against the actual
target address stored in `dpc`.
"Normal" instructions are checked as usual by incrementing the
instruction's PC by either 2 or 4 (depending whether it is compressed)
and comparing that against `dpc`.
2020-07-17 11:15:13 -07:00
Udi
93d920118c [dv/ibex] Switch to request/response terminology
This PR modifies the Ibex DV environment to use request/response
terminology instead of the current outdated naming scheme.
These changes are purely aesthetic.
2020-07-15 09:29:02 -07:00
Tom Roberts
c542edbb1a [rtl] Add register-file ECC checking
- Add SECDED ECC checking to the register file when SecureIbex is
  enabled
- No correction is attempted, but an alert is raised for the system to
  intervene

Signed-off-by: Tom Roberts <tomroberts@lowrisc.org>
2020-07-15 09:50:23 +01:00
Dawid Zimonczyk
1dfddee5e6 Value passed to UVM set_timeout is calculated as 1000000000 basing on 1ns/1ps timescale.
But if you are using precompiled UVM it may be compiled with other timescale depending on compilation option used when it was compiled or tools default timescale value (uvm does not set timescale int the code).
In this case for us precompiled UVM timescale is 1ps/1ps - so UVM gets 1000000000 in set timeout but interprets it as ps. As a result timeout is 1000 times smaller that you expect. That is why we are getting timeouts.
It is hard to find perfect solution. One of them is to recompile the UVM with -timescale 1ns/ps (or whatever you will use for your design).
2020-07-10 10:56:03 +01:00
Dawid Zimonczyk
9208689c21 correct wrong assignment to enum 2020-07-09 18:12:28 +01:00
Udi
75dadb5aef [dv/ibex] Add two new interrupt/debug tests
As a result of lowRISC/opentitan#2405 and lowRISC/ibex#928 (reporting
that interrupts that came in while a load instruction was in the ID
stage caused some incorrect behavior in Ibex), this PR adds some new
directed interrupt and debug tests to check that the core behaves
properly during execution of each supported instruction when some
external irq/debug stimulus comes in.

To do this, we use the two new functions `decode_instr(...)` and
`decode_compressed_instr(...)` in `core_ibex_test_list.sv` to "decode"
every instruction that the `core_ibex_instr_monitor_if` sees in the ID
stage of the pipeline. Once the testbench decodes an instruction that
we have not seen before, it can then drive interrupt or debug stimulus
into the core.

Once any given instruction has been detected by the testbench (and
stimulus driven), it will no longer drive stimulus if this instruction
is seen in the decode pipeline (e.g. if we have previously detected a
`c.addi` instruction in the ID stage and have driven irq/debug stimulus,
we will no longer drive stimulus if we see another `c.addi` instruction,
no matter the operands). This is to avoid driving irq/debug stimulus
after every single instruction as this will add a huge unwanted amount
of simulation latency.

A few notes:

- We drive irq/debug stimulus into the core every time we see a
  `wfi` instruction, as otherwise we will timeout as the core waits
  infinitely for some stimulus from the outside world.
- We ignore some system-level instructions (ebreak/mret/dret) and
  illegal instructionsfor now, as driving stimulus during these
  instructions will result in a nested trap, which requires special
  handling.
- The interrupt agent was modified slightly to drive stimulus by
  default on the falling edge of the clock, so this way we can "catch"
  instructions that are in the ID pipeline for only a single cycle.
- The duration for which the testbench raises `debug_req_i` for the core
  is also increased to avoid edge cases where we lower the debug line
  too early (e.g. while long multicycle instructions like `div` are
  executing in the ID stage).
2020-07-06 17:50:59 -07:00
ganoam
1aa4d5a32b [bitmanip] Optimizations and Parametrization
This commit contains some final optimizations regarding the bit
manipulation extension as well as the parametrization into a balanced
version and a full performance version.

Balanced Version:
        * Supports ZBB, ZBS, ZBF and ZBT extensions
        * Dual cycle instructions:
          ror[i], rol, cmov, cmix fsl, fsr[i]
        * Everything else completes in a single cycle.

Full Version:
        * Supports all 32b sub extensions.
        * Dual cycle instructions:
          ror[i], rol, cmov, cmix fsl, fsr[i], crc32[c], bext, bdep
        * Everything else completes in a single cycle.

Notable Changes:
        * bext/bdep are now multi-cycle: Sharing additional register
          with multiplier module
        * grev/gorc instructions are implemented in separate structures
          rather than sharing the shifter or butterfly network.
        * Speed up decision on using rs1 or rs3 for alu_operand_a by
          introducing single-bit register, to identify ternary
          instructions in their first cycle.
        * Introduce enumerated parameter to chose bit manipulation
          implementation

Signed-off-by: ganoam <gnoam@live.com>
2020-06-26 14:43:24 +02:00
Michael Schaffner
ae547c8d30 [top_pkg] Fix style lint warnings
Signed-off-by: Michael Schaffner <msf@google.com>
2020-06-22 20:52:15 +01:00
Udi
1f26d93267 [ibex/dv] Add clocking blocks to Ibex interfaces
This PR adds clocking blocks to all major Ibex interfaces and updates
all corresponding interface accesses to use these clocking blocks.

A few notes:

- `ibex_mem_intf` has two driver clocking blocks, one for host side and
  one for device side.
  This is because our Ibex testbench currently provides both host and
  device agents for both I/D interfaces (of course we only use the
  reactive device agents in the main testbench).
- `csr_if` and `dut_if` only have one clocking block each, as all
  signals in each will only be either sampled or driven, never both.
- Some utility tasks have been added to some interfaces to wait for a
  specified number of clock cycles.
2020-06-22 12:07:40 -07:00
Rupert Swarbrick
96cf24a41a Add a stress_all_with_reset ICache test
This is like the stress_all test, picking other sequences at random
and running them back-to-back. The difference is in the reset
behaviour, where we randomly pull the reset line at unexpected times
to try to trigger any strange glitches this might cause.

This requires slight changes to the core and memory drivers, which
need to learn to stop and return early from the current item when they
see a reset.
2020-06-22 17:11:59 +01:00
Rupert Swarbrick
962fc8020c Invalidate in an ICache sequence after a change to mem_err_shift
When we chain sequences together, we are careful to pass seeds between
neighbouring sequences. However, I didn't think to check
mem_err_shift. Before this patch, you see problems if you have a
"caching" sequence followed by a "many_errors" sequence with no reset
and no change of seed and they both happen to pick the same address
range.

The problem is that if the data at address A is cached in the first
sequence, the icache will merrily return it when address A comes up in
the second. However, the change to mem_err_shift might mean that this
would cause a memory error if it hadn't been cached, causing the
scoreboard to get upset.

This patch ensures that we always start a sequence with an
invalidation if there was a previous sequence with a different value
of mem_err_shift.

To do this cleanly, the patch also moves some of the "grab the guts of
the old sequence and put it in the new one" logic from
ibex_icache_combo_vseq and into the underlying sequence classes. The
trick is that a sequence now has a handle to the previous sequence (if
there was one), and can use that to extract whatever information it
needs.
2020-06-22 17:11:59 +01:00
Rupert Swarbrick
e243ab2617 Fix ICache caching window test with combination sequences
This fixes several problems. Firstly, the window_reset function was
switching off tracking until it next saw busy_o go low, which is
correct at the start of time, but not what we want after we've
started. This patch splits that behaviour into a new tracking_reset
function (which calls window_reset). This is called on reset or
invalidate.

Secondly, this check was occasionally failing where we'd have an ECC
sequence (which should disable the check) immediately followed by a
caching sequence with similar addresses. If the window ended in the
caching sequence, we'd see a high fetch ratio and conclude that
something had gone wrong.

Now we clear the window completely whenever we fetch an instruction
when the check is disabled, which should avoid the problem (at worst,
you might get 1 instruction overlap, which is unlikely to matter).

Finally, we move the call to tracking_reset up to the end of the reset
sequence. It doesn't usually matter, but if there's a pending item
from the core monitor with busy = 0, we need to make sure that item
comes in before we set not_invalidating = 1. Otherwise, the scoreboard
incorrectly thinks it's seen the end of the invalidation
sequence (before it's even started) and starts tracking fetch ratios
too early.
2020-06-22 17:11:59 +01:00
Rupert Swarbrick
e7c9b52c36 Add ibex_icache_stress_all test
This runs sequences back-to-back, occasionally resetting between
sequences.

Because our virtual sequences are composed of several smaller
sequences, we have to stop them when the core sequence finishes (see
the calls to kill() in ibex_icache_base_vseq). We also have to make
sure that we don't drop items in the memory sequence, which can be
pre-empted as part of sending a response (see the peek/get code
there).

Finally, the memory sequence also has a current seed and a list of
pending grants: this patch has to copy those across between sequences
to make everything work correctly.
2020-06-22 17:11:59 +01:00
Rupert Swarbrick
41a4811a55 Tidy up properly after overriding class in ICache back_line_seq
This virtual sequence controls what sequence we use in the core agent
with a factory override. We need to make sure that we "tidy up" after
starting it, otherwise every sequence afterwards will use the wrong
core sequence.
2020-06-22 17:11:59 +01:00
Rupert Swarbrick
dc708427d0 Remove empty tasks from ibex_icache_base_vseq.sv
These aren't needed, so no reason to keep the scaffolding.
2020-06-22 17:11:59 +01:00
Rupert Swarbrick
0044ea35f9 Use dv_base_vseq's num_trans field rather than making our own 2020-06-22 17:11:59 +01:00
Rupert Swarbrick
a3b53c875c Control core sequence's transaction count from top in ICache tests
This will have no effect for now: we just move the "pick a number in
the range 800..1000" logic to the virtual sequence.

The reason to do this is for tests that combine sequences: we want to
be able to shorten each component sequence so that the combined test
isn't way longer than the original ones were.
2020-06-22 17:11:59 +01:00
Rupert Swarbrick
2c38d22d99 Remove ibex_icache_sanity_vseq
This derived from ibex_icache_base_vseq but didn't do any other
customisation. Let's just use the base vseq for the test.
2020-06-22 17:11:59 +01:00
Rupert Swarbrick
ad80b0b247 Configure ICache mem_error tests from the vseq (not a test class)
As with the ECC sequence, it turns out that you don't actually need
the separate test class for this, so this commit gets rid of it. The
advantage of doing this is that we can now chain this vseq with
others.
2020-06-22 17:11:59 +01:00
Rupert Swarbrick
b49f153a50 Pass mem_err_shift to the ICache memory model on each error check
This has no immediate effect, but it means that the memory agent's
config's "mem_err_shift" value can be changed in the middle of the
test, rather than being fixed in the build_phase.
2020-06-22 17:11:59 +01:00
Rupert Swarbrick
48febdc5d6 Configure ICache ECC tests just from the vseq (not a test class)
It turns out that you don't actually need the separate test class for
this, so this commit gets rid of it. The advantage of doing this is
that we can now chain this vseq with others.
2020-06-22 17:11:59 +01:00
Rupert Swarbrick
a247cd45e9 Add some basic protocol checking to the icache's RAM interface
Since we are binding in an interface anyway, we can add some SV
assertions to make sure nothing too strange is happening.

Note that they aren't as strong as you might expect: we don't check
that rdata isn't X, for example. This is because the cache makes
speculative reads, which it (hopefully) ignores if the data is
invalid.
2020-06-22 10:37:34 +01:00
Rupert Swarbrick
4a748eb522 Enable ICache ECC in the way dvsim.py requires
It seems that dvsim.py doesn't actually use fusesoc to do things like
pass parameters. Instead, we have to set the tool-specific options in
the hjson file by hand.

Fixes issue #964.
2020-06-22 09:25:03 +01:00
Udi
5be84f0f04 [dv/ibex] Update riscv_core_setting to match latest version of riscv-dv 2020-06-19 14:45:55 -07:00
Rupert Swarbrick
37fd4236c8 Correct window_width calculation in ICache UVM scoreboard
If window_range_hi = 32'hfffffffe and window_range_lo =
32'h00000000 (quite possible if we wrap), we were overflowing the
32-bit int.

The other way to write this would be something like

    ((window_range_hi - window_range_lo) / 4 +
     (((window_range_hi - window_range_lo) & 3) != 0))

which avoids needing the extra bit, but that feels very
cumbersome.
2020-06-19 09:26:12 +01:00
Rupert Swarbrick
8fe04c6923 Fix ordering in ICache core monitor start-up
Unsurprisingly, if you only start monitoring for something after
finishing the run phase, you don't see it very often. Oops!
2020-06-19 09:26:12 +01:00
Rupert Swarbrick
2cd77e5739 Correct "cancelled_valid" sequence in ICache UVM core coverage
This is supposed to spot when the valid signal drops without a ready
signal from the core. This is only allowed to happen if the core sends
a branch. The previous sequence was bogus: it didn't work for
back-to-back accesses (because it required $rose(valid)) and it didn't
check that valid actually dropped (which doesn't always happen). The
new one is simpler, and correct!

Note that we still don't see coverage of the sequence. I'll fix that
in the next patch.
2020-06-19 09:26:12 +01:00
Rupert Swarbrick
f1543a13b4 Allow ready & branch in ICache UVM tests
This doesn't actually have any effect (since the branch has priority
over whether the core is ready), but it's possible in the spec, so we
should do it sometimes.
2020-06-19 09:26:12 +01:00
Rupert Swarbrick
36935dcbb0 Weight branches in icache tests to favour edges of address space
This hits some coverpoints that are defined at interface-level in the
core agent. The point is that you want to make sure address wrapping
works correctly (what's the next instruction after 0xfffffffe?).

Note that we now also constrain the base address to be even. This was
technically wrong before, but would only have been a problem if you
picked a base address of 0xffffffff (with a probability of 1 in 4
billion).
2020-06-19 09:26:12 +01:00
Rupert Swarbrick
356fb55f7e Increase priority of failure messages in ICache scoreboard
A few of these messages get printed out just before an error. It's
much more helpful for debugging if you see them with the default
verbosity. They only appear when something goes wrong, so let's just
turn them on.
2020-06-18 09:24:06 +01:00
Rupert Swarbrick
eaa74e963c Fix verbosity in ECC UVM driver
This should have been UVM_HIGH (which disables the messages most of
the time).
2020-06-18 09:24:06 +01:00
Tom Roberts
a2194a723b [dv] Fix DUT probe IF paths
- The testbench probes signals that are unqualified by instr_valid
- This causes events to trigger due to instructions that are not
  actually executed, leading to false timeout failures
- Note this fix alone doesn't eliminate such failures due to another
  issue which will be addressed separately

Signed-off-by: Tom Roberts <tomroberts@lowrisc.org>
2020-06-16 10:59:57 +01:00
Rupert Swarbrick
b060d37d8d Add ECC agents to ICache DV plan document 2020-06-16 09:28:57 +01:00
Rupert Swarbrick
917572c2c1 Define an "ECC agent" for icache testing and a test that uses it
The agent controls an ibex_icache_ecc_if interface, which is bound
into each prim_badbit_ram_1p module. There's a ton of painful wiring
in the environment to create an agent for each of these interfaces and
connect everything up properly.

By default, these agents don't have associated sequences (so they
don't inject read errors). You can switch them on by setting
enable_ecc_errors on the top-level virtual sequence. The patch adds a
vseq to do so (ibex_icache_ecc_vseq).

Note that we don't currently collect any specific coverage for ECC
checks. We'll probably add some uarch functional coverage points,
which will pick it up in the future, or we'll also pick it up if the
cache gets an alert output.
2020-06-16 09:28:57 +01:00
Rupert Swarbrick
48fbea833f Add and use a 'badbit' RAM for ICache tests
This does nothing by default, just wrapping up a prim_generic_ram_1p.
But we can bind an interface into it to inject bit errors by forcing
the bad_bit_mask signal.

Note that the icache uses ECC RAMs in a reasonably unusual way (ORing
together inputs and outputs from its data RAMs), so we have to do this
ourselves, rather than piggy-backing on the implementation or testing
done for e.g. OpenTitan's prim_ram_1p_adv.
2020-06-16 09:28:57 +01:00
Rupert Swarbrick
8a145a9330 Enable ECC in ICache tests
Eventually we probably want to make this configurable but, for now,
enable it unconditionally.
2020-06-16 09:28:57 +01:00
Rupert Swarbrick
2569a63eb7 Drive the branch_spec line in ICache UVM tests
This signal already got driven (to 1) when signalling a branch with
the interface's branch_to task. This patch now drives the branch_spec
line occasionally even if we don't actually do a branch. (One cycle in
64, for now).
2020-06-16 09:19:30 +01:00
Bert Pieters
632ebcfe86 [ibex/dv] add Questa support
Signed-off-by: Bert Pieters <bert.pieters@gmail.com>
2020-06-15 11:06:21 +01:00
Rupert Swarbrick
ec6e08d1cf Simplify timestamps in ICache tests 2020-06-12 16:15:11 +01:00
Udi
976e7edcda [ibex/dv] Add several PMP tests
Signed-off-by: Udi <udij@google.com>
2020-06-09 12:52:10 -07:00