[dif/entropy_src] fix incorrect DIF naming convention
This fixes #7823 by renaming all entropy_src DIFs with the correct
prefix of "dif_entropy_src_" instead of "dif_entropy_", to match the IP
block's name of "entropy_src".
Signed-off-by: Timothy Trippel <ttrippel@google.com>
diff --git a/sw/device/lib/dif/dif_csrng_unittest.cc b/sw/device/lib/dif/dif_csrng_unittest.cc
index e1259d8..3494da0 100644
--- a/sw/device/lib/dif/dif_csrng_unittest.cc
+++ b/sw/device/lib/dif/dif_csrng_unittest.cc
@@ -13,7 +13,7 @@
#include "csrng_regs.h" // Generated
-namespace dif_entropy_unittest {
+namespace dif_csrng_unittest {
namespace {
using ::testing::ElementsAreArray;
@@ -293,4 +293,4 @@
}
} // namespace
-} // namespace dif_entropy_unittest
+} // namespace dif_csrng_unittest
diff --git a/sw/device/lib/dif/dif_entropy.c b/sw/device/lib/dif/dif_entropy_src.c
similarity index 66%
rename from sw/device/lib/dif/dif_entropy.c
rename to sw/device/lib/dif/dif_entropy_src.c
index 5425f4a..0098ab1 100644
--- a/sw/device/lib/dif/dif_entropy.c
+++ b/sw/device/lib/dif/dif_entropy_src.c
@@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
-#include "sw/device/lib/dif/dif_entropy.h"
+#include "sw/device/lib/dif/dif_entropy_src.h"
#include <stddef.h>
@@ -15,8 +15,8 @@
* Sets the `entropy` source configuration register with the settings
* derived from `config`.
*/
-static void set_config_register(const dif_entropy_t *entropy,
- const dif_entropy_config_t *config) {
+static void set_config_register(const dif_entropy_src_t *entropy,
+ const dif_entropy_src_config_t *config) {
// TODO: Make this configurable at the API level.
// TODO: Currently bypass disable cannot be set, as it causes the hw fsm to
// get stuck
@@ -26,19 +26,21 @@
// Configure test cases
reg = bitfield_bit32_write(reg, ENTROPY_SRC_CONF_REPCNT_DISABLE_BIT,
- !config->tests[kDifEntropyTestRepCount]);
- reg = bitfield_bit32_write(reg, ENTROPY_SRC_CONF_ADAPTP_DISABLE_BIT,
- !config->tests[kDifEntropyTestAdaptiveProportion]);
+ !config->tests[kDifEntropySrcTestRepCount]);
+ reg = bitfield_bit32_write(
+ reg, ENTROPY_SRC_CONF_ADAPTP_DISABLE_BIT,
+ !config->tests[kDifEntropySrcTestAdaptiveProportion]);
reg = bitfield_bit32_write(reg, ENTROPY_SRC_CONF_BUCKET_DISABLE_BIT,
- !config->tests[kDifEntropyTestBucket]);
+ !config->tests[kDifEntropySrcTestBucket]);
reg = bitfield_bit32_write(reg, ENTROPY_SRC_CONF_MARKOV_DISABLE_BIT,
- !config->tests[kDifEntropyTestMarkov]);
+ !config->tests[kDifEntropySrcTestMarkov]);
reg = bitfield_bit32_write(reg, ENTROPY_SRC_CONF_HEALTH_TEST_CLR_BIT,
config->reset_health_test_registers);
reg = bitfield_bit32_write(reg, ENTROPY_SRC_CONF_EXTHT_ENABLE_BIT, 0);
// Configure single RNG bit mode
- bool rng_bit_en = config->single_bit_mode != kDifEntropySingleBitModeDisabled;
+ bool rng_bit_en =
+ config->single_bit_mode != kDifEntropySrcSingleBitModeDisabled;
reg = bitfield_bit32_write(reg, ENTROPY_SRC_CONF_RNG_BIT_EN_BIT, rng_bit_en);
uint32_t rng_bit_sel = rng_bit_en ? config->single_bit_mode : 0;
@@ -52,26 +54,26 @@
reg);
}
-dif_entropy_result_t dif_entropy_init(dif_entropy_params_t params,
- dif_entropy_t *entropy) {
+dif_entropy_src_result_t dif_entropy_src_init(dif_entropy_src_params_t params,
+ dif_entropy_src_t *entropy) {
if (entropy == NULL) {
- return kDifEntropyBadArg;
+ return kDifEntropySrcBadArg;
}
- *entropy = (dif_entropy_t){.params = params};
- return kDifEntropyOk;
+ *entropy = (dif_entropy_src_t){.params = params};
+ return kDifEntropySrcOk;
}
-dif_entropy_result_t dif_entropy_configure(const dif_entropy_t *entropy,
- dif_entropy_config_t config) {
+dif_entropy_src_result_t dif_entropy_src_configure(
+ const dif_entropy_src_t *entropy, dif_entropy_src_config_t config) {
if (entropy == NULL) {
- return kDifEntropyBadArg;
+ return kDifEntropySrcBadArg;
}
if (config.lfsr_seed > ENTROPY_SRC_SEED_LFSR_SEED_MASK) {
- return kDifEntropyBadArg;
+ return kDifEntropySrcBadArg;
}
- uint32_t seed = config.mode == kDifEntropyModeLfsr ? config.lfsr_seed : 0;
+ uint32_t seed = config.mode == kDifEntropySrcModeLfsr ? config.lfsr_seed : 0;
mmio_region_write32(entropy->params.base_addr, ENTROPY_SRC_SEED_REG_OFFSET,
seed);
@@ -93,33 +95,34 @@
ENTROPY_SRC_FW_OV_CONTROL_REG_OFFSET, 0);
set_config_register(entropy, &config);
- return kDifEntropyOk;
+ return kDifEntropySrcOk;
}
-static bool get_entropy_avail(const dif_entropy_t *entropy) {
+static bool get_entropy_avail(const dif_entropy_src_t *entropy) {
return mmio_region_get_bit32(entropy->params.base_addr,
ENTROPY_SRC_INTR_STATE_REG_OFFSET,
ENTROPY_SRC_INTR_STATE_ES_ENTROPY_VALID_BIT);
}
-dif_entropy_result_t dif_entropy_avail(const dif_entropy_t *entropy) {
+dif_entropy_src_result_t dif_entropy_src_avail(
+ const dif_entropy_src_t *entropy) {
if (entropy == NULL) {
- return kDifEntropyBadArg;
+ return kDifEntropySrcBadArg;
}
- return get_entropy_avail(entropy) ? kDifEntropyOk
- : kDifEntropyDataUnAvailable;
+ return get_entropy_avail(entropy) ? kDifEntropySrcOk
+ : kDifEntropySrcDataUnAvailable;
}
-dif_entropy_result_t dif_entropy_read(const dif_entropy_t *entropy,
- uint32_t *word) {
+dif_entropy_src_result_t dif_entropy_src_read(const dif_entropy_src_t *entropy,
+ uint32_t *word) {
if (entropy == NULL || word == NULL) {
- return kDifEntropyBadArg;
+ return kDifEntropySrcBadArg;
}
// Check if entropy is available
if (!get_entropy_avail(entropy)) {
- return kDifEntropyDataUnAvailable;
+ return kDifEntropySrcDataUnAvailable;
}
*word = mmio_region_read32(entropy->params.base_addr,
@@ -131,13 +134,14 @@
ENTROPY_SRC_INTR_STATE_REG_OFFSET,
ENTROPY_SRC_INTR_STATE_ES_ENTROPY_VALID_BIT);
- return kDifEntropyOk;
+ return kDifEntropySrcOk;
}
-dif_entropy_result_t dif_entropy_disable(const dif_entropy_t *entropy) {
+dif_entropy_src_result_t dif_entropy_src_disable(
+ const dif_entropy_src_t *entropy) {
// TODO: should first check if entropy is locked and return error if it is.
mmio_region_write32(entropy->params.base_addr, ENTROPY_SRC_CONF_REG_OFFSET,
0);
- return kDifEntropyOk;
+ return kDifEntropySrcOk;
}
diff --git a/sw/device/lib/dif/dif_entropy.h b/sw/device/lib/dif/dif_entropy_src.h
similarity index 69%
rename from sw/device/lib/dif/dif_entropy.h
rename to sw/device/lib/dif/dif_entropy_src.h
index 44fc894..9417082 100644
--- a/sw/device/lib/dif/dif_entropy.h
+++ b/sw/device/lib/dif/dif_entropy_src.h
@@ -2,8 +2,8 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
-#ifndef OPENTITAN_SW_DEVICE_LIB_DIF_DIF_ENTROPY_H_
-#define OPENTITAN_SW_DEVICE_LIB_DIF_DIF_ENTROPY_H_
+#ifndef OPENTITAN_SW_DEVICE_LIB_DIF_DIF_ENTROPY_SRC_H_
+#define OPENTITAN_SW_DEVICE_LIB_DIF_DIF_ENTROPY_SRC_H_
/**
* @file
@@ -25,7 +25,7 @@
* Maximum pre-conditioning FIFO capacity.
*/
// TODO: Synchronize value with hardware.
- kDifEntropyFifoMaxCapacity = 64,
+ kDifEntropySrcFifoMaxCapacity = 64,
};
/**
@@ -34,21 +34,21 @@
* This enum may be used instead of a `bool` when describing an enabled/disabled
* state.
*/
-typedef enum dif_entropy_toggle {
+typedef enum dif_entropy_src_toggle {
/*
* The "enabled" state.
*/
- kDifEntropyToggleEnabled,
+ kDifEntropySrcToggleEnabled,
/**
* The "disabled" state.
*/
- kDifEntropyToggleDisabled,
-} dif_entropy_toggle_t;
+ kDifEntropySrcToggleDisabled,
+} dif_entropy_src_toggle_t;
/**
* A statistical test on the bits emitted by an entropy source.
*/
-typedef enum dif_entropy_test {
+typedef enum dif_entropy_src_test {
/**
* An SP 800-90B repetition count test.
*
@@ -56,7 +56,7 @@
* This test fails if any sequence of bits repeats too many times in a row
* for too many samples.
*/
- kDifEntropyTestRepCount,
+ kDifEntropySrcTestRepCount,
/**
* An SP 800-90B adaptive proportion test.
@@ -64,14 +64,14 @@
* This test screens for statistical bias in the number of ones or zeros
* output by the noise source.
*/
- kDifEntropyTestAdaptiveProportion,
+ kDifEntropySrcTestAdaptiveProportion,
/**
* A bucket test.
*
* This test looks for correlations between individual noise channels.
*/
- kDifEntropyTestBucket,
+ kDifEntropySrcTestBucket,
/**
* A "Markov" test.
@@ -79,7 +79,7 @@
* This test looks for unexpected first-order temporal correlations
* between individual noise channels.
*/
- kDifEntropyTestMarkov,
+ kDifEntropySrcTestMarkov,
/**
* A firmware-driven "mailbox" test.
@@ -87,25 +87,25 @@
* This test allows firmware to inspect 2kbit blocks of entropy, and signal
* potential concerns to the hardware.
*/
- kDifEntropyTestMailbox,
+ kDifEntropySrcTestMailbox,
/**
* A vendor-specific test implemented externally to the IP.
*/
- kDifEntropyTestVendorSpecific,
+ kDifEntropySrcTestVendorSpecific,
/** \internal */
- kDifEntropyTestNumVariants,
-} dif_entropy_test_t;
+ kDifEntropySrcTestNumVariants,
+} dif_entropy_src_test_t;
/**
* A mode of operation for the entropy source.
*/
-typedef enum dif_entropy_mode {
+typedef enum dif_entropy_src_mode {
/**
* Indicates that the source is disabled.
*/
- kDifEntropyModeDisabled = 0,
+ kDifEntropySrcModeDisabled = 0,
/**
* The physical true random number generator mode.
@@ -113,7 +113,7 @@
* This mode uses a physical random noise generator for operation, and is
* truly random. This noise generator is compatible with SP 800-90B.
*/
- kDifEntropyModePtrng = 1,
+ kDifEntropySrcModePtrng = 1,
/**
* The Linear Feedback Shift Register (LFSR) mode.
@@ -121,43 +121,43 @@
* This mode is digital, and as such is only pseudo-random and intended
* for test purposes only.
*
- * In this mode, the `dif_entropy_config.lfsr_seed` value is used to
+ * In this mode, the `dif_entropy_src_config.lfsr_seed` value is used to
* initialize the internal state of the LFSR.
*/
- kDifEntropyModeLfsr = 2,
-} dif_entropy_mode_t;
+ kDifEntropySrcModeLfsr = 2,
+} dif_entropy_src_mode_t;
/**
* A single-bit RNG mode, where only one bit is sampled.
*/
-typedef enum dif_entropy_single_bit_mode {
+typedef enum dif_entropy_src_single_bit_mode {
/**
* Single-bit-mode, sampling the zeroth bit.
*/
- kDifEntropySingleBitMode0 = 0,
+ kDifEntropySrcSingleBitMode0 = 0,
/**
* Single-bit-mode, sampling the first bit.
*/
- kDifEntropySingleBitMode1 = 1,
+ kDifEntropySrcSingleBitMode1 = 1,
/**
* Single-bit-mode, sampling the second bit.
*/
- kDifEntropySingleBitMode2 = 2,
+ kDifEntropySrcSingleBitMode2 = 2,
/**
* Single-bit-mode, sampling the third bit.
*/
- kDifEntropySingleBitMode3 = 3,
+ kDifEntropySrcSingleBitMode3 = 3,
/**
* Indicates that single-bit-mode is disabled.
*/
- kDifEntropySingleBitModeDisabled = 4,
-} dif_entropy_single_bit_mode_t;
+ kDifEntropySrcSingleBitModeDisabled = 4,
+} dif_entropy_src_single_bit_mode_t;
/**
* Criteria used by various entropy source health tests to decide whether the
* test has failed.
*/
-typedef struct dif_entropy_test_config {
+typedef struct dif_entropy_src_test_config {
/**
* The size of the window to use for health tests, in bits.
*/
@@ -196,7 +196,7 @@
* threshold. However, vendors may interpret these values however they wish.
*/
uint16_t vendor_range[2];
-} dif_entropy_test_config_t;
+} dif_entropy_src_test_config_t;
/**
* Hardware instantiation parameters for an entropy source.
@@ -205,12 +205,12 @@
* not determined until the hardware design is used as part of a top-level
* design.
*/
-typedef struct dif_entropy_params {
+typedef struct dif_entropy_src_params {
/**
* The base address for the entropy source hardware registers.
*/
mmio_region_t base_addr;
-} dif_entropy_params_t;
+} dif_entropy_src_params_t;
/**
* Runtime configuration for an entropy source.
@@ -218,22 +218,22 @@
* This struct describes runtime information for one-time configuration of the
* hardware.
*/
-typedef struct dif_entropy_config {
+typedef struct dif_entropy_src_config {
/**
* The mode to configure the entropy source in.
*/
- dif_entropy_mode_t mode;
+ dif_entropy_src_mode_t mode;
/**
* Which health tests to enable.
*
- * The variants of `dif_entropy_test` are used to index fields in this
+ * The variants of `dif_entropy_src_test` are used to index fields in this
* array.
*
- * Note that the value at `kDifEntropyTestMailbox` is ignored, since this test
- * is driven by the firmware, not the hardware.
+ * Note that the value at `kDifEntropySrcTestMailbox` is ignored, since this
+ * test is driven by the firmware, not the hardware.
*/
- bool tests[kDifEntropyTestNumVariants];
+ bool tests[kDifEntropySrcTestNumVariants];
/**
* If set, all health-test-related registers will be cleared.
@@ -245,7 +245,7 @@
/**
* Specifies which single-bit-mode to use, if any at all.
*/
- dif_entropy_single_bit_mode_t single_bit_mode;
+ dif_entropy_src_single_bit_mode_t single_bit_mode;
/**
* If set, entropy will be routed to a firmware-visible register instead of
@@ -268,7 +268,7 @@
/**
* Configuration parameters for health tests.
*/
- dif_entropy_test_config_t test_config;
+ dif_entropy_src_test_config_t test_config;
/**
* The rate at which the entropy bits are generated, in clock cycles.
@@ -277,10 +277,10 @@
/**
* Seed used to load into the LFSR initial state. The maximum allowable value
- * is 15. See `dif_entropy_mode.kDifEntropyModeLfsr` for more details.
+ * is 15. See `dif_entropy_src_mode.kDifEntropySrcModeLfsr` for more details.
*/
uint16_t lfsr_seed;
-} dif_entropy_config_t;
+} dif_entropy_src_config_t;
/**
* A handle to an entropy source.
@@ -288,24 +288,24 @@
* This type should be treated as opaque by users.
*/
typedef struct dif_entropy {
- dif_entropy_params_t params;
-} dif_entropy_t;
+ dif_entropy_src_params_t params;
+} dif_entropy_src_t;
/**
* Revision information for an entropy source.
*
* The fields of this struct have an implementation-specific interpretation.
*/
-typedef struct dif_entropy_revision {
+typedef struct dif_entropy_src_revision {
uint8_t abi_revision;
uint8_t hw_revision;
uint8_t chip_type;
-} dif_entropy_revision_t;
+} dif_entropy_src_revision_t;
/**
* Statistics on entropy source health tests.
*/
-typedef struct dif_entropy_test_stats {
+typedef struct dif_entropy_src_test_stats {
/**
* Watermarks indicating where the value emitted by a particular test has
* ranged through; the low watermark is the lowest observed value, while the
@@ -314,7 +314,7 @@
* Each pair of watermarks is presented as a range from lowest to highest.
*/
// TODO: Document behavior for repcnt and bucket tests.
- uint16_t watermarks[2][kDifEntropyTestNumVariants];
+ uint16_t watermarks[2][kDifEntropySrcTestNumVariants];
/**
* The number of times a particular test has failed.
@@ -325,98 +325,99 @@
* first array element will be zeroed, and the second will be the number
* of fails.
*
- * For `dif_entropy_test.kDifEntropyTestRepCount` and
- * `dif_entropy_test.kDifEntropyTestBucket` the first array element will
- * be the number of fails, and the second will be zeroed.
+ * For `dif_entropy_src_test.kDifEntropySrcTestRepCount` and
+ * `dif_entropy_src_test.kDifEntropySrcTestBucket` the first array element
+ * will be the number of fails, and the second will be zeroed.
*/
- uint32_t fails[2][kDifEntropyTestNumVariants];
+ uint32_t fails[2][kDifEntropySrcTestNumVariants];
/**
* The number of alerts emitted by a particular test.
*
* This has the same layout as `fails`.
*/
- uint8_t alerts[2][kDifEntropyTestNumVariants];
-} dif_entropy_test_stats_t;
+ uint8_t alerts[2][kDifEntropySrcTestNumVariants];
+} dif_entropy_src_test_stats_t;
/**
* The result of an entropy source operation.
*/
-typedef enum dif_entropy_result {
+typedef enum dif_entropy_src_result {
/**
* Indicates that the operation succeeded.
*/
- kDifEntropyOk = 0,
+ kDifEntropySrcOk = 0,
/**
* Indicates some unspecified failure.
*/
- kDifEntropyError = 1,
+ kDifEntropySrcError = 1,
/**
* Indicates that some parameter passed into a function failed a
* precondition.
*
* When this value is returned, no hardware operations occured.
*/
- kDifEntropyBadArg = 2,
+ kDifEntropySrcBadArg = 2,
/**
* Indicates that this operation has been locked out, and can never
* succeed until hardware reset.
*/
- kDifEntropyLocked = 3,
+ kDifEntropySrcLocked = 3,
/**
* Indicates that entropy is not yet available for software consumption
*/
- kDifEntropyDataUnAvailable = 4,
+ kDifEntropySrcDataUnAvailable = 4,
/**
* Indicates that entropy is not idle
*/
- kDifEntropyNotIdle = 5,
-} dif_entropy_result_t;
+ kDifEntropySrcNotIdle = 5,
+} dif_entropy_src_result_t;
/**
* An entropy source interrupt request type.
*/
-typedef enum dif_entropy_irq {
+typedef enum dif_entropy_src_irq {
/**
* Indicates that bits of entropy are available to consume.
*/
- kDifEntropyIrqAvailable,
+ kDifEntropySrcIrqAvailable,
/**
* Indicates that the health test has failed and the alert count has been
* met.
*/
- kDifEntropyIrqUnhealthy,
+ kDifEntropySrcIrqUnhealthy,
/**
* Indicates that an internal error occured in the FIFO, or if an illegal
* state machine state is reached.
*/
- kDifEntropyIrqFatalError,
-} dif_entropy_irq_t;
+ kDifEntropySrcIrqFatalError,
+} dif_entropy_src_irq_t;
/**
* A snapshot of the enablement state of the interrupts for an entropy source.
*
- * This is an opaque type, to be used with the `dif_entropy_irq_disable_all()`
- * and `dif_entropy_irq_restore_all()` functions.
+ * This is an opaque type, to be used with the
+ * `dif_entropy_src_irq_disable_all()` and `dif_entropy_src_irq_restore_all()`
+ * functions.
*/
-typedef uint32_t dif_entropy_irq_snapshot_t;
+typedef uint32_t dif_entropy_src_irq_snapshot_t;
/**
* An entropy source alert type.
*/
-typedef enum dif_entropy_alert {
+typedef enum dif_entropy_src_alert {
/**
* Indicates that the health test criteria were not met.
*/
- kDifEntropyAlert,
+ kDifEntropySrcAlert,
/**
* Indicates that an internal error occurred.
*/
- kDifEntropyFatal,
-} dif_entropy_alert_t;
+ kDifEntropySrcFatal,
+} dif_entropy_src_alert_t;
/**
* Creates a new handle for entropy source.
@@ -428,8 +429,8 @@
* @return The result of the operation.
*/
DIF_WARN_UNUSED_RESULT
-dif_entropy_result_t dif_entropy_init(dif_entropy_params_t params,
- dif_entropy_t *entropy);
+dif_entropy_src_result_t dif_entropy_src_init(dif_entropy_src_params_t params,
+ dif_entropy_src_t *entropy);
/**
* Configures entropy source with runtime information.
@@ -441,8 +442,8 @@
* @return The result of the operation.
*/
DIF_WARN_UNUSED_RESULT
-dif_entropy_result_t dif_entropy_configure(const dif_entropy_t *entropy,
- dif_entropy_config_t config);
+dif_entropy_src_result_t dif_entropy_src_configure(
+ const dif_entropy_src_t *entropy, dif_entropy_src_config_t config);
/**
* Queries the entropy source IP for its revision information.
@@ -452,8 +453,8 @@
* @return The result of the operation.
*/
DIF_WARN_UNUSED_RESULT
-dif_entropy_result_t dif_entropy_get_revision(const dif_entropy_t *entropy,
- dif_entropy_revision_t *revision);
+dif_entropy_src_result_t dif_entropy_src_get_revision(
+ const dif_entropy_src_t *entropy, dif_entropy_src_revision_t *revision);
/**
* Queries the entropy source for health statistics.
@@ -466,21 +467,21 @@
* @return The result of the operation.
*/
DIF_WARN_UNUSED_RESULT
-dif_entropy_result_t dif_entropy_get_stats(const dif_entropy_t *entropy,
- bool fips_mode,
- dif_entropy_test_stats_t *stats);
+dif_entropy_src_result_t dif_entropy_src_get_stats(
+ const dif_entropy_src_t *entropy, bool fips_mode,
+ dif_entropy_src_test_stats_t *stats);
/**
* Locks out entropy source functionality.
*
* This function is reentrant: calling it while functionality is locked will
- * have no effect and return `kDifEntropyOk`.
+ * have no effect and return `kDifEntropySrcOk`.
*
* @param entropy An entropy source handle.
* @return The result of the operation.
*/
DIF_WARN_UNUSED_RESULT
-dif_entropy_result_t dif_entropy_lock(const dif_entropy_t *entropy);
+dif_entropy_src_result_t dif_entropy_src_lock(const dif_entropy_src_t *entropy);
/**
* Checks whether this entropy source is locked.
@@ -490,8 +491,8 @@
* @return The result of the operation.
*/
DIF_WARN_UNUSED_RESULT
-dif_entropy_result_t dif_entropy_is_locked(const dif_entropy_t *entropy,
- bool *is_locked);
+dif_entropy_src_result_t dif_entropy_src_is_locked(
+ const dif_entropy_src_t *entropy, bool *is_locked);
/**
* Checks to see if entropy is available for software consumption
@@ -500,7 +501,8 @@
* @return The result of the operation.
*/
DIF_WARN_UNUSED_RESULT
-dif_entropy_result_t dif_entropy_avail(const dif_entropy_t *entropy);
+dif_entropy_src_result_t dif_entropy_src_avail(
+ const dif_entropy_src_t *entropy);
/**
* Reads off a word of entropy from the entropy source.
@@ -510,8 +512,8 @@
* @return The result of the operation.
*/
DIF_WARN_UNUSED_RESULT
-dif_entropy_result_t dif_entropy_read(const dif_entropy_t *entropy,
- uint32_t *word);
+dif_entropy_src_result_t dif_entropy_src_read(const dif_entropy_src_t *entropy,
+ uint32_t *word);
/**
* Returns whether a particular interrupt is currently pending.
@@ -522,9 +524,9 @@
* @return The result of the operation.
*/
DIF_WARN_UNUSED_RESULT
-dif_entropy_result_t dif_entropy_irq_is_pending(const dif_entropy_t *entropy,
- dif_entropy_irq_t irq,
- bool *is_pending);
+dif_entropy_src_result_t dif_entropy_src_irq_is_pending(
+ const dif_entropy_src_t *entropy, dif_entropy_src_irq_t irq,
+ bool *is_pending);
/**
* Acknowledges a particular interrupt, indicating to the hardware that it has
@@ -535,8 +537,8 @@
* @return The result of the operation.
*/
DIF_WARN_UNUSED_RESULT
-dif_entropy_result_t dif_entropy_irq_acknowledge(const dif_entropy_t *entropy,
- dif_entropy_irq_t irq);
+dif_entropy_src_result_t dif_entropy_src_irq_acknowledge(
+ const dif_entropy_src_t *entropy, dif_entropy_src_irq_t irq);
/**
* Checks whether a particular interrupt is currently enabled or disabled.
@@ -547,9 +549,9 @@
* @return The result of the operation.
*/
DIF_WARN_UNUSED_RESULT
-dif_entropy_result_t dif_entropy_irq_get_enabled(const dif_entropy_t *entropy,
- dif_entropy_irq_t irq,
- dif_entropy_toggle_t *state);
+dif_entropy_src_result_t dif_entropy_src_irq_get_enabled(
+ const dif_entropy_src_t *entropy, dif_entropy_src_irq_t irq,
+ dif_entropy_src_toggle_t *state);
/**
* Sets whether a particular interrupt is currently enabled or disabled.
@@ -560,9 +562,9 @@
* @return The result of the operation.
*/
DIF_WARN_UNUSED_RESULT
-dif_entropy_result_t dif_entropy_irq_set_enabled(const dif_entropy_t *entropy,
- dif_entropy_irq_t irq,
- dif_entropy_toggle_t state);
+dif_entropy_src_result_t dif_entropy_src_irq_set_enabled(
+ const dif_entropy_src_t *entropy, dif_entropy_src_irq_t irq,
+ dif_entropy_src_toggle_t state);
/**
* Forces a particular interrupt, causing it to be serviced as if hardware had
@@ -573,8 +575,8 @@
* @return The result of the operation.
*/
DIF_WARN_UNUSED_RESULT
-dif_entropy_result_t dif_entropy_irq_force(const dif_entropy_t *entropy,
- dif_entropy_irq_t irq);
+dif_entropy_src_result_t dif_entropy_src_irq_force(
+ const dif_entropy_src_t *entropy, dif_entropy_src_irq_t irq);
/**
* Disables all interrupts, optionally snapshotting all toggle state for later
@@ -585,22 +587,23 @@
* @return The result of the operation.
*/
DIF_WARN_UNUSED_RESULT
-dif_entropy_result_t dif_entropy_irq_disable_all(
- const dif_entropy_t *entropy, dif_entropy_irq_snapshot_t *snapshot);
+dif_entropy_src_result_t dif_entropy_src_irq_disable_all(
+ const dif_entropy_src_t *entropy, dif_entropy_src_irq_snapshot_t *snapshot);
/**
* Restores interrupts from the given snapshot.
*
- * This function can be used with `dif_entropy_irq_disable_all()` to temporary
- * interrupt save-and-restore.
+ * This function can be used with `dif_entropy_src_irq_disable_all()` to
+ * temporary interrupt save-and-restore.
*
* @param entropy An entropy source handle.
* @param snapshot A snapshot to restore from.
* @return The result of the operation.
*/
DIF_WARN_UNUSED_RESULT
-dif_entropy_result_t dif_entropy_irq_restore_all(
- const dif_entropy_t *entropy, const dif_entropy_irq_snapshot_t *snapshot);
+dif_entropy_src_result_t dif_entropy_src_irq_restore_all(
+ const dif_entropy_src_t *entropy,
+ const dif_entropy_src_irq_snapshot_t *snapshot);
/**
* Forces a particular alert, causing it to be emitted as if the hardware had
@@ -611,15 +614,15 @@
* @return The result of the operation.
*/
DIF_WARN_UNUSED_RESULT
-dif_entropy_result_t dif_entropy_alert_force(const dif_entropy_t *entropy,
- dif_entropy_alert_t alert);
+dif_entropy_src_result_t dif_entropy_src_alert_force(
+ const dif_entropy_src_t *entropy, dif_entropy_src_alert_t alert);
/**
* Performs an override read from the entropy pipeline.
*
* This function pauses entropy flow out of the pre-conditioner FIFO and
* instead flows words into `buf`. Normal operation of the entropy pipeline
- * will not resume until `dif_entropy_fifo_reconnect()` is called.
+ * will not resume until `dif_entropy_src_fifo_reconnect()` is called.
*
* `buf` may be `NULL`; in this case, reads will be discarded.
*
@@ -629,15 +632,15 @@
* @return The result of the operation.
*/
DIF_WARN_UNUSED_RESULT
-dif_entropy_result_t dif_entropy_fifo_read(const dif_entropy_t *entropy,
- uint32_t *buf, size_t len);
+dif_entropy_src_result_t dif_entropy_src_fifo_read(
+ const dif_entropy_src_t *entropy, uint32_t *buf, size_t len);
/**
* Performs an override write to the entropy pipeline.
*
* This function pauses entropy flow into the pre-conditioner FIFO and
* instead flows words out of `buf`. Normal operation of the entropy pipeline
- * will not resume until `dif_entropy_fifo_reconnect()` is called.
+ * will not resume until `dif_entropy_src_fifo_reconnect()` is called.
*
* @param entropy An entropy source handle.
* @param buf A buffer to push words from into the pipeline.
@@ -645,8 +648,8 @@
* @return The result of the operation.
*/
DIF_WARN_UNUSED_RESULT
-dif_entropy_result_t dif_entropy_fifo_write(const dif_entropy_t *entropy,
- const uint32_t *buf, size_t len);
+dif_entropy_src_result_t dif_entropy_src_fifo_write(
+ const dif_entropy_src_t *entropy, const uint32_t *buf, size_t len);
/**
* Gets the current number of entries in the pre-conditioner FIFO.
@@ -658,8 +661,8 @@
* @return The result of the operation.
*/
DIF_WARN_UNUSED_RESULT
-dif_entropy_result_t dif_entropy_fifo_get_len(const dif_entropy_t *entropy,
- uint8_t *len);
+dif_entropy_src_result_t dif_entropy_src_fifo_get_len(
+ const dif_entropy_src_t *entropy, uint8_t *len);
/**
* Gets the current capacity of the pre-conditioner FIFO.
@@ -669,22 +672,22 @@
* @return The result of the operation.
*/
DIF_WARN_UNUSED_RESULT
-dif_entropy_result_t dif_entropy_fifo_get_capacity(const dif_entropy_t *entropy,
- uint8_t *capacity);
+dif_entropy_src_result_t dif_entropy_src_fifo_get_capacity(
+ const dif_entropy_src_t *entropy, uint8_t *capacity);
/**
* Sets the current capacity of the pre-conditioner FIFO.
*
* The `capacity` value must be less or equal to the physical capacity
- * of the fifo, defined as `kDifEntropyFifoMaxCapacity`.
+ * of the fifo, defined as `kDifEntropySrcFifoMaxCapacity`.
*
* @param entropy An entropy source handle.
* @param capacity The new capacity for the FIFO.
* @return The result of the operation.
*/
DIF_WARN_UNUSED_RESULT
-dif_entropy_result_t dif_entropy_fifo_set_capacity(const dif_entropy_t *entropy,
- uint8_t capacity);
+dif_entropy_src_result_t dif_entropy_src_fifo_set_capacity(
+ const dif_entropy_src_t *entropy, uint8_t capacity);
/**
* Reconnects the entropy pipeline after an operation that pauses it.
@@ -697,7 +700,8 @@
* @return The result of the operation.
*/
DIF_WARN_UNUSED_RESULT
-dif_entropy_result_t dif_entropy_fifo_reconnect(const dif_entropy_t *entropy);
+dif_entropy_src_result_t dif_entropy_src_fifo_reconnect(
+ const dif_entropy_src_t *entropy);
/**
* Disables the entropy module
@@ -706,7 +710,8 @@
* @return The result of the operation.
*/
DIF_WARN_UNUSED_RESULT
-dif_entropy_result_t dif_entropy_disable(const dif_entropy_t *entropy);
+dif_entropy_src_result_t dif_entropy_src_disable(
+ const dif_entropy_src_t *entropy);
/**
* Get main entropy fsm idle status
@@ -715,10 +720,11 @@
* @return The result of the operation.
*/
DIF_WARN_UNUSED_RESULT
-dif_entropy_result_t dif_entropy_get_idle(const dif_entropy_t *entropy);
+dif_entropy_src_result_t dif_entropy_src_get_idle(
+ const dif_entropy_src_t *entropy);
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
-#endif // OPENTITAN_SW_DEVICE_LIB_DIF_DIF_ENTROPY_H_
+#endif // OPENTITAN_SW_DEVICE_LIB_DIF_DIF_ENTROPY_SRC_H_
diff --git a/sw/device/lib/dif/dif_entropy.md b/sw/device/lib/dif/dif_entropy_src.md
similarity index 97%
rename from sw/device/lib/dif/dif_entropy.md
rename to sw/device/lib/dif/dif_entropy_src.md
index f3a157f..793ca43 100644
--- a/sw/device/lib/dif/dif_entropy.md
+++ b/sw/device/lib/dif/dif_entropy_src.md
@@ -4,7 +4,7 @@
<!--
NOTE: This is a template checklist document that is required to be copied over
-to `sw/device/lib/dif/dif_entropy.md` for a new DIF that transitions
+to `sw/device/lib/dif/dif_entropy_src.md` for a new DIF that transitions
from L0 (Specification) to L1 (Development) stage, and updated as needed.
Once done, please remove this comment before checking it in.
-->
diff --git a/sw/device/lib/dif/dif_entropy_src_unittest.cc b/sw/device/lib/dif/dif_entropy_src_unittest.cc
new file mode 100644
index 0000000..4948c25
--- /dev/null
+++ b/sw/device/lib/dif/dif_entropy_src_unittest.cc
@@ -0,0 +1,175 @@
+// Copyright lowRISC contributors.
+// Licensed under the Apache License, Version 2.0, see LICENSE for details.
+// SPDX-License-Identifier: Apache-2.0
+
+#include "sw/device/lib/dif/dif_entropy_src.h"
+
+#include "gtest/gtest.h"
+#include "sw/device/lib/base/mmio.h"
+#include "sw/device/lib/base/testing/mock_mmio.h"
+
+#include "entropy_src_regs.h" // Generated
+
+namespace dif_entropy_src_unittest {
+namespace {
+
+class DifEntropySrcTest : public testing::Test, public mock_mmio::MmioTest {
+ protected:
+ const dif_entropy_src_params_t params_ = {.base_addr = dev().region()};
+ const dif_entropy_src_t entropy_ = {
+ .params = {.base_addr = dev().region()},
+ };
+};
+
+class InitTest : public DifEntropySrcTest {};
+
+TEST_F(InitTest, BadArgs) {
+ EXPECT_EQ(dif_entropy_src_init(params_, nullptr), kDifEntropySrcBadArg);
+}
+
+TEST_F(InitTest, Init) {
+ dif_entropy_src_t entropy;
+ EXPECT_EQ(dif_entropy_src_init(params_, &entropy), kDifEntropySrcOk);
+}
+
+class ConfigTest : public DifEntropySrcTest {
+ protected:
+ dif_entropy_src_config_t config_ = {
+ .mode = kDifEntropySrcModeLfsr,
+ .tests = {0},
+ .reset_health_test_registers = false,
+ .single_bit_mode = kDifEntropySrcSingleBitModeDisabled,
+ .route_to_firmware = false,
+ .fips_mode = false,
+ .test_config = {0},
+ .sample_rate = 64,
+ .lfsr_seed = 4,
+ };
+};
+
+TEST_F(ConfigTest, NullArgs) {
+ EXPECT_EQ(dif_entropy_src_configure(nullptr, {}), kDifEntropySrcBadArg);
+}
+
+TEST_F(ConfigTest, LfsrSeedBadArg) {
+ config_.lfsr_seed = 16;
+ EXPECT_EQ(dif_entropy_src_configure(&entropy_, config_),
+ kDifEntropySrcBadArg);
+}
+
+struct ConfigParams {
+ dif_entropy_src_mode_t mode;
+ dif_entropy_src_single_bit_mode_t single_bit_mode;
+ bool route_to_firmware;
+ bool reset_health_test_registers;
+
+ uint32_t expected_mode;
+ bool expected_rng_bit_en;
+ uint32_t expected_rng_sel;
+ uint32_t expected_seed;
+};
+
+class ConfigTestAllParams : public ConfigTest,
+ public testing::WithParamInterface<ConfigParams> {};
+
+TEST_P(ConfigTestAllParams, ValidConfigurationMode) {
+ const ConfigParams &test_param = GetParam();
+ config_.mode = test_param.mode;
+ config_.single_bit_mode = test_param.single_bit_mode;
+ config_.route_to_firmware = test_param.route_to_firmware;
+ config_.reset_health_test_registers = test_param.reset_health_test_registers;
+
+ EXPECT_WRITE32(ENTROPY_SRC_SEED_REG_OFFSET, test_param.expected_seed);
+ EXPECT_WRITE32(ENTROPY_SRC_RATE_REG_OFFSET, 64);
+ EXPECT_WRITE32(ENTROPY_SRC_ENTROPY_CONTROL_REG_OFFSET,
+ {
+ {ENTROPY_SRC_ENTROPY_CONTROL_ES_ROUTE_BIT,
+ test_param.route_to_firmware},
+ {ENTROPY_SRC_ENTROPY_CONTROL_ES_TYPE_BIT, false},
+ });
+ EXPECT_WRITE32(ENTROPY_SRC_FW_OV_CONTROL_REG_OFFSET, 0);
+ EXPECT_WRITE32(
+ ENTROPY_SRC_CONF_REG_OFFSET,
+ {
+ {ENTROPY_SRC_CONF_ENABLE_OFFSET, test_param.expected_mode},
+ {ENTROPY_SRC_CONF_BOOT_BYPASS_DISABLE_BIT, true},
+ {ENTROPY_SRC_CONF_REPCNT_DISABLE_BIT, true},
+ {ENTROPY_SRC_CONF_ADAPTP_DISABLE_BIT, true},
+ {ENTROPY_SRC_CONF_BUCKET_DISABLE_BIT, true},
+ {ENTROPY_SRC_CONF_MARKOV_DISABLE_BIT, true},
+ {ENTROPY_SRC_CONF_HEALTH_TEST_CLR_BIT,
+ test_param.reset_health_test_registers},
+ {ENTROPY_SRC_CONF_RNG_BIT_EN_BIT, test_param.expected_rng_bit_en},
+ {ENTROPY_SRC_CONF_RNG_BIT_SEL_OFFSET, test_param.expected_rng_sel},
+ {ENTROPY_SRC_CONF_EXTHT_ENABLE_BIT, false},
+ });
+
+ EXPECT_EQ(dif_entropy_src_configure(&entropy_, config_), kDifEntropySrcOk);
+}
+
+INSTANTIATE_TEST_SUITE_P(
+ ConfigTestAllParams, ConfigTestAllParams,
+ testing::Values(
+ // Test entropy mode.
+ ConfigParams{kDifEntropySrcModeDisabled,
+ kDifEntropySrcSingleBitModeDisabled, false, 0, false, 0,
+ 0},
+ ConfigParams{kDifEntropySrcModePtrng,
+ kDifEntropySrcSingleBitModeDisabled, false, false, 1,
+ false, 0, 0},
+ ConfigParams{kDifEntropySrcModeLfsr,
+ kDifEntropySrcSingleBitModeDisabled, false, false, 2,
+ false, 0, 4},
+ // Test route_to_firmware
+ ConfigParams{kDifEntropySrcModeLfsr,
+ kDifEntropySrcSingleBitModeDisabled, true, false, 2, false,
+ 0, 4},
+ // Test reset_health_test_registers
+ ConfigParams{kDifEntropySrcModeLfsr,
+ kDifEntropySrcSingleBitModeDisabled, true, true, 2, false,
+ 0, 4},
+ // Test single_bit_mode
+ ConfigParams{kDifEntropySrcModeLfsr, kDifEntropySrcSingleBitMode0, true,
+ true, 2, true, 0, 4},
+ ConfigParams{kDifEntropySrcModeLfsr, kDifEntropySrcSingleBitMode1, true,
+ true, 2, true, 1, 4},
+ ConfigParams{kDifEntropySrcModeLfsr, kDifEntropySrcSingleBitMode2, true,
+ true, 2, true, 2, 4},
+ ConfigParams{kDifEntropySrcModeLfsr, kDifEntropySrcSingleBitMode3, true,
+ true, 2, true, 3, 4}));
+
+class ReadTest : public DifEntropySrcTest {};
+
+TEST_F(ReadTest, EntropyBadArg) {
+ uint32_t word;
+ EXPECT_EQ(dif_entropy_src_read(nullptr, &word), kDifEntropySrcBadArg);
+}
+
+TEST_F(ReadTest, WordBadArg) {
+ EXPECT_EQ(dif_entropy_src_read(&entropy_, nullptr), kDifEntropySrcBadArg);
+}
+
+TEST_F(ReadTest, ReadDataUnAvailable) {
+ EXPECT_READ32(ENTROPY_SRC_INTR_STATE_REG_OFFSET, 0);
+ uint32_t got_word;
+ EXPECT_EQ(dif_entropy_src_read(&entropy_, &got_word),
+ kDifEntropySrcDataUnAvailable);
+}
+
+TEST_F(ReadTest, ReadOk) {
+ const uint32_t expected_word = 0x65585497;
+ EXPECT_READ32(ENTROPY_SRC_INTR_STATE_REG_OFFSET,
+ 1 << ENTROPY_SRC_INTR_STATE_ES_ENTROPY_VALID_BIT);
+ EXPECT_READ32(ENTROPY_SRC_ENTROPY_DATA_REG_OFFSET, expected_word);
+ EXPECT_READ32(ENTROPY_SRC_INTR_STATE_REG_OFFSET,
+ 1 << ENTROPY_SRC_INTR_STATE_ES_ENTROPY_VALID_BIT);
+ EXPECT_WRITE32(ENTROPY_SRC_INTR_STATE_REG_OFFSET,
+ {{ENTROPY_SRC_INTR_STATE_ES_ENTROPY_VALID_BIT, true}});
+
+ uint32_t got_word;
+ EXPECT_EQ(dif_entropy_src_read(&entropy_, &got_word), kDifEntropySrcOk);
+ EXPECT_EQ(got_word, expected_word);
+}
+
+} // namespace
+} // namespace dif_entropy_src_unittest
diff --git a/sw/device/lib/dif/dif_entropy_unittest.cc b/sw/device/lib/dif/dif_entropy_unittest.cc
deleted file mode 100644
index 1bfedf1..0000000
--- a/sw/device/lib/dif/dif_entropy_unittest.cc
+++ /dev/null
@@ -1,168 +0,0 @@
-// Copyright lowRISC contributors.
-// Licensed under the Apache License, Version 2.0, see LICENSE for details.
-// SPDX-License-Identifier: Apache-2.0
-
-#include "sw/device/lib/dif/dif_entropy.h"
-
-#include "gtest/gtest.h"
-#include "sw/device/lib/base/mmio.h"
-#include "sw/device/lib/base/testing/mock_mmio.h"
-
-#include "entropy_src_regs.h" // Generated
-
-namespace dif_entropy_unittest {
-namespace {
-
-class DifEntropyTest : public testing::Test, public mock_mmio::MmioTest {
- protected:
- const dif_entropy_params_t params_ = {.base_addr = dev().region()};
- const dif_entropy_t entropy_ = {
- .params = {.base_addr = dev().region()},
- };
-};
-
-class InitTest : public DifEntropyTest {};
-
-TEST_F(InitTest, BadArgs) {
- EXPECT_EQ(dif_entropy_init(params_, nullptr), kDifEntropyBadArg);
-}
-
-TEST_F(InitTest, Init) {
- dif_entropy_t entropy;
- EXPECT_EQ(dif_entropy_init(params_, &entropy), kDifEntropyOk);
-}
-
-class ConfigTest : public DifEntropyTest {
- protected:
- dif_entropy_config_t config_ = {
- .mode = kDifEntropyModeLfsr,
- .tests = {0},
- .reset_health_test_registers = false,
- .single_bit_mode = kDifEntropySingleBitModeDisabled,
- .route_to_firmware = false,
- .fips_mode = false,
- .test_config = {0},
- .sample_rate = 64,
- .lfsr_seed = 4,
- };
-};
-
-TEST_F(ConfigTest, NullArgs) {
- EXPECT_EQ(dif_entropy_configure(nullptr, {}), kDifEntropyBadArg);
-}
-
-TEST_F(ConfigTest, LfsrSeedBadArg) {
- config_.lfsr_seed = 16;
- EXPECT_EQ(dif_entropy_configure(&entropy_, config_), kDifEntropyBadArg);
-}
-
-struct ConfigParams {
- dif_entropy_mode_t mode;
- dif_entropy_single_bit_mode_t single_bit_mode;
- bool route_to_firmware;
- bool reset_health_test_registers;
-
- uint32_t expected_mode;
- bool expected_rng_bit_en;
- uint32_t expected_rng_sel;
- uint32_t expected_seed;
-};
-
-class ConfigTestAllParams : public ConfigTest,
- public testing::WithParamInterface<ConfigParams> {};
-
-TEST_P(ConfigTestAllParams, ValidConfigurationMode) {
- const ConfigParams &test_param = GetParam();
- config_.mode = test_param.mode;
- config_.single_bit_mode = test_param.single_bit_mode;
- config_.route_to_firmware = test_param.route_to_firmware;
- config_.reset_health_test_registers = test_param.reset_health_test_registers;
-
- EXPECT_WRITE32(ENTROPY_SRC_SEED_REG_OFFSET, test_param.expected_seed);
- EXPECT_WRITE32(ENTROPY_SRC_RATE_REG_OFFSET, 64);
- EXPECT_WRITE32(ENTROPY_SRC_ENTROPY_CONTROL_REG_OFFSET,
- {
- {ENTROPY_SRC_ENTROPY_CONTROL_ES_ROUTE_BIT,
- test_param.route_to_firmware},
- {ENTROPY_SRC_ENTROPY_CONTROL_ES_TYPE_BIT, false},
- });
- EXPECT_WRITE32(ENTROPY_SRC_FW_OV_CONTROL_REG_OFFSET, 0);
- EXPECT_WRITE32(
- ENTROPY_SRC_CONF_REG_OFFSET,
- {
- {ENTROPY_SRC_CONF_ENABLE_OFFSET, test_param.expected_mode},
- {ENTROPY_SRC_CONF_BOOT_BYPASS_DISABLE_BIT, true},
- {ENTROPY_SRC_CONF_REPCNT_DISABLE_BIT, true},
- {ENTROPY_SRC_CONF_ADAPTP_DISABLE_BIT, true},
- {ENTROPY_SRC_CONF_BUCKET_DISABLE_BIT, true},
- {ENTROPY_SRC_CONF_MARKOV_DISABLE_BIT, true},
- {ENTROPY_SRC_CONF_HEALTH_TEST_CLR_BIT,
- test_param.reset_health_test_registers},
- {ENTROPY_SRC_CONF_RNG_BIT_EN_BIT, test_param.expected_rng_bit_en},
- {ENTROPY_SRC_CONF_RNG_BIT_SEL_OFFSET, test_param.expected_rng_sel},
- {ENTROPY_SRC_CONF_EXTHT_ENABLE_BIT, false},
- });
-
- EXPECT_EQ(dif_entropy_configure(&entropy_, config_), kDifEntropyOk);
-}
-
-INSTANTIATE_TEST_SUITE_P(
- ConfigTestAllParams, ConfigTestAllParams,
- testing::Values(
- // Test entropy mode.
- ConfigParams{kDifEntropyModeDisabled, kDifEntropySingleBitModeDisabled,
- false, 0, false, 0, 0},
- ConfigParams{kDifEntropyModePtrng, kDifEntropySingleBitModeDisabled,
- false, false, 1, false, 0, 0},
- ConfigParams{kDifEntropyModeLfsr, kDifEntropySingleBitModeDisabled,
- false, false, 2, false, 0, 4},
- // Test route_to_firmware
- ConfigParams{kDifEntropyModeLfsr, kDifEntropySingleBitModeDisabled,
- true, false, 2, false, 0, 4},
- // Test reset_health_test_registers
- ConfigParams{kDifEntropyModeLfsr, kDifEntropySingleBitModeDisabled,
- true, true, 2, false, 0, 4},
- // Test single_bit_mode
- ConfigParams{kDifEntropyModeLfsr, kDifEntropySingleBitMode0, true, true,
- 2, true, 0, 4},
- ConfigParams{kDifEntropyModeLfsr, kDifEntropySingleBitMode1, true, true,
- 2, true, 1, 4},
- ConfigParams{kDifEntropyModeLfsr, kDifEntropySingleBitMode2, true, true,
- 2, true, 2, 4},
- ConfigParams{kDifEntropyModeLfsr, kDifEntropySingleBitMode3, true, true,
- 2, true, 3, 4}));
-
-class ReadTest : public DifEntropyTest {};
-
-TEST_F(ReadTest, EntropyBadArg) {
- uint32_t word;
- EXPECT_EQ(dif_entropy_read(nullptr, &word), kDifEntropyBadArg);
-}
-
-TEST_F(ReadTest, WordBadArg) {
- EXPECT_EQ(dif_entropy_read(&entropy_, nullptr), kDifEntropyBadArg);
-}
-
-TEST_F(ReadTest, ReadDataUnAvailable) {
- EXPECT_READ32(ENTROPY_SRC_INTR_STATE_REG_OFFSET, 0);
- uint32_t got_word;
- EXPECT_EQ(dif_entropy_read(&entropy_, &got_word), kDifEntropyDataUnAvailable);
-}
-
-TEST_F(ReadTest, ReadOk) {
- const uint32_t expected_word = 0x65585497;
- EXPECT_READ32(ENTROPY_SRC_INTR_STATE_REG_OFFSET,
- 1 << ENTROPY_SRC_INTR_STATE_ES_ENTROPY_VALID_BIT);
- EXPECT_READ32(ENTROPY_SRC_ENTROPY_DATA_REG_OFFSET, expected_word);
- EXPECT_READ32(ENTROPY_SRC_INTR_STATE_REG_OFFSET,
- 1 << ENTROPY_SRC_INTR_STATE_ES_ENTROPY_VALID_BIT);
- EXPECT_WRITE32(ENTROPY_SRC_INTR_STATE_REG_OFFSET,
- {{ENTROPY_SRC_INTR_STATE_ES_ENTROPY_VALID_BIT, true}});
-
- uint32_t got_word;
- EXPECT_EQ(dif_entropy_read(&entropy_, &got_word), kDifEntropyOk);
- EXPECT_EQ(got_word, expected_word);
-}
-
-} // namespace
-} // namespace dif_entropy_unittest
diff --git a/sw/device/lib/dif/meson.build b/sw/device/lib/dif/meson.build
index ffc9425..b82e4ef 100644
--- a/sw/device/lib/dif/meson.build
+++ b/sw/device/lib/dif/meson.build
@@ -598,12 +598,12 @@
)
# Entropy Source
-sw_lib_dif_entropy = declare_dependency(
+sw_lib_dif_entropy_src = declare_dependency(
link_with: static_library(
- 'sw_lib_dif_entropy',
+ 'sw_lib_dif_entropy_src',
sources: [
- hw_ip_entropy_reg_h,
- 'dif_entropy.c',
+ hw_ip_entropy_src_reg_h,
+ 'dif_entropy_src.c',
],
dependencies: [
sw_lib_mmio,
@@ -612,12 +612,12 @@
)
)
-test('dif_entropy_unittest', executable(
- 'dif_entropy_unittest',
+test('dif_entropy_src_unittest', executable(
+ 'dif_entropy_src_unittest',
sources: [
- hw_ip_entropy_reg_h,
- meson.source_root() / 'sw/device/lib/dif/dif_entropy.c',
- 'dif_entropy_unittest.cc',
+ hw_ip_entropy_src_reg_h,
+ meson.source_root() / 'sw/device/lib/dif/dif_entropy_src.c',
+ 'dif_entropy_src_unittest.cc',
],
dependencies: [
sw_vendor_gtest,
diff --git a/sw/device/lib/testing/entropy_testutils.c b/sw/device/lib/testing/entropy_testutils.c
index c629e76..2e84f2f 100644
--- a/sw/device/lib/testing/entropy_testutils.c
+++ b/sw/device/lib/testing/entropy_testutils.c
@@ -4,41 +4,41 @@
#include "sw/device/lib/base/mmio.h"
#include "sw/device/lib/dif/dif_csrng.h"
-#include "sw/device/lib/dif/dif_entropy.h"
+#include "sw/device/lib/dif/dif_entropy_src.h"
#include "sw/device/lib/testing/check.h"
#include "edn_regs.h" // Generated
#include "hw/top_earlgrey/sw/autogen/top_earlgrey.h"
static void setup_entropy_src(void) {
- const dif_entropy_params_t params = {
+ const dif_entropy_src_params_t params = {
.base_addr = mmio_region_from_addr(TOP_EARLGREY_ENTROPY_SRC_BASE_ADDR),
};
- dif_entropy_t entropy;
- CHECK(dif_entropy_init(params, &entropy) == kDifEntropyOk);
+ dif_entropy_src_t entropy;
+ CHECK(dif_entropy_src_init(params, &entropy) == kDifEntropySrcOk);
// Disable entropy for test purpose, as it has been turned on by ROM
- CHECK(dif_entropy_disable(&entropy) == kDifEntropyOk);
+ CHECK(dif_entropy_src_disable(&entropy) == kDifEntropySrcOk);
- const dif_entropy_config_t config = {
- .mode = kDifEntropyModeLfsr,
+ const dif_entropy_src_config_t config = {
+ .mode = kDifEntropySrcModeLfsr,
.tests =
{
- [kDifEntropyTestRepCount] = false,
- [kDifEntropyTestAdaptiveProportion] = false,
- [kDifEntropyTestBucket] = false,
- [kDifEntropyTestMarkov] = false,
- [kDifEntropyTestMailbox] = false,
- [kDifEntropyTestVendorSpecific] = false,
+ [kDifEntropySrcTestRepCount] = false,
+ [kDifEntropySrcTestAdaptiveProportion] = false,
+ [kDifEntropySrcTestBucket] = false,
+ [kDifEntropySrcTestMarkov] = false,
+ [kDifEntropySrcTestMailbox] = false,
+ [kDifEntropySrcTestVendorSpecific] = false,
},
// this field needs to manually toggled by software. Disable for now
.reset_health_test_registers = false,
- .single_bit_mode = kDifEntropySingleBitModeDisabled,
+ .single_bit_mode = kDifEntropySrcSingleBitModeDisabled,
.route_to_firmware = false,
.sample_rate = 2,
.lfsr_seed = 0,
};
- CHECK(dif_entropy_configure(&entropy, config) == kDifEntropyOk);
+ CHECK(dif_entropy_src_configure(&entropy, config) == kDifEntropySrcOk);
}
static void setup_csrng(void) {
diff --git a/sw/device/lib/testing/meson.build b/sw/device/lib/testing/meson.build
index 3ef237e..f52b904 100644
--- a/sw/device/lib/testing/meson.build
+++ b/sw/device/lib/testing/meson.build
@@ -26,7 +26,7 @@
dependencies: [
top_earlgrey,
sw_lib_mmio,
- sw_lib_dif_entropy,
+ sw_lib_dif_entropy_src,
sw_lib_dif_csrng,
top_earlgrey,
],
diff --git a/sw/device/sca/lib/meson.build b/sw/device/sca/lib/meson.build
index 3c9e9c9..8a10719 100644
--- a/sw/device/sca/lib/meson.build
+++ b/sw/device/sca/lib/meson.build
@@ -13,7 +13,7 @@
],
dependencies: [
sw_lib_dif_clkmgr,
- sw_lib_dif_entropy,
+ sw_lib_dif_entropy_src,
sw_lib_dif_gpio,
sw_lib_dif_rv_timer,
sw_lib_dif_uart,
diff --git a/sw/device/sca/lib/sca.c b/sw/device/sca/lib/sca.c
index 9e732a8..1c74eb0 100644
--- a/sw/device/sca/lib/sca.c
+++ b/sw/device/sca/lib/sca.c
@@ -6,7 +6,7 @@
#include "sw/device/lib/arch/device.h"
#include "sw/device/lib/dif/dif_clkmgr.h"
-#include "sw/device/lib/dif/dif_entropy.h"
+#include "sw/device/lib/dif/dif_entropy_src.h"
#include "sw/device/lib/dif/dif_gpio.h"
#include "sw/device/lib/dif/dif_rv_timer.h"
#include "sw/device/lib/dif/dif_uart.h"
@@ -146,12 +146,13 @@
CSRNG_CTRL_REG_OFFSET, CSRNG_CTRL_REG_RESVAL);
// Disable entropy source through DIF.
- const dif_entropy_params_t entropy_params = {
+ const dif_entropy_src_params_t entropy_params = {
.base_addr = mmio_region_from_addr(TOP_EARLGREY_ENTROPY_SRC_BASE_ADDR),
};
- dif_entropy_t entropy;
- IGNORE_RESULT(dif_entropy_init(entropy_params, &entropy) == kDifEntropyOk);
- IGNORE_RESULT(dif_entropy_disable(&entropy) == kDifEntropyOk);
+ dif_entropy_src_t entropy;
+ IGNORE_RESULT(dif_entropy_src_init(entropy_params, &entropy) ==
+ kDifEntropySrcOk);
+ IGNORE_RESULT(dif_entropy_src_disable(&entropy) == kDifEntropySrcOk);
// Disable HMAC, KMAC, OTBN and USB clocks through CLKMGR DIF.
const dif_clkmgr_params_t clkmgr_params = {
diff --git a/sw/device/tests/dif/dif_entropy_smoketest.c b/sw/device/tests/dif/dif_entropy_src_smoketest.c
similarity index 62%
rename from sw/device/tests/dif/dif_entropy_smoketest.c
rename to sw/device/tests/dif/dif_entropy_src_smoketest.c
index 5e9e3a6..09ab54b 100644
--- a/sw/device/tests/dif/dif_entropy_smoketest.c
+++ b/sw/device/tests/dif/dif_entropy_src_smoketest.c
@@ -4,7 +4,7 @@
#include "sw/device/lib/base/memory.h"
#include "sw/device/lib/base/mmio.h"
-#include "sw/device/lib/dif/dif_entropy.h"
+#include "sw/device/lib/dif/dif_entropy_src.h"
#include "sw/device/lib/runtime/log.h"
#include "sw/device/lib/testing/check.h"
#include "sw/device/lib/testing/test_main.h"
@@ -21,40 +21,40 @@
};
bool test_main() {
- const dif_entropy_params_t params = {
+ const dif_entropy_src_params_t params = {
.base_addr = mmio_region_from_addr(TOP_EARLGREY_ENTROPY_SRC_BASE_ADDR),
};
- dif_entropy_t entropy;
- CHECK(dif_entropy_init(params, &entropy) == kDifEntropyOk);
+ dif_entropy_src_t entropy;
+ CHECK(dif_entropy_src_init(params, &entropy) == kDifEntropySrcOk);
// Disable entropy for test purpose, as it has been turned on by ROM
- CHECK(dif_entropy_disable(&entropy) == kDifEntropyOk);
+ CHECK(dif_entropy_src_disable(&entropy) == kDifEntropySrcOk);
- const dif_entropy_config_t config = {
- .mode = kDifEntropyModeLfsr,
+ const dif_entropy_src_config_t config = {
+ .mode = kDifEntropySrcModeLfsr,
.tests =
{
- [kDifEntropyTestRepCount] = false,
- [kDifEntropyTestAdaptiveProportion] = false,
- [kDifEntropyTestBucket] = false,
- [kDifEntropyTestMarkov] = false,
- [kDifEntropyTestMailbox] = false,
- [kDifEntropyTestVendorSpecific] = false,
+ [kDifEntropySrcTestRepCount] = false,
+ [kDifEntropySrcTestAdaptiveProportion] = false,
+ [kDifEntropySrcTestBucket] = false,
+ [kDifEntropySrcTestMarkov] = false,
+ [kDifEntropySrcTestMailbox] = false,
+ [kDifEntropySrcTestVendorSpecific] = false,
},
// this field needs to manually toggled by software. Disable for now
.reset_health_test_registers = false,
- .single_bit_mode = kDifEntropySingleBitModeDisabled,
+ .single_bit_mode = kDifEntropySrcSingleBitModeDisabled,
.route_to_firmware = true,
.sample_rate = 2,
.lfsr_seed = 2,
};
- CHECK(dif_entropy_configure(&entropy, config) == kDifEntropyOk);
+ CHECK(dif_entropy_src_configure(&entropy, config) == kDifEntropySrcOk);
uint32_t entropy_data[kEntropyDataNumWords];
uint32_t result = 0;
for (uint32_t i = 0; i < kEntropyDataNumWords; ++i) {
// wait for entropy to become available
- while (dif_entropy_read(&entropy, &entropy_data[i]) != kDifEntropyOk)
+ while (dif_entropy_src_read(&entropy, &entropy_data[i]) != kDifEntropySrcOk)
;
LOG_INFO("received 0x%x, expectecd 0x%x", entropy_data[i],
kExpectedEntropyData[i]);
diff --git a/sw/device/tests/dif/meson.build b/sw/device/tests/dif/meson.build
index 7ff797b..2bc9499 100644
--- a/sw/device/tests/dif/meson.build
+++ b/sw/device/tests/dif/meson.build
@@ -262,20 +262,20 @@
}
}
-dif_entropy_smoketest_lib = declare_dependency(
+dif_entropy_src_smoketest_lib = declare_dependency(
link_with: static_library(
- 'dif_entropy_smoketest_lib',
- sources: ['dif_entropy_smoketest.c'],
+ 'dif_entropy_src_smoketest_lib',
+ sources: ['dif_entropy_src_smoketest.c'],
dependencies: [
- sw_lib_dif_entropy,
+ sw_lib_dif_entropy_src,
sw_lib_mmio,
sw_lib_runtime_log,
],
),
)
sw_tests += {
- 'dif_entropy_smoketest': {
- 'library': dif_entropy_smoketest_lib,
+ 'dif_entropy_src_smoketest': {
+ 'library': dif_entropy_src_smoketest_lib,
}
}