[dif/entropy_src] migrate srcs to use autogen'd IRQ DIFs
This partially addresses #8142.
Signed-off-by: Timothy Trippel <ttrippel@google.com>
diff --git a/hw/top_englishbreakfast/util/sw_sources.patch b/hw/top_englishbreakfast/util/sw_sources.patch
index dc6f272..9a53f13 100644
--- a/hw/top_englishbreakfast/util/sw_sources.patch
+++ b/hw/top_englishbreakfast/util/sw_sources.patch
@@ -75,7 +75,7 @@
simple_serial_process_packet();
}
diff --git a/sw/device/sca/lib/sca.c b/sw/device/sca/lib/sca.c
-index ef4443533..5629a15d8 100644
+index e894f1793..5629a15d8 100644
--- a/sw/device/sca/lib/sca.c
+++ b/sw/device/sca/lib/sca.c
@@ -56,7 +56,6 @@ enum {
@@ -102,7 +102,7 @@
}
/**
-@@ -148,32 +143,11 @@ void handler_irq_timer(void) {
+@@ -148,30 +143,11 @@ void handler_irq_timer(void) {
* @param disable Set of peripherals to disable.
*/
void sca_disable_peripherals(sca_peripherals_t disable) {
@@ -119,11 +119,9 @@
- CSRNG_CTRL_REG_OFFSET, CSRNG_CTRL_REG_RESVAL);
- }
- if (disable & kScaPeripheralEntropy) {
-- const dif_entropy_src_params_t entropy_params = {
-- .base_addr = mmio_region_from_addr(TOP_EARLGREY_ENTROPY_SRC_BASE_ADDR),
-- };
- dif_entropy_src_t entropy;
-- IGNORE_RESULT(dif_entropy_src_init(entropy_params, &entropy));
+- IGNORE_RESULT(dif_entropy_src_init(
+- mmio_region_from_addr(TOP_EARLGREY_ENTROPY_SRC_BASE_ADDR), &entropy));
- IGNORE_RESULT(dif_entropy_src_disable(&entropy));
- }
-
@@ -136,7 +134,7 @@
dif_clkmgr_t clkmgr;
IGNORE_RESULT(dif_clkmgr_init(clkmgr_params, &clkmgr));
-@@ -187,19 +161,6 @@ void sca_disable_peripherals(sca_peripherals_t disable) {
+@@ -185,19 +161,6 @@ void sca_disable_peripherals(sca_peripherals_t disable) {
&clkmgr, CLKMGR_CLK_HINTS_CLK_MAIN_HMAC_HINT_BIT,
kDifClkmgrToggleDisabled));
}
@@ -179,7 +177,7 @@
CHECK_DIF_OK(
dif_aes_init(mmio_region_from_addr(TOP_EARLGREY_AES_BASE_ADDR), &aes));
diff --git a/sw/device/tests/meson.build b/sw/device/tests/meson.build
-index 1b1c8ae72..66635fb0a 100644
+index d9260ca0f..ff7e3ee0b 100644
--- a/sw/device/tests/meson.build
+++ b/sw/device/tests/meson.build
@@ -207,7 +207,6 @@ aes_smoketest_lib = declare_dependency(
diff --git a/sw/device/lib/dif/autogen/meson.build b/sw/device/lib/dif/autogen/meson.build
index 6220e73..ccae66e 100644
--- a/sw/device/lib/dif/autogen/meson.build
+++ b/sw/device/lib/dif/autogen/meson.build
@@ -2,6 +2,20 @@
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
+# Autogen Entropy Source DIF library
+sw_lib_dif_autogen_entropy_src = declare_dependency(
+ link_with: static_library(
+ 'sw_lib_dif_autogen_entropy_src',
+ sources: [
+ hw_ip_entropy_src_reg_h,
+ 'dif_entropy_src_autogen.c',
+ ],
+ dependencies: [
+ sw_lib_mmio,
+ ],
+ )
+)
+
# Autogen I2C Controller DIF library
sw_lib_dif_autogen_i2c = declare_dependency(
link_with: static_library(
diff --git a/sw/device/lib/dif/dif_entropy_src.c b/sw/device/lib/dif/dif_entropy_src.c
index 485447f..4acca4e 100644
--- a/sw/device/lib/dif/dif_entropy_src.c
+++ b/sw/device/lib/dif/dif_entropy_src.c
@@ -8,6 +8,7 @@
#include "sw/device/lib/base/memory.h"
#include "sw/device/lib/base/mmio.h"
+#include "sw/device/lib/dif/dif_base.h"
#include "entropy_src_regs.h" // Generated.
@@ -15,7 +16,7 @@
* Sets the `entropy` source configuration register with the settings
* derived from `config`.
*/
-static void set_config_register(const dif_entropy_src_t *entropy,
+static void set_config_register(const dif_entropy_src_t *entropy_src,
const dif_entropy_src_config_t *config) {
// TODO: Make this configurable at the API level.
uint32_t reg = bitfield_field32_write(
@@ -44,34 +45,33 @@
// Enable configuration
uint32_t enable_val = config->mode != kDifEntropySrcModeDisabled ? 0xa : 0x5;
reg = bitfield_field32_write(reg, ENTROPY_SRC_CONF_ENABLE_FIELD, enable_val);
- mmio_region_write32(entropy->params.base_addr, ENTROPY_SRC_CONF_REG_OFFSET,
- reg);
+ mmio_region_write32(entropy_src->base_addr, ENTROPY_SRC_CONF_REG_OFFSET, reg);
}
-dif_entropy_src_result_t dif_entropy_src_init(dif_entropy_src_params_t params,
- dif_entropy_src_t *entropy) {
- if (entropy == NULL) {
- return kDifEntropySrcBadArg;
+dif_result_t dif_entropy_src_init(mmio_region_t base_addr,
+ dif_entropy_src_t *entropy_src) {
+ if (entropy_src == NULL) {
+ return kDifBadArg;
}
- *entropy = (dif_entropy_src_t){.params = params};
- return kDifEntropySrcOk;
+ entropy_src->base_addr = base_addr;
+ return kDifOk;
}
-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 kDifEntropySrcBadArg;
+dif_result_t dif_entropy_src_configure(const dif_entropy_src_t *entropy_src,
+ dif_entropy_src_config_t config) {
+ if (entropy_src == NULL) {
+ return kDifBadArg;
}
if (config.lfsr_seed > ENTROPY_SRC_SEED_LFSR_SEED_MASK) {
- return kDifEntropySrcBadArg;
+ return kDifBadArg;
}
uint32_t seed = config.mode == kDifEntropySrcModeLfsr ? config.lfsr_seed : 0;
- mmio_region_write32(entropy->params.base_addr, ENTROPY_SRC_SEED_REG_OFFSET,
+ mmio_region_write32(entropy_src->base_addr, ENTROPY_SRC_SEED_REG_OFFSET,
seed);
- mmio_region_write32(entropy->params.base_addr, ENTROPY_SRC_RATE_REG_OFFSET,
+ mmio_region_write32(entropy_src->base_addr, ENTROPY_SRC_RATE_REG_OFFSET,
(uint32_t)config.sample_rate);
// Conditioning bypass is hardcoded to enabled. Bypass is not intended as
@@ -81,63 +81,59 @@
0, ENTROPY_SRC_ENTROPY_CONTROL_ES_ROUTE_FIELD, es_route_val);
reg = bitfield_field32_write(reg, ENTROPY_SRC_ENTROPY_CONTROL_ES_TYPE_FIELD,
0x5);
- mmio_region_write32(entropy->params.base_addr,
+ mmio_region_write32(entropy_src->base_addr,
ENTROPY_SRC_ENTROPY_CONTROL_REG_OFFSET, reg);
// TODO: Add test configuration parameters.
// TODO: Add support for FIFO mode.
- mmio_region_write32(entropy->params.base_addr,
+ mmio_region_write32(entropy_src->base_addr,
ENTROPY_SRC_FW_OV_CONTROL_REG_OFFSET, 0);
- set_config_register(entropy, &config);
- return kDifEntropySrcOk;
+ set_config_register(entropy_src, &config);
+ return kDifOk;
}
-static bool get_entropy_avail(const dif_entropy_src_t *entropy) {
- return mmio_region_get_bit32(entropy->params.base_addr,
+static bool get_entropy_avail(const dif_entropy_src_t *entropy_src) {
+ return mmio_region_get_bit32(entropy_src->base_addr,
ENTROPY_SRC_INTR_STATE_REG_OFFSET,
ENTROPY_SRC_INTR_STATE_ES_ENTROPY_VALID_BIT);
}
-dif_entropy_src_result_t dif_entropy_src_avail(
- const dif_entropy_src_t *entropy) {
- if (entropy == NULL) {
- return kDifEntropySrcBadArg;
+dif_result_t dif_entropy_src_avail(const dif_entropy_src_t *entropy_src) {
+ if (entropy_src == NULL) {
+ return kDifBadArg;
}
- return get_entropy_avail(entropy) ? kDifEntropySrcOk
- : kDifEntropySrcDataUnAvailable;
+ return get_entropy_avail(entropy_src) ? kDifOk : kDifUnavailable;
}
-dif_entropy_src_result_t dif_entropy_src_read(const dif_entropy_src_t *entropy,
- uint32_t *word) {
- if (entropy == NULL || word == NULL) {
- return kDifEntropySrcBadArg;
+dif_result_t dif_entropy_src_read(const dif_entropy_src_t *entropy_src,
+ uint32_t *word) {
+ if (entropy_src == NULL || word == NULL) {
+ return kDifBadArg;
}
// Check if entropy is available
- if (!get_entropy_avail(entropy)) {
- return kDifEntropySrcDataUnAvailable;
+ if (!get_entropy_avail(entropy_src)) {
+ return kDifUnavailable;
}
- *word = mmio_region_read32(entropy->params.base_addr,
+ *word = mmio_region_read32(entropy_src->base_addr,
ENTROPY_SRC_ENTROPY_DATA_REG_OFFSET);
// clear interrupt state after fetching read
// if there is still entropy available, the interrupt state will set again
- mmio_region_nonatomic_set_bit32(entropy->params.base_addr,
+ mmio_region_nonatomic_set_bit32(entropy_src->base_addr,
ENTROPY_SRC_INTR_STATE_REG_OFFSET,
ENTROPY_SRC_INTR_STATE_ES_ENTROPY_VALID_BIT);
- return kDifEntropySrcOk;
+ return kDifOk;
}
-dif_entropy_src_result_t dif_entropy_src_disable(
- const dif_entropy_src_t *entropy) {
+dif_result_t dif_entropy_src_disable(const dif_entropy_src_t *entropy_src) {
// 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);
+ mmio_region_write32(entropy_src->base_addr, ENTROPY_SRC_CONF_REG_OFFSET, 0);
- return kDifEntropySrcOk;
+ return kDifOk;
}
diff --git a/sw/device/lib/dif/dif_entropy_src.h b/sw/device/lib/dif/dif_entropy_src.h
index 4b921be..517eaca 100644
--- a/sw/device/lib/dif/dif_entropy_src.h
+++ b/sw/device/lib/dif/dif_entropy_src.h
@@ -15,6 +15,9 @@
#include "sw/device/lib/base/macros.h"
#include "sw/device/lib/base/mmio.h"
+#include "sw/device/lib/dif/dif_base.h"
+
+#include "sw/device/lib/dif/autogen/dif_entropy_src_autogen.h"
#ifdef __cplusplus
extern "C" {
@@ -29,23 +32,6 @@
};
/**
- * A toggle state: enabled, or disabled.
- *
- * This enum may be used instead of a `bool` when describing an enabled/disabled
- * state.
- */
-typedef enum dif_entropy_src_toggle {
- /*
- * The "enabled" state.
- */
- kDifEntropySrcToggleEnabled,
- /**
- * The "disabled" state.
- */
- kDifEntropySrcToggleDisabled,
-} dif_entropy_src_toggle_t;
-
-/**
* A statistical test on the bits emitted by an entropy source.
*/
typedef enum dif_entropy_src_test {
@@ -199,20 +185,6 @@
} dif_entropy_src_test_config_t;
/**
- * Hardware instantiation parameters for an entropy source.
- *
- * This struct describes information about the underlying hardware that is
- * not determined until the hardware design is used as part of a top-level
- * design.
- */
-typedef struct dif_entropy_src_params {
- /**
- * The base address for the entropy source hardware registers.
- */
- mmio_region_t base_addr;
-} dif_entropy_src_params_t;
-
-/**
* Runtime configuration for an entropy source.
*
* This struct describes runtime information for one-time configuration of the
@@ -283,15 +255,6 @@
} dif_entropy_src_config_t;
/**
- * A handle to an entropy source.
- *
- * This type should be treated as opaque by users.
- */
-typedef struct dif_entropy {
- 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.
@@ -340,71 +303,6 @@
} dif_entropy_src_test_stats_t;
/**
- * The result of an entropy source operation.
- */
-typedef enum dif_entropy_src_result {
- /**
- * Indicates that the operation succeeded.
- */
- kDifEntropySrcOk = 0,
- /**
- * Indicates some unspecified failure.
- */
- kDifEntropySrcError = 1,
- /**
- * Indicates that some parameter passed into a function failed a
- * precondition.
- *
- * When this value is returned, no hardware operations occured.
- */
- kDifEntropySrcBadArg = 2,
- /**
- * Indicates that this operation has been locked out, and can never
- * succeed until hardware reset.
- */
- kDifEntropySrcLocked = 3,
- /**
- * Indicates that entropy is not yet available for software consumption
- */
- kDifEntropySrcDataUnAvailable = 4,
- /**
- * Indicates that entropy is not idle
- */
- kDifEntropySrcNotIdle = 5,
-} dif_entropy_src_result_t;
-
-/**
- * An entropy source interrupt request type.
- */
-typedef enum dif_entropy_src_irq {
- /**
- * Indicates that bits of entropy are available to consume.
- */
- kDifEntropySrcIrqAvailable,
-
- /**
- * Indicates that the health test has failed and the alert count has been
- * met.
- */
- kDifEntropySrcIrqUnhealthy,
-
- /**
- * Indicates that an internal error occured in the FIFO, or if an illegal
- * state machine state is reached.
- */
- 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_src_irq_disable_all()` and `dif_entropy_src_irq_restore_all()`
- * functions.
- */
-typedef uint32_t dif_entropy_src_irq_snapshot_t;
-
-/**
* An entropy source alert type.
*/
typedef enum dif_entropy_src_alert {
@@ -424,13 +322,13 @@
*
* This function does not actuate the hardware.
*
- * @param params Hardware instantiation parameters.
+ * @param base_addr Hardware instantiation parameters.
* @param[out] entropy Out param for the initialized handle.
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
-dif_entropy_src_result_t dif_entropy_src_init(dif_entropy_src_params_t params,
- dif_entropy_src_t *entropy);
+dif_result_t dif_entropy_src_init(mmio_region_t base_addr,
+ dif_entropy_src_t *entropy_src);
/**
* Configures entropy source with runtime information.
@@ -442,8 +340,8 @@
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
-dif_entropy_src_result_t dif_entropy_src_configure(
- const dif_entropy_src_t *entropy, dif_entropy_src_config_t config);
+dif_result_t dif_entropy_src_configure(const dif_entropy_src_t *entropy_src,
+ dif_entropy_src_config_t config);
/**
* Queries the entropy source IP for its revision information.
@@ -453,8 +351,8 @@
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
-dif_entropy_src_result_t dif_entropy_src_get_revision(
- const dif_entropy_src_t *entropy, dif_entropy_src_revision_t *revision);
+dif_result_t dif_entropy_src_get_revision(const dif_entropy_src_t *entropy_src,
+ dif_entropy_src_revision_t *revision);
/**
* Queries the entropy source for health statistics.
@@ -467,9 +365,9 @@
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
-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);
+dif_result_t dif_entropy_src_get_stats(const dif_entropy_src_t *entropy_src,
+ bool fips_mode,
+ dif_entropy_src_test_stats_t *stats);
/**
* Locks out entropy source functionality.
@@ -481,7 +379,7 @@
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
-dif_entropy_src_result_t dif_entropy_src_lock(const dif_entropy_src_t *entropy);
+dif_result_t dif_entropy_src_lock(const dif_entropy_src_t *entropy_src);
/**
* Checks whether this entropy source is locked.
@@ -491,8 +389,8 @@
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
-dif_entropy_src_result_t dif_entropy_src_is_locked(
- const dif_entropy_src_t *entropy, bool *is_locked);
+dif_result_t dif_entropy_src_is_locked(const dif_entropy_src_t *entropy_src,
+ bool *is_locked);
/**
* Checks to see if entropy is available for software consumption
@@ -501,8 +399,7 @@
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
-dif_entropy_src_result_t dif_entropy_src_avail(
- const dif_entropy_src_t *entropy);
+dif_result_t dif_entropy_src_avail(const dif_entropy_src_t *entropy_src);
/**
* Reads off a word of entropy from the entropy source.
@@ -512,98 +409,8 @@
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
-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.
- *
- * @param entropy An entropy source handle.
- * @param irq An interrupt type.
- * @param[out] is_pending Out-param for whether the interrupt is pending.
- * @return The result of the operation.
- */
-OT_WARN_UNUSED_RESULT
-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
- * been successfully serviced.
- *
- * @param entropy An entropy source handle.
- * @param irq An interrupt type.
- * @return The result of the operation.
- */
-OT_WARN_UNUSED_RESULT
-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.
- *
- * @param entropy An entropy source handle.
- * @param irq An interrupt type.
- * @param[out] state Out-param toggle state of the interrupt.
- * @return The result of the operation.
- */
-OT_WARN_UNUSED_RESULT
-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.
- *
- * @param entropy An entropy source handle.
- * @param irq An interrupt type.
- * @param state The new toggle state for the interrupt.
- * @return The result of the operation.
- */
-OT_WARN_UNUSED_RESULT
-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
- * asserted it.
- *
- * @param entropy An entropy source handle.
- * @param irq An interrupt type.
- * @return The result of the operation.
- */
-OT_WARN_UNUSED_RESULT
-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
- * restoration.
- *
- * @param entropy An entropy source handle.
- * @param[out] snapshot Out-param for the snapshot; may be `NULL`.
- * @return The result of the operation.
- */
-OT_WARN_UNUSED_RESULT
-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_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.
- */
-OT_WARN_UNUSED_RESULT
-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);
+dif_result_t dif_entropy_src_read(const dif_entropy_src_t *entropy_src,
+ uint32_t *word);
/**
* Forces a particular alert, causing it to be emitted as if the hardware had
@@ -614,8 +421,8 @@
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
-dif_entropy_src_result_t dif_entropy_src_alert_force(
- const dif_entropy_src_t *entropy, dif_entropy_src_alert_t alert);
+dif_result_t dif_entropy_src_alert_force(const dif_entropy_src_t *entropy_src,
+ dif_entropy_src_alert_t alert);
/**
* Performs an override read from the entropy pipeline.
@@ -632,8 +439,8 @@
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
-dif_entropy_src_result_t dif_entropy_src_fifo_read(
- const dif_entropy_src_t *entropy, uint32_t *buf, size_t len);
+dif_result_t dif_entropy_src_fifo_read(const dif_entropy_src_t *entropy_src,
+ uint32_t *buf, size_t len);
/**
* Performs an override write to the entropy pipeline.
@@ -648,8 +455,8 @@
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
-dif_entropy_src_result_t dif_entropy_src_fifo_write(
- const dif_entropy_src_t *entropy, const uint32_t *buf, size_t len);
+dif_result_t dif_entropy_src_fifo_write(const dif_entropy_src_t *entropy_src,
+ const uint32_t *buf, size_t len);
/**
* Gets the current number of entries in the pre-conditioner FIFO.
@@ -661,8 +468,8 @@
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
-dif_entropy_src_result_t dif_entropy_src_fifo_get_len(
- const dif_entropy_src_t *entropy, uint8_t *len);
+dif_result_t dif_entropy_src_fifo_get_len(const dif_entropy_src_t *entropy_src,
+ uint8_t *len);
/**
* Gets the current capacity of the pre-conditioner FIFO.
@@ -672,8 +479,8 @@
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
-dif_entropy_src_result_t dif_entropy_src_fifo_get_capacity(
- const dif_entropy_src_t *entropy, uint8_t *capacity);
+dif_result_t dif_entropy_src_fifo_get_capacity(
+ const dif_entropy_src_t *entropy_src, uint8_t *capacity);
/**
* Sets the current capacity of the pre-conditioner FIFO.
@@ -686,8 +493,8 @@
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
-dif_entropy_src_result_t dif_entropy_src_fifo_set_capacity(
- const dif_entropy_src_t *entropy, uint8_t capacity);
+dif_result_t dif_entropy_src_fifo_set_capacity(
+ const dif_entropy_src_t *entropy_src, uint8_t capacity);
/**
* Reconnects the entropy pipeline after an operation that pauses it.
@@ -700,8 +507,8 @@
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
-dif_entropy_src_result_t dif_entropy_src_fifo_reconnect(
- const dif_entropy_src_t *entropy);
+dif_result_t dif_entropy_src_fifo_reconnect(
+ const dif_entropy_src_t *entropy_src);
/**
* Disables the entropy module
@@ -710,8 +517,7 @@
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
-dif_entropy_src_result_t dif_entropy_src_disable(
- const dif_entropy_src_t *entropy);
+dif_result_t dif_entropy_src_disable(const dif_entropy_src_t *entropy_src);
/**
* Get main entropy fsm idle status
@@ -720,8 +526,7 @@
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
-dif_entropy_src_result_t dif_entropy_src_get_idle(
- const dif_entropy_src_t *entropy);
+dif_result_t dif_entropy_src_get_idle(const dif_entropy_src_t *entropy_src);
#ifdef __cplusplus
} // extern "C"
diff --git a/sw/device/lib/dif/dif_entropy_src_unittest.cc b/sw/device/lib/dif/dif_entropy_src_unittest.cc
index 7e45bf4..d474973 100644
--- a/sw/device/lib/dif/dif_entropy_src_unittest.cc
+++ b/sw/device/lib/dif/dif_entropy_src_unittest.cc
@@ -7,6 +7,7 @@
#include "gtest/gtest.h"
#include "sw/device/lib/base/mmio.h"
#include "sw/device/lib/base/testing/mock_mmio.h"
+#include "sw/device/lib/dif/dif_base.h"
#include "entropy_src_regs.h" // Generated
@@ -15,21 +16,18 @@
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()},
- };
+ const dif_entropy_src_t entropy_src_ = {.base_addr = dev().region()};
};
class InitTest : public DifEntropySrcTest {};
TEST_F(InitTest, BadArgs) {
- EXPECT_EQ(dif_entropy_src_init(params_, nullptr), kDifEntropySrcBadArg);
+ EXPECT_EQ(dif_entropy_src_init(dev().region(), nullptr), kDifBadArg);
}
TEST_F(InitTest, Init) {
dif_entropy_src_t entropy;
- EXPECT_EQ(dif_entropy_src_init(params_, &entropy), kDifEntropySrcOk);
+ EXPECT_EQ(dif_entropy_src_init(dev().region(), &entropy), kDifOk);
}
class ConfigTest : public DifEntropySrcTest {
@@ -48,13 +46,12 @@
};
TEST_F(ConfigTest, NullArgs) {
- EXPECT_EQ(dif_entropy_src_configure(nullptr, {}), kDifEntropySrcBadArg);
+ EXPECT_EQ(dif_entropy_src_configure(nullptr, {}), kDifBadArg);
}
TEST_F(ConfigTest, LfsrSeedBadArg) {
config_.lfsr_seed = 16;
- EXPECT_EQ(dif_entropy_src_configure(&entropy_, config_),
- kDifEntropySrcBadArg);
+ EXPECT_EQ(dif_entropy_src_configure(&entropy_src_, config_), kDifBadArg);
}
struct ConfigParams {
@@ -114,7 +111,7 @@
{ENTROPY_SRC_CONF_ENABLE_OFFSET, enable},
});
- EXPECT_EQ(dif_entropy_src_configure(&entropy_, config_), kDifEntropySrcOk);
+ EXPECT_EQ(dif_entropy_src_configure(&entropy_src_, config_), kDifOk);
}
INSTANTIATE_TEST_SUITE_P(
@@ -152,18 +149,17 @@
TEST_F(ReadTest, EntropyBadArg) {
uint32_t word;
- EXPECT_EQ(dif_entropy_src_read(nullptr, &word), kDifEntropySrcBadArg);
+ EXPECT_EQ(dif_entropy_src_read(nullptr, &word), kDifBadArg);
}
TEST_F(ReadTest, WordBadArg) {
- EXPECT_EQ(dif_entropy_src_read(&entropy_, nullptr), kDifEntropySrcBadArg);
+ EXPECT_EQ(dif_entropy_src_read(&entropy_src_, nullptr), kDifBadArg);
}
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);
+ EXPECT_EQ(dif_entropy_src_read(&entropy_src_, &got_word), kDifUnavailable);
}
TEST_F(ReadTest, ReadOk) {
@@ -177,7 +173,7 @@
{{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(dif_entropy_src_read(&entropy_src_, &got_word), kDifOk);
EXPECT_EQ(got_word, expected_word);
}
diff --git a/sw/device/lib/dif/meson.build b/sw/device/lib/dif/meson.build
index 97370bd..5ef78c3 100644
--- a/sw/device/lib/dif/meson.build
+++ b/sw/device/lib/dif/meson.build
@@ -648,6 +648,7 @@
dependencies: [
sw_lib_mmio,
sw_lib_bitfield,
+ sw_lib_dif_autogen_entropy_src,
],
)
)
@@ -655,9 +656,11 @@
test('dif_entropy_src_unittest', executable(
'dif_entropy_src_unittest',
sources: [
- hw_ip_entropy_src_reg_h,
- meson.source_root() / 'sw/device/lib/dif/dif_entropy_src.c',
'dif_entropy_src_unittest.cc',
+ 'autogen/dif_entropy_src_autogen_unittest.cc',
+ meson.source_root() / 'sw/device/lib/dif/dif_entropy_src.c',
+ meson.source_root() / 'sw/device/lib/dif/autogen/dif_entropy_src_autogen.c',
+ hw_ip_entropy_src_reg_h,
],
dependencies: [
sw_vendor_gtest,
diff --git a/sw/device/lib/testing/entropy_testutils.c b/sw/device/lib/testing/entropy_testutils.c
index 8707611..6c269cc 100644
--- a/sw/device/lib/testing/entropy_testutils.c
+++ b/sw/device/lib/testing/entropy_testutils.c
@@ -11,14 +11,12 @@
#include "hw/top_earlgrey/sw/autogen/top_earlgrey.h"
static void setup_entropy_src(void) {
- const dif_entropy_src_params_t params = {
- .base_addr = mmio_region_from_addr(TOP_EARLGREY_ENTROPY_SRC_BASE_ADDR),
- };
- dif_entropy_src_t entropy;
- CHECK(dif_entropy_src_init(params, &entropy) == kDifEntropySrcOk);
+ dif_entropy_src_t entropy_src;
+ CHECK_DIF_OK(dif_entropy_src_init(
+ mmio_region_from_addr(TOP_EARLGREY_ENTROPY_SRC_BASE_ADDR), &entropy_src));
// Disable entropy for test purpose, as it has been turned on by ROM
- CHECK(dif_entropy_src_disable(&entropy) == kDifEntropySrcOk);
+ CHECK_DIF_OK(dif_entropy_src_disable(&entropy_src));
const dif_entropy_src_config_t config = {
.mode = kDifEntropySrcModeLfsr,
@@ -38,7 +36,7 @@
.sample_rate = 2,
.lfsr_seed = 0,
};
- CHECK(dif_entropy_src_configure(&entropy, config) == kDifEntropySrcOk);
+ CHECK_DIF_OK(dif_entropy_src_configure(&entropy_src, config));
}
static void setup_csrng(void) {
diff --git a/sw/device/sca/lib/sca.c b/sw/device/sca/lib/sca.c
index ef44435..e894f17 100644
--- a/sw/device/sca/lib/sca.c
+++ b/sw/device/sca/lib/sca.c
@@ -161,11 +161,9 @@
CSRNG_CTRL_REG_OFFSET, CSRNG_CTRL_REG_RESVAL);
}
if (disable & kScaPeripheralEntropy) {
- const dif_entropy_src_params_t entropy_params = {
- .base_addr = mmio_region_from_addr(TOP_EARLGREY_ENTROPY_SRC_BASE_ADDR),
- };
dif_entropy_src_t entropy;
- IGNORE_RESULT(dif_entropy_src_init(entropy_params, &entropy));
+ IGNORE_RESULT(dif_entropy_src_init(
+ mmio_region_from_addr(TOP_EARLGREY_ENTROPY_SRC_BASE_ADDR), &entropy));
IGNORE_RESULT(dif_entropy_src_disable(&entropy));
}
diff --git a/sw/device/tests/entropy_src_smoketest.c b/sw/device/tests/entropy_src_smoketest.c
index 67fed96..089b390 100644
--- a/sw/device/tests/entropy_src_smoketest.c
+++ b/sw/device/tests/entropy_src_smoketest.c
@@ -21,14 +21,12 @@
};
bool test_main() {
- const dif_entropy_src_params_t params = {
- .base_addr = mmio_region_from_addr(TOP_EARLGREY_ENTROPY_SRC_BASE_ADDR),
- };
- dif_entropy_src_t entropy;
- CHECK(dif_entropy_src_init(params, &entropy) == kDifEntropySrcOk);
+ dif_entropy_src_t entropy_src;
+ CHECK_DIF_OK(dif_entropy_src_init(
+ mmio_region_from_addr(TOP_EARLGREY_ENTROPY_SRC_BASE_ADDR), &entropy_src));
// Disable entropy for test purpose, as it has been turned on by ROM
- CHECK(dif_entropy_src_disable(&entropy) == kDifEntropySrcOk);
+ CHECK_DIF_OK(dif_entropy_src_disable(&entropy_src));
const dif_entropy_src_config_t config = {
.mode = kDifEntropySrcModeLfsr,
@@ -48,13 +46,13 @@
.sample_rate = 2,
.lfsr_seed = 2,
};
- CHECK(dif_entropy_src_configure(&entropy, config) == kDifEntropySrcOk);
+ CHECK_DIF_OK(dif_entropy_src_configure(&entropy_src, config));
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_src_read(&entropy, &entropy_data[i]) != kDifEntropySrcOk)
+ while (dif_entropy_src_read(&entropy_src, &entropy_data[i]) != kDifOk)
;
LOG_INFO("received 0x%x, expectecd 0x%x", entropy_data[i],
kExpectedEntropyData[i]);