-/* $OpenBSD: plic.c,v 1.5 2021/05/13 09:32:00 kettenis Exp $ */
+/* $OpenBSD: plic.c,v 1.6 2021/05/13 19:26:25 kettenis Exp $ */
/*
* Copyright (c) 2020, Mars Li <mengshi.li.mars@gmail.com>
{
struct plic_softc *sc = plic;
struct plic_intrhand *ih;
- int sie;
+ u_long sie;
if (irqno < 0 || irqno >= PLIC_MAX_IRQS)
panic("plic_intr_establish: bogus irqnumber %d: %s",
irqno, name);
- sie = disable_interrupts();
ih = malloc(sizeof *ih, M_DEVBUF, M_WAITOK);
ih->ih_func = func;
ih->ih_irq = irqno;
ih->ih_name = name;
+ sie = intr_disable();
+
TAILQ_INSERT_TAIL(&sc->sc_isrcs[irqno].is_list, ih, ih_list);
if (name != NULL)
plic_calc_mask();
- restore_interrupts(sie);
+ intr_restore(sie);
return (ih);
}
struct plic_softc *sc = plic;
struct plic_intrhand *ih = cookie;
int irqno = ih->ih_irq;
- int sie;
+ u_long sie;
+
+ sie = intr_disable();
- sie = disable_interrupts();
TAILQ_REMOVE(&sc->sc_isrcs[irqno].is_list, ih, ih_list);
if (ih->ih_name != NULL)
evcount_detach(&ih->ih_count);
+
+ intr_restore(sie);
+
free(ih, M_DEVBUF, 0);
- restore_interrupts(sie);
}
void
plic_setipl(int new)
{
struct cpu_info *ci = curcpu();
- uint64_t sie;
+ u_long sie;
/* disable here is only to keep hardware in sync with ci->ci_cpl */
- sie = disable_interrupts();
+ sie = intr_disable();
ci->ci_cpl = new;
/* higher values are higher priority */
plic_set_threshold(ci->ci_cpuid, new);
- restore_interrupts(sie);
+ intr_restore(sie);
}
/*
-/* $OpenBSD: riscv_cpu_intc.c,v 1.6 2021/05/12 01:20:52 jsg Exp $ */
+/* $OpenBSD: riscv_cpu_intc.c,v 1.7 2021/05/13 19:26:25 kettenis Exp $ */
/*
* Copyright (c) 2020, Mars Li <mengshi.li.mars@gmail.com>
* XXX right time to enable interrupts ??
* might need to postpone untile autoconf is finished
*/
- enable_interrupts();
+ intr_enable();
}
riscv_intc_intr_establish(int irqno, int dummy_level, int (*func)(void *),
void *arg, char *name)
{
- int sie;
struct intrhand *ih;
+ u_long sie;
if (irqno < 0 || irqno >= INTC_NIRQS)
panic("intc_intr_establish: bogus irqnumber %d: %s",
irqno, name);
- sie = disable_interrupts();
ih = malloc(sizeof(*ih), M_DEVBUF, M_WAITOK);
ih->ih_func = func;
ih->ih_irq = irqno;
ih->ih_name = name;
+ sie = intr_disable();
intc_handler[irqno] = ih;
-#ifdef DEBUG_INTC
- printf("\nintc_intr_establish irq %d [%s]\n", irqno, name);
-#endif
- restore_interrupts(sie);
+ intr_restore(sie);
+
return (ih);
}
void
riscv_intc_intr_disestablish(void *cookie)
{
- int sie;
struct intrhand *ih = cookie;
int irqno = ih->ih_irq;
- sie = disable_interrupts();
+ u_long sie;
+ sie = intr_disable();
intc_handler[irqno] = NULL;
- free(ih, M_DEVBUF, 0);
+ intr_restore(sie);
- restore_interrupts(sie);
+ free(ih, M_DEVBUF, 0);
}
-/* $OpenBSD: intr.h,v 1.3 2021/05/12 01:20:52 jsg Exp $ */
+/* $OpenBSD: intr.h,v 1.4 2021/05/13 19:26:25 kettenis Exp $ */
/*
* Copyright (c) 2001-2004 Opsycon AB (www.opsycon.se / www.opsycon.com)
void intr_barrier(void *);
-static inline void
-enable_interrupts(void)
-{
- __asm volatile(
- "csrsi sstatus, %0"
- :: "i" (SSTATUS_SIE)
- );
-}
-
-static inline uint64_t
-disable_interrupts(void)
-{
- uint64_t ret;
-
- __asm volatile(
- "csrrci %0, sstatus, %1"
- : "=&r" (ret) : "i" (SSTATUS_SIE)
- );
-
- return (ret & (SSTATUS_SIE));
-}
-
-static inline void
-restore_interrupts(uint64_t s)
-{
- __asm volatile(
- "csrs sstatus, %0"
- :: "r" (s & (SSTATUS_SIE))
- );
-}
-
void riscv_init_smask(void); /* XXX */
extern uint32_t riscv_smask[NIPL];
-/* $OpenBSD: intr.c,v 1.4 2021/05/12 01:20:52 jsg Exp $ */
+/* $OpenBSD: intr.c,v 1.5 2021/05/13 19:26:25 kettenis Exp $ */
/*
* Copyright (c) 2011 Dale Rahn <drahn@openbsd.org>
riscv_do_pending_intr(int pcpl)
{
struct cpu_info *ci = curcpu();
- int sie;
+ u_long sie;
- sie = disable_interrupts();
+ sie = intr_disable();
#define DO_SOFTINT(si, ipl) \
if ((ci->ci_ipending & riscv_smask[pcpl]) & \
- SI_TO_IRQBIT(si)) { \
- ci->ci_ipending &= ~SI_TO_IRQBIT(si); \
- riscv_intr_func.setipl(ipl); \
- restore_interrupts(sie); \
- softintr_dispatch(si); \
- sie = disable_interrupts(); \
+ SI_TO_IRQBIT(si)) { \
+ ci->ci_ipending &= ~SI_TO_IRQBIT(si); \
+ riscv_intr_func.setipl(ipl); \
+ intr_restore(sie); \
+ softintr_dispatch(si); \
+ sie = intr_disable(); \
}
do {
/* Don't use splx... we are here already! */
riscv_intr_func.setipl(pcpl);
- restore_interrupts(sie);
+ intr_restore(sie);
}
void riscv_set_intr_func(int (*raise)(int), int (*lower)(int),
-/* $OpenBSD: machdep.c,v 1.14 2021/05/12 01:20:52 jsg Exp $ */
+/* $OpenBSD: machdep.c,v 1.15 2021/05/13 19:26:25 kettenis Exp $ */
/*
* Copyright (c) 2014 Patrick Wildt <patrick@blueri.se>
cpu_idle_cycle(void)
{
// Enable interrupts
- enable_interrupts();
+ intr_enable();
// XXX Data Sync Barrier? (Maybe SFENCE???)
__asm volatile("wfi");
}
-/* $OpenBSD: pmap.c,v 1.7 2021/05/12 01:20:52 jsg Exp $ */
+/* $OpenBSD: pmap.c,v 1.8 2021/05/13 19:26:25 kettenis Exp $ */
/*
* Copyright (c) 2019-2020 Brian Bamsch <bbamsch@google.com>
pmap_activate(struct proc *p)
{
pmap_t pm = p->p_vmspace->vm_map.pmap;
- int sie;
+ u_long sie;
- sie = disable_interrupts();
+ sie = intr_disable();
if (p == curproc && pm != curcpu()->ci_curpm)
pmap_set_satp(p);
- restore_interrupts(sie);
+ intr_restore(sie);
}
/*
-/* $OpenBSD: syscall.c,v 1.4 2021/05/12 01:20:52 jsg Exp $ */
+/* $OpenBSD: syscall.c,v 1.5 2021/05/13 19:26:25 kettenis Exp $ */
/*
* Copyright (c) 2020 Brian Bamsch <bbamsch@google.com>
/* Re-enable interrupts if they were enabled previously */
if (__predict_true(frame->tf_scause & EXCP_INTR))
- enable_interrupts();
+ intr_enable();
ap = &frame->tf_a[0]; // Pointer to first arg
code = frame->tf_t[0]; // Syscall code