lowRISC / lowRISC/mocha

[RFC] Use Opentitan DIF API

Open
#583 1 comment 0 reactions 1 assignee View on GitHub

@engdoreis is already working on this.

Since May 28, 2026.

Dominant language
SystemVerilog
Stars
38
Forks
21
Avg merge
2d 23h
Merged PRs (30d)
14

Description

Like the OpenTitan DIFs, the Mocha HAL drivers are not production-ready; they are intended strictly for testing and design verification.

Therefore, to avoid reinventing the wheel and prolonging discussions on PRs regarding the "best" interface, I suggest we copy the DIF functions from OpenTitan for all OpenTitan IPs and replace their MMIO calls with the auto-generated Mocha structs.

This will also reduce the effort of porting the OpenTitan top level tests to Mocha.

This is an example of a porting of a opentitan DIF function.

dif_result_t dif_spi_host_output_set_enabled(const dif_spi_host_t *spi_host,
                                             bool enabled) {
  if (spi_host == NULL) {
    return kDifBadArg;
  }

  uint32_t reg =
      mmio_region_read32(spi_host->base_addr, SPI_HOST_CONTROL_REG_OFFSET);
  mmio_region_write32(
      spi_host->base_addr, SPI_HOST_CONTROL_REG_OFFSET,
      bitfield_bit32_write(reg, SPI_HOST_CONTROL_OUTPUT_EN_BIT, enabled));

  return kDifOk;
}

Ported to Mocha:

mocha_result spi_host_output_set_enabled(spi_host_t spi_host, bool enabled) {
    spi_host_control reg = VOLATILE_READ(spi_host->control);
    reg.output_en = enabled;
    VOLATILE_WRITE(spi_host->control, reg);
    return kMochaOk;
}

This would make the review process easier. The reviewer would not need to question whether the API makes sense (since it's already well-tested), but would instead focus on ensuring that the implementation is correct for Mocha.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.