Skip to content

Commit

Permalink
[dif] Autogen all dif_<ip>_init() DIFs for all IPs.
Browse files Browse the repository at this point in the history
This is the last task that fixes #8409.

This commit:
1. updates the DIF autogen templates to auto-generate the
   `dif_<ip>_init()` DIF and corresponding unit tests for all IPs,
2. re-auto-generates all IP's (autogen'd) DIFs, and
3. deprecates all manually defined `dif_<ip>_init()` DIFs and unit
   tests.

Signed-off-by: Timothy Trippel <ttrippel@google.com>
  • Loading branch information
timothytrippel authored and moidx committed Oct 21, 2021
1 parent ddea231 commit 13b4afb
Show file tree
Hide file tree
Showing 139 changed files with 936 additions and 786 deletions.
11 changes: 11 additions & 0 deletions sw/device/lib/dif/autogen/dif_aes_autogen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
12 changes: 12 additions & 0 deletions sw/device/lib/dif/autogen/dif_aes_autogen.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions sw/device/lib/dif/autogen/dif_aes_autogen_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,23 @@ 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 {
protected:
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
12 changes: 12 additions & 0 deletions sw/device/lib/dif/autogen/dif_alert_handler_autogen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions sw/device/lib/dif/autogen/dif_alert_handler_autogen.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
14 changes: 13 additions & 1 deletion sw/device/lib/dif/autogen/dif_alert_handler_autogen_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,26 @@ 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 {
protected:
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 {};

Expand Down
12 changes: 12 additions & 0 deletions sw/device/lib/dif/autogen/dif_aon_timer_autogen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions sw/device/lib/dif/autogen/dif_aon_timer_autogen.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
13 changes: 12 additions & 1 deletion sw/device/lib/dif/autogen/dif_aon_timer_autogen_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,25 @@ 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 {
protected:
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 {};

Expand Down
11 changes: 11 additions & 0 deletions sw/device/lib/dif/autogen/dif_clkmgr_autogen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
12 changes: 12 additions & 0 deletions sw/device/lib/dif/autogen/dif_clkmgr_autogen.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions sw/device/lib/dif/autogen/dif_clkmgr_autogen_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,24 @@ 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 {
protected:
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
11 changes: 11 additions & 0 deletions sw/device/lib/dif/autogen/dif_csrng_autogen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions sw/device/lib/dif/autogen/dif_csrng_autogen.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
11 changes: 10 additions & 1 deletion sw/device/lib/dif/autogen/dif_csrng_autogen_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,23 @@ 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 {
protected:
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 {};

Expand Down
11 changes: 11 additions & 0 deletions sw/device/lib/dif/autogen/dif_edn_autogen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions sw/device/lib/dif/autogen/dif_edn_autogen.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
11 changes: 10 additions & 1 deletion sw/device/lib/dif/autogen/dif_edn_autogen_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,23 @@ 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 {
protected:
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 {};

Expand Down
12 changes: 12 additions & 0 deletions sw/device/lib/dif/autogen/dif_entropy_src_autogen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 13b4afb

Please sign in to comment.