diff --git a/sw/device/lib/dif/autogen/dif_aes_autogen.c b/sw/device/lib/dif/autogen/dif_aes_autogen.c index 86063214915e8..f4fdd1ab73986 100644 --- a/sw/device/lib/dif/autogen/dif_aes_autogen.c +++ b/sw/device/lib/dif/autogen/dif_aes_autogen.c @@ -7,3 +7,14 @@ #include "sw/device/lib/dif/autogen/dif_aes_autogen.h" #include "aes_regs.h" // Generated. + +OT_WARN_UNUSED_RESULT +dif_result_t dif_aes_init(mmio_region_t base_addr, dif_aes_t *aes) { + if (aes == NULL) { + return kDifBadArg; + } + + aes->base_addr = base_addr; + + return kDifOk; +} diff --git a/sw/device/lib/dif/autogen/dif_aes_autogen.h b/sw/device/lib/dif/autogen/dif_aes_autogen.h index 4582fa46874aa..ff4b4f7ade142 100644 --- a/sw/device/lib/dif/autogen/dif_aes_autogen.h +++ b/sw/device/lib/dif/autogen/dif_aes_autogen.h @@ -35,6 +35,18 @@ typedef struct dif_aes { mmio_region_t base_addr; } dif_aes_t; +/** + * Creates a new handle for a(n) aes peripheral. + * + * This function does not actuate the hardware. + * + * @param base_addr The MMIO base address of the aes peripheral. + * @param[out] aes Out param for the initialized handle. + * @return The result of the operation. + */ +OT_WARN_UNUSED_RESULT +dif_result_t dif_aes_init(mmio_region_t base_addr, dif_aes_t *aes); + #ifdef __cplusplus } // extern "C" #endif // __cplusplus diff --git a/sw/device/lib/dif/autogen/dif_aes_autogen_unittest.cc b/sw/device/lib/dif/autogen/dif_aes_autogen_unittest.cc index 97bc0f9025c0f..4c1f1f7e1d2c2 100644 --- a/sw/device/lib/dif/autogen/dif_aes_autogen_unittest.cc +++ b/sw/device/lib/dif/autogen/dif_aes_autogen_unittest.cc @@ -16,6 +16,7 @@ namespace dif_aes_autogen_unittest { namespace { using ::mock_mmio::MmioTest; using ::mock_mmio::MockDevice; +using ::testing::Eq; using ::testing::Test; class AesTest : public Test, public MmioTest { @@ -23,5 +24,15 @@ class AesTest : public Test, public MmioTest { dif_aes_t aes_ = {.base_addr = dev().region()}; }; +class InitTest : public AesTest {}; + +TEST_F(InitTest, NullArgs) { + EXPECT_EQ(dif_aes_init({.base_addr = dev().region()}, nullptr), kDifBadArg); +} + +TEST_F(InitTest, Success) { + EXPECT_EQ(dif_aes_init({.base_addr = dev().region()}, &aes_), kDifOk); +} + } // namespace } // namespace dif_aes_autogen_unittest diff --git a/sw/device/lib/dif/autogen/dif_alert_handler_autogen.c b/sw/device/lib/dif/autogen/dif_alert_handler_autogen.c index 4f44496471e50..8cec04481c334 100644 --- a/sw/device/lib/dif/autogen/dif_alert_handler_autogen.c +++ b/sw/device/lib/dif/autogen/dif_alert_handler_autogen.c @@ -8,6 +8,18 @@ #include "alert_handler_regs.h" // Generated. +OT_WARN_UNUSED_RESULT +dif_result_t dif_alert_handler_init(mmio_region_t base_addr, + dif_alert_handler_t *alert_handler) { + if (alert_handler == NULL) { + return kDifBadArg; + } + + alert_handler->base_addr = base_addr; + + return kDifOk; +} + /** * Get the corresponding interrupt register bit offset of the IRQ. If the IP's * HJSON does NOT have a field "no_auto_intr_regs = true", then the diff --git a/sw/device/lib/dif/autogen/dif_alert_handler_autogen.h b/sw/device/lib/dif/autogen/dif_alert_handler_autogen.h index 5129e3be62b5f..4ae5615fc9b9b 100644 --- a/sw/device/lib/dif/autogen/dif_alert_handler_autogen.h +++ b/sw/device/lib/dif/autogen/dif_alert_handler_autogen.h @@ -36,6 +36,19 @@ typedef struct dif_alert_handler { mmio_region_t base_addr; } dif_alert_handler_t; +/** + * Creates a new handle for a(n) alert_handler peripheral. + * + * This function does not actuate the hardware. + * + * @param base_addr The MMIO base address of the alert_handler peripheral. + * @param[out] alert_handler Out param for the initialized handle. + * @return The result of the operation. + */ +OT_WARN_UNUSED_RESULT +dif_result_t dif_alert_handler_init(mmio_region_t base_addr, + dif_alert_handler_t *alert_handler); + /** * A alert_handler interrupt request type. */ diff --git a/sw/device/lib/dif/autogen/dif_alert_handler_autogen_unittest.cc b/sw/device/lib/dif/autogen/dif_alert_handler_autogen_unittest.cc index d8fe00f24cb6b..8084450cedf52 100644 --- a/sw/device/lib/dif/autogen/dif_alert_handler_autogen_unittest.cc +++ b/sw/device/lib/dif/autogen/dif_alert_handler_autogen_unittest.cc @@ -16,6 +16,7 @@ namespace dif_alert_handler_autogen_unittest { namespace { using ::mock_mmio::MmioTest; using ::mock_mmio::MockDevice; +using ::testing::Eq; using ::testing::Test; class AlertHandlerTest : public Test, public MmioTest { @@ -23,7 +24,18 @@ class AlertHandlerTest : public Test, public MmioTest { dif_alert_handler_t alert_handler_ = {.base_addr = dev().region()}; }; -using ::testing::Eq; +class InitTest : public AlertHandlerTest {}; + +TEST_F(InitTest, NullArgs) { + EXPECT_EQ(dif_alert_handler_init({.base_addr = dev().region()}, nullptr), + kDifBadArg); +} + +TEST_F(InitTest, Success) { + EXPECT_EQ( + dif_alert_handler_init({.base_addr = dev().region()}, &alert_handler_), + kDifOk); +} class IrqGetStateTest : public AlertHandlerTest {}; diff --git a/sw/device/lib/dif/autogen/dif_aon_timer_autogen.c b/sw/device/lib/dif/autogen/dif_aon_timer_autogen.c index eed4acae44d19..94d583e5ae606 100644 --- a/sw/device/lib/dif/autogen/dif_aon_timer_autogen.c +++ b/sw/device/lib/dif/autogen/dif_aon_timer_autogen.c @@ -16,6 +16,18 @@ static_assert(AON_TIMER_INTR_STATE_WDOG_TIMER_BARK_BIT == AON_TIMER_INTR_TEST_WDOG_TIMER_BARK_BIT, "Expected IRQ bit offsets to match across STATE/TEST regs."); +OT_WARN_UNUSED_RESULT +dif_result_t dif_aon_timer_init(mmio_region_t base_addr, + dif_aon_timer_t *aon_timer) { + if (aon_timer == NULL) { + return kDifBadArg; + } + + aon_timer->base_addr = base_addr; + + return kDifOk; +} + /** * Get the corresponding interrupt register bit offset of the IRQ. If the IP's * HJSON does NOT have a field "no_auto_intr_regs = true", then the diff --git a/sw/device/lib/dif/autogen/dif_aon_timer_autogen.h b/sw/device/lib/dif/autogen/dif_aon_timer_autogen.h index 29bce5282a03d..b147f92910d82 100644 --- a/sw/device/lib/dif/autogen/dif_aon_timer_autogen.h +++ b/sw/device/lib/dif/autogen/dif_aon_timer_autogen.h @@ -36,6 +36,19 @@ typedef struct dif_aon_timer { mmio_region_t base_addr; } dif_aon_timer_t; +/** + * Creates a new handle for a(n) aon_timer peripheral. + * + * This function does not actuate the hardware. + * + * @param base_addr The MMIO base address of the aon_timer peripheral. + * @param[out] aon_timer Out param for the initialized handle. + * @return The result of the operation. + */ +OT_WARN_UNUSED_RESULT +dif_result_t dif_aon_timer_init(mmio_region_t base_addr, + dif_aon_timer_t *aon_timer); + /** * A aon_timer interrupt request type. */ diff --git a/sw/device/lib/dif/autogen/dif_aon_timer_autogen_unittest.cc b/sw/device/lib/dif/autogen/dif_aon_timer_autogen_unittest.cc index 81c52789b8a7d..4e1d8f9716480 100644 --- a/sw/device/lib/dif/autogen/dif_aon_timer_autogen_unittest.cc +++ b/sw/device/lib/dif/autogen/dif_aon_timer_autogen_unittest.cc @@ -16,6 +16,7 @@ namespace dif_aon_timer_autogen_unittest { namespace { using ::mock_mmio::MmioTest; using ::mock_mmio::MockDevice; +using ::testing::Eq; using ::testing::Test; class AonTimerTest : public Test, public MmioTest { @@ -23,7 +24,17 @@ class AonTimerTest : public Test, public MmioTest { dif_aon_timer_t aon_timer_ = {.base_addr = dev().region()}; }; -using ::testing::Eq; +class InitTest : public AonTimerTest {}; + +TEST_F(InitTest, NullArgs) { + EXPECT_EQ(dif_aon_timer_init({.base_addr = dev().region()}, nullptr), + kDifBadArg); +} + +TEST_F(InitTest, Success) { + EXPECT_EQ(dif_aon_timer_init({.base_addr = dev().region()}, &aon_timer_), + kDifOk); +} class IrqGetStateTest : public AonTimerTest {}; diff --git a/sw/device/lib/dif/autogen/dif_clkmgr_autogen.c b/sw/device/lib/dif/autogen/dif_clkmgr_autogen.c index 46935650fee26..68854a4727f23 100644 --- a/sw/device/lib/dif/autogen/dif_clkmgr_autogen.c +++ b/sw/device/lib/dif/autogen/dif_clkmgr_autogen.c @@ -7,3 +7,14 @@ #include "sw/device/lib/dif/autogen/dif_clkmgr_autogen.h" #include "clkmgr_regs.h" // Generated. + +OT_WARN_UNUSED_RESULT +dif_result_t dif_clkmgr_init(mmio_region_t base_addr, dif_clkmgr_t *clkmgr) { + if (clkmgr == NULL) { + return kDifBadArg; + } + + clkmgr->base_addr = base_addr; + + return kDifOk; +} diff --git a/sw/device/lib/dif/autogen/dif_clkmgr_autogen.h b/sw/device/lib/dif/autogen/dif_clkmgr_autogen.h index 1b1d91cc54904..1ef2b0edc39cb 100644 --- a/sw/device/lib/dif/autogen/dif_clkmgr_autogen.h +++ b/sw/device/lib/dif/autogen/dif_clkmgr_autogen.h @@ -35,6 +35,18 @@ typedef struct dif_clkmgr { mmio_region_t base_addr; } dif_clkmgr_t; +/** + * Creates a new handle for a(n) clkmgr peripheral. + * + * This function does not actuate the hardware. + * + * @param base_addr The MMIO base address of the clkmgr peripheral. + * @param[out] clkmgr Out param for the initialized handle. + * @return The result of the operation. + */ +OT_WARN_UNUSED_RESULT +dif_result_t dif_clkmgr_init(mmio_region_t base_addr, dif_clkmgr_t *clkmgr); + #ifdef __cplusplus } // extern "C" #endif // __cplusplus diff --git a/sw/device/lib/dif/autogen/dif_clkmgr_autogen_unittest.cc b/sw/device/lib/dif/autogen/dif_clkmgr_autogen_unittest.cc index 8f8a020718dfe..85cf77ab4097a 100644 --- a/sw/device/lib/dif/autogen/dif_clkmgr_autogen_unittest.cc +++ b/sw/device/lib/dif/autogen/dif_clkmgr_autogen_unittest.cc @@ -16,6 +16,7 @@ namespace dif_clkmgr_autogen_unittest { namespace { using ::mock_mmio::MmioTest; using ::mock_mmio::MockDevice; +using ::testing::Eq; using ::testing::Test; class ClkmgrTest : public Test, public MmioTest { @@ -23,5 +24,16 @@ class ClkmgrTest : public Test, public MmioTest { dif_clkmgr_t clkmgr_ = {.base_addr = dev().region()}; }; +class InitTest : public ClkmgrTest {}; + +TEST_F(InitTest, NullArgs) { + EXPECT_EQ(dif_clkmgr_init({.base_addr = dev().region()}, nullptr), + kDifBadArg); +} + +TEST_F(InitTest, Success) { + EXPECT_EQ(dif_clkmgr_init({.base_addr = dev().region()}, &clkmgr_), kDifOk); +} + } // namespace } // namespace dif_clkmgr_autogen_unittest diff --git a/sw/device/lib/dif/autogen/dif_csrng_autogen.c b/sw/device/lib/dif/autogen/dif_csrng_autogen.c index e59d52c9100bf..3122917c92bc8 100644 --- a/sw/device/lib/dif/autogen/dif_csrng_autogen.c +++ b/sw/device/lib/dif/autogen/dif_csrng_autogen.c @@ -8,6 +8,17 @@ #include "csrng_regs.h" // Generated. +OT_WARN_UNUSED_RESULT +dif_result_t dif_csrng_init(mmio_region_t base_addr, dif_csrng_t *csrng) { + if (csrng == NULL) { + return kDifBadArg; + } + + csrng->base_addr = base_addr; + + return kDifOk; +} + /** * Get the corresponding interrupt register bit offset of the IRQ. If the IP's * HJSON does NOT have a field "no_auto_intr_regs = true", then the diff --git a/sw/device/lib/dif/autogen/dif_csrng_autogen.h b/sw/device/lib/dif/autogen/dif_csrng_autogen.h index 3ae8d0791275c..35989e0741ec9 100644 --- a/sw/device/lib/dif/autogen/dif_csrng_autogen.h +++ b/sw/device/lib/dif/autogen/dif_csrng_autogen.h @@ -35,6 +35,18 @@ typedef struct dif_csrng { mmio_region_t base_addr; } dif_csrng_t; +/** + * Creates a new handle for a(n) csrng peripheral. + * + * This function does not actuate the hardware. + * + * @param base_addr The MMIO base address of the csrng peripheral. + * @param[out] csrng Out param for the initialized handle. + * @return The result of the operation. + */ +OT_WARN_UNUSED_RESULT +dif_result_t dif_csrng_init(mmio_region_t base_addr, dif_csrng_t *csrng); + /** * A csrng interrupt request type. */ diff --git a/sw/device/lib/dif/autogen/dif_csrng_autogen_unittest.cc b/sw/device/lib/dif/autogen/dif_csrng_autogen_unittest.cc index 43154f57d2003..45b5c6325266f 100644 --- a/sw/device/lib/dif/autogen/dif_csrng_autogen_unittest.cc +++ b/sw/device/lib/dif/autogen/dif_csrng_autogen_unittest.cc @@ -16,6 +16,7 @@ namespace dif_csrng_autogen_unittest { namespace { using ::mock_mmio::MmioTest; using ::mock_mmio::MockDevice; +using ::testing::Eq; using ::testing::Test; class CsrngTest : public Test, public MmioTest { @@ -23,7 +24,15 @@ class CsrngTest : public Test, public MmioTest { dif_csrng_t csrng_ = {.base_addr = dev().region()}; }; -using ::testing::Eq; +class InitTest : public CsrngTest {}; + +TEST_F(InitTest, NullArgs) { + EXPECT_EQ(dif_csrng_init({.base_addr = dev().region()}, nullptr), kDifBadArg); +} + +TEST_F(InitTest, Success) { + EXPECT_EQ(dif_csrng_init({.base_addr = dev().region()}, &csrng_), kDifOk); +} class IrqGetStateTest : public CsrngTest {}; diff --git a/sw/device/lib/dif/autogen/dif_edn_autogen.c b/sw/device/lib/dif/autogen/dif_edn_autogen.c index d725b260127d3..c94f8c4977884 100644 --- a/sw/device/lib/dif/autogen/dif_edn_autogen.c +++ b/sw/device/lib/dif/autogen/dif_edn_autogen.c @@ -8,6 +8,17 @@ #include "edn_regs.h" // Generated. +OT_WARN_UNUSED_RESULT +dif_result_t dif_edn_init(mmio_region_t base_addr, dif_edn_t *edn) { + if (edn == NULL) { + return kDifBadArg; + } + + edn->base_addr = base_addr; + + return kDifOk; +} + /** * Get the corresponding interrupt register bit offset of the IRQ. If the IP's * HJSON does NOT have a field "no_auto_intr_regs = true", then the diff --git a/sw/device/lib/dif/autogen/dif_edn_autogen.h b/sw/device/lib/dif/autogen/dif_edn_autogen.h index 2a77874222515..c597a72de74b5 100644 --- a/sw/device/lib/dif/autogen/dif_edn_autogen.h +++ b/sw/device/lib/dif/autogen/dif_edn_autogen.h @@ -35,6 +35,18 @@ typedef struct dif_edn { mmio_region_t base_addr; } dif_edn_t; +/** + * Creates a new handle for a(n) edn peripheral. + * + * This function does not actuate the hardware. + * + * @param base_addr The MMIO base address of the edn peripheral. + * @param[out] edn Out param for the initialized handle. + * @return The result of the operation. + */ +OT_WARN_UNUSED_RESULT +dif_result_t dif_edn_init(mmio_region_t base_addr, dif_edn_t *edn); + /** * A edn interrupt request type. */ diff --git a/sw/device/lib/dif/autogen/dif_edn_autogen_unittest.cc b/sw/device/lib/dif/autogen/dif_edn_autogen_unittest.cc index d3d6896e4ae51..94b25075cf502 100644 --- a/sw/device/lib/dif/autogen/dif_edn_autogen_unittest.cc +++ b/sw/device/lib/dif/autogen/dif_edn_autogen_unittest.cc @@ -16,6 +16,7 @@ namespace dif_edn_autogen_unittest { namespace { using ::mock_mmio::MmioTest; using ::mock_mmio::MockDevice; +using ::testing::Eq; using ::testing::Test; class EdnTest : public Test, public MmioTest { @@ -23,7 +24,15 @@ class EdnTest : public Test, public MmioTest { dif_edn_t edn_ = {.base_addr = dev().region()}; }; -using ::testing::Eq; +class InitTest : public EdnTest {}; + +TEST_F(InitTest, NullArgs) { + EXPECT_EQ(dif_edn_init({.base_addr = dev().region()}, nullptr), kDifBadArg); +} + +TEST_F(InitTest, Success) { + EXPECT_EQ(dif_edn_init({.base_addr = dev().region()}, &edn_), kDifOk); +} class IrqGetStateTest : public EdnTest {}; diff --git a/sw/device/lib/dif/autogen/dif_entropy_src_autogen.c b/sw/device/lib/dif/autogen/dif_entropy_src_autogen.c index fcd4fdc700149..3c778c4318481 100644 --- a/sw/device/lib/dif/autogen/dif_entropy_src_autogen.c +++ b/sw/device/lib/dif/autogen/dif_entropy_src_autogen.c @@ -8,6 +8,18 @@ #include "entropy_src_regs.h" // Generated. +OT_WARN_UNUSED_RESULT +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_src->base_addr = base_addr; + + return kDifOk; +} + /** * Get the corresponding interrupt register bit offset of the IRQ. If the IP's * HJSON does NOT have a field "no_auto_intr_regs = true", then the diff --git a/sw/device/lib/dif/autogen/dif_entropy_src_autogen.h b/sw/device/lib/dif/autogen/dif_entropy_src_autogen.h index 5a2a56f660c48..cb4dcbb6adefe 100644 --- a/sw/device/lib/dif/autogen/dif_entropy_src_autogen.h +++ b/sw/device/lib/dif/autogen/dif_entropy_src_autogen.h @@ -36,6 +36,19 @@ typedef struct dif_entropy_src { mmio_region_t base_addr; } dif_entropy_src_t; +/** + * Creates a new handle for a(n) entropy_src peripheral. + * + * This function does not actuate the hardware. + * + * @param base_addr The MMIO base address of the entropy_src peripheral. + * @param[out] entropy_src Out param for the initialized handle. + * @return The result of the operation. + */ +OT_WARN_UNUSED_RESULT +dif_result_t dif_entropy_src_init(mmio_region_t base_addr, + dif_entropy_src_t *entropy_src); + /** * A entropy_src interrupt request type. */ diff --git a/sw/device/lib/dif/autogen/dif_entropy_src_autogen_unittest.cc b/sw/device/lib/dif/autogen/dif_entropy_src_autogen_unittest.cc index 2560bc2e8d754..0bd92c06a6229 100644 --- a/sw/device/lib/dif/autogen/dif_entropy_src_autogen_unittest.cc +++ b/sw/device/lib/dif/autogen/dif_entropy_src_autogen_unittest.cc @@ -16,6 +16,7 @@ namespace dif_entropy_src_autogen_unittest { namespace { using ::mock_mmio::MmioTest; using ::mock_mmio::MockDevice; +using ::testing::Eq; using ::testing::Test; class EntropySrcTest : public Test, public MmioTest { @@ -23,7 +24,17 @@ class EntropySrcTest : public Test, public MmioTest { dif_entropy_src_t entropy_src_ = {.base_addr = dev().region()}; }; -using ::testing::Eq; +class InitTest : public EntropySrcTest {}; + +TEST_F(InitTest, NullArgs) { + EXPECT_EQ(dif_entropy_src_init({.base_addr = dev().region()}, nullptr), + kDifBadArg); +} + +TEST_F(InitTest, Success) { + EXPECT_EQ(dif_entropy_src_init({.base_addr = dev().region()}, &entropy_src_), + kDifOk); +} class IrqGetStateTest : public EntropySrcTest {}; diff --git a/sw/device/lib/dif/autogen/dif_gpio_autogen.c b/sw/device/lib/dif/autogen/dif_gpio_autogen.c index 595b88a8f7a8c..dedf0e59881f4 100644 --- a/sw/device/lib/dif/autogen/dif_gpio_autogen.c +++ b/sw/device/lib/dif/autogen/dif_gpio_autogen.c @@ -8,6 +8,17 @@ #include "gpio_regs.h" // Generated. +OT_WARN_UNUSED_RESULT +dif_result_t dif_gpio_init(mmio_region_t base_addr, dif_gpio_t *gpio) { + if (gpio == NULL) { + return kDifBadArg; + } + + gpio->base_addr = base_addr; + + return kDifOk; +} + /** * Get the corresponding interrupt register bit offset of the IRQ. If the IP's * HJSON does NOT have a field "no_auto_intr_regs = true", then the diff --git a/sw/device/lib/dif/autogen/dif_gpio_autogen.h b/sw/device/lib/dif/autogen/dif_gpio_autogen.h index 488b1c25ca878..e882b5bc81955 100644 --- a/sw/device/lib/dif/autogen/dif_gpio_autogen.h +++ b/sw/device/lib/dif/autogen/dif_gpio_autogen.h @@ -35,6 +35,18 @@ typedef struct dif_gpio { mmio_region_t base_addr; } dif_gpio_t; +/** + * Creates a new handle for a(n) gpio peripheral. + * + * This function does not actuate the hardware. + * + * @param base_addr The MMIO base address of the gpio peripheral. + * @param[out] gpio Out param for the initialized handle. + * @return The result of the operation. + */ +OT_WARN_UNUSED_RESULT +dif_result_t dif_gpio_init(mmio_region_t base_addr, dif_gpio_t *gpio); + /** * A gpio interrupt request type. */ diff --git a/sw/device/lib/dif/autogen/dif_gpio_autogen_unittest.cc b/sw/device/lib/dif/autogen/dif_gpio_autogen_unittest.cc index 7997d3da2dc66..53fb5d36fb688 100644 --- a/sw/device/lib/dif/autogen/dif_gpio_autogen_unittest.cc +++ b/sw/device/lib/dif/autogen/dif_gpio_autogen_unittest.cc @@ -16,6 +16,7 @@ namespace dif_gpio_autogen_unittest { namespace { using ::mock_mmio::MmioTest; using ::mock_mmio::MockDevice; +using ::testing::Eq; using ::testing::Test; class GpioTest : public Test, public MmioTest { @@ -23,7 +24,15 @@ class GpioTest : public Test, public MmioTest { dif_gpio_t gpio_ = {.base_addr = dev().region()}; }; -using ::testing::Eq; +class InitTest : public GpioTest {}; + +TEST_F(InitTest, NullArgs) { + EXPECT_EQ(dif_gpio_init({.base_addr = dev().region()}, nullptr), kDifBadArg); +} + +TEST_F(InitTest, Success) { + EXPECT_EQ(dif_gpio_init({.base_addr = dev().region()}, &gpio_), kDifOk); +} class IrqGetStateTest : public GpioTest {}; diff --git a/sw/device/lib/dif/autogen/dif_hmac_autogen.c b/sw/device/lib/dif/autogen/dif_hmac_autogen.c index ae99136498921..8be734b626c7f 100644 --- a/sw/device/lib/dif/autogen/dif_hmac_autogen.c +++ b/sw/device/lib/dif/autogen/dif_hmac_autogen.c @@ -8,6 +8,17 @@ #include "hmac_regs.h" // Generated. +OT_WARN_UNUSED_RESULT +dif_result_t dif_hmac_init(mmio_region_t base_addr, dif_hmac_t *hmac) { + if (hmac == NULL) { + return kDifBadArg; + } + + hmac->base_addr = base_addr; + + return kDifOk; +} + /** * Get the corresponding interrupt register bit offset of the IRQ. If the IP's * HJSON does NOT have a field "no_auto_intr_regs = true", then the diff --git a/sw/device/lib/dif/autogen/dif_hmac_autogen.h b/sw/device/lib/dif/autogen/dif_hmac_autogen.h index c9bab9a29b05f..8cda2120499db 100644 --- a/sw/device/lib/dif/autogen/dif_hmac_autogen.h +++ b/sw/device/lib/dif/autogen/dif_hmac_autogen.h @@ -35,6 +35,18 @@ typedef struct dif_hmac { mmio_region_t base_addr; } dif_hmac_t; +/** + * Creates a new handle for a(n) hmac peripheral. + * + * This function does not actuate the hardware. + * + * @param base_addr The MMIO base address of the hmac peripheral. + * @param[out] hmac Out param for the initialized handle. + * @return The result of the operation. + */ +OT_WARN_UNUSED_RESULT +dif_result_t dif_hmac_init(mmio_region_t base_addr, dif_hmac_t *hmac); + /** * A hmac interrupt request type. */ diff --git a/sw/device/lib/dif/autogen/dif_hmac_autogen_unittest.cc b/sw/device/lib/dif/autogen/dif_hmac_autogen_unittest.cc index 500fe6fc89ada..0248b23523a71 100644 --- a/sw/device/lib/dif/autogen/dif_hmac_autogen_unittest.cc +++ b/sw/device/lib/dif/autogen/dif_hmac_autogen_unittest.cc @@ -16,6 +16,7 @@ namespace dif_hmac_autogen_unittest { namespace { using ::mock_mmio::MmioTest; using ::mock_mmio::MockDevice; +using ::testing::Eq; using ::testing::Test; class HmacTest : public Test, public MmioTest { @@ -23,7 +24,15 @@ class HmacTest : public Test, public MmioTest { dif_hmac_t hmac_ = {.base_addr = dev().region()}; }; -using ::testing::Eq; +class InitTest : public HmacTest {}; + +TEST_F(InitTest, NullArgs) { + EXPECT_EQ(dif_hmac_init({.base_addr = dev().region()}, nullptr), kDifBadArg); +} + +TEST_F(InitTest, Success) { + EXPECT_EQ(dif_hmac_init({.base_addr = dev().region()}, &hmac_), kDifOk); +} class IrqGetStateTest : public HmacTest {}; diff --git a/sw/device/lib/dif/autogen/dif_i2c_autogen.c b/sw/device/lib/dif/autogen/dif_i2c_autogen.c index d11ff0bfa3550..50e1486372f4e 100644 --- a/sw/device/lib/dif/autogen/dif_i2c_autogen.c +++ b/sw/device/lib/dif/autogen/dif_i2c_autogen.c @@ -8,6 +8,17 @@ #include "i2c_regs.h" // Generated. +OT_WARN_UNUSED_RESULT +dif_result_t dif_i2c_init(mmio_region_t base_addr, dif_i2c_t *i2c) { + if (i2c == NULL) { + return kDifBadArg; + } + + i2c->base_addr = base_addr; + + return kDifOk; +} + /** * Get the corresponding interrupt register bit offset of the IRQ. If the IP's * HJSON does NOT have a field "no_auto_intr_regs = true", then the diff --git a/sw/device/lib/dif/autogen/dif_i2c_autogen.h b/sw/device/lib/dif/autogen/dif_i2c_autogen.h index 003b0209d4ab2..8dcdf718a5f00 100644 --- a/sw/device/lib/dif/autogen/dif_i2c_autogen.h +++ b/sw/device/lib/dif/autogen/dif_i2c_autogen.h @@ -35,6 +35,18 @@ typedef struct dif_i2c { mmio_region_t base_addr; } dif_i2c_t; +/** + * Creates a new handle for a(n) i2c peripheral. + * + * This function does not actuate the hardware. + * + * @param base_addr The MMIO base address of the i2c peripheral. + * @param[out] i2c Out param for the initialized handle. + * @return The result of the operation. + */ +OT_WARN_UNUSED_RESULT +dif_result_t dif_i2c_init(mmio_region_t base_addr, dif_i2c_t *i2c); + /** * A i2c interrupt request type. */ diff --git a/sw/device/lib/dif/autogen/dif_i2c_autogen_unittest.cc b/sw/device/lib/dif/autogen/dif_i2c_autogen_unittest.cc index 1a50349d9d5d8..bfa0d2f761c34 100644 --- a/sw/device/lib/dif/autogen/dif_i2c_autogen_unittest.cc +++ b/sw/device/lib/dif/autogen/dif_i2c_autogen_unittest.cc @@ -16,6 +16,7 @@ namespace dif_i2c_autogen_unittest { namespace { using ::mock_mmio::MmioTest; using ::mock_mmio::MockDevice; +using ::testing::Eq; using ::testing::Test; class I2cTest : public Test, public MmioTest { @@ -23,7 +24,15 @@ class I2cTest : public Test, public MmioTest { dif_i2c_t i2c_ = {.base_addr = dev().region()}; }; -using ::testing::Eq; +class InitTest : public I2cTest {}; + +TEST_F(InitTest, NullArgs) { + EXPECT_EQ(dif_i2c_init({.base_addr = dev().region()}, nullptr), kDifBadArg); +} + +TEST_F(InitTest, Success) { + EXPECT_EQ(dif_i2c_init({.base_addr = dev().region()}, &i2c_), kDifOk); +} class IrqGetStateTest : public I2cTest {}; diff --git a/sw/device/lib/dif/autogen/dif_keymgr_autogen.c b/sw/device/lib/dif/autogen/dif_keymgr_autogen.c index 8cc34dd333dc7..4eae9c2263a81 100644 --- a/sw/device/lib/dif/autogen/dif_keymgr_autogen.c +++ b/sw/device/lib/dif/autogen/dif_keymgr_autogen.c @@ -8,6 +8,17 @@ #include "keymgr_regs.h" // Generated. +OT_WARN_UNUSED_RESULT +dif_result_t dif_keymgr_init(mmio_region_t base_addr, dif_keymgr_t *keymgr) { + if (keymgr == NULL) { + return kDifBadArg; + } + + keymgr->base_addr = base_addr; + + return kDifOk; +} + /** * Get the corresponding interrupt register bit offset of the IRQ. If the IP's * HJSON does NOT have a field "no_auto_intr_regs = true", then the diff --git a/sw/device/lib/dif/autogen/dif_keymgr_autogen.h b/sw/device/lib/dif/autogen/dif_keymgr_autogen.h index 252b01e39c370..1524adc33d190 100644 --- a/sw/device/lib/dif/autogen/dif_keymgr_autogen.h +++ b/sw/device/lib/dif/autogen/dif_keymgr_autogen.h @@ -35,6 +35,18 @@ typedef struct dif_keymgr { mmio_region_t base_addr; } dif_keymgr_t; +/** + * Creates a new handle for a(n) keymgr peripheral. + * + * This function does not actuate the hardware. + * + * @param base_addr The MMIO base address of the keymgr peripheral. + * @param[out] keymgr Out param for the initialized handle. + * @return The result of the operation. + */ +OT_WARN_UNUSED_RESULT +dif_result_t dif_keymgr_init(mmio_region_t base_addr, dif_keymgr_t *keymgr); + /** * A keymgr interrupt request type. */ diff --git a/sw/device/lib/dif/autogen/dif_keymgr_autogen_unittest.cc b/sw/device/lib/dif/autogen/dif_keymgr_autogen_unittest.cc index ff2432660b62a..c9e39b8b63dde 100644 --- a/sw/device/lib/dif/autogen/dif_keymgr_autogen_unittest.cc +++ b/sw/device/lib/dif/autogen/dif_keymgr_autogen_unittest.cc @@ -16,6 +16,7 @@ namespace dif_keymgr_autogen_unittest { namespace { using ::mock_mmio::MmioTest; using ::mock_mmio::MockDevice; +using ::testing::Eq; using ::testing::Test; class KeymgrTest : public Test, public MmioTest { @@ -23,7 +24,16 @@ class KeymgrTest : public Test, public MmioTest { dif_keymgr_t keymgr_ = {.base_addr = dev().region()}; }; -using ::testing::Eq; +class InitTest : public KeymgrTest {}; + +TEST_F(InitTest, NullArgs) { + EXPECT_EQ(dif_keymgr_init({.base_addr = dev().region()}, nullptr), + kDifBadArg); +} + +TEST_F(InitTest, Success) { + EXPECT_EQ(dif_keymgr_init({.base_addr = dev().region()}, &keymgr_), kDifOk); +} class IrqGetStateTest : public KeymgrTest {}; diff --git a/sw/device/lib/dif/autogen/dif_kmac_autogen.c b/sw/device/lib/dif/autogen/dif_kmac_autogen.c index 141f054c55d62..e5fe7c606f62e 100644 --- a/sw/device/lib/dif/autogen/dif_kmac_autogen.c +++ b/sw/device/lib/dif/autogen/dif_kmac_autogen.c @@ -8,6 +8,17 @@ #include "kmac_regs.h" // Generated. +OT_WARN_UNUSED_RESULT +dif_result_t dif_kmac_init(mmio_region_t base_addr, dif_kmac_t *kmac) { + if (kmac == NULL) { + return kDifBadArg; + } + + kmac->base_addr = base_addr; + + return kDifOk; +} + /** * Get the corresponding interrupt register bit offset of the IRQ. If the IP's * HJSON does NOT have a field "no_auto_intr_regs = true", then the diff --git a/sw/device/lib/dif/autogen/dif_kmac_autogen.h b/sw/device/lib/dif/autogen/dif_kmac_autogen.h index a84579f228160..133f4224eb723 100644 --- a/sw/device/lib/dif/autogen/dif_kmac_autogen.h +++ b/sw/device/lib/dif/autogen/dif_kmac_autogen.h @@ -35,6 +35,18 @@ typedef struct dif_kmac { mmio_region_t base_addr; } dif_kmac_t; +/** + * Creates a new handle for a(n) kmac peripheral. + * + * This function does not actuate the hardware. + * + * @param base_addr The MMIO base address of the kmac peripheral. + * @param[out] kmac Out param for the initialized handle. + * @return The result of the operation. + */ +OT_WARN_UNUSED_RESULT +dif_result_t dif_kmac_init(mmio_region_t base_addr, dif_kmac_t *kmac); + /** * A kmac interrupt request type. */ diff --git a/sw/device/lib/dif/autogen/dif_kmac_autogen_unittest.cc b/sw/device/lib/dif/autogen/dif_kmac_autogen_unittest.cc index d16a5da5ee0fa..08e9a3e410872 100644 --- a/sw/device/lib/dif/autogen/dif_kmac_autogen_unittest.cc +++ b/sw/device/lib/dif/autogen/dif_kmac_autogen_unittest.cc @@ -16,6 +16,7 @@ namespace dif_kmac_autogen_unittest { namespace { using ::mock_mmio::MmioTest; using ::mock_mmio::MockDevice; +using ::testing::Eq; using ::testing::Test; class KmacTest : public Test, public MmioTest { @@ -23,7 +24,15 @@ class KmacTest : public Test, public MmioTest { dif_kmac_t kmac_ = {.base_addr = dev().region()}; }; -using ::testing::Eq; +class InitTest : public KmacTest {}; + +TEST_F(InitTest, NullArgs) { + EXPECT_EQ(dif_kmac_init({.base_addr = dev().region()}, nullptr), kDifBadArg); +} + +TEST_F(InitTest, Success) { + EXPECT_EQ(dif_kmac_init({.base_addr = dev().region()}, &kmac_), kDifOk); +} class IrqGetStateTest : public KmacTest {}; diff --git a/sw/device/lib/dif/autogen/dif_lc_ctrl_autogen.c b/sw/device/lib/dif/autogen/dif_lc_ctrl_autogen.c index 79382fb92d954..e3cafbc2357df 100644 --- a/sw/device/lib/dif/autogen/dif_lc_ctrl_autogen.c +++ b/sw/device/lib/dif/autogen/dif_lc_ctrl_autogen.c @@ -7,3 +7,14 @@ #include "sw/device/lib/dif/autogen/dif_lc_ctrl_autogen.h" #include "lc_ctrl_regs.h" // Generated. + +OT_WARN_UNUSED_RESULT +dif_result_t dif_lc_ctrl_init(mmio_region_t base_addr, dif_lc_ctrl_t *lc_ctrl) { + if (lc_ctrl == NULL) { + return kDifBadArg; + } + + lc_ctrl->base_addr = base_addr; + + return kDifOk; +} diff --git a/sw/device/lib/dif/autogen/dif_lc_ctrl_autogen.h b/sw/device/lib/dif/autogen/dif_lc_ctrl_autogen.h index 315022d943eca..82588138e4324 100644 --- a/sw/device/lib/dif/autogen/dif_lc_ctrl_autogen.h +++ b/sw/device/lib/dif/autogen/dif_lc_ctrl_autogen.h @@ -35,6 +35,18 @@ typedef struct dif_lc_ctrl { mmio_region_t base_addr; } dif_lc_ctrl_t; +/** + * Creates a new handle for a(n) lc_ctrl peripheral. + * + * This function does not actuate the hardware. + * + * @param base_addr The MMIO base address of the lc_ctrl peripheral. + * @param[out] lc_ctrl Out param for the initialized handle. + * @return The result of the operation. + */ +OT_WARN_UNUSED_RESULT +dif_result_t dif_lc_ctrl_init(mmio_region_t base_addr, dif_lc_ctrl_t *lc_ctrl); + #ifdef __cplusplus } // extern "C" #endif // __cplusplus diff --git a/sw/device/lib/dif/autogen/dif_lc_ctrl_autogen_unittest.cc b/sw/device/lib/dif/autogen/dif_lc_ctrl_autogen_unittest.cc index b8badcfe64f57..2993a56acfae9 100644 --- a/sw/device/lib/dif/autogen/dif_lc_ctrl_autogen_unittest.cc +++ b/sw/device/lib/dif/autogen/dif_lc_ctrl_autogen_unittest.cc @@ -16,6 +16,7 @@ namespace dif_lc_ctrl_autogen_unittest { namespace { using ::mock_mmio::MmioTest; using ::mock_mmio::MockDevice; +using ::testing::Eq; using ::testing::Test; class LcCtrlTest : public Test, public MmioTest { @@ -23,5 +24,16 @@ class LcCtrlTest : public Test, public MmioTest { dif_lc_ctrl_t lc_ctrl_ = {.base_addr = dev().region()}; }; +class InitTest : public LcCtrlTest {}; + +TEST_F(InitTest, NullArgs) { + EXPECT_EQ(dif_lc_ctrl_init({.base_addr = dev().region()}, nullptr), + kDifBadArg); +} + +TEST_F(InitTest, Success) { + EXPECT_EQ(dif_lc_ctrl_init({.base_addr = dev().region()}, &lc_ctrl_), kDifOk); +} + } // namespace } // namespace dif_lc_ctrl_autogen_unittest diff --git a/sw/device/lib/dif/autogen/dif_otbn_autogen.c b/sw/device/lib/dif/autogen/dif_otbn_autogen.c index b47c2865859e4..fec68e1353982 100644 --- a/sw/device/lib/dif/autogen/dif_otbn_autogen.c +++ b/sw/device/lib/dif/autogen/dif_otbn_autogen.c @@ -8,6 +8,17 @@ #include "otbn_regs.h" // Generated. +OT_WARN_UNUSED_RESULT +dif_result_t dif_otbn_init(mmio_region_t base_addr, dif_otbn_t *otbn) { + if (otbn == NULL) { + return kDifBadArg; + } + + otbn->base_addr = base_addr; + + return kDifOk; +} + /** * Get the corresponding interrupt register bit offset of the IRQ. If the IP's * HJSON does NOT have a field "no_auto_intr_regs = true", then the diff --git a/sw/device/lib/dif/autogen/dif_otbn_autogen.h b/sw/device/lib/dif/autogen/dif_otbn_autogen.h index 61cec43cdc520..c223364897368 100644 --- a/sw/device/lib/dif/autogen/dif_otbn_autogen.h +++ b/sw/device/lib/dif/autogen/dif_otbn_autogen.h @@ -35,6 +35,18 @@ typedef struct dif_otbn { mmio_region_t base_addr; } dif_otbn_t; +/** + * Creates a new handle for a(n) otbn peripheral. + * + * This function does not actuate the hardware. + * + * @param base_addr The MMIO base address of the otbn peripheral. + * @param[out] otbn Out param for the initialized handle. + * @return The result of the operation. + */ +OT_WARN_UNUSED_RESULT +dif_result_t dif_otbn_init(mmio_region_t base_addr, dif_otbn_t *otbn); + /** * A otbn interrupt request type. */ diff --git a/sw/device/lib/dif/autogen/dif_otbn_autogen_unittest.cc b/sw/device/lib/dif/autogen/dif_otbn_autogen_unittest.cc index f55e491436148..041d35f9fc5de 100644 --- a/sw/device/lib/dif/autogen/dif_otbn_autogen_unittest.cc +++ b/sw/device/lib/dif/autogen/dif_otbn_autogen_unittest.cc @@ -16,6 +16,7 @@ namespace dif_otbn_autogen_unittest { namespace { using ::mock_mmio::MmioTest; using ::mock_mmio::MockDevice; +using ::testing::Eq; using ::testing::Test; class OtbnTest : public Test, public MmioTest { @@ -23,7 +24,15 @@ class OtbnTest : public Test, public MmioTest { dif_otbn_t otbn_ = {.base_addr = dev().region()}; }; -using ::testing::Eq; +class InitTest : public OtbnTest {}; + +TEST_F(InitTest, NullArgs) { + EXPECT_EQ(dif_otbn_init({.base_addr = dev().region()}, nullptr), kDifBadArg); +} + +TEST_F(InitTest, Success) { + EXPECT_EQ(dif_otbn_init({.base_addr = dev().region()}, &otbn_), kDifOk); +} class IrqGetStateTest : public OtbnTest {}; diff --git a/sw/device/lib/dif/autogen/dif_otp_ctrl_autogen.c b/sw/device/lib/dif/autogen/dif_otp_ctrl_autogen.c index 1320b3084b474..115e81e9f3846 100644 --- a/sw/device/lib/dif/autogen/dif_otp_ctrl_autogen.c +++ b/sw/device/lib/dif/autogen/dif_otp_ctrl_autogen.c @@ -8,6 +8,18 @@ #include "otp_ctrl_regs.h" // Generated. +OT_WARN_UNUSED_RESULT +dif_result_t dif_otp_ctrl_init(mmio_region_t base_addr, + dif_otp_ctrl_t *otp_ctrl) { + if (otp_ctrl == NULL) { + return kDifBadArg; + } + + otp_ctrl->base_addr = base_addr; + + return kDifOk; +} + /** * Get the corresponding interrupt register bit offset of the IRQ. If the IP's * HJSON does NOT have a field "no_auto_intr_regs = true", then the diff --git a/sw/device/lib/dif/autogen/dif_otp_ctrl_autogen.h b/sw/device/lib/dif/autogen/dif_otp_ctrl_autogen.h index 40f603dd41563..ca53edf4fc7c3 100644 --- a/sw/device/lib/dif/autogen/dif_otp_ctrl_autogen.h +++ b/sw/device/lib/dif/autogen/dif_otp_ctrl_autogen.h @@ -35,6 +35,19 @@ typedef struct dif_otp_ctrl { mmio_region_t base_addr; } dif_otp_ctrl_t; +/** + * Creates a new handle for a(n) otp_ctrl peripheral. + * + * This function does not actuate the hardware. + * + * @param base_addr The MMIO base address of the otp_ctrl peripheral. + * @param[out] otp_ctrl Out param for the initialized handle. + * @return The result of the operation. + */ +OT_WARN_UNUSED_RESULT +dif_result_t dif_otp_ctrl_init(mmio_region_t base_addr, + dif_otp_ctrl_t *otp_ctrl); + /** * A otp_ctrl interrupt request type. */ diff --git a/sw/device/lib/dif/autogen/dif_otp_ctrl_autogen_unittest.cc b/sw/device/lib/dif/autogen/dif_otp_ctrl_autogen_unittest.cc index 112b82abf02c1..62b7400791caf 100644 --- a/sw/device/lib/dif/autogen/dif_otp_ctrl_autogen_unittest.cc +++ b/sw/device/lib/dif/autogen/dif_otp_ctrl_autogen_unittest.cc @@ -16,6 +16,7 @@ namespace dif_otp_ctrl_autogen_unittest { namespace { using ::mock_mmio::MmioTest; using ::mock_mmio::MockDevice; +using ::testing::Eq; using ::testing::Test; class OtpCtrlTest : public Test, public MmioTest { @@ -23,7 +24,17 @@ class OtpCtrlTest : public Test, public MmioTest { dif_otp_ctrl_t otp_ctrl_ = {.base_addr = dev().region()}; }; -using ::testing::Eq; +class InitTest : public OtpCtrlTest {}; + +TEST_F(InitTest, NullArgs) { + EXPECT_EQ(dif_otp_ctrl_init({.base_addr = dev().region()}, nullptr), + kDifBadArg); +} + +TEST_F(InitTest, Success) { + EXPECT_EQ(dif_otp_ctrl_init({.base_addr = dev().region()}, &otp_ctrl_), + kDifOk); +} class IrqGetStateTest : public OtpCtrlTest {}; diff --git a/sw/device/lib/dif/autogen/dif_pinmux_autogen.c b/sw/device/lib/dif/autogen/dif_pinmux_autogen.c index 52f15e0c083f1..aa4941221bc5d 100644 --- a/sw/device/lib/dif/autogen/dif_pinmux_autogen.c +++ b/sw/device/lib/dif/autogen/dif_pinmux_autogen.c @@ -7,3 +7,14 @@ #include "sw/device/lib/dif/autogen/dif_pinmux_autogen.h" #include "pinmux_regs.h" // Generated. + +OT_WARN_UNUSED_RESULT +dif_result_t dif_pinmux_init(mmio_region_t base_addr, dif_pinmux_t *pinmux) { + if (pinmux == NULL) { + return kDifBadArg; + } + + pinmux->base_addr = base_addr; + + return kDifOk; +} diff --git a/sw/device/lib/dif/autogen/dif_pinmux_autogen.h b/sw/device/lib/dif/autogen/dif_pinmux_autogen.h index 1f1f8e48fa00f..21c71cc6d79c9 100644 --- a/sw/device/lib/dif/autogen/dif_pinmux_autogen.h +++ b/sw/device/lib/dif/autogen/dif_pinmux_autogen.h @@ -35,6 +35,18 @@ typedef struct dif_pinmux { mmio_region_t base_addr; } dif_pinmux_t; +/** + * Creates a new handle for a(n) pinmux peripheral. + * + * This function does not actuate the hardware. + * + * @param base_addr The MMIO base address of the pinmux peripheral. + * @param[out] pinmux Out param for the initialized handle. + * @return The result of the operation. + */ +OT_WARN_UNUSED_RESULT +dif_result_t dif_pinmux_init(mmio_region_t base_addr, dif_pinmux_t *pinmux); + #ifdef __cplusplus } // extern "C" #endif // __cplusplus diff --git a/sw/device/lib/dif/autogen/dif_pinmux_autogen_unittest.cc b/sw/device/lib/dif/autogen/dif_pinmux_autogen_unittest.cc index ef3a0748b725f..305211ca2534f 100644 --- a/sw/device/lib/dif/autogen/dif_pinmux_autogen_unittest.cc +++ b/sw/device/lib/dif/autogen/dif_pinmux_autogen_unittest.cc @@ -16,6 +16,7 @@ namespace dif_pinmux_autogen_unittest { namespace { using ::mock_mmio::MmioTest; using ::mock_mmio::MockDevice; +using ::testing::Eq; using ::testing::Test; class PinmuxTest : public Test, public MmioTest { @@ -23,5 +24,16 @@ class PinmuxTest : public Test, public MmioTest { dif_pinmux_t pinmux_ = {.base_addr = dev().region()}; }; +class InitTest : public PinmuxTest {}; + +TEST_F(InitTest, NullArgs) { + EXPECT_EQ(dif_pinmux_init({.base_addr = dev().region()}, nullptr), + kDifBadArg); +} + +TEST_F(InitTest, Success) { + EXPECT_EQ(dif_pinmux_init({.base_addr = dev().region()}, &pinmux_), kDifOk); +} + } // namespace } // namespace dif_pinmux_autogen_unittest diff --git a/sw/device/lib/dif/autogen/dif_pwrmgr_autogen.c b/sw/device/lib/dif/autogen/dif_pwrmgr_autogen.c index e7c131e1c77d9..d466a00081b2d 100644 --- a/sw/device/lib/dif/autogen/dif_pwrmgr_autogen.c +++ b/sw/device/lib/dif/autogen/dif_pwrmgr_autogen.c @@ -8,6 +8,17 @@ #include "pwrmgr_regs.h" // Generated. +OT_WARN_UNUSED_RESULT +dif_result_t dif_pwrmgr_init(mmio_region_t base_addr, dif_pwrmgr_t *pwrmgr) { + if (pwrmgr == NULL) { + return kDifBadArg; + } + + pwrmgr->base_addr = base_addr; + + return kDifOk; +} + /** * Get the corresponding interrupt register bit offset of the IRQ. If the IP's * HJSON does NOT have a field "no_auto_intr_regs = true", then the diff --git a/sw/device/lib/dif/autogen/dif_pwrmgr_autogen.h b/sw/device/lib/dif/autogen/dif_pwrmgr_autogen.h index 044f3e80381e0..aac2334c0f12f 100644 --- a/sw/device/lib/dif/autogen/dif_pwrmgr_autogen.h +++ b/sw/device/lib/dif/autogen/dif_pwrmgr_autogen.h @@ -35,6 +35,18 @@ typedef struct dif_pwrmgr { mmio_region_t base_addr; } dif_pwrmgr_t; +/** + * Creates a new handle for a(n) pwrmgr peripheral. + * + * This function does not actuate the hardware. + * + * @param base_addr The MMIO base address of the pwrmgr peripheral. + * @param[out] pwrmgr Out param for the initialized handle. + * @return The result of the operation. + */ +OT_WARN_UNUSED_RESULT +dif_result_t dif_pwrmgr_init(mmio_region_t base_addr, dif_pwrmgr_t *pwrmgr); + /** * A pwrmgr interrupt request type. */ diff --git a/sw/device/lib/dif/autogen/dif_pwrmgr_autogen_unittest.cc b/sw/device/lib/dif/autogen/dif_pwrmgr_autogen_unittest.cc index 06423b4b799ca..b1afe02b719b4 100644 --- a/sw/device/lib/dif/autogen/dif_pwrmgr_autogen_unittest.cc +++ b/sw/device/lib/dif/autogen/dif_pwrmgr_autogen_unittest.cc @@ -16,6 +16,7 @@ namespace dif_pwrmgr_autogen_unittest { namespace { using ::mock_mmio::MmioTest; using ::mock_mmio::MockDevice; +using ::testing::Eq; using ::testing::Test; class PwrmgrTest : public Test, public MmioTest { @@ -23,7 +24,16 @@ class PwrmgrTest : public Test, public MmioTest { dif_pwrmgr_t pwrmgr_ = {.base_addr = dev().region()}; }; -using ::testing::Eq; +class InitTest : public PwrmgrTest {}; + +TEST_F(InitTest, NullArgs) { + EXPECT_EQ(dif_pwrmgr_init({.base_addr = dev().region()}, nullptr), + kDifBadArg); +} + +TEST_F(InitTest, Success) { + EXPECT_EQ(dif_pwrmgr_init({.base_addr = dev().region()}, &pwrmgr_), kDifOk); +} class IrqGetStateTest : public PwrmgrTest {}; diff --git a/sw/device/lib/dif/autogen/dif_rstmgr_autogen.c b/sw/device/lib/dif/autogen/dif_rstmgr_autogen.c index 3ef0e81e500be..75ce85e8eb3e6 100644 --- a/sw/device/lib/dif/autogen/dif_rstmgr_autogen.c +++ b/sw/device/lib/dif/autogen/dif_rstmgr_autogen.c @@ -7,3 +7,14 @@ #include "sw/device/lib/dif/autogen/dif_rstmgr_autogen.h" #include "rstmgr_regs.h" // Generated. + +OT_WARN_UNUSED_RESULT +dif_result_t dif_rstmgr_init(mmio_region_t base_addr, dif_rstmgr_t *rstmgr) { + if (rstmgr == NULL) { + return kDifBadArg; + } + + rstmgr->base_addr = base_addr; + + return kDifOk; +} diff --git a/sw/device/lib/dif/autogen/dif_rstmgr_autogen.h b/sw/device/lib/dif/autogen/dif_rstmgr_autogen.h index 8596cd9e55b8c..6bf24db8f5066 100644 --- a/sw/device/lib/dif/autogen/dif_rstmgr_autogen.h +++ b/sw/device/lib/dif/autogen/dif_rstmgr_autogen.h @@ -35,6 +35,18 @@ typedef struct dif_rstmgr { mmio_region_t base_addr; } dif_rstmgr_t; +/** + * Creates a new handle for a(n) rstmgr peripheral. + * + * This function does not actuate the hardware. + * + * @param base_addr The MMIO base address of the rstmgr peripheral. + * @param[out] rstmgr Out param for the initialized handle. + * @return The result of the operation. + */ +OT_WARN_UNUSED_RESULT +dif_result_t dif_rstmgr_init(mmio_region_t base_addr, dif_rstmgr_t *rstmgr); + #ifdef __cplusplus } // extern "C" #endif // __cplusplus diff --git a/sw/device/lib/dif/autogen/dif_rstmgr_autogen_unittest.cc b/sw/device/lib/dif/autogen/dif_rstmgr_autogen_unittest.cc index 12bbf7ef0dc1f..0438a584fa6e1 100644 --- a/sw/device/lib/dif/autogen/dif_rstmgr_autogen_unittest.cc +++ b/sw/device/lib/dif/autogen/dif_rstmgr_autogen_unittest.cc @@ -16,6 +16,7 @@ namespace dif_rstmgr_autogen_unittest { namespace { using ::mock_mmio::MmioTest; using ::mock_mmio::MockDevice; +using ::testing::Eq; using ::testing::Test; class RstmgrTest : public Test, public MmioTest { @@ -23,5 +24,16 @@ class RstmgrTest : public Test, public MmioTest { dif_rstmgr_t rstmgr_ = {.base_addr = dev().region()}; }; +class InitTest : public RstmgrTest {}; + +TEST_F(InitTest, NullArgs) { + EXPECT_EQ(dif_rstmgr_init({.base_addr = dev().region()}, nullptr), + kDifBadArg); +} + +TEST_F(InitTest, Success) { + EXPECT_EQ(dif_rstmgr_init({.base_addr = dev().region()}, &rstmgr_), kDifOk); +} + } // namespace } // namespace dif_rstmgr_autogen_unittest diff --git a/sw/device/lib/dif/autogen/dif_rv_plic_autogen.c b/sw/device/lib/dif/autogen/dif_rv_plic_autogen.c index c3c433437858e..04205185c63c7 100644 --- a/sw/device/lib/dif/autogen/dif_rv_plic_autogen.c +++ b/sw/device/lib/dif/autogen/dif_rv_plic_autogen.c @@ -7,3 +7,14 @@ #include "sw/device/lib/dif/autogen/dif_rv_plic_autogen.h" #include "rv_plic_regs.h" // Generated. + +OT_WARN_UNUSED_RESULT +dif_result_t dif_rv_plic_init(mmio_region_t base_addr, dif_rv_plic_t *rv_plic) { + if (rv_plic == NULL) { + return kDifBadArg; + } + + rv_plic->base_addr = base_addr; + + return kDifOk; +} diff --git a/sw/device/lib/dif/autogen/dif_rv_plic_autogen.h b/sw/device/lib/dif/autogen/dif_rv_plic_autogen.h index f0b8097a3e74a..cec00bb71d554 100644 --- a/sw/device/lib/dif/autogen/dif_rv_plic_autogen.h +++ b/sw/device/lib/dif/autogen/dif_rv_plic_autogen.h @@ -35,6 +35,18 @@ typedef struct dif_rv_plic { mmio_region_t base_addr; } dif_rv_plic_t; +/** + * Creates a new handle for a(n) rv_plic peripheral. + * + * This function does not actuate the hardware. + * + * @param base_addr The MMIO base address of the rv_plic peripheral. + * @param[out] rv_plic Out param for the initialized handle. + * @return The result of the operation. + */ +OT_WARN_UNUSED_RESULT +dif_result_t dif_rv_plic_init(mmio_region_t base_addr, dif_rv_plic_t *rv_plic); + #ifdef __cplusplus } // extern "C" #endif // __cplusplus diff --git a/sw/device/lib/dif/autogen/dif_rv_plic_autogen_unittest.cc b/sw/device/lib/dif/autogen/dif_rv_plic_autogen_unittest.cc index 6fbb0f38e9271..cfff9d5624cf7 100644 --- a/sw/device/lib/dif/autogen/dif_rv_plic_autogen_unittest.cc +++ b/sw/device/lib/dif/autogen/dif_rv_plic_autogen_unittest.cc @@ -16,6 +16,7 @@ namespace dif_rv_plic_autogen_unittest { namespace { using ::mock_mmio::MmioTest; using ::mock_mmio::MockDevice; +using ::testing::Eq; using ::testing::Test; class RvPlicTest : public Test, public MmioTest { @@ -23,5 +24,16 @@ class RvPlicTest : public Test, public MmioTest { dif_rv_plic_t rv_plic_ = {.base_addr = dev().region()}; }; +class InitTest : public RvPlicTest {}; + +TEST_F(InitTest, NullArgs) { + EXPECT_EQ(dif_rv_plic_init({.base_addr = dev().region()}, nullptr), + kDifBadArg); +} + +TEST_F(InitTest, Success) { + EXPECT_EQ(dif_rv_plic_init({.base_addr = dev().region()}, &rv_plic_), kDifOk); +} + } // namespace } // namespace dif_rv_plic_autogen_unittest diff --git a/sw/device/lib/dif/autogen/dif_rv_timer_autogen.c b/sw/device/lib/dif/autogen/dif_rv_timer_autogen.c index 60257a34d386f..588d0a0dbaa5d 100644 --- a/sw/device/lib/dif/autogen/dif_rv_timer_autogen.c +++ b/sw/device/lib/dif/autogen/dif_rv_timer_autogen.c @@ -14,6 +14,18 @@ static_assert(RV_TIMER_INTR_STATE0_IS_0_BIT == RV_TIMER_INTR_ENABLE0_IE_0_BIT, static_assert(RV_TIMER_INTR_STATE0_IS_0_BIT == RV_TIMER_INTR_TEST0_T_0_BIT, "Expected IRQ bit offsets to match across STATE/ENABLE regs."); +OT_WARN_UNUSED_RESULT +dif_result_t dif_rv_timer_init(mmio_region_t base_addr, + dif_rv_timer_t *rv_timer) { + if (rv_timer == NULL) { + return kDifBadArg; + } + + rv_timer->base_addr = base_addr; + + return kDifOk; +} + typedef enum dif_rv_timer_intr_reg { kDifRvTimerIntrRegState = 0, kDifRvTimerIntrRegEnable = 1, diff --git a/sw/device/lib/dif/autogen/dif_rv_timer_autogen.h b/sw/device/lib/dif/autogen/dif_rv_timer_autogen.h index 325f101cbfcbd..418eaad9cad59 100644 --- a/sw/device/lib/dif/autogen/dif_rv_timer_autogen.h +++ b/sw/device/lib/dif/autogen/dif_rv_timer_autogen.h @@ -35,6 +35,19 @@ typedef struct dif_rv_timer { mmio_region_t base_addr; } dif_rv_timer_t; +/** + * Creates a new handle for a(n) rv_timer peripheral. + * + * This function does not actuate the hardware. + * + * @param base_addr The MMIO base address of the rv_timer peripheral. + * @param[out] rv_timer Out param for the initialized handle. + * @return The result of the operation. + */ +OT_WARN_UNUSED_RESULT +dif_result_t dif_rv_timer_init(mmio_region_t base_addr, + dif_rv_timer_t *rv_timer); + /** * A rv_timer interrupt request type. */ diff --git a/sw/device/lib/dif/autogen/dif_rv_timer_autogen_unittest.cc b/sw/device/lib/dif/autogen/dif_rv_timer_autogen_unittest.cc index f66280ddf639e..093419f16d89e 100644 --- a/sw/device/lib/dif/autogen/dif_rv_timer_autogen_unittest.cc +++ b/sw/device/lib/dif/autogen/dif_rv_timer_autogen_unittest.cc @@ -16,6 +16,7 @@ namespace dif_rv_timer_autogen_unittest { namespace { using ::mock_mmio::MmioTest; using ::mock_mmio::MockDevice; +using ::testing::Eq; using ::testing::Test; class RvTimerTest : public Test, public MmioTest { @@ -23,7 +24,17 @@ class RvTimerTest : public Test, public MmioTest { dif_rv_timer_t rv_timer_ = {.base_addr = dev().region()}; }; -using ::testing::Eq; +class InitTest : public RvTimerTest {}; + +TEST_F(InitTest, NullArgs) { + EXPECT_EQ(dif_rv_timer_init({.base_addr = dev().region()}, nullptr), + kDifBadArg); +} + +TEST_F(InitTest, Success) { + EXPECT_EQ(dif_rv_timer_init({.base_addr = dev().region()}, &rv_timer_), + kDifOk); +} class IrqGetStateTest : public RvTimerTest {}; diff --git a/sw/device/lib/dif/autogen/dif_spi_device_autogen.c b/sw/device/lib/dif/autogen/dif_spi_device_autogen.c index ce330c8e0fde2..9b730c698c87a 100644 --- a/sw/device/lib/dif/autogen/dif_spi_device_autogen.c +++ b/sw/device/lib/dif/autogen/dif_spi_device_autogen.c @@ -8,6 +8,18 @@ #include "spi_device_regs.h" // Generated. +OT_WARN_UNUSED_RESULT +dif_result_t dif_spi_device_init(mmio_region_t base_addr, + dif_spi_device_t *spi_device) { + if (spi_device == NULL) { + return kDifBadArg; + } + + spi_device->base_addr = base_addr; + + return kDifOk; +} + /** * Get the corresponding interrupt register bit offset of the IRQ. If the IP's * HJSON does NOT have a field "no_auto_intr_regs = true", then the diff --git a/sw/device/lib/dif/autogen/dif_spi_device_autogen.h b/sw/device/lib/dif/autogen/dif_spi_device_autogen.h index a74bddb9f8ef5..1db65bf2cff4f 100644 --- a/sw/device/lib/dif/autogen/dif_spi_device_autogen.h +++ b/sw/device/lib/dif/autogen/dif_spi_device_autogen.h @@ -36,6 +36,19 @@ typedef struct dif_spi_device { mmio_region_t base_addr; } dif_spi_device_t; +/** + * Creates a new handle for a(n) spi_device peripheral. + * + * This function does not actuate the hardware. + * + * @param base_addr The MMIO base address of the spi_device peripheral. + * @param[out] spi_device Out param for the initialized handle. + * @return The result of the operation. + */ +OT_WARN_UNUSED_RESULT +dif_result_t dif_spi_device_init(mmio_region_t base_addr, + dif_spi_device_t *spi_device); + /** * A spi_device interrupt request type. */ diff --git a/sw/device/lib/dif/autogen/dif_spi_device_autogen_unittest.cc b/sw/device/lib/dif/autogen/dif_spi_device_autogen_unittest.cc index faa8f62e4072e..151f208ed7c17 100644 --- a/sw/device/lib/dif/autogen/dif_spi_device_autogen_unittest.cc +++ b/sw/device/lib/dif/autogen/dif_spi_device_autogen_unittest.cc @@ -16,6 +16,7 @@ namespace dif_spi_device_autogen_unittest { namespace { using ::mock_mmio::MmioTest; using ::mock_mmio::MockDevice; +using ::testing::Eq; using ::testing::Test; class SpiDeviceTest : public Test, public MmioTest { @@ -23,7 +24,17 @@ class SpiDeviceTest : public Test, public MmioTest { dif_spi_device_t spi_device_ = {.base_addr = dev().region()}; }; -using ::testing::Eq; +class InitTest : public SpiDeviceTest {}; + +TEST_F(InitTest, NullArgs) { + EXPECT_EQ(dif_spi_device_init({.base_addr = dev().region()}, nullptr), + kDifBadArg); +} + +TEST_F(InitTest, Success) { + EXPECT_EQ(dif_spi_device_init({.base_addr = dev().region()}, &spi_device_), + kDifOk); +} class IrqGetStateTest : public SpiDeviceTest {}; diff --git a/sw/device/lib/dif/autogen/dif_sram_ctrl_autogen.c b/sw/device/lib/dif/autogen/dif_sram_ctrl_autogen.c index fe2a352f09aba..bb61bcfcb283e 100644 --- a/sw/device/lib/dif/autogen/dif_sram_ctrl_autogen.c +++ b/sw/device/lib/dif/autogen/dif_sram_ctrl_autogen.c @@ -7,3 +7,15 @@ #include "sw/device/lib/dif/autogen/dif_sram_ctrl_autogen.h" #include "sram_ctrl_regs.h" // Generated. + +OT_WARN_UNUSED_RESULT +dif_result_t dif_sram_ctrl_init(mmio_region_t base_addr, + dif_sram_ctrl_t *sram_ctrl) { + if (sram_ctrl == NULL) { + return kDifBadArg; + } + + sram_ctrl->base_addr = base_addr; + + return kDifOk; +} diff --git a/sw/device/lib/dif/autogen/dif_sram_ctrl_autogen.h b/sw/device/lib/dif/autogen/dif_sram_ctrl_autogen.h index f2aed1a373e9e..aae2dd411924a 100644 --- a/sw/device/lib/dif/autogen/dif_sram_ctrl_autogen.h +++ b/sw/device/lib/dif/autogen/dif_sram_ctrl_autogen.h @@ -36,6 +36,19 @@ typedef struct dif_sram_ctrl { mmio_region_t base_addr; } dif_sram_ctrl_t; +/** + * Creates a new handle for a(n) sram_ctrl peripheral. + * + * This function does not actuate the hardware. + * + * @param base_addr The MMIO base address of the sram_ctrl peripheral. + * @param[out] sram_ctrl Out param for the initialized handle. + * @return The result of the operation. + */ +OT_WARN_UNUSED_RESULT +dif_result_t dif_sram_ctrl_init(mmio_region_t base_addr, + dif_sram_ctrl_t *sram_ctrl); + #ifdef __cplusplus } // extern "C" #endif // __cplusplus diff --git a/sw/device/lib/dif/autogen/dif_sram_ctrl_autogen_unittest.cc b/sw/device/lib/dif/autogen/dif_sram_ctrl_autogen_unittest.cc index aac7e32ab9fde..996d41ece36d8 100644 --- a/sw/device/lib/dif/autogen/dif_sram_ctrl_autogen_unittest.cc +++ b/sw/device/lib/dif/autogen/dif_sram_ctrl_autogen_unittest.cc @@ -16,6 +16,7 @@ namespace dif_sram_ctrl_autogen_unittest { namespace { using ::mock_mmio::MmioTest; using ::mock_mmio::MockDevice; +using ::testing::Eq; using ::testing::Test; class SramCtrlTest : public Test, public MmioTest { @@ -23,5 +24,17 @@ class SramCtrlTest : public Test, public MmioTest { dif_sram_ctrl_t sram_ctrl_ = {.base_addr = dev().region()}; }; +class InitTest : public SramCtrlTest {}; + +TEST_F(InitTest, NullArgs) { + EXPECT_EQ(dif_sram_ctrl_init({.base_addr = dev().region()}, nullptr), + kDifBadArg); +} + +TEST_F(InitTest, Success) { + EXPECT_EQ(dif_sram_ctrl_init({.base_addr = dev().region()}, &sram_ctrl_), + kDifOk); +} + } // namespace } // namespace dif_sram_ctrl_autogen_unittest diff --git a/sw/device/lib/dif/autogen/dif_uart_autogen.c b/sw/device/lib/dif/autogen/dif_uart_autogen.c index 9017d21460667..9cab1686acd8e 100644 --- a/sw/device/lib/dif/autogen/dif_uart_autogen.c +++ b/sw/device/lib/dif/autogen/dif_uart_autogen.c @@ -8,6 +8,17 @@ #include "uart_regs.h" // Generated. +OT_WARN_UNUSED_RESULT +dif_result_t dif_uart_init(mmio_region_t base_addr, dif_uart_t *uart) { + if (uart == NULL) { + return kDifBadArg; + } + + uart->base_addr = base_addr; + + return kDifOk; +} + /** * Get the corresponding interrupt register bit offset of the IRQ. If the IP's * HJSON does NOT have a field "no_auto_intr_regs = true", then the diff --git a/sw/device/lib/dif/autogen/dif_uart_autogen.h b/sw/device/lib/dif/autogen/dif_uart_autogen.h index ad4d9f92b6f24..880e1abc1d8f4 100644 --- a/sw/device/lib/dif/autogen/dif_uart_autogen.h +++ b/sw/device/lib/dif/autogen/dif_uart_autogen.h @@ -35,6 +35,18 @@ typedef struct dif_uart { mmio_region_t base_addr; } dif_uart_t; +/** + * Creates a new handle for a(n) uart peripheral. + * + * This function does not actuate the hardware. + * + * @param base_addr The MMIO base address of the uart peripheral. + * @param[out] uart Out param for the initialized handle. + * @return The result of the operation. + */ +OT_WARN_UNUSED_RESULT +dif_result_t dif_uart_init(mmio_region_t base_addr, dif_uart_t *uart); + /** * A uart interrupt request type. */ diff --git a/sw/device/lib/dif/autogen/dif_uart_autogen_unittest.cc b/sw/device/lib/dif/autogen/dif_uart_autogen_unittest.cc index 85e8a96a35c4f..e439237e627c3 100644 --- a/sw/device/lib/dif/autogen/dif_uart_autogen_unittest.cc +++ b/sw/device/lib/dif/autogen/dif_uart_autogen_unittest.cc @@ -16,6 +16,7 @@ namespace dif_uart_autogen_unittest { namespace { using ::mock_mmio::MmioTest; using ::mock_mmio::MockDevice; +using ::testing::Eq; using ::testing::Test; class UartTest : public Test, public MmioTest { @@ -23,7 +24,15 @@ class UartTest : public Test, public MmioTest { dif_uart_t uart_ = {.base_addr = dev().region()}; }; -using ::testing::Eq; +class InitTest : public UartTest {}; + +TEST_F(InitTest, NullArgs) { + EXPECT_EQ(dif_uart_init({.base_addr = dev().region()}, nullptr), kDifBadArg); +} + +TEST_F(InitTest, Success) { + EXPECT_EQ(dif_uart_init({.base_addr = dev().region()}, &uart_), kDifOk); +} class IrqGetStateTest : public UartTest {}; diff --git a/sw/device/lib/dif/autogen/dif_usbdev_autogen.c b/sw/device/lib/dif/autogen/dif_usbdev_autogen.c index 366b40d81848d..c25af29c40644 100644 --- a/sw/device/lib/dif/autogen/dif_usbdev_autogen.c +++ b/sw/device/lib/dif/autogen/dif_usbdev_autogen.c @@ -8,6 +8,17 @@ #include "usbdev_regs.h" // Generated. +OT_WARN_UNUSED_RESULT +dif_result_t dif_usbdev_init(mmio_region_t base_addr, dif_usbdev_t *usbdev) { + if (usbdev == NULL) { + return kDifBadArg; + } + + usbdev->base_addr = base_addr; + + return kDifOk; +} + /** * Get the corresponding interrupt register bit offset of the IRQ. If the IP's * HJSON does NOT have a field "no_auto_intr_regs = true", then the diff --git a/sw/device/lib/dif/autogen/dif_usbdev_autogen.h b/sw/device/lib/dif/autogen/dif_usbdev_autogen.h index fbbbe1219f326..7322ec46fc733 100644 --- a/sw/device/lib/dif/autogen/dif_usbdev_autogen.h +++ b/sw/device/lib/dif/autogen/dif_usbdev_autogen.h @@ -35,6 +35,18 @@ typedef struct dif_usbdev { mmio_region_t base_addr; } dif_usbdev_t; +/** + * Creates a new handle for a(n) usbdev peripheral. + * + * This function does not actuate the hardware. + * + * @param base_addr The MMIO base address of the usbdev peripheral. + * @param[out] usbdev Out param for the initialized handle. + * @return The result of the operation. + */ +OT_WARN_UNUSED_RESULT +dif_result_t dif_usbdev_init(mmio_region_t base_addr, dif_usbdev_t *usbdev); + /** * A usbdev interrupt request type. */ diff --git a/sw/device/lib/dif/autogen/dif_usbdev_autogen_unittest.cc b/sw/device/lib/dif/autogen/dif_usbdev_autogen_unittest.cc index 2e22c8fdec883..3edaf90c96305 100644 --- a/sw/device/lib/dif/autogen/dif_usbdev_autogen_unittest.cc +++ b/sw/device/lib/dif/autogen/dif_usbdev_autogen_unittest.cc @@ -16,6 +16,7 @@ namespace dif_usbdev_autogen_unittest { namespace { using ::mock_mmio::MmioTest; using ::mock_mmio::MockDevice; +using ::testing::Eq; using ::testing::Test; class UsbdevTest : public Test, public MmioTest { @@ -23,7 +24,16 @@ class UsbdevTest : public Test, public MmioTest { dif_usbdev_t usbdev_ = {.base_addr = dev().region()}; }; -using ::testing::Eq; +class InitTest : public UsbdevTest {}; + +TEST_F(InitTest, NullArgs) { + EXPECT_EQ(dif_usbdev_init({.base_addr = dev().region()}, nullptr), + kDifBadArg); +} + +TEST_F(InitTest, Success) { + EXPECT_EQ(dif_usbdev_init({.base_addr = dev().region()}, &usbdev_), kDifOk); +} class IrqGetStateTest : public UsbdevTest {}; diff --git a/sw/device/lib/dif/dif_aes.c b/sw/device/lib/dif/dif_aes.c index fe18646746294..7bf912dc887e1 100644 --- a/sw/device/lib/dif/dif_aes.c +++ b/sw/device/lib/dif/dif_aes.c @@ -190,16 +190,6 @@ static void aes_set_multireg(const dif_aes_t *aes, const uint32_t *data, } } -dif_result_t dif_aes_init(mmio_region_t base_addr, dif_aes_t *aes) { - if (aes == NULL) { - return kDifBadArg; - } - - aes->base_addr = base_addr; - - return kDifOk; -} - dif_result_t dif_aes_reset(const dif_aes_t *aes) { if (aes == NULL) { return kDifBadArg; diff --git a/sw/device/lib/dif/dif_aes.h b/sw/device/lib/dif/dif_aes.h index b43e42930952c..603f585afd5da 100644 --- a/sw/device/lib/dif/dif_aes.h +++ b/sw/device/lib/dif/dif_aes.h @@ -172,18 +172,6 @@ typedef enum dif_aes_alert { kDifAlertRecovCtrlUpdateErr, } dif_aes_alert_t; -/** - * Creates a new handle for AES. - * - * This function does not actuate the hardware. - * - * @param base_addr Hardware instantiation base address. - * @param[out] aes Out param for the initialised handle. - * @return The result of the operation. - */ -OT_WARN_UNUSED_RESULT -dif_result_t dif_aes_init(mmio_region_t base_addr, dif_aes_t *aes); - /** * Resets an instance of AES. * diff --git a/sw/device/lib/dif/dif_alert_handler.c b/sw/device/lib/dif/dif_alert_handler.c index e2a6f53c2aa4e..85963f4136298 100644 --- a/sw/device/lib/dif/dif_alert_handler.c +++ b/sw/device/lib/dif/dif_alert_handler.c @@ -19,17 +19,6 @@ static_assert(ALERT_HANDLER_PARAM_N_PHASES == 4, static_assert(ALERT_HANDLER_PARAM_N_LOC_ALERT == 7, "Expected seven local alerts!"); -dif_result_t dif_alert_handler_init(mmio_region_t base_addr, - dif_alert_handler_t *alert_handler) { - if (alert_handler == NULL) { - return kDifBadArg; - } - - alert_handler->base_addr = base_addr; - - return kDifOk; -} - /** * Classifies alerts for a single alert class. Returns `false` if any of the * provided configuration is invalid. diff --git a/sw/device/lib/dif/dif_alert_handler.h b/sw/device/lib/dif/dif_alert_handler.h index aba1cb805a6f2..ee724d3dcdea0 100644 --- a/sw/device/lib/dif/dif_alert_handler.h +++ b/sw/device/lib/dif/dif_alert_handler.h @@ -313,19 +313,6 @@ typedef struct dif_alert_handler_config { size_t classes_len; } dif_alert_handler_config_t; -/** - * Creates a new handle for alert handler. - * - * This function does not actuate the hardware. - * - * @param base_addr Hardware instantiation base address. - * @param handler Out param for the initialized handle. - * @return The result of the operation. - */ -OT_WARN_UNUSED_RESULT -dif_result_t dif_alert_handler_init(mmio_region_t base_addr, - dif_alert_handler_t *alert_handler); - /** * Configures alert handler with runtime information. * diff --git a/sw/device/lib/dif/dif_alert_handler_unittest.cc b/sw/device/lib/dif/dif_alert_handler_unittest.cc index 4a3247c071a64..76fde0c699d00 100644 --- a/sw/device/lib/dif/dif_alert_handler_unittest.cc +++ b/sw/device/lib/dif/dif_alert_handler_unittest.cc @@ -30,19 +30,6 @@ class AlertHandlerTest : public testing::Test, public MmioTest { dif_alert_handler_t alert_handler_ = {.base_addr = dev().region()}; }; -class InitTest : public AlertHandlerTest, - public testing::WithParamInterface {}; - -TEST_F(InitTest, Success) { - dif_alert_handler_t alert_handler; - - EXPECT_EQ(dif_alert_handler_init(dev().region(), &alert_handler), kDifOk); -} - -TEST_F(InitTest, NullArgs) { - EXPECT_EQ(dif_alert_handler_init(dev().region(), nullptr), kDifBadArg); -} - class ConfigTest : public AlertHandlerTest { // We provide our own dev_ member variable in this fixture, in order to // support IgnoreMmioCalls(). diff --git a/sw/device/lib/dif/dif_aon_timer.c b/sw/device/lib/dif/dif_aon_timer.c index 23c006006fe9e..e1ffacde7c54f 100644 --- a/sw/device/lib/dif/dif_aon_timer.c +++ b/sw/device/lib/dif/dif_aon_timer.c @@ -57,16 +57,6 @@ static bool aon_timer_watchdog_is_locked(const dif_aon_timer_t *aon) { return !bitfield_bit32_read(reg, AON_TIMER_WDOG_REGWEN_REGWEN_BIT); } -dif_result_t dif_aon_timer_init(mmio_region_t base_addr, dif_aon_timer_t *aon) { - if (aon == NULL) { - return kDifBadArg; - } - - aon->base_addr = base_addr; - - return kDifOk; -} - dif_result_t dif_aon_timer_wakeup_start(const dif_aon_timer_t *aon, uint32_t threshold, uint32_t prescaler) { diff --git a/sw/device/lib/dif/dif_aon_timer.h b/sw/device/lib/dif/dif_aon_timer.h index 0bf20dc7b902c..e0830337143e7 100644 --- a/sw/device/lib/dif/dif_aon_timer.h +++ b/sw/device/lib/dif/dif_aon_timer.h @@ -24,18 +24,6 @@ extern "C" { #endif // __cplusplus -/** - * Creates a new handle for Always-On Timer. - * - * This function does not actuate the hardware. - * - * @param base_addr Hardware instantiation base address. - * @param[out] aon Out param for the initialised handle. - * @return The result of the operation. - */ -OT_WARN_UNUSED_RESULT -dif_result_t dif_aon_timer_init(mmio_region_t base_addr, dif_aon_timer_t *aon); - /** * Starts Always-On Timer (wake-up timer). * diff --git a/sw/device/lib/dif/dif_aon_timer_unittest.cc b/sw/device/lib/dif/dif_aon_timer_unittest.cc index 7a12e6765d540..13e0d1a615d71 100644 --- a/sw/device/lib/dif/dif_aon_timer_unittest.cc +++ b/sw/device/lib/dif/dif_aon_timer_unittest.cc @@ -25,17 +25,6 @@ class AonTimerTest : public Test, public MmioTest { dif_aon_timer_t aon_ = {.base_addr = dev().region()}; }; -class InitTest : public AonTimerTest {}; - -TEST_F(InitTest, NullArgs) { - EXPECT_EQ(dif_aon_timer_init(dev().region(), nullptr), kDifBadArg); -} - -TEST_F(InitTest, Success) { - dif_aon_timer_t aon; - EXPECT_EQ(dif_aon_timer_init(dev().region(), &aon), kDifOk); -} - class WakeupStartTest : public AonTimerTest {}; TEST_F(WakeupStartTest, NullArgs) { diff --git a/sw/device/lib/dif/dif_clkmgr.c b/sw/device/lib/dif/dif_clkmgr.c index c7949f1a1c102..61ca9e5537498 100644 --- a/sw/device/lib/dif/dif_clkmgr.c +++ b/sw/device/lib/dif/dif_clkmgr.c @@ -34,16 +34,6 @@ static bool clkmgr_valid_hintable_clock(dif_clkmgr_hintable_clock_t clock) { return clock < CLKMGR_PARAM_NUM_HINTABLE_CLOCKS; } -dif_result_t dif_clkmgr_init(mmio_region_t base_addr, dif_clkmgr_t *clkmgr) { - if (clkmgr == NULL) { - return kDifBadArg; - } - - clkmgr->base_addr = base_addr; - - return kDifOk; -} - dif_result_t dif_clkmgr_gateable_clock_get_enabled( const dif_clkmgr_t *clkmgr, dif_clkmgr_gateable_clock_t clock, bool *is_enabled) { diff --git a/sw/device/lib/dif/dif_clkmgr.h b/sw/device/lib/dif/dif_clkmgr.h index 3877926253488..f25eb48212188 100644 --- a/sw/device/lib/dif/dif_clkmgr.h +++ b/sw/device/lib/dif/dif_clkmgr.h @@ -40,18 +40,6 @@ typedef uint32_t dif_clkmgr_gateable_clock_t; */ typedef uint32_t dif_clkmgr_hintable_clock_t; -/** - * Creates a new handle for a clock manager. - * - * This function does not actuate the hardware. - * - * @param base_addr Hardware instantiation base address. - * @param[out] clkmgr Out param for the initialized handle. - * @return The result of the operation. - */ -OT_WARN_UNUSED_RESULT -dif_result_t dif_clkmgr_init(mmio_region_t base_addr, dif_clkmgr_t *clkmgr); - /** * Check if a Gateable Clock is Enabled or Disabled. * diff --git a/sw/device/lib/dif/dif_clkmgr_unittest.cc b/sw/device/lib/dif/dif_clkmgr_unittest.cc index 5faf857aed617..e7c6f51102897 100644 --- a/sw/device/lib/dif/dif_clkmgr_unittest.cc +++ b/sw/device/lib/dif/dif_clkmgr_unittest.cc @@ -20,16 +20,8 @@ using testing::Test; class ClkMgrTest : public Test, public MmioTest { protected: dif_clkmgr_t clkmgr_ = {.base_addr = dev().region()}; - ClkMgrTest() { EXPECT_EQ(dif_clkmgr_init(dev().region(), &clkmgr_), kDifOk); } }; -class InitTest : public ClkMgrTest {}; - -TEST_F(InitTest, NullArgs) { - // Null handle. - EXPECT_EQ(dif_clkmgr_init(dev().region(), nullptr), kDifBadArg); -} - class GateableClockTest : public ClkMgrTest {}; TEST_F(GateableClockTest, SetEnabled) { diff --git a/sw/device/lib/dif/dif_csrng.c b/sw/device/lib/dif/dif_csrng.c index 7881f1fcbc1ad..2d6226860f043 100644 --- a/sw/device/lib/dif/dif_csrng.c +++ b/sw/device/lib/dif/dif_csrng.c @@ -116,16 +116,6 @@ static bool is_output_ready(const dif_csrng_t *csrng) { return status.valid_data; } -dif_result_t dif_csrng_init(mmio_region_t base_addr, dif_csrng_t *csrng) { - if (csrng == NULL) { - return kDifBadArg; - } - - csrng->base_addr = base_addr; - - return kDifOk; -} - dif_result_t dif_csrng_configure(const dif_csrng_t *csrng) { if (csrng == NULL) { return kDifBadArg; diff --git a/sw/device/lib/dif/dif_csrng.h b/sw/device/lib/dif/dif_csrng.h index 0b2d152d2ae2c..e4da067e8b306 100644 --- a/sw/device/lib/dif/dif_csrng.h +++ b/sw/device/lib/dif/dif_csrng.h @@ -186,18 +186,6 @@ typedef struct dif_csrng_internal_state { bool fips_compliance; } dif_csrng_internal_state_t; -/** - * Creates a new handle for CSRNG. - * - * This function does not actuate the hardware. - * - * @param base_addr Hardware instantiation base address. - * @param[out] csrng Out param for the initialized handle. - * @return The result of the operation. - */ -OT_WARN_UNUSED_RESULT -dif_result_t dif_csrng_init(mmio_region_t base_addr, dif_csrng_t *csrng); - /** * Configures CSRNG. * diff --git a/sw/device/lib/dif/dif_csrng_unittest.cc b/sw/device/lib/dif/dif_csrng_unittest.cc index 3b912daf3bb71..d7cb2f6938de6 100644 --- a/sw/device/lib/dif/dif_csrng_unittest.cc +++ b/sw/device/lib/dif/dif_csrng_unittest.cc @@ -23,17 +23,6 @@ class DifCsrngTest : public testing::Test, public mock_mmio::MmioTest { const dif_csrng_t csrng_ = {.base_addr = dev().region()}; }; -class InitTest : public DifCsrngTest {}; - -TEST_F(InitTest, BadArgs) { - EXPECT_EQ(dif_csrng_init(dev().region(), nullptr), kDifBadArg); -} - -TEST_F(InitTest, InitOk) { - dif_csrng_t csrng; - EXPECT_EQ(dif_csrng_init(dev().region(), &csrng), kDifOk); -} - class ConfigTest : public DifCsrngTest {}; TEST_F(ConfigTest, NullArgs) { diff --git a/sw/device/lib/dif/dif_edn.c b/sw/device/lib/dif/dif_edn.c index 1a062debed250..3b2e3fcdf3194 100644 --- a/sw/device/lib/dif/dif_edn.c +++ b/sw/device/lib/dif/dif_edn.c @@ -5,13 +5,3 @@ #include "sw/device/lib/dif/dif_edn.h" #include "edn_regs.h" // Generated - -dif_result_t dif_edn_init(mmio_region_t base_addr, dif_edn_t *edn) { - if (edn == NULL) { - return kDifBadArg; - } - - edn->base_addr = base_addr; - - return kDifOk; -} diff --git a/sw/device/lib/dif/dif_edn.h b/sw/device/lib/dif/dif_edn.h index 67d7a4e8056c7..09354ad77555e 100644 --- a/sw/device/lib/dif/dif_edn.h +++ b/sw/device/lib/dif/dif_edn.h @@ -101,18 +101,6 @@ typedef struct dif_edn_auto_params { uint32_t reseed_interval; } dif_edn_auto_params_t; -/** - * Creates a new handle for Entropy Distribution Network. - * - * This function does not actuate the hardware. - * - * @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_result_t dif_edn_init(mmio_region_t base_addr, dif_edn_t *edn); - /** * Configures Entropy Distribution Network with runtime information. * diff --git a/sw/device/lib/dif/dif_entropy_src.c b/sw/device/lib/dif/dif_entropy_src.c index 2ad5c9dbc9d65..2fa8049ac34f9 100644 --- a/sw/device/lib/dif/dif_entropy_src.c +++ b/sw/device/lib/dif/dif_entropy_src.c @@ -87,15 +87,6 @@ static dif_result_t fw_override_set( return kDifOk; } -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_src->base_addr = base_addr; - return kDifOk; -} - dif_result_t dif_entropy_src_configure(const dif_entropy_src_t *entropy_src, dif_entropy_src_config_t config) { if (entropy_src == NULL) { diff --git a/sw/device/lib/dif/dif_entropy_src.h b/sw/device/lib/dif/dif_entropy_src.h index 8e2387fd5c838..ad28a105813fe 100644 --- a/sw/device/lib/dif/dif_entropy_src.h +++ b/sw/device/lib/dif/dif_entropy_src.h @@ -336,19 +336,6 @@ typedef enum dif_entropy_src_alert { kDifEntropySrcFatal, } dif_entropy_src_alert_t; -/** - * Creates a new handle for entropy source. - * - * This function does not actuate the hardware. - * - * @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_result_t dif_entropy_src_init(mmio_region_t base_addr, - dif_entropy_src_t *entropy_src); - /** * Configures entropy source with runtime information. * diff --git a/sw/device/lib/dif/dif_entropy_src_unittest.cc b/sw/device/lib/dif/dif_entropy_src_unittest.cc index 132eab01bba48..67053ea431869 100644 --- a/sw/device/lib/dif/dif_entropy_src_unittest.cc +++ b/sw/device/lib/dif/dif_entropy_src_unittest.cc @@ -20,17 +20,6 @@ class DifEntropySrcTest : public testing::Test, public mock_mmio::MmioTest { 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(dev().region(), nullptr), kDifBadArg); -} - -TEST_F(InitTest, Init) { - dif_entropy_src_t entropy; - EXPECT_EQ(dif_entropy_src_init(dev().region(), &entropy), kDifOk); -} - class ConfigTest : public DifEntropySrcTest { protected: dif_entropy_src_config_t config_ = { diff --git a/sw/device/lib/dif/dif_gpio.c b/sw/device/lib/dif/dif_gpio.c index e0ba6a4831551..273bddbca88a5 100644 --- a/sw/device/lib/dif/dif_gpio.c +++ b/sw/device/lib/dif/dif_gpio.c @@ -99,16 +99,6 @@ static dif_result_t gpio_masked_bit_write(const dif_gpio_t *gpio, return kDifOk; } -dif_result_t dif_gpio_init(mmio_region_t base_addr, dif_gpio_t *gpio) { - if (gpio == NULL) { - return kDifBadArg; - } - - gpio->base_addr = base_addr; - - return kDifOk; -} - dif_result_t dif_gpio_reset(const dif_gpio_t *gpio) { if (gpio == NULL) { return kDifBadArg; diff --git a/sw/device/lib/dif/dif_gpio.h b/sw/device/lib/dif/dif_gpio.h index 1a1c789d0b69c..3d0404aa56f8a 100644 --- a/sw/device/lib/dif/dif_gpio.h +++ b/sw/device/lib/dif/dif_gpio.h @@ -88,18 +88,6 @@ typedef uint32_t dif_gpio_state_t; */ typedef uint32_t dif_gpio_mask_t; -/** - * Creates a new handle for GPIO. - * - * This function does not actuate the hardware. - * - * @param params Hardware instantiation parameters. - * @param[out] gpio Out param for the initialized handle. - * @return The result of the operation. - */ -OT_WARN_UNUSED_RESULT -dif_result_t dif_gpio_init(mmio_region_t base_addr, dif_gpio_t *gpio); - /** * Resets a GPIO device. * diff --git a/sw/device/lib/dif/dif_gpio_unittest.cc b/sw/device/lib/dif/dif_gpio_unittest.cc index 61508f42a0310..588c428388a52 100644 --- a/sw/device/lib/dif/dif_gpio_unittest.cc +++ b/sw/device/lib/dif/dif_gpio_unittest.cc @@ -25,18 +25,6 @@ uint32_t AllOnesExcept(uint32_t index) { return ~AllZerosExcept(index); } // Base class for the test fixtures in this file. class GpioTest : public testing::Test, public mock_mmio::MmioTest {}; -// Init tests -class InitTest : public GpioTest {}; - -TEST_F(InitTest, NullArgs) { - EXPECT_EQ(dif_gpio_init(dev().region(), nullptr), kDifBadArg); -} - -TEST_F(InitTest, Init) { - dif_gpio_t gpio; - EXPECT_EQ(dif_gpio_init(dev().region(), &gpio), kDifOk); -} - // Base class for the rest of the tests in this file, provides a // `dif_gpio_t` instance. class GpioTestInitialized : public GpioTest { diff --git a/sw/device/lib/dif/dif_hmac.c b/sw/device/lib/dif/dif_hmac.c index 332c7893eb7e3..ce0b8f54e6386 100644 --- a/sw/device/lib/dif/dif_hmac.c +++ b/sw/device/lib/dif/dif_hmac.c @@ -39,16 +39,6 @@ static uint32_t get_fifo_available_space(const dif_hmac_t *hmac) { return HMAC_MSG_FIFO_SIZE_WORDS - get_fifo_entry_count(hmac); } -dif_result_t dif_hmac_init(mmio_region_t base_addr, dif_hmac_t *hmac) { - if (hmac == NULL) { - return kDifBadArg; - } - - hmac->base_addr = base_addr; - - return kDifOk; -} - /** * Sets up the CFG value for a given per-transaction configuration. * diff --git a/sw/device/lib/dif/dif_hmac.h b/sw/device/lib/dif/dif_hmac.h index a2c2bead05045..0852fe415ab90 100644 --- a/sw/device/lib/dif/dif_hmac.h +++ b/sw/device/lib/dif/dif_hmac.h @@ -60,20 +60,6 @@ typedef struct dif_hmac_digest { uint32_t digest[8]; } dif_hmac_digest_t; -/** - * Initializes the HMAC device described by `config`, writing internal state to - * `hmac_out`. - * - * This function *must* be called on a particular `mmio_region_t` before calling - * any other functions in this header with that `mmio_region_t`. - * - * @param base_addr Hardware instantiation base address. - * @param[out] hmac_out The location at which to write HMAC state. This location - * must be valid to write to. - * @return The result of the operation. - */ -dif_result_t dif_hmac_init(mmio_region_t base_addr, dif_hmac_t *hmac_out); - /** * Resets the HMAC engine and readies it to receive a new message to process an * HMAC digest. diff --git a/sw/device/lib/dif/dif_i2c.c b/sw/device/lib/dif/dif_i2c.c index e5a690482039b..7b0e93996b3f3 100644 --- a/sw/device/lib/dif/dif_i2c.c +++ b/sw/device/lib/dif/dif_i2c.c @@ -129,16 +129,6 @@ dif_result_t dif_i2c_compute_timing(dif_i2c_timing_config_t timing_config, return kDifOk; } -dif_result_t dif_i2c_init(mmio_region_t base_addr, dif_i2c_t *i2c) { - if (i2c == NULL) { - return kDifBadArg; - } - - i2c->base_addr = base_addr; - - return kDifOk; -} - dif_result_t dif_i2c_configure(const dif_i2c_t *i2c, dif_i2c_config_t config) { if (i2c == NULL) { return kDifBadArg; diff --git a/sw/device/lib/dif/dif_i2c.h b/sw/device/lib/dif/dif_i2c.h index ae5f55996f4ea..9aa8e44613726 100644 --- a/sw/device/lib/dif/dif_i2c.h +++ b/sw/device/lib/dif/dif_i2c.h @@ -258,17 +258,6 @@ typedef enum dif_i2c_fmt { OT_WARN_UNUSED_RESULT dif_result_t dif_i2c_compute_timing(dif_i2c_timing_config_t timing_config, dif_i2c_config_t *config); -/** - * Creates a new handle for I2C. - * - * This function does not actuate the hardware. - * - * @param base_addr Hardware instantiation base address. - * @param[out] i2c Out param for the initialized handle. - * @return The result of the operation. - */ -OT_WARN_UNUSED_RESULT -dif_result_t dif_i2c_init(mmio_region_t base_addr, dif_i2c_t *i2c); /** * Configures I2C with runtime information. diff --git a/sw/device/lib/dif/dif_keymgr.c b/sw/device/lib/dif/dif_keymgr.c index 110614a3cf06a..a62652300cf0d 100644 --- a/sw/device/lib/dif/dif_keymgr.c +++ b/sw/device/lib/dif/dif_keymgr.c @@ -256,16 +256,6 @@ static dif_toggle_t bool_to_toggle(bool val) { return val ? kDifToggleEnabled : kDifToggleDisabled; } -dif_result_t dif_keymgr_init(mmio_region_t base_addr, dif_keymgr_t *keymgr) { - if (keymgr == NULL) { - return kDifBadArg; - } - - keymgr->base_addr = base_addr; - - return kDifOk; -} - dif_result_t dif_keymgr_configure(const dif_keymgr_t *keymgr, dif_keymgr_config_t config) { if (keymgr == NULL) { diff --git a/sw/device/lib/dif/dif_keymgr.h b/sw/device/lib/dif/dif_keymgr.h index a66118d421304..6dd93ae86edd0 100644 --- a/sw/device/lib/dif/dif_keymgr.h +++ b/sw/device/lib/dif/dif_keymgr.h @@ -23,6 +23,27 @@ extern "C" { #endif // __cplusplus +/** + * A typical usage of this library during different secure boot + * stages is as follows: + * + * - In Mask ROM: + * - Create a new handle: `dif_keymgr_init()`. + * - Configure hardware: `dif_keymgr_configure()`. + * - Initialize state: `dif_keymgr_advance_state()`, + * `dif_keymgr_get_status_codes()`, `dif_keymgr_get_state()`. + * - Advance state: `dif_keymgr_advance_state()`, + * `dif_keymgr_get_status_codes()`, `dif_keymgr_get_state()`. + * - In subsequent boot stages, i.e. ROM_EXT, BL0, kernel: + * - Create a new handle: `dif_keymgr_init()`. + * - Generate keys and/or identity seeds: + * `dif_keymgr_generate_versioned_key()`, + * `dif_keymgr_generate_identity_seed()`, `dif_keymgr_get_status_codes()`. + * - Read output (if applicable): `dif_keymgr_read_output()`. + * - Advance state: `dif_keymgr_advance_state()`, + * `dif_keymgr_get_status_codes()`, `dif_keymgr_get_state()`. + */ + /** * Enumeration for side load slot clearing. */ @@ -160,37 +181,6 @@ typedef enum dif_keymgr_state { kDifKeymgrStateInvalid, } dif_keymgr_state_t; -/** - * Creates a new handle for key manager. - * - * This function does not actuate the hardware and must be called to initialize - * the handle that must be passed to other functions in this library in each - * boot stage. A typical usage of this library during different secure boot - * stages is as follows: - * - * - In Mask ROM: - * - Create a new handle: `dif_keymgr_init()`. - * - Configure hardware: `dif_keymgr_configure()`. - * - Initialize state: `dif_keymgr_advance_state()`, - * `dif_keymgr_get_status_codes()`, `dif_keymgr_get_state()`. - * - Advance state: `dif_keymgr_advance_state()`, - * `dif_keymgr_get_status_codes()`, `dif_keymgr_get_state()`. - * - In subsequent boot stages, i.e. ROM_EXT, BL0, kernel: - * - Create a new handle: `dif_keymgr_init()`. - * - Generate keys and/or identity seeds: - * `dif_keymgr_generate_versioned_key()`, - * `dif_keymgr_generate_identity_seed()`, `dif_keymgr_get_status_codes()`. - * - Read output (if applicable): `dif_keymgr_read_output()`. - * - Advance state: `dif_keymgr_advance_state()`, - * `dif_keymgr_get_status_codes()`, `dif_keymgr_get_state()`. - * - * @param base_addr Hardware instantiation base address. - * @param[out] keymgr Out-param for the initialized handle. - * @return The result of the operation. - */ -OT_WARN_UNUSED_RESULT -dif_result_t dif_keymgr_init(mmio_region_t base_addr, dif_keymgr_t *keymgr); - /** * Configures key manager with runtime information. * diff --git a/sw/device/lib/dif/dif_keymgr_unittest.cc b/sw/device/lib/dif/dif_keymgr_unittest.cc index fb2af6ecd0a2f..247899b76ba4c 100644 --- a/sw/device/lib/dif/dif_keymgr_unittest.cc +++ b/sw/device/lib/dif/dif_keymgr_unittest.cc @@ -142,17 +142,6 @@ INSTANTIATE_TEST_SUITE_P( return ss.str(); }); -class InitTest : public DifKeymgrTest {}; - -TEST_F(InitTest, BadArgs) { - EXPECT_EQ(dif_keymgr_init(dev().region(), nullptr), kDifBadArg); -} - -TEST_F(InitTest, Init) { - dif_keymgr_t keymgr; - EXPECT_EQ(dif_keymgr_init(dev().region(), &keymgr), kDifOk); -} - /** * Base class for the rest of the tests in this file, provides a * `dif_keymgr_t` instance and some methods for common expectations. diff --git a/sw/device/lib/dif/dif_kmac.c b/sw/device/lib/dif/dif_kmac.c index 4a00f20de7db4..ef88f8264a666 100644 --- a/sw/device/lib/dif/dif_kmac.c +++ b/sw/device/lib/dif/dif_kmac.c @@ -138,16 +138,6 @@ static bool is_state_squeeze(const dif_kmac_t *kmac) { return bitfield_bit32_read(reg, KMAC_STATUS_SHA3_SQUEEZE_BIT); } -dif_result_t dif_kmac_init(mmio_region_t base_addr, dif_kmac_t *kmac) { - if (kmac == NULL) { - return kDifBadArg; - } - - kmac->base_addr = base_addr; - - return kDifOk; -} - dif_result_t dif_kmac_configure(dif_kmac_t *kmac, dif_kmac_config_t config) { if (kmac == NULL) { return kDifBadArg; diff --git a/sw/device/lib/dif/dif_kmac.h b/sw/device/lib/dif/dif_kmac.h index 8d0c53744da68..50e1df86a70ff 100644 --- a/sw/device/lib/dif/dif_kmac.h +++ b/sw/device/lib/dif/dif_kmac.h @@ -383,18 +383,6 @@ typedef enum dif_kmac_fifo_state { kDifKmacFifoStateFull, } dif_kmac_fifo_state_t; -/** - * Creates a new handle for KMAC. - * - * This function does not actuate the hardware. - * - * @param base_addr Hardware instantiation base address. - * @param[out] kmac Out param for the initialized handle. - * @return The result of the operation. - */ -OT_WARN_UNUSED_RESULT -dif_result_t dif_kmac_init(mmio_region_t base_addr, dif_kmac_t *kmac); - /** * Configures KMAC with runtime information. * diff --git a/sw/device/lib/dif/dif_lc_ctrl.c b/sw/device/lib/dif/dif_lc_ctrl.c index 82ca0ce568777..696fd522bef1c 100644 --- a/sw/device/lib/dif/dif_lc_ctrl.c +++ b/sw/device/lib/dif/dif_lc_ctrl.c @@ -23,15 +23,6 @@ enum { kLcCtrlMutexRelease = 0, }; -dif_result_t dif_lc_ctrl_init(mmio_region_t base_addr, dif_lc_ctrl_t *lc) { - if (lc == NULL) { - return kDifBadArg; - } - - lc->base_addr = base_addr; - return kDifOk; -} - dif_result_t dif_lc_ctrl_get_state(const dif_lc_ctrl_t *lc, dif_lc_ctrl_state_t *state) { if (lc == NULL || state == NULL) { diff --git a/sw/device/lib/dif/dif_lc_ctrl.h b/sw/device/lib/dif/dif_lc_ctrl.h index 3f8d88cad461e..84bdd582598d6 100644 --- a/sw/device/lib/dif/dif_lc_ctrl.h +++ b/sw/device/lib/dif/dif_lc_ctrl.h @@ -317,18 +317,6 @@ typedef enum dif_lc_ctrl_alert { kDifLcCtrlAlertBus, } dif_lc_ctrl_alert_t; -/** - * Creates a new handle for the lifecycle controller. - * - * This function does not actuate the hardware. - * - * @param base_addr Base address of the UART peripheral. - * @param[out] lc Out param for the initialized handle. - * @return The result of the operation. - */ -OT_WARN_UNUSED_RESULT -dif_result_t dif_lc_ctrl_init(mmio_region_t base_addr, dif_lc_ctrl_t *lc); - /** * Returns the current state of the lifecycle controller. * diff --git a/sw/device/lib/dif/dif_lc_ctrl_unittest.cc b/sw/device/lib/dif/dif_lc_ctrl_unittest.cc index 289be7fef0f93..fe05ca07353ce 100644 --- a/sw/device/lib/dif/dif_lc_ctrl_unittest.cc +++ b/sw/device/lib/dif/dif_lc_ctrl_unittest.cc @@ -27,17 +27,6 @@ class LcCtrlTest : public Test, public MmioTest { dif_lc_ctrl_t lc_ = {.base_addr = dev().region()}; }; -class InitTest : public LcCtrlTest {}; - -TEST_F(InitTest, Success) { - EXPECT_EQ(dif_lc_ctrl_init({.base_addr = dev().region()}, &lc_), kDifOk); -} - -TEST_F(InitTest, NullArgs) { - EXPECT_EQ(dif_lc_ctrl_init({.base_addr = dev().region()}, nullptr), - kDifBadArg); -} - class StateTest : public LcCtrlTest {}; TEST_F(StateTest, GetState) { diff --git a/sw/device/lib/dif/dif_otbn.c b/sw/device/lib/dif/dif_otbn.c index 2f9f9f845dfe1..0bd6532d4b6cf 100644 --- a/sw/device/lib/dif/dif_otbn.c +++ b/sw/device/lib/dif/dif_otbn.c @@ -67,17 +67,6 @@ static bool check_offset_len(uint32_t offset_bytes, size_t len_bytes, offset_bytes + len_bytes <= mem_size); } -dif_result_t dif_otbn_init(mmio_region_t base_addr, dif_otbn_t *otbn) { - if (otbn == NULL) { - return kDifBadArg; - } - - otbn->base_addr = base_addr; - dif_otbn_reset(otbn); - - return kDifOk; -} - dif_result_t dif_otbn_reset(const dif_otbn_t *otbn) { if (otbn == NULL) { return kDifBadArg; diff --git a/sw/device/lib/dif/dif_otbn.h b/sw/device/lib/dif/dif_otbn.h index f834ae67f06b1..188607f4cd2f8 100644 --- a/sw/device/lib/dif/dif_otbn.h +++ b/sw/device/lib/dif/dif_otbn.h @@ -77,19 +77,6 @@ typedef enum dif_otbn_err_bits { kDifOtbnErrBitsFatalSoftware = (1 << 22), } dif_otbn_err_bits_t; -/** - * Initialize a OTBN device using `config` and return its internal state. - * - * A particular OTBN device must first be initialized by this function - * before calling other functions of this library. - * - * @param base_addr Hardware instantiation base address. - * @param[out] otbn OTBN instance that will store the internal state of the - * initialized OTBN device. - * @return The result of the operation. - */ -dif_result_t dif_otbn_init(mmio_region_t base_addr, dif_otbn_t *otbn); - /** * Reset OTBN device. * diff --git a/sw/device/lib/dif/dif_otbn_unittest.cc b/sw/device/lib/dif/dif_otbn_unittest.cc index d3da104afaac1..68cc39115f65d 100644 --- a/sw/device/lib/dif/dif_otbn_unittest.cc +++ b/sw/device/lib/dif/dif_otbn_unittest.cc @@ -27,24 +27,9 @@ class OtbnTest : public Test, public MmioTest { std::numeric_limits::max()); } - mmio_region_t base_addr_ = dev().region(); - dif_otbn_t dif_otbn_ = { - /* base_addr = */ base_addr_, - }; + dif_otbn_t dif_otbn_ = {.base_addr = dev().region()}; }; -class InitTest : public OtbnTest {}; - -TEST_F(InitTest, NullArgs) { - EXPECT_EQ(dif_otbn_init(base_addr_, nullptr), kDifBadArg); -} - -TEST_F(InitTest, Default) { - ExpectDeviceReset(); - - EXPECT_EQ(dif_otbn_init(base_addr_, &dif_otbn_), kDifOk); -} - class ResetTest : public OtbnTest {}; TEST_F(ResetTest, NullArgs) { EXPECT_EQ(dif_otbn_reset(nullptr), kDifBadArg); } diff --git a/sw/device/lib/dif/dif_otp_ctrl.c b/sw/device/lib/dif/dif_otp_ctrl.c index 47ba8f61f1814..95019b03eb0e5 100644 --- a/sw/device/lib/dif/dif_otp_ctrl.c +++ b/sw/device/lib/dif/dif_otp_ctrl.c @@ -12,16 +12,6 @@ #include "otp_ctrl_regs.h" // Generated. -dif_result_t dif_otp_ctrl_init(mmio_region_t base_addr, dif_otp_ctrl_t *otp) { - if (otp == NULL) { - return kDifBadArg; - } - - otp->base_addr = base_addr; - - return kDifOk; -} - /** * Checks if integrity/consistency-check-related operations are locked. * diff --git a/sw/device/lib/dif/dif_otp_ctrl.h b/sw/device/lib/dif/dif_otp_ctrl.h index 56e9f18e9d901..e9c0546ff61fa 100644 --- a/sw/device/lib/dif/dif_otp_ctrl.h +++ b/sw/device/lib/dif/dif_otp_ctrl.h @@ -289,18 +289,6 @@ typedef struct dif_otp_ctrl_status { dif_otp_ctrl_error_t causes[kDifOtpCtrlStatusCodeHasCauseLast + 1]; } dif_otp_ctrl_status_t; -/** - * Creates a new handle for OTP. - * - * This function does not actuate the hardware. - * - * @param base_addr Hardware instantiation base address. - * @param[out] otp Out param for the initialized handle. - * @return The result of the operation. - */ -OT_WARN_UNUSED_RESULT -dif_result_t dif_otp_ctrl_init(mmio_region_t base_addr, dif_otp_ctrl_t *otp); - /** * Configures OTP with runtime information. * diff --git a/sw/device/lib/dif/dif_otp_ctrl_unittest.cc b/sw/device/lib/dif/dif_otp_ctrl_unittest.cc index 594f03b4c6bd8..562439eece79a 100644 --- a/sw/device/lib/dif/dif_otp_ctrl_unittest.cc +++ b/sw/device/lib/dif/dif_otp_ctrl_unittest.cc @@ -27,17 +27,6 @@ class OtpTest : public testing::Test, public MmioTest { dif_otp_ctrl_t otp_ = {.base_addr = dev().region()}; }; -class InitTest : public OtpTest {}; - -TEST_F(InitTest, Success) { - dif_otp_ctrl_t handler; - EXPECT_EQ(dif_otp_ctrl_init(dev().region(), &handler), kDifOk); -} - -TEST_F(InitTest, NullArgs) { - EXPECT_EQ(dif_otp_ctrl_init(dev().region(), nullptr), kDifBadArg); -} - class ConfigTest : public OtpTest {}; TEST_F(ConfigTest, Basic) { diff --git a/sw/device/lib/dif/dif_pinmux.h b/sw/device/lib/dif/dif_pinmux.h index cad17f4c8713f..3723a52a19f2a 100644 --- a/sw/device/lib/dif/dif_pinmux.h +++ b/sw/device/lib/dif/dif_pinmux.h @@ -268,18 +268,6 @@ typedef struct dif_pinmux_wakeup_timed_config { dif_pinmux_wakeup_config_t common; } dif_pinmux_wakeup_timed_config_t; -/** - * Creates a new handle for a Pin Multiplexer. - * - * This function does not actuate the hardware. - * - * @param params Hardware instantiation parameters. - * @param[out] pinmux Out param for the initialized handle. - * @return The result of the operation. - */ -OT_WARN_UNUSED_RESULT -dif_result_t dif_pinmux_init(mmio_region_t base_addr, dif_pinmux_t *pinmux); - /** * Locks out Pin Multiplexer functionality based on the `target` and `index`. * diff --git a/sw/device/lib/dif/dif_pwrmgr.c b/sw/device/lib/dif/dif_pwrmgr.c index f985b1e5a87e9..df2f9e06f98bd 100644 --- a/sw/device/lib/dif/dif_pwrmgr.c +++ b/sw/device/lib/dif/dif_pwrmgr.c @@ -242,16 +242,6 @@ static bool request_sources_is_locked(const dif_pwrmgr_t *pwrmgr, return !bitfield_bit32_read(reg_val, reg_info.write_enable_bit_index); } -dif_result_t dif_pwrmgr_init(mmio_region_t base_addr, dif_pwrmgr_t *pwrmgr) { - if (pwrmgr == NULL) { - return kDifBadArg; - } - - pwrmgr->base_addr = base_addr; - - return kDifOk; -} - dif_result_t dif_pwrmgr_low_power_set_enabled(const dif_pwrmgr_t *pwrmgr, dif_toggle_t new_state) { if (pwrmgr == NULL) { diff --git a/sw/device/lib/dif/dif_pwrmgr.h b/sw/device/lib/dif/dif_pwrmgr.h index 8bc0cee6f47c9..d96d9838f6d07 100644 --- a/sw/device/lib/dif/dif_pwrmgr.h +++ b/sw/device/lib/dif/dif_pwrmgr.h @@ -183,18 +183,6 @@ typedef enum dif_pwrmgr_alert { kDifPwrmgrAlertFatalFault = 0, } dif_pwrmgr_alert_t; -/** - * Creates a new handle for power manager. - * - * This function does not actuate the hardware. - * - * @param base_addr Hardware instantiation base address. - * @param[out] pwrmgr Out-param for the initialized handle. - * @return The result of the operation. - */ -OT_WARN_UNUSED_RESULT -dif_result_t dif_pwrmgr_init(mmio_region_t base_addr, dif_pwrmgr_t *pwrmgr); - /** * Enables or disables low power state. * diff --git a/sw/device/lib/dif/dif_pwrmgr_unittest.cc b/sw/device/lib/dif/dif_pwrmgr_unittest.cc index b1f4bf2b97a55..dbc06158a43c0 100644 --- a/sw/device/lib/dif/dif_pwrmgr_unittest.cc +++ b/sw/device/lib/dif/dif_pwrmgr_unittest.cc @@ -35,22 +35,9 @@ static constexpr dif_pwrmgr_domain_config_t kBadConfig = static constexpr dif_pwrmgr_request_sources_t kBadSources = std::numeric_limits::max(); -class DifPwrmgrTest : public testing::Test, public mock_mmio::MmioTest {}; - -class InitTest : public DifPwrmgrTest {}; - -TEST_F(InitTest, BadArgs) { - EXPECT_EQ(dif_pwrmgr_init(dev().region(), nullptr), kDifBadArg); -} - -TEST_F(InitTest, Init) { - dif_pwrmgr_t pwrmgr; - EXPECT_EQ(dif_pwrmgr_init(dev().region(), &pwrmgr), kDifOk); -} - // Base class for the rest of the tests in this file, provides a // `dif_pwrmgr_t` instance. -class DifPwrmgrInitialized : public DifPwrmgrTest { +class DifPwrmgrInitialized : public testing::Test, public mock_mmio::MmioTest { protected: /** * Expectations for functions that need to sync data to slow clock domain. diff --git a/sw/device/lib/dif/dif_rstmgr.c b/sw/device/lib/dif/dif_rstmgr.c index 72cf76c2214a2..f2e804b7f50e0 100644 --- a/sw/device/lib/dif/dif_rstmgr.c +++ b/sw/device/lib/dif/dif_rstmgr.c @@ -88,16 +88,6 @@ static void rstmgr_reset_info_clear(mmio_region_t base_addr) { mmio_region_write32(base_addr, RSTMGR_RESET_INFO_REG_OFFSET, UINT32_MAX); } -dif_result_t dif_rstmgr_init(mmio_region_t base_addr, dif_rstmgr_t *handle) { - if (handle == NULL) { - return kDifBadArg; - } - - handle->base_addr = base_addr; - - return kDifOk; -} - dif_result_t dif_rstmgr_reset(const dif_rstmgr_t *handle) { if (handle == NULL) { return kDifBadArg; diff --git a/sw/device/lib/dif/dif_rstmgr.h b/sw/device/lib/dif/dif_rstmgr.h index 6c667d33933cf..71bb837a22ad0 100644 --- a/sw/device/lib/dif/dif_rstmgr.h +++ b/sw/device/lib/dif/dif_rstmgr.h @@ -87,18 +87,6 @@ typedef enum dif_rstmgr_reset_info { */ typedef uint32_t dif_rstmgr_peripheral_t; -/** - * Creates a new handle for Reset Manager. - * - * This function does not actuate the hardware. - * - * @param params Hardware instantiation parameters. - * @param handle Out param for the initialized handle. - * @return The result of the operation. - */ -OT_WARN_UNUSED_RESULT -dif_result_t dif_rstmgr_init(mmio_region_t base_addr, dif_rstmgr_t *handle); - /** * Resets the Reset Manager registers to sane defaults. * diff --git a/sw/device/lib/dif/dif_rstmgr_unittest.cc b/sw/device/lib/dif/dif_rstmgr_unittest.cc index e2f8b455b5f61..5384c79642631 100644 --- a/sw/device/lib/dif/dif_rstmgr_unittest.cc +++ b/sw/device/lib/dif/dif_rstmgr_unittest.cc @@ -27,17 +27,6 @@ class RstmgrTest : public Test, public MmioTest { dif_rstmgr_t rstmgr_ = {.base_addr = dev().region()}; }; -class InitTest : public RstmgrTest {}; - -TEST_F(InitTest, NullArgs) { - EXPECT_EQ(dif_rstmgr_init(dev().region(), nullptr), kDifBadArg); -} - -TEST_F(InitTest, Success) { - dif_rstmgr_t rstmgr; - EXPECT_EQ(dif_rstmgr_init(dev().region(), &rstmgr), kDifOk); -} - class ResetTest : public RstmgrTest {}; TEST_F(ResetTest, NullArgs) { diff --git a/sw/device/lib/dif/dif_rv_plic.c b/sw/device/lib/dif/dif_rv_plic.c index bfcfa027e02cc..79d13ffca8b55 100644 --- a/sw/device/lib/dif/dif_rv_plic.c +++ b/sw/device/lib/dif/dif_rv_plic.c @@ -149,16 +149,6 @@ dif_result_t dif_rv_plic_reset(const dif_rv_plic_t *plic) { return kDifOk; } -dif_result_t dif_rv_plic_init(mmio_region_t base_addr, dif_rv_plic_t *plic) { - if (plic == NULL) { - return kDifBadArg; - } - - plic->base_addr = base_addr; - - return kDifOk; -} - dif_result_t dif_rv_plic_irq_get_enabled(const dif_rv_plic_t *plic, dif_rv_plic_irq_id_t irq, dif_rv_plic_target_t target, diff --git a/sw/device/lib/dif/dif_rv_plic.h b/sw/device/lib/dif/dif_rv_plic.h index cf7ba4a71ddca..62f5ba011b61c 100644 --- a/sw/device/lib/dif/dif_rv_plic.h +++ b/sw/device/lib/dif/dif_rv_plic.h @@ -65,18 +65,6 @@ typedef uint32_t dif_rv_plic_irq_id_t; */ typedef uint32_t dif_rv_plic_target_t; -/** - * Creates a new handle for PLIC. - * - * This function does not actuate the hardware. - * - * @param params Hardware instantiation parameters. - * @param[out] plic Out param for the initialized handle. - * @return The result of the operation. - */ -OT_WARN_UNUSED_RESULT -dif_result_t dif_rv_plic_init(mmio_region_t base_addr, dif_rv_plic_t *plic); - /** * Resets the PLIC to a clean state. * diff --git a/sw/device/lib/dif/dif_rv_plic_unittest.cc b/sw/device/lib/dif/dif_rv_plic_unittest.cc index 266d445776a70..60f594ddf1f44 100644 --- a/sw/device/lib/dif/dif_rv_plic_unittest.cc +++ b/sw/device/lib/dif/dif_rv_plic_unittest.cc @@ -33,16 +33,6 @@ class PlicTest : public Test, public MmioTest { dif_rv_plic_t plic_ = {.base_addr = dev().region()}; }; -class InitTest : public PlicTest {}; - -TEST_F(InitTest, NullArgs) { - EXPECT_EQ(dif_rv_plic_init(dev().region(), nullptr), kDifBadArg); -} - -TEST_F(InitTest, Success) { - EXPECT_EQ(dif_rv_plic_init(dev().region(), &plic_), kDifOk); -} - class ResetTest : public PlicTest { protected: void ExpectReset() { diff --git a/sw/device/lib/dif/dif_rv_timer.c b/sw/device/lib/dif/dif_rv_timer.c index 6f432307d0409..439b5030a6a54 100644 --- a/sw/device/lib/dif/dif_rv_timer.c +++ b/sw/device/lib/dif/dif_rv_timer.c @@ -36,17 +36,6 @@ static ptrdiff_t reg_for_hart(uint32_t hart, ptrdiff_t reg_offset) { return kHartRegisterSpacing * hart + reg_offset; } -dif_result_t dif_rv_timer_init(mmio_region_t base_addr, - dif_rv_timer_t *timer_out) { - if (timer_out == NULL) { - return kDifBadArg; - } - - timer_out->base_addr = base_addr; - - return kDifOk; -} - /** * A naive implementation of the Euclidean algorithm by repeated remainder. */ diff --git a/sw/device/lib/dif/dif_rv_timer.h b/sw/device/lib/dif/dif_rv_timer.h index 0b2d3c1c20d8c..57f5ba4cc7bc6 100644 --- a/sw/device/lib/dif/dif_rv_timer.h +++ b/sw/device/lib/dif/dif_rv_timer.h @@ -84,19 +84,6 @@ dif_result_t dif_rv_timer_approximate_tick_params( uint64_t clock_freq, uint64_t counter_freq, dif_rv_timer_tick_params_t *out); -/** - * Initialize a RISC-V timer device with the given configuration. - * - * This function will deactivate all counters and reset all timers, which should - * each be configured and turned on manually after this function returns. - * - * @param base_addr MMIO region for the device hardware registers. - * @param[out] timer_out The timer device. - * @return The result of the operation. - */ -dif_result_t dif_rv_timer_init(mmio_region_t base_addr, - dif_rv_timer_t *timer_out); - /** * Completely resets a timer device, disabling all IRQs, counters, and * comparators. diff --git a/sw/device/lib/dif/dif_rv_timer_unittest.cc b/sw/device/lib/dif/dif_rv_timer_unittest.cc index 797038613430d..7623d12999df2 100644 --- a/sw/device/lib/dif/dif_rv_timer_unittest.cc +++ b/sw/device/lib/dif/dif_rv_timer_unittest.cc @@ -113,16 +113,6 @@ ptrdiff_t IrqRegForHart(uint32_t hart, uint32_t comparators, constexpr uint32_t kAllOnes = std::numeric_limits::max(); -class InitTest : public TimerTest {}; - -TEST_F(InitTest, Success) { - EXPECT_EQ(dif_rv_timer_init(dev().region(), &rv_timer_), kDifOk); -} - -TEST_F(InitTest, NullArgs) { - EXPECT_EQ(dif_rv_timer_init(dev().region(), nullptr), kDifBadArg); -} - class ResetTest : public TimerTest {}; TEST_F(ResetTest, Success) { diff --git a/sw/device/lib/dif/dif_spi_device.c b/sw/device/lib/dif/dif_spi_device.c index 370bc70f38a1b..873b07cee6759 100644 --- a/sw/device/lib/dif/dif_spi_device.c +++ b/sw/device/lib/dif/dif_spi_device.c @@ -12,17 +12,6 @@ const uint16_t kDifSpiDeviceBufferLen = SPI_DEVICE_BUFFER_SIZE_BYTES; -dif_result_t dif_spi_device_init(mmio_region_t base_addr, - dif_spi_device_t *spi) { - if (spi == NULL) { - return kDifBadArg; - } - - spi->base_addr = base_addr; - - return kDifOk; -} - /** * Computes the required value of the control register from a given * configuration. diff --git a/sw/device/lib/dif/dif_spi_device.h b/sw/device/lib/dif/dif_spi_device.h index 8006fc23f7a1e..bf3ad037bf66a 100644 --- a/sw/device/lib/dif/dif_spi_device.h +++ b/sw/device/lib/dif/dif_spi_device.h @@ -86,19 +86,6 @@ typedef struct dif_spi_device_config { */ extern const uint16_t kDifSpiDeviceBufferLen; -/** - * Creates a new handle for SPI. - * - * This function does not actuate the hardware. - * - * @param base_addr Hardware instantiation base address. - * @param[out] spi Out param for the initialized handle. - * @return The result of the operation. - */ -OT_WARN_UNUSED_RESULT -dif_result_t dif_spi_device_init(mmio_region_t base_addr, - dif_spi_device_t *spi); - /** * Configures SPI with runtime information. * diff --git a/sw/device/lib/dif/dif_sram_ctrl.c b/sw/device/lib/dif/dif_sram_ctrl.c index 9ead895869f01..9efd7501c65fd 100644 --- a/sw/device/lib/dif/dif_sram_ctrl.c +++ b/sw/device/lib/dif/dif_sram_ctrl.c @@ -28,17 +28,6 @@ static uint32_t sram_ctrl_get_status(const dif_sram_ctrl_t *sram_ctrl) { return mmio_region_read32(sram_ctrl->base_addr, SRAM_CTRL_STATUS_REG_OFFSET); } -dif_result_t dif_sram_ctrl_init(mmio_region_t base_addr, - dif_sram_ctrl_t *sram_ctrl) { - if (sram_ctrl == NULL) { - return kDifBadArg; - } - - sram_ctrl->base_addr = base_addr; - - return kDifOk; -} - dif_result_t dif_sram_ctrl_request_new_key(const dif_sram_ctrl_t *sram_ctrl) { if (sram_ctrl == NULL) { return kDifBadArg; diff --git a/sw/device/lib/dif/dif_sram_ctrl.h b/sw/device/lib/dif/dif_sram_ctrl.h index 7f23dc68749bb..6745b62c4eb7c 100644 --- a/sw/device/lib/dif/dif_sram_ctrl.h +++ b/sw/device/lib/dif/dif_sram_ctrl.h @@ -93,19 +93,6 @@ typedef enum dif_sram_ctrl_lock { kDifSramCtrlLockExec, } dif_sram_ctrl_lock_t; -/** - * Creates a new handle for SRAM Controller. - * - * This function does not actuate the hardware. - * - * @param base_addr The MMIO base address of the IP. - * @param[out] sram_ctrl Out param for the initialized handle. - * @return The result of the operation. - */ -OT_WARN_UNUSED_RESULT -dif_result_t dif_sram_ctrl_init(mmio_region_t base_addr, - dif_sram_ctrl_t *sram_ctrl); - /** * Performs SRAM scrambling. * diff --git a/sw/device/lib/dif/dif_sram_ctrl_unittest.cc b/sw/device/lib/dif/dif_sram_ctrl_unittest.cc index 81fc7c7e8296b..353e4e073b9c3 100644 --- a/sw/device/lib/dif/dif_sram_ctrl_unittest.cc +++ b/sw/device/lib/dif/dif_sram_ctrl_unittest.cc @@ -22,12 +22,6 @@ class SramCtrlTest : public Test, public MmioTest { dif_sram_ctrl_t sram_ctrl_ = {.base_addr = dev().region()}; }; -class InitTest : public SramCtrlTest {}; - -TEST_F(InitTest, NullArgs) { - EXPECT_EQ(dif_sram_ctrl_init(dev().region(), nullptr), kDifBadArg); -} - class RequestNewKeyTest : public SramCtrlTest {}; TEST_F(RequestNewKeyTest, NullArgs) { diff --git a/sw/device/lib/dif/dif_uart.c b/sw/device/lib/dif/dif_uart.c index 5a318026eea56..8dd91fd40c474 100644 --- a/sw/device/lib/dif/dif_uart.c +++ b/sw/device/lib/dif/dif_uart.c @@ -86,15 +86,6 @@ static size_t uart_bytes_receive(const dif_uart_t *uart, size_t bytes_requested, return bytes_read; } -dif_result_t dif_uart_init(mmio_region_t base_addr, dif_uart_t *uart) { - if (uart == NULL) { - return kDifBadArg; - } - - uart->base_addr = base_addr; - return kDifOk; -} - dif_result_t dif_uart_configure(const dif_uart_t *uart, dif_uart_config_t config) { if (uart == NULL) { diff --git a/sw/device/lib/dif/dif_uart.h b/sw/device/lib/dif/dif_uart.h index 0372097b755ed..2faea54b2a26a 100644 --- a/sw/device/lib/dif/dif_uart.h +++ b/sw/device/lib/dif/dif_uart.h @@ -122,18 +122,6 @@ typedef enum dif_uart_loopback { */ extern const uint32_t kDifUartFifoSizeBytes; -/** - * Creates a new handle for UART. - * - * This function does not actuate the hardware. - * - * @param base_addr Base address of the UART peripheral. - * @param[out] uart Out param for the initialized handle. - * @return The result of the operation. - */ -OT_WARN_UNUSED_RESULT -dif_result_t dif_uart_init(mmio_region_t base_addr, dif_uart_t *uart); - /** * Configures UART with runtime information. * diff --git a/sw/device/lib/dif/dif_uart_unittest.cc b/sw/device/lib/dif/dif_uart_unittest.cc index 07b7f6513c28f..c555929651bb5 100644 --- a/sw/device/lib/dif/dif_uart_unittest.cc +++ b/sw/device/lib/dif/dif_uart_unittest.cc @@ -55,12 +55,6 @@ class UartTest : public Test, public MmioTest { }; }; -class InitTest : public UartTest {}; - -TEST_F(InitTest, NullArgs) { - EXPECT_EQ(dif_uart_init({.base_addr = dev().region()}, nullptr), kDifBadArg); -} - class ConfigTest : public UartTest {}; TEST_F(ConfigTest, NullArgs) { diff --git a/sw/device/lib/dif/dif_usbdev.c b/sw/device/lib/dif/dif_usbdev.c index 86fc491eaab94..41a3b8dfcdb30 100644 --- a/sw/device/lib/dif/dif_usbdev.c +++ b/sw/device/lib/dif/dif_usbdev.c @@ -232,16 +232,6 @@ static uint32_t get_buffer_addr(uint8_t buffer_id, size_t offset) { * USBDEV DIF library functions. */ -dif_result_t dif_usbdev_init(mmio_region_t base_addr, dif_usbdev_t *usbdev) { - if (usbdev == NULL) { - return kDifBadArg; - } - - usbdev->base_addr = base_addr; - - return kDifOk; -} - dif_result_t dif_usbdev_configure(const dif_usbdev_t *usbdev, dif_usbdev_buffer_pool_t *buffer_pool, dif_usbdev_config_t config) { diff --git a/sw/device/lib/dif/dif_usbdev.h b/sw/device/lib/dif/dif_usbdev.h index 47ffbb9662c4a..bec038b87b3a9 100644 --- a/sw/device/lib/dif/dif_usbdev.h +++ b/sw/device/lib/dif/dif_usbdev.h @@ -139,19 +139,6 @@ typedef struct dif_usbdev_config { dif_toggle_t clock_sync_signals; } dif_usbdev_config_t; -/** - * Initialize a USB device. - * - * A USB device must first be initialized by this function before calling other - * functions in this library. - * - * @param base_addr Hardware instantiation base address. - * @param[out] usbdev The initialized USB device handle. - * @return The result of the operation. - */ -OT_WARN_UNUSED_RESULT -dif_result_t dif_usbdev_init(mmio_region_t base_addr, dif_usbdev_t *usbdev); - /** * Configures a USB device with runtime information. * diff --git a/util/make_new_dif/dif_autogen.c.tpl b/util/make_new_dif/dif_autogen.c.tpl index f05670ade9b57..847735cf84d35 100644 --- a/util/make_new_dif/dif_autogen.c.tpl +++ b/util/make_new_dif/dif_autogen.c.tpl @@ -30,8 +30,6 @@ #include "${ip.name_snake}_regs.h" // Generated. -% if len(ip.irqs) > 0: - % if ip.name_snake == "aon_timer": #include % for irq in ip.irqs: @@ -50,42 +48,58 @@ ${ip.name_upper}_INTR_TEST0_T_${loop.index}_BIT, "Expected IRQ bit offsets to match across STATE/ENABLE regs."); % endfor +% endif - typedef enum dif_${ip.name_snake}_intr_reg { - kDif${ip.name_camel}IntrRegState = 0, - kDif${ip.name_camel}IntrRegEnable = 1, - kDif${ip.name_camel}IntrRegTest = 2, - } dif_${ip.name_snake}_intr_reg_t; +OT_WARN_UNUSED_RESULT +dif_result_t dif_${ip.name_snake}_init( + mmio_region_t base_addr, + dif_${ip.name_snake}_t *${ip.name_snake}) { + if (${ip.name_snake} == NULL) { + return kDifBadArg; + } - static bool ${ip.name_snake}_get_irq_reg_offset( - dif_${ip.name_snake}_intr_reg_t intr_reg, - dif_${ip.name_snake}_irq_t irq, - uint32_t *intr_reg_offset) { + ${ip.name_snake}->base_addr = base_addr; - switch (intr_reg) { + return kDifOk; +} - % for intr_reg_str in ["State", "Enable", "Test"]: - case kDif${ip.name_camel}IntrReg${intr_reg_str}: - switch (irq) { - % for hart_id in range(int(ip.parameters["N_HARTS"].default)): - % for timer_id in range(int(ip.parameters["N_TIMERS"].default)): - case kDif${ip.name_camel}IrqTimerExpiredHart${hart_id}Timer${timer_id}: - *intr_reg_offset = ${ip.name_upper}_INTR_${intr_reg_str.upper()}${hart_id}_REG_OFFSET; - break; +% if len(ip.irqs) > 0: + % if ip.name_snake == "rv_timer": + typedef enum dif_${ip.name_snake}_intr_reg { + kDif${ip.name_camel}IntrRegState = 0, + kDif${ip.name_camel}IntrRegEnable = 1, + kDif${ip.name_camel}IntrRegTest = 2, + } dif_${ip.name_snake}_intr_reg_t; + + static bool ${ip.name_snake}_get_irq_reg_offset( + dif_${ip.name_snake}_intr_reg_t intr_reg, + dif_${ip.name_snake}_irq_t irq, + uint32_t *intr_reg_offset) { + + switch (intr_reg) { + + % for intr_reg_str in ["State", "Enable", "Test"]: + case kDif${ip.name_camel}IntrReg${intr_reg_str}: + switch (irq) { + % for hart_id in range(int(ip.parameters["N_HARTS"].default)): + % for timer_id in range(int(ip.parameters["N_TIMERS"].default)): + case kDif${ip.name_camel}IrqTimerExpiredHart${hart_id}Timer${timer_id}: + *intr_reg_offset = ${ip.name_upper}_INTR_${intr_reg_str.upper()}${hart_id}_REG_OFFSET; + break; + % endfor % endfor - % endfor - default: - return false; - } - break; - % endfor - default: - return false; - } + default: + return false; + } + break; + % endfor + default: + return false; + } - return true; - } -% endif + return true; + } + % endif /** * Get the corresponding interrupt register bit offset of the IRQ. If the IP's diff --git a/util/make_new_dif/dif_autogen.h.tpl b/util/make_new_dif/dif_autogen.h.tpl index cac35cf7afcd1..af12dc14c930b 100644 --- a/util/make_new_dif/dif_autogen.h.tpl +++ b/util/make_new_dif/dif_autogen.h.tpl @@ -50,8 +50,21 @@ typedef struct dif_${ip.name_snake} { mmio_region_t base_addr; } dif_${ip.name_snake}_t; -% if len(ip.irqs) > 0: +/** + * Creates a new handle for a(n) ${ip.name_snake} peripheral. + * + * This function does not actuate the hardware. + * + * @param base_addr The MMIO base address of the ${ip.name_snake} peripheral. + * @param[out] ${ip.name_snake} Out param for the initialized handle. + * @return The result of the operation. + */ +OT_WARN_UNUSED_RESULT +dif_result_t dif_${ip.name_snake}_init( + mmio_region_t base_addr, + dif_${ip.name_snake}_t *${ip.name_snake}); +% if len(ip.irqs) > 0: /** * A ${ip.name_snake} interrupt request type. */ diff --git a/util/make_new_dif/dif_autogen_unittest.cc.tpl b/util/make_new_dif/dif_autogen_unittest.cc.tpl index 3da736e0ada07..cd3ecf82354c2 100644 --- a/util/make_new_dif/dif_autogen_unittest.cc.tpl +++ b/util/make_new_dif/dif_autogen_unittest.cc.tpl @@ -12,7 +12,6 @@ This template requires the following Python objects to be passed: 1. ip: See util/make_new_dif.py for the definition of the `ip` obj. - 2. list[irq]: See util/make_new_dif.py for the definition of the `irq` obj. // This file is auto-generated. @@ -29,6 +28,7 @@ namespace dif_${ip.name_snake}_autogen_unittest { namespace { using ::mock_mmio::MmioTest; using ::mock_mmio::MockDevice; + using ::testing::Eq; using ::testing::Test; class ${ip.name_camel}Test : public Test, public MmioTest { @@ -36,9 +36,23 @@ namespace { dif_${ip.name_snake}_t ${ip.name_snake}_ = {.base_addr = dev().region()}; }; -% if len(ip.irqs) > 0: - using ::testing::Eq; + class InitTest : public ${ip.name_camel}Test {}; + TEST_F(InitTest, NullArgs) { + EXPECT_EQ(dif_${ip.name_snake}_init( + {.base_addr = dev().region()}, + nullptr), + kDifBadArg); + } + + TEST_F(InitTest, Success) { + EXPECT_EQ(dif_${ip.name_snake}_init( + {.base_addr = dev().region()}, + &${ip.name_snake}_), + kDifOk); + } + +% if len(ip.irqs) > 0: class IrqGetStateTest : public ${ip.name_camel}Test {}; TEST_F(IrqGetStateTest, NullArgs) { diff --git a/util/make_new_dif/dif_template.h.tpl b/util/make_new_dif/dif_template.h.tpl index f51ffcfb8e9d5..2ff92e8ad2f66 100644 --- a/util/make_new_dif/dif_template.h.tpl +++ b/util/make_new_dif/dif_template.h.tpl @@ -67,20 +67,6 @@ typedef struct dif_${ip.name_snake}_output { // Your fields here. } dif_${ip.name_snake}_output_t; -/** - * Creates a new handle for ${ip.name_long_lower}. - * - * This function does not actuate the hardware. - * - * @param base_addr The MMIO base address of the IP. - * @param[out] ${ip.name_snake} Out param for the initialized handle. - * @return The result of the operation. - */ -OT_WARN_UNUSED_RESULT -dif_result_t dif_${ip.name_snake}_init( - mmio_region_t base_addr, - dif_${ip.name_snake}_t *${ip.name_snake}); - /** * Configures ${ip.name_long_lower} with runtime information. *