[dif/edn] Integrate autogen'd IRQ DIFs into source tree.
This commit partially addresses #8142. Specifically it:
1. deprecates existing (manually implemented) Entropy Distribution Network
IRQ DIFs,
2. integrates the auto-generated Entropy Distribution Network IRQ DIFs
into meson build targets, and
3. refactors all existing source code to make use of the new auto-genenerated
Entropy Distribution Network IRQ DIFs, and supporting shared DIF typedefs
and error codes.
This continues the long-term goal of auto-generating all IRQ DIFs across
all IPs, as described in #8142.
Signed-off-by: Timothy Trippel <ttrippel@google.com>
diff --git a/sw/device/lib/dif/autogen/meson.build b/sw/device/lib/dif/autogen/meson.build
index de4db56..55eee1a 100644
--- a/sw/device/lib/dif/autogen/meson.build
+++ b/sw/device/lib/dif/autogen/meson.build
@@ -2,13 +2,13 @@
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
-# Autogen OTBN DIF library
-sw_lib_dif_autogen_otbn = declare_dependency(
+# Autogen EDN DIF library
+sw_lib_dif_autogen_edn = declare_dependency(
link_with: static_library(
- 'sw_lib_dif_autogen_otbn',
+ 'sw_lib_dif_autogen_edn',
sources: [
- hw_ip_otbn_reg_h,
- 'dif_otbn_autogen.c',
+ hw_ip_edn_reg_h,
+ 'dif_edn_autogen.c',
],
dependencies: [
sw_lib_mmio,
@@ -142,6 +142,20 @@
)
)
+# Autogen OTBN DIF library
+sw_lib_dif_autogen_otbn = declare_dependency(
+ link_with: static_library(
+ 'sw_lib_dif_autogen_otbn',
+ sources: [
+ hw_ip_otbn_reg_h,
+ 'dif_otbn_autogen.c',
+ ],
+ dependencies: [
+ sw_lib_mmio,
+ ],
+ )
+)
+
# Autogen UART DIF library
sw_lib_dif_autogen_uart = declare_dependency(
link_with: static_library(
diff --git a/sw/device/lib/dif/dif_edn.h b/sw/device/lib/dif/dif_edn.h
index 0d312ad..67d7a4e 100644
--- a/sw/device/lib/dif/dif_edn.h
+++ b/sw/device/lib/dif/dif_edn.h
@@ -45,6 +45,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_edn_autogen.h"
#ifdef __cplusplus
extern "C" {
@@ -59,77 +62,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_edn_toggle {
- /*
- * The "enabled" state.
- */
- kDifEdnToggleEnabled,
- /**
- * The "disabled" state.
- */
- kDifEdnToggleDisabled,
-} dif_edn_toggle_t;
-
-/**
- * Hardware instantiation parameters for Entropy Distribution Network.
- *
- * 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_edn_params {
- /**
- * The base address for the Entropy Distribution Network hardware registers.
- */
- mmio_region_t base_addr;
-} dif_edn_params_t;
-
-/**
- * A handle to Entropy Distribution Network.
- *
- * This type should be treated as opaque by users.
- */
-typedef struct dif_edn {
- dif_edn_params_t params;
-} dif_edn_t;
-
-/**
- * The result of a Entropy Distribution Network operation.
- */
-typedef enum dif_edn_result {
- /**
- * Indicates that the operation succeeded.
- */
- kDifEdnOk = 0,
- /**
- * Indicates some unspecified failure.
- */
- kDifEdnError = 1,
- /**
- * Indicates that some parameter passed into a function failed a
- * precondition.
- *
- * When this value is returned, no hardware operations occurred.
- */
- kDifEdnBadArg = 2,
- /**
- * Indicates that this operation has been locked out, and can never
- * succeed until hardware reset.
- */
- kDifEdnLocked = 3,
- /**
- * Indicates that the device is busy and cannot perform the requested
- * operation.
- */
- kDifEdnBusy = 4,
-} dif_edn_result_t;
-
-/**
* CSRNG additional parameters for instantiate and generate commands.
*/
typedef struct dif_edn_seed_material {
@@ -170,38 +102,16 @@
} dif_edn_auto_params_t;
/**
- * A Entropy Distribution Network interrupt request type.
- */
-typedef enum dif_edn_irq {
- /**
- * Asserted when a CSRNG request has completed.
- */
- kDifEdnCmdReqDone,
- /**
- * Asserted when a FIFO error occurs.
- */
- kDifEdnFatalError,
-} dif_edn_irq_t;
-
-/**
- * A snapshot of the enablement state of the interrupts the device.
- *
- * This is an opaque type, to be used with the `dif_edn_irq_disable_all()` and
- * `dif_edn_irq_restore_all()` functions.
- */
-typedef uint32_t dif_edn_irq_snapshot_t;
-
-/**
* Creates a new handle for Entropy Distribution Network.
*
* This function does not actuate the hardware.
*
- * @param params Hardware instantiation parameters.
+ * @param base_addr Hardware instantiation base address.
* @param[out] edn Out param for the initialized handle.
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
-dif_edn_result_t dif_edn_init(dif_edn_params_t params, dif_edn_t *edn);
+dif_result_t dif_edn_init(mmio_region_t base_addr, dif_edn_t *edn);
/**
* Configures Entropy Distribution Network with runtime information.
@@ -212,7 +122,7 @@
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
-dif_edn_result_t dif_edn_configure(const dif_edn_t *edn);
+dif_result_t dif_edn_configure(const dif_edn_t *edn);
/**
* Enables the Entropy Distribution Network in boot-time mode.
@@ -224,7 +134,7 @@
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
-dif_edn_result_t dif_edn_boot_mode_start(const dif_edn_t *edn);
+dif_result_t dif_edn_boot_mode_start(const dif_edn_t *edn);
/**
* Enables the Entropy Distribution Network in auto refresh mode.
@@ -237,8 +147,8 @@
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
-dif_edn_result_t dif_edn_auto_mode_start(const dif_edn_t *edn,
- dif_edn_auto_params_t *config);
+dif_result_t dif_edn_auto_mode_start(const dif_edn_t *edn,
+ dif_edn_auto_params_t *config);
/**
* EDN Status flags.
@@ -263,8 +173,8 @@
* @param set Flag state (set/unset).
* @return The result of the operation.
*/
-dif_edn_result_t dif_edn_get_status(const dif_edn_t *edn, dif_edn_status_t flag,
- bool *set);
+dif_result_t dif_edn_get_status(const dif_edn_t *edn, dif_edn_status_t flag,
+ bool *set);
/**
* Stops the current mode of operation and disables the entropy module.
@@ -273,7 +183,7 @@
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
-dif_edn_result_t dif_edn_stop(const dif_edn_t *edn);
+dif_result_t dif_edn_stop(const dif_edn_t *edn);
/**
* Locks out Entropy Distribution Network functionality.
@@ -285,7 +195,7 @@
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
-dif_edn_result_t dif_edn_lock(const dif_edn_t *edn);
+dif_result_t dif_edn_lock(const dif_edn_t *edn);
/**
* Checks whether this Entropy Distribution Network is locked.
@@ -295,94 +205,7 @@
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
-dif_edn_result_t dif_edn_is_locked(const dif_edn_t *edn, bool *is_locked);
-
-/**
- * Returns whether a particular interrupt is currently pending.
- *
- * @param edn An Entropy Distribution Network 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_edn_result_t dif_edn_irq_is_pending(const dif_edn_t *edn, dif_edn_irq_t irq,
- bool *is_pending);
-
-/**
- * Acknowledges a particular interrupt, indicating to the hardware that it has
- * been successfully serviced.
- *
- * @param edn An Entropy Distribution Network handle.
- * @param irq An interrupt type.
- * @return The result of the operation.
- */
-OT_WARN_UNUSED_RESULT
-dif_edn_result_t dif_edn_irq_acknowledge(const dif_edn_t *edn,
- dif_edn_irq_t irq);
-
-/**
- * Checks whether a particular interrupt is currently enabled or disabled.
- *
- * @param edn An Entropy Distribution Network 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_edn_result_t dif_edn_irq_get_enabled(const dif_edn_t *edn,
- dif_edn_irq_t irq,
- dif_edn_toggle_t *state);
-
-/**
- * Sets whether a particular interrupt is currently enabled or disabled.
- *
- * @param edn An Entropy Distribution Network 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_edn_result_t dif_edn_irq_set_enabled(const dif_edn_t *edn,
- dif_edn_irq_t irq,
- dif_edn_toggle_t state);
-
-/**
- * Forces a particular interrupt, causing it to be serviced as if hardware had
- * asserted it.
- *
- * @param edn An Entropy Distribution Network handle.
- * @param irq An interrupt type.
- * @return The result of the operation.
- */
-OT_WARN_UNUSED_RESULT
-dif_edn_result_t dif_edn_irq_force(const dif_edn_t *edn, dif_edn_irq_t irq);
-
-/**
- * Disables all interrupts, optionally snapshotting all toggle state for later
- * restoration.
- *
- * @param edn An Entropy Distribution Network handle.
- * @param[out] snapshot Out-param for the snapshot; may be `NULL`.
- * @return The result of the operation.
- */
-OT_WARN_UNUSED_RESULT
-dif_edn_result_t dif_edn_irq_disable_all(const dif_edn_t *edn,
- dif_edn_irq_snapshot_t *snapshot);
-
-/**
- * Restores interrupts from the given snapshot.
- *
- * This function can be used with `dif_edn_irq_disable_all()` to temporary
- * interrupt save-and-restore.
- *
- * @param edn An Entropy Distribution Network handle.
- * @param snapshot A snapshot to restore from.
- * @return The result of the operation.
- */
-OT_WARN_UNUSED_RESULT
-dif_edn_result_t dif_edn_irq_restore_all(
- const dif_edn_t *edn, const dif_edn_irq_snapshot_t *snapshot);
+dif_result_t dif_edn_is_locked(const dif_edn_t *edn, bool *is_locked);
#ifdef __cplusplus
} // extern "C"
diff --git a/sw/device/lib/dif/meson.build b/sw/device/lib/dif/meson.build
index 783c7b0..32089d2 100644
--- a/sw/device/lib/dif/meson.build
+++ b/sw/device/lib/dif/meson.build
@@ -81,10 +81,29 @@
],
dependencies: [
sw_lib_mmio,
+ sw_lib_dif_autogen_edn,
],
)
)
+test('dif_edn_unittest', executable(
+ 'dif_edn_unittest',
+ sources: [
+ 'autogen/dif_edn_autogen_unittest.cc',
+ meson.source_root() / 'sw/device/lib/dif/dif_edn.c',
+ meson.source_root() / 'sw/device/lib/dif/autogen/dif_edn_autogen.c',
+ hw_ip_edn_reg_h,
+ ],
+ dependencies: [
+ sw_vendor_gtest,
+ sw_lib_base_testing_mock_mmio,
+ ],
+ native: true,
+ c_args: ['-DMOCK_MMIO'],
+ cpp_args: ['-DMOCK_MMIO'],
+ ),
+ suite: 'dif',
+)
# UART DIF library (dif_uart)
sw_lib_dif_uart = declare_dependency(