Skip to content

Commit

Permalink
core: interrupts: add gic_spi_release_to_ns API to reset the properties
Browse files Browse the repository at this point in the history
of an interrupt

This patch introduces gic_spi_release_to_ns API to release an interrupt
to Non secure settings. This functionality is essential for scenarios
where a specific interrupt needs to be dynamically set to either Group
1 Secure (G1S) or Group 1 Non-Secure (G1NS) at different times.

Signed-off-by: Runyang Chen <runyang.chen@mediatek.com>
  • Loading branch information
Runyang Chen committed Jul 11, 2024
1 parent ac5bf9b commit 0e58e2d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
24 changes: 24 additions & 0 deletions core/drivers/gic.c
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,30 @@ void gic_dump_state(void)
}
}

void gic_spi_release_to_ns(size_t it)
{
struct gic_data *gd = &gic_data;
size_t idx = it / NUM_INTS_PER_REG;
uint32_t mask = 1 << (it % NUM_INTS_PER_REG);

assert(it < gd->max_it && it >= GIC_SPI_BASE);
/* Assert it's already disabled */
assert(!gic_it_is_enabled(gd, it));
/* Assert it's secure to start with */
assert(!gic_it_get_group(gd, it));

gic_it_set_cpu_mask(gd, it, 0);
gic_it_set_prio(gd, it, GIC_SPI_PRI_NS_EL1);

/* Clear pending status */
io_write32(gd->gicd_base + GICD_ICPENDR(idx), mask);
/* Assign it to NS Group1 */
io_setbits32(gd->gicd_base + GICD_IGROUPR(idx), mask);
#if defined(CFG_ARM_GICV3)
io_clrbits32(gd->gicd_base + GICD_IGROUPMODR(idx), mask);
#endif
}

static void __maybe_unused gic_native_itr_handler(void)
{
struct gic_data *gd = &gic_data;
Expand Down
5 changes: 5 additions & 0 deletions core/include/drivers/gic.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#define GIC_SGI_SEC_BASE 8
/* Max ID for secure SGIs */
#define GIC_SGI_SEC_MAX 15
/* Default IRQ priority for SPIs in Non-Sec EL1 */
#define GIC_SPI_PRI_NS_EL1 0xa0

/*
* The two gic_init() and gic_init_v3() functions initializes the struct
Expand All @@ -56,4 +58,7 @@ void gic_init_per_cpu(void);

/* Print GIC state to console */
void gic_dump_state(void);

/* Release the property for a shared peripheral interrupt */
void gic_spi_release_to_ns(size_t it);
#endif /*__DRIVERS_GIC_H*/

0 comments on commit 0e58e2d

Please sign in to comment.