Skip to content

[hw] rom_ctrl added to mocha#389

Open
KolosKoblasz-Semify wants to merge 6 commits intolowRISC:mainfrom
KolosKoblasz-Semify:kk_rom_ctrl
Open

[hw] rom_ctrl added to mocha#389
KolosKoblasz-Semify wants to merge 6 commits intolowRISC:mainfrom
KolosKoblasz-Semify:kk_rom_ctrl

Conversation

@KolosKoblasz-Semify
Copy link
Copy Markdown
Collaborator

  1. existing source files vendored in
  2. rom_ctrl integrated at topl level, AXI and TL busnetwork extended
  3. new smoketest written for reading rom init values
  4. xbar_peri regenerated include new rom_ctrl_regs TL interface

@KolosKoblasz-Semify KolosKoblasz-Semify marked this pull request as ready for review March 27, 2026 14:55
@KolosKoblasz-Semify KolosKoblasz-Semify changed the title rom_ctrl added to mocha [hw] rom_ctrl added to mocha Mar 30, 2026
Copy link
Copy Markdown
Collaborator

@marnovandermaas marnovandermaas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some initial comments from my end. Please also have a look at the CI failures.

Comment thread hw/top_chip/ip/xbar_peri/xbar_peri.hjson Outdated
Comment thread hw/top_chip/ip/xbar_peri/xbar_peri.hjson Outdated
Comment thread hw/top_chip/ip/xbar_peri/data/autogen/xbar_peri.hjson
Comment thread hw/vendor/lowrisc_ip.vendor.hjson Outdated
Comment thread hw/top_chip/dv/tb/tb.sv Outdated
Comment thread hw/top_chip/rtl/top_pkg.sv Outdated
Comment thread hw/top_chip/rtl/top_chip_system.sv Outdated
Comment thread sw/device/lib/hal/mocha.c Outdated
Comment thread sw/device/lib/hal/rom_ctrl.c Outdated
Comment thread sw/device/tests/rom_ctrl/mem_init_file.vmem
@KolosKoblasz-Semify KolosKoblasz-Semify force-pushed the kk_rom_ctrl branch 3 times, most recently from 71fd63b to e3eebff Compare April 1, 2026 09:23
Copy link
Copy Markdown
Contributor

@ziuziakowska ziuziakowska left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some nits on the software.

Something to consider might also be modelling the ROM as a const char * instead of a void * typedef, as that could prevent writing through the pointer (although I believe that should cause a fault anyway).

Comment thread sw/device/tests/rom_ctrl/smoketest.c Outdated
Comment thread sw/device/lib/hal/rom_ctrl.h Outdated
Comment thread sw/device/lib/hal/CMakeLists.txt Outdated
Comment thread sw/device/tests/rom_ctrl/smoketest.c Outdated
Comment thread sw/device/tests/rom_ctrl/smoketest.c Outdated
Copy link
Copy Markdown
Contributor

@raylau1 raylau1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this, I have added some comment.

Comment thread hw/top_chip/dv/tb/tb.sv Outdated
Comment thread hw/top_chip/dv/verilator/top_chip_verilator.sv Outdated
Comment thread hw/top_chip/dv/verilator/top_chip_verilator.vlt Outdated
Comment thread hw/top_chip/dv/top_chip_sim_cfg.hjson Outdated
Comment thread hw/top_chip/rtl/top_chip_system.sv Outdated
Comment thread hw/top_chip/rtl/top_chip_system.sv Outdated
Comment thread hw/top_chip/rtl/top_chip_system.sv Outdated
Comment thread hw/top_chip/rtl/top_chip_system.sv Outdated
Comment thread hw/top_chip/rtl/top_chip_system.sv Outdated
Comment thread sw/device/tests/CMakeLists.txt Outdated
@KolosKoblasz-Semify KolosKoblasz-Semify force-pushed the kk_rom_ctrl branch 2 times, most recently from e72eb24 to 555b922 Compare April 7, 2026 13:42
@raylau1

This comment was marked as resolved.

@KolosKoblasz-Semify

This comment was marked as resolved.

@raylau1

This comment was marked as resolved.

Copy link
Copy Markdown
Collaborator

@marnovandermaas marnovandermaas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! Some more comments from my end before we can merge this.

Comment thread util/artefacts.py
Comment thread hw/top_chip/ip/xbar_peri/data/autogen/xbar_peri.hjson
Comment thread hw/top_chip/ip/xbar_peri/xbar_peri.hjson Outdated
Comment thread hw/vendor/lowrisc_ip.vendor.hjson Outdated
Comment thread hw/top_chip/dv/tb/tb.sv
Comment thread hw/top_chip/rtl/top_chip_system.sv Outdated
Comment thread hw/top_chip/rtl/top_chip_system.sv Outdated
Comment thread hw/top_chip/rtl/top_chip_system.sv Outdated
Comment thread sw/device/tests/CMakeLists.txt
Comment thread util/verilator_runner.sh Outdated
Copy link
Copy Markdown
Collaborator

@marnovandermaas marnovandermaas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more comments on the software side.

Comment thread sw/device/tests/rom_ctrl/smoketest.c Outdated
Comment thread sw/device/tests/rom_ctrl/smoketest.c Outdated
 * rom_ctrl_regs if added to xbapr_peri cfg
 * kmac vendored in
 * lowrisc_ip.vendor.hjson modified
 * Apply patch on prim_xilinx_rom.sv. Vivado synth failed
   due to string type parameter.
 * axi bus network expanded to handle rom_ctrl data interface
 * xbar_peri module connected to rom_ctrl register interface
 * verilator rule exclusions added
 * Path to ROM init file added to tb.sv
 * clk and reset of the new axi bus and rom_ctrl fixed on top level
 * backdoor access for ROM config added
 * new testcase implemented among top level sw tests
 * the new test reads the compile time initialized ROM values
 * if any comparision fails (expected values differs from read value)
   test is terminated with an error
 * sw test files reformated to complie with clang format
 * fixed issues highlighted during PR review
@KolosKoblasz-Semify
Copy link
Copy Markdown
Collaborator Author

Just some nits on the software.

Something to consider might also be modelling the ROM as a const char * instead of a void * typedef, as that could prevent writing through the pointer (although I believe that should cause a fault anyway).

If we do these changes for rom_ctrl tests then it will be inconsistent with other sw tests like: spi_host, rstmgr, mailbox, etc..
It is also working as is, so I don't think it worth the effort and further delays.

 * xbar_peri IP regenerated with new paths during CI/CD tests
 * ROM backdoor init command added to sw regression tests
 * FPGA tests need ROM initialization to pass
 * RomInitFile argument and init file paths added to the
   nix/fpga.nix script
Copy link
Copy Markdown
Contributor

@raylau1 raylau1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding all the fixes! I found a few small issues with DV and software, otherwise should be ready to merge.

Comment on lines 309 to +312
name: rom_ctrl
tests: [
"rom_ctrl_integrity_check"
"rom_ctrl_integrity_check",
"rom_ctrl_smoke"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rom_ctrl_smoke_cheri should be added to the rom_ctrl tests

Comment thread sw/device/lib/hal/mocha.h
Comment on lines +39 to +40
rom_t mocha_system_rom(void);
rom_ctrl_t mocha_system_rom_ctrl(void);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is sorted in order of memory map, mocha_system_rom should be before mailbox and mocha_system_rom_ctrl between rstmgr and uart

#include "hal/mocha.h"
#include <stdint.h>

/* Read specific word_idx-th word from ROM memory */
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment seems outdated, there is no word_idx argument and rel_addr specifies a byte offset

Comment on lines +54 to +62
bool test_main()
{
rom_t rom = mocha_system_rom();
uart_t console = mocha_system_uart();

uart_init(console);

return rom_read_test(rom, console);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to reinitialize UART, you can get the console handle with:

bool test_main(uart_t console)
{
    ...
}

Comment on lines 252 to 257
"mailbox_smoke",
"mailbox_smoke_cheri",
"axi_sram_smoke",
"axi_sram_smoke_cheri",
"axi_sram_smoke_cheri"
]
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rom_ctrl_smoke and rom_ctrl_smoke_cheri should be added to the smoke regression tests. Also do not remove the comma if it is not necessary.

Copy link
Copy Markdown
Collaborator

@marnovandermaas marnovandermaas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few more comments from my end. Would you mind checking that all your lint rules are necessary? It looks like your disabling more than you need to still, which is undesirable.

: _sram(sram_hier_path, sram_size_words, 8),
_dram(dram_hier_path, dram_size_words, 8) {}
_dram(dram_hier_path, dram_size_words, 8),
_rom("TOP.top_chip_verilator.u_top_chip_system.u_rom_ctrl.gen_rom_scramble_disabled.u_rom.u_prim_rom", 8192, 4) {}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add rom_hier_path and rom_size_words in here.

lint_off -rule UNUSEDSIGNAL -file "*/rom_ctrl.sv" -match "*kmac_rom_last_outer*"
lint_off -rule UNDRIVEN -file "*/rom_ctrl.sv" -match "*kmac_rom_last_outer*"
lint_off -rule UNUSEDSIGNAL -file "*/rom_ctrl.sv" -match "*kmac_err*"
lint_off -rule UNDRIVEN -file "*/rom_ctrl.sv" -match "*kmac_err*"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure about this undriven?

assign kmac_data_o = '0;
assign kmac_rom_rdy_outer = 1'b0;
assign kmac_done = 1'b0;
assign kmac_digest = '0;
assign kmac_err = 1'b0;

lint_off -rule UNUSEDSIGNAL -file "*/rom_ctrl.sv" -match "*kmac_rom_rdy*"
lint_off -rule UNDRIVEN -file "*/rom_ctrl.sv" -match "*kmac_rom_rdy*"
lint_off -rule UNUSEDSIGNAL -file "*/rom_ctrl.sv" -match "*kmac_rom_rdy_outer*"
lint_off -rule UNDRIVEN -file "*/rom_ctrl.sv" -match "*kmac_rom_rdy_outer*"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure about this undriven?

assign kmac_data_o = '0;
assign kmac_rom_rdy_outer = 1'b0;
assign kmac_done = 1'b0;
assign kmac_digest = '0;
assign kmac_err = 1'b0;


// rom_ctrl.sv
lint_off -rule UNUSEDSIGNAL -file "*/rom_ctrl.sv" -match "*checker_rom_rdata*"
lint_off -rule UNDRIVEN -file "*/rom_ctrl.sv" -match "*checker_rom_rdata*"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure about this undriven?

.chk_rdata_o (checker_rom_rdata),

lint_off -rule UNDRIVEN -file "*/rom_ctrl.sv" -match "*checker_rom_rdata*"
lint_off -rule UNUSEDSIGNAL -file "*/rom_ctrl.sv" -match "*checker_rom_rdata_outer*"
lint_off -rule UNDRIVEN -file "*/rom_ctrl.sv" -match "*checker_rom_rdata_outer*"
lint_off -rule UNUSEDSIGNAL -file "*/rom_ctrl.sv" -match "*kmac_rom_rdy*"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure about this unused?

assign unused_fsm_inputs = ^{kmac_rom_rdy, kmac_done, kmac_digest, digest_q, exp_digest_q};

lint_off -rule WIDTHTRUNC -file "*/lowrisc_prim_count_0/rtl/prim_count.sv"

// rom_ctrl.sv
lint_off -rule UNUSEDSIGNAL -file "*/rom_ctrl.sv" -match "*checker_rom_rdata*"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind changing all of these files to "*/rom_ctrl/src/rom_ctrl.sv"

Copy link
Copy Markdown
Collaborator

@marnovandermaas marnovandermaas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to create an empty commit?

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants