From: kettenis Date: Sun, 7 Apr 2024 21:08:59 +0000 (+0000) Subject: The RISC-V architecture has cache-coherent DMA... until it doesn't. This X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=16c51e1a089c5661c8fd59ecd70bdd987735791f;p=openbsd The RISC-V architecture has cache-coherent DMA... until it doesn't. This is indicated by a "dma-noncoherent" property on the bus or device nodes in the device tree. Set the BUS_DMA_COHERENT flag on the DMA tag for mainbus(4) and modify the flags based on the presence of "dma-coherent" and "dma-noncoherent" properties where appropriate. ok patrick@ --- diff --git a/sys/arch/riscv64/dev/mainbus.c b/sys/arch/riscv64/dev/mainbus.c index d68acbd68c4..c51f6b025e8 100644 --- a/sys/arch/riscv64/dev/mainbus.c +++ b/sys/arch/riscv64/dev/mainbus.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mainbus.c,v 1.8 2021/06/20 16:51:37 deraadt Exp $ */ +/* $OpenBSD: mainbus.c,v 1.9 2024/04/07 21:08:59 kettenis Exp $ */ /* * Copyright (c) 2016 Patrick Wildt @@ -64,7 +64,7 @@ struct cfdriver mainbus_cd = { struct machine_bus_dma_tag mainbus_dma_tag = { NULL, - 0, + BUS_DMA_COHERENT, _dmamap_create, _dmamap_destroy, _dmamap_load, @@ -246,6 +246,18 @@ mainbus_attach_node(struct device *self, int node, cfmatch_t submatch) OF_getpropintarray(node, "interrupts", fa.fa_intr, len); } + if (OF_getproplen(node, "dma-noncoherent") >= 0) { + fa.fa_dmat = malloc(sizeof(*sc->sc_dmat), + M_DEVBUF, M_WAITOK | M_ZERO); + memcpy(fa.fa_dmat, sc->sc_dmat, sizeof(*sc->sc_dmat)); + fa.fa_dmat->_flags &= ~BUS_DMA_COHERENT; + } else if (OF_getproplen(node, "dma-coherent") >= 0) { + fa.fa_dmat = malloc(sizeof(*sc->sc_dmat), + M_DEVBUF, M_WAITOK | M_ZERO); + memcpy(fa.fa_dmat, sc->sc_dmat, sizeof(*sc->sc_dmat)); + fa.fa_dmat->_flags |= BUS_DMA_COHERENT; + } + if (submatch == NULL && sc->sc_early == 0) print = mainbus_print; if (submatch == NULL) diff --git a/sys/arch/riscv64/dev/simplebus.c b/sys/arch/riscv64/dev/simplebus.c index 3f74e2367e0..082395c1322 100644 --- a/sys/arch/riscv64/dev/simplebus.c +++ b/sys/arch/riscv64/dev/simplebus.c @@ -1,4 +1,4 @@ -/* $OpenBSD: simplebus.c,v 1.6 2023/09/22 01:10:44 jsg Exp $ */ +/* $OpenBSD: simplebus.c,v 1.7 2024/04/07 21:08:59 kettenis Exp $ */ /* * Copyright (c) 2016 Patrick Wildt @@ -226,7 +226,12 @@ simplebus_attach_node(struct device *self, int node) OF_getpropintarray(node, "interrupts", fa.fa_intr, len); } - if (OF_getproplen(node, "dma-coherent") >= 0) { + if (OF_getproplen(node, "dma-noncoherent") >= 0) { + fa.fa_dmat = malloc(sizeof(sc->sc_dma), + M_DEVBUF, M_WAITOK | M_ZERO); + memcpy(fa.fa_dmat, &sc->sc_dma, sizeof(sc->sc_dma)); + fa.fa_dmat->_flags &= ~BUS_DMA_COHERENT; + } else if (OF_getproplen(node, "dma-coherent") >= 0) { fa.fa_dmat = malloc(sizeof(sc->sc_dma), M_DEVBUF, M_WAITOK | M_ZERO); memcpy(fa.fa_dmat, &sc->sc_dma, sizeof(sc->sc_dma));