opentitan icon indicating copy to clipboard operation
opentitan copied to clipboard

[all] need C/Rust register definitions for all releases and ToT

Open vsukhoml opened this issue 5 years ago • 4 comments

OpenTitan evolves quickly and some registers are changing as a result. This complicates driver development as registers have to be reviewed with every sync. To support development of firmware solutions for OT we need to export register definitions, starting addresses into something which can be directly consumed by C and Rust. Acceptable forms would defining constants for component's base address and either offsets or structs for each register and field. It is desirable to make it easier for use with Rust (TockOS), but C should also be covered. TockOS as an example provides it's way to detailed register specification using library https://github.com/tock/tock/tree/master/libraries/tock-register-interface. Defining structs is a bit more preferable than defining offsets of registers as it typically results in more efficient code generation - compiler can compute offset from already loaded in register base address rather than loading constant again (may change with better compiler).

vsukhoml avatar Sep 20 '21 21:09 vsukhoml

CC @arunthomas

msfschaffner avatar Mar 08 '22 06:03 msfschaffner

I was under the impression regtool addressed this issue?

domrizz0 avatar Mar 17 '22 13:03 domrizz0

Afaik, our regtool can generate such headers for both C and Rust. @timothytrippel / @drewmacrae can you maybe point @vsukhoml to the appropriate command or build rule in meson / bazel?

msfschaffner avatar Mar 23 '22 22:03 msfschaffner

Meson build rules that invoke reggen are here. Note meson only builds C headers for now, and we probably won't expand this since we are transitioning to bazel soon.

Custom Bazel rule that invokes reggen is here, and the instantiations of that rule are within each IP's data dir, e.g., for the adc_ctrl see here. Similarly, bazel only builds C headers for now, but this rule can be expanded to generate Rust constants too (just different flags to pass to reggen).

To build an individual IP's autogenerated C header you can use bazel build //hw/ip/adc_ctrl/data:adc_ctrl_regs.

To batch generate all the header files for all IPs, you can just use the makefile in hw/, by running make -C hw regs-rust for Rust and make -C hw regs-header for C headers.

timothytrippel avatar Mar 23 '22 22:03 timothytrippel