irq: multilevel: allow to APIs to always work

When `CONFIG_MULTI_LEVEL_INTERRUPTS` is enabled, bits in a
`uint32_t` is always partitioned into 3 levels, we can safely
remove the `CONFIG_*_LEVEL_INTERRUPTS` checks so that the
APIs always works.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
This commit is contained in:
Yong Cong Sin 2024-09-23 14:07:18 +08:00 committed by Alberto Escolar
commit 3fa7d783d6

View file

@ -36,11 +36,11 @@ static inline unsigned int irq_get_level(unsigned int irq)
const uint32_t mask3 = BIT_MASK(CONFIG_3RD_LEVEL_INTERRUPT_BITS) << const uint32_t mask3 = BIT_MASK(CONFIG_3RD_LEVEL_INTERRUPT_BITS) <<
(CONFIG_1ST_LEVEL_INTERRUPT_BITS + CONFIG_2ND_LEVEL_INTERRUPT_BITS); (CONFIG_1ST_LEVEL_INTERRUPT_BITS + CONFIG_2ND_LEVEL_INTERRUPT_BITS);
if (IS_ENABLED(CONFIG_3RD_LEVEL_INTERRUPTS) && (irq & mask3) != 0) { if ((irq & mask3) != 0) {
return 3; return 3;
} }
if (IS_ENABLED(CONFIG_2ND_LEVEL_INTERRUPTS) && (irq & mask2) != 0) { if ((irq & mask2) != 0) {
return 2; return 2;
} }
@ -59,7 +59,9 @@ static inline unsigned int irq_get_level(unsigned int irq)
*/ */
static inline unsigned int irq_from_level_2(unsigned int irq) static inline unsigned int irq_from_level_2(unsigned int irq)
{ {
if (IS_ENABLED(CONFIG_3RD_LEVEL_INTERRUPTS)) { unsigned int level = irq_get_level(irq);
if (level == 3) {
return ((irq >> CONFIG_1ST_LEVEL_INTERRUPT_BITS) & return ((irq >> CONFIG_1ST_LEVEL_INTERRUPT_BITS) &
BIT_MASK(CONFIG_2ND_LEVEL_INTERRUPT_BITS)) - 1; BIT_MASK(CONFIG_2ND_LEVEL_INTERRUPT_BITS)) - 1;
} else { } else {
@ -249,10 +251,14 @@ static inline unsigned int irq_get_intc_irq(unsigned int irq)
{ {
const unsigned int level = irq_get_level(irq); const unsigned int level = irq_get_level(irq);
__ASSERT_NO_MSG(level > 1 && level <= 3); if (level == 3) {
return irq &
return irq & BIT_MASK(CONFIG_1ST_LEVEL_INTERRUPT_BITS + BIT_MASK(CONFIG_1ST_LEVEL_INTERRUPT_BITS + CONFIG_2ND_LEVEL_INTERRUPT_BITS);
(level == 3 ? CONFIG_2ND_LEVEL_INTERRUPT_BITS : 0)); } else if (level == 2) {
return irq & BIT_MASK(CONFIG_1ST_LEVEL_INTERRUPT_BITS);
} else {
return irq;
}
} }
#endif /* CONFIG_MULTI_LEVEL_INTERRUPTS */ #endif /* CONFIG_MULTI_LEVEL_INTERRUPTS */