Software APIs
rv_core_ibex_icache_invalidate_test.c
1 // Copyright lowRISC contributors (OpenTitan project).
2 // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3 // SPDX-License-Identifier: Apache-2.0
4 
7 #include "sw/device/lib/testing/test_framework/check.h"
9 
10 // Initialize OTTF.
11 OTTF_DEFINE_TEST_CONFIG();
12 
13 // Number of instruction cache invalidations. This gets overwritten by the
14 // vseq via the backdoor symbol overwrite mechanism and thus must be declared
15 // `static volatile`. The default value applies to non-DV runs, though.
16 static volatile const uint8_t kNumIcacheInvals = 7;
17 
18 bool test_main(void) {
19  // Ensure that the instruction cache will get invalidated at least two times.
20  CHECK(kNumIcacheInvals >= 2);
21 
22  // Invalidate instruction cache multiple times.
23  for (unsigned i = 0; i < kNumIcacheInvals; i++) {
25 
26  uint32_t cpuctrlsts;
27  // Check that the icache scramble key is no longer valid.
28  CSR_READ(CSR_REG_CPUCTRL, &cpuctrlsts);
29  CHECK((cpuctrlsts & (1 << 8)) == 0);
30 
31  // Wait for the icache scramble key to become valid before requesting the
32  // next invalidation.
33  do {
34  CSR_READ(CSR_REG_CPUCTRL, &cpuctrlsts);
35  } while ((cpuctrlsts & (1 << 8)) == 0);
36  }
37 
38  return true;
39 }