Skip to content

Commit 3f3e37a

Browse files
ycsinnashif
authored andcommitted
drivers: intc: plic: refactor lock in plic_irq_enable_set_state()
Move the lock out from the `plic_irq_enable_set_state()` function to cover the entire configuration process, so the whole of enable/disable is atomic. Signed-off-by: Yong Cong Sin <[email protected]> Signed-off-by: Yong Cong Sin <[email protected]>
1 parent f777030 commit 3f3e37a

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

drivers/interrupt_controller/intc_plic.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,15 +214,11 @@ static void plic_irq_enable_set_state(uint32_t irq, bool enable)
214214
for (uint32_t cpu_num = 0; cpu_num < arch_num_cpus(); cpu_num++) {
215215
mem_addr_t en_addr =
216216
get_context_en_addr(dev, cpu_num) + local_irq_to_reg_offset(local_irq);
217-
218217
uint32_t en_value;
219-
uint32_t key;
220218

221-
key = irq_lock();
222219
en_value = sys_read32(en_addr);
223220
WRITE_BIT(en_value, local_irq & PLIC_REG_MASK, enable);
224221
sys_write32(en_value, en_addr);
225-
irq_unlock(key);
226222
}
227223
}
228224

@@ -238,7 +234,11 @@ static void plic_irq_enable_set_state(uint32_t irq, bool enable)
238234
*/
239235
void riscv_plic_irq_enable(uint32_t irq)
240236
{
237+
uint32_t key = irq_lock();
238+
241239
plic_irq_enable_set_state(irq, true);
240+
241+
irq_unlock(key);
242242
}
243243

244244
/**
@@ -253,7 +253,11 @@ void riscv_plic_irq_enable(uint32_t irq)
253253
*/
254254
void riscv_plic_irq_disable(uint32_t irq)
255255
{
256+
uint32_t key = irq_lock();
257+
256258
plic_irq_enable_set_state(irq, false);
259+
260+
irq_unlock(key);
257261
}
258262

259263
/**

0 commit comments

Comments
 (0)