Skip to content

Commit

Permalink
[make_new_dif] Only consider earlgrey IPs for isr_testutils
Browse files Browse the repository at this point in the history
We are current in a weird spot: we have DIFs for IPs in Darjeeling
but isr_testutils it not quite ready to be multitop. This is because
it contains code for *every IP* but clearly not all IPs exist in
every top. This kind of works because we generate C headers for all
IPs independently of the top and so we happily compile DMA code on
Earlgrey...
However, when we start marking headers as only compatible with the
active top, this will break down and isr_testutils will not compile
anymore.

Furthermore, the isr_testutils template already assume Earlgrey by
including `top_earlgrey.h` and the Python generator does not even
take the top description as input so it's top independent.

This will require a proper fix eventually but this commit
implements a stopgap: it only considers Earlgrey IPs for inclusion
in isr_testutils. This at least guarantees that it create a
consistent, if earlgrey-specific, file.

Signed-off-by: Amaury Pouly <amaury.pouly@lowrisc.org>
  • Loading branch information
pamaury committed Dec 18, 2024
1 parent 9037810 commit c1d762f
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 239 deletions.
3 changes: 0 additions & 3 deletions sw/device/lib/testing/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,14 @@ cc_library(
"//sw/device/lib/dif:alert_handler",
"//sw/device/lib/dif:aon_timer",
"//sw/device/lib/dif:csrng",
"//sw/device/lib/dif:dma",
"//sw/device/lib/dif:edn",
"//sw/device/lib/dif:entropy_src",
"//sw/device/lib/dif:flash_ctrl",
"//sw/device/lib/dif:gpio",
"//sw/device/lib/dif:hmac",
"//sw/device/lib/dif:i2c",
"//sw/device/lib/dif:keymgr",
"//sw/device/lib/dif:keymgr_dpe",
"//sw/device/lib/dif:kmac",
"//sw/device/lib/dif:mbx",
"//sw/device/lib/dif:otbn",
"//sw/device/lib/dif:otp_ctrl",
"//sw/device/lib/dif:pattgen",
Expand Down
125 changes: 0 additions & 125 deletions sw/device/lib/testing/autogen/isr_testutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,14 @@
#include "sw/device/lib/dif/dif_aon_timer.h"
#include "sw/device/lib/dif/dif_base.h"
#include "sw/device/lib/dif/dif_csrng.h"
#include "sw/device/lib/dif/dif_dma.h"
#include "sw/device/lib/dif/dif_edn.h"
#include "sw/device/lib/dif/dif_entropy_src.h"
#include "sw/device/lib/dif/dif_flash_ctrl.h"
#include "sw/device/lib/dif/dif_gpio.h"
#include "sw/device/lib/dif/dif_hmac.h"
#include "sw/device/lib/dif/dif_i2c.h"
#include "sw/device/lib/dif/dif_keymgr.h"
#include "sw/device/lib/dif/dif_keymgr_dpe.h"
#include "sw/device/lib/dif/dif_kmac.h"
#include "sw/device/lib/dif/dif_mbx.h"
#include "sw/device/lib/dif/dif_otbn.h"
#include "sw/device/lib/dif/dif_otp_ctrl.h"
#include "sw/device/lib/dif/dif_pattgen.h"
Expand Down Expand Up @@ -212,47 +209,6 @@ void isr_testutils_csrng_isr(
plic_irq_id));
}

void isr_testutils_dma_isr(plic_isr_ctx_t plic_ctx, dma_isr_ctx_t dma_ctx,
bool mute_status_irq,
top_earlgrey_plic_peripheral_t *peripheral_serviced,
dif_dma_irq_t *irq_serviced) {
// Claim the IRQ at the PLIC.
dif_rv_plic_irq_id_t plic_irq_id;
CHECK_DIF_OK(
dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));

// Get the peripheral the IRQ belongs to.
*peripheral_serviced = (top_earlgrey_plic_peripheral_t)
top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];

// Get the IRQ that was fired from the PLIC IRQ ID.
dif_dma_irq_t irq =
(dif_dma_irq_t)(plic_irq_id - dma_ctx.plic_dma_start_irq_id);
*irq_serviced = irq;

// Check if it is supposed to be the only IRQ fired.
if (dma_ctx.is_only_irq) {
dif_dma_irq_state_snapshot_t snapshot;
CHECK_DIF_OK(dif_dma_irq_get_state(dma_ctx.dma, &snapshot));
CHECK(snapshot == (dif_dma_irq_state_snapshot_t)(1 << irq),
"Only dma IRQ %d expected to fire. Actual IRQ state = %x", irq,
snapshot);
}

// Acknowledge the IRQ at the peripheral if IRQ is of the event type.
dif_irq_type_t type;
CHECK_DIF_OK(dif_dma_irq_get_type(dma_ctx.dma, irq, &type));
if (type == kDifIrqTypeEvent) {
CHECK_DIF_OK(dif_dma_irq_acknowledge(dma_ctx.dma, irq));
} else if (mute_status_irq) {
CHECK_DIF_OK(dif_dma_irq_set_enabled(dma_ctx.dma, irq, kDifToggleDisabled));
}

// Complete the IRQ at the PLIC.
CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
plic_irq_id));
}

void isr_testutils_edn_isr(plic_isr_ctx_t plic_ctx, edn_isr_ctx_t edn_ctx,
top_earlgrey_plic_peripheral_t *peripheral_serviced,
dif_edn_irq_t *irq_serviced) {
Expand Down Expand Up @@ -540,49 +496,6 @@ void isr_testutils_keymgr_isr(
plic_irq_id));
}

void isr_testutils_keymgr_dpe_isr(
plic_isr_ctx_t plic_ctx, keymgr_dpe_isr_ctx_t keymgr_dpe_ctx,
top_earlgrey_plic_peripheral_t *peripheral_serviced,
dif_keymgr_dpe_irq_t *irq_serviced) {
// Claim the IRQ at the PLIC.
dif_rv_plic_irq_id_t plic_irq_id;
CHECK_DIF_OK(
dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));

// Get the peripheral the IRQ belongs to.
*peripheral_serviced = (top_earlgrey_plic_peripheral_t)
top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];

// Get the IRQ that was fired from the PLIC IRQ ID.
dif_keymgr_dpe_irq_t irq =
(dif_keymgr_dpe_irq_t)(plic_irq_id -
keymgr_dpe_ctx.plic_keymgr_dpe_start_irq_id);
*irq_serviced = irq;

// Check if it is supposed to be the only IRQ fired.
if (keymgr_dpe_ctx.is_only_irq) {
dif_keymgr_dpe_irq_state_snapshot_t snapshot;
CHECK_DIF_OK(
dif_keymgr_dpe_irq_get_state(keymgr_dpe_ctx.keymgr_dpe, &snapshot));
CHECK(snapshot == (dif_keymgr_dpe_irq_state_snapshot_t)(1 << irq),
"Only keymgr_dpe IRQ %d expected to fire. Actual IRQ state = %x", irq,
snapshot);
}

// Acknowledge the IRQ at the peripheral if IRQ is of the event type.
dif_irq_type_t type;
CHECK_DIF_OK(
dif_keymgr_dpe_irq_get_type(keymgr_dpe_ctx.keymgr_dpe, irq, &type));
if (type == kDifIrqTypeEvent) {
CHECK_DIF_OK(
dif_keymgr_dpe_irq_acknowledge(keymgr_dpe_ctx.keymgr_dpe, irq));
}

// Complete the IRQ at the PLIC.
CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
plic_irq_id));
}

void isr_testutils_kmac_isr(plic_isr_ctx_t plic_ctx, kmac_isr_ctx_t kmac_ctx,
bool mute_status_irq,
top_earlgrey_plic_peripheral_t *peripheral_serviced,
Expand Down Expand Up @@ -625,44 +538,6 @@ void isr_testutils_kmac_isr(plic_isr_ctx_t plic_ctx, kmac_isr_ctx_t kmac_ctx,
plic_irq_id));
}

void isr_testutils_mbx_isr(plic_isr_ctx_t plic_ctx, mbx_isr_ctx_t mbx_ctx,
top_earlgrey_plic_peripheral_t *peripheral_serviced,
dif_mbx_irq_t *irq_serviced) {
// Claim the IRQ at the PLIC.
dif_rv_plic_irq_id_t plic_irq_id;
CHECK_DIF_OK(
dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));

// Get the peripheral the IRQ belongs to.
*peripheral_serviced = (top_earlgrey_plic_peripheral_t)
top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];

// Get the IRQ that was fired from the PLIC IRQ ID.
dif_mbx_irq_t irq =
(dif_mbx_irq_t)(plic_irq_id - mbx_ctx.plic_mbx_start_irq_id);
*irq_serviced = irq;

// Check if it is supposed to be the only IRQ fired.
if (mbx_ctx.is_only_irq) {
dif_mbx_irq_state_snapshot_t snapshot;
CHECK_DIF_OK(dif_mbx_irq_get_state(mbx_ctx.mbx, &snapshot));
CHECK(snapshot == (dif_mbx_irq_state_snapshot_t)(1 << irq),
"Only mbx IRQ %d expected to fire. Actual IRQ state = %x", irq,
snapshot);
}

// Acknowledge the IRQ at the peripheral if IRQ is of the event type.
dif_irq_type_t type;
CHECK_DIF_OK(dif_mbx_irq_get_type(mbx_ctx.mbx, irq, &type));
if (type == kDifIrqTypeEvent) {
CHECK_DIF_OK(dif_mbx_irq_acknowledge(mbx_ctx.mbx, irq));
}

// Complete the IRQ at the PLIC.
CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
plic_irq_id));
}

void isr_testutils_otbn_isr(plic_isr_ctx_t plic_ctx, otbn_isr_ctx_t otbn_ctx,
top_earlgrey_plic_peripheral_t *peripheral_serviced,
dif_otbn_irq_t *irq_serviced) {
Expand Down
111 changes: 0 additions & 111 deletions sw/device/lib/testing/autogen/isr_testutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,14 @@
#include "sw/device/lib/dif/dif_alert_handler.h"
#include "sw/device/lib/dif/dif_aon_timer.h"
#include "sw/device/lib/dif/dif_csrng.h"
#include "sw/device/lib/dif/dif_dma.h"
#include "sw/device/lib/dif/dif_edn.h"
#include "sw/device/lib/dif/dif_entropy_src.h"
#include "sw/device/lib/dif/dif_flash_ctrl.h"
#include "sw/device/lib/dif/dif_gpio.h"
#include "sw/device/lib/dif/dif_hmac.h"
#include "sw/device/lib/dif/dif_i2c.h"
#include "sw/device/lib/dif/dif_keymgr.h"
#include "sw/device/lib/dif/dif_keymgr_dpe.h"
#include "sw/device/lib/dif/dif_kmac.h"
#include "sw/device/lib/dif/dif_mbx.h"
#include "sw/device/lib/dif/dif_otbn.h"
#include "sw/device/lib/dif/dif_otp_ctrl.h"
#include "sw/device/lib/dif/dif_pattgen.h"
Expand Down Expand Up @@ -145,28 +142,6 @@ typedef struct csrng_isr_ctx {
bool is_only_irq;
} csrng_isr_ctx_t;

/**
* A handle to a dma ISR context struct.
*/
typedef struct dma_isr_ctx {
/**
* A handle to a dma.
*/
dif_dma_t *dma;
/**
* The PLIC IRQ ID where this dma instance's IRQs start.
*/
dif_rv_plic_irq_id_t plic_dma_start_irq_id;
/**
* The dma IRQ that is expected to be encountered in the ISR.
*/
dif_dma_irq_t expected_irq;
/**
* Whether or not a single IRQ is expected to be encountered in the ISR.
*/
bool is_only_irq;
} dma_isr_ctx_t;

/**
* A handle to a edn ISR context struct.
*/
Expand Down Expand Up @@ -321,28 +296,6 @@ typedef struct keymgr_isr_ctx {
bool is_only_irq;
} keymgr_isr_ctx_t;

/**
* A handle to a keymgr_dpe ISR context struct.
*/
typedef struct keymgr_dpe_isr_ctx {
/**
* A handle to a keymgr_dpe.
*/
dif_keymgr_dpe_t *keymgr_dpe;
/**
* The PLIC IRQ ID where this keymgr_dpe instance's IRQs start.
*/
dif_rv_plic_irq_id_t plic_keymgr_dpe_start_irq_id;
/**
* The keymgr_dpe IRQ that is expected to be encountered in the ISR.
*/
dif_keymgr_dpe_irq_t expected_irq;
/**
* Whether or not a single IRQ is expected to be encountered in the ISR.
*/
bool is_only_irq;
} keymgr_dpe_isr_ctx_t;

/**
* A handle to a kmac ISR context struct.
*/
Expand All @@ -365,28 +318,6 @@ typedef struct kmac_isr_ctx {
bool is_only_irq;
} kmac_isr_ctx_t;

/**
* A handle to a mbx ISR context struct.
*/
typedef struct mbx_isr_ctx {
/**
* A handle to a mbx.
*/
dif_mbx_t *mbx;
/**
* The PLIC IRQ ID where this mbx instance's IRQs start.
*/
dif_rv_plic_irq_id_t plic_mbx_start_irq_id;
/**
* The mbx IRQ that is expected to be encountered in the ISR.
*/
dif_mbx_irq_t expected_irq;
/**
* Whether or not a single IRQ is expected to be encountered in the ISR.
*/
bool is_only_irq;
} mbx_isr_ctx_t;

/**
* A handle to a otbn ISR context struct.
*/
Expand Down Expand Up @@ -686,21 +617,6 @@ void isr_testutils_csrng_isr(
top_earlgrey_plic_peripheral_t *peripheral_serviced,
dif_csrng_irq_t *irq_serviced);

/**
* Services an dma IRQ.
*
* @param plic_ctx A PLIC ISR context handle.
* @param dma_ctx A(n) dma ISR context handle.
* @param mute_status_irq set to true to disable the serviced status type IRQ.
* @param[out] peripheral_serviced Out param for the peripheral that was
* serviced.
* @param[out] irq_serviced Out param for the IRQ that was serviced.
*/
void isr_testutils_dma_isr(plic_isr_ctx_t plic_ctx, dma_isr_ctx_t dma_ctx,
bool mute_status_irq,
top_earlgrey_plic_peripheral_t *peripheral_serviced,
dif_dma_irq_t *irq_serviced);

/**
* Services an edn IRQ.
*
Expand Down Expand Up @@ -800,20 +716,6 @@ void isr_testutils_keymgr_isr(
top_earlgrey_plic_peripheral_t *peripheral_serviced,
dif_keymgr_irq_t *irq_serviced);

/**
* Services an keymgr_dpe IRQ.
*
* @param plic_ctx A PLIC ISR context handle.
* @param keymgr_dpe_ctx A(n) keymgr_dpe ISR context handle.
* @param[out] peripheral_serviced Out param for the peripheral that was
* serviced.
* @param[out] irq_serviced Out param for the IRQ that was serviced.
*/
void isr_testutils_keymgr_dpe_isr(
plic_isr_ctx_t plic_ctx, keymgr_dpe_isr_ctx_t keymgr_dpe_ctx,
top_earlgrey_plic_peripheral_t *peripheral_serviced,
dif_keymgr_dpe_irq_t *irq_serviced);

/**
* Services an kmac IRQ.
*
Expand All @@ -829,19 +731,6 @@ void isr_testutils_kmac_isr(plic_isr_ctx_t plic_ctx, kmac_isr_ctx_t kmac_ctx,
top_earlgrey_plic_peripheral_t *peripheral_serviced,
dif_kmac_irq_t *irq_serviced);

/**
* Services an mbx IRQ.
*
* @param plic_ctx A PLIC ISR context handle.
* @param mbx_ctx A(n) mbx ISR context handle.
* @param[out] peripheral_serviced Out param for the peripheral that was
* serviced.
* @param[out] irq_serviced Out param for the IRQ that was serviced.
*/
void isr_testutils_mbx_isr(plic_isr_ctx_t plic_ctx, mbx_isr_ctx_t mbx_ctx,
top_earlgrey_plic_peripheral_t *peripheral_serviced,
dif_mbx_irq_t *irq_serviced);

/**
* Services an otbn IRQ.
*
Expand Down
4 changes: 4 additions & 0 deletions util/make_new_dif.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def main():
sys.exit(1)
ipgen_modules = lib.get_ipgen_modules(topcfg)
reggen_top_modules = lib.get_top_reggen_modules(topcfg)
all_modules = [m['type'] for m in topcfg['module']]

# Check for regeneration mode (used in CI check:
# ci/scripts/check-generated.sh)
Expand All @@ -115,6 +116,9 @@ def main():
# (/path/to/dif_uart_autogen.c) and returns the IP name in lower
# case snake mode (i.e., uart).
ip_name_snake = Path(autogen_src_filename).stem[4:-8]
# Only considers IPs for that particular top.
if ip_name_snake not in all_modules:
continue
# NOTE: ip.name_long_* not needed for auto-generated files which
# are the only files (re-)generated in regen mode.
ips.append(
Expand Down

0 comments on commit c1d762f

Please sign in to comment.