Skip to content

Commit e8fcb8d

Browse files
povergoingNicolas Pitre
authored and
Nicolas Pitre
committed
drivers: gic: Add irq pending check and clear function
Implement irq pending check and clear function for both gic and gicv3. Signed-off-by: Jaxson Han <[email protected]>
1 parent 53ce332 commit e8fcb8d

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

drivers/interrupt_controller/intc_gic.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,29 @@ bool arm_gic_irq_is_enabled(unsigned int irq)
5757
return (enabler & (1 << int_off)) != 0;
5858
}
5959

60+
bool arm_gic_irq_is_pending(unsigned int irq)
61+
{
62+
int int_grp, int_off;
63+
unsigned int enabler;
64+
65+
int_grp = irq / 32;
66+
int_off = irq % 32;
67+
68+
enabler = sys_read32(GICD_ISPENDRn + int_grp * 4);
69+
70+
return (enabler & (1 << int_off)) != 0;
71+
}
72+
73+
void arm_gic_irq_clear_pending(unsigned int irq)
74+
{
75+
int int_grp, int_off;
76+
77+
int_grp = irq / 32;
78+
int_off = irq % 32;
79+
80+
sys_write32((1 << int_off), (GICD_ICPENDRn + int_grp * 4));
81+
}
82+
6083
void arm_gic_irq_set_priority(
6184
unsigned int irq, unsigned int prio, uint32_t flags)
6285
{

drivers/interrupt_controller/intc_gicv3.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,25 @@ bool arm_gic_irq_is_enabled(unsigned int intid)
213213
return (val & mask) != 0;
214214
}
215215

216+
bool arm_gic_irq_is_pending(unsigned int intid)
217+
{
218+
uint32_t mask = BIT(intid & (GIC_NUM_INTR_PER_REG - 1));
219+
uint32_t idx = intid / GIC_NUM_INTR_PER_REG;
220+
uint32_t val;
221+
222+
val = sys_read32(ISPENDR(GET_DIST_BASE(intid), idx));
223+
224+
return (val & mask) != 0;
225+
}
226+
227+
void arm_gic_irq_clear_pending(unsigned int intid)
228+
{
229+
uint32_t mask = BIT(intid & (GIC_NUM_INTR_PER_REG - 1));
230+
uint32_t idx = intid / GIC_NUM_INTR_PER_REG;
231+
232+
sys_write32(mask, ICPENDR(GET_DIST_BASE(intid), idx));
233+
}
234+
216235
unsigned int arm_gic_get_active(void)
217236
{
218237
int intid;

include/zephyr/drivers/interrupt_controller/gic.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,21 @@ void arm_gic_irq_disable(unsigned int irq);
294294
*/
295295
bool arm_gic_irq_is_enabled(unsigned int irq);
296296

297+
/**
298+
* @brief Check if an interrupt is pending
299+
*
300+
* @param irq interrupt ID
301+
* @return Returns true if interrupt is pending, false otherwise
302+
*/
303+
bool arm_gic_irq_is_pending(unsigned int irq);
304+
305+
/**
306+
* @brief Clear the pending irq
307+
*
308+
* @param irq interrupt ID
309+
*/
310+
void arm_gic_irq_clear_pending(unsigned int irq);
311+
297312
/**
298313
* @brief Set interrupt priority
299314
*

0 commit comments

Comments
 (0)