Skip to content

[hw] rom_ctrl added to mocha#389

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

[hw] rom_ctrl added to mocha#389
KolosKoblasz-Semify wants to merge 5 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.

},
{ name: "rom_ctrl_regs", // Rom_ctrl_regs
type: "device",
clock: "clk_io_i",
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.

This should be clk_main_i

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

{ name: "rom_ctrl_regs", // Rom_ctrl_regs
type: "device",
clock: "clk_io_i",
reset: "rst_io_ni",
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.

This should be rst_main_ni

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

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.

Why did you move this file?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The .hjson file is relocated now because I found counter intuitive to store the "source" file for IP generation in the generated folder.

Comment on lines +33 to +34
{from: "hw/ip/rom_ctrl", to: "ip/rom_ctrl", patch_dir: "rom_ctrl"}, // ROM Control.
{from: "hw/ip/kmac", to: "ip/kmac", patch_dir: "kmac"}, // kmac.
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.

Adding the patch directories should be in the same commit as where you add them to the vendor.hjson file.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed. IPs and vendoring script committed at the same time

top_chip_system #() dut (
top_chip_system # (
.SramInitFile(""),
.BootRomInitFile("sw/device/tests/rom_ctrl/mem_init_file.vmem")
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.

Nit: RomInitFile

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

Comment on lines +1017 to +1022
// Inter-module signals
.rom_cfg_i ('0), // TO DO: What goes here?
.pwrmgr_data_o (), // TO DO: What goes here?
.keymgr_data_o (), // TO DO: What goes here?
.kmac_data_o (), // TO DO: What goes here?
.kmac_data_i ('0), // TO DO: What goes here?
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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Wired up unconnected ports with signals.

rom_t mocha_system_rom(void)
{
#if defined(__riscv_zcherihybrid)
return (uart_t)create_mmio_capability(rom_base, 0x48u);
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.

The second argument should be the size of the ROM which is 32 KiB.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

Comment on lines +13 to +17
uint32_t res;

res = DEV_READ(rom + 4*word_idx);

return res;
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.

Nit: just return the DEV_READ.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

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.

It might be good to put some data in the middle and at the end of ROM as well to test the edges out.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Date put at the beginning, middle and end sections of the ROM. rom_ctrl_smoketest revised to test all relevant address ranges.

 * rom_ctrl_regs if added to xbapr_peri cfg
 * kmac vendored in
 * lowrisc_ip.vendor.hjson modified
 * 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
 * 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 compplie with clang format
 * util/artifacts.py regenrates the xbar_peri files and it needs
   correct paths pointing at the .hjson cfg file and the output
   directory
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 on lines +55 to +62
bool read_test_res;

uart_init(console);

read_test_res = rom_read_test(rom, console);

return read_test_res;
}
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.

Nit: Just return rom_read_test(...)

Comment on lines +16 to +17
#define ROM_CTRL_FROM_BASE_ADDR(addr) ((rom_ctrl_t)(addr))
#define ROM_FROM_BASE_ADDR(addr) ((rom_t)(addr))
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.

Nit: These macros are unused, create_mmio_capability and casting is preferred.

# SPDX-License-Identifier: Apache-2.0

set(SRCS clkmgr.c gpio.c i2c.c mailbox.c mocha.c plic.c rstmgr.c spi_device.c timer.c uart.c)
set(SRCS clkmgr.c gpio.c i2c.c mailbox.c mocha.c plic.c rstmgr.c spi_device.c timer.c uart.c rom_ctrl.c)
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.

Nit: Should be between plic and rstmgr.

uint8_t data_length = 4;

// ROM Address values
const uint32_t expected_addresses[3] = { 0x00000000, 0x00004000, 0x00007FF0 };
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.

Nit: I would call this just addresses.

Comment on lines +32 to +33
for (uint8_t address_idx = 0; address_idx < address_length; address_idx++) {
for (uint8_t word_idx = 0; word_idx < data_length; word_idx++) {
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.

In builtin.h we have an ARRAY_LEN macro to get the lengths of static arrays.

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.

3 participants