Index: sys/riscv/riscv/plic.c =================================================================== --- sys/riscv/riscv/plic.c +++ sys/riscv/riscv/plic.c @@ -179,11 +179,11 @@ sc = device_get_softc(dev); src = (struct plic_irqsrc *)isrc; - cpu = PCPU_GET(cpuid); - - reg = RD4(sc, PLIC_ENABLE(sc, src->irq, cpu)); - reg &= ~(1 << (src->irq % 32)); - WR4(sc, PLIC_ENABLE(sc, src->irq, cpu), reg); + CPU_FOREACH(cpu) { + reg = RD4(sc, PLIC_ENABLE(sc, src->irq, cpu)); + reg &= ~(1 << (src->irq % 32)); + WR4(sc, PLIC_ENABLE(sc, src->irq, cpu), reg); + } } static void @@ -197,13 +197,11 @@ sc = device_get_softc(dev); src = (struct plic_irqsrc *)isrc; - WR4(sc, PLIC_PRIORITY(src->irq), 1); - - cpu = PCPU_GET(cpuid); - - reg = RD4(sc, PLIC_ENABLE(sc, src->irq, cpu)); - reg |= (1 << (src->irq % 32)); - WR4(sc, PLIC_ENABLE(sc, src->irq, cpu), reg); + CPU_FOREACH(cpu) { + reg = RD4(sc, PLIC_ENABLE(sc, src->irq, cpu)); + reg |= (1 << (src->irq % 32)); + WR4(sc, PLIC_ENABLE(sc, src->irq, cpu), reg); + } } static int @@ -292,7 +290,6 @@ /* Register the interrupt sources */ isrcs = sc->isrcs; name = device_get_nameunit(sc->dev); - cpu = PCPU_GET(cpuid); for (irq = 1; irq <= sc->ndev; irq++) { isrcs[irq].irq = irq; error = intr_isrc_register(&isrcs[irq].isrc, sc->dev, @@ -363,7 +360,9 @@ } OF_prop_free(cells); - WR4(sc, PLIC_THRESHOLD(sc, cpu), 0); + /* Set the threshold for each CPU to accept all priorities */ + CPU_FOREACH(cpu) + WR4(sc, PLIC_THRESHOLD(sc, cpu), 0); xref = OF_xref_from_node(node); pic = intr_pic_register(sc->dev, xref); @@ -399,6 +398,22 @@ WR4(sc, PLIC_PRIORITY(src->irq), 1); } +static int +plic_setup_intr(device_t dev, struct intr_irqsrc *isrc, + struct resource *res, struct intr_map_data *data) +{ + struct plic_softc *sc; + struct plic_irqsrc *src; + + if (isrc->isrc_handlers == 0) { + sc = device_get_softc(dev); + src = (struct plic_irqsrc *)isrc; + WR4(sc, PLIC_PRIORITY(src->irq), 1); + } + + return (0); +} + static device_method_t plic_methods[] = { DEVMETHOD(device_probe, plic_probe), DEVMETHOD(device_attach, plic_attach), @@ -408,6 +423,7 @@ DEVMETHOD(pic_map_intr, plic_map_intr), DEVMETHOD(pic_pre_ithread, plic_pre_ithread), DEVMETHOD(pic_post_ithread, plic_post_ithread), + DEVMETHOD(pic_setup_intr, plic_setup_intr), DEVMETHOD_END };