Skip to content

Conversation

@rivos-eblot
Copy link

@rivos-eblot rivos-eblot commented Oct 30, 2025

This PR generalizes OTP implementation, so that code is no longer duplicated for each top.

Most of the code is now implemented in a new component OtOTPEngineState (ot_otp_engine.c) which contains over 4/5 of the duplicated code that used to exist in ot_otp_eg.c and ot_otp_dj.c files.

Those two latter files now only contain what is specific to each Top:

  • register definitions (IO regs and SW CFG regs) + their reset values
  • partition definitions
  • key seed definition
  • HW cfg exposed to other "HW" clients
  • LC controller tokens
  • some lightweight glue logic

Some note about the interfaces/classes:

  • OtOTPIf(Class) interface exposes the public interface of the OTP, i.e. the API that other OpenTitan "HW" devices can use to communicate with the OTP
  • OtOTPImplIf(Class) interface exposes the semi- private interface that a top-specific OTP implementation exposes to the OtOTPEngineState
  • OtOtpBeIf(Class) interface exposes the public interface of an OTP backend, which describes the characteristics of a specific backend. Note that ideally, this component should manage the QEMU OTP image file, which is not (yet) the case.
  • OtOTPEngineState/Class implements the whole OTP emulation. It is an abstract class whose concrete implementation is Top-specific.
  • OtOTPEgState/Class and OtOTPDjState/Class are two concrete implementations of OtOTPEngineState/Class. Each implements the implements the OtOTPIf interface which is exposed to the OTP clients, and implement the OtOTPImplIf to provide the features required by their abstract class OtOTPEngineState/Class.

@rivos-eblot rivos-eblot force-pushed the dev/ebl/otp_unify branch 2 times, most recently from 8494dad to 56b1a5e Compare October 31, 2025 14:24
Copy link

@AlexJones0 AlexJones0 left a comment

Choose a reason for hiding this comment

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

Partial review (reviewed up to the "merge OTP implementation" commit, and I only looked at the ot_otp_engine.h and ot_otp_{dj,eg}_parts.c files in that commit so far).

@rivos-eblot rivos-eblot force-pushed the dev/ebl/otp_unify branch 2 times, most recently from b588e1b to 5e0c13a Compare October 31, 2025 17:11
Disable all LLVM rules as they hard-code paths from LLVM project.

llvm-header-guard therefore suggests to replace header guard path with
the full absolute path of the current local check out directory path!

It appears that llvm-* rules are only to be used for the LLVM project
itself, but they are nevertheless automatically added with the default
`*` wildcard...

Signed-off-by: Emmanuel Blot <[email protected]>
- move partition names to the OtOTPPartDesc array
- allocate arrays of string properties and their matching byte values at runtime,
- rename partition-related variables, as several new variables are added
- replace statically defined constants with dynamic variables
- clean up

Signed-off-by: Emmanuel Blot <[email protected]>
- move partition names to the OtOTPPartDesc array
- allocate arrays of string properties and their matching byte values at runtime,
- rename partition-related variables, as several new variables are added
- replace statically defined constants with dynamic variables
- clean up

Signed-off-by: Emmanuel Blot <[email protected]>
…erface.

This is the second step towards unification of OtOTP* implementations.

It is better to expose the OtOTPState feature as an interface, so that OtOTPState
can later implement the common feature for all OtOTP Top-specialized implementation.

Signed-off-by: Emmanuel Blot <[email protected]>
@rivos-eblot rivos-eblot marked this pull request as ready for review October 31, 2025 17:36
@rivos-eblot rivos-eblot force-pushed the dev/ebl/otp_unify branch 2 times, most recently from 1aadd5c to d7b4ee4 Compare October 31, 2025 18:09
Copy link

@AlexJones0 AlexJones0 left a comment

Choose a reason for hiding this comment

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

Thanks, this LGTM once my remaining comments are addressed. With a PR this large I will probably have missed a few things but all the Earlgrey OTP tests I have are passing for me, so there are no obvious regressions at least.

@rivos-eblot
Copy link
Author

Thanks, this LGTM once my remaining comments are addressed. With a PR this large I will probably have missed a few things but all the Earlgrey OTP tests I have are passing for me, so there are no obvious regressions at least.

Thanks for the reviews.

Copy link

@loiclefort loiclefort left a comment

Choose a reason for hiding this comment

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

LGTM

… Darjeeling

- merge and adapt common code into OtOTPEngine
- keep only OTP top-specific implementation in ot_otp_eg.c and ot_otp_dj.c,
  which implement the OtOTPImplIf interface (specialization for Tops)
- regenerate OTP partition descriptions and key seed definition with otptool.py

Signed-off-by: Emmanuel Blot <[email protected]>
- use Top defined constants
- simplify stack of macro calls
- remove definitions from ot_otp_engine.h

Signed-off-by: Emmanuel Blot <[email protected]>
…ctory

This is needed to implement other OTP top-specific implementations.

Signed-off-by: Emmanuel Blot <[email protected]>
…rties

- secret_scrambling_keys: the exact number of such properties is created.
  this avoid allocated useless memory, and ensure QEMU property subsystem
  may report any attempt to define values for keys that do not exist

- secret_scrambling_key and inv_default_data values are now tied to the
  partition controller, rather than to be allocated as separate arrays

Signed-off-by: Emmanuel Blot <[email protected]>
Should start with OT_OTP, OtOtp, ot_otp to prevent from unexpected conflicts

Signed-off-by: Emmanuel Blot <[email protected]>
@rivos-eblot rivos-eblot merged commit cb53468 into lowRISC:ot-9.2.0 Nov 4, 2025
9 of 10 checks passed
@rivos-eblot rivos-eblot deleted the dev/ebl/otp_unify branch November 4, 2025 07:50
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